]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.5-201211042157.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.5-201211042157.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index 39462cf..611a556 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 @@ -163,14 +181,15 @@ machtypes.h
131 map
132 map_hugetlb
133 maui_boot.h
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 @@ -187,6 +206,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 @@ -196,6 +217,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160 +pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164 @@ -205,7 +227,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 @@ -215,8 +240,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 @@ -226,6 +254,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 @@ -237,13 +266,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 @@ -251,9 +284,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 ad7e2e5..199f49e 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 @@ -2050,6 +2053,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 6e4a00d..4c7aa4f 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 @@ -404,8 +405,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 @@ -561,6 +562,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 @@ -715,7 +770,7 @@ export mod_strip_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 @@ -762,6 +817,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 @@ -771,7 +828,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 @@ -815,6 +872,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 @@ -922,6 +980,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 @@ -937,7 +997,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 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
395 MRPROPER_DIRS += include/config usr/include include/generated \
396 arch/*/include/generated
397 MRPROPER_FILES += .config .config.old .version .old_version \
398 - include/linux/version.h \
399 + include/linux/version.h tools/gcc/size_overflow_hash.h\
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
401
402 # clean - Delete most, but leave enough to build external modules
403 @@ -1032,6 +1092,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 @@ -1192,6 +1253,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 @@ -1326,17 +1389,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 @@ -1346,11 +1413,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 bc1acdd..a922a6d 100644
583 --- a/arch/alpha/kernel/osf_sys.c
584 +++ b/arch/alpha/kernel/osf_sys.c
585 @@ -1312,7 +1312,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 @@ -1348,6 +1348,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 @@ -1355,8 +1359,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 e4448e1..7bc86b7 100644
1422 --- a/arch/arm/include/asm/cacheflush.h
1423 +++ b/arch/arm/include/asm/cacheflush.h
1424 @@ -108,7 +108,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 ecf9019..b71d9a1 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 af7b0bd..6750a8c 100644
1539 --- a/arch/arm/include/asm/thread_info.h
1540 +++ b/arch/arm/include/asm/thread_info.h
1541 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1542 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1543 #define TIF_SYSCALL_TRACE 8
1544 #define TIF_SYSCALL_AUDIT 9
1545 +
1546 +/* within 8 bits of TIF_SYSCALL_TRACE
1547 + to meet flexible second operand requirements
1548 +*/
1549 +#define TIF_GRSEC_SETXID 10
1550 +
1551 #define TIF_POLLING_NRFLAG 16
1552 #define TIF_USING_IWMMXT 17
1553 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1554 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1555 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
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)
1562 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
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 77bd79f..ad4cd27 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 693b744..e684262 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
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 @@ -501,12 +501,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 3e0fc5f..a42d2ec 100644
1680 --- a/arch/arm/kernel/ptrace.c
1681 +++ b/arch/arm/kernel/ptrace.c
1682 @@ -913,11 +913,20 @@ 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 unsigned long ip;
1694
1695 +#ifdef CONFIG_GRKERNSEC_SETXID
1696 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1697 + gr_delayed_cred_worker();
1698 +#endif
1699 +
1700 if (!test_thread_flag(TIF_SYSCALL_TRACE))
1701 return scno;
1702
1703 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1704 index a81dcec..ac42f0f 100644
1705 --- a/arch/arm/kernel/setup.c
1706 +++ b/arch/arm/kernel/setup.c
1707 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1708 struct cpu_tlb_fns cpu_tlb __read_mostly;
1709 #endif
1710 #ifdef MULTI_USER
1711 -struct cpu_user_fns cpu_user __read_mostly;
1712 +struct cpu_user_fns cpu_user __read_only;
1713 #endif
1714 #ifdef MULTI_CACHE
1715 -struct cpu_cache_fns cpu_cache __read_mostly;
1716 +struct cpu_cache_fns cpu_cache __read_only;
1717 #endif
1718 #ifdef CONFIG_OUTER_CACHE
1719 -struct outer_cache_fns outer_cache __read_mostly;
1720 +struct outer_cache_fns outer_cache __read_only;
1721 EXPORT_SYMBOL(outer_cache);
1722 #endif
1723
1724 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1725 index b0179b8..b54c6c1 100644
1726 --- a/arch/arm/kernel/traps.c
1727 +++ b/arch/arm/kernel/traps.c
1728 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
1729 static int die_owner = -1;
1730 static unsigned int die_nest_count;
1731
1732 +extern void gr_handle_kernel_exploit(void);
1733 +
1734 static unsigned long oops_begin(void)
1735 {
1736 int cpu;
1737 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
1738 panic("Fatal exception in interrupt");
1739 if (panic_on_oops)
1740 panic("Fatal exception");
1741 +
1742 + gr_handle_kernel_exploit();
1743 +
1744 if (signr)
1745 do_exit(signr);
1746 }
1747 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1748 index 66a477a..bee61d3 100644
1749 --- a/arch/arm/lib/copy_from_user.S
1750 +++ b/arch/arm/lib/copy_from_user.S
1751 @@ -16,7 +16,7 @@
1752 /*
1753 * Prototype:
1754 *
1755 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1756 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1757 *
1758 * Purpose:
1759 *
1760 @@ -84,11 +84,11 @@
1761
1762 .text
1763
1764 -ENTRY(__copy_from_user)
1765 +ENTRY(___copy_from_user)
1766
1767 #include "copy_template.S"
1768
1769 -ENDPROC(__copy_from_user)
1770 +ENDPROC(___copy_from_user)
1771
1772 .pushsection .fixup,"ax"
1773 .align 0
1774 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1775 index 6ee2f67..d1cce76 100644
1776 --- a/arch/arm/lib/copy_page.S
1777 +++ b/arch/arm/lib/copy_page.S
1778 @@ -10,6 +10,7 @@
1779 * ASM optimised string functions
1780 */
1781 #include <linux/linkage.h>
1782 +#include <linux/const.h>
1783 #include <asm/assembler.h>
1784 #include <asm/asm-offsets.h>
1785 #include <asm/cache.h>
1786 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1787 index d066df6..df28194 100644
1788 --- a/arch/arm/lib/copy_to_user.S
1789 +++ b/arch/arm/lib/copy_to_user.S
1790 @@ -16,7 +16,7 @@
1791 /*
1792 * Prototype:
1793 *
1794 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1795 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1796 *
1797 * Purpose:
1798 *
1799 @@ -88,11 +88,11 @@
1800 .text
1801
1802 ENTRY(__copy_to_user_std)
1803 -WEAK(__copy_to_user)
1804 +WEAK(___copy_to_user)
1805
1806 #include "copy_template.S"
1807
1808 -ENDPROC(__copy_to_user)
1809 +ENDPROC(___copy_to_user)
1810 ENDPROC(__copy_to_user_std)
1811
1812 .pushsection .fixup,"ax"
1813 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1814 index 025f742..8432b08 100644
1815 --- a/arch/arm/lib/uaccess_with_memcpy.c
1816 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1817 @@ -104,7 +104,7 @@ out:
1818 }
1819
1820 unsigned long
1821 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1822 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1823 {
1824 /*
1825 * This test is stubbed out of the main function above to keep
1826 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1827 index 1201191..eabbb2c 100644
1828 --- a/arch/arm/mach-kirkwood/common.c
1829 +++ b/arch/arm/mach-kirkwood/common.c
1830 @@ -160,7 +160,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1831 clk_gate_ops.disable(hw);
1832 }
1833
1834 -static struct clk_ops clk_gate_fn_ops;
1835 +static clk_ops_no_const clk_gate_fn_ops;
1836
1837 static struct clk __init *clk_register_gate_fn(struct device *dev,
1838 const char *name,
1839 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1840 index 677357f..8828dda 100644
1841 --- a/arch/arm/mach-omap2/board-n8x0.c
1842 +++ b/arch/arm/mach-omap2/board-n8x0.c
1843 @@ -593,7 +593,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1844 }
1845 #endif
1846
1847 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1848 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1849 .late_init = n8x0_menelaus_late_init,
1850 };
1851
1852 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1853 index c3bd834..e81ef02 100644
1854 --- a/arch/arm/mm/fault.c
1855 +++ b/arch/arm/mm/fault.c
1856 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1857 }
1858 #endif
1859
1860 +#ifdef CONFIG_PAX_PAGEEXEC
1861 + if (fsr & FSR_LNX_PF) {
1862 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1863 + do_group_exit(SIGKILL);
1864 + }
1865 +#endif
1866 +
1867 tsk->thread.address = addr;
1868 tsk->thread.error_code = fsr;
1869 tsk->thread.trap_no = 14;
1870 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1871 }
1872 #endif /* CONFIG_MMU */
1873
1874 +#ifdef CONFIG_PAX_PAGEEXEC
1875 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1876 +{
1877 + long i;
1878 +
1879 + printk(KERN_ERR "PAX: bytes at PC: ");
1880 + for (i = 0; i < 20; i++) {
1881 + unsigned char c;
1882 + if (get_user(c, (__force unsigned char __user *)pc+i))
1883 + printk(KERN_CONT "?? ");
1884 + else
1885 + printk(KERN_CONT "%02x ", c);
1886 + }
1887 + printk("\n");
1888 +
1889 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1890 + for (i = -1; i < 20; i++) {
1891 + unsigned long c;
1892 + if (get_user(c, (__force unsigned long __user *)sp+i))
1893 + printk(KERN_CONT "???????? ");
1894 + else
1895 + printk(KERN_CONT "%08lx ", c);
1896 + }
1897 + printk("\n");
1898 +}
1899 +#endif
1900 +
1901 /*
1902 * First Level Translation Fault Handler
1903 *
1904 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1905 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1906 struct siginfo info;
1907
1908 +#ifdef CONFIG_PAX_REFCOUNT
1909 + if (fsr_fs(ifsr) == 2) {
1910 + unsigned int bkpt;
1911 +
1912 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1913 + current->thread.error_code = ifsr;
1914 + current->thread.trap_no = 0;
1915 + pax_report_refcount_overflow(regs);
1916 + fixup_exception(regs);
1917 + return;
1918 + }
1919 + }
1920 +#endif
1921 +
1922 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1923 return;
1924
1925 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1926 index ce8cb19..3ec539d 100644
1927 --- a/arch/arm/mm/mmap.c
1928 +++ b/arch/arm/mm/mmap.c
1929 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1930 if (len > TASK_SIZE)
1931 return -ENOMEM;
1932
1933 +#ifdef CONFIG_PAX_RANDMMAP
1934 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1935 +#endif
1936 +
1937 if (addr) {
1938 if (do_align)
1939 addr = COLOUR_ALIGN(addr, pgoff);
1940 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1941 addr = PAGE_ALIGN(addr);
1942
1943 vma = find_vma(mm, addr);
1944 - if (TASK_SIZE - len >= addr &&
1945 - (!vma || addr + len <= vma->vm_start))
1946 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1947 return addr;
1948 }
1949 if (len > mm->cached_hole_size) {
1950 - start_addr = addr = mm->free_area_cache;
1951 + start_addr = addr = mm->free_area_cache;
1952 } else {
1953 - start_addr = addr = mm->mmap_base;
1954 - mm->cached_hole_size = 0;
1955 + start_addr = addr = mm->mmap_base;
1956 + mm->cached_hole_size = 0;
1957 }
1958
1959 full_search:
1960 @@ -124,14 +127,14 @@ full_search:
1961 * Start a new search - just in case we missed
1962 * some holes.
1963 */
1964 - if (start_addr != TASK_UNMAPPED_BASE) {
1965 - start_addr = addr = TASK_UNMAPPED_BASE;
1966 + if (start_addr != mm->mmap_base) {
1967 + start_addr = addr = mm->mmap_base;
1968 mm->cached_hole_size = 0;
1969 goto full_search;
1970 }
1971 return -ENOMEM;
1972 }
1973 - if (!vma || addr + len <= vma->vm_start) {
1974 + if (check_heap_stack_gap(vma, addr, len)) {
1975 /*
1976 * Remember the place where we stopped the search:
1977 */
1978 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
1979
1980 if (mmap_is_legacy()) {
1981 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
1982 +
1983 +#ifdef CONFIG_PAX_RANDMMAP
1984 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1985 + mm->mmap_base += mm->delta_mmap;
1986 +#endif
1987 +
1988 mm->get_unmapped_area = arch_get_unmapped_area;
1989 mm->unmap_area = arch_unmap_area;
1990 } else {
1991 mm->mmap_base = mmap_base(random_factor);
1992 +
1993 +#ifdef CONFIG_PAX_RANDMMAP
1994 + if (mm->pax_flags & MF_PAX_RANDMMAP)
1995 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
1996 +#endif
1997 +
1998 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
1999 mm->unmap_area = arch_unmap_area_topdown;
2000 }
2001 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2002 index fd556f7..af2e7d2 100644
2003 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2004 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2005 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2006 value in bridge_virt_base */
2007 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2008 const int win);
2009 -};
2010 +} __no_const;
2011
2012 /*
2013 * Information needed to setup one address mapping.
2014 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2015 index f5144cd..71f6d1f 100644
2016 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2017 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2018 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
2019 int (*started)(unsigned ch);
2020 int (*flush)(unsigned ch);
2021 int (*stop)(unsigned ch);
2022 -};
2023 +} __no_const;
2024
2025 extern void *samsung_dmadev_get_ops(void);
2026 extern void *s3c_dma_get_ops(void);
2027 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2028 index 5f28cae..3d23723 100644
2029 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2030 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2031 @@ -14,7 +14,7 @@
2032 struct s5p_ehci_platdata {
2033 int (*phy_init)(struct platform_device *pdev, int type);
2034 int (*phy_exit)(struct platform_device *pdev, int type);
2035 -};
2036 +} __no_const;
2037
2038 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2039
2040 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2041 index c3a58a1..78fbf54 100644
2042 --- a/arch/avr32/include/asm/cache.h
2043 +++ b/arch/avr32/include/asm/cache.h
2044 @@ -1,8 +1,10 @@
2045 #ifndef __ASM_AVR32_CACHE_H
2046 #define __ASM_AVR32_CACHE_H
2047
2048 +#include <linux/const.h>
2049 +
2050 #define L1_CACHE_SHIFT 5
2051 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2052 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2053
2054 /*
2055 * Memory returned by kmalloc() may be used for DMA, so we must make
2056 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2057 index 3b3159b..425ea94 100644
2058 --- a/arch/avr32/include/asm/elf.h
2059 +++ b/arch/avr32/include/asm/elf.h
2060 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2061 the loader. We need to make sure that it is out of the way of the program
2062 that it will "exec", and that there is sufficient room for the brk. */
2063
2064 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2065 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2066
2067 +#ifdef CONFIG_PAX_ASLR
2068 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2069 +
2070 +#define PAX_DELTA_MMAP_LEN 15
2071 +#define PAX_DELTA_STACK_LEN 15
2072 +#endif
2073
2074 /* This yields a mask that user programs can use to figure out what
2075 instruction set this CPU supports. This could be done in user space,
2076 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2077 index 479330b..53717a8 100644
2078 --- a/arch/avr32/include/asm/kmap_types.h
2079 +++ b/arch/avr32/include/asm/kmap_types.h
2080 @@ -2,9 +2,9 @@
2081 #define __ASM_AVR32_KMAP_TYPES_H
2082
2083 #ifdef CONFIG_DEBUG_HIGHMEM
2084 -# define KM_TYPE_NR 29
2085 +# define KM_TYPE_NR 30
2086 #else
2087 -# define KM_TYPE_NR 14
2088 +# define KM_TYPE_NR 15
2089 #endif
2090
2091 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2092 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2093 index b92e609..b69c101 100644
2094 --- a/arch/avr32/mm/fault.c
2095 +++ b/arch/avr32/mm/fault.c
2096 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2097
2098 int exception_trace = 1;
2099
2100 +#ifdef CONFIG_PAX_PAGEEXEC
2101 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2102 +{
2103 + unsigned long i;
2104 +
2105 + printk(KERN_ERR "PAX: bytes at PC: ");
2106 + for (i = 0; i < 20; i++) {
2107 + unsigned char c;
2108 + if (get_user(c, (unsigned char *)pc+i))
2109 + printk(KERN_CONT "???????? ");
2110 + else
2111 + printk(KERN_CONT "%02x ", c);
2112 + }
2113 + printk("\n");
2114 +}
2115 +#endif
2116 +
2117 /*
2118 * This routine handles page faults. It determines the address and the
2119 * problem, and then passes it off to one of the appropriate routines.
2120 @@ -173,6 +190,16 @@ bad_area:
2121 up_read(&mm->mmap_sem);
2122
2123 if (user_mode(regs)) {
2124 +
2125 +#ifdef CONFIG_PAX_PAGEEXEC
2126 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2127 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2128 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2129 + do_group_exit(SIGKILL);
2130 + }
2131 + }
2132 +#endif
2133 +
2134 if (exception_trace && printk_ratelimit())
2135 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2136 "sp %08lx ecr %lu\n",
2137 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2138 index 568885a..f8008df 100644
2139 --- a/arch/blackfin/include/asm/cache.h
2140 +++ b/arch/blackfin/include/asm/cache.h
2141 @@ -7,6 +7,7 @@
2142 #ifndef __ARCH_BLACKFIN_CACHE_H
2143 #define __ARCH_BLACKFIN_CACHE_H
2144
2145 +#include <linux/const.h>
2146 #include <linux/linkage.h> /* for asmlinkage */
2147
2148 /*
2149 @@ -14,7 +15,7 @@
2150 * Blackfin loads 32 bytes for cache
2151 */
2152 #define L1_CACHE_SHIFT 5
2153 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2154 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2155 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2156
2157 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2158 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2159 index aea2718..3639a60 100644
2160 --- a/arch/cris/include/arch-v10/arch/cache.h
2161 +++ b/arch/cris/include/arch-v10/arch/cache.h
2162 @@ -1,8 +1,9 @@
2163 #ifndef _ASM_ARCH_CACHE_H
2164 #define _ASM_ARCH_CACHE_H
2165
2166 +#include <linux/const.h>
2167 /* Etrax 100LX have 32-byte cache-lines. */
2168 -#define L1_CACHE_BYTES 32
2169 #define L1_CACHE_SHIFT 5
2170 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2171
2172 #endif /* _ASM_ARCH_CACHE_H */
2173 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2174 index 7caf25d..ee65ac5 100644
2175 --- a/arch/cris/include/arch-v32/arch/cache.h
2176 +++ b/arch/cris/include/arch-v32/arch/cache.h
2177 @@ -1,11 +1,12 @@
2178 #ifndef _ASM_CRIS_ARCH_CACHE_H
2179 #define _ASM_CRIS_ARCH_CACHE_H
2180
2181 +#include <linux/const.h>
2182 #include <arch/hwregs/dma.h>
2183
2184 /* A cache-line is 32 bytes. */
2185 -#define L1_CACHE_BYTES 32
2186 #define L1_CACHE_SHIFT 5
2187 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2188
2189 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2190
2191 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2192 index b86329d..6709906 100644
2193 --- a/arch/frv/include/asm/atomic.h
2194 +++ b/arch/frv/include/asm/atomic.h
2195 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2196 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2197 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2198
2199 +#define atomic64_read_unchecked(v) atomic64_read(v)
2200 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2201 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2202 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2203 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2204 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2205 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2206 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2207 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2208 +
2209 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2210 {
2211 int c, old;
2212 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2213 index 2797163..c2a401d 100644
2214 --- a/arch/frv/include/asm/cache.h
2215 +++ b/arch/frv/include/asm/cache.h
2216 @@ -12,10 +12,11 @@
2217 #ifndef __ASM_CACHE_H
2218 #define __ASM_CACHE_H
2219
2220 +#include <linux/const.h>
2221
2222 /* bytes per L1 cache line */
2223 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2224 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2225 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2226
2227 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2228 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2229 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2230 index 43901f2..0d8b865 100644
2231 --- a/arch/frv/include/asm/kmap_types.h
2232 +++ b/arch/frv/include/asm/kmap_types.h
2233 @@ -2,6 +2,6 @@
2234 #ifndef _ASM_KMAP_TYPES_H
2235 #define _ASM_KMAP_TYPES_H
2236
2237 -#define KM_TYPE_NR 17
2238 +#define KM_TYPE_NR 18
2239
2240 #endif
2241 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2242 index 385fd30..6c3d97e 100644
2243 --- a/arch/frv/mm/elf-fdpic.c
2244 +++ b/arch/frv/mm/elf-fdpic.c
2245 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2246 if (addr) {
2247 addr = PAGE_ALIGN(addr);
2248 vma = find_vma(current->mm, addr);
2249 - if (TASK_SIZE - len >= addr &&
2250 - (!vma || addr + len <= vma->vm_start))
2251 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2252 goto success;
2253 }
2254
2255 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2256 for (; vma; vma = vma->vm_next) {
2257 if (addr > limit)
2258 break;
2259 - if (addr + len <= vma->vm_start)
2260 + if (check_heap_stack_gap(vma, addr, len))
2261 goto success;
2262 addr = vma->vm_end;
2263 }
2264 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2265 for (; vma; vma = vma->vm_next) {
2266 if (addr > limit)
2267 break;
2268 - if (addr + len <= vma->vm_start)
2269 + if (check_heap_stack_gap(vma, addr, len))
2270 goto success;
2271 addr = vma->vm_end;
2272 }
2273 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2274 index c635028..6d9445a 100644
2275 --- a/arch/h8300/include/asm/cache.h
2276 +++ b/arch/h8300/include/asm/cache.h
2277 @@ -1,8 +1,10 @@
2278 #ifndef __ARCH_H8300_CACHE_H
2279 #define __ARCH_H8300_CACHE_H
2280
2281 +#include <linux/const.h>
2282 +
2283 /* bytes per L1 cache line */
2284 -#define L1_CACHE_BYTES 4
2285 +#define L1_CACHE_BYTES _AC(4,UL)
2286
2287 /* m68k-elf-gcc 2.95.2 doesn't like these */
2288
2289 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2290 index 0f01de2..d37d309 100644
2291 --- a/arch/hexagon/include/asm/cache.h
2292 +++ b/arch/hexagon/include/asm/cache.h
2293 @@ -21,9 +21,11 @@
2294 #ifndef __ASM_CACHE_H
2295 #define __ASM_CACHE_H
2296
2297 +#include <linux/const.h>
2298 +
2299 /* Bytes per L1 cache line */
2300 -#define L1_CACHE_SHIFT (5)
2301 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2302 +#define L1_CACHE_SHIFT 5
2303 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2304
2305 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2306 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2307 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2308 index 6e6fe18..a6ae668 100644
2309 --- a/arch/ia64/include/asm/atomic.h
2310 +++ b/arch/ia64/include/asm/atomic.h
2311 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2312 #define atomic64_inc(v) atomic64_add(1, (v))
2313 #define atomic64_dec(v) atomic64_sub(1, (v))
2314
2315 +#define atomic64_read_unchecked(v) atomic64_read(v)
2316 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2317 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2318 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2319 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2320 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2321 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2322 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2323 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2324 +
2325 /* Atomic operations are already serializing */
2326 #define smp_mb__before_atomic_dec() barrier()
2327 #define smp_mb__after_atomic_dec() barrier()
2328 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2329 index 988254a..e1ee885 100644
2330 --- a/arch/ia64/include/asm/cache.h
2331 +++ b/arch/ia64/include/asm/cache.h
2332 @@ -1,6 +1,7 @@
2333 #ifndef _ASM_IA64_CACHE_H
2334 #define _ASM_IA64_CACHE_H
2335
2336 +#include <linux/const.h>
2337
2338 /*
2339 * Copyright (C) 1998-2000 Hewlett-Packard Co
2340 @@ -9,7 +10,7 @@
2341
2342 /* Bytes per L1 (data) cache line. */
2343 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2344 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2345 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2346
2347 #ifdef CONFIG_SMP
2348 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2349 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2350 index b5298eb..67c6e62 100644
2351 --- a/arch/ia64/include/asm/elf.h
2352 +++ b/arch/ia64/include/asm/elf.h
2353 @@ -42,6 +42,13 @@
2354 */
2355 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2356
2357 +#ifdef CONFIG_PAX_ASLR
2358 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2359 +
2360 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2361 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2362 +#endif
2363 +
2364 #define PT_IA_64_UNWIND 0x70000001
2365
2366 /* IA-64 relocations: */
2367 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2368 index 96a8d92..617a1cf 100644
2369 --- a/arch/ia64/include/asm/pgalloc.h
2370 +++ b/arch/ia64/include/asm/pgalloc.h
2371 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2372 pgd_val(*pgd_entry) = __pa(pud);
2373 }
2374
2375 +static inline void
2376 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2377 +{
2378 + pgd_populate(mm, pgd_entry, pud);
2379 +}
2380 +
2381 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2382 {
2383 return quicklist_alloc(0, GFP_KERNEL, NULL);
2384 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2385 pud_val(*pud_entry) = __pa(pmd);
2386 }
2387
2388 +static inline void
2389 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2390 +{
2391 + pud_populate(mm, pud_entry, pmd);
2392 +}
2393 +
2394 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2395 {
2396 return quicklist_alloc(0, GFP_KERNEL, NULL);
2397 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2398 index 815810c..d60bd4c 100644
2399 --- a/arch/ia64/include/asm/pgtable.h
2400 +++ b/arch/ia64/include/asm/pgtable.h
2401 @@ -12,7 +12,7 @@
2402 * David Mosberger-Tang <davidm@hpl.hp.com>
2403 */
2404
2405 -
2406 +#include <linux/const.h>
2407 #include <asm/mman.h>
2408 #include <asm/page.h>
2409 #include <asm/processor.h>
2410 @@ -142,6 +142,17 @@
2411 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2412 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2413 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2414 +
2415 +#ifdef CONFIG_PAX_PAGEEXEC
2416 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2417 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2418 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2419 +#else
2420 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2421 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2422 +# define PAGE_COPY_NOEXEC PAGE_COPY
2423 +#endif
2424 +
2425 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2426 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2427 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2428 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2429 index 54ff557..70c88b7 100644
2430 --- a/arch/ia64/include/asm/spinlock.h
2431 +++ b/arch/ia64/include/asm/spinlock.h
2432 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2433 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2434
2435 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2436 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2437 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2438 }
2439
2440 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2441 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2442 index 449c8c0..432a3d2 100644
2443 --- a/arch/ia64/include/asm/uaccess.h
2444 +++ b/arch/ia64/include/asm/uaccess.h
2445 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2446 const void *__cu_from = (from); \
2447 long __cu_len = (n); \
2448 \
2449 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2450 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2451 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2452 __cu_len; \
2453 })
2454 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2455 long __cu_len = (n); \
2456 \
2457 __chk_user_ptr(__cu_from); \
2458 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2459 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2460 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2461 __cu_len; \
2462 })
2463 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2464 index 24603be..948052d 100644
2465 --- a/arch/ia64/kernel/module.c
2466 +++ b/arch/ia64/kernel/module.c
2467 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2468 void
2469 module_free (struct module *mod, void *module_region)
2470 {
2471 - if (mod && mod->arch.init_unw_table &&
2472 - module_region == mod->module_init) {
2473 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2474 unw_remove_unwind_table(mod->arch.init_unw_table);
2475 mod->arch.init_unw_table = NULL;
2476 }
2477 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2478 }
2479
2480 static inline int
2481 +in_init_rx (const struct module *mod, uint64_t addr)
2482 +{
2483 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2484 +}
2485 +
2486 +static inline int
2487 +in_init_rw (const struct module *mod, uint64_t addr)
2488 +{
2489 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2490 +}
2491 +
2492 +static inline int
2493 in_init (const struct module *mod, uint64_t addr)
2494 {
2495 - return addr - (uint64_t) mod->module_init < mod->init_size;
2496 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2497 +}
2498 +
2499 +static inline int
2500 +in_core_rx (const struct module *mod, uint64_t addr)
2501 +{
2502 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2503 +}
2504 +
2505 +static inline int
2506 +in_core_rw (const struct module *mod, uint64_t addr)
2507 +{
2508 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2509 }
2510
2511 static inline int
2512 in_core (const struct module *mod, uint64_t addr)
2513 {
2514 - return addr - (uint64_t) mod->module_core < mod->core_size;
2515 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2516 }
2517
2518 static inline int
2519 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2520 break;
2521
2522 case RV_BDREL:
2523 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2524 + if (in_init_rx(mod, val))
2525 + val -= (uint64_t) mod->module_init_rx;
2526 + else if (in_init_rw(mod, val))
2527 + val -= (uint64_t) mod->module_init_rw;
2528 + else if (in_core_rx(mod, val))
2529 + val -= (uint64_t) mod->module_core_rx;
2530 + else if (in_core_rw(mod, val))
2531 + val -= (uint64_t) mod->module_core_rw;
2532 break;
2533
2534 case RV_LTV:
2535 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2536 * addresses have been selected...
2537 */
2538 uint64_t gp;
2539 - if (mod->core_size > MAX_LTOFF)
2540 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2541 /*
2542 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2543 * at the end of the module.
2544 */
2545 - gp = mod->core_size - MAX_LTOFF / 2;
2546 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2547 else
2548 - gp = mod->core_size / 2;
2549 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2550 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2551 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2552 mod->arch.gp = gp;
2553 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2554 }
2555 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2556 index d9439ef..b9a4303 100644
2557 --- a/arch/ia64/kernel/sys_ia64.c
2558 +++ b/arch/ia64/kernel/sys_ia64.c
2559 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2560 if (REGION_NUMBER(addr) == RGN_HPAGE)
2561 addr = 0;
2562 #endif
2563 +
2564 +#ifdef CONFIG_PAX_RANDMMAP
2565 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2566 + addr = mm->free_area_cache;
2567 + else
2568 +#endif
2569 +
2570 if (!addr)
2571 addr = mm->free_area_cache;
2572
2573 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2574 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2575 /* At this point: (!vma || addr < vma->vm_end). */
2576 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2577 - if (start_addr != TASK_UNMAPPED_BASE) {
2578 + if (start_addr != mm->mmap_base) {
2579 /* Start a new search --- just in case we missed some holes. */
2580 - addr = TASK_UNMAPPED_BASE;
2581 + addr = mm->mmap_base;
2582 goto full_search;
2583 }
2584 return -ENOMEM;
2585 }
2586 - if (!vma || addr + len <= vma->vm_start) {
2587 + if (check_heap_stack_gap(vma, addr, len)) {
2588 /* Remember the address where we stopped this search: */
2589 mm->free_area_cache = addr + len;
2590 return addr;
2591 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2592 index 0ccb28f..8992469 100644
2593 --- a/arch/ia64/kernel/vmlinux.lds.S
2594 +++ b/arch/ia64/kernel/vmlinux.lds.S
2595 @@ -198,7 +198,7 @@ SECTIONS {
2596 /* Per-cpu data: */
2597 . = ALIGN(PERCPU_PAGE_SIZE);
2598 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2599 - __phys_per_cpu_start = __per_cpu_load;
2600 + __phys_per_cpu_start = per_cpu_load;
2601 /*
2602 * ensure percpu data fits
2603 * into percpu page size
2604 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2605 index 8443daf..0a01e30 100644
2606 --- a/arch/ia64/mm/fault.c
2607 +++ b/arch/ia64/mm/fault.c
2608 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2609 return pte_present(pte);
2610 }
2611
2612 +#ifdef CONFIG_PAX_PAGEEXEC
2613 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2614 +{
2615 + unsigned long i;
2616 +
2617 + printk(KERN_ERR "PAX: bytes at PC: ");
2618 + for (i = 0; i < 8; i++) {
2619 + unsigned int c;
2620 + if (get_user(c, (unsigned int *)pc+i))
2621 + printk(KERN_CONT "???????? ");
2622 + else
2623 + printk(KERN_CONT "%08x ", c);
2624 + }
2625 + printk("\n");
2626 +}
2627 +#endif
2628 +
2629 # define VM_READ_BIT 0
2630 # define VM_WRITE_BIT 1
2631 # define VM_EXEC_BIT 2
2632 @@ -149,8 +166,21 @@ retry:
2633 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
2634 goto bad_area;
2635
2636 - if ((vma->vm_flags & mask) != mask)
2637 + if ((vma->vm_flags & mask) != mask) {
2638 +
2639 +#ifdef CONFIG_PAX_PAGEEXEC
2640 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2641 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2642 + goto bad_area;
2643 +
2644 + up_read(&mm->mmap_sem);
2645 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2646 + do_group_exit(SIGKILL);
2647 + }
2648 +#endif
2649 +
2650 goto bad_area;
2651 + }
2652
2653 /*
2654 * If for any reason at all we couldn't handle the fault, make
2655 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2656 index 5ca674b..e0e1b70 100644
2657 --- a/arch/ia64/mm/hugetlbpage.c
2658 +++ b/arch/ia64/mm/hugetlbpage.c
2659 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2660 /* At this point: (!vmm || addr < vmm->vm_end). */
2661 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2662 return -ENOMEM;
2663 - if (!vmm || (addr + len) <= vmm->vm_start)
2664 + if (check_heap_stack_gap(vmm, addr, len))
2665 return addr;
2666 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2667 }
2668 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2669 index 0eab454..bd794f2 100644
2670 --- a/arch/ia64/mm/init.c
2671 +++ b/arch/ia64/mm/init.c
2672 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2673 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2674 vma->vm_end = vma->vm_start + PAGE_SIZE;
2675 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2676 +
2677 +#ifdef CONFIG_PAX_PAGEEXEC
2678 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2679 + vma->vm_flags &= ~VM_EXEC;
2680 +
2681 +#ifdef CONFIG_PAX_MPROTECT
2682 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2683 + vma->vm_flags &= ~VM_MAYEXEC;
2684 +#endif
2685 +
2686 + }
2687 +#endif
2688 +
2689 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2690 down_write(&current->mm->mmap_sem);
2691 if (insert_vm_struct(current->mm, vma)) {
2692 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2693 index 40b3ee9..8c2c112 100644
2694 --- a/arch/m32r/include/asm/cache.h
2695 +++ b/arch/m32r/include/asm/cache.h
2696 @@ -1,8 +1,10 @@
2697 #ifndef _ASM_M32R_CACHE_H
2698 #define _ASM_M32R_CACHE_H
2699
2700 +#include <linux/const.h>
2701 +
2702 /* L1 cache line size */
2703 #define L1_CACHE_SHIFT 4
2704 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2705 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2706
2707 #endif /* _ASM_M32R_CACHE_H */
2708 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2709 index 82abd15..d95ae5d 100644
2710 --- a/arch/m32r/lib/usercopy.c
2711 +++ b/arch/m32r/lib/usercopy.c
2712 @@ -14,6 +14,9 @@
2713 unsigned long
2714 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2715 {
2716 + if ((long)n < 0)
2717 + return n;
2718 +
2719 prefetch(from);
2720 if (access_ok(VERIFY_WRITE, to, n))
2721 __copy_user(to,from,n);
2722 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2723 unsigned long
2724 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2725 {
2726 + if ((long)n < 0)
2727 + return n;
2728 +
2729 prefetchw(to);
2730 if (access_ok(VERIFY_READ, from, n))
2731 __copy_user_zeroing(to,from,n);
2732 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2733 index 0395c51..5f26031 100644
2734 --- a/arch/m68k/include/asm/cache.h
2735 +++ b/arch/m68k/include/asm/cache.h
2736 @@ -4,9 +4,11 @@
2737 #ifndef __ARCH_M68K_CACHE_H
2738 #define __ARCH_M68K_CACHE_H
2739
2740 +#include <linux/const.h>
2741 +
2742 /* bytes per L1 cache line */
2743 #define L1_CACHE_SHIFT 4
2744 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2745 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2746
2747 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2748
2749 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2750 index 4efe96a..60e8699 100644
2751 --- a/arch/microblaze/include/asm/cache.h
2752 +++ b/arch/microblaze/include/asm/cache.h
2753 @@ -13,11 +13,12 @@
2754 #ifndef _ASM_MICROBLAZE_CACHE_H
2755 #define _ASM_MICROBLAZE_CACHE_H
2756
2757 +#include <linux/const.h>
2758 #include <asm/registers.h>
2759
2760 #define L1_CACHE_SHIFT 5
2761 /* word-granular cache in microblaze */
2762 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2763 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2764
2765 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2766
2767 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2768 index 3f4c5cb..3439c6e 100644
2769 --- a/arch/mips/include/asm/atomic.h
2770 +++ b/arch/mips/include/asm/atomic.h
2771 @@ -21,6 +21,10 @@
2772 #include <asm/cmpxchg.h>
2773 #include <asm/war.h>
2774
2775 +#ifdef CONFIG_GENERIC_ATOMIC64
2776 +#include <asm-generic/atomic64.h>
2777 +#endif
2778 +
2779 #define ATOMIC_INIT(i) { (i) }
2780
2781 /*
2782 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2783 */
2784 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2785
2786 +#define atomic64_read_unchecked(v) atomic64_read(v)
2787 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2788 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2789 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2790 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2791 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2792 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2793 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2794 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2795 +
2796 #endif /* CONFIG_64BIT */
2797
2798 /*
2799 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2800 index b4db69f..8f3b093 100644
2801 --- a/arch/mips/include/asm/cache.h
2802 +++ b/arch/mips/include/asm/cache.h
2803 @@ -9,10 +9,11 @@
2804 #ifndef _ASM_CACHE_H
2805 #define _ASM_CACHE_H
2806
2807 +#include <linux/const.h>
2808 #include <kmalloc.h>
2809
2810 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2811 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2812 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2813
2814 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2815 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2816 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2817 index 455c0ac..ad65fbe 100644
2818 --- a/arch/mips/include/asm/elf.h
2819 +++ b/arch/mips/include/asm/elf.h
2820 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2821 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2822 #endif
2823
2824 +#ifdef CONFIG_PAX_ASLR
2825 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2826 +
2827 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2828 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2829 +#endif
2830 +
2831 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2832 struct linux_binprm;
2833 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2834 int uses_interp);
2835
2836 -struct mm_struct;
2837 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2838 -#define arch_randomize_brk arch_randomize_brk
2839 -
2840 #endif /* _ASM_ELF_H */
2841 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2842 index c1f6afa..38cc6e9 100644
2843 --- a/arch/mips/include/asm/exec.h
2844 +++ b/arch/mips/include/asm/exec.h
2845 @@ -12,6 +12,6 @@
2846 #ifndef _ASM_EXEC_H
2847 #define _ASM_EXEC_H
2848
2849 -extern unsigned long arch_align_stack(unsigned long sp);
2850 +#define arch_align_stack(x) ((x) & ~0xfUL)
2851
2852 #endif /* _ASM_EXEC_H */
2853 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2854 index da9bd7d..91aa7ab 100644
2855 --- a/arch/mips/include/asm/page.h
2856 +++ b/arch/mips/include/asm/page.h
2857 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2858 #ifdef CONFIG_CPU_MIPS32
2859 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2860 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2861 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2862 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2863 #else
2864 typedef struct { unsigned long long pte; } pte_t;
2865 #define pte_val(x) ((x).pte)
2866 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2867 index 881d18b..cea38bc 100644
2868 --- a/arch/mips/include/asm/pgalloc.h
2869 +++ b/arch/mips/include/asm/pgalloc.h
2870 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2871 {
2872 set_pud(pud, __pud((unsigned long)pmd));
2873 }
2874 +
2875 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2876 +{
2877 + pud_populate(mm, pud, pmd);
2878 +}
2879 #endif
2880
2881 /*
2882 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2883 index ca97e0e..cd08920 100644
2884 --- a/arch/mips/include/asm/thread_info.h
2885 +++ b/arch/mips/include/asm/thread_info.h
2886 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2887 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2888 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2889 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2890 +/* li takes a 32bit immediate */
2891 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2892 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2893
2894 #ifdef CONFIG_MIPS32_O32
2895 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2896 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2897 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2898 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2899 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2900 +
2901 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2902
2903 /* work to do in syscall_trace_leave() */
2904 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2905 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2906
2907 /* work to do on interrupt/exception return */
2908 #define _TIF_WORK_MASK (0x0000ffef & \
2909 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2910 /* work to do on any return to u-space */
2911 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2912 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2913
2914 #endif /* __KERNEL__ */
2915
2916 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2917 index 9fdd8bc..4bd7f1a 100644
2918 --- a/arch/mips/kernel/binfmt_elfn32.c
2919 +++ b/arch/mips/kernel/binfmt_elfn32.c
2920 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2921 #undef ELF_ET_DYN_BASE
2922 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2923
2924 +#ifdef CONFIG_PAX_ASLR
2925 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2926 +
2927 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2928 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2929 +#endif
2930 +
2931 #include <asm/processor.h>
2932 #include <linux/module.h>
2933 #include <linux/elfcore.h>
2934 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2935 index ff44823..97f8906 100644
2936 --- a/arch/mips/kernel/binfmt_elfo32.c
2937 +++ b/arch/mips/kernel/binfmt_elfo32.c
2938 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2939 #undef ELF_ET_DYN_BASE
2940 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2941
2942 +#ifdef CONFIG_PAX_ASLR
2943 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2944 +
2945 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2946 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2947 +#endif
2948 +
2949 #include <asm/processor.h>
2950
2951 /*
2952 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2953 index e9a5fd7..378809a 100644
2954 --- a/arch/mips/kernel/process.c
2955 +++ b/arch/mips/kernel/process.c
2956 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2957 out:
2958 return pc;
2959 }
2960 -
2961 -/*
2962 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2963 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2964 - */
2965 -unsigned long arch_align_stack(unsigned long sp)
2966 -{
2967 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2968 - sp -= get_random_int() & ~PAGE_MASK;
2969 -
2970 - return sp & ALMASK;
2971 -}
2972 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
2973 index 4812c6d..2069554 100644
2974 --- a/arch/mips/kernel/ptrace.c
2975 +++ b/arch/mips/kernel/ptrace.c
2976 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
2977 return arch;
2978 }
2979
2980 +#ifdef CONFIG_GRKERNSEC_SETXID
2981 +extern void gr_delayed_cred_worker(void);
2982 +#endif
2983 +
2984 /*
2985 * Notification of system call entry/exit
2986 * - triggered by current->work.syscall_trace
2987 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
2988 /* do the secure computing check first */
2989 secure_computing_strict(regs->regs[2]);
2990
2991 +#ifdef CONFIG_GRKERNSEC_SETXID
2992 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2993 + gr_delayed_cred_worker();
2994 +#endif
2995 +
2996 if (!(current->ptrace & PT_PTRACED))
2997 goto out;
2998
2999 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3000 index a632bc1..0b77c7c 100644
3001 --- a/arch/mips/kernel/scall32-o32.S
3002 +++ b/arch/mips/kernel/scall32-o32.S
3003 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3004
3005 stack_done:
3006 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3007 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3008 + li t1, _TIF_SYSCALL_WORK
3009 and t0, t1
3010 bnez t0, syscall_trace_entry # -> yes
3011
3012 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3013 index 3b5a5e9..e1ee86d 100644
3014 --- a/arch/mips/kernel/scall64-64.S
3015 +++ b/arch/mips/kernel/scall64-64.S
3016 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3017
3018 sd a3, PT_R26(sp) # save a3 for syscall restarting
3019
3020 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3021 + li t1, _TIF_SYSCALL_WORK
3022 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3023 and t0, t1, t0
3024 bnez t0, syscall_trace_entry
3025 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3026 index 6be6f70..1859577 100644
3027 --- a/arch/mips/kernel/scall64-n32.S
3028 +++ b/arch/mips/kernel/scall64-n32.S
3029 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3030
3031 sd a3, PT_R26(sp) # save a3 for syscall restarting
3032
3033 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3034 + li t1, _TIF_SYSCALL_WORK
3035 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3036 and t0, t1, t0
3037 bnez t0, n32_syscall_trace_entry
3038 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3039 index 5422855..74e63a3 100644
3040 --- a/arch/mips/kernel/scall64-o32.S
3041 +++ b/arch/mips/kernel/scall64-o32.S
3042 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3043 PTR 4b, bad_stack
3044 .previous
3045
3046 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3047 + li t1, _TIF_SYSCALL_WORK
3048 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3049 and t0, t1, t0
3050 bnez t0, trace_a_syscall
3051 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3052 index c14f6df..537e729 100644
3053 --- a/arch/mips/mm/fault.c
3054 +++ b/arch/mips/mm/fault.c
3055 @@ -27,6 +27,23 @@
3056 #include <asm/highmem.h> /* For VMALLOC_END */
3057 #include <linux/kdebug.h>
3058
3059 +#ifdef CONFIG_PAX_PAGEEXEC
3060 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3061 +{
3062 + unsigned long i;
3063 +
3064 + printk(KERN_ERR "PAX: bytes at PC: ");
3065 + for (i = 0; i < 5; i++) {
3066 + unsigned int c;
3067 + if (get_user(c, (unsigned int *)pc+i))
3068 + printk(KERN_CONT "???????? ");
3069 + else
3070 + printk(KERN_CONT "%08x ", c);
3071 + }
3072 + printk("\n");
3073 +}
3074 +#endif
3075 +
3076 /*
3077 * This routine handles page faults. It determines the address,
3078 * and the problem, and then passes it off to one of the appropriate
3079 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3080 index 302d779..7d35bf8 100644
3081 --- a/arch/mips/mm/mmap.c
3082 +++ b/arch/mips/mm/mmap.c
3083 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3084 do_color_align = 1;
3085
3086 /* requesting a specific address */
3087 +
3088 +#ifdef CONFIG_PAX_RANDMMAP
3089 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3090 +#endif
3091 +
3092 if (addr) {
3093 if (do_color_align)
3094 addr = COLOUR_ALIGN(addr, pgoff);
3095 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3096 addr = PAGE_ALIGN(addr);
3097
3098 vma = find_vma(mm, addr);
3099 - if (TASK_SIZE - len >= addr &&
3100 - (!vma || addr + len <= vma->vm_start))
3101 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3102 return addr;
3103 }
3104
3105 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3106 /* At this point: (!vma || addr < vma->vm_end). */
3107 if (TASK_SIZE - len < addr)
3108 return -ENOMEM;
3109 - if (!vma || addr + len <= vma->vm_start)
3110 + if (check_heap_stack_gap(vmm, addr, len))
3111 return addr;
3112 addr = vma->vm_end;
3113 if (do_color_align)
3114 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3115 /* make sure it can fit in the remaining address space */
3116 if (likely(addr > len)) {
3117 vma = find_vma(mm, addr - len);
3118 - if (!vma || addr <= vma->vm_start) {
3119 + if (check_heap_stack_gap(vmm, addr - len, len))
3120 /* cache the address as a hint for next time */
3121 return mm->free_area_cache = addr - len;
3122 }
3123 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3124 * return with success:
3125 */
3126 vma = find_vma(mm, addr);
3127 - if (likely(!vma || addr + len <= vma->vm_start)) {
3128 + if (check_heap_stack_gap(vmm, addr, len)) {
3129 /* cache the address as a hint for next time */
3130 return mm->free_area_cache = addr;
3131 }
3132 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3133 mm->unmap_area = arch_unmap_area_topdown;
3134 }
3135 }
3136 -
3137 -static inline unsigned long brk_rnd(void)
3138 -{
3139 - unsigned long rnd = get_random_int();
3140 -
3141 - rnd = rnd << PAGE_SHIFT;
3142 - /* 8MB for 32bit, 256MB for 64bit */
3143 - if (TASK_IS_32BIT_ADDR)
3144 - rnd = rnd & 0x7ffffful;
3145 - else
3146 - rnd = rnd & 0xffffffful;
3147 -
3148 - return rnd;
3149 -}
3150 -
3151 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3152 -{
3153 - unsigned long base = mm->brk;
3154 - unsigned long ret;
3155 -
3156 - ret = PAGE_ALIGN(base + brk_rnd());
3157 -
3158 - if (ret < mm->brk)
3159 - return mm->brk;
3160 -
3161 - return ret;
3162 -}
3163 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3164 index 967d144..db12197 100644
3165 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3166 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3167 @@ -11,12 +11,14 @@
3168 #ifndef _ASM_PROC_CACHE_H
3169 #define _ASM_PROC_CACHE_H
3170
3171 +#include <linux/const.h>
3172 +
3173 /* L1 cache */
3174
3175 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3176 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3177 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3178 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3179 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3180 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3181
3182 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3183 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3184 index bcb5df2..84fabd2 100644
3185 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3186 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3187 @@ -16,13 +16,15 @@
3188 #ifndef _ASM_PROC_CACHE_H
3189 #define _ASM_PROC_CACHE_H
3190
3191 +#include <linux/const.h>
3192 +
3193 /*
3194 * L1 cache
3195 */
3196 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3197 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3198 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3199 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3200 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3201 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3202
3203 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3204 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3205 index 4ce7a01..449202a 100644
3206 --- a/arch/openrisc/include/asm/cache.h
3207 +++ b/arch/openrisc/include/asm/cache.h
3208 @@ -19,11 +19,13 @@
3209 #ifndef __ASM_OPENRISC_CACHE_H
3210 #define __ASM_OPENRISC_CACHE_H
3211
3212 +#include <linux/const.h>
3213 +
3214 /* FIXME: How can we replace these with values from the CPU...
3215 * they shouldn't be hard-coded!
3216 */
3217
3218 -#define L1_CACHE_BYTES 16
3219 #define L1_CACHE_SHIFT 4
3220 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3221
3222 #endif /* __ASM_OPENRISC_CACHE_H */
3223 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3224 index af9cf30..2aae9b2 100644
3225 --- a/arch/parisc/include/asm/atomic.h
3226 +++ b/arch/parisc/include/asm/atomic.h
3227 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3228
3229 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3230
3231 +#define atomic64_read_unchecked(v) atomic64_read(v)
3232 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3233 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3234 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3235 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3236 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3237 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3238 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3239 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3240 +
3241 #endif /* !CONFIG_64BIT */
3242
3243
3244 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3245 index 47f11c7..3420df2 100644
3246 --- a/arch/parisc/include/asm/cache.h
3247 +++ b/arch/parisc/include/asm/cache.h
3248 @@ -5,6 +5,7 @@
3249 #ifndef __ARCH_PARISC_CACHE_H
3250 #define __ARCH_PARISC_CACHE_H
3251
3252 +#include <linux/const.h>
3253
3254 /*
3255 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3256 @@ -15,13 +16,13 @@
3257 * just ruin performance.
3258 */
3259 #ifdef CONFIG_PA20
3260 -#define L1_CACHE_BYTES 64
3261 #define L1_CACHE_SHIFT 6
3262 #else
3263 -#define L1_CACHE_BYTES 32
3264 #define L1_CACHE_SHIFT 5
3265 #endif
3266
3267 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3268 +
3269 #ifndef __ASSEMBLY__
3270
3271 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3272 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3273 index 19f6cb1..6c78cf2 100644
3274 --- a/arch/parisc/include/asm/elf.h
3275 +++ b/arch/parisc/include/asm/elf.h
3276 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3277
3278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3279
3280 +#ifdef CONFIG_PAX_ASLR
3281 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3282 +
3283 +#define PAX_DELTA_MMAP_LEN 16
3284 +#define PAX_DELTA_STACK_LEN 16
3285 +#endif
3286 +
3287 /* This yields a mask that user programs can use to figure out what
3288 instruction set this CPU supports. This could be done in user space,
3289 but it's not easy, and we've already done it here. */
3290 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3291 index fc987a1..6e068ef 100644
3292 --- a/arch/parisc/include/asm/pgalloc.h
3293 +++ b/arch/parisc/include/asm/pgalloc.h
3294 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3295 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3296 }
3297
3298 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3299 +{
3300 + pgd_populate(mm, pgd, pmd);
3301 +}
3302 +
3303 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3304 {
3305 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3306 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3307 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3308 #define pmd_free(mm, x) do { } while (0)
3309 #define pgd_populate(mm, pmd, pte) BUG()
3310 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3311
3312 #endif
3313
3314 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3315 index ee99f23..802b0a1 100644
3316 --- a/arch/parisc/include/asm/pgtable.h
3317 +++ b/arch/parisc/include/asm/pgtable.h
3318 @@ -212,6 +212,17 @@ struct vm_area_struct;
3319 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3320 #define PAGE_COPY PAGE_EXECREAD
3321 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3322 +
3323 +#ifdef CONFIG_PAX_PAGEEXEC
3324 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3325 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3326 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3327 +#else
3328 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3329 +# define PAGE_COPY_NOEXEC PAGE_COPY
3330 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3331 +#endif
3332 +
3333 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3334 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3335 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3336 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3337 index 4ba2c93..f5e3974 100644
3338 --- a/arch/parisc/include/asm/uaccess.h
3339 +++ b/arch/parisc/include/asm/uaccess.h
3340 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3341 const void __user *from,
3342 unsigned long n)
3343 {
3344 - int sz = __compiletime_object_size(to);
3345 + size_t sz = __compiletime_object_size(to);
3346 int ret = -EFAULT;
3347
3348 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3349 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3350 ret = __copy_from_user(to, from, n);
3351 else
3352 copy_from_user_overflow();
3353 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3354 index 5e34ccf..672bc9c 100644
3355 --- a/arch/parisc/kernel/module.c
3356 +++ b/arch/parisc/kernel/module.c
3357 @@ -98,16 +98,38 @@
3358
3359 /* three functions to determine where in the module core
3360 * or init pieces the location is */
3361 +static inline int in_init_rx(struct module *me, void *loc)
3362 +{
3363 + return (loc >= me->module_init_rx &&
3364 + loc < (me->module_init_rx + me->init_size_rx));
3365 +}
3366 +
3367 +static inline int in_init_rw(struct module *me, void *loc)
3368 +{
3369 + return (loc >= me->module_init_rw &&
3370 + loc < (me->module_init_rw + me->init_size_rw));
3371 +}
3372 +
3373 static inline int in_init(struct module *me, void *loc)
3374 {
3375 - return (loc >= me->module_init &&
3376 - loc <= (me->module_init + me->init_size));
3377 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3378 +}
3379 +
3380 +static inline int in_core_rx(struct module *me, void *loc)
3381 +{
3382 + return (loc >= me->module_core_rx &&
3383 + loc < (me->module_core_rx + me->core_size_rx));
3384 +}
3385 +
3386 +static inline int in_core_rw(struct module *me, void *loc)
3387 +{
3388 + return (loc >= me->module_core_rw &&
3389 + loc < (me->module_core_rw + me->core_size_rw));
3390 }
3391
3392 static inline int in_core(struct module *me, void *loc)
3393 {
3394 - return (loc >= me->module_core &&
3395 - loc <= (me->module_core + me->core_size));
3396 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3397 }
3398
3399 static inline int in_local(struct module *me, void *loc)
3400 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3401 }
3402
3403 /* align things a bit */
3404 - me->core_size = ALIGN(me->core_size, 16);
3405 - me->arch.got_offset = me->core_size;
3406 - me->core_size += gots * sizeof(struct got_entry);
3407 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3408 + me->arch.got_offset = me->core_size_rw;
3409 + me->core_size_rw += gots * sizeof(struct got_entry);
3410
3411 - me->core_size = ALIGN(me->core_size, 16);
3412 - me->arch.fdesc_offset = me->core_size;
3413 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3414 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3415 + me->arch.fdesc_offset = me->core_size_rw;
3416 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3417
3418 me->arch.got_max = gots;
3419 me->arch.fdesc_max = fdescs;
3420 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3421
3422 BUG_ON(value == 0);
3423
3424 - got = me->module_core + me->arch.got_offset;
3425 + got = me->module_core_rw + me->arch.got_offset;
3426 for (i = 0; got[i].addr; i++)
3427 if (got[i].addr == value)
3428 goto out;
3429 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3430 #ifdef CONFIG_64BIT
3431 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3432 {
3433 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3434 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3435
3436 if (!value) {
3437 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3438 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3439
3440 /* Create new one */
3441 fdesc->addr = value;
3442 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3443 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3444 return (Elf_Addr)fdesc;
3445 }
3446 #endif /* CONFIG_64BIT */
3447 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3448
3449 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3450 end = table + sechdrs[me->arch.unwind_section].sh_size;
3451 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3452 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3453
3454 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3455 me->arch.unwind_section, table, end, gp);
3456 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3457 index 7426e40..30c8dbe 100644
3458 --- a/arch/parisc/kernel/sys_parisc.c
3459 +++ b/arch/parisc/kernel/sys_parisc.c
3460 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3461 /* At this point: (!vma || addr < vma->vm_end). */
3462 if (TASK_SIZE - len < addr)
3463 return -ENOMEM;
3464 - if (!vma || addr + len <= vma->vm_start)
3465 + if (check_heap_stack_gap(vma, addr, len))
3466 return addr;
3467 addr = vma->vm_end;
3468 }
3469 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3470 /* At this point: (!vma || addr < vma->vm_end). */
3471 if (TASK_SIZE - len < addr)
3472 return -ENOMEM;
3473 - if (!vma || addr + len <= vma->vm_start)
3474 + if (check_heap_stack_gap(vma, addr, len))
3475 return addr;
3476 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3477 if (addr < vma->vm_end) /* handle wraparound */
3478 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3479 if (flags & MAP_FIXED)
3480 return addr;
3481 if (!addr)
3482 - addr = TASK_UNMAPPED_BASE;
3483 + addr = current->mm->mmap_base;
3484
3485 if (filp) {
3486 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3487 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3488 index 45ba99f..8e22c33 100644
3489 --- a/arch/parisc/kernel/traps.c
3490 +++ b/arch/parisc/kernel/traps.c
3491 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3492
3493 down_read(&current->mm->mmap_sem);
3494 vma = find_vma(current->mm,regs->iaoq[0]);
3495 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3496 - && (vma->vm_flags & VM_EXEC)) {
3497 -
3498 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3499 fault_address = regs->iaoq[0];
3500 fault_space = regs->iasq[0];
3501
3502 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3503 index 18162ce..94de376 100644
3504 --- a/arch/parisc/mm/fault.c
3505 +++ b/arch/parisc/mm/fault.c
3506 @@ -15,6 +15,7 @@
3507 #include <linux/sched.h>
3508 #include <linux/interrupt.h>
3509 #include <linux/module.h>
3510 +#include <linux/unistd.h>
3511
3512 #include <asm/uaccess.h>
3513 #include <asm/traps.h>
3514 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3515 static unsigned long
3516 parisc_acctyp(unsigned long code, unsigned int inst)
3517 {
3518 - if (code == 6 || code == 16)
3519 + if (code == 6 || code == 7 || code == 16)
3520 return VM_EXEC;
3521
3522 switch (inst & 0xf0000000) {
3523 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3524 }
3525 #endif
3526
3527 +#ifdef CONFIG_PAX_PAGEEXEC
3528 +/*
3529 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3530 + *
3531 + * returns 1 when task should be killed
3532 + * 2 when rt_sigreturn trampoline was detected
3533 + * 3 when unpatched PLT trampoline was detected
3534 + */
3535 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3536 +{
3537 +
3538 +#ifdef CONFIG_PAX_EMUPLT
3539 + int err;
3540 +
3541 + do { /* PaX: unpatched PLT emulation */
3542 + unsigned int bl, depwi;
3543 +
3544 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3545 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3546 +
3547 + if (err)
3548 + break;
3549 +
3550 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3551 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3552 +
3553 + err = get_user(ldw, (unsigned int *)addr);
3554 + err |= get_user(bv, (unsigned int *)(addr+4));
3555 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3556 +
3557 + if (err)
3558 + break;
3559 +
3560 + if (ldw == 0x0E801096U &&
3561 + bv == 0xEAC0C000U &&
3562 + ldw2 == 0x0E881095U)
3563 + {
3564 + unsigned int resolver, map;
3565 +
3566 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3567 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3568 + if (err)
3569 + break;
3570 +
3571 + regs->gr[20] = instruction_pointer(regs)+8;
3572 + regs->gr[21] = map;
3573 + regs->gr[22] = resolver;
3574 + regs->iaoq[0] = resolver | 3UL;
3575 + regs->iaoq[1] = regs->iaoq[0] + 4;
3576 + return 3;
3577 + }
3578 + }
3579 + } while (0);
3580 +#endif
3581 +
3582 +#ifdef CONFIG_PAX_EMUTRAMP
3583 +
3584 +#ifndef CONFIG_PAX_EMUSIGRT
3585 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3586 + return 1;
3587 +#endif
3588 +
3589 + do { /* PaX: rt_sigreturn emulation */
3590 + unsigned int ldi1, ldi2, bel, nop;
3591 +
3592 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3593 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3594 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3595 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3596 +
3597 + if (err)
3598 + break;
3599 +
3600 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3601 + ldi2 == 0x3414015AU &&
3602 + bel == 0xE4008200U &&
3603 + nop == 0x08000240U)
3604 + {
3605 + regs->gr[25] = (ldi1 & 2) >> 1;
3606 + regs->gr[20] = __NR_rt_sigreturn;
3607 + regs->gr[31] = regs->iaoq[1] + 16;
3608 + regs->sr[0] = regs->iasq[1];
3609 + regs->iaoq[0] = 0x100UL;
3610 + regs->iaoq[1] = regs->iaoq[0] + 4;
3611 + regs->iasq[0] = regs->sr[2];
3612 + regs->iasq[1] = regs->sr[2];
3613 + return 2;
3614 + }
3615 + } while (0);
3616 +#endif
3617 +
3618 + return 1;
3619 +}
3620 +
3621 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3622 +{
3623 + unsigned long i;
3624 +
3625 + printk(KERN_ERR "PAX: bytes at PC: ");
3626 + for (i = 0; i < 5; i++) {
3627 + unsigned int c;
3628 + if (get_user(c, (unsigned int *)pc+i))
3629 + printk(KERN_CONT "???????? ");
3630 + else
3631 + printk(KERN_CONT "%08x ", c);
3632 + }
3633 + printk("\n");
3634 +}
3635 +#endif
3636 +
3637 int fixup_exception(struct pt_regs *regs)
3638 {
3639 const struct exception_table_entry *fix;
3640 @@ -192,8 +303,33 @@ good_area:
3641
3642 acc_type = parisc_acctyp(code,regs->iir);
3643
3644 - if ((vma->vm_flags & acc_type) != acc_type)
3645 + if ((vma->vm_flags & acc_type) != acc_type) {
3646 +
3647 +#ifdef CONFIG_PAX_PAGEEXEC
3648 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3649 + (address & ~3UL) == instruction_pointer(regs))
3650 + {
3651 + up_read(&mm->mmap_sem);
3652 + switch (pax_handle_fetch_fault(regs)) {
3653 +
3654 +#ifdef CONFIG_PAX_EMUPLT
3655 + case 3:
3656 + return;
3657 +#endif
3658 +
3659 +#ifdef CONFIG_PAX_EMUTRAMP
3660 + case 2:
3661 + return;
3662 +#endif
3663 +
3664 + }
3665 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3666 + do_group_exit(SIGKILL);
3667 + }
3668 +#endif
3669 +
3670 goto bad_area;
3671 + }
3672
3673 /*
3674 * If for any reason at all we couldn't handle the fault, make
3675 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3676 index da29032..f76c24c 100644
3677 --- a/arch/powerpc/include/asm/atomic.h
3678 +++ b/arch/powerpc/include/asm/atomic.h
3679 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3680 return t1;
3681 }
3682
3683 +#define atomic64_read_unchecked(v) atomic64_read(v)
3684 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3685 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3686 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3687 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3688 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3689 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3690 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3691 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3692 +
3693 #endif /* __powerpc64__ */
3694
3695 #endif /* __KERNEL__ */
3696 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3697 index 9e495c9..b6878e5 100644
3698 --- a/arch/powerpc/include/asm/cache.h
3699 +++ b/arch/powerpc/include/asm/cache.h
3700 @@ -3,6 +3,7 @@
3701
3702 #ifdef __KERNEL__
3703
3704 +#include <linux/const.h>
3705
3706 /* bytes per L1 cache line */
3707 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3708 @@ -22,7 +23,7 @@
3709 #define L1_CACHE_SHIFT 7
3710 #endif
3711
3712 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3713 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3714
3715 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3716
3717 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3718 index 3bf9cca..e7457d0 100644
3719 --- a/arch/powerpc/include/asm/elf.h
3720 +++ b/arch/powerpc/include/asm/elf.h
3721 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3722 the loader. We need to make sure that it is out of the way of the program
3723 that it will "exec", and that there is sufficient room for the brk. */
3724
3725 -extern unsigned long randomize_et_dyn(unsigned long base);
3726 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3727 +#define ELF_ET_DYN_BASE (0x20000000)
3728 +
3729 +#ifdef CONFIG_PAX_ASLR
3730 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3731 +
3732 +#ifdef __powerpc64__
3733 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3734 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3735 +#else
3736 +#define PAX_DELTA_MMAP_LEN 15
3737 +#define PAX_DELTA_STACK_LEN 15
3738 +#endif
3739 +#endif
3740
3741 /*
3742 * Our registers are always unsigned longs, whether we're a 32 bit
3743 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3744 (0x7ff >> (PAGE_SHIFT - 12)) : \
3745 (0x3ffff >> (PAGE_SHIFT - 12)))
3746
3747 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3748 -#define arch_randomize_brk arch_randomize_brk
3749 -
3750 #endif /* __KERNEL__ */
3751
3752 /*
3753 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3754 index 8196e9c..d83a9f3 100644
3755 --- a/arch/powerpc/include/asm/exec.h
3756 +++ b/arch/powerpc/include/asm/exec.h
3757 @@ -4,6 +4,6 @@
3758 #ifndef _ASM_POWERPC_EXEC_H
3759 #define _ASM_POWERPC_EXEC_H
3760
3761 -extern unsigned long arch_align_stack(unsigned long sp);
3762 +#define arch_align_stack(x) ((x) & ~0xfUL)
3763
3764 #endif /* _ASM_POWERPC_EXEC_H */
3765 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3766 index 5acabbd..7ea14fa 100644
3767 --- a/arch/powerpc/include/asm/kmap_types.h
3768 +++ b/arch/powerpc/include/asm/kmap_types.h
3769 @@ -10,7 +10,7 @@
3770 * 2 of the License, or (at your option) any later version.
3771 */
3772
3773 -#define KM_TYPE_NR 16
3774 +#define KM_TYPE_NR 17
3775
3776 #endif /* __KERNEL__ */
3777 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
3778 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3779 index d4a7f64..451de1c 100644
3780 --- a/arch/powerpc/include/asm/mman.h
3781 +++ b/arch/powerpc/include/asm/mman.h
3782 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3783 }
3784 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3785
3786 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3787 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3788 {
3789 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3790 }
3791 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3792 index f072e97..b436dee 100644
3793 --- a/arch/powerpc/include/asm/page.h
3794 +++ b/arch/powerpc/include/asm/page.h
3795 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3796 * and needs to be executable. This means the whole heap ends
3797 * up being executable.
3798 */
3799 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3800 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3801 +#define VM_DATA_DEFAULT_FLAGS32 \
3802 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3803 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3804
3805 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3806 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3807 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3808 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3809 #endif
3810
3811 +#define ktla_ktva(addr) (addr)
3812 +#define ktva_ktla(addr) (addr)
3813 +
3814 /*
3815 * Use the top bit of the higher-level page table entries to indicate whether
3816 * the entries we point to contain hugepages. This works because we know that
3817 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3818 index fed85e6..da5c71b 100644
3819 --- a/arch/powerpc/include/asm/page_64.h
3820 +++ b/arch/powerpc/include/asm/page_64.h
3821 @@ -146,15 +146,18 @@ do { \
3822 * stack by default, so in the absence of a PT_GNU_STACK program header
3823 * we turn execute permission off.
3824 */
3825 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3826 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3827 +#define VM_STACK_DEFAULT_FLAGS32 \
3828 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3829 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3830
3831 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3832 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3833
3834 +#ifndef CONFIG_PAX_PAGEEXEC
3835 #define VM_STACK_DEFAULT_FLAGS \
3836 (is_32bit_task() ? \
3837 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3838 +#endif
3839
3840 #include <asm-generic/getorder.h>
3841
3842 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3843 index 292725c..f87ae14 100644
3844 --- a/arch/powerpc/include/asm/pgalloc-64.h
3845 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3846 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3847 #ifndef CONFIG_PPC_64K_PAGES
3848
3849 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3850 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3851
3852 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3853 {
3854 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3855 pud_set(pud, (unsigned long)pmd);
3856 }
3857
3858 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859 +{
3860 + pud_populate(mm, pud, pmd);
3861 +}
3862 +
3863 #define pmd_populate(mm, pmd, pte_page) \
3864 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3865 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3866 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3867 #else /* CONFIG_PPC_64K_PAGES */
3868
3869 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3870 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3871
3872 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3873 pte_t *pte)
3874 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3875 index 2e0e411..7899c68 100644
3876 --- a/arch/powerpc/include/asm/pgtable.h
3877 +++ b/arch/powerpc/include/asm/pgtable.h
3878 @@ -2,6 +2,7 @@
3879 #define _ASM_POWERPC_PGTABLE_H
3880 #ifdef __KERNEL__
3881
3882 +#include <linux/const.h>
3883 #ifndef __ASSEMBLY__
3884 #include <asm/processor.h> /* For TASK_SIZE */
3885 #include <asm/mmu.h>
3886 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3887 index 4aad413..85d86bf 100644
3888 --- a/arch/powerpc/include/asm/pte-hash32.h
3889 +++ b/arch/powerpc/include/asm/pte-hash32.h
3890 @@ -21,6 +21,7 @@
3891 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3892 #define _PAGE_USER 0x004 /* usermode access allowed */
3893 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3894 +#define _PAGE_EXEC _PAGE_GUARDED
3895 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3896 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3897 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3898 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3899 index 6386086..6982225 100644
3900 --- a/arch/powerpc/include/asm/reg.h
3901 +++ b/arch/powerpc/include/asm/reg.h
3902 @@ -212,6 +212,7 @@
3903 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3904 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3905 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3906 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3907 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3908 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3909 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3910 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3911 index faf9352..ab2ccec 100644
3912 --- a/arch/powerpc/include/asm/thread_info.h
3913 +++ b/arch/powerpc/include/asm/thread_info.h
3914 @@ -97,12 +97,14 @@ static inline struct thread_info *current_thread_info(void)
3915 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3916 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3917 #define TIF_SINGLESTEP 8 /* singlestepping active */
3918 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3919 #define TIF_SECCOMP 10 /* secure computing */
3920 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3921 #define TIF_NOERROR 12 /* Force successful syscall return */
3922 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3923 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3924 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3925 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3926 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3927
3928 /* as above, but as bit values */
3929 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3930 @@ -119,8 +121,10 @@ static inline struct thread_info *current_thread_info(void)
3931 #define _TIF_NOERROR (1<<TIF_NOERROR)
3932 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3933 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3934 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3935 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3936 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3937 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3938 + _TIF_GRSEC_SETXID)
3939
3940 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3941 _TIF_NOTIFY_RESUME)
3942 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3943 index 17bb40c..353c98b 100644
3944 --- a/arch/powerpc/include/asm/uaccess.h
3945 +++ b/arch/powerpc/include/asm/uaccess.h
3946 @@ -13,6 +13,8 @@
3947 #define VERIFY_READ 0
3948 #define VERIFY_WRITE 1
3949
3950 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3951 +
3952 /*
3953 * The fs value determines whether argument validity checking should be
3954 * performed or not. If get_fs() == USER_DS, checking is performed, with
3955 @@ -329,52 +331,6 @@ do { \
3956 extern unsigned long __copy_tofrom_user(void __user *to,
3957 const void __user *from, unsigned long size);
3958
3959 -#ifndef __powerpc64__
3960 -
3961 -static inline unsigned long copy_from_user(void *to,
3962 - const void __user *from, unsigned long n)
3963 -{
3964 - unsigned long over;
3965 -
3966 - if (access_ok(VERIFY_READ, from, n))
3967 - return __copy_tofrom_user((__force void __user *)to, from, n);
3968 - if ((unsigned long)from < TASK_SIZE) {
3969 - over = (unsigned long)from + n - TASK_SIZE;
3970 - return __copy_tofrom_user((__force void __user *)to, from,
3971 - n - over) + over;
3972 - }
3973 - return n;
3974 -}
3975 -
3976 -static inline unsigned long copy_to_user(void __user *to,
3977 - const void *from, unsigned long n)
3978 -{
3979 - unsigned long over;
3980 -
3981 - if (access_ok(VERIFY_WRITE, to, n))
3982 - return __copy_tofrom_user(to, (__force void __user *)from, n);
3983 - if ((unsigned long)to < TASK_SIZE) {
3984 - over = (unsigned long)to + n - TASK_SIZE;
3985 - return __copy_tofrom_user(to, (__force void __user *)from,
3986 - n - over) + over;
3987 - }
3988 - return n;
3989 -}
3990 -
3991 -#else /* __powerpc64__ */
3992 -
3993 -#define __copy_in_user(to, from, size) \
3994 - __copy_tofrom_user((to), (from), (size))
3995 -
3996 -extern unsigned long copy_from_user(void *to, const void __user *from,
3997 - unsigned long n);
3998 -extern unsigned long copy_to_user(void __user *to, const void *from,
3999 - unsigned long n);
4000 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4001 - unsigned long n);
4002 -
4003 -#endif /* __powerpc64__ */
4004 -
4005 static inline unsigned long __copy_from_user_inatomic(void *to,
4006 const void __user *from, unsigned long n)
4007 {
4008 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4009 if (ret == 0)
4010 return 0;
4011 }
4012 +
4013 + if (!__builtin_constant_p(n))
4014 + check_object_size(to, n, false);
4015 +
4016 return __copy_tofrom_user((__force void __user *)to, from, n);
4017 }
4018
4019 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4020 if (ret == 0)
4021 return 0;
4022 }
4023 +
4024 + if (!__builtin_constant_p(n))
4025 + check_object_size(from, n, true);
4026 +
4027 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4028 }
4029
4030 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4031 return __copy_to_user_inatomic(to, from, size);
4032 }
4033
4034 +#ifndef __powerpc64__
4035 +
4036 +static inline unsigned long __must_check copy_from_user(void *to,
4037 + const void __user *from, unsigned long n)
4038 +{
4039 + unsigned long over;
4040 +
4041 + if ((long)n < 0)
4042 + return n;
4043 +
4044 + if (access_ok(VERIFY_READ, from, n)) {
4045 + if (!__builtin_constant_p(n))
4046 + check_object_size(to, n, false);
4047 + return __copy_tofrom_user((__force void __user *)to, from, n);
4048 + }
4049 + if ((unsigned long)from < TASK_SIZE) {
4050 + over = (unsigned long)from + n - TASK_SIZE;
4051 + if (!__builtin_constant_p(n - over))
4052 + check_object_size(to, n - over, false);
4053 + return __copy_tofrom_user((__force void __user *)to, from,
4054 + n - over) + over;
4055 + }
4056 + return n;
4057 +}
4058 +
4059 +static inline unsigned long __must_check copy_to_user(void __user *to,
4060 + const void *from, unsigned long n)
4061 +{
4062 + unsigned long over;
4063 +
4064 + if ((long)n < 0)
4065 + return n;
4066 +
4067 + if (access_ok(VERIFY_WRITE, to, n)) {
4068 + if (!__builtin_constant_p(n))
4069 + check_object_size(from, n, true);
4070 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4071 + }
4072 + if ((unsigned long)to < TASK_SIZE) {
4073 + over = (unsigned long)to + n - TASK_SIZE;
4074 + if (!__builtin_constant_p(n))
4075 + check_object_size(from, n - over, true);
4076 + return __copy_tofrom_user(to, (__force void __user *)from,
4077 + n - over) + over;
4078 + }
4079 + return n;
4080 +}
4081 +
4082 +#else /* __powerpc64__ */
4083 +
4084 +#define __copy_in_user(to, from, size) \
4085 + __copy_tofrom_user((to), (from), (size))
4086 +
4087 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4088 +{
4089 + if ((long)n < 0 || n > INT_MAX)
4090 + return n;
4091 +
4092 + if (!__builtin_constant_p(n))
4093 + check_object_size(to, n, false);
4094 +
4095 + if (likely(access_ok(VERIFY_READ, from, n)))
4096 + n = __copy_from_user(to, from, n);
4097 + else
4098 + memset(to, 0, n);
4099 + return n;
4100 +}
4101 +
4102 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4103 +{
4104 + if ((long)n < 0 || n > INT_MAX)
4105 + return n;
4106 +
4107 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4108 + if (!__builtin_constant_p(n))
4109 + check_object_size(from, n, true);
4110 + n = __copy_to_user(to, from, n);
4111 + }
4112 + return n;
4113 +}
4114 +
4115 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4116 + unsigned long n);
4117 +
4118 +#endif /* __powerpc64__ */
4119 +
4120 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4121
4122 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4123 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4124 index 98be7f0..8ef62de 100644
4125 --- a/arch/powerpc/kernel/exceptions-64e.S
4126 +++ b/arch/powerpc/kernel/exceptions-64e.S
4127 @@ -661,6 +661,7 @@ storage_fault_common:
4128 std r14,_DAR(r1)
4129 std r15,_DSISR(r1)
4130 addi r3,r1,STACK_FRAME_OVERHEAD
4131 + bl .save_nvgprs
4132 mr r4,r14
4133 mr r5,r15
4134 ld r14,PACA_EXGEN+EX_R14(r13)
4135 @@ -669,8 +670,7 @@ storage_fault_common:
4136 cmpdi r3,0
4137 bne- 1f
4138 b .ret_from_except_lite
4139 -1: bl .save_nvgprs
4140 - mr r5,r3
4141 +1: mr r5,r3
4142 addi r3,r1,STACK_FRAME_OVERHEAD
4143 ld r4,_DAR(r1)
4144 bl .bad_page_fault
4145 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4146 index 39aa97d..dc916ee 100644
4147 --- a/arch/powerpc/kernel/exceptions-64s.S
4148 +++ b/arch/powerpc/kernel/exceptions-64s.S
4149 @@ -890,10 +890,10 @@ handle_page_fault:
4150 11: ld r4,_DAR(r1)
4151 ld r5,_DSISR(r1)
4152 addi r3,r1,STACK_FRAME_OVERHEAD
4153 + bl .save_nvgprs
4154 bl .do_page_fault
4155 cmpdi r3,0
4156 beq+ 12f
4157 - bl .save_nvgprs
4158 mr r5,r3
4159 addi r3,r1,STACK_FRAME_OVERHEAD
4160 lwz r4,_DAR(r1)
4161 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4162 index 2e3200c..72095ce 100644
4163 --- a/arch/powerpc/kernel/module_32.c
4164 +++ b/arch/powerpc/kernel/module_32.c
4165 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4166 me->arch.core_plt_section = i;
4167 }
4168 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4169 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4170 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4171 return -ENOEXEC;
4172 }
4173
4174 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4175
4176 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4177 /* Init, or core PLT? */
4178 - if (location >= mod->module_core
4179 - && location < mod->module_core + mod->core_size)
4180 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4181 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4182 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4183 - else
4184 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4185 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4186 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4187 + else {
4188 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4189 + return ~0UL;
4190 + }
4191
4192 /* Find this entry, or if that fails, the next avail. entry */
4193 while (entry->jump[0]) {
4194 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4195 index 1a1f2dd..f4d1bb4 100644
4196 --- a/arch/powerpc/kernel/process.c
4197 +++ b/arch/powerpc/kernel/process.c
4198 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4199 * Lookup NIP late so we have the best change of getting the
4200 * above info out without failing
4201 */
4202 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4203 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4204 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4205 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4206 #endif
4207 show_stack(current, (unsigned long *) regs->gpr[1]);
4208 if (!user_mode(regs))
4209 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4210 newsp = stack[0];
4211 ip = stack[STACK_FRAME_LR_SAVE];
4212 if (!firstframe || ip != lr) {
4213 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4214 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4215 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4216 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4217 - printk(" (%pS)",
4218 + printk(" (%pA)",
4219 (void *)current->ret_stack[curr_frame].ret);
4220 curr_frame--;
4221 }
4222 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4223 struct pt_regs *regs = (struct pt_regs *)
4224 (sp + STACK_FRAME_OVERHEAD);
4225 lr = regs->link;
4226 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4227 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4228 regs->trap, (void *)regs->nip, (void *)lr);
4229 firstframe = 1;
4230 }
4231 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4232 mtspr(SPRN_CTRLT, ctrl);
4233 }
4234 #endif /* CONFIG_PPC64 */
4235 -
4236 -unsigned long arch_align_stack(unsigned long sp)
4237 -{
4238 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4239 - sp -= get_random_int() & ~PAGE_MASK;
4240 - return sp & ~0xf;
4241 -}
4242 -
4243 -static inline unsigned long brk_rnd(void)
4244 -{
4245 - unsigned long rnd = 0;
4246 -
4247 - /* 8MB for 32bit, 1GB for 64bit */
4248 - if (is_32bit_task())
4249 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4250 - else
4251 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4252 -
4253 - return rnd << PAGE_SHIFT;
4254 -}
4255 -
4256 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4257 -{
4258 - unsigned long base = mm->brk;
4259 - unsigned long ret;
4260 -
4261 -#ifdef CONFIG_PPC_STD_MMU_64
4262 - /*
4263 - * If we are using 1TB segments and we are allowed to randomise
4264 - * the heap, we can put it above 1TB so it is backed by a 1TB
4265 - * segment. Otherwise the heap will be in the bottom 1TB
4266 - * which always uses 256MB segments and this may result in a
4267 - * performance penalty.
4268 - */
4269 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4270 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4271 -#endif
4272 -
4273 - ret = PAGE_ALIGN(base + brk_rnd());
4274 -
4275 - if (ret < mm->brk)
4276 - return mm->brk;
4277 -
4278 - return ret;
4279 -}
4280 -
4281 -unsigned long randomize_et_dyn(unsigned long base)
4282 -{
4283 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4284 -
4285 - if (ret < base)
4286 - return base;
4287 -
4288 - return ret;
4289 -}
4290 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4291 index c10fc28..c4ef063 100644
4292 --- a/arch/powerpc/kernel/ptrace.c
4293 +++ b/arch/powerpc/kernel/ptrace.c
4294 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4295 return ret;
4296 }
4297
4298 +#ifdef CONFIG_GRKERNSEC_SETXID
4299 +extern void gr_delayed_cred_worker(void);
4300 +#endif
4301 +
4302 /*
4303 * We must return the syscall number to actually look up in the table.
4304 * This can be -1L to skip running any syscall at all.
4305 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4306
4307 secure_computing_strict(regs->gpr[0]);
4308
4309 +#ifdef CONFIG_GRKERNSEC_SETXID
4310 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4311 + gr_delayed_cred_worker();
4312 +#endif
4313 +
4314 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4315 tracehook_report_syscall_entry(regs))
4316 /*
4317 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4318 {
4319 int step;
4320
4321 +#ifdef CONFIG_GRKERNSEC_SETXID
4322 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4323 + gr_delayed_cred_worker();
4324 +#endif
4325 +
4326 audit_syscall_exit(regs);
4327
4328 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4329 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4330 index 8b4c049..dcd6ef3 100644
4331 --- a/arch/powerpc/kernel/signal_32.c
4332 +++ b/arch/powerpc/kernel/signal_32.c
4333 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4334 /* Save user registers on the stack */
4335 frame = &rt_sf->uc.uc_mcontext;
4336 addr = frame;
4337 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4338 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4339 if (save_user_regs(regs, frame, 0, 1))
4340 goto badframe;
4341 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4342 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4343 index d183f87..1867f1a 100644
4344 --- a/arch/powerpc/kernel/signal_64.c
4345 +++ b/arch/powerpc/kernel/signal_64.c
4346 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4347 current->thread.fpscr.val = 0;
4348
4349 /* Set up to return from userspace. */
4350 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4351 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4352 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4353 } else {
4354 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4355 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4356 index ae0843f..f16372c 100644
4357 --- a/arch/powerpc/kernel/traps.c
4358 +++ b/arch/powerpc/kernel/traps.c
4359 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4360 return flags;
4361 }
4362
4363 +extern void gr_handle_kernel_exploit(void);
4364 +
4365 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4366 int signr)
4367 {
4368 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4369 panic("Fatal exception in interrupt");
4370 if (panic_on_oops)
4371 panic("Fatal exception");
4372 +
4373 + gr_handle_kernel_exploit();
4374 +
4375 do_exit(signr);
4376 }
4377
4378 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4379 index b67db22..38825d2 100644
4380 --- a/arch/powerpc/kernel/vdso.c
4381 +++ b/arch/powerpc/kernel/vdso.c
4382 @@ -34,6 +34,7 @@
4383 #include <asm/firmware.h>
4384 #include <asm/vdso.h>
4385 #include <asm/vdso_datapage.h>
4386 +#include <asm/mman.h>
4387
4388 #include "setup.h"
4389
4390 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4391 vdso_base = VDSO32_MBASE;
4392 #endif
4393
4394 - current->mm->context.vdso_base = 0;
4395 + current->mm->context.vdso_base = ~0UL;
4396
4397 /* vDSO has a problem and was disabled, just don't "enable" it for the
4398 * process
4399 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4400 vdso_base = get_unmapped_area(NULL, vdso_base,
4401 (vdso_pages << PAGE_SHIFT) +
4402 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4403 - 0, 0);
4404 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4405 if (IS_ERR_VALUE(vdso_base)) {
4406 rc = vdso_base;
4407 goto fail_mmapsem;
4408 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4409 index 5eea6f3..5d10396 100644
4410 --- a/arch/powerpc/lib/usercopy_64.c
4411 +++ b/arch/powerpc/lib/usercopy_64.c
4412 @@ -9,22 +9,6 @@
4413 #include <linux/module.h>
4414 #include <asm/uaccess.h>
4415
4416 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4417 -{
4418 - if (likely(access_ok(VERIFY_READ, from, n)))
4419 - n = __copy_from_user(to, from, n);
4420 - else
4421 - memset(to, 0, n);
4422 - return n;
4423 -}
4424 -
4425 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4426 -{
4427 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4428 - n = __copy_to_user(to, from, n);
4429 - return n;
4430 -}
4431 -
4432 unsigned long copy_in_user(void __user *to, const void __user *from,
4433 unsigned long n)
4434 {
4435 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4436 return n;
4437 }
4438
4439 -EXPORT_SYMBOL(copy_from_user);
4440 -EXPORT_SYMBOL(copy_to_user);
4441 EXPORT_SYMBOL(copy_in_user);
4442
4443 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4444 index 08ffcf5..a0ab912 100644
4445 --- a/arch/powerpc/mm/fault.c
4446 +++ b/arch/powerpc/mm/fault.c
4447 @@ -32,6 +32,10 @@
4448 #include <linux/perf_event.h>
4449 #include <linux/magic.h>
4450 #include <linux/ratelimit.h>
4451 +#include <linux/slab.h>
4452 +#include <linux/pagemap.h>
4453 +#include <linux/compiler.h>
4454 +#include <linux/unistd.h>
4455
4456 #include <asm/firmware.h>
4457 #include <asm/page.h>
4458 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4459 }
4460 #endif
4461
4462 +#ifdef CONFIG_PAX_PAGEEXEC
4463 +/*
4464 + * PaX: decide what to do with offenders (regs->nip = fault address)
4465 + *
4466 + * returns 1 when task should be killed
4467 + */
4468 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4469 +{
4470 + return 1;
4471 +}
4472 +
4473 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4474 +{
4475 + unsigned long i;
4476 +
4477 + printk(KERN_ERR "PAX: bytes at PC: ");
4478 + for (i = 0; i < 5; i++) {
4479 + unsigned int c;
4480 + if (get_user(c, (unsigned int __user *)pc+i))
4481 + printk(KERN_CONT "???????? ");
4482 + else
4483 + printk(KERN_CONT "%08x ", c);
4484 + }
4485 + printk("\n");
4486 +}
4487 +#endif
4488 +
4489 /*
4490 * Check whether the instruction at regs->nip is a store using
4491 * an update addressing form which will update r1.
4492 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4493 * indicate errors in DSISR but can validly be set in SRR1.
4494 */
4495 if (trap == 0x400)
4496 - error_code &= 0x48200000;
4497 + error_code &= 0x58200000;
4498 else
4499 is_write = error_code & DSISR_ISSTORE;
4500 #else
4501 @@ -366,7 +397,7 @@ good_area:
4502 * "undefined". Of those that can be set, this is the only
4503 * one which seems bad.
4504 */
4505 - if (error_code & 0x10000000)
4506 + if (error_code & DSISR_GUARDED)
4507 /* Guarded storage error. */
4508 goto bad_area;
4509 #endif /* CONFIG_8xx */
4510 @@ -381,7 +412,7 @@ good_area:
4511 * processors use the same I/D cache coherency mechanism
4512 * as embedded.
4513 */
4514 - if (error_code & DSISR_PROTFAULT)
4515 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4516 goto bad_area;
4517 #endif /* CONFIG_PPC_STD_MMU */
4518
4519 @@ -463,6 +494,23 @@ bad_area:
4520 bad_area_nosemaphore:
4521 /* User mode accesses cause a SIGSEGV */
4522 if (user_mode(regs)) {
4523 +
4524 +#ifdef CONFIG_PAX_PAGEEXEC
4525 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4526 +#ifdef CONFIG_PPC_STD_MMU
4527 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4528 +#else
4529 + if (is_exec && regs->nip == address) {
4530 +#endif
4531 + switch (pax_handle_fetch_fault(regs)) {
4532 + }
4533 +
4534 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4535 + do_group_exit(SIGKILL);
4536 + }
4537 + }
4538 +#endif
4539 +
4540 _exception(SIGSEGV, regs, code, address);
4541 return 0;
4542 }
4543 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4544 index 67a42ed..1c7210c 100644
4545 --- a/arch/powerpc/mm/mmap_64.c
4546 +++ b/arch/powerpc/mm/mmap_64.c
4547 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4548 */
4549 if (mmap_is_legacy()) {
4550 mm->mmap_base = TASK_UNMAPPED_BASE;
4551 +
4552 +#ifdef CONFIG_PAX_RANDMMAP
4553 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4554 + mm->mmap_base += mm->delta_mmap;
4555 +#endif
4556 +
4557 mm->get_unmapped_area = arch_get_unmapped_area;
4558 mm->unmap_area = arch_unmap_area;
4559 } else {
4560 mm->mmap_base = mmap_base();
4561 +
4562 +#ifdef CONFIG_PAX_RANDMMAP
4563 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4564 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4565 +#endif
4566 +
4567 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4568 mm->unmap_area = arch_unmap_area_topdown;
4569 }
4570 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4571 index 73709f7..6b90313 100644
4572 --- a/arch/powerpc/mm/slice.c
4573 +++ b/arch/powerpc/mm/slice.c
4574 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4575 if ((mm->task_size - len) < addr)
4576 return 0;
4577 vma = find_vma(mm, addr);
4578 - return (!vma || (addr + len) <= vma->vm_start);
4579 + return check_heap_stack_gap(vma, addr, len);
4580 }
4581
4582 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4583 @@ -256,7 +256,7 @@ full_search:
4584 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4585 continue;
4586 }
4587 - if (!vma || addr + len <= vma->vm_start) {
4588 + if (check_heap_stack_gap(vma, addr, len)) {
4589 /*
4590 * Remember the place where we stopped the search:
4591 */
4592 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4593 }
4594 }
4595
4596 - addr = mm->mmap_base;
4597 - while (addr > len) {
4598 + if (mm->mmap_base < len)
4599 + addr = -ENOMEM;
4600 + else
4601 + addr = mm->mmap_base - len;
4602 +
4603 + while (!IS_ERR_VALUE(addr)) {
4604 /* Go down by chunk size */
4605 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4606 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4607
4608 /* Check for hit with different page size */
4609 mask = slice_range_to_mask(addr, len);
4610 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4611 * return with success:
4612 */
4613 vma = find_vma(mm, addr);
4614 - if (!vma || (addr + len) <= vma->vm_start) {
4615 + if (check_heap_stack_gap(vma, addr, len)) {
4616 /* remember the address as a hint for next time */
4617 if (use_cache)
4618 mm->free_area_cache = addr;
4619 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4620 mm->cached_hole_size = vma->vm_start - addr;
4621
4622 /* try just below the current vma->vm_start */
4623 - addr = vma->vm_start;
4624 + addr = skip_heap_stack_gap(vma, len);
4625 }
4626
4627 /*
4628 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4629 if (fixed && addr > (mm->task_size - len))
4630 return -EINVAL;
4631
4632 +#ifdef CONFIG_PAX_RANDMMAP
4633 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4634 + addr = 0;
4635 +#endif
4636 +
4637 /* If hint, make sure it matches our alignment restrictions */
4638 if (!fixed && addr) {
4639 addr = _ALIGN_UP(addr, 1ul << pshift);
4640 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4641 index c797832..ce575c8 100644
4642 --- a/arch/s390/include/asm/atomic.h
4643 +++ b/arch/s390/include/asm/atomic.h
4644 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4645 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4646 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4647
4648 +#define atomic64_read_unchecked(v) atomic64_read(v)
4649 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4650 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4651 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4652 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4653 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4654 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4655 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4656 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4657 +
4658 #define smp_mb__before_atomic_dec() smp_mb()
4659 #define smp_mb__after_atomic_dec() smp_mb()
4660 #define smp_mb__before_atomic_inc() smp_mb()
4661 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4662 index 4d7ccac..d03d0ad 100644
4663 --- a/arch/s390/include/asm/cache.h
4664 +++ b/arch/s390/include/asm/cache.h
4665 @@ -9,8 +9,10 @@
4666 #ifndef __ARCH_S390_CACHE_H
4667 #define __ARCH_S390_CACHE_H
4668
4669 -#define L1_CACHE_BYTES 256
4670 +#include <linux/const.h>
4671 +
4672 #define L1_CACHE_SHIFT 8
4673 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4674 #define NET_SKB_PAD 32
4675
4676 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4677 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4678 index 9b94a16..63d4034 100644
4679 --- a/arch/s390/include/asm/elf.h
4680 +++ b/arch/s390/include/asm/elf.h
4681 @@ -159,8 +159,14 @@ extern unsigned int vdso_enabled;
4682 the loader. We need to make sure that it is out of the way of the program
4683 that it will "exec", and that there is sufficient room for the brk. */
4684
4685 -extern unsigned long randomize_et_dyn(unsigned long base);
4686 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4687 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4688 +
4689 +#ifdef CONFIG_PAX_ASLR
4690 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4691 +
4692 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4693 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4694 +#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. */
4698 @@ -209,7 +215,4 @@ struct linux_binprm;
4699 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4700 int arch_setup_additional_pages(struct linux_binprm *, int);
4701
4702 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4703 -#define arch_randomize_brk arch_randomize_brk
4704 -
4705 #endif
4706 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4707 index c4a93d6..4d2a9b4 100644
4708 --- a/arch/s390/include/asm/exec.h
4709 +++ b/arch/s390/include/asm/exec.h
4710 @@ -7,6 +7,6 @@
4711 #ifndef __ASM_EXEC_H
4712 #define __ASM_EXEC_H
4713
4714 -extern unsigned long arch_align_stack(unsigned long sp);
4715 +#define arch_align_stack(x) ((x) & ~0xfUL)
4716
4717 #endif /* __ASM_EXEC_H */
4718 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4719 index a8ab18b..75ddbf0 100644
4720 --- a/arch/s390/include/asm/uaccess.h
4721 +++ b/arch/s390/include/asm/uaccess.h
4722 @@ -239,6 +239,10 @@ static inline unsigned long __must_check
4723 copy_to_user(void __user *to, const void *from, unsigned long n)
4724 {
4725 might_fault();
4726 +
4727 + if ((long)n < 0)
4728 + return n;
4729 +
4730 if (access_ok(VERIFY_WRITE, to, n))
4731 n = __copy_to_user(to, from, n);
4732 return n;
4733 @@ -264,6 +268,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4734 static inline unsigned long __must_check
4735 __copy_from_user(void *to, const void __user *from, unsigned long n)
4736 {
4737 + if ((long)n < 0)
4738 + return n;
4739 +
4740 if (__builtin_constant_p(n) && (n <= 256))
4741 return uaccess.copy_from_user_small(n, from, to);
4742 else
4743 @@ -295,10 +302,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4744 static inline unsigned long __must_check
4745 copy_from_user(void *to, const void __user *from, unsigned long n)
4746 {
4747 - unsigned int sz = __compiletime_object_size(to);
4748 + size_t sz = __compiletime_object_size(to);
4749
4750 might_fault();
4751 - if (unlikely(sz != -1 && sz < n)) {
4752 +
4753 + if ((long)n < 0)
4754 + return n;
4755 +
4756 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4757 copy_from_user_overflow();
4758 return n;
4759 }
4760 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4761 index 46412b1..e32874f 100644
4762 --- a/arch/s390/kernel/module.c
4763 +++ b/arch/s390/kernel/module.c
4764 @@ -160,11 +160,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4765
4766 /* Increase core size by size of got & plt and set start
4767 offsets for got and plt. */
4768 - me->core_size = ALIGN(me->core_size, 4);
4769 - me->arch.got_offset = me->core_size;
4770 - me->core_size += me->arch.got_size;
4771 - me->arch.plt_offset = me->core_size;
4772 - me->core_size += me->arch.plt_size;
4773 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4774 + me->arch.got_offset = me->core_size_rw;
4775 + me->core_size_rw += me->arch.got_size;
4776 + me->arch.plt_offset = me->core_size_rx;
4777 + me->core_size_rx += me->arch.plt_size;
4778 return 0;
4779 }
4780
4781 @@ -241,7 +241,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4782 if (info->got_initialized == 0) {
4783 Elf_Addr *gotent;
4784
4785 - gotent = me->module_core + me->arch.got_offset +
4786 + gotent = me->module_core_rw + me->arch.got_offset +
4787 info->got_offset;
4788 *gotent = val;
4789 info->got_initialized = 1;
4790 @@ -265,7 +265,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4791 else if (r_type == R_390_GOTENT ||
4792 r_type == R_390_GOTPLTENT)
4793 *(unsigned int *) loc =
4794 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4795 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4796 else if (r_type == R_390_GOT64 ||
4797 r_type == R_390_GOTPLT64)
4798 *(unsigned long *) loc = val;
4799 @@ -279,7 +279,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4800 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4801 if (info->plt_initialized == 0) {
4802 unsigned int *ip;
4803 - ip = me->module_core + me->arch.plt_offset +
4804 + ip = me->module_core_rx + me->arch.plt_offset +
4805 info->plt_offset;
4806 #ifndef CONFIG_64BIT
4807 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4808 @@ -304,7 +304,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4809 val - loc + 0xffffUL < 0x1ffffeUL) ||
4810 (r_type == R_390_PLT32DBL &&
4811 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4812 - val = (Elf_Addr) me->module_core +
4813 + val = (Elf_Addr) me->module_core_rx +
4814 me->arch.plt_offset +
4815 info->plt_offset;
4816 val += rela->r_addend - loc;
4817 @@ -326,7 +326,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4818 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4819 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4820 val = val + rela->r_addend -
4821 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4822 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4823 if (r_type == R_390_GOTOFF16)
4824 *(unsigned short *) loc = val;
4825 else if (r_type == R_390_GOTOFF32)
4826 @@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4827 break;
4828 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4829 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4830 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4831 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4832 rela->r_addend - loc;
4833 if (r_type == R_390_GOTPC)
4834 *(unsigned int *) loc = val;
4835 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4836 index 7331753..dd71de4 100644
4837 --- a/arch/s390/kernel/process.c
4838 +++ b/arch/s390/kernel/process.c
4839 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4840 }
4841 return 0;
4842 }
4843 -
4844 -unsigned long arch_align_stack(unsigned long sp)
4845 -{
4846 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4847 - sp -= get_random_int() & ~PAGE_MASK;
4848 - return sp & ~0xf;
4849 -}
4850 -
4851 -static inline unsigned long brk_rnd(void)
4852 -{
4853 - /* 8MB for 32bit, 1GB for 64bit */
4854 - if (is_32bit_task())
4855 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4856 - else
4857 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4858 -}
4859 -
4860 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4861 -{
4862 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4863 -
4864 - if (ret < mm->brk)
4865 - return mm->brk;
4866 - return ret;
4867 -}
4868 -
4869 -unsigned long randomize_et_dyn(unsigned long base)
4870 -{
4871 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4872 -
4873 - if (!(current->flags & PF_RANDOMIZE))
4874 - return base;
4875 - if (ret < base)
4876 - return base;
4877 - return ret;
4878 -}
4879 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4880 index c59a5ef..3fae59c 100644
4881 --- a/arch/s390/mm/mmap.c
4882 +++ b/arch/s390/mm/mmap.c
4883 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4884 */
4885 if (mmap_is_legacy()) {
4886 mm->mmap_base = TASK_UNMAPPED_BASE;
4887 +
4888 +#ifdef CONFIG_PAX_RANDMMAP
4889 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4890 + mm->mmap_base += mm->delta_mmap;
4891 +#endif
4892 +
4893 mm->get_unmapped_area = arch_get_unmapped_area;
4894 mm->unmap_area = arch_unmap_area;
4895 } else {
4896 mm->mmap_base = mmap_base();
4897 +
4898 +#ifdef CONFIG_PAX_RANDMMAP
4899 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4900 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4901 +#endif
4902 +
4903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4904 mm->unmap_area = arch_unmap_area_topdown;
4905 }
4906 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4907 */
4908 if (mmap_is_legacy()) {
4909 mm->mmap_base = TASK_UNMAPPED_BASE;
4910 +
4911 +#ifdef CONFIG_PAX_RANDMMAP
4912 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4913 + mm->mmap_base += mm->delta_mmap;
4914 +#endif
4915 +
4916 mm->get_unmapped_area = s390_get_unmapped_area;
4917 mm->unmap_area = arch_unmap_area;
4918 } else {
4919 mm->mmap_base = mmap_base();
4920 +
4921 +#ifdef CONFIG_PAX_RANDMMAP
4922 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4923 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4924 +#endif
4925 +
4926 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4927 mm->unmap_area = arch_unmap_area_topdown;
4928 }
4929 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4930 index ae3d59f..f65f075 100644
4931 --- a/arch/score/include/asm/cache.h
4932 +++ b/arch/score/include/asm/cache.h
4933 @@ -1,7 +1,9 @@
4934 #ifndef _ASM_SCORE_CACHE_H
4935 #define _ASM_SCORE_CACHE_H
4936
4937 +#include <linux/const.h>
4938 +
4939 #define L1_CACHE_SHIFT 4
4940 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4941 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4942
4943 #endif /* _ASM_SCORE_CACHE_H */
4944 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
4945 index f9f3cd5..58ff438 100644
4946 --- a/arch/score/include/asm/exec.h
4947 +++ b/arch/score/include/asm/exec.h
4948 @@ -1,6 +1,6 @@
4949 #ifndef _ASM_SCORE_EXEC_H
4950 #define _ASM_SCORE_EXEC_H
4951
4952 -extern unsigned long arch_align_stack(unsigned long sp);
4953 +#define arch_align_stack(x) (x)
4954
4955 #endif /* _ASM_SCORE_EXEC_H */
4956 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
4957 index 637970c..0b6556b 100644
4958 --- a/arch/score/kernel/process.c
4959 +++ b/arch/score/kernel/process.c
4960 @@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
4961
4962 return task_pt_regs(task)->cp0_epc;
4963 }
4964 -
4965 -unsigned long arch_align_stack(unsigned long sp)
4966 -{
4967 - return sp;
4968 -}
4969 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
4970 index ef9e555..331bd29 100644
4971 --- a/arch/sh/include/asm/cache.h
4972 +++ b/arch/sh/include/asm/cache.h
4973 @@ -9,10 +9,11 @@
4974 #define __ASM_SH_CACHE_H
4975 #ifdef __KERNEL__
4976
4977 +#include <linux/const.h>
4978 #include <linux/init.h>
4979 #include <cpu/cache.h>
4980
4981 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4982 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4983
4984 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4985
4986 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
4987 index afeb710..d1d1289 100644
4988 --- a/arch/sh/mm/mmap.c
4989 +++ b/arch/sh/mm/mmap.c
4990 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4991 addr = PAGE_ALIGN(addr);
4992
4993 vma = find_vma(mm, addr);
4994 - if (TASK_SIZE - len >= addr &&
4995 - (!vma || addr + len <= vma->vm_start))
4996 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
4997 return addr;
4998 }
4999
5000 @@ -106,7 +105,7 @@ full_search:
5001 }
5002 return -ENOMEM;
5003 }
5004 - if (likely(!vma || addr + len <= vma->vm_start)) {
5005 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5006 /*
5007 * Remember the place where we stopped the search:
5008 */
5009 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5010 addr = PAGE_ALIGN(addr);
5011
5012 vma = find_vma(mm, addr);
5013 - if (TASK_SIZE - len >= addr &&
5014 - (!vma || addr + len <= vma->vm_start))
5015 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5016 return addr;
5017 }
5018
5019 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5020 /* make sure it can fit in the remaining address space */
5021 if (likely(addr > len)) {
5022 vma = find_vma(mm, addr-len);
5023 - if (!vma || addr <= vma->vm_start) {
5024 + if (check_heap_stack_gap(vma, addr - len, len)) {
5025 /* remember the address as a hint for next time */
5026 return (mm->free_area_cache = addr-len);
5027 }
5028 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5029 if (unlikely(mm->mmap_base < len))
5030 goto bottomup;
5031
5032 - addr = mm->mmap_base-len;
5033 - if (do_colour_align)
5034 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5035 + addr = mm->mmap_base - len;
5036
5037 do {
5038 + if (do_colour_align)
5039 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5040 /*
5041 * Lookup failure means no vma is above this address,
5042 * else if new region fits below vma->vm_start,
5043 * return with success:
5044 */
5045 vma = find_vma(mm, addr);
5046 - if (likely(!vma || addr+len <= vma->vm_start)) {
5047 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5048 /* remember the address as a hint for next time */
5049 return (mm->free_area_cache = addr);
5050 }
5051 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5052 mm->cached_hole_size = vma->vm_start - addr;
5053
5054 /* try just below the current vma->vm_start */
5055 - addr = vma->vm_start-len;
5056 - if (do_colour_align)
5057 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5058 - } while (likely(len < vma->vm_start));
5059 + addr = skip_heap_stack_gap(vma, len);
5060 + } while (!IS_ERR_VALUE(addr));
5061
5062 bottomup:
5063 /*
5064 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5065 index ce35a1c..2e7b8f9 100644
5066 --- a/arch/sparc/include/asm/atomic_64.h
5067 +++ b/arch/sparc/include/asm/atomic_64.h
5068 @@ -14,18 +14,40 @@
5069 #define ATOMIC64_INIT(i) { (i) }
5070
5071 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5072 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5073 +{
5074 + return v->counter;
5075 +}
5076 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5077 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5078 +{
5079 + return v->counter;
5080 +}
5081
5082 #define atomic_set(v, i) (((v)->counter) = i)
5083 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5084 +{
5085 + v->counter = i;
5086 +}
5087 #define atomic64_set(v, i) (((v)->counter) = i)
5088 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5089 +{
5090 + v->counter = i;
5091 +}
5092
5093 extern void atomic_add(int, atomic_t *);
5094 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5095 extern void atomic64_add(long, atomic64_t *);
5096 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5097 extern void atomic_sub(int, atomic_t *);
5098 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5099 extern void atomic64_sub(long, atomic64_t *);
5100 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5101
5102 extern int atomic_add_ret(int, atomic_t *);
5103 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5104 extern long atomic64_add_ret(long, atomic64_t *);
5105 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5106 extern int atomic_sub_ret(int, atomic_t *);
5107 extern long atomic64_sub_ret(long, atomic64_t *);
5108
5109 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5110 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5111
5112 #define atomic_inc_return(v) atomic_add_ret(1, v)
5113 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5114 +{
5115 + return atomic_add_ret_unchecked(1, v);
5116 +}
5117 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5118 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5119 +{
5120 + return atomic64_add_ret_unchecked(1, v);
5121 +}
5122
5123 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5124 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5125
5126 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5127 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5128 +{
5129 + return atomic_add_ret_unchecked(i, v);
5130 +}
5131 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5132 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5133 +{
5134 + return atomic64_add_ret_unchecked(i, v);
5135 +}
5136
5137 /*
5138 * atomic_inc_and_test - increment and test
5139 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5140 * other cases.
5141 */
5142 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5143 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5144 +{
5145 + return atomic_inc_return_unchecked(v) == 0;
5146 +}
5147 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5148
5149 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5150 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5151 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5152
5153 #define atomic_inc(v) atomic_add(1, v)
5154 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5155 +{
5156 + atomic_add_unchecked(1, v);
5157 +}
5158 #define atomic64_inc(v) atomic64_add(1, v)
5159 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5160 +{
5161 + atomic64_add_unchecked(1, v);
5162 +}
5163
5164 #define atomic_dec(v) atomic_sub(1, v)
5165 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5166 +{
5167 + atomic_sub_unchecked(1, v);
5168 +}
5169 #define atomic64_dec(v) atomic64_sub(1, v)
5170 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5171 +{
5172 + atomic64_sub_unchecked(1, v);
5173 +}
5174
5175 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5176 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5177
5178 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5179 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5180 +{
5181 + return cmpxchg(&v->counter, old, new);
5182 +}
5183 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5184 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5185 +{
5186 + return xchg(&v->counter, new);
5187 +}
5188
5189 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5190 {
5191 - int c, old;
5192 + int c, old, new;
5193 c = atomic_read(v);
5194 for (;;) {
5195 - if (unlikely(c == (u)))
5196 + if (unlikely(c == u))
5197 break;
5198 - old = atomic_cmpxchg((v), c, c + (a));
5199 +
5200 + asm volatile("addcc %2, %0, %0\n"
5201 +
5202 +#ifdef CONFIG_PAX_REFCOUNT
5203 + "tvs %%icc, 6\n"
5204 +#endif
5205 +
5206 + : "=r" (new)
5207 + : "0" (c), "ir" (a)
5208 + : "cc");
5209 +
5210 + old = atomic_cmpxchg(v, c, new);
5211 if (likely(old == c))
5212 break;
5213 c = old;
5214 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5215 #define atomic64_cmpxchg(v, o, n) \
5216 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5217 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5218 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5219 +{
5220 + return xchg(&v->counter, new);
5221 +}
5222
5223 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5224 {
5225 - long c, old;
5226 + long c, old, new;
5227 c = atomic64_read(v);
5228 for (;;) {
5229 - if (unlikely(c == (u)))
5230 + if (unlikely(c == u))
5231 break;
5232 - old = atomic64_cmpxchg((v), c, c + (a));
5233 +
5234 + asm volatile("addcc %2, %0, %0\n"
5235 +
5236 +#ifdef CONFIG_PAX_REFCOUNT
5237 + "tvs %%xcc, 6\n"
5238 +#endif
5239 +
5240 + : "=r" (new)
5241 + : "0" (c), "ir" (a)
5242 + : "cc");
5243 +
5244 + old = atomic64_cmpxchg(v, c, new);
5245 if (likely(old == c))
5246 break;
5247 c = old;
5248 }
5249 - return c != (u);
5250 + return c != u;
5251 }
5252
5253 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5254 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5255 index 5bb6991..5c2132e 100644
5256 --- a/arch/sparc/include/asm/cache.h
5257 +++ b/arch/sparc/include/asm/cache.h
5258 @@ -7,10 +7,12 @@
5259 #ifndef _SPARC_CACHE_H
5260 #define _SPARC_CACHE_H
5261
5262 +#include <linux/const.h>
5263 +
5264 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5265
5266 #define L1_CACHE_SHIFT 5
5267 -#define L1_CACHE_BYTES 32
5268 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5269
5270 #ifdef CONFIG_SPARC32
5271 #define SMP_CACHE_BYTES_SHIFT 5
5272 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5273 index 2d4d755..81b6662 100644
5274 --- a/arch/sparc/include/asm/elf_32.h
5275 +++ b/arch/sparc/include/asm/elf_32.h
5276 @@ -114,6 +114,13 @@ typedef struct {
5277
5278 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5279
5280 +#ifdef CONFIG_PAX_ASLR
5281 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5282 +
5283 +#define PAX_DELTA_MMAP_LEN 16
5284 +#define PAX_DELTA_STACK_LEN 16
5285 +#endif
5286 +
5287 /* This yields a mask that user programs can use to figure out what
5288 instruction set this cpu supports. This can NOT be done in userspace
5289 on Sparc. */
5290 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5291 index 7df8b7f..4946269 100644
5292 --- a/arch/sparc/include/asm/elf_64.h
5293 +++ b/arch/sparc/include/asm/elf_64.h
5294 @@ -180,6 +180,13 @@ typedef struct {
5295 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5296 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5297
5298 +#ifdef CONFIG_PAX_ASLR
5299 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5300 +
5301 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5302 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5303 +#endif
5304 +
5305 extern unsigned long sparc64_elf_hwcap;
5306 #define ELF_HWCAP sparc64_elf_hwcap
5307
5308 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5309 index 9b1c36d..209298b 100644
5310 --- a/arch/sparc/include/asm/pgalloc_32.h
5311 +++ b/arch/sparc/include/asm/pgalloc_32.h
5312 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5313 }
5314
5315 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5316 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5317
5318 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5319 unsigned long address)
5320 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5321 index 40b2d7a..22a665b 100644
5322 --- a/arch/sparc/include/asm/pgalloc_64.h
5323 +++ b/arch/sparc/include/asm/pgalloc_64.h
5324 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5325 }
5326
5327 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5328 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5329
5330 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5331 {
5332 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5333 index 6fc1348..390c50a 100644
5334 --- a/arch/sparc/include/asm/pgtable_32.h
5335 +++ b/arch/sparc/include/asm/pgtable_32.h
5336 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5337 #define PAGE_SHARED SRMMU_PAGE_SHARED
5338 #define PAGE_COPY SRMMU_PAGE_COPY
5339 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5340 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5341 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5342 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5343 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5344
5345 /* Top-level page directory - dummy used by init-mm.
5346 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
5347
5348 /* xwr */
5349 #define __P000 PAGE_NONE
5350 -#define __P001 PAGE_READONLY
5351 -#define __P010 PAGE_COPY
5352 -#define __P011 PAGE_COPY
5353 +#define __P001 PAGE_READONLY_NOEXEC
5354 +#define __P010 PAGE_COPY_NOEXEC
5355 +#define __P011 PAGE_COPY_NOEXEC
5356 #define __P100 PAGE_READONLY
5357 #define __P101 PAGE_READONLY
5358 #define __P110 PAGE_COPY
5359 #define __P111 PAGE_COPY
5360
5361 #define __S000 PAGE_NONE
5362 -#define __S001 PAGE_READONLY
5363 -#define __S010 PAGE_SHARED
5364 -#define __S011 PAGE_SHARED
5365 +#define __S001 PAGE_READONLY_NOEXEC
5366 +#define __S010 PAGE_SHARED_NOEXEC
5367 +#define __S011 PAGE_SHARED_NOEXEC
5368 #define __S100 PAGE_READONLY
5369 #define __S101 PAGE_READONLY
5370 #define __S110 PAGE_SHARED
5371 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5372 index 79da178..c2eede8 100644
5373 --- a/arch/sparc/include/asm/pgtsrmmu.h
5374 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5375 @@ -115,6 +115,11 @@
5376 SRMMU_EXEC | SRMMU_REF)
5377 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5378 SRMMU_EXEC | SRMMU_REF)
5379 +
5380 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5381 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5382 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5383 +
5384 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5385 SRMMU_DIRTY | SRMMU_REF)
5386
5387 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5388 index 9689176..63c18ea 100644
5389 --- a/arch/sparc/include/asm/spinlock_64.h
5390 +++ b/arch/sparc/include/asm/spinlock_64.h
5391 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5392
5393 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5394
5395 -static void inline arch_read_lock(arch_rwlock_t *lock)
5396 +static inline void arch_read_lock(arch_rwlock_t *lock)
5397 {
5398 unsigned long tmp1, tmp2;
5399
5400 __asm__ __volatile__ (
5401 "1: ldsw [%2], %0\n"
5402 " brlz,pn %0, 2f\n"
5403 -"4: add %0, 1, %1\n"
5404 +"4: addcc %0, 1, %1\n"
5405 +
5406 +#ifdef CONFIG_PAX_REFCOUNT
5407 +" tvs %%icc, 6\n"
5408 +#endif
5409 +
5410 " cas [%2], %0, %1\n"
5411 " cmp %0, %1\n"
5412 " bne,pn %%icc, 1b\n"
5413 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5414 " .previous"
5415 : "=&r" (tmp1), "=&r" (tmp2)
5416 : "r" (lock)
5417 - : "memory");
5418 + : "memory", "cc");
5419 }
5420
5421 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5422 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5423 {
5424 int tmp1, tmp2;
5425
5426 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5427 "1: ldsw [%2], %0\n"
5428 " brlz,a,pn %0, 2f\n"
5429 " mov 0, %0\n"
5430 -" add %0, 1, %1\n"
5431 +" addcc %0, 1, %1\n"
5432 +
5433 +#ifdef CONFIG_PAX_REFCOUNT
5434 +" tvs %%icc, 6\n"
5435 +#endif
5436 +
5437 " cas [%2], %0, %1\n"
5438 " cmp %0, %1\n"
5439 " bne,pn %%icc, 1b\n"
5440 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5441 return tmp1;
5442 }
5443
5444 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5445 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5446 {
5447 unsigned long tmp1, tmp2;
5448
5449 __asm__ __volatile__(
5450 "1: lduw [%2], %0\n"
5451 -" sub %0, 1, %1\n"
5452 +" subcc %0, 1, %1\n"
5453 +
5454 +#ifdef CONFIG_PAX_REFCOUNT
5455 +" tvs %%icc, 6\n"
5456 +#endif
5457 +
5458 " cas [%2], %0, %1\n"
5459 " cmp %0, %1\n"
5460 " bne,pn %%xcc, 1b\n"
5461 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5462 : "memory");
5463 }
5464
5465 -static void inline arch_write_lock(arch_rwlock_t *lock)
5466 +static inline void arch_write_lock(arch_rwlock_t *lock)
5467 {
5468 unsigned long mask, tmp1, tmp2;
5469
5470 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5471 : "memory");
5472 }
5473
5474 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5475 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5476 {
5477 __asm__ __volatile__(
5478 " stw %%g0, [%0]"
5479 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5480 : "memory");
5481 }
5482
5483 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5484 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5485 {
5486 unsigned long mask, tmp1, tmp2, result;
5487
5488 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5489 index e6cd224..3a71793 100644
5490 --- a/arch/sparc/include/asm/thread_info_32.h
5491 +++ b/arch/sparc/include/asm/thread_info_32.h
5492 @@ -49,6 +49,8 @@ struct thread_info {
5493 unsigned long w_saved;
5494
5495 struct restart_block restart_block;
5496 +
5497 + unsigned long lowest_stack;
5498 };
5499
5500 /*
5501 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5502 index cfa8c38..13f30d3 100644
5503 --- a/arch/sparc/include/asm/thread_info_64.h
5504 +++ b/arch/sparc/include/asm/thread_info_64.h
5505 @@ -63,6 +63,8 @@ struct thread_info {
5506 struct pt_regs *kern_una_regs;
5507 unsigned int kern_una_insn;
5508
5509 + unsigned long lowest_stack;
5510 +
5511 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5512 };
5513
5514 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5515 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5516 /* flag bit 6 is available */
5517 #define TIF_32BIT 7 /* 32-bit binary */
5518 -/* flag bit 8 is available */
5519 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5520 #define TIF_SECCOMP 9 /* secure computing */
5521 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5522 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5523 +
5524 /* NOTE: Thread flags >= 12 should be ones we have no interest
5525 * in using in assembly, else we can't use the mask as
5526 * an immediate value in instructions such as andcc.
5527 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5528 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5529 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5530 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5531 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5532
5533 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5534 _TIF_DO_NOTIFY_RESUME_MASK | \
5535 _TIF_NEED_RESCHED)
5536 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5537
5538 +#define _TIF_WORK_SYSCALL \
5539 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5540 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5541 +
5542 +
5543 /*
5544 * Thread-synchronous status.
5545 *
5546 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5547 index 0167d26..9acd8ed 100644
5548 --- a/arch/sparc/include/asm/uaccess.h
5549 +++ b/arch/sparc/include/asm/uaccess.h
5550 @@ -1,5 +1,13 @@
5551 #ifndef ___ASM_SPARC_UACCESS_H
5552 #define ___ASM_SPARC_UACCESS_H
5553 +
5554 +#ifdef __KERNEL__
5555 +#ifndef __ASSEMBLY__
5556 +#include <linux/types.h>
5557 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5558 +#endif
5559 +#endif
5560 +
5561 #if defined(__sparc__) && defined(__arch64__)
5562 #include <asm/uaccess_64.h>
5563 #else
5564 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5565 index 53a28dd..50c38c3 100644
5566 --- a/arch/sparc/include/asm/uaccess_32.h
5567 +++ b/arch/sparc/include/asm/uaccess_32.h
5568 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5569
5570 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5571 {
5572 - if (n && __access_ok((unsigned long) to, n))
5573 + if ((long)n < 0)
5574 + return n;
5575 +
5576 + if (n && __access_ok((unsigned long) to, n)) {
5577 + if (!__builtin_constant_p(n))
5578 + check_object_size(from, n, true);
5579 return __copy_user(to, (__force void __user *) from, n);
5580 - else
5581 + } else
5582 return n;
5583 }
5584
5585 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5586 {
5587 + if ((long)n < 0)
5588 + return n;
5589 +
5590 + if (!__builtin_constant_p(n))
5591 + check_object_size(from, n, true);
5592 +
5593 return __copy_user(to, (__force void __user *) from, n);
5594 }
5595
5596 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5597 {
5598 - if (n && __access_ok((unsigned long) from, n))
5599 + if ((long)n < 0)
5600 + return n;
5601 +
5602 + if (n && __access_ok((unsigned long) from, n)) {
5603 + if (!__builtin_constant_p(n))
5604 + check_object_size(to, n, false);
5605 return __copy_user((__force void __user *) to, from, n);
5606 - else
5607 + } else
5608 return n;
5609 }
5610
5611 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5612 {
5613 + if ((long)n < 0)
5614 + return n;
5615 +
5616 return __copy_user((__force void __user *) to, from, n);
5617 }
5618
5619 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5620 index 7c831d8..d440ca7 100644
5621 --- a/arch/sparc/include/asm/uaccess_64.h
5622 +++ b/arch/sparc/include/asm/uaccess_64.h
5623 @@ -10,6 +10,7 @@
5624 #include <linux/compiler.h>
5625 #include <linux/string.h>
5626 #include <linux/thread_info.h>
5627 +#include <linux/kernel.h>
5628 #include <asm/asi.h>
5629 #include <asm/spitfire.h>
5630 #include <asm-generic/uaccess-unaligned.h>
5631 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5632 static inline unsigned long __must_check
5633 copy_from_user(void *to, const void __user *from, unsigned long size)
5634 {
5635 - unsigned long ret = ___copy_from_user(to, from, size);
5636 + unsigned long ret;
5637
5638 + if ((long)size < 0 || size > INT_MAX)
5639 + return size;
5640 +
5641 + if (!__builtin_constant_p(size))
5642 + check_object_size(to, size, false);
5643 +
5644 + ret = ___copy_from_user(to, from, size);
5645 if (unlikely(ret))
5646 ret = copy_from_user_fixup(to, from, size);
5647
5648 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5649 static inline unsigned long __must_check
5650 copy_to_user(void __user *to, const void *from, unsigned long size)
5651 {
5652 - unsigned long ret = ___copy_to_user(to, from, size);
5653 + unsigned long ret;
5654
5655 + if ((long)size < 0 || size > INT_MAX)
5656 + return size;
5657 +
5658 + if (!__builtin_constant_p(size))
5659 + check_object_size(from, size, true);
5660 +
5661 + ret = ___copy_to_user(to, from, size);
5662 if (unlikely(ret))
5663 ret = copy_to_user_fixup(to, from, size);
5664 return ret;
5665 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5666 index 6cf591b..b49e65a 100644
5667 --- a/arch/sparc/kernel/Makefile
5668 +++ b/arch/sparc/kernel/Makefile
5669 @@ -3,7 +3,7 @@
5670 #
5671
5672 asflags-y := -ansi
5673 -ccflags-y := -Werror
5674 +#ccflags-y := -Werror
5675
5676 extra-y := head_$(BITS).o
5677
5678 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5679 index 14006d8..8146238 100644
5680 --- a/arch/sparc/kernel/process_32.c
5681 +++ b/arch/sparc/kernel/process_32.c
5682 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5683
5684 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5685 r->psr, r->pc, r->npc, r->y, print_tainted());
5686 - printk("PC: <%pS>\n", (void *) r->pc);
5687 + printk("PC: <%pA>\n", (void *) r->pc);
5688 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5689 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5690 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5691 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5692 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5693 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5694 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5695 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5696
5697 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5698 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5699 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5700 rw = (struct reg_window32 *) fp;
5701 pc = rw->ins[7];
5702 printk("[%08lx : ", pc);
5703 - printk("%pS ] ", (void *) pc);
5704 + printk("%pA ] ", (void *) pc);
5705 fp = rw->ins[6];
5706 } while (++count < 16);
5707 printk("\n");
5708 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5709 index aff0c72..9067b39 100644
5710 --- a/arch/sparc/kernel/process_64.c
5711 +++ b/arch/sparc/kernel/process_64.c
5712 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5713 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5714 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5715 if (regs->tstate & TSTATE_PRIV)
5716 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5717 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5718 }
5719
5720 void show_regs(struct pt_regs *regs)
5721 {
5722 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5723 regs->tpc, regs->tnpc, regs->y, print_tainted());
5724 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5725 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5726 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5727 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5728 regs->u_regs[3]);
5729 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5730 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5731 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5732 regs->u_regs[15]);
5733 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5734 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5735 show_regwindow(regs);
5736 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5737 }
5738 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5739 ((tp && tp->task) ? tp->task->pid : -1));
5740
5741 if (gp->tstate & TSTATE_PRIV) {
5742 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5743 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5744 (void *) gp->tpc,
5745 (void *) gp->o7,
5746 (void *) gp->i7,
5747 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5748 index 484daba..0674139 100644
5749 --- a/arch/sparc/kernel/ptrace_64.c
5750 +++ b/arch/sparc/kernel/ptrace_64.c
5751 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5752 return ret;
5753 }
5754
5755 +#ifdef CONFIG_GRKERNSEC_SETXID
5756 +extern void gr_delayed_cred_worker(void);
5757 +#endif
5758 +
5759 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5760 {
5761 int ret = 0;
5762 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5763 /* do the secure computing check first */
5764 secure_computing_strict(regs->u_regs[UREG_G1]);
5765
5766 +#ifdef CONFIG_GRKERNSEC_SETXID
5767 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5768 + gr_delayed_cred_worker();
5769 +#endif
5770 +
5771 if (test_thread_flag(TIF_SYSCALL_TRACE))
5772 ret = tracehook_report_syscall_entry(regs);
5773
5774 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5775
5776 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5777 {
5778 +#ifdef CONFIG_GRKERNSEC_SETXID
5779 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5780 + gr_delayed_cred_worker();
5781 +#endif
5782 +
5783 audit_syscall_exit(regs);
5784
5785 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5786 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5787 index 0c9b31b..7cb7aee 100644
5788 --- a/arch/sparc/kernel/sys_sparc_32.c
5789 +++ b/arch/sparc/kernel/sys_sparc_32.c
5790 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5791 if (len > TASK_SIZE - PAGE_SIZE)
5792 return -ENOMEM;
5793 if (!addr)
5794 - addr = TASK_UNMAPPED_BASE;
5795 + addr = current->mm->mmap_base;
5796
5797 if (flags & MAP_SHARED)
5798 addr = COLOUR_ALIGN(addr);
5799 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5800 /* At this point: (!vmm || addr < vmm->vm_end). */
5801 if (TASK_SIZE - PAGE_SIZE - len < addr)
5802 return -ENOMEM;
5803 - if (!vmm || addr + len <= vmm->vm_start)
5804 + if (check_heap_stack_gap(vmm, addr, len))
5805 return addr;
5806 addr = vmm->vm_end;
5807 if (flags & MAP_SHARED)
5808 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5809 index 11c6c96..3ec33e8 100644
5810 --- a/arch/sparc/kernel/sys_sparc_64.c
5811 +++ b/arch/sparc/kernel/sys_sparc_64.c
5812 @@ -107,7 +107,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5813 /* We do not accept a shared mapping if it would violate
5814 * cache aliasing constraints.
5815 */
5816 - if ((flags & MAP_SHARED) &&
5817 + if ((filp || (flags & MAP_SHARED)) &&
5818 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5819 return -EINVAL;
5820 return addr;
5821 @@ -122,6 +122,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5822 if (filp || (flags & MAP_SHARED))
5823 do_color_align = 1;
5824
5825 +#ifdef CONFIG_PAX_RANDMMAP
5826 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5827 +#endif
5828 +
5829 if (addr) {
5830 if (do_color_align)
5831 addr = COLOUR_ALIGN(addr, pgoff);
5832 @@ -129,15 +133,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5833 addr = PAGE_ALIGN(addr);
5834
5835 vma = find_vma(mm, addr);
5836 - if (task_size - len >= addr &&
5837 - (!vma || addr + len <= vma->vm_start))
5838 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5839 return addr;
5840 }
5841
5842 if (len > mm->cached_hole_size) {
5843 - start_addr = addr = mm->free_area_cache;
5844 + start_addr = addr = mm->free_area_cache;
5845 } else {
5846 - start_addr = addr = TASK_UNMAPPED_BASE;
5847 + start_addr = addr = mm->mmap_base;
5848 mm->cached_hole_size = 0;
5849 }
5850
5851 @@ -157,14 +160,14 @@ full_search:
5852 vma = find_vma(mm, VA_EXCLUDE_END);
5853 }
5854 if (unlikely(task_size < addr)) {
5855 - if (start_addr != TASK_UNMAPPED_BASE) {
5856 - start_addr = addr = TASK_UNMAPPED_BASE;
5857 + if (start_addr != mm->mmap_base) {
5858 + start_addr = addr = mm->mmap_base;
5859 mm->cached_hole_size = 0;
5860 goto full_search;
5861 }
5862 return -ENOMEM;
5863 }
5864 - if (likely(!vma || addr + len <= vma->vm_start)) {
5865 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5866 /*
5867 * Remember the place where we stopped the search:
5868 */
5869 @@ -198,7 +201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5870 /* We do not accept a shared mapping if it would violate
5871 * cache aliasing constraints.
5872 */
5873 - if ((flags & MAP_SHARED) &&
5874 + if ((filp || (flags & MAP_SHARED)) &&
5875 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5876 return -EINVAL;
5877 return addr;
5878 @@ -219,8 +222,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5879 addr = PAGE_ALIGN(addr);
5880
5881 vma = find_vma(mm, addr);
5882 - if (task_size - len >= addr &&
5883 - (!vma || addr + len <= vma->vm_start))
5884 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5885 return addr;
5886 }
5887
5888 @@ -241,7 +243,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5889 /* make sure it can fit in the remaining address space */
5890 if (likely(addr > len)) {
5891 vma = find_vma(mm, addr-len);
5892 - if (!vma || addr <= vma->vm_start) {
5893 + if (check_heap_stack_gap(vma, addr - len, len)) {
5894 /* remember the address as a hint for next time */
5895 return (mm->free_area_cache = addr-len);
5896 }
5897 @@ -250,18 +252,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5898 if (unlikely(mm->mmap_base < len))
5899 goto bottomup;
5900
5901 - addr = mm->mmap_base-len;
5902 - if (do_color_align)
5903 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5904 + addr = mm->mmap_base - len;
5905
5906 do {
5907 + if (do_color_align)
5908 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5909 /*
5910 * Lookup failure means no vma is above this address,
5911 * else if new region fits below vma->vm_start,
5912 * return with success:
5913 */
5914 vma = find_vma(mm, addr);
5915 - if (likely(!vma || addr+len <= vma->vm_start)) {
5916 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5917 /* remember the address as a hint for next time */
5918 return (mm->free_area_cache = addr);
5919 }
5920 @@ -271,10 +273,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5921 mm->cached_hole_size = vma->vm_start - addr;
5922
5923 /* try just below the current vma->vm_start */
5924 - addr = vma->vm_start-len;
5925 - if (do_color_align)
5926 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5927 - } while (likely(len < vma->vm_start));
5928 + addr = skip_heap_stack_gap(vma, len);
5929 + } while (!IS_ERR_VALUE(addr));
5930
5931 bottomup:
5932 /*
5933 @@ -373,6 +373,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5934 gap == RLIM_INFINITY ||
5935 sysctl_legacy_va_layout) {
5936 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5937 +
5938 +#ifdef CONFIG_PAX_RANDMMAP
5939 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5940 + mm->mmap_base += mm->delta_mmap;
5941 +#endif
5942 +
5943 mm->get_unmapped_area = arch_get_unmapped_area;
5944 mm->unmap_area = arch_unmap_area;
5945 } else {
5946 @@ -385,6 +391,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5947 gap = (task_size / 6 * 5);
5948
5949 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
5950 +
5951 +#ifdef CONFIG_PAX_RANDMMAP
5952 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5953 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5954 +#endif
5955 +
5956 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5957 mm->unmap_area = arch_unmap_area_topdown;
5958 }
5959 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
5960 index 7f5f65d..3308382 100644
5961 --- a/arch/sparc/kernel/syscalls.S
5962 +++ b/arch/sparc/kernel/syscalls.S
5963 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
5964 #endif
5965 .align 32
5966 1: ldx [%g6 + TI_FLAGS], %l5
5967 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5968 + andcc %l5, _TIF_WORK_SYSCALL, %g0
5969 be,pt %icc, rtrap
5970 nop
5971 call syscall_trace_leave
5972 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
5973
5974 srl %i5, 0, %o5 ! IEU1
5975 srl %i2, 0, %o2 ! IEU0 Group
5976 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5977 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5978 bne,pn %icc, linux_syscall_trace32 ! CTI
5979 mov %i0, %l5 ! IEU1
5980 call %l7 ! CTI Group brk forced
5981 @@ -202,7 +202,7 @@ linux_sparc_syscall:
5982
5983 mov %i3, %o3 ! IEU1
5984 mov %i4, %o4 ! IEU0 Group
5985 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5986 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5987 bne,pn %icc, linux_syscall_trace ! CTI Group
5988 mov %i0, %l5 ! IEU0
5989 2: call %l7 ! CTI Group brk forced
5990 @@ -218,7 +218,7 @@ ret_sys_call:
5991
5992 cmp %o0, -ERESTART_RESTARTBLOCK
5993 bgeu,pn %xcc, 1f
5994 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
5995 + andcc %l0, _TIF_WORK_SYSCALL, %g0
5996 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
5997
5998 2:
5999 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6000 index a5785ea..405c5f7 100644
6001 --- a/arch/sparc/kernel/traps_32.c
6002 +++ b/arch/sparc/kernel/traps_32.c
6003 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6004 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6005 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6006
6007 +extern void gr_handle_kernel_exploit(void);
6008 +
6009 void die_if_kernel(char *str, struct pt_regs *regs)
6010 {
6011 static int die_counter;
6012 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6013 count++ < 30 &&
6014 (((unsigned long) rw) >= PAGE_OFFSET) &&
6015 !(((unsigned long) rw) & 0x7)) {
6016 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6017 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6018 (void *) rw->ins[7]);
6019 rw = (struct reg_window32 *)rw->ins[6];
6020 }
6021 }
6022 printk("Instruction DUMP:");
6023 instruction_dump ((unsigned long *) regs->pc);
6024 - if(regs->psr & PSR_PS)
6025 + if(regs->psr & PSR_PS) {
6026 + gr_handle_kernel_exploit();
6027 do_exit(SIGKILL);
6028 + }
6029 do_exit(SIGSEGV);
6030 }
6031
6032 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6033 index 3b05e66..6ea2917 100644
6034 --- a/arch/sparc/kernel/traps_64.c
6035 +++ b/arch/sparc/kernel/traps_64.c
6036 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6037 i + 1,
6038 p->trapstack[i].tstate, p->trapstack[i].tpc,
6039 p->trapstack[i].tnpc, p->trapstack[i].tt);
6040 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6041 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6042 }
6043 }
6044
6045 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6046
6047 lvl -= 0x100;
6048 if (regs->tstate & TSTATE_PRIV) {
6049 +
6050 +#ifdef CONFIG_PAX_REFCOUNT
6051 + if (lvl == 6)
6052 + pax_report_refcount_overflow(regs);
6053 +#endif
6054 +
6055 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6056 die_if_kernel(buffer, regs);
6057 }
6058 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6059 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6060 {
6061 char buffer[32];
6062 -
6063 +
6064 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6065 0, lvl, SIGTRAP) == NOTIFY_STOP)
6066 return;
6067
6068 +#ifdef CONFIG_PAX_REFCOUNT
6069 + if (lvl == 6)
6070 + pax_report_refcount_overflow(regs);
6071 +#endif
6072 +
6073 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6074
6075 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6076 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6077 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6078 printk("%s" "ERROR(%d): ",
6079 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6080 - printk("TPC<%pS>\n", (void *) regs->tpc);
6081 + printk("TPC<%pA>\n", (void *) regs->tpc);
6082 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6083 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6084 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6085 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6086 smp_processor_id(),
6087 (type & 0x1) ? 'I' : 'D',
6088 regs->tpc);
6089 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6090 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6091 panic("Irrecoverable Cheetah+ parity error.");
6092 }
6093
6094 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6095 smp_processor_id(),
6096 (type & 0x1) ? 'I' : 'D',
6097 regs->tpc);
6098 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6099 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6100 }
6101
6102 struct sun4v_error_entry {
6103 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6104
6105 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6106 regs->tpc, tl);
6107 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6108 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6109 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6110 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6111 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6112 (void *) regs->u_regs[UREG_I7]);
6113 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6114 "pte[%lx] error[%lx]\n",
6115 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6116
6117 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6118 regs->tpc, tl);
6119 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6120 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6121 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6122 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6123 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6124 (void *) regs->u_regs[UREG_I7]);
6125 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6126 "pte[%lx] error[%lx]\n",
6127 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6128 fp = (unsigned long)sf->fp + STACK_BIAS;
6129 }
6130
6131 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6132 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6133 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6134 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6135 int index = tsk->curr_ret_stack;
6136 if (tsk->ret_stack && index >= graph) {
6137 pc = tsk->ret_stack[index - graph].ret;
6138 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6139 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6140 graph++;
6141 }
6142 }
6143 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6144 return (struct reg_window *) (fp + STACK_BIAS);
6145 }
6146
6147 +extern void gr_handle_kernel_exploit(void);
6148 +
6149 void die_if_kernel(char *str, struct pt_regs *regs)
6150 {
6151 static int die_counter;
6152 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6153 while (rw &&
6154 count++ < 30 &&
6155 kstack_valid(tp, (unsigned long) rw)) {
6156 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6157 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6158 (void *) rw->ins[7]);
6159
6160 rw = kernel_stack_up(rw);
6161 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6162 }
6163 user_instruction_dump ((unsigned int __user *) regs->tpc);
6164 }
6165 - if (regs->tstate & TSTATE_PRIV)
6166 + if (regs->tstate & TSTATE_PRIV) {
6167 + gr_handle_kernel_exploit();
6168 do_exit(SIGKILL);
6169 + }
6170 do_exit(SIGSEGV);
6171 }
6172 EXPORT_SYMBOL(die_if_kernel);
6173 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6174 index f81d038..e7a4680 100644
6175 --- a/arch/sparc/kernel/unaligned_64.c
6176 +++ b/arch/sparc/kernel/unaligned_64.c
6177 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6178 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6179
6180 if (__ratelimit(&ratelimit)) {
6181 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6182 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6183 regs->tpc, (void *) regs->tpc);
6184 }
6185 }
6186 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6187 index dff4096..bd9a388 100644
6188 --- a/arch/sparc/lib/Makefile
6189 +++ b/arch/sparc/lib/Makefile
6190 @@ -2,7 +2,7 @@
6191 #
6192
6193 asflags-y := -ansi -DST_DIV0=0x02
6194 -ccflags-y := -Werror
6195 +#ccflags-y := -Werror
6196
6197 lib-$(CONFIG_SPARC32) += ashrdi3.o
6198 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6199 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6200 index 4d502da..527c48d 100644
6201 --- a/arch/sparc/lib/atomic_64.S
6202 +++ b/arch/sparc/lib/atomic_64.S
6203 @@ -17,7 +17,12 @@
6204 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6205 BACKOFF_SETUP(%o2)
6206 1: lduw [%o1], %g1
6207 - add %g1, %o0, %g7
6208 + addcc %g1, %o0, %g7
6209 +
6210 +#ifdef CONFIG_PAX_REFCOUNT
6211 + tvs %icc, 6
6212 +#endif
6213 +
6214 cas [%o1], %g1, %g7
6215 cmp %g1, %g7
6216 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6217 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6218 2: BACKOFF_SPIN(%o2, %o3, 1b)
6219 ENDPROC(atomic_add)
6220
6221 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6222 + BACKOFF_SETUP(%o2)
6223 +1: lduw [%o1], %g1
6224 + add %g1, %o0, %g7
6225 + cas [%o1], %g1, %g7
6226 + cmp %g1, %g7
6227 + bne,pn %icc, 2f
6228 + nop
6229 + retl
6230 + nop
6231 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6232 +ENDPROC(atomic_add_unchecked)
6233 +
6234 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6235 BACKOFF_SETUP(%o2)
6236 1: lduw [%o1], %g1
6237 - sub %g1, %o0, %g7
6238 + subcc %g1, %o0, %g7
6239 +
6240 +#ifdef CONFIG_PAX_REFCOUNT
6241 + tvs %icc, 6
6242 +#endif
6243 +
6244 cas [%o1], %g1, %g7
6245 cmp %g1, %g7
6246 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6247 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6248 2: BACKOFF_SPIN(%o2, %o3, 1b)
6249 ENDPROC(atomic_sub)
6250
6251 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6252 + BACKOFF_SETUP(%o2)
6253 +1: lduw [%o1], %g1
6254 + sub %g1, %o0, %g7
6255 + cas [%o1], %g1, %g7
6256 + cmp %g1, %g7
6257 + bne,pn %icc, 2f
6258 + nop
6259 + retl
6260 + nop
6261 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6262 +ENDPROC(atomic_sub_unchecked)
6263 +
6264 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6265 BACKOFF_SETUP(%o2)
6266 1: lduw [%o1], %g1
6267 - add %g1, %o0, %g7
6268 + addcc %g1, %o0, %g7
6269 +
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + tvs %icc, 6
6272 +#endif
6273 +
6274 cas [%o1], %g1, %g7
6275 cmp %g1, %g7
6276 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6277 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6278 2: BACKOFF_SPIN(%o2, %o3, 1b)
6279 ENDPROC(atomic_add_ret)
6280
6281 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6282 + BACKOFF_SETUP(%o2)
6283 +1: lduw [%o1], %g1
6284 + addcc %g1, %o0, %g7
6285 + cas [%o1], %g1, %g7
6286 + cmp %g1, %g7
6287 + bne,pn %icc, 2f
6288 + add %g7, %o0, %g7
6289 + sra %g7, 0, %o0
6290 + retl
6291 + nop
6292 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6293 +ENDPROC(atomic_add_ret_unchecked)
6294 +
6295 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6296 BACKOFF_SETUP(%o2)
6297 1: lduw [%o1], %g1
6298 - sub %g1, %o0, %g7
6299 + subcc %g1, %o0, %g7
6300 +
6301 +#ifdef CONFIG_PAX_REFCOUNT
6302 + tvs %icc, 6
6303 +#endif
6304 +
6305 cas [%o1], %g1, %g7
6306 cmp %g1, %g7
6307 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6308 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6309 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6310 BACKOFF_SETUP(%o2)
6311 1: ldx [%o1], %g1
6312 - add %g1, %o0, %g7
6313 + addcc %g1, %o0, %g7
6314 +
6315 +#ifdef CONFIG_PAX_REFCOUNT
6316 + tvs %xcc, 6
6317 +#endif
6318 +
6319 casx [%o1], %g1, %g7
6320 cmp %g1, %g7
6321 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6322 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6323 2: BACKOFF_SPIN(%o2, %o3, 1b)
6324 ENDPROC(atomic64_add)
6325
6326 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6327 + BACKOFF_SETUP(%o2)
6328 +1: ldx [%o1], %g1
6329 + addcc %g1, %o0, %g7
6330 + casx [%o1], %g1, %g7
6331 + cmp %g1, %g7
6332 + bne,pn %xcc, 2f
6333 + nop
6334 + retl
6335 + nop
6336 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6337 +ENDPROC(atomic64_add_unchecked)
6338 +
6339 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6340 BACKOFF_SETUP(%o2)
6341 1: ldx [%o1], %g1
6342 - sub %g1, %o0, %g7
6343 + subcc %g1, %o0, %g7
6344 +
6345 +#ifdef CONFIG_PAX_REFCOUNT
6346 + tvs %xcc, 6
6347 +#endif
6348 +
6349 casx [%o1], %g1, %g7
6350 cmp %g1, %g7
6351 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6352 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6353 2: BACKOFF_SPIN(%o2, %o3, 1b)
6354 ENDPROC(atomic64_sub)
6355
6356 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6357 + BACKOFF_SETUP(%o2)
6358 +1: ldx [%o1], %g1
6359 + subcc %g1, %o0, %g7
6360 + casx [%o1], %g1, %g7
6361 + cmp %g1, %g7
6362 + bne,pn %xcc, 2f
6363 + nop
6364 + retl
6365 + nop
6366 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6367 +ENDPROC(atomic64_sub_unchecked)
6368 +
6369 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6370 BACKOFF_SETUP(%o2)
6371 1: ldx [%o1], %g1
6372 - add %g1, %o0, %g7
6373 + addcc %g1, %o0, %g7
6374 +
6375 +#ifdef CONFIG_PAX_REFCOUNT
6376 + tvs %xcc, 6
6377 +#endif
6378 +
6379 casx [%o1], %g1, %g7
6380 cmp %g1, %g7
6381 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6382 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6383 2: BACKOFF_SPIN(%o2, %o3, 1b)
6384 ENDPROC(atomic64_add_ret)
6385
6386 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6387 + BACKOFF_SETUP(%o2)
6388 +1: ldx [%o1], %g1
6389 + addcc %g1, %o0, %g7
6390 + casx [%o1], %g1, %g7
6391 + cmp %g1, %g7
6392 + bne,pn %xcc, 2f
6393 + add %g7, %o0, %g7
6394 + mov %g7, %o0
6395 + retl
6396 + nop
6397 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6398 +ENDPROC(atomic64_add_ret_unchecked)
6399 +
6400 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6401 BACKOFF_SETUP(%o2)
6402 1: ldx [%o1], %g1
6403 - sub %g1, %o0, %g7
6404 + subcc %g1, %o0, %g7
6405 +
6406 +#ifdef CONFIG_PAX_REFCOUNT
6407 + tvs %xcc, 6
6408 +#endif
6409 +
6410 casx [%o1], %g1, %g7
6411 cmp %g1, %g7
6412 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6413 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6414 index 3b31218..345c609 100644
6415 --- a/arch/sparc/lib/ksyms.c
6416 +++ b/arch/sparc/lib/ksyms.c
6417 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6418
6419 /* Atomic counter implementation. */
6420 EXPORT_SYMBOL(atomic_add);
6421 +EXPORT_SYMBOL(atomic_add_unchecked);
6422 EXPORT_SYMBOL(atomic_add_ret);
6423 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6424 EXPORT_SYMBOL(atomic_sub);
6425 +EXPORT_SYMBOL(atomic_sub_unchecked);
6426 EXPORT_SYMBOL(atomic_sub_ret);
6427 EXPORT_SYMBOL(atomic64_add);
6428 +EXPORT_SYMBOL(atomic64_add_unchecked);
6429 EXPORT_SYMBOL(atomic64_add_ret);
6430 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6431 EXPORT_SYMBOL(atomic64_sub);
6432 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6433 EXPORT_SYMBOL(atomic64_sub_ret);
6434
6435 /* Atomic bit operations. */
6436 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6437 index 30c3ecc..736f015 100644
6438 --- a/arch/sparc/mm/Makefile
6439 +++ b/arch/sparc/mm/Makefile
6440 @@ -2,7 +2,7 @@
6441 #
6442
6443 asflags-y := -ansi
6444 -ccflags-y := -Werror
6445 +#ccflags-y := -Werror
6446
6447 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6448 obj-y += fault_$(BITS).o
6449 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6450 index 77ac917..baf45db 100644
6451 --- a/arch/sparc/mm/fault_32.c
6452 +++ b/arch/sparc/mm/fault_32.c
6453 @@ -21,6 +21,9 @@
6454 #include <linux/perf_event.h>
6455 #include <linux/interrupt.h>
6456 #include <linux/kdebug.h>
6457 +#include <linux/slab.h>
6458 +#include <linux/pagemap.h>
6459 +#include <linux/compiler.h>
6460
6461 #include <asm/page.h>
6462 #include <asm/pgtable.h>
6463 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6464 return safe_compute_effective_address(regs, insn);
6465 }
6466
6467 +#ifdef CONFIG_PAX_PAGEEXEC
6468 +#ifdef CONFIG_PAX_DLRESOLVE
6469 +static void pax_emuplt_close(struct vm_area_struct *vma)
6470 +{
6471 + vma->vm_mm->call_dl_resolve = 0UL;
6472 +}
6473 +
6474 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6475 +{
6476 + unsigned int *kaddr;
6477 +
6478 + vmf->page = alloc_page(GFP_HIGHUSER);
6479 + if (!vmf->page)
6480 + return VM_FAULT_OOM;
6481 +
6482 + kaddr = kmap(vmf->page);
6483 + memset(kaddr, 0, PAGE_SIZE);
6484 + kaddr[0] = 0x9DE3BFA8U; /* save */
6485 + flush_dcache_page(vmf->page);
6486 + kunmap(vmf->page);
6487 + return VM_FAULT_MAJOR;
6488 +}
6489 +
6490 +static const struct vm_operations_struct pax_vm_ops = {
6491 + .close = pax_emuplt_close,
6492 + .fault = pax_emuplt_fault
6493 +};
6494 +
6495 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6496 +{
6497 + int ret;
6498 +
6499 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6500 + vma->vm_mm = current->mm;
6501 + vma->vm_start = addr;
6502 + vma->vm_end = addr + PAGE_SIZE;
6503 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6504 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6505 + vma->vm_ops = &pax_vm_ops;
6506 +
6507 + ret = insert_vm_struct(current->mm, vma);
6508 + if (ret)
6509 + return ret;
6510 +
6511 + ++current->mm->total_vm;
6512 + return 0;
6513 +}
6514 +#endif
6515 +
6516 +/*
6517 + * PaX: decide what to do with offenders (regs->pc = fault address)
6518 + *
6519 + * returns 1 when task should be killed
6520 + * 2 when patched PLT trampoline was detected
6521 + * 3 when unpatched PLT trampoline was detected
6522 + */
6523 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6524 +{
6525 +
6526 +#ifdef CONFIG_PAX_EMUPLT
6527 + int err;
6528 +
6529 + do { /* PaX: patched PLT emulation #1 */
6530 + unsigned int sethi1, sethi2, jmpl;
6531 +
6532 + err = get_user(sethi1, (unsigned int *)regs->pc);
6533 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6534 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6535 +
6536 + if (err)
6537 + break;
6538 +
6539 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6540 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6541 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6542 + {
6543 + unsigned int addr;
6544 +
6545 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6546 + addr = regs->u_regs[UREG_G1];
6547 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6548 + regs->pc = addr;
6549 + regs->npc = addr+4;
6550 + return 2;
6551 + }
6552 + } while (0);
6553 +
6554 + do { /* PaX: patched PLT emulation #2 */
6555 + unsigned int ba;
6556 +
6557 + err = get_user(ba, (unsigned int *)regs->pc);
6558 +
6559 + if (err)
6560 + break;
6561 +
6562 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6563 + unsigned int addr;
6564 +
6565 + if ((ba & 0xFFC00000U) == 0x30800000U)
6566 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6567 + else
6568 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6569 + regs->pc = addr;
6570 + regs->npc = addr+4;
6571 + return 2;
6572 + }
6573 + } while (0);
6574 +
6575 + do { /* PaX: patched PLT emulation #3 */
6576 + unsigned int sethi, bajmpl, nop;
6577 +
6578 + err = get_user(sethi, (unsigned int *)regs->pc);
6579 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6580 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6581 +
6582 + if (err)
6583 + break;
6584 +
6585 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6586 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6587 + nop == 0x01000000U)
6588 + {
6589 + unsigned int addr;
6590 +
6591 + addr = (sethi & 0x003FFFFFU) << 10;
6592 + regs->u_regs[UREG_G1] = addr;
6593 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6594 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6595 + else
6596 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6597 + regs->pc = addr;
6598 + regs->npc = addr+4;
6599 + return 2;
6600 + }
6601 + } while (0);
6602 +
6603 + do { /* PaX: unpatched PLT emulation step 1 */
6604 + unsigned int sethi, ba, nop;
6605 +
6606 + err = get_user(sethi, (unsigned int *)regs->pc);
6607 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6608 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6609 +
6610 + if (err)
6611 + break;
6612 +
6613 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6614 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6615 + nop == 0x01000000U)
6616 + {
6617 + unsigned int addr, save, call;
6618 +
6619 + if ((ba & 0xFFC00000U) == 0x30800000U)
6620 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6621 + else
6622 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6623 +
6624 + err = get_user(save, (unsigned int *)addr);
6625 + err |= get_user(call, (unsigned int *)(addr+4));
6626 + err |= get_user(nop, (unsigned int *)(addr+8));
6627 + if (err)
6628 + break;
6629 +
6630 +#ifdef CONFIG_PAX_DLRESOLVE
6631 + if (save == 0x9DE3BFA8U &&
6632 + (call & 0xC0000000U) == 0x40000000U &&
6633 + nop == 0x01000000U)
6634 + {
6635 + struct vm_area_struct *vma;
6636 + unsigned long call_dl_resolve;
6637 +
6638 + down_read(&current->mm->mmap_sem);
6639 + call_dl_resolve = current->mm->call_dl_resolve;
6640 + up_read(&current->mm->mmap_sem);
6641 + if (likely(call_dl_resolve))
6642 + goto emulate;
6643 +
6644 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6645 +
6646 + down_write(&current->mm->mmap_sem);
6647 + if (current->mm->call_dl_resolve) {
6648 + call_dl_resolve = current->mm->call_dl_resolve;
6649 + up_write(&current->mm->mmap_sem);
6650 + if (vma)
6651 + kmem_cache_free(vm_area_cachep, vma);
6652 + goto emulate;
6653 + }
6654 +
6655 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6656 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6657 + up_write(&current->mm->mmap_sem);
6658 + if (vma)
6659 + kmem_cache_free(vm_area_cachep, vma);
6660 + return 1;
6661 + }
6662 +
6663 + if (pax_insert_vma(vma, call_dl_resolve)) {
6664 + up_write(&current->mm->mmap_sem);
6665 + kmem_cache_free(vm_area_cachep, vma);
6666 + return 1;
6667 + }
6668 +
6669 + current->mm->call_dl_resolve = call_dl_resolve;
6670 + up_write(&current->mm->mmap_sem);
6671 +
6672 +emulate:
6673 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6674 + regs->pc = call_dl_resolve;
6675 + regs->npc = addr+4;
6676 + return 3;
6677 + }
6678 +#endif
6679 +
6680 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6681 + if ((save & 0xFFC00000U) == 0x05000000U &&
6682 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6683 + nop == 0x01000000U)
6684 + {
6685 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6686 + regs->u_regs[UREG_G2] = addr + 4;
6687 + addr = (save & 0x003FFFFFU) << 10;
6688 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6689 + regs->pc = addr;
6690 + regs->npc = addr+4;
6691 + return 3;
6692 + }
6693 + }
6694 + } while (0);
6695 +
6696 + do { /* PaX: unpatched PLT emulation step 2 */
6697 + unsigned int save, call, nop;
6698 +
6699 + err = get_user(save, (unsigned int *)(regs->pc-4));
6700 + err |= get_user(call, (unsigned int *)regs->pc);
6701 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6702 + if (err)
6703 + break;
6704 +
6705 + if (save == 0x9DE3BFA8U &&
6706 + (call & 0xC0000000U) == 0x40000000U &&
6707 + nop == 0x01000000U)
6708 + {
6709 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6710 +
6711 + regs->u_regs[UREG_RETPC] = regs->pc;
6712 + regs->pc = dl_resolve;
6713 + regs->npc = dl_resolve+4;
6714 + return 3;
6715 + }
6716 + } while (0);
6717 +#endif
6718 +
6719 + return 1;
6720 +}
6721 +
6722 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6723 +{
6724 + unsigned long i;
6725 +
6726 + printk(KERN_ERR "PAX: bytes at PC: ");
6727 + for (i = 0; i < 8; i++) {
6728 + unsigned int c;
6729 + if (get_user(c, (unsigned int *)pc+i))
6730 + printk(KERN_CONT "???????? ");
6731 + else
6732 + printk(KERN_CONT "%08x ", c);
6733 + }
6734 + printk("\n");
6735 +}
6736 +#endif
6737 +
6738 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6739 int text_fault)
6740 {
6741 @@ -230,6 +504,24 @@ good_area:
6742 if (!(vma->vm_flags & VM_WRITE))
6743 goto bad_area;
6744 } else {
6745 +
6746 +#ifdef CONFIG_PAX_PAGEEXEC
6747 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6748 + up_read(&mm->mmap_sem);
6749 + switch (pax_handle_fetch_fault(regs)) {
6750 +
6751 +#ifdef CONFIG_PAX_EMUPLT
6752 + case 2:
6753 + case 3:
6754 + return;
6755 +#endif
6756 +
6757 + }
6758 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6759 + do_group_exit(SIGKILL);
6760 + }
6761 +#endif
6762 +
6763 /* Allow reads even for write-only mappings */
6764 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6765 goto bad_area;
6766 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6767 index 1fe0429..8dd5dd5 100644
6768 --- a/arch/sparc/mm/fault_64.c
6769 +++ b/arch/sparc/mm/fault_64.c
6770 @@ -21,6 +21,9 @@
6771 #include <linux/kprobes.h>
6772 #include <linux/kdebug.h>
6773 #include <linux/percpu.h>
6774 +#include <linux/slab.h>
6775 +#include <linux/pagemap.h>
6776 +#include <linux/compiler.h>
6777
6778 #include <asm/page.h>
6779 #include <asm/pgtable.h>
6780 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6781 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6782 regs->tpc);
6783 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6784 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6785 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6786 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6787 dump_stack();
6788 unhandled_fault(regs->tpc, current, regs);
6789 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6790 show_regs(regs);
6791 }
6792
6793 +#ifdef CONFIG_PAX_PAGEEXEC
6794 +#ifdef CONFIG_PAX_DLRESOLVE
6795 +static void pax_emuplt_close(struct vm_area_struct *vma)
6796 +{
6797 + vma->vm_mm->call_dl_resolve = 0UL;
6798 +}
6799 +
6800 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6801 +{
6802 + unsigned int *kaddr;
6803 +
6804 + vmf->page = alloc_page(GFP_HIGHUSER);
6805 + if (!vmf->page)
6806 + return VM_FAULT_OOM;
6807 +
6808 + kaddr = kmap(vmf->page);
6809 + memset(kaddr, 0, PAGE_SIZE);
6810 + kaddr[0] = 0x9DE3BFA8U; /* save */
6811 + flush_dcache_page(vmf->page);
6812 + kunmap(vmf->page);
6813 + return VM_FAULT_MAJOR;
6814 +}
6815 +
6816 +static const struct vm_operations_struct pax_vm_ops = {
6817 + .close = pax_emuplt_close,
6818 + .fault = pax_emuplt_fault
6819 +};
6820 +
6821 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6822 +{
6823 + int ret;
6824 +
6825 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6826 + vma->vm_mm = current->mm;
6827 + vma->vm_start = addr;
6828 + vma->vm_end = addr + PAGE_SIZE;
6829 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6830 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6831 + vma->vm_ops = &pax_vm_ops;
6832 +
6833 + ret = insert_vm_struct(current->mm, vma);
6834 + if (ret)
6835 + return ret;
6836 +
6837 + ++current->mm->total_vm;
6838 + return 0;
6839 +}
6840 +#endif
6841 +
6842 +/*
6843 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6844 + *
6845 + * returns 1 when task should be killed
6846 + * 2 when patched PLT trampoline was detected
6847 + * 3 when unpatched PLT trampoline was detected
6848 + */
6849 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6850 +{
6851 +
6852 +#ifdef CONFIG_PAX_EMUPLT
6853 + int err;
6854 +
6855 + do { /* PaX: patched PLT emulation #1 */
6856 + unsigned int sethi1, sethi2, jmpl;
6857 +
6858 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6859 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6860 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6861 +
6862 + if (err)
6863 + break;
6864 +
6865 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6866 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6867 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6868 + {
6869 + unsigned long addr;
6870 +
6871 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6872 + addr = regs->u_regs[UREG_G1];
6873 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6874 +
6875 + if (test_thread_flag(TIF_32BIT))
6876 + addr &= 0xFFFFFFFFUL;
6877 +
6878 + regs->tpc = addr;
6879 + regs->tnpc = addr+4;
6880 + return 2;
6881 + }
6882 + } while (0);
6883 +
6884 + do { /* PaX: patched PLT emulation #2 */
6885 + unsigned int ba;
6886 +
6887 + err = get_user(ba, (unsigned int *)regs->tpc);
6888 +
6889 + if (err)
6890 + break;
6891 +
6892 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6893 + unsigned long addr;
6894 +
6895 + if ((ba & 0xFFC00000U) == 0x30800000U)
6896 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6897 + else
6898 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6899 +
6900 + if (test_thread_flag(TIF_32BIT))
6901 + addr &= 0xFFFFFFFFUL;
6902 +
6903 + regs->tpc = addr;
6904 + regs->tnpc = addr+4;
6905 + return 2;
6906 + }
6907 + } while (0);
6908 +
6909 + do { /* PaX: patched PLT emulation #3 */
6910 + unsigned int sethi, bajmpl, nop;
6911 +
6912 + err = get_user(sethi, (unsigned int *)regs->tpc);
6913 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6914 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6915 +
6916 + if (err)
6917 + break;
6918 +
6919 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6920 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6921 + nop == 0x01000000U)
6922 + {
6923 + unsigned long addr;
6924 +
6925 + addr = (sethi & 0x003FFFFFU) << 10;
6926 + regs->u_regs[UREG_G1] = addr;
6927 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6928 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6929 + else
6930 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6931 +
6932 + if (test_thread_flag(TIF_32BIT))
6933 + addr &= 0xFFFFFFFFUL;
6934 +
6935 + regs->tpc = addr;
6936 + regs->tnpc = addr+4;
6937 + return 2;
6938 + }
6939 + } while (0);
6940 +
6941 + do { /* PaX: patched PLT emulation #4 */
6942 + unsigned int sethi, mov1, call, mov2;
6943 +
6944 + err = get_user(sethi, (unsigned int *)regs->tpc);
6945 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6946 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6947 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6948 +
6949 + if (err)
6950 + break;
6951 +
6952 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6953 + mov1 == 0x8210000FU &&
6954 + (call & 0xC0000000U) == 0x40000000U &&
6955 + mov2 == 0x9E100001U)
6956 + {
6957 + unsigned long addr;
6958 +
6959 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6960 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6961 +
6962 + if (test_thread_flag(TIF_32BIT))
6963 + addr &= 0xFFFFFFFFUL;
6964 +
6965 + regs->tpc = addr;
6966 + regs->tnpc = addr+4;
6967 + return 2;
6968 + }
6969 + } while (0);
6970 +
6971 + do { /* PaX: patched PLT emulation #5 */
6972 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6973 +
6974 + err = get_user(sethi, (unsigned int *)regs->tpc);
6975 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6976 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6977 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6978 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6979 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6980 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6981 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6982 +
6983 + if (err)
6984 + break;
6985 +
6986 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6987 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6988 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6989 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6990 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
6991 + sllx == 0x83287020U &&
6992 + jmpl == 0x81C04005U &&
6993 + nop == 0x01000000U)
6994 + {
6995 + unsigned long addr;
6996 +
6997 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
6998 + regs->u_regs[UREG_G1] <<= 32;
6999 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7000 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7001 + regs->tpc = addr;
7002 + regs->tnpc = addr+4;
7003 + return 2;
7004 + }
7005 + } while (0);
7006 +
7007 + do { /* PaX: patched PLT emulation #6 */
7008 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7009 +
7010 + err = get_user(sethi, (unsigned int *)regs->tpc);
7011 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7012 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7013 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7014 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7015 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7016 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7017 +
7018 + if (err)
7019 + break;
7020 +
7021 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7022 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7023 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7024 + sllx == 0x83287020U &&
7025 + (or & 0xFFFFE000U) == 0x8A116000U &&
7026 + jmpl == 0x81C04005U &&
7027 + nop == 0x01000000U)
7028 + {
7029 + unsigned long addr;
7030 +
7031 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7032 + regs->u_regs[UREG_G1] <<= 32;
7033 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7034 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7035 + regs->tpc = addr;
7036 + regs->tnpc = addr+4;
7037 + return 2;
7038 + }
7039 + } while (0);
7040 +
7041 + do { /* PaX: unpatched PLT emulation step 1 */
7042 + unsigned int sethi, ba, nop;
7043 +
7044 + err = get_user(sethi, (unsigned int *)regs->tpc);
7045 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7046 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7047 +
7048 + if (err)
7049 + break;
7050 +
7051 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7052 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7053 + nop == 0x01000000U)
7054 + {
7055 + unsigned long addr;
7056 + unsigned int save, call;
7057 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7058 +
7059 + if ((ba & 0xFFC00000U) == 0x30800000U)
7060 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7061 + else
7062 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7063 +
7064 + if (test_thread_flag(TIF_32BIT))
7065 + addr &= 0xFFFFFFFFUL;
7066 +
7067 + err = get_user(save, (unsigned int *)addr);
7068 + err |= get_user(call, (unsigned int *)(addr+4));
7069 + err |= get_user(nop, (unsigned int *)(addr+8));
7070 + if (err)
7071 + break;
7072 +
7073 +#ifdef CONFIG_PAX_DLRESOLVE
7074 + if (save == 0x9DE3BFA8U &&
7075 + (call & 0xC0000000U) == 0x40000000U &&
7076 + nop == 0x01000000U)
7077 + {
7078 + struct vm_area_struct *vma;
7079 + unsigned long call_dl_resolve;
7080 +
7081 + down_read(&current->mm->mmap_sem);
7082 + call_dl_resolve = current->mm->call_dl_resolve;
7083 + up_read(&current->mm->mmap_sem);
7084 + if (likely(call_dl_resolve))
7085 + goto emulate;
7086 +
7087 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7088 +
7089 + down_write(&current->mm->mmap_sem);
7090 + if (current->mm->call_dl_resolve) {
7091 + call_dl_resolve = current->mm->call_dl_resolve;
7092 + up_write(&current->mm->mmap_sem);
7093 + if (vma)
7094 + kmem_cache_free(vm_area_cachep, vma);
7095 + goto emulate;
7096 + }
7097 +
7098 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7099 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7100 + up_write(&current->mm->mmap_sem);
7101 + if (vma)
7102 + kmem_cache_free(vm_area_cachep, vma);
7103 + return 1;
7104 + }
7105 +
7106 + if (pax_insert_vma(vma, call_dl_resolve)) {
7107 + up_write(&current->mm->mmap_sem);
7108 + kmem_cache_free(vm_area_cachep, vma);
7109 + return 1;
7110 + }
7111 +
7112 + current->mm->call_dl_resolve = call_dl_resolve;
7113 + up_write(&current->mm->mmap_sem);
7114 +
7115 +emulate:
7116 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7117 + regs->tpc = call_dl_resolve;
7118 + regs->tnpc = addr+4;
7119 + return 3;
7120 + }
7121 +#endif
7122 +
7123 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7124 + if ((save & 0xFFC00000U) == 0x05000000U &&
7125 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7126 + nop == 0x01000000U)
7127 + {
7128 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7129 + regs->u_regs[UREG_G2] = addr + 4;
7130 + addr = (save & 0x003FFFFFU) << 10;
7131 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7132 +
7133 + if (test_thread_flag(TIF_32BIT))
7134 + addr &= 0xFFFFFFFFUL;
7135 +
7136 + regs->tpc = addr;
7137 + regs->tnpc = addr+4;
7138 + return 3;
7139 + }
7140 +
7141 + /* PaX: 64-bit PLT stub */
7142 + err = get_user(sethi1, (unsigned int *)addr);
7143 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7144 + err |= get_user(or1, (unsigned int *)(addr+8));
7145 + err |= get_user(or2, (unsigned int *)(addr+12));
7146 + err |= get_user(sllx, (unsigned int *)(addr+16));
7147 + err |= get_user(add, (unsigned int *)(addr+20));
7148 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7149 + err |= get_user(nop, (unsigned int *)(addr+28));
7150 + if (err)
7151 + break;
7152 +
7153 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7154 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7155 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7156 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7157 + sllx == 0x89293020U &&
7158 + add == 0x8A010005U &&
7159 + jmpl == 0x89C14000U &&
7160 + nop == 0x01000000U)
7161 + {
7162 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7163 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7164 + regs->u_regs[UREG_G4] <<= 32;
7165 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7166 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7167 + regs->u_regs[UREG_G4] = addr + 24;
7168 + addr = regs->u_regs[UREG_G5];
7169 + regs->tpc = addr;
7170 + regs->tnpc = addr+4;
7171 + return 3;
7172 + }
7173 + }
7174 + } while (0);
7175 +
7176 +#ifdef CONFIG_PAX_DLRESOLVE
7177 + do { /* PaX: unpatched PLT emulation step 2 */
7178 + unsigned int save, call, nop;
7179 +
7180 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7181 + err |= get_user(call, (unsigned int *)regs->tpc);
7182 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7183 + if (err)
7184 + break;
7185 +
7186 + if (save == 0x9DE3BFA8U &&
7187 + (call & 0xC0000000U) == 0x40000000U &&
7188 + nop == 0x01000000U)
7189 + {
7190 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7191 +
7192 + if (test_thread_flag(TIF_32BIT))
7193 + dl_resolve &= 0xFFFFFFFFUL;
7194 +
7195 + regs->u_regs[UREG_RETPC] = regs->tpc;
7196 + regs->tpc = dl_resolve;
7197 + regs->tnpc = dl_resolve+4;
7198 + return 3;
7199 + }
7200 + } while (0);
7201 +#endif
7202 +
7203 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7204 + unsigned int sethi, ba, nop;
7205 +
7206 + err = get_user(sethi, (unsigned int *)regs->tpc);
7207 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7208 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7209 +
7210 + if (err)
7211 + break;
7212 +
7213 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7214 + (ba & 0xFFF00000U) == 0x30600000U &&
7215 + nop == 0x01000000U)
7216 + {
7217 + unsigned long addr;
7218 +
7219 + addr = (sethi & 0x003FFFFFU) << 10;
7220 + regs->u_regs[UREG_G1] = addr;
7221 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7222 +
7223 + if (test_thread_flag(TIF_32BIT))
7224 + addr &= 0xFFFFFFFFUL;
7225 +
7226 + regs->tpc = addr;
7227 + regs->tnpc = addr+4;
7228 + return 2;
7229 + }
7230 + } while (0);
7231 +
7232 +#endif
7233 +
7234 + return 1;
7235 +}
7236 +
7237 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7238 +{
7239 + unsigned long i;
7240 +
7241 + printk(KERN_ERR "PAX: bytes at PC: ");
7242 + for (i = 0; i < 8; i++) {
7243 + unsigned int c;
7244 + if (get_user(c, (unsigned int *)pc+i))
7245 + printk(KERN_CONT "???????? ");
7246 + else
7247 + printk(KERN_CONT "%08x ", c);
7248 + }
7249 + printk("\n");
7250 +}
7251 +#endif
7252 +
7253 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7254 {
7255 struct mm_struct *mm = current->mm;
7256 @@ -343,6 +806,29 @@ retry:
7257 if (!vma)
7258 goto bad_area;
7259
7260 +#ifdef CONFIG_PAX_PAGEEXEC
7261 + /* PaX: detect ITLB misses on non-exec pages */
7262 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7263 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7264 + {
7265 + if (address != regs->tpc)
7266 + goto good_area;
7267 +
7268 + up_read(&mm->mmap_sem);
7269 + switch (pax_handle_fetch_fault(regs)) {
7270 +
7271 +#ifdef CONFIG_PAX_EMUPLT
7272 + case 2:
7273 + case 3:
7274 + return;
7275 +#endif
7276 +
7277 + }
7278 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7279 + do_group_exit(SIGKILL);
7280 + }
7281 +#endif
7282 +
7283 /* Pure DTLB misses do not tell us whether the fault causing
7284 * load/store/atomic was a write or not, it only says that there
7285 * was no match. So in such a case we (carefully) read the
7286 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7287 index 07e1453..0a7d9e9 100644
7288 --- a/arch/sparc/mm/hugetlbpage.c
7289 +++ b/arch/sparc/mm/hugetlbpage.c
7290 @@ -67,7 +67,7 @@ full_search:
7291 }
7292 return -ENOMEM;
7293 }
7294 - if (likely(!vma || addr + len <= vma->vm_start)) {
7295 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7296 /*
7297 * Remember the place where we stopped the search:
7298 */
7299 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7300 /* make sure it can fit in the remaining address space */
7301 if (likely(addr > len)) {
7302 vma = find_vma(mm, addr-len);
7303 - if (!vma || addr <= vma->vm_start) {
7304 + if (check_heap_stack_gap(vma, addr - len, len)) {
7305 /* remember the address as a hint for next time */
7306 return (mm->free_area_cache = addr-len);
7307 }
7308 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7309 if (unlikely(mm->mmap_base < len))
7310 goto bottomup;
7311
7312 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7313 + addr = mm->mmap_base - len;
7314
7315 do {
7316 + addr &= HPAGE_MASK;
7317 /*
7318 * Lookup failure means no vma is above this address,
7319 * else if new region fits below vma->vm_start,
7320 * return with success:
7321 */
7322 vma = find_vma(mm, addr);
7323 - if (likely(!vma || addr+len <= vma->vm_start)) {
7324 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7325 /* remember the address as a hint for next time */
7326 return (mm->free_area_cache = addr);
7327 }
7328 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7329 mm->cached_hole_size = vma->vm_start - addr;
7330
7331 /* try just below the current vma->vm_start */
7332 - addr = (vma->vm_start-len) & HPAGE_MASK;
7333 - } while (likely(len < vma->vm_start));
7334 + addr = skip_heap_stack_gap(vma, len);
7335 + } while (!IS_ERR_VALUE(addr));
7336
7337 bottomup:
7338 /*
7339 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7340 if (addr) {
7341 addr = ALIGN(addr, HPAGE_SIZE);
7342 vma = find_vma(mm, addr);
7343 - if (task_size - len >= addr &&
7344 - (!vma || addr + len <= vma->vm_start))
7345 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7346 return addr;
7347 }
7348 if (mm->get_unmapped_area == arch_get_unmapped_area)
7349 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7350 index f4500c6..889656c 100644
7351 --- a/arch/tile/include/asm/atomic_64.h
7352 +++ b/arch/tile/include/asm/atomic_64.h
7353 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7354
7355 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7356
7357 +#define atomic64_read_unchecked(v) atomic64_read(v)
7358 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7359 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7360 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7361 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7362 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7363 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7364 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7365 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7366 +
7367 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7368 #define smp_mb__before_atomic_dec() smp_mb()
7369 #define smp_mb__after_atomic_dec() smp_mb()
7370 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7371 index a9a5299..0fce79e 100644
7372 --- a/arch/tile/include/asm/cache.h
7373 +++ b/arch/tile/include/asm/cache.h
7374 @@ -15,11 +15,12 @@
7375 #ifndef _ASM_TILE_CACHE_H
7376 #define _ASM_TILE_CACHE_H
7377
7378 +#include <linux/const.h>
7379 #include <arch/chip.h>
7380
7381 /* bytes per L1 data cache line */
7382 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7383 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7384 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7385
7386 /* bytes per L2 cache line */
7387 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7388 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7389 index 9ab078a..d6635c2 100644
7390 --- a/arch/tile/include/asm/uaccess.h
7391 +++ b/arch/tile/include/asm/uaccess.h
7392 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7393 const void __user *from,
7394 unsigned long n)
7395 {
7396 - int sz = __compiletime_object_size(to);
7397 + size_t sz = __compiletime_object_size(to);
7398
7399 - if (likely(sz == -1 || sz >= n))
7400 + if (likely(sz == (size_t)-1 || sz >= n))
7401 n = _copy_from_user(to, from, n);
7402 else
7403 copy_from_user_overflow();
7404 diff --git a/arch/um/Makefile b/arch/um/Makefile
7405 index 0970910..9f65c40 100644
7406 --- a/arch/um/Makefile
7407 +++ b/arch/um/Makefile
7408 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7409 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7410 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7411
7412 +ifdef CONSTIFY_PLUGIN
7413 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7414 +endif
7415 +
7416 #This will adjust *FLAGS accordingly to the platform.
7417 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7418
7419 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7420 index 19e1bdd..3665b77 100644
7421 --- a/arch/um/include/asm/cache.h
7422 +++ b/arch/um/include/asm/cache.h
7423 @@ -1,6 +1,7 @@
7424 #ifndef __UM_CACHE_H
7425 #define __UM_CACHE_H
7426
7427 +#include <linux/const.h>
7428
7429 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7430 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7431 @@ -12,6 +13,6 @@
7432 # define L1_CACHE_SHIFT 5
7433 #endif
7434
7435 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7436 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7437
7438 #endif
7439 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7440 index 2e0a6b1..a64d0f5 100644
7441 --- a/arch/um/include/asm/kmap_types.h
7442 +++ b/arch/um/include/asm/kmap_types.h
7443 @@ -8,6 +8,6 @@
7444
7445 /* No more #include "asm/arch/kmap_types.h" ! */
7446
7447 -#define KM_TYPE_NR 14
7448 +#define KM_TYPE_NR 15
7449
7450 #endif
7451 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7452 index 7cfc3ce..cbd1a58 100644
7453 --- a/arch/um/include/asm/page.h
7454 +++ b/arch/um/include/asm/page.h
7455 @@ -14,6 +14,9 @@
7456 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7457 #define PAGE_MASK (~(PAGE_SIZE-1))
7458
7459 +#define ktla_ktva(addr) (addr)
7460 +#define ktva_ktla(addr) (addr)
7461 +
7462 #ifndef __ASSEMBLY__
7463
7464 struct page;
7465 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7466 index 0032f92..cd151e0 100644
7467 --- a/arch/um/include/asm/pgtable-3level.h
7468 +++ b/arch/um/include/asm/pgtable-3level.h
7469 @@ -58,6 +58,7 @@
7470 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7471 #define pud_populate(mm, pud, pmd) \
7472 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7473 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7474
7475 #ifdef CONFIG_64BIT
7476 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7477 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7478 index c5f5afa..6abce4b 100644
7479 --- a/arch/um/kernel/process.c
7480 +++ b/arch/um/kernel/process.c
7481 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7482 return 2;
7483 }
7484
7485 -/*
7486 - * Only x86 and x86_64 have an arch_align_stack().
7487 - * All other arches have "#define arch_align_stack(x) (x)"
7488 - * in their asm/system.h
7489 - * As this is included in UML from asm-um/system-generic.h,
7490 - * we can use it to behave as the subarch does.
7491 - */
7492 -#ifndef arch_align_stack
7493 -unsigned long arch_align_stack(unsigned long sp)
7494 -{
7495 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7496 - sp -= get_random_int() % 8192;
7497 - return sp & ~0xf;
7498 -}
7499 -#endif
7500 -
7501 unsigned long get_wchan(struct task_struct *p)
7502 {
7503 unsigned long stack_page, sp, ip;
7504 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7505 index ad8f795..2c7eec6 100644
7506 --- a/arch/unicore32/include/asm/cache.h
7507 +++ b/arch/unicore32/include/asm/cache.h
7508 @@ -12,8 +12,10 @@
7509 #ifndef __UNICORE_CACHE_H__
7510 #define __UNICORE_CACHE_H__
7511
7512 -#define L1_CACHE_SHIFT (5)
7513 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7514 +#include <linux/const.h>
7515 +
7516 +#define L1_CACHE_SHIFT 5
7517 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7518
7519 /*
7520 * Memory returned by kmalloc() may be used for DMA, so we must make
7521 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7522 index 50a1d1f..c26369f 100644
7523 --- a/arch/x86/Kconfig
7524 +++ b/arch/x86/Kconfig
7525 @@ -220,7 +220,7 @@ config X86_HT
7526
7527 config X86_32_LAZY_GS
7528 def_bool y
7529 - depends on X86_32 && !CC_STACKPROTECTOR
7530 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7531
7532 config ARCH_HWEIGHT_CFLAGS
7533 string
7534 @@ -1049,7 +1049,7 @@ choice
7535
7536 config NOHIGHMEM
7537 bool "off"
7538 - depends on !X86_NUMAQ
7539 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7540 ---help---
7541 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7542 However, the address space of 32-bit x86 processors is only 4
7543 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7544
7545 config HIGHMEM4G
7546 bool "4GB"
7547 - depends on !X86_NUMAQ
7548 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7549 ---help---
7550 Select this if you have a 32-bit processor and between 1 and 4
7551 gigabytes of physical RAM.
7552 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7553 hex
7554 default 0xB0000000 if VMSPLIT_3G_OPT
7555 default 0x80000000 if VMSPLIT_2G
7556 - default 0x78000000 if VMSPLIT_2G_OPT
7557 + default 0x70000000 if VMSPLIT_2G_OPT
7558 default 0x40000000 if VMSPLIT_1G
7559 default 0xC0000000
7560 depends on X86_32
7561 @@ -1528,6 +1528,7 @@ config SECCOMP
7562
7563 config CC_STACKPROTECTOR
7564 bool "Enable -fstack-protector buffer overflow detection"
7565 + depends on X86_64 || !PAX_MEMORY_UDEREF
7566 ---help---
7567 This option turns on the -fstack-protector GCC feature. This
7568 feature puts, at the beginning of functions, a canary value on
7569 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7570 config PHYSICAL_START
7571 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7572 default "0x1000000"
7573 + range 0x400000 0x40000000
7574 ---help---
7575 This gives the physical address where the kernel is loaded.
7576
7577 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7578 config PHYSICAL_ALIGN
7579 hex "Alignment value to which kernel should be aligned" if X86_32
7580 default "0x1000000"
7581 + range 0x400000 0x1000000 if PAX_KERNEXEC
7582 range 0x2000 0x1000000
7583 ---help---
7584 This value puts the alignment restrictions on physical address
7585 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7586 Say N if you want to disable CPU hotplug.
7587
7588 config COMPAT_VDSO
7589 - def_bool y
7590 + def_bool n
7591 prompt "Compat VDSO support"
7592 depends on X86_32 || IA32_EMULATION
7593 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7594 ---help---
7595 Map the 32-bit VDSO to the predictable old-style address too.
7596
7597 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7598 index 706e12e..62e4feb 100644
7599 --- a/arch/x86/Kconfig.cpu
7600 +++ b/arch/x86/Kconfig.cpu
7601 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7602
7603 config X86_F00F_BUG
7604 def_bool y
7605 - depends on M586MMX || M586TSC || M586 || M486 || M386
7606 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7607
7608 config X86_INVD_BUG
7609 def_bool y
7610 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7611
7612 config X86_ALIGNMENT_16
7613 def_bool y
7614 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7615 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7616
7617 config X86_INTEL_USERCOPY
7618 def_bool y
7619 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7620 # generates cmov.
7621 config X86_CMOV
7622 def_bool y
7623 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7624 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7625
7626 config X86_MINIMUM_CPU_FAMILY
7627 int
7628 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7629 index b322f12..652d0d9 100644
7630 --- a/arch/x86/Kconfig.debug
7631 +++ b/arch/x86/Kconfig.debug
7632 @@ -84,7 +84,7 @@ config X86_PTDUMP
7633 config DEBUG_RODATA
7634 bool "Write protect kernel read-only data structures"
7635 default y
7636 - depends on DEBUG_KERNEL
7637 + depends on DEBUG_KERNEL && BROKEN
7638 ---help---
7639 Mark the kernel read-only data as write-protected in the pagetables,
7640 in order to catch accidental (and incorrect) writes to such const
7641 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7642
7643 config DEBUG_SET_MODULE_RONX
7644 bool "Set loadable kernel module data as NX and text as RO"
7645 - depends on MODULES
7646 + depends on MODULES && BROKEN
7647 ---help---
7648 This option helps catch unintended modifications to loadable
7649 kernel module's text and read-only data. It also prevents execution
7650 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7651
7652 config DEBUG_STRICT_USER_COPY_CHECKS
7653 bool "Strict copy size checks"
7654 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7655 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7656 ---help---
7657 Enabling this option turns a certain set of sanity checks for user
7658 copy operations into compile time failures.
7659 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7660 index 05afcca..b6ecb51 100644
7661 --- a/arch/x86/Makefile
7662 +++ b/arch/x86/Makefile
7663 @@ -50,6 +50,7 @@ else
7664 UTS_MACHINE := x86_64
7665 CHECKFLAGS += -D__x86_64__ -m64
7666
7667 + biarch := $(call cc-option,-m64)
7668 KBUILD_AFLAGS += -m64
7669 KBUILD_CFLAGS += -m64
7670
7671 @@ -229,3 +230,12 @@ define archhelp
7672 echo ' FDARGS="..." arguments for the booted kernel'
7673 echo ' FDINITRD=file initrd for the booted kernel'
7674 endef
7675 +
7676 +define OLD_LD
7677 +
7678 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7679 +*** Please upgrade your binutils to 2.18 or newer
7680 +endef
7681 +
7682 +archprepare:
7683 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7684 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7685 index f7535be..37db2d1 100644
7686 --- a/arch/x86/boot/Makefile
7687 +++ b/arch/x86/boot/Makefile
7688 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7689 $(call cc-option, -fno-stack-protector) \
7690 $(call cc-option, -mpreferred-stack-boundary=2)
7691 KBUILD_CFLAGS += $(call cc-option, -m32)
7692 +ifdef CONSTIFY_PLUGIN
7693 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7694 +endif
7695 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7696 GCOV_PROFILE := n
7697
7698 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7699 index 878e4b9..20537ab 100644
7700 --- a/arch/x86/boot/bitops.h
7701 +++ b/arch/x86/boot/bitops.h
7702 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7703 u8 v;
7704 const u32 *p = (const u32 *)addr;
7705
7706 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7707 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7708 return v;
7709 }
7710
7711 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7712
7713 static inline void set_bit(int nr, void *addr)
7714 {
7715 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7716 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7717 }
7718
7719 #endif /* BOOT_BITOPS_H */
7720 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7721 index 18997e5..83d9c67 100644
7722 --- a/arch/x86/boot/boot.h
7723 +++ b/arch/x86/boot/boot.h
7724 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7725 static inline u16 ds(void)
7726 {
7727 u16 seg;
7728 - asm("movw %%ds,%0" : "=rm" (seg));
7729 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7730 return seg;
7731 }
7732
7733 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7734 static inline int memcmp(const void *s1, const void *s2, size_t len)
7735 {
7736 u8 diff;
7737 - asm("repe; cmpsb; setnz %0"
7738 + asm volatile("repe; cmpsb; setnz %0"
7739 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7740 return diff;
7741 }
7742 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7743 index 8a84501..b2d165f 100644
7744 --- a/arch/x86/boot/compressed/Makefile
7745 +++ b/arch/x86/boot/compressed/Makefile
7746 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7747 KBUILD_CFLAGS += $(cflags-y)
7748 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7749 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7750 +ifdef CONSTIFY_PLUGIN
7751 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7752 +endif
7753
7754 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7755 GCOV_PROFILE := n
7756 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7757 index b3e0227..f2c02d5 100644
7758 --- a/arch/x86/boot/compressed/eboot.c
7759 +++ b/arch/x86/boot/compressed/eboot.c
7760 @@ -142,7 +142,6 @@ again:
7761 *addr = max_addr;
7762 }
7763
7764 -free_pool:
7765 efi_call_phys1(sys_table->boottime->free_pool, map);
7766
7767 fail:
7768 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7769 if (i == map_size / desc_size)
7770 status = EFI_NOT_FOUND;
7771
7772 -free_pool:
7773 efi_call_phys1(sys_table->boottime->free_pool, map);
7774 fail:
7775 return status;
7776 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7777 index aa4aaf1..6656f2f 100644
7778 --- a/arch/x86/boot/compressed/head_32.S
7779 +++ b/arch/x86/boot/compressed/head_32.S
7780 @@ -116,7 +116,7 @@ preferred_addr:
7781 notl %eax
7782 andl %eax, %ebx
7783 #else
7784 - movl $LOAD_PHYSICAL_ADDR, %ebx
7785 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7786 #endif
7787
7788 /* Target address to relocate to for decompression */
7789 @@ -202,7 +202,7 @@ relocated:
7790 * and where it was actually loaded.
7791 */
7792 movl %ebp, %ebx
7793 - subl $LOAD_PHYSICAL_ADDR, %ebx
7794 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7795 jz 2f /* Nothing to be done if loaded at compiled addr. */
7796 /*
7797 * Process relocations.
7798 @@ -210,8 +210,7 @@ relocated:
7799
7800 1: subl $4, %edi
7801 movl (%edi), %ecx
7802 - testl %ecx, %ecx
7803 - jz 2f
7804 + jecxz 2f
7805 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7806 jmp 1b
7807 2:
7808 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7809 index 2c4b171..e1fa5b1 100644
7810 --- a/arch/x86/boot/compressed/head_64.S
7811 +++ b/arch/x86/boot/compressed/head_64.S
7812 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7813 notl %eax
7814 andl %eax, %ebx
7815 #else
7816 - movl $LOAD_PHYSICAL_ADDR, %ebx
7817 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7818 #endif
7819
7820 /* Target address to relocate to for decompression */
7821 @@ -273,7 +273,7 @@ preferred_addr:
7822 notq %rax
7823 andq %rax, %rbp
7824 #else
7825 - movq $LOAD_PHYSICAL_ADDR, %rbp
7826 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7827 #endif
7828
7829 /* Target address to relocate to for decompression */
7830 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7831 index 88f7ff6..ed695dd 100644
7832 --- a/arch/x86/boot/compressed/misc.c
7833 +++ b/arch/x86/boot/compressed/misc.c
7834 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7835 case PT_LOAD:
7836 #ifdef CONFIG_RELOCATABLE
7837 dest = output;
7838 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7839 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7840 #else
7841 dest = (void *)(phdr->p_paddr);
7842 #endif
7843 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7844 error("Destination address too large");
7845 #endif
7846 #ifndef CONFIG_RELOCATABLE
7847 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7848 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7849 error("Wrong destination address");
7850 #endif
7851
7852 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7853 index 4d3ff03..e4972ff 100644
7854 --- a/arch/x86/boot/cpucheck.c
7855 +++ b/arch/x86/boot/cpucheck.c
7856 @@ -74,7 +74,7 @@ static int has_fpu(void)
7857 u16 fcw = -1, fsw = -1;
7858 u32 cr0;
7859
7860 - asm("movl %%cr0,%0" : "=r" (cr0));
7861 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7862 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7863 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7864 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7865 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7866 {
7867 u32 f0, f1;
7868
7869 - asm("pushfl ; "
7870 + asm volatile("pushfl ; "
7871 "pushfl ; "
7872 "popl %0 ; "
7873 "movl %0,%1 ; "
7874 @@ -115,7 +115,7 @@ static void get_flags(void)
7875 set_bit(X86_FEATURE_FPU, cpu.flags);
7876
7877 if (has_eflag(X86_EFLAGS_ID)) {
7878 - asm("cpuid"
7879 + asm volatile("cpuid"
7880 : "=a" (max_intel_level),
7881 "=b" (cpu_vendor[0]),
7882 "=d" (cpu_vendor[1]),
7883 @@ -124,7 +124,7 @@ static void get_flags(void)
7884
7885 if (max_intel_level >= 0x00000001 &&
7886 max_intel_level <= 0x0000ffff) {
7887 - asm("cpuid"
7888 + asm volatile("cpuid"
7889 : "=a" (tfms),
7890 "=c" (cpu.flags[4]),
7891 "=d" (cpu.flags[0])
7892 @@ -136,7 +136,7 @@ static void get_flags(void)
7893 cpu.model += ((tfms >> 16) & 0xf) << 4;
7894 }
7895
7896 - asm("cpuid"
7897 + asm volatile("cpuid"
7898 : "=a" (max_amd_level)
7899 : "a" (0x80000000)
7900 : "ebx", "ecx", "edx");
7901 @@ -144,7 +144,7 @@ static void get_flags(void)
7902 if (max_amd_level >= 0x80000001 &&
7903 max_amd_level <= 0x8000ffff) {
7904 u32 eax = 0x80000001;
7905 - asm("cpuid"
7906 + asm volatile("cpuid"
7907 : "+a" (eax),
7908 "=c" (cpu.flags[6]),
7909 "=d" (cpu.flags[1])
7910 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7911 u32 ecx = MSR_K7_HWCR;
7912 u32 eax, edx;
7913
7914 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7915 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7916 eax &= ~(1 << 15);
7917 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7918 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7919
7920 get_flags(); /* Make sure it really did something */
7921 err = check_flags();
7922 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7923 u32 ecx = MSR_VIA_FCR;
7924 u32 eax, edx;
7925
7926 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7927 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7928 eax |= (1<<1)|(1<<7);
7929 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7930 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7931
7932 set_bit(X86_FEATURE_CX8, cpu.flags);
7933 err = check_flags();
7934 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7935 u32 eax, edx;
7936 u32 level = 1;
7937
7938 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7939 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7940 - asm("cpuid"
7941 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7942 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7943 + asm volatile("cpuid"
7944 : "+a" (level), "=d" (cpu.flags[0])
7945 : : "ecx", "ebx");
7946 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7947 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7948
7949 err = check_flags();
7950 }
7951 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7952 index b4e15dd..8ac59ce 100644
7953 --- a/arch/x86/boot/header.S
7954 +++ b/arch/x86/boot/header.S
7955 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7956 # single linked list of
7957 # struct setup_data
7958
7959 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7960 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7961
7962 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7963 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7964 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7965 +#else
7966 #define VO_INIT_SIZE (VO__end - VO__text)
7967 +#endif
7968 #if ZO_INIT_SIZE > VO_INIT_SIZE
7969 #define INIT_SIZE ZO_INIT_SIZE
7970 #else
7971 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7972 index db75d07..8e6d0af 100644
7973 --- a/arch/x86/boot/memory.c
7974 +++ b/arch/x86/boot/memory.c
7975 @@ -19,7 +19,7 @@
7976
7977 static int detect_memory_e820(void)
7978 {
7979 - int count = 0;
7980 + unsigned int count = 0;
7981 struct biosregs ireg, oreg;
7982 struct e820entry *desc = boot_params.e820_map;
7983 static struct e820entry buf; /* static so it is zeroed */
7984 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7985 index 11e8c6e..fdbb1ed 100644
7986 --- a/arch/x86/boot/video-vesa.c
7987 +++ b/arch/x86/boot/video-vesa.c
7988 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7989
7990 boot_params.screen_info.vesapm_seg = oreg.es;
7991 boot_params.screen_info.vesapm_off = oreg.di;
7992 + boot_params.screen_info.vesapm_size = oreg.cx;
7993 }
7994
7995 /*
7996 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
7997 index 43eda28..5ab5fdb 100644
7998 --- a/arch/x86/boot/video.c
7999 +++ b/arch/x86/boot/video.c
8000 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8001 static unsigned int get_entry(void)
8002 {
8003 char entry_buf[4];
8004 - int i, len = 0;
8005 + unsigned int i, len = 0;
8006 int key;
8007 unsigned int v;
8008
8009 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8010 index 5b577d5..3c1fed4 100644
8011 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8012 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8013 @@ -8,6 +8,8 @@
8014 * including this sentence is retained in full.
8015 */
8016
8017 +#include <asm/alternative-asm.h>
8018 +
8019 .extern crypto_ft_tab
8020 .extern crypto_it_tab
8021 .extern crypto_fl_tab
8022 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8023 je B192; \
8024 leaq 32(r9),r9;
8025
8026 +#define ret pax_force_retaddr 0, 1; ret
8027 +
8028 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8029 movq r1,r2; \
8030 movq r3,r4; \
8031 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8032 index 3470624..201259d 100644
8033 --- a/arch/x86/crypto/aesni-intel_asm.S
8034 +++ b/arch/x86/crypto/aesni-intel_asm.S
8035 @@ -31,6 +31,7 @@
8036
8037 #include <linux/linkage.h>
8038 #include <asm/inst.h>
8039 +#include <asm/alternative-asm.h>
8040
8041 #ifdef __x86_64__
8042 .data
8043 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8044 pop %r14
8045 pop %r13
8046 pop %r12
8047 + pax_force_retaddr 0, 1
8048 ret
8049 +ENDPROC(aesni_gcm_dec)
8050
8051
8052 /*****************************************************************************
8053 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8054 pop %r14
8055 pop %r13
8056 pop %r12
8057 + pax_force_retaddr 0, 1
8058 ret
8059 +ENDPROC(aesni_gcm_enc)
8060
8061 #endif
8062
8063 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8064 pxor %xmm1, %xmm0
8065 movaps %xmm0, (TKEYP)
8066 add $0x10, TKEYP
8067 + pax_force_retaddr_bts
8068 ret
8069
8070 .align 4
8071 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8072 shufps $0b01001110, %xmm2, %xmm1
8073 movaps %xmm1, 0x10(TKEYP)
8074 add $0x20, TKEYP
8075 + pax_force_retaddr_bts
8076 ret
8077
8078 .align 4
8079 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8080
8081 movaps %xmm0, (TKEYP)
8082 add $0x10, TKEYP
8083 + pax_force_retaddr_bts
8084 ret
8085
8086 .align 4
8087 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8088 pxor %xmm1, %xmm2
8089 movaps %xmm2, (TKEYP)
8090 add $0x10, TKEYP
8091 + pax_force_retaddr_bts
8092 ret
8093
8094 /*
8095 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8096 #ifndef __x86_64__
8097 popl KEYP
8098 #endif
8099 + pax_force_retaddr 0, 1
8100 ret
8101 +ENDPROC(aesni_set_key)
8102
8103 /*
8104 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8105 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8106 popl KLEN
8107 popl KEYP
8108 #endif
8109 + pax_force_retaddr 0, 1
8110 ret
8111 +ENDPROC(aesni_enc)
8112
8113 /*
8114 * _aesni_enc1: internal ABI
8115 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8116 AESENC KEY STATE
8117 movaps 0x70(TKEYP), KEY
8118 AESENCLAST KEY STATE
8119 + pax_force_retaddr_bts
8120 ret
8121
8122 /*
8123 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8124 AESENCLAST KEY STATE2
8125 AESENCLAST KEY STATE3
8126 AESENCLAST KEY STATE4
8127 + pax_force_retaddr_bts
8128 ret
8129
8130 /*
8131 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8132 popl KLEN
8133 popl KEYP
8134 #endif
8135 + pax_force_retaddr 0, 1
8136 ret
8137 +ENDPROC(aesni_dec)
8138
8139 /*
8140 * _aesni_dec1: internal ABI
8141 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8142 AESDEC KEY STATE
8143 movaps 0x70(TKEYP), KEY
8144 AESDECLAST KEY STATE
8145 + pax_force_retaddr_bts
8146 ret
8147
8148 /*
8149 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8150 AESDECLAST KEY STATE2
8151 AESDECLAST KEY STATE3
8152 AESDECLAST KEY STATE4
8153 + pax_force_retaddr_bts
8154 ret
8155
8156 /*
8157 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8158 popl KEYP
8159 popl LEN
8160 #endif
8161 + pax_force_retaddr 0, 1
8162 ret
8163 +ENDPROC(aesni_ecb_enc)
8164
8165 /*
8166 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8167 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8168 popl KEYP
8169 popl LEN
8170 #endif
8171 + pax_force_retaddr 0, 1
8172 ret
8173 +ENDPROC(aesni_ecb_dec)
8174
8175 /*
8176 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8177 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8178 popl LEN
8179 popl IVP
8180 #endif
8181 + pax_force_retaddr 0, 1
8182 ret
8183 +ENDPROC(aesni_cbc_enc)
8184
8185 /*
8186 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8187 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8188 popl LEN
8189 popl IVP
8190 #endif
8191 + pax_force_retaddr 0, 1
8192 ret
8193 +ENDPROC(aesni_cbc_dec)
8194
8195 #ifdef __x86_64__
8196 .align 16
8197 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8198 mov $1, TCTR_LOW
8199 MOVQ_R64_XMM TCTR_LOW INC
8200 MOVQ_R64_XMM CTR TCTR_LOW
8201 + pax_force_retaddr_bts
8202 ret
8203
8204 /*
8205 @@ -2554,6 +2582,7 @@ _aesni_inc:
8206 .Linc_low:
8207 movaps CTR, IV
8208 PSHUFB_XMM BSWAP_MASK IV
8209 + pax_force_retaddr_bts
8210 ret
8211
8212 /*
8213 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8214 .Lctr_enc_ret:
8215 movups IV, (IVP)
8216 .Lctr_enc_just_ret:
8217 + pax_force_retaddr 0, 1
8218 ret
8219 +ENDPROC(aesni_ctr_enc)
8220 #endif
8221 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8222 index 391d245..67f35c2 100644
8223 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8224 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8225 @@ -20,6 +20,8 @@
8226 *
8227 */
8228
8229 +#include <asm/alternative-asm.h>
8230 +
8231 .file "blowfish-x86_64-asm.S"
8232 .text
8233
8234 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8235 jnz __enc_xor;
8236
8237 write_block();
8238 + pax_force_retaddr 0, 1
8239 ret;
8240 __enc_xor:
8241 xor_block();
8242 + pax_force_retaddr 0, 1
8243 ret;
8244
8245 .align 8
8246 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8247
8248 movq %r11, %rbp;
8249
8250 + pax_force_retaddr 0, 1
8251 ret;
8252
8253 /**********************************************************************
8254 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8255
8256 popq %rbx;
8257 popq %rbp;
8258 + pax_force_retaddr 0, 1
8259 ret;
8260
8261 __enc_xor4:
8262 @@ -349,6 +355,7 @@ __enc_xor4:
8263
8264 popq %rbx;
8265 popq %rbp;
8266 + pax_force_retaddr 0, 1
8267 ret;
8268
8269 .align 8
8270 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8271 popq %rbx;
8272 popq %rbp;
8273
8274 + pax_force_retaddr 0, 1
8275 ret;
8276
8277 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8278 index 0b33743..7a56206 100644
8279 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8280 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8281 @@ -20,6 +20,8 @@
8282 *
8283 */
8284
8285 +#include <asm/alternative-asm.h>
8286 +
8287 .file "camellia-x86_64-asm_64.S"
8288 .text
8289
8290 @@ -229,12 +231,14 @@ __enc_done:
8291 enc_outunpack(mov, RT1);
8292
8293 movq RRBP, %rbp;
8294 + pax_force_retaddr 0, 1
8295 ret;
8296
8297 __enc_xor:
8298 enc_outunpack(xor, RT1);
8299
8300 movq RRBP, %rbp;
8301 + pax_force_retaddr 0, 1
8302 ret;
8303
8304 .global camellia_dec_blk;
8305 @@ -275,6 +279,7 @@ __dec_rounds16:
8306 dec_outunpack();
8307
8308 movq RRBP, %rbp;
8309 + pax_force_retaddr 0, 1
8310 ret;
8311
8312 /**********************************************************************
8313 @@ -468,6 +473,7 @@ __enc2_done:
8314
8315 movq RRBP, %rbp;
8316 popq %rbx;
8317 + pax_force_retaddr 0, 1
8318 ret;
8319
8320 __enc2_xor:
8321 @@ -475,6 +481,7 @@ __enc2_xor:
8322
8323 movq RRBP, %rbp;
8324 popq %rbx;
8325 + pax_force_retaddr 0, 1
8326 ret;
8327
8328 .global camellia_dec_blk_2way;
8329 @@ -517,4 +524,5 @@ __dec2_rounds16:
8330
8331 movq RRBP, %rbp;
8332 movq RXOR, %rbx;
8333 + pax_force_retaddr 0, 1
8334 ret;
8335 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8336 index 6214a9b..1f4fc9a 100644
8337 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8338 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8339 @@ -1,3 +1,5 @@
8340 +#include <asm/alternative-asm.h>
8341 +
8342 # enter ECRYPT_encrypt_bytes
8343 .text
8344 .p2align 5
8345 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8346 add %r11,%rsp
8347 mov %rdi,%rax
8348 mov %rsi,%rdx
8349 + pax_force_retaddr 0, 1
8350 ret
8351 # bytesatleast65:
8352 ._bytesatleast65:
8353 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8354 add %r11,%rsp
8355 mov %rdi,%rax
8356 mov %rsi,%rdx
8357 + pax_force_retaddr
8358 ret
8359 # enter ECRYPT_ivsetup
8360 .text
8361 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8362 add %r11,%rsp
8363 mov %rdi,%rax
8364 mov %rsi,%rdx
8365 + pax_force_retaddr
8366 ret
8367 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8368 index 504106b..4e50951 100644
8369 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8370 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8371 @@ -24,6 +24,8 @@
8372 *
8373 */
8374
8375 +#include <asm/alternative-asm.h>
8376 +
8377 .file "serpent-avx-x86_64-asm_64.S"
8378 .text
8379
8380 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8381 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8382 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8383
8384 + pax_force_retaddr
8385 ret;
8386
8387 __enc_xor8:
8388 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8389 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8390
8391 + pax_force_retaddr
8392 ret;
8393
8394 .align 8
8395 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8396 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8397 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8398
8399 + pax_force_retaddr
8400 ret;
8401 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8402 index 3ee1ff0..cbc568b 100644
8403 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8404 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8405 @@ -24,6 +24,8 @@
8406 *
8407 */
8408
8409 +#include <asm/alternative-asm.h>
8410 +
8411 .file "serpent-sse2-x86_64-asm_64.S"
8412 .text
8413
8414 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8415 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8416 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8417
8418 + pax_force_retaddr
8419 ret;
8420
8421 __enc_xor8:
8422 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8423 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8424
8425 + pax_force_retaddr
8426 ret;
8427
8428 .align 8
8429 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8430 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8431 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8432
8433 + pax_force_retaddr
8434 ret;
8435 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8436 index 49d6987..df66bd4 100644
8437 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8438 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8439 @@ -28,6 +28,8 @@
8440 * (at your option) any later version.
8441 */
8442
8443 +#include <asm/alternative-asm.h>
8444 +
8445 #define CTX %rdi // arg1
8446 #define BUF %rsi // arg2
8447 #define CNT %rdx // arg3
8448 @@ -104,6 +106,7 @@
8449 pop %r12
8450 pop %rbp
8451 pop %rbx
8452 + pax_force_retaddr 0, 1
8453 ret
8454
8455 .size \name, .-\name
8456 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8457 index 35f4557..16b379f 100644
8458 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8459 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8460 @@ -21,6 +21,8 @@
8461 *
8462 */
8463
8464 +#include <asm/alternative-asm.h>
8465 +
8466 .file "twofish-avx-x86_64-asm_64.S"
8467 .text
8468
8469 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8470 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8471 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8472
8473 + pax_force_retaddr
8474 ret;
8475
8476 __enc_xor8:
8477 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8478 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8479
8480 + pax_force_retaddr
8481 ret;
8482
8483 .align 8
8484 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8485 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8486 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8487
8488 + pax_force_retaddr
8489 ret;
8490 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8491 index 5b012a2..36d5364 100644
8492 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8493 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8494 @@ -20,6 +20,8 @@
8495 *
8496 */
8497
8498 +#include <asm/alternative-asm.h>
8499 +
8500 .file "twofish-x86_64-asm-3way.S"
8501 .text
8502
8503 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8504 popq %r13;
8505 popq %r14;
8506 popq %r15;
8507 + pax_force_retaddr 0, 1
8508 ret;
8509
8510 __enc_xor3:
8511 @@ -271,6 +274,7 @@ __enc_xor3:
8512 popq %r13;
8513 popq %r14;
8514 popq %r15;
8515 + pax_force_retaddr 0, 1
8516 ret;
8517
8518 .global twofish_dec_blk_3way
8519 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8520 popq %r13;
8521 popq %r14;
8522 popq %r15;
8523 + pax_force_retaddr 0, 1
8524 ret;
8525
8526 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8527 index 7bcf3fc..f53832f 100644
8528 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8529 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8530 @@ -21,6 +21,7 @@
8531 .text
8532
8533 #include <asm/asm-offsets.h>
8534 +#include <asm/alternative-asm.h>
8535
8536 #define a_offset 0
8537 #define b_offset 4
8538 @@ -268,6 +269,7 @@ twofish_enc_blk:
8539
8540 popq R1
8541 movq $1,%rax
8542 + pax_force_retaddr 0, 1
8543 ret
8544
8545 twofish_dec_blk:
8546 @@ -319,4 +321,5 @@ twofish_dec_blk:
8547
8548 popq R1
8549 movq $1,%rax
8550 + pax_force_retaddr 0, 1
8551 ret
8552 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8553 index 07b3a68..bd2a388 100644
8554 --- a/arch/x86/ia32/ia32_aout.c
8555 +++ b/arch/x86/ia32/ia32_aout.c
8556 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8557 unsigned long dump_start, dump_size;
8558 struct user32 dump;
8559
8560 + memset(&dump, 0, sizeof(dump));
8561 +
8562 fs = get_fs();
8563 set_fs(KERNEL_DS);
8564 has_dumped = 1;
8565 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8566 index 673ac9b..7a8c5df 100644
8567 --- a/arch/x86/ia32/ia32_signal.c
8568 +++ b/arch/x86/ia32/ia32_signal.c
8569 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8570 }
8571 seg = get_fs();
8572 set_fs(KERNEL_DS);
8573 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8574 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8575 set_fs(seg);
8576 if (ret >= 0 && uoss_ptr) {
8577 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8578 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8579 */
8580 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8581 size_t frame_size,
8582 - void **fpstate)
8583 + void __user **fpstate)
8584 {
8585 unsigned long sp;
8586
8587 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8588
8589 if (used_math()) {
8590 sp = sp - sig_xstate_ia32_size;
8591 - *fpstate = (struct _fpstate_ia32 *) sp;
8592 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8593 if (save_i387_xstate_ia32(*fpstate) < 0)
8594 return (void __user *) -1L;
8595 }
8596 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8597 sp -= frame_size;
8598 /* Align the stack pointer according to the i386 ABI,
8599 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8600 - sp = ((sp + 4) & -16ul) - 4;
8601 + sp = ((sp - 12) & -16ul) - 4;
8602 return (void __user *) sp;
8603 }
8604
8605 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8606 * These are actually not used anymore, but left because some
8607 * gdb versions depend on them as a marker.
8608 */
8609 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8610 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8611 } put_user_catch(err);
8612
8613 if (err)
8614 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8615 0xb8,
8616 __NR_ia32_rt_sigreturn,
8617 0x80cd,
8618 - 0,
8619 + 0
8620 };
8621
8622 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8623 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8624
8625 if (ka->sa.sa_flags & SA_RESTORER)
8626 restorer = ka->sa.sa_restorer;
8627 + else if (current->mm->context.vdso)
8628 + /* Return stub is in 32bit vsyscall page */
8629 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8630 else
8631 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8632 - rt_sigreturn);
8633 + restorer = &frame->retcode;
8634 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8635
8636 /*
8637 * Not actually used anymore, but left because some gdb
8638 * versions need it.
8639 */
8640 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8641 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8642 } put_user_catch(err);
8643
8644 if (err)
8645 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8646 index 20e5f7b..f33c779 100644
8647 --- a/arch/x86/ia32/ia32entry.S
8648 +++ b/arch/x86/ia32/ia32entry.S
8649 @@ -14,8 +14,10 @@
8650 #include <asm/segment.h>
8651 #include <asm/irqflags.h>
8652 #include <asm/asm.h>
8653 +#include <asm/pgtable.h>
8654 #include <linux/linkage.h>
8655 #include <linux/err.h>
8656 +#include <asm/alternative-asm.h>
8657
8658 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8659 #include <linux/elf-em.h>
8660 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8661 ENDPROC(native_irq_enable_sysexit)
8662 #endif
8663
8664 + .macro pax_enter_kernel_user
8665 + pax_set_fptr_mask
8666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8667 + call pax_enter_kernel_user
8668 +#endif
8669 + .endm
8670 +
8671 + .macro pax_exit_kernel_user
8672 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8673 + call pax_exit_kernel_user
8674 +#endif
8675 +#ifdef CONFIG_PAX_RANDKSTACK
8676 + pushq %rax
8677 + pushq %r11
8678 + call pax_randomize_kstack
8679 + popq %r11
8680 + popq %rax
8681 +#endif
8682 + .endm
8683 +
8684 +.macro pax_erase_kstack
8685 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8686 + call pax_erase_kstack
8687 +#endif
8688 +.endm
8689 +
8690 /*
8691 * 32bit SYSENTER instruction entry.
8692 *
8693 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8694 CFI_REGISTER rsp,rbp
8695 SWAPGS_UNSAFE_STACK
8696 movq PER_CPU_VAR(kernel_stack), %rsp
8697 - addq $(KERNEL_STACK_OFFSET),%rsp
8698 - /*
8699 - * No need to follow this irqs on/off section: the syscall
8700 - * disabled irqs, here we enable it straight after entry:
8701 - */
8702 - ENABLE_INTERRUPTS(CLBR_NONE)
8703 movl %ebp,%ebp /* zero extension */
8704 pushq_cfi $__USER32_DS
8705 /*CFI_REL_OFFSET ss,0*/
8706 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8707 CFI_REL_OFFSET rsp,0
8708 pushfq_cfi
8709 /*CFI_REL_OFFSET rflags,0*/
8710 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8711 - CFI_REGISTER rip,r10
8712 + orl $X86_EFLAGS_IF,(%rsp)
8713 + GET_THREAD_INFO(%r11)
8714 + movl TI_sysenter_return(%r11), %r11d
8715 + CFI_REGISTER rip,r11
8716 pushq_cfi $__USER32_CS
8717 /*CFI_REL_OFFSET cs,0*/
8718 movl %eax, %eax
8719 - pushq_cfi %r10
8720 + pushq_cfi %r11
8721 CFI_REL_OFFSET rip,0
8722 pushq_cfi %rax
8723 cld
8724 SAVE_ARGS 0,1,0
8725 + pax_enter_kernel_user
8726 +
8727 +#ifdef CONFIG_PAX_RANDKSTACK
8728 + pax_erase_kstack
8729 +#endif
8730 +
8731 + /*
8732 + * No need to follow this irqs on/off section: the syscall
8733 + * disabled irqs, here we enable it straight after entry:
8734 + */
8735 + ENABLE_INTERRUPTS(CLBR_NONE)
8736 /* no need to do an access_ok check here because rbp has been
8737 32bit zero extended */
8738 +
8739 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8740 + mov $PAX_USER_SHADOW_BASE,%r11
8741 + add %r11,%rbp
8742 +#endif
8743 +
8744 1: movl (%rbp),%ebp
8745 _ASM_EXTABLE(1b,ia32_badarg)
8746 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8747 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8748 + GET_THREAD_INFO(%r11)
8749 + orl $TS_COMPAT,TI_status(%r11)
8750 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8751 CFI_REMEMBER_STATE
8752 jnz sysenter_tracesys
8753 cmpq $(IA32_NR_syscalls-1),%rax
8754 @@ -159,12 +201,15 @@ sysenter_do_call:
8755 sysenter_dispatch:
8756 call *ia32_sys_call_table(,%rax,8)
8757 movq %rax,RAX-ARGOFFSET(%rsp)
8758 + GET_THREAD_INFO(%r11)
8759 DISABLE_INTERRUPTS(CLBR_NONE)
8760 TRACE_IRQS_OFF
8761 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8762 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8763 jnz sysexit_audit
8764 sysexit_from_sys_call:
8765 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8766 + pax_exit_kernel_user
8767 + pax_erase_kstack
8768 + andl $~TS_COMPAT,TI_status(%r11)
8769 /* clear IF, that popfq doesn't enable interrupts early */
8770 andl $~0x200,EFLAGS-R11(%rsp)
8771 movl RIP-R11(%rsp),%edx /* User %eip */
8772 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8773 movl %eax,%esi /* 2nd arg: syscall number */
8774 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8775 call __audit_syscall_entry
8776 +
8777 + pax_erase_kstack
8778 +
8779 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8780 cmpq $(IA32_NR_syscalls-1),%rax
8781 ja ia32_badsys
8782 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8783 .endm
8784
8785 .macro auditsys_exit exit
8786 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8787 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8788 jnz ia32_ret_from_sys_call
8789 TRACE_IRQS_ON
8790 sti
8791 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8792 1: setbe %al /* 1 if error, 0 if not */
8793 movzbl %al,%edi /* zero-extend that into %edi */
8794 call __audit_syscall_exit
8795 + GET_THREAD_INFO(%r11)
8796 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8797 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8798 cli
8799 TRACE_IRQS_OFF
8800 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8801 + testl %edi,TI_flags(%r11)
8802 jz \exit
8803 CLEAR_RREGS -ARGOFFSET
8804 jmp int_with_check
8805 @@ -234,7 +283,7 @@ sysexit_audit:
8806
8807 sysenter_tracesys:
8808 #ifdef CONFIG_AUDITSYSCALL
8809 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8810 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8811 jz sysenter_auditsys
8812 #endif
8813 SAVE_REST
8814 @@ -246,6 +295,9 @@ sysenter_tracesys:
8815 RESTORE_REST
8816 cmpq $(IA32_NR_syscalls-1),%rax
8817 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8818 +
8819 + pax_erase_kstack
8820 +
8821 jmp sysenter_do_call
8822 CFI_ENDPROC
8823 ENDPROC(ia32_sysenter_target)
8824 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8825 ENTRY(ia32_cstar_target)
8826 CFI_STARTPROC32 simple
8827 CFI_SIGNAL_FRAME
8828 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8829 + CFI_DEF_CFA rsp,0
8830 CFI_REGISTER rip,rcx
8831 /*CFI_REGISTER rflags,r11*/
8832 SWAPGS_UNSAFE_STACK
8833 movl %esp,%r8d
8834 CFI_REGISTER rsp,r8
8835 movq PER_CPU_VAR(kernel_stack),%rsp
8836 + SAVE_ARGS 8*6,0,0
8837 + pax_enter_kernel_user
8838 +
8839 +#ifdef CONFIG_PAX_RANDKSTACK
8840 + pax_erase_kstack
8841 +#endif
8842 +
8843 /*
8844 * No need to follow this irqs on/off section: the syscall
8845 * disabled irqs and here we enable it straight after entry:
8846 */
8847 ENABLE_INTERRUPTS(CLBR_NONE)
8848 - SAVE_ARGS 8,0,0
8849 movl %eax,%eax /* zero extension */
8850 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8851 movq %rcx,RIP-ARGOFFSET(%rsp)
8852 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8853 /* no need to do an access_ok check here because r8 has been
8854 32bit zero extended */
8855 /* hardware stack frame is complete now */
8856 +
8857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8858 + mov $PAX_USER_SHADOW_BASE,%r11
8859 + add %r11,%r8
8860 +#endif
8861 +
8862 1: movl (%r8),%r9d
8863 _ASM_EXTABLE(1b,ia32_badarg)
8864 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8865 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8866 + GET_THREAD_INFO(%r11)
8867 + orl $TS_COMPAT,TI_status(%r11)
8868 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8869 CFI_REMEMBER_STATE
8870 jnz cstar_tracesys
8871 cmpq $IA32_NR_syscalls-1,%rax
8872 @@ -314,12 +379,15 @@ cstar_do_call:
8873 cstar_dispatch:
8874 call *ia32_sys_call_table(,%rax,8)
8875 movq %rax,RAX-ARGOFFSET(%rsp)
8876 + GET_THREAD_INFO(%r11)
8877 DISABLE_INTERRUPTS(CLBR_NONE)
8878 TRACE_IRQS_OFF
8879 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8880 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8881 jnz sysretl_audit
8882 sysretl_from_sys_call:
8883 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8884 + pax_exit_kernel_user
8885 + pax_erase_kstack
8886 + andl $~TS_COMPAT,TI_status(%r11)
8887 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8888 movl RIP-ARGOFFSET(%rsp),%ecx
8889 CFI_REGISTER rip,rcx
8890 @@ -347,7 +415,7 @@ sysretl_audit:
8891
8892 cstar_tracesys:
8893 #ifdef CONFIG_AUDITSYSCALL
8894 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8895 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8896 jz cstar_auditsys
8897 #endif
8898 xchgl %r9d,%ebp
8899 @@ -361,6 +429,9 @@ cstar_tracesys:
8900 xchgl %ebp,%r9d
8901 cmpq $(IA32_NR_syscalls-1),%rax
8902 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8903 +
8904 + pax_erase_kstack
8905 +
8906 jmp cstar_do_call
8907 END(ia32_cstar_target)
8908
8909 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8910 CFI_REL_OFFSET rip,RIP-RIP
8911 PARAVIRT_ADJUST_EXCEPTION_FRAME
8912 SWAPGS
8913 - /*
8914 - * No need to follow this irqs on/off section: the syscall
8915 - * disabled irqs and here we enable it straight after entry:
8916 - */
8917 - ENABLE_INTERRUPTS(CLBR_NONE)
8918 movl %eax,%eax
8919 pushq_cfi %rax
8920 cld
8921 /* note the registers are not zero extended to the sf.
8922 this could be a problem. */
8923 SAVE_ARGS 0,1,0
8924 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8925 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8926 + pax_enter_kernel_user
8927 +
8928 +#ifdef CONFIG_PAX_RANDKSTACK
8929 + pax_erase_kstack
8930 +#endif
8931 +
8932 + /*
8933 + * No need to follow this irqs on/off section: the syscall
8934 + * disabled irqs and here we enable it straight after entry:
8935 + */
8936 + ENABLE_INTERRUPTS(CLBR_NONE)
8937 + GET_THREAD_INFO(%r11)
8938 + orl $TS_COMPAT,TI_status(%r11)
8939 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8940 jnz ia32_tracesys
8941 cmpq $(IA32_NR_syscalls-1),%rax
8942 ja ia32_badsys
8943 @@ -436,6 +514,9 @@ ia32_tracesys:
8944 RESTORE_REST
8945 cmpq $(IA32_NR_syscalls-1),%rax
8946 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8947 +
8948 + pax_erase_kstack
8949 +
8950 jmp ia32_do_call
8951 END(ia32_syscall)
8952
8953 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8954 index 4540bec..714d913 100644
8955 --- a/arch/x86/ia32/sys_ia32.c
8956 +++ b/arch/x86/ia32/sys_ia32.c
8957 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8958 */
8959 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8960 {
8961 - typeof(ubuf->st_uid) uid = 0;
8962 - typeof(ubuf->st_gid) gid = 0;
8963 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8964 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8965 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8966 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8967 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8968 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8969 return ret;
8970 }
8971
8972 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8973 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8974 int options)
8975 {
8976 return compat_sys_wait4(pid, stat_addr, options, NULL);
8977 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8978 mm_segment_t old_fs = get_fs();
8979
8980 set_fs(KERNEL_DS);
8981 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8982 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8983 set_fs(old_fs);
8984 if (put_compat_timespec(&t, interval))
8985 return -EFAULT;
8986 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8987 mm_segment_t old_fs = get_fs();
8988
8989 set_fs(KERNEL_DS);
8990 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8991 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8992 set_fs(old_fs);
8993 if (!ret) {
8994 switch (_NSIG_WORDS) {
8995 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8996 if (copy_siginfo_from_user32(&info, uinfo))
8997 return -EFAULT;
8998 set_fs(KERNEL_DS);
8999 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9000 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9001 set_fs(old_fs);
9002 return ret;
9003 }
9004 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9005 return -EFAULT;
9006
9007 set_fs(KERNEL_DS);
9008 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9009 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9010 count);
9011 set_fs(old_fs);
9012
9013 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9014 index 952bd01..7692c6f 100644
9015 --- a/arch/x86/include/asm/alternative-asm.h
9016 +++ b/arch/x86/include/asm/alternative-asm.h
9017 @@ -15,6 +15,45 @@
9018 .endm
9019 #endif
9020
9021 +#ifdef KERNEXEC_PLUGIN
9022 + .macro pax_force_retaddr_bts rip=0
9023 + btsq $63,\rip(%rsp)
9024 + .endm
9025 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9026 + .macro pax_force_retaddr rip=0, reload=0
9027 + btsq $63,\rip(%rsp)
9028 + .endm
9029 + .macro pax_force_fptr ptr
9030 + btsq $63,\ptr
9031 + .endm
9032 + .macro pax_set_fptr_mask
9033 + .endm
9034 +#endif
9035 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9036 + .macro pax_force_retaddr rip=0, reload=0
9037 + .if \reload
9038 + pax_set_fptr_mask
9039 + .endif
9040 + orq %r10,\rip(%rsp)
9041 + .endm
9042 + .macro pax_force_fptr ptr
9043 + orq %r10,\ptr
9044 + .endm
9045 + .macro pax_set_fptr_mask
9046 + movabs $0x8000000000000000,%r10
9047 + .endm
9048 +#endif
9049 +#else
9050 + .macro pax_force_retaddr rip=0, reload=0
9051 + .endm
9052 + .macro pax_force_fptr ptr
9053 + .endm
9054 + .macro pax_force_retaddr_bts rip=0
9055 + .endm
9056 + .macro pax_set_fptr_mask
9057 + .endm
9058 +#endif
9059 +
9060 .macro altinstruction_entry orig alt feature orig_len alt_len
9061 .long \orig - .
9062 .long \alt - .
9063 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9064 index 7078068..f58bcda 100644
9065 --- a/arch/x86/include/asm/alternative.h
9066 +++ b/arch/x86/include/asm/alternative.h
9067 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9068 ".section .discard,\"aw\",@progbits\n" \
9069 DISCARD_ENTRY(1) \
9070 ".previous\n" \
9071 - ".section .altinstr_replacement, \"ax\"\n" \
9072 + ".section .altinstr_replacement, \"a\"\n" \
9073 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9074 ".previous"
9075
9076 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9077 DISCARD_ENTRY(1) \
9078 DISCARD_ENTRY(2) \
9079 ".previous\n" \
9080 - ".section .altinstr_replacement, \"ax\"\n" \
9081 + ".section .altinstr_replacement, \"a\"\n" \
9082 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9083 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9084 ".previous"
9085 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9086 index f342612..b3fe911 100644
9087 --- a/arch/x86/include/asm/apic.h
9088 +++ b/arch/x86/include/asm/apic.h
9089 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9090
9091 #ifdef CONFIG_X86_LOCAL_APIC
9092
9093 -extern unsigned int apic_verbosity;
9094 +extern int apic_verbosity;
9095 extern int local_apic_timer_c2_ok;
9096
9097 extern int disable_apic;
9098 @@ -391,7 +391,7 @@ struct apic {
9099 */
9100 int (*x86_32_numa_cpu_node)(int cpu);
9101 #endif
9102 -};
9103 +} __do_const;
9104
9105 /*
9106 * Pointer to the local APIC driver in use on this system (there's
9107 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9108 index 20370c6..a2eb9b0 100644
9109 --- a/arch/x86/include/asm/apm.h
9110 +++ b/arch/x86/include/asm/apm.h
9111 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9112 __asm__ __volatile__(APM_DO_ZERO_SEGS
9113 "pushl %%edi\n\t"
9114 "pushl %%ebp\n\t"
9115 - "lcall *%%cs:apm_bios_entry\n\t"
9116 + "lcall *%%ss:apm_bios_entry\n\t"
9117 "setc %%al\n\t"
9118 "popl %%ebp\n\t"
9119 "popl %%edi\n\t"
9120 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9121 __asm__ __volatile__(APM_DO_ZERO_SEGS
9122 "pushl %%edi\n\t"
9123 "pushl %%ebp\n\t"
9124 - "lcall *%%cs:apm_bios_entry\n\t"
9125 + "lcall *%%ss:apm_bios_entry\n\t"
9126 "setc %%bl\n\t"
9127 "popl %%ebp\n\t"
9128 "popl %%edi\n\t"
9129 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9130 index 58cb6d4..a4b806c 100644
9131 --- a/arch/x86/include/asm/atomic.h
9132 +++ b/arch/x86/include/asm/atomic.h
9133 @@ -22,7 +22,18 @@
9134 */
9135 static inline int atomic_read(const atomic_t *v)
9136 {
9137 - return (*(volatile int *)&(v)->counter);
9138 + return (*(volatile const int *)&(v)->counter);
9139 +}
9140 +
9141 +/**
9142 + * atomic_read_unchecked - read atomic variable
9143 + * @v: pointer of type atomic_unchecked_t
9144 + *
9145 + * Atomically reads the value of @v.
9146 + */
9147 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9148 +{
9149 + return (*(volatile const int *)&(v)->counter);
9150 }
9151
9152 /**
9153 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9154 }
9155
9156 /**
9157 + * atomic_set_unchecked - set atomic variable
9158 + * @v: pointer of type atomic_unchecked_t
9159 + * @i: required value
9160 + *
9161 + * Atomically sets the value of @v to @i.
9162 + */
9163 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9164 +{
9165 + v->counter = i;
9166 +}
9167 +
9168 +/**
9169 * atomic_add - add integer to atomic variable
9170 * @i: integer value to add
9171 * @v: pointer of type atomic_t
9172 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9173 */
9174 static inline void atomic_add(int i, atomic_t *v)
9175 {
9176 - asm volatile(LOCK_PREFIX "addl %1,%0"
9177 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9178 +
9179 +#ifdef CONFIG_PAX_REFCOUNT
9180 + "jno 0f\n"
9181 + LOCK_PREFIX "subl %1,%0\n"
9182 + "int $4\n0:\n"
9183 + _ASM_EXTABLE(0b, 0b)
9184 +#endif
9185 +
9186 + : "+m" (v->counter)
9187 + : "ir" (i));
9188 +}
9189 +
9190 +/**
9191 + * atomic_add_unchecked - add integer to atomic variable
9192 + * @i: integer value to add
9193 + * @v: pointer of type atomic_unchecked_t
9194 + *
9195 + * Atomically adds @i to @v.
9196 + */
9197 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9198 +{
9199 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9200 : "+m" (v->counter)
9201 : "ir" (i));
9202 }
9203 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9204 */
9205 static inline void atomic_sub(int i, atomic_t *v)
9206 {
9207 - asm volatile(LOCK_PREFIX "subl %1,%0"
9208 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9209 +
9210 +#ifdef CONFIG_PAX_REFCOUNT
9211 + "jno 0f\n"
9212 + LOCK_PREFIX "addl %1,%0\n"
9213 + "int $4\n0:\n"
9214 + _ASM_EXTABLE(0b, 0b)
9215 +#endif
9216 +
9217 + : "+m" (v->counter)
9218 + : "ir" (i));
9219 +}
9220 +
9221 +/**
9222 + * atomic_sub_unchecked - subtract integer from atomic variable
9223 + * @i: integer value to subtract
9224 + * @v: pointer of type atomic_unchecked_t
9225 + *
9226 + * Atomically subtracts @i from @v.
9227 + */
9228 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9229 +{
9230 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9231 : "+m" (v->counter)
9232 : "ir" (i));
9233 }
9234 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9235 {
9236 unsigned char c;
9237
9238 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9239 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9240 +
9241 +#ifdef CONFIG_PAX_REFCOUNT
9242 + "jno 0f\n"
9243 + LOCK_PREFIX "addl %2,%0\n"
9244 + "int $4\n0:\n"
9245 + _ASM_EXTABLE(0b, 0b)
9246 +#endif
9247 +
9248 + "sete %1\n"
9249 : "+m" (v->counter), "=qm" (c)
9250 : "ir" (i) : "memory");
9251 return c;
9252 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9253 */
9254 static inline void atomic_inc(atomic_t *v)
9255 {
9256 - asm volatile(LOCK_PREFIX "incl %0"
9257 + asm volatile(LOCK_PREFIX "incl %0\n"
9258 +
9259 +#ifdef CONFIG_PAX_REFCOUNT
9260 + "jno 0f\n"
9261 + LOCK_PREFIX "decl %0\n"
9262 + "int $4\n0:\n"
9263 + _ASM_EXTABLE(0b, 0b)
9264 +#endif
9265 +
9266 + : "+m" (v->counter));
9267 +}
9268 +
9269 +/**
9270 + * atomic_inc_unchecked - increment atomic variable
9271 + * @v: pointer of type atomic_unchecked_t
9272 + *
9273 + * Atomically increments @v by 1.
9274 + */
9275 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9276 +{
9277 + asm volatile(LOCK_PREFIX "incl %0\n"
9278 : "+m" (v->counter));
9279 }
9280
9281 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9282 */
9283 static inline void atomic_dec(atomic_t *v)
9284 {
9285 - asm volatile(LOCK_PREFIX "decl %0"
9286 + asm volatile(LOCK_PREFIX "decl %0\n"
9287 +
9288 +#ifdef CONFIG_PAX_REFCOUNT
9289 + "jno 0f\n"
9290 + LOCK_PREFIX "incl %0\n"
9291 + "int $4\n0:\n"
9292 + _ASM_EXTABLE(0b, 0b)
9293 +#endif
9294 +
9295 + : "+m" (v->counter));
9296 +}
9297 +
9298 +/**
9299 + * atomic_dec_unchecked - decrement atomic variable
9300 + * @v: pointer of type atomic_unchecked_t
9301 + *
9302 + * Atomically decrements @v by 1.
9303 + */
9304 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9305 +{
9306 + asm volatile(LOCK_PREFIX "decl %0\n"
9307 : "+m" (v->counter));
9308 }
9309
9310 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9311 {
9312 unsigned char c;
9313
9314 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9315 + asm volatile(LOCK_PREFIX "decl %0\n"
9316 +
9317 +#ifdef CONFIG_PAX_REFCOUNT
9318 + "jno 0f\n"
9319 + LOCK_PREFIX "incl %0\n"
9320 + "int $4\n0:\n"
9321 + _ASM_EXTABLE(0b, 0b)
9322 +#endif
9323 +
9324 + "sete %1\n"
9325 : "+m" (v->counter), "=qm" (c)
9326 : : "memory");
9327 return c != 0;
9328 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9329 {
9330 unsigned char c;
9331
9332 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9333 + asm volatile(LOCK_PREFIX "incl %0\n"
9334 +
9335 +#ifdef CONFIG_PAX_REFCOUNT
9336 + "jno 0f\n"
9337 + LOCK_PREFIX "decl %0\n"
9338 + "int $4\n0:\n"
9339 + _ASM_EXTABLE(0b, 0b)
9340 +#endif
9341 +
9342 + "sete %1\n"
9343 + : "+m" (v->counter), "=qm" (c)
9344 + : : "memory");
9345 + return c != 0;
9346 +}
9347 +
9348 +/**
9349 + * atomic_inc_and_test_unchecked - increment and test
9350 + * @v: pointer of type atomic_unchecked_t
9351 + *
9352 + * Atomically increments @v by 1
9353 + * and returns true if the result is zero, or false for all
9354 + * other cases.
9355 + */
9356 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9357 +{
9358 + unsigned char c;
9359 +
9360 + asm volatile(LOCK_PREFIX "incl %0\n"
9361 + "sete %1\n"
9362 : "+m" (v->counter), "=qm" (c)
9363 : : "memory");
9364 return c != 0;
9365 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9366 {
9367 unsigned char c;
9368
9369 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9370 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9371 +
9372 +#ifdef CONFIG_PAX_REFCOUNT
9373 + "jno 0f\n"
9374 + LOCK_PREFIX "subl %2,%0\n"
9375 + "int $4\n0:\n"
9376 + _ASM_EXTABLE(0b, 0b)
9377 +#endif
9378 +
9379 + "sets %1\n"
9380 : "+m" (v->counter), "=qm" (c)
9381 : "ir" (i) : "memory");
9382 return c;
9383 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9384 goto no_xadd;
9385 #endif
9386 /* Modern 486+ processor */
9387 - return i + xadd(&v->counter, i);
9388 + return i + xadd_check_overflow(&v->counter, i);
9389
9390 #ifdef CONFIG_M386
9391 no_xadd: /* Legacy 386 processor */
9392 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9393 }
9394
9395 /**
9396 + * atomic_add_return_unchecked - add integer and return
9397 + * @i: integer value to add
9398 + * @v: pointer of type atomic_unchecked_t
9399 + *
9400 + * Atomically adds @i to @v and returns @i + @v
9401 + */
9402 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9403 +{
9404 +#ifdef CONFIG_M386
9405 + int __i;
9406 + unsigned long flags;
9407 + if (unlikely(boot_cpu_data.x86 <= 3))
9408 + goto no_xadd;
9409 +#endif
9410 + /* Modern 486+ processor */
9411 + return i + xadd(&v->counter, i);
9412 +
9413 +#ifdef CONFIG_M386
9414 +no_xadd: /* Legacy 386 processor */
9415 + raw_local_irq_save(flags);
9416 + __i = atomic_read_unchecked(v);
9417 + atomic_set_unchecked(v, i + __i);
9418 + raw_local_irq_restore(flags);
9419 + return i + __i;
9420 +#endif
9421 +}
9422 +
9423 +/**
9424 * atomic_sub_return - subtract integer and return
9425 * @v: pointer of type atomic_t
9426 * @i: integer value to subtract
9427 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9428 }
9429
9430 #define atomic_inc_return(v) (atomic_add_return(1, v))
9431 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9432 +{
9433 + return atomic_add_return_unchecked(1, v);
9434 +}
9435 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9436
9437 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9438 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9439 return cmpxchg(&v->counter, old, new);
9440 }
9441
9442 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9443 +{
9444 + return cmpxchg(&v->counter, old, new);
9445 +}
9446 +
9447 static inline int atomic_xchg(atomic_t *v, int new)
9448 {
9449 return xchg(&v->counter, new);
9450 }
9451
9452 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9453 +{
9454 + return xchg(&v->counter, new);
9455 +}
9456 +
9457 /**
9458 * __atomic_add_unless - add unless the number is already a given value
9459 * @v: pointer of type atomic_t
9460 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9461 */
9462 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9463 {
9464 - int c, old;
9465 + int c, old, new;
9466 c = atomic_read(v);
9467 for (;;) {
9468 - if (unlikely(c == (u)))
9469 + if (unlikely(c == u))
9470 break;
9471 - old = atomic_cmpxchg((v), c, c + (a));
9472 +
9473 + asm volatile("addl %2,%0\n"
9474 +
9475 +#ifdef CONFIG_PAX_REFCOUNT
9476 + "jno 0f\n"
9477 + "subl %2,%0\n"
9478 + "int $4\n0:\n"
9479 + _ASM_EXTABLE(0b, 0b)
9480 +#endif
9481 +
9482 + : "=r" (new)
9483 + : "0" (c), "ir" (a));
9484 +
9485 + old = atomic_cmpxchg(v, c, new);
9486 if (likely(old == c))
9487 break;
9488 c = old;
9489 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9490 return c;
9491 }
9492
9493 +/**
9494 + * atomic_inc_not_zero_hint - increment if not null
9495 + * @v: pointer of type atomic_t
9496 + * @hint: probable value of the atomic before the increment
9497 + *
9498 + * This version of atomic_inc_not_zero() gives a hint of probable
9499 + * value of the atomic. This helps processor to not read the memory
9500 + * before doing the atomic read/modify/write cycle, lowering
9501 + * number of bus transactions on some arches.
9502 + *
9503 + * Returns: 0 if increment was not done, 1 otherwise.
9504 + */
9505 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9506 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9507 +{
9508 + int val, c = hint, new;
9509 +
9510 + /* sanity test, should be removed by compiler if hint is a constant */
9511 + if (!hint)
9512 + return __atomic_add_unless(v, 1, 0);
9513 +
9514 + do {
9515 + asm volatile("incl %0\n"
9516 +
9517 +#ifdef CONFIG_PAX_REFCOUNT
9518 + "jno 0f\n"
9519 + "decl %0\n"
9520 + "int $4\n0:\n"
9521 + _ASM_EXTABLE(0b, 0b)
9522 +#endif
9523 +
9524 + : "=r" (new)
9525 + : "0" (c));
9526 +
9527 + val = atomic_cmpxchg(v, c, new);
9528 + if (val == c)
9529 + return 1;
9530 + c = val;
9531 + } while (c);
9532 +
9533 + return 0;
9534 +}
9535
9536 /*
9537 * atomic_dec_if_positive - decrement by 1 if old value positive
9538 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9539 #endif
9540
9541 /* These are x86-specific, used by some header files */
9542 -#define atomic_clear_mask(mask, addr) \
9543 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9544 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9545 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9546 +{
9547 + asm volatile(LOCK_PREFIX "andl %1,%0"
9548 + : "+m" (v->counter)
9549 + : "r" (~(mask))
9550 + : "memory");
9551 +}
9552
9553 -#define atomic_set_mask(mask, addr) \
9554 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9555 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9556 - : "memory")
9557 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9558 +{
9559 + asm volatile(LOCK_PREFIX "andl %1,%0"
9560 + : "+m" (v->counter)
9561 + : "r" (~(mask))
9562 + : "memory");
9563 +}
9564 +
9565 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9566 +{
9567 + asm volatile(LOCK_PREFIX "orl %1,%0"
9568 + : "+m" (v->counter)
9569 + : "r" (mask)
9570 + : "memory");
9571 +}
9572 +
9573 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9574 +{
9575 + asm volatile(LOCK_PREFIX "orl %1,%0"
9576 + : "+m" (v->counter)
9577 + : "r" (mask)
9578 + : "memory");
9579 +}
9580
9581 /* Atomic operations are already serializing on x86 */
9582 #define smp_mb__before_atomic_dec() barrier()
9583 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9584 index b154de7..aadebd8 100644
9585 --- a/arch/x86/include/asm/atomic64_32.h
9586 +++ b/arch/x86/include/asm/atomic64_32.h
9587 @@ -12,6 +12,14 @@ typedef struct {
9588 u64 __aligned(8) counter;
9589 } atomic64_t;
9590
9591 +#ifdef CONFIG_PAX_REFCOUNT
9592 +typedef struct {
9593 + u64 __aligned(8) counter;
9594 +} atomic64_unchecked_t;
9595 +#else
9596 +typedef atomic64_t atomic64_unchecked_t;
9597 +#endif
9598 +
9599 #define ATOMIC64_INIT(val) { (val) }
9600
9601 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9602 @@ -37,21 +45,31 @@ typedef struct {
9603 ATOMIC64_DECL_ONE(sym##_386)
9604
9605 ATOMIC64_DECL_ONE(add_386);
9606 +ATOMIC64_DECL_ONE(add_unchecked_386);
9607 ATOMIC64_DECL_ONE(sub_386);
9608 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9609 ATOMIC64_DECL_ONE(inc_386);
9610 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9611 ATOMIC64_DECL_ONE(dec_386);
9612 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9613 #endif
9614
9615 #define alternative_atomic64(f, out, in...) \
9616 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9617
9618 ATOMIC64_DECL(read);
9619 +ATOMIC64_DECL(read_unchecked);
9620 ATOMIC64_DECL(set);
9621 +ATOMIC64_DECL(set_unchecked);
9622 ATOMIC64_DECL(xchg);
9623 ATOMIC64_DECL(add_return);
9624 +ATOMIC64_DECL(add_return_unchecked);
9625 ATOMIC64_DECL(sub_return);
9626 +ATOMIC64_DECL(sub_return_unchecked);
9627 ATOMIC64_DECL(inc_return);
9628 +ATOMIC64_DECL(inc_return_unchecked);
9629 ATOMIC64_DECL(dec_return);
9630 +ATOMIC64_DECL(dec_return_unchecked);
9631 ATOMIC64_DECL(dec_if_positive);
9632 ATOMIC64_DECL(inc_not_zero);
9633 ATOMIC64_DECL(add_unless);
9634 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9635 }
9636
9637 /**
9638 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9639 + * @p: pointer to type atomic64_unchecked_t
9640 + * @o: expected value
9641 + * @n: new value
9642 + *
9643 + * Atomically sets @v to @n if it was equal to @o and returns
9644 + * the old value.
9645 + */
9646 +
9647 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9648 +{
9649 + return cmpxchg64(&v->counter, o, n);
9650 +}
9651 +
9652 +/**
9653 * atomic64_xchg - xchg atomic64 variable
9654 * @v: pointer to type atomic64_t
9655 * @n: value to assign
9656 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9657 }
9658
9659 /**
9660 + * atomic64_set_unchecked - set atomic64 variable
9661 + * @v: pointer to type atomic64_unchecked_t
9662 + * @n: value to assign
9663 + *
9664 + * Atomically sets the value of @v to @n.
9665 + */
9666 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9667 +{
9668 + unsigned high = (unsigned)(i >> 32);
9669 + unsigned low = (unsigned)i;
9670 + alternative_atomic64(set, /* no output */,
9671 + "S" (v), "b" (low), "c" (high)
9672 + : "eax", "edx", "memory");
9673 +}
9674 +
9675 +/**
9676 * atomic64_read - read atomic64 variable
9677 * @v: pointer to type atomic64_t
9678 *
9679 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9680 }
9681
9682 /**
9683 + * atomic64_read_unchecked - read atomic64 variable
9684 + * @v: pointer to type atomic64_unchecked_t
9685 + *
9686 + * Atomically reads the value of @v and returns it.
9687 + */
9688 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9689 +{
9690 + long long r;
9691 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9692 + return r;
9693 + }
9694 +
9695 +/**
9696 * atomic64_add_return - add and return
9697 * @i: integer value to add
9698 * @v: pointer to type atomic64_t
9699 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9700 return i;
9701 }
9702
9703 +/**
9704 + * atomic64_add_return_unchecked - add and return
9705 + * @i: integer value to add
9706 + * @v: pointer to type atomic64_unchecked_t
9707 + *
9708 + * Atomically adds @i to @v and returns @i + *@v
9709 + */
9710 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9711 +{
9712 + alternative_atomic64(add_return_unchecked,
9713 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9714 + ASM_NO_INPUT_CLOBBER("memory"));
9715 + return i;
9716 +}
9717 +
9718 /*
9719 * Other variants with different arithmetic operators:
9720 */
9721 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9722 return a;
9723 }
9724
9725 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9726 +{
9727 + long long a;
9728 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9729 + "S" (v) : "memory", "ecx");
9730 + return a;
9731 +}
9732 +
9733 static inline long long atomic64_dec_return(atomic64_t *v)
9734 {
9735 long long a;
9736 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9737 }
9738
9739 /**
9740 + * atomic64_add_unchecked - add integer to atomic64 variable
9741 + * @i: integer value to add
9742 + * @v: pointer to type atomic64_unchecked_t
9743 + *
9744 + * Atomically adds @i to @v.
9745 + */
9746 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9747 +{
9748 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9749 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9750 + ASM_NO_INPUT_CLOBBER("memory"));
9751 + return i;
9752 +}
9753 +
9754 +/**
9755 * atomic64_sub - subtract the atomic64 variable
9756 * @i: integer value to subtract
9757 * @v: pointer to type atomic64_t
9758 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9759 index 0e1cbfc..5623683 100644
9760 --- a/arch/x86/include/asm/atomic64_64.h
9761 +++ b/arch/x86/include/asm/atomic64_64.h
9762 @@ -18,7 +18,19 @@
9763 */
9764 static inline long atomic64_read(const atomic64_t *v)
9765 {
9766 - return (*(volatile long *)&(v)->counter);
9767 + return (*(volatile const long *)&(v)->counter);
9768 +}
9769 +
9770 +/**
9771 + * atomic64_read_unchecked - read atomic64 variable
9772 + * @v: pointer of type atomic64_unchecked_t
9773 + *
9774 + * Atomically reads the value of @v.
9775 + * Doesn't imply a read memory barrier.
9776 + */
9777 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9778 +{
9779 + return (*(volatile const long *)&(v)->counter);
9780 }
9781
9782 /**
9783 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9784 }
9785
9786 /**
9787 + * atomic64_set_unchecked - set atomic64 variable
9788 + * @v: pointer to type atomic64_unchecked_t
9789 + * @i: required value
9790 + *
9791 + * Atomically sets the value of @v to @i.
9792 + */
9793 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9794 +{
9795 + v->counter = i;
9796 +}
9797 +
9798 +/**
9799 * atomic64_add - add integer to atomic64 variable
9800 * @i: integer value to add
9801 * @v: pointer to type atomic64_t
9802 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9803 */
9804 static inline void atomic64_add(long i, atomic64_t *v)
9805 {
9806 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9807 +
9808 +#ifdef CONFIG_PAX_REFCOUNT
9809 + "jno 0f\n"
9810 + LOCK_PREFIX "subq %1,%0\n"
9811 + "int $4\n0:\n"
9812 + _ASM_EXTABLE(0b, 0b)
9813 +#endif
9814 +
9815 + : "=m" (v->counter)
9816 + : "er" (i), "m" (v->counter));
9817 +}
9818 +
9819 +/**
9820 + * atomic64_add_unchecked - add integer to atomic64 variable
9821 + * @i: integer value to add
9822 + * @v: pointer to type atomic64_unchecked_t
9823 + *
9824 + * Atomically adds @i to @v.
9825 + */
9826 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9827 +{
9828 asm volatile(LOCK_PREFIX "addq %1,%0"
9829 : "=m" (v->counter)
9830 : "er" (i), "m" (v->counter));
9831 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9832 */
9833 static inline void atomic64_sub(long i, atomic64_t *v)
9834 {
9835 - asm volatile(LOCK_PREFIX "subq %1,%0"
9836 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9837 +
9838 +#ifdef CONFIG_PAX_REFCOUNT
9839 + "jno 0f\n"
9840 + LOCK_PREFIX "addq %1,%0\n"
9841 + "int $4\n0:\n"
9842 + _ASM_EXTABLE(0b, 0b)
9843 +#endif
9844 +
9845 + : "=m" (v->counter)
9846 + : "er" (i), "m" (v->counter));
9847 +}
9848 +
9849 +/**
9850 + * atomic64_sub_unchecked - subtract the atomic64 variable
9851 + * @i: integer value to subtract
9852 + * @v: pointer to type atomic64_unchecked_t
9853 + *
9854 + * Atomically subtracts @i from @v.
9855 + */
9856 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9857 +{
9858 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9859 : "=m" (v->counter)
9860 : "er" (i), "m" (v->counter));
9861 }
9862 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9863 {
9864 unsigned char c;
9865
9866 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9867 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9868 +
9869 +#ifdef CONFIG_PAX_REFCOUNT
9870 + "jno 0f\n"
9871 + LOCK_PREFIX "addq %2,%0\n"
9872 + "int $4\n0:\n"
9873 + _ASM_EXTABLE(0b, 0b)
9874 +#endif
9875 +
9876 + "sete %1\n"
9877 : "=m" (v->counter), "=qm" (c)
9878 : "er" (i), "m" (v->counter) : "memory");
9879 return c;
9880 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9881 */
9882 static inline void atomic64_inc(atomic64_t *v)
9883 {
9884 + asm volatile(LOCK_PREFIX "incq %0\n"
9885 +
9886 +#ifdef CONFIG_PAX_REFCOUNT
9887 + "jno 0f\n"
9888 + LOCK_PREFIX "decq %0\n"
9889 + "int $4\n0:\n"
9890 + _ASM_EXTABLE(0b, 0b)
9891 +#endif
9892 +
9893 + : "=m" (v->counter)
9894 + : "m" (v->counter));
9895 +}
9896 +
9897 +/**
9898 + * atomic64_inc_unchecked - increment atomic64 variable
9899 + * @v: pointer to type atomic64_unchecked_t
9900 + *
9901 + * Atomically increments @v by 1.
9902 + */
9903 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9904 +{
9905 asm volatile(LOCK_PREFIX "incq %0"
9906 : "=m" (v->counter)
9907 : "m" (v->counter));
9908 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9909 */
9910 static inline void atomic64_dec(atomic64_t *v)
9911 {
9912 - asm volatile(LOCK_PREFIX "decq %0"
9913 + asm volatile(LOCK_PREFIX "decq %0\n"
9914 +
9915 +#ifdef CONFIG_PAX_REFCOUNT
9916 + "jno 0f\n"
9917 + LOCK_PREFIX "incq %0\n"
9918 + "int $4\n0:\n"
9919 + _ASM_EXTABLE(0b, 0b)
9920 +#endif
9921 +
9922 + : "=m" (v->counter)
9923 + : "m" (v->counter));
9924 +}
9925 +
9926 +/**
9927 + * atomic64_dec_unchecked - decrement atomic64 variable
9928 + * @v: pointer to type atomic64_t
9929 + *
9930 + * Atomically decrements @v by 1.
9931 + */
9932 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9933 +{
9934 + asm volatile(LOCK_PREFIX "decq %0\n"
9935 : "=m" (v->counter)
9936 : "m" (v->counter));
9937 }
9938 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9939 {
9940 unsigned char c;
9941
9942 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9943 + asm volatile(LOCK_PREFIX "decq %0\n"
9944 +
9945 +#ifdef CONFIG_PAX_REFCOUNT
9946 + "jno 0f\n"
9947 + LOCK_PREFIX "incq %0\n"
9948 + "int $4\n0:\n"
9949 + _ASM_EXTABLE(0b, 0b)
9950 +#endif
9951 +
9952 + "sete %1\n"
9953 : "=m" (v->counter), "=qm" (c)
9954 : "m" (v->counter) : "memory");
9955 return c != 0;
9956 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9957 {
9958 unsigned char c;
9959
9960 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9961 + asm volatile(LOCK_PREFIX "incq %0\n"
9962 +
9963 +#ifdef CONFIG_PAX_REFCOUNT
9964 + "jno 0f\n"
9965 + LOCK_PREFIX "decq %0\n"
9966 + "int $4\n0:\n"
9967 + _ASM_EXTABLE(0b, 0b)
9968 +#endif
9969 +
9970 + "sete %1\n"
9971 : "=m" (v->counter), "=qm" (c)
9972 : "m" (v->counter) : "memory");
9973 return c != 0;
9974 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9975 {
9976 unsigned char c;
9977
9978 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9979 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9980 +
9981 +#ifdef CONFIG_PAX_REFCOUNT
9982 + "jno 0f\n"
9983 + LOCK_PREFIX "subq %2,%0\n"
9984 + "int $4\n0:\n"
9985 + _ASM_EXTABLE(0b, 0b)
9986 +#endif
9987 +
9988 + "sets %1\n"
9989 : "=m" (v->counter), "=qm" (c)
9990 : "er" (i), "m" (v->counter) : "memory");
9991 return c;
9992 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9993 */
9994 static inline long atomic64_add_return(long i, atomic64_t *v)
9995 {
9996 + return i + xadd_check_overflow(&v->counter, i);
9997 +}
9998 +
9999 +/**
10000 + * atomic64_add_return_unchecked - add and return
10001 + * @i: integer value to add
10002 + * @v: pointer to type atomic64_unchecked_t
10003 + *
10004 + * Atomically adds @i to @v and returns @i + @v
10005 + */
10006 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10007 +{
10008 return i + xadd(&v->counter, i);
10009 }
10010
10011 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10012 }
10013
10014 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10015 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10016 +{
10017 + return atomic64_add_return_unchecked(1, v);
10018 +}
10019 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10020
10021 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10022 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10023 return cmpxchg(&v->counter, old, new);
10024 }
10025
10026 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10027 +{
10028 + return cmpxchg(&v->counter, old, new);
10029 +}
10030 +
10031 static inline long atomic64_xchg(atomic64_t *v, long new)
10032 {
10033 return xchg(&v->counter, new);
10034 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10035 */
10036 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10037 {
10038 - long c, old;
10039 + long c, old, new;
10040 c = atomic64_read(v);
10041 for (;;) {
10042 - if (unlikely(c == (u)))
10043 + if (unlikely(c == u))
10044 break;
10045 - old = atomic64_cmpxchg((v), c, c + (a));
10046 +
10047 + asm volatile("add %2,%0\n"
10048 +
10049 +#ifdef CONFIG_PAX_REFCOUNT
10050 + "jno 0f\n"
10051 + "sub %2,%0\n"
10052 + "int $4\n0:\n"
10053 + _ASM_EXTABLE(0b, 0b)
10054 +#endif
10055 +
10056 + : "=r" (new)
10057 + : "0" (c), "ir" (a));
10058 +
10059 + old = atomic64_cmpxchg(v, c, new);
10060 if (likely(old == c))
10061 break;
10062 c = old;
10063 }
10064 - return c != (u);
10065 + return c != u;
10066 }
10067
10068 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10069 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10070 index 72f5009..2f8b9a9 100644
10071 --- a/arch/x86/include/asm/bitops.h
10072 +++ b/arch/x86/include/asm/bitops.h
10073 @@ -40,7 +40,7 @@
10074 * a mask operation on a byte.
10075 */
10076 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10077 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10078 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10079 #define CONST_MASK(nr) (1 << ((nr) & 7))
10080
10081 /**
10082 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10083 index b13fe63..0dab13a 100644
10084 --- a/arch/x86/include/asm/boot.h
10085 +++ b/arch/x86/include/asm/boot.h
10086 @@ -11,10 +11,15 @@
10087 #include <asm/pgtable_types.h>
10088
10089 /* Physical address where kernel should be loaded. */
10090 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10091 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10092 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10093 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10094
10095 +#ifndef __ASSEMBLY__
10096 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10097 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10098 +#endif
10099 +
10100 /* Minimum kernel alignment, as a power of two */
10101 #ifdef CONFIG_X86_64
10102 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10103 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10104 index 48f99f1..d78ebf9 100644
10105 --- a/arch/x86/include/asm/cache.h
10106 +++ b/arch/x86/include/asm/cache.h
10107 @@ -5,12 +5,13 @@
10108
10109 /* L1 cache line size */
10110 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10111 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10112 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10113
10114 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10115 +#define __read_only __attribute__((__section__(".data..read_only")))
10116
10117 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10118 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10119 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10120
10121 #ifdef CONFIG_X86_VSMP
10122 #ifdef CONFIG_SMP
10123 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10124 index 9863ee3..4a1f8e1 100644
10125 --- a/arch/x86/include/asm/cacheflush.h
10126 +++ b/arch/x86/include/asm/cacheflush.h
10127 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10128 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10129
10130 if (pg_flags == _PGMT_DEFAULT)
10131 - return -1;
10132 + return ~0UL;
10133 else if (pg_flags == _PGMT_WC)
10134 return _PAGE_CACHE_WC;
10135 else if (pg_flags == _PGMT_UC_MINUS)
10136 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10137 index 46fc474..b02b0f9 100644
10138 --- a/arch/x86/include/asm/checksum_32.h
10139 +++ b/arch/x86/include/asm/checksum_32.h
10140 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10141 int len, __wsum sum,
10142 int *src_err_ptr, int *dst_err_ptr);
10143
10144 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10145 + int len, __wsum sum,
10146 + int *src_err_ptr, int *dst_err_ptr);
10147 +
10148 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10149 + int len, __wsum sum,
10150 + int *src_err_ptr, int *dst_err_ptr);
10151 +
10152 /*
10153 * Note: when you get a NULL pointer exception here this means someone
10154 * passed in an incorrect kernel address to one of these functions.
10155 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10156 int *err_ptr)
10157 {
10158 might_sleep();
10159 - return csum_partial_copy_generic((__force void *)src, dst,
10160 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10161 len, sum, err_ptr, NULL);
10162 }
10163
10164 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10165 {
10166 might_sleep();
10167 if (access_ok(VERIFY_WRITE, dst, len))
10168 - return csum_partial_copy_generic(src, (__force void *)dst,
10169 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10170 len, sum, NULL, err_ptr);
10171
10172 if (len)
10173 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10174 index 99480e5..d81165b 100644
10175 --- a/arch/x86/include/asm/cmpxchg.h
10176 +++ b/arch/x86/include/asm/cmpxchg.h
10177 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10178 __compiletime_error("Bad argument size for cmpxchg");
10179 extern void __xadd_wrong_size(void)
10180 __compiletime_error("Bad argument size for xadd");
10181 +extern void __xadd_check_overflow_wrong_size(void)
10182 + __compiletime_error("Bad argument size for xadd_check_overflow");
10183 extern void __add_wrong_size(void)
10184 __compiletime_error("Bad argument size for add");
10185 +extern void __add_check_overflow_wrong_size(void)
10186 + __compiletime_error("Bad argument size for add_check_overflow");
10187
10188 /*
10189 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10190 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10191 __ret; \
10192 })
10193
10194 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10195 + ({ \
10196 + __typeof__ (*(ptr)) __ret = (arg); \
10197 + switch (sizeof(*(ptr))) { \
10198 + case __X86_CASE_L: \
10199 + asm volatile (lock #op "l %0, %1\n" \
10200 + "jno 0f\n" \
10201 + "mov %0,%1\n" \
10202 + "int $4\n0:\n" \
10203 + _ASM_EXTABLE(0b, 0b) \
10204 + : "+r" (__ret), "+m" (*(ptr)) \
10205 + : : "memory", "cc"); \
10206 + break; \
10207 + case __X86_CASE_Q: \
10208 + asm volatile (lock #op "q %q0, %1\n" \
10209 + "jno 0f\n" \
10210 + "mov %0,%1\n" \
10211 + "int $4\n0:\n" \
10212 + _ASM_EXTABLE(0b, 0b) \
10213 + : "+r" (__ret), "+m" (*(ptr)) \
10214 + : : "memory", "cc"); \
10215 + break; \
10216 + default: \
10217 + __ ## op ## _check_overflow_wrong_size(); \
10218 + } \
10219 + __ret; \
10220 + })
10221 +
10222 /*
10223 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10224 * Since this is generally used to protect other memory information, we
10225 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10226 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10227 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10228
10229 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10230 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10231 +
10232 #define __add(ptr, inc, lock) \
10233 ({ \
10234 __typeof__ (*(ptr)) __ret = (inc); \
10235 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10236 index 6b7ee5f..9d664b3 100644
10237 --- a/arch/x86/include/asm/cpufeature.h
10238 +++ b/arch/x86/include/asm/cpufeature.h
10239 @@ -202,13 +202,14 @@
10240 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10241 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10242 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10243 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10244 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10245 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10246 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10247 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10248 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10249 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10250 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10251 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10252
10253 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10254
10255 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10256 ".section .discard,\"aw\",@progbits\n"
10257 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10258 ".previous\n"
10259 - ".section .altinstr_replacement,\"ax\"\n"
10260 + ".section .altinstr_replacement,\"a\"\n"
10261 "3: movb $1,%0\n"
10262 "4:\n"
10263 ".previous\n"
10264 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10265 index 8bf1c06..f723dfd 100644
10266 --- a/arch/x86/include/asm/desc.h
10267 +++ b/arch/x86/include/asm/desc.h
10268 @@ -4,6 +4,7 @@
10269 #include <asm/desc_defs.h>
10270 #include <asm/ldt.h>
10271 #include <asm/mmu.h>
10272 +#include <asm/pgtable.h>
10273
10274 #include <linux/smp.h>
10275 #include <linux/percpu.h>
10276 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10277
10278 desc->type = (info->read_exec_only ^ 1) << 1;
10279 desc->type |= info->contents << 2;
10280 + desc->type |= info->seg_not_present ^ 1;
10281
10282 desc->s = 1;
10283 desc->dpl = 0x3;
10284 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10285 }
10286
10287 extern struct desc_ptr idt_descr;
10288 -extern gate_desc idt_table[];
10289 extern struct desc_ptr nmi_idt_descr;
10290 -extern gate_desc nmi_idt_table[];
10291 -
10292 -struct gdt_page {
10293 - struct desc_struct gdt[GDT_ENTRIES];
10294 -} __attribute__((aligned(PAGE_SIZE)));
10295 -
10296 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10297 +extern gate_desc idt_table[256];
10298 +extern gate_desc nmi_idt_table[256];
10299
10300 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10301 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10302 {
10303 - return per_cpu(gdt_page, cpu).gdt;
10304 + return cpu_gdt_table[cpu];
10305 }
10306
10307 #ifdef CONFIG_X86_64
10308 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10309 unsigned long base, unsigned dpl, unsigned flags,
10310 unsigned short seg)
10311 {
10312 - gate->a = (seg << 16) | (base & 0xffff);
10313 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10314 + gate->gate.offset_low = base;
10315 + gate->gate.seg = seg;
10316 + gate->gate.reserved = 0;
10317 + gate->gate.type = type;
10318 + gate->gate.s = 0;
10319 + gate->gate.dpl = dpl;
10320 + gate->gate.p = 1;
10321 + gate->gate.offset_high = base >> 16;
10322 }
10323
10324 #endif
10325 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10326
10327 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10328 {
10329 + pax_open_kernel();
10330 memcpy(&idt[entry], gate, sizeof(*gate));
10331 + pax_close_kernel();
10332 }
10333
10334 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10335 {
10336 + pax_open_kernel();
10337 memcpy(&ldt[entry], desc, 8);
10338 + pax_close_kernel();
10339 }
10340
10341 static inline void
10342 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10343 default: size = sizeof(*gdt); break;
10344 }
10345
10346 + pax_open_kernel();
10347 memcpy(&gdt[entry], desc, size);
10348 + pax_close_kernel();
10349 }
10350
10351 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10352 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10353
10354 static inline void native_load_tr_desc(void)
10355 {
10356 + pax_open_kernel();
10357 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10358 + pax_close_kernel();
10359 }
10360
10361 static inline void native_load_gdt(const struct desc_ptr *dtr)
10362 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10363 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10364 unsigned int i;
10365
10366 + pax_open_kernel();
10367 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10368 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10369 + pax_close_kernel();
10370 }
10371
10372 #define _LDT_empty(info) \
10373 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10374 }
10375
10376 #ifdef CONFIG_X86_64
10377 -static inline void set_nmi_gate(int gate, void *addr)
10378 +static inline void set_nmi_gate(int gate, const void *addr)
10379 {
10380 gate_desc s;
10381
10382 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10383 }
10384 #endif
10385
10386 -static inline void _set_gate(int gate, unsigned type, void *addr,
10387 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10388 unsigned dpl, unsigned ist, unsigned seg)
10389 {
10390 gate_desc s;
10391 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10392 * Pentium F0 0F bugfix can have resulted in the mapped
10393 * IDT being write-protected.
10394 */
10395 -static inline void set_intr_gate(unsigned int n, void *addr)
10396 +static inline void set_intr_gate(unsigned int n, const void *addr)
10397 {
10398 BUG_ON((unsigned)n > 0xFF);
10399 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10400 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10401 /*
10402 * This routine sets up an interrupt gate at directory privilege level 3.
10403 */
10404 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10405 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10406 {
10407 BUG_ON((unsigned)n > 0xFF);
10408 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10409 }
10410
10411 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10412 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10413 {
10414 BUG_ON((unsigned)n > 0xFF);
10415 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10416 }
10417
10418 -static inline void set_trap_gate(unsigned int n, void *addr)
10419 +static inline void set_trap_gate(unsigned int n, const void *addr)
10420 {
10421 BUG_ON((unsigned)n > 0xFF);
10422 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10423 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10424 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10425 {
10426 BUG_ON((unsigned)n > 0xFF);
10427 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10428 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10429 }
10430
10431 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10432 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10433 {
10434 BUG_ON((unsigned)n > 0xFF);
10435 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10436 }
10437
10438 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10439 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10440 {
10441 BUG_ON((unsigned)n > 0xFF);
10442 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10443 }
10444
10445 +#ifdef CONFIG_X86_32
10446 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10447 +{
10448 + struct desc_struct d;
10449 +
10450 + if (likely(limit))
10451 + limit = (limit - 1UL) >> PAGE_SHIFT;
10452 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10453 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10454 +}
10455 +#endif
10456 +
10457 #endif /* _ASM_X86_DESC_H */
10458 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10459 index 278441f..b95a174 100644
10460 --- a/arch/x86/include/asm/desc_defs.h
10461 +++ b/arch/x86/include/asm/desc_defs.h
10462 @@ -31,6 +31,12 @@ struct desc_struct {
10463 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10464 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10465 };
10466 + struct {
10467 + u16 offset_low;
10468 + u16 seg;
10469 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10470 + unsigned offset_high: 16;
10471 + } gate;
10472 };
10473 } __attribute__((packed));
10474
10475 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10476 index 3778256..c5d4fce 100644
10477 --- a/arch/x86/include/asm/e820.h
10478 +++ b/arch/x86/include/asm/e820.h
10479 @@ -69,7 +69,7 @@ struct e820map {
10480 #define ISA_START_ADDRESS 0xa0000
10481 #define ISA_END_ADDRESS 0x100000
10482
10483 -#define BIOS_BEGIN 0x000a0000
10484 +#define BIOS_BEGIN 0x000c0000
10485 #define BIOS_END 0x00100000
10486
10487 #define BIOS_ROM_BASE 0xffe00000
10488 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10489 index 5939f44..f8845f6 100644
10490 --- a/arch/x86/include/asm/elf.h
10491 +++ b/arch/x86/include/asm/elf.h
10492 @@ -243,7 +243,25 @@ extern int force_personality32;
10493 the loader. We need to make sure that it is out of the way of the program
10494 that it will "exec", and that there is sufficient room for the brk. */
10495
10496 +#ifdef CONFIG_PAX_SEGMEXEC
10497 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10498 +#else
10499 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10500 +#endif
10501 +
10502 +#ifdef CONFIG_PAX_ASLR
10503 +#ifdef CONFIG_X86_32
10504 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10505 +
10506 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10507 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10508 +#else
10509 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10510 +
10511 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10512 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10513 +#endif
10514 +#endif
10515
10516 /* This yields a mask that user programs can use to figure out what
10517 instruction set this CPU supports. This could be done in user space,
10518 @@ -296,16 +314,12 @@ do { \
10519
10520 #define ARCH_DLINFO \
10521 do { \
10522 - if (vdso_enabled) \
10523 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10524 - (unsigned long)current->mm->context.vdso); \
10525 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10526 } while (0)
10527
10528 #define ARCH_DLINFO_X32 \
10529 do { \
10530 - if (vdso_enabled) \
10531 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10532 - (unsigned long)current->mm->context.vdso); \
10533 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10534 } while (0)
10535
10536 #define AT_SYSINFO 32
10537 @@ -320,7 +334,7 @@ else \
10538
10539 #endif /* !CONFIG_X86_32 */
10540
10541 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10542 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10543
10544 #define VDSO_ENTRY \
10545 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10546 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10547 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10548 #define compat_arch_setup_additional_pages syscall32_setup_pages
10549
10550 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10551 -#define arch_randomize_brk arch_randomize_brk
10552 -
10553 /*
10554 * True on X86_32 or when emulating IA32 on X86_64
10555 */
10556 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10557 index 75ce3f4..882e801 100644
10558 --- a/arch/x86/include/asm/emergency-restart.h
10559 +++ b/arch/x86/include/asm/emergency-restart.h
10560 @@ -13,6 +13,6 @@ enum reboot_type {
10561
10562 extern enum reboot_type reboot_type;
10563
10564 -extern void machine_emergency_restart(void);
10565 +extern void machine_emergency_restart(void) __noreturn;
10566
10567 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10568 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10569 index 75f4c6d..ee3eb8f 100644
10570 --- a/arch/x86/include/asm/fpu-internal.h
10571 +++ b/arch/x86/include/asm/fpu-internal.h
10572 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10573 {
10574 int err;
10575
10576 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10577 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10578 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10579 +#endif
10580 +
10581 /* See comment in fxsave() below. */
10582 #ifdef CONFIG_AS_FXSAVEQ
10583 asm volatile("1: fxrstorq %[fx]\n\t"
10584 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10585 {
10586 int err;
10587
10588 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10589 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10590 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10591 +#endif
10592 +
10593 /*
10594 * Clear the bytes not touched by the fxsave and reserved
10595 * for the SW usage.
10596 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10597 "emms\n\t" /* clear stack tags */
10598 "fildl %P[addr]", /* set F?P to defined value */
10599 X86_FEATURE_FXSAVE_LEAK,
10600 - [addr] "m" (tsk->thread.fpu.has_fpu));
10601 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10602
10603 return fpu_restore_checking(&tsk->thread.fpu);
10604 }
10605 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10606 index 71ecbcb..bac10b7 100644
10607 --- a/arch/x86/include/asm/futex.h
10608 +++ b/arch/x86/include/asm/futex.h
10609 @@ -11,16 +11,18 @@
10610 #include <asm/processor.h>
10611
10612 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10613 + typecheck(u32 __user *, uaddr); \
10614 asm volatile("1:\t" insn "\n" \
10615 "2:\t.section .fixup,\"ax\"\n" \
10616 "3:\tmov\t%3, %1\n" \
10617 "\tjmp\t2b\n" \
10618 "\t.previous\n" \
10619 _ASM_EXTABLE(1b, 3b) \
10620 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10621 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10622 : "i" (-EFAULT), "0" (oparg), "1" (0))
10623
10624 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10625 + typecheck(u32 __user *, uaddr); \
10626 asm volatile("1:\tmovl %2, %0\n" \
10627 "\tmovl\t%0, %3\n" \
10628 "\t" insn "\n" \
10629 @@ -33,7 +35,7 @@
10630 _ASM_EXTABLE(1b, 4b) \
10631 _ASM_EXTABLE(2b, 4b) \
10632 : "=&a" (oldval), "=&r" (ret), \
10633 - "+m" (*uaddr), "=&r" (tem) \
10634 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10635 : "r" (oparg), "i" (-EFAULT), "1" (0))
10636
10637 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10638 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10639
10640 switch (op) {
10641 case FUTEX_OP_SET:
10642 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10643 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10644 break;
10645 case FUTEX_OP_ADD:
10646 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10647 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10648 uaddr, oparg);
10649 break;
10650 case FUTEX_OP_OR:
10651 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10652 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10653 return -EFAULT;
10654
10655 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10656 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10657 "2:\t.section .fixup, \"ax\"\n"
10658 "3:\tmov %3, %0\n"
10659 "\tjmp 2b\n"
10660 "\t.previous\n"
10661 _ASM_EXTABLE(1b, 3b)
10662 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10663 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10664 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10665 : "memory"
10666 );
10667 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10668 index eb92a6e..b98b2f4 100644
10669 --- a/arch/x86/include/asm/hw_irq.h
10670 +++ b/arch/x86/include/asm/hw_irq.h
10671 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10672 extern void enable_IO_APIC(void);
10673
10674 /* Statistics */
10675 -extern atomic_t irq_err_count;
10676 -extern atomic_t irq_mis_count;
10677 +extern atomic_unchecked_t irq_err_count;
10678 +extern atomic_unchecked_t irq_mis_count;
10679
10680 /* EISA */
10681 extern void eisa_set_level_irq(unsigned int irq);
10682 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10683 index d8e8eef..99f81ae 100644
10684 --- a/arch/x86/include/asm/io.h
10685 +++ b/arch/x86/include/asm/io.h
10686 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10687
10688 #include <linux/vmalloc.h>
10689
10690 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10691 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10692 +{
10693 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10694 +}
10695 +
10696 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10697 +{
10698 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10699 +}
10700 +
10701 /*
10702 * Convert a virtual cached pointer to an uncached pointer
10703 */
10704 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10705 index bba3cf8..06bc8da 100644
10706 --- a/arch/x86/include/asm/irqflags.h
10707 +++ b/arch/x86/include/asm/irqflags.h
10708 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10709 sti; \
10710 sysexit
10711
10712 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10713 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10714 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10715 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10716 +
10717 #else
10718 #define INTERRUPT_RETURN iret
10719 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10720 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10721 index 5478825..839e88c 100644
10722 --- a/arch/x86/include/asm/kprobes.h
10723 +++ b/arch/x86/include/asm/kprobes.h
10724 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10725 #define RELATIVEJUMP_SIZE 5
10726 #define RELATIVECALL_OPCODE 0xe8
10727 #define RELATIVE_ADDR_SIZE 4
10728 -#define MAX_STACK_SIZE 64
10729 -#define MIN_STACK_SIZE(ADDR) \
10730 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10731 - THREAD_SIZE - (unsigned long)(ADDR))) \
10732 - ? (MAX_STACK_SIZE) \
10733 - : (((unsigned long)current_thread_info()) + \
10734 - THREAD_SIZE - (unsigned long)(ADDR)))
10735 +#define MAX_STACK_SIZE 64UL
10736 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10737
10738 #define flush_insn_slot(p) do { } while (0)
10739
10740 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10741 index 09155d6..d2e6df9 100644
10742 --- a/arch/x86/include/asm/kvm_host.h
10743 +++ b/arch/x86/include/asm/kvm_host.h
10744 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10745 int (*check_intercept)(struct kvm_vcpu *vcpu,
10746 struct x86_instruction_info *info,
10747 enum x86_intercept_stage stage);
10748 -};
10749 +} __do_const;
10750
10751 struct kvm_arch_async_pf {
10752 u32 token;
10753 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10754 index c8bed0d..e5721fa 100644
10755 --- a/arch/x86/include/asm/local.h
10756 +++ b/arch/x86/include/asm/local.h
10757 @@ -17,26 +17,58 @@ typedef struct {
10758
10759 static inline void local_inc(local_t *l)
10760 {
10761 - asm volatile(_ASM_INC "%0"
10762 + asm volatile(_ASM_INC "%0\n"
10763 +
10764 +#ifdef CONFIG_PAX_REFCOUNT
10765 + "jno 0f\n"
10766 + _ASM_DEC "%0\n"
10767 + "int $4\n0:\n"
10768 + _ASM_EXTABLE(0b, 0b)
10769 +#endif
10770 +
10771 : "+m" (l->a.counter));
10772 }
10773
10774 static inline void local_dec(local_t *l)
10775 {
10776 - asm volatile(_ASM_DEC "%0"
10777 + asm volatile(_ASM_DEC "%0\n"
10778 +
10779 +#ifdef CONFIG_PAX_REFCOUNT
10780 + "jno 0f\n"
10781 + _ASM_INC "%0\n"
10782 + "int $4\n0:\n"
10783 + _ASM_EXTABLE(0b, 0b)
10784 +#endif
10785 +
10786 : "+m" (l->a.counter));
10787 }
10788
10789 static inline void local_add(long i, local_t *l)
10790 {
10791 - asm volatile(_ASM_ADD "%1,%0"
10792 + asm volatile(_ASM_ADD "%1,%0\n"
10793 +
10794 +#ifdef CONFIG_PAX_REFCOUNT
10795 + "jno 0f\n"
10796 + _ASM_SUB "%1,%0\n"
10797 + "int $4\n0:\n"
10798 + _ASM_EXTABLE(0b, 0b)
10799 +#endif
10800 +
10801 : "+m" (l->a.counter)
10802 : "ir" (i));
10803 }
10804
10805 static inline void local_sub(long i, local_t *l)
10806 {
10807 - asm volatile(_ASM_SUB "%1,%0"
10808 + asm volatile(_ASM_SUB "%1,%0\n"
10809 +
10810 +#ifdef CONFIG_PAX_REFCOUNT
10811 + "jno 0f\n"
10812 + _ASM_ADD "%1,%0\n"
10813 + "int $4\n0:\n"
10814 + _ASM_EXTABLE(0b, 0b)
10815 +#endif
10816 +
10817 : "+m" (l->a.counter)
10818 : "ir" (i));
10819 }
10820 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10821 {
10822 unsigned char c;
10823
10824 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10825 + asm volatile(_ASM_SUB "%2,%0\n"
10826 +
10827 +#ifdef CONFIG_PAX_REFCOUNT
10828 + "jno 0f\n"
10829 + _ASM_ADD "%2,%0\n"
10830 + "int $4\n0:\n"
10831 + _ASM_EXTABLE(0b, 0b)
10832 +#endif
10833 +
10834 + "sete %1\n"
10835 : "+m" (l->a.counter), "=qm" (c)
10836 : "ir" (i) : "memory");
10837 return c;
10838 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10839 {
10840 unsigned char c;
10841
10842 - asm volatile(_ASM_DEC "%0; sete %1"
10843 + asm volatile(_ASM_DEC "%0\n"
10844 +
10845 +#ifdef CONFIG_PAX_REFCOUNT
10846 + "jno 0f\n"
10847 + _ASM_INC "%0\n"
10848 + "int $4\n0:\n"
10849 + _ASM_EXTABLE(0b, 0b)
10850 +#endif
10851 +
10852 + "sete %1\n"
10853 : "+m" (l->a.counter), "=qm" (c)
10854 : : "memory");
10855 return c != 0;
10856 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10857 {
10858 unsigned char c;
10859
10860 - asm volatile(_ASM_INC "%0; sete %1"
10861 + asm volatile(_ASM_INC "%0\n"
10862 +
10863 +#ifdef CONFIG_PAX_REFCOUNT
10864 + "jno 0f\n"
10865 + _ASM_DEC "%0\n"
10866 + "int $4\n0:\n"
10867 + _ASM_EXTABLE(0b, 0b)
10868 +#endif
10869 +
10870 + "sete %1\n"
10871 : "+m" (l->a.counter), "=qm" (c)
10872 : : "memory");
10873 return c != 0;
10874 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10875 {
10876 unsigned char c;
10877
10878 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10879 + asm volatile(_ASM_ADD "%2,%0\n"
10880 +
10881 +#ifdef CONFIG_PAX_REFCOUNT
10882 + "jno 0f\n"
10883 + _ASM_SUB "%2,%0\n"
10884 + "int $4\n0:\n"
10885 + _ASM_EXTABLE(0b, 0b)
10886 +#endif
10887 +
10888 + "sets %1\n"
10889 : "+m" (l->a.counter), "=qm" (c)
10890 : "ir" (i) : "memory");
10891 return c;
10892 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10893 #endif
10894 /* Modern 486+ processor */
10895 __i = i;
10896 - asm volatile(_ASM_XADD "%0, %1;"
10897 + asm volatile(_ASM_XADD "%0, %1\n"
10898 +
10899 +#ifdef CONFIG_PAX_REFCOUNT
10900 + "jno 0f\n"
10901 + _ASM_MOV "%0,%1\n"
10902 + "int $4\n0:\n"
10903 + _ASM_EXTABLE(0b, 0b)
10904 +#endif
10905 +
10906 : "+r" (i), "+m" (l->a.counter)
10907 : : "memory");
10908 return i + __i;
10909 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10910 index 593e51d..fa69c9a 100644
10911 --- a/arch/x86/include/asm/mman.h
10912 +++ b/arch/x86/include/asm/mman.h
10913 @@ -5,4 +5,14 @@
10914
10915 #include <asm-generic/mman.h>
10916
10917 +#ifdef __KERNEL__
10918 +#ifndef __ASSEMBLY__
10919 +#ifdef CONFIG_X86_32
10920 +#define arch_mmap_check i386_mmap_check
10921 +int i386_mmap_check(unsigned long addr, unsigned long len,
10922 + unsigned long flags);
10923 +#endif
10924 +#endif
10925 +#endif
10926 +
10927 #endif /* _ASM_X86_MMAN_H */
10928 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10929 index 5f55e69..e20bfb1 100644
10930 --- a/arch/x86/include/asm/mmu.h
10931 +++ b/arch/x86/include/asm/mmu.h
10932 @@ -9,7 +9,7 @@
10933 * we put the segment information here.
10934 */
10935 typedef struct {
10936 - void *ldt;
10937 + struct desc_struct *ldt;
10938 int size;
10939
10940 #ifdef CONFIG_X86_64
10941 @@ -18,7 +18,19 @@ typedef struct {
10942 #endif
10943
10944 struct mutex lock;
10945 - void *vdso;
10946 + unsigned long vdso;
10947 +
10948 +#ifdef CONFIG_X86_32
10949 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10950 + unsigned long user_cs_base;
10951 + unsigned long user_cs_limit;
10952 +
10953 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10954 + cpumask_t cpu_user_cs_mask;
10955 +#endif
10956 +
10957 +#endif
10958 +#endif
10959 } mm_context_t;
10960
10961 #ifdef CONFIG_SMP
10962 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10963 index cdbf367..adb37ac 100644
10964 --- a/arch/x86/include/asm/mmu_context.h
10965 +++ b/arch/x86/include/asm/mmu_context.h
10966 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10967
10968 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10969 {
10970 +
10971 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10972 + unsigned int i;
10973 + pgd_t *pgd;
10974 +
10975 + pax_open_kernel();
10976 + pgd = get_cpu_pgd(smp_processor_id());
10977 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10978 + set_pgd_batched(pgd+i, native_make_pgd(0));
10979 + pax_close_kernel();
10980 +#endif
10981 +
10982 #ifdef CONFIG_SMP
10983 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10984 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10985 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10986 struct task_struct *tsk)
10987 {
10988 unsigned cpu = smp_processor_id();
10989 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10990 + int tlbstate = TLBSTATE_OK;
10991 +#endif
10992
10993 if (likely(prev != next)) {
10994 #ifdef CONFIG_SMP
10995 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10996 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10997 +#endif
10998 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10999 this_cpu_write(cpu_tlbstate.active_mm, next);
11000 #endif
11001 cpumask_set_cpu(cpu, mm_cpumask(next));
11002
11003 /* Re-load page tables */
11004 +#ifdef CONFIG_PAX_PER_CPU_PGD
11005 + pax_open_kernel();
11006 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11007 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11008 + pax_close_kernel();
11009 + load_cr3(get_cpu_pgd(cpu));
11010 +#else
11011 load_cr3(next->pgd);
11012 +#endif
11013
11014 /* stop flush ipis for the previous mm */
11015 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11016 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11017 */
11018 if (unlikely(prev->context.ldt != next->context.ldt))
11019 load_LDT_nolock(&next->context);
11020 - }
11021 +
11022 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11023 + if (!(__supported_pte_mask & _PAGE_NX)) {
11024 + smp_mb__before_clear_bit();
11025 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11026 + smp_mb__after_clear_bit();
11027 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11028 + }
11029 +#endif
11030 +
11031 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11032 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11033 + prev->context.user_cs_limit != next->context.user_cs_limit))
11034 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11035 #ifdef CONFIG_SMP
11036 + else if (unlikely(tlbstate != TLBSTATE_OK))
11037 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11038 +#endif
11039 +#endif
11040 +
11041 + }
11042 else {
11043 +
11044 +#ifdef CONFIG_PAX_PER_CPU_PGD
11045 + pax_open_kernel();
11046 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11047 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11048 + pax_close_kernel();
11049 + load_cr3(get_cpu_pgd(cpu));
11050 +#endif
11051 +
11052 +#ifdef CONFIG_SMP
11053 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11054 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11055
11056 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11057 * tlb flush IPI delivery. We must reload CR3
11058 * to make sure to use no freed page tables.
11059 */
11060 +
11061 +#ifndef CONFIG_PAX_PER_CPU_PGD
11062 load_cr3(next->pgd);
11063 +#endif
11064 +
11065 load_LDT_nolock(&next->context);
11066 +
11067 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11068 + if (!(__supported_pte_mask & _PAGE_NX))
11069 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11070 +#endif
11071 +
11072 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11073 +#ifdef CONFIG_PAX_PAGEEXEC
11074 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11075 +#endif
11076 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11077 +#endif
11078 +
11079 }
11080 +#endif
11081 }
11082 -#endif
11083 }
11084
11085 #define activate_mm(prev, next) \
11086 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11087 index 9eae775..c914fea 100644
11088 --- a/arch/x86/include/asm/module.h
11089 +++ b/arch/x86/include/asm/module.h
11090 @@ -5,6 +5,7 @@
11091
11092 #ifdef CONFIG_X86_64
11093 /* X86_64 does not define MODULE_PROC_FAMILY */
11094 +#define MODULE_PROC_FAMILY ""
11095 #elif defined CONFIG_M386
11096 #define MODULE_PROC_FAMILY "386 "
11097 #elif defined CONFIG_M486
11098 @@ -59,8 +60,20 @@
11099 #error unknown processor family
11100 #endif
11101
11102 -#ifdef CONFIG_X86_32
11103 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11104 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11105 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11106 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11107 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11108 +#else
11109 +#define MODULE_PAX_KERNEXEC ""
11110 #endif
11111
11112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11113 +#define MODULE_PAX_UDEREF "UDEREF "
11114 +#else
11115 +#define MODULE_PAX_UDEREF ""
11116 +#endif
11117 +
11118 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11119 +
11120 #endif /* _ASM_X86_MODULE_H */
11121 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11122 index 320f7bb..e89f8f8 100644
11123 --- a/arch/x86/include/asm/page_64_types.h
11124 +++ b/arch/x86/include/asm/page_64_types.h
11125 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11126
11127 /* duplicated to the one in bootmem.h */
11128 extern unsigned long max_pfn;
11129 -extern unsigned long phys_base;
11130 +extern const unsigned long phys_base;
11131
11132 extern unsigned long __phys_addr(unsigned long);
11133 #define __phys_reloc_hide(x) (x)
11134 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11135 index a0facf3..c017b15 100644
11136 --- a/arch/x86/include/asm/paravirt.h
11137 +++ b/arch/x86/include/asm/paravirt.h
11138 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11139 val);
11140 }
11141
11142 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11143 +{
11144 + pgdval_t val = native_pgd_val(pgd);
11145 +
11146 + if (sizeof(pgdval_t) > sizeof(long))
11147 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11148 + val, (u64)val >> 32);
11149 + else
11150 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11151 + val);
11152 +}
11153 +
11154 static inline void pgd_clear(pgd_t *pgdp)
11155 {
11156 set_pgd(pgdp, __pgd(0));
11157 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11158 pv_mmu_ops.set_fixmap(idx, phys, flags);
11159 }
11160
11161 +#ifdef CONFIG_PAX_KERNEXEC
11162 +static inline unsigned long pax_open_kernel(void)
11163 +{
11164 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11165 +}
11166 +
11167 +static inline unsigned long pax_close_kernel(void)
11168 +{
11169 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11170 +}
11171 +#else
11172 +static inline unsigned long pax_open_kernel(void) { return 0; }
11173 +static inline unsigned long pax_close_kernel(void) { return 0; }
11174 +#endif
11175 +
11176 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11177
11178 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11179 @@ -929,7 +956,7 @@ extern void default_banner(void);
11180
11181 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11182 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11183 -#define PARA_INDIRECT(addr) *%cs:addr
11184 +#define PARA_INDIRECT(addr) *%ss:addr
11185 #endif
11186
11187 #define INTERRUPT_RETURN \
11188 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11189 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11190 CLBR_NONE, \
11191 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11192 +
11193 +#define GET_CR0_INTO_RDI \
11194 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11195 + mov %rax,%rdi
11196 +
11197 +#define SET_RDI_INTO_CR0 \
11198 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11199 +
11200 +#define GET_CR3_INTO_RDI \
11201 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11202 + mov %rax,%rdi
11203 +
11204 +#define SET_RDI_INTO_CR3 \
11205 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11206 +
11207 #endif /* CONFIG_X86_32 */
11208
11209 #endif /* __ASSEMBLY__ */
11210 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11211 index 142236e..6a6b4a6 100644
11212 --- a/arch/x86/include/asm/paravirt_types.h
11213 +++ b/arch/x86/include/asm/paravirt_types.h
11214 @@ -84,20 +84,20 @@ struct pv_init_ops {
11215 */
11216 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11217 unsigned long addr, unsigned len);
11218 -};
11219 +} __no_const;
11220
11221
11222 struct pv_lazy_ops {
11223 /* Set deferred update mode, used for batching operations. */
11224 void (*enter)(void);
11225 void (*leave)(void);
11226 -};
11227 +} __no_const;
11228
11229 struct pv_time_ops {
11230 unsigned long long (*sched_clock)(void);
11231 unsigned long long (*steal_clock)(int cpu);
11232 unsigned long (*get_tsc_khz)(void);
11233 -};
11234 +} __no_const;
11235
11236 struct pv_cpu_ops {
11237 /* hooks for various privileged instructions */
11238 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11239
11240 void (*start_context_switch)(struct task_struct *prev);
11241 void (*end_context_switch)(struct task_struct *next);
11242 -};
11243 +} __no_const;
11244
11245 struct pv_irq_ops {
11246 /*
11247 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11248 unsigned long start_eip,
11249 unsigned long start_esp);
11250 #endif
11251 -};
11252 +} __no_const;
11253
11254 struct pv_mmu_ops {
11255 unsigned long (*read_cr2)(void);
11256 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11257 struct paravirt_callee_save make_pud;
11258
11259 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11260 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11261 #endif /* PAGETABLE_LEVELS == 4 */
11262 #endif /* PAGETABLE_LEVELS >= 3 */
11263
11264 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11265 an mfn. We can tell which is which from the index. */
11266 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11267 phys_addr_t phys, pgprot_t flags);
11268 +
11269 +#ifdef CONFIG_PAX_KERNEXEC
11270 + unsigned long (*pax_open_kernel)(void);
11271 + unsigned long (*pax_close_kernel)(void);
11272 +#endif
11273 +
11274 };
11275
11276 struct arch_spinlock;
11277 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11278 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11279 int (*spin_trylock)(struct arch_spinlock *lock);
11280 void (*spin_unlock)(struct arch_spinlock *lock);
11281 -};
11282 +} __no_const;
11283
11284 /* This contains all the paravirt structures: we get a convenient
11285 * number for each function using the offset which we use to indicate
11286 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11287 index b4389a4..7024269 100644
11288 --- a/arch/x86/include/asm/pgalloc.h
11289 +++ b/arch/x86/include/asm/pgalloc.h
11290 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11291 pmd_t *pmd, pte_t *pte)
11292 {
11293 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11294 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11295 +}
11296 +
11297 +static inline void pmd_populate_user(struct mm_struct *mm,
11298 + pmd_t *pmd, pte_t *pte)
11299 +{
11300 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11301 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11302 }
11303
11304 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11305
11306 #ifdef CONFIG_X86_PAE
11307 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11308 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11309 +{
11310 + pud_populate(mm, pudp, pmd);
11311 +}
11312 #else /* !CONFIG_X86_PAE */
11313 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11314 {
11315 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11316 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11317 }
11318 +
11319 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11320 +{
11321 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11322 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11323 +}
11324 #endif /* CONFIG_X86_PAE */
11325
11326 #if PAGETABLE_LEVELS > 3
11327 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11328 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11329 }
11330
11331 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11332 +{
11333 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11334 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11335 +}
11336 +
11337 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11338 {
11339 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11340 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11341 index f2b489c..4f7e2e5 100644
11342 --- a/arch/x86/include/asm/pgtable-2level.h
11343 +++ b/arch/x86/include/asm/pgtable-2level.h
11344 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11345
11346 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11347 {
11348 + pax_open_kernel();
11349 *pmdp = pmd;
11350 + pax_close_kernel();
11351 }
11352
11353 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11354 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11355 index 4cc9f2b..5fd9226 100644
11356 --- a/arch/x86/include/asm/pgtable-3level.h
11357 +++ b/arch/x86/include/asm/pgtable-3level.h
11358 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11359
11360 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11361 {
11362 + pax_open_kernel();
11363 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11364 + pax_close_kernel();
11365 }
11366
11367 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11368 {
11369 + pax_open_kernel();
11370 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11371 + pax_close_kernel();
11372 }
11373
11374 /*
11375 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11376 index c3520d7..cf742ef 100644
11377 --- a/arch/x86/include/asm/pgtable.h
11378 +++ b/arch/x86/include/asm/pgtable.h
11379 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11380
11381 #ifndef __PAGETABLE_PUD_FOLDED
11382 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11383 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11384 #define pgd_clear(pgd) native_pgd_clear(pgd)
11385 #endif
11386
11387 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11388
11389 #define arch_end_context_switch(prev) do {} while(0)
11390
11391 +#define pax_open_kernel() native_pax_open_kernel()
11392 +#define pax_close_kernel() native_pax_close_kernel()
11393 #endif /* CONFIG_PARAVIRT */
11394
11395 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11396 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11397 +
11398 +#ifdef CONFIG_PAX_KERNEXEC
11399 +static inline unsigned long native_pax_open_kernel(void)
11400 +{
11401 + unsigned long cr0;
11402 +
11403 + preempt_disable();
11404 + barrier();
11405 + cr0 = read_cr0() ^ X86_CR0_WP;
11406 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11407 + write_cr0(cr0);
11408 + return cr0 ^ X86_CR0_WP;
11409 +}
11410 +
11411 +static inline unsigned long native_pax_close_kernel(void)
11412 +{
11413 + unsigned long cr0;
11414 +
11415 + cr0 = read_cr0() ^ X86_CR0_WP;
11416 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11417 + write_cr0(cr0);
11418 + barrier();
11419 + preempt_enable_no_resched();
11420 + return cr0 ^ X86_CR0_WP;
11421 +}
11422 +#else
11423 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11424 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11425 +#endif
11426 +
11427 /*
11428 * The following only work if pte_present() is true.
11429 * Undefined behaviour if not..
11430 */
11431 +static inline int pte_user(pte_t pte)
11432 +{
11433 + return pte_val(pte) & _PAGE_USER;
11434 +}
11435 +
11436 static inline int pte_dirty(pte_t pte)
11437 {
11438 return pte_flags(pte) & _PAGE_DIRTY;
11439 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11440 return pte_clear_flags(pte, _PAGE_RW);
11441 }
11442
11443 +static inline pte_t pte_mkread(pte_t pte)
11444 +{
11445 + return __pte(pte_val(pte) | _PAGE_USER);
11446 +}
11447 +
11448 static inline pte_t pte_mkexec(pte_t pte)
11449 {
11450 - return pte_clear_flags(pte, _PAGE_NX);
11451 +#ifdef CONFIG_X86_PAE
11452 + if (__supported_pte_mask & _PAGE_NX)
11453 + return pte_clear_flags(pte, _PAGE_NX);
11454 + else
11455 +#endif
11456 + return pte_set_flags(pte, _PAGE_USER);
11457 +}
11458 +
11459 +static inline pte_t pte_exprotect(pte_t pte)
11460 +{
11461 +#ifdef CONFIG_X86_PAE
11462 + if (__supported_pte_mask & _PAGE_NX)
11463 + return pte_set_flags(pte, _PAGE_NX);
11464 + else
11465 +#endif
11466 + return pte_clear_flags(pte, _PAGE_USER);
11467 }
11468
11469 static inline pte_t pte_mkdirty(pte_t pte)
11470 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11471 #endif
11472
11473 #ifndef __ASSEMBLY__
11474 +
11475 +#ifdef CONFIG_PAX_PER_CPU_PGD
11476 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11477 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11478 +{
11479 + return cpu_pgd[cpu];
11480 +}
11481 +#endif
11482 +
11483 #include <linux/mm_types.h>
11484
11485 static inline int pte_none(pte_t pte)
11486 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11487
11488 static inline int pgd_bad(pgd_t pgd)
11489 {
11490 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11491 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11492 }
11493
11494 static inline int pgd_none(pgd_t pgd)
11495 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11496 * pgd_offset() returns a (pgd_t *)
11497 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11498 */
11499 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11500 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11501 +
11502 +#ifdef CONFIG_PAX_PER_CPU_PGD
11503 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11504 +#endif
11505 +
11506 /*
11507 * a shortcut which implies the use of the kernel's pgd, instead
11508 * of a process's
11509 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11510 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11511 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11512
11513 +#ifdef CONFIG_X86_32
11514 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11515 +#else
11516 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11517 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11518 +
11519 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11520 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11521 +#else
11522 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11523 +#endif
11524 +
11525 +#endif
11526 +
11527 #ifndef __ASSEMBLY__
11528
11529 extern int direct_gbpages;
11530 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11531 * dst and src can be on the same page, but the range must not overlap,
11532 * and must not cross a page boundary.
11533 */
11534 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11535 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11536 {
11537 - memcpy(dst, src, count * sizeof(pgd_t));
11538 + pax_open_kernel();
11539 + while (count--)
11540 + *dst++ = *src++;
11541 + pax_close_kernel();
11542 }
11543
11544 +#ifdef CONFIG_PAX_PER_CPU_PGD
11545 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11546 +#endif
11547 +
11548 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11549 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11550 +#else
11551 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11552 +#endif
11553
11554 #include <asm-generic/pgtable.h>
11555 #endif /* __ASSEMBLY__ */
11556 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11557 index 0c92113..34a77c6 100644
11558 --- a/arch/x86/include/asm/pgtable_32.h
11559 +++ b/arch/x86/include/asm/pgtable_32.h
11560 @@ -25,9 +25,6 @@
11561 struct mm_struct;
11562 struct vm_area_struct;
11563
11564 -extern pgd_t swapper_pg_dir[1024];
11565 -extern pgd_t initial_page_table[1024];
11566 -
11567 static inline void pgtable_cache_init(void) { }
11568 static inline void check_pgt_cache(void) { }
11569 void paging_init(void);
11570 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11571 # include <asm/pgtable-2level.h>
11572 #endif
11573
11574 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11575 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11576 +#ifdef CONFIG_X86_PAE
11577 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11578 +#endif
11579 +
11580 #if defined(CONFIG_HIGHPTE)
11581 #define pte_offset_map(dir, address) \
11582 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11583 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11584 /* Clear a kernel PTE and flush it from the TLB */
11585 #define kpte_clear_flush(ptep, vaddr) \
11586 do { \
11587 + pax_open_kernel(); \
11588 pte_clear(&init_mm, (vaddr), (ptep)); \
11589 + pax_close_kernel(); \
11590 __flush_tlb_one((vaddr)); \
11591 } while (0)
11592
11593 @@ -74,6 +79,9 @@ do { \
11594
11595 #endif /* !__ASSEMBLY__ */
11596
11597 +#define HAVE_ARCH_UNMAPPED_AREA
11598 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11599 +
11600 /*
11601 * kern_addr_valid() is (1) for FLATMEM and (0) for
11602 * SPARSEMEM and DISCONTIGMEM
11603 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11604 index ed5903b..c7fe163 100644
11605 --- a/arch/x86/include/asm/pgtable_32_types.h
11606 +++ b/arch/x86/include/asm/pgtable_32_types.h
11607 @@ -8,7 +8,7 @@
11608 */
11609 #ifdef CONFIG_X86_PAE
11610 # include <asm/pgtable-3level_types.h>
11611 -# define PMD_SIZE (1UL << PMD_SHIFT)
11612 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11613 # define PMD_MASK (~(PMD_SIZE - 1))
11614 #else
11615 # include <asm/pgtable-2level_types.h>
11616 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11617 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11618 #endif
11619
11620 +#ifdef CONFIG_PAX_KERNEXEC
11621 +#ifndef __ASSEMBLY__
11622 +extern unsigned char MODULES_EXEC_VADDR[];
11623 +extern unsigned char MODULES_EXEC_END[];
11624 +#endif
11625 +#include <asm/boot.h>
11626 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11627 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11628 +#else
11629 +#define ktla_ktva(addr) (addr)
11630 +#define ktva_ktla(addr) (addr)
11631 +#endif
11632 +
11633 #define MODULES_VADDR VMALLOC_START
11634 #define MODULES_END VMALLOC_END
11635 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11636 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11637 index 8251be0..4ea8b46 100644
11638 --- a/arch/x86/include/asm/pgtable_64.h
11639 +++ b/arch/x86/include/asm/pgtable_64.h
11640 @@ -16,10 +16,14 @@
11641
11642 extern pud_t level3_kernel_pgt[512];
11643 extern pud_t level3_ident_pgt[512];
11644 +extern pud_t level3_vmalloc_start_pgt[512];
11645 +extern pud_t level3_vmalloc_end_pgt[512];
11646 +extern pud_t level3_vmemmap_pgt[512];
11647 +extern pud_t level2_vmemmap_pgt[512];
11648 extern pmd_t level2_kernel_pgt[512];
11649 extern pmd_t level2_fixmap_pgt[512];
11650 -extern pmd_t level2_ident_pgt[512];
11651 -extern pgd_t init_level4_pgt[];
11652 +extern pmd_t level2_ident_pgt[512*2];
11653 +extern pgd_t init_level4_pgt[512];
11654
11655 #define swapper_pg_dir init_level4_pgt
11656
11657 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11658
11659 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11660 {
11661 + pax_open_kernel();
11662 *pmdp = pmd;
11663 + pax_close_kernel();
11664 }
11665
11666 static inline void native_pmd_clear(pmd_t *pmd)
11667 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11668
11669 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11670 {
11671 + pax_open_kernel();
11672 *pudp = pud;
11673 + pax_close_kernel();
11674 }
11675
11676 static inline void native_pud_clear(pud_t *pud)
11677 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11678
11679 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11680 {
11681 + pax_open_kernel();
11682 + *pgdp = pgd;
11683 + pax_close_kernel();
11684 +}
11685 +
11686 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11687 +{
11688 *pgdp = pgd;
11689 }
11690
11691 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11692 index 766ea16..5b96cb3 100644
11693 --- a/arch/x86/include/asm/pgtable_64_types.h
11694 +++ b/arch/x86/include/asm/pgtable_64_types.h
11695 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11696 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11697 #define MODULES_END _AC(0xffffffffff000000, UL)
11698 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11699 +#define MODULES_EXEC_VADDR MODULES_VADDR
11700 +#define MODULES_EXEC_END MODULES_END
11701 +
11702 +#define ktla_ktva(addr) (addr)
11703 +#define ktva_ktla(addr) (addr)
11704
11705 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11706 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11707 index 013286a..8b42f4f 100644
11708 --- a/arch/x86/include/asm/pgtable_types.h
11709 +++ b/arch/x86/include/asm/pgtable_types.h
11710 @@ -16,13 +16,12 @@
11711 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11712 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11713 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11714 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11715 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11716 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11717 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11718 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11719 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11720 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11721 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11722 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11723 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11724 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11725
11726 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11727 @@ -40,7 +39,6 @@
11728 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11729 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11730 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11731 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11732 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11733 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11734 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11735 @@ -57,8 +55,10 @@
11736
11737 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11738 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11739 -#else
11740 +#elif defined(CONFIG_KMEMCHECK)
11741 #define _PAGE_NX (_AT(pteval_t, 0))
11742 +#else
11743 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11744 #endif
11745
11746 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11747 @@ -96,6 +96,9 @@
11748 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11749 _PAGE_ACCESSED)
11750
11751 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11752 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11753 +
11754 #define __PAGE_KERNEL_EXEC \
11755 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11756 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11757 @@ -106,7 +109,7 @@
11758 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11759 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11760 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11761 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11762 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11763 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11764 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11765 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11766 @@ -168,8 +171,8 @@
11767 * bits are combined, this will alow user to access the high address mapped
11768 * VDSO in the presence of CONFIG_COMPAT_VDSO
11769 */
11770 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11771 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11772 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11773 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11774 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11775 #endif
11776
11777 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11778 {
11779 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11780 }
11781 +#endif
11782
11783 +#if PAGETABLE_LEVELS == 3
11784 +#include <asm-generic/pgtable-nopud.h>
11785 +#endif
11786 +
11787 +#if PAGETABLE_LEVELS == 2
11788 +#include <asm-generic/pgtable-nopmd.h>
11789 +#endif
11790 +
11791 +#ifndef __ASSEMBLY__
11792 #if PAGETABLE_LEVELS > 3
11793 typedef struct { pudval_t pud; } pud_t;
11794
11795 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11796 return pud.pud;
11797 }
11798 #else
11799 -#include <asm-generic/pgtable-nopud.h>
11800 -
11801 static inline pudval_t native_pud_val(pud_t pud)
11802 {
11803 return native_pgd_val(pud.pgd);
11804 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11805 return pmd.pmd;
11806 }
11807 #else
11808 -#include <asm-generic/pgtable-nopmd.h>
11809 -
11810 static inline pmdval_t native_pmd_val(pmd_t pmd)
11811 {
11812 return native_pgd_val(pmd.pud.pgd);
11813 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11814
11815 extern pteval_t __supported_pte_mask;
11816 extern void set_nx(void);
11817 -extern int nx_enabled;
11818
11819 #define pgprot_writecombine pgprot_writecombine
11820 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11821 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11822 index aea1d1d..680cf09 100644
11823 --- a/arch/x86/include/asm/processor-flags.h
11824 +++ b/arch/x86/include/asm/processor-flags.h
11825 @@ -65,6 +65,7 @@
11826 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11827 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11828 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11829 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11830
11831 /*
11832 * x86-64 Task Priority Register, CR8
11833 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11834 index d048cad..45e350f 100644
11835 --- a/arch/x86/include/asm/processor.h
11836 +++ b/arch/x86/include/asm/processor.h
11837 @@ -289,7 +289,7 @@ struct tss_struct {
11838
11839 } ____cacheline_aligned;
11840
11841 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11842 +extern struct tss_struct init_tss[NR_CPUS];
11843
11844 /*
11845 * Save the original ist values for checking stack pointers during debugging
11846 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11847 */
11848 #define TASK_SIZE PAGE_OFFSET
11849 #define TASK_SIZE_MAX TASK_SIZE
11850 +
11851 +#ifdef CONFIG_PAX_SEGMEXEC
11852 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11853 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11854 +#else
11855 #define STACK_TOP TASK_SIZE
11856 -#define STACK_TOP_MAX STACK_TOP
11857 +#endif
11858 +
11859 +#define STACK_TOP_MAX TASK_SIZE
11860
11861 #define INIT_THREAD { \
11862 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11863 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11864 .vm86_info = NULL, \
11865 .sysenter_cs = __KERNEL_CS, \
11866 .io_bitmap_ptr = NULL, \
11867 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11868 */
11869 #define INIT_TSS { \
11870 .x86_tss = { \
11871 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11872 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11873 .ss0 = __KERNEL_DS, \
11874 .ss1 = __KERNEL_CS, \
11875 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11876 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11877 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11878
11879 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11880 -#define KSTK_TOP(info) \
11881 -({ \
11882 - unsigned long *__ptr = (unsigned long *)(info); \
11883 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11884 -})
11885 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11886
11887 /*
11888 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11889 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11890 #define task_pt_regs(task) \
11891 ({ \
11892 struct pt_regs *__regs__; \
11893 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11894 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11895 __regs__ - 1; \
11896 })
11897
11898 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11899 /*
11900 * User space process size. 47bits minus one guard page.
11901 */
11902 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11903 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11904
11905 /* This decides where the kernel will search for a free chunk of vm
11906 * space during mmap's.
11907 */
11908 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11909 - 0xc0000000 : 0xFFFFe000)
11910 + 0xc0000000 : 0xFFFFf000)
11911
11912 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11913 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11914 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11915 #define STACK_TOP_MAX TASK_SIZE_MAX
11916
11917 #define INIT_THREAD { \
11918 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11919 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11920 }
11921
11922 #define INIT_TSS { \
11923 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11924 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11925 }
11926
11927 /*
11928 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11929 */
11930 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11931
11932 +#ifdef CONFIG_PAX_SEGMEXEC
11933 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11934 +#endif
11935 +
11936 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11937
11938 /* Get/set a process' ability to use the timestamp counter instruction */
11939 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11940 #define cpu_has_amd_erratum(x) (false)
11941 #endif /* CONFIG_CPU_SUP_AMD */
11942
11943 -extern unsigned long arch_align_stack(unsigned long sp);
11944 +#define arch_align_stack(x) ((x) & ~0xfUL)
11945 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11946
11947 void default_idle(void);
11948 bool set_pm_idle_to_default(void);
11949
11950 -void stop_this_cpu(void *dummy);
11951 +void stop_this_cpu(void *dummy) __noreturn;
11952
11953 #endif /* _ASM_X86_PROCESSOR_H */
11954 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11955 index dcfde52..dbfea06 100644
11956 --- a/arch/x86/include/asm/ptrace.h
11957 +++ b/arch/x86/include/asm/ptrace.h
11958 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11959 }
11960
11961 /*
11962 - * user_mode_vm(regs) determines whether a register set came from user mode.
11963 + * user_mode(regs) determines whether a register set came from user mode.
11964 * This is true if V8086 mode was enabled OR if the register set was from
11965 * protected mode with RPL-3 CS value. This tricky test checks that with
11966 * one comparison. Many places in the kernel can bypass this full check
11967 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11968 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11969 + * be used.
11970 */
11971 -static inline int user_mode(struct pt_regs *regs)
11972 +static inline int user_mode_novm(struct pt_regs *regs)
11973 {
11974 #ifdef CONFIG_X86_32
11975 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11976 #else
11977 - return !!(regs->cs & 3);
11978 + return !!(regs->cs & SEGMENT_RPL_MASK);
11979 #endif
11980 }
11981
11982 -static inline int user_mode_vm(struct pt_regs *regs)
11983 +static inline int user_mode(struct pt_regs *regs)
11984 {
11985 #ifdef CONFIG_X86_32
11986 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11987 USER_RPL;
11988 #else
11989 - return user_mode(regs);
11990 + return user_mode_novm(regs);
11991 #endif
11992 }
11993
11994 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11995 #ifdef CONFIG_X86_64
11996 static inline bool user_64bit_mode(struct pt_regs *regs)
11997 {
11998 + unsigned long cs = regs->cs & 0xffff;
11999 #ifndef CONFIG_PARAVIRT
12000 /*
12001 * On non-paravirt systems, this is the only long mode CPL 3
12002 * selector. We do not allow long mode selectors in the LDT.
12003 */
12004 - return regs->cs == __USER_CS;
12005 + return cs == __USER_CS;
12006 #else
12007 /* Headers are too twisted for this to go in paravirt.h. */
12008 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12009 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12010 #endif
12011 }
12012 #endif
12013 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12014 index fe1ec5b..dc5c3fe 100644
12015 --- a/arch/x86/include/asm/realmode.h
12016 +++ b/arch/x86/include/asm/realmode.h
12017 @@ -22,16 +22,14 @@ struct real_mode_header {
12018 #endif
12019 /* APM/BIOS reboot */
12020 u32 machine_real_restart_asm;
12021 -#ifdef CONFIG_X86_64
12022 u32 machine_real_restart_seg;
12023 -#endif
12024 };
12025
12026 /* This must match data at trampoline_32/64.S */
12027 struct trampoline_header {
12028 #ifdef CONFIG_X86_32
12029 u32 start;
12030 - u16 gdt_pad;
12031 + u16 boot_cs;
12032 u16 gdt_limit;
12033 u32 gdt_base;
12034 #else
12035 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12036 index a82c4f1..ac45053 100644
12037 --- a/arch/x86/include/asm/reboot.h
12038 +++ b/arch/x86/include/asm/reboot.h
12039 @@ -6,13 +6,13 @@
12040 struct pt_regs;
12041
12042 struct machine_ops {
12043 - void (*restart)(char *cmd);
12044 - void (*halt)(void);
12045 - void (*power_off)(void);
12046 + void (* __noreturn restart)(char *cmd);
12047 + void (* __noreturn halt)(void);
12048 + void (* __noreturn power_off)(void);
12049 void (*shutdown)(void);
12050 void (*crash_shutdown)(struct pt_regs *);
12051 - void (*emergency_restart)(void);
12052 -};
12053 + void (* __noreturn emergency_restart)(void);
12054 +} __no_const;
12055
12056 extern struct machine_ops machine_ops;
12057
12058 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12059 index 2dbe4a7..ce1db00 100644
12060 --- a/arch/x86/include/asm/rwsem.h
12061 +++ b/arch/x86/include/asm/rwsem.h
12062 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12063 {
12064 asm volatile("# beginning down_read\n\t"
12065 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12066 +
12067 +#ifdef CONFIG_PAX_REFCOUNT
12068 + "jno 0f\n"
12069 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12070 + "int $4\n0:\n"
12071 + _ASM_EXTABLE(0b, 0b)
12072 +#endif
12073 +
12074 /* adds 0x00000001 */
12075 " jns 1f\n"
12076 " call call_rwsem_down_read_failed\n"
12077 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12078 "1:\n\t"
12079 " mov %1,%2\n\t"
12080 " add %3,%2\n\t"
12081 +
12082 +#ifdef CONFIG_PAX_REFCOUNT
12083 + "jno 0f\n"
12084 + "sub %3,%2\n"
12085 + "int $4\n0:\n"
12086 + _ASM_EXTABLE(0b, 0b)
12087 +#endif
12088 +
12089 " jle 2f\n\t"
12090 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12091 " jnz 1b\n\t"
12092 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12093 long tmp;
12094 asm volatile("# beginning down_write\n\t"
12095 LOCK_PREFIX " xadd %1,(%2)\n\t"
12096 +
12097 +#ifdef CONFIG_PAX_REFCOUNT
12098 + "jno 0f\n"
12099 + "mov %1,(%2)\n"
12100 + "int $4\n0:\n"
12101 + _ASM_EXTABLE(0b, 0b)
12102 +#endif
12103 +
12104 /* adds 0xffff0001, returns the old value */
12105 " test %1,%1\n\t"
12106 /* was the count 0 before? */
12107 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12108 long tmp;
12109 asm volatile("# beginning __up_read\n\t"
12110 LOCK_PREFIX " xadd %1,(%2)\n\t"
12111 +
12112 +#ifdef CONFIG_PAX_REFCOUNT
12113 + "jno 0f\n"
12114 + "mov %1,(%2)\n"
12115 + "int $4\n0:\n"
12116 + _ASM_EXTABLE(0b, 0b)
12117 +#endif
12118 +
12119 /* subtracts 1, returns the old value */
12120 " jns 1f\n\t"
12121 " call call_rwsem_wake\n" /* expects old value in %edx */
12122 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12123 long tmp;
12124 asm volatile("# beginning __up_write\n\t"
12125 LOCK_PREFIX " xadd %1,(%2)\n\t"
12126 +
12127 +#ifdef CONFIG_PAX_REFCOUNT
12128 + "jno 0f\n"
12129 + "mov %1,(%2)\n"
12130 + "int $4\n0:\n"
12131 + _ASM_EXTABLE(0b, 0b)
12132 +#endif
12133 +
12134 /* subtracts 0xffff0001, returns the old value */
12135 " jns 1f\n\t"
12136 " call call_rwsem_wake\n" /* expects old value in %edx */
12137 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12138 {
12139 asm volatile("# beginning __downgrade_write\n\t"
12140 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12141 +
12142 +#ifdef CONFIG_PAX_REFCOUNT
12143 + "jno 0f\n"
12144 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12145 + "int $4\n0:\n"
12146 + _ASM_EXTABLE(0b, 0b)
12147 +#endif
12148 +
12149 /*
12150 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12151 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12152 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12153 */
12154 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12155 {
12156 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12157 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12158 +
12159 +#ifdef CONFIG_PAX_REFCOUNT
12160 + "jno 0f\n"
12161 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12162 + "int $4\n0:\n"
12163 + _ASM_EXTABLE(0b, 0b)
12164 +#endif
12165 +
12166 : "+m" (sem->count)
12167 : "er" (delta));
12168 }
12169 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12170 */
12171 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12172 {
12173 - return delta + xadd(&sem->count, delta);
12174 + return delta + xadd_check_overflow(&sem->count, delta);
12175 }
12176
12177 #endif /* __KERNEL__ */
12178 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12179 index c48a950..c6d7468 100644
12180 --- a/arch/x86/include/asm/segment.h
12181 +++ b/arch/x86/include/asm/segment.h
12182 @@ -64,10 +64,15 @@
12183 * 26 - ESPFIX small SS
12184 * 27 - per-cpu [ offset to per-cpu data area ]
12185 * 28 - stack_canary-20 [ for stack protector ]
12186 - * 29 - unused
12187 - * 30 - unused
12188 + * 29 - PCI BIOS CS
12189 + * 30 - PCI BIOS DS
12190 * 31 - TSS for double fault handler
12191 */
12192 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12193 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12194 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12195 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12196 +
12197 #define GDT_ENTRY_TLS_MIN 6
12198 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12199
12200 @@ -79,6 +84,8 @@
12201
12202 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12203
12204 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12205 +
12206 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12207
12208 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12209 @@ -104,6 +111,12 @@
12210 #define __KERNEL_STACK_CANARY 0
12211 #endif
12212
12213 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12214 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12215 +
12216 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12217 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12218 +
12219 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12220
12221 /*
12222 @@ -141,7 +154,7 @@
12223 */
12224
12225 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12226 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12227 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12228
12229
12230 #else
12231 @@ -165,6 +178,8 @@
12232 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12233 #define __USER32_DS __USER_DS
12234
12235 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12236 +
12237 #define GDT_ENTRY_TSS 8 /* needs two entries */
12238 #define GDT_ENTRY_LDT 10 /* needs two entries */
12239 #define GDT_ENTRY_TLS_MIN 12
12240 @@ -185,6 +200,7 @@
12241 #endif
12242
12243 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12244 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12245 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12246 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12247 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12248 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12249 {
12250 unsigned long __limit;
12251 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12252 - return __limit + 1;
12253 + return __limit;
12254 }
12255
12256 #endif /* !__ASSEMBLY__ */
12257 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12258 index 4f19a15..9e14f27 100644
12259 --- a/arch/x86/include/asm/smp.h
12260 +++ b/arch/x86/include/asm/smp.h
12261 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12262 /* cpus sharing the last level cache: */
12263 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12264 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12265 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12266 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12267
12268 static inline struct cpumask *cpu_sibling_mask(int cpu)
12269 {
12270 @@ -79,7 +79,7 @@ struct smp_ops {
12271
12272 void (*send_call_func_ipi)(const struct cpumask *mask);
12273 void (*send_call_func_single_ipi)(int cpu);
12274 -};
12275 +} __no_const;
12276
12277 /* Globals due to paravirt */
12278 extern void set_cpu_sibling_map(int cpu);
12279 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12280 extern int safe_smp_processor_id(void);
12281
12282 #elif defined(CONFIG_X86_64_SMP)
12283 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12284 -
12285 -#define stack_smp_processor_id() \
12286 -({ \
12287 - struct thread_info *ti; \
12288 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12289 - ti->cpu; \
12290 -})
12291 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12292 +#define stack_smp_processor_id() raw_smp_processor_id()
12293 #define safe_smp_processor_id() smp_processor_id()
12294
12295 #endif
12296 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12297 index 33692ea..350a534 100644
12298 --- a/arch/x86/include/asm/spinlock.h
12299 +++ b/arch/x86/include/asm/spinlock.h
12300 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12301 static inline void arch_read_lock(arch_rwlock_t *rw)
12302 {
12303 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12304 +
12305 +#ifdef CONFIG_PAX_REFCOUNT
12306 + "jno 0f\n"
12307 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12308 + "int $4\n0:\n"
12309 + _ASM_EXTABLE(0b, 0b)
12310 +#endif
12311 +
12312 "jns 1f\n"
12313 "call __read_lock_failed\n\t"
12314 "1:\n"
12315 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12316 static inline void arch_write_lock(arch_rwlock_t *rw)
12317 {
12318 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12319 +
12320 +#ifdef CONFIG_PAX_REFCOUNT
12321 + "jno 0f\n"
12322 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12323 + "int $4\n0:\n"
12324 + _ASM_EXTABLE(0b, 0b)
12325 +#endif
12326 +
12327 "jz 1f\n"
12328 "call __write_lock_failed\n\t"
12329 "1:\n"
12330 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12331
12332 static inline void arch_read_unlock(arch_rwlock_t *rw)
12333 {
12334 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12335 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12336 +
12337 +#ifdef CONFIG_PAX_REFCOUNT
12338 + "jno 0f\n"
12339 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12340 + "int $4\n0:\n"
12341 + _ASM_EXTABLE(0b, 0b)
12342 +#endif
12343 +
12344 :"+m" (rw->lock) : : "memory");
12345 }
12346
12347 static inline void arch_write_unlock(arch_rwlock_t *rw)
12348 {
12349 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12350 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12351 +
12352 +#ifdef CONFIG_PAX_REFCOUNT
12353 + "jno 0f\n"
12354 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12355 + "int $4\n0:\n"
12356 + _ASM_EXTABLE(0b, 0b)
12357 +#endif
12358 +
12359 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12360 }
12361
12362 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12363 index 6a99859..03cb807 100644
12364 --- a/arch/x86/include/asm/stackprotector.h
12365 +++ b/arch/x86/include/asm/stackprotector.h
12366 @@ -47,7 +47,7 @@
12367 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12368 */
12369 #define GDT_STACK_CANARY_INIT \
12370 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12371 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12372
12373 /*
12374 * Initialize the stackprotector canary value.
12375 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12376
12377 static inline void load_stack_canary_segment(void)
12378 {
12379 -#ifdef CONFIG_X86_32
12380 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12381 asm volatile ("mov %0, %%gs" : : "r" (0));
12382 #endif
12383 }
12384 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12385 index 70bbe39..4ae2bd4 100644
12386 --- a/arch/x86/include/asm/stacktrace.h
12387 +++ b/arch/x86/include/asm/stacktrace.h
12388 @@ -11,28 +11,20 @@
12389
12390 extern int kstack_depth_to_print;
12391
12392 -struct thread_info;
12393 +struct task_struct;
12394 struct stacktrace_ops;
12395
12396 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12397 - unsigned long *stack,
12398 - unsigned long bp,
12399 - const struct stacktrace_ops *ops,
12400 - void *data,
12401 - unsigned long *end,
12402 - int *graph);
12403 +typedef unsigned long walk_stack_t(struct task_struct *task,
12404 + void *stack_start,
12405 + unsigned long *stack,
12406 + unsigned long bp,
12407 + const struct stacktrace_ops *ops,
12408 + void *data,
12409 + unsigned long *end,
12410 + int *graph);
12411
12412 -extern unsigned long
12413 -print_context_stack(struct thread_info *tinfo,
12414 - unsigned long *stack, unsigned long bp,
12415 - const struct stacktrace_ops *ops, void *data,
12416 - unsigned long *end, int *graph);
12417 -
12418 -extern unsigned long
12419 -print_context_stack_bp(struct thread_info *tinfo,
12420 - unsigned long *stack, unsigned long bp,
12421 - const struct stacktrace_ops *ops, void *data,
12422 - unsigned long *end, int *graph);
12423 +extern walk_stack_t print_context_stack;
12424 +extern walk_stack_t print_context_stack_bp;
12425
12426 /* Generic stack tracer with callbacks */
12427
12428 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12429 void (*address)(void *data, unsigned long address, int reliable);
12430 /* On negative return stop dumping */
12431 int (*stack)(void *data, char *name);
12432 - walk_stack_t walk_stack;
12433 + walk_stack_t *walk_stack;
12434 };
12435
12436 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12437 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12438 index 4ec45b3..a4f0a8a 100644
12439 --- a/arch/x86/include/asm/switch_to.h
12440 +++ b/arch/x86/include/asm/switch_to.h
12441 @@ -108,7 +108,7 @@ do { \
12442 "call __switch_to\n\t" \
12443 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12444 __switch_canary \
12445 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12446 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12447 "movq %%rax,%%rdi\n\t" \
12448 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12449 "jnz ret_from_fork\n\t" \
12450 @@ -119,7 +119,7 @@ do { \
12451 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12452 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12453 [_tif_fork] "i" (_TIF_FORK), \
12454 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12455 + [thread_info] "m" (current_tinfo), \
12456 [current_task] "m" (current_task) \
12457 __switch_canary_iparam \
12458 : "memory", "cc" __EXTRA_CLOBBER)
12459 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12460 index 3fda9db4..4ca1c61 100644
12461 --- a/arch/x86/include/asm/sys_ia32.h
12462 +++ b/arch/x86/include/asm/sys_ia32.h
12463 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12464 struct old_sigaction32 __user *);
12465 asmlinkage long sys32_alarm(unsigned int);
12466
12467 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12468 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12469 asmlinkage long sys32_sysfs(int, u32, u32);
12470
12471 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12472 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12473 index 89f794f..1422765 100644
12474 --- a/arch/x86/include/asm/thread_info.h
12475 +++ b/arch/x86/include/asm/thread_info.h
12476 @@ -10,6 +10,7 @@
12477 #include <linux/compiler.h>
12478 #include <asm/page.h>
12479 #include <asm/types.h>
12480 +#include <asm/percpu.h>
12481
12482 /*
12483 * low level task data that entry.S needs immediate access to
12484 @@ -24,7 +25,6 @@ struct exec_domain;
12485 #include <linux/atomic.h>
12486
12487 struct thread_info {
12488 - struct task_struct *task; /* main task structure */
12489 struct exec_domain *exec_domain; /* execution domain */
12490 __u32 flags; /* low level flags */
12491 __u32 status; /* thread synchronous flags */
12492 @@ -34,19 +34,13 @@ struct thread_info {
12493 mm_segment_t addr_limit;
12494 struct restart_block restart_block;
12495 void __user *sysenter_return;
12496 -#ifdef CONFIG_X86_32
12497 - unsigned long previous_esp; /* ESP of the previous stack in
12498 - case of nested (IRQ) stacks
12499 - */
12500 - __u8 supervisor_stack[0];
12501 -#endif
12502 + unsigned long lowest_stack;
12503 unsigned int sig_on_uaccess_error:1;
12504 unsigned int uaccess_err:1; /* uaccess failed */
12505 };
12506
12507 -#define INIT_THREAD_INFO(tsk) \
12508 +#define INIT_THREAD_INFO \
12509 { \
12510 - .task = &tsk, \
12511 .exec_domain = &default_exec_domain, \
12512 .flags = 0, \
12513 .cpu = 0, \
12514 @@ -57,7 +51,7 @@ struct thread_info {
12515 }, \
12516 }
12517
12518 -#define init_thread_info (init_thread_union.thread_info)
12519 +#define init_thread_info (init_thread_union.stack)
12520 #define init_stack (init_thread_union.stack)
12521
12522 #else /* !__ASSEMBLY__ */
12523 @@ -98,6 +92,7 @@ struct thread_info {
12524 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12525 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12526 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12527 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12528
12529 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12530 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12531 @@ -122,16 +117,18 @@ struct thread_info {
12532 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12533 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12534 #define _TIF_X32 (1 << TIF_X32)
12535 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12536
12537 /* work to do in syscall_trace_enter() */
12538 #define _TIF_WORK_SYSCALL_ENTRY \
12539 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12540 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12541 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12542 + _TIF_GRSEC_SETXID)
12543
12544 /* work to do in syscall_trace_leave() */
12545 #define _TIF_WORK_SYSCALL_EXIT \
12546 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12547 - _TIF_SYSCALL_TRACEPOINT)
12548 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12549
12550 /* work to do on interrupt/exception return */
12551 #define _TIF_WORK_MASK \
12552 @@ -141,7 +138,8 @@ struct thread_info {
12553
12554 /* work to do on any return to user space */
12555 #define _TIF_ALLWORK_MASK \
12556 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12557 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12558 + _TIF_GRSEC_SETXID)
12559
12560 /* Only used for 64 bit */
12561 #define _TIF_DO_NOTIFY_MASK \
12562 @@ -157,45 +155,40 @@ struct thread_info {
12563
12564 #define PREEMPT_ACTIVE 0x10000000
12565
12566 -#ifdef CONFIG_X86_32
12567 -
12568 -#define STACK_WARN (THREAD_SIZE/8)
12569 -/*
12570 - * macros/functions for gaining access to the thread information structure
12571 - *
12572 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12573 - */
12574 -#ifndef __ASSEMBLY__
12575 -
12576 -
12577 -/* how to get the current stack pointer from C */
12578 -register unsigned long current_stack_pointer asm("esp") __used;
12579 -
12580 -/* how to get the thread information struct from C */
12581 -static inline struct thread_info *current_thread_info(void)
12582 -{
12583 - return (struct thread_info *)
12584 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12585 -}
12586 -
12587 -#else /* !__ASSEMBLY__ */
12588 -
12589 +#ifdef __ASSEMBLY__
12590 /* how to get the thread information struct from ASM */
12591 #define GET_THREAD_INFO(reg) \
12592 - movl $-THREAD_SIZE, reg; \
12593 - andl %esp, reg
12594 + mov PER_CPU_VAR(current_tinfo), reg
12595
12596 /* use this one if reg already contains %esp */
12597 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12598 - andl $-THREAD_SIZE, reg
12599 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12600 +#else
12601 +/* how to get the thread information struct from C */
12602 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12603 +
12604 +static __always_inline struct thread_info *current_thread_info(void)
12605 +{
12606 + return this_cpu_read_stable(current_tinfo);
12607 +}
12608 +#endif
12609 +
12610 +#ifdef CONFIG_X86_32
12611 +
12612 +#define STACK_WARN (THREAD_SIZE/8)
12613 +/*
12614 + * macros/functions for gaining access to the thread information structure
12615 + *
12616 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12617 + */
12618 +#ifndef __ASSEMBLY__
12619 +
12620 +/* how to get the current stack pointer from C */
12621 +register unsigned long current_stack_pointer asm("esp") __used;
12622
12623 #endif
12624
12625 #else /* X86_32 */
12626
12627 -#include <asm/percpu.h>
12628 -#define KERNEL_STACK_OFFSET (5*8)
12629 -
12630 /*
12631 * macros/functions for gaining access to the thread information structure
12632 * preempt_count needs to be 1 initially, until the scheduler is functional.
12633 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12634 #ifndef __ASSEMBLY__
12635 DECLARE_PER_CPU(unsigned long, kernel_stack);
12636
12637 -static inline struct thread_info *current_thread_info(void)
12638 -{
12639 - struct thread_info *ti;
12640 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12641 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12642 - return ti;
12643 -}
12644 -
12645 -#else /* !__ASSEMBLY__ */
12646 -
12647 -/* how to get the thread information struct from ASM */
12648 -#define GET_THREAD_INFO(reg) \
12649 - movq PER_CPU_VAR(kernel_stack),reg ; \
12650 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12651 -
12652 -/*
12653 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12654 - * a certain register (to be used in assembler memory operands).
12655 - */
12656 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12657 -
12658 +/* how to get the current stack pointer from C */
12659 +register unsigned long current_stack_pointer asm("rsp") __used;
12660 #endif
12661
12662 #endif /* !X86_32 */
12663 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12664 extern void arch_task_cache_init(void);
12665 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12666 extern void arch_release_task_struct(struct task_struct *tsk);
12667 +
12668 +#define __HAVE_THREAD_FUNCTIONS
12669 +#define task_thread_info(task) (&(task)->tinfo)
12670 +#define task_stack_page(task) ((task)->stack)
12671 +#define setup_thread_stack(p, org) do {} while (0)
12672 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12673 +
12674 #endif
12675 #endif /* _ASM_X86_THREAD_INFO_H */
12676 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12677 index e1f3a17..1ab364d 100644
12678 --- a/arch/x86/include/asm/uaccess.h
12679 +++ b/arch/x86/include/asm/uaccess.h
12680 @@ -7,12 +7,15 @@
12681 #include <linux/compiler.h>
12682 #include <linux/thread_info.h>
12683 #include <linux/string.h>
12684 +#include <linux/sched.h>
12685 #include <asm/asm.h>
12686 #include <asm/page.h>
12687
12688 #define VERIFY_READ 0
12689 #define VERIFY_WRITE 1
12690
12691 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12692 +
12693 /*
12694 * The fs value determines whether argument validity checking should be
12695 * performed or not. If get_fs() == USER_DS, checking is performed, with
12696 @@ -28,7 +31,12 @@
12697
12698 #define get_ds() (KERNEL_DS)
12699 #define get_fs() (current_thread_info()->addr_limit)
12700 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12701 +void __set_fs(mm_segment_t x);
12702 +void set_fs(mm_segment_t x);
12703 +#else
12704 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12705 +#endif
12706
12707 #define segment_eq(a, b) ((a).seg == (b).seg)
12708
12709 @@ -76,8 +84,33 @@
12710 * checks that the pointer is in the user space range - after calling
12711 * this function, memory access functions may still return -EFAULT.
12712 */
12713 -#define access_ok(type, addr, size) \
12714 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12715 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12716 +#define access_ok(type, addr, size) \
12717 +({ \
12718 + long __size = size; \
12719 + unsigned long __addr = (unsigned long)addr; \
12720 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12721 + unsigned long __end_ao = __addr + __size - 1; \
12722 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12723 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12724 + while(__addr_ao <= __end_ao) { \
12725 + char __c_ao; \
12726 + __addr_ao += PAGE_SIZE; \
12727 + if (__size > PAGE_SIZE) \
12728 + cond_resched(); \
12729 + if (__get_user(__c_ao, (char __user *)__addr)) \
12730 + break; \
12731 + if (type != VERIFY_WRITE) { \
12732 + __addr = __addr_ao; \
12733 + continue; \
12734 + } \
12735 + if (__put_user(__c_ao, (char __user *)__addr)) \
12736 + break; \
12737 + __addr = __addr_ao; \
12738 + } \
12739 + } \
12740 + __ret_ao; \
12741 +})
12742
12743 /*
12744 * The exception table consists of pairs of addresses relative to the
12745 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12746 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12747 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12748
12749 -
12750 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12751 +#define __copyuser_seg "gs;"
12752 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12753 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12754 +#else
12755 +#define __copyuser_seg
12756 +#define __COPYUSER_SET_ES
12757 +#define __COPYUSER_RESTORE_ES
12758 +#endif
12759
12760 #ifdef CONFIG_X86_32
12761 #define __put_user_asm_u64(x, addr, err, errret) \
12762 - asm volatile("1: movl %%eax,0(%2)\n" \
12763 - "2: movl %%edx,4(%2)\n" \
12764 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12765 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12766 "3:\n" \
12767 ".section .fixup,\"ax\"\n" \
12768 "4: movl %3,%0\n" \
12769 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12770 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12771
12772 #define __put_user_asm_ex_u64(x, addr) \
12773 - asm volatile("1: movl %%eax,0(%1)\n" \
12774 - "2: movl %%edx,4(%1)\n" \
12775 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12776 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12777 "3:\n" \
12778 _ASM_EXTABLE_EX(1b, 2b) \
12779 _ASM_EXTABLE_EX(2b, 3b) \
12780 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12781 __typeof__(*(ptr)) __pu_val; \
12782 __chk_user_ptr(ptr); \
12783 might_fault(); \
12784 - __pu_val = x; \
12785 + __pu_val = (x); \
12786 switch (sizeof(*(ptr))) { \
12787 case 1: \
12788 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12789 @@ -379,7 +420,7 @@ do { \
12790 } while (0)
12791
12792 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12793 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12794 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12795 "2:\n" \
12796 ".section .fixup,\"ax\"\n" \
12797 "3: mov %3,%0\n" \
12798 @@ -387,7 +428,7 @@ do { \
12799 " jmp 2b\n" \
12800 ".previous\n" \
12801 _ASM_EXTABLE(1b, 3b) \
12802 - : "=r" (err), ltype(x) \
12803 + : "=r" (err), ltype (x) \
12804 : "m" (__m(addr)), "i" (errret), "0" (err))
12805
12806 #define __get_user_size_ex(x, ptr, size) \
12807 @@ -412,7 +453,7 @@ do { \
12808 } while (0)
12809
12810 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12811 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12812 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12813 "2:\n" \
12814 _ASM_EXTABLE_EX(1b, 2b) \
12815 : ltype(x) : "m" (__m(addr)))
12816 @@ -429,13 +470,24 @@ do { \
12817 int __gu_err; \
12818 unsigned long __gu_val; \
12819 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12820 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12821 + (x) = (__typeof__(*(ptr)))__gu_val; \
12822 __gu_err; \
12823 })
12824
12825 /* FIXME: this hack is definitely wrong -AK */
12826 struct __large_struct { unsigned long buf[100]; };
12827 -#define __m(x) (*(struct __large_struct __user *)(x))
12828 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12829 +#define ____m(x) \
12830 +({ \
12831 + unsigned long ____x = (unsigned long)(x); \
12832 + if (____x < PAX_USER_SHADOW_BASE) \
12833 + ____x += PAX_USER_SHADOW_BASE; \
12834 + (void __user *)____x; \
12835 +})
12836 +#else
12837 +#define ____m(x) (x)
12838 +#endif
12839 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12840
12841 /*
12842 * Tell gcc we read from memory instead of writing: this is because
12843 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12844 * aliasing issues.
12845 */
12846 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12847 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12848 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12849 "2:\n" \
12850 ".section .fixup,\"ax\"\n" \
12851 "3: mov %3,%0\n" \
12852 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12853 ".previous\n" \
12854 _ASM_EXTABLE(1b, 3b) \
12855 : "=r"(err) \
12856 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12857 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12858
12859 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12860 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12861 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12862 "2:\n" \
12863 _ASM_EXTABLE_EX(1b, 2b) \
12864 : : ltype(x), "m" (__m(addr)))
12865 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12866 * On error, the variable @x is set to zero.
12867 */
12868
12869 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12870 +#define __get_user(x, ptr) get_user((x), (ptr))
12871 +#else
12872 #define __get_user(x, ptr) \
12873 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12874 +#endif
12875
12876 /**
12877 * __put_user: - Write a simple value into user space, with less checking.
12878 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12879 * Returns zero on success, or -EFAULT on error.
12880 */
12881
12882 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12883 +#define __put_user(x, ptr) put_user((x), (ptr))
12884 +#else
12885 #define __put_user(x, ptr) \
12886 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12887 +#endif
12888
12889 #define __get_user_unaligned __get_user
12890 #define __put_user_unaligned __put_user
12891 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12892 #define get_user_ex(x, ptr) do { \
12893 unsigned long __gue_val; \
12894 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12895 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12896 + (x) = (__typeof__(*(ptr)))__gue_val; \
12897 } while (0)
12898
12899 #ifdef CONFIG_X86_WP_WORKS_OK
12900 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12901 index 576e39b..ccd0a39 100644
12902 --- a/arch/x86/include/asm/uaccess_32.h
12903 +++ b/arch/x86/include/asm/uaccess_32.h
12904 @@ -11,15 +11,15 @@
12905 #include <asm/page.h>
12906
12907 unsigned long __must_check __copy_to_user_ll
12908 - (void __user *to, const void *from, unsigned long n);
12909 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12910 unsigned long __must_check __copy_from_user_ll
12911 - (void *to, const void __user *from, unsigned long n);
12912 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12913 unsigned long __must_check __copy_from_user_ll_nozero
12914 - (void *to, const void __user *from, unsigned long n);
12915 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12916 unsigned long __must_check __copy_from_user_ll_nocache
12917 - (void *to, const void __user *from, unsigned long n);
12918 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12919 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12920 - (void *to, const void __user *from, unsigned long n);
12921 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12922
12923 /**
12924 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12925 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12926 static __always_inline unsigned long __must_check
12927 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12928 {
12929 + if ((long)n < 0)
12930 + return n;
12931 +
12932 if (__builtin_constant_p(n)) {
12933 unsigned long ret;
12934
12935 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12936 return ret;
12937 }
12938 }
12939 + if (!__builtin_constant_p(n))
12940 + check_object_size(from, n, true);
12941 return __copy_to_user_ll(to, from, n);
12942 }
12943
12944 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12945 __copy_to_user(void __user *to, const void *from, unsigned long n)
12946 {
12947 might_fault();
12948 +
12949 return __copy_to_user_inatomic(to, from, n);
12950 }
12951
12952 static __always_inline unsigned long
12953 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12954 {
12955 + if ((long)n < 0)
12956 + return n;
12957 +
12958 /* Avoid zeroing the tail if the copy fails..
12959 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12960 * but as the zeroing behaviour is only significant when n is not
12961 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12962 __copy_from_user(void *to, const void __user *from, unsigned long n)
12963 {
12964 might_fault();
12965 +
12966 + if ((long)n < 0)
12967 + return n;
12968 +
12969 if (__builtin_constant_p(n)) {
12970 unsigned long ret;
12971
12972 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12973 return ret;
12974 }
12975 }
12976 + if (!__builtin_constant_p(n))
12977 + check_object_size(to, n, false);
12978 return __copy_from_user_ll(to, from, n);
12979 }
12980
12981 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12982 const void __user *from, unsigned long n)
12983 {
12984 might_fault();
12985 +
12986 + if ((long)n < 0)
12987 + return n;
12988 +
12989 if (__builtin_constant_p(n)) {
12990 unsigned long ret;
12991
12992 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12993 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12994 unsigned long n)
12995 {
12996 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12997 + if ((long)n < 0)
12998 + return n;
12999 +
13000 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13001 }
13002
13003 -unsigned long __must_check copy_to_user(void __user *to,
13004 - const void *from, unsigned long n);
13005 -unsigned long __must_check _copy_from_user(void *to,
13006 - const void __user *from,
13007 - unsigned long n);
13008 -
13009 +extern void copy_to_user_overflow(void)
13010 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13011 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13012 +#else
13013 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13014 +#endif
13015 +;
13016
13017 extern void copy_from_user_overflow(void)
13018 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13019 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13020 #endif
13021 ;
13022
13023 -static inline unsigned long __must_check copy_from_user(void *to,
13024 - const void __user *from,
13025 - unsigned long n)
13026 +/**
13027 + * copy_to_user: - Copy a block of data into user space.
13028 + * @to: Destination address, in user space.
13029 + * @from: Source address, in kernel space.
13030 + * @n: Number of bytes to copy.
13031 + *
13032 + * Context: User context only. This function may sleep.
13033 + *
13034 + * Copy data from kernel space to user space.
13035 + *
13036 + * Returns number of bytes that could not be copied.
13037 + * On success, this will be zero.
13038 + */
13039 +static inline unsigned long __must_check
13040 +copy_to_user(void __user *to, const void *from, unsigned long n)
13041 {
13042 - int sz = __compiletime_object_size(to);
13043 + size_t sz = __compiletime_object_size(from);
13044
13045 - if (likely(sz == -1 || sz >= n))
13046 - n = _copy_from_user(to, from, n);
13047 - else
13048 + if (unlikely(sz != (size_t)-1 && sz < n))
13049 + copy_to_user_overflow();
13050 + else if (access_ok(VERIFY_WRITE, to, n))
13051 + n = __copy_to_user(to, from, n);
13052 + return n;
13053 +}
13054 +
13055 +/**
13056 + * copy_from_user: - Copy a block of data from user space.
13057 + * @to: Destination address, in kernel space.
13058 + * @from: Source address, in user space.
13059 + * @n: Number of bytes to copy.
13060 + *
13061 + * Context: User context only. This function may sleep.
13062 + *
13063 + * Copy data from user space to kernel space.
13064 + *
13065 + * Returns number of bytes that could not be copied.
13066 + * On success, this will be zero.
13067 + *
13068 + * If some data could not be copied, this function will pad the copied
13069 + * data to the requested size using zero bytes.
13070 + */
13071 +static inline unsigned long __must_check
13072 +copy_from_user(void *to, const void __user *from, unsigned long n)
13073 +{
13074 + size_t sz = __compiletime_object_size(to);
13075 +
13076 + if (unlikely(sz != (size_t)-1 && sz < n))
13077 copy_from_user_overflow();
13078 -
13079 + else if (access_ok(VERIFY_READ, from, n))
13080 + n = __copy_from_user(to, from, n);
13081 + else if ((long)n > 0) {
13082 + if (!__builtin_constant_p(n))
13083 + check_object_size(to, n, false);
13084 + memset(to, 0, n);
13085 + }
13086 return n;
13087 }
13088
13089 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13090 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13091 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13092 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13093
13094 #endif /* _ASM_X86_UACCESS_32_H */
13095 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13096 index d8def8b..ac7fc15 100644
13097 --- a/arch/x86/include/asm/uaccess_64.h
13098 +++ b/arch/x86/include/asm/uaccess_64.h
13099 @@ -10,6 +10,9 @@
13100 #include <asm/alternative.h>
13101 #include <asm/cpufeature.h>
13102 #include <asm/page.h>
13103 +#include <asm/pgtable.h>
13104 +
13105 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13106
13107 /*
13108 * Copy To/From Userspace
13109 @@ -17,13 +20,13 @@
13110
13111 /* Handles exceptions in both to and from, but doesn't do access_ok */
13112 __must_check unsigned long
13113 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13114 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13115 __must_check unsigned long
13116 -copy_user_generic_string(void *to, const void *from, unsigned len);
13117 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13118 __must_check unsigned long
13119 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13120 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13121
13122 -static __always_inline __must_check unsigned long
13123 +static __always_inline __must_check __size_overflow(3) unsigned long
13124 copy_user_generic(void *to, const void *from, unsigned len)
13125 {
13126 unsigned ret;
13127 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13128 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13129 "=d" (len)),
13130 "1" (to), "2" (from), "3" (len)
13131 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13132 + : "memory", "rcx", "r8", "r9", "r11");
13133 return ret;
13134 }
13135
13136 +static __always_inline __must_check unsigned long
13137 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13138 +static __always_inline __must_check unsigned long
13139 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13140 __must_check unsigned long
13141 -_copy_to_user(void __user *to, const void *from, unsigned len);
13142 -__must_check unsigned long
13143 -_copy_from_user(void *to, const void __user *from, unsigned len);
13144 -__must_check unsigned long
13145 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13146 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13147 +
13148 +extern void copy_to_user_overflow(void)
13149 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13150 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13151 +#else
13152 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13153 +#endif
13154 +;
13155 +
13156 +extern void copy_from_user_overflow(void)
13157 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13158 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13159 +#else
13160 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13161 +#endif
13162 +;
13163
13164 static inline unsigned long __must_check copy_from_user(void *to,
13165 const void __user *from,
13166 unsigned long n)
13167 {
13168 - int sz = __compiletime_object_size(to);
13169 -
13170 might_fault();
13171 - if (likely(sz == -1 || sz >= n))
13172 - n = _copy_from_user(to, from, n);
13173 -#ifdef CONFIG_DEBUG_VM
13174 - else
13175 - WARN(1, "Buffer overflow detected!\n");
13176 -#endif
13177 +
13178 + if (access_ok(VERIFY_READ, from, n))
13179 + n = __copy_from_user(to, from, n);
13180 + else if (n < INT_MAX) {
13181 + if (!__builtin_constant_p(n))
13182 + check_object_size(to, n, false);
13183 + memset(to, 0, n);
13184 + }
13185 return n;
13186 }
13187
13188 static __always_inline __must_check
13189 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13190 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13191 {
13192 might_fault();
13193
13194 - return _copy_to_user(dst, src, size);
13195 + if (access_ok(VERIFY_WRITE, dst, size))
13196 + size = __copy_to_user(dst, src, size);
13197 + return size;
13198 }
13199
13200 static __always_inline __must_check
13201 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13202 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13203 {
13204 - int ret = 0;
13205 + size_t sz = __compiletime_object_size(dst);
13206 + unsigned ret = 0;
13207
13208 might_fault();
13209 - if (!__builtin_constant_p(size))
13210 - return copy_user_generic(dst, (__force void *)src, size);
13211 +
13212 + if (size > INT_MAX)
13213 + return size;
13214 +
13215 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13216 + if (!__access_ok(VERIFY_READ, src, size))
13217 + return size;
13218 +#endif
13219 +
13220 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13221 + copy_from_user_overflow();
13222 + return size;
13223 + }
13224 +
13225 + if (!__builtin_constant_p(size)) {
13226 + check_object_size(dst, size, false);
13227 +
13228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13229 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13230 + src += PAX_USER_SHADOW_BASE;
13231 +#endif
13232 +
13233 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13234 + }
13235 switch (size) {
13236 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13237 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13238 ret, "b", "b", "=q", 1);
13239 return ret;
13240 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13241 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13242 ret, "w", "w", "=r", 2);
13243 return ret;
13244 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13245 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13246 ret, "l", "k", "=r", 4);
13247 return ret;
13248 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13249 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13250 ret, "q", "", "=r", 8);
13251 return ret;
13252 case 10:
13253 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13254 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13255 ret, "q", "", "=r", 10);
13256 if (unlikely(ret))
13257 return ret;
13258 __get_user_asm(*(u16 *)(8 + (char *)dst),
13259 - (u16 __user *)(8 + (char __user *)src),
13260 + (const u16 __user *)(8 + (const char __user *)src),
13261 ret, "w", "w", "=r", 2);
13262 return ret;
13263 case 16:
13264 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13265 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13266 ret, "q", "", "=r", 16);
13267 if (unlikely(ret))
13268 return ret;
13269 __get_user_asm(*(u64 *)(8 + (char *)dst),
13270 - (u64 __user *)(8 + (char __user *)src),
13271 + (const u64 __user *)(8 + (const char __user *)src),
13272 ret, "q", "", "=r", 8);
13273 return ret;
13274 default:
13275 - return copy_user_generic(dst, (__force void *)src, size);
13276 +
13277 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13278 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13279 + src += PAX_USER_SHADOW_BASE;
13280 +#endif
13281 +
13282 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13283 }
13284 }
13285
13286 static __always_inline __must_check
13287 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13288 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13289 {
13290 - int ret = 0;
13291 + size_t sz = __compiletime_object_size(src);
13292 + unsigned ret = 0;
13293
13294 might_fault();
13295 - if (!__builtin_constant_p(size))
13296 - return copy_user_generic((__force void *)dst, src, size);
13297 +
13298 + if (size > INT_MAX)
13299 + return size;
13300 +
13301 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13302 + if (!__access_ok(VERIFY_WRITE, dst, size))
13303 + return size;
13304 +#endif
13305 +
13306 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13307 + copy_to_user_overflow();
13308 + return size;
13309 + }
13310 +
13311 + if (!__builtin_constant_p(size)) {
13312 + check_object_size(src, size, true);
13313 +
13314 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13315 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13316 + dst += PAX_USER_SHADOW_BASE;
13317 +#endif
13318 +
13319 + return copy_user_generic((__force_kernel void *)dst, src, size);
13320 + }
13321 switch (size) {
13322 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13323 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13324 ret, "b", "b", "iq", 1);
13325 return ret;
13326 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13327 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13328 ret, "w", "w", "ir", 2);
13329 return ret;
13330 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13331 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13332 ret, "l", "k", "ir", 4);
13333 return ret;
13334 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13335 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13336 ret, "q", "", "er", 8);
13337 return ret;
13338 case 10:
13339 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13340 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13341 ret, "q", "", "er", 10);
13342 if (unlikely(ret))
13343 return ret;
13344 asm("":::"memory");
13345 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13346 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13347 ret, "w", "w", "ir", 2);
13348 return ret;
13349 case 16:
13350 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13351 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13352 ret, "q", "", "er", 16);
13353 if (unlikely(ret))
13354 return ret;
13355 asm("":::"memory");
13356 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13357 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13358 ret, "q", "", "er", 8);
13359 return ret;
13360 default:
13361 - return copy_user_generic((__force void *)dst, src, size);
13362 +
13363 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13364 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13365 + dst += PAX_USER_SHADOW_BASE;
13366 +#endif
13367 +
13368 + return copy_user_generic((__force_kernel void *)dst, src, size);
13369 }
13370 }
13371
13372 static __always_inline __must_check
13373 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13374 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13375 {
13376 - int ret = 0;
13377 + unsigned ret = 0;
13378
13379 might_fault();
13380 - if (!__builtin_constant_p(size))
13381 - return copy_user_generic((__force void *)dst,
13382 - (__force void *)src, size);
13383 +
13384 + if (size > INT_MAX)
13385 + return size;
13386 +
13387 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13388 + if (!__access_ok(VERIFY_READ, src, size))
13389 + return size;
13390 + if (!__access_ok(VERIFY_WRITE, dst, size))
13391 + return size;
13392 +#endif
13393 +
13394 + if (!__builtin_constant_p(size)) {
13395 +
13396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13397 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13398 + src += PAX_USER_SHADOW_BASE;
13399 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13400 + dst += PAX_USER_SHADOW_BASE;
13401 +#endif
13402 +
13403 + return copy_user_generic((__force_kernel void *)dst,
13404 + (__force_kernel const void *)src, size);
13405 + }
13406 switch (size) {
13407 case 1: {
13408 u8 tmp;
13409 - __get_user_asm(tmp, (u8 __user *)src,
13410 + __get_user_asm(tmp, (const u8 __user *)src,
13411 ret, "b", "b", "=q", 1);
13412 if (likely(!ret))
13413 __put_user_asm(tmp, (u8 __user *)dst,
13414 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13415 }
13416 case 2: {
13417 u16 tmp;
13418 - __get_user_asm(tmp, (u16 __user *)src,
13419 + __get_user_asm(tmp, (const u16 __user *)src,
13420 ret, "w", "w", "=r", 2);
13421 if (likely(!ret))
13422 __put_user_asm(tmp, (u16 __user *)dst,
13423 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13424
13425 case 4: {
13426 u32 tmp;
13427 - __get_user_asm(tmp, (u32 __user *)src,
13428 + __get_user_asm(tmp, (const u32 __user *)src,
13429 ret, "l", "k", "=r", 4);
13430 if (likely(!ret))
13431 __put_user_asm(tmp, (u32 __user *)dst,
13432 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13433 }
13434 case 8: {
13435 u64 tmp;
13436 - __get_user_asm(tmp, (u64 __user *)src,
13437 + __get_user_asm(tmp, (const u64 __user *)src,
13438 ret, "q", "", "=r", 8);
13439 if (likely(!ret))
13440 __put_user_asm(tmp, (u64 __user *)dst,
13441 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13442 return ret;
13443 }
13444 default:
13445 - return copy_user_generic((__force void *)dst,
13446 - (__force void *)src, size);
13447 +
13448 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13449 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13450 + src += PAX_USER_SHADOW_BASE;
13451 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13452 + dst += PAX_USER_SHADOW_BASE;
13453 +#endif
13454 +
13455 + return copy_user_generic((__force_kernel void *)dst,
13456 + (__force_kernel const void *)src, size);
13457 }
13458 }
13459
13460 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13461 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13462 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13463 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13464
13465 static __must_check __always_inline int
13466 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13467 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13468 {
13469 - return copy_user_generic(dst, (__force const void *)src, size);
13470 + if (size > INT_MAX)
13471 + return size;
13472 +
13473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13474 + if (!__access_ok(VERIFY_READ, src, size))
13475 + return size;
13476 +
13477 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13478 + src += PAX_USER_SHADOW_BASE;
13479 +#endif
13480 +
13481 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13482 }
13483
13484 -static __must_check __always_inline int
13485 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13486 +static __must_check __always_inline unsigned long
13487 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13488 {
13489 - return copy_user_generic((__force void *)dst, src, size);
13490 + if (size > INT_MAX)
13491 + return size;
13492 +
13493 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13494 + if (!__access_ok(VERIFY_WRITE, dst, size))
13495 + return size;
13496 +
13497 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13498 + dst += PAX_USER_SHADOW_BASE;
13499 +#endif
13500 +
13501 + return copy_user_generic((__force_kernel void *)dst, src, size);
13502 }
13503
13504 -extern long __copy_user_nocache(void *dst, const void __user *src,
13505 - unsigned size, int zerorest);
13506 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13507 + unsigned long size, int zerorest) __size_overflow(3);
13508
13509 -static inline int
13510 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13511 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13512 {
13513 might_sleep();
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 +#endif
13522 +
13523 return __copy_user_nocache(dst, src, size, 1);
13524 }
13525
13526 -static inline int
13527 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13528 - unsigned size)
13529 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13530 + unsigned long size)
13531 {
13532 + if (size > INT_MAX)
13533 + return size;
13534 +
13535 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13536 + if (!__access_ok(VERIFY_READ, src, size))
13537 + return size;
13538 +#endif
13539 +
13540 return __copy_user_nocache(dst, src, size, 0);
13541 }
13542
13543 -unsigned long
13544 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13545 +extern unsigned long
13546 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13547
13548 #endif /* _ASM_X86_UACCESS_64_H */
13549 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13550 index bb05228..d763d5b 100644
13551 --- a/arch/x86/include/asm/vdso.h
13552 +++ b/arch/x86/include/asm/vdso.h
13553 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13554 #define VDSO32_SYMBOL(base, name) \
13555 ({ \
13556 extern const char VDSO32_##name[]; \
13557 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13558 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13559 })
13560 #endif
13561
13562 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13563 index 5b238981..77fdd78 100644
13564 --- a/arch/x86/include/asm/word-at-a-time.h
13565 +++ b/arch/x86/include/asm/word-at-a-time.h
13566 @@ -11,7 +11,7 @@
13567 * and shift, for example.
13568 */
13569 struct word_at_a_time {
13570 - const unsigned long one_bits, high_bits;
13571 + unsigned long one_bits, high_bits;
13572 };
13573
13574 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13575 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13576 index 38155f6..e4184ba 100644
13577 --- a/arch/x86/include/asm/x86_init.h
13578 +++ b/arch/x86/include/asm/x86_init.h
13579 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13580 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13581 void (*find_smp_config)(void);
13582 void (*get_smp_config)(unsigned int early);
13583 -};
13584 +} __no_const;
13585
13586 /**
13587 * struct x86_init_resources - platform specific resource related ops
13588 @@ -43,7 +43,7 @@ struct x86_init_resources {
13589 void (*probe_roms)(void);
13590 void (*reserve_resources)(void);
13591 char *(*memory_setup)(void);
13592 -};
13593 +} __no_const;
13594
13595 /**
13596 * struct x86_init_irqs - platform specific interrupt setup
13597 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13598 void (*pre_vector_init)(void);
13599 void (*intr_init)(void);
13600 void (*trap_init)(void);
13601 -};
13602 +} __no_const;
13603
13604 /**
13605 * struct x86_init_oem - oem platform specific customizing functions
13606 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13607 struct x86_init_oem {
13608 void (*arch_setup)(void);
13609 void (*banner)(void);
13610 -};
13611 +} __no_const;
13612
13613 /**
13614 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13615 @@ -77,7 +77,7 @@ struct x86_init_oem {
13616 */
13617 struct x86_init_mapping {
13618 void (*pagetable_reserve)(u64 start, u64 end);
13619 -};
13620 +} __no_const;
13621
13622 /**
13623 * struct x86_init_paging - platform specific paging functions
13624 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13625 struct x86_init_paging {
13626 void (*pagetable_setup_start)(pgd_t *base);
13627 void (*pagetable_setup_done)(pgd_t *base);
13628 -};
13629 +} __no_const;
13630
13631 /**
13632 * struct x86_init_timers - platform specific timer setup
13633 @@ -102,7 +102,7 @@ struct x86_init_timers {
13634 void (*tsc_pre_init)(void);
13635 void (*timer_init)(void);
13636 void (*wallclock_init)(void);
13637 -};
13638 +} __no_const;
13639
13640 /**
13641 * struct x86_init_iommu - platform specific iommu setup
13642 @@ -110,7 +110,7 @@ struct x86_init_timers {
13643 */
13644 struct x86_init_iommu {
13645 int (*iommu_init)(void);
13646 -};
13647 +} __no_const;
13648
13649 /**
13650 * struct x86_init_pci - platform specific pci init functions
13651 @@ -124,7 +124,7 @@ struct x86_init_pci {
13652 int (*init)(void);
13653 void (*init_irq)(void);
13654 void (*fixup_irqs)(void);
13655 -};
13656 +} __no_const;
13657
13658 /**
13659 * struct x86_init_ops - functions for platform specific setup
13660 @@ -140,7 +140,7 @@ struct x86_init_ops {
13661 struct x86_init_timers timers;
13662 struct x86_init_iommu iommu;
13663 struct x86_init_pci pci;
13664 -};
13665 +} __no_const;
13666
13667 /**
13668 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13669 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13670 void (*setup_percpu_clockev)(void);
13671 void (*early_percpu_clock_init)(void);
13672 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13673 -};
13674 +} __no_const;
13675
13676 /**
13677 * struct x86_platform_ops - platform specific runtime functions
13678 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13679 void (*save_sched_clock_state)(void);
13680 void (*restore_sched_clock_state)(void);
13681 void (*apic_post_init)(void);
13682 -};
13683 +} __no_const;
13684
13685 struct pci_dev;
13686
13687 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13688 void (*teardown_msi_irq)(unsigned int irq);
13689 void (*teardown_msi_irqs)(struct pci_dev *dev);
13690 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13691 -};
13692 +} __no_const;
13693
13694 struct x86_io_apic_ops {
13695 void (*init) (void);
13696 unsigned int (*read) (unsigned int apic, unsigned int reg);
13697 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13698 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13699 -};
13700 +} __no_const;
13701
13702 extern struct x86_init_ops x86_init;
13703 extern struct x86_cpuinit_ops x86_cpuinit;
13704 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13705 index 8a1b6f9..a29c4e4 100644
13706 --- a/arch/x86/include/asm/xsave.h
13707 +++ b/arch/x86/include/asm/xsave.h
13708 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13709 {
13710 int err;
13711
13712 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13713 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13714 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13715 +#endif
13716 +
13717 /*
13718 * Clear the xsave header first, so that reserved fields are
13719 * initialized to zero.
13720 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13721 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13722 {
13723 int err;
13724 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13725 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13726 u32 lmask = mask;
13727 u32 hmask = mask >> 32;
13728
13729 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13730 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13731 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13732 +#endif
13733 +
13734 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13735 "2:\n"
13736 ".section .fixup,\"ax\"\n"
13737 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13738 index 1b8e5a0..354fd59 100644
13739 --- a/arch/x86/kernel/acpi/sleep.c
13740 +++ b/arch/x86/kernel/acpi/sleep.c
13741 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13742 #else /* CONFIG_64BIT */
13743 #ifdef CONFIG_SMP
13744 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13745 +
13746 + pax_open_kernel();
13747 early_gdt_descr.address =
13748 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13749 + pax_close_kernel();
13750 +
13751 initial_gs = per_cpu_offset(smp_processor_id());
13752 #endif
13753 initial_code = (unsigned long)wakeup_long64;
13754 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13755 index 13ab720..95d5442 100644
13756 --- a/arch/x86/kernel/acpi/wakeup_32.S
13757 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13758 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13759 # and restore the stack ... but you need gdt for this to work
13760 movl saved_context_esp, %esp
13761
13762 - movl %cs:saved_magic, %eax
13763 - cmpl $0x12345678, %eax
13764 + cmpl $0x12345678, saved_magic
13765 jne bogus_magic
13766
13767 # jump to place where we left off
13768 - movl saved_eip, %eax
13769 - jmp *%eax
13770 + jmp *(saved_eip)
13771
13772 bogus_magic:
13773 jmp bogus_magic
13774 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13775 index ced4534..3e75d69 100644
13776 --- a/arch/x86/kernel/alternative.c
13777 +++ b/arch/x86/kernel/alternative.c
13778 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13779 */
13780 for (a = start; a < end; a++) {
13781 instr = (u8 *)&a->instr_offset + a->instr_offset;
13782 +
13783 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13784 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13785 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13786 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13787 +#endif
13788 +
13789 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13790 BUG_ON(a->replacementlen > a->instrlen);
13791 BUG_ON(a->instrlen > sizeof(insnbuf));
13792 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13793 for (poff = start; poff < end; poff++) {
13794 u8 *ptr = (u8 *)poff + *poff;
13795
13796 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13797 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13798 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13799 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13800 +#endif
13801 +
13802 if (!*poff || ptr < text || ptr >= text_end)
13803 continue;
13804 /* turn DS segment override prefix into lock prefix */
13805 - if (*ptr == 0x3e)
13806 + if (*ktla_ktva(ptr) == 0x3e)
13807 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13808 };
13809 mutex_unlock(&text_mutex);
13810 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13811 for (poff = start; poff < end; poff++) {
13812 u8 *ptr = (u8 *)poff + *poff;
13813
13814 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13815 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13816 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13817 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13818 +#endif
13819 +
13820 if (!*poff || ptr < text || ptr >= text_end)
13821 continue;
13822 /* turn lock prefix into DS segment override prefix */
13823 - if (*ptr == 0xf0)
13824 + if (*ktla_ktva(ptr) == 0xf0)
13825 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13826 };
13827 mutex_unlock(&text_mutex);
13828 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13829
13830 BUG_ON(p->len > MAX_PATCH_LEN);
13831 /* prep the buffer with the original instructions */
13832 - memcpy(insnbuf, p->instr, p->len);
13833 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13834 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13835 (unsigned long)p->instr, p->len);
13836
13837 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13838 if (smp_alt_once)
13839 free_init_pages("SMP alternatives",
13840 (unsigned long)__smp_locks,
13841 - (unsigned long)__smp_locks_end);
13842 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13843
13844 restart_nmi();
13845 }
13846 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13847 * instructions. And on the local CPU you need to be protected again NMI or MCE
13848 * handlers seeing an inconsistent instruction while you patch.
13849 */
13850 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13851 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13852 size_t len)
13853 {
13854 unsigned long flags;
13855 local_irq_save(flags);
13856 - memcpy(addr, opcode, len);
13857 +
13858 + pax_open_kernel();
13859 + memcpy(ktla_ktva(addr), opcode, len);
13860 sync_core();
13861 + pax_close_kernel();
13862 +
13863 local_irq_restore(flags);
13864 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13865 that causes hangs on some VIA CPUs. */
13866 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13867 */
13868 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13869 {
13870 - unsigned long flags;
13871 - char *vaddr;
13872 + unsigned char *vaddr = ktla_ktva(addr);
13873 struct page *pages[2];
13874 - int i;
13875 + size_t i;
13876
13877 if (!core_kernel_text((unsigned long)addr)) {
13878 - pages[0] = vmalloc_to_page(addr);
13879 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13880 + pages[0] = vmalloc_to_page(vaddr);
13881 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13882 } else {
13883 - pages[0] = virt_to_page(addr);
13884 + pages[0] = virt_to_page(vaddr);
13885 WARN_ON(!PageReserved(pages[0]));
13886 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13887 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13888 }
13889 BUG_ON(!pages[0]);
13890 - local_irq_save(flags);
13891 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13892 - if (pages[1])
13893 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13894 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13895 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13896 - clear_fixmap(FIX_TEXT_POKE0);
13897 - if (pages[1])
13898 - clear_fixmap(FIX_TEXT_POKE1);
13899 - local_flush_tlb();
13900 - sync_core();
13901 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13902 - that causes hangs on some VIA CPUs. */
13903 + text_poke_early(addr, opcode, len);
13904 for (i = 0; i < len; i++)
13905 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13906 - local_irq_restore(flags);
13907 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13908 return addr;
13909 }
13910
13911 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13912 index 24deb30..94a3426 100644
13913 --- a/arch/x86/kernel/apic/apic.c
13914 +++ b/arch/x86/kernel/apic/apic.c
13915 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13916 /*
13917 * Debug level, exported for io_apic.c
13918 */
13919 -unsigned int apic_verbosity;
13920 +int apic_verbosity;
13921
13922 int pic_mode;
13923
13924 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13925 apic_write(APIC_ESR, 0);
13926 v1 = apic_read(APIC_ESR);
13927 ack_APIC_irq();
13928 - atomic_inc(&irq_err_count);
13929 + atomic_inc_unchecked(&irq_err_count);
13930
13931 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13932 smp_processor_id(), v0 , v1);
13933 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13934 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13935 /* Should happen once for each apic */
13936 WARN_ON((*drv)->eoi_write == eoi_write);
13937 - (*drv)->eoi_write = eoi_write;
13938 + pax_open_kernel();
13939 + *(void **)&(*drv)->eoi_write = eoi_write;
13940 + pax_close_kernel();
13941 }
13942 }
13943
13944 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13945 index c265593..137c4ac 100644
13946 --- a/arch/x86/kernel/apic/io_apic.c
13947 +++ b/arch/x86/kernel/apic/io_apic.c
13948 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13949 }
13950 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13951
13952 -void lock_vector_lock(void)
13953 +void lock_vector_lock(void) __acquires(vector_lock)
13954 {
13955 /* Used to the online set of cpus does not change
13956 * during assign_irq_vector.
13957 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13958 raw_spin_lock(&vector_lock);
13959 }
13960
13961 -void unlock_vector_lock(void)
13962 +void unlock_vector_lock(void) __releases(vector_lock)
13963 {
13964 raw_spin_unlock(&vector_lock);
13965 }
13966 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13967 ack_APIC_irq();
13968 }
13969
13970 -atomic_t irq_mis_count;
13971 +atomic_unchecked_t irq_mis_count;
13972
13973 #ifdef CONFIG_GENERIC_PENDING_IRQ
13974 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13975 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13976 * at the cpu.
13977 */
13978 if (!(v & (1 << (i & 0x1f)))) {
13979 - atomic_inc(&irq_mis_count);
13980 + atomic_inc_unchecked(&irq_mis_count);
13981
13982 eoi_ioapic_irq(irq, cfg);
13983 }
13984 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13985 index d65464e..1035d31 100644
13986 --- a/arch/x86/kernel/apm_32.c
13987 +++ b/arch/x86/kernel/apm_32.c
13988 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
13989 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13990 * even though they are called in protected mode.
13991 */
13992 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13993 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13994 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13995
13996 static const char driver_version[] = "1.16ac"; /* no spaces */
13997 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
13998 BUG_ON(cpu != 0);
13999 gdt = get_cpu_gdt_table(cpu);
14000 save_desc_40 = gdt[0x40 / 8];
14001 +
14002 + pax_open_kernel();
14003 gdt[0x40 / 8] = bad_bios_desc;
14004 + pax_close_kernel();
14005
14006 apm_irq_save(flags);
14007 APM_DO_SAVE_SEGS;
14008 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14009 &call->esi);
14010 APM_DO_RESTORE_SEGS;
14011 apm_irq_restore(flags);
14012 +
14013 + pax_open_kernel();
14014 gdt[0x40 / 8] = save_desc_40;
14015 + pax_close_kernel();
14016 +
14017 put_cpu();
14018
14019 return call->eax & 0xff;
14020 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14021 BUG_ON(cpu != 0);
14022 gdt = get_cpu_gdt_table(cpu);
14023 save_desc_40 = gdt[0x40 / 8];
14024 +
14025 + pax_open_kernel();
14026 gdt[0x40 / 8] = bad_bios_desc;
14027 + pax_close_kernel();
14028
14029 apm_irq_save(flags);
14030 APM_DO_SAVE_SEGS;
14031 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14032 &call->eax);
14033 APM_DO_RESTORE_SEGS;
14034 apm_irq_restore(flags);
14035 +
14036 + pax_open_kernel();
14037 gdt[0x40 / 8] = save_desc_40;
14038 + pax_close_kernel();
14039 +
14040 put_cpu();
14041 return error;
14042 }
14043 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14044 * code to that CPU.
14045 */
14046 gdt = get_cpu_gdt_table(0);
14047 +
14048 + pax_open_kernel();
14049 set_desc_base(&gdt[APM_CS >> 3],
14050 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14051 set_desc_base(&gdt[APM_CS_16 >> 3],
14052 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14053 set_desc_base(&gdt[APM_DS >> 3],
14054 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14055 + pax_close_kernel();
14056
14057 proc_create("apm", 0, NULL, &apm_file_ops);
14058
14059 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14060 index 68de2dc..1f3c720 100644
14061 --- a/arch/x86/kernel/asm-offsets.c
14062 +++ b/arch/x86/kernel/asm-offsets.c
14063 @@ -33,6 +33,8 @@ void common(void) {
14064 OFFSET(TI_status, thread_info, status);
14065 OFFSET(TI_addr_limit, thread_info, addr_limit);
14066 OFFSET(TI_preempt_count, thread_info, preempt_count);
14067 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14068 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14069
14070 BLANK();
14071 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14072 @@ -53,8 +55,26 @@ void common(void) {
14073 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14074 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14075 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14076 +
14077 +#ifdef CONFIG_PAX_KERNEXEC
14078 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14079 #endif
14080
14081 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14082 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14083 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14084 +#ifdef CONFIG_X86_64
14085 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14086 +#endif
14087 +#endif
14088 +
14089 +#endif
14090 +
14091 + BLANK();
14092 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14093 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14094 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14095 +
14096 #ifdef CONFIG_XEN
14097 BLANK();
14098 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14099 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14100 index 1b4754f..fbb4227 100644
14101 --- a/arch/x86/kernel/asm-offsets_64.c
14102 +++ b/arch/x86/kernel/asm-offsets_64.c
14103 @@ -76,6 +76,7 @@ int main(void)
14104 BLANK();
14105 #undef ENTRY
14106
14107 + DEFINE(TSS_size, sizeof(struct tss_struct));
14108 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14109 BLANK();
14110
14111 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14112 index d30a6a9..79becab 100644
14113 --- a/arch/x86/kernel/cpu/Makefile
14114 +++ b/arch/x86/kernel/cpu/Makefile
14115 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14116 CFLAGS_REMOVE_perf_event.o = -pg
14117 endif
14118
14119 -# Make sure load_percpu_segment has no stackprotector
14120 -nostackp := $(call cc-option, -fno-stack-protector)
14121 -CFLAGS_common.o := $(nostackp)
14122 -
14123 obj-y := intel_cacheinfo.o scattered.o topology.o
14124 obj-y += proc.o capflags.o powerflags.o common.o
14125 obj-y += vmware.o hypervisor.o mshyperv.o
14126 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14127 index 9d92e19..49d7d79 100644
14128 --- a/arch/x86/kernel/cpu/amd.c
14129 +++ b/arch/x86/kernel/cpu/amd.c
14130 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14131 unsigned int size)
14132 {
14133 /* AMD errata T13 (order #21922) */
14134 - if ((c->x86 == 6)) {
14135 + if (c->x86 == 6) {
14136 /* Duron Rev A0 */
14137 if (c->x86_model == 3 && c->x86_mask == 0)
14138 size = 64;
14139 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14140 index a5fbc3c..2254849 100644
14141 --- a/arch/x86/kernel/cpu/common.c
14142 +++ b/arch/x86/kernel/cpu/common.c
14143 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14144
14145 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14146
14147 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14148 -#ifdef CONFIG_X86_64
14149 - /*
14150 - * We need valid kernel segments for data and code in long mode too
14151 - * IRET will check the segment types kkeil 2000/10/28
14152 - * Also sysret mandates a special GDT layout
14153 - *
14154 - * TLS descriptors are currently at a different place compared to i386.
14155 - * Hopefully nobody expects them at a fixed place (Wine?)
14156 - */
14157 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14158 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14159 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14160 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14161 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14162 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14163 -#else
14164 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14165 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14166 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14167 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14168 - /*
14169 - * Segments used for calling PnP BIOS have byte granularity.
14170 - * They code segments and data segments have fixed 64k limits,
14171 - * the transfer segment sizes are set at run time.
14172 - */
14173 - /* 32-bit code */
14174 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14175 - /* 16-bit code */
14176 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14177 - /* 16-bit data */
14178 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14179 - /* 16-bit data */
14180 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14181 - /* 16-bit data */
14182 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14183 - /*
14184 - * The APM segments have byte granularity and their bases
14185 - * are set at run time. All have 64k limits.
14186 - */
14187 - /* 32-bit code */
14188 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14189 - /* 16-bit code */
14190 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14191 - /* data */
14192 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14193 -
14194 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14195 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14196 - GDT_STACK_CANARY_INIT
14197 -#endif
14198 -} };
14199 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14200 -
14201 static int __init x86_xsave_setup(char *s)
14202 {
14203 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14204 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14205 {
14206 struct desc_ptr gdt_descr;
14207
14208 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14209 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14210 gdt_descr.size = GDT_SIZE - 1;
14211 load_gdt(&gdt_descr);
14212 /* Reload the per-cpu base */
14213 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14214 /* Filter out anything that depends on CPUID levels we don't have */
14215 filter_cpuid_features(c, true);
14216
14217 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14218 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14219 +#endif
14220 +
14221 /* If the model name is still unset, do table lookup. */
14222 if (!c->x86_model_id[0]) {
14223 const char *p;
14224 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14225 }
14226 __setup("clearcpuid=", setup_disablecpuid);
14227
14228 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14229 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14230 +
14231 #ifdef CONFIG_X86_64
14232 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14233 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14234 - (unsigned long) nmi_idt_table };
14235 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14236
14237 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14238 irq_stack_union) __aligned(PAGE_SIZE);
14239 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14240 EXPORT_PER_CPU_SYMBOL(current_task);
14241
14242 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14243 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14244 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14245 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14246
14247 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14248 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14249 {
14250 memset(regs, 0, sizeof(struct pt_regs));
14251 regs->fs = __KERNEL_PERCPU;
14252 - regs->gs = __KERNEL_STACK_CANARY;
14253 + savesegment(gs, regs->gs);
14254
14255 return regs;
14256 }
14257 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14258 int i;
14259
14260 cpu = stack_smp_processor_id();
14261 - t = &per_cpu(init_tss, cpu);
14262 + t = init_tss + cpu;
14263 oist = &per_cpu(orig_ist, cpu);
14264
14265 #ifdef CONFIG_NUMA
14266 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14267 switch_to_new_gdt(cpu);
14268 loadsegment(fs, 0);
14269
14270 - load_idt((const struct desc_ptr *)&idt_descr);
14271 + load_idt(&idt_descr);
14272
14273 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14274 syscall_init();
14275 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14276 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14277 barrier();
14278
14279 - x86_configure_nx();
14280 if (cpu != 0)
14281 enable_x2apic();
14282
14283 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14284 {
14285 int cpu = smp_processor_id();
14286 struct task_struct *curr = current;
14287 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14288 + struct tss_struct *t = init_tss + cpu;
14289 struct thread_struct *thread = &curr->thread;
14290
14291 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14292 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14293 index 0a4ce29..f211176 100644
14294 --- a/arch/x86/kernel/cpu/intel.c
14295 +++ b/arch/x86/kernel/cpu/intel.c
14296 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14297 * Update the IDT descriptor and reload the IDT so that
14298 * it uses the read-only mapped virtual address.
14299 */
14300 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14301 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14302 load_idt(&idt_descr);
14303 }
14304 #endif
14305 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14306 index 292d025..b520c94 100644
14307 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14308 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14309 @@ -45,6 +45,7 @@
14310 #include <asm/processor.h>
14311 #include <asm/mce.h>
14312 #include <asm/msr.h>
14313 +#include <asm/local.h>
14314
14315 #include "mce-internal.h"
14316
14317 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14318 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14319 m->cs, m->ip);
14320
14321 - if (m->cs == __KERNEL_CS)
14322 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14323 print_symbol("{%s}", m->ip);
14324 pr_cont("\n");
14325 }
14326 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14327
14328 #define PANIC_TIMEOUT 5 /* 5 seconds */
14329
14330 -static atomic_t mce_paniced;
14331 +static atomic_unchecked_t mce_paniced;
14332
14333 static int fake_panic;
14334 -static atomic_t mce_fake_paniced;
14335 +static atomic_unchecked_t mce_fake_paniced;
14336
14337 /* Panic in progress. Enable interrupts and wait for final IPI */
14338 static void wait_for_panic(void)
14339 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14340 /*
14341 * Make sure only one CPU runs in machine check panic
14342 */
14343 - if (atomic_inc_return(&mce_paniced) > 1)
14344 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14345 wait_for_panic();
14346 barrier();
14347
14348 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14349 console_verbose();
14350 } else {
14351 /* Don't log too much for fake panic */
14352 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14353 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14354 return;
14355 }
14356 /* First print corrected ones that are still unlogged */
14357 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14358 * might have been modified by someone else.
14359 */
14360 rmb();
14361 - if (atomic_read(&mce_paniced))
14362 + if (atomic_read_unchecked(&mce_paniced))
14363 wait_for_panic();
14364 if (!monarch_timeout)
14365 goto out;
14366 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14367 }
14368
14369 /* Call the installed machine check handler for this CPU setup. */
14370 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14371 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14372 unexpected_machine_check;
14373
14374 /*
14375 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14376 return;
14377 }
14378
14379 + pax_open_kernel();
14380 machine_check_vector = do_machine_check;
14381 + pax_close_kernel();
14382
14383 __mcheck_cpu_init_generic();
14384 __mcheck_cpu_init_vendor(c);
14385 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14386 */
14387
14388 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14389 -static int mce_chrdev_open_count; /* #times opened */
14390 +static local_t mce_chrdev_open_count; /* #times opened */
14391 static int mce_chrdev_open_exclu; /* already open exclusive? */
14392
14393 static int mce_chrdev_open(struct inode *inode, struct file *file)
14394 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14395 spin_lock(&mce_chrdev_state_lock);
14396
14397 if (mce_chrdev_open_exclu ||
14398 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14399 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14400 spin_unlock(&mce_chrdev_state_lock);
14401
14402 return -EBUSY;
14403 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14404
14405 if (file->f_flags & O_EXCL)
14406 mce_chrdev_open_exclu = 1;
14407 - mce_chrdev_open_count++;
14408 + local_inc(&mce_chrdev_open_count);
14409
14410 spin_unlock(&mce_chrdev_state_lock);
14411
14412 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14413 {
14414 spin_lock(&mce_chrdev_state_lock);
14415
14416 - mce_chrdev_open_count--;
14417 + local_dec(&mce_chrdev_open_count);
14418 mce_chrdev_open_exclu = 0;
14419
14420 spin_unlock(&mce_chrdev_state_lock);
14421 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14422 static void mce_reset(void)
14423 {
14424 cpu_missing = 0;
14425 - atomic_set(&mce_fake_paniced, 0);
14426 + atomic_set_unchecked(&mce_fake_paniced, 0);
14427 atomic_set(&mce_executing, 0);
14428 atomic_set(&mce_callin, 0);
14429 atomic_set(&global_nwo, 0);
14430 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14431 index 2d5454c..51987eb 100644
14432 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14433 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14434 @@ -11,6 +11,7 @@
14435 #include <asm/processor.h>
14436 #include <asm/mce.h>
14437 #include <asm/msr.h>
14438 +#include <asm/pgtable.h>
14439
14440 /* By default disabled */
14441 int mce_p5_enabled __read_mostly;
14442 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14443 if (!cpu_has(c, X86_FEATURE_MCE))
14444 return;
14445
14446 + pax_open_kernel();
14447 machine_check_vector = pentium_machine_check;
14448 + pax_close_kernel();
14449 /* Make sure the vector pointer is visible before we enable MCEs: */
14450 wmb();
14451
14452 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14453 index 2d7998f..17c9de1 100644
14454 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14455 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14456 @@ -10,6 +10,7 @@
14457 #include <asm/processor.h>
14458 #include <asm/mce.h>
14459 #include <asm/msr.h>
14460 +#include <asm/pgtable.h>
14461
14462 /* Machine check handler for WinChip C6: */
14463 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14464 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14465 {
14466 u32 lo, hi;
14467
14468 + pax_open_kernel();
14469 machine_check_vector = winchip_machine_check;
14470 + pax_close_kernel();
14471 /* Make sure the vector pointer is visible before we enable MCEs: */
14472 wmb();
14473
14474 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14475 index 6b96110..0da73eb 100644
14476 --- a/arch/x86/kernel/cpu/mtrr/main.c
14477 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14478 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14479 u64 size_or_mask, size_and_mask;
14480 static bool mtrr_aps_delayed_init;
14481
14482 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14483 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14484
14485 const struct mtrr_ops *mtrr_if;
14486
14487 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14488 index df5e41f..816c719 100644
14489 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14490 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14491 @@ -25,7 +25,7 @@ struct mtrr_ops {
14492 int (*validate_add_page)(unsigned long base, unsigned long size,
14493 unsigned int type);
14494 int (*have_wrcomb)(void);
14495 -};
14496 +} __do_const;
14497
14498 extern int generic_get_free_region(unsigned long base, unsigned long size,
14499 int replace_reg);
14500 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14501 index 915b876..171f845 100644
14502 --- a/arch/x86/kernel/cpu/perf_event.c
14503 +++ b/arch/x86/kernel/cpu/perf_event.c
14504 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14505 if (idx > GDT_ENTRIES)
14506 return 0;
14507
14508 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14509 + desc = get_cpu_gdt_table(smp_processor_id());
14510 }
14511
14512 return get_desc_base(desc + idx);
14513 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14514 break;
14515
14516 perf_callchain_store(entry, frame.return_address);
14517 - fp = frame.next_frame;
14518 + fp = (const void __force_user *)frame.next_frame;
14519 }
14520 }
14521
14522 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14523 index 6bca492..36e4496 100644
14524 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14525 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14526 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14527 * v2 and above have a perf capabilities MSR
14528 */
14529 if (version > 1) {
14530 - u64 capabilities;
14531 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14532
14533 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14534 - x86_pmu.intel_cap.capabilities = capabilities;
14535 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14536 + x86_pmu.intel_cap.capabilities = capabilities;
14537 }
14538
14539 intel_ds_init();
14540 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14541 index 13ad899..f642b9a 100644
14542 --- a/arch/x86/kernel/crash.c
14543 +++ b/arch/x86/kernel/crash.c
14544 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14545 {
14546 #ifdef CONFIG_X86_32
14547 struct pt_regs fixed_regs;
14548 -#endif
14549
14550 -#ifdef CONFIG_X86_32
14551 - if (!user_mode_vm(regs)) {
14552 + if (!user_mode(regs)) {
14553 crash_fixup_ss_esp(&fixed_regs, regs);
14554 regs = &fixed_regs;
14555 }
14556 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14557 index 37250fe..bf2ec74 100644
14558 --- a/arch/x86/kernel/doublefault_32.c
14559 +++ b/arch/x86/kernel/doublefault_32.c
14560 @@ -11,7 +11,7 @@
14561
14562 #define DOUBLEFAULT_STACKSIZE (1024)
14563 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14564 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14565 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14566
14567 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14568
14569 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14570 unsigned long gdt, tss;
14571
14572 store_gdt(&gdt_desc);
14573 - gdt = gdt_desc.address;
14574 + gdt = (unsigned long)gdt_desc.address;
14575
14576 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14577
14578 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14579 /* 0x2 bit is always set */
14580 .flags = X86_EFLAGS_SF | 0x2,
14581 .sp = STACK_START,
14582 - .es = __USER_DS,
14583 + .es = __KERNEL_DS,
14584 .cs = __KERNEL_CS,
14585 .ss = __KERNEL_DS,
14586 - .ds = __USER_DS,
14587 + .ds = __KERNEL_DS,
14588 .fs = __KERNEL_PERCPU,
14589
14590 .__cr3 = __pa_nodebug(swapper_pg_dir),
14591 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14592 index ae42418b..787c16b 100644
14593 --- a/arch/x86/kernel/dumpstack.c
14594 +++ b/arch/x86/kernel/dumpstack.c
14595 @@ -2,6 +2,9 @@
14596 * Copyright (C) 1991, 1992 Linus Torvalds
14597 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14598 */
14599 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14600 +#define __INCLUDED_BY_HIDESYM 1
14601 +#endif
14602 #include <linux/kallsyms.h>
14603 #include <linux/kprobes.h>
14604 #include <linux/uaccess.h>
14605 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14606 static void
14607 print_ftrace_graph_addr(unsigned long addr, void *data,
14608 const struct stacktrace_ops *ops,
14609 - struct thread_info *tinfo, int *graph)
14610 + struct task_struct *task, int *graph)
14611 {
14612 - struct task_struct *task;
14613 unsigned long ret_addr;
14614 int index;
14615
14616 if (addr != (unsigned long)return_to_handler)
14617 return;
14618
14619 - task = tinfo->task;
14620 index = task->curr_ret_stack;
14621
14622 if (!task->ret_stack || index < *graph)
14623 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14624 static inline void
14625 print_ftrace_graph_addr(unsigned long addr, void *data,
14626 const struct stacktrace_ops *ops,
14627 - struct thread_info *tinfo, int *graph)
14628 + struct task_struct *task, int *graph)
14629 { }
14630 #endif
14631
14632 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14634 */
14635
14636 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14637 - void *p, unsigned int size, void *end)
14638 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14639 {
14640 - void *t = tinfo;
14641 if (end) {
14642 if (p < end && p >= (end-THREAD_SIZE))
14643 return 1;
14644 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14645 }
14646
14647 unsigned long
14648 -print_context_stack(struct thread_info *tinfo,
14649 +print_context_stack(struct task_struct *task, void *stack_start,
14650 unsigned long *stack, unsigned long bp,
14651 const struct stacktrace_ops *ops, void *data,
14652 unsigned long *end, int *graph)
14653 {
14654 struct stack_frame *frame = (struct stack_frame *)bp;
14655
14656 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14657 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14658 unsigned long addr;
14659
14660 addr = *stack;
14661 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14662 } else {
14663 ops->address(data, addr, 0);
14664 }
14665 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14666 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14667 }
14668 stack++;
14669 }
14670 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14671 EXPORT_SYMBOL_GPL(print_context_stack);
14672
14673 unsigned long
14674 -print_context_stack_bp(struct thread_info *tinfo,
14675 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14676 unsigned long *stack, unsigned long bp,
14677 const struct stacktrace_ops *ops, void *data,
14678 unsigned long *end, int *graph)
14679 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14680 struct stack_frame *frame = (struct stack_frame *)bp;
14681 unsigned long *ret_addr = &frame->return_address;
14682
14683 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14684 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14685 unsigned long addr = *ret_addr;
14686
14687 if (!__kernel_text_address(addr))
14688 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 ops->address(data, addr, 1);
14690 frame = frame->next_frame;
14691 ret_addr = &frame->return_address;
14692 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14693 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14694 }
14695
14696 return (unsigned long)frame;
14697 @@ -189,7 +188,7 @@ void dump_stack(void)
14698
14699 bp = stack_frame(current, NULL);
14700 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14701 - current->pid, current->comm, print_tainted(),
14702 + task_pid_nr(current), current->comm, print_tainted(),
14703 init_utsname()->release,
14704 (int)strcspn(init_utsname()->version, " "),
14705 init_utsname()->version);
14706 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14707 }
14708 EXPORT_SYMBOL_GPL(oops_begin);
14709
14710 +extern void gr_handle_kernel_exploit(void);
14711 +
14712 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14713 {
14714 if (regs && kexec_should_crash(current))
14715 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14716 panic("Fatal exception in interrupt");
14717 if (panic_on_oops)
14718 panic("Fatal exception");
14719 - do_exit(signr);
14720 +
14721 + gr_handle_kernel_exploit();
14722 +
14723 + do_group_exit(signr);
14724 }
14725
14726 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14727 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14728 print_modules();
14729 show_regs(regs);
14730 #ifdef CONFIG_X86_32
14731 - if (user_mode_vm(regs)) {
14732 + if (user_mode(regs)) {
14733 sp = regs->sp;
14734 ss = regs->ss & 0xffff;
14735 } else {
14736 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14737 unsigned long flags = oops_begin();
14738 int sig = SIGSEGV;
14739
14740 - if (!user_mode_vm(regs))
14741 + if (!user_mode(regs))
14742 report_bug(regs->ip, regs);
14743
14744 if (__die(str, regs, err))
14745 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14746 index 1038a41..ac7e5f6 100644
14747 --- a/arch/x86/kernel/dumpstack_32.c
14748 +++ b/arch/x86/kernel/dumpstack_32.c
14749 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14750 bp = stack_frame(task, regs);
14751
14752 for (;;) {
14753 - struct thread_info *context;
14754 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14755
14756 - context = (struct thread_info *)
14757 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14758 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14759 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14760
14761 - stack = (unsigned long *)context->previous_esp;
14762 - if (!stack)
14763 + if (stack_start == task_stack_page(task))
14764 break;
14765 + stack = *(unsigned long **)stack_start;
14766 if (ops->stack(data, "IRQ") < 0)
14767 break;
14768 touch_nmi_watchdog();
14769 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14770 {
14771 int i;
14772
14773 - __show_regs(regs, !user_mode_vm(regs));
14774 + __show_regs(regs, !user_mode(regs));
14775
14776 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14777 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14778 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14779 * When in-kernel, we also print out the stack and code at the
14780 * time of the fault..
14781 */
14782 - if (!user_mode_vm(regs)) {
14783 + if (!user_mode(regs)) {
14784 unsigned int code_prologue = code_bytes * 43 / 64;
14785 unsigned int code_len = code_bytes;
14786 unsigned char c;
14787 u8 *ip;
14788 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14789
14790 pr_emerg("Stack:\n");
14791 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14792
14793 pr_emerg("Code:");
14794
14795 - ip = (u8 *)regs->ip - code_prologue;
14796 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14797 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14798 /* try starting at IP */
14799 - ip = (u8 *)regs->ip;
14800 + ip = (u8 *)regs->ip + cs_base;
14801 code_len = code_len - code_prologue + 1;
14802 }
14803 for (i = 0; i < code_len; i++, ip++) {
14804 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14805 pr_cont(" Bad EIP value.");
14806 break;
14807 }
14808 - if (ip == (u8 *)regs->ip)
14809 + if (ip == (u8 *)regs->ip + cs_base)
14810 pr_cont(" <%02x>", c);
14811 else
14812 pr_cont(" %02x", c);
14813 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14814 {
14815 unsigned short ud2;
14816
14817 + ip = ktla_ktva(ip);
14818 if (ip < PAGE_OFFSET)
14819 return 0;
14820 if (probe_kernel_address((unsigned short *)ip, ud2))
14821 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14822
14823 return ud2 == 0x0b0f;
14824 }
14825 +
14826 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14827 +void pax_check_alloca(unsigned long size)
14828 +{
14829 + unsigned long sp = (unsigned long)&sp, stack_left;
14830 +
14831 + /* all kernel stacks are of the same size */
14832 + stack_left = sp & (THREAD_SIZE - 1);
14833 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14834 +}
14835 +EXPORT_SYMBOL(pax_check_alloca);
14836 +#endif
14837 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14838 index b653675..33190c0 100644
14839 --- a/arch/x86/kernel/dumpstack_64.c
14840 +++ b/arch/x86/kernel/dumpstack_64.c
14841 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14842 unsigned long *irq_stack_end =
14843 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14844 unsigned used = 0;
14845 - struct thread_info *tinfo;
14846 int graph = 0;
14847 unsigned long dummy;
14848 + void *stack_start;
14849
14850 if (!task)
14851 task = current;
14852 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14853 * current stack address. If the stacks consist of nested
14854 * exceptions
14855 */
14856 - tinfo = task_thread_info(task);
14857 for (;;) {
14858 char *id;
14859 unsigned long *estack_end;
14860 +
14861 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14862 &used, &id);
14863
14864 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14865 if (ops->stack(data, id) < 0)
14866 break;
14867
14868 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14869 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14870 data, estack_end, &graph);
14871 ops->stack(data, "<EOE>");
14872 /*
14873 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 * second-to-last pointer (index -2 to end) in the
14875 * exception stack:
14876 */
14877 + if ((u16)estack_end[-1] != __KERNEL_DS)
14878 + goto out;
14879 stack = (unsigned long *) estack_end[-2];
14880 continue;
14881 }
14882 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14884 if (ops->stack(data, "IRQ") < 0)
14885 break;
14886 - bp = ops->walk_stack(tinfo, stack, bp,
14887 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14888 ops, data, irq_stack_end, &graph);
14889 /*
14890 * We link to the next stack (which would be
14891 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 /*
14893 * This handles the process stack:
14894 */
14895 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14896 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14897 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14898 +out:
14899 put_cpu();
14900 }
14901 EXPORT_SYMBOL(dump_trace);
14902 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14903
14904 return ud2 == 0x0b0f;
14905 }
14906 +
14907 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14908 +void pax_check_alloca(unsigned long size)
14909 +{
14910 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14911 + unsigned cpu, used;
14912 + char *id;
14913 +
14914 + /* check the process stack first */
14915 + stack_start = (unsigned long)task_stack_page(current);
14916 + stack_end = stack_start + THREAD_SIZE;
14917 + if (likely(stack_start <= sp && sp < stack_end)) {
14918 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14919 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14920 + return;
14921 + }
14922 +
14923 + cpu = get_cpu();
14924 +
14925 + /* check the irq stacks */
14926 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14927 + stack_start = stack_end - IRQ_STACK_SIZE;
14928 + if (stack_start <= sp && sp < stack_end) {
14929 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14930 + put_cpu();
14931 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14932 + return;
14933 + }
14934 +
14935 + /* check the exception stacks */
14936 + used = 0;
14937 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14938 + stack_start = stack_end - EXCEPTION_STKSZ;
14939 + if (stack_end && stack_start <= sp && sp < stack_end) {
14940 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14941 + put_cpu();
14942 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14943 + return;
14944 + }
14945 +
14946 + put_cpu();
14947 +
14948 + /* unknown stack */
14949 + BUG();
14950 +}
14951 +EXPORT_SYMBOL(pax_check_alloca);
14952 +#endif
14953 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14954 index 9b9f18b..9fcaa04 100644
14955 --- a/arch/x86/kernel/early_printk.c
14956 +++ b/arch/x86/kernel/early_printk.c
14957 @@ -7,6 +7,7 @@
14958 #include <linux/pci_regs.h>
14959 #include <linux/pci_ids.h>
14960 #include <linux/errno.h>
14961 +#include <linux/sched.h>
14962 #include <asm/io.h>
14963 #include <asm/processor.h>
14964 #include <asm/fcntl.h>
14965 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14966 index 8f8e8ee..3617d6e 100644
14967 --- a/arch/x86/kernel/entry_32.S
14968 +++ b/arch/x86/kernel/entry_32.S
14969 @@ -176,13 +176,153 @@
14970 /*CFI_REL_OFFSET gs, PT_GS*/
14971 .endm
14972 .macro SET_KERNEL_GS reg
14973 +
14974 +#ifdef CONFIG_CC_STACKPROTECTOR
14975 movl $(__KERNEL_STACK_CANARY), \reg
14976 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14977 + movl $(__USER_DS), \reg
14978 +#else
14979 + xorl \reg, \reg
14980 +#endif
14981 +
14982 movl \reg, %gs
14983 .endm
14984
14985 #endif /* CONFIG_X86_32_LAZY_GS */
14986
14987 -.macro SAVE_ALL
14988 +.macro pax_enter_kernel
14989 +#ifdef CONFIG_PAX_KERNEXEC
14990 + call pax_enter_kernel
14991 +#endif
14992 +.endm
14993 +
14994 +.macro pax_exit_kernel
14995 +#ifdef CONFIG_PAX_KERNEXEC
14996 + call pax_exit_kernel
14997 +#endif
14998 +.endm
14999 +
15000 +#ifdef CONFIG_PAX_KERNEXEC
15001 +ENTRY(pax_enter_kernel)
15002 +#ifdef CONFIG_PARAVIRT
15003 + pushl %eax
15004 + pushl %ecx
15005 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15006 + mov %eax, %esi
15007 +#else
15008 + mov %cr0, %esi
15009 +#endif
15010 + bts $16, %esi
15011 + jnc 1f
15012 + mov %cs, %esi
15013 + cmp $__KERNEL_CS, %esi
15014 + jz 3f
15015 + ljmp $__KERNEL_CS, $3f
15016 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15017 +2:
15018 +#ifdef CONFIG_PARAVIRT
15019 + mov %esi, %eax
15020 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15021 +#else
15022 + mov %esi, %cr0
15023 +#endif
15024 +3:
15025 +#ifdef CONFIG_PARAVIRT
15026 + popl %ecx
15027 + popl %eax
15028 +#endif
15029 + ret
15030 +ENDPROC(pax_enter_kernel)
15031 +
15032 +ENTRY(pax_exit_kernel)
15033 +#ifdef CONFIG_PARAVIRT
15034 + pushl %eax
15035 + pushl %ecx
15036 +#endif
15037 + mov %cs, %esi
15038 + cmp $__KERNEXEC_KERNEL_CS, %esi
15039 + jnz 2f
15040 +#ifdef CONFIG_PARAVIRT
15041 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15042 + mov %eax, %esi
15043 +#else
15044 + mov %cr0, %esi
15045 +#endif
15046 + btr $16, %esi
15047 + ljmp $__KERNEL_CS, $1f
15048 +1:
15049 +#ifdef CONFIG_PARAVIRT
15050 + mov %esi, %eax
15051 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15052 +#else
15053 + mov %esi, %cr0
15054 +#endif
15055 +2:
15056 +#ifdef CONFIG_PARAVIRT
15057 + popl %ecx
15058 + popl %eax
15059 +#endif
15060 + ret
15061 +ENDPROC(pax_exit_kernel)
15062 +#endif
15063 +
15064 +.macro pax_erase_kstack
15065 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15066 + call pax_erase_kstack
15067 +#endif
15068 +.endm
15069 +
15070 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15071 +/*
15072 + * ebp: thread_info
15073 + */
15074 +ENTRY(pax_erase_kstack)
15075 + pushl %edi
15076 + pushl %ecx
15077 + pushl %eax
15078 +
15079 + mov TI_lowest_stack(%ebp), %edi
15080 + mov $-0xBEEF, %eax
15081 + std
15082 +
15083 +1: mov %edi, %ecx
15084 + and $THREAD_SIZE_asm - 1, %ecx
15085 + shr $2, %ecx
15086 + repne scasl
15087 + jecxz 2f
15088 +
15089 + cmp $2*16, %ecx
15090 + jc 2f
15091 +
15092 + mov $2*16, %ecx
15093 + repe scasl
15094 + jecxz 2f
15095 + jne 1b
15096 +
15097 +2: cld
15098 + mov %esp, %ecx
15099 + sub %edi, %ecx
15100 +
15101 + cmp $THREAD_SIZE_asm, %ecx
15102 + jb 3f
15103 + ud2
15104 +3:
15105 +
15106 + shr $2, %ecx
15107 + rep stosl
15108 +
15109 + mov TI_task_thread_sp0(%ebp), %edi
15110 + sub $128, %edi
15111 + mov %edi, TI_lowest_stack(%ebp)
15112 +
15113 + popl %eax
15114 + popl %ecx
15115 + popl %edi
15116 + ret
15117 +ENDPROC(pax_erase_kstack)
15118 +#endif
15119 +
15120 +.macro __SAVE_ALL _DS
15121 cld
15122 PUSH_GS
15123 pushl_cfi %fs
15124 @@ -205,7 +345,7 @@
15125 CFI_REL_OFFSET ecx, 0
15126 pushl_cfi %ebx
15127 CFI_REL_OFFSET ebx, 0
15128 - movl $(__USER_DS), %edx
15129 + movl $\_DS, %edx
15130 movl %edx, %ds
15131 movl %edx, %es
15132 movl $(__KERNEL_PERCPU), %edx
15133 @@ -213,6 +353,15 @@
15134 SET_KERNEL_GS %edx
15135 .endm
15136
15137 +.macro SAVE_ALL
15138 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15139 + __SAVE_ALL __KERNEL_DS
15140 + pax_enter_kernel
15141 +#else
15142 + __SAVE_ALL __USER_DS
15143 +#endif
15144 +.endm
15145 +
15146 .macro RESTORE_INT_REGS
15147 popl_cfi %ebx
15148 CFI_RESTORE ebx
15149 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15150 popfl_cfi
15151 jmp syscall_exit
15152 CFI_ENDPROC
15153 -END(ret_from_fork)
15154 +ENDPROC(ret_from_fork)
15155
15156 /*
15157 * Interrupt exit functions should be protected against kprobes
15158 @@ -329,7 +478,15 @@ ret_from_intr:
15159 andl $SEGMENT_RPL_MASK, %eax
15160 #endif
15161 cmpl $USER_RPL, %eax
15162 +
15163 +#ifdef CONFIG_PAX_KERNEXEC
15164 + jae resume_userspace
15165 +
15166 + pax_exit_kernel
15167 + jmp resume_kernel
15168 +#else
15169 jb resume_kernel # not returning to v8086 or userspace
15170 +#endif
15171
15172 ENTRY(resume_userspace)
15173 LOCKDEP_SYS_EXIT
15174 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15175 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15176 # int/exception return?
15177 jne work_pending
15178 - jmp restore_all
15179 -END(ret_from_exception)
15180 + jmp restore_all_pax
15181 +ENDPROC(ret_from_exception)
15182
15183 #ifdef CONFIG_PREEMPT
15184 ENTRY(resume_kernel)
15185 @@ -357,7 +514,7 @@ need_resched:
15186 jz restore_all
15187 call preempt_schedule_irq
15188 jmp need_resched
15189 -END(resume_kernel)
15190 +ENDPROC(resume_kernel)
15191 #endif
15192 CFI_ENDPROC
15193 /*
15194 @@ -391,28 +548,43 @@ sysenter_past_esp:
15195 /*CFI_REL_OFFSET cs, 0*/
15196 /*
15197 * Push current_thread_info()->sysenter_return to the stack.
15198 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15199 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15200 */
15201 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15202 + pushl_cfi $0
15203 CFI_REL_OFFSET eip, 0
15204
15205 pushl_cfi %eax
15206 SAVE_ALL
15207 + GET_THREAD_INFO(%ebp)
15208 + movl TI_sysenter_return(%ebp),%ebp
15209 + movl %ebp,PT_EIP(%esp)
15210 ENABLE_INTERRUPTS(CLBR_NONE)
15211
15212 /*
15213 * Load the potential sixth argument from user stack.
15214 * Careful about security.
15215 */
15216 + movl PT_OLDESP(%esp),%ebp
15217 +
15218 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15219 + mov PT_OLDSS(%esp),%ds
15220 +1: movl %ds:(%ebp),%ebp
15221 + push %ss
15222 + pop %ds
15223 +#else
15224 cmpl $__PAGE_OFFSET-3,%ebp
15225 jae syscall_fault
15226 1: movl (%ebp),%ebp
15227 +#endif
15228 +
15229 movl %ebp,PT_EBP(%esp)
15230 _ASM_EXTABLE(1b,syscall_fault)
15231
15232 GET_THREAD_INFO(%ebp)
15233
15234 +#ifdef CONFIG_PAX_RANDKSTACK
15235 + pax_erase_kstack
15236 +#endif
15237 +
15238 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15239 jnz sysenter_audit
15240 sysenter_do_call:
15241 @@ -427,12 +599,24 @@ sysenter_do_call:
15242 testl $_TIF_ALLWORK_MASK, %ecx
15243 jne sysexit_audit
15244 sysenter_exit:
15245 +
15246 +#ifdef CONFIG_PAX_RANDKSTACK
15247 + pushl_cfi %eax
15248 + movl %esp, %eax
15249 + call pax_randomize_kstack
15250 + popl_cfi %eax
15251 +#endif
15252 +
15253 + pax_erase_kstack
15254 +
15255 /* if something modifies registers it must also disable sysexit */
15256 movl PT_EIP(%esp), %edx
15257 movl PT_OLDESP(%esp), %ecx
15258 xorl %ebp,%ebp
15259 TRACE_IRQS_ON
15260 1: mov PT_FS(%esp), %fs
15261 +2: mov PT_DS(%esp), %ds
15262 +3: mov PT_ES(%esp), %es
15263 PTGS_TO_GS
15264 ENABLE_INTERRUPTS_SYSEXIT
15265
15266 @@ -449,6 +633,9 @@ sysenter_audit:
15267 movl %eax,%edx /* 2nd arg: syscall number */
15268 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15269 call __audit_syscall_entry
15270 +
15271 + pax_erase_kstack
15272 +
15273 pushl_cfi %ebx
15274 movl PT_EAX(%esp),%eax /* reload syscall number */
15275 jmp sysenter_do_call
15276 @@ -474,10 +661,16 @@ sysexit_audit:
15277
15278 CFI_ENDPROC
15279 .pushsection .fixup,"ax"
15280 -2: movl $0,PT_FS(%esp)
15281 +4: movl $0,PT_FS(%esp)
15282 + jmp 1b
15283 +5: movl $0,PT_DS(%esp)
15284 + jmp 1b
15285 +6: movl $0,PT_ES(%esp)
15286 jmp 1b
15287 .popsection
15288 - _ASM_EXTABLE(1b,2b)
15289 + _ASM_EXTABLE(1b,4b)
15290 + _ASM_EXTABLE(2b,5b)
15291 + _ASM_EXTABLE(3b,6b)
15292 PTGS_TO_GS_EX
15293 ENDPROC(ia32_sysenter_target)
15294
15295 @@ -491,6 +684,11 @@ ENTRY(system_call)
15296 pushl_cfi %eax # save orig_eax
15297 SAVE_ALL
15298 GET_THREAD_INFO(%ebp)
15299 +
15300 +#ifdef CONFIG_PAX_RANDKSTACK
15301 + pax_erase_kstack
15302 +#endif
15303 +
15304 # system call tracing in operation / emulation
15305 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15306 jnz syscall_trace_entry
15307 @@ -509,6 +707,15 @@ syscall_exit:
15308 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15309 jne syscall_exit_work
15310
15311 +restore_all_pax:
15312 +
15313 +#ifdef CONFIG_PAX_RANDKSTACK
15314 + movl %esp, %eax
15315 + call pax_randomize_kstack
15316 +#endif
15317 +
15318 + pax_erase_kstack
15319 +
15320 restore_all:
15321 TRACE_IRQS_IRET
15322 restore_all_notrace:
15323 @@ -565,14 +772,34 @@ ldt_ss:
15324 * compensating for the offset by changing to the ESPFIX segment with
15325 * a base address that matches for the difference.
15326 */
15327 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15328 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15329 mov %esp, %edx /* load kernel esp */
15330 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15331 mov %dx, %ax /* eax: new kernel esp */
15332 sub %eax, %edx /* offset (low word is 0) */
15333 +#ifdef CONFIG_SMP
15334 + movl PER_CPU_VAR(cpu_number), %ebx
15335 + shll $PAGE_SHIFT_asm, %ebx
15336 + addl $cpu_gdt_table, %ebx
15337 +#else
15338 + movl $cpu_gdt_table, %ebx
15339 +#endif
15340 shr $16, %edx
15341 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15342 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15343 +
15344 +#ifdef CONFIG_PAX_KERNEXEC
15345 + mov %cr0, %esi
15346 + btr $16, %esi
15347 + mov %esi, %cr0
15348 +#endif
15349 +
15350 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15351 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15352 +
15353 +#ifdef CONFIG_PAX_KERNEXEC
15354 + bts $16, %esi
15355 + mov %esi, %cr0
15356 +#endif
15357 +
15358 pushl_cfi $__ESPFIX_SS
15359 pushl_cfi %eax /* new kernel esp */
15360 /* Disable interrupts, but do not irqtrace this section: we
15361 @@ -601,35 +828,23 @@ work_resched:
15362 movl TI_flags(%ebp), %ecx
15363 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15364 # than syscall tracing?
15365 - jz restore_all
15366 + jz restore_all_pax
15367 testb $_TIF_NEED_RESCHED, %cl
15368 jnz work_resched
15369
15370 work_notifysig: # deal with pending signals and
15371 # notify-resume requests
15372 + movl %esp, %eax
15373 #ifdef CONFIG_VM86
15374 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15375 - movl %esp, %eax
15376 - jne work_notifysig_v86 # returning to kernel-space or
15377 + jz 1f # returning to kernel-space or
15378 # vm86-space
15379 - TRACE_IRQS_ON
15380 - ENABLE_INTERRUPTS(CLBR_NONE)
15381 - movb PT_CS(%esp), %bl
15382 - andb $SEGMENT_RPL_MASK, %bl
15383 - cmpb $USER_RPL, %bl
15384 - jb resume_kernel
15385 - xorl %edx, %edx
15386 - call do_notify_resume
15387 - jmp resume_userspace
15388
15389 - ALIGN
15390 -work_notifysig_v86:
15391 pushl_cfi %ecx # save ti_flags for do_notify_resume
15392 call save_v86_state # %eax contains pt_regs pointer
15393 popl_cfi %ecx
15394 movl %eax, %esp
15395 -#else
15396 - movl %esp, %eax
15397 +1:
15398 #endif
15399 TRACE_IRQS_ON
15400 ENABLE_INTERRUPTS(CLBR_NONE)
15401 @@ -640,7 +855,7 @@ work_notifysig_v86:
15402 xorl %edx, %edx
15403 call do_notify_resume
15404 jmp resume_userspace
15405 -END(work_pending)
15406 +ENDPROC(work_pending)
15407
15408 # perform syscall exit tracing
15409 ALIGN
15410 @@ -648,11 +863,14 @@ syscall_trace_entry:
15411 movl $-ENOSYS,PT_EAX(%esp)
15412 movl %esp, %eax
15413 call syscall_trace_enter
15414 +
15415 + pax_erase_kstack
15416 +
15417 /* What it returned is what we'll actually use. */
15418 cmpl $(NR_syscalls), %eax
15419 jnae syscall_call
15420 jmp syscall_exit
15421 -END(syscall_trace_entry)
15422 +ENDPROC(syscall_trace_entry)
15423
15424 # perform syscall exit tracing
15425 ALIGN
15426 @@ -665,20 +883,24 @@ syscall_exit_work:
15427 movl %esp, %eax
15428 call syscall_trace_leave
15429 jmp resume_userspace
15430 -END(syscall_exit_work)
15431 +ENDPROC(syscall_exit_work)
15432 CFI_ENDPROC
15433
15434 RING0_INT_FRAME # can't unwind into user space anyway
15435 syscall_fault:
15436 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15437 + push %ss
15438 + pop %ds
15439 +#endif
15440 GET_THREAD_INFO(%ebp)
15441 movl $-EFAULT,PT_EAX(%esp)
15442 jmp resume_userspace
15443 -END(syscall_fault)
15444 +ENDPROC(syscall_fault)
15445
15446 syscall_badsys:
15447 movl $-ENOSYS,PT_EAX(%esp)
15448 jmp resume_userspace
15449 -END(syscall_badsys)
15450 +ENDPROC(syscall_badsys)
15451 CFI_ENDPROC
15452 /*
15453 * End of kprobes section
15454 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15455 CFI_ENDPROC
15456 ENDPROC(ptregs_clone)
15457
15458 + ALIGN;
15459 +ENTRY(kernel_execve)
15460 + CFI_STARTPROC
15461 + pushl_cfi %ebp
15462 + sub $PT_OLDSS+4,%esp
15463 + pushl_cfi %edi
15464 + pushl_cfi %ecx
15465 + pushl_cfi %eax
15466 + lea 3*4(%esp),%edi
15467 + mov $PT_OLDSS/4+1,%ecx
15468 + xorl %eax,%eax
15469 + rep stosl
15470 + popl_cfi %eax
15471 + popl_cfi %ecx
15472 + popl_cfi %edi
15473 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15474 + pushl_cfi %esp
15475 + call sys_execve
15476 + add $4,%esp
15477 + CFI_ADJUST_CFA_OFFSET -4
15478 + GET_THREAD_INFO(%ebp)
15479 + test %eax,%eax
15480 + jz syscall_exit
15481 + add $PT_OLDSS+4,%esp
15482 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15483 + popl_cfi %ebp
15484 + ret
15485 + CFI_ENDPROC
15486 +ENDPROC(kernel_execve)
15487 +
15488 .macro FIXUP_ESPFIX_STACK
15489 /*
15490 * Switch back for ESPFIX stack to the normal zerobased stack
15491 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15492 * normal stack and adjusts ESP with the matching offset.
15493 */
15494 /* fixup the stack */
15495 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15496 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15497 +#ifdef CONFIG_SMP
15498 + movl PER_CPU_VAR(cpu_number), %ebx
15499 + shll $PAGE_SHIFT_asm, %ebx
15500 + addl $cpu_gdt_table, %ebx
15501 +#else
15502 + movl $cpu_gdt_table, %ebx
15503 +#endif
15504 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15505 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15506 shl $16, %eax
15507 addl %esp, %eax /* the adjusted stack pointer */
15508 pushl_cfi $__KERNEL_DS
15509 @@ -813,7 +1072,7 @@ vector=vector+1
15510 .endr
15511 2: jmp common_interrupt
15512 .endr
15513 -END(irq_entries_start)
15514 +ENDPROC(irq_entries_start)
15515
15516 .previous
15517 END(interrupt)
15518 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15519 pushl_cfi $do_coprocessor_error
15520 jmp error_code
15521 CFI_ENDPROC
15522 -END(coprocessor_error)
15523 +ENDPROC(coprocessor_error)
15524
15525 ENTRY(simd_coprocessor_error)
15526 RING0_INT_FRAME
15527 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15528 #endif
15529 jmp error_code
15530 CFI_ENDPROC
15531 -END(simd_coprocessor_error)
15532 +ENDPROC(simd_coprocessor_error)
15533
15534 ENTRY(device_not_available)
15535 RING0_INT_FRAME
15536 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15537 pushl_cfi $do_device_not_available
15538 jmp error_code
15539 CFI_ENDPROC
15540 -END(device_not_available)
15541 +ENDPROC(device_not_available)
15542
15543 #ifdef CONFIG_PARAVIRT
15544 ENTRY(native_iret)
15545 iret
15546 _ASM_EXTABLE(native_iret, iret_exc)
15547 -END(native_iret)
15548 +ENDPROC(native_iret)
15549
15550 ENTRY(native_irq_enable_sysexit)
15551 sti
15552 sysexit
15553 -END(native_irq_enable_sysexit)
15554 +ENDPROC(native_irq_enable_sysexit)
15555 #endif
15556
15557 ENTRY(overflow)
15558 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15559 pushl_cfi $do_overflow
15560 jmp error_code
15561 CFI_ENDPROC
15562 -END(overflow)
15563 +ENDPROC(overflow)
15564
15565 ENTRY(bounds)
15566 RING0_INT_FRAME
15567 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15568 pushl_cfi $do_bounds
15569 jmp error_code
15570 CFI_ENDPROC
15571 -END(bounds)
15572 +ENDPROC(bounds)
15573
15574 ENTRY(invalid_op)
15575 RING0_INT_FRAME
15576 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15577 pushl_cfi $do_invalid_op
15578 jmp error_code
15579 CFI_ENDPROC
15580 -END(invalid_op)
15581 +ENDPROC(invalid_op)
15582
15583 ENTRY(coprocessor_segment_overrun)
15584 RING0_INT_FRAME
15585 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15586 pushl_cfi $do_coprocessor_segment_overrun
15587 jmp error_code
15588 CFI_ENDPROC
15589 -END(coprocessor_segment_overrun)
15590 +ENDPROC(coprocessor_segment_overrun)
15591
15592 ENTRY(invalid_TSS)
15593 RING0_EC_FRAME
15594 pushl_cfi $do_invalid_TSS
15595 jmp error_code
15596 CFI_ENDPROC
15597 -END(invalid_TSS)
15598 +ENDPROC(invalid_TSS)
15599
15600 ENTRY(segment_not_present)
15601 RING0_EC_FRAME
15602 pushl_cfi $do_segment_not_present
15603 jmp error_code
15604 CFI_ENDPROC
15605 -END(segment_not_present)
15606 +ENDPROC(segment_not_present)
15607
15608 ENTRY(stack_segment)
15609 RING0_EC_FRAME
15610 pushl_cfi $do_stack_segment
15611 jmp error_code
15612 CFI_ENDPROC
15613 -END(stack_segment)
15614 +ENDPROC(stack_segment)
15615
15616 ENTRY(alignment_check)
15617 RING0_EC_FRAME
15618 pushl_cfi $do_alignment_check
15619 jmp error_code
15620 CFI_ENDPROC
15621 -END(alignment_check)
15622 +ENDPROC(alignment_check)
15623
15624 ENTRY(divide_error)
15625 RING0_INT_FRAME
15626 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15627 pushl_cfi $do_divide_error
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(divide_error)
15631 +ENDPROC(divide_error)
15632
15633 #ifdef CONFIG_X86_MCE
15634 ENTRY(machine_check)
15635 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15636 pushl_cfi machine_check_vector
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(machine_check)
15640 +ENDPROC(machine_check)
15641 #endif
15642
15643 ENTRY(spurious_interrupt_bug)
15644 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15645 pushl_cfi $do_spurious_interrupt_bug
15646 jmp error_code
15647 CFI_ENDPROC
15648 -END(spurious_interrupt_bug)
15649 +ENDPROC(spurious_interrupt_bug)
15650 /*
15651 * End of kprobes section
15652 */
15653 @@ -1102,7 +1361,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15654
15655 ENTRY(mcount)
15656 ret
15657 -END(mcount)
15658 +ENDPROC(mcount)
15659
15660 ENTRY(ftrace_caller)
15661 cmpl $0, function_trace_stop
15662 @@ -1131,7 +1390,7 @@ ftrace_graph_call:
15663 .globl ftrace_stub
15664 ftrace_stub:
15665 ret
15666 -END(ftrace_caller)
15667 +ENDPROC(ftrace_caller)
15668
15669 #else /* ! CONFIG_DYNAMIC_FTRACE */
15670
15671 @@ -1167,7 +1426,7 @@ trace:
15672 popl %ecx
15673 popl %eax
15674 jmp ftrace_stub
15675 -END(mcount)
15676 +ENDPROC(mcount)
15677 #endif /* CONFIG_DYNAMIC_FTRACE */
15678 #endif /* CONFIG_FUNCTION_TRACER */
15679
15680 @@ -1188,7 +1447,7 @@ ENTRY(ftrace_graph_caller)
15681 popl %ecx
15682 popl %eax
15683 ret
15684 -END(ftrace_graph_caller)
15685 +ENDPROC(ftrace_graph_caller)
15686
15687 .globl return_to_handler
15688 return_to_handler:
15689 @@ -1243,15 +1502,18 @@ error_code:
15690 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15691 REG_TO_PTGS %ecx
15692 SET_KERNEL_GS %ecx
15693 - movl $(__USER_DS), %ecx
15694 + movl $(__KERNEL_DS), %ecx
15695 movl %ecx, %ds
15696 movl %ecx, %es
15697 +
15698 + pax_enter_kernel
15699 +
15700 TRACE_IRQS_OFF
15701 movl %esp,%eax # pt_regs pointer
15702 call *%edi
15703 jmp ret_from_exception
15704 CFI_ENDPROC
15705 -END(page_fault)
15706 +ENDPROC(page_fault)
15707
15708 /*
15709 * Debug traps and NMI can happen at the one SYSENTER instruction
15710 @@ -1293,7 +1555,7 @@ debug_stack_correct:
15711 call do_debug
15712 jmp ret_from_exception
15713 CFI_ENDPROC
15714 -END(debug)
15715 +ENDPROC(debug)
15716
15717 /*
15718 * NMI is doubly nasty. It can happen _while_ we're handling
15719 @@ -1330,6 +1592,9 @@ nmi_stack_correct:
15720 xorl %edx,%edx # zero error code
15721 movl %esp,%eax # pt_regs pointer
15722 call do_nmi
15723 +
15724 + pax_exit_kernel
15725 +
15726 jmp restore_all_notrace
15727 CFI_ENDPROC
15728
15729 @@ -1366,12 +1631,15 @@ nmi_espfix_stack:
15730 FIXUP_ESPFIX_STACK # %eax == %esp
15731 xorl %edx,%edx # zero error code
15732 call do_nmi
15733 +
15734 + pax_exit_kernel
15735 +
15736 RESTORE_REGS
15737 lss 12+4(%esp), %esp # back to espfix stack
15738 CFI_ADJUST_CFA_OFFSET -24
15739 jmp irq_return
15740 CFI_ENDPROC
15741 -END(nmi)
15742 +ENDPROC(nmi)
15743
15744 ENTRY(int3)
15745 RING0_INT_FRAME
15746 @@ -1383,14 +1651,14 @@ ENTRY(int3)
15747 call do_int3
15748 jmp ret_from_exception
15749 CFI_ENDPROC
15750 -END(int3)
15751 +ENDPROC(int3)
15752
15753 ENTRY(general_protection)
15754 RING0_EC_FRAME
15755 pushl_cfi $do_general_protection
15756 jmp error_code
15757 CFI_ENDPROC
15758 -END(general_protection)
15759 +ENDPROC(general_protection)
15760
15761 #ifdef CONFIG_KVM_GUEST
15762 ENTRY(async_page_fault)
15763 @@ -1398,7 +1666,7 @@ ENTRY(async_page_fault)
15764 pushl_cfi $do_async_page_fault
15765 jmp error_code
15766 CFI_ENDPROC
15767 -END(async_page_fault)
15768 +ENDPROC(async_page_fault)
15769 #endif
15770
15771 /*
15772 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15773 index dcdd0ea..de0bb2d 100644
15774 --- a/arch/x86/kernel/entry_64.S
15775 +++ b/arch/x86/kernel/entry_64.S
15776 @@ -57,6 +57,8 @@
15777 #include <asm/percpu.h>
15778 #include <asm/asm.h>
15779 #include <linux/err.h>
15780 +#include <asm/pgtable.h>
15781 +#include <asm/alternative-asm.h>
15782
15783 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15784 #include <linux/elf-em.h>
15785 @@ -70,8 +72,9 @@
15786 #ifdef CONFIG_FUNCTION_TRACER
15787 #ifdef CONFIG_DYNAMIC_FTRACE
15788 ENTRY(mcount)
15789 + pax_force_retaddr
15790 retq
15791 -END(mcount)
15792 +ENDPROC(mcount)
15793
15794 ENTRY(ftrace_caller)
15795 cmpl $0, function_trace_stop
15796 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15797 #endif
15798
15799 GLOBAL(ftrace_stub)
15800 + pax_force_retaddr
15801 retq
15802 -END(ftrace_caller)
15803 +ENDPROC(ftrace_caller)
15804
15805 #else /* ! CONFIG_DYNAMIC_FTRACE */
15806 ENTRY(mcount)
15807 @@ -114,6 +118,7 @@ ENTRY(mcount)
15808 #endif
15809
15810 GLOBAL(ftrace_stub)
15811 + pax_force_retaddr
15812 retq
15813
15814 trace:
15815 @@ -123,12 +128,13 @@ trace:
15816 movq 8(%rbp), %rsi
15817 subq $MCOUNT_INSN_SIZE, %rdi
15818
15819 + pax_force_fptr ftrace_trace_function
15820 call *ftrace_trace_function
15821
15822 MCOUNT_RESTORE_FRAME
15823
15824 jmp ftrace_stub
15825 -END(mcount)
15826 +ENDPROC(mcount)
15827 #endif /* CONFIG_DYNAMIC_FTRACE */
15828 #endif /* CONFIG_FUNCTION_TRACER */
15829
15830 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15831
15832 MCOUNT_RESTORE_FRAME
15833
15834 + pax_force_retaddr
15835 retq
15836 -END(ftrace_graph_caller)
15837 +ENDPROC(ftrace_graph_caller)
15838
15839 GLOBAL(return_to_handler)
15840 subq $24, %rsp
15841 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15842 movq 8(%rsp), %rdx
15843 movq (%rsp), %rax
15844 addq $24, %rsp
15845 + pax_force_fptr %rdi
15846 jmp *%rdi
15847 #endif
15848
15849 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15850 ENDPROC(native_usergs_sysret64)
15851 #endif /* CONFIG_PARAVIRT */
15852
15853 + .macro ljmpq sel, off
15854 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15855 + .byte 0x48; ljmp *1234f(%rip)
15856 + .pushsection .rodata
15857 + .align 16
15858 + 1234: .quad \off; .word \sel
15859 + .popsection
15860 +#else
15861 + pushq $\sel
15862 + pushq $\off
15863 + lretq
15864 +#endif
15865 + .endm
15866 +
15867 + .macro pax_enter_kernel
15868 + pax_set_fptr_mask
15869 +#ifdef CONFIG_PAX_KERNEXEC
15870 + call pax_enter_kernel
15871 +#endif
15872 + .endm
15873 +
15874 + .macro pax_exit_kernel
15875 +#ifdef CONFIG_PAX_KERNEXEC
15876 + call pax_exit_kernel
15877 +#endif
15878 + .endm
15879 +
15880 +#ifdef CONFIG_PAX_KERNEXEC
15881 +ENTRY(pax_enter_kernel)
15882 + pushq %rdi
15883 +
15884 +#ifdef CONFIG_PARAVIRT
15885 + PV_SAVE_REGS(CLBR_RDI)
15886 +#endif
15887 +
15888 + GET_CR0_INTO_RDI
15889 + bts $16,%rdi
15890 + jnc 3f
15891 + mov %cs,%edi
15892 + cmp $__KERNEL_CS,%edi
15893 + jnz 2f
15894 +1:
15895 +
15896 +#ifdef CONFIG_PARAVIRT
15897 + PV_RESTORE_REGS(CLBR_RDI)
15898 +#endif
15899 +
15900 + popq %rdi
15901 + pax_force_retaddr
15902 + retq
15903 +
15904 +2: ljmpq __KERNEL_CS,1f
15905 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15906 +4: SET_RDI_INTO_CR0
15907 + jmp 1b
15908 +ENDPROC(pax_enter_kernel)
15909 +
15910 +ENTRY(pax_exit_kernel)
15911 + pushq %rdi
15912 +
15913 +#ifdef CONFIG_PARAVIRT
15914 + PV_SAVE_REGS(CLBR_RDI)
15915 +#endif
15916 +
15917 + mov %cs,%rdi
15918 + cmp $__KERNEXEC_KERNEL_CS,%edi
15919 + jz 2f
15920 +1:
15921 +
15922 +#ifdef CONFIG_PARAVIRT
15923 + PV_RESTORE_REGS(CLBR_RDI);
15924 +#endif
15925 +
15926 + popq %rdi
15927 + pax_force_retaddr
15928 + retq
15929 +
15930 +2: GET_CR0_INTO_RDI
15931 + btr $16,%rdi
15932 + ljmpq __KERNEL_CS,3f
15933 +3: SET_RDI_INTO_CR0
15934 + jmp 1b
15935 +#ifdef CONFIG_PARAVIRT
15936 + PV_RESTORE_REGS(CLBR_RDI);
15937 +#endif
15938 +
15939 + popq %rdi
15940 + pax_force_retaddr
15941 + retq
15942 +ENDPROC(pax_exit_kernel)
15943 +#endif
15944 +
15945 + .macro pax_enter_kernel_user
15946 + pax_set_fptr_mask
15947 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15948 + call pax_enter_kernel_user
15949 +#endif
15950 + .endm
15951 +
15952 + .macro pax_exit_kernel_user
15953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15954 + call pax_exit_kernel_user
15955 +#endif
15956 +#ifdef CONFIG_PAX_RANDKSTACK
15957 + pushq %rax
15958 + call pax_randomize_kstack
15959 + popq %rax
15960 +#endif
15961 + .endm
15962 +
15963 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15964 +ENTRY(pax_enter_kernel_user)
15965 + pushq %rdi
15966 + pushq %rbx
15967 +
15968 +#ifdef CONFIG_PARAVIRT
15969 + PV_SAVE_REGS(CLBR_RDI)
15970 +#endif
15971 +
15972 + GET_CR3_INTO_RDI
15973 + mov %rdi,%rbx
15974 + add $__START_KERNEL_map,%rbx
15975 + sub phys_base(%rip),%rbx
15976 +
15977 +#ifdef CONFIG_PARAVIRT
15978 + pushq %rdi
15979 + cmpl $0, pv_info+PARAVIRT_enabled
15980 + jz 1f
15981 + i = 0
15982 + .rept USER_PGD_PTRS
15983 + mov i*8(%rbx),%rsi
15984 + mov $0,%sil
15985 + lea i*8(%rbx),%rdi
15986 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15987 + i = i + 1
15988 + .endr
15989 + jmp 2f
15990 +1:
15991 +#endif
15992 +
15993 + i = 0
15994 + .rept USER_PGD_PTRS
15995 + movb $0,i*8(%rbx)
15996 + i = i + 1
15997 + .endr
15998 +
15999 +#ifdef CONFIG_PARAVIRT
16000 +2: popq %rdi
16001 +#endif
16002 + SET_RDI_INTO_CR3
16003 +
16004 +#ifdef CONFIG_PAX_KERNEXEC
16005 + GET_CR0_INTO_RDI
16006 + bts $16,%rdi
16007 + SET_RDI_INTO_CR0
16008 +#endif
16009 +
16010 +#ifdef CONFIG_PARAVIRT
16011 + PV_RESTORE_REGS(CLBR_RDI)
16012 +#endif
16013 +
16014 + popq %rbx
16015 + popq %rdi
16016 + pax_force_retaddr
16017 + retq
16018 +ENDPROC(pax_enter_kernel_user)
16019 +
16020 +ENTRY(pax_exit_kernel_user)
16021 + push %rdi
16022 +
16023 +#ifdef CONFIG_PARAVIRT
16024 + pushq %rbx
16025 + PV_SAVE_REGS(CLBR_RDI)
16026 +#endif
16027 +
16028 +#ifdef CONFIG_PAX_KERNEXEC
16029 + GET_CR0_INTO_RDI
16030 + btr $16,%rdi
16031 + SET_RDI_INTO_CR0
16032 +#endif
16033 +
16034 + GET_CR3_INTO_RDI
16035 + add $__START_KERNEL_map,%rdi
16036 + sub phys_base(%rip),%rdi
16037 +
16038 +#ifdef CONFIG_PARAVIRT
16039 + cmpl $0, pv_info+PARAVIRT_enabled
16040 + jz 1f
16041 + mov %rdi,%rbx
16042 + i = 0
16043 + .rept USER_PGD_PTRS
16044 + mov i*8(%rbx),%rsi
16045 + mov $0x67,%sil
16046 + lea i*8(%rbx),%rdi
16047 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16048 + i = i + 1
16049 + .endr
16050 + jmp 2f
16051 +1:
16052 +#endif
16053 +
16054 + i = 0
16055 + .rept USER_PGD_PTRS
16056 + movb $0x67,i*8(%rdi)
16057 + i = i + 1
16058 + .endr
16059 +
16060 +#ifdef CONFIG_PARAVIRT
16061 +2: PV_RESTORE_REGS(CLBR_RDI)
16062 + popq %rbx
16063 +#endif
16064 +
16065 + popq %rdi
16066 + pax_force_retaddr
16067 + retq
16068 +ENDPROC(pax_exit_kernel_user)
16069 +#endif
16070 +
16071 +.macro pax_erase_kstack
16072 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16073 + call pax_erase_kstack
16074 +#endif
16075 +.endm
16076 +
16077 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16078 +ENTRY(pax_erase_kstack)
16079 + pushq %rdi
16080 + pushq %rcx
16081 + pushq %rax
16082 + pushq %r11
16083 +
16084 + GET_THREAD_INFO(%r11)
16085 + mov TI_lowest_stack(%r11), %rdi
16086 + mov $-0xBEEF, %rax
16087 + std
16088 +
16089 +1: mov %edi, %ecx
16090 + and $THREAD_SIZE_asm - 1, %ecx
16091 + shr $3, %ecx
16092 + repne scasq
16093 + jecxz 2f
16094 +
16095 + cmp $2*8, %ecx
16096 + jc 2f
16097 +
16098 + mov $2*8, %ecx
16099 + repe scasq
16100 + jecxz 2f
16101 + jne 1b
16102 +
16103 +2: cld
16104 + mov %esp, %ecx
16105 + sub %edi, %ecx
16106 +
16107 + cmp $THREAD_SIZE_asm, %rcx
16108 + jb 3f
16109 + ud2
16110 +3:
16111 +
16112 + shr $3, %ecx
16113 + rep stosq
16114 +
16115 + mov TI_task_thread_sp0(%r11), %rdi
16116 + sub $256, %rdi
16117 + mov %rdi, TI_lowest_stack(%r11)
16118 +
16119 + popq %r11
16120 + popq %rax
16121 + popq %rcx
16122 + popq %rdi
16123 + pax_force_retaddr
16124 + ret
16125 +ENDPROC(pax_erase_kstack)
16126 +#endif
16127
16128 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16129 #ifdef CONFIG_TRACE_IRQFLAGS
16130 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16131 .endm
16132
16133 .macro UNFAKE_STACK_FRAME
16134 - addq $8*6, %rsp
16135 - CFI_ADJUST_CFA_OFFSET -(6*8)
16136 + addq $8*6 + ARG_SKIP, %rsp
16137 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16138 .endm
16139
16140 /*
16141 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16142 movq %rsp, %rsi
16143
16144 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16145 - testl $3, CS-RBP(%rsi)
16146 + testb $3, CS-RBP(%rsi)
16147 je 1f
16148 SWAPGS
16149 /*
16150 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16151 movq_cfi r15, R15+16
16152 movq %r11, 8(%rsp) /* return address */
16153 FIXUP_TOP_OF_STACK %r11, 16
16154 + pax_force_retaddr
16155 ret
16156 CFI_ENDPROC
16157 -END(save_rest)
16158 +ENDPROC(save_rest)
16159
16160 /* save complete stack frame */
16161 .pushsection .kprobes.text, "ax"
16162 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16163 js 1f /* negative -> in kernel */
16164 SWAPGS
16165 xorl %ebx,%ebx
16166 -1: ret
16167 +1: pax_force_retaddr_bts
16168 + ret
16169 CFI_ENDPROC
16170 -END(save_paranoid)
16171 +ENDPROC(save_paranoid)
16172 .popsection
16173
16174 /*
16175 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16176
16177 RESTORE_REST
16178
16179 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16180 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16181 jz retint_restore_args
16182
16183 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16184 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16185 jmp ret_from_sys_call # go to the SYSRET fastpath
16186
16187 CFI_ENDPROC
16188 -END(ret_from_fork)
16189 +ENDPROC(ret_from_fork)
16190
16191 /*
16192 * System call entry. Up to 6 arguments in registers are supported.
16193 @@ -495,7 +779,7 @@ END(ret_from_fork)
16194 ENTRY(system_call)
16195 CFI_STARTPROC simple
16196 CFI_SIGNAL_FRAME
16197 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16198 + CFI_DEF_CFA rsp,0
16199 CFI_REGISTER rip,rcx
16200 /*CFI_REGISTER rflags,r11*/
16201 SWAPGS_UNSAFE_STACK
16202 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16203
16204 movq %rsp,PER_CPU_VAR(old_rsp)
16205 movq PER_CPU_VAR(kernel_stack),%rsp
16206 + SAVE_ARGS 8*6,0
16207 + pax_enter_kernel_user
16208 +
16209 +#ifdef CONFIG_PAX_RANDKSTACK
16210 + pax_erase_kstack
16211 +#endif
16212 +
16213 /*
16214 * No need to follow this irqs off/on section - it's straight
16215 * and short:
16216 */
16217 ENABLE_INTERRUPTS(CLBR_NONE)
16218 - SAVE_ARGS 8,0
16219 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16220 movq %rcx,RIP-ARGOFFSET(%rsp)
16221 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16222 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16223 + GET_THREAD_INFO(%rcx)
16224 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16225 jnz tracesys
16226 system_call_fastpath:
16227 #if __SYSCALL_MASK == ~0
16228 @@ -527,7 +818,7 @@ system_call_fastpath:
16229 cmpl $__NR_syscall_max,%eax
16230 #endif
16231 ja badsys
16232 - movq %r10,%rcx
16233 + movq R10-ARGOFFSET(%rsp),%rcx
16234 call *sys_call_table(,%rax,8) # XXX: rip relative
16235 movq %rax,RAX-ARGOFFSET(%rsp)
16236 /*
16237 @@ -541,10 +832,13 @@ sysret_check:
16238 LOCKDEP_SYS_EXIT
16239 DISABLE_INTERRUPTS(CLBR_NONE)
16240 TRACE_IRQS_OFF
16241 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16242 + GET_THREAD_INFO(%rcx)
16243 + movl TI_flags(%rcx),%edx
16244 andl %edi,%edx
16245 jnz sysret_careful
16246 CFI_REMEMBER_STATE
16247 + pax_exit_kernel_user
16248 + pax_erase_kstack
16249 /*
16250 * sysretq will re-enable interrupts:
16251 */
16252 @@ -596,14 +890,18 @@ badsys:
16253 * jump back to the normal fast path.
16254 */
16255 auditsys:
16256 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16257 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16258 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16259 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16260 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16261 movq %rax,%rsi /* 2nd arg: syscall number */
16262 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16263 call __audit_syscall_entry
16264 +
16265 + pax_erase_kstack
16266 +
16267 LOAD_ARGS 0 /* reload call-clobbered registers */
16268 + pax_set_fptr_mask
16269 jmp system_call_fastpath
16270
16271 /*
16272 @@ -624,7 +922,7 @@ sysret_audit:
16273 /* Do syscall tracing */
16274 tracesys:
16275 #ifdef CONFIG_AUDITSYSCALL
16276 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16277 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16278 jz auditsys
16279 #endif
16280 SAVE_REST
16281 @@ -632,12 +930,16 @@ tracesys:
16282 FIXUP_TOP_OF_STACK %rdi
16283 movq %rsp,%rdi
16284 call syscall_trace_enter
16285 +
16286 + pax_erase_kstack
16287 +
16288 /*
16289 * Reload arg registers from stack in case ptrace changed them.
16290 * We don't reload %rax because syscall_trace_enter() returned
16291 * the value it wants us to use in the table lookup.
16292 */
16293 LOAD_ARGS ARGOFFSET, 1
16294 + pax_set_fptr_mask
16295 RESTORE_REST
16296 #if __SYSCALL_MASK == ~0
16297 cmpq $__NR_syscall_max,%rax
16298 @@ -646,7 +948,7 @@ tracesys:
16299 cmpl $__NR_syscall_max,%eax
16300 #endif
16301 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16302 - movq %r10,%rcx /* fixup for C */
16303 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16304 call *sys_call_table(,%rax,8)
16305 movq %rax,RAX-ARGOFFSET(%rsp)
16306 /* Use IRET because user could have changed frame */
16307 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16308 andl %edi,%edx
16309 jnz int_careful
16310 andl $~TS_COMPAT,TI_status(%rcx)
16311 - jmp retint_swapgs
16312 + pax_exit_kernel_user
16313 + pax_erase_kstack
16314 + jmp retint_swapgs_pax
16315
16316 /* Either reschedule or signal or syscall exit tracking needed. */
16317 /* First do a reschedule test. */
16318 @@ -713,7 +1017,7 @@ int_restore_rest:
16319 TRACE_IRQS_OFF
16320 jmp int_with_check
16321 CFI_ENDPROC
16322 -END(system_call)
16323 +ENDPROC(system_call)
16324
16325 /*
16326 * Certain special system calls that need to save a complete full stack frame.
16327 @@ -729,7 +1033,7 @@ ENTRY(\label)
16328 call \func
16329 jmp ptregscall_common
16330 CFI_ENDPROC
16331 -END(\label)
16332 +ENDPROC(\label)
16333 .endm
16334
16335 PTREGSCALL stub_clone, sys_clone, %r8
16336 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16337 movq_cfi_restore R12+8, r12
16338 movq_cfi_restore RBP+8, rbp
16339 movq_cfi_restore RBX+8, rbx
16340 + pax_force_retaddr
16341 ret $REST_SKIP /* pop extended registers */
16342 CFI_ENDPROC
16343 -END(ptregscall_common)
16344 +ENDPROC(ptregscall_common)
16345
16346 ENTRY(stub_execve)
16347 CFI_STARTPROC
16348 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16349 RESTORE_REST
16350 jmp int_ret_from_sys_call
16351 CFI_ENDPROC
16352 -END(stub_execve)
16353 +ENDPROC(stub_execve)
16354
16355 /*
16356 * sigreturn is special because it needs to restore all registers on return.
16357 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16358 RESTORE_REST
16359 jmp int_ret_from_sys_call
16360 CFI_ENDPROC
16361 -END(stub_rt_sigreturn)
16362 +ENDPROC(stub_rt_sigreturn)
16363
16364 #ifdef CONFIG_X86_X32_ABI
16365 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16366 @@ -851,7 +1156,7 @@ vector=vector+1
16367 2: jmp common_interrupt
16368 .endr
16369 CFI_ENDPROC
16370 -END(irq_entries_start)
16371 +ENDPROC(irq_entries_start)
16372
16373 .previous
16374 END(interrupt)
16375 @@ -871,6 +1176,16 @@ END(interrupt)
16376 subq $ORIG_RAX-RBP, %rsp
16377 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16378 SAVE_ARGS_IRQ
16379 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16380 + testb $3, CS(%rdi)
16381 + jnz 1f
16382 + pax_enter_kernel
16383 + jmp 2f
16384 +1: pax_enter_kernel_user
16385 +2:
16386 +#else
16387 + pax_enter_kernel
16388 +#endif
16389 call \func
16390 .endm
16391
16392 @@ -902,7 +1217,7 @@ ret_from_intr:
16393
16394 exit_intr:
16395 GET_THREAD_INFO(%rcx)
16396 - testl $3,CS-ARGOFFSET(%rsp)
16397 + testb $3,CS-ARGOFFSET(%rsp)
16398 je retint_kernel
16399
16400 /* Interrupt came from user space */
16401 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16402 * The iretq could re-enable interrupts:
16403 */
16404 DISABLE_INTERRUPTS(CLBR_ANY)
16405 + pax_exit_kernel_user
16406 +retint_swapgs_pax:
16407 TRACE_IRQS_IRETQ
16408 SWAPGS
16409 jmp restore_args
16410
16411 retint_restore_args: /* return to kernel space */
16412 DISABLE_INTERRUPTS(CLBR_ANY)
16413 + pax_exit_kernel
16414 + pax_force_retaddr RIP-ARGOFFSET
16415 /*
16416 * The iretq could re-enable interrupts:
16417 */
16418 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16419 #endif
16420
16421 CFI_ENDPROC
16422 -END(common_interrupt)
16423 +ENDPROC(common_interrupt)
16424 /*
16425 * End of kprobes section
16426 */
16427 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16428 interrupt \do_sym
16429 jmp ret_from_intr
16430 CFI_ENDPROC
16431 -END(\sym)
16432 +ENDPROC(\sym)
16433 .endm
16434
16435 #ifdef CONFIG_SMP
16436 @@ -1084,12 +1403,22 @@ ENTRY(\sym)
16437 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16438 call error_entry
16439 DEFAULT_FRAME 0
16440 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16441 + testb $3, CS(%rsp)
16442 + jnz 1f
16443 + pax_enter_kernel
16444 + jmp 2f
16445 +1: pax_enter_kernel_user
16446 +2:
16447 +#else
16448 + pax_enter_kernel
16449 +#endif
16450 movq %rsp,%rdi /* pt_regs pointer */
16451 xorl %esi,%esi /* no error code */
16452 call \do_sym
16453 jmp error_exit /* %ebx: no swapgs flag */
16454 CFI_ENDPROC
16455 -END(\sym)
16456 +ENDPROC(\sym)
16457 .endm
16458
16459 .macro paranoidzeroentry sym do_sym
16460 @@ -1101,15 +1430,25 @@ ENTRY(\sym)
16461 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16462 call save_paranoid
16463 TRACE_IRQS_OFF
16464 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16465 + testb $3, CS(%rsp)
16466 + jnz 1f
16467 + pax_enter_kernel
16468 + jmp 2f
16469 +1: pax_enter_kernel_user
16470 +2:
16471 +#else
16472 + pax_enter_kernel
16473 +#endif
16474 movq %rsp,%rdi /* pt_regs pointer */
16475 xorl %esi,%esi /* no error code */
16476 call \do_sym
16477 jmp paranoid_exit /* %ebx: no swapgs flag */
16478 CFI_ENDPROC
16479 -END(\sym)
16480 +ENDPROC(\sym)
16481 .endm
16482
16483 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16484 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16485 .macro paranoidzeroentry_ist sym do_sym ist
16486 ENTRY(\sym)
16487 INTR_FRAME
16488 @@ -1119,14 +1458,30 @@ ENTRY(\sym)
16489 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16490 call save_paranoid
16491 TRACE_IRQS_OFF_DEBUG
16492 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16493 + testb $3, CS(%rsp)
16494 + jnz 1f
16495 + pax_enter_kernel
16496 + jmp 2f
16497 +1: pax_enter_kernel_user
16498 +2:
16499 +#else
16500 + pax_enter_kernel
16501 +#endif
16502 movq %rsp,%rdi /* pt_regs pointer */
16503 xorl %esi,%esi /* no error code */
16504 +#ifdef CONFIG_SMP
16505 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16506 + lea init_tss(%r12), %r12
16507 +#else
16508 + lea init_tss(%rip), %r12
16509 +#endif
16510 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16511 call \do_sym
16512 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16513 jmp paranoid_exit /* %ebx: no swapgs flag */
16514 CFI_ENDPROC
16515 -END(\sym)
16516 +ENDPROC(\sym)
16517 .endm
16518
16519 .macro errorentry sym do_sym
16520 @@ -1137,13 +1492,23 @@ ENTRY(\sym)
16521 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16522 call error_entry
16523 DEFAULT_FRAME 0
16524 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16525 + testb $3, CS(%rsp)
16526 + jnz 1f
16527 + pax_enter_kernel
16528 + jmp 2f
16529 +1: pax_enter_kernel_user
16530 +2:
16531 +#else
16532 + pax_enter_kernel
16533 +#endif
16534 movq %rsp,%rdi /* pt_regs pointer */
16535 movq ORIG_RAX(%rsp),%rsi /* get error code */
16536 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16537 call \do_sym
16538 jmp error_exit /* %ebx: no swapgs flag */
16539 CFI_ENDPROC
16540 -END(\sym)
16541 +ENDPROC(\sym)
16542 .endm
16543
16544 /* error code is on the stack already */
16545 @@ -1156,13 +1521,23 @@ ENTRY(\sym)
16546 call save_paranoid
16547 DEFAULT_FRAME 0
16548 TRACE_IRQS_OFF
16549 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16550 + testb $3, CS(%rsp)
16551 + jnz 1f
16552 + pax_enter_kernel
16553 + jmp 2f
16554 +1: pax_enter_kernel_user
16555 +2:
16556 +#else
16557 + pax_enter_kernel
16558 +#endif
16559 movq %rsp,%rdi /* pt_regs pointer */
16560 movq ORIG_RAX(%rsp),%rsi /* get error code */
16561 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16562 call \do_sym
16563 jmp paranoid_exit /* %ebx: no swapgs flag */
16564 CFI_ENDPROC
16565 -END(\sym)
16566 +ENDPROC(\sym)
16567 .endm
16568
16569 zeroentry divide_error do_divide_error
16570 @@ -1192,9 +1567,10 @@ gs_change:
16571 2: mfence /* workaround */
16572 SWAPGS
16573 popfq_cfi
16574 + pax_force_retaddr
16575 ret
16576 CFI_ENDPROC
16577 -END(native_load_gs_index)
16578 +ENDPROC(native_load_gs_index)
16579
16580 _ASM_EXTABLE(gs_change,bad_gs)
16581 .section .fixup,"ax"
16582 @@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16583 * Here we are in the child and the registers are set as they were
16584 * at kernel_thread() invocation in the parent.
16585 */
16586 + pax_force_fptr %rsi
16587 call *%rsi
16588 # exit
16589 mov %eax, %edi
16590 call do_exit
16591 ud2 # padding for call trace
16592 CFI_ENDPROC
16593 -END(kernel_thread_helper)
16594 +ENDPROC(kernel_thread_helper)
16595
16596 /*
16597 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16598 @@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16599 RESTORE_REST
16600 testq %rax,%rax
16601 je int_ret_from_sys_call
16602 - RESTORE_ARGS
16603 UNFAKE_STACK_FRAME
16604 + pax_force_retaddr
16605 ret
16606 CFI_ENDPROC
16607 -END(kernel_execve)
16608 +ENDPROC(kernel_execve)
16609
16610 /* Call softirq on interrupt stack. Interrupts are off. */
16611 ENTRY(call_softirq)
16612 @@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16613 CFI_DEF_CFA_REGISTER rsp
16614 CFI_ADJUST_CFA_OFFSET -8
16615 decl PER_CPU_VAR(irq_count)
16616 + pax_force_retaddr
16617 ret
16618 CFI_ENDPROC
16619 -END(call_softirq)
16620 +ENDPROC(call_softirq)
16621
16622 #ifdef CONFIG_XEN
16623 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16624 @@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16625 decl PER_CPU_VAR(irq_count)
16626 jmp error_exit
16627 CFI_ENDPROC
16628 -END(xen_do_hypervisor_callback)
16629 +ENDPROC(xen_do_hypervisor_callback)
16630
16631 /*
16632 * Hypervisor uses this for application faults while it executes.
16633 @@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16634 SAVE_ALL
16635 jmp error_exit
16636 CFI_ENDPROC
16637 -END(xen_failsafe_callback)
16638 +ENDPROC(xen_failsafe_callback)
16639
16640 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16641 xen_hvm_callback_vector xen_evtchn_do_upcall
16642 @@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16643 TRACE_IRQS_OFF_DEBUG
16644 testl %ebx,%ebx /* swapgs needed? */
16645 jnz paranoid_restore
16646 - testl $3,CS(%rsp)
16647 + testb $3,CS(%rsp)
16648 jnz paranoid_userspace
16649 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16650 + pax_exit_kernel
16651 + TRACE_IRQS_IRETQ 0
16652 + SWAPGS_UNSAFE_STACK
16653 + RESTORE_ALL 8
16654 + pax_force_retaddr_bts
16655 + jmp irq_return
16656 +#endif
16657 paranoid_swapgs:
16658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16659 + pax_exit_kernel_user
16660 +#else
16661 + pax_exit_kernel
16662 +#endif
16663 TRACE_IRQS_IRETQ 0
16664 SWAPGS_UNSAFE_STACK
16665 RESTORE_ALL 8
16666 jmp irq_return
16667 paranoid_restore:
16668 + pax_exit_kernel
16669 TRACE_IRQS_IRETQ_DEBUG 0
16670 RESTORE_ALL 8
16671 + pax_force_retaddr_bts
16672 jmp irq_return
16673 paranoid_userspace:
16674 GET_THREAD_INFO(%rcx)
16675 @@ -1454,7 +1847,7 @@ paranoid_schedule:
16676 TRACE_IRQS_OFF
16677 jmp paranoid_userspace
16678 CFI_ENDPROC
16679 -END(paranoid_exit)
16680 +ENDPROC(paranoid_exit)
16681
16682 /*
16683 * Exception entry point. This expects an error code/orig_rax on the stack.
16684 @@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16685 movq_cfi r14, R14+8
16686 movq_cfi r15, R15+8
16687 xorl %ebx,%ebx
16688 - testl $3,CS+8(%rsp)
16689 + testb $3,CS+8(%rsp)
16690 je error_kernelspace
16691 error_swapgs:
16692 SWAPGS
16693 error_sti:
16694 TRACE_IRQS_OFF
16695 + pax_force_retaddr_bts
16696 ret
16697
16698 /*
16699 @@ -1513,7 +1907,7 @@ bstep_iret:
16700 movq %rcx,RIP+8(%rsp)
16701 jmp error_swapgs
16702 CFI_ENDPROC
16703 -END(error_entry)
16704 +ENDPROC(error_entry)
16705
16706
16707 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16708 @@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16709 jnz retint_careful
16710 jmp retint_swapgs
16711 CFI_ENDPROC
16712 -END(error_exit)
16713 +ENDPROC(error_exit)
16714
16715 /*
16716 * Test if a given stack is an NMI stack or not.
16717 @@ -1591,9 +1985,11 @@ ENTRY(nmi)
16718 * If %cs was not the kernel segment, then the NMI triggered in user
16719 * space, which means it is definitely not nested.
16720 */
16721 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16722 + je 1f
16723 cmpl $__KERNEL_CS, 16(%rsp)
16724 jne first_nmi
16725 -
16726 +1:
16727 /*
16728 * Check the special variable on the stack to see if NMIs are
16729 * executing.
16730 @@ -1752,6 +2148,17 @@ end_repeat_nmi:
16731 */
16732 movq %cr2, %r12
16733
16734 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16735 + testb $3, CS(%rsp)
16736 + jnz 1f
16737 + pax_enter_kernel
16738 + jmp 2f
16739 +1: pax_enter_kernel_user
16740 +2:
16741 +#else
16742 + pax_enter_kernel
16743 +#endif
16744 +
16745 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16746 movq %rsp,%rdi
16747 movq $-1,%rsi
16748 @@ -1767,21 +2174,32 @@ end_repeat_nmi:
16749 testl %ebx,%ebx /* swapgs needed? */
16750 jnz nmi_restore
16751 nmi_swapgs:
16752 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16753 + pax_exit_kernel_user
16754 +#else
16755 + pax_exit_kernel
16756 +#endif
16757 SWAPGS_UNSAFE_STACK
16758 + RESTORE_ALL 8
16759 + /* Clear the NMI executing stack variable */
16760 + movq $0, 10*8(%rsp)
16761 + jmp irq_return
16762 nmi_restore:
16763 + pax_exit_kernel
16764 RESTORE_ALL 8
16765 + pax_force_retaddr_bts
16766 /* Clear the NMI executing stack variable */
16767 movq $0, 10*8(%rsp)
16768 jmp irq_return
16769 CFI_ENDPROC
16770 -END(nmi)
16771 +ENDPROC(nmi)
16772
16773 ENTRY(ignore_sysret)
16774 CFI_STARTPROC
16775 mov $-ENOSYS,%eax
16776 sysret
16777 CFI_ENDPROC
16778 -END(ignore_sysret)
16779 +ENDPROC(ignore_sysret)
16780
16781 /*
16782 * End of kprobes section
16783 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16784 index c3a7cb4..3ad00dc 100644
16785 --- a/arch/x86/kernel/ftrace.c
16786 +++ b/arch/x86/kernel/ftrace.c
16787 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16788 {
16789 unsigned char replaced[MCOUNT_INSN_SIZE];
16790
16791 + ip = ktla_ktva(ip);
16792 +
16793 /*
16794 * Note: Due to modules and __init, code can
16795 * disappear and change, we need to protect against faulting
16796 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16797 unsigned char old[MCOUNT_INSN_SIZE], *new;
16798 int ret;
16799
16800 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16801 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16802 new = ftrace_call_replace(ip, (unsigned long)func);
16803
16804 /* See comment above by declaration of modifying_ftrace_code */
16805 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16806 {
16807 unsigned char code[MCOUNT_INSN_SIZE];
16808
16809 + ip = ktla_ktva(ip);
16810 +
16811 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16812 return -EFAULT;
16813
16814 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16815 index c18f59d..9c0c9f6 100644
16816 --- a/arch/x86/kernel/head32.c
16817 +++ b/arch/x86/kernel/head32.c
16818 @@ -18,6 +18,7 @@
16819 #include <asm/io_apic.h>
16820 #include <asm/bios_ebda.h>
16821 #include <asm/tlbflush.h>
16822 +#include <asm/boot.h>
16823
16824 static void __init i386_default_early_setup(void)
16825 {
16826 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16827
16828 void __init i386_start_kernel(void)
16829 {
16830 - memblock_reserve(__pa_symbol(&_text),
16831 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16832 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16833
16834 #ifdef CONFIG_BLK_DEV_INITRD
16835 /* Reserve INITRD */
16836 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16837 index d42ab17..87b9555 100644
16838 --- a/arch/x86/kernel/head_32.S
16839 +++ b/arch/x86/kernel/head_32.S
16840 @@ -26,6 +26,12 @@
16841 /* Physical address */
16842 #define pa(X) ((X) - __PAGE_OFFSET)
16843
16844 +#ifdef CONFIG_PAX_KERNEXEC
16845 +#define ta(X) (X)
16846 +#else
16847 +#define ta(X) ((X) - __PAGE_OFFSET)
16848 +#endif
16849 +
16850 /*
16851 * References to members of the new_cpu_data structure.
16852 */
16853 @@ -55,11 +61,7 @@
16854 * and small than max_low_pfn, otherwise will waste some page table entries
16855 */
16856
16857 -#if PTRS_PER_PMD > 1
16858 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16859 -#else
16860 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16861 -#endif
16862 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16863
16864 /* Number of possible pages in the lowmem region */
16865 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16866 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16867 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16868
16869 /*
16870 + * Real beginning of normal "text" segment
16871 + */
16872 +ENTRY(stext)
16873 +ENTRY(_stext)
16874 +
16875 +/*
16876 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16877 * %esi points to the real-mode code as a 32-bit pointer.
16878 * CS and DS must be 4 GB flat segments, but we don't depend on
16879 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16880 * can.
16881 */
16882 __HEAD
16883 +
16884 +#ifdef CONFIG_PAX_KERNEXEC
16885 + jmp startup_32
16886 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16887 +.fill PAGE_SIZE-5,1,0xcc
16888 +#endif
16889 +
16890 ENTRY(startup_32)
16891 movl pa(stack_start),%ecx
16892
16893 @@ -106,6 +121,59 @@ ENTRY(startup_32)
16894 2:
16895 leal -__PAGE_OFFSET(%ecx),%esp
16896
16897 +#ifdef CONFIG_SMP
16898 + movl $pa(cpu_gdt_table),%edi
16899 + movl $__per_cpu_load,%eax
16900 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
16901 + rorl $16,%eax
16902 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
16903 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
16904 + movl $__per_cpu_end - 1,%eax
16905 + subl $__per_cpu_start,%eax
16906 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
16907 +#endif
16908 +
16909 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16910 + movl $NR_CPUS,%ecx
16911 + movl $pa(cpu_gdt_table),%edi
16912 +1:
16913 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16914 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16915 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16916 + addl $PAGE_SIZE_asm,%edi
16917 + loop 1b
16918 +#endif
16919 +
16920 +#ifdef CONFIG_PAX_KERNEXEC
16921 + movl $pa(boot_gdt),%edi
16922 + movl $__LOAD_PHYSICAL_ADDR,%eax
16923 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
16924 + rorl $16,%eax
16925 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
16926 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
16927 + rorl $16,%eax
16928 +
16929 + ljmp $(__BOOT_CS),$1f
16930 +1:
16931 +
16932 + movl $NR_CPUS,%ecx
16933 + movl $pa(cpu_gdt_table),%edi
16934 + addl $__PAGE_OFFSET,%eax
16935 +1:
16936 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
16937 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
16938 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
16939 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
16940 + rorl $16,%eax
16941 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
16942 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
16943 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
16944 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
16945 + rorl $16,%eax
16946 + addl $PAGE_SIZE_asm,%edi
16947 + loop 1b
16948 +#endif
16949 +
16950 /*
16951 * Clear BSS first so that there are no surprises...
16952 */
16953 @@ -196,8 +264,11 @@ ENTRY(startup_32)
16954 movl %eax, pa(max_pfn_mapped)
16955
16956 /* Do early initialization of the fixmap area */
16957 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16958 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16959 +#ifdef CONFIG_COMPAT_VDSO
16960 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16961 +#else
16962 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16963 +#endif
16964 #else /* Not PAE */
16965
16966 page_pde_offset = (__PAGE_OFFSET >> 20);
16967 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16968 movl %eax, pa(max_pfn_mapped)
16969
16970 /* Do early initialization of the fixmap area */
16971 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16972 - movl %eax,pa(initial_page_table+0xffc)
16973 +#ifdef CONFIG_COMPAT_VDSO
16974 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16975 +#else
16976 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16977 +#endif
16978 #endif
16979
16980 #ifdef CONFIG_PARAVIRT
16981 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16982 cmpl $num_subarch_entries, %eax
16983 jae bad_subarch
16984
16985 - movl pa(subarch_entries)(,%eax,4), %eax
16986 - subl $__PAGE_OFFSET, %eax
16987 - jmp *%eax
16988 + jmp *pa(subarch_entries)(,%eax,4)
16989
16990 bad_subarch:
16991 WEAK(lguest_entry)
16992 @@ -256,10 +328,10 @@ WEAK(xen_entry)
16993 __INITDATA
16994
16995 subarch_entries:
16996 - .long default_entry /* normal x86/PC */
16997 - .long lguest_entry /* lguest hypervisor */
16998 - .long xen_entry /* Xen hypervisor */
16999 - .long default_entry /* Moorestown MID */
17000 + .long ta(default_entry) /* normal x86/PC */
17001 + .long ta(lguest_entry) /* lguest hypervisor */
17002 + .long ta(xen_entry) /* Xen hypervisor */
17003 + .long ta(default_entry) /* Moorestown MID */
17004 num_subarch_entries = (. - subarch_entries) / 4
17005 .previous
17006 #else
17007 @@ -310,6 +382,7 @@ default_entry:
17008 orl %edx,%eax
17009 movl %eax,%cr4
17010
17011 +#ifdef CONFIG_X86_PAE
17012 testb $X86_CR4_PAE, %al # check if PAE is enabled
17013 jz 6f
17014
17015 @@ -338,6 +411,9 @@ default_entry:
17016 /* Make changes effective */
17017 wrmsr
17018
17019 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17020 +#endif
17021 +
17022 6:
17023
17024 /*
17025 @@ -436,14 +512,20 @@ is386: movl $2,%ecx # set MP
17026 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17027 movl %eax,%ss # after changing gdt.
17028
17029 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17030 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17031 movl %eax,%ds
17032 movl %eax,%es
17033
17034 movl $(__KERNEL_PERCPU), %eax
17035 movl %eax,%fs # set this cpu's percpu
17036
17037 +#ifdef CONFIG_CC_STACKPROTECTOR
17038 movl $(__KERNEL_STACK_CANARY),%eax
17039 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17040 + movl $(__USER_DS),%eax
17041 +#else
17042 + xorl %eax,%eax
17043 +#endif
17044 movl %eax,%gs
17045
17046 xorl %eax,%eax # Clear LDT
17047 @@ -520,8 +602,11 @@ setup_once:
17048 * relocation. Manually set base address in stack canary
17049 * segment descriptor.
17050 */
17051 - movl $gdt_page,%eax
17052 + movl $cpu_gdt_table,%eax
17053 movl $stack_canary,%ecx
17054 +#ifdef CONFIG_SMP
17055 + addl $__per_cpu_load,%ecx
17056 +#endif
17057 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17058 shrl $16, %ecx
17059 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17060 @@ -552,7 +637,7 @@ ENDPROC(early_idt_handlers)
17061 /* This is global to keep gas from relaxing the jumps */
17062 ENTRY(early_idt_handler)
17063 cld
17064 - cmpl $2,%ss:early_recursion_flag
17065 + cmpl $1,%ss:early_recursion_flag
17066 je hlt_loop
17067 incl %ss:early_recursion_flag
17068
17069 @@ -590,8 +675,8 @@ ENTRY(early_idt_handler)
17070 pushl (20+6*4)(%esp) /* trapno */
17071 pushl $fault_msg
17072 call printk
17073 -#endif
17074 call dump_stack
17075 +#endif
17076 hlt_loop:
17077 hlt
17078 jmp hlt_loop
17079 @@ -610,8 +695,11 @@ ENDPROC(early_idt_handler)
17080 /* This is the default interrupt "handler" :-) */
17081 ALIGN
17082 ignore_int:
17083 - cld
17084 #ifdef CONFIG_PRINTK
17085 + cmpl $2,%ss:early_recursion_flag
17086 + je hlt_loop
17087 + incl %ss:early_recursion_flag
17088 + cld
17089 pushl %eax
17090 pushl %ecx
17091 pushl %edx
17092 @@ -620,9 +708,6 @@ ignore_int:
17093 movl $(__KERNEL_DS),%eax
17094 movl %eax,%ds
17095 movl %eax,%es
17096 - cmpl $2,early_recursion_flag
17097 - je hlt_loop
17098 - incl early_recursion_flag
17099 pushl 16(%esp)
17100 pushl 24(%esp)
17101 pushl 32(%esp)
17102 @@ -656,29 +741,43 @@ ENTRY(setup_once_ref)
17103 /*
17104 * BSS section
17105 */
17106 -__PAGE_ALIGNED_BSS
17107 - .align PAGE_SIZE
17108 #ifdef CONFIG_X86_PAE
17109 +.section .initial_pg_pmd,"a",@progbits
17110 initial_pg_pmd:
17111 .fill 1024*KPMDS,4,0
17112 #else
17113 +.section .initial_page_table,"a",@progbits
17114 ENTRY(initial_page_table)
17115 .fill 1024,4,0
17116 #endif
17117 +.section .initial_pg_fixmap,"a",@progbits
17118 initial_pg_fixmap:
17119 .fill 1024,4,0
17120 +.section .empty_zero_page,"a",@progbits
17121 ENTRY(empty_zero_page)
17122 .fill 4096,1,0
17123 +.section .swapper_pg_dir,"a",@progbits
17124 ENTRY(swapper_pg_dir)
17125 +#ifdef CONFIG_X86_PAE
17126 + .fill 4,8,0
17127 +#else
17128 .fill 1024,4,0
17129 +#endif
17130 +
17131 +/*
17132 + * The IDT has to be page-aligned to simplify the Pentium
17133 + * F0 0F bug workaround.. We have a special link segment
17134 + * for this.
17135 + */
17136 +.section .idt,"a",@progbits
17137 +ENTRY(idt_table)
17138 + .fill 256,8,0
17139
17140 /*
17141 * This starts the data section.
17142 */
17143 #ifdef CONFIG_X86_PAE
17144 -__PAGE_ALIGNED_DATA
17145 - /* Page-aligned for the benefit of paravirt? */
17146 - .align PAGE_SIZE
17147 +.section .initial_page_table,"a",@progbits
17148 ENTRY(initial_page_table)
17149 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17150 # if KPMDS == 3
17151 @@ -697,12 +796,20 @@ ENTRY(initial_page_table)
17152 # error "Kernel PMDs should be 1, 2 or 3"
17153 # endif
17154 .align PAGE_SIZE /* needs to be page-sized too */
17155 +
17156 +#ifdef CONFIG_PAX_PER_CPU_PGD
17157 +ENTRY(cpu_pgd)
17158 + .rept NR_CPUS
17159 + .fill 4,8,0
17160 + .endr
17161 +#endif
17162 +
17163 #endif
17164
17165 .data
17166 .balign 4
17167 ENTRY(stack_start)
17168 - .long init_thread_union+THREAD_SIZE
17169 + .long init_thread_union+THREAD_SIZE-8
17170
17171 __INITRODATA
17172 int_msg:
17173 @@ -730,7 +837,7 @@ fault_msg:
17174 * segment size, and 32-bit linear address value:
17175 */
17176
17177 - .data
17178 +.section .rodata,"a",@progbits
17179 .globl boot_gdt_descr
17180 .globl idt_descr
17181
17182 @@ -739,7 +846,7 @@ fault_msg:
17183 .word 0 # 32 bit align gdt_desc.address
17184 boot_gdt_descr:
17185 .word __BOOT_DS+7
17186 - .long boot_gdt - __PAGE_OFFSET
17187 + .long pa(boot_gdt)
17188
17189 .word 0 # 32-bit align idt_desc.address
17190 idt_descr:
17191 @@ -750,7 +857,7 @@ idt_descr:
17192 .word 0 # 32 bit align gdt_desc.address
17193 ENTRY(early_gdt_descr)
17194 .word GDT_ENTRIES*8-1
17195 - .long gdt_page /* Overwritten for secondary CPUs */
17196 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17197
17198 /*
17199 * The boot_gdt must mirror the equivalent in setup.S and is
17200 @@ -759,5 +866,65 @@ ENTRY(early_gdt_descr)
17201 .align L1_CACHE_BYTES
17202 ENTRY(boot_gdt)
17203 .fill GDT_ENTRY_BOOT_CS,8,0
17204 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17205 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17206 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17207 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17208 +
17209 + .align PAGE_SIZE_asm
17210 +ENTRY(cpu_gdt_table)
17211 + .rept NR_CPUS
17212 + .quad 0x0000000000000000 /* NULL descriptor */
17213 + .quad 0x0000000000000000 /* 0x0b reserved */
17214 + .quad 0x0000000000000000 /* 0x13 reserved */
17215 + .quad 0x0000000000000000 /* 0x1b reserved */
17216 +
17217 +#ifdef CONFIG_PAX_KERNEXEC
17218 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17219 +#else
17220 + .quad 0x0000000000000000 /* 0x20 unused */
17221 +#endif
17222 +
17223 + .quad 0x0000000000000000 /* 0x28 unused */
17224 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17225 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17226 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17227 + .quad 0x0000000000000000 /* 0x4b reserved */
17228 + .quad 0x0000000000000000 /* 0x53 reserved */
17229 + .quad 0x0000000000000000 /* 0x5b reserved */
17230 +
17231 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17232 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17233 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17234 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17235 +
17236 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17237 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17238 +
17239 + /*
17240 + * Segments used for calling PnP BIOS have byte granularity.
17241 + * The code segments and data segments have fixed 64k limits,
17242 + * the transfer segment sizes are set at run time.
17243 + */
17244 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17245 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17246 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17247 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17248 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17249 +
17250 + /*
17251 + * The APM segments have byte granularity and their bases
17252 + * are set at run time. All have 64k limits.
17253 + */
17254 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17255 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17256 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17257 +
17258 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17259 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17260 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17261 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17262 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17263 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17264 +
17265 + /* Be sure this is zeroed to avoid false validations in Xen */
17266 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17267 + .endr
17268 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17269 index 94bf9cc..400455a 100644
17270 --- a/arch/x86/kernel/head_64.S
17271 +++ b/arch/x86/kernel/head_64.S
17272 @@ -20,6 +20,8 @@
17273 #include <asm/processor-flags.h>
17274 #include <asm/percpu.h>
17275 #include <asm/nops.h>
17276 +#include <asm/cpufeature.h>
17277 +#include <asm/alternative-asm.h>
17278
17279 #ifdef CONFIG_PARAVIRT
17280 #include <asm/asm-offsets.h>
17281 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17282 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17283 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17284 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17285 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17286 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17287 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17288 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17289 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17290 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17291
17292 .text
17293 __HEAD
17294 @@ -88,35 +96,23 @@ startup_64:
17295 */
17296 addq %rbp, init_level4_pgt + 0(%rip)
17297 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17298 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17299 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17300 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17301 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17302
17303 addq %rbp, level3_ident_pgt + 0(%rip)
17304 +#ifndef CONFIG_XEN
17305 + addq %rbp, level3_ident_pgt + 8(%rip)
17306 +#endif
17307
17308 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17309 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17310 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17311 +
17312 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17313 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17314
17315 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17316 -
17317 - /* Add an Identity mapping if I am above 1G */
17318 - leaq _text(%rip), %rdi
17319 - andq $PMD_PAGE_MASK, %rdi
17320 -
17321 - movq %rdi, %rax
17322 - shrq $PUD_SHIFT, %rax
17323 - andq $(PTRS_PER_PUD - 1), %rax
17324 - jz ident_complete
17325 -
17326 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17327 - leaq level3_ident_pgt(%rip), %rbx
17328 - movq %rdx, 0(%rbx, %rax, 8)
17329 -
17330 - movq %rdi, %rax
17331 - shrq $PMD_SHIFT, %rax
17332 - andq $(PTRS_PER_PMD - 1), %rax
17333 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17334 - leaq level2_spare_pgt(%rip), %rbx
17335 - movq %rdx, 0(%rbx, %rax, 8)
17336 -ident_complete:
17337 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17338
17339 /*
17340 * Fixup the kernel text+data virtual addresses. Note that
17341 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17342 * after the boot processor executes this code.
17343 */
17344
17345 - /* Enable PAE mode and PGE */
17346 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17347 + /* Enable PAE mode and PSE/PGE */
17348 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17349 movq %rax, %cr4
17350
17351 /* Setup early boot stage 4 level pagetables. */
17352 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17353 movl $MSR_EFER, %ecx
17354 rdmsr
17355 btsl $_EFER_SCE, %eax /* Enable System Call */
17356 - btl $20,%edi /* No Execute supported? */
17357 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17358 jnc 1f
17359 btsl $_EFER_NX, %eax
17360 + leaq init_level4_pgt(%rip), %rdi
17361 +#ifndef CONFIG_EFI
17362 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17363 +#endif
17364 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17365 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17366 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17367 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17368 1: wrmsr /* Make changes effective */
17369
17370 /* Setup cr0 */
17371 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17372 * jump. In addition we need to ensure %cs is set so we make this
17373 * a far return.
17374 */
17375 + pax_set_fptr_mask
17376 movq initial_code(%rip),%rax
17377 pushq $0 # fake return address to stop unwinder
17378 pushq $__KERNEL_CS # set correct cs
17379 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17380 bad_address:
17381 jmp bad_address
17382
17383 - .section ".init.text","ax"
17384 + __INIT
17385 .globl early_idt_handlers
17386 early_idt_handlers:
17387 # 104(%rsp) %rflags
17388 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17389 addq $16,%rsp # drop vector number and error code
17390 decl early_recursion_flag(%rip)
17391 INTERRUPT_RETURN
17392 + .previous
17393
17394 + __INITDATA
17395 .balign 4
17396 early_recursion_flag:
17397 .long 0
17398 + .previous
17399
17400 + .section .rodata,"a",@progbits
17401 #ifdef CONFIG_EARLY_PRINTK
17402 early_idt_msg:
17403 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17404 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17405 #endif /* CONFIG_EARLY_PRINTK */
17406 .previous
17407
17408 + .section .rodata,"a",@progbits
17409 #define NEXT_PAGE(name) \
17410 .balign PAGE_SIZE; \
17411 ENTRY(name)
17412 @@ -372,7 +382,6 @@ ENTRY(name)
17413 i = i + 1 ; \
17414 .endr
17415
17416 - .data
17417 /*
17418 * This default setting generates an ident mapping at address 0x100000
17419 * and a mapping for the kernel that precisely maps virtual address
17420 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17421 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17422 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17423 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17424 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17425 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17426 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17427 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17428 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17429 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17430 .org init_level4_pgt + L4_START_KERNEL*8, 0
17431 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17432 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17433
17434 +#ifdef CONFIG_PAX_PER_CPU_PGD
17435 +NEXT_PAGE(cpu_pgd)
17436 + .rept NR_CPUS
17437 + .fill 512,8,0
17438 + .endr
17439 +#endif
17440 +
17441 NEXT_PAGE(level3_ident_pgt)
17442 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17443 +#ifdef CONFIG_XEN
17444 .fill 511,8,0
17445 +#else
17446 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17447 + .fill 510,8,0
17448 +#endif
17449 +
17450 +NEXT_PAGE(level3_vmalloc_start_pgt)
17451 + .fill 512,8,0
17452 +
17453 +NEXT_PAGE(level3_vmalloc_end_pgt)
17454 + .fill 512,8,0
17455 +
17456 +NEXT_PAGE(level3_vmemmap_pgt)
17457 + .fill L3_VMEMMAP_START,8,0
17458 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17459
17460 NEXT_PAGE(level3_kernel_pgt)
17461 .fill L3_START_KERNEL,8,0
17462 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17463 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17464 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17465
17466 +NEXT_PAGE(level2_vmemmap_pgt)
17467 + .fill 512,8,0
17468 +
17469 NEXT_PAGE(level2_fixmap_pgt)
17470 - .fill 506,8,0
17471 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17472 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17473 - .fill 5,8,0
17474 + .fill 507,8,0
17475 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17476 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17477 + .fill 4,8,0
17478
17479 -NEXT_PAGE(level1_fixmap_pgt)
17480 +NEXT_PAGE(level1_vsyscall_pgt)
17481 .fill 512,8,0
17482
17483 -NEXT_PAGE(level2_ident_pgt)
17484 - /* Since I easily can, map the first 1G.
17485 + /* Since I easily can, map the first 2G.
17486 * Don't set NX because code runs from these pages.
17487 */
17488 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17489 +NEXT_PAGE(level2_ident_pgt)
17490 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17491
17492 NEXT_PAGE(level2_kernel_pgt)
17493 /*
17494 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17495 * If you want to increase this then increase MODULES_VADDR
17496 * too.)
17497 */
17498 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17499 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17500 -
17501 -NEXT_PAGE(level2_spare_pgt)
17502 - .fill 512, 8, 0
17503 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17504
17505 #undef PMDS
17506 #undef NEXT_PAGE
17507
17508 - .data
17509 + .align PAGE_SIZE
17510 +ENTRY(cpu_gdt_table)
17511 + .rept NR_CPUS
17512 + .quad 0x0000000000000000 /* NULL descriptor */
17513 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17514 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17515 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17516 + .quad 0x00cffb000000ffff /* __USER32_CS */
17517 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17518 + .quad 0x00affb000000ffff /* __USER_CS */
17519 +
17520 +#ifdef CONFIG_PAX_KERNEXEC
17521 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17522 +#else
17523 + .quad 0x0 /* unused */
17524 +#endif
17525 +
17526 + .quad 0,0 /* TSS */
17527 + .quad 0,0 /* LDT */
17528 + .quad 0,0,0 /* three TLS descriptors */
17529 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17530 + /* asm/segment.h:GDT_ENTRIES must match this */
17531 +
17532 + /* zero the remaining page */
17533 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17534 + .endr
17535 +
17536 .align 16
17537 .globl early_gdt_descr
17538 early_gdt_descr:
17539 .word GDT_ENTRIES*8-1
17540 early_gdt_descr_base:
17541 - .quad INIT_PER_CPU_VAR(gdt_page)
17542 + .quad cpu_gdt_table
17543
17544 ENTRY(phys_base)
17545 /* This must match the first entry in level2_kernel_pgt */
17546 .quad 0x0000000000000000
17547
17548 #include "../../x86/xen/xen-head.S"
17549 -
17550 - .section .bss, "aw", @nobits
17551 +
17552 + .section .rodata,"a",@progbits
17553 .align L1_CACHE_BYTES
17554 ENTRY(idt_table)
17555 - .skip IDT_ENTRIES * 16
17556 + .fill 512,8,0
17557
17558 .align L1_CACHE_BYTES
17559 ENTRY(nmi_idt_table)
17560 - .skip IDT_ENTRIES * 16
17561 + .fill 512,8,0
17562
17563 __PAGE_ALIGNED_BSS
17564 .align PAGE_SIZE
17565 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17566 index 9c3bd4a..e1d9b35 100644
17567 --- a/arch/x86/kernel/i386_ksyms_32.c
17568 +++ b/arch/x86/kernel/i386_ksyms_32.c
17569 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17570 EXPORT_SYMBOL(cmpxchg8b_emu);
17571 #endif
17572
17573 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17574 +
17575 /* Networking helper routines. */
17576 EXPORT_SYMBOL(csum_partial_copy_generic);
17577 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17578 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17579
17580 EXPORT_SYMBOL(__get_user_1);
17581 EXPORT_SYMBOL(__get_user_2);
17582 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17583
17584 EXPORT_SYMBOL(csum_partial);
17585 EXPORT_SYMBOL(empty_zero_page);
17586 +
17587 +#ifdef CONFIG_PAX_KERNEXEC
17588 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17589 +#endif
17590 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17591 index f250431..54097e7 100644
17592 --- a/arch/x86/kernel/i387.c
17593 +++ b/arch/x86/kernel/i387.c
17594 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17595 static inline bool interrupted_user_mode(void)
17596 {
17597 struct pt_regs *regs = get_irq_regs();
17598 - return regs && user_mode_vm(regs);
17599 + return regs && user_mode(regs);
17600 }
17601
17602 /*
17603 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17604 index 36d1853..bf25736 100644
17605 --- a/arch/x86/kernel/i8259.c
17606 +++ b/arch/x86/kernel/i8259.c
17607 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17608 "spurious 8259A interrupt: IRQ%d.\n", irq);
17609 spurious_irq_mask |= irqmask;
17610 }
17611 - atomic_inc(&irq_err_count);
17612 + atomic_inc_unchecked(&irq_err_count);
17613 /*
17614 * Theoretically we do not have to handle this IRQ,
17615 * but in Linux this does not cause problems and is
17616 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17617 index 8c96897..be66bfa 100644
17618 --- a/arch/x86/kernel/ioport.c
17619 +++ b/arch/x86/kernel/ioport.c
17620 @@ -6,6 +6,7 @@
17621 #include <linux/sched.h>
17622 #include <linux/kernel.h>
17623 #include <linux/capability.h>
17624 +#include <linux/security.h>
17625 #include <linux/errno.h>
17626 #include <linux/types.h>
17627 #include <linux/ioport.h>
17628 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17629
17630 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17631 return -EINVAL;
17632 +#ifdef CONFIG_GRKERNSEC_IO
17633 + if (turn_on && grsec_disable_privio) {
17634 + gr_handle_ioperm();
17635 + return -EPERM;
17636 + }
17637 +#endif
17638 if (turn_on && !capable(CAP_SYS_RAWIO))
17639 return -EPERM;
17640
17641 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17642 * because the ->io_bitmap_max value must match the bitmap
17643 * contents:
17644 */
17645 - tss = &per_cpu(init_tss, get_cpu());
17646 + tss = init_tss + get_cpu();
17647
17648 if (turn_on)
17649 bitmap_clear(t->io_bitmap_ptr, from, num);
17650 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17651 return -EINVAL;
17652 /* Trying to gain more privileges? */
17653 if (level > old) {
17654 +#ifdef CONFIG_GRKERNSEC_IO
17655 + if (grsec_disable_privio) {
17656 + gr_handle_iopl();
17657 + return -EPERM;
17658 + }
17659 +#endif
17660 if (!capable(CAP_SYS_RAWIO))
17661 return -EPERM;
17662 }
17663 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17664 index d44f782..31ab01e 100644
17665 --- a/arch/x86/kernel/irq.c
17666 +++ b/arch/x86/kernel/irq.c
17667 @@ -18,7 +18,7 @@
17668 #include <asm/mce.h>
17669 #include <asm/hw_irq.h>
17670
17671 -atomic_t irq_err_count;
17672 +atomic_unchecked_t irq_err_count;
17673
17674 /* Function pointer for generic interrupt vector handling */
17675 void (*x86_platform_ipi_callback)(void) = NULL;
17676 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17677 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17678 seq_printf(p, " Machine check polls\n");
17679 #endif
17680 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17681 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17682 #if defined(CONFIG_X86_IO_APIC)
17683 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17684 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17685 #endif
17686 return 0;
17687 }
17688 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17689
17690 u64 arch_irq_stat(void)
17691 {
17692 - u64 sum = atomic_read(&irq_err_count);
17693 + u64 sum = atomic_read_unchecked(&irq_err_count);
17694
17695 #ifdef CONFIG_X86_IO_APIC
17696 - sum += atomic_read(&irq_mis_count);
17697 + sum += atomic_read_unchecked(&irq_mis_count);
17698 #endif
17699 return sum;
17700 }
17701 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17702 index 344faf8..355f60d 100644
17703 --- a/arch/x86/kernel/irq_32.c
17704 +++ b/arch/x86/kernel/irq_32.c
17705 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17706 __asm__ __volatile__("andl %%esp,%0" :
17707 "=r" (sp) : "0" (THREAD_SIZE - 1));
17708
17709 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17710 + return sp < STACK_WARN;
17711 }
17712
17713 static void print_stack_overflow(void)
17714 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17715 * per-CPU IRQ handling contexts (thread information and stack)
17716 */
17717 union irq_ctx {
17718 - struct thread_info tinfo;
17719 - u32 stack[THREAD_SIZE/sizeof(u32)];
17720 + unsigned long previous_esp;
17721 + u32 stack[THREAD_SIZE/sizeof(u32)];
17722 } __attribute__((aligned(THREAD_SIZE)));
17723
17724 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17725 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17726 static inline int
17727 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17728 {
17729 - union irq_ctx *curctx, *irqctx;
17730 + union irq_ctx *irqctx;
17731 u32 *isp, arg1, arg2;
17732
17733 - curctx = (union irq_ctx *) current_thread_info();
17734 irqctx = __this_cpu_read(hardirq_ctx);
17735
17736 /*
17737 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17738 * handler) we can't do that and just have to keep using the
17739 * current stack (which is the irq stack already after all)
17740 */
17741 - if (unlikely(curctx == irqctx))
17742 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17743 return 0;
17744
17745 /* build the stack frame on the IRQ stack */
17746 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17747 - irqctx->tinfo.task = curctx->tinfo.task;
17748 - irqctx->tinfo.previous_esp = current_stack_pointer;
17749 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17750 + irqctx->previous_esp = current_stack_pointer;
17751
17752 - /* Copy the preempt_count so that the [soft]irq checks work. */
17753 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17754 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17755 + __set_fs(MAKE_MM_SEG(0));
17756 +#endif
17757
17758 if (unlikely(overflow))
17759 call_on_stack(print_stack_overflow, isp);
17760 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17761 : "0" (irq), "1" (desc), "2" (isp),
17762 "D" (desc->handle_irq)
17763 : "memory", "cc", "ecx");
17764 +
17765 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17766 + __set_fs(current_thread_info()->addr_limit);
17767 +#endif
17768 +
17769 return 1;
17770 }
17771
17772 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17773 */
17774 void __cpuinit irq_ctx_init(int cpu)
17775 {
17776 - union irq_ctx *irqctx;
17777 -
17778 if (per_cpu(hardirq_ctx, cpu))
17779 return;
17780
17781 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17782 - THREADINFO_GFP,
17783 - THREAD_SIZE_ORDER));
17784 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17785 - irqctx->tinfo.cpu = cpu;
17786 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17787 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17788 -
17789 - per_cpu(hardirq_ctx, cpu) = irqctx;
17790 -
17791 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17792 - THREADINFO_GFP,
17793 - THREAD_SIZE_ORDER));
17794 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17795 - irqctx->tinfo.cpu = cpu;
17796 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17797 -
17798 - per_cpu(softirq_ctx, cpu) = irqctx;
17799 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17800 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17801 +
17802 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17803 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17804
17805 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17806 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17807 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17808 asmlinkage void do_softirq(void)
17809 {
17810 unsigned long flags;
17811 - struct thread_info *curctx;
17812 union irq_ctx *irqctx;
17813 u32 *isp;
17814
17815 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17816 local_irq_save(flags);
17817
17818 if (local_softirq_pending()) {
17819 - curctx = current_thread_info();
17820 irqctx = __this_cpu_read(softirq_ctx);
17821 - irqctx->tinfo.task = curctx->task;
17822 - irqctx->tinfo.previous_esp = current_stack_pointer;
17823 + irqctx->previous_esp = current_stack_pointer;
17824
17825 /* build the stack frame on the softirq stack */
17826 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17827 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17828 +
17829 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17830 + __set_fs(MAKE_MM_SEG(0));
17831 +#endif
17832
17833 call_on_stack(__do_softirq, isp);
17834 +
17835 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17836 + __set_fs(current_thread_info()->addr_limit);
17837 +#endif
17838 +
17839 /*
17840 * Shouldn't happen, we returned above if in_interrupt():
17841 */
17842 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17843 if (unlikely(!desc))
17844 return false;
17845
17846 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17847 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17848 if (unlikely(overflow))
17849 print_stack_overflow();
17850 desc->handle_irq(irq, desc);
17851 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17852 index d04d3ec..ea4b374 100644
17853 --- a/arch/x86/kernel/irq_64.c
17854 +++ b/arch/x86/kernel/irq_64.c
17855 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17856 u64 estack_top, estack_bottom;
17857 u64 curbase = (u64)task_stack_page(current);
17858
17859 - if (user_mode_vm(regs))
17860 + if (user_mode(regs))
17861 return;
17862
17863 if (regs->sp >= curbase + sizeof(struct thread_info) +
17864 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17865 index dc1404b..bbc43e7 100644
17866 --- a/arch/x86/kernel/kdebugfs.c
17867 +++ b/arch/x86/kernel/kdebugfs.c
17868 @@ -27,7 +27,7 @@ struct setup_data_node {
17869 u32 len;
17870 };
17871
17872 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17873 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17874 size_t count, loff_t *ppos)
17875 {
17876 struct setup_data_node *node = file->private_data;
17877 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17878 index 3f61904..873cea9 100644
17879 --- a/arch/x86/kernel/kgdb.c
17880 +++ b/arch/x86/kernel/kgdb.c
17881 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17882 #ifdef CONFIG_X86_32
17883 switch (regno) {
17884 case GDB_SS:
17885 - if (!user_mode_vm(regs))
17886 + if (!user_mode(regs))
17887 *(unsigned long *)mem = __KERNEL_DS;
17888 break;
17889 case GDB_SP:
17890 - if (!user_mode_vm(regs))
17891 + if (!user_mode(regs))
17892 *(unsigned long *)mem = kernel_stack_pointer(regs);
17893 break;
17894 case GDB_GS:
17895 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17896 case 'k':
17897 /* clear the trace bit */
17898 linux_regs->flags &= ~X86_EFLAGS_TF;
17899 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17900 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17901
17902 /* set the trace bit if we're stepping */
17903 if (remcomInBuffer[0] == 's') {
17904 linux_regs->flags |= X86_EFLAGS_TF;
17905 - atomic_set(&kgdb_cpu_doing_single_step,
17906 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17907 raw_smp_processor_id());
17908 }
17909
17910 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17911
17912 switch (cmd) {
17913 case DIE_DEBUG:
17914 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17915 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17916 if (user_mode(regs))
17917 return single_step_cont(regs, args);
17918 break;
17919 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17920 index c5e410e..da6aaf9 100644
17921 --- a/arch/x86/kernel/kprobes-opt.c
17922 +++ b/arch/x86/kernel/kprobes-opt.c
17923 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17924 * Verify if the address gap is in 2GB range, because this uses
17925 * a relative jump.
17926 */
17927 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17928 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17929 if (abs(rel) > 0x7fffffff)
17930 return -ERANGE;
17931
17932 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17933 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17934
17935 /* Set probe function call */
17936 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17937 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17938
17939 /* Set returning jmp instruction at the tail of out-of-line buffer */
17940 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17941 - (u8 *)op->kp.addr + op->optinsn.size);
17942 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17943
17944 flush_icache_range((unsigned long) buf,
17945 (unsigned long) buf + TMPL_END_IDX +
17946 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17947 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17948
17949 /* Backup instructions which will be replaced by jump address */
17950 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17951 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17952 RELATIVE_ADDR_SIZE);
17953
17954 insn_buf[0] = RELATIVEJUMP_OPCODE;
17955 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17956 index e2f751e..dffa2a0 100644
17957 --- a/arch/x86/kernel/kprobes.c
17958 +++ b/arch/x86/kernel/kprobes.c
17959 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17960 } __attribute__((packed)) *insn;
17961
17962 insn = (struct __arch_relative_insn *)from;
17963 +
17964 + pax_open_kernel();
17965 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17966 insn->op = op;
17967 + pax_close_kernel();
17968 }
17969
17970 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17971 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17972 kprobe_opcode_t opcode;
17973 kprobe_opcode_t *orig_opcodes = opcodes;
17974
17975 - if (search_exception_tables((unsigned long)opcodes))
17976 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17977 return 0; /* Page fault may occur on this address. */
17978
17979 retry:
17980 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17981 /* Another subsystem puts a breakpoint, failed to recover */
17982 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17983 return 0;
17984 + pax_open_kernel();
17985 memcpy(dest, insn.kaddr, insn.length);
17986 + pax_close_kernel();
17987
17988 #ifdef CONFIG_X86_64
17989 if (insn_rip_relative(&insn)) {
17990 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17991 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17992 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17993 disp = (u8 *) dest + insn_offset_displacement(&insn);
17994 + pax_open_kernel();
17995 *(s32 *) disp = (s32) newdisp;
17996 + pax_close_kernel();
17997 }
17998 #endif
17999 return insn.length;
18000 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18001 * nor set current_kprobe, because it doesn't use single
18002 * stepping.
18003 */
18004 - regs->ip = (unsigned long)p->ainsn.insn;
18005 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18006 preempt_enable_no_resched();
18007 return;
18008 }
18009 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18010 if (p->opcode == BREAKPOINT_INSTRUCTION)
18011 regs->ip = (unsigned long)p->addr;
18012 else
18013 - regs->ip = (unsigned long)p->ainsn.insn;
18014 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18015 }
18016
18017 /*
18018 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18019 setup_singlestep(p, regs, kcb, 0);
18020 return 1;
18021 }
18022 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18023 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18024 /*
18025 * The breakpoint instruction was removed right
18026 * after we hit it. Another cpu has removed
18027 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18028 " movq %rax, 152(%rsp)\n"
18029 RESTORE_REGS_STRING
18030 " popfq\n"
18031 +#ifdef KERNEXEC_PLUGIN
18032 + " btsq $63,(%rsp)\n"
18033 +#endif
18034 #else
18035 " pushf\n"
18036 SAVE_REGS_STRING
18037 @@ -765,7 +775,7 @@ static void __kprobes
18038 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18039 {
18040 unsigned long *tos = stack_addr(regs);
18041 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18042 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18043 unsigned long orig_ip = (unsigned long)p->addr;
18044 kprobe_opcode_t *insn = p->ainsn.insn;
18045
18046 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18047 struct die_args *args = data;
18048 int ret = NOTIFY_DONE;
18049
18050 - if (args->regs && user_mode_vm(args->regs))
18051 + if (args->regs && user_mode(args->regs))
18052 return ret;
18053
18054 switch (val) {
18055 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18056 index ebc9873..1b9724b 100644
18057 --- a/arch/x86/kernel/ldt.c
18058 +++ b/arch/x86/kernel/ldt.c
18059 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18060 if (reload) {
18061 #ifdef CONFIG_SMP
18062 preempt_disable();
18063 - load_LDT(pc);
18064 + load_LDT_nolock(pc);
18065 if (!cpumask_equal(mm_cpumask(current->mm),
18066 cpumask_of(smp_processor_id())))
18067 smp_call_function(flush_ldt, current->mm, 1);
18068 preempt_enable();
18069 #else
18070 - load_LDT(pc);
18071 + load_LDT_nolock(pc);
18072 #endif
18073 }
18074 if (oldsize) {
18075 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18076 return err;
18077
18078 for (i = 0; i < old->size; i++)
18079 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18080 + write_ldt_entry(new->ldt, i, old->ldt + i);
18081 return 0;
18082 }
18083
18084 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18085 retval = copy_ldt(&mm->context, &old_mm->context);
18086 mutex_unlock(&old_mm->context.lock);
18087 }
18088 +
18089 + if (tsk == current) {
18090 + mm->context.vdso = 0;
18091 +
18092 +#ifdef CONFIG_X86_32
18093 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18094 + mm->context.user_cs_base = 0UL;
18095 + mm->context.user_cs_limit = ~0UL;
18096 +
18097 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18098 + cpus_clear(mm->context.cpu_user_cs_mask);
18099 +#endif
18100 +
18101 +#endif
18102 +#endif
18103 +
18104 + }
18105 +
18106 return retval;
18107 }
18108
18109 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18110 }
18111 }
18112
18113 +#ifdef CONFIG_PAX_SEGMEXEC
18114 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18115 + error = -EINVAL;
18116 + goto out_unlock;
18117 + }
18118 +#endif
18119 +
18120 fill_ldt(&ldt, &ldt_info);
18121 if (oldmode)
18122 ldt.avl = 0;
18123 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18124 index 5b19e4d..6476a76 100644
18125 --- a/arch/x86/kernel/machine_kexec_32.c
18126 +++ b/arch/x86/kernel/machine_kexec_32.c
18127 @@ -26,7 +26,7 @@
18128 #include <asm/cacheflush.h>
18129 #include <asm/debugreg.h>
18130
18131 -static void set_idt(void *newidt, __u16 limit)
18132 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18133 {
18134 struct desc_ptr curidt;
18135
18136 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18137 }
18138
18139
18140 -static void set_gdt(void *newgdt, __u16 limit)
18141 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18142 {
18143 struct desc_ptr curgdt;
18144
18145 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18146 }
18147
18148 control_page = page_address(image->control_code_page);
18149 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18150 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18151
18152 relocate_kernel_ptr = control_page;
18153 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18154 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18155 index 0327e2b..e43737b 100644
18156 --- a/arch/x86/kernel/microcode_intel.c
18157 +++ b/arch/x86/kernel/microcode_intel.c
18158 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18159
18160 static int get_ucode_user(void *to, const void *from, size_t n)
18161 {
18162 - return copy_from_user(to, from, n);
18163 + return copy_from_user(to, (const void __force_user *)from, n);
18164 }
18165
18166 static enum ucode_state
18167 request_microcode_user(int cpu, const void __user *buf, size_t size)
18168 {
18169 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18170 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18171 }
18172
18173 static void microcode_fini_cpu(int cpu)
18174 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18175 index 216a4d7..b328f09 100644
18176 --- a/arch/x86/kernel/module.c
18177 +++ b/arch/x86/kernel/module.c
18178 @@ -43,15 +43,60 @@ do { \
18179 } while (0)
18180 #endif
18181
18182 -void *module_alloc(unsigned long size)
18183 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18184 {
18185 - if (PAGE_ALIGN(size) > MODULES_LEN)
18186 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18187 return NULL;
18188 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18189 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18190 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18191 -1, __builtin_return_address(0));
18192 }
18193
18194 +void *module_alloc(unsigned long size)
18195 +{
18196 +
18197 +#ifdef CONFIG_PAX_KERNEXEC
18198 + return __module_alloc(size, PAGE_KERNEL);
18199 +#else
18200 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18201 +#endif
18202 +
18203 +}
18204 +
18205 +#ifdef CONFIG_PAX_KERNEXEC
18206 +#ifdef CONFIG_X86_32
18207 +void *module_alloc_exec(unsigned long size)
18208 +{
18209 + struct vm_struct *area;
18210 +
18211 + if (size == 0)
18212 + return NULL;
18213 +
18214 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18215 + return area ? area->addr : NULL;
18216 +}
18217 +EXPORT_SYMBOL(module_alloc_exec);
18218 +
18219 +void module_free_exec(struct module *mod, void *module_region)
18220 +{
18221 + vunmap(module_region);
18222 +}
18223 +EXPORT_SYMBOL(module_free_exec);
18224 +#else
18225 +void module_free_exec(struct module *mod, void *module_region)
18226 +{
18227 + module_free(mod, module_region);
18228 +}
18229 +EXPORT_SYMBOL(module_free_exec);
18230 +
18231 +void *module_alloc_exec(unsigned long size)
18232 +{
18233 + return __module_alloc(size, PAGE_KERNEL_RX);
18234 +}
18235 +EXPORT_SYMBOL(module_alloc_exec);
18236 +#endif
18237 +#endif
18238 +
18239 #ifdef CONFIG_X86_32
18240 int apply_relocate(Elf32_Shdr *sechdrs,
18241 const char *strtab,
18242 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18243 unsigned int i;
18244 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18245 Elf32_Sym *sym;
18246 - uint32_t *location;
18247 + uint32_t *plocation, location;
18248
18249 DEBUGP("Applying relocate section %u to %u\n",
18250 relsec, sechdrs[relsec].sh_info);
18251 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18252 /* This is where to make the change */
18253 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18254 - + rel[i].r_offset;
18255 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18256 + location = (uint32_t)plocation;
18257 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18258 + plocation = ktla_ktva((void *)plocation);
18259 /* This is the symbol it is referring to. Note that all
18260 undefined symbols have been resolved. */
18261 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18262 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18263 switch (ELF32_R_TYPE(rel[i].r_info)) {
18264 case R_386_32:
18265 /* We add the value into the location given */
18266 - *location += sym->st_value;
18267 + pax_open_kernel();
18268 + *plocation += sym->st_value;
18269 + pax_close_kernel();
18270 break;
18271 case R_386_PC32:
18272 /* Add the value, subtract its position */
18273 - *location += sym->st_value - (uint32_t)location;
18274 + pax_open_kernel();
18275 + *plocation += sym->st_value - location;
18276 + pax_close_kernel();
18277 break;
18278 default:
18279 pr_err("%s: Unknown relocation: %u\n",
18280 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18281 case R_X86_64_NONE:
18282 break;
18283 case R_X86_64_64:
18284 + pax_open_kernel();
18285 *(u64 *)loc = val;
18286 + pax_close_kernel();
18287 break;
18288 case R_X86_64_32:
18289 + pax_open_kernel();
18290 *(u32 *)loc = val;
18291 + pax_close_kernel();
18292 if (val != *(u32 *)loc)
18293 goto overflow;
18294 break;
18295 case R_X86_64_32S:
18296 + pax_open_kernel();
18297 *(s32 *)loc = val;
18298 + pax_close_kernel();
18299 if ((s64)val != *(s32 *)loc)
18300 goto overflow;
18301 break;
18302 case R_X86_64_PC32:
18303 val -= (u64)loc;
18304 + pax_open_kernel();
18305 *(u32 *)loc = val;
18306 + pax_close_kernel();
18307 +
18308 #if 0
18309 if ((s64)val != *(s32 *)loc)
18310 goto overflow;
18311 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18312 index f84f5c5..e27e54b 100644
18313 --- a/arch/x86/kernel/nmi.c
18314 +++ b/arch/x86/kernel/nmi.c
18315 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18316 dotraplinkage notrace __kprobes void
18317 do_nmi(struct pt_regs *regs, long error_code)
18318 {
18319 +
18320 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18321 + if (!user_mode(regs)) {
18322 + unsigned long cs = regs->cs & 0xFFFF;
18323 + unsigned long ip = ktva_ktla(regs->ip);
18324 +
18325 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18326 + regs->ip = ip;
18327 + }
18328 +#endif
18329 +
18330 nmi_nesting_preprocess(regs);
18331
18332 nmi_enter();
18333 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18334 index 676b8c7..870ba04 100644
18335 --- a/arch/x86/kernel/paravirt-spinlocks.c
18336 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18337 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18338 arch_spin_lock(lock);
18339 }
18340
18341 -struct pv_lock_ops pv_lock_ops = {
18342 +struct pv_lock_ops pv_lock_ops __read_only = {
18343 #ifdef CONFIG_SMP
18344 .spin_is_locked = __ticket_spin_is_locked,
18345 .spin_is_contended = __ticket_spin_is_contended,
18346 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18347 index 17fff18..7bb2088 100644
18348 --- a/arch/x86/kernel/paravirt.c
18349 +++ b/arch/x86/kernel/paravirt.c
18350 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18351 {
18352 return x;
18353 }
18354 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18355 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18356 +#endif
18357
18358 void __init default_banner(void)
18359 {
18360 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18361 if (opfunc == NULL)
18362 /* If there's no function, patch it with a ud2a (BUG) */
18363 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18364 - else if (opfunc == _paravirt_nop)
18365 + else if (opfunc == (void *)_paravirt_nop)
18366 /* If the operation is a nop, then nop the callsite */
18367 ret = paravirt_patch_nop();
18368
18369 /* identity functions just return their single argument */
18370 - else if (opfunc == _paravirt_ident_32)
18371 + else if (opfunc == (void *)_paravirt_ident_32)
18372 ret = paravirt_patch_ident_32(insnbuf, len);
18373 - else if (opfunc == _paravirt_ident_64)
18374 + else if (opfunc == (void *)_paravirt_ident_64)
18375 ret = paravirt_patch_ident_64(insnbuf, len);
18376 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18377 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18378 + ret = paravirt_patch_ident_64(insnbuf, len);
18379 +#endif
18380
18381 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18382 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18383 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18384 if (insn_len > len || start == NULL)
18385 insn_len = len;
18386 else
18387 - memcpy(insnbuf, start, insn_len);
18388 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18389
18390 return insn_len;
18391 }
18392 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18393 preempt_enable();
18394 }
18395
18396 -struct pv_info pv_info = {
18397 +struct pv_info pv_info __read_only = {
18398 .name = "bare hardware",
18399 .paravirt_enabled = 0,
18400 .kernel_rpl = 0,
18401 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18402 #endif
18403 };
18404
18405 -struct pv_init_ops pv_init_ops = {
18406 +struct pv_init_ops pv_init_ops __read_only = {
18407 .patch = native_patch,
18408 };
18409
18410 -struct pv_time_ops pv_time_ops = {
18411 +struct pv_time_ops pv_time_ops __read_only = {
18412 .sched_clock = native_sched_clock,
18413 .steal_clock = native_steal_clock,
18414 };
18415
18416 -struct pv_irq_ops pv_irq_ops = {
18417 +struct pv_irq_ops pv_irq_ops __read_only = {
18418 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18419 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18420 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18421 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18422 #endif
18423 };
18424
18425 -struct pv_cpu_ops pv_cpu_ops = {
18426 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18427 .cpuid = native_cpuid,
18428 .get_debugreg = native_get_debugreg,
18429 .set_debugreg = native_set_debugreg,
18430 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18431 .end_context_switch = paravirt_nop,
18432 };
18433
18434 -struct pv_apic_ops pv_apic_ops = {
18435 +struct pv_apic_ops pv_apic_ops __read_only = {
18436 #ifdef CONFIG_X86_LOCAL_APIC
18437 .startup_ipi_hook = paravirt_nop,
18438 #endif
18439 };
18440
18441 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18442 +#ifdef CONFIG_X86_32
18443 +#ifdef CONFIG_X86_PAE
18444 +/* 64-bit pagetable entries */
18445 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18446 +#else
18447 /* 32-bit pagetable entries */
18448 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18449 +#endif
18450 #else
18451 /* 64-bit pagetable entries */
18452 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18453 #endif
18454
18455 -struct pv_mmu_ops pv_mmu_ops = {
18456 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18457
18458 .read_cr2 = native_read_cr2,
18459 .write_cr2 = native_write_cr2,
18460 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18461 .make_pud = PTE_IDENT,
18462
18463 .set_pgd = native_set_pgd,
18464 + .set_pgd_batched = native_set_pgd_batched,
18465 #endif
18466 #endif /* PAGETABLE_LEVELS >= 3 */
18467
18468 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18469 },
18470
18471 .set_fixmap = native_set_fixmap,
18472 +
18473 +#ifdef CONFIG_PAX_KERNEXEC
18474 + .pax_open_kernel = native_pax_open_kernel,
18475 + .pax_close_kernel = native_pax_close_kernel,
18476 +#endif
18477 +
18478 };
18479
18480 EXPORT_SYMBOL_GPL(pv_time_ops);
18481 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18482 index 35ccf75..7a15747 100644
18483 --- a/arch/x86/kernel/pci-iommu_table.c
18484 +++ b/arch/x86/kernel/pci-iommu_table.c
18485 @@ -2,7 +2,7 @@
18486 #include <asm/iommu_table.h>
18487 #include <linux/string.h>
18488 #include <linux/kallsyms.h>
18489 -
18490 +#include <linux/sched.h>
18491
18492 #define DEBUG 1
18493
18494 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18495 index ef6a845..8028ed3 100644
18496 --- a/arch/x86/kernel/process.c
18497 +++ b/arch/x86/kernel/process.c
18498 @@ -36,7 +36,8 @@
18499 * section. Since TSS's are completely CPU-local, we want them
18500 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18501 */
18502 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18503 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18504 +EXPORT_SYMBOL(init_tss);
18505
18506 #ifdef CONFIG_X86_64
18507 static DEFINE_PER_CPU(unsigned char, is_idle);
18508 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18509 task_xstate_cachep =
18510 kmem_cache_create("task_xstate", xstate_size,
18511 __alignof__(union thread_xstate),
18512 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18513 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18514 }
18515
18516 static inline void drop_fpu(struct task_struct *tsk)
18517 @@ -117,7 +118,7 @@ void exit_thread(void)
18518 unsigned long *bp = t->io_bitmap_ptr;
18519
18520 if (bp) {
18521 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18522 + struct tss_struct *tss = init_tss + get_cpu();
18523
18524 t->io_bitmap_ptr = NULL;
18525 clear_thread_flag(TIF_IO_BITMAP);
18526 @@ -148,7 +149,7 @@ void show_regs_common(void)
18527 board = dmi_get_system_info(DMI_BOARD_NAME);
18528
18529 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18530 - current->pid, current->comm, print_tainted(),
18531 + task_pid_nr(current), current->comm, print_tainted(),
18532 init_utsname()->release,
18533 (int)strcspn(init_utsname()->version, " "),
18534 init_utsname()->version,
18535 @@ -161,6 +162,9 @@ void flush_thread(void)
18536 {
18537 struct task_struct *tsk = current;
18538
18539 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18540 + loadsegment(gs, 0);
18541 +#endif
18542 flush_ptrace_hw_breakpoint(tsk);
18543 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18544 drop_fpu(tsk);
18545 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18546 regs.di = (unsigned long) arg;
18547
18548 #ifdef CONFIG_X86_32
18549 - regs.ds = __USER_DS;
18550 - regs.es = __USER_DS;
18551 + regs.ds = __KERNEL_DS;
18552 + regs.es = __KERNEL_DS;
18553 regs.fs = __KERNEL_PERCPU;
18554 - regs.gs = __KERNEL_STACK_CANARY;
18555 + savesegment(gs, regs.gs);
18556 #else
18557 regs.ss = __KERNEL_DS;
18558 #endif
18559 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18560 void exit_idle(void)
18561 {
18562 /* idle loop has pid 0 */
18563 - if (current->pid)
18564 + if (task_pid_nr(current))
18565 return;
18566 __exit_idle();
18567 }
18568 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18569
18570 return ret;
18571 }
18572 -void stop_this_cpu(void *dummy)
18573 +__noreturn void stop_this_cpu(void *dummy)
18574 {
18575 local_irq_disable();
18576 /*
18577 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18578 }
18579 early_param("idle", idle_setup);
18580
18581 -unsigned long arch_align_stack(unsigned long sp)
18582 +#ifdef CONFIG_PAX_RANDKSTACK
18583 +void pax_randomize_kstack(struct pt_regs *regs)
18584 {
18585 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18586 - sp -= get_random_int() % 8192;
18587 - return sp & ~0xf;
18588 -}
18589 + struct thread_struct *thread = &current->thread;
18590 + unsigned long time;
18591
18592 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18593 -{
18594 - unsigned long range_end = mm->brk + 0x02000000;
18595 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18596 -}
18597 + if (!randomize_va_space)
18598 + return;
18599 +
18600 + if (v8086_mode(regs))
18601 + return;
18602
18603 + rdtscl(time);
18604 +
18605 + /* P4 seems to return a 0 LSB, ignore it */
18606 +#ifdef CONFIG_MPENTIUM4
18607 + time &= 0x3EUL;
18608 + time <<= 2;
18609 +#elif defined(CONFIG_X86_64)
18610 + time &= 0xFUL;
18611 + time <<= 4;
18612 +#else
18613 + time &= 0x1FUL;
18614 + time <<= 3;
18615 +#endif
18616 +
18617 + thread->sp0 ^= time;
18618 + load_sp0(init_tss + smp_processor_id(), thread);
18619 +
18620 +#ifdef CONFIG_X86_64
18621 + this_cpu_write(kernel_stack, thread->sp0);
18622 +#endif
18623 +}
18624 +#endif
18625 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18626 index 516fa18..80bd9e6 100644
18627 --- a/arch/x86/kernel/process_32.c
18628 +++ b/arch/x86/kernel/process_32.c
18629 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18630 unsigned long thread_saved_pc(struct task_struct *tsk)
18631 {
18632 return ((unsigned long *)tsk->thread.sp)[3];
18633 +//XXX return tsk->thread.eip;
18634 }
18635
18636 void __show_regs(struct pt_regs *regs, int all)
18637 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18638 unsigned long sp;
18639 unsigned short ss, gs;
18640
18641 - if (user_mode_vm(regs)) {
18642 + if (user_mode(regs)) {
18643 sp = regs->sp;
18644 ss = regs->ss & 0xffff;
18645 - gs = get_user_gs(regs);
18646 } else {
18647 sp = kernel_stack_pointer(regs);
18648 savesegment(ss, ss);
18649 - savesegment(gs, gs);
18650 }
18651 + gs = get_user_gs(regs);
18652
18653 show_regs_common();
18654
18655 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18656 struct task_struct *tsk;
18657 int err;
18658
18659 - childregs = task_pt_regs(p);
18660 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18661 *childregs = *regs;
18662 childregs->ax = 0;
18663 childregs->sp = sp;
18664
18665 p->thread.sp = (unsigned long) childregs;
18666 p->thread.sp0 = (unsigned long) (childregs+1);
18667 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18668
18669 p->thread.ip = (unsigned long) ret_from_fork;
18670
18671 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18672 struct thread_struct *prev = &prev_p->thread,
18673 *next = &next_p->thread;
18674 int cpu = smp_processor_id();
18675 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18676 + struct tss_struct *tss = init_tss + cpu;
18677 fpu_switch_t fpu;
18678
18679 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18680 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18681 */
18682 lazy_save_gs(prev->gs);
18683
18684 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18685 + __set_fs(task_thread_info(next_p)->addr_limit);
18686 +#endif
18687 +
18688 /*
18689 * Load the per-thread Thread-Local Storage descriptor.
18690 */
18691 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18692 */
18693 arch_end_context_switch(next_p);
18694
18695 + this_cpu_write(current_task, next_p);
18696 + this_cpu_write(current_tinfo, &next_p->tinfo);
18697 +
18698 /*
18699 * Restore %gs if needed (which is common)
18700 */
18701 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18702
18703 switch_fpu_finish(next_p, fpu);
18704
18705 - this_cpu_write(current_task, next_p);
18706 -
18707 return prev_p;
18708 }
18709
18710 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18711 } while (count++ < 16);
18712 return 0;
18713 }
18714 -
18715 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18716 index 0a980c9..1d0e689 100644
18717 --- a/arch/x86/kernel/process_64.c
18718 +++ b/arch/x86/kernel/process_64.c
18719 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18720 struct pt_regs *childregs;
18721 struct task_struct *me = current;
18722
18723 - childregs = ((struct pt_regs *)
18724 - (THREAD_SIZE + task_stack_page(p))) - 1;
18725 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18726 *childregs = *regs;
18727
18728 childregs->ax = 0;
18729 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18730 p->thread.sp = (unsigned long) childregs;
18731 p->thread.sp0 = (unsigned long) (childregs+1);
18732 p->thread.usersp = me->thread.usersp;
18733 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18734
18735 set_tsk_thread_flag(p, TIF_FORK);
18736
18737 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18738 struct thread_struct *prev = &prev_p->thread;
18739 struct thread_struct *next = &next_p->thread;
18740 int cpu = smp_processor_id();
18741 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18742 + struct tss_struct *tss = init_tss + cpu;
18743 unsigned fsindex, gsindex;
18744 fpu_switch_t fpu;
18745
18746 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18747 prev->usersp = this_cpu_read(old_rsp);
18748 this_cpu_write(old_rsp, next->usersp);
18749 this_cpu_write(current_task, next_p);
18750 + this_cpu_write(current_tinfo, &next_p->tinfo);
18751
18752 - this_cpu_write(kernel_stack,
18753 - (unsigned long)task_stack_page(next_p) +
18754 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18755 + this_cpu_write(kernel_stack, next->sp0);
18756
18757 /*
18758 * Now maybe reload the debug registers and handle I/O bitmaps
18759 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18760 if (!p || p == current || p->state == TASK_RUNNING)
18761 return 0;
18762 stack = (unsigned long)task_stack_page(p);
18763 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18764 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18765 return 0;
18766 fp = *(u64 *)(p->thread.sp);
18767 do {
18768 - if (fp < (unsigned long)stack ||
18769 - fp >= (unsigned long)stack+THREAD_SIZE)
18770 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18771 return 0;
18772 ip = *(u64 *)(fp+8);
18773 if (!in_sched_functions(ip))
18774 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18775 index c4c6a5c..905f440 100644
18776 --- a/arch/x86/kernel/ptrace.c
18777 +++ b/arch/x86/kernel/ptrace.c
18778 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18779 unsigned long addr, unsigned long data)
18780 {
18781 int ret;
18782 - unsigned long __user *datap = (unsigned long __user *)data;
18783 + unsigned long __user *datap = (__force unsigned long __user *)data;
18784
18785 switch (request) {
18786 /* read the word at location addr in the USER area. */
18787 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18788 if ((int) addr < 0)
18789 return -EIO;
18790 ret = do_get_thread_area(child, addr,
18791 - (struct user_desc __user *)data);
18792 + (__force struct user_desc __user *) data);
18793 break;
18794
18795 case PTRACE_SET_THREAD_AREA:
18796 if ((int) addr < 0)
18797 return -EIO;
18798 ret = do_set_thread_area(child, addr,
18799 - (struct user_desc __user *)data, 0);
18800 + (__force struct user_desc __user *) data, 0);
18801 break;
18802 #endif
18803
18804 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18805 memset(info, 0, sizeof(*info));
18806 info->si_signo = SIGTRAP;
18807 info->si_code = si_code;
18808 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18809 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18810 }
18811
18812 void user_single_step_siginfo(struct task_struct *tsk,
18813 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18814 # define IS_IA32 0
18815 #endif
18816
18817 +#ifdef CONFIG_GRKERNSEC_SETXID
18818 +extern void gr_delayed_cred_worker(void);
18819 +#endif
18820 +
18821 /*
18822 * We must return the syscall number to actually look up in the table.
18823 * This can be -1L to skip running any syscall at all.
18824 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18825 {
18826 long ret = 0;
18827
18828 +#ifdef CONFIG_GRKERNSEC_SETXID
18829 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18830 + gr_delayed_cred_worker();
18831 +#endif
18832 +
18833 /*
18834 * If we stepped into a sysenter/syscall insn, it trapped in
18835 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18836 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18837 {
18838 bool step;
18839
18840 +#ifdef CONFIG_GRKERNSEC_SETXID
18841 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18842 + gr_delayed_cred_worker();
18843 +#endif
18844 +
18845 audit_syscall_exit(regs);
18846
18847 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18848 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18849 index 42eb330..139955c 100644
18850 --- a/arch/x86/kernel/pvclock.c
18851 +++ b/arch/x86/kernel/pvclock.c
18852 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18853 return pv_tsc_khz;
18854 }
18855
18856 -static atomic64_t last_value = ATOMIC64_INIT(0);
18857 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18858
18859 void pvclock_resume(void)
18860 {
18861 - atomic64_set(&last_value, 0);
18862 + atomic64_set_unchecked(&last_value, 0);
18863 }
18864
18865 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18866 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18867 * updating at the same time, and one of them could be slightly behind,
18868 * making the assumption that last_value always go forward fail to hold.
18869 */
18870 - last = atomic64_read(&last_value);
18871 + last = atomic64_read_unchecked(&last_value);
18872 do {
18873 if (ret < last)
18874 return last;
18875 - last = atomic64_cmpxchg(&last_value, last, ret);
18876 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18877 } while (unlikely(last != ret));
18878
18879 return ret;
18880 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18881 index 52190a9..8074389 100644
18882 --- a/arch/x86/kernel/reboot.c
18883 +++ b/arch/x86/kernel/reboot.c
18884 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18885 EXPORT_SYMBOL(pm_power_off);
18886
18887 static const struct desc_ptr no_idt = {};
18888 -static int reboot_mode;
18889 +static unsigned short reboot_mode;
18890 enum reboot_type reboot_type = BOOT_ACPI;
18891 int reboot_force;
18892
18893 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18894
18895 void __noreturn machine_real_restart(unsigned int type)
18896 {
18897 +
18898 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18899 + struct desc_struct *gdt;
18900 +#endif
18901 +
18902 local_irq_disable();
18903
18904 /*
18905 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18906
18907 /* Jump to the identity-mapped low memory code */
18908 #ifdef CONFIG_X86_32
18909 - asm volatile("jmpl *%0" : :
18910 +
18911 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18912 + gdt = get_cpu_gdt_table(smp_processor_id());
18913 + pax_open_kernel();
18914 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18915 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18916 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18917 + loadsegment(ds, __KERNEL_DS);
18918 + loadsegment(es, __KERNEL_DS);
18919 + loadsegment(ss, __KERNEL_DS);
18920 +#endif
18921 +#ifdef CONFIG_PAX_KERNEXEC
18922 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18923 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18924 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18925 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18926 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18927 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18928 +#endif
18929 + pax_close_kernel();
18930 +#endif
18931 +
18932 + asm volatile("ljmpl *%0" : :
18933 "rm" (real_mode_header->machine_real_restart_asm),
18934 "a" (type));
18935 #else
18936 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18937 * try to force a triple fault and then cycle between hitting the keyboard
18938 * controller and doing that
18939 */
18940 -static void native_machine_emergency_restart(void)
18941 +static void __noreturn native_machine_emergency_restart(void)
18942 {
18943 int i;
18944 int attempt = 0;
18945 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18946 #endif
18947 }
18948
18949 -static void __machine_emergency_restart(int emergency)
18950 +static void __noreturn __machine_emergency_restart(int emergency)
18951 {
18952 reboot_emergency = emergency;
18953 machine_ops.emergency_restart();
18954 }
18955
18956 -static void native_machine_restart(char *__unused)
18957 +static void __noreturn native_machine_restart(char *__unused)
18958 {
18959 pr_notice("machine restart\n");
18960
18961 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18962 __machine_emergency_restart(0);
18963 }
18964
18965 -static void native_machine_halt(void)
18966 +static void __noreturn native_machine_halt(void)
18967 {
18968 /* Stop other cpus and apics */
18969 machine_shutdown();
18970 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
18971 stop_this_cpu(NULL);
18972 }
18973
18974 -static void native_machine_power_off(void)
18975 +static void __noreturn native_machine_power_off(void)
18976 {
18977 if (pm_power_off) {
18978 if (!reboot_force)
18979 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18980 }
18981 /* A fallback in case there is no PM info available */
18982 tboot_shutdown(TB_SHUTDOWN_HALT);
18983 + unreachable();
18984 }
18985
18986 struct machine_ops machine_ops = {
18987 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18988 index 7a6f3b3..bed145d7 100644
18989 --- a/arch/x86/kernel/relocate_kernel_64.S
18990 +++ b/arch/x86/kernel/relocate_kernel_64.S
18991 @@ -11,6 +11,7 @@
18992 #include <asm/kexec.h>
18993 #include <asm/processor-flags.h>
18994 #include <asm/pgtable_types.h>
18995 +#include <asm/alternative-asm.h>
18996
18997 /*
18998 * Must be relocatable PIC code callable as a C function
18999 @@ -160,13 +161,14 @@ identity_mapped:
19000 xorq %rbp, %rbp
19001 xorq %r8, %r8
19002 xorq %r9, %r9
19003 - xorq %r10, %r9
19004 + xorq %r10, %r10
19005 xorq %r11, %r11
19006 xorq %r12, %r12
19007 xorq %r13, %r13
19008 xorq %r14, %r14
19009 xorq %r15, %r15
19010
19011 + pax_force_retaddr 0, 1
19012 ret
19013
19014 1:
19015 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19016 index 5cee802..bc22bc3 100644
19017 --- a/arch/x86/kernel/setup.c
19018 +++ b/arch/x86/kernel/setup.c
19019 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19020
19021 switch (data->type) {
19022 case SETUP_E820_EXT:
19023 - parse_e820_ext(data);
19024 + parse_e820_ext((struct setup_data __force_kernel *)data);
19025 break;
19026 case SETUP_DTB:
19027 add_dtb(pa_data);
19028 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19029 * area (640->1Mb) as ram even though it is not.
19030 * take them out.
19031 */
19032 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19033 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19034 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19035 }
19036
19037 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19038
19039 if (!boot_params.hdr.root_flags)
19040 root_mountflags &= ~MS_RDONLY;
19041 - init_mm.start_code = (unsigned long) _text;
19042 - init_mm.end_code = (unsigned long) _etext;
19043 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19044 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19045 init_mm.end_data = (unsigned long) _edata;
19046 init_mm.brk = _brk_end;
19047
19048 - code_resource.start = virt_to_phys(_text);
19049 - code_resource.end = virt_to_phys(_etext)-1;
19050 - data_resource.start = virt_to_phys(_etext);
19051 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19052 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19053 + data_resource.start = virt_to_phys(_sdata);
19054 data_resource.end = virt_to_phys(_edata)-1;
19055 bss_resource.start = virt_to_phys(&__bss_start);
19056 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19057 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19058 index 5cdff03..5810740 100644
19059 --- a/arch/x86/kernel/setup_percpu.c
19060 +++ b/arch/x86/kernel/setup_percpu.c
19061 @@ -21,19 +21,17 @@
19062 #include <asm/cpu.h>
19063 #include <asm/stackprotector.h>
19064
19065 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19066 +#ifdef CONFIG_SMP
19067 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19068 EXPORT_PER_CPU_SYMBOL(cpu_number);
19069 +#endif
19070
19071 -#ifdef CONFIG_X86_64
19072 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19073 -#else
19074 -#define BOOT_PERCPU_OFFSET 0
19075 -#endif
19076
19077 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19078 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19079
19080 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19081 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19082 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19083 };
19084 EXPORT_SYMBOL(__per_cpu_offset);
19085 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19086 {
19087 #ifdef CONFIG_X86_32
19088 struct desc_struct gdt;
19089 + unsigned long base = per_cpu_offset(cpu);
19090
19091 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19092 - 0x2 | DESCTYPE_S, 0x8);
19093 - gdt.s = 1;
19094 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19095 + 0x83 | DESCTYPE_S, 0xC);
19096 write_gdt_entry(get_cpu_gdt_table(cpu),
19097 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19098 #endif
19099 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19100 /* alrighty, percpu areas up and running */
19101 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19102 for_each_possible_cpu(cpu) {
19103 +#ifdef CONFIG_CC_STACKPROTECTOR
19104 +#ifdef CONFIG_X86_32
19105 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19106 +#endif
19107 +#endif
19108 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19109 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19110 per_cpu(cpu_number, cpu) = cpu;
19111 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19112 */
19113 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19114 #endif
19115 +#ifdef CONFIG_CC_STACKPROTECTOR
19116 +#ifdef CONFIG_X86_32
19117 + if (!cpu)
19118 + per_cpu(stack_canary.canary, cpu) = canary;
19119 +#endif
19120 +#endif
19121 /*
19122 * Up to this point, the boot CPU has been using .init.data
19123 * area. Reload any changed state for the boot CPU.
19124 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19125 index b280908..6de349e 100644
19126 --- a/arch/x86/kernel/signal.c
19127 +++ b/arch/x86/kernel/signal.c
19128 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19129 * Align the stack pointer according to the i386 ABI,
19130 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19131 */
19132 - sp = ((sp + 4) & -16ul) - 4;
19133 + sp = ((sp - 12) & -16ul) - 4;
19134 #else /* !CONFIG_X86_32 */
19135 sp = round_down(sp, 16) - 8;
19136 #endif
19137 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19138 * Return an always-bogus address instead so we will die with SIGSEGV.
19139 */
19140 if (onsigstack && !likely(on_sig_stack(sp)))
19141 - return (void __user *)-1L;
19142 + return (__force void __user *)-1L;
19143
19144 /* save i387 state */
19145 if (used_math() && save_i387_xstate(*fpstate) < 0)
19146 - return (void __user *)-1L;
19147 + return (__force void __user *)-1L;
19148
19149 return (void __user *)sp;
19150 }
19151 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19152 }
19153
19154 if (current->mm->context.vdso)
19155 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19156 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19157 else
19158 - restorer = &frame->retcode;
19159 + restorer = (void __user *)&frame->retcode;
19160 if (ka->sa.sa_flags & SA_RESTORER)
19161 restorer = ka->sa.sa_restorer;
19162
19163 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19164 * reasons and because gdb uses it as a signature to notice
19165 * signal handler stack frames.
19166 */
19167 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19168 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19169
19170 if (err)
19171 return -EFAULT;
19172 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19173 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19174
19175 /* Set up to return from userspace. */
19176 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19177 + if (current->mm->context.vdso)
19178 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19179 + else
19180 + restorer = (void __user *)&frame->retcode;
19181 if (ka->sa.sa_flags & SA_RESTORER)
19182 restorer = ka->sa.sa_restorer;
19183 put_user_ex(restorer, &frame->pretcode);
19184 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19185 * reasons and because gdb uses it as a signature to notice
19186 * signal handler stack frames.
19187 */
19188 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19189 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19190 } put_user_catch(err);
19191
19192 if (err)
19193 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19194 index 7c5a8c3..88d422f 100644
19195 --- a/arch/x86/kernel/smpboot.c
19196 +++ b/arch/x86/kernel/smpboot.c
19197 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19198 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19199 (THREAD_SIZE + task_stack_page(idle))) - 1);
19200 per_cpu(current_task, cpu) = idle;
19201 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19202
19203 #ifdef CONFIG_X86_32
19204 /* Stack for startup_32 can be just as for start_secondary onwards */
19205 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19206 #else
19207 clear_tsk_thread_flag(idle, TIF_FORK);
19208 initial_gs = per_cpu_offset(cpu);
19209 - per_cpu(kernel_stack, cpu) =
19210 - (unsigned long)task_stack_page(idle) -
19211 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19212 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19213 #endif
19214 +
19215 + pax_open_kernel();
19216 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19217 + pax_close_kernel();
19218 +
19219 initial_code = (unsigned long)start_secondary;
19220 stack_start = idle->thread.sp;
19221
19222 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19223
19224 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19225
19226 +#ifdef CONFIG_PAX_PER_CPU_PGD
19227 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19228 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19229 + KERNEL_PGD_PTRS);
19230 +#endif
19231 +
19232 err = do_boot_cpu(apicid, cpu, tidle);
19233 if (err) {
19234 pr_debug("do_boot_cpu failed %d\n", err);
19235 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19236 index c346d11..d43b163 100644
19237 --- a/arch/x86/kernel/step.c
19238 +++ b/arch/x86/kernel/step.c
19239 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19240 struct desc_struct *desc;
19241 unsigned long base;
19242
19243 - seg &= ~7UL;
19244 + seg >>= 3;
19245
19246 mutex_lock(&child->mm->context.lock);
19247 - if (unlikely((seg >> 3) >= child->mm->context.size))
19248 + if (unlikely(seg >= child->mm->context.size))
19249 addr = -1L; /* bogus selector, access would fault */
19250 else {
19251 desc = child->mm->context.ldt + seg;
19252 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19253 addr += base;
19254 }
19255 mutex_unlock(&child->mm->context.lock);
19256 - }
19257 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19258 + addr = ktla_ktva(addr);
19259
19260 return addr;
19261 }
19262 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19263 unsigned char opcode[15];
19264 unsigned long addr = convert_ip_to_linear(child, regs);
19265
19266 + if (addr == -EINVAL)
19267 + return 0;
19268 +
19269 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19270 for (i = 0; i < copied; i++) {
19271 switch (opcode[i]) {
19272 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19273 index 0b0cb5f..db6b9ed 100644
19274 --- a/arch/x86/kernel/sys_i386_32.c
19275 +++ b/arch/x86/kernel/sys_i386_32.c
19276 @@ -24,17 +24,224 @@
19277
19278 #include <asm/syscalls.h>
19279
19280 -/*
19281 - * Do a system call from kernel instead of calling sys_execve so we
19282 - * end up with proper pt_regs.
19283 - */
19284 -int kernel_execve(const char *filename,
19285 - const char *const argv[],
19286 - const char *const envp[])
19287 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19288 {
19289 - long __res;
19290 - asm volatile ("int $0x80"
19291 - : "=a" (__res)
19292 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19293 - return __res;
19294 + unsigned long pax_task_size = TASK_SIZE;
19295 +
19296 +#ifdef CONFIG_PAX_SEGMEXEC
19297 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19298 + pax_task_size = SEGMEXEC_TASK_SIZE;
19299 +#endif
19300 +
19301 + if (len > pax_task_size || addr > pax_task_size - len)
19302 + return -EINVAL;
19303 +
19304 + return 0;
19305 +}
19306 +
19307 +unsigned long
19308 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19309 + unsigned long len, unsigned long pgoff, unsigned long flags)
19310 +{
19311 + struct mm_struct *mm = current->mm;
19312 + struct vm_area_struct *vma;
19313 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19314 +
19315 +#ifdef CONFIG_PAX_SEGMEXEC
19316 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19317 + pax_task_size = SEGMEXEC_TASK_SIZE;
19318 +#endif
19319 +
19320 + pax_task_size -= PAGE_SIZE;
19321 +
19322 + if (len > pax_task_size)
19323 + return -ENOMEM;
19324 +
19325 + if (flags & MAP_FIXED)
19326 + return addr;
19327 +
19328 +#ifdef CONFIG_PAX_RANDMMAP
19329 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19330 +#endif
19331 +
19332 + if (addr) {
19333 + addr = PAGE_ALIGN(addr);
19334 + if (pax_task_size - len >= addr) {
19335 + vma = find_vma(mm, addr);
19336 + if (check_heap_stack_gap(vma, addr, len))
19337 + return addr;
19338 + }
19339 + }
19340 + if (len > mm->cached_hole_size) {
19341 + start_addr = addr = mm->free_area_cache;
19342 + } else {
19343 + start_addr = addr = mm->mmap_base;
19344 + mm->cached_hole_size = 0;
19345 + }
19346 +
19347 +#ifdef CONFIG_PAX_PAGEEXEC
19348 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19349 + start_addr = 0x00110000UL;
19350 +
19351 +#ifdef CONFIG_PAX_RANDMMAP
19352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19353 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19354 +#endif
19355 +
19356 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19357 + start_addr = addr = mm->mmap_base;
19358 + else
19359 + addr = start_addr;
19360 + }
19361 +#endif
19362 +
19363 +full_search:
19364 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19365 + /* At this point: (!vma || addr < vma->vm_end). */
19366 + if (pax_task_size - len < addr) {
19367 + /*
19368 + * Start a new search - just in case we missed
19369 + * some holes.
19370 + */
19371 + if (start_addr != mm->mmap_base) {
19372 + start_addr = addr = mm->mmap_base;
19373 + mm->cached_hole_size = 0;
19374 + goto full_search;
19375 + }
19376 + return -ENOMEM;
19377 + }
19378 + if (check_heap_stack_gap(vma, addr, len))
19379 + break;
19380 + if (addr + mm->cached_hole_size < vma->vm_start)
19381 + mm->cached_hole_size = vma->vm_start - addr;
19382 + addr = vma->vm_end;
19383 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19384 + start_addr = addr = mm->mmap_base;
19385 + mm->cached_hole_size = 0;
19386 + goto full_search;
19387 + }
19388 + }
19389 +
19390 + /*
19391 + * Remember the place where we stopped the search:
19392 + */
19393 + mm->free_area_cache = addr + len;
19394 + return addr;
19395 +}
19396 +
19397 +unsigned long
19398 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19399 + const unsigned long len, const unsigned long pgoff,
19400 + const unsigned long flags)
19401 +{
19402 + struct vm_area_struct *vma;
19403 + struct mm_struct *mm = current->mm;
19404 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19405 +
19406 +#ifdef CONFIG_PAX_SEGMEXEC
19407 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19408 + pax_task_size = SEGMEXEC_TASK_SIZE;
19409 +#endif
19410 +
19411 + pax_task_size -= PAGE_SIZE;
19412 +
19413 + /* requested length too big for entire address space */
19414 + if (len > pax_task_size)
19415 + return -ENOMEM;
19416 +
19417 + if (flags & MAP_FIXED)
19418 + return addr;
19419 +
19420 +#ifdef CONFIG_PAX_PAGEEXEC
19421 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19422 + goto bottomup;
19423 +#endif
19424 +
19425 +#ifdef CONFIG_PAX_RANDMMAP
19426 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19427 +#endif
19428 +
19429 + /* requesting a specific address */
19430 + if (addr) {
19431 + addr = PAGE_ALIGN(addr);
19432 + if (pax_task_size - len >= addr) {
19433 + vma = find_vma(mm, addr);
19434 + if (check_heap_stack_gap(vma, addr, len))
19435 + return addr;
19436 + }
19437 + }
19438 +
19439 + /* check if free_area_cache is useful for us */
19440 + if (len <= mm->cached_hole_size) {
19441 + mm->cached_hole_size = 0;
19442 + mm->free_area_cache = mm->mmap_base;
19443 + }
19444 +
19445 + /* either no address requested or can't fit in requested address hole */
19446 + addr = mm->free_area_cache;
19447 +
19448 + /* make sure it can fit in the remaining address space */
19449 + if (addr > len) {
19450 + vma = find_vma(mm, addr-len);
19451 + if (check_heap_stack_gap(vma, addr - len, len))
19452 + /* remember the address as a hint for next time */
19453 + return (mm->free_area_cache = addr-len);
19454 + }
19455 +
19456 + if (mm->mmap_base < len)
19457 + goto bottomup;
19458 +
19459 + addr = mm->mmap_base-len;
19460 +
19461 + do {
19462 + /*
19463 + * Lookup failure means no vma is above this address,
19464 + * else if new region fits below vma->vm_start,
19465 + * return with success:
19466 + */
19467 + vma = find_vma(mm, addr);
19468 + if (check_heap_stack_gap(vma, addr, len))
19469 + /* remember the address as a hint for next time */
19470 + return (mm->free_area_cache = addr);
19471 +
19472 + /* remember the largest hole we saw so far */
19473 + if (addr + mm->cached_hole_size < vma->vm_start)
19474 + mm->cached_hole_size = vma->vm_start - addr;
19475 +
19476 + /* try just below the current vma->vm_start */
19477 + addr = skip_heap_stack_gap(vma, len);
19478 + } while (!IS_ERR_VALUE(addr));
19479 +
19480 +bottomup:
19481 + /*
19482 + * A failed mmap() very likely causes application failure,
19483 + * so fall back to the bottom-up function here. This scenario
19484 + * can happen with large stack limits and large mmap()
19485 + * allocations.
19486 + */
19487 +
19488 +#ifdef CONFIG_PAX_SEGMEXEC
19489 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19490 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19491 + else
19492 +#endif
19493 +
19494 + mm->mmap_base = TASK_UNMAPPED_BASE;
19495 +
19496 +#ifdef CONFIG_PAX_RANDMMAP
19497 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19498 + mm->mmap_base += mm->delta_mmap;
19499 +#endif
19500 +
19501 + mm->free_area_cache = mm->mmap_base;
19502 + mm->cached_hole_size = ~0UL;
19503 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19504 + /*
19505 + * Restore the topdown base:
19506 + */
19507 + mm->mmap_base = base;
19508 + mm->free_area_cache = base;
19509 + mm->cached_hole_size = ~0UL;
19510 +
19511 + return addr;
19512 }
19513 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19514 index b4d3c39..82bb73b 100644
19515 --- a/arch/x86/kernel/sys_x86_64.c
19516 +++ b/arch/x86/kernel/sys_x86_64.c
19517 @@ -95,8 +95,8 @@ out:
19518 return error;
19519 }
19520
19521 -static void find_start_end(unsigned long flags, unsigned long *begin,
19522 - unsigned long *end)
19523 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19524 + unsigned long *begin, unsigned long *end)
19525 {
19526 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19527 unsigned long new_begin;
19528 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19529 *begin = new_begin;
19530 }
19531 } else {
19532 - *begin = TASK_UNMAPPED_BASE;
19533 + *begin = mm->mmap_base;
19534 *end = TASK_SIZE;
19535 }
19536 }
19537 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19538 if (flags & MAP_FIXED)
19539 return addr;
19540
19541 - find_start_end(flags, &begin, &end);
19542 + find_start_end(mm, flags, &begin, &end);
19543
19544 if (len > end)
19545 return -ENOMEM;
19546
19547 +#ifdef CONFIG_PAX_RANDMMAP
19548 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19549 +#endif
19550 +
19551 if (addr) {
19552 addr = PAGE_ALIGN(addr);
19553 vma = find_vma(mm, addr);
19554 - if (end - len >= addr &&
19555 - (!vma || addr + len <= vma->vm_start))
19556 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19557 return addr;
19558 }
19559 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19560 @@ -172,7 +175,7 @@ full_search:
19561 }
19562 return -ENOMEM;
19563 }
19564 - if (!vma || addr + len <= vma->vm_start) {
19565 + if (check_heap_stack_gap(vma, addr, len)) {
19566 /*
19567 * Remember the place where we stopped the search:
19568 */
19569 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19570 {
19571 struct vm_area_struct *vma;
19572 struct mm_struct *mm = current->mm;
19573 - unsigned long addr = addr0, start_addr;
19574 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19575
19576 /* requested length too big for entire address space */
19577 if (len > TASK_SIZE)
19578 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19579 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19580 goto bottomup;
19581
19582 +#ifdef CONFIG_PAX_RANDMMAP
19583 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19584 +#endif
19585 +
19586 /* requesting a specific address */
19587 if (addr) {
19588 addr = PAGE_ALIGN(addr);
19589 - vma = find_vma(mm, addr);
19590 - if (TASK_SIZE - len >= addr &&
19591 - (!vma || addr + len <= vma->vm_start))
19592 - return addr;
19593 + if (TASK_SIZE - len >= addr) {
19594 + vma = find_vma(mm, addr);
19595 + if (check_heap_stack_gap(vma, addr, len))
19596 + return addr;
19597 + }
19598 }
19599
19600 /* check if free_area_cache is useful for us */
19601 @@ -240,7 +248,7 @@ try_again:
19602 * return with success:
19603 */
19604 vma = find_vma(mm, addr);
19605 - if (!vma || addr+len <= vma->vm_start)
19606 + if (check_heap_stack_gap(vma, addr, len))
19607 /* remember the address as a hint for next time */
19608 return mm->free_area_cache = addr;
19609
19610 @@ -249,8 +257,8 @@ try_again:
19611 mm->cached_hole_size = vma->vm_start - addr;
19612
19613 /* try just below the current vma->vm_start */
19614 - addr = vma->vm_start-len;
19615 - } while (len < vma->vm_start);
19616 + addr = skip_heap_stack_gap(vma, len);
19617 + } while (!IS_ERR_VALUE(addr));
19618
19619 fail:
19620 /*
19621 @@ -270,13 +278,21 @@ bottomup:
19622 * can happen with large stack limits and large mmap()
19623 * allocations.
19624 */
19625 + mm->mmap_base = TASK_UNMAPPED_BASE;
19626 +
19627 +#ifdef CONFIG_PAX_RANDMMAP
19628 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19629 + mm->mmap_base += mm->delta_mmap;
19630 +#endif
19631 +
19632 + mm->free_area_cache = mm->mmap_base;
19633 mm->cached_hole_size = ~0UL;
19634 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19635 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19636 /*
19637 * Restore the topdown base:
19638 */
19639 - mm->free_area_cache = mm->mmap_base;
19640 + mm->mmap_base = base;
19641 + mm->free_area_cache = base;
19642 mm->cached_hole_size = ~0UL;
19643
19644 return addr;
19645 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19646 index f84fe00..93fe08f 100644
19647 --- a/arch/x86/kernel/tboot.c
19648 +++ b/arch/x86/kernel/tboot.c
19649 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19650
19651 void tboot_shutdown(u32 shutdown_type)
19652 {
19653 - void (*shutdown)(void);
19654 + void (* __noreturn shutdown)(void);
19655
19656 if (!tboot_enabled())
19657 return;
19658 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19659
19660 switch_to_tboot_pt();
19661
19662 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19663 + shutdown = (void *)tboot->shutdown_entry;
19664 shutdown();
19665
19666 /* should not reach here */
19667 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19668 return 0;
19669 }
19670
19671 -static atomic_t ap_wfs_count;
19672 +static atomic_unchecked_t ap_wfs_count;
19673
19674 static int tboot_wait_for_aps(int num_aps)
19675 {
19676 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19677 {
19678 switch (action) {
19679 case CPU_DYING:
19680 - atomic_inc(&ap_wfs_count);
19681 + atomic_inc_unchecked(&ap_wfs_count);
19682 if (num_online_cpus() == 1)
19683 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19684 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19685 return NOTIFY_BAD;
19686 break;
19687 }
19688 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19689
19690 tboot_create_trampoline();
19691
19692 - atomic_set(&ap_wfs_count, 0);
19693 + atomic_set_unchecked(&ap_wfs_count, 0);
19694 register_hotcpu_notifier(&tboot_cpu_notifier);
19695
19696 acpi_os_set_prepare_sleep(&tboot_sleep);
19697 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19698 index 24d3c91..d06b473 100644
19699 --- a/arch/x86/kernel/time.c
19700 +++ b/arch/x86/kernel/time.c
19701 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19702 {
19703 unsigned long pc = instruction_pointer(regs);
19704
19705 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19706 + if (!user_mode(regs) && in_lock_functions(pc)) {
19707 #ifdef CONFIG_FRAME_POINTER
19708 - return *(unsigned long *)(regs->bp + sizeof(long));
19709 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19710 #else
19711 unsigned long *sp =
19712 (unsigned long *)kernel_stack_pointer(regs);
19713 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19714 * or above a saved flags. Eflags has bits 22-31 zero,
19715 * kernel addresses don't.
19716 */
19717 +
19718 +#ifdef CONFIG_PAX_KERNEXEC
19719 + return ktla_ktva(sp[0]);
19720 +#else
19721 if (sp[0] >> 22)
19722 return sp[0];
19723 if (sp[1] >> 22)
19724 return sp[1];
19725 #endif
19726 +
19727 +#endif
19728 }
19729 return pc;
19730 }
19731 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19732 index 9d9d2f9..cad418a 100644
19733 --- a/arch/x86/kernel/tls.c
19734 +++ b/arch/x86/kernel/tls.c
19735 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19736 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19737 return -EINVAL;
19738
19739 +#ifdef CONFIG_PAX_SEGMEXEC
19740 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19741 + return -EINVAL;
19742 +#endif
19743 +
19744 set_tls_desc(p, idx, &info, 1);
19745
19746 return 0;
19747 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19748
19749 if (kbuf)
19750 info = kbuf;
19751 - else if (__copy_from_user(infobuf, ubuf, count))
19752 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19753 return -EFAULT;
19754 else
19755 info = infobuf;
19756 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19757 index b481341..5918bbe 100644
19758 --- a/arch/x86/kernel/traps.c
19759 +++ b/arch/x86/kernel/traps.c
19760 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19761
19762 /* Do we ignore FPU interrupts ? */
19763 char ignore_fpu_irq;
19764 -
19765 -/*
19766 - * The IDT has to be page-aligned to simplify the Pentium
19767 - * F0 0F bug workaround.
19768 - */
19769 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19770 #endif
19771
19772 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19773 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19774 }
19775
19776 static void __kprobes
19777 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19778 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19779 long error_code, siginfo_t *info)
19780 {
19781 struct task_struct *tsk = current;
19782
19783 #ifdef CONFIG_X86_32
19784 - if (regs->flags & X86_VM_MASK) {
19785 + if (v8086_mode(regs)) {
19786 /*
19787 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19788 * On nmi (interrupt 2), do_trap should not be called.
19789 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19790 }
19791 #endif
19792
19793 - if (!user_mode(regs))
19794 + if (!user_mode_novm(regs))
19795 goto kernel_trap;
19796
19797 #ifdef CONFIG_X86_32
19798 @@ -147,7 +141,7 @@ trap_signal:
19799 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19800 printk_ratelimit()) {
19801 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19802 - tsk->comm, tsk->pid, str,
19803 + tsk->comm, task_pid_nr(tsk), str,
19804 regs->ip, regs->sp, error_code);
19805 print_vma_addr(" in ", regs->ip);
19806 pr_cont("\n");
19807 @@ -164,8 +158,20 @@ kernel_trap:
19808 if (!fixup_exception(regs)) {
19809 tsk->thread.error_code = error_code;
19810 tsk->thread.trap_nr = trapnr;
19811 +
19812 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19813 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19814 + str = "PAX: suspicious stack segment fault";
19815 +#endif
19816 +
19817 die(str, regs, error_code);
19818 }
19819 +
19820 +#ifdef CONFIG_PAX_REFCOUNT
19821 + if (trapnr == 4)
19822 + pax_report_refcount_overflow(regs);
19823 +#endif
19824 +
19825 return;
19826
19827 #ifdef CONFIG_X86_32
19828 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19829 conditional_sti(regs);
19830
19831 #ifdef CONFIG_X86_32
19832 - if (regs->flags & X86_VM_MASK)
19833 + if (v8086_mode(regs))
19834 goto gp_in_vm86;
19835 #endif
19836
19837 tsk = current;
19838 - if (!user_mode(regs))
19839 + if (!user_mode_novm(regs))
19840 goto gp_in_kernel;
19841
19842 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19843 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19844 + struct mm_struct *mm = tsk->mm;
19845 + unsigned long limit;
19846 +
19847 + down_write(&mm->mmap_sem);
19848 + limit = mm->context.user_cs_limit;
19849 + if (limit < TASK_SIZE) {
19850 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19851 + up_write(&mm->mmap_sem);
19852 + return;
19853 + }
19854 + up_write(&mm->mmap_sem);
19855 + }
19856 +#endif
19857 +
19858 tsk->thread.error_code = error_code;
19859 tsk->thread.trap_nr = X86_TRAP_GP;
19860
19861 @@ -297,6 +319,13 @@ gp_in_kernel:
19862 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19863 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19864 return;
19865 +
19866 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19867 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19868 + die("PAX: suspicious general protection fault", regs, error_code);
19869 + else
19870 +#endif
19871 +
19872 die("general protection fault", regs, error_code);
19873 }
19874
19875 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19876 /* It's safe to allow irq's after DR6 has been saved */
19877 preempt_conditional_sti(regs);
19878
19879 - if (regs->flags & X86_VM_MASK) {
19880 + if (v8086_mode(regs)) {
19881 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19882 X86_TRAP_DB);
19883 preempt_conditional_cli(regs);
19884 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19885 * We already checked v86 mode above, so we can check for kernel mode
19886 * by just checking the CPL of CS.
19887 */
19888 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19889 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19890 tsk->thread.debugreg6 &= ~DR_STEP;
19891 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19892 regs->flags &= ~X86_EFLAGS_TF;
19893 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19894 return;
19895 conditional_sti(regs);
19896
19897 - if (!user_mode_vm(regs))
19898 + if (!user_mode(regs))
19899 {
19900 if (!fixup_exception(regs)) {
19901 task->thread.error_code = error_code;
19902 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19903 index 36fd420..7e5892d 100644
19904 --- a/arch/x86/kernel/uprobes.c
19905 +++ b/arch/x86/kernel/uprobes.c
19906 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19907 int ret = NOTIFY_DONE;
19908
19909 /* We are only interested in userspace traps */
19910 - if (regs && !user_mode_vm(regs))
19911 + if (regs && !user_mode(regs))
19912 return NOTIFY_DONE;
19913
19914 switch (val) {
19915 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19916 index b9242ba..50c5edd 100644
19917 --- a/arch/x86/kernel/verify_cpu.S
19918 +++ b/arch/x86/kernel/verify_cpu.S
19919 @@ -20,6 +20,7 @@
19920 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19921 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19922 * arch/x86/kernel/head_32.S: processor startup
19923 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19924 *
19925 * verify_cpu, returns the status of longmode and SSE in register %eax.
19926 * 0: Success 1: Failure
19927 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19928 index 54abcc0..eb6c848 100644
19929 --- a/arch/x86/kernel/vm86_32.c
19930 +++ b/arch/x86/kernel/vm86_32.c
19931 @@ -43,6 +43,7 @@
19932 #include <linux/ptrace.h>
19933 #include <linux/audit.h>
19934 #include <linux/stddef.h>
19935 +#include <linux/grsecurity.h>
19936
19937 #include <asm/uaccess.h>
19938 #include <asm/io.h>
19939 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19940 do_exit(SIGSEGV);
19941 }
19942
19943 - tss = &per_cpu(init_tss, get_cpu());
19944 + tss = init_tss + get_cpu();
19945 current->thread.sp0 = current->thread.saved_sp0;
19946 current->thread.sysenter_cs = __KERNEL_CS;
19947 load_sp0(tss, &current->thread);
19948 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19949 struct task_struct *tsk;
19950 int tmp, ret = -EPERM;
19951
19952 +#ifdef CONFIG_GRKERNSEC_VM86
19953 + if (!capable(CAP_SYS_RAWIO)) {
19954 + gr_handle_vm86();
19955 + goto out;
19956 + }
19957 +#endif
19958 +
19959 tsk = current;
19960 if (tsk->thread.saved_sp0)
19961 goto out;
19962 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19963 int tmp, ret;
19964 struct vm86plus_struct __user *v86;
19965
19966 +#ifdef CONFIG_GRKERNSEC_VM86
19967 + if (!capable(CAP_SYS_RAWIO)) {
19968 + gr_handle_vm86();
19969 + ret = -EPERM;
19970 + goto out;
19971 + }
19972 +#endif
19973 +
19974 tsk = current;
19975 switch (cmd) {
19976 case VM86_REQUEST_IRQ:
19977 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19978 tsk->thread.saved_fs = info->regs32->fs;
19979 tsk->thread.saved_gs = get_user_gs(info->regs32);
19980
19981 - tss = &per_cpu(init_tss, get_cpu());
19982 + tss = init_tss + get_cpu();
19983 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19984 if (cpu_has_sep)
19985 tsk->thread.sysenter_cs = 0;
19986 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19987 goto cannot_handle;
19988 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19989 goto cannot_handle;
19990 - intr_ptr = (unsigned long __user *) (i << 2);
19991 + intr_ptr = (__force unsigned long __user *) (i << 2);
19992 if (get_user(segoffs, intr_ptr))
19993 goto cannot_handle;
19994 if ((segoffs >> 16) == BIOSSEG)
19995 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19996 index 22a1530..8fbaaad 100644
19997 --- a/arch/x86/kernel/vmlinux.lds.S
19998 +++ b/arch/x86/kernel/vmlinux.lds.S
19999 @@ -26,6 +26,13 @@
20000 #include <asm/page_types.h>
20001 #include <asm/cache.h>
20002 #include <asm/boot.h>
20003 +#include <asm/segment.h>
20004 +
20005 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20006 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20007 +#else
20008 +#define __KERNEL_TEXT_OFFSET 0
20009 +#endif
20010
20011 #undef i386 /* in case the preprocessor is a 32bit one */
20012
20013 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20014
20015 PHDRS {
20016 text PT_LOAD FLAGS(5); /* R_E */
20017 +#ifdef CONFIG_X86_32
20018 + module PT_LOAD FLAGS(5); /* R_E */
20019 +#endif
20020 +#ifdef CONFIG_XEN
20021 + rodata PT_LOAD FLAGS(5); /* R_E */
20022 +#else
20023 + rodata PT_LOAD FLAGS(4); /* R__ */
20024 +#endif
20025 data PT_LOAD FLAGS(6); /* RW_ */
20026 -#ifdef CONFIG_X86_64
20027 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20028 #ifdef CONFIG_SMP
20029 percpu PT_LOAD FLAGS(6); /* RW_ */
20030 #endif
20031 + text.init PT_LOAD FLAGS(5); /* R_E */
20032 + text.exit PT_LOAD FLAGS(5); /* R_E */
20033 init PT_LOAD FLAGS(7); /* RWE */
20034 -#endif
20035 note PT_NOTE FLAGS(0); /* ___ */
20036 }
20037
20038 SECTIONS
20039 {
20040 #ifdef CONFIG_X86_32
20041 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20042 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20043 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20044 #else
20045 - . = __START_KERNEL;
20046 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20047 + . = __START_KERNEL;
20048 #endif
20049
20050 /* Text and read-only data */
20051 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20052 - _text = .;
20053 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20054 /* bootstrapping code */
20055 +#ifdef CONFIG_X86_32
20056 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20057 +#else
20058 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20059 +#endif
20060 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20061 + _text = .;
20062 HEAD_TEXT
20063 #ifdef CONFIG_X86_32
20064 . = ALIGN(PAGE_SIZE);
20065 @@ -108,13 +128,48 @@ SECTIONS
20066 IRQENTRY_TEXT
20067 *(.fixup)
20068 *(.gnu.warning)
20069 - /* End of text section */
20070 - _etext = .;
20071 } :text = 0x9090
20072
20073 - NOTES :text :note
20074 + . += __KERNEL_TEXT_OFFSET;
20075
20076 - EXCEPTION_TABLE(16) :text = 0x9090
20077 +#ifdef CONFIG_X86_32
20078 + . = ALIGN(PAGE_SIZE);
20079 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20080 +
20081 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20082 + MODULES_EXEC_VADDR = .;
20083 + BYTE(0)
20084 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20085 + . = ALIGN(HPAGE_SIZE) - 1;
20086 + MODULES_EXEC_END = .;
20087 +#endif
20088 +
20089 + } :module
20090 +#endif
20091 +
20092 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20093 + /* End of text section */
20094 + BYTE(0)
20095 + _etext = . - __KERNEL_TEXT_OFFSET;
20096 + }
20097 +
20098 +#ifdef CONFIG_X86_32
20099 + . = ALIGN(PAGE_SIZE);
20100 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20101 + *(.idt)
20102 + . = ALIGN(PAGE_SIZE);
20103 + *(.empty_zero_page)
20104 + *(.initial_pg_fixmap)
20105 + *(.initial_pg_pmd)
20106 + *(.initial_page_table)
20107 + *(.swapper_pg_dir)
20108 + } :rodata
20109 +#endif
20110 +
20111 + . = ALIGN(PAGE_SIZE);
20112 + NOTES :rodata :note
20113 +
20114 + EXCEPTION_TABLE(16) :rodata
20115
20116 #if defined(CONFIG_DEBUG_RODATA)
20117 /* .text should occupy whole number of pages */
20118 @@ -126,16 +181,20 @@ SECTIONS
20119
20120 /* Data */
20121 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20122 +
20123 +#ifdef CONFIG_PAX_KERNEXEC
20124 + . = ALIGN(HPAGE_SIZE);
20125 +#else
20126 + . = ALIGN(PAGE_SIZE);
20127 +#endif
20128 +
20129 /* Start of data section */
20130 _sdata = .;
20131
20132 /* init_task */
20133 INIT_TASK_DATA(THREAD_SIZE)
20134
20135 -#ifdef CONFIG_X86_32
20136 - /* 32 bit has nosave before _edata */
20137 NOSAVE_DATA
20138 -#endif
20139
20140 PAGE_ALIGNED_DATA(PAGE_SIZE)
20141
20142 @@ -176,12 +235,19 @@ SECTIONS
20143 #endif /* CONFIG_X86_64 */
20144
20145 /* Init code and data - will be freed after init */
20146 - . = ALIGN(PAGE_SIZE);
20147 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20148 + BYTE(0)
20149 +
20150 +#ifdef CONFIG_PAX_KERNEXEC
20151 + . = ALIGN(HPAGE_SIZE);
20152 +#else
20153 + . = ALIGN(PAGE_SIZE);
20154 +#endif
20155 +
20156 __init_begin = .; /* paired with __init_end */
20157 - }
20158 + } :init.begin
20159
20160 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20161 +#ifdef CONFIG_SMP
20162 /*
20163 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20164 * output PHDR, so the next output section - .init.text - should
20165 @@ -190,12 +256,27 @@ SECTIONS
20166 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20167 #endif
20168
20169 - INIT_TEXT_SECTION(PAGE_SIZE)
20170 -#ifdef CONFIG_X86_64
20171 - :init
20172 -#endif
20173 + . = ALIGN(PAGE_SIZE);
20174 + init_begin = .;
20175 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20176 + VMLINUX_SYMBOL(_sinittext) = .;
20177 + INIT_TEXT
20178 + VMLINUX_SYMBOL(_einittext) = .;
20179 + . = ALIGN(PAGE_SIZE);
20180 + } :text.init
20181
20182 - INIT_DATA_SECTION(16)
20183 + /*
20184 + * .exit.text is discard at runtime, not link time, to deal with
20185 + * references from .altinstructions and .eh_frame
20186 + */
20187 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20188 + EXIT_TEXT
20189 + . = ALIGN(16);
20190 + } :text.exit
20191 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20192 +
20193 + . = ALIGN(PAGE_SIZE);
20194 + INIT_DATA_SECTION(16) :init
20195
20196 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20197 __x86_cpu_dev_start = .;
20198 @@ -257,19 +338,12 @@ SECTIONS
20199 }
20200
20201 . = ALIGN(8);
20202 - /*
20203 - * .exit.text is discard at runtime, not link time, to deal with
20204 - * references from .altinstructions and .eh_frame
20205 - */
20206 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20207 - EXIT_TEXT
20208 - }
20209
20210 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20211 EXIT_DATA
20212 }
20213
20214 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20215 +#ifndef CONFIG_SMP
20216 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20217 #endif
20218
20219 @@ -288,16 +362,10 @@ SECTIONS
20220 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20221 __smp_locks = .;
20222 *(.smp_locks)
20223 - . = ALIGN(PAGE_SIZE);
20224 __smp_locks_end = .;
20225 + . = ALIGN(PAGE_SIZE);
20226 }
20227
20228 -#ifdef CONFIG_X86_64
20229 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20230 - NOSAVE_DATA
20231 - }
20232 -#endif
20233 -
20234 /* BSS */
20235 . = ALIGN(PAGE_SIZE);
20236 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20237 @@ -313,6 +381,7 @@ SECTIONS
20238 __brk_base = .;
20239 . += 64 * 1024; /* 64k alignment slop space */
20240 *(.brk_reservation) /* areas brk users have reserved */
20241 + . = ALIGN(HPAGE_SIZE);
20242 __brk_limit = .;
20243 }
20244
20245 @@ -339,13 +408,12 @@ SECTIONS
20246 * for the boot processor.
20247 */
20248 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20249 -INIT_PER_CPU(gdt_page);
20250 INIT_PER_CPU(irq_stack_union);
20251
20252 /*
20253 * Build-time check on the image size:
20254 */
20255 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20256 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20257 "kernel image bigger than KERNEL_IMAGE_SIZE");
20258
20259 #ifdef CONFIG_SMP
20260 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20261 index 992f890..fc38904 100644
20262 --- a/arch/x86/kernel/vsmp_64.c
20263 +++ b/arch/x86/kernel/vsmp_64.c
20264 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20265 static void vsmp_apic_post_init(void)
20266 {
20267 /* need to update phys_pkg_id */
20268 - apic->phys_pkg_id = apicid_phys_pkg_id;
20269 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20270 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20271 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20272 }
20273
20274 void __init vsmp_init(void)
20275 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20276 index 8d141b3..40a0fe4 100644
20277 --- a/arch/x86/kernel/vsyscall_64.c
20278 +++ b/arch/x86/kernel/vsyscall_64.c
20279 @@ -56,15 +56,13 @@
20280 DEFINE_VVAR(int, vgetcpu_mode);
20281 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20282
20283 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20284 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20285
20286 static int __init vsyscall_setup(char *str)
20287 {
20288 if (str) {
20289 if (!strcmp("emulate", str))
20290 vsyscall_mode = EMULATE;
20291 - else if (!strcmp("native", str))
20292 - vsyscall_mode = NATIVE;
20293 else if (!strcmp("none", str))
20294 vsyscall_mode = NONE;
20295 else
20296 @@ -306,8 +304,7 @@ done:
20297 return true;
20298
20299 sigsegv:
20300 - force_sig(SIGSEGV, current);
20301 - return true;
20302 + do_group_exit(SIGKILL);
20303 }
20304
20305 /*
20306 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20307 extern char __vvar_page;
20308 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20309
20310 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20311 - vsyscall_mode == NATIVE
20312 - ? PAGE_KERNEL_VSYSCALL
20313 - : PAGE_KERNEL_VVAR);
20314 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20315 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20316 (unsigned long)VSYSCALL_START);
20317
20318 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20319 index 6020f6f..bedd6e3 100644
20320 --- a/arch/x86/kernel/x8664_ksyms_64.c
20321 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20322 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20323 EXPORT_SYMBOL(copy_user_generic_unrolled);
20324 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20325 EXPORT_SYMBOL(__copy_user_nocache);
20326 -EXPORT_SYMBOL(_copy_from_user);
20327 -EXPORT_SYMBOL(_copy_to_user);
20328
20329 EXPORT_SYMBOL(copy_page);
20330 EXPORT_SYMBOL(clear_page);
20331 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20332 index 3d3e207..1a73ab2 100644
20333 --- a/arch/x86/kernel/xsave.c
20334 +++ b/arch/x86/kernel/xsave.c
20335 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20336 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20337 return -EINVAL;
20338
20339 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20340 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20341 fx_sw_user->extended_size -
20342 FP_XSTATE_MAGIC2_SIZE));
20343 if (err)
20344 @@ -268,7 +268,7 @@ fx_only:
20345 * the other extended state.
20346 */
20347 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20348 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20349 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20350 }
20351
20352 /*
20353 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20354 if (use_xsave())
20355 err = restore_user_xstate(buf);
20356 else
20357 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20358 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20359 buf);
20360 if (unlikely(err)) {
20361 /*
20362 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20363 index 0595f13..b544fa3 100644
20364 --- a/arch/x86/kvm/cpuid.c
20365 +++ b/arch/x86/kvm/cpuid.c
20366 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20367 struct kvm_cpuid2 *cpuid,
20368 struct kvm_cpuid_entry2 __user *entries)
20369 {
20370 - int r;
20371 + int r, i;
20372
20373 r = -E2BIG;
20374 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20375 goto out;
20376 r = -EFAULT;
20377 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20378 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20379 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20380 goto out;
20381 + for (i = 0; i < cpuid->nent; ++i) {
20382 + struct kvm_cpuid_entry2 cpuid_entry;
20383 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20384 + goto out;
20385 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20386 + }
20387 vcpu->arch.cpuid_nent = cpuid->nent;
20388 kvm_apic_set_version(vcpu);
20389 kvm_x86_ops->cpuid_update(vcpu);
20390 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20391 struct kvm_cpuid2 *cpuid,
20392 struct kvm_cpuid_entry2 __user *entries)
20393 {
20394 - int r;
20395 + int r, i;
20396
20397 r = -E2BIG;
20398 if (cpuid->nent < vcpu->arch.cpuid_nent)
20399 goto out;
20400 r = -EFAULT;
20401 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20402 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20403 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20404 goto out;
20405 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20406 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20407 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20408 + goto out;
20409 + }
20410 return 0;
20411
20412 out:
20413 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20414 index a3b57a2..ebbe732 100644
20415 --- a/arch/x86/kvm/emulate.c
20416 +++ b/arch/x86/kvm/emulate.c
20417 @@ -256,6 +256,7 @@ struct gprefix {
20418
20419 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20420 do { \
20421 + unsigned long _tmp; \
20422 __asm__ __volatile__ ( \
20423 _PRE_EFLAGS("0", "4", "2") \
20424 _op _suffix " %"_x"3,%1; " \
20425 @@ -270,8 +271,6 @@ struct gprefix {
20426 /* Raw emulation: instruction has two explicit operands. */
20427 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20428 do { \
20429 - unsigned long _tmp; \
20430 - \
20431 switch ((ctxt)->dst.bytes) { \
20432 case 2: \
20433 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20434 @@ -287,7 +286,6 @@ struct gprefix {
20435
20436 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20437 do { \
20438 - unsigned long _tmp; \
20439 switch ((ctxt)->dst.bytes) { \
20440 case 1: \
20441 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20442 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20443 index ce87878..ab48aa3 100644
20444 --- a/arch/x86/kvm/lapic.c
20445 +++ b/arch/x86/kvm/lapic.c
20446 @@ -54,7 +54,7 @@
20447 #define APIC_BUS_CYCLE_NS 1
20448
20449 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20450 -#define apic_debug(fmt, arg...)
20451 +#define apic_debug(fmt, arg...) do {} while (0)
20452
20453 #define APIC_LVT_NUM 6
20454 /* 14 is the version for Xeon and Pentium 8.4.8*/
20455 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20456 index bb7cf01..0348a05 100644
20457 --- a/arch/x86/kvm/paging_tmpl.h
20458 +++ b/arch/x86/kvm/paging_tmpl.h
20459 @@ -196,7 +196,7 @@ retry_walk:
20460 if (unlikely(kvm_is_error_hva(host_addr)))
20461 goto error;
20462
20463 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20464 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20465 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20466 goto error;
20467
20468 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20469 index baead95..90feeb4 100644
20470 --- a/arch/x86/kvm/svm.c
20471 +++ b/arch/x86/kvm/svm.c
20472 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20473 int cpu = raw_smp_processor_id();
20474
20475 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20476 +
20477 + pax_open_kernel();
20478 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20479 + pax_close_kernel();
20480 +
20481 load_TR_desc();
20482 }
20483
20484 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20485 #endif
20486 #endif
20487
20488 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20489 + __set_fs(current_thread_info()->addr_limit);
20490 +#endif
20491 +
20492 reload_tss(vcpu);
20493
20494 local_irq_disable();
20495 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20496 index b1eb202..254e292 100644
20497 --- a/arch/x86/kvm/vmx.c
20498 +++ b/arch/x86/kvm/vmx.c
20499 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20500 struct desc_struct *descs;
20501
20502 descs = (void *)gdt->address;
20503 +
20504 + pax_open_kernel();
20505 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20506 + pax_close_kernel();
20507 +
20508 load_TR_desc();
20509 }
20510
20511 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20512 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20513 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20514
20515 +#ifdef CONFIG_PAX_PER_CPU_PGD
20516 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20517 +#endif
20518 +
20519 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20520 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20521 vmx->loaded_vmcs->cpu = cpu;
20522 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20523 if (!cpu_has_vmx_flexpriority())
20524 flexpriority_enabled = 0;
20525
20526 - if (!cpu_has_vmx_tpr_shadow())
20527 - kvm_x86_ops->update_cr8_intercept = NULL;
20528 + if (!cpu_has_vmx_tpr_shadow()) {
20529 + pax_open_kernel();
20530 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20531 + pax_close_kernel();
20532 + }
20533
20534 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20535 kvm_disable_largepages();
20536 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20537
20538 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20539 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20540 +
20541 +#ifndef CONFIG_PAX_PER_CPU_PGD
20542 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20543 +#endif
20544
20545 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20546 #ifdef CONFIG_X86_64
20547 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20548 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20549
20550 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20551 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20552 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20553
20554 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20555 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20556 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20557 "jmp .Lkvm_vmx_return \n\t"
20558 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20559 ".Lkvm_vmx_return: "
20560 +
20561 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20562 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20563 + ".Lkvm_vmx_return2: "
20564 +#endif
20565 +
20566 /* Save guest registers, load host registers, keep flags */
20567 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20568 "pop %0 \n\t"
20569 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20570 #endif
20571 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20572 [wordsize]"i"(sizeof(ulong))
20573 +
20574 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20575 + ,[cs]"i"(__KERNEL_CS)
20576 +#endif
20577 +
20578 : "cc", "memory"
20579 , R"ax", R"bx", R"di", R"si"
20580 #ifdef CONFIG_X86_64
20581 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20582 #endif
20583 );
20584
20585 -#ifndef CONFIG_X86_64
20586 +#ifdef CONFIG_X86_32
20587 /*
20588 * The sysexit path does not restore ds/es, so we must set them to
20589 * a reasonable value ourselves.
20590 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20591 * may be executed in interrupt context, which saves and restore segments
20592 * around it, nullifying its effect.
20593 */
20594 - loadsegment(ds, __USER_DS);
20595 - loadsegment(es, __USER_DS);
20596 + loadsegment(ds, __KERNEL_DS);
20597 + loadsegment(es, __KERNEL_DS);
20598 + loadsegment(ss, __KERNEL_DS);
20599 +
20600 +#ifdef CONFIG_PAX_KERNEXEC
20601 + loadsegment(fs, __KERNEL_PERCPU);
20602 +#endif
20603 +
20604 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20605 + __set_fs(current_thread_info()->addr_limit);
20606 +#endif
20607 +
20608 #endif
20609
20610 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20611 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20612 index 2966c84..207d0cb 100644
20613 --- a/arch/x86/kvm/x86.c
20614 +++ b/arch/x86/kvm/x86.c
20615 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20616 {
20617 struct kvm *kvm = vcpu->kvm;
20618 int lm = is_long_mode(vcpu);
20619 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20620 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20621 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20622 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20623 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20624 : kvm->arch.xen_hvm_config.blob_size_32;
20625 u32 page_num = data & ~PAGE_MASK;
20626 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20627 if (n < msr_list.nmsrs)
20628 goto out;
20629 r = -EFAULT;
20630 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20631 + goto out;
20632 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20633 num_msrs_to_save * sizeof(u32)))
20634 goto out;
20635 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20636 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20637 struct kvm_interrupt *irq)
20638 {
20639 - if (irq->irq < 0 || irq->irq >= 256)
20640 + if (irq->irq >= 256)
20641 return -EINVAL;
20642 if (irqchip_in_kernel(vcpu->kvm))
20643 return -ENXIO;
20644 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20645 kvm_mmu_set_mmio_spte_mask(mask);
20646 }
20647
20648 -int kvm_arch_init(void *opaque)
20649 +int kvm_arch_init(const void *opaque)
20650 {
20651 int r;
20652 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20653 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20654 index 642d880..cc9ebac 100644
20655 --- a/arch/x86/lguest/boot.c
20656 +++ b/arch/x86/lguest/boot.c
20657 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20658
20659 static void set_lguest_basic_apic_ops(void)
20660 {
20661 - apic->read = lguest_apic_read;
20662 - apic->write = lguest_apic_write;
20663 - apic->icr_read = lguest_apic_icr_read;
20664 - apic->icr_write = lguest_apic_icr_write;
20665 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20666 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20667 + *(void **)&apic->read = lguest_apic_read;
20668 + *(void **)&apic->write = lguest_apic_write;
20669 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20670 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20671 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20672 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20673 };
20674 #endif
20675
20676 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20677 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20678 * Launcher to reboot us.
20679 */
20680 -static void lguest_restart(char *reason)
20681 +static __noreturn void lguest_restart(char *reason)
20682 {
20683 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20684 + BUG();
20685 }
20686
20687 /*G:050
20688 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20689 index 00933d5..3a64af9 100644
20690 --- a/arch/x86/lib/atomic64_386_32.S
20691 +++ b/arch/x86/lib/atomic64_386_32.S
20692 @@ -48,6 +48,10 @@ BEGIN(read)
20693 movl (v), %eax
20694 movl 4(v), %edx
20695 RET_ENDP
20696 +BEGIN(read_unchecked)
20697 + movl (v), %eax
20698 + movl 4(v), %edx
20699 +RET_ENDP
20700 #undef v
20701
20702 #define v %esi
20703 @@ -55,6 +59,10 @@ BEGIN(set)
20704 movl %ebx, (v)
20705 movl %ecx, 4(v)
20706 RET_ENDP
20707 +BEGIN(set_unchecked)
20708 + movl %ebx, (v)
20709 + movl %ecx, 4(v)
20710 +RET_ENDP
20711 #undef v
20712
20713 #define v %esi
20714 @@ -70,6 +78,20 @@ RET_ENDP
20715 BEGIN(add)
20716 addl %eax, (v)
20717 adcl %edx, 4(v)
20718 +
20719 +#ifdef CONFIG_PAX_REFCOUNT
20720 + jno 0f
20721 + subl %eax, (v)
20722 + sbbl %edx, 4(v)
20723 + int $4
20724 +0:
20725 + _ASM_EXTABLE(0b, 0b)
20726 +#endif
20727 +
20728 +RET_ENDP
20729 +BEGIN(add_unchecked)
20730 + addl %eax, (v)
20731 + adcl %edx, 4(v)
20732 RET_ENDP
20733 #undef v
20734
20735 @@ -77,6 +99,24 @@ RET_ENDP
20736 BEGIN(add_return)
20737 addl (v), %eax
20738 adcl 4(v), %edx
20739 +
20740 +#ifdef CONFIG_PAX_REFCOUNT
20741 + into
20742 +1234:
20743 + _ASM_EXTABLE(1234b, 2f)
20744 +#endif
20745 +
20746 + movl %eax, (v)
20747 + movl %edx, 4(v)
20748 +
20749 +#ifdef CONFIG_PAX_REFCOUNT
20750 +2:
20751 +#endif
20752 +
20753 +RET_ENDP
20754 +BEGIN(add_return_unchecked)
20755 + addl (v), %eax
20756 + adcl 4(v), %edx
20757 movl %eax, (v)
20758 movl %edx, 4(v)
20759 RET_ENDP
20760 @@ -86,6 +126,20 @@ RET_ENDP
20761 BEGIN(sub)
20762 subl %eax, (v)
20763 sbbl %edx, 4(v)
20764 +
20765 +#ifdef CONFIG_PAX_REFCOUNT
20766 + jno 0f
20767 + addl %eax, (v)
20768 + adcl %edx, 4(v)
20769 + int $4
20770 +0:
20771 + _ASM_EXTABLE(0b, 0b)
20772 +#endif
20773 +
20774 +RET_ENDP
20775 +BEGIN(sub_unchecked)
20776 + subl %eax, (v)
20777 + sbbl %edx, 4(v)
20778 RET_ENDP
20779 #undef v
20780
20781 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20782 sbbl $0, %edx
20783 addl (v), %eax
20784 adcl 4(v), %edx
20785 +
20786 +#ifdef CONFIG_PAX_REFCOUNT
20787 + into
20788 +1234:
20789 + _ASM_EXTABLE(1234b, 2f)
20790 +#endif
20791 +
20792 + movl %eax, (v)
20793 + movl %edx, 4(v)
20794 +
20795 +#ifdef CONFIG_PAX_REFCOUNT
20796 +2:
20797 +#endif
20798 +
20799 +RET_ENDP
20800 +BEGIN(sub_return_unchecked)
20801 + negl %edx
20802 + negl %eax
20803 + sbbl $0, %edx
20804 + addl (v), %eax
20805 + adcl 4(v), %edx
20806 movl %eax, (v)
20807 movl %edx, 4(v)
20808 RET_ENDP
20809 @@ -105,6 +180,20 @@ RET_ENDP
20810 BEGIN(inc)
20811 addl $1, (v)
20812 adcl $0, 4(v)
20813 +
20814 +#ifdef CONFIG_PAX_REFCOUNT
20815 + jno 0f
20816 + subl $1, (v)
20817 + sbbl $0, 4(v)
20818 + int $4
20819 +0:
20820 + _ASM_EXTABLE(0b, 0b)
20821 +#endif
20822 +
20823 +RET_ENDP
20824 +BEGIN(inc_unchecked)
20825 + addl $1, (v)
20826 + adcl $0, 4(v)
20827 RET_ENDP
20828 #undef v
20829
20830 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20831 movl 4(v), %edx
20832 addl $1, %eax
20833 adcl $0, %edx
20834 +
20835 +#ifdef CONFIG_PAX_REFCOUNT
20836 + into
20837 +1234:
20838 + _ASM_EXTABLE(1234b, 2f)
20839 +#endif
20840 +
20841 + movl %eax, (v)
20842 + movl %edx, 4(v)
20843 +
20844 +#ifdef CONFIG_PAX_REFCOUNT
20845 +2:
20846 +#endif
20847 +
20848 +RET_ENDP
20849 +BEGIN(inc_return_unchecked)
20850 + movl (v), %eax
20851 + movl 4(v), %edx
20852 + addl $1, %eax
20853 + adcl $0, %edx
20854 movl %eax, (v)
20855 movl %edx, 4(v)
20856 RET_ENDP
20857 @@ -123,6 +232,20 @@ RET_ENDP
20858 BEGIN(dec)
20859 subl $1, (v)
20860 sbbl $0, 4(v)
20861 +
20862 +#ifdef CONFIG_PAX_REFCOUNT
20863 + jno 0f
20864 + addl $1, (v)
20865 + adcl $0, 4(v)
20866 + int $4
20867 +0:
20868 + _ASM_EXTABLE(0b, 0b)
20869 +#endif
20870 +
20871 +RET_ENDP
20872 +BEGIN(dec_unchecked)
20873 + subl $1, (v)
20874 + sbbl $0, 4(v)
20875 RET_ENDP
20876 #undef v
20877
20878 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20879 movl 4(v), %edx
20880 subl $1, %eax
20881 sbbl $0, %edx
20882 +
20883 +#ifdef CONFIG_PAX_REFCOUNT
20884 + into
20885 +1234:
20886 + _ASM_EXTABLE(1234b, 2f)
20887 +#endif
20888 +
20889 + movl %eax, (v)
20890 + movl %edx, 4(v)
20891 +
20892 +#ifdef CONFIG_PAX_REFCOUNT
20893 +2:
20894 +#endif
20895 +
20896 +RET_ENDP
20897 +BEGIN(dec_return_unchecked)
20898 + movl (v), %eax
20899 + movl 4(v), %edx
20900 + subl $1, %eax
20901 + sbbl $0, %edx
20902 movl %eax, (v)
20903 movl %edx, 4(v)
20904 RET_ENDP
20905 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20906 adcl %edx, %edi
20907 addl (v), %eax
20908 adcl 4(v), %edx
20909 +
20910 +#ifdef CONFIG_PAX_REFCOUNT
20911 + into
20912 +1234:
20913 + _ASM_EXTABLE(1234b, 2f)
20914 +#endif
20915 +
20916 cmpl %eax, %ecx
20917 je 3f
20918 1:
20919 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20920 1:
20921 addl $1, %eax
20922 adcl $0, %edx
20923 +
20924 +#ifdef CONFIG_PAX_REFCOUNT
20925 + into
20926 +1234:
20927 + _ASM_EXTABLE(1234b, 2f)
20928 +#endif
20929 +
20930 movl %eax, (v)
20931 movl %edx, 4(v)
20932 movl $1, %eax
20933 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20934 movl 4(v), %edx
20935 subl $1, %eax
20936 sbbl $0, %edx
20937 +
20938 +#ifdef CONFIG_PAX_REFCOUNT
20939 + into
20940 +1234:
20941 + _ASM_EXTABLE(1234b, 1f)
20942 +#endif
20943 +
20944 js 1f
20945 movl %eax, (v)
20946 movl %edx, 4(v)
20947 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20948 index f5cc9eb..51fa319 100644
20949 --- a/arch/x86/lib/atomic64_cx8_32.S
20950 +++ b/arch/x86/lib/atomic64_cx8_32.S
20951 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20952 CFI_STARTPROC
20953
20954 read64 %ecx
20955 + pax_force_retaddr
20956 ret
20957 CFI_ENDPROC
20958 ENDPROC(atomic64_read_cx8)
20959
20960 +ENTRY(atomic64_read_unchecked_cx8)
20961 + CFI_STARTPROC
20962 +
20963 + read64 %ecx
20964 + pax_force_retaddr
20965 + ret
20966 + CFI_ENDPROC
20967 +ENDPROC(atomic64_read_unchecked_cx8)
20968 +
20969 ENTRY(atomic64_set_cx8)
20970 CFI_STARTPROC
20971
20972 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20973 cmpxchg8b (%esi)
20974 jne 1b
20975
20976 + pax_force_retaddr
20977 ret
20978 CFI_ENDPROC
20979 ENDPROC(atomic64_set_cx8)
20980
20981 +ENTRY(atomic64_set_unchecked_cx8)
20982 + CFI_STARTPROC
20983 +
20984 +1:
20985 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20986 + * are atomic on 586 and newer */
20987 + cmpxchg8b (%esi)
20988 + jne 1b
20989 +
20990 + pax_force_retaddr
20991 + ret
20992 + CFI_ENDPROC
20993 +ENDPROC(atomic64_set_unchecked_cx8)
20994 +
20995 ENTRY(atomic64_xchg_cx8)
20996 CFI_STARTPROC
20997
20998 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20999 cmpxchg8b (%esi)
21000 jne 1b
21001
21002 + pax_force_retaddr
21003 ret
21004 CFI_ENDPROC
21005 ENDPROC(atomic64_xchg_cx8)
21006
21007 -.macro addsub_return func ins insc
21008 -ENTRY(atomic64_\func\()_return_cx8)
21009 +.macro addsub_return func ins insc unchecked=""
21010 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21011 CFI_STARTPROC
21012 SAVE ebp
21013 SAVE ebx
21014 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21015 movl %edx, %ecx
21016 \ins\()l %esi, %ebx
21017 \insc\()l %edi, %ecx
21018 +
21019 +.ifb \unchecked
21020 +#ifdef CONFIG_PAX_REFCOUNT
21021 + into
21022 +2:
21023 + _ASM_EXTABLE(2b, 3f)
21024 +#endif
21025 +.endif
21026 +
21027 LOCK_PREFIX
21028 cmpxchg8b (%ebp)
21029 jne 1b
21030 -
21031 -10:
21032 movl %ebx, %eax
21033 movl %ecx, %edx
21034 +
21035 +.ifb \unchecked
21036 +#ifdef CONFIG_PAX_REFCOUNT
21037 +3:
21038 +#endif
21039 +.endif
21040 +
21041 RESTORE edi
21042 RESTORE esi
21043 RESTORE ebx
21044 RESTORE ebp
21045 + pax_force_retaddr
21046 ret
21047 CFI_ENDPROC
21048 -ENDPROC(atomic64_\func\()_return_cx8)
21049 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21050 .endm
21051
21052 addsub_return add add adc
21053 addsub_return sub sub sbb
21054 +addsub_return add add adc _unchecked
21055 +addsub_return sub sub sbb _unchecked
21056
21057 -.macro incdec_return func ins insc
21058 -ENTRY(atomic64_\func\()_return_cx8)
21059 +.macro incdec_return func ins insc unchecked=""
21060 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21061 CFI_STARTPROC
21062 SAVE ebx
21063
21064 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21065 movl %edx, %ecx
21066 \ins\()l $1, %ebx
21067 \insc\()l $0, %ecx
21068 +
21069 +.ifb \unchecked
21070 +#ifdef CONFIG_PAX_REFCOUNT
21071 + into
21072 +2:
21073 + _ASM_EXTABLE(2b, 3f)
21074 +#endif
21075 +.endif
21076 +
21077 LOCK_PREFIX
21078 cmpxchg8b (%esi)
21079 jne 1b
21080
21081 -10:
21082 movl %ebx, %eax
21083 movl %ecx, %edx
21084 +
21085 +.ifb \unchecked
21086 +#ifdef CONFIG_PAX_REFCOUNT
21087 +3:
21088 +#endif
21089 +.endif
21090 +
21091 RESTORE ebx
21092 + pax_force_retaddr
21093 ret
21094 CFI_ENDPROC
21095 -ENDPROC(atomic64_\func\()_return_cx8)
21096 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21097 .endm
21098
21099 incdec_return inc add adc
21100 incdec_return dec sub sbb
21101 +incdec_return inc add adc _unchecked
21102 +incdec_return dec sub sbb _unchecked
21103
21104 ENTRY(atomic64_dec_if_positive_cx8)
21105 CFI_STARTPROC
21106 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21107 movl %edx, %ecx
21108 subl $1, %ebx
21109 sbb $0, %ecx
21110 +
21111 +#ifdef CONFIG_PAX_REFCOUNT
21112 + into
21113 +1234:
21114 + _ASM_EXTABLE(1234b, 2f)
21115 +#endif
21116 +
21117 js 2f
21118 LOCK_PREFIX
21119 cmpxchg8b (%esi)
21120 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21121 movl %ebx, %eax
21122 movl %ecx, %edx
21123 RESTORE ebx
21124 + pax_force_retaddr
21125 ret
21126 CFI_ENDPROC
21127 ENDPROC(atomic64_dec_if_positive_cx8)
21128 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21129 movl %edx, %ecx
21130 addl %ebp, %ebx
21131 adcl %edi, %ecx
21132 +
21133 +#ifdef CONFIG_PAX_REFCOUNT
21134 + into
21135 +1234:
21136 + _ASM_EXTABLE(1234b, 3f)
21137 +#endif
21138 +
21139 LOCK_PREFIX
21140 cmpxchg8b (%esi)
21141 jne 1b
21142 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21143 CFI_ADJUST_CFA_OFFSET -8
21144 RESTORE ebx
21145 RESTORE ebp
21146 + pax_force_retaddr
21147 ret
21148 4:
21149 cmpl %edx, 4(%esp)
21150 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21151 xorl %ecx, %ecx
21152 addl $1, %ebx
21153 adcl %edx, %ecx
21154 +
21155 +#ifdef CONFIG_PAX_REFCOUNT
21156 + into
21157 +1234:
21158 + _ASM_EXTABLE(1234b, 3f)
21159 +#endif
21160 +
21161 LOCK_PREFIX
21162 cmpxchg8b (%esi)
21163 jne 1b
21164 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21165 movl $1, %eax
21166 3:
21167 RESTORE ebx
21168 + pax_force_retaddr
21169 ret
21170 CFI_ENDPROC
21171 ENDPROC(atomic64_inc_not_zero_cx8)
21172 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21173 index 2af5df3..62b1a5a 100644
21174 --- a/arch/x86/lib/checksum_32.S
21175 +++ b/arch/x86/lib/checksum_32.S
21176 @@ -29,7 +29,8 @@
21177 #include <asm/dwarf2.h>
21178 #include <asm/errno.h>
21179 #include <asm/asm.h>
21180 -
21181 +#include <asm/segment.h>
21182 +
21183 /*
21184 * computes a partial checksum, e.g. for TCP/UDP fragments
21185 */
21186 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21187
21188 #define ARGBASE 16
21189 #define FP 12
21190 -
21191 -ENTRY(csum_partial_copy_generic)
21192 +
21193 +ENTRY(csum_partial_copy_generic_to_user)
21194 CFI_STARTPROC
21195 +
21196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21197 + pushl_cfi %gs
21198 + popl_cfi %es
21199 + jmp csum_partial_copy_generic
21200 +#endif
21201 +
21202 +ENTRY(csum_partial_copy_generic_from_user)
21203 +
21204 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21205 + pushl_cfi %gs
21206 + popl_cfi %ds
21207 +#endif
21208 +
21209 +ENTRY(csum_partial_copy_generic)
21210 subl $4,%esp
21211 CFI_ADJUST_CFA_OFFSET 4
21212 pushl_cfi %edi
21213 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21214 jmp 4f
21215 SRC(1: movw (%esi), %bx )
21216 addl $2, %esi
21217 -DST( movw %bx, (%edi) )
21218 +DST( movw %bx, %es:(%edi) )
21219 addl $2, %edi
21220 addw %bx, %ax
21221 adcl $0, %eax
21222 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21223 SRC(1: movl (%esi), %ebx )
21224 SRC( movl 4(%esi), %edx )
21225 adcl %ebx, %eax
21226 -DST( movl %ebx, (%edi) )
21227 +DST( movl %ebx, %es:(%edi) )
21228 adcl %edx, %eax
21229 -DST( movl %edx, 4(%edi) )
21230 +DST( movl %edx, %es:4(%edi) )
21231
21232 SRC( movl 8(%esi), %ebx )
21233 SRC( movl 12(%esi), %edx )
21234 adcl %ebx, %eax
21235 -DST( movl %ebx, 8(%edi) )
21236 +DST( movl %ebx, %es:8(%edi) )
21237 adcl %edx, %eax
21238 -DST( movl %edx, 12(%edi) )
21239 +DST( movl %edx, %es:12(%edi) )
21240
21241 SRC( movl 16(%esi), %ebx )
21242 SRC( movl 20(%esi), %edx )
21243 adcl %ebx, %eax
21244 -DST( movl %ebx, 16(%edi) )
21245 +DST( movl %ebx, %es:16(%edi) )
21246 adcl %edx, %eax
21247 -DST( movl %edx, 20(%edi) )
21248 +DST( movl %edx, %es:20(%edi) )
21249
21250 SRC( movl 24(%esi), %ebx )
21251 SRC( movl 28(%esi), %edx )
21252 adcl %ebx, %eax
21253 -DST( movl %ebx, 24(%edi) )
21254 +DST( movl %ebx, %es:24(%edi) )
21255 adcl %edx, %eax
21256 -DST( movl %edx, 28(%edi) )
21257 +DST( movl %edx, %es:28(%edi) )
21258
21259 lea 32(%esi), %esi
21260 lea 32(%edi), %edi
21261 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21262 shrl $2, %edx # This clears CF
21263 SRC(3: movl (%esi), %ebx )
21264 adcl %ebx, %eax
21265 -DST( movl %ebx, (%edi) )
21266 +DST( movl %ebx, %es:(%edi) )
21267 lea 4(%esi), %esi
21268 lea 4(%edi), %edi
21269 dec %edx
21270 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21271 jb 5f
21272 SRC( movw (%esi), %cx )
21273 leal 2(%esi), %esi
21274 -DST( movw %cx, (%edi) )
21275 +DST( movw %cx, %es:(%edi) )
21276 leal 2(%edi), %edi
21277 je 6f
21278 shll $16,%ecx
21279 SRC(5: movb (%esi), %cl )
21280 -DST( movb %cl, (%edi) )
21281 +DST( movb %cl, %es:(%edi) )
21282 6: addl %ecx, %eax
21283 adcl $0, %eax
21284 7:
21285 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21286
21287 6001:
21288 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21289 - movl $-EFAULT, (%ebx)
21290 + movl $-EFAULT, %ss:(%ebx)
21291
21292 # zero the complete destination - computing the rest
21293 # is too much work
21294 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21295
21296 6002:
21297 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21298 - movl $-EFAULT,(%ebx)
21299 + movl $-EFAULT,%ss:(%ebx)
21300 jmp 5000b
21301
21302 .previous
21303
21304 + pushl_cfi %ss
21305 + popl_cfi %ds
21306 + pushl_cfi %ss
21307 + popl_cfi %es
21308 popl_cfi %ebx
21309 CFI_RESTORE ebx
21310 popl_cfi %esi
21311 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21312 popl_cfi %ecx # equivalent to addl $4,%esp
21313 ret
21314 CFI_ENDPROC
21315 -ENDPROC(csum_partial_copy_generic)
21316 +ENDPROC(csum_partial_copy_generic_to_user)
21317
21318 #else
21319
21320 /* Version for PentiumII/PPro */
21321
21322 #define ROUND1(x) \
21323 + nop; nop; nop; \
21324 SRC(movl x(%esi), %ebx ) ; \
21325 addl %ebx, %eax ; \
21326 - DST(movl %ebx, x(%edi) ) ;
21327 + DST(movl %ebx, %es:x(%edi)) ;
21328
21329 #define ROUND(x) \
21330 + nop; nop; nop; \
21331 SRC(movl x(%esi), %ebx ) ; \
21332 adcl %ebx, %eax ; \
21333 - DST(movl %ebx, x(%edi) ) ;
21334 + DST(movl %ebx, %es:x(%edi)) ;
21335
21336 #define ARGBASE 12
21337 -
21338 -ENTRY(csum_partial_copy_generic)
21339 +
21340 +ENTRY(csum_partial_copy_generic_to_user)
21341 CFI_STARTPROC
21342 +
21343 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21344 + pushl_cfi %gs
21345 + popl_cfi %es
21346 + jmp csum_partial_copy_generic
21347 +#endif
21348 +
21349 +ENTRY(csum_partial_copy_generic_from_user)
21350 +
21351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21352 + pushl_cfi %gs
21353 + popl_cfi %ds
21354 +#endif
21355 +
21356 +ENTRY(csum_partial_copy_generic)
21357 pushl_cfi %ebx
21358 CFI_REL_OFFSET ebx, 0
21359 pushl_cfi %edi
21360 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21361 subl %ebx, %edi
21362 lea -1(%esi),%edx
21363 andl $-32,%edx
21364 - lea 3f(%ebx,%ebx), %ebx
21365 + lea 3f(%ebx,%ebx,2), %ebx
21366 testl %esi, %esi
21367 jmp *%ebx
21368 1: addl $64,%esi
21369 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21370 jb 5f
21371 SRC( movw (%esi), %dx )
21372 leal 2(%esi), %esi
21373 -DST( movw %dx, (%edi) )
21374 +DST( movw %dx, %es:(%edi) )
21375 leal 2(%edi), %edi
21376 je 6f
21377 shll $16,%edx
21378 5:
21379 SRC( movb (%esi), %dl )
21380 -DST( movb %dl, (%edi) )
21381 +DST( movb %dl, %es:(%edi) )
21382 6: addl %edx, %eax
21383 adcl $0, %eax
21384 7:
21385 .section .fixup, "ax"
21386 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21387 - movl $-EFAULT, (%ebx)
21388 + movl $-EFAULT, %ss:(%ebx)
21389 # zero the complete destination (computing the rest is too much work)
21390 movl ARGBASE+8(%esp),%edi # dst
21391 movl ARGBASE+12(%esp),%ecx # len
21392 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21393 rep; stosb
21394 jmp 7b
21395 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21396 - movl $-EFAULT, (%ebx)
21397 + movl $-EFAULT, %ss:(%ebx)
21398 jmp 7b
21399 .previous
21400
21401 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21402 + pushl_cfi %ss
21403 + popl_cfi %ds
21404 + pushl_cfi %ss
21405 + popl_cfi %es
21406 +#endif
21407 +
21408 popl_cfi %esi
21409 CFI_RESTORE esi
21410 popl_cfi %edi
21411 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21412 CFI_RESTORE ebx
21413 ret
21414 CFI_ENDPROC
21415 -ENDPROC(csum_partial_copy_generic)
21416 +ENDPROC(csum_partial_copy_generic_to_user)
21417
21418 #undef ROUND
21419 #undef ROUND1
21420 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21421 index f2145cf..cea889d 100644
21422 --- a/arch/x86/lib/clear_page_64.S
21423 +++ b/arch/x86/lib/clear_page_64.S
21424 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21425 movl $4096/8,%ecx
21426 xorl %eax,%eax
21427 rep stosq
21428 + pax_force_retaddr
21429 ret
21430 CFI_ENDPROC
21431 ENDPROC(clear_page_c)
21432 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21433 movl $4096,%ecx
21434 xorl %eax,%eax
21435 rep stosb
21436 + pax_force_retaddr
21437 ret
21438 CFI_ENDPROC
21439 ENDPROC(clear_page_c_e)
21440 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21441 leaq 64(%rdi),%rdi
21442 jnz .Lloop
21443 nop
21444 + pax_force_retaddr
21445 ret
21446 CFI_ENDPROC
21447 .Lclear_page_end:
21448 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21449
21450 #include <asm/cpufeature.h>
21451
21452 - .section .altinstr_replacement,"ax"
21453 + .section .altinstr_replacement,"a"
21454 1: .byte 0xeb /* jmp <disp8> */
21455 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21456 2: .byte 0xeb /* jmp <disp8> */
21457 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21458 index 1e572c5..2a162cd 100644
21459 --- a/arch/x86/lib/cmpxchg16b_emu.S
21460 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21461 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21462
21463 popf
21464 mov $1, %al
21465 + pax_force_retaddr
21466 ret
21467
21468 not_same:
21469 popf
21470 xor %al,%al
21471 + pax_force_retaddr
21472 ret
21473
21474 CFI_ENDPROC
21475 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21476 index 6b34d04..dccb07f 100644
21477 --- a/arch/x86/lib/copy_page_64.S
21478 +++ b/arch/x86/lib/copy_page_64.S
21479 @@ -9,6 +9,7 @@ copy_page_c:
21480 CFI_STARTPROC
21481 movl $4096/8,%ecx
21482 rep movsq
21483 + pax_force_retaddr
21484 ret
21485 CFI_ENDPROC
21486 ENDPROC(copy_page_c)
21487 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21488
21489 ENTRY(copy_page)
21490 CFI_STARTPROC
21491 - subq $2*8,%rsp
21492 - CFI_ADJUST_CFA_OFFSET 2*8
21493 + subq $3*8,%rsp
21494 + CFI_ADJUST_CFA_OFFSET 3*8
21495 movq %rbx,(%rsp)
21496 CFI_REL_OFFSET rbx, 0
21497 movq %r12,1*8(%rsp)
21498 CFI_REL_OFFSET r12, 1*8
21499 + movq %r13,2*8(%rsp)
21500 + CFI_REL_OFFSET r13, 2*8
21501
21502 movl $(4096/64)-5,%ecx
21503 .p2align 4
21504 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21505 movq 16 (%rsi), %rdx
21506 movq 24 (%rsi), %r8
21507 movq 32 (%rsi), %r9
21508 - movq 40 (%rsi), %r10
21509 + movq 40 (%rsi), %r13
21510 movq 48 (%rsi), %r11
21511 movq 56 (%rsi), %r12
21512
21513 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21514 movq %rdx, 16 (%rdi)
21515 movq %r8, 24 (%rdi)
21516 movq %r9, 32 (%rdi)
21517 - movq %r10, 40 (%rdi)
21518 + movq %r13, 40 (%rdi)
21519 movq %r11, 48 (%rdi)
21520 movq %r12, 56 (%rdi)
21521
21522 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21523 movq 16 (%rsi), %rdx
21524 movq 24 (%rsi), %r8
21525 movq 32 (%rsi), %r9
21526 - movq 40 (%rsi), %r10
21527 + movq 40 (%rsi), %r13
21528 movq 48 (%rsi), %r11
21529 movq 56 (%rsi), %r12
21530
21531 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21532 movq %rdx, 16 (%rdi)
21533 movq %r8, 24 (%rdi)
21534 movq %r9, 32 (%rdi)
21535 - movq %r10, 40 (%rdi)
21536 + movq %r13, 40 (%rdi)
21537 movq %r11, 48 (%rdi)
21538 movq %r12, 56 (%rdi)
21539
21540 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21541 CFI_RESTORE rbx
21542 movq 1*8(%rsp),%r12
21543 CFI_RESTORE r12
21544 - addq $2*8,%rsp
21545 - CFI_ADJUST_CFA_OFFSET -2*8
21546 + movq 2*8(%rsp),%r13
21547 + CFI_RESTORE r13
21548 + addq $3*8,%rsp
21549 + CFI_ADJUST_CFA_OFFSET -3*8
21550 + pax_force_retaddr
21551 ret
21552 .Lcopy_page_end:
21553 CFI_ENDPROC
21554 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21555
21556 #include <asm/cpufeature.h>
21557
21558 - .section .altinstr_replacement,"ax"
21559 + .section .altinstr_replacement,"a"
21560 1: .byte 0xeb /* jmp <disp8> */
21561 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21562 2:
21563 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21564 index 5b2995f..78e7644 100644
21565 --- a/arch/x86/lib/copy_user_64.S
21566 +++ b/arch/x86/lib/copy_user_64.S
21567 @@ -17,6 +17,7 @@
21568 #include <asm/cpufeature.h>
21569 #include <asm/alternative-asm.h>
21570 #include <asm/asm.h>
21571 +#include <asm/pgtable.h>
21572
21573 /*
21574 * By placing feature2 after feature1 in altinstructions section, we logically
21575 @@ -30,7 +31,7 @@
21576 .byte 0xe9 /* 32bit jump */
21577 .long \orig-1f /* by default jump to orig */
21578 1:
21579 - .section .altinstr_replacement,"ax"
21580 + .section .altinstr_replacement,"a"
21581 2: .byte 0xe9 /* near jump with 32bit immediate */
21582 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21583 3: .byte 0xe9 /* near jump with 32bit immediate */
21584 @@ -69,47 +70,20 @@
21585 #endif
21586 .endm
21587
21588 -/* Standard copy_to_user with segment limit checking */
21589 -ENTRY(_copy_to_user)
21590 - CFI_STARTPROC
21591 - GET_THREAD_INFO(%rax)
21592 - movq %rdi,%rcx
21593 - addq %rdx,%rcx
21594 - jc bad_to_user
21595 - cmpq TI_addr_limit(%rax),%rcx
21596 - ja bad_to_user
21597 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21598 - copy_user_generic_unrolled,copy_user_generic_string, \
21599 - copy_user_enhanced_fast_string
21600 - CFI_ENDPROC
21601 -ENDPROC(_copy_to_user)
21602 -
21603 -/* Standard copy_from_user with segment limit checking */
21604 -ENTRY(_copy_from_user)
21605 - CFI_STARTPROC
21606 - GET_THREAD_INFO(%rax)
21607 - movq %rsi,%rcx
21608 - addq %rdx,%rcx
21609 - jc bad_from_user
21610 - cmpq TI_addr_limit(%rax),%rcx
21611 - ja bad_from_user
21612 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21613 - copy_user_generic_unrolled,copy_user_generic_string, \
21614 - copy_user_enhanced_fast_string
21615 - CFI_ENDPROC
21616 -ENDPROC(_copy_from_user)
21617 -
21618 .section .fixup,"ax"
21619 /* must zero dest */
21620 ENTRY(bad_from_user)
21621 bad_from_user:
21622 CFI_STARTPROC
21623 + testl %edx,%edx
21624 + js bad_to_user
21625 movl %edx,%ecx
21626 xorl %eax,%eax
21627 rep
21628 stosb
21629 bad_to_user:
21630 movl %edx,%eax
21631 + pax_force_retaddr
21632 ret
21633 CFI_ENDPROC
21634 ENDPROC(bad_from_user)
21635 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21636 jz 17f
21637 1: movq (%rsi),%r8
21638 2: movq 1*8(%rsi),%r9
21639 -3: movq 2*8(%rsi),%r10
21640 +3: movq 2*8(%rsi),%rax
21641 4: movq 3*8(%rsi),%r11
21642 5: movq %r8,(%rdi)
21643 6: movq %r9,1*8(%rdi)
21644 -7: movq %r10,2*8(%rdi)
21645 +7: movq %rax,2*8(%rdi)
21646 8: movq %r11,3*8(%rdi)
21647 9: movq 4*8(%rsi),%r8
21648 10: movq 5*8(%rsi),%r9
21649 -11: movq 6*8(%rsi),%r10
21650 +11: movq 6*8(%rsi),%rax
21651 12: movq 7*8(%rsi),%r11
21652 13: movq %r8,4*8(%rdi)
21653 14: movq %r9,5*8(%rdi)
21654 -15: movq %r10,6*8(%rdi)
21655 +15: movq %rax,6*8(%rdi)
21656 16: movq %r11,7*8(%rdi)
21657 leaq 64(%rsi),%rsi
21658 leaq 64(%rdi),%rdi
21659 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21660 decl %ecx
21661 jnz 21b
21662 23: xor %eax,%eax
21663 + pax_force_retaddr
21664 ret
21665
21666 .section .fixup,"ax"
21667 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21668 3: rep
21669 movsb
21670 4: xorl %eax,%eax
21671 + pax_force_retaddr
21672 ret
21673
21674 .section .fixup,"ax"
21675 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21676 1: rep
21677 movsb
21678 2: xorl %eax,%eax
21679 + pax_force_retaddr
21680 ret
21681
21682 .section .fixup,"ax"
21683 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21684 index cacddc7..09d49e4 100644
21685 --- a/arch/x86/lib/copy_user_nocache_64.S
21686 +++ b/arch/x86/lib/copy_user_nocache_64.S
21687 @@ -8,6 +8,7 @@
21688
21689 #include <linux/linkage.h>
21690 #include <asm/dwarf2.h>
21691 +#include <asm/alternative-asm.h>
21692
21693 #define FIX_ALIGNMENT 1
21694
21695 @@ -15,6 +16,7 @@
21696 #include <asm/asm-offsets.h>
21697 #include <asm/thread_info.h>
21698 #include <asm/asm.h>
21699 +#include <asm/pgtable.h>
21700
21701 .macro ALIGN_DESTINATION
21702 #ifdef FIX_ALIGNMENT
21703 @@ -48,6 +50,15 @@
21704 */
21705 ENTRY(__copy_user_nocache)
21706 CFI_STARTPROC
21707 +
21708 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21709 + mov $PAX_USER_SHADOW_BASE,%rcx
21710 + cmp %rcx,%rsi
21711 + jae 1f
21712 + add %rcx,%rsi
21713 +1:
21714 +#endif
21715 +
21716 cmpl $8,%edx
21717 jb 20f /* less then 8 bytes, go to byte copy loop */
21718 ALIGN_DESTINATION
21719 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21720 jz 17f
21721 1: movq (%rsi),%r8
21722 2: movq 1*8(%rsi),%r9
21723 -3: movq 2*8(%rsi),%r10
21724 +3: movq 2*8(%rsi),%rax
21725 4: movq 3*8(%rsi),%r11
21726 5: movnti %r8,(%rdi)
21727 6: movnti %r9,1*8(%rdi)
21728 -7: movnti %r10,2*8(%rdi)
21729 +7: movnti %rax,2*8(%rdi)
21730 8: movnti %r11,3*8(%rdi)
21731 9: movq 4*8(%rsi),%r8
21732 10: movq 5*8(%rsi),%r9
21733 -11: movq 6*8(%rsi),%r10
21734 +11: movq 6*8(%rsi),%rax
21735 12: movq 7*8(%rsi),%r11
21736 13: movnti %r8,4*8(%rdi)
21737 14: movnti %r9,5*8(%rdi)
21738 -15: movnti %r10,6*8(%rdi)
21739 +15: movnti %rax,6*8(%rdi)
21740 16: movnti %r11,7*8(%rdi)
21741 leaq 64(%rsi),%rsi
21742 leaq 64(%rdi),%rdi
21743 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21744 jnz 21b
21745 23: xorl %eax,%eax
21746 sfence
21747 + pax_force_retaddr
21748 ret
21749
21750 .section .fixup,"ax"
21751 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21752 index 2419d5f..953ee51 100644
21753 --- a/arch/x86/lib/csum-copy_64.S
21754 +++ b/arch/x86/lib/csum-copy_64.S
21755 @@ -9,6 +9,7 @@
21756 #include <asm/dwarf2.h>
21757 #include <asm/errno.h>
21758 #include <asm/asm.h>
21759 +#include <asm/alternative-asm.h>
21760
21761 /*
21762 * Checksum copy with exception handling.
21763 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21764 CFI_RESTORE rbp
21765 addq $7*8, %rsp
21766 CFI_ADJUST_CFA_OFFSET -7*8
21767 + pax_force_retaddr 0, 1
21768 ret
21769 CFI_RESTORE_STATE
21770
21771 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21772 index 25b7ae8..3b52ccd 100644
21773 --- a/arch/x86/lib/csum-wrappers_64.c
21774 +++ b/arch/x86/lib/csum-wrappers_64.c
21775 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21776 len -= 2;
21777 }
21778 }
21779 - isum = csum_partial_copy_generic((__force const void *)src,
21780 +
21781 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21782 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21783 + src += PAX_USER_SHADOW_BASE;
21784 +#endif
21785 +
21786 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21787 dst, len, isum, errp, NULL);
21788 if (unlikely(*errp))
21789 goto out_err;
21790 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21791 }
21792
21793 *errp = 0;
21794 - return csum_partial_copy_generic(src, (void __force *)dst,
21795 +
21796 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21797 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21798 + dst += PAX_USER_SHADOW_BASE;
21799 +#endif
21800 +
21801 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21802 len, isum, NULL, errp);
21803 }
21804 EXPORT_SYMBOL(csum_partial_copy_to_user);
21805 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21806 index b33b1fb..219f389 100644
21807 --- a/arch/x86/lib/getuser.S
21808 +++ b/arch/x86/lib/getuser.S
21809 @@ -33,15 +33,38 @@
21810 #include <asm/asm-offsets.h>
21811 #include <asm/thread_info.h>
21812 #include <asm/asm.h>
21813 +#include <asm/segment.h>
21814 +#include <asm/pgtable.h>
21815 +#include <asm/alternative-asm.h>
21816 +
21817 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21818 +#define __copyuser_seg gs;
21819 +#else
21820 +#define __copyuser_seg
21821 +#endif
21822
21823 .text
21824 ENTRY(__get_user_1)
21825 CFI_STARTPROC
21826 +
21827 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21828 GET_THREAD_INFO(%_ASM_DX)
21829 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21830 jae bad_get_user
21831 -1: movzb (%_ASM_AX),%edx
21832 +
21833 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21834 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21835 + cmp %_ASM_DX,%_ASM_AX
21836 + jae 1234f
21837 + add %_ASM_DX,%_ASM_AX
21838 +1234:
21839 +#endif
21840 +
21841 +#endif
21842 +
21843 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21844 xor %eax,%eax
21845 + pax_force_retaddr
21846 ret
21847 CFI_ENDPROC
21848 ENDPROC(__get_user_1)
21849 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21850 ENTRY(__get_user_2)
21851 CFI_STARTPROC
21852 add $1,%_ASM_AX
21853 +
21854 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21855 jc bad_get_user
21856 GET_THREAD_INFO(%_ASM_DX)
21857 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21858 jae bad_get_user
21859 -2: movzwl -1(%_ASM_AX),%edx
21860 +
21861 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21862 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21863 + cmp %_ASM_DX,%_ASM_AX
21864 + jae 1234f
21865 + add %_ASM_DX,%_ASM_AX
21866 +1234:
21867 +#endif
21868 +
21869 +#endif
21870 +
21871 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21872 xor %eax,%eax
21873 + pax_force_retaddr
21874 ret
21875 CFI_ENDPROC
21876 ENDPROC(__get_user_2)
21877 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21878 ENTRY(__get_user_4)
21879 CFI_STARTPROC
21880 add $3,%_ASM_AX
21881 +
21882 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21883 jc bad_get_user
21884 GET_THREAD_INFO(%_ASM_DX)
21885 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21886 jae bad_get_user
21887 -3: mov -3(%_ASM_AX),%edx
21888 +
21889 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21890 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21891 + cmp %_ASM_DX,%_ASM_AX
21892 + jae 1234f
21893 + add %_ASM_DX,%_ASM_AX
21894 +1234:
21895 +#endif
21896 +
21897 +#endif
21898 +
21899 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21900 xor %eax,%eax
21901 + pax_force_retaddr
21902 ret
21903 CFI_ENDPROC
21904 ENDPROC(__get_user_4)
21905 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21906 GET_THREAD_INFO(%_ASM_DX)
21907 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21908 jae bad_get_user
21909 +
21910 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21911 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21912 + cmp %_ASM_DX,%_ASM_AX
21913 + jae 1234f
21914 + add %_ASM_DX,%_ASM_AX
21915 +1234:
21916 +#endif
21917 +
21918 4: movq -7(%_ASM_AX),%_ASM_DX
21919 xor %eax,%eax
21920 + pax_force_retaddr
21921 ret
21922 CFI_ENDPROC
21923 ENDPROC(__get_user_8)
21924 @@ -91,6 +152,7 @@ bad_get_user:
21925 CFI_STARTPROC
21926 xor %edx,%edx
21927 mov $(-EFAULT),%_ASM_AX
21928 + pax_force_retaddr
21929 ret
21930 CFI_ENDPROC
21931 END(bad_get_user)
21932 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21933 index b1e6c4b..21ae8fc 100644
21934 --- a/arch/x86/lib/insn.c
21935 +++ b/arch/x86/lib/insn.c
21936 @@ -21,6 +21,11 @@
21937 #include <linux/string.h>
21938 #include <asm/inat.h>
21939 #include <asm/insn.h>
21940 +#ifdef __KERNEL__
21941 +#include <asm/pgtable_types.h>
21942 +#else
21943 +#define ktla_ktva(addr) addr
21944 +#endif
21945
21946 /* Verify next sizeof(t) bytes can be on the same instruction */
21947 #define validate_next(t, insn, n) \
21948 @@ -49,8 +54,8 @@
21949 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21950 {
21951 memset(insn, 0, sizeof(*insn));
21952 - insn->kaddr = kaddr;
21953 - insn->next_byte = kaddr;
21954 + insn->kaddr = ktla_ktva(kaddr);
21955 + insn->next_byte = ktla_ktva(kaddr);
21956 insn->x86_64 = x86_64 ? 1 : 0;
21957 insn->opnd_bytes = 4;
21958 if (x86_64)
21959 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21960 index 05a95e7..326f2fa 100644
21961 --- a/arch/x86/lib/iomap_copy_64.S
21962 +++ b/arch/x86/lib/iomap_copy_64.S
21963 @@ -17,6 +17,7 @@
21964
21965 #include <linux/linkage.h>
21966 #include <asm/dwarf2.h>
21967 +#include <asm/alternative-asm.h>
21968
21969 /*
21970 * override generic version in lib/iomap_copy.c
21971 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21972 CFI_STARTPROC
21973 movl %edx,%ecx
21974 rep movsd
21975 + pax_force_retaddr
21976 ret
21977 CFI_ENDPROC
21978 ENDPROC(__iowrite32_copy)
21979 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21980 index 1c273be..da9cc0e 100644
21981 --- a/arch/x86/lib/memcpy_64.S
21982 +++ b/arch/x86/lib/memcpy_64.S
21983 @@ -33,6 +33,7 @@
21984 rep movsq
21985 movl %edx, %ecx
21986 rep movsb
21987 + pax_force_retaddr
21988 ret
21989 .Lmemcpy_e:
21990 .previous
21991 @@ -49,6 +50,7 @@
21992 movq %rdi, %rax
21993 movq %rdx, %rcx
21994 rep movsb
21995 + pax_force_retaddr
21996 ret
21997 .Lmemcpy_e_e:
21998 .previous
21999 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22000 */
22001 movq 0*8(%rsi), %r8
22002 movq 1*8(%rsi), %r9
22003 - movq 2*8(%rsi), %r10
22004 + movq 2*8(%rsi), %rcx
22005 movq 3*8(%rsi), %r11
22006 leaq 4*8(%rsi), %rsi
22007
22008 movq %r8, 0*8(%rdi)
22009 movq %r9, 1*8(%rdi)
22010 - movq %r10, 2*8(%rdi)
22011 + movq %rcx, 2*8(%rdi)
22012 movq %r11, 3*8(%rdi)
22013 leaq 4*8(%rdi), %rdi
22014 jae .Lcopy_forward_loop
22015 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22016 subq $0x20, %rdx
22017 movq -1*8(%rsi), %r8
22018 movq -2*8(%rsi), %r9
22019 - movq -3*8(%rsi), %r10
22020 + movq -3*8(%rsi), %rcx
22021 movq -4*8(%rsi), %r11
22022 leaq -4*8(%rsi), %rsi
22023 movq %r8, -1*8(%rdi)
22024 movq %r9, -2*8(%rdi)
22025 - movq %r10, -3*8(%rdi)
22026 + movq %rcx, -3*8(%rdi)
22027 movq %r11, -4*8(%rdi)
22028 leaq -4*8(%rdi), %rdi
22029 jae .Lcopy_backward_loop
22030 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22031 */
22032 movq 0*8(%rsi), %r8
22033 movq 1*8(%rsi), %r9
22034 - movq -2*8(%rsi, %rdx), %r10
22035 + movq -2*8(%rsi, %rdx), %rcx
22036 movq -1*8(%rsi, %rdx), %r11
22037 movq %r8, 0*8(%rdi)
22038 movq %r9, 1*8(%rdi)
22039 - movq %r10, -2*8(%rdi, %rdx)
22040 + movq %rcx, -2*8(%rdi, %rdx)
22041 movq %r11, -1*8(%rdi, %rdx)
22042 + pax_force_retaddr
22043 retq
22044 .p2align 4
22045 .Lless_16bytes:
22046 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22047 movq -1*8(%rsi, %rdx), %r9
22048 movq %r8, 0*8(%rdi)
22049 movq %r9, -1*8(%rdi, %rdx)
22050 + pax_force_retaddr
22051 retq
22052 .p2align 4
22053 .Lless_8bytes:
22054 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22055 movl -4(%rsi, %rdx), %r8d
22056 movl %ecx, (%rdi)
22057 movl %r8d, -4(%rdi, %rdx)
22058 + pax_force_retaddr
22059 retq
22060 .p2align 4
22061 .Lless_3bytes:
22062 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22063 movb %cl, (%rdi)
22064
22065 .Lend:
22066 + pax_force_retaddr
22067 retq
22068 CFI_ENDPROC
22069 ENDPROC(memcpy)
22070 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22071 index ee16461..c39c199 100644
22072 --- a/arch/x86/lib/memmove_64.S
22073 +++ b/arch/x86/lib/memmove_64.S
22074 @@ -61,13 +61,13 @@ ENTRY(memmove)
22075 5:
22076 sub $0x20, %rdx
22077 movq 0*8(%rsi), %r11
22078 - movq 1*8(%rsi), %r10
22079 + movq 1*8(%rsi), %rcx
22080 movq 2*8(%rsi), %r9
22081 movq 3*8(%rsi), %r8
22082 leaq 4*8(%rsi), %rsi
22083
22084 movq %r11, 0*8(%rdi)
22085 - movq %r10, 1*8(%rdi)
22086 + movq %rcx, 1*8(%rdi)
22087 movq %r9, 2*8(%rdi)
22088 movq %r8, 3*8(%rdi)
22089 leaq 4*8(%rdi), %rdi
22090 @@ -81,10 +81,10 @@ ENTRY(memmove)
22091 4:
22092 movq %rdx, %rcx
22093 movq -8(%rsi, %rdx), %r11
22094 - lea -8(%rdi, %rdx), %r10
22095 + lea -8(%rdi, %rdx), %r9
22096 shrq $3, %rcx
22097 rep movsq
22098 - movq %r11, (%r10)
22099 + movq %r11, (%r9)
22100 jmp 13f
22101 .Lmemmove_end_forward:
22102
22103 @@ -95,14 +95,14 @@ ENTRY(memmove)
22104 7:
22105 movq %rdx, %rcx
22106 movq (%rsi), %r11
22107 - movq %rdi, %r10
22108 + movq %rdi, %r9
22109 leaq -8(%rsi, %rdx), %rsi
22110 leaq -8(%rdi, %rdx), %rdi
22111 shrq $3, %rcx
22112 std
22113 rep movsq
22114 cld
22115 - movq %r11, (%r10)
22116 + movq %r11, (%r9)
22117 jmp 13f
22118
22119 /*
22120 @@ -127,13 +127,13 @@ ENTRY(memmove)
22121 8:
22122 subq $0x20, %rdx
22123 movq -1*8(%rsi), %r11
22124 - movq -2*8(%rsi), %r10
22125 + movq -2*8(%rsi), %rcx
22126 movq -3*8(%rsi), %r9
22127 movq -4*8(%rsi), %r8
22128 leaq -4*8(%rsi), %rsi
22129
22130 movq %r11, -1*8(%rdi)
22131 - movq %r10, -2*8(%rdi)
22132 + movq %rcx, -2*8(%rdi)
22133 movq %r9, -3*8(%rdi)
22134 movq %r8, -4*8(%rdi)
22135 leaq -4*8(%rdi), %rdi
22136 @@ -151,11 +151,11 @@ ENTRY(memmove)
22137 * Move data from 16 bytes to 31 bytes.
22138 */
22139 movq 0*8(%rsi), %r11
22140 - movq 1*8(%rsi), %r10
22141 + movq 1*8(%rsi), %rcx
22142 movq -2*8(%rsi, %rdx), %r9
22143 movq -1*8(%rsi, %rdx), %r8
22144 movq %r11, 0*8(%rdi)
22145 - movq %r10, 1*8(%rdi)
22146 + movq %rcx, 1*8(%rdi)
22147 movq %r9, -2*8(%rdi, %rdx)
22148 movq %r8, -1*8(%rdi, %rdx)
22149 jmp 13f
22150 @@ -167,9 +167,9 @@ ENTRY(memmove)
22151 * Move data from 8 bytes to 15 bytes.
22152 */
22153 movq 0*8(%rsi), %r11
22154 - movq -1*8(%rsi, %rdx), %r10
22155 + movq -1*8(%rsi, %rdx), %r9
22156 movq %r11, 0*8(%rdi)
22157 - movq %r10, -1*8(%rdi, %rdx)
22158 + movq %r9, -1*8(%rdi, %rdx)
22159 jmp 13f
22160 10:
22161 cmpq $4, %rdx
22162 @@ -178,9 +178,9 @@ ENTRY(memmove)
22163 * Move data from 4 bytes to 7 bytes.
22164 */
22165 movl (%rsi), %r11d
22166 - movl -4(%rsi, %rdx), %r10d
22167 + movl -4(%rsi, %rdx), %r9d
22168 movl %r11d, (%rdi)
22169 - movl %r10d, -4(%rdi, %rdx)
22170 + movl %r9d, -4(%rdi, %rdx)
22171 jmp 13f
22172 11:
22173 cmp $2, %rdx
22174 @@ -189,9 +189,9 @@ ENTRY(memmove)
22175 * Move data from 2 bytes to 3 bytes.
22176 */
22177 movw (%rsi), %r11w
22178 - movw -2(%rsi, %rdx), %r10w
22179 + movw -2(%rsi, %rdx), %r9w
22180 movw %r11w, (%rdi)
22181 - movw %r10w, -2(%rdi, %rdx)
22182 + movw %r9w, -2(%rdi, %rdx)
22183 jmp 13f
22184 12:
22185 cmp $1, %rdx
22186 @@ -202,6 +202,7 @@ ENTRY(memmove)
22187 movb (%rsi), %r11b
22188 movb %r11b, (%rdi)
22189 13:
22190 + pax_force_retaddr
22191 retq
22192 CFI_ENDPROC
22193
22194 @@ -210,6 +211,7 @@ ENTRY(memmove)
22195 /* Forward moving data. */
22196 movq %rdx, %rcx
22197 rep movsb
22198 + pax_force_retaddr
22199 retq
22200 .Lmemmove_end_forward_efs:
22201 .previous
22202 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22203 index 2dcb380..963660a 100644
22204 --- a/arch/x86/lib/memset_64.S
22205 +++ b/arch/x86/lib/memset_64.S
22206 @@ -30,6 +30,7 @@
22207 movl %edx,%ecx
22208 rep stosb
22209 movq %r9,%rax
22210 + pax_force_retaddr
22211 ret
22212 .Lmemset_e:
22213 .previous
22214 @@ -52,6 +53,7 @@
22215 movq %rdx,%rcx
22216 rep stosb
22217 movq %r9,%rax
22218 + pax_force_retaddr
22219 ret
22220 .Lmemset_e_e:
22221 .previous
22222 @@ -59,7 +61,7 @@
22223 ENTRY(memset)
22224 ENTRY(__memset)
22225 CFI_STARTPROC
22226 - movq %rdi,%r10
22227 + movq %rdi,%r11
22228
22229 /* expand byte value */
22230 movzbl %sil,%ecx
22231 @@ -117,7 +119,8 @@ ENTRY(__memset)
22232 jnz .Lloop_1
22233
22234 .Lende:
22235 - movq %r10,%rax
22236 + movq %r11,%rax
22237 + pax_force_retaddr
22238 ret
22239
22240 CFI_RESTORE_STATE
22241 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22242 index c9f2d9b..e7fd2c0 100644
22243 --- a/arch/x86/lib/mmx_32.c
22244 +++ b/arch/x86/lib/mmx_32.c
22245 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22246 {
22247 void *p;
22248 int i;
22249 + unsigned long cr0;
22250
22251 if (unlikely(in_interrupt()))
22252 return __memcpy(to, from, len);
22253 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22254 kernel_fpu_begin();
22255
22256 __asm__ __volatile__ (
22257 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22258 - " prefetch 64(%0)\n"
22259 - " prefetch 128(%0)\n"
22260 - " prefetch 192(%0)\n"
22261 - " prefetch 256(%0)\n"
22262 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22263 + " prefetch 64(%1)\n"
22264 + " prefetch 128(%1)\n"
22265 + " prefetch 192(%1)\n"
22266 + " prefetch 256(%1)\n"
22267 "2: \n"
22268 ".section .fixup, \"ax\"\n"
22269 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22270 + "3: \n"
22271 +
22272 +#ifdef CONFIG_PAX_KERNEXEC
22273 + " movl %%cr0, %0\n"
22274 + " movl %0, %%eax\n"
22275 + " andl $0xFFFEFFFF, %%eax\n"
22276 + " movl %%eax, %%cr0\n"
22277 +#endif
22278 +
22279 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22280 +
22281 +#ifdef CONFIG_PAX_KERNEXEC
22282 + " movl %0, %%cr0\n"
22283 +#endif
22284 +
22285 " jmp 2b\n"
22286 ".previous\n"
22287 _ASM_EXTABLE(1b, 3b)
22288 - : : "r" (from));
22289 + : "=&r" (cr0) : "r" (from) : "ax");
22290
22291 for ( ; i > 5; i--) {
22292 __asm__ __volatile__ (
22293 - "1: prefetch 320(%0)\n"
22294 - "2: movq (%0), %%mm0\n"
22295 - " movq 8(%0), %%mm1\n"
22296 - " movq 16(%0), %%mm2\n"
22297 - " movq 24(%0), %%mm3\n"
22298 - " movq %%mm0, (%1)\n"
22299 - " movq %%mm1, 8(%1)\n"
22300 - " movq %%mm2, 16(%1)\n"
22301 - " movq %%mm3, 24(%1)\n"
22302 - " movq 32(%0), %%mm0\n"
22303 - " movq 40(%0), %%mm1\n"
22304 - " movq 48(%0), %%mm2\n"
22305 - " movq 56(%0), %%mm3\n"
22306 - " movq %%mm0, 32(%1)\n"
22307 - " movq %%mm1, 40(%1)\n"
22308 - " movq %%mm2, 48(%1)\n"
22309 - " movq %%mm3, 56(%1)\n"
22310 + "1: prefetch 320(%1)\n"
22311 + "2: movq (%1), %%mm0\n"
22312 + " movq 8(%1), %%mm1\n"
22313 + " movq 16(%1), %%mm2\n"
22314 + " movq 24(%1), %%mm3\n"
22315 + " movq %%mm0, (%2)\n"
22316 + " movq %%mm1, 8(%2)\n"
22317 + " movq %%mm2, 16(%2)\n"
22318 + " movq %%mm3, 24(%2)\n"
22319 + " movq 32(%1), %%mm0\n"
22320 + " movq 40(%1), %%mm1\n"
22321 + " movq 48(%1), %%mm2\n"
22322 + " movq 56(%1), %%mm3\n"
22323 + " movq %%mm0, 32(%2)\n"
22324 + " movq %%mm1, 40(%2)\n"
22325 + " movq %%mm2, 48(%2)\n"
22326 + " movq %%mm3, 56(%2)\n"
22327 ".section .fixup, \"ax\"\n"
22328 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22329 + "3:\n"
22330 +
22331 +#ifdef CONFIG_PAX_KERNEXEC
22332 + " movl %%cr0, %0\n"
22333 + " movl %0, %%eax\n"
22334 + " andl $0xFFFEFFFF, %%eax\n"
22335 + " movl %%eax, %%cr0\n"
22336 +#endif
22337 +
22338 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22339 +
22340 +#ifdef CONFIG_PAX_KERNEXEC
22341 + " movl %0, %%cr0\n"
22342 +#endif
22343 +
22344 " jmp 2b\n"
22345 ".previous\n"
22346 _ASM_EXTABLE(1b, 3b)
22347 - : : "r" (from), "r" (to) : "memory");
22348 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22349
22350 from += 64;
22351 to += 64;
22352 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22353 static void fast_copy_page(void *to, void *from)
22354 {
22355 int i;
22356 + unsigned long cr0;
22357
22358 kernel_fpu_begin();
22359
22360 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22361 * but that is for later. -AV
22362 */
22363 __asm__ __volatile__(
22364 - "1: prefetch (%0)\n"
22365 - " prefetch 64(%0)\n"
22366 - " prefetch 128(%0)\n"
22367 - " prefetch 192(%0)\n"
22368 - " prefetch 256(%0)\n"
22369 + "1: prefetch (%1)\n"
22370 + " prefetch 64(%1)\n"
22371 + " prefetch 128(%1)\n"
22372 + " prefetch 192(%1)\n"
22373 + " prefetch 256(%1)\n"
22374 "2: \n"
22375 ".section .fixup, \"ax\"\n"
22376 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22377 + "3: \n"
22378 +
22379 +#ifdef CONFIG_PAX_KERNEXEC
22380 + " movl %%cr0, %0\n"
22381 + " movl %0, %%eax\n"
22382 + " andl $0xFFFEFFFF, %%eax\n"
22383 + " movl %%eax, %%cr0\n"
22384 +#endif
22385 +
22386 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22387 +
22388 +#ifdef CONFIG_PAX_KERNEXEC
22389 + " movl %0, %%cr0\n"
22390 +#endif
22391 +
22392 " jmp 2b\n"
22393 ".previous\n"
22394 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22395 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22396
22397 for (i = 0; i < (4096-320)/64; i++) {
22398 __asm__ __volatile__ (
22399 - "1: prefetch 320(%0)\n"
22400 - "2: movq (%0), %%mm0\n"
22401 - " movntq %%mm0, (%1)\n"
22402 - " movq 8(%0), %%mm1\n"
22403 - " movntq %%mm1, 8(%1)\n"
22404 - " movq 16(%0), %%mm2\n"
22405 - " movntq %%mm2, 16(%1)\n"
22406 - " movq 24(%0), %%mm3\n"
22407 - " movntq %%mm3, 24(%1)\n"
22408 - " movq 32(%0), %%mm4\n"
22409 - " movntq %%mm4, 32(%1)\n"
22410 - " movq 40(%0), %%mm5\n"
22411 - " movntq %%mm5, 40(%1)\n"
22412 - " movq 48(%0), %%mm6\n"
22413 - " movntq %%mm6, 48(%1)\n"
22414 - " movq 56(%0), %%mm7\n"
22415 - " movntq %%mm7, 56(%1)\n"
22416 + "1: prefetch 320(%1)\n"
22417 + "2: movq (%1), %%mm0\n"
22418 + " movntq %%mm0, (%2)\n"
22419 + " movq 8(%1), %%mm1\n"
22420 + " movntq %%mm1, 8(%2)\n"
22421 + " movq 16(%1), %%mm2\n"
22422 + " movntq %%mm2, 16(%2)\n"
22423 + " movq 24(%1), %%mm3\n"
22424 + " movntq %%mm3, 24(%2)\n"
22425 + " movq 32(%1), %%mm4\n"
22426 + " movntq %%mm4, 32(%2)\n"
22427 + " movq 40(%1), %%mm5\n"
22428 + " movntq %%mm5, 40(%2)\n"
22429 + " movq 48(%1), %%mm6\n"
22430 + " movntq %%mm6, 48(%2)\n"
22431 + " movq 56(%1), %%mm7\n"
22432 + " movntq %%mm7, 56(%2)\n"
22433 ".section .fixup, \"ax\"\n"
22434 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22435 + "3:\n"
22436 +
22437 +#ifdef CONFIG_PAX_KERNEXEC
22438 + " movl %%cr0, %0\n"
22439 + " movl %0, %%eax\n"
22440 + " andl $0xFFFEFFFF, %%eax\n"
22441 + " movl %%eax, %%cr0\n"
22442 +#endif
22443 +
22444 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22445 +
22446 +#ifdef CONFIG_PAX_KERNEXEC
22447 + " movl %0, %%cr0\n"
22448 +#endif
22449 +
22450 " jmp 2b\n"
22451 ".previous\n"
22452 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22453 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22454
22455 from += 64;
22456 to += 64;
22457 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22458 static void fast_copy_page(void *to, void *from)
22459 {
22460 int i;
22461 + unsigned long cr0;
22462
22463 kernel_fpu_begin();
22464
22465 __asm__ __volatile__ (
22466 - "1: prefetch (%0)\n"
22467 - " prefetch 64(%0)\n"
22468 - " prefetch 128(%0)\n"
22469 - " prefetch 192(%0)\n"
22470 - " prefetch 256(%0)\n"
22471 + "1: prefetch (%1)\n"
22472 + " prefetch 64(%1)\n"
22473 + " prefetch 128(%1)\n"
22474 + " prefetch 192(%1)\n"
22475 + " prefetch 256(%1)\n"
22476 "2: \n"
22477 ".section .fixup, \"ax\"\n"
22478 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22479 + "3: \n"
22480 +
22481 +#ifdef CONFIG_PAX_KERNEXEC
22482 + " movl %%cr0, %0\n"
22483 + " movl %0, %%eax\n"
22484 + " andl $0xFFFEFFFF, %%eax\n"
22485 + " movl %%eax, %%cr0\n"
22486 +#endif
22487 +
22488 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22489 +
22490 +#ifdef CONFIG_PAX_KERNEXEC
22491 + " movl %0, %%cr0\n"
22492 +#endif
22493 +
22494 " jmp 2b\n"
22495 ".previous\n"
22496 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22497 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22498
22499 for (i = 0; i < 4096/64; 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 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22561 index f6d13ee..aca5f0b 100644
22562 --- a/arch/x86/lib/msr-reg.S
22563 +++ b/arch/x86/lib/msr-reg.S
22564 @@ -3,6 +3,7 @@
22565 #include <asm/dwarf2.h>
22566 #include <asm/asm.h>
22567 #include <asm/msr.h>
22568 +#include <asm/alternative-asm.h>
22569
22570 #ifdef CONFIG_X86_64
22571 /*
22572 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22573 CFI_STARTPROC
22574 pushq_cfi %rbx
22575 pushq_cfi %rbp
22576 - movq %rdi, %r10 /* Save pointer */
22577 + movq %rdi, %r9 /* Save pointer */
22578 xorl %r11d, %r11d /* Return value */
22579 movl (%rdi), %eax
22580 movl 4(%rdi), %ecx
22581 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22582 movl 28(%rdi), %edi
22583 CFI_REMEMBER_STATE
22584 1: \op
22585 -2: movl %eax, (%r10)
22586 +2: movl %eax, (%r9)
22587 movl %r11d, %eax /* Return value */
22588 - movl %ecx, 4(%r10)
22589 - movl %edx, 8(%r10)
22590 - movl %ebx, 12(%r10)
22591 - movl %ebp, 20(%r10)
22592 - movl %esi, 24(%r10)
22593 - movl %edi, 28(%r10)
22594 + movl %ecx, 4(%r9)
22595 + movl %edx, 8(%r9)
22596 + movl %ebx, 12(%r9)
22597 + movl %ebp, 20(%r9)
22598 + movl %esi, 24(%r9)
22599 + movl %edi, 28(%r9)
22600 popq_cfi %rbp
22601 popq_cfi %rbx
22602 + pax_force_retaddr
22603 ret
22604 3:
22605 CFI_RESTORE_STATE
22606 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22607 index 7f951c8..ebd573a 100644
22608 --- a/arch/x86/lib/putuser.S
22609 +++ b/arch/x86/lib/putuser.S
22610 @@ -15,7 +15,9 @@
22611 #include <asm/thread_info.h>
22612 #include <asm/errno.h>
22613 #include <asm/asm.h>
22614 -
22615 +#include <asm/segment.h>
22616 +#include <asm/pgtable.h>
22617 +#include <asm/alternative-asm.h>
22618
22619 /*
22620 * __put_user_X
22621 @@ -29,52 +31,119 @@
22622 * as they get called from within inline assembly.
22623 */
22624
22625 -#define ENTER CFI_STARTPROC ; \
22626 - GET_THREAD_INFO(%_ASM_BX)
22627 -#define EXIT ret ; \
22628 +#define ENTER CFI_STARTPROC
22629 +#define EXIT pax_force_retaddr; ret ; \
22630 CFI_ENDPROC
22631
22632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22633 +#define _DEST %_ASM_CX,%_ASM_BX
22634 +#else
22635 +#define _DEST %_ASM_CX
22636 +#endif
22637 +
22638 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22639 +#define __copyuser_seg gs;
22640 +#else
22641 +#define __copyuser_seg
22642 +#endif
22643 +
22644 .text
22645 ENTRY(__put_user_1)
22646 ENTER
22647 +
22648 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22649 + GET_THREAD_INFO(%_ASM_BX)
22650 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22651 jae bad_put_user
22652 -1: movb %al,(%_ASM_CX)
22653 +
22654 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22655 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22656 + cmp %_ASM_BX,%_ASM_CX
22657 + jb 1234f
22658 + xor %ebx,%ebx
22659 +1234:
22660 +#endif
22661 +
22662 +#endif
22663 +
22664 +1: __copyuser_seg movb %al,(_DEST)
22665 xor %eax,%eax
22666 EXIT
22667 ENDPROC(__put_user_1)
22668
22669 ENTRY(__put_user_2)
22670 ENTER
22671 +
22672 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22673 + GET_THREAD_INFO(%_ASM_BX)
22674 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22675 sub $1,%_ASM_BX
22676 cmp %_ASM_BX,%_ASM_CX
22677 jae bad_put_user
22678 -2: movw %ax,(%_ASM_CX)
22679 +
22680 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22681 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22682 + cmp %_ASM_BX,%_ASM_CX
22683 + jb 1234f
22684 + xor %ebx,%ebx
22685 +1234:
22686 +#endif
22687 +
22688 +#endif
22689 +
22690 +2: __copyuser_seg movw %ax,(_DEST)
22691 xor %eax,%eax
22692 EXIT
22693 ENDPROC(__put_user_2)
22694
22695 ENTRY(__put_user_4)
22696 ENTER
22697 +
22698 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22699 + GET_THREAD_INFO(%_ASM_BX)
22700 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22701 sub $3,%_ASM_BX
22702 cmp %_ASM_BX,%_ASM_CX
22703 jae bad_put_user
22704 -3: movl %eax,(%_ASM_CX)
22705 +
22706 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22707 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22708 + cmp %_ASM_BX,%_ASM_CX
22709 + jb 1234f
22710 + xor %ebx,%ebx
22711 +1234:
22712 +#endif
22713 +
22714 +#endif
22715 +
22716 +3: __copyuser_seg movl %eax,(_DEST)
22717 xor %eax,%eax
22718 EXIT
22719 ENDPROC(__put_user_4)
22720
22721 ENTRY(__put_user_8)
22722 ENTER
22723 +
22724 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22725 + GET_THREAD_INFO(%_ASM_BX)
22726 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22727 sub $7,%_ASM_BX
22728 cmp %_ASM_BX,%_ASM_CX
22729 jae bad_put_user
22730 -4: mov %_ASM_AX,(%_ASM_CX)
22731 +
22732 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22733 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22734 + cmp %_ASM_BX,%_ASM_CX
22735 + jb 1234f
22736 + xor %ebx,%ebx
22737 +1234:
22738 +#endif
22739 +
22740 +#endif
22741 +
22742 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22743 #ifdef CONFIG_X86_32
22744 -5: movl %edx,4(%_ASM_CX)
22745 +5: __copyuser_seg movl %edx,4(_DEST)
22746 #endif
22747 xor %eax,%eax
22748 EXIT
22749 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22750 index 1cad221..de671ee 100644
22751 --- a/arch/x86/lib/rwlock.S
22752 +++ b/arch/x86/lib/rwlock.S
22753 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22754 FRAME
22755 0: LOCK_PREFIX
22756 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22757 +
22758 +#ifdef CONFIG_PAX_REFCOUNT
22759 + jno 1234f
22760 + LOCK_PREFIX
22761 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22762 + int $4
22763 +1234:
22764 + _ASM_EXTABLE(1234b, 1234b)
22765 +#endif
22766 +
22767 1: rep; nop
22768 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22769 jne 1b
22770 LOCK_PREFIX
22771 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22772 +
22773 +#ifdef CONFIG_PAX_REFCOUNT
22774 + jno 1234f
22775 + LOCK_PREFIX
22776 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22777 + int $4
22778 +1234:
22779 + _ASM_EXTABLE(1234b, 1234b)
22780 +#endif
22781 +
22782 jnz 0b
22783 ENDFRAME
22784 + pax_force_retaddr
22785 ret
22786 CFI_ENDPROC
22787 END(__write_lock_failed)
22788 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22789 FRAME
22790 0: LOCK_PREFIX
22791 READ_LOCK_SIZE(inc) (%__lock_ptr)
22792 +
22793 +#ifdef CONFIG_PAX_REFCOUNT
22794 + jno 1234f
22795 + LOCK_PREFIX
22796 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22797 + int $4
22798 +1234:
22799 + _ASM_EXTABLE(1234b, 1234b)
22800 +#endif
22801 +
22802 1: rep; nop
22803 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22804 js 1b
22805 LOCK_PREFIX
22806 READ_LOCK_SIZE(dec) (%__lock_ptr)
22807 +
22808 +#ifdef CONFIG_PAX_REFCOUNT
22809 + jno 1234f
22810 + LOCK_PREFIX
22811 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22812 + int $4
22813 +1234:
22814 + _ASM_EXTABLE(1234b, 1234b)
22815 +#endif
22816 +
22817 js 0b
22818 ENDFRAME
22819 + pax_force_retaddr
22820 ret
22821 CFI_ENDPROC
22822 END(__read_lock_failed)
22823 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22824 index 5dff5f0..cadebf4 100644
22825 --- a/arch/x86/lib/rwsem.S
22826 +++ b/arch/x86/lib/rwsem.S
22827 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22828 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22829 CFI_RESTORE __ASM_REG(dx)
22830 restore_common_regs
22831 + pax_force_retaddr
22832 ret
22833 CFI_ENDPROC
22834 ENDPROC(call_rwsem_down_read_failed)
22835 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22836 movq %rax,%rdi
22837 call rwsem_down_write_failed
22838 restore_common_regs
22839 + pax_force_retaddr
22840 ret
22841 CFI_ENDPROC
22842 ENDPROC(call_rwsem_down_write_failed)
22843 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22844 movq %rax,%rdi
22845 call rwsem_wake
22846 restore_common_regs
22847 -1: ret
22848 +1: pax_force_retaddr
22849 + ret
22850 CFI_ENDPROC
22851 ENDPROC(call_rwsem_wake)
22852
22853 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22854 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22855 CFI_RESTORE __ASM_REG(dx)
22856 restore_common_regs
22857 + pax_force_retaddr
22858 ret
22859 CFI_ENDPROC
22860 ENDPROC(call_rwsem_downgrade_wake)
22861 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22862 index a63efd6..ccecad8 100644
22863 --- a/arch/x86/lib/thunk_64.S
22864 +++ b/arch/x86/lib/thunk_64.S
22865 @@ -8,6 +8,7 @@
22866 #include <linux/linkage.h>
22867 #include <asm/dwarf2.h>
22868 #include <asm/calling.h>
22869 +#include <asm/alternative-asm.h>
22870
22871 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22872 .macro THUNK name, func, put_ret_addr_in_rdi=0
22873 @@ -41,5 +42,6 @@
22874 SAVE_ARGS
22875 restore:
22876 RESTORE_ARGS
22877 + pax_force_retaddr
22878 ret
22879 CFI_ENDPROC
22880 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22881 index 1781b2f..90368dd 100644
22882 --- a/arch/x86/lib/usercopy_32.c
22883 +++ b/arch/x86/lib/usercopy_32.c
22884 @@ -42,10 +42,12 @@ do { \
22885 int __d0; \
22886 might_fault(); \
22887 __asm__ __volatile__( \
22888 + __COPYUSER_SET_ES \
22889 "0: rep; stosl\n" \
22890 " movl %2,%0\n" \
22891 "1: rep; stosb\n" \
22892 "2:\n" \
22893 + __COPYUSER_RESTORE_ES \
22894 ".section .fixup,\"ax\"\n" \
22895 "3: lea 0(%2,%0,4),%0\n" \
22896 " jmp 2b\n" \
22897 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22898
22899 #ifdef CONFIG_X86_INTEL_USERCOPY
22900 static unsigned long
22901 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22902 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22903 {
22904 int d0, d1;
22905 __asm__ __volatile__(
22906 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22907 " .align 2,0x90\n"
22908 "3: movl 0(%4), %%eax\n"
22909 "4: movl 4(%4), %%edx\n"
22910 - "5: movl %%eax, 0(%3)\n"
22911 - "6: movl %%edx, 4(%3)\n"
22912 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22913 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22914 "7: movl 8(%4), %%eax\n"
22915 "8: movl 12(%4),%%edx\n"
22916 - "9: movl %%eax, 8(%3)\n"
22917 - "10: movl %%edx, 12(%3)\n"
22918 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22919 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22920 "11: movl 16(%4), %%eax\n"
22921 "12: movl 20(%4), %%edx\n"
22922 - "13: movl %%eax, 16(%3)\n"
22923 - "14: movl %%edx, 20(%3)\n"
22924 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22925 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22926 "15: movl 24(%4), %%eax\n"
22927 "16: movl 28(%4), %%edx\n"
22928 - "17: movl %%eax, 24(%3)\n"
22929 - "18: movl %%edx, 28(%3)\n"
22930 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22931 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22932 "19: movl 32(%4), %%eax\n"
22933 "20: movl 36(%4), %%edx\n"
22934 - "21: movl %%eax, 32(%3)\n"
22935 - "22: movl %%edx, 36(%3)\n"
22936 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22937 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22938 "23: movl 40(%4), %%eax\n"
22939 "24: movl 44(%4), %%edx\n"
22940 - "25: movl %%eax, 40(%3)\n"
22941 - "26: movl %%edx, 44(%3)\n"
22942 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22943 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22944 "27: movl 48(%4), %%eax\n"
22945 "28: movl 52(%4), %%edx\n"
22946 - "29: movl %%eax, 48(%3)\n"
22947 - "30: movl %%edx, 52(%3)\n"
22948 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22949 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22950 "31: movl 56(%4), %%eax\n"
22951 "32: movl 60(%4), %%edx\n"
22952 - "33: movl %%eax, 56(%3)\n"
22953 - "34: movl %%edx, 60(%3)\n"
22954 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22955 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22956 " addl $-64, %0\n"
22957 " addl $64, %4\n"
22958 " addl $64, %3\n"
22959 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22960 " shrl $2, %0\n"
22961 " andl $3, %%eax\n"
22962 " cld\n"
22963 + __COPYUSER_SET_ES
22964 "99: rep; movsl\n"
22965 "36: movl %%eax, %0\n"
22966 "37: rep; movsb\n"
22967 "100:\n"
22968 + __COPYUSER_RESTORE_ES
22969 ".section .fixup,\"ax\"\n"
22970 "101: lea 0(%%eax,%0,4),%0\n"
22971 " jmp 100b\n"
22972 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22973 }
22974
22975 static unsigned long
22976 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22977 +{
22978 + int d0, d1;
22979 + __asm__ __volatile__(
22980 + " .align 2,0x90\n"
22981 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22982 + " cmpl $67, %0\n"
22983 + " jbe 3f\n"
22984 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22985 + " .align 2,0x90\n"
22986 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22987 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22988 + "5: movl %%eax, 0(%3)\n"
22989 + "6: movl %%edx, 4(%3)\n"
22990 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22991 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22992 + "9: movl %%eax, 8(%3)\n"
22993 + "10: movl %%edx, 12(%3)\n"
22994 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22995 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22996 + "13: movl %%eax, 16(%3)\n"
22997 + "14: movl %%edx, 20(%3)\n"
22998 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22999 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23000 + "17: movl %%eax, 24(%3)\n"
23001 + "18: movl %%edx, 28(%3)\n"
23002 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23003 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23004 + "21: movl %%eax, 32(%3)\n"
23005 + "22: movl %%edx, 36(%3)\n"
23006 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23007 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23008 + "25: movl %%eax, 40(%3)\n"
23009 + "26: movl %%edx, 44(%3)\n"
23010 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23011 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23012 + "29: movl %%eax, 48(%3)\n"
23013 + "30: movl %%edx, 52(%3)\n"
23014 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23015 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23016 + "33: movl %%eax, 56(%3)\n"
23017 + "34: movl %%edx, 60(%3)\n"
23018 + " addl $-64, %0\n"
23019 + " addl $64, %4\n"
23020 + " addl $64, %3\n"
23021 + " cmpl $63, %0\n"
23022 + " ja 1b\n"
23023 + "35: movl %0, %%eax\n"
23024 + " shrl $2, %0\n"
23025 + " andl $3, %%eax\n"
23026 + " cld\n"
23027 + "99: rep; "__copyuser_seg" movsl\n"
23028 + "36: movl %%eax, %0\n"
23029 + "37: rep; "__copyuser_seg" movsb\n"
23030 + "100:\n"
23031 + ".section .fixup,\"ax\"\n"
23032 + "101: lea 0(%%eax,%0,4),%0\n"
23033 + " jmp 100b\n"
23034 + ".previous\n"
23035 + _ASM_EXTABLE(1b,100b)
23036 + _ASM_EXTABLE(2b,100b)
23037 + _ASM_EXTABLE(3b,100b)
23038 + _ASM_EXTABLE(4b,100b)
23039 + _ASM_EXTABLE(5b,100b)
23040 + _ASM_EXTABLE(6b,100b)
23041 + _ASM_EXTABLE(7b,100b)
23042 + _ASM_EXTABLE(8b,100b)
23043 + _ASM_EXTABLE(9b,100b)
23044 + _ASM_EXTABLE(10b,100b)
23045 + _ASM_EXTABLE(11b,100b)
23046 + _ASM_EXTABLE(12b,100b)
23047 + _ASM_EXTABLE(13b,100b)
23048 + _ASM_EXTABLE(14b,100b)
23049 + _ASM_EXTABLE(15b,100b)
23050 + _ASM_EXTABLE(16b,100b)
23051 + _ASM_EXTABLE(17b,100b)
23052 + _ASM_EXTABLE(18b,100b)
23053 + _ASM_EXTABLE(19b,100b)
23054 + _ASM_EXTABLE(20b,100b)
23055 + _ASM_EXTABLE(21b,100b)
23056 + _ASM_EXTABLE(22b,100b)
23057 + _ASM_EXTABLE(23b,100b)
23058 + _ASM_EXTABLE(24b,100b)
23059 + _ASM_EXTABLE(25b,100b)
23060 + _ASM_EXTABLE(26b,100b)
23061 + _ASM_EXTABLE(27b,100b)
23062 + _ASM_EXTABLE(28b,100b)
23063 + _ASM_EXTABLE(29b,100b)
23064 + _ASM_EXTABLE(30b,100b)
23065 + _ASM_EXTABLE(31b,100b)
23066 + _ASM_EXTABLE(32b,100b)
23067 + _ASM_EXTABLE(33b,100b)
23068 + _ASM_EXTABLE(34b,100b)
23069 + _ASM_EXTABLE(35b,100b)
23070 + _ASM_EXTABLE(36b,100b)
23071 + _ASM_EXTABLE(37b,100b)
23072 + _ASM_EXTABLE(99b,101b)
23073 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23074 + : "1"(to), "2"(from), "0"(size)
23075 + : "eax", "edx", "memory");
23076 + return size;
23077 +}
23078 +
23079 +static unsigned long __size_overflow(3)
23080 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23081 {
23082 int d0, d1;
23083 __asm__ __volatile__(
23084 " .align 2,0x90\n"
23085 - "0: movl 32(%4), %%eax\n"
23086 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23087 " cmpl $67, %0\n"
23088 " jbe 2f\n"
23089 - "1: movl 64(%4), %%eax\n"
23090 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23091 " .align 2,0x90\n"
23092 - "2: movl 0(%4), %%eax\n"
23093 - "21: movl 4(%4), %%edx\n"
23094 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23095 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23096 " movl %%eax, 0(%3)\n"
23097 " movl %%edx, 4(%3)\n"
23098 - "3: movl 8(%4), %%eax\n"
23099 - "31: movl 12(%4),%%edx\n"
23100 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23101 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23102 " movl %%eax, 8(%3)\n"
23103 " movl %%edx, 12(%3)\n"
23104 - "4: movl 16(%4), %%eax\n"
23105 - "41: movl 20(%4), %%edx\n"
23106 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23107 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23108 " movl %%eax, 16(%3)\n"
23109 " movl %%edx, 20(%3)\n"
23110 - "10: movl 24(%4), %%eax\n"
23111 - "51: movl 28(%4), %%edx\n"
23112 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23113 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23114 " movl %%eax, 24(%3)\n"
23115 " movl %%edx, 28(%3)\n"
23116 - "11: movl 32(%4), %%eax\n"
23117 - "61: movl 36(%4), %%edx\n"
23118 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23119 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23120 " movl %%eax, 32(%3)\n"
23121 " movl %%edx, 36(%3)\n"
23122 - "12: movl 40(%4), %%eax\n"
23123 - "71: movl 44(%4), %%edx\n"
23124 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23125 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23126 " movl %%eax, 40(%3)\n"
23127 " movl %%edx, 44(%3)\n"
23128 - "13: movl 48(%4), %%eax\n"
23129 - "81: movl 52(%4), %%edx\n"
23130 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23131 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23132 " movl %%eax, 48(%3)\n"
23133 " movl %%edx, 52(%3)\n"
23134 - "14: movl 56(%4), %%eax\n"
23135 - "91: movl 60(%4), %%edx\n"
23136 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23137 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23138 " movl %%eax, 56(%3)\n"
23139 " movl %%edx, 60(%3)\n"
23140 " addl $-64, %0\n"
23141 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23142 " shrl $2, %0\n"
23143 " andl $3, %%eax\n"
23144 " cld\n"
23145 - "6: rep; movsl\n"
23146 + "6: rep; "__copyuser_seg" movsl\n"
23147 " movl %%eax,%0\n"
23148 - "7: rep; movsb\n"
23149 + "7: rep; "__copyuser_seg" movsb\n"
23150 "8:\n"
23151 ".section .fixup,\"ax\"\n"
23152 "9: lea 0(%%eax,%0,4),%0\n"
23153 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23154 * hyoshiok@miraclelinux.com
23155 */
23156
23157 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23158 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23159 const void __user *from, unsigned long size)
23160 {
23161 int d0, d1;
23162
23163 __asm__ __volatile__(
23164 " .align 2,0x90\n"
23165 - "0: movl 32(%4), %%eax\n"
23166 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23167 " cmpl $67, %0\n"
23168 " jbe 2f\n"
23169 - "1: movl 64(%4), %%eax\n"
23170 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23171 " .align 2,0x90\n"
23172 - "2: movl 0(%4), %%eax\n"
23173 - "21: movl 4(%4), %%edx\n"
23174 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23175 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23176 " movnti %%eax, 0(%3)\n"
23177 " movnti %%edx, 4(%3)\n"
23178 - "3: movl 8(%4), %%eax\n"
23179 - "31: movl 12(%4),%%edx\n"
23180 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23181 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23182 " movnti %%eax, 8(%3)\n"
23183 " movnti %%edx, 12(%3)\n"
23184 - "4: movl 16(%4), %%eax\n"
23185 - "41: movl 20(%4), %%edx\n"
23186 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23187 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23188 " movnti %%eax, 16(%3)\n"
23189 " movnti %%edx, 20(%3)\n"
23190 - "10: movl 24(%4), %%eax\n"
23191 - "51: movl 28(%4), %%edx\n"
23192 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23193 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23194 " movnti %%eax, 24(%3)\n"
23195 " movnti %%edx, 28(%3)\n"
23196 - "11: movl 32(%4), %%eax\n"
23197 - "61: movl 36(%4), %%edx\n"
23198 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23199 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23200 " movnti %%eax, 32(%3)\n"
23201 " movnti %%edx, 36(%3)\n"
23202 - "12: movl 40(%4), %%eax\n"
23203 - "71: movl 44(%4), %%edx\n"
23204 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23205 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23206 " movnti %%eax, 40(%3)\n"
23207 " movnti %%edx, 44(%3)\n"
23208 - "13: movl 48(%4), %%eax\n"
23209 - "81: movl 52(%4), %%edx\n"
23210 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23211 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23212 " movnti %%eax, 48(%3)\n"
23213 " movnti %%edx, 52(%3)\n"
23214 - "14: movl 56(%4), %%eax\n"
23215 - "91: movl 60(%4), %%edx\n"
23216 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23217 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23218 " movnti %%eax, 56(%3)\n"
23219 " movnti %%edx, 60(%3)\n"
23220 " addl $-64, %0\n"
23221 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23222 " shrl $2, %0\n"
23223 " andl $3, %%eax\n"
23224 " cld\n"
23225 - "6: rep; movsl\n"
23226 + "6: rep; "__copyuser_seg" movsl\n"
23227 " movl %%eax,%0\n"
23228 - "7: rep; movsb\n"
23229 + "7: rep; "__copyuser_seg" movsb\n"
23230 "8:\n"
23231 ".section .fixup,\"ax\"\n"
23232 "9: lea 0(%%eax,%0,4),%0\n"
23233 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23234 return size;
23235 }
23236
23237 -static unsigned long __copy_user_intel_nocache(void *to,
23238 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23239 const void __user *from, unsigned long size)
23240 {
23241 int d0, d1;
23242
23243 __asm__ __volatile__(
23244 " .align 2,0x90\n"
23245 - "0: movl 32(%4), %%eax\n"
23246 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23247 " cmpl $67, %0\n"
23248 " jbe 2f\n"
23249 - "1: movl 64(%4), %%eax\n"
23250 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23251 " .align 2,0x90\n"
23252 - "2: movl 0(%4), %%eax\n"
23253 - "21: movl 4(%4), %%edx\n"
23254 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23255 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23256 " movnti %%eax, 0(%3)\n"
23257 " movnti %%edx, 4(%3)\n"
23258 - "3: movl 8(%4), %%eax\n"
23259 - "31: movl 12(%4),%%edx\n"
23260 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23261 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23262 " movnti %%eax, 8(%3)\n"
23263 " movnti %%edx, 12(%3)\n"
23264 - "4: movl 16(%4), %%eax\n"
23265 - "41: movl 20(%4), %%edx\n"
23266 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23267 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23268 " movnti %%eax, 16(%3)\n"
23269 " movnti %%edx, 20(%3)\n"
23270 - "10: movl 24(%4), %%eax\n"
23271 - "51: movl 28(%4), %%edx\n"
23272 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23273 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23274 " movnti %%eax, 24(%3)\n"
23275 " movnti %%edx, 28(%3)\n"
23276 - "11: movl 32(%4), %%eax\n"
23277 - "61: movl 36(%4), %%edx\n"
23278 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23279 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23280 " movnti %%eax, 32(%3)\n"
23281 " movnti %%edx, 36(%3)\n"
23282 - "12: movl 40(%4), %%eax\n"
23283 - "71: movl 44(%4), %%edx\n"
23284 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23285 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23286 " movnti %%eax, 40(%3)\n"
23287 " movnti %%edx, 44(%3)\n"
23288 - "13: movl 48(%4), %%eax\n"
23289 - "81: movl 52(%4), %%edx\n"
23290 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23291 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23292 " movnti %%eax, 48(%3)\n"
23293 " movnti %%edx, 52(%3)\n"
23294 - "14: movl 56(%4), %%eax\n"
23295 - "91: movl 60(%4), %%edx\n"
23296 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23297 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23298 " movnti %%eax, 56(%3)\n"
23299 " movnti %%edx, 60(%3)\n"
23300 " addl $-64, %0\n"
23301 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23302 " shrl $2, %0\n"
23303 " andl $3, %%eax\n"
23304 " cld\n"
23305 - "6: rep; movsl\n"
23306 + "6: rep; "__copyuser_seg" movsl\n"
23307 " movl %%eax,%0\n"
23308 - "7: rep; movsb\n"
23309 + "7: rep; "__copyuser_seg" movsb\n"
23310 "8:\n"
23311 ".section .fixup,\"ax\"\n"
23312 "9: lea 0(%%eax,%0,4),%0\n"
23313 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23314 */
23315 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23316 unsigned long size);
23317 -unsigned long __copy_user_intel(void __user *to, const void *from,
23318 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23319 + unsigned long size);
23320 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23321 unsigned long size);
23322 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23323 const void __user *from, unsigned long size);
23324 #endif /* CONFIG_X86_INTEL_USERCOPY */
23325
23326 /* Generic arbitrary sized copy. */
23327 -#define __copy_user(to, from, size) \
23328 +#define __copy_user(to, from, size, prefix, set, restore) \
23329 do { \
23330 int __d0, __d1, __d2; \
23331 __asm__ __volatile__( \
23332 + set \
23333 " cmp $7,%0\n" \
23334 " jbe 1f\n" \
23335 " movl %1,%0\n" \
23336 " negl %0\n" \
23337 " andl $7,%0\n" \
23338 " subl %0,%3\n" \
23339 - "4: rep; movsb\n" \
23340 + "4: rep; "prefix"movsb\n" \
23341 " movl %3,%0\n" \
23342 " shrl $2,%0\n" \
23343 " andl $3,%3\n" \
23344 " .align 2,0x90\n" \
23345 - "0: rep; movsl\n" \
23346 + "0: rep; "prefix"movsl\n" \
23347 " movl %3,%0\n" \
23348 - "1: rep; movsb\n" \
23349 + "1: rep; "prefix"movsb\n" \
23350 "2:\n" \
23351 + restore \
23352 ".section .fixup,\"ax\"\n" \
23353 "5: addl %3,%0\n" \
23354 " jmp 2b\n" \
23355 @@ -537,14 +649,14 @@ do { \
23356 " negl %0\n" \
23357 " andl $7,%0\n" \
23358 " subl %0,%3\n" \
23359 - "4: rep; movsb\n" \
23360 + "4: rep; "__copyuser_seg"movsb\n" \
23361 " movl %3,%0\n" \
23362 " shrl $2,%0\n" \
23363 " andl $3,%3\n" \
23364 " .align 2,0x90\n" \
23365 - "0: rep; movsl\n" \
23366 + "0: rep; "__copyuser_seg"movsl\n" \
23367 " movl %3,%0\n" \
23368 - "1: rep; movsb\n" \
23369 + "1: rep; "__copyuser_seg"movsb\n" \
23370 "2:\n" \
23371 ".section .fixup,\"ax\"\n" \
23372 "5: addl %3,%0\n" \
23373 @@ -627,9 +739,9 @@ survive:
23374 }
23375 #endif
23376 if (movsl_is_ok(to, from, n))
23377 - __copy_user(to, from, n);
23378 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23379 else
23380 - n = __copy_user_intel(to, from, n);
23381 + n = __generic_copy_to_user_intel(to, from, n);
23382 return n;
23383 }
23384 EXPORT_SYMBOL(__copy_to_user_ll);
23385 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23386 unsigned long n)
23387 {
23388 if (movsl_is_ok(to, from, n))
23389 - __copy_user(to, from, n);
23390 + __copy_user(to, from, n, __copyuser_seg, "", "");
23391 else
23392 - n = __copy_user_intel((void __user *)to,
23393 - (const void *)from, n);
23394 + n = __generic_copy_from_user_intel(to, from, n);
23395 return n;
23396 }
23397 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23398 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23399 if (n > 64 && cpu_has_xmm2)
23400 n = __copy_user_intel_nocache(to, from, n);
23401 else
23402 - __copy_user(to, from, n);
23403 + __copy_user(to, from, n, __copyuser_seg, "", "");
23404 #else
23405 - __copy_user(to, from, n);
23406 + __copy_user(to, from, n, __copyuser_seg, "", "");
23407 #endif
23408 return n;
23409 }
23410 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23411
23412 -/**
23413 - * copy_to_user: - Copy a block of data into user space.
23414 - * @to: Destination address, in user space.
23415 - * @from: Source address, in kernel space.
23416 - * @n: Number of bytes to copy.
23417 - *
23418 - * Context: User context only. This function may sleep.
23419 - *
23420 - * Copy data from kernel space to user space.
23421 - *
23422 - * Returns number of bytes that could not be copied.
23423 - * On success, this will be zero.
23424 - */
23425 -unsigned long
23426 -copy_to_user(void __user *to, const void *from, unsigned long n)
23427 -{
23428 - if (access_ok(VERIFY_WRITE, to, n))
23429 - n = __copy_to_user(to, from, n);
23430 - return n;
23431 -}
23432 -EXPORT_SYMBOL(copy_to_user);
23433 -
23434 -/**
23435 - * copy_from_user: - Copy a block of data from user space.
23436 - * @to: Destination address, in kernel space.
23437 - * @from: Source address, in user space.
23438 - * @n: Number of bytes to copy.
23439 - *
23440 - * Context: User context only. This function may sleep.
23441 - *
23442 - * Copy data from user space to kernel space.
23443 - *
23444 - * Returns number of bytes that could not be copied.
23445 - * On success, this will be zero.
23446 - *
23447 - * If some data could not be copied, this function will pad the copied
23448 - * data to the requested size using zero bytes.
23449 - */
23450 -unsigned long
23451 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23452 -{
23453 - if (access_ok(VERIFY_READ, from, n))
23454 - n = __copy_from_user(to, from, n);
23455 - else
23456 - memset(to, 0, n);
23457 - return n;
23458 -}
23459 -EXPORT_SYMBOL(_copy_from_user);
23460 -
23461 void copy_from_user_overflow(void)
23462 {
23463 WARN(1, "Buffer overflow detected!\n");
23464 }
23465 EXPORT_SYMBOL(copy_from_user_overflow);
23466 +
23467 +void copy_to_user_overflow(void)
23468 +{
23469 + WARN(1, "Buffer overflow detected!\n");
23470 +}
23471 +EXPORT_SYMBOL(copy_to_user_overflow);
23472 +
23473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23474 +void __set_fs(mm_segment_t x)
23475 +{
23476 + switch (x.seg) {
23477 + case 0:
23478 + loadsegment(gs, 0);
23479 + break;
23480 + case TASK_SIZE_MAX:
23481 + loadsegment(gs, __USER_DS);
23482 + break;
23483 + case -1UL:
23484 + loadsegment(gs, __KERNEL_DS);
23485 + break;
23486 + default:
23487 + BUG();
23488 + }
23489 + return;
23490 +}
23491 +EXPORT_SYMBOL(__set_fs);
23492 +
23493 +void set_fs(mm_segment_t x)
23494 +{
23495 + current_thread_info()->addr_limit = x;
23496 + __set_fs(x);
23497 +}
23498 +EXPORT_SYMBOL(set_fs);
23499 +#endif
23500 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23501 index e5b130b..6690d31 100644
23502 --- a/arch/x86/lib/usercopy_64.c
23503 +++ b/arch/x86/lib/usercopy_64.c
23504 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23505 {
23506 long __d0;
23507 might_fault();
23508 +
23509 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23510 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23511 + addr += PAX_USER_SHADOW_BASE;
23512 +#endif
23513 +
23514 /* no memory constraint because it doesn't change any memory gcc knows
23515 about */
23516 asm volatile(
23517 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23518 }
23519 EXPORT_SYMBOL(clear_user);
23520
23521 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23522 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23523 {
23524 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23525 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23526 - }
23527 - return len;
23528 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23529 +
23530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23531 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23532 + to += PAX_USER_SHADOW_BASE;
23533 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23534 + from += PAX_USER_SHADOW_BASE;
23535 +#endif
23536 +
23537 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23538 + }
23539 + return len;
23540 }
23541 EXPORT_SYMBOL(copy_in_user);
23542
23543 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23544 * it is not necessary to optimize tail handling.
23545 */
23546 unsigned long
23547 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23548 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23549 {
23550 char c;
23551 unsigned zero_len;
23552 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23553 break;
23554 return len;
23555 }
23556 +
23557 +void copy_from_user_overflow(void)
23558 +{
23559 + WARN(1, "Buffer overflow detected!\n");
23560 +}
23561 +EXPORT_SYMBOL(copy_from_user_overflow);
23562 +
23563 +void copy_to_user_overflow(void)
23564 +{
23565 + WARN(1, "Buffer overflow detected!\n");
23566 +}
23567 +EXPORT_SYMBOL(copy_to_user_overflow);
23568 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23569 index 903ec1e..c4166b2 100644
23570 --- a/arch/x86/mm/extable.c
23571 +++ b/arch/x86/mm/extable.c
23572 @@ -6,12 +6,24 @@
23573 static inline unsigned long
23574 ex_insn_addr(const struct exception_table_entry *x)
23575 {
23576 - return (unsigned long)&x->insn + x->insn;
23577 + unsigned long reloc = 0;
23578 +
23579 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23580 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23581 +#endif
23582 +
23583 + return (unsigned long)&x->insn + x->insn + reloc;
23584 }
23585 static inline unsigned long
23586 ex_fixup_addr(const struct exception_table_entry *x)
23587 {
23588 - return (unsigned long)&x->fixup + x->fixup;
23589 + unsigned long reloc = 0;
23590 +
23591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23592 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23593 +#endif
23594 +
23595 + return (unsigned long)&x->fixup + x->fixup + reloc;
23596 }
23597
23598 int fixup_exception(struct pt_regs *regs)
23599 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23600 unsigned long new_ip;
23601
23602 #ifdef CONFIG_PNPBIOS
23603 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23604 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23605 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23606 extern u32 pnp_bios_is_utter_crap;
23607 pnp_bios_is_utter_crap = 1;
23608 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23609 i += 4;
23610 p->fixup -= i;
23611 i += 4;
23612 +
23613 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23614 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23615 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23616 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23617 +#endif
23618 +
23619 }
23620 }
23621
23622 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23623 index 76dcd9d..e9dffde 100644
23624 --- a/arch/x86/mm/fault.c
23625 +++ b/arch/x86/mm/fault.c
23626 @@ -13,11 +13,18 @@
23627 #include <linux/perf_event.h> /* perf_sw_event */
23628 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23629 #include <linux/prefetch.h> /* prefetchw */
23630 +#include <linux/unistd.h>
23631 +#include <linux/compiler.h>
23632
23633 #include <asm/traps.h> /* dotraplinkage, ... */
23634 #include <asm/pgalloc.h> /* pgd_*(), ... */
23635 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23636 #include <asm/fixmap.h> /* VSYSCALL_START */
23637 +#include <asm/tlbflush.h>
23638 +
23639 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23640 +#include <asm/stacktrace.h>
23641 +#endif
23642
23643 /*
23644 * Page fault error code bits:
23645 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23646 int ret = 0;
23647
23648 /* kprobe_running() needs smp_processor_id() */
23649 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23650 + if (kprobes_built_in() && !user_mode(regs)) {
23651 preempt_disable();
23652 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23653 ret = 1;
23654 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23655 return !instr_lo || (instr_lo>>1) == 1;
23656 case 0x00:
23657 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23658 - if (probe_kernel_address(instr, opcode))
23659 + if (user_mode(regs)) {
23660 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23661 + return 0;
23662 + } else if (probe_kernel_address(instr, opcode))
23663 return 0;
23664
23665 *prefetch = (instr_lo == 0xF) &&
23666 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23667 while (instr < max_instr) {
23668 unsigned char opcode;
23669
23670 - if (probe_kernel_address(instr, opcode))
23671 + if (user_mode(regs)) {
23672 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23673 + break;
23674 + } else if (probe_kernel_address(instr, opcode))
23675 break;
23676
23677 instr++;
23678 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23679 force_sig_info(si_signo, &info, tsk);
23680 }
23681
23682 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23683 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23684 +#endif
23685 +
23686 +#ifdef CONFIG_PAX_EMUTRAMP
23687 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23688 +#endif
23689 +
23690 +#ifdef CONFIG_PAX_PAGEEXEC
23691 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23692 +{
23693 + pgd_t *pgd;
23694 + pud_t *pud;
23695 + pmd_t *pmd;
23696 +
23697 + pgd = pgd_offset(mm, address);
23698 + if (!pgd_present(*pgd))
23699 + return NULL;
23700 + pud = pud_offset(pgd, address);
23701 + if (!pud_present(*pud))
23702 + return NULL;
23703 + pmd = pmd_offset(pud, address);
23704 + if (!pmd_present(*pmd))
23705 + return NULL;
23706 + return pmd;
23707 +}
23708 +#endif
23709 +
23710 DEFINE_SPINLOCK(pgd_lock);
23711 LIST_HEAD(pgd_list);
23712
23713 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23714 for (address = VMALLOC_START & PMD_MASK;
23715 address >= TASK_SIZE && address < FIXADDR_TOP;
23716 address += PMD_SIZE) {
23717 +
23718 +#ifdef CONFIG_PAX_PER_CPU_PGD
23719 + unsigned long cpu;
23720 +#else
23721 struct page *page;
23722 +#endif
23723
23724 spin_lock(&pgd_lock);
23725 +
23726 +#ifdef CONFIG_PAX_PER_CPU_PGD
23727 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23728 + pgd_t *pgd = get_cpu_pgd(cpu);
23729 + pmd_t *ret;
23730 +#else
23731 list_for_each_entry(page, &pgd_list, lru) {
23732 + pgd_t *pgd = page_address(page);
23733 spinlock_t *pgt_lock;
23734 pmd_t *ret;
23735
23736 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23737 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23738
23739 spin_lock(pgt_lock);
23740 - ret = vmalloc_sync_one(page_address(page), address);
23741 +#endif
23742 +
23743 + ret = vmalloc_sync_one(pgd, address);
23744 +
23745 +#ifndef CONFIG_PAX_PER_CPU_PGD
23746 spin_unlock(pgt_lock);
23747 +#endif
23748
23749 if (!ret)
23750 break;
23751 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23752 * an interrupt in the middle of a task switch..
23753 */
23754 pgd_paddr = read_cr3();
23755 +
23756 +#ifdef CONFIG_PAX_PER_CPU_PGD
23757 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23758 +#endif
23759 +
23760 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23761 if (!pmd_k)
23762 return -1;
23763 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23764 * happen within a race in page table update. In the later
23765 * case just flush:
23766 */
23767 +
23768 +#ifdef CONFIG_PAX_PER_CPU_PGD
23769 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23770 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23771 +#else
23772 pgd = pgd_offset(current->active_mm, address);
23773 +#endif
23774 +
23775 pgd_ref = pgd_offset_k(address);
23776 if (pgd_none(*pgd_ref))
23777 return -1;
23778 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23779 static int is_errata100(struct pt_regs *regs, unsigned long address)
23780 {
23781 #ifdef CONFIG_X86_64
23782 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23783 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23784 return 1;
23785 #endif
23786 return 0;
23787 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23788 }
23789
23790 static const char nx_warning[] = KERN_CRIT
23791 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23792 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23793
23794 static void
23795 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23796 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23797 if (!oops_may_print())
23798 return;
23799
23800 - if (error_code & PF_INSTR) {
23801 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23802 unsigned int level;
23803
23804 pte_t *pte = lookup_address(address, &level);
23805
23806 if (pte && pte_present(*pte) && !pte_exec(*pte))
23807 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23808 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23809 }
23810
23811 +#ifdef CONFIG_PAX_KERNEXEC
23812 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23813 + if (current->signal->curr_ip)
23814 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23815 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23816 + else
23817 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23818 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23819 + }
23820 +#endif
23821 +
23822 printk(KERN_ALERT "BUG: unable to handle kernel ");
23823 if (address < PAGE_SIZE)
23824 printk(KERN_CONT "NULL pointer dereference");
23825 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23826 }
23827 #endif
23828
23829 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23830 + if (pax_is_fetch_fault(regs, error_code, address)) {
23831 +
23832 +#ifdef CONFIG_PAX_EMUTRAMP
23833 + switch (pax_handle_fetch_fault(regs)) {
23834 + case 2:
23835 + return;
23836 + }
23837 +#endif
23838 +
23839 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23840 + do_group_exit(SIGKILL);
23841 + }
23842 +#endif
23843 +
23844 if (unlikely(show_unhandled_signals))
23845 show_signal_msg(regs, error_code, address, tsk);
23846
23847 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23848 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23849 printk(KERN_ERR
23850 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23851 - tsk->comm, tsk->pid, address);
23852 + tsk->comm, task_pid_nr(tsk), address);
23853 code = BUS_MCEERR_AR;
23854 }
23855 #endif
23856 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23857 return 1;
23858 }
23859
23860 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23861 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23862 +{
23863 + pte_t *pte;
23864 + pmd_t *pmd;
23865 + spinlock_t *ptl;
23866 + unsigned char pte_mask;
23867 +
23868 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23869 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23870 + return 0;
23871 +
23872 + /* PaX: it's our fault, let's handle it if we can */
23873 +
23874 + /* PaX: take a look at read faults before acquiring any locks */
23875 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23876 + /* instruction fetch attempt from a protected page in user mode */
23877 + up_read(&mm->mmap_sem);
23878 +
23879 +#ifdef CONFIG_PAX_EMUTRAMP
23880 + switch (pax_handle_fetch_fault(regs)) {
23881 + case 2:
23882 + return 1;
23883 + }
23884 +#endif
23885 +
23886 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23887 + do_group_exit(SIGKILL);
23888 + }
23889 +
23890 + pmd = pax_get_pmd(mm, address);
23891 + if (unlikely(!pmd))
23892 + return 0;
23893 +
23894 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23895 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23896 + pte_unmap_unlock(pte, ptl);
23897 + return 0;
23898 + }
23899 +
23900 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23901 + /* write attempt to a protected page in user mode */
23902 + pte_unmap_unlock(pte, ptl);
23903 + return 0;
23904 + }
23905 +
23906 +#ifdef CONFIG_SMP
23907 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23908 +#else
23909 + if (likely(address > get_limit(regs->cs)))
23910 +#endif
23911 + {
23912 + set_pte(pte, pte_mkread(*pte));
23913 + __flush_tlb_one(address);
23914 + pte_unmap_unlock(pte, ptl);
23915 + up_read(&mm->mmap_sem);
23916 + return 1;
23917 + }
23918 +
23919 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23920 +
23921 + /*
23922 + * PaX: fill DTLB with user rights and retry
23923 + */
23924 + __asm__ __volatile__ (
23925 + "orb %2,(%1)\n"
23926 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23927 +/*
23928 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23929 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23930 + * page fault when examined during a TLB load attempt. this is true not only
23931 + * for PTEs holding a non-present entry but also present entries that will
23932 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23933 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23934 + * for our target pages since their PTEs are simply not in the TLBs at all.
23935 +
23936 + * the best thing in omitting it is that we gain around 15-20% speed in the
23937 + * fast path of the page fault handler and can get rid of tracing since we
23938 + * can no longer flush unintended entries.
23939 + */
23940 + "invlpg (%0)\n"
23941 +#endif
23942 + __copyuser_seg"testb $0,(%0)\n"
23943 + "xorb %3,(%1)\n"
23944 + :
23945 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23946 + : "memory", "cc");
23947 + pte_unmap_unlock(pte, ptl);
23948 + up_read(&mm->mmap_sem);
23949 + return 1;
23950 +}
23951 +#endif
23952 +
23953 /*
23954 * Handle a spurious fault caused by a stale TLB entry.
23955 *
23956 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23957 static inline int
23958 access_error(unsigned long error_code, struct vm_area_struct *vma)
23959 {
23960 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23961 + return 1;
23962 +
23963 if (error_code & PF_WRITE) {
23964 /* write, present and write, not present: */
23965 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23966 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23967 {
23968 struct vm_area_struct *vma;
23969 struct task_struct *tsk;
23970 - unsigned long address;
23971 struct mm_struct *mm;
23972 int fault;
23973 int write = error_code & PF_WRITE;
23974 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23975 (write ? FAULT_FLAG_WRITE : 0);
23976
23977 - tsk = current;
23978 - mm = tsk->mm;
23979 -
23980 /* Get the faulting address: */
23981 - address = read_cr2();
23982 + unsigned long address = read_cr2();
23983 +
23984 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23985 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23986 + if (!search_exception_tables(regs->ip)) {
23987 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23988 + bad_area_nosemaphore(regs, error_code, address);
23989 + return;
23990 + }
23991 + if (address < PAX_USER_SHADOW_BASE) {
23992 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23993 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23994 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23995 + } else
23996 + address -= PAX_USER_SHADOW_BASE;
23997 + }
23998 +#endif
23999 +
24000 + tsk = current;
24001 + mm = tsk->mm;
24002
24003 /*
24004 * Detect and handle instructions that would cause a page fault for
24005 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24006 * User-mode registers count as a user access even for any
24007 * potential system fault or CPU buglet:
24008 */
24009 - if (user_mode_vm(regs)) {
24010 + if (user_mode(regs)) {
24011 local_irq_enable();
24012 error_code |= PF_USER;
24013 } else {
24014 @@ -1132,6 +1339,11 @@ retry:
24015 might_sleep();
24016 }
24017
24018 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24019 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24020 + return;
24021 +#endif
24022 +
24023 vma = find_vma(mm, address);
24024 if (unlikely(!vma)) {
24025 bad_area(regs, error_code, address);
24026 @@ -1143,18 +1355,24 @@ retry:
24027 bad_area(regs, error_code, address);
24028 return;
24029 }
24030 - if (error_code & PF_USER) {
24031 - /*
24032 - * Accessing the stack below %sp is always a bug.
24033 - * The large cushion allows instructions like enter
24034 - * and pusha to work. ("enter $65535, $31" pushes
24035 - * 32 pointers and then decrements %sp by 65535.)
24036 - */
24037 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24038 - bad_area(regs, error_code, address);
24039 - return;
24040 - }
24041 + /*
24042 + * Accessing the stack below %sp is always a bug.
24043 + * The large cushion allows instructions like enter
24044 + * and pusha to work. ("enter $65535, $31" pushes
24045 + * 32 pointers and then decrements %sp by 65535.)
24046 + */
24047 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24048 + bad_area(regs, error_code, address);
24049 + return;
24050 }
24051 +
24052 +#ifdef CONFIG_PAX_SEGMEXEC
24053 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24054 + bad_area(regs, error_code, address);
24055 + return;
24056 + }
24057 +#endif
24058 +
24059 if (unlikely(expand_stack(vma, address))) {
24060 bad_area(regs, error_code, address);
24061 return;
24062 @@ -1209,3 +1427,292 @@ good_area:
24063
24064 up_read(&mm->mmap_sem);
24065 }
24066 +
24067 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24068 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24069 +{
24070 + struct mm_struct *mm = current->mm;
24071 + unsigned long ip = regs->ip;
24072 +
24073 + if (v8086_mode(regs))
24074 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24075 +
24076 +#ifdef CONFIG_PAX_PAGEEXEC
24077 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24078 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24079 + return true;
24080 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24081 + return true;
24082 + return false;
24083 + }
24084 +#endif
24085 +
24086 +#ifdef CONFIG_PAX_SEGMEXEC
24087 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24088 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24089 + return true;
24090 + return false;
24091 + }
24092 +#endif
24093 +
24094 + return false;
24095 +}
24096 +#endif
24097 +
24098 +#ifdef CONFIG_PAX_EMUTRAMP
24099 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24100 +{
24101 + int err;
24102 +
24103 + do { /* PaX: libffi trampoline emulation */
24104 + unsigned char mov, jmp;
24105 + unsigned int addr1, addr2;
24106 +
24107 +#ifdef CONFIG_X86_64
24108 + if ((regs->ip + 9) >> 32)
24109 + break;
24110 +#endif
24111 +
24112 + err = get_user(mov, (unsigned char __user *)regs->ip);
24113 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24114 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24115 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24116 +
24117 + if (err)
24118 + break;
24119 +
24120 + if (mov == 0xB8 && jmp == 0xE9) {
24121 + regs->ax = addr1;
24122 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24123 + return 2;
24124 + }
24125 + } while (0);
24126 +
24127 + do { /* PaX: gcc trampoline emulation #1 */
24128 + unsigned char mov1, mov2;
24129 + unsigned short jmp;
24130 + unsigned int addr1, addr2;
24131 +
24132 +#ifdef CONFIG_X86_64
24133 + if ((regs->ip + 11) >> 32)
24134 + break;
24135 +#endif
24136 +
24137 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24138 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24139 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24140 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24141 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24142 +
24143 + if (err)
24144 + break;
24145 +
24146 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24147 + regs->cx = addr1;
24148 + regs->ax = addr2;
24149 + regs->ip = addr2;
24150 + return 2;
24151 + }
24152 + } while (0);
24153 +
24154 + do { /* PaX: gcc trampoline emulation #2 */
24155 + unsigned char mov, jmp;
24156 + unsigned int addr1, addr2;
24157 +
24158 +#ifdef CONFIG_X86_64
24159 + if ((regs->ip + 9) >> 32)
24160 + break;
24161 +#endif
24162 +
24163 + err = get_user(mov, (unsigned char __user *)regs->ip);
24164 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24165 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24166 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24167 +
24168 + if (err)
24169 + break;
24170 +
24171 + if (mov == 0xB9 && jmp == 0xE9) {
24172 + regs->cx = addr1;
24173 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24174 + return 2;
24175 + }
24176 + } while (0);
24177 +
24178 + return 1; /* PaX in action */
24179 +}
24180 +
24181 +#ifdef CONFIG_X86_64
24182 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24183 +{
24184 + int err;
24185 +
24186 + do { /* PaX: libffi trampoline emulation */
24187 + unsigned short mov1, mov2, jmp1;
24188 + unsigned char stcclc, jmp2;
24189 + unsigned long addr1, addr2;
24190 +
24191 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24192 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24193 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24194 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24195 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24196 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24197 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24198 +
24199 + if (err)
24200 + break;
24201 +
24202 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24203 + regs->r11 = addr1;
24204 + regs->r10 = addr2;
24205 + if (stcclc == 0xF8)
24206 + regs->flags &= ~X86_EFLAGS_CF;
24207 + else
24208 + regs->flags |= X86_EFLAGS_CF;
24209 + regs->ip = addr1;
24210 + return 2;
24211 + }
24212 + } while (0);
24213 +
24214 + do { /* PaX: gcc trampoline emulation #1 */
24215 + unsigned short mov1, mov2, jmp1;
24216 + unsigned char jmp2;
24217 + unsigned int addr1;
24218 + unsigned long addr2;
24219 +
24220 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24221 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24222 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24223 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24224 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24225 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24226 +
24227 + if (err)
24228 + break;
24229 +
24230 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24231 + regs->r11 = addr1;
24232 + regs->r10 = addr2;
24233 + regs->ip = addr1;
24234 + return 2;
24235 + }
24236 + } while (0);
24237 +
24238 + do { /* PaX: gcc trampoline emulation #2 */
24239 + unsigned short mov1, mov2, jmp1;
24240 + unsigned char jmp2;
24241 + unsigned long addr1, addr2;
24242 +
24243 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24244 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24245 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24246 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24247 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24248 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24249 +
24250 + if (err)
24251 + break;
24252 +
24253 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24254 + regs->r11 = addr1;
24255 + regs->r10 = addr2;
24256 + regs->ip = addr1;
24257 + return 2;
24258 + }
24259 + } while (0);
24260 +
24261 + return 1; /* PaX in action */
24262 +}
24263 +#endif
24264 +
24265 +/*
24266 + * PaX: decide what to do with offenders (regs->ip = fault address)
24267 + *
24268 + * returns 1 when task should be killed
24269 + * 2 when gcc trampoline was detected
24270 + */
24271 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24272 +{
24273 + if (v8086_mode(regs))
24274 + return 1;
24275 +
24276 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24277 + return 1;
24278 +
24279 +#ifdef CONFIG_X86_32
24280 + return pax_handle_fetch_fault_32(regs);
24281 +#else
24282 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24283 + return pax_handle_fetch_fault_32(regs);
24284 + else
24285 + return pax_handle_fetch_fault_64(regs);
24286 +#endif
24287 +}
24288 +#endif
24289 +
24290 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24291 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24292 +{
24293 + long i;
24294 +
24295 + printk(KERN_ERR "PAX: bytes at PC: ");
24296 + for (i = 0; i < 20; i++) {
24297 + unsigned char c;
24298 + if (get_user(c, (unsigned char __force_user *)pc+i))
24299 + printk(KERN_CONT "?? ");
24300 + else
24301 + printk(KERN_CONT "%02x ", c);
24302 + }
24303 + printk("\n");
24304 +
24305 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24306 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24307 + unsigned long c;
24308 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24309 +#ifdef CONFIG_X86_32
24310 + printk(KERN_CONT "???????? ");
24311 +#else
24312 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24313 + printk(KERN_CONT "???????? ???????? ");
24314 + else
24315 + printk(KERN_CONT "???????????????? ");
24316 +#endif
24317 + } else {
24318 +#ifdef CONFIG_X86_64
24319 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24320 + printk(KERN_CONT "%08x ", (unsigned int)c);
24321 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24322 + } else
24323 +#endif
24324 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24325 + }
24326 + }
24327 + printk("\n");
24328 +}
24329 +#endif
24330 +
24331 +/**
24332 + * probe_kernel_write(): safely attempt to write to a location
24333 + * @dst: address to write to
24334 + * @src: pointer to the data that shall be written
24335 + * @size: size of the data chunk
24336 + *
24337 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24338 + * happens, handle that and return -EFAULT.
24339 + */
24340 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24341 +{
24342 + long ret;
24343 + mm_segment_t old_fs = get_fs();
24344 +
24345 + set_fs(KERNEL_DS);
24346 + pagefault_disable();
24347 + pax_open_kernel();
24348 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24349 + pax_close_kernel();
24350 + pagefault_enable();
24351 + set_fs(old_fs);
24352 +
24353 + return ret ? -EFAULT : 0;
24354 +}
24355 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24356 index dd74e46..7d26398 100644
24357 --- a/arch/x86/mm/gup.c
24358 +++ b/arch/x86/mm/gup.c
24359 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24360 addr = start;
24361 len = (unsigned long) nr_pages << PAGE_SHIFT;
24362 end = start + len;
24363 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24364 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24365 (void __user *)start, len)))
24366 return 0;
24367
24368 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24369 index 6f31ee5..8ee4164 100644
24370 --- a/arch/x86/mm/highmem_32.c
24371 +++ b/arch/x86/mm/highmem_32.c
24372 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24373 idx = type + KM_TYPE_NR*smp_processor_id();
24374 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24375 BUG_ON(!pte_none(*(kmap_pte-idx)));
24376 +
24377 + pax_open_kernel();
24378 set_pte(kmap_pte-idx, mk_pte(page, prot));
24379 + pax_close_kernel();
24380 +
24381 arch_flush_lazy_mmu_mode();
24382
24383 return (void *)vaddr;
24384 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24385 index b91e485..d00e7c9 100644
24386 --- a/arch/x86/mm/hugetlbpage.c
24387 +++ b/arch/x86/mm/hugetlbpage.c
24388 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24389 struct hstate *h = hstate_file(file);
24390 struct mm_struct *mm = current->mm;
24391 struct vm_area_struct *vma;
24392 - unsigned long start_addr;
24393 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24394 +
24395 +#ifdef CONFIG_PAX_SEGMEXEC
24396 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24397 + pax_task_size = SEGMEXEC_TASK_SIZE;
24398 +#endif
24399 +
24400 + pax_task_size -= PAGE_SIZE;
24401
24402 if (len > mm->cached_hole_size) {
24403 - start_addr = mm->free_area_cache;
24404 + start_addr = mm->free_area_cache;
24405 } else {
24406 - start_addr = TASK_UNMAPPED_BASE;
24407 - mm->cached_hole_size = 0;
24408 + start_addr = mm->mmap_base;
24409 + mm->cached_hole_size = 0;
24410 }
24411
24412 full_search:
24413 @@ -291,26 +298,27 @@ full_search:
24414
24415 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24416 /* At this point: (!vma || addr < vma->vm_end). */
24417 - if (TASK_SIZE - len < addr) {
24418 + if (pax_task_size - len < addr) {
24419 /*
24420 * Start a new search - just in case we missed
24421 * some holes.
24422 */
24423 - if (start_addr != TASK_UNMAPPED_BASE) {
24424 - start_addr = TASK_UNMAPPED_BASE;
24425 + if (start_addr != mm->mmap_base) {
24426 + start_addr = mm->mmap_base;
24427 mm->cached_hole_size = 0;
24428 goto full_search;
24429 }
24430 return -ENOMEM;
24431 }
24432 - if (!vma || addr + len <= vma->vm_start) {
24433 - mm->free_area_cache = addr + len;
24434 - return addr;
24435 - }
24436 + if (check_heap_stack_gap(vma, addr, len))
24437 + break;
24438 if (addr + mm->cached_hole_size < vma->vm_start)
24439 mm->cached_hole_size = vma->vm_start - addr;
24440 addr = ALIGN(vma->vm_end, huge_page_size(h));
24441 }
24442 +
24443 + mm->free_area_cache = addr + len;
24444 + return addr;
24445 }
24446
24447 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24448 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24449 struct mm_struct *mm = current->mm;
24450 struct vm_area_struct *vma;
24451 unsigned long base = mm->mmap_base;
24452 - unsigned long addr = addr0;
24453 + unsigned long addr;
24454 unsigned long largest_hole = mm->cached_hole_size;
24455 - unsigned long start_addr;
24456
24457 /* don't allow allocations above current base */
24458 if (mm->free_area_cache > base)
24459 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24460 largest_hole = 0;
24461 mm->free_area_cache = base;
24462 }
24463 -try_again:
24464 - start_addr = mm->free_area_cache;
24465
24466 /* make sure it can fit in the remaining address space */
24467 if (mm->free_area_cache < len)
24468 goto fail;
24469
24470 /* either no address requested or can't fit in requested address hole */
24471 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24472 + addr = mm->free_area_cache - len;
24473 do {
24474 + addr &= huge_page_mask(h);
24475 /*
24476 * Lookup failure means no vma is above this address,
24477 * i.e. return with success:
24478 @@ -351,10 +357,10 @@ try_again:
24479 if (!vma)
24480 return addr;
24481
24482 - if (addr + len <= vma->vm_start) {
24483 + if (check_heap_stack_gap(vma, addr, len)) {
24484 /* remember the address as a hint for next time */
24485 - mm->cached_hole_size = largest_hole;
24486 - return (mm->free_area_cache = addr);
24487 + mm->cached_hole_size = largest_hole;
24488 + return (mm->free_area_cache = addr);
24489 } else if (mm->free_area_cache == vma->vm_end) {
24490 /* pull free_area_cache down to the first hole */
24491 mm->free_area_cache = vma->vm_start;
24492 @@ -363,29 +369,34 @@ try_again:
24493
24494 /* remember the largest hole we saw so far */
24495 if (addr + largest_hole < vma->vm_start)
24496 - largest_hole = vma->vm_start - addr;
24497 + largest_hole = vma->vm_start - addr;
24498
24499 /* try just below the current vma->vm_start */
24500 - addr = (vma->vm_start - len) & huge_page_mask(h);
24501 - } while (len <= vma->vm_start);
24502 + addr = skip_heap_stack_gap(vma, len);
24503 + } while (!IS_ERR_VALUE(addr));
24504
24505 fail:
24506 /*
24507 - * if hint left us with no space for the requested
24508 - * mapping then try again:
24509 - */
24510 - if (start_addr != base) {
24511 - mm->free_area_cache = base;
24512 - largest_hole = 0;
24513 - goto try_again;
24514 - }
24515 - /*
24516 * A failed mmap() very likely causes application failure,
24517 * so fall back to the bottom-up function here. This scenario
24518 * can happen with large stack limits and large mmap()
24519 * allocations.
24520 */
24521 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24522 +
24523 +#ifdef CONFIG_PAX_SEGMEXEC
24524 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24525 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24526 + else
24527 +#endif
24528 +
24529 + mm->mmap_base = TASK_UNMAPPED_BASE;
24530 +
24531 +#ifdef CONFIG_PAX_RANDMMAP
24532 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24533 + mm->mmap_base += mm->delta_mmap;
24534 +#endif
24535 +
24536 + mm->free_area_cache = mm->mmap_base;
24537 mm->cached_hole_size = ~0UL;
24538 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24539 len, pgoff, flags);
24540 @@ -393,6 +404,7 @@ fail:
24541 /*
24542 * Restore the topdown base:
24543 */
24544 + mm->mmap_base = base;
24545 mm->free_area_cache = base;
24546 mm->cached_hole_size = ~0UL;
24547
24548 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24549 struct hstate *h = hstate_file(file);
24550 struct mm_struct *mm = current->mm;
24551 struct vm_area_struct *vma;
24552 + unsigned long pax_task_size = TASK_SIZE;
24553
24554 if (len & ~huge_page_mask(h))
24555 return -EINVAL;
24556 - if (len > TASK_SIZE)
24557 +
24558 +#ifdef CONFIG_PAX_SEGMEXEC
24559 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24560 + pax_task_size = SEGMEXEC_TASK_SIZE;
24561 +#endif
24562 +
24563 + pax_task_size -= PAGE_SIZE;
24564 +
24565 + if (len > pax_task_size)
24566 return -ENOMEM;
24567
24568 if (flags & MAP_FIXED) {
24569 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24570 if (addr) {
24571 addr = ALIGN(addr, huge_page_size(h));
24572 vma = find_vma(mm, addr);
24573 - if (TASK_SIZE - len >= addr &&
24574 - (!vma || addr + len <= vma->vm_start))
24575 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24576 return addr;
24577 }
24578 if (mm->get_unmapped_area == arch_get_unmapped_area)
24579 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24580 index d7aea41..f753ad2 100644
24581 --- a/arch/x86/mm/init.c
24582 +++ b/arch/x86/mm/init.c
24583 @@ -16,6 +16,8 @@
24584 #include <asm/tlb.h>
24585 #include <asm/proto.h>
24586 #include <asm/dma.h> /* for MAX_DMA_PFN */
24587 +#include <asm/desc.h>
24588 +#include <asm/bios_ebda.h>
24589
24590 unsigned long __initdata pgt_buf_start;
24591 unsigned long __meminitdata pgt_buf_end;
24592 @@ -44,7 +46,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
24593 {
24594 int i;
24595 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
24596 - unsigned long start = 0, good_end;
24597 + unsigned long start = 0x100000, good_end;
24598 phys_addr_t base;
24599
24600 for (i = 0; i < nr_range; i++) {
24601 @@ -321,10 +323,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24602 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24603 * mmio resources as well as potential bios/acpi data regions.
24604 */
24605 +
24606 +#ifdef CONFIG_GRKERNSEC_KMEM
24607 +static unsigned int ebda_start __read_only;
24608 +static unsigned int ebda_end __read_only;
24609 +#endif
24610 +
24611 int devmem_is_allowed(unsigned long pagenr)
24612 {
24613 - if (pagenr < 256)
24614 +#ifdef CONFIG_GRKERNSEC_KMEM
24615 + /* allow BDA */
24616 + if (!pagenr)
24617 return 1;
24618 + /* allow EBDA */
24619 + if (pagenr >= ebda_start && pagenr < ebda_end)
24620 + return 1;
24621 +#else
24622 + if (!pagenr)
24623 + return 1;
24624 +#ifdef CONFIG_VM86
24625 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24626 + return 1;
24627 +#endif
24628 +#endif
24629 +
24630 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24631 + return 1;
24632 +#ifdef CONFIG_GRKERNSEC_KMEM
24633 + /* throw out everything else below 1MB */
24634 + if (pagenr <= 256)
24635 + return 0;
24636 +#endif
24637 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24638 return 0;
24639 if (!page_is_ram(pagenr))
24640 @@ -381,8 +410,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24641 #endif
24642 }
24643
24644 +#ifdef CONFIG_GRKERNSEC_KMEM
24645 +static inline void gr_init_ebda(void)
24646 +{
24647 + unsigned int ebda_addr;
24648 + unsigned int ebda_size = 0;
24649 +
24650 + ebda_addr = get_bios_ebda();
24651 + if (ebda_addr) {
24652 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24653 + ebda_size <<= 10;
24654 + }
24655 + if (ebda_addr && ebda_size) {
24656 + ebda_start = ebda_addr >> PAGE_SHIFT;
24657 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24658 + } else {
24659 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24660 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24661 + }
24662 +}
24663 +#else
24664 +static inline void gr_init_ebda(void) { }
24665 +#endif
24666 +
24667 void free_initmem(void)
24668 {
24669 +#ifdef CONFIG_PAX_KERNEXEC
24670 +#ifdef CONFIG_X86_32
24671 + /* PaX: limit KERNEL_CS to actual size */
24672 + unsigned long addr, limit;
24673 + struct desc_struct d;
24674 + int cpu;
24675 +#else
24676 + pgd_t *pgd;
24677 + pud_t *pud;
24678 + pmd_t *pmd;
24679 + unsigned long addr, end;
24680 +#endif
24681 +#endif
24682 +
24683 + gr_init_ebda();
24684 +
24685 +#ifdef CONFIG_PAX_KERNEXEC
24686 +#ifdef CONFIG_X86_32
24687 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24688 + limit = (limit - 1UL) >> PAGE_SHIFT;
24689 +
24690 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24691 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24692 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24693 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24694 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
24695 + }
24696 +
24697 + /* PaX: make KERNEL_CS read-only */
24698 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24699 + if (!paravirt_enabled())
24700 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24701 +/*
24702 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24703 + pgd = pgd_offset_k(addr);
24704 + pud = pud_offset(pgd, addr);
24705 + pmd = pmd_offset(pud, addr);
24706 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24707 + }
24708 +*/
24709 +#ifdef CONFIG_X86_PAE
24710 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24711 +/*
24712 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24713 + pgd = pgd_offset_k(addr);
24714 + pud = pud_offset(pgd, addr);
24715 + pmd = pmd_offset(pud, addr);
24716 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24717 + }
24718 +*/
24719 +#endif
24720 +
24721 +#ifdef CONFIG_MODULES
24722 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24723 +#endif
24724 +
24725 +#else
24726 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24727 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24728 + pgd = pgd_offset_k(addr);
24729 + pud = pud_offset(pgd, addr);
24730 + pmd = pmd_offset(pud, addr);
24731 + if (!pmd_present(*pmd))
24732 + continue;
24733 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24734 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24735 + else
24736 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24737 + }
24738 +
24739 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24740 + end = addr + KERNEL_IMAGE_SIZE;
24741 + for (; addr < end; addr += PMD_SIZE) {
24742 + pgd = pgd_offset_k(addr);
24743 + pud = pud_offset(pgd, addr);
24744 + pmd = pmd_offset(pud, addr);
24745 + if (!pmd_present(*pmd))
24746 + continue;
24747 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24748 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24749 + }
24750 +#endif
24751 +
24752 + flush_tlb_all();
24753 +#endif
24754 +
24755 free_init_pages("unused kernel memory",
24756 (unsigned long)(&__init_begin),
24757 (unsigned long)(&__init_end));
24758 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24759 index 575d86f..4987469 100644
24760 --- a/arch/x86/mm/init_32.c
24761 +++ b/arch/x86/mm/init_32.c
24762 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24763 }
24764
24765 /*
24766 - * Creates a middle page table and puts a pointer to it in the
24767 - * given global directory entry. This only returns the gd entry
24768 - * in non-PAE compilation mode, since the middle layer is folded.
24769 - */
24770 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24771 -{
24772 - pud_t *pud;
24773 - pmd_t *pmd_table;
24774 -
24775 -#ifdef CONFIG_X86_PAE
24776 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24777 - if (after_bootmem)
24778 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24779 - else
24780 - pmd_table = (pmd_t *)alloc_low_page();
24781 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24782 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24783 - pud = pud_offset(pgd, 0);
24784 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24785 -
24786 - return pmd_table;
24787 - }
24788 -#endif
24789 - pud = pud_offset(pgd, 0);
24790 - pmd_table = pmd_offset(pud, 0);
24791 -
24792 - return pmd_table;
24793 -}
24794 -
24795 -/*
24796 * Create a page table and place a pointer to it in a middle page
24797 * directory entry:
24798 */
24799 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24800 page_table = (pte_t *)alloc_low_page();
24801
24802 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24803 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24804 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24805 +#else
24806 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24807 +#endif
24808 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24809 }
24810
24811 return pte_offset_kernel(pmd, 0);
24812 }
24813
24814 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24815 +{
24816 + pud_t *pud;
24817 + pmd_t *pmd_table;
24818 +
24819 + pud = pud_offset(pgd, 0);
24820 + pmd_table = pmd_offset(pud, 0);
24821 +
24822 + return pmd_table;
24823 +}
24824 +
24825 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24826 {
24827 int pgd_idx = pgd_index(vaddr);
24828 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24829 int pgd_idx, pmd_idx;
24830 unsigned long vaddr;
24831 pgd_t *pgd;
24832 + pud_t *pud;
24833 pmd_t *pmd;
24834 pte_t *pte = NULL;
24835
24836 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24837 pgd = pgd_base + pgd_idx;
24838
24839 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24840 - pmd = one_md_table_init(pgd);
24841 - pmd = pmd + pmd_index(vaddr);
24842 + pud = pud_offset(pgd, vaddr);
24843 + pmd = pmd_offset(pud, vaddr);
24844 +
24845 +#ifdef CONFIG_X86_PAE
24846 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24847 +#endif
24848 +
24849 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24850 pmd++, pmd_idx++) {
24851 pte = page_table_kmap_check(one_page_table_init(pmd),
24852 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24853 }
24854 }
24855
24856 -static inline int is_kernel_text(unsigned long addr)
24857 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24858 {
24859 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24860 - return 1;
24861 - return 0;
24862 + if ((start > ktla_ktva((unsigned long)_etext) ||
24863 + end <= ktla_ktva((unsigned long)_stext)) &&
24864 + (start > ktla_ktva((unsigned long)_einittext) ||
24865 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24866 +
24867 +#ifdef CONFIG_ACPI_SLEEP
24868 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24869 +#endif
24870 +
24871 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24872 + return 0;
24873 + return 1;
24874 }
24875
24876 /*
24877 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24878 unsigned long last_map_addr = end;
24879 unsigned long start_pfn, end_pfn;
24880 pgd_t *pgd_base = swapper_pg_dir;
24881 - int pgd_idx, pmd_idx, pte_ofs;
24882 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24883 unsigned long pfn;
24884 pgd_t *pgd;
24885 + pud_t *pud;
24886 pmd_t *pmd;
24887 pte_t *pte;
24888 unsigned pages_2m, pages_4k;
24889 @@ -280,8 +281,13 @@ repeat:
24890 pfn = start_pfn;
24891 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24892 pgd = pgd_base + pgd_idx;
24893 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24894 - pmd = one_md_table_init(pgd);
24895 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24896 + pud = pud_offset(pgd, 0);
24897 + pmd = pmd_offset(pud, 0);
24898 +
24899 +#ifdef CONFIG_X86_PAE
24900 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24901 +#endif
24902
24903 if (pfn >= end_pfn)
24904 continue;
24905 @@ -293,14 +299,13 @@ repeat:
24906 #endif
24907 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24908 pmd++, pmd_idx++) {
24909 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24910 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24911
24912 /*
24913 * Map with big pages if possible, otherwise
24914 * create normal page tables:
24915 */
24916 if (use_pse) {
24917 - unsigned int addr2;
24918 pgprot_t prot = PAGE_KERNEL_LARGE;
24919 /*
24920 * first pass will use the same initial
24921 @@ -310,11 +315,7 @@ repeat:
24922 __pgprot(PTE_IDENT_ATTR |
24923 _PAGE_PSE);
24924
24925 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24926 - PAGE_OFFSET + PAGE_SIZE-1;
24927 -
24928 - if (is_kernel_text(addr) ||
24929 - is_kernel_text(addr2))
24930 + if (is_kernel_text(address, address + PMD_SIZE))
24931 prot = PAGE_KERNEL_LARGE_EXEC;
24932
24933 pages_2m++;
24934 @@ -331,7 +332,7 @@ repeat:
24935 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24936 pte += pte_ofs;
24937 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24938 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24939 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24940 pgprot_t prot = PAGE_KERNEL;
24941 /*
24942 * first pass will use the same initial
24943 @@ -339,7 +340,7 @@ repeat:
24944 */
24945 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24946
24947 - if (is_kernel_text(addr))
24948 + if (is_kernel_text(address, address + PAGE_SIZE))
24949 prot = PAGE_KERNEL_EXEC;
24950
24951 pages_4k++;
24952 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24953
24954 pud = pud_offset(pgd, va);
24955 pmd = pmd_offset(pud, va);
24956 - if (!pmd_present(*pmd))
24957 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24958 break;
24959
24960 pte = pte_offset_kernel(pmd, va);
24961 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24962
24963 static void __init pagetable_init(void)
24964 {
24965 - pgd_t *pgd_base = swapper_pg_dir;
24966 -
24967 - permanent_kmaps_init(pgd_base);
24968 + permanent_kmaps_init(swapper_pg_dir);
24969 }
24970
24971 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24972 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24973 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24974
24975 /* user-defined highmem size */
24976 @@ -734,6 +733,12 @@ void __init mem_init(void)
24977
24978 pci_iommu_alloc();
24979
24980 +#ifdef CONFIG_PAX_PER_CPU_PGD
24981 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24982 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24983 + KERNEL_PGD_PTRS);
24984 +#endif
24985 +
24986 #ifdef CONFIG_FLATMEM
24987 BUG_ON(!mem_map);
24988 #endif
24989 @@ -760,7 +765,7 @@ void __init mem_init(void)
24990 reservedpages++;
24991
24992 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24993 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24994 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24995 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24996
24997 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24998 @@ -801,10 +806,10 @@ void __init mem_init(void)
24999 ((unsigned long)&__init_end -
25000 (unsigned long)&__init_begin) >> 10,
25001
25002 - (unsigned long)&_etext, (unsigned long)&_edata,
25003 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25004 + (unsigned long)&_sdata, (unsigned long)&_edata,
25005 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25006
25007 - (unsigned long)&_text, (unsigned long)&_etext,
25008 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25009 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25010
25011 /*
25012 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25013 if (!kernel_set_to_readonly)
25014 return;
25015
25016 + start = ktla_ktva(start);
25017 pr_debug("Set kernel text: %lx - %lx for read write\n",
25018 start, start+size);
25019
25020 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25021 if (!kernel_set_to_readonly)
25022 return;
25023
25024 + start = ktla_ktva(start);
25025 pr_debug("Set kernel text: %lx - %lx for read only\n",
25026 start, start+size);
25027
25028 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25029 unsigned long start = PFN_ALIGN(_text);
25030 unsigned long size = PFN_ALIGN(_etext) - start;
25031
25032 + start = ktla_ktva(start);
25033 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25034 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25035 size >> 10);
25036 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25037 index 3baff25..8b37564 100644
25038 --- a/arch/x86/mm/init_64.c
25039 +++ b/arch/x86/mm/init_64.c
25040 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25041 * around without checking the pgd every time.
25042 */
25043
25044 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25045 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25046 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25047
25048 int force_personality32;
25049 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25050
25051 for (address = start; address <= end; address += PGDIR_SIZE) {
25052 const pgd_t *pgd_ref = pgd_offset_k(address);
25053 +
25054 +#ifdef CONFIG_PAX_PER_CPU_PGD
25055 + unsigned long cpu;
25056 +#else
25057 struct page *page;
25058 +#endif
25059
25060 if (pgd_none(*pgd_ref))
25061 continue;
25062
25063 spin_lock(&pgd_lock);
25064 +
25065 +#ifdef CONFIG_PAX_PER_CPU_PGD
25066 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25067 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25068 +#else
25069 list_for_each_entry(page, &pgd_list, lru) {
25070 pgd_t *pgd;
25071 spinlock_t *pgt_lock;
25072 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25073 /* the pgt_lock only for Xen */
25074 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25075 spin_lock(pgt_lock);
25076 +#endif
25077
25078 if (pgd_none(*pgd))
25079 set_pgd(pgd, *pgd_ref);
25080 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25081 BUG_ON(pgd_page_vaddr(*pgd)
25082 != pgd_page_vaddr(*pgd_ref));
25083
25084 +#ifndef CONFIG_PAX_PER_CPU_PGD
25085 spin_unlock(pgt_lock);
25086 +#endif
25087 +
25088 }
25089 spin_unlock(&pgd_lock);
25090 }
25091 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25092 {
25093 if (pgd_none(*pgd)) {
25094 pud_t *pud = (pud_t *)spp_getpage();
25095 - pgd_populate(&init_mm, pgd, pud);
25096 + pgd_populate_kernel(&init_mm, pgd, pud);
25097 if (pud != pud_offset(pgd, 0))
25098 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25099 pud, pud_offset(pgd, 0));
25100 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25101 {
25102 if (pud_none(*pud)) {
25103 pmd_t *pmd = (pmd_t *) spp_getpage();
25104 - pud_populate(&init_mm, pud, pmd);
25105 + pud_populate_kernel(&init_mm, pud, pmd);
25106 if (pmd != pmd_offset(pud, 0))
25107 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25108 pmd, pmd_offset(pud, 0));
25109 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25110 pmd = fill_pmd(pud, vaddr);
25111 pte = fill_pte(pmd, vaddr);
25112
25113 + pax_open_kernel();
25114 set_pte(pte, new_pte);
25115 + pax_close_kernel();
25116
25117 /*
25118 * It's enough to flush this one mapping.
25119 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25120 pgd = pgd_offset_k((unsigned long)__va(phys));
25121 if (pgd_none(*pgd)) {
25122 pud = (pud_t *) spp_getpage();
25123 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25124 - _PAGE_USER));
25125 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25126 }
25127 pud = pud_offset(pgd, (unsigned long)__va(phys));
25128 if (pud_none(*pud)) {
25129 pmd = (pmd_t *) spp_getpage();
25130 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25131 - _PAGE_USER));
25132 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25133 }
25134 pmd = pmd_offset(pud, phys);
25135 BUG_ON(!pmd_none(*pmd));
25136 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25137 if (pfn >= pgt_buf_top)
25138 panic("alloc_low_page: ran out of memory");
25139
25140 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25141 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25142 clear_page(adr);
25143 *phys = pfn * PAGE_SIZE;
25144 return adr;
25145 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25146
25147 phys = __pa(virt);
25148 left = phys & (PAGE_SIZE - 1);
25149 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25150 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25151 adr = (void *)(((unsigned long)adr) | left);
25152
25153 return adr;
25154 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25155 unmap_low_page(pmd);
25156
25157 spin_lock(&init_mm.page_table_lock);
25158 - pud_populate(&init_mm, pud, __va(pmd_phys));
25159 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25160 spin_unlock(&init_mm.page_table_lock);
25161 }
25162 __flush_tlb_all();
25163 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
25164 unmap_low_page(pud);
25165
25166 spin_lock(&init_mm.page_table_lock);
25167 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25168 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25169 spin_unlock(&init_mm.page_table_lock);
25170 pgd_changed = true;
25171 }
25172 @@ -691,6 +705,12 @@ void __init mem_init(void)
25173
25174 pci_iommu_alloc();
25175
25176 +#ifdef CONFIG_PAX_PER_CPU_PGD
25177 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25178 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25179 + KERNEL_PGD_PTRS);
25180 +#endif
25181 +
25182 /* clear_bss() already clear the empty_zero_page */
25183
25184 reservedpages = 0;
25185 @@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
25186 static struct vm_area_struct gate_vma = {
25187 .vm_start = VSYSCALL_START,
25188 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25189 - .vm_page_prot = PAGE_READONLY_EXEC,
25190 - .vm_flags = VM_READ | VM_EXEC
25191 + .vm_page_prot = PAGE_READONLY,
25192 + .vm_flags = VM_READ
25193 };
25194
25195 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25196 @@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
25197
25198 const char *arch_vma_name(struct vm_area_struct *vma)
25199 {
25200 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25201 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25202 return "[vdso]";
25203 if (vma == &gate_vma)
25204 return "[vsyscall]";
25205 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25206 index 7b179b4..6bd1777 100644
25207 --- a/arch/x86/mm/iomap_32.c
25208 +++ b/arch/x86/mm/iomap_32.c
25209 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25210 type = kmap_atomic_idx_push();
25211 idx = type + KM_TYPE_NR * smp_processor_id();
25212 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25213 +
25214 + pax_open_kernel();
25215 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25216 + pax_close_kernel();
25217 +
25218 arch_flush_lazy_mmu_mode();
25219
25220 return (void *)vaddr;
25221 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25222 index 78fe3f1..8293b6f 100644
25223 --- a/arch/x86/mm/ioremap.c
25224 +++ b/arch/x86/mm/ioremap.c
25225 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25226 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25227 int is_ram = page_is_ram(pfn);
25228
25229 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25230 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25231 return NULL;
25232 WARN_ON_ONCE(is_ram);
25233 }
25234 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25235
25236 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25237 if (page_is_ram(start >> PAGE_SHIFT))
25238 +#ifdef CONFIG_HIGHMEM
25239 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25240 +#endif
25241 return __va(phys);
25242
25243 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25244 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25245 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25246
25247 static __initdata int after_paging_init;
25248 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25249 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25250
25251 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25252 {
25253 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25254 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25255
25256 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25257 - memset(bm_pte, 0, sizeof(bm_pte));
25258 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25259 + pmd_populate_user(&init_mm, pmd, bm_pte);
25260
25261 /*
25262 * The boot-ioremap range spans multiple pmds, for which
25263 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25264 index d87dd6d..bf3fa66 100644
25265 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25266 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25267 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25268 * memory (e.g. tracked pages)? For now, we need this to avoid
25269 * invoking kmemcheck for PnP BIOS calls.
25270 */
25271 - if (regs->flags & X86_VM_MASK)
25272 + if (v8086_mode(regs))
25273 return false;
25274 - if (regs->cs != __KERNEL_CS)
25275 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25276 return false;
25277
25278 pte = kmemcheck_pte_lookup(address);
25279 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25280 index 845df68..1d8d29f 100644
25281 --- a/arch/x86/mm/mmap.c
25282 +++ b/arch/x86/mm/mmap.c
25283 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25284 * Leave an at least ~128 MB hole with possible stack randomization.
25285 */
25286 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25287 -#define MAX_GAP (TASK_SIZE/6*5)
25288 +#define MAX_GAP (pax_task_size/6*5)
25289
25290 static int mmap_is_legacy(void)
25291 {
25292 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25293 return rnd << PAGE_SHIFT;
25294 }
25295
25296 -static unsigned long mmap_base(void)
25297 +static unsigned long mmap_base(struct mm_struct *mm)
25298 {
25299 unsigned long gap = rlimit(RLIMIT_STACK);
25300 + unsigned long pax_task_size = TASK_SIZE;
25301 +
25302 +#ifdef CONFIG_PAX_SEGMEXEC
25303 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25304 + pax_task_size = SEGMEXEC_TASK_SIZE;
25305 +#endif
25306
25307 if (gap < MIN_GAP)
25308 gap = MIN_GAP;
25309 else if (gap > MAX_GAP)
25310 gap = MAX_GAP;
25311
25312 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25313 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25314 }
25315
25316 /*
25317 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25318 * does, but not when emulating X86_32
25319 */
25320 -static unsigned long mmap_legacy_base(void)
25321 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25322 {
25323 - if (mmap_is_ia32())
25324 + if (mmap_is_ia32()) {
25325 +
25326 +#ifdef CONFIG_PAX_SEGMEXEC
25327 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25328 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25329 + else
25330 +#endif
25331 +
25332 return TASK_UNMAPPED_BASE;
25333 - else
25334 + } else
25335 return TASK_UNMAPPED_BASE + mmap_rnd();
25336 }
25337
25338 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25339 void arch_pick_mmap_layout(struct mm_struct *mm)
25340 {
25341 if (mmap_is_legacy()) {
25342 - mm->mmap_base = mmap_legacy_base();
25343 + mm->mmap_base = mmap_legacy_base(mm);
25344 +
25345 +#ifdef CONFIG_PAX_RANDMMAP
25346 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25347 + mm->mmap_base += mm->delta_mmap;
25348 +#endif
25349 +
25350 mm->get_unmapped_area = arch_get_unmapped_area;
25351 mm->unmap_area = arch_unmap_area;
25352 } else {
25353 - mm->mmap_base = mmap_base();
25354 + mm->mmap_base = mmap_base(mm);
25355 +
25356 +#ifdef CONFIG_PAX_RANDMMAP
25357 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25358 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25359 +#endif
25360 +
25361 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25362 mm->unmap_area = arch_unmap_area_topdown;
25363 }
25364 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25365 index dc0b727..dc9d71a 100644
25366 --- a/arch/x86/mm/mmio-mod.c
25367 +++ b/arch/x86/mm/mmio-mod.c
25368 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25369 break;
25370 default:
25371 {
25372 - unsigned char *ip = (unsigned char *)instptr;
25373 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25374 my_trace->opcode = MMIO_UNKNOWN_OP;
25375 my_trace->width = 0;
25376 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25377 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25378 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25379 void __iomem *addr)
25380 {
25381 - static atomic_t next_id;
25382 + static atomic_unchecked_t next_id;
25383 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25384 /* These are page-unaligned. */
25385 struct mmiotrace_map map = {
25386 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25387 .private = trace
25388 },
25389 .phys = offset,
25390 - .id = atomic_inc_return(&next_id)
25391 + .id = atomic_inc_return_unchecked(&next_id)
25392 };
25393 map.map_id = trace->id;
25394
25395 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25396 index b008656..773eac2 100644
25397 --- a/arch/x86/mm/pageattr-test.c
25398 +++ b/arch/x86/mm/pageattr-test.c
25399 @@ -36,7 +36,7 @@ enum {
25400
25401 static int pte_testbit(pte_t pte)
25402 {
25403 - return pte_flags(pte) & _PAGE_UNUSED1;
25404 + return pte_flags(pte) & _PAGE_CPA_TEST;
25405 }
25406
25407 struct split_state {
25408 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25409 index a718e0d..45efc32 100644
25410 --- a/arch/x86/mm/pageattr.c
25411 +++ b/arch/x86/mm/pageattr.c
25412 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25413 */
25414 #ifdef CONFIG_PCI_BIOS
25415 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25416 - pgprot_val(forbidden) |= _PAGE_NX;
25417 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25418 #endif
25419
25420 /*
25421 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25422 * Does not cover __inittext since that is gone later on. On
25423 * 64bit we do not enforce !NX on the low mapping
25424 */
25425 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25426 - pgprot_val(forbidden) |= _PAGE_NX;
25427 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25428 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25429
25430 +#ifdef CONFIG_DEBUG_RODATA
25431 /*
25432 * The .rodata section needs to be read-only. Using the pfn
25433 * catches all aliases.
25434 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25435 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25436 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25437 pgprot_val(forbidden) |= _PAGE_RW;
25438 +#endif
25439
25440 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25441 /*
25442 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25443 }
25444 #endif
25445
25446 +#ifdef CONFIG_PAX_KERNEXEC
25447 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25448 + pgprot_val(forbidden) |= _PAGE_RW;
25449 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25450 + }
25451 +#endif
25452 +
25453 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25454
25455 return prot;
25456 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25457 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25458 {
25459 /* change init_mm */
25460 + pax_open_kernel();
25461 set_pte_atomic(kpte, pte);
25462 +
25463 #ifdef CONFIG_X86_32
25464 if (!SHARED_KERNEL_PMD) {
25465 +
25466 +#ifdef CONFIG_PAX_PER_CPU_PGD
25467 + unsigned long cpu;
25468 +#else
25469 struct page *page;
25470 +#endif
25471
25472 +#ifdef CONFIG_PAX_PER_CPU_PGD
25473 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25474 + pgd_t *pgd = get_cpu_pgd(cpu);
25475 +#else
25476 list_for_each_entry(page, &pgd_list, lru) {
25477 - pgd_t *pgd;
25478 + pgd_t *pgd = (pgd_t *)page_address(page);
25479 +#endif
25480 +
25481 pud_t *pud;
25482 pmd_t *pmd;
25483
25484 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25485 + pgd += pgd_index(address);
25486 pud = pud_offset(pgd, address);
25487 pmd = pmd_offset(pud, address);
25488 set_pte_atomic((pte_t *)pmd, pte);
25489 }
25490 }
25491 #endif
25492 + pax_close_kernel();
25493 }
25494
25495 static int
25496 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25497 index 3d68ef6..7f69136 100644
25498 --- a/arch/x86/mm/pat.c
25499 +++ b/arch/x86/mm/pat.c
25500 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25501
25502 if (!entry) {
25503 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25504 - current->comm, current->pid, start, end - 1);
25505 + current->comm, task_pid_nr(current), start, end - 1);
25506 return -EINVAL;
25507 }
25508
25509 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25510
25511 while (cursor < to) {
25512 if (!devmem_is_allowed(pfn)) {
25513 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25514 - current->comm, from, to - 1);
25515 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25516 + current->comm, from, to - 1, cursor);
25517 return 0;
25518 }
25519 cursor += PAGE_SIZE;
25520 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25521 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25522 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25523 "for [mem %#010Lx-%#010Lx]\n",
25524 - current->comm, current->pid,
25525 + current->comm, task_pid_nr(current),
25526 cattr_name(flags),
25527 base, (unsigned long long)(base + size-1));
25528 return -EINVAL;
25529 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25530 flags = lookup_memtype(paddr);
25531 if (want_flags != flags) {
25532 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25533 - current->comm, current->pid,
25534 + current->comm, task_pid_nr(current),
25535 cattr_name(want_flags),
25536 (unsigned long long)paddr,
25537 (unsigned long long)(paddr + size - 1),
25538 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25539 free_memtype(paddr, paddr + size);
25540 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25541 " for [mem %#010Lx-%#010Lx], got %s\n",
25542 - current->comm, current->pid,
25543 + current->comm, task_pid_nr(current),
25544 cattr_name(want_flags),
25545 (unsigned long long)paddr,
25546 (unsigned long long)(paddr + size - 1),
25547 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25548 index 9f0614d..92ae64a 100644
25549 --- a/arch/x86/mm/pf_in.c
25550 +++ b/arch/x86/mm/pf_in.c
25551 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25552 int i;
25553 enum reason_type rv = OTHERS;
25554
25555 - p = (unsigned char *)ins_addr;
25556 + p = (unsigned char *)ktla_ktva(ins_addr);
25557 p += skip_prefix(p, &prf);
25558 p += get_opcode(p, &opcode);
25559
25560 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25561 struct prefix_bits prf;
25562 int i;
25563
25564 - p = (unsigned char *)ins_addr;
25565 + p = (unsigned char *)ktla_ktva(ins_addr);
25566 p += skip_prefix(p, &prf);
25567 p += get_opcode(p, &opcode);
25568
25569 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25570 struct prefix_bits prf;
25571 int i;
25572
25573 - p = (unsigned char *)ins_addr;
25574 + p = (unsigned char *)ktla_ktva(ins_addr);
25575 p += skip_prefix(p, &prf);
25576 p += get_opcode(p, &opcode);
25577
25578 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25579 struct prefix_bits prf;
25580 int i;
25581
25582 - p = (unsigned char *)ins_addr;
25583 + p = (unsigned char *)ktla_ktva(ins_addr);
25584 p += skip_prefix(p, &prf);
25585 p += get_opcode(p, &opcode);
25586 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25587 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25588 struct prefix_bits prf;
25589 int i;
25590
25591 - p = (unsigned char *)ins_addr;
25592 + p = (unsigned char *)ktla_ktva(ins_addr);
25593 p += skip_prefix(p, &prf);
25594 p += get_opcode(p, &opcode);
25595 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25596 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25597 index 8573b83..4f3ed7e 100644
25598 --- a/arch/x86/mm/pgtable.c
25599 +++ b/arch/x86/mm/pgtable.c
25600 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25601 list_del(&page->lru);
25602 }
25603
25604 -#define UNSHARED_PTRS_PER_PGD \
25605 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25606 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25607 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25608
25609 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25610 +{
25611 + unsigned int count = USER_PGD_PTRS;
25612
25613 + while (count--)
25614 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25615 +}
25616 +#endif
25617 +
25618 +#ifdef CONFIG_PAX_PER_CPU_PGD
25619 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25620 +{
25621 + unsigned int count = USER_PGD_PTRS;
25622 +
25623 + while (count--) {
25624 + pgd_t pgd;
25625 +
25626 +#ifdef CONFIG_X86_64
25627 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25628 +#else
25629 + pgd = *src++;
25630 +#endif
25631 +
25632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25633 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25634 +#endif
25635 +
25636 + *dst++ = pgd;
25637 + }
25638 +
25639 +}
25640 +#endif
25641 +
25642 +#ifdef CONFIG_X86_64
25643 +#define pxd_t pud_t
25644 +#define pyd_t pgd_t
25645 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25646 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25647 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25648 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25649 +#define PYD_SIZE PGDIR_SIZE
25650 +#else
25651 +#define pxd_t pmd_t
25652 +#define pyd_t pud_t
25653 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25654 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25655 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25656 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25657 +#define PYD_SIZE PUD_SIZE
25658 +#endif
25659 +
25660 +#ifdef CONFIG_PAX_PER_CPU_PGD
25661 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25662 +static inline void pgd_dtor(pgd_t *pgd) {}
25663 +#else
25664 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25665 {
25666 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25667 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25668 pgd_list_del(pgd);
25669 spin_unlock(&pgd_lock);
25670 }
25671 +#endif
25672
25673 /*
25674 * List of all pgd's needed for non-PAE so it can invalidate entries
25675 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25676 * -- wli
25677 */
25678
25679 -#ifdef CONFIG_X86_PAE
25680 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25681 /*
25682 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25683 * updating the top-level pagetable entries to guarantee the
25684 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25685 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25686 * and initialize the kernel pmds here.
25687 */
25688 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25689 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25690
25691 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25692 {
25693 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25694 */
25695 flush_tlb_mm(mm);
25696 }
25697 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25698 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25699 #else /* !CONFIG_X86_PAE */
25700
25701 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25702 -#define PREALLOCATED_PMDS 0
25703 +#define PREALLOCATED_PXDS 0
25704
25705 #endif /* CONFIG_X86_PAE */
25706
25707 -static void free_pmds(pmd_t *pmds[])
25708 +static void free_pxds(pxd_t *pxds[])
25709 {
25710 int i;
25711
25712 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25713 - if (pmds[i])
25714 - free_page((unsigned long)pmds[i]);
25715 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25716 + if (pxds[i])
25717 + free_page((unsigned long)pxds[i]);
25718 }
25719
25720 -static int preallocate_pmds(pmd_t *pmds[])
25721 +static int preallocate_pxds(pxd_t *pxds[])
25722 {
25723 int i;
25724 bool failed = false;
25725
25726 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25727 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25728 - if (pmd == NULL)
25729 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25730 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25731 + if (pxd == NULL)
25732 failed = true;
25733 - pmds[i] = pmd;
25734 + pxds[i] = pxd;
25735 }
25736
25737 if (failed) {
25738 - free_pmds(pmds);
25739 + free_pxds(pxds);
25740 return -ENOMEM;
25741 }
25742
25743 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25744 * preallocate which never got a corresponding vma will need to be
25745 * freed manually.
25746 */
25747 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25748 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25749 {
25750 int i;
25751
25752 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25753 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25754 pgd_t pgd = pgdp[i];
25755
25756 if (pgd_val(pgd) != 0) {
25757 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25758 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25759
25760 - pgdp[i] = native_make_pgd(0);
25761 + set_pgd(pgdp + i, native_make_pgd(0));
25762
25763 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25764 - pmd_free(mm, pmd);
25765 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25766 + pxd_free(mm, pxd);
25767 }
25768 }
25769 }
25770
25771 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25772 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25773 {
25774 - pud_t *pud;
25775 + pyd_t *pyd;
25776 unsigned long addr;
25777 int i;
25778
25779 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25780 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25781 return;
25782
25783 - pud = pud_offset(pgd, 0);
25784 +#ifdef CONFIG_X86_64
25785 + pyd = pyd_offset(mm, 0L);
25786 +#else
25787 + pyd = pyd_offset(pgd, 0L);
25788 +#endif
25789
25790 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25791 - i++, pud++, addr += PUD_SIZE) {
25792 - pmd_t *pmd = pmds[i];
25793 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25794 + i++, pyd++, addr += PYD_SIZE) {
25795 + pxd_t *pxd = pxds[i];
25796
25797 if (i >= KERNEL_PGD_BOUNDARY)
25798 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25799 - sizeof(pmd_t) * PTRS_PER_PMD);
25800 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25801 + sizeof(pxd_t) * PTRS_PER_PMD);
25802
25803 - pud_populate(mm, pud, pmd);
25804 + pyd_populate(mm, pyd, pxd);
25805 }
25806 }
25807
25808 pgd_t *pgd_alloc(struct mm_struct *mm)
25809 {
25810 pgd_t *pgd;
25811 - pmd_t *pmds[PREALLOCATED_PMDS];
25812 + pxd_t *pxds[PREALLOCATED_PXDS];
25813
25814 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25815
25816 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25817
25818 mm->pgd = pgd;
25819
25820 - if (preallocate_pmds(pmds) != 0)
25821 + if (preallocate_pxds(pxds) != 0)
25822 goto out_free_pgd;
25823
25824 if (paravirt_pgd_alloc(mm) != 0)
25825 - goto out_free_pmds;
25826 + goto out_free_pxds;
25827
25828 /*
25829 * Make sure that pre-populating the pmds is atomic with
25830 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25831 spin_lock(&pgd_lock);
25832
25833 pgd_ctor(mm, pgd);
25834 - pgd_prepopulate_pmd(mm, pgd, pmds);
25835 + pgd_prepopulate_pxd(mm, pgd, pxds);
25836
25837 spin_unlock(&pgd_lock);
25838
25839 return pgd;
25840
25841 -out_free_pmds:
25842 - free_pmds(pmds);
25843 +out_free_pxds:
25844 + free_pxds(pxds);
25845 out_free_pgd:
25846 free_page((unsigned long)pgd);
25847 out:
25848 @@ -295,7 +356,7 @@ out:
25849
25850 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25851 {
25852 - pgd_mop_up_pmds(mm, pgd);
25853 + pgd_mop_up_pxds(mm, pgd);
25854 pgd_dtor(pgd);
25855 paravirt_pgd_free(mm, pgd);
25856 free_page((unsigned long)pgd);
25857 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25858 index a69bcb8..19068ab 100644
25859 --- a/arch/x86/mm/pgtable_32.c
25860 +++ b/arch/x86/mm/pgtable_32.c
25861 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25862 return;
25863 }
25864 pte = pte_offset_kernel(pmd, vaddr);
25865 +
25866 + pax_open_kernel();
25867 if (pte_val(pteval))
25868 set_pte_at(&init_mm, vaddr, pte, pteval);
25869 else
25870 pte_clear(&init_mm, vaddr, pte);
25871 + pax_close_kernel();
25872
25873 /*
25874 * It's enough to flush this one mapping.
25875 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25876 index 410531d..0f16030 100644
25877 --- a/arch/x86/mm/setup_nx.c
25878 +++ b/arch/x86/mm/setup_nx.c
25879 @@ -5,8 +5,10 @@
25880 #include <asm/pgtable.h>
25881 #include <asm/proto.h>
25882
25883 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25884 static int disable_nx __cpuinitdata;
25885
25886 +#ifndef CONFIG_PAX_PAGEEXEC
25887 /*
25888 * noexec = on|off
25889 *
25890 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25891 return 0;
25892 }
25893 early_param("noexec", noexec_setup);
25894 +#endif
25895 +
25896 +#endif
25897
25898 void __cpuinit x86_configure_nx(void)
25899 {
25900 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25901 if (cpu_has_nx && !disable_nx)
25902 __supported_pte_mask |= _PAGE_NX;
25903 else
25904 +#endif
25905 __supported_pte_mask &= ~_PAGE_NX;
25906 }
25907
25908 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25909 index 613cd83..3a21f1c 100644
25910 --- a/arch/x86/mm/tlb.c
25911 +++ b/arch/x86/mm/tlb.c
25912 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25913 BUG();
25914 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25915 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25916 +
25917 +#ifndef CONFIG_PAX_PER_CPU_PGD
25918 load_cr3(swapper_pg_dir);
25919 +#endif
25920 +
25921 }
25922 }
25923 EXPORT_SYMBOL_GPL(leave_mm);
25924 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25925 index 877b9a1..a8ecf42 100644
25926 --- a/arch/x86/net/bpf_jit.S
25927 +++ b/arch/x86/net/bpf_jit.S
25928 @@ -9,6 +9,7 @@
25929 */
25930 #include <linux/linkage.h>
25931 #include <asm/dwarf2.h>
25932 +#include <asm/alternative-asm.h>
25933
25934 /*
25935 * Calling convention :
25936 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25937 jle bpf_slow_path_word
25938 mov (SKBDATA,%rsi),%eax
25939 bswap %eax /* ntohl() */
25940 + pax_force_retaddr
25941 ret
25942
25943 sk_load_half:
25944 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25945 jle bpf_slow_path_half
25946 movzwl (SKBDATA,%rsi),%eax
25947 rol $8,%ax # ntohs()
25948 + pax_force_retaddr
25949 ret
25950
25951 sk_load_byte:
25952 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25953 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25954 jle bpf_slow_path_byte
25955 movzbl (SKBDATA,%rsi),%eax
25956 + pax_force_retaddr
25957 ret
25958
25959 /**
25960 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25961 movzbl (SKBDATA,%rsi),%ebx
25962 and $15,%bl
25963 shl $2,%bl
25964 + pax_force_retaddr
25965 ret
25966
25967 /* rsi contains offset and can be scratched */
25968 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25969 js bpf_error
25970 mov -12(%rbp),%eax
25971 bswap %eax
25972 + pax_force_retaddr
25973 ret
25974
25975 bpf_slow_path_half:
25976 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25977 mov -12(%rbp),%ax
25978 rol $8,%ax
25979 movzwl %ax,%eax
25980 + pax_force_retaddr
25981 ret
25982
25983 bpf_slow_path_byte:
25984 bpf_slow_path_common(1)
25985 js bpf_error
25986 movzbl -12(%rbp),%eax
25987 + pax_force_retaddr
25988 ret
25989
25990 bpf_slow_path_byte_msh:
25991 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25992 and $15,%al
25993 shl $2,%al
25994 xchg %eax,%ebx
25995 + pax_force_retaddr
25996 ret
25997
25998 #define sk_negative_common(SIZE) \
25999 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26000 sk_negative_common(4)
26001 mov (%rax), %eax
26002 bswap %eax
26003 + pax_force_retaddr
26004 ret
26005
26006 bpf_slow_path_half_neg:
26007 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26008 mov (%rax),%ax
26009 rol $8,%ax
26010 movzwl %ax,%eax
26011 + pax_force_retaddr
26012 ret
26013
26014 bpf_slow_path_byte_neg:
26015 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26016 .globl sk_load_byte_negative_offset
26017 sk_negative_common(1)
26018 movzbl (%rax), %eax
26019 + pax_force_retaddr
26020 ret
26021
26022 bpf_slow_path_byte_msh_neg:
26023 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26024 and $15,%al
26025 shl $2,%al
26026 xchg %eax,%ebx
26027 + pax_force_retaddr
26028 ret
26029
26030 bpf_error:
26031 @@ -197,4 +210,5 @@ bpf_error:
26032 xor %eax,%eax
26033 mov -8(%rbp),%rbx
26034 leaveq
26035 + pax_force_retaddr
26036 ret
26037 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26038 index 33643a8..8e44870 100644
26039 --- a/arch/x86/net/bpf_jit_comp.c
26040 +++ b/arch/x86/net/bpf_jit_comp.c
26041 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26042 set_fs(old_fs);
26043 }
26044
26045 +struct bpf_jit_work {
26046 + struct work_struct work;
26047 + void *image;
26048 +};
26049 +
26050 #define CHOOSE_LOAD_FUNC(K, func) \
26051 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26052
26053 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26054 if (addrs == NULL)
26055 return;
26056
26057 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26058 + if (!fp->work)
26059 + goto out;
26060 +
26061 /* Before first pass, make a rough estimation of addrs[]
26062 * each bpf instruction is translated to less than 64 bytes
26063 */
26064 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26065 break;
26066 default:
26067 /* hmm, too complex filter, give up with jit compiler */
26068 - goto out;
26069 + goto error;
26070 }
26071 ilen = prog - temp;
26072 if (image) {
26073 if (unlikely(proglen + ilen > oldproglen)) {
26074 pr_err("bpb_jit_compile fatal error\n");
26075 - kfree(addrs);
26076 - module_free(NULL, image);
26077 - return;
26078 + module_free_exec(NULL, image);
26079 + goto error;
26080 }
26081 + pax_open_kernel();
26082 memcpy(image + proglen, temp, ilen);
26083 + pax_close_kernel();
26084 }
26085 proglen += ilen;
26086 addrs[i] = proglen;
26087 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26088 break;
26089 }
26090 if (proglen == oldproglen) {
26091 - image = module_alloc(max_t(unsigned int,
26092 - proglen,
26093 - sizeof(struct work_struct)));
26094 + image = module_alloc_exec(proglen);
26095 if (!image)
26096 - goto out;
26097 + goto error;
26098 }
26099 oldproglen = proglen;
26100 }
26101 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26102 bpf_flush_icache(image, image + proglen);
26103
26104 fp->bpf_func = (void *)image;
26105 - }
26106 + } else
26107 +error:
26108 + kfree(fp->work);
26109 +
26110 out:
26111 kfree(addrs);
26112 return;
26113 @@ -652,18 +663,20 @@ out:
26114
26115 static void jit_free_defer(struct work_struct *arg)
26116 {
26117 - module_free(NULL, arg);
26118 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26119 + kfree(arg);
26120 }
26121
26122 /* run from softirq, we must use a work_struct to call
26123 - * module_free() from process context
26124 + * module_free_exec() from process context
26125 */
26126 void bpf_jit_free(struct sk_filter *fp)
26127 {
26128 if (fp->bpf_func != sk_run_filter) {
26129 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26130 + struct work_struct *work = &fp->work->work;
26131
26132 INIT_WORK(work, jit_free_defer);
26133 + fp->work->image = fp->bpf_func;
26134 schedule_work(work);
26135 }
26136 }
26137 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26138 index d6aa6e8..266395a 100644
26139 --- a/arch/x86/oprofile/backtrace.c
26140 +++ b/arch/x86/oprofile/backtrace.c
26141 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26142 struct stack_frame_ia32 *fp;
26143 unsigned long bytes;
26144
26145 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26146 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26147 if (bytes != sizeof(bufhead))
26148 return NULL;
26149
26150 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26151 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26152
26153 oprofile_add_trace(bufhead[0].return_address);
26154
26155 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26156 struct stack_frame bufhead[2];
26157 unsigned long bytes;
26158
26159 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26160 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26161 if (bytes != sizeof(bufhead))
26162 return NULL;
26163
26164 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26165 {
26166 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26167
26168 - if (!user_mode_vm(regs)) {
26169 + if (!user_mode(regs)) {
26170 unsigned long stack = kernel_stack_pointer(regs);
26171 if (depth)
26172 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26173 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26174 index e14a2ff..3fd6b58 100644
26175 --- a/arch/x86/pci/mrst.c
26176 +++ b/arch/x86/pci/mrst.c
26177 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26178 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26179 pci_mmcfg_late_init();
26180 pcibios_enable_irq = mrst_pci_irq_enable;
26181 - pci_root_ops = pci_mrst_ops;
26182 + pax_open_kernel();
26183 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26184 + pax_close_kernel();
26185 pci_soc_mode = 1;
26186 /* Continue with standard init */
26187 return 1;
26188 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26189 index da8fe05..7ee6704 100644
26190 --- a/arch/x86/pci/pcbios.c
26191 +++ b/arch/x86/pci/pcbios.c
26192 @@ -79,50 +79,93 @@ union bios32 {
26193 static struct {
26194 unsigned long address;
26195 unsigned short segment;
26196 -} bios32_indirect = { 0, __KERNEL_CS };
26197 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26198
26199 /*
26200 * Returns the entry point for the given service, NULL on error
26201 */
26202
26203 -static unsigned long bios32_service(unsigned long service)
26204 +static unsigned long __devinit bios32_service(unsigned long service)
26205 {
26206 unsigned char return_code; /* %al */
26207 unsigned long address; /* %ebx */
26208 unsigned long length; /* %ecx */
26209 unsigned long entry; /* %edx */
26210 unsigned long flags;
26211 + struct desc_struct d, *gdt;
26212
26213 local_irq_save(flags);
26214 - __asm__("lcall *(%%edi); cld"
26215 +
26216 + gdt = get_cpu_gdt_table(smp_processor_id());
26217 +
26218 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26219 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26220 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26221 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26222 +
26223 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26224 : "=a" (return_code),
26225 "=b" (address),
26226 "=c" (length),
26227 "=d" (entry)
26228 : "0" (service),
26229 "1" (0),
26230 - "D" (&bios32_indirect));
26231 + "D" (&bios32_indirect),
26232 + "r"(__PCIBIOS_DS)
26233 + : "memory");
26234 +
26235 + pax_open_kernel();
26236 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26237 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26238 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26239 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26240 + pax_close_kernel();
26241 +
26242 local_irq_restore(flags);
26243
26244 switch (return_code) {
26245 - case 0:
26246 - return address + entry;
26247 - case 0x80: /* Not present */
26248 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26249 - return 0;
26250 - default: /* Shouldn't happen */
26251 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26252 - service, return_code);
26253 + case 0: {
26254 + int cpu;
26255 + unsigned char flags;
26256 +
26257 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26258 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26259 + printk(KERN_WARNING "bios32_service: not valid\n");
26260 return 0;
26261 + }
26262 + address = address + PAGE_OFFSET;
26263 + length += 16UL; /* some BIOSs underreport this... */
26264 + flags = 4;
26265 + if (length >= 64*1024*1024) {
26266 + length >>= PAGE_SHIFT;
26267 + flags |= 8;
26268 + }
26269 +
26270 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26271 + gdt = get_cpu_gdt_table(cpu);
26272 + pack_descriptor(&d, address, length, 0x9b, flags);
26273 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26274 + pack_descriptor(&d, address, length, 0x93, flags);
26275 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26276 + }
26277 + return entry;
26278 + }
26279 + case 0x80: /* Not present */
26280 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26281 + return 0;
26282 + default: /* Shouldn't happen */
26283 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26284 + service, return_code);
26285 + return 0;
26286 }
26287 }
26288
26289 static struct {
26290 unsigned long address;
26291 unsigned short segment;
26292 -} pci_indirect = { 0, __KERNEL_CS };
26293 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26294
26295 -static int pci_bios_present;
26296 +static int pci_bios_present __read_only;
26297
26298 static int __devinit check_pcibios(void)
26299 {
26300 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26301 unsigned long flags, pcibios_entry;
26302
26303 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26304 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26305 + pci_indirect.address = pcibios_entry;
26306
26307 local_irq_save(flags);
26308 - __asm__(
26309 - "lcall *(%%edi); cld\n\t"
26310 + __asm__("movw %w6, %%ds\n\t"
26311 + "lcall *%%ss:(%%edi); cld\n\t"
26312 + "push %%ss\n\t"
26313 + "pop %%ds\n\t"
26314 "jc 1f\n\t"
26315 "xor %%ah, %%ah\n"
26316 "1:"
26317 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26318 "=b" (ebx),
26319 "=c" (ecx)
26320 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26321 - "D" (&pci_indirect)
26322 + "D" (&pci_indirect),
26323 + "r" (__PCIBIOS_DS)
26324 : "memory");
26325 local_irq_restore(flags);
26326
26327 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26328
26329 switch (len) {
26330 case 1:
26331 - __asm__("lcall *(%%esi); cld\n\t"
26332 + __asm__("movw %w6, %%ds\n\t"
26333 + "lcall *%%ss:(%%esi); cld\n\t"
26334 + "push %%ss\n\t"
26335 + "pop %%ds\n\t"
26336 "jc 1f\n\t"
26337 "xor %%ah, %%ah\n"
26338 "1:"
26339 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26340 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26341 "b" (bx),
26342 "D" ((long)reg),
26343 - "S" (&pci_indirect));
26344 + "S" (&pci_indirect),
26345 + "r" (__PCIBIOS_DS));
26346 /*
26347 * Zero-extend the result beyond 8 bits, do not trust the
26348 * BIOS having done it:
26349 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26350 *value &= 0xff;
26351 break;
26352 case 2:
26353 - __asm__("lcall *(%%esi); cld\n\t"
26354 + __asm__("movw %w6, %%ds\n\t"
26355 + "lcall *%%ss:(%%esi); cld\n\t"
26356 + "push %%ss\n\t"
26357 + "pop %%ds\n\t"
26358 "jc 1f\n\t"
26359 "xor %%ah, %%ah\n"
26360 "1:"
26361 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26362 : "1" (PCIBIOS_READ_CONFIG_WORD),
26363 "b" (bx),
26364 "D" ((long)reg),
26365 - "S" (&pci_indirect));
26366 + "S" (&pci_indirect),
26367 + "r" (__PCIBIOS_DS));
26368 /*
26369 * Zero-extend the result beyond 16 bits, do not trust the
26370 * BIOS having done it:
26371 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26372 *value &= 0xffff;
26373 break;
26374 case 4:
26375 - __asm__("lcall *(%%esi); cld\n\t"
26376 + __asm__("movw %w6, %%ds\n\t"
26377 + "lcall *%%ss:(%%esi); cld\n\t"
26378 + "push %%ss\n\t"
26379 + "pop %%ds\n\t"
26380 "jc 1f\n\t"
26381 "xor %%ah, %%ah\n"
26382 "1:"
26383 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26384 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26385 "b" (bx),
26386 "D" ((long)reg),
26387 - "S" (&pci_indirect));
26388 + "S" (&pci_indirect),
26389 + "r" (__PCIBIOS_DS));
26390 break;
26391 }
26392
26393 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26394
26395 switch (len) {
26396 case 1:
26397 - __asm__("lcall *(%%esi); cld\n\t"
26398 + __asm__("movw %w6, %%ds\n\t"
26399 + "lcall *%%ss:(%%esi); cld\n\t"
26400 + "push %%ss\n\t"
26401 + "pop %%ds\n\t"
26402 "jc 1f\n\t"
26403 "xor %%ah, %%ah\n"
26404 "1:"
26405 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26406 "c" (value),
26407 "b" (bx),
26408 "D" ((long)reg),
26409 - "S" (&pci_indirect));
26410 + "S" (&pci_indirect),
26411 + "r" (__PCIBIOS_DS));
26412 break;
26413 case 2:
26414 - __asm__("lcall *(%%esi); cld\n\t"
26415 + __asm__("movw %w6, %%ds\n\t"
26416 + "lcall *%%ss:(%%esi); cld\n\t"
26417 + "push %%ss\n\t"
26418 + "pop %%ds\n\t"
26419 "jc 1f\n\t"
26420 "xor %%ah, %%ah\n"
26421 "1:"
26422 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26423 "c" (value),
26424 "b" (bx),
26425 "D" ((long)reg),
26426 - "S" (&pci_indirect));
26427 + "S" (&pci_indirect),
26428 + "r" (__PCIBIOS_DS));
26429 break;
26430 case 4:
26431 - __asm__("lcall *(%%esi); cld\n\t"
26432 + __asm__("movw %w6, %%ds\n\t"
26433 + "lcall *%%ss:(%%esi); cld\n\t"
26434 + "push %%ss\n\t"
26435 + "pop %%ds\n\t"
26436 "jc 1f\n\t"
26437 "xor %%ah, %%ah\n"
26438 "1:"
26439 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26440 "c" (value),
26441 "b" (bx),
26442 "D" ((long)reg),
26443 - "S" (&pci_indirect));
26444 + "S" (&pci_indirect),
26445 + "r" (__PCIBIOS_DS));
26446 break;
26447 }
26448
26449 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26450
26451 DBG("PCI: Fetching IRQ routing table... ");
26452 __asm__("push %%es\n\t"
26453 + "movw %w8, %%ds\n\t"
26454 "push %%ds\n\t"
26455 "pop %%es\n\t"
26456 - "lcall *(%%esi); cld\n\t"
26457 + "lcall *%%ss:(%%esi); cld\n\t"
26458 "pop %%es\n\t"
26459 + "push %%ss\n\t"
26460 + "pop %%ds\n"
26461 "jc 1f\n\t"
26462 "xor %%ah, %%ah\n"
26463 "1:"
26464 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26465 "1" (0),
26466 "D" ((long) &opt),
26467 "S" (&pci_indirect),
26468 - "m" (opt)
26469 + "m" (opt),
26470 + "r" (__PCIBIOS_DS)
26471 : "memory");
26472 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26473 if (ret & 0xff00)
26474 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26475 {
26476 int ret;
26477
26478 - __asm__("lcall *(%%esi); cld\n\t"
26479 + __asm__("movw %w5, %%ds\n\t"
26480 + "lcall *%%ss:(%%esi); cld\n\t"
26481 + "push %%ss\n\t"
26482 + "pop %%ds\n"
26483 "jc 1f\n\t"
26484 "xor %%ah, %%ah\n"
26485 "1:"
26486 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26487 : "0" (PCIBIOS_SET_PCI_HW_INT),
26488 "b" ((dev->bus->number << 8) | dev->devfn),
26489 "c" ((irq << 8) | (pin + 10)),
26490 - "S" (&pci_indirect));
26491 + "S" (&pci_indirect),
26492 + "r" (__PCIBIOS_DS));
26493 return !(ret & 0xff00);
26494 }
26495 EXPORT_SYMBOL(pcibios_set_irq_routing);
26496 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26497 index 40e4469..1ab536e 100644
26498 --- a/arch/x86/platform/efi/efi_32.c
26499 +++ b/arch/x86/platform/efi/efi_32.c
26500 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26501 {
26502 struct desc_ptr gdt_descr;
26503
26504 +#ifdef CONFIG_PAX_KERNEXEC
26505 + struct desc_struct d;
26506 +#endif
26507 +
26508 local_irq_save(efi_rt_eflags);
26509
26510 load_cr3(initial_page_table);
26511 __flush_tlb_all();
26512
26513 +#ifdef CONFIG_PAX_KERNEXEC
26514 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26515 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26516 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26517 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26518 +#endif
26519 +
26520 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26521 gdt_descr.size = GDT_SIZE - 1;
26522 load_gdt(&gdt_descr);
26523 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26524 {
26525 struct desc_ptr gdt_descr;
26526
26527 +#ifdef CONFIG_PAX_KERNEXEC
26528 + struct desc_struct d;
26529 +
26530 + memset(&d, 0, sizeof d);
26531 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26532 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26533 +#endif
26534 +
26535 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26536 gdt_descr.size = GDT_SIZE - 1;
26537 load_gdt(&gdt_descr);
26538 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26539 index fbe66e6..eae5e38 100644
26540 --- a/arch/x86/platform/efi/efi_stub_32.S
26541 +++ b/arch/x86/platform/efi/efi_stub_32.S
26542 @@ -6,7 +6,9 @@
26543 */
26544
26545 #include <linux/linkage.h>
26546 +#include <linux/init.h>
26547 #include <asm/page_types.h>
26548 +#include <asm/segment.h>
26549
26550 /*
26551 * efi_call_phys(void *, ...) is a function with variable parameters.
26552 @@ -20,7 +22,7 @@
26553 * service functions will comply with gcc calling convention, too.
26554 */
26555
26556 -.text
26557 +__INIT
26558 ENTRY(efi_call_phys)
26559 /*
26560 * 0. The function can only be called in Linux kernel. So CS has been
26561 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26562 * The mapping of lower virtual memory has been created in prelog and
26563 * epilog.
26564 */
26565 - movl $1f, %edx
26566 - subl $__PAGE_OFFSET, %edx
26567 - jmp *%edx
26568 +#ifdef CONFIG_PAX_KERNEXEC
26569 + movl $(__KERNEXEC_EFI_DS), %edx
26570 + mov %edx, %ds
26571 + mov %edx, %es
26572 + mov %edx, %ss
26573 + addl $2f,(1f)
26574 + ljmp *(1f)
26575 +
26576 +__INITDATA
26577 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26578 +.previous
26579 +
26580 +2:
26581 + subl $2b,(1b)
26582 +#else
26583 + jmp 1f-__PAGE_OFFSET
26584 1:
26585 +#endif
26586
26587 /*
26588 * 2. Now on the top of stack is the return
26589 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26590 * parameter 2, ..., param n. To make things easy, we save the return
26591 * address of efi_call_phys in a global variable.
26592 */
26593 - popl %edx
26594 - movl %edx, saved_return_addr
26595 - /* get the function pointer into ECX*/
26596 - popl %ecx
26597 - movl %ecx, efi_rt_function_ptr
26598 - movl $2f, %edx
26599 - subl $__PAGE_OFFSET, %edx
26600 - pushl %edx
26601 + popl (saved_return_addr)
26602 + popl (efi_rt_function_ptr)
26603
26604 /*
26605 * 3. Clear PG bit in %CR0.
26606 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26607 /*
26608 * 5. Call the physical function.
26609 */
26610 - jmp *%ecx
26611 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26612
26613 -2:
26614 /*
26615 * 6. After EFI runtime service returns, control will return to
26616 * following instruction. We'd better readjust stack pointer first.
26617 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26618 movl %cr0, %edx
26619 orl $0x80000000, %edx
26620 movl %edx, %cr0
26621 - jmp 1f
26622 -1:
26623 +
26624 /*
26625 * 8. Now restore the virtual mode from flat mode by
26626 * adding EIP with PAGE_OFFSET.
26627 */
26628 - movl $1f, %edx
26629 - jmp *%edx
26630 +#ifdef CONFIG_PAX_KERNEXEC
26631 + movl $(__KERNEL_DS), %edx
26632 + mov %edx, %ds
26633 + mov %edx, %es
26634 + mov %edx, %ss
26635 + ljmp $(__KERNEL_CS),$1f
26636 +#else
26637 + jmp 1f+__PAGE_OFFSET
26638 +#endif
26639 1:
26640
26641 /*
26642 * 9. Balance the stack. And because EAX contain the return value,
26643 * we'd better not clobber it.
26644 */
26645 - leal efi_rt_function_ptr, %edx
26646 - movl (%edx), %ecx
26647 - pushl %ecx
26648 + pushl (efi_rt_function_ptr)
26649
26650 /*
26651 - * 10. Push the saved return address onto the stack and return.
26652 + * 10. Return to the saved return address.
26653 */
26654 - leal saved_return_addr, %edx
26655 - movl (%edx), %ecx
26656 - pushl %ecx
26657 - ret
26658 + jmpl *(saved_return_addr)
26659 ENDPROC(efi_call_phys)
26660 .previous
26661
26662 -.data
26663 +__INITDATA
26664 saved_return_addr:
26665 .long 0
26666 efi_rt_function_ptr:
26667 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26668 index 4c07cca..2c8427d 100644
26669 --- a/arch/x86/platform/efi/efi_stub_64.S
26670 +++ b/arch/x86/platform/efi/efi_stub_64.S
26671 @@ -7,6 +7,7 @@
26672 */
26673
26674 #include <linux/linkage.h>
26675 +#include <asm/alternative-asm.h>
26676
26677 #define SAVE_XMM \
26678 mov %rsp, %rax; \
26679 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26680 call *%rdi
26681 addq $32, %rsp
26682 RESTORE_XMM
26683 + pax_force_retaddr 0, 1
26684 ret
26685 ENDPROC(efi_call0)
26686
26687 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26688 call *%rdi
26689 addq $32, %rsp
26690 RESTORE_XMM
26691 + pax_force_retaddr 0, 1
26692 ret
26693 ENDPROC(efi_call1)
26694
26695 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26696 call *%rdi
26697 addq $32, %rsp
26698 RESTORE_XMM
26699 + pax_force_retaddr 0, 1
26700 ret
26701 ENDPROC(efi_call2)
26702
26703 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26704 call *%rdi
26705 addq $32, %rsp
26706 RESTORE_XMM
26707 + pax_force_retaddr 0, 1
26708 ret
26709 ENDPROC(efi_call3)
26710
26711 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26712 call *%rdi
26713 addq $32, %rsp
26714 RESTORE_XMM
26715 + pax_force_retaddr 0, 1
26716 ret
26717 ENDPROC(efi_call4)
26718
26719 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26720 call *%rdi
26721 addq $48, %rsp
26722 RESTORE_XMM
26723 + pax_force_retaddr 0, 1
26724 ret
26725 ENDPROC(efi_call5)
26726
26727 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26728 call *%rdi
26729 addq $48, %rsp
26730 RESTORE_XMM
26731 + pax_force_retaddr 0, 1
26732 ret
26733 ENDPROC(efi_call6)
26734 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26735 index fd41a92..9c33628 100644
26736 --- a/arch/x86/platform/mrst/mrst.c
26737 +++ b/arch/x86/platform/mrst/mrst.c
26738 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26739 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26740 int sfi_mrtc_num;
26741
26742 -static void mrst_power_off(void)
26743 +static __noreturn void mrst_power_off(void)
26744 {
26745 + BUG();
26746 }
26747
26748 -static void mrst_reboot(void)
26749 +static __noreturn void mrst_reboot(void)
26750 {
26751 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26752 + BUG();
26753 }
26754
26755 /* parse all the mtimer info to a static mtimer array */
26756 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26757 index 218cdb1..fd55c08 100644
26758 --- a/arch/x86/power/cpu.c
26759 +++ b/arch/x86/power/cpu.c
26760 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26761 static void fix_processor_context(void)
26762 {
26763 int cpu = smp_processor_id();
26764 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26765 + struct tss_struct *t = init_tss + cpu;
26766
26767 set_tss_desc(cpu, t); /*
26768 * This just modifies memory; should not be
26769 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26770 */
26771
26772 #ifdef CONFIG_X86_64
26773 + pax_open_kernel();
26774 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26775 + pax_close_kernel();
26776
26777 syscall_init(); /* This sets MSR_*STAR and related */
26778 #endif
26779 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26780 index cbca565..bae7133 100644
26781 --- a/arch/x86/realmode/init.c
26782 +++ b/arch/x86/realmode/init.c
26783 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26784 __va(real_mode_header->trampoline_header);
26785
26786 #ifdef CONFIG_X86_32
26787 - trampoline_header->start = __pa(startup_32_smp);
26788 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26789 +
26790 +#ifdef CONFIG_PAX_KERNEXEC
26791 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26792 +#endif
26793 +
26794 + trampoline_header->boot_cs = __BOOT_CS;
26795 trampoline_header->gdt_limit = __BOOT_DS + 7;
26796 trampoline_header->gdt_base = __pa(boot_gdt);
26797 #else
26798 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26799 index 8869287..d577672 100644
26800 --- a/arch/x86/realmode/rm/Makefile
26801 +++ b/arch/x86/realmode/rm/Makefile
26802 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26803 $(call cc-option, -fno-unit-at-a-time)) \
26804 $(call cc-option, -fno-stack-protector) \
26805 $(call cc-option, -mpreferred-stack-boundary=2)
26806 +ifdef CONSTIFY_PLUGIN
26807 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26808 +endif
26809 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26810 GCOV_PROFILE := n
26811 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26812 index a28221d..93c40f1 100644
26813 --- a/arch/x86/realmode/rm/header.S
26814 +++ b/arch/x86/realmode/rm/header.S
26815 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26816 #endif
26817 /* APM/BIOS reboot */
26818 .long pa_machine_real_restart_asm
26819 -#ifdef CONFIG_X86_64
26820 +#ifdef CONFIG_X86_32
26821 + .long __KERNEL_CS
26822 +#else
26823 .long __KERNEL32_CS
26824 #endif
26825 END(real_mode_header)
26826 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26827 index c1b2791..f9e31c7 100644
26828 --- a/arch/x86/realmode/rm/trampoline_32.S
26829 +++ b/arch/x86/realmode/rm/trampoline_32.S
26830 @@ -25,6 +25,12 @@
26831 #include <asm/page_types.h>
26832 #include "realmode.h"
26833
26834 +#ifdef CONFIG_PAX_KERNEXEC
26835 +#define ta(X) (X)
26836 +#else
26837 +#define ta(X) (pa_ ## X)
26838 +#endif
26839 +
26840 .text
26841 .code16
26842
26843 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26844
26845 cli # We should be safe anyway
26846
26847 - movl tr_start, %eax # where we need to go
26848 -
26849 movl $0xA5A5A5A5, trampoline_status
26850 # write marker for master knows we're running
26851
26852 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26853 movw $1, %dx # protected mode (PE) bit
26854 lmsw %dx # into protected mode
26855
26856 - ljmpl $__BOOT_CS, $pa_startup_32
26857 + ljmpl *(trampoline_header)
26858
26859 .section ".text32","ax"
26860 .code32
26861 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26862 .balign 8
26863 GLOBAL(trampoline_header)
26864 tr_start: .space 4
26865 - tr_gdt_pad: .space 2
26866 + tr_boot_cs: .space 2
26867 tr_gdt: .space 6
26868 END(trampoline_header)
26869
26870 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26871 index bb360dc..3e5945f 100644
26872 --- a/arch/x86/realmode/rm/trampoline_64.S
26873 +++ b/arch/x86/realmode/rm/trampoline_64.S
26874 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26875 wrmsr
26876
26877 # Enable paging and in turn activate Long Mode
26878 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26879 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26880 movl %eax, %cr0
26881
26882 /*
26883 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26884 index 5a1847d..deccb30 100644
26885 --- a/arch/x86/tools/relocs.c
26886 +++ b/arch/x86/tools/relocs.c
26887 @@ -12,10 +12,13 @@
26888 #include <regex.h>
26889 #include <tools/le_byteshift.h>
26890
26891 +#include "../../../include/generated/autoconf.h"
26892 +
26893 static void die(char *fmt, ...);
26894
26895 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26896 static Elf32_Ehdr ehdr;
26897 +static Elf32_Phdr *phdr;
26898 static unsigned long reloc_count, reloc_idx;
26899 static unsigned long *relocs;
26900 static unsigned long reloc16_count, reloc16_idx;
26901 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26902 }
26903 }
26904
26905 +static void read_phdrs(FILE *fp)
26906 +{
26907 + unsigned int i;
26908 +
26909 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26910 + if (!phdr) {
26911 + die("Unable to allocate %d program headers\n",
26912 + ehdr.e_phnum);
26913 + }
26914 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26915 + die("Seek to %d failed: %s\n",
26916 + ehdr.e_phoff, strerror(errno));
26917 + }
26918 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26919 + die("Cannot read ELF program headers: %s\n",
26920 + strerror(errno));
26921 + }
26922 + for(i = 0; i < ehdr.e_phnum; i++) {
26923 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26924 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26925 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26926 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26927 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26928 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26929 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26930 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26931 + }
26932 +
26933 +}
26934 +
26935 static void read_shdrs(FILE *fp)
26936 {
26937 - int i;
26938 + unsigned int i;
26939 Elf32_Shdr shdr;
26940
26941 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26942 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26943
26944 static void read_strtabs(FILE *fp)
26945 {
26946 - int i;
26947 + unsigned int i;
26948 for (i = 0; i < ehdr.e_shnum; i++) {
26949 struct section *sec = &secs[i];
26950 if (sec->shdr.sh_type != SHT_STRTAB) {
26951 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26952
26953 static void read_symtabs(FILE *fp)
26954 {
26955 - int i,j;
26956 + unsigned int i,j;
26957 for (i = 0; i < ehdr.e_shnum; i++) {
26958 struct section *sec = &secs[i];
26959 if (sec->shdr.sh_type != SHT_SYMTAB) {
26960 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26961 }
26962
26963
26964 -static void read_relocs(FILE *fp)
26965 +static void read_relocs(FILE *fp, int use_real_mode)
26966 {
26967 - int i,j;
26968 + unsigned int i,j;
26969 + uint32_t base;
26970 +
26971 for (i = 0; i < ehdr.e_shnum; i++) {
26972 struct section *sec = &secs[i];
26973 if (sec->shdr.sh_type != SHT_REL) {
26974 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26975 die("Cannot read symbol table: %s\n",
26976 strerror(errno));
26977 }
26978 + base = 0;
26979 +
26980 +#ifdef CONFIG_X86_32
26981 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26982 + if (phdr[j].p_type != PT_LOAD )
26983 + continue;
26984 + 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)
26985 + continue;
26986 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26987 + break;
26988 + }
26989 +#endif
26990 +
26991 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26992 Elf32_Rel *rel = &sec->reltab[j];
26993 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26994 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26995 rel->r_info = elf32_to_cpu(rel->r_info);
26996 }
26997 }
26998 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26999
27000 static void print_absolute_symbols(void)
27001 {
27002 - int i;
27003 + unsigned int i;
27004 printf("Absolute symbols\n");
27005 printf(" Num: Value Size Type Bind Visibility Name\n");
27006 for (i = 0; i < ehdr.e_shnum; i++) {
27007 struct section *sec = &secs[i];
27008 char *sym_strtab;
27009 - int j;
27010 + unsigned int j;
27011
27012 if (sec->shdr.sh_type != SHT_SYMTAB) {
27013 continue;
27014 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27015
27016 static void print_absolute_relocs(void)
27017 {
27018 - int i, printed = 0;
27019 + unsigned int i, printed = 0;
27020
27021 for (i = 0; i < ehdr.e_shnum; i++) {
27022 struct section *sec = &secs[i];
27023 struct section *sec_applies, *sec_symtab;
27024 char *sym_strtab;
27025 Elf32_Sym *sh_symtab;
27026 - int j;
27027 + unsigned int j;
27028 if (sec->shdr.sh_type != SHT_REL) {
27029 continue;
27030 }
27031 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27032 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27033 int use_real_mode)
27034 {
27035 - int i;
27036 + unsigned int i;
27037 /* Walk through the relocations */
27038 for (i = 0; i < ehdr.e_shnum; i++) {
27039 char *sym_strtab;
27040 Elf32_Sym *sh_symtab;
27041 struct section *sec_applies, *sec_symtab;
27042 - int j;
27043 + unsigned int j;
27044 struct section *sec = &secs[i];
27045
27046 if (sec->shdr.sh_type != SHT_REL) {
27047 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27048 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27049 r_type = ELF32_R_TYPE(rel->r_info);
27050
27051 + if (!use_real_mode) {
27052 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27053 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27054 + continue;
27055 +
27056 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27057 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27058 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27059 + continue;
27060 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27061 + continue;
27062 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27063 + continue;
27064 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27065 + continue;
27066 +#endif
27067 + }
27068 +
27069 shn_abs = sym->st_shndx == SHN_ABS;
27070
27071 switch (r_type) {
27072 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27073
27074 static void emit_relocs(int as_text, int use_real_mode)
27075 {
27076 - int i;
27077 + unsigned int i;
27078 /* Count how many relocations I have and allocate space for them. */
27079 reloc_count = 0;
27080 walk_relocs(count_reloc, use_real_mode);
27081 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27082 fname, strerror(errno));
27083 }
27084 read_ehdr(fp);
27085 + read_phdrs(fp);
27086 read_shdrs(fp);
27087 read_strtabs(fp);
27088 read_symtabs(fp);
27089 - read_relocs(fp);
27090 + read_relocs(fp, use_real_mode);
27091 if (show_absolute_syms) {
27092 print_absolute_symbols();
27093 return 0;
27094 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27095 index fd14be1..e3c79c0 100644
27096 --- a/arch/x86/vdso/Makefile
27097 +++ b/arch/x86/vdso/Makefile
27098 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27099 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27100 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27101
27102 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27103 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27104 GCOV_PROFILE := n
27105
27106 #
27107 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27108 index 0faad64..39ef157 100644
27109 --- a/arch/x86/vdso/vdso32-setup.c
27110 +++ b/arch/x86/vdso/vdso32-setup.c
27111 @@ -25,6 +25,7 @@
27112 #include <asm/tlbflush.h>
27113 #include <asm/vdso.h>
27114 #include <asm/proto.h>
27115 +#include <asm/mman.h>
27116
27117 enum {
27118 VDSO_DISABLED = 0,
27119 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27120 void enable_sep_cpu(void)
27121 {
27122 int cpu = get_cpu();
27123 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27124 + struct tss_struct *tss = init_tss + cpu;
27125
27126 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27127 put_cpu();
27128 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27129 gate_vma.vm_start = FIXADDR_USER_START;
27130 gate_vma.vm_end = FIXADDR_USER_END;
27131 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27132 - gate_vma.vm_page_prot = __P101;
27133 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27134
27135 return 0;
27136 }
27137 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27138 if (compat)
27139 addr = VDSO_HIGH_BASE;
27140 else {
27141 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27142 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27143 if (IS_ERR_VALUE(addr)) {
27144 ret = addr;
27145 goto up_fail;
27146 }
27147 }
27148
27149 - current->mm->context.vdso = (void *)addr;
27150 + current->mm->context.vdso = addr;
27151
27152 if (compat_uses_vma || !compat) {
27153 /*
27154 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27155 }
27156
27157 current_thread_info()->sysenter_return =
27158 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27159 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27160
27161 up_fail:
27162 if (ret)
27163 - current->mm->context.vdso = NULL;
27164 + current->mm->context.vdso = 0;
27165
27166 up_write(&mm->mmap_sem);
27167
27168 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27169
27170 const char *arch_vma_name(struct vm_area_struct *vma)
27171 {
27172 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27173 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27174 return "[vdso]";
27175 +
27176 +#ifdef CONFIG_PAX_SEGMEXEC
27177 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27178 + return "[vdso]";
27179 +#endif
27180 +
27181 return NULL;
27182 }
27183
27184 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27185 * Check to see if the corresponding task was created in compat vdso
27186 * mode.
27187 */
27188 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27189 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27190 return &gate_vma;
27191 return NULL;
27192 }
27193 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27194 index 00aaf04..4a26505 100644
27195 --- a/arch/x86/vdso/vma.c
27196 +++ b/arch/x86/vdso/vma.c
27197 @@ -16,8 +16,6 @@
27198 #include <asm/vdso.h>
27199 #include <asm/page.h>
27200
27201 -unsigned int __read_mostly vdso_enabled = 1;
27202 -
27203 extern char vdso_start[], vdso_end[];
27204 extern unsigned short vdso_sync_cpuid;
27205
27206 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27207 * unaligned here as a result of stack start randomization.
27208 */
27209 addr = PAGE_ALIGN(addr);
27210 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27211
27212 return addr;
27213 }
27214 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27215 unsigned size)
27216 {
27217 struct mm_struct *mm = current->mm;
27218 - unsigned long addr;
27219 + unsigned long addr = 0;
27220 int ret;
27221
27222 - if (!vdso_enabled)
27223 - return 0;
27224 -
27225 down_write(&mm->mmap_sem);
27226 +
27227 +#ifdef CONFIG_PAX_RANDMMAP
27228 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27229 +#endif
27230 +
27231 addr = vdso_addr(mm->start_stack, size);
27232 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27233 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27234 if (IS_ERR_VALUE(addr)) {
27235 ret = addr;
27236 goto up_fail;
27237 }
27238
27239 - current->mm->context.vdso = (void *)addr;
27240 + mm->context.vdso = addr;
27241
27242 ret = install_special_mapping(mm, addr, size,
27243 VM_READ|VM_EXEC|
27244 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27245 pages);
27246 - if (ret) {
27247 - current->mm->context.vdso = NULL;
27248 - goto up_fail;
27249 - }
27250 + if (ret)
27251 + mm->context.vdso = 0;
27252
27253 up_fail:
27254 up_write(&mm->mmap_sem);
27255 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27256 vdsox32_size);
27257 }
27258 #endif
27259 -
27260 -static __init int vdso_setup(char *s)
27261 -{
27262 - vdso_enabled = simple_strtoul(s, NULL, 0);
27263 - return 0;
27264 -}
27265 -__setup("vdso=", vdso_setup);
27266 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27267 index c1461de..355f120 100644
27268 --- a/arch/x86/xen/enlighten.c
27269 +++ b/arch/x86/xen/enlighten.c
27270 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27271
27272 struct shared_info xen_dummy_shared_info;
27273
27274 -void *xen_initial_gdt;
27275 -
27276 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27277 __read_mostly int xen_have_vector_callback;
27278 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27279 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27280
27281 static void set_xen_basic_apic_ops(void)
27282 {
27283 - apic->read = xen_apic_read;
27284 - apic->write = xen_apic_write;
27285 - apic->icr_read = xen_apic_icr_read;
27286 - apic->icr_write = xen_apic_icr_write;
27287 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27288 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27289 - apic->set_apic_id = xen_set_apic_id;
27290 - apic->get_apic_id = xen_get_apic_id;
27291 + *(void **)&apic->read = xen_apic_read;
27292 + *(void **)&apic->write = xen_apic_write;
27293 + *(void **)&apic->icr_read = xen_apic_icr_read;
27294 + *(void **)&apic->icr_write = xen_apic_icr_write;
27295 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27296 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27297 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27298 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27299
27300 #ifdef CONFIG_SMP
27301 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27302 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27303 - apic->send_IPI_mask = xen_send_IPI_mask;
27304 - apic->send_IPI_all = xen_send_IPI_all;
27305 - apic->send_IPI_self = xen_send_IPI_self;
27306 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27307 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27308 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27309 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27310 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27311 #endif
27312 }
27313
27314 @@ -1221,30 +1219,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27315 #endif
27316 };
27317
27318 -static void xen_reboot(int reason)
27319 +static __noreturn void xen_reboot(int reason)
27320 {
27321 struct sched_shutdown r = { .reason = reason };
27322
27323 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27324 - BUG();
27325 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27326 + BUG();
27327 }
27328
27329 -static void xen_restart(char *msg)
27330 +static __noreturn void xen_restart(char *msg)
27331 {
27332 xen_reboot(SHUTDOWN_reboot);
27333 }
27334
27335 -static void xen_emergency_restart(void)
27336 +static __noreturn void xen_emergency_restart(void)
27337 {
27338 xen_reboot(SHUTDOWN_reboot);
27339 }
27340
27341 -static void xen_machine_halt(void)
27342 +static __noreturn void xen_machine_halt(void)
27343 {
27344 xen_reboot(SHUTDOWN_poweroff);
27345 }
27346
27347 -static void xen_machine_power_off(void)
27348 +static __noreturn void xen_machine_power_off(void)
27349 {
27350 if (pm_power_off)
27351 pm_power_off();
27352 @@ -1347,7 +1345,17 @@ asmlinkage void __init xen_start_kernel(void)
27353 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27354
27355 /* Work out if we support NX */
27356 - x86_configure_nx();
27357 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27358 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27359 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27360 + unsigned l, h;
27361 +
27362 + __supported_pte_mask |= _PAGE_NX;
27363 + rdmsr(MSR_EFER, l, h);
27364 + l |= EFER_NX;
27365 + wrmsr(MSR_EFER, l, h);
27366 + }
27367 +#endif
27368
27369 xen_setup_features();
27370
27371 @@ -1378,13 +1386,6 @@ asmlinkage void __init xen_start_kernel(void)
27372
27373 machine_ops = xen_machine_ops;
27374
27375 - /*
27376 - * The only reliable way to retain the initial address of the
27377 - * percpu gdt_page is to remember it here, so we can go and
27378 - * mark it RW later, when the initial percpu area is freed.
27379 - */
27380 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27381 -
27382 xen_smp_init();
27383
27384 #ifdef CONFIG_ACPI_NUMA
27385 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27386 index 5141d80..6c9fb41 100644
27387 --- a/arch/x86/xen/mmu.c
27388 +++ b/arch/x86/xen/mmu.c
27389 @@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27390 convert_pfn_mfn(init_level4_pgt);
27391 convert_pfn_mfn(level3_ident_pgt);
27392 convert_pfn_mfn(level3_kernel_pgt);
27393 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27394 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27395 + convert_pfn_mfn(level3_vmemmap_pgt);
27396
27397 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27398 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27399 @@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27400 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27401 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27402 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27403 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27404 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27405 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27406 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27407 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27408 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27409 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27410
27411 @@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27412 pv_mmu_ops.set_pud = xen_set_pud;
27413 #if PAGETABLE_LEVELS == 4
27414 pv_mmu_ops.set_pgd = xen_set_pgd;
27415 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27416 #endif
27417
27418 /* This will work as long as patching hasn't happened yet
27419 @@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27420 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27421 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27422 .set_pgd = xen_set_pgd_hyper,
27423 + .set_pgd_batched = xen_set_pgd_hyper,
27424
27425 .alloc_pud = xen_alloc_pmd_init,
27426 .release_pud = xen_release_pmd_init,
27427 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27428 index f58dca7..ad21f52 100644
27429 --- a/arch/x86/xen/smp.c
27430 +++ b/arch/x86/xen/smp.c
27431 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27432 {
27433 BUG_ON(smp_processor_id() != 0);
27434 native_smp_prepare_boot_cpu();
27435 -
27436 - /* We've switched to the "real" per-cpu gdt, so make sure the
27437 - old memory can be recycled */
27438 - make_lowmem_page_readwrite(xen_initial_gdt);
27439 -
27440 xen_filter_cpu_maps();
27441 xen_setup_vcpu_info_placement();
27442 }
27443 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27444 gdt = get_cpu_gdt_table(cpu);
27445
27446 ctxt->flags = VGCF_IN_KERNEL;
27447 - ctxt->user_regs.ds = __USER_DS;
27448 - ctxt->user_regs.es = __USER_DS;
27449 + ctxt->user_regs.ds = __KERNEL_DS;
27450 + ctxt->user_regs.es = __KERNEL_DS;
27451 ctxt->user_regs.ss = __KERNEL_DS;
27452 #ifdef CONFIG_X86_32
27453 ctxt->user_regs.fs = __KERNEL_PERCPU;
27454 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27455 + savesegment(gs, ctxt->user_regs.gs);
27456 #else
27457 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27458 #endif
27459 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27460 int rc;
27461
27462 per_cpu(current_task, cpu) = idle;
27463 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27464 #ifdef CONFIG_X86_32
27465 irq_ctx_init(cpu);
27466 #else
27467 clear_tsk_thread_flag(idle, TIF_FORK);
27468 - per_cpu(kernel_stack, cpu) =
27469 - (unsigned long)task_stack_page(idle) -
27470 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27471 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27472 #endif
27473 xen_setup_runstate_info(cpu);
27474 xen_setup_timer(cpu);
27475 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27476 index f9643fc..602e8af 100644
27477 --- a/arch/x86/xen/xen-asm_32.S
27478 +++ b/arch/x86/xen/xen-asm_32.S
27479 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27480 ESP_OFFSET=4 # bytes pushed onto stack
27481
27482 /*
27483 - * Store vcpu_info pointer for easy access. Do it this way to
27484 - * avoid having to reload %fs
27485 + * Store vcpu_info pointer for easy access.
27486 */
27487 #ifdef CONFIG_SMP
27488 - GET_THREAD_INFO(%eax)
27489 - movl TI_cpu(%eax), %eax
27490 - movl __per_cpu_offset(,%eax,4), %eax
27491 - mov xen_vcpu(%eax), %eax
27492 + push %fs
27493 + mov $(__KERNEL_PERCPU), %eax
27494 + mov %eax, %fs
27495 + mov PER_CPU_VAR(xen_vcpu), %eax
27496 + pop %fs
27497 #else
27498 movl xen_vcpu, %eax
27499 #endif
27500 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27501 index aaa7291..3f77960 100644
27502 --- a/arch/x86/xen/xen-head.S
27503 +++ b/arch/x86/xen/xen-head.S
27504 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27505 #ifdef CONFIG_X86_32
27506 mov %esi,xen_start_info
27507 mov $init_thread_union+THREAD_SIZE,%esp
27508 +#ifdef CONFIG_SMP
27509 + movl $cpu_gdt_table,%edi
27510 + movl $__per_cpu_load,%eax
27511 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27512 + rorl $16,%eax
27513 + movb %al,__KERNEL_PERCPU + 4(%edi)
27514 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27515 + movl $__per_cpu_end - 1,%eax
27516 + subl $__per_cpu_start,%eax
27517 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27518 +#endif
27519 #else
27520 mov %rsi,xen_start_info
27521 mov $init_thread_union+THREAD_SIZE,%rsp
27522 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27523 index 202d4c1..99b072a 100644
27524 --- a/arch/x86/xen/xen-ops.h
27525 +++ b/arch/x86/xen/xen-ops.h
27526 @@ -10,8 +10,6 @@
27527 extern const char xen_hypervisor_callback[];
27528 extern const char xen_failsafe_callback[];
27529
27530 -extern void *xen_initial_gdt;
27531 -
27532 struct trap_info;
27533 void xen_copy_trap_info(struct trap_info *traps);
27534
27535 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27536 index 525bd3d..ef888b1 100644
27537 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27538 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27539 @@ -119,9 +119,9 @@
27540 ----------------------------------------------------------------------*/
27541
27542 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27543 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27544 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27545 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27546 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27547
27548 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27549 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27550 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27551 index 2f33760..835e50a 100644
27552 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27553 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27554 @@ -11,6 +11,7 @@
27555 #ifndef _XTENSA_CORE_H
27556 #define _XTENSA_CORE_H
27557
27558 +#include <linux/const.h>
27559
27560 /****************************************************************************
27561 Parameters Useful for Any Code, USER or PRIVILEGED
27562 @@ -112,9 +113,9 @@
27563 ----------------------------------------------------------------------*/
27564
27565 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27566 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27567 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27568 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27569 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27570
27571 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27572 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27573 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27574 index af00795..2bb8105 100644
27575 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27576 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27577 @@ -11,6 +11,7 @@
27578 #ifndef _XTENSA_CORE_CONFIGURATION_H
27579 #define _XTENSA_CORE_CONFIGURATION_H
27580
27581 +#include <linux/const.h>
27582
27583 /****************************************************************************
27584 Parameters Useful for Any Code, USER or PRIVILEGED
27585 @@ -118,9 +119,9 @@
27586 ----------------------------------------------------------------------*/
27587
27588 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27589 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27590 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27591 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27592 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27593
27594 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27595 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27596 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27597 index 58916af..9cb880b 100644
27598 --- a/block/blk-iopoll.c
27599 +++ b/block/blk-iopoll.c
27600 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27601 }
27602 EXPORT_SYMBOL(blk_iopoll_complete);
27603
27604 -static void blk_iopoll_softirq(struct softirq_action *h)
27605 +static void blk_iopoll_softirq(void)
27606 {
27607 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27608 int rearm = 0, budget = blk_iopoll_budget;
27609 diff --git a/block/blk-map.c b/block/blk-map.c
27610 index 623e1cd..ca1e109 100644
27611 --- a/block/blk-map.c
27612 +++ b/block/blk-map.c
27613 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27614 if (!len || !kbuf)
27615 return -EINVAL;
27616
27617 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27618 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27619 if (do_copy)
27620 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27621 else
27622 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27623 index 467c8de..4bddc6d 100644
27624 --- a/block/blk-softirq.c
27625 +++ b/block/blk-softirq.c
27626 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27627 * Softirq action handler - move entries to local list and loop over them
27628 * while passing them to the queue registered handler.
27629 */
27630 -static void blk_done_softirq(struct softirq_action *h)
27631 +static void blk_done_softirq(void)
27632 {
27633 struct list_head *cpu_list, local_list;
27634
27635 diff --git a/block/bsg.c b/block/bsg.c
27636 index ff64ae3..593560c 100644
27637 --- a/block/bsg.c
27638 +++ b/block/bsg.c
27639 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27640 struct sg_io_v4 *hdr, struct bsg_device *bd,
27641 fmode_t has_write_perm)
27642 {
27643 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27644 + unsigned char *cmdptr;
27645 +
27646 if (hdr->request_len > BLK_MAX_CDB) {
27647 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27648 if (!rq->cmd)
27649 return -ENOMEM;
27650 - }
27651 + cmdptr = rq->cmd;
27652 + } else
27653 + cmdptr = tmpcmd;
27654
27655 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27656 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27657 hdr->request_len))
27658 return -EFAULT;
27659
27660 + if (cmdptr != rq->cmd)
27661 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27662 +
27663 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27664 if (blk_verify_command(rq->cmd, has_write_perm))
27665 return -EPERM;
27666 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27667 index 7c668c8..db3521c 100644
27668 --- a/block/compat_ioctl.c
27669 +++ b/block/compat_ioctl.c
27670 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27671 err |= __get_user(f->spec1, &uf->spec1);
27672 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27673 err |= __get_user(name, &uf->name);
27674 - f->name = compat_ptr(name);
27675 + f->name = (void __force_kernel *)compat_ptr(name);
27676 if (err) {
27677 err = -EFAULT;
27678 goto out;
27679 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27680 index 6296b40..417c00f 100644
27681 --- a/block/partitions/efi.c
27682 +++ b/block/partitions/efi.c
27683 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27684 if (!gpt)
27685 return NULL;
27686
27687 + if (!le32_to_cpu(gpt->num_partition_entries))
27688 + return NULL;
27689 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27690 + if (!pte)
27691 + return NULL;
27692 +
27693 count = le32_to_cpu(gpt->num_partition_entries) *
27694 le32_to_cpu(gpt->sizeof_partition_entry);
27695 - if (!count)
27696 - return NULL;
27697 - pte = kzalloc(count, GFP_KERNEL);
27698 - if (!pte)
27699 - return NULL;
27700 -
27701 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27702 (u8 *) pte,
27703 count) < count) {
27704 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27705 index 9a87daa..fb17486 100644
27706 --- a/block/scsi_ioctl.c
27707 +++ b/block/scsi_ioctl.c
27708 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27709 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27710 struct sg_io_hdr *hdr, fmode_t mode)
27711 {
27712 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27713 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27714 + unsigned char *cmdptr;
27715 +
27716 + if (rq->cmd != rq->__cmd)
27717 + cmdptr = rq->cmd;
27718 + else
27719 + cmdptr = tmpcmd;
27720 +
27721 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27722 return -EFAULT;
27723 +
27724 + if (cmdptr != rq->cmd)
27725 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27726 +
27727 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27728 return -EPERM;
27729
27730 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27731 int err;
27732 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27733 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27734 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27735 + unsigned char *cmdptr;
27736
27737 if (!sic)
27738 return -EINVAL;
27739 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27740 */
27741 err = -EFAULT;
27742 rq->cmd_len = cmdlen;
27743 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27744 +
27745 + if (rq->cmd != rq->__cmd)
27746 + cmdptr = rq->cmd;
27747 + else
27748 + cmdptr = tmpcmd;
27749 +
27750 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27751 goto error;
27752
27753 + if (rq->cmd != cmdptr)
27754 + memcpy(rq->cmd, cmdptr, cmdlen);
27755 +
27756 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27757 goto error;
27758
27759 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27760 index 671d4d6..5f24030 100644
27761 --- a/crypto/cryptd.c
27762 +++ b/crypto/cryptd.c
27763 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27764
27765 struct cryptd_blkcipher_request_ctx {
27766 crypto_completion_t complete;
27767 -};
27768 +} __no_const;
27769
27770 struct cryptd_hash_ctx {
27771 struct crypto_shash *child;
27772 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27773
27774 struct cryptd_aead_request_ctx {
27775 crypto_completion_t complete;
27776 -};
27777 +} __no_const;
27778
27779 static void cryptd_queue_worker(struct work_struct *work);
27780
27781 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27782 index e6defd8..c26a225 100644
27783 --- a/drivers/acpi/apei/cper.c
27784 +++ b/drivers/acpi/apei/cper.c
27785 @@ -38,12 +38,12 @@
27786 */
27787 u64 cper_next_record_id(void)
27788 {
27789 - static atomic64_t seq;
27790 + static atomic64_unchecked_t seq;
27791
27792 - if (!atomic64_read(&seq))
27793 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27794 + if (!atomic64_read_unchecked(&seq))
27795 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27796
27797 - return atomic64_inc_return(&seq);
27798 + return atomic64_inc_return_unchecked(&seq);
27799 }
27800 EXPORT_SYMBOL_GPL(cper_next_record_id);
27801
27802 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27803 index 7586544..636a2f0 100644
27804 --- a/drivers/acpi/ec_sys.c
27805 +++ b/drivers/acpi/ec_sys.c
27806 @@ -12,6 +12,7 @@
27807 #include <linux/acpi.h>
27808 #include <linux/debugfs.h>
27809 #include <linux/module.h>
27810 +#include <linux/uaccess.h>
27811 #include "internal.h"
27812
27813 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27814 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27815 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27816 */
27817 unsigned int size = EC_SPACE_SIZE;
27818 - u8 *data = (u8 *) buf;
27819 + u8 data;
27820 loff_t init_off = *off;
27821 int err = 0;
27822
27823 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27824 size = count;
27825
27826 while (size) {
27827 - err = ec_read(*off, &data[*off - init_off]);
27828 + err = ec_read(*off, &data);
27829 if (err)
27830 return err;
27831 + if (put_user(data, &buf[*off - init_off]))
27832 + return -EFAULT;
27833 *off += 1;
27834 size--;
27835 }
27836 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27837
27838 unsigned int size = count;
27839 loff_t init_off = *off;
27840 - u8 *data = (u8 *) buf;
27841 int err = 0;
27842
27843 if (*off >= EC_SPACE_SIZE)
27844 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27845 }
27846
27847 while (size) {
27848 - u8 byte_write = data[*off - init_off];
27849 + u8 byte_write;
27850 + if (get_user(byte_write, &buf[*off - init_off]))
27851 + return -EFAULT;
27852 err = ec_write(*off, byte_write);
27853 if (err)
27854 return err;
27855 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27856 index 251c7b62..000462d 100644
27857 --- a/drivers/acpi/proc.c
27858 +++ b/drivers/acpi/proc.c
27859 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27860 size_t count, loff_t * ppos)
27861 {
27862 struct list_head *node, *next;
27863 - char strbuf[5];
27864 - char str[5] = "";
27865 - unsigned int len = count;
27866 + char strbuf[5] = {0};
27867
27868 - if (len > 4)
27869 - len = 4;
27870 - if (len < 0)
27871 + if (count > 4)
27872 + count = 4;
27873 + if (copy_from_user(strbuf, buffer, count))
27874 return -EFAULT;
27875 -
27876 - if (copy_from_user(strbuf, buffer, len))
27877 - return -EFAULT;
27878 - strbuf[len] = '\0';
27879 - sscanf(strbuf, "%s", str);
27880 + strbuf[count] = '\0';
27881
27882 mutex_lock(&acpi_device_lock);
27883 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27884 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27885 if (!dev->wakeup.flags.valid)
27886 continue;
27887
27888 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27889 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27890 if (device_can_wakeup(&dev->dev)) {
27891 bool enable = !device_may_wakeup(&dev->dev);
27892 device_set_wakeup_enable(&dev->dev, enable);
27893 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27894 index bfc31cb..8213ce1 100644
27895 --- a/drivers/acpi/processor_driver.c
27896 +++ b/drivers/acpi/processor_driver.c
27897 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27898 return 0;
27899 #endif
27900
27901 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27902 + BUG_ON(pr->id >= nr_cpu_ids);
27903
27904 /*
27905 * Buggy BIOS check
27906 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27907 index 8e1039c..ea9cbd4 100644
27908 --- a/drivers/ata/libata-core.c
27909 +++ b/drivers/ata/libata-core.c
27910 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27911 struct ata_port *ap;
27912 unsigned int tag;
27913
27914 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27915 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27916 ap = qc->ap;
27917
27918 qc->flags = 0;
27919 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27920 struct ata_port *ap;
27921 struct ata_link *link;
27922
27923 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27924 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27925 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27926 ap = qc->ap;
27927 link = qc->dev->link;
27928 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27929 return;
27930
27931 spin_lock(&lock);
27932 + pax_open_kernel();
27933
27934 for (cur = ops->inherits; cur; cur = cur->inherits) {
27935 void **inherit = (void **)cur;
27936 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27937 if (IS_ERR(*pp))
27938 *pp = NULL;
27939
27940 - ops->inherits = NULL;
27941 + *(struct ata_port_operations **)&ops->inherits = NULL;
27942
27943 + pax_close_kernel();
27944 spin_unlock(&lock);
27945 }
27946
27947 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27948 index bfaa5cb..3ba1cc3 100644
27949 --- a/drivers/ata/pata_arasan_cf.c
27950 +++ b/drivers/ata/pata_arasan_cf.c
27951 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27952 /* Handle platform specific quirks */
27953 if (pdata->quirk) {
27954 if (pdata->quirk & CF_BROKEN_PIO) {
27955 - ap->ops->set_piomode = NULL;
27956 + pax_open_kernel();
27957 + *(void **)&ap->ops->set_piomode = NULL;
27958 + pax_close_kernel();
27959 ap->pio_mask = 0;
27960 }
27961 if (pdata->quirk & CF_BROKEN_MWDMA)
27962 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27963 index f9b983a..887b9d8 100644
27964 --- a/drivers/atm/adummy.c
27965 +++ b/drivers/atm/adummy.c
27966 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27967 vcc->pop(vcc, skb);
27968 else
27969 dev_kfree_skb_any(skb);
27970 - atomic_inc(&vcc->stats->tx);
27971 + atomic_inc_unchecked(&vcc->stats->tx);
27972
27973 return 0;
27974 }
27975 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27976 index 89b30f3..7964211 100644
27977 --- a/drivers/atm/ambassador.c
27978 +++ b/drivers/atm/ambassador.c
27979 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27980 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27981
27982 // VC layer stats
27983 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27984 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27985
27986 // free the descriptor
27987 kfree (tx_descr);
27988 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27989 dump_skb ("<<<", vc, skb);
27990
27991 // VC layer stats
27992 - atomic_inc(&atm_vcc->stats->rx);
27993 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27994 __net_timestamp(skb);
27995 // end of our responsibility
27996 atm_vcc->push (atm_vcc, skb);
27997 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27998 } else {
27999 PRINTK (KERN_INFO, "dropped over-size frame");
28000 // should we count this?
28001 - atomic_inc(&atm_vcc->stats->rx_drop);
28002 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28003 }
28004
28005 } else {
28006 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28007 }
28008
28009 if (check_area (skb->data, skb->len)) {
28010 - atomic_inc(&atm_vcc->stats->tx_err);
28011 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28012 return -ENOMEM; // ?
28013 }
28014
28015 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28016 index b22d71c..d6e1049 100644
28017 --- a/drivers/atm/atmtcp.c
28018 +++ b/drivers/atm/atmtcp.c
28019 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28020 if (vcc->pop) vcc->pop(vcc,skb);
28021 else dev_kfree_skb(skb);
28022 if (dev_data) return 0;
28023 - atomic_inc(&vcc->stats->tx_err);
28024 + atomic_inc_unchecked(&vcc->stats->tx_err);
28025 return -ENOLINK;
28026 }
28027 size = skb->len+sizeof(struct atmtcp_hdr);
28028 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28029 if (!new_skb) {
28030 if (vcc->pop) vcc->pop(vcc,skb);
28031 else dev_kfree_skb(skb);
28032 - atomic_inc(&vcc->stats->tx_err);
28033 + atomic_inc_unchecked(&vcc->stats->tx_err);
28034 return -ENOBUFS;
28035 }
28036 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28037 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28038 if (vcc->pop) vcc->pop(vcc,skb);
28039 else dev_kfree_skb(skb);
28040 out_vcc->push(out_vcc,new_skb);
28041 - atomic_inc(&vcc->stats->tx);
28042 - atomic_inc(&out_vcc->stats->rx);
28043 + atomic_inc_unchecked(&vcc->stats->tx);
28044 + atomic_inc_unchecked(&out_vcc->stats->rx);
28045 return 0;
28046 }
28047
28048 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28049 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28050 read_unlock(&vcc_sklist_lock);
28051 if (!out_vcc) {
28052 - atomic_inc(&vcc->stats->tx_err);
28053 + atomic_inc_unchecked(&vcc->stats->tx_err);
28054 goto done;
28055 }
28056 skb_pull(skb,sizeof(struct atmtcp_hdr));
28057 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28058 __net_timestamp(new_skb);
28059 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28060 out_vcc->push(out_vcc,new_skb);
28061 - atomic_inc(&vcc->stats->tx);
28062 - atomic_inc(&out_vcc->stats->rx);
28063 + atomic_inc_unchecked(&vcc->stats->tx);
28064 + atomic_inc_unchecked(&out_vcc->stats->rx);
28065 done:
28066 if (vcc->pop) vcc->pop(vcc,skb);
28067 else dev_kfree_skb(skb);
28068 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28069 index 2059ee4..faf51c7 100644
28070 --- a/drivers/atm/eni.c
28071 +++ b/drivers/atm/eni.c
28072 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28073 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28074 vcc->dev->number);
28075 length = 0;
28076 - atomic_inc(&vcc->stats->rx_err);
28077 + atomic_inc_unchecked(&vcc->stats->rx_err);
28078 }
28079 else {
28080 length = ATM_CELL_SIZE-1; /* no HEC */
28081 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28082 size);
28083 }
28084 eff = length = 0;
28085 - atomic_inc(&vcc->stats->rx_err);
28086 + atomic_inc_unchecked(&vcc->stats->rx_err);
28087 }
28088 else {
28089 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28090 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28091 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28092 vcc->dev->number,vcc->vci,length,size << 2,descr);
28093 length = eff = 0;
28094 - atomic_inc(&vcc->stats->rx_err);
28095 + atomic_inc_unchecked(&vcc->stats->rx_err);
28096 }
28097 }
28098 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28099 @@ -767,7 +767,7 @@ rx_dequeued++;
28100 vcc->push(vcc,skb);
28101 pushed++;
28102 }
28103 - atomic_inc(&vcc->stats->rx);
28104 + atomic_inc_unchecked(&vcc->stats->rx);
28105 }
28106 wake_up(&eni_dev->rx_wait);
28107 }
28108 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28109 PCI_DMA_TODEVICE);
28110 if (vcc->pop) vcc->pop(vcc,skb);
28111 else dev_kfree_skb_irq(skb);
28112 - atomic_inc(&vcc->stats->tx);
28113 + atomic_inc_unchecked(&vcc->stats->tx);
28114 wake_up(&eni_dev->tx_wait);
28115 dma_complete++;
28116 }
28117 @@ -1567,7 +1567,7 @@ tx_complete++;
28118 /*--------------------------------- entries ---------------------------------*/
28119
28120
28121 -static const char *media_name[] __devinitdata = {
28122 +static const char *media_name[] __devinitconst = {
28123 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28124 "UTP", "05?", "06?", "07?", /* 4- 7 */
28125 "TAXI","09?", "10?", "11?", /* 8-11 */
28126 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28127 index 86fed1b..6dc4721 100644
28128 --- a/drivers/atm/firestream.c
28129 +++ b/drivers/atm/firestream.c
28130 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28131 }
28132 }
28133
28134 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28135 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28136
28137 fs_dprintk (FS_DEBUG_TXMEM, "i");
28138 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28139 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28140 #endif
28141 skb_put (skb, qe->p1 & 0xffff);
28142 ATM_SKB(skb)->vcc = atm_vcc;
28143 - atomic_inc(&atm_vcc->stats->rx);
28144 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28145 __net_timestamp(skb);
28146 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28147 atm_vcc->push (atm_vcc, skb);
28148 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28149 kfree (pe);
28150 }
28151 if (atm_vcc)
28152 - atomic_inc(&atm_vcc->stats->rx_drop);
28153 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28154 break;
28155 case 0x1f: /* Reassembly abort: no buffers. */
28156 /* Silently increment error counter. */
28157 if (atm_vcc)
28158 - atomic_inc(&atm_vcc->stats->rx_drop);
28159 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28160 break;
28161 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28162 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28163 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28164 index 361f5ae..7fc552d 100644
28165 --- a/drivers/atm/fore200e.c
28166 +++ b/drivers/atm/fore200e.c
28167 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28168 #endif
28169 /* check error condition */
28170 if (*entry->status & STATUS_ERROR)
28171 - atomic_inc(&vcc->stats->tx_err);
28172 + atomic_inc_unchecked(&vcc->stats->tx_err);
28173 else
28174 - atomic_inc(&vcc->stats->tx);
28175 + atomic_inc_unchecked(&vcc->stats->tx);
28176 }
28177 }
28178
28179 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28180 if (skb == NULL) {
28181 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28182
28183 - atomic_inc(&vcc->stats->rx_drop);
28184 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28185 return -ENOMEM;
28186 }
28187
28188 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28189
28190 dev_kfree_skb_any(skb);
28191
28192 - atomic_inc(&vcc->stats->rx_drop);
28193 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28194 return -ENOMEM;
28195 }
28196
28197 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28198
28199 vcc->push(vcc, skb);
28200 - atomic_inc(&vcc->stats->rx);
28201 + atomic_inc_unchecked(&vcc->stats->rx);
28202
28203 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28204
28205 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28206 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28207 fore200e->atm_dev->number,
28208 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28209 - atomic_inc(&vcc->stats->rx_err);
28210 + atomic_inc_unchecked(&vcc->stats->rx_err);
28211 }
28212 }
28213
28214 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28215 goto retry_here;
28216 }
28217
28218 - atomic_inc(&vcc->stats->tx_err);
28219 + atomic_inc_unchecked(&vcc->stats->tx_err);
28220
28221 fore200e->tx_sat++;
28222 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28223 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28224 index b182c2f..1c6fa8a 100644
28225 --- a/drivers/atm/he.c
28226 +++ b/drivers/atm/he.c
28227 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28228
28229 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28230 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28231 - atomic_inc(&vcc->stats->rx_drop);
28232 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28233 goto return_host_buffers;
28234 }
28235
28236 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28237 RBRQ_LEN_ERR(he_dev->rbrq_head)
28238 ? "LEN_ERR" : "",
28239 vcc->vpi, vcc->vci);
28240 - atomic_inc(&vcc->stats->rx_err);
28241 + atomic_inc_unchecked(&vcc->stats->rx_err);
28242 goto return_host_buffers;
28243 }
28244
28245 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28246 vcc->push(vcc, skb);
28247 spin_lock(&he_dev->global_lock);
28248
28249 - atomic_inc(&vcc->stats->rx);
28250 + atomic_inc_unchecked(&vcc->stats->rx);
28251
28252 return_host_buffers:
28253 ++pdus_assembled;
28254 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28255 tpd->vcc->pop(tpd->vcc, tpd->skb);
28256 else
28257 dev_kfree_skb_any(tpd->skb);
28258 - atomic_inc(&tpd->vcc->stats->tx_err);
28259 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28260 }
28261 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28262 return;
28263 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28264 vcc->pop(vcc, skb);
28265 else
28266 dev_kfree_skb_any(skb);
28267 - atomic_inc(&vcc->stats->tx_err);
28268 + atomic_inc_unchecked(&vcc->stats->tx_err);
28269 return -EINVAL;
28270 }
28271
28272 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28273 vcc->pop(vcc, skb);
28274 else
28275 dev_kfree_skb_any(skb);
28276 - atomic_inc(&vcc->stats->tx_err);
28277 + atomic_inc_unchecked(&vcc->stats->tx_err);
28278 return -EINVAL;
28279 }
28280 #endif
28281 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28282 vcc->pop(vcc, skb);
28283 else
28284 dev_kfree_skb_any(skb);
28285 - atomic_inc(&vcc->stats->tx_err);
28286 + atomic_inc_unchecked(&vcc->stats->tx_err);
28287 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28288 return -ENOMEM;
28289 }
28290 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28291 vcc->pop(vcc, skb);
28292 else
28293 dev_kfree_skb_any(skb);
28294 - atomic_inc(&vcc->stats->tx_err);
28295 + atomic_inc_unchecked(&vcc->stats->tx_err);
28296 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28297 return -ENOMEM;
28298 }
28299 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28300 __enqueue_tpd(he_dev, tpd, cid);
28301 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28302
28303 - atomic_inc(&vcc->stats->tx);
28304 + atomic_inc_unchecked(&vcc->stats->tx);
28305
28306 return 0;
28307 }
28308 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28309 index 7d01c2a..4e3ac01 100644
28310 --- a/drivers/atm/horizon.c
28311 +++ b/drivers/atm/horizon.c
28312 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28313 {
28314 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28315 // VC layer stats
28316 - atomic_inc(&vcc->stats->rx);
28317 + atomic_inc_unchecked(&vcc->stats->rx);
28318 __net_timestamp(skb);
28319 // end of our responsibility
28320 vcc->push (vcc, skb);
28321 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28322 dev->tx_iovec = NULL;
28323
28324 // VC layer stats
28325 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28326 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28327
28328 // free the skb
28329 hrz_kfree_skb (skb);
28330 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28331 index 8974bd2..b856f85 100644
28332 --- a/drivers/atm/idt77252.c
28333 +++ b/drivers/atm/idt77252.c
28334 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28335 else
28336 dev_kfree_skb(skb);
28337
28338 - atomic_inc(&vcc->stats->tx);
28339 + atomic_inc_unchecked(&vcc->stats->tx);
28340 }
28341
28342 atomic_dec(&scq->used);
28343 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28344 if ((sb = dev_alloc_skb(64)) == NULL) {
28345 printk("%s: Can't allocate buffers for aal0.\n",
28346 card->name);
28347 - atomic_add(i, &vcc->stats->rx_drop);
28348 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28349 break;
28350 }
28351 if (!atm_charge(vcc, sb->truesize)) {
28352 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28353 card->name);
28354 - atomic_add(i - 1, &vcc->stats->rx_drop);
28355 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28356 dev_kfree_skb(sb);
28357 break;
28358 }
28359 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28360 ATM_SKB(sb)->vcc = vcc;
28361 __net_timestamp(sb);
28362 vcc->push(vcc, sb);
28363 - atomic_inc(&vcc->stats->rx);
28364 + atomic_inc_unchecked(&vcc->stats->rx);
28365
28366 cell += ATM_CELL_PAYLOAD;
28367 }
28368 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28369 "(CDC: %08x)\n",
28370 card->name, len, rpp->len, readl(SAR_REG_CDC));
28371 recycle_rx_pool_skb(card, rpp);
28372 - atomic_inc(&vcc->stats->rx_err);
28373 + atomic_inc_unchecked(&vcc->stats->rx_err);
28374 return;
28375 }
28376 if (stat & SAR_RSQE_CRC) {
28377 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28378 recycle_rx_pool_skb(card, rpp);
28379 - atomic_inc(&vcc->stats->rx_err);
28380 + atomic_inc_unchecked(&vcc->stats->rx_err);
28381 return;
28382 }
28383 if (skb_queue_len(&rpp->queue) > 1) {
28384 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28385 RXPRINTK("%s: Can't alloc RX skb.\n",
28386 card->name);
28387 recycle_rx_pool_skb(card, rpp);
28388 - atomic_inc(&vcc->stats->rx_err);
28389 + atomic_inc_unchecked(&vcc->stats->rx_err);
28390 return;
28391 }
28392 if (!atm_charge(vcc, skb->truesize)) {
28393 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28394 __net_timestamp(skb);
28395
28396 vcc->push(vcc, skb);
28397 - atomic_inc(&vcc->stats->rx);
28398 + atomic_inc_unchecked(&vcc->stats->rx);
28399
28400 return;
28401 }
28402 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28403 __net_timestamp(skb);
28404
28405 vcc->push(vcc, skb);
28406 - atomic_inc(&vcc->stats->rx);
28407 + atomic_inc_unchecked(&vcc->stats->rx);
28408
28409 if (skb->truesize > SAR_FB_SIZE_3)
28410 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28411 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28412 if (vcc->qos.aal != ATM_AAL0) {
28413 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28414 card->name, vpi, vci);
28415 - atomic_inc(&vcc->stats->rx_drop);
28416 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28417 goto drop;
28418 }
28419
28420 if ((sb = dev_alloc_skb(64)) == NULL) {
28421 printk("%s: Can't allocate buffers for AAL0.\n",
28422 card->name);
28423 - atomic_inc(&vcc->stats->rx_err);
28424 + atomic_inc_unchecked(&vcc->stats->rx_err);
28425 goto drop;
28426 }
28427
28428 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28429 ATM_SKB(sb)->vcc = vcc;
28430 __net_timestamp(sb);
28431 vcc->push(vcc, sb);
28432 - atomic_inc(&vcc->stats->rx);
28433 + atomic_inc_unchecked(&vcc->stats->rx);
28434
28435 drop:
28436 skb_pull(queue, 64);
28437 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28438
28439 if (vc == NULL) {
28440 printk("%s: NULL connection in send().\n", card->name);
28441 - atomic_inc(&vcc->stats->tx_err);
28442 + atomic_inc_unchecked(&vcc->stats->tx_err);
28443 dev_kfree_skb(skb);
28444 return -EINVAL;
28445 }
28446 if (!test_bit(VCF_TX, &vc->flags)) {
28447 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28448 - atomic_inc(&vcc->stats->tx_err);
28449 + atomic_inc_unchecked(&vcc->stats->tx_err);
28450 dev_kfree_skb(skb);
28451 return -EINVAL;
28452 }
28453 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28454 break;
28455 default:
28456 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28457 - atomic_inc(&vcc->stats->tx_err);
28458 + atomic_inc_unchecked(&vcc->stats->tx_err);
28459 dev_kfree_skb(skb);
28460 return -EINVAL;
28461 }
28462
28463 if (skb_shinfo(skb)->nr_frags != 0) {
28464 printk("%s: No scatter-gather yet.\n", card->name);
28465 - atomic_inc(&vcc->stats->tx_err);
28466 + atomic_inc_unchecked(&vcc->stats->tx_err);
28467 dev_kfree_skb(skb);
28468 return -EINVAL;
28469 }
28470 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28471
28472 err = queue_skb(card, vc, skb, oam);
28473 if (err) {
28474 - atomic_inc(&vcc->stats->tx_err);
28475 + atomic_inc_unchecked(&vcc->stats->tx_err);
28476 dev_kfree_skb(skb);
28477 return err;
28478 }
28479 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28480 skb = dev_alloc_skb(64);
28481 if (!skb) {
28482 printk("%s: Out of memory in send_oam().\n", card->name);
28483 - atomic_inc(&vcc->stats->tx_err);
28484 + atomic_inc_unchecked(&vcc->stats->tx_err);
28485 return -ENOMEM;
28486 }
28487 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28488 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28489 index 96cce6d..62c3ec5 100644
28490 --- a/drivers/atm/iphase.c
28491 +++ b/drivers/atm/iphase.c
28492 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28493 status = (u_short) (buf_desc_ptr->desc_mode);
28494 if (status & (RX_CER | RX_PTE | RX_OFL))
28495 {
28496 - atomic_inc(&vcc->stats->rx_err);
28497 + atomic_inc_unchecked(&vcc->stats->rx_err);
28498 IF_ERR(printk("IA: bad packet, dropping it");)
28499 if (status & RX_CER) {
28500 IF_ERR(printk(" cause: packet CRC error\n");)
28501 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28502 len = dma_addr - buf_addr;
28503 if (len > iadev->rx_buf_sz) {
28504 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28505 - atomic_inc(&vcc->stats->rx_err);
28506 + atomic_inc_unchecked(&vcc->stats->rx_err);
28507 goto out_free_desc;
28508 }
28509
28510 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28511 ia_vcc = INPH_IA_VCC(vcc);
28512 if (ia_vcc == NULL)
28513 {
28514 - atomic_inc(&vcc->stats->rx_err);
28515 + atomic_inc_unchecked(&vcc->stats->rx_err);
28516 atm_return(vcc, skb->truesize);
28517 dev_kfree_skb_any(skb);
28518 goto INCR_DLE;
28519 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28520 if ((length > iadev->rx_buf_sz) || (length >
28521 (skb->len - sizeof(struct cpcs_trailer))))
28522 {
28523 - atomic_inc(&vcc->stats->rx_err);
28524 + atomic_inc_unchecked(&vcc->stats->rx_err);
28525 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28526 length, skb->len);)
28527 atm_return(vcc, skb->truesize);
28528 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28529
28530 IF_RX(printk("rx_dle_intr: skb push");)
28531 vcc->push(vcc,skb);
28532 - atomic_inc(&vcc->stats->rx);
28533 + atomic_inc_unchecked(&vcc->stats->rx);
28534 iadev->rx_pkt_cnt++;
28535 }
28536 INCR_DLE:
28537 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28538 {
28539 struct k_sonet_stats *stats;
28540 stats = &PRIV(_ia_dev[board])->sonet_stats;
28541 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28542 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28543 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28544 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28545 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28546 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28547 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28548 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28549 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28550 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28551 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28552 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28553 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28554 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28555 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28556 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28557 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28558 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28559 }
28560 ia_cmds.status = 0;
28561 break;
28562 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28563 if ((desc == 0) || (desc > iadev->num_tx_desc))
28564 {
28565 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28566 - atomic_inc(&vcc->stats->tx);
28567 + atomic_inc_unchecked(&vcc->stats->tx);
28568 if (vcc->pop)
28569 vcc->pop(vcc, skb);
28570 else
28571 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28572 ATM_DESC(skb) = vcc->vci;
28573 skb_queue_tail(&iadev->tx_dma_q, skb);
28574
28575 - atomic_inc(&vcc->stats->tx);
28576 + atomic_inc_unchecked(&vcc->stats->tx);
28577 iadev->tx_pkt_cnt++;
28578 /* Increment transaction counter */
28579 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28580
28581 #if 0
28582 /* add flow control logic */
28583 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28584 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28585 if (iavcc->vc_desc_cnt > 10) {
28586 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28587 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28588 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28589 index 68c7588..7036683 100644
28590 --- a/drivers/atm/lanai.c
28591 +++ b/drivers/atm/lanai.c
28592 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28593 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28594 lanai_endtx(lanai, lvcc);
28595 lanai_free_skb(lvcc->tx.atmvcc, skb);
28596 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28597 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28598 }
28599
28600 /* Try to fill the buffer - don't call unless there is backlog */
28601 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28602 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28603 __net_timestamp(skb);
28604 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28605 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28606 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28607 out:
28608 lvcc->rx.buf.ptr = end;
28609 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28610 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28611 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28612 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28613 lanai->stats.service_rxnotaal5++;
28614 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28615 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28616 return 0;
28617 }
28618 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28619 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28620 int bytes;
28621 read_unlock(&vcc_sklist_lock);
28622 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28623 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28624 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28625 lvcc->stats.x.aal5.service_trash++;
28626 bytes = (SERVICE_GET_END(s) * 16) -
28627 (((unsigned long) lvcc->rx.buf.ptr) -
28628 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28629 }
28630 if (s & SERVICE_STREAM) {
28631 read_unlock(&vcc_sklist_lock);
28632 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28633 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28634 lvcc->stats.x.aal5.service_stream++;
28635 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28636 "PDU on VCI %d!\n", lanai->number, vci);
28637 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28638 return 0;
28639 }
28640 DPRINTK("got rx crc error on vci %d\n", vci);
28641 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28642 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28643 lvcc->stats.x.aal5.service_rxcrc++;
28644 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28645 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28646 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28647 index 1c70c45..300718d 100644
28648 --- a/drivers/atm/nicstar.c
28649 +++ b/drivers/atm/nicstar.c
28650 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28651 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28652 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28653 card->index);
28654 - atomic_inc(&vcc->stats->tx_err);
28655 + atomic_inc_unchecked(&vcc->stats->tx_err);
28656 dev_kfree_skb_any(skb);
28657 return -EINVAL;
28658 }
28659 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28660 if (!vc->tx) {
28661 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28662 card->index);
28663 - atomic_inc(&vcc->stats->tx_err);
28664 + atomic_inc_unchecked(&vcc->stats->tx_err);
28665 dev_kfree_skb_any(skb);
28666 return -EINVAL;
28667 }
28668 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28669 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28670 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28671 card->index);
28672 - atomic_inc(&vcc->stats->tx_err);
28673 + atomic_inc_unchecked(&vcc->stats->tx_err);
28674 dev_kfree_skb_any(skb);
28675 return -EINVAL;
28676 }
28677
28678 if (skb_shinfo(skb)->nr_frags != 0) {
28679 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28680 - atomic_inc(&vcc->stats->tx_err);
28681 + atomic_inc_unchecked(&vcc->stats->tx_err);
28682 dev_kfree_skb_any(skb);
28683 return -EINVAL;
28684 }
28685 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28686 }
28687
28688 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28689 - atomic_inc(&vcc->stats->tx_err);
28690 + atomic_inc_unchecked(&vcc->stats->tx_err);
28691 dev_kfree_skb_any(skb);
28692 return -EIO;
28693 }
28694 - atomic_inc(&vcc->stats->tx);
28695 + atomic_inc_unchecked(&vcc->stats->tx);
28696
28697 return 0;
28698 }
28699 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28700 printk
28701 ("nicstar%d: Can't allocate buffers for aal0.\n",
28702 card->index);
28703 - atomic_add(i, &vcc->stats->rx_drop);
28704 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28705 break;
28706 }
28707 if (!atm_charge(vcc, sb->truesize)) {
28708 RXPRINTK
28709 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28710 card->index);
28711 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28712 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28713 dev_kfree_skb_any(sb);
28714 break;
28715 }
28716 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28717 ATM_SKB(sb)->vcc = vcc;
28718 __net_timestamp(sb);
28719 vcc->push(vcc, sb);
28720 - atomic_inc(&vcc->stats->rx);
28721 + atomic_inc_unchecked(&vcc->stats->rx);
28722 cell += ATM_CELL_PAYLOAD;
28723 }
28724
28725 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28726 if (iovb == NULL) {
28727 printk("nicstar%d: Out of iovec buffers.\n",
28728 card->index);
28729 - atomic_inc(&vcc->stats->rx_drop);
28730 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28731 recycle_rx_buf(card, skb);
28732 return;
28733 }
28734 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28735 small or large buffer itself. */
28736 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28737 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28738 - atomic_inc(&vcc->stats->rx_err);
28739 + atomic_inc_unchecked(&vcc->stats->rx_err);
28740 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28741 NS_MAX_IOVECS);
28742 NS_PRV_IOVCNT(iovb) = 0;
28743 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28744 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28745 card->index);
28746 which_list(card, skb);
28747 - atomic_inc(&vcc->stats->rx_err);
28748 + atomic_inc_unchecked(&vcc->stats->rx_err);
28749 recycle_rx_buf(card, skb);
28750 vc->rx_iov = NULL;
28751 recycle_iov_buf(card, iovb);
28752 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28753 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28754 card->index);
28755 which_list(card, skb);
28756 - atomic_inc(&vcc->stats->rx_err);
28757 + atomic_inc_unchecked(&vcc->stats->rx_err);
28758 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28759 NS_PRV_IOVCNT(iovb));
28760 vc->rx_iov = NULL;
28761 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28762 printk(" - PDU size mismatch.\n");
28763 else
28764 printk(".\n");
28765 - atomic_inc(&vcc->stats->rx_err);
28766 + atomic_inc_unchecked(&vcc->stats->rx_err);
28767 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28768 NS_PRV_IOVCNT(iovb));
28769 vc->rx_iov = NULL;
28770 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28771 /* skb points to a small buffer */
28772 if (!atm_charge(vcc, skb->truesize)) {
28773 push_rxbufs(card, skb);
28774 - atomic_inc(&vcc->stats->rx_drop);
28775 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28776 } else {
28777 skb_put(skb, len);
28778 dequeue_sm_buf(card, skb);
28779 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28780 ATM_SKB(skb)->vcc = vcc;
28781 __net_timestamp(skb);
28782 vcc->push(vcc, skb);
28783 - atomic_inc(&vcc->stats->rx);
28784 + atomic_inc_unchecked(&vcc->stats->rx);
28785 }
28786 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28787 struct sk_buff *sb;
28788 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28789 if (len <= NS_SMBUFSIZE) {
28790 if (!atm_charge(vcc, sb->truesize)) {
28791 push_rxbufs(card, sb);
28792 - atomic_inc(&vcc->stats->rx_drop);
28793 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28794 } else {
28795 skb_put(sb, len);
28796 dequeue_sm_buf(card, sb);
28797 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28798 ATM_SKB(sb)->vcc = vcc;
28799 __net_timestamp(sb);
28800 vcc->push(vcc, sb);
28801 - atomic_inc(&vcc->stats->rx);
28802 + atomic_inc_unchecked(&vcc->stats->rx);
28803 }
28804
28805 push_rxbufs(card, skb);
28806 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28807
28808 if (!atm_charge(vcc, skb->truesize)) {
28809 push_rxbufs(card, skb);
28810 - atomic_inc(&vcc->stats->rx_drop);
28811 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28812 } else {
28813 dequeue_lg_buf(card, skb);
28814 #ifdef NS_USE_DESTRUCTORS
28815 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28816 ATM_SKB(skb)->vcc = vcc;
28817 __net_timestamp(skb);
28818 vcc->push(vcc, skb);
28819 - atomic_inc(&vcc->stats->rx);
28820 + atomic_inc_unchecked(&vcc->stats->rx);
28821 }
28822
28823 push_rxbufs(card, sb);
28824 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28825 printk
28826 ("nicstar%d: Out of huge buffers.\n",
28827 card->index);
28828 - atomic_inc(&vcc->stats->rx_drop);
28829 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28830 recycle_iovec_rx_bufs(card,
28831 (struct iovec *)
28832 iovb->data,
28833 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28834 card->hbpool.count++;
28835 } else
28836 dev_kfree_skb_any(hb);
28837 - atomic_inc(&vcc->stats->rx_drop);
28838 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28839 } else {
28840 /* Copy the small buffer to the huge buffer */
28841 sb = (struct sk_buff *)iov->iov_base;
28842 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28843 #endif /* NS_USE_DESTRUCTORS */
28844 __net_timestamp(hb);
28845 vcc->push(vcc, hb);
28846 - atomic_inc(&vcc->stats->rx);
28847 + atomic_inc_unchecked(&vcc->stats->rx);
28848 }
28849 }
28850
28851 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28852 index 9851093..adb2b1e 100644
28853 --- a/drivers/atm/solos-pci.c
28854 +++ b/drivers/atm/solos-pci.c
28855 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28856 }
28857 atm_charge(vcc, skb->truesize);
28858 vcc->push(vcc, skb);
28859 - atomic_inc(&vcc->stats->rx);
28860 + atomic_inc_unchecked(&vcc->stats->rx);
28861 break;
28862
28863 case PKT_STATUS:
28864 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28865 vcc = SKB_CB(oldskb)->vcc;
28866
28867 if (vcc) {
28868 - atomic_inc(&vcc->stats->tx);
28869 + atomic_inc_unchecked(&vcc->stats->tx);
28870 solos_pop(vcc, oldskb);
28871 } else
28872 dev_kfree_skb_irq(oldskb);
28873 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28874 index 0215934..ce9f5b1 100644
28875 --- a/drivers/atm/suni.c
28876 +++ b/drivers/atm/suni.c
28877 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28878
28879
28880 #define ADD_LIMITED(s,v) \
28881 - atomic_add((v),&stats->s); \
28882 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28883 + atomic_add_unchecked((v),&stats->s); \
28884 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28885
28886
28887 static void suni_hz(unsigned long from_timer)
28888 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28889 index 5120a96..e2572bd 100644
28890 --- a/drivers/atm/uPD98402.c
28891 +++ b/drivers/atm/uPD98402.c
28892 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28893 struct sonet_stats tmp;
28894 int error = 0;
28895
28896 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28897 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28898 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28899 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28900 if (zero && !error) {
28901 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28902
28903
28904 #define ADD_LIMITED(s,v) \
28905 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28906 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28907 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28908 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28909 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28910 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28911
28912
28913 static void stat_event(struct atm_dev *dev)
28914 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28915 if (reason & uPD98402_INT_PFM) stat_event(dev);
28916 if (reason & uPD98402_INT_PCO) {
28917 (void) GET(PCOCR); /* clear interrupt cause */
28918 - atomic_add(GET(HECCT),
28919 + atomic_add_unchecked(GET(HECCT),
28920 &PRIV(dev)->sonet_stats.uncorr_hcs);
28921 }
28922 if ((reason & uPD98402_INT_RFO) &&
28923 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28924 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28925 uPD98402_INT_LOS),PIMR); /* enable them */
28926 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28927 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28928 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28929 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28930 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28931 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28932 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28933 return 0;
28934 }
28935
28936 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28937 index abe4e20..83c4727 100644
28938 --- a/drivers/atm/zatm.c
28939 +++ b/drivers/atm/zatm.c
28940 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28941 }
28942 if (!size) {
28943 dev_kfree_skb_irq(skb);
28944 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28945 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28946 continue;
28947 }
28948 if (!atm_charge(vcc,skb->truesize)) {
28949 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28950 skb->len = size;
28951 ATM_SKB(skb)->vcc = vcc;
28952 vcc->push(vcc,skb);
28953 - atomic_inc(&vcc->stats->rx);
28954 + atomic_inc_unchecked(&vcc->stats->rx);
28955 }
28956 zout(pos & 0xffff,MTA(mbx));
28957 #if 0 /* probably a stupid idea */
28958 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28959 skb_queue_head(&zatm_vcc->backlog,skb);
28960 break;
28961 }
28962 - atomic_inc(&vcc->stats->tx);
28963 + atomic_inc_unchecked(&vcc->stats->tx);
28964 wake_up(&zatm_vcc->tx_wait);
28965 }
28966
28967 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28968 index deb4a45..211eff2 100644
28969 --- a/drivers/base/devtmpfs.c
28970 +++ b/drivers/base/devtmpfs.c
28971 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28972 if (!thread)
28973 return 0;
28974
28975 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28976 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28977 if (err)
28978 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28979 else
28980 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28981 index cbb463b..babe2cf 100644
28982 --- a/drivers/base/power/wakeup.c
28983 +++ b/drivers/base/power/wakeup.c
28984 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28985 * They need to be modified together atomically, so it's better to use one
28986 * atomic variable to hold them both.
28987 */
28988 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28989 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28990
28991 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28992 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28993
28994 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28995 {
28996 - unsigned int comb = atomic_read(&combined_event_count);
28997 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28998
28999 *cnt = (comb >> IN_PROGRESS_BITS);
29000 *inpr = comb & MAX_IN_PROGRESS;
29001 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29002 ws->start_prevent_time = ws->last_time;
29003
29004 /* Increment the counter of events in progress. */
29005 - cec = atomic_inc_return(&combined_event_count);
29006 + cec = atomic_inc_return_unchecked(&combined_event_count);
29007
29008 trace_wakeup_source_activate(ws->name, cec);
29009 }
29010 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29011 * Increment the counter of registered wakeup events and decrement the
29012 * couter of wakeup events in progress simultaneously.
29013 */
29014 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29015 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29016 trace_wakeup_source_deactivate(ws->name, cec);
29017
29018 split_counters(&cnt, &inpr);
29019 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29020 index b0f553b..77b928b 100644
29021 --- a/drivers/block/cciss.c
29022 +++ b/drivers/block/cciss.c
29023 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29024 int err;
29025 u32 cp;
29026
29027 + memset(&arg64, 0, sizeof(arg64));
29028 +
29029 err = 0;
29030 err |=
29031 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29032 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29033 while (!list_empty(&h->reqQ)) {
29034 c = list_entry(h->reqQ.next, CommandList_struct, list);
29035 /* can't do anything if fifo is full */
29036 - if ((h->access.fifo_full(h))) {
29037 + if ((h->access->fifo_full(h))) {
29038 dev_warn(&h->pdev->dev, "fifo full\n");
29039 break;
29040 }
29041 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29042 h->Qdepth--;
29043
29044 /* Tell the controller execute command */
29045 - h->access.submit_command(h, c);
29046 + h->access->submit_command(h, c);
29047
29048 /* Put job onto the completed Q */
29049 addQ(&h->cmpQ, c);
29050 @@ -3443,17 +3445,17 @@ startio:
29051
29052 static inline unsigned long get_next_completion(ctlr_info_t *h)
29053 {
29054 - return h->access.command_completed(h);
29055 + return h->access->command_completed(h);
29056 }
29057
29058 static inline int interrupt_pending(ctlr_info_t *h)
29059 {
29060 - return h->access.intr_pending(h);
29061 + return h->access->intr_pending(h);
29062 }
29063
29064 static inline long interrupt_not_for_us(ctlr_info_t *h)
29065 {
29066 - return ((h->access.intr_pending(h) == 0) ||
29067 + return ((h->access->intr_pending(h) == 0) ||
29068 (h->interrupts_enabled == 0));
29069 }
29070
29071 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29072 u32 a;
29073
29074 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29075 - return h->access.command_completed(h);
29076 + return h->access->command_completed(h);
29077
29078 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29079 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29080 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29081 trans_support & CFGTBL_Trans_use_short_tags);
29082
29083 /* Change the access methods to the performant access methods */
29084 - h->access = SA5_performant_access;
29085 + h->access = &SA5_performant_access;
29086 h->transMethod = CFGTBL_Trans_Performant;
29087
29088 return;
29089 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29090 if (prod_index < 0)
29091 return -ENODEV;
29092 h->product_name = products[prod_index].product_name;
29093 - h->access = *(products[prod_index].access);
29094 + h->access = products[prod_index].access;
29095
29096 if (cciss_board_disabled(h)) {
29097 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29098 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29099 }
29100
29101 /* make sure the board interrupts are off */
29102 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29103 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29104 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29105 if (rc)
29106 goto clean2;
29107 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29108 * fake ones to scoop up any residual completions.
29109 */
29110 spin_lock_irqsave(&h->lock, flags);
29111 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29112 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29113 spin_unlock_irqrestore(&h->lock, flags);
29114 free_irq(h->intr[h->intr_mode], h);
29115 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29116 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29117 dev_info(&h->pdev->dev, "Board READY.\n");
29118 dev_info(&h->pdev->dev,
29119 "Waiting for stale completions to drain.\n");
29120 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29121 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29122 msleep(10000);
29123 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29124 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29125
29126 rc = controller_reset_failed(h->cfgtable);
29127 if (rc)
29128 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29129 cciss_scsi_setup(h);
29130
29131 /* Turn the interrupts on so we can service requests */
29132 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29133 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29134
29135 /* Get the firmware version */
29136 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29137 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29138 kfree(flush_buf);
29139 if (return_code != IO_OK)
29140 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29141 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29142 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29143 free_irq(h->intr[h->intr_mode], h);
29144 }
29145
29146 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29147 index 7fda30e..eb5dfe0 100644
29148 --- a/drivers/block/cciss.h
29149 +++ b/drivers/block/cciss.h
29150 @@ -101,7 +101,7 @@ struct ctlr_info
29151 /* information about each logical volume */
29152 drive_info_struct *drv[CISS_MAX_LUN];
29153
29154 - struct access_method access;
29155 + struct access_method *access;
29156
29157 /* queue and queue Info */
29158 struct list_head reqQ;
29159 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29160 index 9125bbe..eede5c8 100644
29161 --- a/drivers/block/cpqarray.c
29162 +++ b/drivers/block/cpqarray.c
29163 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29164 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29165 goto Enomem4;
29166 }
29167 - hba[i]->access.set_intr_mask(hba[i], 0);
29168 + hba[i]->access->set_intr_mask(hba[i], 0);
29169 if (request_irq(hba[i]->intr, do_ida_intr,
29170 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29171 {
29172 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29173 add_timer(&hba[i]->timer);
29174
29175 /* Enable IRQ now that spinlock and rate limit timer are set up */
29176 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29177 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29178
29179 for(j=0; j<NWD; j++) {
29180 struct gendisk *disk = ida_gendisk[i][j];
29181 @@ -694,7 +694,7 @@ DBGINFO(
29182 for(i=0; i<NR_PRODUCTS; i++) {
29183 if (board_id == products[i].board_id) {
29184 c->product_name = products[i].product_name;
29185 - c->access = *(products[i].access);
29186 + c->access = products[i].access;
29187 break;
29188 }
29189 }
29190 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29191 hba[ctlr]->intr = intr;
29192 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29193 hba[ctlr]->product_name = products[j].product_name;
29194 - hba[ctlr]->access = *(products[j].access);
29195 + hba[ctlr]->access = products[j].access;
29196 hba[ctlr]->ctlr = ctlr;
29197 hba[ctlr]->board_id = board_id;
29198 hba[ctlr]->pci_dev = NULL; /* not PCI */
29199 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29200
29201 while((c = h->reqQ) != NULL) {
29202 /* Can't do anything if we're busy */
29203 - if (h->access.fifo_full(h) == 0)
29204 + if (h->access->fifo_full(h) == 0)
29205 return;
29206
29207 /* Get the first entry from the request Q */
29208 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29209 h->Qdepth--;
29210
29211 /* Tell the controller to do our bidding */
29212 - h->access.submit_command(h, c);
29213 + h->access->submit_command(h, c);
29214
29215 /* Get onto the completion Q */
29216 addQ(&h->cmpQ, c);
29217 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29218 unsigned long flags;
29219 __u32 a,a1;
29220
29221 - istat = h->access.intr_pending(h);
29222 + istat = h->access->intr_pending(h);
29223 /* Is this interrupt for us? */
29224 if (istat == 0)
29225 return IRQ_NONE;
29226 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29227 */
29228 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29229 if (istat & FIFO_NOT_EMPTY) {
29230 - while((a = h->access.command_completed(h))) {
29231 + while((a = h->access->command_completed(h))) {
29232 a1 = a; a &= ~3;
29233 if ((c = h->cmpQ) == NULL)
29234 {
29235 @@ -1449,11 +1449,11 @@ static int sendcmd(
29236 /*
29237 * Disable interrupt
29238 */
29239 - info_p->access.set_intr_mask(info_p, 0);
29240 + info_p->access->set_intr_mask(info_p, 0);
29241 /* Make sure there is room in the command FIFO */
29242 /* Actually it should be completely empty at this time. */
29243 for (i = 200000; i > 0; i--) {
29244 - temp = info_p->access.fifo_full(info_p);
29245 + temp = info_p->access->fifo_full(info_p);
29246 if (temp != 0) {
29247 break;
29248 }
29249 @@ -1466,7 +1466,7 @@ DBG(
29250 /*
29251 * Send the cmd
29252 */
29253 - info_p->access.submit_command(info_p, c);
29254 + info_p->access->submit_command(info_p, c);
29255 complete = pollcomplete(ctlr);
29256
29257 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29258 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29259 * we check the new geometry. Then turn interrupts back on when
29260 * we're done.
29261 */
29262 - host->access.set_intr_mask(host, 0);
29263 + host->access->set_intr_mask(host, 0);
29264 getgeometry(ctlr);
29265 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29266 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29267
29268 for(i=0; i<NWD; i++) {
29269 struct gendisk *disk = ida_gendisk[ctlr][i];
29270 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29271 /* Wait (up to 2 seconds) for a command to complete */
29272
29273 for (i = 200000; i > 0; i--) {
29274 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29275 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29276 if (done == 0) {
29277 udelay(10); /* a short fixed delay */
29278 } else
29279 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29280 index be73e9d..7fbf140 100644
29281 --- a/drivers/block/cpqarray.h
29282 +++ b/drivers/block/cpqarray.h
29283 @@ -99,7 +99,7 @@ struct ctlr_info {
29284 drv_info_t drv[NWD];
29285 struct proc_dir_entry *proc;
29286
29287 - struct access_method access;
29288 + struct access_method *access;
29289
29290 cmdlist_t *reqQ;
29291 cmdlist_t *cmpQ;
29292 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29293 index b953cc7..e3dc580 100644
29294 --- a/drivers/block/drbd/drbd_int.h
29295 +++ b/drivers/block/drbd/drbd_int.h
29296 @@ -735,7 +735,7 @@ struct drbd_request;
29297 struct drbd_epoch {
29298 struct list_head list;
29299 unsigned int barrier_nr;
29300 - atomic_t epoch_size; /* increased on every request added. */
29301 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29302 atomic_t active; /* increased on every req. added, and dec on every finished. */
29303 unsigned long flags;
29304 };
29305 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29306 void *int_dig_in;
29307 void *int_dig_vv;
29308 wait_queue_head_t seq_wait;
29309 - atomic_t packet_seq;
29310 + atomic_unchecked_t packet_seq;
29311 unsigned int peer_seq;
29312 spinlock_t peer_seq_lock;
29313 unsigned int minor;
29314 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29315
29316 static inline void drbd_tcp_cork(struct socket *sock)
29317 {
29318 - int __user val = 1;
29319 + int val = 1;
29320 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29321 - (char __user *)&val, sizeof(val));
29322 + (char __force_user *)&val, sizeof(val));
29323 }
29324
29325 static inline void drbd_tcp_uncork(struct socket *sock)
29326 {
29327 - int __user val = 0;
29328 + int val = 0;
29329 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29330 - (char __user *)&val, sizeof(val));
29331 + (char __force_user *)&val, sizeof(val));
29332 }
29333
29334 static inline void drbd_tcp_nodelay(struct socket *sock)
29335 {
29336 - int __user val = 1;
29337 + int val = 1;
29338 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29339 - (char __user *)&val, sizeof(val));
29340 + (char __force_user *)&val, sizeof(val));
29341 }
29342
29343 static inline void drbd_tcp_quickack(struct socket *sock)
29344 {
29345 - int __user val = 2;
29346 + int val = 2;
29347 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29348 - (char __user *)&val, sizeof(val));
29349 + (char __force_user *)&val, sizeof(val));
29350 }
29351
29352 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29353 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29354 index f93a032..71c87bf 100644
29355 --- a/drivers/block/drbd/drbd_main.c
29356 +++ b/drivers/block/drbd/drbd_main.c
29357 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29358 p.sector = sector;
29359 p.block_id = block_id;
29360 p.blksize = blksize;
29361 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29362 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29363
29364 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29365 return false;
29366 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29367
29368 p.sector = cpu_to_be64(req->sector);
29369 p.block_id = (unsigned long)req;
29370 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29371 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29372
29373 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29374
29375 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29376 atomic_set(&mdev->unacked_cnt, 0);
29377 atomic_set(&mdev->local_cnt, 0);
29378 atomic_set(&mdev->net_cnt, 0);
29379 - atomic_set(&mdev->packet_seq, 0);
29380 + atomic_set_unchecked(&mdev->packet_seq, 0);
29381 atomic_set(&mdev->pp_in_use, 0);
29382 atomic_set(&mdev->pp_in_use_by_net, 0);
29383 atomic_set(&mdev->rs_sect_in, 0);
29384 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29385 mdev->receiver.t_state);
29386
29387 /* no need to lock it, I'm the only thread alive */
29388 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29389 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29390 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29391 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29392 mdev->al_writ_cnt =
29393 mdev->bm_writ_cnt =
29394 mdev->read_cnt =
29395 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29396 index edb490a..ecd69da 100644
29397 --- a/drivers/block/drbd/drbd_nl.c
29398 +++ b/drivers/block/drbd/drbd_nl.c
29399 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29400 module_put(THIS_MODULE);
29401 }
29402
29403 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29404 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29405
29406 static unsigned short *
29407 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29408 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29409 cn_reply->id.idx = CN_IDX_DRBD;
29410 cn_reply->id.val = CN_VAL_DRBD;
29411
29412 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29413 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29414 cn_reply->ack = 0; /* not used here. */
29415 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29416 (int)((char *)tl - (char *)reply->tag_list);
29417 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29418 cn_reply->id.idx = CN_IDX_DRBD;
29419 cn_reply->id.val = CN_VAL_DRBD;
29420
29421 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29422 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29423 cn_reply->ack = 0; /* not used here. */
29424 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29425 (int)((char *)tl - (char *)reply->tag_list);
29426 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29427 cn_reply->id.idx = CN_IDX_DRBD;
29428 cn_reply->id.val = CN_VAL_DRBD;
29429
29430 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29431 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29432 cn_reply->ack = 0; // not used here.
29433 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29434 (int)((char*)tl - (char*)reply->tag_list);
29435 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29436 cn_reply->id.idx = CN_IDX_DRBD;
29437 cn_reply->id.val = CN_VAL_DRBD;
29438
29439 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29440 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29441 cn_reply->ack = 0; /* not used here. */
29442 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29443 (int)((char *)tl - (char *)reply->tag_list);
29444 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29445 index c74ca2d..860c819 100644
29446 --- a/drivers/block/drbd/drbd_receiver.c
29447 +++ b/drivers/block/drbd/drbd_receiver.c
29448 @@ -898,7 +898,7 @@ retry:
29449 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29450 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29451
29452 - atomic_set(&mdev->packet_seq, 0);
29453 + atomic_set_unchecked(&mdev->packet_seq, 0);
29454 mdev->peer_seq = 0;
29455
29456 if (drbd_send_protocol(mdev) == -1)
29457 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29458 do {
29459 next_epoch = NULL;
29460
29461 - epoch_size = atomic_read(&epoch->epoch_size);
29462 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29463
29464 switch (ev & ~EV_CLEANUP) {
29465 case EV_PUT:
29466 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29467 rv = FE_DESTROYED;
29468 } else {
29469 epoch->flags = 0;
29470 - atomic_set(&epoch->epoch_size, 0);
29471 + atomic_set_unchecked(&epoch->epoch_size, 0);
29472 /* atomic_set(&epoch->active, 0); is already zero */
29473 if (rv == FE_STILL_LIVE)
29474 rv = FE_RECYCLED;
29475 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29476 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29477 drbd_flush(mdev);
29478
29479 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29480 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29481 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29482 if (epoch)
29483 break;
29484 }
29485
29486 epoch = mdev->current_epoch;
29487 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29488 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29489
29490 D_ASSERT(atomic_read(&epoch->active) == 0);
29491 D_ASSERT(epoch->flags == 0);
29492 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29493 }
29494
29495 epoch->flags = 0;
29496 - atomic_set(&epoch->epoch_size, 0);
29497 + atomic_set_unchecked(&epoch->epoch_size, 0);
29498 atomic_set(&epoch->active, 0);
29499
29500 spin_lock(&mdev->epoch_lock);
29501 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29502 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29503 list_add(&epoch->list, &mdev->current_epoch->list);
29504 mdev->current_epoch = epoch;
29505 mdev->epochs++;
29506 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29507 spin_unlock(&mdev->peer_seq_lock);
29508
29509 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29510 - atomic_inc(&mdev->current_epoch->epoch_size);
29511 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29512 return drbd_drain_block(mdev, data_size);
29513 }
29514
29515 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29516
29517 spin_lock(&mdev->epoch_lock);
29518 e->epoch = mdev->current_epoch;
29519 - atomic_inc(&e->epoch->epoch_size);
29520 + atomic_inc_unchecked(&e->epoch->epoch_size);
29521 atomic_inc(&e->epoch->active);
29522 spin_unlock(&mdev->epoch_lock);
29523
29524 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29525 D_ASSERT(list_empty(&mdev->done_ee));
29526
29527 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29528 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29529 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29530 D_ASSERT(list_empty(&mdev->current_epoch->list));
29531 }
29532
29533 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29534 index 3bba655..6151b66 100644
29535 --- a/drivers/block/loop.c
29536 +++ b/drivers/block/loop.c
29537 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29538 mm_segment_t old_fs = get_fs();
29539
29540 set_fs(get_ds());
29541 - bw = file->f_op->write(file, buf, len, &pos);
29542 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29543 set_fs(old_fs);
29544 if (likely(bw == len))
29545 return 0;
29546 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29547 index ea6f632..eafb192 100644
29548 --- a/drivers/char/Kconfig
29549 +++ b/drivers/char/Kconfig
29550 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29551
29552 config DEVKMEM
29553 bool "/dev/kmem virtual device support"
29554 - default y
29555 + default n
29556 + depends on !GRKERNSEC_KMEM
29557 help
29558 Say Y here if you want to support the /dev/kmem device. The
29559 /dev/kmem device is rarely used, but can be used for certain
29560 @@ -581,6 +582,7 @@ config DEVPORT
29561 bool
29562 depends on !M68K
29563 depends on ISA || PCI
29564 + depends on !GRKERNSEC_KMEM
29565 default y
29566
29567 source "drivers/s390/char/Kconfig"
29568 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29569 index 2e04433..22afc64 100644
29570 --- a/drivers/char/agp/frontend.c
29571 +++ b/drivers/char/agp/frontend.c
29572 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29573 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29574 return -EFAULT;
29575
29576 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29577 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29578 return -EFAULT;
29579
29580 client = agp_find_client_by_pid(reserve.pid);
29581 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29582 index 21cb980..f15107c 100644
29583 --- a/drivers/char/genrtc.c
29584 +++ b/drivers/char/genrtc.c
29585 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29586 switch (cmd) {
29587
29588 case RTC_PLL_GET:
29589 + memset(&pll, 0, sizeof(pll));
29590 if (get_rtc_pll(&pll))
29591 return -EINVAL;
29592 else
29593 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29594 index dfd7876..c0b0885 100644
29595 --- a/drivers/char/hpet.c
29596 +++ b/drivers/char/hpet.c
29597 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29598 }
29599
29600 static int
29601 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29602 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29603 struct hpet_info *info)
29604 {
29605 struct hpet_timer __iomem *timer;
29606 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29607 index 2c29942..604c5ba 100644
29608 --- a/drivers/char/ipmi/ipmi_msghandler.c
29609 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29610 @@ -420,7 +420,7 @@ struct ipmi_smi {
29611 struct proc_dir_entry *proc_dir;
29612 char proc_dir_name[10];
29613
29614 - atomic_t stats[IPMI_NUM_STATS];
29615 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29616
29617 /*
29618 * run_to_completion duplicate of smb_info, smi_info
29619 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29620
29621
29622 #define ipmi_inc_stat(intf, stat) \
29623 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29624 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29625 #define ipmi_get_stat(intf, stat) \
29626 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29627 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29628
29629 static int is_lan_addr(struct ipmi_addr *addr)
29630 {
29631 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29632 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29633 init_waitqueue_head(&intf->waitq);
29634 for (i = 0; i < IPMI_NUM_STATS; i++)
29635 - atomic_set(&intf->stats[i], 0);
29636 + atomic_set_unchecked(&intf->stats[i], 0);
29637
29638 intf->proc_dir = NULL;
29639
29640 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29641 index 83f85cf..279e63f 100644
29642 --- a/drivers/char/ipmi/ipmi_si_intf.c
29643 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29644 @@ -275,7 +275,7 @@ struct smi_info {
29645 unsigned char slave_addr;
29646
29647 /* Counters and things for the proc filesystem. */
29648 - atomic_t stats[SI_NUM_STATS];
29649 + atomic_unchecked_t stats[SI_NUM_STATS];
29650
29651 struct task_struct *thread;
29652
29653 @@ -284,9 +284,9 @@ struct smi_info {
29654 };
29655
29656 #define smi_inc_stat(smi, stat) \
29657 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29658 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29659 #define smi_get_stat(smi, stat) \
29660 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29661 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29662
29663 #define SI_MAX_PARMS 4
29664
29665 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29666 atomic_set(&new_smi->req_events, 0);
29667 new_smi->run_to_completion = 0;
29668 for (i = 0; i < SI_NUM_STATS; i++)
29669 - atomic_set(&new_smi->stats[i], 0);
29670 + atomic_set_unchecked(&new_smi->stats[i], 0);
29671
29672 new_smi->interrupt_disabled = 1;
29673 atomic_set(&new_smi->stop_operation, 0);
29674 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29675 index 47ff7e4..0c7d340 100644
29676 --- a/drivers/char/mbcs.c
29677 +++ b/drivers/char/mbcs.c
29678 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29679 return 0;
29680 }
29681
29682 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29683 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29684 {
29685 .part_num = MBCS_PART_NUM,
29686 .mfg_num = MBCS_MFG_NUM,
29687 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29688 index e5eedfa..fcab50ea 100644
29689 --- a/drivers/char/mem.c
29690 +++ b/drivers/char/mem.c
29691 @@ -18,6 +18,7 @@
29692 #include <linux/raw.h>
29693 #include <linux/tty.h>
29694 #include <linux/capability.h>
29695 +#include <linux/security.h>
29696 #include <linux/ptrace.h>
29697 #include <linux/device.h>
29698 #include <linux/highmem.h>
29699 @@ -37,6 +38,10 @@
29700
29701 #define DEVPORT_MINOR 4
29702
29703 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29704 +extern const struct file_operations grsec_fops;
29705 +#endif
29706 +
29707 static inline unsigned long size_inside_page(unsigned long start,
29708 unsigned long size)
29709 {
29710 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29711
29712 while (cursor < to) {
29713 if (!devmem_is_allowed(pfn)) {
29714 +#ifdef CONFIG_GRKERNSEC_KMEM
29715 + gr_handle_mem_readwrite(from, to);
29716 +#else
29717 printk(KERN_INFO
29718 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29719 current->comm, from, to);
29720 +#endif
29721 return 0;
29722 }
29723 cursor += PAGE_SIZE;
29724 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29725 }
29726 return 1;
29727 }
29728 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29729 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29730 +{
29731 + return 0;
29732 +}
29733 #else
29734 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29735 {
29736 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29737
29738 while (count > 0) {
29739 unsigned long remaining;
29740 + char *temp;
29741
29742 sz = size_inside_page(p, count);
29743
29744 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29745 if (!ptr)
29746 return -EFAULT;
29747
29748 - remaining = copy_to_user(buf, ptr, sz);
29749 +#ifdef CONFIG_PAX_USERCOPY
29750 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29751 + if (!temp) {
29752 + unxlate_dev_mem_ptr(p, ptr);
29753 + return -ENOMEM;
29754 + }
29755 + memcpy(temp, ptr, sz);
29756 +#else
29757 + temp = ptr;
29758 +#endif
29759 +
29760 + remaining = copy_to_user(buf, temp, sz);
29761 +
29762 +#ifdef CONFIG_PAX_USERCOPY
29763 + kfree(temp);
29764 +#endif
29765 +
29766 unxlate_dev_mem_ptr(p, ptr);
29767 if (remaining)
29768 return -EFAULT;
29769 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29770 size_t count, loff_t *ppos)
29771 {
29772 unsigned long p = *ppos;
29773 - ssize_t low_count, read, sz;
29774 + ssize_t low_count, read, sz, err = 0;
29775 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29776 - int err = 0;
29777
29778 read = 0;
29779 if (p < (unsigned long) high_memory) {
29780 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29781 }
29782 #endif
29783 while (low_count > 0) {
29784 + char *temp;
29785 +
29786 sz = size_inside_page(p, low_count);
29787
29788 /*
29789 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29790 */
29791 kbuf = xlate_dev_kmem_ptr((char *)p);
29792
29793 - if (copy_to_user(buf, kbuf, sz))
29794 +#ifdef CONFIG_PAX_USERCOPY
29795 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29796 + if (!temp)
29797 + return -ENOMEM;
29798 + memcpy(temp, kbuf, sz);
29799 +#else
29800 + temp = kbuf;
29801 +#endif
29802 +
29803 + err = copy_to_user(buf, temp, sz);
29804 +
29805 +#ifdef CONFIG_PAX_USERCOPY
29806 + kfree(temp);
29807 +#endif
29808 +
29809 + if (err)
29810 return -EFAULT;
29811 buf += sz;
29812 p += sz;
29813 @@ -833,6 +880,9 @@ static const struct memdev {
29814 #ifdef CONFIG_CRASH_DUMP
29815 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29816 #endif
29817 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29818 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29819 +#endif
29820 };
29821
29822 static int memory_open(struct inode *inode, struct file *filp)
29823 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29824 index 9df78e2..01ba9ae 100644
29825 --- a/drivers/char/nvram.c
29826 +++ b/drivers/char/nvram.c
29827 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29828
29829 spin_unlock_irq(&rtc_lock);
29830
29831 - if (copy_to_user(buf, contents, tmp - contents))
29832 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29833 return -EFAULT;
29834
29835 *ppos = i;
29836 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29837 index 0a484b4..f48ccd1 100644
29838 --- a/drivers/char/pcmcia/synclink_cs.c
29839 +++ b/drivers/char/pcmcia/synclink_cs.c
29840 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29841
29842 if (debug_level >= DEBUG_LEVEL_INFO)
29843 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29844 - __FILE__,__LINE__, info->device_name, port->count);
29845 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29846
29847 - WARN_ON(!port->count);
29848 + WARN_ON(!atomic_read(&port->count));
29849
29850 if (tty_port_close_start(port, tty, filp) == 0)
29851 goto cleanup;
29852 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29853 cleanup:
29854 if (debug_level >= DEBUG_LEVEL_INFO)
29855 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29856 - tty->driver->name, port->count);
29857 + tty->driver->name, atomic_read(&port->count));
29858 }
29859
29860 /* Wait until the transmitter is empty.
29861 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29862
29863 if (debug_level >= DEBUG_LEVEL_INFO)
29864 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29865 - __FILE__,__LINE__,tty->driver->name, port->count);
29866 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29867
29868 /* If port is closing, signal caller to try again */
29869 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29870 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29871 goto cleanup;
29872 }
29873 spin_lock(&port->lock);
29874 - port->count++;
29875 + atomic_inc(&port->count);
29876 spin_unlock(&port->lock);
29877 spin_unlock_irqrestore(&info->netlock, flags);
29878
29879 - if (port->count == 1) {
29880 + if (atomic_read(&port->count) == 1) {
29881 /* 1st open on this device, init hardware */
29882 retval = startup(info, tty);
29883 if (retval < 0)
29884 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29885 unsigned short new_crctype;
29886
29887 /* return error if TTY interface open */
29888 - if (info->port.count)
29889 + if (atomic_read(&info->port.count))
29890 return -EBUSY;
29891
29892 switch (encoding)
29893 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29894
29895 /* arbitrate between network and tty opens */
29896 spin_lock_irqsave(&info->netlock, flags);
29897 - if (info->port.count != 0 || info->netcount != 0) {
29898 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29899 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29900 spin_unlock_irqrestore(&info->netlock, flags);
29901 return -EBUSY;
29902 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29903 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29904
29905 /* return error if TTY interface open */
29906 - if (info->port.count)
29907 + if (atomic_read(&info->port.count))
29908 return -EBUSY;
29909
29910 if (cmd != SIOCWANDEV)
29911 diff --git a/drivers/char/random.c b/drivers/char/random.c
29912 index b86eae9..4192a7a 100644
29913 --- a/drivers/char/random.c
29914 +++ b/drivers/char/random.c
29915 @@ -272,8 +272,13 @@
29916 /*
29917 * Configuration information
29918 */
29919 +#ifdef CONFIG_GRKERNSEC_RANDNET
29920 +#define INPUT_POOL_WORDS 512
29921 +#define OUTPUT_POOL_WORDS 128
29922 +#else
29923 #define INPUT_POOL_WORDS 128
29924 #define OUTPUT_POOL_WORDS 32
29925 +#endif
29926 #define SEC_XFER_SIZE 512
29927 #define EXTRACT_SIZE 10
29928
29929 @@ -313,10 +318,17 @@ static struct poolinfo {
29930 int poolwords;
29931 int tap1, tap2, tap3, tap4, tap5;
29932 } poolinfo_table[] = {
29933 +#ifdef CONFIG_GRKERNSEC_RANDNET
29934 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29935 + { 512, 411, 308, 208, 104, 1 },
29936 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29937 + { 128, 103, 76, 51, 25, 1 },
29938 +#else
29939 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29940 { 128, 103, 76, 51, 25, 1 },
29941 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29942 { 32, 26, 20, 14, 7, 1 },
29943 +#endif
29944 #if 0
29945 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29946 { 2048, 1638, 1231, 819, 411, 1 },
29947 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29948 input_rotate += i ? 7 : 14;
29949 }
29950
29951 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29952 - ACCESS_ONCE(r->add_ptr) = i;
29953 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29954 + ACCESS_ONCE_RW(r->add_ptr) = i;
29955 smp_wmb();
29956
29957 if (out)
29958 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29959 }
29960 #endif
29961
29962 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29963 +u64 latent_entropy;
29964 +
29965 +__init void transfer_latent_entropy(void)
29966 +{
29967 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29968 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29969 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29970 +}
29971 +#endif
29972 +
29973 /*********************************************************************
29974 *
29975 * Entropy extraction routines
29976 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29977
29978 extract_buf(r, tmp);
29979 i = min_t(int, nbytes, EXTRACT_SIZE);
29980 - if (copy_to_user(buf, tmp, i)) {
29981 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29982 ret = -EFAULT;
29983 break;
29984 }
29985 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29986 #include <linux/sysctl.h>
29987
29988 static int min_read_thresh = 8, min_write_thresh;
29989 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29990 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29991 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29992 static char sysctl_bootid[16];
29993
29994 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29995 index f877805..403375a 100644
29996 --- a/drivers/char/sonypi.c
29997 +++ b/drivers/char/sonypi.c
29998 @@ -54,6 +54,7 @@
29999
30000 #include <asm/uaccess.h>
30001 #include <asm/io.h>
30002 +#include <asm/local.h>
30003
30004 #include <linux/sonypi.h>
30005
30006 @@ -490,7 +491,7 @@ static struct sonypi_device {
30007 spinlock_t fifo_lock;
30008 wait_queue_head_t fifo_proc_list;
30009 struct fasync_struct *fifo_async;
30010 - int open_count;
30011 + local_t open_count;
30012 int model;
30013 struct input_dev *input_jog_dev;
30014 struct input_dev *input_key_dev;
30015 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30016 static int sonypi_misc_release(struct inode *inode, struct file *file)
30017 {
30018 mutex_lock(&sonypi_device.lock);
30019 - sonypi_device.open_count--;
30020 + local_dec(&sonypi_device.open_count);
30021 mutex_unlock(&sonypi_device.lock);
30022 return 0;
30023 }
30024 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30025 {
30026 mutex_lock(&sonypi_device.lock);
30027 /* Flush input queue on first open */
30028 - if (!sonypi_device.open_count)
30029 + if (!local_read(&sonypi_device.open_count))
30030 kfifo_reset(&sonypi_device.fifo);
30031 - sonypi_device.open_count++;
30032 + local_inc(&sonypi_device.open_count);
30033 mutex_unlock(&sonypi_device.lock);
30034
30035 return 0;
30036 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30037 index 4dc8024..90108d1 100644
30038 --- a/drivers/char/tpm/tpm.c
30039 +++ b/drivers/char/tpm/tpm.c
30040 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30041 chip->vendor.req_complete_val)
30042 goto out_recv;
30043
30044 - if ((status == chip->vendor.req_canceled)) {
30045 + if (status == chip->vendor.req_canceled) {
30046 dev_err(chip->dev, "Operation Canceled\n");
30047 rc = -ECANCELED;
30048 goto out;
30049 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30050 index 0636520..169c1d0 100644
30051 --- a/drivers/char/tpm/tpm_bios.c
30052 +++ b/drivers/char/tpm/tpm_bios.c
30053 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30054 event = addr;
30055
30056 if ((event->event_type == 0 && event->event_size == 0) ||
30057 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30058 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30059 return NULL;
30060
30061 return addr;
30062 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30063 return NULL;
30064
30065 if ((event->event_type == 0 && event->event_size == 0) ||
30066 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30067 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30068 return NULL;
30069
30070 (*pos)++;
30071 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30072 int i;
30073
30074 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30075 - seq_putc(m, data[i]);
30076 + if (!seq_putc(m, data[i]))
30077 + return -EFAULT;
30078
30079 return 0;
30080 }
30081 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30082 log->bios_event_log_end = log->bios_event_log + len;
30083
30084 virt = acpi_os_map_memory(start, len);
30085 + if (!virt) {
30086 + kfree(log->bios_event_log);
30087 + log->bios_event_log = NULL;
30088 + return -EFAULT;
30089 + }
30090
30091 - memcpy(log->bios_event_log, virt, len);
30092 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30093
30094 acpi_os_unmap_memory(virt, len);
30095 return 0;
30096 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30097 index cdf2f54..e55c197 100644
30098 --- a/drivers/char/virtio_console.c
30099 +++ b/drivers/char/virtio_console.c
30100 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30101 if (to_user) {
30102 ssize_t ret;
30103
30104 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30105 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30106 if (ret)
30107 return -EFAULT;
30108 } else {
30109 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30110 if (!port_has_data(port) && !port->host_connected)
30111 return 0;
30112
30113 - return fill_readbuf(port, ubuf, count, true);
30114 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30115 }
30116
30117 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30118 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30119 index e164c55..3aabb50 100644
30120 --- a/drivers/edac/edac_pci_sysfs.c
30121 +++ b/drivers/edac/edac_pci_sysfs.c
30122 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30123 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30124 static int edac_pci_poll_msec = 1000; /* one second workq period */
30125
30126 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30127 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30128 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30129 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30130
30131 static struct kobject *edac_pci_top_main_kobj;
30132 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30133 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30134 edac_printk(KERN_CRIT, EDAC_PCI,
30135 "Signaled System Error on %s\n",
30136 pci_name(dev));
30137 - atomic_inc(&pci_nonparity_count);
30138 + atomic_inc_unchecked(&pci_nonparity_count);
30139 }
30140
30141 if (status & (PCI_STATUS_PARITY)) {
30142 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30143 "Master Data Parity Error on %s\n",
30144 pci_name(dev));
30145
30146 - atomic_inc(&pci_parity_count);
30147 + atomic_inc_unchecked(&pci_parity_count);
30148 }
30149
30150 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30151 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30152 "Detected Parity Error on %s\n",
30153 pci_name(dev));
30154
30155 - atomic_inc(&pci_parity_count);
30156 + atomic_inc_unchecked(&pci_parity_count);
30157 }
30158 }
30159
30160 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30161 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30162 "Signaled System Error on %s\n",
30163 pci_name(dev));
30164 - atomic_inc(&pci_nonparity_count);
30165 + atomic_inc_unchecked(&pci_nonparity_count);
30166 }
30167
30168 if (status & (PCI_STATUS_PARITY)) {
30169 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30170 "Master Data Parity Error on "
30171 "%s\n", pci_name(dev));
30172
30173 - atomic_inc(&pci_parity_count);
30174 + atomic_inc_unchecked(&pci_parity_count);
30175 }
30176
30177 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30178 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30179 "Detected Parity Error on %s\n",
30180 pci_name(dev));
30181
30182 - atomic_inc(&pci_parity_count);
30183 + atomic_inc_unchecked(&pci_parity_count);
30184 }
30185 }
30186 }
30187 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30188 if (!check_pci_errors)
30189 return;
30190
30191 - before_count = atomic_read(&pci_parity_count);
30192 + before_count = atomic_read_unchecked(&pci_parity_count);
30193
30194 /* scan all PCI devices looking for a Parity Error on devices and
30195 * bridges.
30196 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30197 /* Only if operator has selected panic on PCI Error */
30198 if (edac_pci_get_panic_on_pe()) {
30199 /* If the count is different 'after' from 'before' */
30200 - if (before_count != atomic_read(&pci_parity_count))
30201 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30202 panic("EDAC: PCI Parity Error");
30203 }
30204 }
30205 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30206 index 8c87a5e..a19cbd7 100644
30207 --- a/drivers/edac/mce_amd.h
30208 +++ b/drivers/edac/mce_amd.h
30209 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30210 struct amd_decoder_ops {
30211 bool (*dc_mce)(u16, u8);
30212 bool (*ic_mce)(u16, u8);
30213 -};
30214 +} __no_const;
30215
30216 void amd_report_gart_errors(bool);
30217 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30218 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30219 index 57ea7f4..789e3c3 100644
30220 --- a/drivers/firewire/core-card.c
30221 +++ b/drivers/firewire/core-card.c
30222 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30223
30224 void fw_core_remove_card(struct fw_card *card)
30225 {
30226 - struct fw_card_driver dummy_driver = dummy_driver_template;
30227 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30228
30229 card->driver->update_phy_reg(card, 4,
30230 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30231 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30232 index f8d2287..5aaf4db 100644
30233 --- a/drivers/firewire/core-cdev.c
30234 +++ b/drivers/firewire/core-cdev.c
30235 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30236 int ret;
30237
30238 if ((request->channels == 0 && request->bandwidth == 0) ||
30239 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30240 - request->bandwidth < 0)
30241 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30242 return -EINVAL;
30243
30244 r = kmalloc(sizeof(*r), GFP_KERNEL);
30245 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30246 index 87d6f2d..5bf9d90 100644
30247 --- a/drivers/firewire/core-transaction.c
30248 +++ b/drivers/firewire/core-transaction.c
30249 @@ -37,6 +37,7 @@
30250 #include <linux/timer.h>
30251 #include <linux/types.h>
30252 #include <linux/workqueue.h>
30253 +#include <linux/sched.h>
30254
30255 #include <asm/byteorder.h>
30256
30257 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30258 index 515a42c..5ecf3ba 100644
30259 --- a/drivers/firewire/core.h
30260 +++ b/drivers/firewire/core.h
30261 @@ -111,6 +111,7 @@ struct fw_card_driver {
30262
30263 int (*stop_iso)(struct fw_iso_context *ctx);
30264 };
30265 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30266
30267 void fw_card_initialize(struct fw_card *card,
30268 const struct fw_card_driver *driver, struct device *device);
30269 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30270 index b298158..7ed8432 100644
30271 --- a/drivers/firmware/dmi_scan.c
30272 +++ b/drivers/firmware/dmi_scan.c
30273 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30274 }
30275 }
30276 else {
30277 - /*
30278 - * no iounmap() for that ioremap(); it would be a no-op, but
30279 - * it's so early in setup that sucker gets confused into doing
30280 - * what it shouldn't if we actually call it.
30281 - */
30282 p = dmi_ioremap(0xF0000, 0x10000);
30283 if (p == NULL)
30284 goto error;
30285 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30286 if (buf == NULL)
30287 return -1;
30288
30289 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30290 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30291
30292 iounmap(buf);
30293 return 0;
30294 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30295 index 82d5c20..44a7177 100644
30296 --- a/drivers/gpio/gpio-vr41xx.c
30297 +++ b/drivers/gpio/gpio-vr41xx.c
30298 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30299 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30300 maskl, pendl, maskh, pendh);
30301
30302 - atomic_inc(&irq_err_count);
30303 + atomic_inc_unchecked(&irq_err_count);
30304
30305 return -EINVAL;
30306 }
30307 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30308 index 3252e70..b5314ace 100644
30309 --- a/drivers/gpu/drm/drm_crtc_helper.c
30310 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30311 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30312 struct drm_crtc *tmp;
30313 int crtc_mask = 1;
30314
30315 - WARN(!crtc, "checking null crtc?\n");
30316 + BUG_ON(!crtc);
30317
30318 dev = crtc->dev;
30319
30320 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30321 index 9238de4..a27c72a 100644
30322 --- a/drivers/gpu/drm/drm_drv.c
30323 +++ b/drivers/gpu/drm/drm_drv.c
30324 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30325 /**
30326 * Copy and IOCTL return string to user space
30327 */
30328 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30329 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30330 {
30331 int len;
30332
30333 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30334 return -ENODEV;
30335
30336 atomic_inc(&dev->ioctl_count);
30337 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30338 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30339 ++file_priv->ioctl_count;
30340
30341 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30342 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30343 index 5062eec..4e3e51f 100644
30344 --- a/drivers/gpu/drm/drm_fops.c
30345 +++ b/drivers/gpu/drm/drm_fops.c
30346 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30347 }
30348
30349 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30350 - atomic_set(&dev->counts[i], 0);
30351 + atomic_set_unchecked(&dev->counts[i], 0);
30352
30353 dev->sigdata.lock = NULL;
30354
30355 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30356
30357 retcode = drm_open_helper(inode, filp, dev);
30358 if (!retcode) {
30359 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30360 - if (!dev->open_count++)
30361 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30362 + if (local_inc_return(&dev->open_count) == 1)
30363 retcode = drm_setup(dev);
30364 }
30365 if (!retcode) {
30366 @@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30367
30368 mutex_lock(&drm_global_mutex);
30369
30370 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30371 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30372
30373 if (dev->driver->preclose)
30374 dev->driver->preclose(dev, file_priv);
30375 @@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30376 * Begin inline drm_release
30377 */
30378
30379 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30380 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30381 task_pid_nr(current),
30382 (long)old_encode_dev(file_priv->minor->device),
30383 - dev->open_count);
30384 + local_read(&dev->open_count));
30385
30386 /* Release any auth tokens that might point to this file_priv,
30387 (do that under the drm_global_mutex) */
30388 @@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30389 * End inline drm_release
30390 */
30391
30392 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30393 - if (!--dev->open_count) {
30394 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30395 + if (local_dec_and_test(&dev->open_count)) {
30396 if (atomic_read(&dev->ioctl_count)) {
30397 DRM_ERROR("Device busy: %d\n",
30398 atomic_read(&dev->ioctl_count));
30399 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30400 index c87dc96..326055d 100644
30401 --- a/drivers/gpu/drm/drm_global.c
30402 +++ b/drivers/gpu/drm/drm_global.c
30403 @@ -36,7 +36,7 @@
30404 struct drm_global_item {
30405 struct mutex mutex;
30406 void *object;
30407 - int refcount;
30408 + atomic_t refcount;
30409 };
30410
30411 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30412 @@ -49,7 +49,7 @@ void drm_global_init(void)
30413 struct drm_global_item *item = &glob[i];
30414 mutex_init(&item->mutex);
30415 item->object = NULL;
30416 - item->refcount = 0;
30417 + atomic_set(&item->refcount, 0);
30418 }
30419 }
30420
30421 @@ -59,7 +59,7 @@ void drm_global_release(void)
30422 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30423 struct drm_global_item *item = &glob[i];
30424 BUG_ON(item->object != NULL);
30425 - BUG_ON(item->refcount != 0);
30426 + BUG_ON(atomic_read(&item->refcount) != 0);
30427 }
30428 }
30429
30430 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30431 void *object;
30432
30433 mutex_lock(&item->mutex);
30434 - if (item->refcount == 0) {
30435 + if (atomic_read(&item->refcount) == 0) {
30436 item->object = kzalloc(ref->size, GFP_KERNEL);
30437 if (unlikely(item->object == NULL)) {
30438 ret = -ENOMEM;
30439 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30440 goto out_err;
30441
30442 }
30443 - ++item->refcount;
30444 + atomic_inc(&item->refcount);
30445 ref->object = item->object;
30446 object = item->object;
30447 mutex_unlock(&item->mutex);
30448 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30449 struct drm_global_item *item = &glob[ref->global_type];
30450
30451 mutex_lock(&item->mutex);
30452 - BUG_ON(item->refcount == 0);
30453 + BUG_ON(atomic_read(&item->refcount) == 0);
30454 BUG_ON(ref->object != item->object);
30455 - if (--item->refcount == 0) {
30456 + if (atomic_dec_and_test(&item->refcount)) {
30457 ref->release(ref);
30458 item->object = NULL;
30459 }
30460 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30461 index 8928edb..0c79258 100644
30462 --- a/drivers/gpu/drm/drm_info.c
30463 +++ b/drivers/gpu/drm/drm_info.c
30464 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30465 struct drm_local_map *map;
30466 struct drm_map_list *r_list;
30467
30468 - /* Hardcoded from _DRM_FRAME_BUFFER,
30469 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30470 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30471 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30472 + static const char * const types[] = {
30473 + [_DRM_FRAME_BUFFER] = "FB",
30474 + [_DRM_REGISTERS] = "REG",
30475 + [_DRM_SHM] = "SHM",
30476 + [_DRM_AGP] = "AGP",
30477 + [_DRM_SCATTER_GATHER] = "SG",
30478 + [_DRM_CONSISTENT] = "PCI",
30479 + [_DRM_GEM] = "GEM" };
30480 const char *type;
30481 int i;
30482
30483 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30484 map = r_list->map;
30485 if (!map)
30486 continue;
30487 - if (map->type < 0 || map->type > 5)
30488 + if (map->type >= ARRAY_SIZE(types))
30489 type = "??";
30490 else
30491 type = types[map->type];
30492 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30493 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30494 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30495 vma->vm_flags & VM_IO ? 'i' : '-',
30496 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30497 + 0);
30498 +#else
30499 vma->vm_pgoff);
30500 +#endif
30501
30502 #if defined(__i386__)
30503 pgprot = pgprot_val(vma->vm_page_prot);
30504 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30505 index 637fcc3..e890b33 100644
30506 --- a/drivers/gpu/drm/drm_ioc32.c
30507 +++ b/drivers/gpu/drm/drm_ioc32.c
30508 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30509 request = compat_alloc_user_space(nbytes);
30510 if (!access_ok(VERIFY_WRITE, request, nbytes))
30511 return -EFAULT;
30512 - list = (struct drm_buf_desc *) (request + 1);
30513 + list = (struct drm_buf_desc __user *) (request + 1);
30514
30515 if (__put_user(count, &request->count)
30516 || __put_user(list, &request->list))
30517 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30518 request = compat_alloc_user_space(nbytes);
30519 if (!access_ok(VERIFY_WRITE, request, nbytes))
30520 return -EFAULT;
30521 - list = (struct drm_buf_pub *) (request + 1);
30522 + list = (struct drm_buf_pub __user *) (request + 1);
30523
30524 if (__put_user(count, &request->count)
30525 || __put_user(list, &request->list))
30526 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30527 index 64a62c6..ceab35e 100644
30528 --- a/drivers/gpu/drm/drm_ioctl.c
30529 +++ b/drivers/gpu/drm/drm_ioctl.c
30530 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30531 stats->data[i].value =
30532 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30533 else
30534 - stats->data[i].value = atomic_read(&dev->counts[i]);
30535 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30536 stats->data[i].type = dev->types[i];
30537 }
30538
30539 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30540 index 3203955..c8090af 100644
30541 --- a/drivers/gpu/drm/drm_lock.c
30542 +++ b/drivers/gpu/drm/drm_lock.c
30543 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30544 if (drm_lock_take(&master->lock, lock->context)) {
30545 master->lock.file_priv = file_priv;
30546 master->lock.lock_time = jiffies;
30547 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30548 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30549 break; /* Got lock */
30550 }
30551
30552 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30553 return -EINVAL;
30554 }
30555
30556 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30557 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30558
30559 if (drm_lock_free(&master->lock, lock->context)) {
30560 /* FIXME: Should really bail out here. */
30561 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30562 index 21bcd4a..8e074e0 100644
30563 --- a/drivers/gpu/drm/drm_stub.c
30564 +++ b/drivers/gpu/drm/drm_stub.c
30565 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30566
30567 drm_device_set_unplugged(dev);
30568
30569 - if (dev->open_count == 0) {
30570 + if (local_read(&dev->open_count) == 0) {
30571 drm_put_dev(dev);
30572 }
30573 mutex_unlock(&drm_global_mutex);
30574 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30575 index 463ec68..f5bd2b5 100644
30576 --- a/drivers/gpu/drm/i810/i810_dma.c
30577 +++ b/drivers/gpu/drm/i810/i810_dma.c
30578 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30579 dma->buflist[vertex->idx],
30580 vertex->discard, vertex->used);
30581
30582 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30583 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30584 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30585 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30586 sarea_priv->last_enqueue = dev_priv->counter - 1;
30587 sarea_priv->last_dispatch = (int)hw_status[5];
30588
30589 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30590 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30591 mc->last_render);
30592
30593 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30594 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30595 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30596 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30597 sarea_priv->last_enqueue = dev_priv->counter - 1;
30598 sarea_priv->last_dispatch = (int)hw_status[5];
30599
30600 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30601 index 6e0acad..93c8289 100644
30602 --- a/drivers/gpu/drm/i810/i810_drv.h
30603 +++ b/drivers/gpu/drm/i810/i810_drv.h
30604 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30605 int page_flipping;
30606
30607 wait_queue_head_t irq_queue;
30608 - atomic_t irq_received;
30609 - atomic_t irq_emitted;
30610 + atomic_unchecked_t irq_received;
30611 + atomic_unchecked_t irq_emitted;
30612
30613 int front_offset;
30614 } drm_i810_private_t;
30615 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30616 index 359f6e8..ada68fd 100644
30617 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30618 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30619 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30620 I915_READ(GTIMR));
30621 }
30622 seq_printf(m, "Interrupts received: %d\n",
30623 - atomic_read(&dev_priv->irq_received));
30624 + atomic_read_unchecked(&dev_priv->irq_received));
30625 for (i = 0; i < I915_NUM_RINGS; i++) {
30626 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30627 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30628 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30629 index 914c0df..d47d380 100644
30630 --- a/drivers/gpu/drm/i915/i915_dma.c
30631 +++ b/drivers/gpu/drm/i915/i915_dma.c
30632 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30633 bool can_switch;
30634
30635 spin_lock(&dev->count_lock);
30636 - can_switch = (dev->open_count == 0);
30637 + can_switch = (local_read(&dev->open_count) == 0);
30638 spin_unlock(&dev->count_lock);
30639 return can_switch;
30640 }
30641 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30642 index 627fe35..c9a7346 100644
30643 --- a/drivers/gpu/drm/i915/i915_drv.h
30644 +++ b/drivers/gpu/drm/i915/i915_drv.h
30645 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30646 /* render clock increase/decrease */
30647 /* display clock increase/decrease */
30648 /* pll clock increase/decrease */
30649 -};
30650 +} __no_const;
30651
30652 struct drm_i915_gt_funcs {
30653 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30654 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30655 -};
30656 +} __no_const;
30657
30658 struct intel_device_info {
30659 u8 gen;
30660 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30661 int current_page;
30662 int page_flipping;
30663
30664 - atomic_t irq_received;
30665 + atomic_unchecked_t irq_received;
30666
30667 /* protects the irq masks */
30668 spinlock_t irq_lock;
30669 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30670 * will be page flipped away on the next vblank. When it
30671 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30672 */
30673 - atomic_t pending_flip;
30674 + atomic_unchecked_t pending_flip;
30675 };
30676
30677 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30678 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30679 struct drm_i915_private *dev_priv, unsigned port);
30680 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30681 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30682 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30683 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30684 {
30685 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30686 }
30687 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30688 index cdf46b5..e785624 100644
30689 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30690 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30691 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30692 i915_gem_clflush_object(obj);
30693
30694 if (obj->base.pending_write_domain)
30695 - cd->flips |= atomic_read(&obj->pending_flip);
30696 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30697
30698 /* The actual obj->write_domain will be updated with
30699 * pending_write_domain after we emit the accumulated flush for all
30700 @@ -907,9 +907,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30701
30702 static int
30703 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30704 - int count)
30705 + unsigned int count)
30706 {
30707 - int i;
30708 + unsigned int i;
30709
30710 for (i = 0; i < count; i++) {
30711 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30712 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30713 index 73fa3e1..ab2e9b9 100644
30714 --- a/drivers/gpu/drm/i915/i915_irq.c
30715 +++ b/drivers/gpu/drm/i915/i915_irq.c
30716 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30717 u32 pipe_stats[I915_MAX_PIPES];
30718 bool blc_event;
30719
30720 - atomic_inc(&dev_priv->irq_received);
30721 + atomic_inc_unchecked(&dev_priv->irq_received);
30722
30723 while (true) {
30724 iir = I915_READ(VLV_IIR);
30725 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30726 irqreturn_t ret = IRQ_NONE;
30727 int i;
30728
30729 - atomic_inc(&dev_priv->irq_received);
30730 + atomic_inc_unchecked(&dev_priv->irq_received);
30731
30732 /* disable master interrupt before clearing iir */
30733 de_ier = I915_READ(DEIER);
30734 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30735 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30736 u32 hotplug_mask;
30737
30738 - atomic_inc(&dev_priv->irq_received);
30739 + atomic_inc_unchecked(&dev_priv->irq_received);
30740
30741 /* disable master interrupt before clearing iir */
30742 de_ier = I915_READ(DEIER);
30743 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30744 {
30745 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30746
30747 - atomic_set(&dev_priv->irq_received, 0);
30748 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30749
30750 I915_WRITE(HWSTAM, 0xeffe);
30751
30752 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30753 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30754 int pipe;
30755
30756 - atomic_set(&dev_priv->irq_received, 0);
30757 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30758
30759 /* VLV magic */
30760 I915_WRITE(VLV_IMR, 0);
30761 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30762 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30763 int pipe;
30764
30765 - atomic_set(&dev_priv->irq_received, 0);
30766 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30767
30768 for_each_pipe(pipe)
30769 I915_WRITE(PIPESTAT(pipe), 0);
30770 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30771 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30772 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30773
30774 - atomic_inc(&dev_priv->irq_received);
30775 + atomic_inc_unchecked(&dev_priv->irq_received);
30776
30777 iir = I915_READ16(IIR);
30778 if (iir == 0)
30779 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30780 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30781 int pipe;
30782
30783 - atomic_set(&dev_priv->irq_received, 0);
30784 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30785
30786 if (I915_HAS_HOTPLUG(dev)) {
30787 I915_WRITE(PORT_HOTPLUG_EN, 0);
30788 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30789 };
30790 int pipe, ret = IRQ_NONE;
30791
30792 - atomic_inc(&dev_priv->irq_received);
30793 + atomic_inc_unchecked(&dev_priv->irq_received);
30794
30795 iir = I915_READ(IIR);
30796 do {
30797 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30798 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30799 int pipe;
30800
30801 - atomic_set(&dev_priv->irq_received, 0);
30802 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30803
30804 I915_WRITE(PORT_HOTPLUG_EN, 0);
30805 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30806 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30807 int irq_received;
30808 int ret = IRQ_NONE, pipe;
30809
30810 - atomic_inc(&dev_priv->irq_received);
30811 + atomic_inc_unchecked(&dev_priv->irq_received);
30812
30813 iir = I915_READ(IIR);
30814
30815 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30816 index b634f6f..43c62f5 100644
30817 --- a/drivers/gpu/drm/i915/intel_display.c
30818 +++ b/drivers/gpu/drm/i915/intel_display.c
30819 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30820
30821 wait_event(dev_priv->pending_flip_queue,
30822 atomic_read(&dev_priv->mm.wedged) ||
30823 - atomic_read(&obj->pending_flip) == 0);
30824 + atomic_read_unchecked(&obj->pending_flip) == 0);
30825
30826 /* Big Hammer, we also need to ensure that any pending
30827 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30828 @@ -6168,8 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30829
30830 obj = work->old_fb_obj;
30831
30832 - atomic_clear_mask(1 << intel_crtc->plane,
30833 - &obj->pending_flip.counter);
30834 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30835
30836 wake_up(&dev_priv->pending_flip_queue);
30837 schedule_work(&work->work);
30838 @@ -6515,7 +6514,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30839 /* Block clients from rendering to the new back buffer until
30840 * the flip occurs and the object is no longer visible.
30841 */
30842 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30843 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30844
30845 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30846 if (ret)
30847 @@ -6530,7 +6529,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30848 return 0;
30849
30850 cleanup_pending:
30851 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30852 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30853 drm_gem_object_unreference(&work->old_fb_obj->base);
30854 drm_gem_object_unreference(&obj->base);
30855 mutex_unlock(&dev->struct_mutex);
30856 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30857 index 54558a0..2d97005 100644
30858 --- a/drivers/gpu/drm/mga/mga_drv.h
30859 +++ b/drivers/gpu/drm/mga/mga_drv.h
30860 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30861 u32 clear_cmd;
30862 u32 maccess;
30863
30864 - atomic_t vbl_received; /**< Number of vblanks received. */
30865 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30866 wait_queue_head_t fence_queue;
30867 - atomic_t last_fence_retired;
30868 + atomic_unchecked_t last_fence_retired;
30869 u32 next_fence_to_post;
30870
30871 unsigned int fb_cpp;
30872 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30873 index 2581202..f230a8d9 100644
30874 --- a/drivers/gpu/drm/mga/mga_irq.c
30875 +++ b/drivers/gpu/drm/mga/mga_irq.c
30876 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30877 if (crtc != 0)
30878 return 0;
30879
30880 - return atomic_read(&dev_priv->vbl_received);
30881 + return atomic_read_unchecked(&dev_priv->vbl_received);
30882 }
30883
30884
30885 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30886 /* VBLANK interrupt */
30887 if (status & MGA_VLINEPEN) {
30888 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30889 - atomic_inc(&dev_priv->vbl_received);
30890 + atomic_inc_unchecked(&dev_priv->vbl_received);
30891 drm_handle_vblank(dev, 0);
30892 handled = 1;
30893 }
30894 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30895 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30896 MGA_WRITE(MGA_PRIMEND, prim_end);
30897
30898 - atomic_inc(&dev_priv->last_fence_retired);
30899 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30900 DRM_WAKEUP(&dev_priv->fence_queue);
30901 handled = 1;
30902 }
30903 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30904 * using fences.
30905 */
30906 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30907 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30908 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30909 - *sequence) <= (1 << 23)));
30910
30911 *sequence = cur_fence;
30912 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30913 index a0a3fe3..209bf10 100644
30914 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30915 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30916 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30917 struct bit_table {
30918 const char id;
30919 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30920 -};
30921 +} __no_const;
30922
30923 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30924
30925 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30926 index 4f2cc95..9c6c510 100644
30927 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30928 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30929 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30930 u32 handle, u16 class);
30931 void (*set_tile_region)(struct drm_device *dev, int i);
30932 void (*tlb_flush)(struct drm_device *, int engine);
30933 -};
30934 +} __no_const;
30935
30936 struct nouveau_instmem_engine {
30937 void *priv;
30938 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30939 struct nouveau_mc_engine {
30940 int (*init)(struct drm_device *dev);
30941 void (*takedown)(struct drm_device *dev);
30942 -};
30943 +} __no_const;
30944
30945 struct nouveau_timer_engine {
30946 int (*init)(struct drm_device *dev);
30947 void (*takedown)(struct drm_device *dev);
30948 uint64_t (*read)(struct drm_device *dev);
30949 -};
30950 +} __no_const;
30951
30952 struct nouveau_fb_engine {
30953 int num_tiles;
30954 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30955 void (*put)(struct drm_device *, struct nouveau_mem **);
30956
30957 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30958 -};
30959 +} __no_const;
30960
30961 struct nouveau_engine {
30962 struct nouveau_instmem_engine instmem;
30963 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30964 struct drm_global_reference mem_global_ref;
30965 struct ttm_bo_global_ref bo_global_ref;
30966 struct ttm_bo_device bdev;
30967 - atomic_t validate_sequence;
30968 + atomic_unchecked_t validate_sequence;
30969 int (*move)(struct nouveau_channel *,
30970 struct ttm_buffer_object *,
30971 struct ttm_mem_reg *, struct ttm_mem_reg *);
30972 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30973 index af7cfb8..aadc2a3 100644
30974 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30975 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30976 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30977 int trycnt = 0;
30978 int ret, i;
30979
30980 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30981 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30982 retry:
30983 if (++trycnt > 100000) {
30984 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30985 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30986 index c610144..97440e2 100644
30987 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30988 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30989 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30990 bool can_switch;
30991
30992 spin_lock(&dev->count_lock);
30993 - can_switch = (dev->open_count == 0);
30994 + can_switch = (local_read(&dev->open_count) == 0);
30995 spin_unlock(&dev->count_lock);
30996 return can_switch;
30997 }
30998 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30999 index 93240bd..c490f60 100644
31000 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31001 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31002 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31003 }
31004
31005 if (nv_encoder->dcb->type == OUTPUT_DP) {
31006 - struct dp_train_func func = {
31007 + static struct dp_train_func func = {
31008 .link_set = nv50_sor_dp_link_set,
31009 .train_set = nv50_sor_dp_train_set,
31010 .train_adj = nv50_sor_dp_train_adj
31011 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31012 index 8a2fc89..3a5cf40 100644
31013 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31014 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31015 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31016 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31017
31018 if (nv_encoder->dcb->type == OUTPUT_DP) {
31019 - struct dp_train_func func = {
31020 + static struct dp_train_func func = {
31021 .link_set = nvd0_sor_dp_link_set,
31022 .train_set = nvd0_sor_dp_train_set,
31023 .train_adj = nvd0_sor_dp_train_adj
31024 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31025 index bcac90b..53bfc76 100644
31026 --- a/drivers/gpu/drm/r128/r128_cce.c
31027 +++ b/drivers/gpu/drm/r128/r128_cce.c
31028 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31029
31030 /* GH: Simple idle check.
31031 */
31032 - atomic_set(&dev_priv->idle_count, 0);
31033 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31034
31035 /* We don't support anything other than bus-mastering ring mode,
31036 * but the ring can be in either AGP or PCI space for the ring
31037 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31038 index 930c71b..499aded 100644
31039 --- a/drivers/gpu/drm/r128/r128_drv.h
31040 +++ b/drivers/gpu/drm/r128/r128_drv.h
31041 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31042 int is_pci;
31043 unsigned long cce_buffers_offset;
31044
31045 - atomic_t idle_count;
31046 + atomic_unchecked_t idle_count;
31047
31048 int page_flipping;
31049 int current_page;
31050 u32 crtc_offset;
31051 u32 crtc_offset_cntl;
31052
31053 - atomic_t vbl_received;
31054 + atomic_unchecked_t vbl_received;
31055
31056 u32 color_fmt;
31057 unsigned int front_offset;
31058 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31059 index 429d5a0..7e899ed 100644
31060 --- a/drivers/gpu/drm/r128/r128_irq.c
31061 +++ b/drivers/gpu/drm/r128/r128_irq.c
31062 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31063 if (crtc != 0)
31064 return 0;
31065
31066 - return atomic_read(&dev_priv->vbl_received);
31067 + return atomic_read_unchecked(&dev_priv->vbl_received);
31068 }
31069
31070 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31071 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31072 /* VBLANK interrupt */
31073 if (status & R128_CRTC_VBLANK_INT) {
31074 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31075 - atomic_inc(&dev_priv->vbl_received);
31076 + atomic_inc_unchecked(&dev_priv->vbl_received);
31077 drm_handle_vblank(dev, 0);
31078 return IRQ_HANDLED;
31079 }
31080 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31081 index a9e33ce..09edd4b 100644
31082 --- a/drivers/gpu/drm/r128/r128_state.c
31083 +++ b/drivers/gpu/drm/r128/r128_state.c
31084 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31085
31086 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31087 {
31088 - if (atomic_read(&dev_priv->idle_count) == 0)
31089 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31090 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31091 else
31092 - atomic_set(&dev_priv->idle_count, 0);
31093 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31094 }
31095
31096 #endif
31097 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31098 index 5a82b6b..9e69c73 100644
31099 --- a/drivers/gpu/drm/radeon/mkregtable.c
31100 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31101 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31102 regex_t mask_rex;
31103 regmatch_t match[4];
31104 char buf[1024];
31105 - size_t end;
31106 + long end;
31107 int len;
31108 int done = 0;
31109 int r;
31110 unsigned o;
31111 struct offset *offset;
31112 char last_reg_s[10];
31113 - int last_reg;
31114 + unsigned long last_reg;
31115
31116 if (regcomp
31117 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31118 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31119 index 59a1531..3bab49b 100644
31120 --- a/drivers/gpu/drm/radeon/radeon.h
31121 +++ b/drivers/gpu/drm/radeon/radeon.h
31122 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31123 int x2, int y2);
31124 void (*draw_auto)(struct radeon_device *rdev);
31125 void (*set_default_state)(struct radeon_device *rdev);
31126 -};
31127 +} __no_const;
31128
31129 struct r600_blit {
31130 struct radeon_bo *shader_obj;
31131 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31132 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31133 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31134 } pflip;
31135 -};
31136 +} __no_const;
31137
31138 /*
31139 * Asic structures
31140 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31141 index 7a3daeb..5016171 100644
31142 --- a/drivers/gpu/drm/radeon/radeon_device.c
31143 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31144 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31145 bool can_switch;
31146
31147 spin_lock(&dev->count_lock);
31148 - can_switch = (dev->open_count == 0);
31149 + can_switch = (local_read(&dev->open_count) == 0);
31150 spin_unlock(&dev->count_lock);
31151 return can_switch;
31152 }
31153 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31154 index a1b59ca..86f2d44 100644
31155 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31156 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31157 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31158
31159 /* SW interrupt */
31160 wait_queue_head_t swi_queue;
31161 - atomic_t swi_emitted;
31162 + atomic_unchecked_t swi_emitted;
31163 int vblank_crtc;
31164 uint32_t irq_enable_reg;
31165 uint32_t r500_disp_irq_reg;
31166 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31167 index 48b7cea..342236f 100644
31168 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31169 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31170 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31171 request = compat_alloc_user_space(sizeof(*request));
31172 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31173 || __put_user(req32.param, &request->param)
31174 - || __put_user((void __user *)(unsigned long)req32.value,
31175 + || __put_user((unsigned long)req32.value,
31176 &request->value))
31177 return -EFAULT;
31178
31179 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31180 index 00da384..32f972d 100644
31181 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31182 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31183 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31184 unsigned int ret;
31185 RING_LOCALS;
31186
31187 - atomic_inc(&dev_priv->swi_emitted);
31188 - ret = atomic_read(&dev_priv->swi_emitted);
31189 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31190 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31191
31192 BEGIN_RING(4);
31193 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31194 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31195 drm_radeon_private_t *dev_priv =
31196 (drm_radeon_private_t *) dev->dev_private;
31197
31198 - atomic_set(&dev_priv->swi_emitted, 0);
31199 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31200 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31201
31202 dev->max_vblank_count = 0x001fffff;
31203 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31204 index e8422ae..d22d4a8 100644
31205 --- a/drivers/gpu/drm/radeon/radeon_state.c
31206 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31207 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31208 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31209 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31210
31211 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31212 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31213 sarea_priv->nbox * sizeof(depth_boxes[0])))
31214 return -EFAULT;
31215
31216 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31217 {
31218 drm_radeon_private_t *dev_priv = dev->dev_private;
31219 drm_radeon_getparam_t *param = data;
31220 - int value;
31221 + int value = 0;
31222
31223 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31224
31225 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31226 index 5b71c71..650f9e4 100644
31227 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31228 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31229 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31230 }
31231 if (unlikely(ttm_vm_ops == NULL)) {
31232 ttm_vm_ops = vma->vm_ops;
31233 - radeon_ttm_vm_ops = *ttm_vm_ops;
31234 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31235 + pax_open_kernel();
31236 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31237 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31238 + pax_close_kernel();
31239 }
31240 vma->vm_ops = &radeon_ttm_vm_ops;
31241 return 0;
31242 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31243 index 3b663fc..57850f4 100644
31244 --- a/drivers/gpu/drm/radeon/rs690.c
31245 +++ b/drivers/gpu/drm/radeon/rs690.c
31246 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31247 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31248 rdev->pm.sideport_bandwidth.full)
31249 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31250 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31251 + read_delay_latency.full = dfixed_const(800 * 1000);
31252 read_delay_latency.full = dfixed_div(read_delay_latency,
31253 rdev->pm.igp_sideport_mclk);
31254 + a.full = dfixed_const(370);
31255 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31256 } else {
31257 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31258 rdev->pm.k8_bandwidth.full)
31259 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31260 index ebc6fac..a8313ed 100644
31261 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31262 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31263 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31264 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31265 struct shrink_control *sc)
31266 {
31267 - static atomic_t start_pool = ATOMIC_INIT(0);
31268 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31269 unsigned i;
31270 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31271 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31272 struct ttm_page_pool *pool;
31273 int shrink_pages = sc->nr_to_scan;
31274
31275 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31276 index 88edacc..1e5412b 100644
31277 --- a/drivers/gpu/drm/via/via_drv.h
31278 +++ b/drivers/gpu/drm/via/via_drv.h
31279 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31280 typedef uint32_t maskarray_t[5];
31281
31282 typedef struct drm_via_irq {
31283 - atomic_t irq_received;
31284 + atomic_unchecked_t irq_received;
31285 uint32_t pending_mask;
31286 uint32_t enable_mask;
31287 wait_queue_head_t irq_queue;
31288 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31289 struct timeval last_vblank;
31290 int last_vblank_valid;
31291 unsigned usec_per_vblank;
31292 - atomic_t vbl_received;
31293 + atomic_unchecked_t vbl_received;
31294 drm_via_state_t hc_state;
31295 char pci_buf[VIA_PCI_BUF_SIZE];
31296 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31297 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31298 index d391f48..10c8ca3 100644
31299 --- a/drivers/gpu/drm/via/via_irq.c
31300 +++ b/drivers/gpu/drm/via/via_irq.c
31301 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31302 if (crtc != 0)
31303 return 0;
31304
31305 - return atomic_read(&dev_priv->vbl_received);
31306 + return atomic_read_unchecked(&dev_priv->vbl_received);
31307 }
31308
31309 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31310 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31311
31312 status = VIA_READ(VIA_REG_INTERRUPT);
31313 if (status & VIA_IRQ_VBLANK_PENDING) {
31314 - atomic_inc(&dev_priv->vbl_received);
31315 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31316 + atomic_inc_unchecked(&dev_priv->vbl_received);
31317 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31318 do_gettimeofday(&cur_vblank);
31319 if (dev_priv->last_vblank_valid) {
31320 dev_priv->usec_per_vblank =
31321 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31322 dev_priv->last_vblank = cur_vblank;
31323 dev_priv->last_vblank_valid = 1;
31324 }
31325 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31326 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31327 DRM_DEBUG("US per vblank is: %u\n",
31328 dev_priv->usec_per_vblank);
31329 }
31330 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31331
31332 for (i = 0; i < dev_priv->num_irqs; ++i) {
31333 if (status & cur_irq->pending_mask) {
31334 - atomic_inc(&cur_irq->irq_received);
31335 + atomic_inc_unchecked(&cur_irq->irq_received);
31336 DRM_WAKEUP(&cur_irq->irq_queue);
31337 handled = 1;
31338 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31339 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31340 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31341 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31342 masks[irq][4]));
31343 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31344 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31345 } else {
31346 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31347 (((cur_irq_sequence =
31348 - atomic_read(&cur_irq->irq_received)) -
31349 + atomic_read_unchecked(&cur_irq->irq_received)) -
31350 *sequence) <= (1 << 23)));
31351 }
31352 *sequence = cur_irq_sequence;
31353 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31354 }
31355
31356 for (i = 0; i < dev_priv->num_irqs; ++i) {
31357 - atomic_set(&cur_irq->irq_received, 0);
31358 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31359 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31360 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31361 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31362 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31363 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31364 case VIA_IRQ_RELATIVE:
31365 irqwait->request.sequence +=
31366 - atomic_read(&cur_irq->irq_received);
31367 + atomic_read_unchecked(&cur_irq->irq_received);
31368 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31369 case VIA_IRQ_ABSOLUTE:
31370 break;
31371 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31372 index 29c984f..4084f1a 100644
31373 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31374 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31375 @@ -263,7 +263,7 @@ struct vmw_private {
31376 * Fencing and IRQs.
31377 */
31378
31379 - atomic_t marker_seq;
31380 + atomic_unchecked_t marker_seq;
31381 wait_queue_head_t fence_queue;
31382 wait_queue_head_t fifo_queue;
31383 int fence_queue_waiters; /* Protected by hw_mutex */
31384 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31385 index a0c2f12..68ae6cb 100644
31386 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31387 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31388 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31389 (unsigned int) min,
31390 (unsigned int) fifo->capabilities);
31391
31392 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31393 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31394 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31395 vmw_marker_queue_init(&fifo->marker_queue);
31396 return vmw_fifo_send_fence(dev_priv, &dummy);
31397 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31398 if (reserveable)
31399 iowrite32(bytes, fifo_mem +
31400 SVGA_FIFO_RESERVED);
31401 - return fifo_mem + (next_cmd >> 2);
31402 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31403 } else {
31404 need_bounce = true;
31405 }
31406 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31407
31408 fm = vmw_fifo_reserve(dev_priv, bytes);
31409 if (unlikely(fm == NULL)) {
31410 - *seqno = atomic_read(&dev_priv->marker_seq);
31411 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31412 ret = -ENOMEM;
31413 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31414 false, 3*HZ);
31415 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31416 }
31417
31418 do {
31419 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31420 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31421 } while (*seqno == 0);
31422
31423 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31424 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31425 index cabc95f..14b3d77 100644
31426 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31427 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31428 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31429 * emitted. Then the fence is stale and signaled.
31430 */
31431
31432 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31433 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31434 > VMW_FENCE_WRAP);
31435
31436 return ret;
31437 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31438
31439 if (fifo_idle)
31440 down_read(&fifo_state->rwsem);
31441 - signal_seq = atomic_read(&dev_priv->marker_seq);
31442 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31443 ret = 0;
31444
31445 for (;;) {
31446 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31447 index 8a8725c..afed796 100644
31448 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31449 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31450 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31451 while (!vmw_lag_lt(queue, us)) {
31452 spin_lock(&queue->lock);
31453 if (list_empty(&queue->head))
31454 - seqno = atomic_read(&dev_priv->marker_seq);
31455 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31456 else {
31457 marker = list_first_entry(&queue->head,
31458 struct vmw_marker, head);
31459 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31460 index 5de3bb3..08e5063 100644
31461 --- a/drivers/hid/hid-core.c
31462 +++ b/drivers/hid/hid-core.c
31463 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31464
31465 int hid_add_device(struct hid_device *hdev)
31466 {
31467 - static atomic_t id = ATOMIC_INIT(0);
31468 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31469 int ret;
31470
31471 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31472 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31473 /* XXX hack, any other cleaner solution after the driver core
31474 * is converted to allow more than 20 bytes as the device name? */
31475 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31476 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31477 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31478
31479 hid_debug_register(hdev, dev_name(&hdev->dev));
31480 ret = device_add(&hdev->dev);
31481 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31482 index eec3291..8ed706b 100644
31483 --- a/drivers/hid/hid-wiimote-debug.c
31484 +++ b/drivers/hid/hid-wiimote-debug.c
31485 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31486 else if (size == 0)
31487 return -EIO;
31488
31489 - if (copy_to_user(u, buf, size))
31490 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31491 return -EFAULT;
31492
31493 *off += size;
31494 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31495 index 14599e2..711c965 100644
31496 --- a/drivers/hid/usbhid/hiddev.c
31497 +++ b/drivers/hid/usbhid/hiddev.c
31498 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31499 break;
31500
31501 case HIDIOCAPPLICATION:
31502 - if (arg < 0 || arg >= hid->maxapplication)
31503 + if (arg >= hid->maxapplication)
31504 break;
31505
31506 for (i = 0; i < hid->maxcollection; i++)
31507 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31508 index f4c3d28..82f45a9 100644
31509 --- a/drivers/hv/channel.c
31510 +++ b/drivers/hv/channel.c
31511 @@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31512 int ret = 0;
31513 int t;
31514
31515 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31516 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31517 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31518 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31519
31520 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31521 if (ret)
31522 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31523 index 86f8885..ab9cb2b 100644
31524 --- a/drivers/hv/hv.c
31525 +++ b/drivers/hv/hv.c
31526 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31527 u64 output_address = (output) ? virt_to_phys(output) : 0;
31528 u32 output_address_hi = output_address >> 32;
31529 u32 output_address_lo = output_address & 0xFFFFFFFF;
31530 - void *hypercall_page = hv_context.hypercall_page;
31531 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31532
31533 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31534 "=a"(hv_status_lo) : "d" (control_hi),
31535 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31536 index 0614ff3..f0b2b5c 100644
31537 --- a/drivers/hv/hyperv_vmbus.h
31538 +++ b/drivers/hv/hyperv_vmbus.h
31539 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31540 struct vmbus_connection {
31541 enum vmbus_connect_state conn_state;
31542
31543 - atomic_t next_gpadl_handle;
31544 + atomic_unchecked_t next_gpadl_handle;
31545
31546 /*
31547 * Represents channel interrupts. Each bit position represents a
31548 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31549 index 4748086..3abf845 100644
31550 --- a/drivers/hv/vmbus_drv.c
31551 +++ b/drivers/hv/vmbus_drv.c
31552 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31553 {
31554 int ret = 0;
31555
31556 - static atomic_t device_num = ATOMIC_INIT(0);
31557 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31558
31559 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31560 - atomic_inc_return(&device_num));
31561 + atomic_inc_return_unchecked(&device_num));
31562
31563 child_device_obj->device.bus = &hv_bus;
31564 child_device_obj->device.parent = &hv_acpi_dev->dev;
31565 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31566 index 8b011d0..3de24a1 100644
31567 --- a/drivers/hwmon/sht15.c
31568 +++ b/drivers/hwmon/sht15.c
31569 @@ -166,7 +166,7 @@ struct sht15_data {
31570 int supply_uV;
31571 bool supply_uV_valid;
31572 struct work_struct update_supply_work;
31573 - atomic_t interrupt_handled;
31574 + atomic_unchecked_t interrupt_handled;
31575 };
31576
31577 /**
31578 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31579 return ret;
31580
31581 gpio_direction_input(data->pdata->gpio_data);
31582 - atomic_set(&data->interrupt_handled, 0);
31583 + atomic_set_unchecked(&data->interrupt_handled, 0);
31584
31585 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31586 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31587 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31588 /* Only relevant if the interrupt hasn't occurred. */
31589 - if (!atomic_read(&data->interrupt_handled))
31590 + if (!atomic_read_unchecked(&data->interrupt_handled))
31591 schedule_work(&data->read_work);
31592 }
31593 ret = wait_event_timeout(data->wait_queue,
31594 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31595
31596 /* First disable the interrupt */
31597 disable_irq_nosync(irq);
31598 - atomic_inc(&data->interrupt_handled);
31599 + atomic_inc_unchecked(&data->interrupt_handled);
31600 /* Then schedule a reading work struct */
31601 if (data->state != SHT15_READING_NOTHING)
31602 schedule_work(&data->read_work);
31603 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31604 * If not, then start the interrupt again - care here as could
31605 * have gone low in meantime so verify it hasn't!
31606 */
31607 - atomic_set(&data->interrupt_handled, 0);
31608 + atomic_set_unchecked(&data->interrupt_handled, 0);
31609 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31610 /* If still not occurred or another handler was scheduled */
31611 if (gpio_get_value(data->pdata->gpio_data)
31612 - || atomic_read(&data->interrupt_handled))
31613 + || atomic_read_unchecked(&data->interrupt_handled))
31614 return;
31615 }
31616
31617 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31618 index 378fcb5..5e91fa8 100644
31619 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31620 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31621 @@ -43,7 +43,7 @@
31622 extern struct i2c_adapter amd756_smbus;
31623
31624 static struct i2c_adapter *s4882_adapter;
31625 -static struct i2c_algorithm *s4882_algo;
31626 +static i2c_algorithm_no_const *s4882_algo;
31627
31628 /* Wrapper access functions for multiplexed SMBus */
31629 static DEFINE_MUTEX(amd756_lock);
31630 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31631 index 29015eb..af2d8e9 100644
31632 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31633 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31634 @@ -41,7 +41,7 @@
31635 extern struct i2c_adapter *nforce2_smbus;
31636
31637 static struct i2c_adapter *s4985_adapter;
31638 -static struct i2c_algorithm *s4985_algo;
31639 +static i2c_algorithm_no_const *s4985_algo;
31640
31641 /* Wrapper access functions for multiplexed SMBus */
31642 static DEFINE_MUTEX(nforce2_lock);
31643 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31644 index 1038c38..eb92f51 100644
31645 --- a/drivers/i2c/i2c-mux.c
31646 +++ b/drivers/i2c/i2c-mux.c
31647 @@ -30,7 +30,7 @@
31648 /* multiplexer per channel data */
31649 struct i2c_mux_priv {
31650 struct i2c_adapter adap;
31651 - struct i2c_algorithm algo;
31652 + i2c_algorithm_no_const algo;
31653
31654 struct i2c_adapter *parent;
31655 void *mux_priv; /* the mux chip/device */
31656 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31657 index 57d00ca..0145194 100644
31658 --- a/drivers/ide/aec62xx.c
31659 +++ b/drivers/ide/aec62xx.c
31660 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31661 .cable_detect = atp86x_cable_detect,
31662 };
31663
31664 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31665 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31666 { /* 0: AEC6210 */
31667 .name = DRV_NAME,
31668 .init_chipset = init_chipset_aec62xx,
31669 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31670 index 2c8016a..911a27c 100644
31671 --- a/drivers/ide/alim15x3.c
31672 +++ b/drivers/ide/alim15x3.c
31673 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31674 .dma_sff_read_status = ide_dma_sff_read_status,
31675 };
31676
31677 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31678 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31679 .name = DRV_NAME,
31680 .init_chipset = init_chipset_ali15x3,
31681 .init_hwif = init_hwif_ali15x3,
31682 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31683 index 3747b25..56fc995 100644
31684 --- a/drivers/ide/amd74xx.c
31685 +++ b/drivers/ide/amd74xx.c
31686 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31687 .udma_mask = udma, \
31688 }
31689
31690 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31691 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31692 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31693 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31694 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31695 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31696 index 15f0ead..cb43480 100644
31697 --- a/drivers/ide/atiixp.c
31698 +++ b/drivers/ide/atiixp.c
31699 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31700 .cable_detect = atiixp_cable_detect,
31701 };
31702
31703 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31704 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31705 { /* 0: IXP200/300/400/700 */
31706 .name = DRV_NAME,
31707 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31708 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31709 index 5f80312..d1fc438 100644
31710 --- a/drivers/ide/cmd64x.c
31711 +++ b/drivers/ide/cmd64x.c
31712 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31713 .dma_sff_read_status = ide_dma_sff_read_status,
31714 };
31715
31716 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31717 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31718 { /* 0: CMD643 */
31719 .name = DRV_NAME,
31720 .init_chipset = init_chipset_cmd64x,
31721 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31722 index 2c1e5f7..1444762 100644
31723 --- a/drivers/ide/cs5520.c
31724 +++ b/drivers/ide/cs5520.c
31725 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31726 .set_dma_mode = cs5520_set_dma_mode,
31727 };
31728
31729 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31730 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31731 .name = DRV_NAME,
31732 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31733 .port_ops = &cs5520_port_ops,
31734 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31735 index 4dc4eb9..49b40ad 100644
31736 --- a/drivers/ide/cs5530.c
31737 +++ b/drivers/ide/cs5530.c
31738 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31739 .udma_filter = cs5530_udma_filter,
31740 };
31741
31742 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31743 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31744 .name = DRV_NAME,
31745 .init_chipset = init_chipset_cs5530,
31746 .init_hwif = init_hwif_cs5530,
31747 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31748 index 5059faf..18d4c85 100644
31749 --- a/drivers/ide/cs5535.c
31750 +++ b/drivers/ide/cs5535.c
31751 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31752 .cable_detect = cs5535_cable_detect,
31753 };
31754
31755 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31756 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31757 .name = DRV_NAME,
31758 .port_ops = &cs5535_port_ops,
31759 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31760 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31761 index 847553f..3ffb49d 100644
31762 --- a/drivers/ide/cy82c693.c
31763 +++ b/drivers/ide/cy82c693.c
31764 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31765 .set_dma_mode = cy82c693_set_dma_mode,
31766 };
31767
31768 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31769 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31770 .name = DRV_NAME,
31771 .init_iops = init_iops_cy82c693,
31772 .port_ops = &cy82c693_port_ops,
31773 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31774 index 58c51cd..4aec3b8 100644
31775 --- a/drivers/ide/hpt366.c
31776 +++ b/drivers/ide/hpt366.c
31777 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31778 }
31779 };
31780
31781 -static const struct hpt_info hpt36x __devinitdata = {
31782 +static const struct hpt_info hpt36x __devinitconst = {
31783 .chip_name = "HPT36x",
31784 .chip_type = HPT36x,
31785 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31786 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31787 .timings = &hpt36x_timings
31788 };
31789
31790 -static const struct hpt_info hpt370 __devinitdata = {
31791 +static const struct hpt_info hpt370 __devinitconst = {
31792 .chip_name = "HPT370",
31793 .chip_type = HPT370,
31794 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31795 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31796 .timings = &hpt37x_timings
31797 };
31798
31799 -static const struct hpt_info hpt370a __devinitdata = {
31800 +static const struct hpt_info hpt370a __devinitconst = {
31801 .chip_name = "HPT370A",
31802 .chip_type = HPT370A,
31803 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31804 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31805 .timings = &hpt37x_timings
31806 };
31807
31808 -static const struct hpt_info hpt374 __devinitdata = {
31809 +static const struct hpt_info hpt374 __devinitconst = {
31810 .chip_name = "HPT374",
31811 .chip_type = HPT374,
31812 .udma_mask = ATA_UDMA5,
31813 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31814 .timings = &hpt37x_timings
31815 };
31816
31817 -static const struct hpt_info hpt372 __devinitdata = {
31818 +static const struct hpt_info hpt372 __devinitconst = {
31819 .chip_name = "HPT372",
31820 .chip_type = HPT372,
31821 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31822 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31823 .timings = &hpt37x_timings
31824 };
31825
31826 -static const struct hpt_info hpt372a __devinitdata = {
31827 +static const struct hpt_info hpt372a __devinitconst = {
31828 .chip_name = "HPT372A",
31829 .chip_type = HPT372A,
31830 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31831 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31832 .timings = &hpt37x_timings
31833 };
31834
31835 -static const struct hpt_info hpt302 __devinitdata = {
31836 +static const struct hpt_info hpt302 __devinitconst = {
31837 .chip_name = "HPT302",
31838 .chip_type = HPT302,
31839 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31840 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31841 .timings = &hpt37x_timings
31842 };
31843
31844 -static const struct hpt_info hpt371 __devinitdata = {
31845 +static const struct hpt_info hpt371 __devinitconst = {
31846 .chip_name = "HPT371",
31847 .chip_type = HPT371,
31848 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31849 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31850 .timings = &hpt37x_timings
31851 };
31852
31853 -static const struct hpt_info hpt372n __devinitdata = {
31854 +static const struct hpt_info hpt372n __devinitconst = {
31855 .chip_name = "HPT372N",
31856 .chip_type = HPT372N,
31857 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31858 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31859 .timings = &hpt37x_timings
31860 };
31861
31862 -static const struct hpt_info hpt302n __devinitdata = {
31863 +static const struct hpt_info hpt302n __devinitconst = {
31864 .chip_name = "HPT302N",
31865 .chip_type = HPT302N,
31866 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31867 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31868 .timings = &hpt37x_timings
31869 };
31870
31871 -static const struct hpt_info hpt371n __devinitdata = {
31872 +static const struct hpt_info hpt371n __devinitconst = {
31873 .chip_name = "HPT371N",
31874 .chip_type = HPT371N,
31875 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31876 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31877 .dma_sff_read_status = ide_dma_sff_read_status,
31878 };
31879
31880 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31881 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31882 { /* 0: HPT36x */
31883 .name = DRV_NAME,
31884 .init_chipset = init_chipset_hpt366,
31885 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31886 index 8126824..55a2798 100644
31887 --- a/drivers/ide/ide-cd.c
31888 +++ b/drivers/ide/ide-cd.c
31889 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31890 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31891 if ((unsigned long)buf & alignment
31892 || blk_rq_bytes(rq) & q->dma_pad_mask
31893 - || object_is_on_stack(buf))
31894 + || object_starts_on_stack(buf))
31895 drive->dma = 0;
31896 }
31897 }
31898 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31899 index 7f56b73..dab5b67 100644
31900 --- a/drivers/ide/ide-pci-generic.c
31901 +++ b/drivers/ide/ide-pci-generic.c
31902 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31903 .udma_mask = ATA_UDMA6, \
31904 }
31905
31906 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31907 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31908 /* 0: Unknown */
31909 DECLARE_GENERIC_PCI_DEV(0),
31910
31911 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31912 index 560e66d..d5dd180 100644
31913 --- a/drivers/ide/it8172.c
31914 +++ b/drivers/ide/it8172.c
31915 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31916 .set_dma_mode = it8172_set_dma_mode,
31917 };
31918
31919 -static const struct ide_port_info it8172_port_info __devinitdata = {
31920 +static const struct ide_port_info it8172_port_info __devinitconst = {
31921 .name = DRV_NAME,
31922 .port_ops = &it8172_port_ops,
31923 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31924 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31925 index 46816ba..1847aeb 100644
31926 --- a/drivers/ide/it8213.c
31927 +++ b/drivers/ide/it8213.c
31928 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31929 .cable_detect = it8213_cable_detect,
31930 };
31931
31932 -static const struct ide_port_info it8213_chipset __devinitdata = {
31933 +static const struct ide_port_info it8213_chipset __devinitconst = {
31934 .name = DRV_NAME,
31935 .enablebits = { {0x41, 0x80, 0x80} },
31936 .port_ops = &it8213_port_ops,
31937 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31938 index 2e3169f..c5611db 100644
31939 --- a/drivers/ide/it821x.c
31940 +++ b/drivers/ide/it821x.c
31941 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31942 .cable_detect = it821x_cable_detect,
31943 };
31944
31945 -static const struct ide_port_info it821x_chipset __devinitdata = {
31946 +static const struct ide_port_info it821x_chipset __devinitconst = {
31947 .name = DRV_NAME,
31948 .init_chipset = init_chipset_it821x,
31949 .init_hwif = init_hwif_it821x,
31950 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31951 index 74c2c4a..efddd7d 100644
31952 --- a/drivers/ide/jmicron.c
31953 +++ b/drivers/ide/jmicron.c
31954 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31955 .cable_detect = jmicron_cable_detect,
31956 };
31957
31958 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31959 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31960 .name = DRV_NAME,
31961 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31962 .port_ops = &jmicron_port_ops,
31963 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31964 index 95327a2..73f78d8 100644
31965 --- a/drivers/ide/ns87415.c
31966 +++ b/drivers/ide/ns87415.c
31967 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31968 .dma_sff_read_status = superio_dma_sff_read_status,
31969 };
31970
31971 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31972 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31973 .name = DRV_NAME,
31974 .init_hwif = init_hwif_ns87415,
31975 .tp_ops = &ns87415_tp_ops,
31976 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31977 index 1a53a4c..39edc66 100644
31978 --- a/drivers/ide/opti621.c
31979 +++ b/drivers/ide/opti621.c
31980 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31981 .set_pio_mode = opti621_set_pio_mode,
31982 };
31983
31984 -static const struct ide_port_info opti621_chipset __devinitdata = {
31985 +static const struct ide_port_info opti621_chipset __devinitconst = {
31986 .name = DRV_NAME,
31987 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31988 .port_ops = &opti621_port_ops,
31989 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31990 index 9546fe2..2e5ceb6 100644
31991 --- a/drivers/ide/pdc202xx_new.c
31992 +++ b/drivers/ide/pdc202xx_new.c
31993 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31994 .udma_mask = udma, \
31995 }
31996
31997 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31998 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31999 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32000 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32001 };
32002 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32003 index 3a35ec6..5634510 100644
32004 --- a/drivers/ide/pdc202xx_old.c
32005 +++ b/drivers/ide/pdc202xx_old.c
32006 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32007 .max_sectors = sectors, \
32008 }
32009
32010 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32011 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32012 { /* 0: PDC20246 */
32013 .name = DRV_NAME,
32014 .init_chipset = init_chipset_pdc202xx,
32015 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32016 index 1892e81..fe0fd60 100644
32017 --- a/drivers/ide/piix.c
32018 +++ b/drivers/ide/piix.c
32019 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32020 .udma_mask = udma, \
32021 }
32022
32023 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32024 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32025 /* 0: MPIIX */
32026 { /*
32027 * MPIIX actually has only a single IDE channel mapped to
32028 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32029 index a6414a8..c04173e 100644
32030 --- a/drivers/ide/rz1000.c
32031 +++ b/drivers/ide/rz1000.c
32032 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32033 }
32034 }
32035
32036 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32037 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32038 .name = DRV_NAME,
32039 .host_flags = IDE_HFLAG_NO_DMA,
32040 };
32041 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32042 index 356b9b5..d4758eb 100644
32043 --- a/drivers/ide/sc1200.c
32044 +++ b/drivers/ide/sc1200.c
32045 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32046 .dma_sff_read_status = ide_dma_sff_read_status,
32047 };
32048
32049 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32050 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32051 .name = DRV_NAME,
32052 .port_ops = &sc1200_port_ops,
32053 .dma_ops = &sc1200_dma_ops,
32054 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32055 index b7f5b0c..9701038 100644
32056 --- a/drivers/ide/scc_pata.c
32057 +++ b/drivers/ide/scc_pata.c
32058 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32059 .dma_sff_read_status = scc_dma_sff_read_status,
32060 };
32061
32062 -static const struct ide_port_info scc_chipset __devinitdata = {
32063 +static const struct ide_port_info scc_chipset __devinitconst = {
32064 .name = "sccIDE",
32065 .init_iops = init_iops_scc,
32066 .init_dma = scc_init_dma,
32067 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32068 index 35fb8da..24d72ef 100644
32069 --- a/drivers/ide/serverworks.c
32070 +++ b/drivers/ide/serverworks.c
32071 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32072 .cable_detect = svwks_cable_detect,
32073 };
32074
32075 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32076 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32077 { /* 0: OSB4 */
32078 .name = DRV_NAME,
32079 .init_chipset = init_chipset_svwks,
32080 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32081 index ddeda44..46f7e30 100644
32082 --- a/drivers/ide/siimage.c
32083 +++ b/drivers/ide/siimage.c
32084 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32085 .udma_mask = ATA_UDMA6, \
32086 }
32087
32088 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32089 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32090 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32091 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32092 };
32093 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32094 index 4a00225..09e61b4 100644
32095 --- a/drivers/ide/sis5513.c
32096 +++ b/drivers/ide/sis5513.c
32097 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32098 .cable_detect = sis_cable_detect,
32099 };
32100
32101 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32102 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32103 .name = DRV_NAME,
32104 .init_chipset = init_chipset_sis5513,
32105 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32106 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32107 index f21dc2a..d051cd2 100644
32108 --- a/drivers/ide/sl82c105.c
32109 +++ b/drivers/ide/sl82c105.c
32110 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32111 .dma_sff_read_status = ide_dma_sff_read_status,
32112 };
32113
32114 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32115 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32116 .name = DRV_NAME,
32117 .init_chipset = init_chipset_sl82c105,
32118 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32119 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32120 index 864ffe0..863a5e9 100644
32121 --- a/drivers/ide/slc90e66.c
32122 +++ b/drivers/ide/slc90e66.c
32123 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32124 .cable_detect = slc90e66_cable_detect,
32125 };
32126
32127 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32128 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32129 .name = DRV_NAME,
32130 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32131 .port_ops = &slc90e66_port_ops,
32132 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32133 index 4799d5c..1794678 100644
32134 --- a/drivers/ide/tc86c001.c
32135 +++ b/drivers/ide/tc86c001.c
32136 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32137 .dma_sff_read_status = ide_dma_sff_read_status,
32138 };
32139
32140 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32141 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32142 .name = DRV_NAME,
32143 .init_hwif = init_hwif_tc86c001,
32144 .port_ops = &tc86c001_port_ops,
32145 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32146 index 281c914..55ce1b8 100644
32147 --- a/drivers/ide/triflex.c
32148 +++ b/drivers/ide/triflex.c
32149 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32150 .set_dma_mode = triflex_set_mode,
32151 };
32152
32153 -static const struct ide_port_info triflex_device __devinitdata = {
32154 +static const struct ide_port_info triflex_device __devinitconst = {
32155 .name = DRV_NAME,
32156 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32157 .port_ops = &triflex_port_ops,
32158 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32159 index 4b42ca0..e494a98 100644
32160 --- a/drivers/ide/trm290.c
32161 +++ b/drivers/ide/trm290.c
32162 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32163 .dma_check = trm290_dma_check,
32164 };
32165
32166 -static const struct ide_port_info trm290_chipset __devinitdata = {
32167 +static const struct ide_port_info trm290_chipset __devinitconst = {
32168 .name = DRV_NAME,
32169 .init_hwif = init_hwif_trm290,
32170 .tp_ops = &trm290_tp_ops,
32171 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32172 index f46f49c..eb77678 100644
32173 --- a/drivers/ide/via82cxxx.c
32174 +++ b/drivers/ide/via82cxxx.c
32175 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32176 .cable_detect = via82cxxx_cable_detect,
32177 };
32178
32179 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32180 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32181 .name = DRV_NAME,
32182 .init_chipset = init_chipset_via82cxxx,
32183 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32184 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32185 index 73d4531..c90cd2d 100644
32186 --- a/drivers/ieee802154/fakehard.c
32187 +++ b/drivers/ieee802154/fakehard.c
32188 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32189 phy->transmit_power = 0xbf;
32190
32191 dev->netdev_ops = &fake_ops;
32192 - dev->ml_priv = &fake_mlme;
32193 + dev->ml_priv = (void *)&fake_mlme;
32194
32195 priv = netdev_priv(dev);
32196 priv->phy = phy;
32197 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32198 index d67999f..4c5d083 100644
32199 --- a/drivers/infiniband/core/cm.c
32200 +++ b/drivers/infiniband/core/cm.c
32201 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32202
32203 struct cm_counter_group {
32204 struct kobject obj;
32205 - atomic_long_t counter[CM_ATTR_COUNT];
32206 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32207 };
32208
32209 struct cm_counter_attribute {
32210 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32211 struct ib_mad_send_buf *msg = NULL;
32212 int ret;
32213
32214 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32215 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32216 counter[CM_REQ_COUNTER]);
32217
32218 /* Quick state check to discard duplicate REQs. */
32219 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32220 if (!cm_id_priv)
32221 return;
32222
32223 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32224 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32225 counter[CM_REP_COUNTER]);
32226 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32227 if (ret)
32228 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32229 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32230 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32231 spin_unlock_irq(&cm_id_priv->lock);
32232 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32233 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32234 counter[CM_RTU_COUNTER]);
32235 goto out;
32236 }
32237 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32238 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32239 dreq_msg->local_comm_id);
32240 if (!cm_id_priv) {
32241 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32242 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32243 counter[CM_DREQ_COUNTER]);
32244 cm_issue_drep(work->port, work->mad_recv_wc);
32245 return -EINVAL;
32246 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32247 case IB_CM_MRA_REP_RCVD:
32248 break;
32249 case IB_CM_TIMEWAIT:
32250 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32251 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32252 counter[CM_DREQ_COUNTER]);
32253 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32254 goto unlock;
32255 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32256 cm_free_msg(msg);
32257 goto deref;
32258 case IB_CM_DREQ_RCVD:
32259 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32260 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32261 counter[CM_DREQ_COUNTER]);
32262 goto unlock;
32263 default:
32264 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32265 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32266 cm_id_priv->msg, timeout)) {
32267 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32268 - atomic_long_inc(&work->port->
32269 + atomic_long_inc_unchecked(&work->port->
32270 counter_group[CM_RECV_DUPLICATES].
32271 counter[CM_MRA_COUNTER]);
32272 goto out;
32273 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32274 break;
32275 case IB_CM_MRA_REQ_RCVD:
32276 case IB_CM_MRA_REP_RCVD:
32277 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32278 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32279 counter[CM_MRA_COUNTER]);
32280 /* fall through */
32281 default:
32282 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32283 case IB_CM_LAP_IDLE:
32284 break;
32285 case IB_CM_MRA_LAP_SENT:
32286 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32287 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32288 counter[CM_LAP_COUNTER]);
32289 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32290 goto unlock;
32291 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32292 cm_free_msg(msg);
32293 goto deref;
32294 case IB_CM_LAP_RCVD:
32295 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32296 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32297 counter[CM_LAP_COUNTER]);
32298 goto unlock;
32299 default:
32300 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32301 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32302 if (cur_cm_id_priv) {
32303 spin_unlock_irq(&cm.lock);
32304 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32305 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32306 counter[CM_SIDR_REQ_COUNTER]);
32307 goto out; /* Duplicate message. */
32308 }
32309 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32310 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32311 msg->retries = 1;
32312
32313 - atomic_long_add(1 + msg->retries,
32314 + atomic_long_add_unchecked(1 + msg->retries,
32315 &port->counter_group[CM_XMIT].counter[attr_index]);
32316 if (msg->retries)
32317 - atomic_long_add(msg->retries,
32318 + atomic_long_add_unchecked(msg->retries,
32319 &port->counter_group[CM_XMIT_RETRIES].
32320 counter[attr_index]);
32321
32322 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32323 }
32324
32325 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32326 - atomic_long_inc(&port->counter_group[CM_RECV].
32327 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32328 counter[attr_id - CM_ATTR_ID_OFFSET]);
32329
32330 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32331 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32332 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32333
32334 return sprintf(buf, "%ld\n",
32335 - atomic_long_read(&group->counter[cm_attr->index]));
32336 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32337 }
32338
32339 static const struct sysfs_ops cm_counter_ops = {
32340 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32341 index 176c8f9..2627b62 100644
32342 --- a/drivers/infiniband/core/fmr_pool.c
32343 +++ b/drivers/infiniband/core/fmr_pool.c
32344 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32345
32346 struct task_struct *thread;
32347
32348 - atomic_t req_ser;
32349 - atomic_t flush_ser;
32350 + atomic_unchecked_t req_ser;
32351 + atomic_unchecked_t flush_ser;
32352
32353 wait_queue_head_t force_wait;
32354 };
32355 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32356 struct ib_fmr_pool *pool = pool_ptr;
32357
32358 do {
32359 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32360 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32361 ib_fmr_batch_release(pool);
32362
32363 - atomic_inc(&pool->flush_ser);
32364 + atomic_inc_unchecked(&pool->flush_ser);
32365 wake_up_interruptible(&pool->force_wait);
32366
32367 if (pool->flush_function)
32368 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32369 }
32370
32371 set_current_state(TASK_INTERRUPTIBLE);
32372 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32373 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32374 !kthread_should_stop())
32375 schedule();
32376 __set_current_state(TASK_RUNNING);
32377 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32378 pool->dirty_watermark = params->dirty_watermark;
32379 pool->dirty_len = 0;
32380 spin_lock_init(&pool->pool_lock);
32381 - atomic_set(&pool->req_ser, 0);
32382 - atomic_set(&pool->flush_ser, 0);
32383 + atomic_set_unchecked(&pool->req_ser, 0);
32384 + atomic_set_unchecked(&pool->flush_ser, 0);
32385 init_waitqueue_head(&pool->force_wait);
32386
32387 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32388 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32389 }
32390 spin_unlock_irq(&pool->pool_lock);
32391
32392 - serial = atomic_inc_return(&pool->req_ser);
32393 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32394 wake_up_process(pool->thread);
32395
32396 if (wait_event_interruptible(pool->force_wait,
32397 - atomic_read(&pool->flush_ser) - serial >= 0))
32398 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32399 return -EINTR;
32400
32401 return 0;
32402 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32403 } else {
32404 list_add_tail(&fmr->list, &pool->dirty_list);
32405 if (++pool->dirty_len >= pool->dirty_watermark) {
32406 - atomic_inc(&pool->req_ser);
32407 + atomic_inc_unchecked(&pool->req_ser);
32408 wake_up_process(pool->thread);
32409 }
32410 }
32411 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32412 index 57e07c6..56d09d4 100644
32413 --- a/drivers/infiniband/hw/cxgb4/mem.c
32414 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32415 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32416 int err;
32417 struct fw_ri_tpte tpt;
32418 u32 stag_idx;
32419 - static atomic_t key;
32420 + static atomic_unchecked_t key;
32421
32422 if (c4iw_fatal_error(rdev))
32423 return -EIO;
32424 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32425 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32426 rdev->stats.stag.max = rdev->stats.stag.cur;
32427 mutex_unlock(&rdev->stats.lock);
32428 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32429 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32430 }
32431 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32432 __func__, stag_state, type, pdid, stag_idx);
32433 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32434 index 79b3dbc..96e5fcc 100644
32435 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32436 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32437 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32438 struct ib_atomic_eth *ateth;
32439 struct ipath_ack_entry *e;
32440 u64 vaddr;
32441 - atomic64_t *maddr;
32442 + atomic64_unchecked_t *maddr;
32443 u64 sdata;
32444 u32 rkey;
32445 u8 next;
32446 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32447 IB_ACCESS_REMOTE_ATOMIC)))
32448 goto nack_acc_unlck;
32449 /* Perform atomic OP and save result. */
32450 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32451 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32452 sdata = be64_to_cpu(ateth->swap_data);
32453 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32454 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32455 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32456 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32457 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32458 be64_to_cpu(ateth->compare_data),
32459 sdata);
32460 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32461 index 1f95bba..9530f87 100644
32462 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32463 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32464 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32465 unsigned long flags;
32466 struct ib_wc wc;
32467 u64 sdata;
32468 - atomic64_t *maddr;
32469 + atomic64_unchecked_t *maddr;
32470 enum ib_wc_status send_status;
32471
32472 /*
32473 @@ -382,11 +382,11 @@ again:
32474 IB_ACCESS_REMOTE_ATOMIC)))
32475 goto acc_err;
32476 /* Perform atomic OP and save result. */
32477 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32478 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32479 sdata = wqe->wr.wr.atomic.compare_add;
32480 *(u64 *) sqp->s_sge.sge.vaddr =
32481 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32482 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32483 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32484 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32485 sdata, wqe->wr.wr.atomic.swap);
32486 goto send_comp;
32487 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32488 index 7140199..da60063 100644
32489 --- a/drivers/infiniband/hw/nes/nes.c
32490 +++ b/drivers/infiniband/hw/nes/nes.c
32491 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32492 LIST_HEAD(nes_adapter_list);
32493 static LIST_HEAD(nes_dev_list);
32494
32495 -atomic_t qps_destroyed;
32496 +atomic_unchecked_t qps_destroyed;
32497
32498 static unsigned int ee_flsh_adapter;
32499 static unsigned int sysfs_nonidx_addr;
32500 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32501 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32502 struct nes_adapter *nesadapter = nesdev->nesadapter;
32503
32504 - atomic_inc(&qps_destroyed);
32505 + atomic_inc_unchecked(&qps_destroyed);
32506
32507 /* Free the control structures */
32508
32509 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32510 index c438e46..ca30356 100644
32511 --- a/drivers/infiniband/hw/nes/nes.h
32512 +++ b/drivers/infiniband/hw/nes/nes.h
32513 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32514 extern unsigned int wqm_quanta;
32515 extern struct list_head nes_adapter_list;
32516
32517 -extern atomic_t cm_connects;
32518 -extern atomic_t cm_accepts;
32519 -extern atomic_t cm_disconnects;
32520 -extern atomic_t cm_closes;
32521 -extern atomic_t cm_connecteds;
32522 -extern atomic_t cm_connect_reqs;
32523 -extern atomic_t cm_rejects;
32524 -extern atomic_t mod_qp_timouts;
32525 -extern atomic_t qps_created;
32526 -extern atomic_t qps_destroyed;
32527 -extern atomic_t sw_qps_destroyed;
32528 +extern atomic_unchecked_t cm_connects;
32529 +extern atomic_unchecked_t cm_accepts;
32530 +extern atomic_unchecked_t cm_disconnects;
32531 +extern atomic_unchecked_t cm_closes;
32532 +extern atomic_unchecked_t cm_connecteds;
32533 +extern atomic_unchecked_t cm_connect_reqs;
32534 +extern atomic_unchecked_t cm_rejects;
32535 +extern atomic_unchecked_t mod_qp_timouts;
32536 +extern atomic_unchecked_t qps_created;
32537 +extern atomic_unchecked_t qps_destroyed;
32538 +extern atomic_unchecked_t sw_qps_destroyed;
32539 extern u32 mh_detected;
32540 extern u32 mh_pauses_sent;
32541 extern u32 cm_packets_sent;
32542 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32543 extern u32 cm_packets_received;
32544 extern u32 cm_packets_dropped;
32545 extern u32 cm_packets_retrans;
32546 -extern atomic_t cm_listens_created;
32547 -extern atomic_t cm_listens_destroyed;
32548 +extern atomic_unchecked_t cm_listens_created;
32549 +extern atomic_unchecked_t cm_listens_destroyed;
32550 extern u32 cm_backlog_drops;
32551 -extern atomic_t cm_loopbacks;
32552 -extern atomic_t cm_nodes_created;
32553 -extern atomic_t cm_nodes_destroyed;
32554 -extern atomic_t cm_accel_dropped_pkts;
32555 -extern atomic_t cm_resets_recvd;
32556 -extern atomic_t pau_qps_created;
32557 -extern atomic_t pau_qps_destroyed;
32558 +extern atomic_unchecked_t cm_loopbacks;
32559 +extern atomic_unchecked_t cm_nodes_created;
32560 +extern atomic_unchecked_t cm_nodes_destroyed;
32561 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32562 +extern atomic_unchecked_t cm_resets_recvd;
32563 +extern atomic_unchecked_t pau_qps_created;
32564 +extern atomic_unchecked_t pau_qps_destroyed;
32565
32566 extern u32 int_mod_timer_init;
32567 extern u32 int_mod_cq_depth_256;
32568 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32569 index 020e95c..fbb3450 100644
32570 --- a/drivers/infiniband/hw/nes/nes_cm.c
32571 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32572 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32573 u32 cm_packets_retrans;
32574 u32 cm_packets_created;
32575 u32 cm_packets_received;
32576 -atomic_t cm_listens_created;
32577 -atomic_t cm_listens_destroyed;
32578 +atomic_unchecked_t cm_listens_created;
32579 +atomic_unchecked_t cm_listens_destroyed;
32580 u32 cm_backlog_drops;
32581 -atomic_t cm_loopbacks;
32582 -atomic_t cm_nodes_created;
32583 -atomic_t cm_nodes_destroyed;
32584 -atomic_t cm_accel_dropped_pkts;
32585 -atomic_t cm_resets_recvd;
32586 +atomic_unchecked_t cm_loopbacks;
32587 +atomic_unchecked_t cm_nodes_created;
32588 +atomic_unchecked_t cm_nodes_destroyed;
32589 +atomic_unchecked_t cm_accel_dropped_pkts;
32590 +atomic_unchecked_t cm_resets_recvd;
32591
32592 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32593 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32594 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32595
32596 static struct nes_cm_core *g_cm_core;
32597
32598 -atomic_t cm_connects;
32599 -atomic_t cm_accepts;
32600 -atomic_t cm_disconnects;
32601 -atomic_t cm_closes;
32602 -atomic_t cm_connecteds;
32603 -atomic_t cm_connect_reqs;
32604 -atomic_t cm_rejects;
32605 +atomic_unchecked_t cm_connects;
32606 +atomic_unchecked_t cm_accepts;
32607 +atomic_unchecked_t cm_disconnects;
32608 +atomic_unchecked_t cm_closes;
32609 +atomic_unchecked_t cm_connecteds;
32610 +atomic_unchecked_t cm_connect_reqs;
32611 +atomic_unchecked_t cm_rejects;
32612
32613 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32614 {
32615 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32616 kfree(listener);
32617 listener = NULL;
32618 ret = 0;
32619 - atomic_inc(&cm_listens_destroyed);
32620 + atomic_inc_unchecked(&cm_listens_destroyed);
32621 } else {
32622 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32623 }
32624 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32625 cm_node->rem_mac);
32626
32627 add_hte_node(cm_core, cm_node);
32628 - atomic_inc(&cm_nodes_created);
32629 + atomic_inc_unchecked(&cm_nodes_created);
32630
32631 return cm_node;
32632 }
32633 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32634 }
32635
32636 atomic_dec(&cm_core->node_cnt);
32637 - atomic_inc(&cm_nodes_destroyed);
32638 + atomic_inc_unchecked(&cm_nodes_destroyed);
32639 nesqp = cm_node->nesqp;
32640 if (nesqp) {
32641 nesqp->cm_node = NULL;
32642 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32643
32644 static void drop_packet(struct sk_buff *skb)
32645 {
32646 - atomic_inc(&cm_accel_dropped_pkts);
32647 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32648 dev_kfree_skb_any(skb);
32649 }
32650
32651 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32652 {
32653
32654 int reset = 0; /* whether to send reset in case of err.. */
32655 - atomic_inc(&cm_resets_recvd);
32656 + atomic_inc_unchecked(&cm_resets_recvd);
32657 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32658 " refcnt=%d\n", cm_node, cm_node->state,
32659 atomic_read(&cm_node->ref_count));
32660 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32661 rem_ref_cm_node(cm_node->cm_core, cm_node);
32662 return NULL;
32663 }
32664 - atomic_inc(&cm_loopbacks);
32665 + atomic_inc_unchecked(&cm_loopbacks);
32666 loopbackremotenode->loopbackpartner = cm_node;
32667 loopbackremotenode->tcp_cntxt.rcv_wscale =
32668 NES_CM_DEFAULT_RCV_WND_SCALE;
32669 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32670 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32671 else {
32672 rem_ref_cm_node(cm_core, cm_node);
32673 - atomic_inc(&cm_accel_dropped_pkts);
32674 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32675 dev_kfree_skb_any(skb);
32676 }
32677 break;
32678 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32679
32680 if ((cm_id) && (cm_id->event_handler)) {
32681 if (issue_disconn) {
32682 - atomic_inc(&cm_disconnects);
32683 + atomic_inc_unchecked(&cm_disconnects);
32684 cm_event.event = IW_CM_EVENT_DISCONNECT;
32685 cm_event.status = disconn_status;
32686 cm_event.local_addr = cm_id->local_addr;
32687 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32688 }
32689
32690 if (issue_close) {
32691 - atomic_inc(&cm_closes);
32692 + atomic_inc_unchecked(&cm_closes);
32693 nes_disconnect(nesqp, 1);
32694
32695 cm_id->provider_data = nesqp;
32696 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32697
32698 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32699 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32700 - atomic_inc(&cm_accepts);
32701 + atomic_inc_unchecked(&cm_accepts);
32702
32703 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32704 netdev_refcnt_read(nesvnic->netdev));
32705 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32706 struct nes_cm_core *cm_core;
32707 u8 *start_buff;
32708
32709 - atomic_inc(&cm_rejects);
32710 + atomic_inc_unchecked(&cm_rejects);
32711 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32712 loopback = cm_node->loopbackpartner;
32713 cm_core = cm_node->cm_core;
32714 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32715 ntohl(cm_id->local_addr.sin_addr.s_addr),
32716 ntohs(cm_id->local_addr.sin_port));
32717
32718 - atomic_inc(&cm_connects);
32719 + atomic_inc_unchecked(&cm_connects);
32720 nesqp->active_conn = 1;
32721
32722 /* cache the cm_id in the qp */
32723 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32724 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32725 return err;
32726 }
32727 - atomic_inc(&cm_listens_created);
32728 + atomic_inc_unchecked(&cm_listens_created);
32729 }
32730
32731 cm_id->add_ref(cm_id);
32732 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32733
32734 if (nesqp->destroyed)
32735 return;
32736 - atomic_inc(&cm_connecteds);
32737 + atomic_inc_unchecked(&cm_connecteds);
32738 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32739 " local port 0x%04X. jiffies = %lu.\n",
32740 nesqp->hwqp.qp_id,
32741 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32742
32743 cm_id->add_ref(cm_id);
32744 ret = cm_id->event_handler(cm_id, &cm_event);
32745 - atomic_inc(&cm_closes);
32746 + atomic_inc_unchecked(&cm_closes);
32747 cm_event.event = IW_CM_EVENT_CLOSE;
32748 cm_event.status = 0;
32749 cm_event.provider_data = cm_id->provider_data;
32750 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32751 return;
32752 cm_id = cm_node->cm_id;
32753
32754 - atomic_inc(&cm_connect_reqs);
32755 + atomic_inc_unchecked(&cm_connect_reqs);
32756 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32757 cm_node, cm_id, jiffies);
32758
32759 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32760 return;
32761 cm_id = cm_node->cm_id;
32762
32763 - atomic_inc(&cm_connect_reqs);
32764 + atomic_inc_unchecked(&cm_connect_reqs);
32765 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32766 cm_node, cm_id, jiffies);
32767
32768 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32769 index 3ba7be3..c81f6ff 100644
32770 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32771 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32772 @@ -40,8 +40,8 @@
32773 #include "nes.h"
32774 #include "nes_mgt.h"
32775
32776 -atomic_t pau_qps_created;
32777 -atomic_t pau_qps_destroyed;
32778 +atomic_unchecked_t pau_qps_created;
32779 +atomic_unchecked_t pau_qps_destroyed;
32780
32781 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32782 {
32783 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32784 {
32785 struct sk_buff *skb;
32786 unsigned long flags;
32787 - atomic_inc(&pau_qps_destroyed);
32788 + atomic_inc_unchecked(&pau_qps_destroyed);
32789
32790 /* Free packets that have not yet been forwarded */
32791 /* Lock is acquired by skb_dequeue when removing the skb */
32792 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32793 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32794 skb_queue_head_init(&nesqp->pau_list);
32795 spin_lock_init(&nesqp->pau_lock);
32796 - atomic_inc(&pau_qps_created);
32797 + atomic_inc_unchecked(&pau_qps_created);
32798 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32799 }
32800
32801 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32802 index f3a3ecf..57d311d 100644
32803 --- a/drivers/infiniband/hw/nes/nes_nic.c
32804 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32805 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32806 target_stat_values[++index] = mh_detected;
32807 target_stat_values[++index] = mh_pauses_sent;
32808 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32809 - target_stat_values[++index] = atomic_read(&cm_connects);
32810 - target_stat_values[++index] = atomic_read(&cm_accepts);
32811 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32812 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32813 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32814 - target_stat_values[++index] = atomic_read(&cm_rejects);
32815 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32816 - target_stat_values[++index] = atomic_read(&qps_created);
32817 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32818 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32819 - target_stat_values[++index] = atomic_read(&cm_closes);
32820 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32821 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32822 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32823 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32824 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32825 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32826 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32827 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32828 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32829 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32830 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32831 target_stat_values[++index] = cm_packets_sent;
32832 target_stat_values[++index] = cm_packets_bounced;
32833 target_stat_values[++index] = cm_packets_created;
32834 target_stat_values[++index] = cm_packets_received;
32835 target_stat_values[++index] = cm_packets_dropped;
32836 target_stat_values[++index] = cm_packets_retrans;
32837 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32838 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32839 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32840 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32841 target_stat_values[++index] = cm_backlog_drops;
32842 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32843 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32844 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32845 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32846 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32847 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32848 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32849 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32850 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32851 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32852 target_stat_values[++index] = nesadapter->free_4kpbl;
32853 target_stat_values[++index] = nesadapter->free_256pbl;
32854 target_stat_values[++index] = int_mod_timer_init;
32855 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32856 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32857 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32858 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32859 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32860 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32861 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32862 }
32863
32864 /**
32865 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32866 index 8b8812d..a5e1133 100644
32867 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32868 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32869 @@ -46,9 +46,9 @@
32870
32871 #include <rdma/ib_umem.h>
32872
32873 -atomic_t mod_qp_timouts;
32874 -atomic_t qps_created;
32875 -atomic_t sw_qps_destroyed;
32876 +atomic_unchecked_t mod_qp_timouts;
32877 +atomic_unchecked_t qps_created;
32878 +atomic_unchecked_t sw_qps_destroyed;
32879
32880 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32881
32882 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32883 if (init_attr->create_flags)
32884 return ERR_PTR(-EINVAL);
32885
32886 - atomic_inc(&qps_created);
32887 + atomic_inc_unchecked(&qps_created);
32888 switch (init_attr->qp_type) {
32889 case IB_QPT_RC:
32890 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32891 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32892 struct iw_cm_event cm_event;
32893 int ret = 0;
32894
32895 - atomic_inc(&sw_qps_destroyed);
32896 + atomic_inc_unchecked(&sw_qps_destroyed);
32897 nesqp->destroyed = 1;
32898
32899 /* Blow away the connection if it exists. */
32900 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32901 index 7b1b8669..4b69f85 100644
32902 --- a/drivers/infiniband/hw/qib/qib.h
32903 +++ b/drivers/infiniband/hw/qib/qib.h
32904 @@ -51,6 +51,7 @@
32905 #include <linux/completion.h>
32906 #include <linux/kref.h>
32907 #include <linux/sched.h>
32908 +#include <linux/slab.h>
32909
32910 #include "qib_common.h"
32911 #include "qib_verbs.h"
32912 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32913 index da739d9..da1c7f4 100644
32914 --- a/drivers/input/gameport/gameport.c
32915 +++ b/drivers/input/gameport/gameport.c
32916 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32917 */
32918 static void gameport_init_port(struct gameport *gameport)
32919 {
32920 - static atomic_t gameport_no = ATOMIC_INIT(0);
32921 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32922
32923 __module_get(THIS_MODULE);
32924
32925 mutex_init(&gameport->drv_mutex);
32926 device_initialize(&gameport->dev);
32927 dev_set_name(&gameport->dev, "gameport%lu",
32928 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32929 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32930 gameport->dev.bus = &gameport_bus;
32931 gameport->dev.release = gameport_release_port;
32932 if (gameport->parent)
32933 diff --git a/drivers/input/input.c b/drivers/input/input.c
32934 index 8921c61..f5cd63d 100644
32935 --- a/drivers/input/input.c
32936 +++ b/drivers/input/input.c
32937 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32938 */
32939 int input_register_device(struct input_dev *dev)
32940 {
32941 - static atomic_t input_no = ATOMIC_INIT(0);
32942 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32943 struct input_handler *handler;
32944 const char *path;
32945 int error;
32946 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32947 dev->setkeycode = input_default_setkeycode;
32948
32949 dev_set_name(&dev->dev, "input%ld",
32950 - (unsigned long) atomic_inc_return(&input_no) - 1);
32951 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32952
32953 error = device_add(&dev->dev);
32954 if (error)
32955 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32956 index 04c69af..5f92d00 100644
32957 --- a/drivers/input/joystick/sidewinder.c
32958 +++ b/drivers/input/joystick/sidewinder.c
32959 @@ -30,6 +30,7 @@
32960 #include <linux/kernel.h>
32961 #include <linux/module.h>
32962 #include <linux/slab.h>
32963 +#include <linux/sched.h>
32964 #include <linux/init.h>
32965 #include <linux/input.h>
32966 #include <linux/gameport.h>
32967 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32968 index 83811e4..0822b90 100644
32969 --- a/drivers/input/joystick/xpad.c
32970 +++ b/drivers/input/joystick/xpad.c
32971 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32972
32973 static int xpad_led_probe(struct usb_xpad *xpad)
32974 {
32975 - static atomic_t led_seq = ATOMIC_INIT(0);
32976 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32977 long led_no;
32978 struct xpad_led *led;
32979 struct led_classdev *led_cdev;
32980 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32981 if (!led)
32982 return -ENOMEM;
32983
32984 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32985 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32986
32987 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32988 led->xpad = xpad;
32989 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32990 index 0110b5a..d3ad144 100644
32991 --- a/drivers/input/mousedev.c
32992 +++ b/drivers/input/mousedev.c
32993 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32994
32995 spin_unlock_irq(&client->packet_lock);
32996
32997 - if (copy_to_user(buffer, data, count))
32998 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32999 return -EFAULT;
33000
33001 return count;
33002 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33003 index d0f7533..fb8215b 100644
33004 --- a/drivers/input/serio/serio.c
33005 +++ b/drivers/input/serio/serio.c
33006 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33007 */
33008 static void serio_init_port(struct serio *serio)
33009 {
33010 - static atomic_t serio_no = ATOMIC_INIT(0);
33011 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33012
33013 __module_get(THIS_MODULE);
33014
33015 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33016 mutex_init(&serio->drv_mutex);
33017 device_initialize(&serio->dev);
33018 dev_set_name(&serio->dev, "serio%ld",
33019 - (long)atomic_inc_return(&serio_no) - 1);
33020 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33021 serio->dev.bus = &serio_bus;
33022 serio->dev.release = serio_release_port;
33023 serio->dev.groups = serio_device_attr_groups;
33024 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33025 index 38c4bd8..58965d9 100644
33026 --- a/drivers/isdn/capi/capi.c
33027 +++ b/drivers/isdn/capi/capi.c
33028 @@ -83,8 +83,8 @@ struct capiminor {
33029
33030 struct capi20_appl *ap;
33031 u32 ncci;
33032 - atomic_t datahandle;
33033 - atomic_t msgid;
33034 + atomic_unchecked_t datahandle;
33035 + atomic_unchecked_t msgid;
33036
33037 struct tty_port port;
33038 int ttyinstop;
33039 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33040 capimsg_setu16(s, 2, mp->ap->applid);
33041 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33042 capimsg_setu8 (s, 5, CAPI_RESP);
33043 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33044 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33045 capimsg_setu32(s, 8, mp->ncci);
33046 capimsg_setu16(s, 12, datahandle);
33047 }
33048 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33049 mp->outbytes -= len;
33050 spin_unlock_bh(&mp->outlock);
33051
33052 - datahandle = atomic_inc_return(&mp->datahandle);
33053 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33054 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33055 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33056 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33057 capimsg_setu16(skb->data, 2, mp->ap->applid);
33058 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33059 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33060 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33061 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33062 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33063 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33064 capimsg_setu16(skb->data, 16, len); /* Data length */
33065 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33066 index a6d9fd2..afdb8a3 100644
33067 --- a/drivers/isdn/gigaset/interface.c
33068 +++ b/drivers/isdn/gigaset/interface.c
33069 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33070 }
33071 tty->driver_data = cs;
33072
33073 - ++cs->port.count;
33074 + atomic_inc(&cs->port.count);
33075
33076 - if (cs->port.count == 1) {
33077 + if (atomic_read(&cs->port.count) == 1) {
33078 tty_port_tty_set(&cs->port, tty);
33079 tty->low_latency = 1;
33080 }
33081 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33082
33083 if (!cs->connected)
33084 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33085 - else if (!cs->port.count)
33086 + else if (!atomic_read(&cs->port.count))
33087 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33088 - else if (!--cs->port.count)
33089 + else if (!atomic_dec_return(&cs->port.count))
33090 tty_port_tty_set(&cs->port, NULL);
33091
33092 mutex_unlock(&cs->mutex);
33093 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33094 index 821f7ac..28d4030 100644
33095 --- a/drivers/isdn/hardware/avm/b1.c
33096 +++ b/drivers/isdn/hardware/avm/b1.c
33097 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33098 }
33099 if (left) {
33100 if (t4file->user) {
33101 - if (copy_from_user(buf, dp, left))
33102 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33103 return -EFAULT;
33104 } else {
33105 memcpy(buf, dp, left);
33106 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33107 }
33108 if (left) {
33109 if (config->user) {
33110 - if (copy_from_user(buf, dp, left))
33111 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33112 return -EFAULT;
33113 } else {
33114 memcpy(buf, dp, left);
33115 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33116 index dd6b53a..19d9ee6 100644
33117 --- a/drivers/isdn/hardware/eicon/divasync.h
33118 +++ b/drivers/isdn/hardware/eicon/divasync.h
33119 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33120 } diva_didd_add_adapter_t;
33121 typedef struct _diva_didd_remove_adapter {
33122 IDI_CALL p_request;
33123 -} diva_didd_remove_adapter_t;
33124 +} __no_const diva_didd_remove_adapter_t;
33125 typedef struct _diva_didd_read_adapter_array {
33126 void *buffer;
33127 dword length;
33128 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33129 index d303e65..28bcb7b 100644
33130 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33131 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33132 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33133 typedef struct _diva_os_idi_adapter_interface {
33134 diva_init_card_proc_t cleanup_adapter_proc;
33135 diva_cmd_card_proc_t cmd_proc;
33136 -} diva_os_idi_adapter_interface_t;
33137 +} __no_const diva_os_idi_adapter_interface_t;
33138
33139 typedef struct _diva_os_xdi_adapter {
33140 struct list_head link;
33141 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33142 index 7bc5067..fd36232 100644
33143 --- a/drivers/isdn/i4l/isdn_tty.c
33144 +++ b/drivers/isdn/i4l/isdn_tty.c
33145 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33146 port = &info->port;
33147 #ifdef ISDN_DEBUG_MODEM_OPEN
33148 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33149 - port->count);
33150 + atomic_read(&port->count))
33151 #endif
33152 - port->count++;
33153 + atomic_inc(&port->count);
33154 tty->driver_data = info;
33155 port->tty = tty;
33156 tty->port = port;
33157 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33158 #endif
33159 return;
33160 }
33161 - if ((tty->count == 1) && (port->count != 1)) {
33162 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33163 /*
33164 * Uh, oh. tty->count is 1, which means that the tty
33165 * structure will be freed. Info->count should always
33166 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33167 * serial port won't be shutdown.
33168 */
33169 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33170 - "info->count is %d\n", port->count);
33171 - port->count = 1;
33172 + "info->count is %d\n", atomic_read(&port->count));
33173 + atomic_set(&port->count, 1);
33174 }
33175 - if (--port->count < 0) {
33176 + if (atomic_dec_return(&port->count) < 0) {
33177 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33178 - info->line, port->count);
33179 - port->count = 0;
33180 + info->line, atomic_read(&port->count));
33181 + atomic_set(&port->count, 0);
33182 }
33183 - if (port->count) {
33184 + if (atomic_read(&port->count)) {
33185 #ifdef ISDN_DEBUG_MODEM_OPEN
33186 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33187 #endif
33188 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33189 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33190 return;
33191 isdn_tty_shutdown(info);
33192 - port->count = 0;
33193 + atomic_set(&port->count, 0);
33194 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33195 port->tty = NULL;
33196 wake_up_interruptible(&port->open_wait);
33197 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33198 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33199 modem_info *info = &dev->mdm.info[i];
33200
33201 - if (info->port.count == 0)
33202 + if (atomic_read(&info->port.count) == 0)
33203 continue;
33204 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33205 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33206 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33207 index e74df7c..03a03ba 100644
33208 --- a/drivers/isdn/icn/icn.c
33209 +++ b/drivers/isdn/icn/icn.c
33210 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33211 if (count > len)
33212 count = len;
33213 if (user) {
33214 - if (copy_from_user(msg, buf, count))
33215 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33216 return -EFAULT;
33217 } else
33218 memcpy(msg, buf, count);
33219 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33220 index b5fdcb7..5b6c59f 100644
33221 --- a/drivers/lguest/core.c
33222 +++ b/drivers/lguest/core.c
33223 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33224 * it's worked so far. The end address needs +1 because __get_vm_area
33225 * allocates an extra guard page, so we need space for that.
33226 */
33227 +
33228 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33229 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33230 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33231 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33232 +#else
33233 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33234 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33235 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33236 +#endif
33237 +
33238 if (!switcher_vma) {
33239 err = -ENOMEM;
33240 printk("lguest: could not map switcher pages high\n");
33241 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33242 * Now the Switcher is mapped at the right address, we can't fail!
33243 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33244 */
33245 - memcpy(switcher_vma->addr, start_switcher_text,
33246 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33247 end_switcher_text - start_switcher_text);
33248
33249 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33250 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33251 index 39809035..ce25c5e 100644
33252 --- a/drivers/lguest/x86/core.c
33253 +++ b/drivers/lguest/x86/core.c
33254 @@ -59,7 +59,7 @@ static struct {
33255 /* Offset from where switcher.S was compiled to where we've copied it */
33256 static unsigned long switcher_offset(void)
33257 {
33258 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33259 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33260 }
33261
33262 /* This cpu's struct lguest_pages. */
33263 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33264 * These copies are pretty cheap, so we do them unconditionally: */
33265 /* Save the current Host top-level page directory.
33266 */
33267 +
33268 +#ifdef CONFIG_PAX_PER_CPU_PGD
33269 + pages->state.host_cr3 = read_cr3();
33270 +#else
33271 pages->state.host_cr3 = __pa(current->mm->pgd);
33272 +#endif
33273 +
33274 /*
33275 * Set up the Guest's page tables to see this CPU's pages (and no
33276 * other CPU's pages).
33277 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33278 * compiled-in switcher code and the high-mapped copy we just made.
33279 */
33280 for (i = 0; i < IDT_ENTRIES; i++)
33281 - default_idt_entries[i] += switcher_offset();
33282 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33283
33284 /*
33285 * Set up the Switcher's per-cpu areas.
33286 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33287 * it will be undisturbed when we switch. To change %cs and jump we
33288 * need this structure to feed to Intel's "lcall" instruction.
33289 */
33290 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33291 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33292 lguest_entry.segment = LGUEST_CS;
33293
33294 /*
33295 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33296 index 40634b0..4f5855e 100644
33297 --- a/drivers/lguest/x86/switcher_32.S
33298 +++ b/drivers/lguest/x86/switcher_32.S
33299 @@ -87,6 +87,7 @@
33300 #include <asm/page.h>
33301 #include <asm/segment.h>
33302 #include <asm/lguest.h>
33303 +#include <asm/processor-flags.h>
33304
33305 // We mark the start of the code to copy
33306 // It's placed in .text tho it's never run here
33307 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33308 // Changes type when we load it: damn Intel!
33309 // For after we switch over our page tables
33310 // That entry will be read-only: we'd crash.
33311 +
33312 +#ifdef CONFIG_PAX_KERNEXEC
33313 + mov %cr0, %edx
33314 + xor $X86_CR0_WP, %edx
33315 + mov %edx, %cr0
33316 +#endif
33317 +
33318 movl $(GDT_ENTRY_TSS*8), %edx
33319 ltr %dx
33320
33321 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33322 // Let's clear it again for our return.
33323 // The GDT descriptor of the Host
33324 // Points to the table after two "size" bytes
33325 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33326 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33327 // Clear "used" from type field (byte 5, bit 2)
33328 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33329 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33330 +
33331 +#ifdef CONFIG_PAX_KERNEXEC
33332 + mov %cr0, %eax
33333 + xor $X86_CR0_WP, %eax
33334 + mov %eax, %cr0
33335 +#endif
33336
33337 // Once our page table's switched, the Guest is live!
33338 // The Host fades as we run this final step.
33339 @@ -295,13 +309,12 @@ deliver_to_host:
33340 // I consulted gcc, and it gave
33341 // These instructions, which I gladly credit:
33342 leal (%edx,%ebx,8), %eax
33343 - movzwl (%eax),%edx
33344 - movl 4(%eax), %eax
33345 - xorw %ax, %ax
33346 - orl %eax, %edx
33347 + movl 4(%eax), %edx
33348 + movw (%eax), %dx
33349 // Now the address of the handler's in %edx
33350 // We call it now: its "iret" drops us home.
33351 - jmp *%edx
33352 + ljmp $__KERNEL_CS, $1f
33353 +1: jmp *%edx
33354
33355 // Every interrupt can come to us here
33356 // But we must truly tell each apart.
33357 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33358 index 20e5c2c..9e849a9 100644
33359 --- a/drivers/macintosh/macio_asic.c
33360 +++ b/drivers/macintosh/macio_asic.c
33361 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33362 * MacIO is matched against any Apple ID, it's probe() function
33363 * will then decide wether it applies or not
33364 */
33365 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33366 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33367 .vendor = PCI_VENDOR_ID_APPLE,
33368 .device = PCI_ANY_ID,
33369 .subvendor = PCI_ANY_ID,
33370 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33371 index 94e7f6b..2f4a0d8 100644
33372 --- a/drivers/md/bitmap.c
33373 +++ b/drivers/md/bitmap.c
33374 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33375 chunk_kb ? "KB" : "B");
33376 if (bitmap->storage.file) {
33377 seq_printf(seq, ", file: ");
33378 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33379 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33380 }
33381
33382 seq_printf(seq, "\n");
33383 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33384 index afd9598..528d8f9 100644
33385 --- a/drivers/md/dm-ioctl.c
33386 +++ b/drivers/md/dm-ioctl.c
33387 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33388 cmd == DM_LIST_VERSIONS_CMD)
33389 return 0;
33390
33391 - if ((cmd == DM_DEV_CREATE_CMD)) {
33392 + if (cmd == DM_DEV_CREATE_CMD) {
33393 if (!*param->name) {
33394 DMWARN("name not supplied when creating device");
33395 return -EINVAL;
33396 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33397 index bc5ddba8..b961159 100644
33398 --- a/drivers/md/dm-raid1.c
33399 +++ b/drivers/md/dm-raid1.c
33400 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33401
33402 struct mirror {
33403 struct mirror_set *ms;
33404 - atomic_t error_count;
33405 + atomic_unchecked_t error_count;
33406 unsigned long error_type;
33407 struct dm_dev *dev;
33408 sector_t offset;
33409 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33410 struct mirror *m;
33411
33412 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33413 - if (!atomic_read(&m->error_count))
33414 + if (!atomic_read_unchecked(&m->error_count))
33415 return m;
33416
33417 return NULL;
33418 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33419 * simple way to tell if a device has encountered
33420 * errors.
33421 */
33422 - atomic_inc(&m->error_count);
33423 + atomic_inc_unchecked(&m->error_count);
33424
33425 if (test_and_set_bit(error_type, &m->error_type))
33426 return;
33427 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33428 struct mirror *m = get_default_mirror(ms);
33429
33430 do {
33431 - if (likely(!atomic_read(&m->error_count)))
33432 + if (likely(!atomic_read_unchecked(&m->error_count)))
33433 return m;
33434
33435 if (m-- == ms->mirror)
33436 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33437 {
33438 struct mirror *default_mirror = get_default_mirror(m->ms);
33439
33440 - return !atomic_read(&default_mirror->error_count);
33441 + return !atomic_read_unchecked(&default_mirror->error_count);
33442 }
33443
33444 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33445 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33446 */
33447 if (likely(region_in_sync(ms, region, 1)))
33448 m = choose_mirror(ms, bio->bi_sector);
33449 - else if (m && atomic_read(&m->error_count))
33450 + else if (m && atomic_read_unchecked(&m->error_count))
33451 m = NULL;
33452
33453 if (likely(m))
33454 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33455 }
33456
33457 ms->mirror[mirror].ms = ms;
33458 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33459 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33460 ms->mirror[mirror].error_type = 0;
33461 ms->mirror[mirror].offset = offset;
33462
33463 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33464 */
33465 static char device_status_char(struct mirror *m)
33466 {
33467 - if (!atomic_read(&(m->error_count)))
33468 + if (!atomic_read_unchecked(&(m->error_count)))
33469 return 'A';
33470
33471 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33472 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33473 index a087bf2..4c94786 100644
33474 --- a/drivers/md/dm-stripe.c
33475 +++ b/drivers/md/dm-stripe.c
33476 @@ -20,7 +20,7 @@ struct stripe {
33477 struct dm_dev *dev;
33478 sector_t physical_start;
33479
33480 - atomic_t error_count;
33481 + atomic_unchecked_t error_count;
33482 };
33483
33484 struct stripe_c {
33485 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33486 kfree(sc);
33487 return r;
33488 }
33489 - atomic_set(&(sc->stripe[i].error_count), 0);
33490 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33491 }
33492
33493 ti->private = sc;
33494 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33495 DMEMIT("%d ", sc->stripes);
33496 for (i = 0; i < sc->stripes; i++) {
33497 DMEMIT("%s ", sc->stripe[i].dev->name);
33498 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33499 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33500 'D' : 'A';
33501 }
33502 buffer[i] = '\0';
33503 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33504 */
33505 for (i = 0; i < sc->stripes; i++)
33506 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33507 - atomic_inc(&(sc->stripe[i].error_count));
33508 - if (atomic_read(&(sc->stripe[i].error_count)) <
33509 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33510 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33511 DM_IO_ERROR_THRESHOLD)
33512 schedule_work(&sc->trigger_event);
33513 }
33514 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33515 index 100368e..64262ce 100644
33516 --- a/drivers/md/dm-table.c
33517 +++ b/drivers/md/dm-table.c
33518 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33519 if (!dev_size)
33520 return 0;
33521
33522 - if ((start >= dev_size) || (start + len > dev_size)) {
33523 + if ((start >= dev_size) || (len > dev_size - start)) {
33524 DMWARN("%s: %s too small for target: "
33525 "start=%llu, len=%llu, dev_size=%llu",
33526 dm_device_name(ti->table->md), bdevname(bdev, b),
33527 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33528 index 693e149..b7e0fde 100644
33529 --- a/drivers/md/dm-thin-metadata.c
33530 +++ b/drivers/md/dm-thin-metadata.c
33531 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33532 {
33533 pmd->info.tm = pmd->tm;
33534 pmd->info.levels = 2;
33535 - pmd->info.value_type.context = pmd->data_sm;
33536 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33537 pmd->info.value_type.size = sizeof(__le64);
33538 pmd->info.value_type.inc = data_block_inc;
33539 pmd->info.value_type.dec = data_block_dec;
33540 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33541
33542 pmd->bl_info.tm = pmd->tm;
33543 pmd->bl_info.levels = 1;
33544 - pmd->bl_info.value_type.context = pmd->data_sm;
33545 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33546 pmd->bl_info.value_type.size = sizeof(__le64);
33547 pmd->bl_info.value_type.inc = data_block_inc;
33548 pmd->bl_info.value_type.dec = data_block_dec;
33549 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33550 index 67ffa39..cb3b1dd 100644
33551 --- a/drivers/md/dm.c
33552 +++ b/drivers/md/dm.c
33553 @@ -176,9 +176,9 @@ struct mapped_device {
33554 /*
33555 * Event handling.
33556 */
33557 - atomic_t event_nr;
33558 + atomic_unchecked_t event_nr;
33559 wait_queue_head_t eventq;
33560 - atomic_t uevent_seq;
33561 + atomic_unchecked_t uevent_seq;
33562 struct list_head uevent_list;
33563 spinlock_t uevent_lock; /* Protect access to uevent_list */
33564
33565 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33566 rwlock_init(&md->map_lock);
33567 atomic_set(&md->holders, 1);
33568 atomic_set(&md->open_count, 0);
33569 - atomic_set(&md->event_nr, 0);
33570 - atomic_set(&md->uevent_seq, 0);
33571 + atomic_set_unchecked(&md->event_nr, 0);
33572 + atomic_set_unchecked(&md->uevent_seq, 0);
33573 INIT_LIST_HEAD(&md->uevent_list);
33574 spin_lock_init(&md->uevent_lock);
33575
33576 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33577
33578 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33579
33580 - atomic_inc(&md->event_nr);
33581 + atomic_inc_unchecked(&md->event_nr);
33582 wake_up(&md->eventq);
33583 }
33584
33585 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33586
33587 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33588 {
33589 - return atomic_add_return(1, &md->uevent_seq);
33590 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33591 }
33592
33593 uint32_t dm_get_event_nr(struct mapped_device *md)
33594 {
33595 - return atomic_read(&md->event_nr);
33596 + return atomic_read_unchecked(&md->event_nr);
33597 }
33598
33599 int dm_wait_event(struct mapped_device *md, int event_nr)
33600 {
33601 return wait_event_interruptible(md->eventq,
33602 - (event_nr != atomic_read(&md->event_nr)));
33603 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33604 }
33605
33606 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33607 diff --git a/drivers/md/md.c b/drivers/md/md.c
33608 index 308e87b..7f365d6 100644
33609 --- a/drivers/md/md.c
33610 +++ b/drivers/md/md.c
33611 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33612 * start build, activate spare
33613 */
33614 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33615 -static atomic_t md_event_count;
33616 +static atomic_unchecked_t md_event_count;
33617 void md_new_event(struct mddev *mddev)
33618 {
33619 - atomic_inc(&md_event_count);
33620 + atomic_inc_unchecked(&md_event_count);
33621 wake_up(&md_event_waiters);
33622 }
33623 EXPORT_SYMBOL_GPL(md_new_event);
33624 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33625 */
33626 static void md_new_event_inintr(struct mddev *mddev)
33627 {
33628 - atomic_inc(&md_event_count);
33629 + atomic_inc_unchecked(&md_event_count);
33630 wake_up(&md_event_waiters);
33631 }
33632
33633 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33634 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33635 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33636 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33637 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33638 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33639
33640 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33641 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33642 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33643 else
33644 sb->resync_offset = cpu_to_le64(0);
33645
33646 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33647 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33648
33649 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33650 sb->size = cpu_to_le64(mddev->dev_sectors);
33651 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33652 static ssize_t
33653 errors_show(struct md_rdev *rdev, char *page)
33654 {
33655 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33656 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33657 }
33658
33659 static ssize_t
33660 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33661 char *e;
33662 unsigned long n = simple_strtoul(buf, &e, 10);
33663 if (*buf && (*e == 0 || *e == '\n')) {
33664 - atomic_set(&rdev->corrected_errors, n);
33665 + atomic_set_unchecked(&rdev->corrected_errors, n);
33666 return len;
33667 }
33668 return -EINVAL;
33669 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33670 rdev->sb_loaded = 0;
33671 rdev->bb_page = NULL;
33672 atomic_set(&rdev->nr_pending, 0);
33673 - atomic_set(&rdev->read_errors, 0);
33674 - atomic_set(&rdev->corrected_errors, 0);
33675 + atomic_set_unchecked(&rdev->read_errors, 0);
33676 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33677
33678 INIT_LIST_HEAD(&rdev->same_set);
33679 init_waitqueue_head(&rdev->blocked_wait);
33680 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33681
33682 spin_unlock(&pers_lock);
33683 seq_printf(seq, "\n");
33684 - seq->poll_event = atomic_read(&md_event_count);
33685 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33686 return 0;
33687 }
33688 if (v == (void*)2) {
33689 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33690 return error;
33691
33692 seq = file->private_data;
33693 - seq->poll_event = atomic_read(&md_event_count);
33694 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33695 return error;
33696 }
33697
33698 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33699 /* always allow read */
33700 mask = POLLIN | POLLRDNORM;
33701
33702 - if (seq->poll_event != atomic_read(&md_event_count))
33703 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33704 mask |= POLLERR | POLLPRI;
33705 return mask;
33706 }
33707 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33708 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33709 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33710 (int)part_stat_read(&disk->part0, sectors[1]) -
33711 - atomic_read(&disk->sync_io);
33712 + atomic_read_unchecked(&disk->sync_io);
33713 /* sync IO will cause sync_io to increase before the disk_stats
33714 * as sync_io is counted when a request starts, and
33715 * disk_stats is counted when it completes.
33716 diff --git a/drivers/md/md.h b/drivers/md/md.h
33717 index f385b03..b600be8 100644
33718 --- a/drivers/md/md.h
33719 +++ b/drivers/md/md.h
33720 @@ -94,13 +94,13 @@ struct md_rdev {
33721 * only maintained for arrays that
33722 * support hot removal
33723 */
33724 - atomic_t read_errors; /* number of consecutive read errors that
33725 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33726 * we have tried to ignore.
33727 */
33728 struct timespec last_read_error; /* monotonic time since our
33729 * last read error
33730 */
33731 - atomic_t corrected_errors; /* number of corrected read errors,
33732 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33733 * for reporting to userspace and storing
33734 * in superblock.
33735 */
33736 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33737
33738 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33739 {
33740 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33741 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33742 }
33743
33744 struct md_personality
33745 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33746 index f6d29e6..7917f5e 100644
33747 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33748 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33749 @@ -22,7 +22,7 @@
33750 * Space map interface.
33751 */
33752 struct sm_disk {
33753 - struct dm_space_map sm;
33754 + dm_space_map_no_const sm;
33755
33756 struct ll_disk ll;
33757 struct ll_disk old_ll;
33758 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33759 index e89ae5e..062e4c2 100644
33760 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33761 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33762 @@ -43,7 +43,7 @@ struct block_op {
33763 };
33764
33765 struct sm_metadata {
33766 - struct dm_space_map sm;
33767 + dm_space_map_no_const sm;
33768
33769 struct ll_disk ll;
33770 struct ll_disk old_ll;
33771 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33772 index 1cbfc6b..56e1dbb 100644
33773 --- a/drivers/md/persistent-data/dm-space-map.h
33774 +++ b/drivers/md/persistent-data/dm-space-map.h
33775 @@ -60,6 +60,7 @@ struct dm_space_map {
33776 int (*root_size)(struct dm_space_map *sm, size_t *result);
33777 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33778 };
33779 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33780
33781 /*----------------------------------------------------------------*/
33782
33783 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33784 index 611b5f7..cee0bfb 100644
33785 --- a/drivers/md/raid1.c
33786 +++ b/drivers/md/raid1.c
33787 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33788 if (r1_sync_page_io(rdev, sect, s,
33789 bio->bi_io_vec[idx].bv_page,
33790 READ) != 0)
33791 - atomic_add(s, &rdev->corrected_errors);
33792 + atomic_add_unchecked(s, &rdev->corrected_errors);
33793 }
33794 sectors -= s;
33795 sect += s;
33796 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33797 test_bit(In_sync, &rdev->flags)) {
33798 if (r1_sync_page_io(rdev, sect, s,
33799 conf->tmppage, READ)) {
33800 - atomic_add(s, &rdev->corrected_errors);
33801 + atomic_add_unchecked(s, &rdev->corrected_errors);
33802 printk(KERN_INFO
33803 "md/raid1:%s: read error corrected "
33804 "(%d sectors at %llu on %s)\n",
33805 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33806 index a48c215..6bda6f4 100644
33807 --- a/drivers/md/raid10.c
33808 +++ b/drivers/md/raid10.c
33809 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33810 /* The write handler will notice the lack of
33811 * R10BIO_Uptodate and record any errors etc
33812 */
33813 - atomic_add(r10_bio->sectors,
33814 + atomic_add_unchecked(r10_bio->sectors,
33815 &conf->mirrors[d].rdev->corrected_errors);
33816
33817 /* for reconstruct, we always reschedule after a read.
33818 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33819 {
33820 struct timespec cur_time_mon;
33821 unsigned long hours_since_last;
33822 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33823 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33824
33825 ktime_get_ts(&cur_time_mon);
33826
33827 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33828 * overflowing the shift of read_errors by hours_since_last.
33829 */
33830 if (hours_since_last >= 8 * sizeof(read_errors))
33831 - atomic_set(&rdev->read_errors, 0);
33832 + atomic_set_unchecked(&rdev->read_errors, 0);
33833 else
33834 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33835 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33836 }
33837
33838 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33839 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33840 return;
33841
33842 check_decay_read_errors(mddev, rdev);
33843 - atomic_inc(&rdev->read_errors);
33844 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33845 + atomic_inc_unchecked(&rdev->read_errors);
33846 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33847 char b[BDEVNAME_SIZE];
33848 bdevname(rdev->bdev, b);
33849
33850 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33851 "md/raid10:%s: %s: Raid device exceeded "
33852 "read_error threshold [cur %d:max %d]\n",
33853 mdname(mddev), b,
33854 - atomic_read(&rdev->read_errors), max_read_errors);
33855 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33856 printk(KERN_NOTICE
33857 "md/raid10:%s: %s: Failing raid device\n",
33858 mdname(mddev), b);
33859 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33860 sect +
33861 choose_data_offset(r10_bio, rdev)),
33862 bdevname(rdev->bdev, b));
33863 - atomic_add(s, &rdev->corrected_errors);
33864 + atomic_add_unchecked(s, &rdev->corrected_errors);
33865 }
33866
33867 rdev_dec_pending(rdev, mddev);
33868 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33869 index 0689173..35df76c 100644
33870 --- a/drivers/md/raid5.c
33871 +++ b/drivers/md/raid5.c
33872 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33873 mdname(conf->mddev), STRIPE_SECTORS,
33874 (unsigned long long)s,
33875 bdevname(rdev->bdev, b));
33876 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33877 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33878 clear_bit(R5_ReadError, &sh->dev[i].flags);
33879 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33880 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33881 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33882
33883 - if (atomic_read(&rdev->read_errors))
33884 - atomic_set(&rdev->read_errors, 0);
33885 + if (atomic_read_unchecked(&rdev->read_errors))
33886 + atomic_set_unchecked(&rdev->read_errors, 0);
33887 } else {
33888 const char *bdn = bdevname(rdev->bdev, b);
33889 int retry = 0;
33890 int set_bad = 0;
33891
33892 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33893 - atomic_inc(&rdev->read_errors);
33894 + atomic_inc_unchecked(&rdev->read_errors);
33895 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33896 printk_ratelimited(
33897 KERN_WARNING
33898 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33899 mdname(conf->mddev),
33900 (unsigned long long)s,
33901 bdn);
33902 - } else if (atomic_read(&rdev->read_errors)
33903 + } else if (atomic_read_unchecked(&rdev->read_errors)
33904 > conf->max_nr_stripes)
33905 printk(KERN_WARNING
33906 "md/raid:%s: Too many read errors, failing device %s.\n",
33907 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33908 index ebf3f05..b1f3e77 100644
33909 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33910 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33911 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33912 .subvendor = _subvend, .subdevice = _subdev, \
33913 .driver_data = (unsigned long)&_driverdata }
33914
33915 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33916 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33917 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33918 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33919 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33920 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33921 index fa7188a..04a045e 100644
33922 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33923 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33924 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33925 union {
33926 dmx_ts_cb ts;
33927 dmx_section_cb sec;
33928 - } cb;
33929 + } __no_const cb;
33930
33931 struct dvb_demux *demux;
33932 void *priv;
33933 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33934 index 39eab73..60033e7 100644
33935 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33936 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33937 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33938 const struct dvb_device *template, void *priv, int type)
33939 {
33940 struct dvb_device *dvbdev;
33941 - struct file_operations *dvbdevfops;
33942 + file_operations_no_const *dvbdevfops;
33943 struct device *clsdev;
33944 int minor;
33945 int id;
33946 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33947 index 3940bb0..fb3952a 100644
33948 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33949 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33950 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33951
33952 struct dib0700_adapter_state {
33953 int (*set_param_save) (struct dvb_frontend *);
33954 -};
33955 +} __no_const;
33956
33957 static int dib7070_set_param_override(struct dvb_frontend *fe)
33958 {
33959 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33960 index 9382895..ac8093c 100644
33961 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33962 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33963 @@ -95,7 +95,7 @@ struct su3000_state {
33964
33965 struct s6x0_state {
33966 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33967 -};
33968 +} __no_const;
33969
33970 /* debug */
33971 static int dvb_usb_dw2102_debug;
33972 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33973 index 404f63a..4796533 100644
33974 --- a/drivers/media/dvb/frontends/dib3000.h
33975 +++ b/drivers/media/dvb/frontends/dib3000.h
33976 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33977 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33978 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33979 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33980 -};
33981 +} __no_const;
33982
33983 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33984 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33985 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33986 index 72ee8de..eae0c80 100644
33987 --- a/drivers/media/dvb/ngene/ngene-cards.c
33988 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33989 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
33990
33991 /****************************************************************************/
33992
33993 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33994 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33995 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33996 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33997 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33998 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33999 index 697a421..16c5a5f 100644
34000 --- a/drivers/media/radio/radio-cadet.c
34001 +++ b/drivers/media/radio/radio-cadet.c
34002 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34003 unsigned char readbuf[RDS_BUFFER];
34004 int i = 0;
34005
34006 + if (count > RDS_BUFFER)
34007 + return -EFAULT;
34008 mutex_lock(&dev->lock);
34009 if (dev->rdsstat == 0)
34010 cadet_start_rds(dev);
34011 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34012 while (i < count && dev->rdsin != dev->rdsout)
34013 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34014
34015 - if (i && copy_to_user(data, readbuf, i))
34016 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34017 i = -EFAULT;
34018 unlock:
34019 mutex_unlock(&dev->lock);
34020 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34021 index 55cbd78..428b0da 100644
34022 --- a/drivers/media/radio/radio-tea5777.h
34023 +++ b/drivers/media/radio/radio-tea5777.h
34024 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34025
34026 struct radio_tea5777 {
34027 struct v4l2_device *v4l2_dev;
34028 - struct v4l2_file_operations fops;
34029 + v4l2_file_operations_no_const fops;
34030 struct video_device vd; /* video device */
34031 bool has_am; /* Device can tune to AM freqs */
34032 bool write_before_read; /* must write before read quirk */
34033 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34034 index 9cde353..8c6a1c3 100644
34035 --- a/drivers/media/video/au0828/au0828.h
34036 +++ b/drivers/media/video/au0828/au0828.h
34037 @@ -191,7 +191,7 @@ struct au0828_dev {
34038
34039 /* I2C */
34040 struct i2c_adapter i2c_adap;
34041 - struct i2c_algorithm i2c_algo;
34042 + i2c_algorithm_no_const i2c_algo;
34043 struct i2c_client i2c_client;
34044 u32 i2c_rc;
34045
34046 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34047 index dfac6e3..c26de31 100644
34048 --- a/drivers/media/video/cx88/cx88-alsa.c
34049 +++ b/drivers/media/video/cx88/cx88-alsa.c
34050 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34051 * Only boards with eeprom and byte 1 at eeprom=1 have it
34052 */
34053
34054 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34055 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34056 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34057 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34058 {0, }
34059 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34060 index 88cf9d9..bbc4b2c 100644
34061 --- a/drivers/media/video/omap/omap_vout.c
34062 +++ b/drivers/media/video/omap/omap_vout.c
34063 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34064 OMAP_VIDEO2,
34065 };
34066
34067 -static struct videobuf_queue_ops video_vbq_ops;
34068 /* Variables configurable through module params*/
34069 static u32 video1_numbuffers = 3;
34070 static u32 video2_numbuffers = 3;
34071 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34072 {
34073 struct videobuf_queue *q;
34074 struct omap_vout_device *vout = NULL;
34075 + static struct videobuf_queue_ops video_vbq_ops = {
34076 + .buf_setup = omap_vout_buffer_setup,
34077 + .buf_prepare = omap_vout_buffer_prepare,
34078 + .buf_release = omap_vout_buffer_release,
34079 + .buf_queue = omap_vout_buffer_queue,
34080 + };
34081
34082 vout = video_drvdata(file);
34083 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34084 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34085 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34086
34087 q = &vout->vbq;
34088 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34089 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34090 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34091 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34092 spin_lock_init(&vout->vbq_lock);
34093
34094 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34095 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34096 index 036952f..80d356d 100644
34097 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34098 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34099 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34100
34101 /* I2C stuff */
34102 struct i2c_adapter i2c_adap;
34103 - struct i2c_algorithm i2c_algo;
34104 + i2c_algorithm_no_const i2c_algo;
34105 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34106 int i2c_cx25840_hack_state;
34107 int i2c_linked;
34108 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34109 index 02194c0..091733b 100644
34110 --- a/drivers/media/video/timblogiw.c
34111 +++ b/drivers/media/video/timblogiw.c
34112 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34113
34114 /* Platform device functions */
34115
34116 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34117 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34118 .vidioc_querycap = timblogiw_querycap,
34119 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34120 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34121 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34122 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34123 };
34124
34125 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34126 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34127 .owner = THIS_MODULE,
34128 .open = timblogiw_open,
34129 .release = timblogiw_close,
34130 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34131 index d99db56..a16b959 100644
34132 --- a/drivers/message/fusion/mptbase.c
34133 +++ b/drivers/message/fusion/mptbase.c
34134 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34135 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34136 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34137
34138 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34139 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34140 +#else
34141 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34142 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34143 +#endif
34144 +
34145 /*
34146 * Rounding UP to nearest 4-kB boundary here...
34147 */
34148 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34149 index 551262e..7551198 100644
34150 --- a/drivers/message/fusion/mptsas.c
34151 +++ b/drivers/message/fusion/mptsas.c
34152 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34153 return 0;
34154 }
34155
34156 +static inline void
34157 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34158 +{
34159 + if (phy_info->port_details) {
34160 + phy_info->port_details->rphy = rphy;
34161 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34162 + ioc->name, rphy));
34163 + }
34164 +
34165 + if (rphy) {
34166 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34167 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34168 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34169 + ioc->name, rphy, rphy->dev.release));
34170 + }
34171 +}
34172 +
34173 /* no mutex */
34174 static void
34175 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34176 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34177 return NULL;
34178 }
34179
34180 -static inline void
34181 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34182 -{
34183 - if (phy_info->port_details) {
34184 - phy_info->port_details->rphy = rphy;
34185 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34186 - ioc->name, rphy));
34187 - }
34188 -
34189 - if (rphy) {
34190 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34191 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34192 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34193 - ioc->name, rphy, rphy->dev.release));
34194 - }
34195 -}
34196 -
34197 static inline struct sas_port *
34198 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34199 {
34200 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34201 index 0c3ced7..1fe34ec 100644
34202 --- a/drivers/message/fusion/mptscsih.c
34203 +++ b/drivers/message/fusion/mptscsih.c
34204 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34205
34206 h = shost_priv(SChost);
34207
34208 - if (h) {
34209 - if (h->info_kbuf == NULL)
34210 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34211 - return h->info_kbuf;
34212 - h->info_kbuf[0] = '\0';
34213 + if (!h)
34214 + return NULL;
34215
34216 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34217 - h->info_kbuf[size-1] = '\0';
34218 - }
34219 + if (h->info_kbuf == NULL)
34220 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34221 + return h->info_kbuf;
34222 + h->info_kbuf[0] = '\0';
34223 +
34224 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34225 + h->info_kbuf[size-1] = '\0';
34226
34227 return h->info_kbuf;
34228 }
34229 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34230 index 8001aa6..b137580 100644
34231 --- a/drivers/message/i2o/i2o_proc.c
34232 +++ b/drivers/message/i2o/i2o_proc.c
34233 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34234 "Array Controller Device"
34235 };
34236
34237 -static char *chtostr(char *tmp, u8 *chars, int n)
34238 -{
34239 - tmp[0] = 0;
34240 - return strncat(tmp, (char *)chars, n);
34241 -}
34242 -
34243 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34244 char *group)
34245 {
34246 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34247 } *result;
34248
34249 i2o_exec_execute_ddm_table ddm_table;
34250 - char tmp[28 + 1];
34251
34252 result = kmalloc(sizeof(*result), GFP_KERNEL);
34253 if (!result)
34254 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34255
34256 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34257 seq_printf(seq, "%-#8x", ddm_table.module_id);
34258 - seq_printf(seq, "%-29s",
34259 - chtostr(tmp, ddm_table.module_name_version, 28));
34260 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34261 seq_printf(seq, "%9d ", ddm_table.data_size);
34262 seq_printf(seq, "%8d", ddm_table.code_size);
34263
34264 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34265
34266 i2o_driver_result_table *result;
34267 i2o_driver_store_table *dst;
34268 - char tmp[28 + 1];
34269
34270 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34271 if (result == NULL)
34272 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34273
34274 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34275 seq_printf(seq, "%-#8x", dst->module_id);
34276 - seq_printf(seq, "%-29s",
34277 - chtostr(tmp, dst->module_name_version, 28));
34278 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34279 + seq_printf(seq, "%-.28s", dst->module_name_version);
34280 + seq_printf(seq, "%-.8s", dst->date);
34281 seq_printf(seq, "%8d ", dst->module_size);
34282 seq_printf(seq, "%8d ", dst->mpb_size);
34283 seq_printf(seq, "0x%04x", dst->module_flags);
34284 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34285 // == (allow) 512d bytes (max)
34286 static u16 *work16 = (u16 *) work32;
34287 int token;
34288 - char tmp[16 + 1];
34289
34290 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34291
34292 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34293 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34294 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34295 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34296 - seq_printf(seq, "Vendor info : %s\n",
34297 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34298 - seq_printf(seq, "Product info : %s\n",
34299 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34300 - seq_printf(seq, "Description : %s\n",
34301 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34302 - seq_printf(seq, "Product rev. : %s\n",
34303 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34304 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34305 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34306 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34307 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34308
34309 seq_printf(seq, "Serial number : ");
34310 print_serial_number(seq, (u8 *) (work32 + 16),
34311 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34312 u8 pad[256]; // allow up to 256 byte (max) serial number
34313 } result;
34314
34315 - char tmp[24 + 1];
34316 -
34317 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34318
34319 if (token < 0) {
34320 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34321 }
34322
34323 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34324 - seq_printf(seq, "Module name : %s\n",
34325 - chtostr(tmp, result.module_name, 24));
34326 - seq_printf(seq, "Module revision : %s\n",
34327 - chtostr(tmp, result.module_rev, 8));
34328 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34329 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34330
34331 seq_printf(seq, "Serial number : ");
34332 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34333 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34334 u8 instance_number[4];
34335 } result;
34336
34337 - char tmp[64 + 1];
34338 -
34339 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34340
34341 if (token < 0) {
34342 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34343 return 0;
34344 }
34345
34346 - seq_printf(seq, "Device name : %s\n",
34347 - chtostr(tmp, result.device_name, 64));
34348 - seq_printf(seq, "Service name : %s\n",
34349 - chtostr(tmp, result.service_name, 64));
34350 - seq_printf(seq, "Physical name : %s\n",
34351 - chtostr(tmp, result.physical_location, 64));
34352 - seq_printf(seq, "Instance number : %s\n",
34353 - chtostr(tmp, result.instance_number, 4));
34354 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34355 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34356 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34357 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34358
34359 return 0;
34360 }
34361 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34362 index a8c08f3..155fe3d 100644
34363 --- a/drivers/message/i2o/iop.c
34364 +++ b/drivers/message/i2o/iop.c
34365 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34366
34367 spin_lock_irqsave(&c->context_list_lock, flags);
34368
34369 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34370 - atomic_inc(&c->context_list_counter);
34371 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34372 + atomic_inc_unchecked(&c->context_list_counter);
34373
34374 - entry->context = atomic_read(&c->context_list_counter);
34375 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34376
34377 list_add(&entry->list, &c->context_list);
34378
34379 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34380
34381 #if BITS_PER_LONG == 64
34382 spin_lock_init(&c->context_list_lock);
34383 - atomic_set(&c->context_list_counter, 0);
34384 + atomic_set_unchecked(&c->context_list_counter, 0);
34385 INIT_LIST_HEAD(&c->context_list);
34386 #endif
34387
34388 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34389 index 7ce65f4..e66e9bc 100644
34390 --- a/drivers/mfd/abx500-core.c
34391 +++ b/drivers/mfd/abx500-core.c
34392 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34393
34394 struct abx500_device_entry {
34395 struct list_head list;
34396 - struct abx500_ops ops;
34397 + abx500_ops_no_const ops;
34398 struct device *dev;
34399 };
34400
34401 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34402 index 965c480..71f2db9 100644
34403 --- a/drivers/mfd/janz-cmodio.c
34404 +++ b/drivers/mfd/janz-cmodio.c
34405 @@ -13,6 +13,7 @@
34406
34407 #include <linux/kernel.h>
34408 #include <linux/module.h>
34409 +#include <linux/slab.h>
34410 #include <linux/init.h>
34411 #include <linux/pci.h>
34412 #include <linux/interrupt.h>
34413 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34414 index a981e2a..5ca0c8b 100644
34415 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34416 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34417 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34418 * the lid is closed. This leads to interrupts as soon as a little move
34419 * is done.
34420 */
34421 - atomic_inc(&lis3->count);
34422 + atomic_inc_unchecked(&lis3->count);
34423
34424 wake_up_interruptible(&lis3->misc_wait);
34425 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34426 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34427 if (lis3->pm_dev)
34428 pm_runtime_get_sync(lis3->pm_dev);
34429
34430 - atomic_set(&lis3->count, 0);
34431 + atomic_set_unchecked(&lis3->count, 0);
34432 return 0;
34433 }
34434
34435 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34436 add_wait_queue(&lis3->misc_wait, &wait);
34437 while (true) {
34438 set_current_state(TASK_INTERRUPTIBLE);
34439 - data = atomic_xchg(&lis3->count, 0);
34440 + data = atomic_xchg_unchecked(&lis3->count, 0);
34441 if (data)
34442 break;
34443
34444 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34445 struct lis3lv02d, miscdev);
34446
34447 poll_wait(file, &lis3->misc_wait, wait);
34448 - if (atomic_read(&lis3->count))
34449 + if (atomic_read_unchecked(&lis3->count))
34450 return POLLIN | POLLRDNORM;
34451 return 0;
34452 }
34453 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34454 index 2b1482a..5d33616 100644
34455 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34456 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34457 @@ -266,7 +266,7 @@ struct lis3lv02d {
34458 struct input_polled_dev *idev; /* input device */
34459 struct platform_device *pdev; /* platform device */
34460 struct regulator_bulk_data regulators[2];
34461 - atomic_t count; /* interrupt count after last read */
34462 + atomic_unchecked_t count; /* interrupt count after last read */
34463 union axis_conversion ac; /* hw -> logical axis */
34464 int mapped_btns[3];
34465
34466 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34467 index 2f30bad..c4c13d0 100644
34468 --- a/drivers/misc/sgi-gru/gruhandles.c
34469 +++ b/drivers/misc/sgi-gru/gruhandles.c
34470 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34471 unsigned long nsec;
34472
34473 nsec = CLKS2NSEC(clks);
34474 - atomic_long_inc(&mcs_op_statistics[op].count);
34475 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34476 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34477 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34478 if (mcs_op_statistics[op].max < nsec)
34479 mcs_op_statistics[op].max = nsec;
34480 }
34481 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34482 index 950dbe9..eeef0f8 100644
34483 --- a/drivers/misc/sgi-gru/gruprocfs.c
34484 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34485 @@ -32,9 +32,9 @@
34486
34487 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34488
34489 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34490 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34491 {
34492 - unsigned long val = atomic_long_read(v);
34493 + unsigned long val = atomic_long_read_unchecked(v);
34494
34495 seq_printf(s, "%16lu %s\n", val, id);
34496 }
34497 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34498
34499 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34500 for (op = 0; op < mcsop_last; op++) {
34501 - count = atomic_long_read(&mcs_op_statistics[op].count);
34502 - total = atomic_long_read(&mcs_op_statistics[op].total);
34503 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34504 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34505 max = mcs_op_statistics[op].max;
34506 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34507 count ? total / count : 0, max);
34508 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34509 index 5c3ce24..4915ccb 100644
34510 --- a/drivers/misc/sgi-gru/grutables.h
34511 +++ b/drivers/misc/sgi-gru/grutables.h
34512 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34513 * GRU statistics.
34514 */
34515 struct gru_stats_s {
34516 - atomic_long_t vdata_alloc;
34517 - atomic_long_t vdata_free;
34518 - atomic_long_t gts_alloc;
34519 - atomic_long_t gts_free;
34520 - atomic_long_t gms_alloc;
34521 - atomic_long_t gms_free;
34522 - atomic_long_t gts_double_allocate;
34523 - atomic_long_t assign_context;
34524 - atomic_long_t assign_context_failed;
34525 - atomic_long_t free_context;
34526 - atomic_long_t load_user_context;
34527 - atomic_long_t load_kernel_context;
34528 - atomic_long_t lock_kernel_context;
34529 - atomic_long_t unlock_kernel_context;
34530 - atomic_long_t steal_user_context;
34531 - atomic_long_t steal_kernel_context;
34532 - atomic_long_t steal_context_failed;
34533 - atomic_long_t nopfn;
34534 - atomic_long_t asid_new;
34535 - atomic_long_t asid_next;
34536 - atomic_long_t asid_wrap;
34537 - atomic_long_t asid_reuse;
34538 - atomic_long_t intr;
34539 - atomic_long_t intr_cbr;
34540 - atomic_long_t intr_tfh;
34541 - atomic_long_t intr_spurious;
34542 - atomic_long_t intr_mm_lock_failed;
34543 - atomic_long_t call_os;
34544 - atomic_long_t call_os_wait_queue;
34545 - atomic_long_t user_flush_tlb;
34546 - atomic_long_t user_unload_context;
34547 - atomic_long_t user_exception;
34548 - atomic_long_t set_context_option;
34549 - atomic_long_t check_context_retarget_intr;
34550 - atomic_long_t check_context_unload;
34551 - atomic_long_t tlb_dropin;
34552 - atomic_long_t tlb_preload_page;
34553 - atomic_long_t tlb_dropin_fail_no_asid;
34554 - atomic_long_t tlb_dropin_fail_upm;
34555 - atomic_long_t tlb_dropin_fail_invalid;
34556 - atomic_long_t tlb_dropin_fail_range_active;
34557 - atomic_long_t tlb_dropin_fail_idle;
34558 - atomic_long_t tlb_dropin_fail_fmm;
34559 - atomic_long_t tlb_dropin_fail_no_exception;
34560 - atomic_long_t tfh_stale_on_fault;
34561 - atomic_long_t mmu_invalidate_range;
34562 - atomic_long_t mmu_invalidate_page;
34563 - atomic_long_t flush_tlb;
34564 - atomic_long_t flush_tlb_gru;
34565 - atomic_long_t flush_tlb_gru_tgh;
34566 - atomic_long_t flush_tlb_gru_zero_asid;
34567 + atomic_long_unchecked_t vdata_alloc;
34568 + atomic_long_unchecked_t vdata_free;
34569 + atomic_long_unchecked_t gts_alloc;
34570 + atomic_long_unchecked_t gts_free;
34571 + atomic_long_unchecked_t gms_alloc;
34572 + atomic_long_unchecked_t gms_free;
34573 + atomic_long_unchecked_t gts_double_allocate;
34574 + atomic_long_unchecked_t assign_context;
34575 + atomic_long_unchecked_t assign_context_failed;
34576 + atomic_long_unchecked_t free_context;
34577 + atomic_long_unchecked_t load_user_context;
34578 + atomic_long_unchecked_t load_kernel_context;
34579 + atomic_long_unchecked_t lock_kernel_context;
34580 + atomic_long_unchecked_t unlock_kernel_context;
34581 + atomic_long_unchecked_t steal_user_context;
34582 + atomic_long_unchecked_t steal_kernel_context;
34583 + atomic_long_unchecked_t steal_context_failed;
34584 + atomic_long_unchecked_t nopfn;
34585 + atomic_long_unchecked_t asid_new;
34586 + atomic_long_unchecked_t asid_next;
34587 + atomic_long_unchecked_t asid_wrap;
34588 + atomic_long_unchecked_t asid_reuse;
34589 + atomic_long_unchecked_t intr;
34590 + atomic_long_unchecked_t intr_cbr;
34591 + atomic_long_unchecked_t intr_tfh;
34592 + atomic_long_unchecked_t intr_spurious;
34593 + atomic_long_unchecked_t intr_mm_lock_failed;
34594 + atomic_long_unchecked_t call_os;
34595 + atomic_long_unchecked_t call_os_wait_queue;
34596 + atomic_long_unchecked_t user_flush_tlb;
34597 + atomic_long_unchecked_t user_unload_context;
34598 + atomic_long_unchecked_t user_exception;
34599 + atomic_long_unchecked_t set_context_option;
34600 + atomic_long_unchecked_t check_context_retarget_intr;
34601 + atomic_long_unchecked_t check_context_unload;
34602 + atomic_long_unchecked_t tlb_dropin;
34603 + atomic_long_unchecked_t tlb_preload_page;
34604 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34605 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34606 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34607 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34608 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34609 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34610 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34611 + atomic_long_unchecked_t tfh_stale_on_fault;
34612 + atomic_long_unchecked_t mmu_invalidate_range;
34613 + atomic_long_unchecked_t mmu_invalidate_page;
34614 + atomic_long_unchecked_t flush_tlb;
34615 + atomic_long_unchecked_t flush_tlb_gru;
34616 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34617 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34618
34619 - atomic_long_t copy_gpa;
34620 - atomic_long_t read_gpa;
34621 + atomic_long_unchecked_t copy_gpa;
34622 + atomic_long_unchecked_t read_gpa;
34623
34624 - atomic_long_t mesq_receive;
34625 - atomic_long_t mesq_receive_none;
34626 - atomic_long_t mesq_send;
34627 - atomic_long_t mesq_send_failed;
34628 - atomic_long_t mesq_noop;
34629 - atomic_long_t mesq_send_unexpected_error;
34630 - atomic_long_t mesq_send_lb_overflow;
34631 - atomic_long_t mesq_send_qlimit_reached;
34632 - atomic_long_t mesq_send_amo_nacked;
34633 - atomic_long_t mesq_send_put_nacked;
34634 - atomic_long_t mesq_page_overflow;
34635 - atomic_long_t mesq_qf_locked;
34636 - atomic_long_t mesq_qf_noop_not_full;
34637 - atomic_long_t mesq_qf_switch_head_failed;
34638 - atomic_long_t mesq_qf_unexpected_error;
34639 - atomic_long_t mesq_noop_unexpected_error;
34640 - atomic_long_t mesq_noop_lb_overflow;
34641 - atomic_long_t mesq_noop_qlimit_reached;
34642 - atomic_long_t mesq_noop_amo_nacked;
34643 - atomic_long_t mesq_noop_put_nacked;
34644 - atomic_long_t mesq_noop_page_overflow;
34645 + atomic_long_unchecked_t mesq_receive;
34646 + atomic_long_unchecked_t mesq_receive_none;
34647 + atomic_long_unchecked_t mesq_send;
34648 + atomic_long_unchecked_t mesq_send_failed;
34649 + atomic_long_unchecked_t mesq_noop;
34650 + atomic_long_unchecked_t mesq_send_unexpected_error;
34651 + atomic_long_unchecked_t mesq_send_lb_overflow;
34652 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34653 + atomic_long_unchecked_t mesq_send_amo_nacked;
34654 + atomic_long_unchecked_t mesq_send_put_nacked;
34655 + atomic_long_unchecked_t mesq_page_overflow;
34656 + atomic_long_unchecked_t mesq_qf_locked;
34657 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34658 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34659 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34660 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34661 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34662 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34663 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34664 + atomic_long_unchecked_t mesq_noop_put_nacked;
34665 + atomic_long_unchecked_t mesq_noop_page_overflow;
34666
34667 };
34668
34669 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34670 tghop_invalidate, mcsop_last};
34671
34672 struct mcs_op_statistic {
34673 - atomic_long_t count;
34674 - atomic_long_t total;
34675 + atomic_long_unchecked_t count;
34676 + atomic_long_unchecked_t total;
34677 unsigned long max;
34678 };
34679
34680 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34681
34682 #define STAT(id) do { \
34683 if (gru_options & OPT_STATS) \
34684 - atomic_long_inc(&gru_stats.id); \
34685 + atomic_long_inc_unchecked(&gru_stats.id); \
34686 } while (0)
34687
34688 #ifdef CONFIG_SGI_GRU_DEBUG
34689 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34690 index c862cd4..0d176fe 100644
34691 --- a/drivers/misc/sgi-xp/xp.h
34692 +++ b/drivers/misc/sgi-xp/xp.h
34693 @@ -288,7 +288,7 @@ struct xpc_interface {
34694 xpc_notify_func, void *);
34695 void (*received) (short, int, void *);
34696 enum xp_retval (*partid_to_nasids) (short, void *);
34697 -};
34698 +} __no_const;
34699
34700 extern struct xpc_interface xpc_interface;
34701
34702 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34703 index b94d5f7..7f494c5 100644
34704 --- a/drivers/misc/sgi-xp/xpc.h
34705 +++ b/drivers/misc/sgi-xp/xpc.h
34706 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34707 void (*received_payload) (struct xpc_channel *, void *);
34708 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34709 };
34710 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34711
34712 /* struct xpc_partition act_state values (for XPC HB) */
34713
34714 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34715 /* found in xpc_main.c */
34716 extern struct device *xpc_part;
34717 extern struct device *xpc_chan;
34718 -extern struct xpc_arch_operations xpc_arch_ops;
34719 +extern xpc_arch_operations_no_const xpc_arch_ops;
34720 extern int xpc_disengage_timelimit;
34721 extern int xpc_disengage_timedout;
34722 extern int xpc_activate_IRQ_rcvd;
34723 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34724 index 8d082b4..aa749ae 100644
34725 --- a/drivers/misc/sgi-xp/xpc_main.c
34726 +++ b/drivers/misc/sgi-xp/xpc_main.c
34727 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34728 .notifier_call = xpc_system_die,
34729 };
34730
34731 -struct xpc_arch_operations xpc_arch_ops;
34732 +xpc_arch_operations_no_const xpc_arch_ops;
34733
34734 /*
34735 * Timer function to enforce the timelimit on the partition disengage.
34736 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34737 index 504da71..9722d43 100644
34738 --- a/drivers/mmc/host/sdhci-pci.c
34739 +++ b/drivers/mmc/host/sdhci-pci.c
34740 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34741 .probe = via_probe,
34742 };
34743
34744 -static const struct pci_device_id pci_ids[] __devinitdata = {
34745 +static const struct pci_device_id pci_ids[] __devinitconst = {
34746 {
34747 .vendor = PCI_VENDOR_ID_RICOH,
34748 .device = PCI_DEVICE_ID_RICOH_R5C822,
34749 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34750 index a4eb8b5..8c0628f 100644
34751 --- a/drivers/mtd/devices/doc2000.c
34752 +++ b/drivers/mtd/devices/doc2000.c
34753 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34754
34755 /* The ECC will not be calculated correctly if less than 512 is written */
34756 /* DBB-
34757 - if (len != 0x200 && eccbuf)
34758 + if (len != 0x200)
34759 printk(KERN_WARNING
34760 "ECC needs a full sector write (adr: %lx size %lx)\n",
34761 (long) to, (long) len);
34762 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34763 index 0650aaf..7718762 100644
34764 --- a/drivers/mtd/nand/denali.c
34765 +++ b/drivers/mtd/nand/denali.c
34766 @@ -26,6 +26,7 @@
34767 #include <linux/pci.h>
34768 #include <linux/mtd/mtd.h>
34769 #include <linux/module.h>
34770 +#include <linux/slab.h>
34771
34772 #include "denali.h"
34773
34774 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34775 index 51b9d6a..52af9a7 100644
34776 --- a/drivers/mtd/nftlmount.c
34777 +++ b/drivers/mtd/nftlmount.c
34778 @@ -24,6 +24,7 @@
34779 #include <asm/errno.h>
34780 #include <linux/delay.h>
34781 #include <linux/slab.h>
34782 +#include <linux/sched.h>
34783 #include <linux/mtd/mtd.h>
34784 #include <linux/mtd/nand.h>
34785 #include <linux/mtd/nftl.h>
34786 diff --git a/drivers/net/bonding/bond_sysfs.c b/drivers/net/bonding/bond_sysfs.c
34787 index dc15d24..ef8d2a0 100644
34788 --- a/drivers/net/bonding/bond_sysfs.c
34789 +++ b/drivers/net/bonding/bond_sysfs.c
34790 @@ -1060,7 +1060,7 @@ static ssize_t bonding_store_primary(struct device *d,
34791 goto out;
34792 }
34793
34794 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34795 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34796
34797 /* check to see if we are clearing primary */
34798 if (!strlen(ifname) || buf[0] == '\n') {
34799 @@ -1237,7 +1237,7 @@ static ssize_t bonding_store_active_slave(struct device *d,
34800 goto out;
34801 }
34802
34803 - sscanf(buf, "%16s", ifname); /* IFNAMSIZ */
34804 + sscanf(buf, "%15s", ifname); /* IFNAMSIZ */
34805
34806 /* check to see if we are clearing active */
34807 if (!strlen(ifname) || buf[0] == '\n') {
34808 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34809 index 57d64b8..623dd86 100644
34810 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34811 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34812 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34813 */
34814
34815 #define ATL2_PARAM(X, desc) \
34816 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34817 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34818 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34819 MODULE_PARM_DESC(X, desc);
34820 #else
34821 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34822 index 0875ecf..794cdf3 100644
34823 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34824 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
34825 @@ -3051,9 +3051,8 @@ static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
34826 struct eth_stats_info *ether_stat =
34827 &bp->slowpath->drv_info_to_mcp.ether_stat;
34828
34829 - /* leave last char as NULL */
34830 - memcpy(ether_stat->version, DRV_MODULE_VERSION,
34831 - ETH_STAT_INFO_VERSION_LEN - 1);
34832 + strlcpy(ether_stat->version, DRV_MODULE_VERSION,
34833 + ETH_STAT_INFO_VERSION_LEN);
34834
34835 bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
34836 DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
34837 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34838 index f83e033..8b4f43a 100644
34839 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34840 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34841 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34842
34843 int (*wait_comp)(struct bnx2x *bp,
34844 struct bnx2x_rx_mode_ramrod_params *p);
34845 -};
34846 +} __no_const;
34847
34848 /********************** Set multicast group ***********************************/
34849
34850 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34851 index 6d52cb2..bc95640 100644
34852 --- a/drivers/net/ethernet/broadcom/tg3.h
34853 +++ b/drivers/net/ethernet/broadcom/tg3.h
34854 @@ -140,6 +140,7 @@
34855 #define CHIPREV_ID_5750_A0 0x4000
34856 #define CHIPREV_ID_5750_A1 0x4001
34857 #define CHIPREV_ID_5750_A3 0x4003
34858 +#define CHIPREV_ID_5750_C1 0x4201
34859 #define CHIPREV_ID_5750_C2 0x4202
34860 #define CHIPREV_ID_5752_A0_HW 0x5000
34861 #define CHIPREV_ID_5752_A0 0x6000
34862 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34863 index 8cffcdf..aadf043 100644
34864 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34865 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34866 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34867 */
34868 struct l2t_skb_cb {
34869 arp_failure_handler_func arp_failure_handler;
34870 -};
34871 +} __no_const;
34872
34873 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34874
34875 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34876 index f879e92..726f20f 100644
34877 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34878 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34879 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34880 for (i=0; i<ETH_ALEN; i++) {
34881 tmp.addr[i] = dev->dev_addr[i];
34882 }
34883 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34884 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34885 break;
34886
34887 case DE4X5_SET_HWADDR: /* Set the hardware address */
34888 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34889 spin_lock_irqsave(&lp->lock, flags);
34890 memcpy(&statbuf, &lp->pktStats, ioc->len);
34891 spin_unlock_irqrestore(&lp->lock, flags);
34892 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34893 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34894 return -EFAULT;
34895 break;
34896 }
34897 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34898 index ed7d1dc..d426748 100644
34899 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34900 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34901 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34902 {NULL}};
34903
34904
34905 -static const char *block_name[] __devinitdata = {
34906 +static const char *block_name[] __devinitconst = {
34907 "21140 non-MII",
34908 "21140 MII PHY",
34909 "21142 Serial PHY",
34910 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34911 index 75d45f8..3d9c55b 100644
34912 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34913 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34914 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34915 struct uli_phy_ops {
34916 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34917 u16 (*read)(struct uli526x_board_info *, u8, u8);
34918 - } phy;
34919 + } __no_const phy;
34920 struct net_device *next_dev; /* next device */
34921 struct pci_dev *pdev; /* PCI device */
34922 spinlock_t lock;
34923 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34924 index 4d1ffca..7c1ec4d 100644
34925 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34926 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34927 @@ -236,7 +236,7 @@ struct pci_id_info {
34928 int drv_flags; /* Driver use, intended as capability flags. */
34929 };
34930
34931 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34932 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34933 { /* Sometime a Level-One switch card. */
34934 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34935 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34936 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34937 index d7bb52a..3b83588 100644
34938 --- a/drivers/net/ethernet/dlink/sundance.c
34939 +++ b/drivers/net/ethernet/dlink/sundance.c
34940 @@ -218,7 +218,7 @@ enum {
34941 struct pci_id_info {
34942 const char *name;
34943 };
34944 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34945 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34946 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34947 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34948 {"D-Link DFE-580TX 4 port Server Adapter"},
34949 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34950 index 78b8aa8..dd6323a 100644
34951 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34952 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34953 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34954
34955 if (wrapped)
34956 newacc += 65536;
34957 - ACCESS_ONCE(*acc) = newacc;
34958 + ACCESS_ONCE_RW(*acc) = newacc;
34959 }
34960
34961 void be_parse_stats(struct be_adapter *adapter)
34962 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34963 index 74d749e..eefb1bd 100644
34964 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34965 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34966 @@ -31,6 +31,8 @@
34967 #include <linux/netdevice.h>
34968 #include <linux/phy.h>
34969 #include <linux/platform_device.h>
34970 +#include <linux/interrupt.h>
34971 +#include <linux/irqreturn.h>
34972 #include <net/ip.h>
34973
34974 #include "ftgmac100.h"
34975 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34976 index b901a01..1ff32ee 100644
34977 --- a/drivers/net/ethernet/faraday/ftmac100.c
34978 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34979 @@ -31,6 +31,8 @@
34980 #include <linux/module.h>
34981 #include <linux/netdevice.h>
34982 #include <linux/platform_device.h>
34983 +#include <linux/interrupt.h>
34984 +#include <linux/irqreturn.h>
34985
34986 #include "ftmac100.h"
34987
34988 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34989 index 9d71c9c..0e4a0ac 100644
34990 --- a/drivers/net/ethernet/fealnx.c
34991 +++ b/drivers/net/ethernet/fealnx.c
34992 @@ -150,7 +150,7 @@ struct chip_info {
34993 int flags;
34994 };
34995
34996 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34997 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34998 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34999 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35000 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35001 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35002 index ed5b409..ec37828 100644
35003 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35004 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35005 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35006 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35007 s32 (*read_mac_addr)(struct e1000_hw *);
35008 };
35009 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35010
35011 /*
35012 * When to use various PHY register access functions:
35013 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35014 void (*power_up)(struct e1000_hw *);
35015 void (*power_down)(struct e1000_hw *);
35016 };
35017 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35018
35019 /* Function pointers for the NVM. */
35020 struct e1000_nvm_operations {
35021 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35022 s32 (*validate)(struct e1000_hw *);
35023 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35024 };
35025 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35026
35027 struct e1000_mac_info {
35028 - struct e1000_mac_operations ops;
35029 + e1000_mac_operations_no_const ops;
35030 u8 addr[ETH_ALEN];
35031 u8 perm_addr[ETH_ALEN];
35032
35033 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35034 };
35035
35036 struct e1000_phy_info {
35037 - struct e1000_phy_operations ops;
35038 + e1000_phy_operations_no_const ops;
35039
35040 enum e1000_phy_type type;
35041
35042 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35043 };
35044
35045 struct e1000_nvm_info {
35046 - struct e1000_nvm_operations ops;
35047 + e1000_nvm_operations_no_const ops;
35048
35049 enum e1000_nvm_type type;
35050 enum e1000_nvm_override override;
35051 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35052 index c2a51dc..c2bd262 100644
35053 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35054 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35055 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35056 void (*release_swfw_sync)(struct e1000_hw *, u16);
35057
35058 };
35059 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35060
35061 struct e1000_phy_operations {
35062 s32 (*acquire)(struct e1000_hw *);
35063 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35064 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35065 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35066 };
35067 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35068
35069 struct e1000_nvm_operations {
35070 s32 (*acquire)(struct e1000_hw *);
35071 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35072 s32 (*validate)(struct e1000_hw *);
35073 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35074 };
35075 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35076
35077 struct e1000_info {
35078 s32 (*get_invariants)(struct e1000_hw *);
35079 @@ -364,7 +367,7 @@ struct e1000_info {
35080 extern const struct e1000_info e1000_82575_info;
35081
35082 struct e1000_mac_info {
35083 - struct e1000_mac_operations ops;
35084 + e1000_mac_operations_no_const ops;
35085
35086 u8 addr[6];
35087 u8 perm_addr[6];
35088 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35089 };
35090
35091 struct e1000_phy_info {
35092 - struct e1000_phy_operations ops;
35093 + e1000_phy_operations_no_const ops;
35094
35095 enum e1000_phy_type type;
35096
35097 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35098 };
35099
35100 struct e1000_nvm_info {
35101 - struct e1000_nvm_operations ops;
35102 + e1000_nvm_operations_no_const ops;
35103 enum e1000_nvm_type type;
35104 enum e1000_nvm_override override;
35105
35106 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35107 s32 (*check_for_ack)(struct e1000_hw *, u16);
35108 s32 (*check_for_rst)(struct e1000_hw *, u16);
35109 };
35110 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35111
35112 struct e1000_mbx_stats {
35113 u32 msgs_tx;
35114 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35115 };
35116
35117 struct e1000_mbx_info {
35118 - struct e1000_mbx_operations ops;
35119 + e1000_mbx_operations_no_const ops;
35120 struct e1000_mbx_stats stats;
35121 u32 timeout;
35122 u32 usec_delay;
35123 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35124 index 57db3c6..aa825fc 100644
35125 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35126 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35127 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35128 s32 (*read_mac_addr)(struct e1000_hw *);
35129 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35130 };
35131 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35132
35133 struct e1000_mac_info {
35134 - struct e1000_mac_operations ops;
35135 + e1000_mac_operations_no_const ops;
35136 u8 addr[6];
35137 u8 perm_addr[6];
35138
35139 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35140 s32 (*check_for_ack)(struct e1000_hw *);
35141 s32 (*check_for_rst)(struct e1000_hw *);
35142 };
35143 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35144
35145 struct e1000_mbx_stats {
35146 u32 msgs_tx;
35147 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35148 };
35149
35150 struct e1000_mbx_info {
35151 - struct e1000_mbx_operations ops;
35152 + e1000_mbx_operations_no_const ops;
35153 struct e1000_mbx_stats stats;
35154 u32 timeout;
35155 u32 usec_delay;
35156 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35157 index 3456d56..b688d81 100644
35158 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35159 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35160 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35161 /* store the new cycle speed */
35162 adapter->cycle_speed = cycle_speed;
35163
35164 - ACCESS_ONCE(adapter->base_incval) = incval;
35165 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35166 smp_mb();
35167
35168 /* grab the ptp lock */
35169 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35170 index 400f86a..7f2e062 100644
35171 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35172 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35173 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35174 s32 (*update_checksum)(struct ixgbe_hw *);
35175 u16 (*calc_checksum)(struct ixgbe_hw *);
35176 };
35177 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35178
35179 struct ixgbe_mac_operations {
35180 s32 (*init_hw)(struct ixgbe_hw *);
35181 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35182 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35183 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35184 };
35185 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35186
35187 struct ixgbe_phy_operations {
35188 s32 (*identify)(struct ixgbe_hw *);
35189 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35190 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35191 s32 (*check_overtemp)(struct ixgbe_hw *);
35192 };
35193 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35194
35195 struct ixgbe_eeprom_info {
35196 - struct ixgbe_eeprom_operations ops;
35197 + ixgbe_eeprom_operations_no_const ops;
35198 enum ixgbe_eeprom_type type;
35199 u32 semaphore_delay;
35200 u16 word_size;
35201 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35202
35203 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35204 struct ixgbe_mac_info {
35205 - struct ixgbe_mac_operations ops;
35206 + ixgbe_mac_operations_no_const ops;
35207 enum ixgbe_mac_type type;
35208 u8 addr[ETH_ALEN];
35209 u8 perm_addr[ETH_ALEN];
35210 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35211 };
35212
35213 struct ixgbe_phy_info {
35214 - struct ixgbe_phy_operations ops;
35215 + ixgbe_phy_operations_no_const ops;
35216 struct mdio_if_info mdio;
35217 enum ixgbe_phy_type type;
35218 u32 id;
35219 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35220 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35221 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35222 };
35223 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35224
35225 struct ixgbe_mbx_stats {
35226 u32 msgs_tx;
35227 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35228 };
35229
35230 struct ixgbe_mbx_info {
35231 - struct ixgbe_mbx_operations ops;
35232 + ixgbe_mbx_operations_no_const ops;
35233 struct ixgbe_mbx_stats stats;
35234 u32 timeout;
35235 u32 usec_delay;
35236 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35237 index 25c951d..cc7cf33 100644
35238 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35239 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35240 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35241 s32 (*clear_vfta)(struct ixgbe_hw *);
35242 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35243 };
35244 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35245
35246 enum ixgbe_mac_type {
35247 ixgbe_mac_unknown = 0,
35248 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35249 };
35250
35251 struct ixgbe_mac_info {
35252 - struct ixgbe_mac_operations ops;
35253 + ixgbe_mac_operations_no_const ops;
35254 u8 addr[6];
35255 u8 perm_addr[6];
35256
35257 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35258 s32 (*check_for_ack)(struct ixgbe_hw *);
35259 s32 (*check_for_rst)(struct ixgbe_hw *);
35260 };
35261 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35262
35263 struct ixgbe_mbx_stats {
35264 u32 msgs_tx;
35265 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35266 };
35267
35268 struct ixgbe_mbx_info {
35269 - struct ixgbe_mbx_operations ops;
35270 + ixgbe_mbx_operations_no_const ops;
35271 struct ixgbe_mbx_stats stats;
35272 u32 timeout;
35273 u32 udelay;
35274 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35275 index 9e0c1ee..8471f77 100644
35276 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35277 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35278 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35279 void (*link_down)(struct __vxge_hw_device *devh);
35280 void (*crit_err)(struct __vxge_hw_device *devh,
35281 enum vxge_hw_event type, u64 ext_data);
35282 -};
35283 +} __no_const;
35284
35285 /*
35286 * struct __vxge_hw_blockpool_entry - Block private data structure
35287 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35288 index 4a518a3..936b334 100644
35289 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35290 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35291 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35292 struct vxge_hw_mempool_dma *dma_object,
35293 u32 index,
35294 u32 is_last);
35295 -};
35296 +} __no_const;
35297
35298 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35299 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35300 diff --git a/drivers/net/ethernet/nxp/lpc_eth.c b/drivers/net/ethernet/nxp/lpc_eth.c
35301 index 53743f7..af8b414 100644
35302 --- a/drivers/net/ethernet/nxp/lpc_eth.c
35303 +++ b/drivers/net/ethernet/nxp/lpc_eth.c
35304 @@ -1524,6 +1524,7 @@ static int lpc_eth_drv_remove(struct platform_device *pdev)
35305 pldat->dma_buff_base_p);
35306 free_irq(ndev->irq, ndev);
35307 iounmap(pldat->net_base);
35308 + mdiobus_unregister(pldat->mii_bus);
35309 mdiobus_free(pldat->mii_bus);
35310 clk_disable(pldat->clk);
35311 clk_put(pldat->clk);
35312 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35313 index b47d5b3..273a516 100644
35314 --- a/drivers/net/ethernet/realtek/r8169.c
35315 +++ b/drivers/net/ethernet/realtek/r8169.c
35316 @@ -745,22 +745,22 @@ struct rtl8169_private {
35317 struct mdio_ops {
35318 void (*write)(struct rtl8169_private *, int, int);
35319 int (*read)(struct rtl8169_private *, int);
35320 - } mdio_ops;
35321 + } __no_const mdio_ops;
35322
35323 struct pll_power_ops {
35324 void (*down)(struct rtl8169_private *);
35325 void (*up)(struct rtl8169_private *);
35326 - } pll_power_ops;
35327 + } __no_const pll_power_ops;
35328
35329 struct jumbo_ops {
35330 void (*enable)(struct rtl8169_private *);
35331 void (*disable)(struct rtl8169_private *);
35332 - } jumbo_ops;
35333 + } __no_const jumbo_ops;
35334
35335 struct csi_ops {
35336 void (*write)(struct rtl8169_private *, int, int);
35337 u32 (*read)(struct rtl8169_private *, int);
35338 - } csi_ops;
35339 + } __no_const csi_ops;
35340
35341 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35342 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35343 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35344 index 4613591..d816601 100644
35345 --- a/drivers/net/ethernet/sis/sis190.c
35346 +++ b/drivers/net/ethernet/sis/sis190.c
35347 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35348 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35349 struct net_device *dev)
35350 {
35351 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35352 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35353 struct sis190_private *tp = netdev_priv(dev);
35354 struct pci_dev *isa_bridge;
35355 u8 reg, tmp8;
35356 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35357 index 0c74a70..3bc6f68 100644
35358 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35359 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35360 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35361
35362 writel(value, ioaddr + MMC_CNTRL);
35363
35364 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35365 - MMC_CNTRL, value);
35366 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35367 +// MMC_CNTRL, value);
35368 }
35369
35370 /* To mask all all interrupts.*/
35371 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35372 index 95ceb35..318fc12 100644
35373 --- a/drivers/net/hyperv/hyperv_net.h
35374 +++ b/drivers/net/hyperv/hyperv_net.h
35375 @@ -99,7 +99,7 @@ struct rndis_device {
35376
35377 enum rndis_device_state state;
35378 bool link_state;
35379 - atomic_t new_req_id;
35380 + atomic_unchecked_t new_req_id;
35381
35382 spinlock_t request_lock;
35383 struct list_head req_list;
35384 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35385 index 1e88a10..1b01736 100644
35386 --- a/drivers/net/hyperv/rndis_filter.c
35387 +++ b/drivers/net/hyperv/rndis_filter.c
35388 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35389 * template
35390 */
35391 set = &rndis_msg->msg.set_req;
35392 - set->req_id = atomic_inc_return(&dev->new_req_id);
35393 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35394
35395 /* Add to the request list */
35396 spin_lock_irqsave(&dev->request_lock, flags);
35397 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35398
35399 /* Setup the rndis set */
35400 halt = &request->request_msg.msg.halt_req;
35401 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35402 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35403
35404 /* Ignore return since this msg is optional. */
35405 rndis_filter_send_request(dev, request);
35406 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
35407 index daec9b0..6428fcb 100644
35408 --- a/drivers/net/phy/mdio-bitbang.c
35409 +++ b/drivers/net/phy/mdio-bitbang.c
35410 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
35411 struct mdiobb_ctrl *ctrl = bus->priv;
35412
35413 module_put(ctrl->ops->owner);
35414 + mdiobus_unregister(bus);
35415 mdiobus_free(bus);
35416 }
35417 EXPORT_SYMBOL(free_mdio_bitbang);
35418 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35419 index 5c05572..389610b 100644
35420 --- a/drivers/net/ppp/ppp_generic.c
35421 +++ b/drivers/net/ppp/ppp_generic.c
35422 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35423 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35424 struct ppp_stats stats;
35425 struct ppp_comp_stats cstats;
35426 - char *vers;
35427
35428 switch (cmd) {
35429 case SIOCGPPPSTATS:
35430 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35431 break;
35432
35433 case SIOCGPPPVER:
35434 - vers = PPP_VERSION;
35435 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35436 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35437 break;
35438 err = 0;
35439 break;
35440 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35441 index 3a16d4f..a311cec 100644
35442 --- a/drivers/net/tun.c
35443 +++ b/drivers/net/tun.c
35444 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35445 }
35446
35447 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35448 - unsigned long arg, int ifreq_len)
35449 + unsigned long arg, size_t ifreq_len)
35450 {
35451 struct tun_file *tfile = file->private_data;
35452 struct tun_struct *tun;
35453 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35454 int vnet_hdr_sz;
35455 int ret;
35456
35457 + if (ifreq_len > sizeof ifr)
35458 + return -EFAULT;
35459 +
35460 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35461 if (copy_from_user(&ifr, argp, ifreq_len))
35462 return -EFAULT;
35463 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35464 index 62f30b4..ff99dfd 100644
35465 --- a/drivers/net/usb/hso.c
35466 +++ b/drivers/net/usb/hso.c
35467 @@ -71,7 +71,7 @@
35468 #include <asm/byteorder.h>
35469 #include <linux/serial_core.h>
35470 #include <linux/serial.h>
35471 -
35472 +#include <asm/local.h>
35473
35474 #define MOD_AUTHOR "Option Wireless"
35475 #define MOD_DESCRIPTION "USB High Speed Option driver"
35476 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35477 struct urb *urb;
35478
35479 urb = serial->rx_urb[0];
35480 - if (serial->port.count > 0) {
35481 + if (atomic_read(&serial->port.count) > 0) {
35482 count = put_rxbuf_data(urb, serial);
35483 if (count == -1)
35484 return;
35485 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35486 DUMP1(urb->transfer_buffer, urb->actual_length);
35487
35488 /* Anyone listening? */
35489 - if (serial->port.count == 0)
35490 + if (atomic_read(&serial->port.count) == 0)
35491 return;
35492
35493 if (status == 0) {
35494 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35495 tty_port_tty_set(&serial->port, tty);
35496
35497 /* check for port already opened, if not set the termios */
35498 - serial->port.count++;
35499 - if (serial->port.count == 1) {
35500 + if (atomic_inc_return(&serial->port.count) == 1) {
35501 serial->rx_state = RX_IDLE;
35502 /* Force default termio settings */
35503 _hso_serial_set_termios(tty, NULL);
35504 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35505 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35506 if (result) {
35507 hso_stop_serial_device(serial->parent);
35508 - serial->port.count--;
35509 + atomic_dec(&serial->port.count);
35510 kref_put(&serial->parent->ref, hso_serial_ref_free);
35511 }
35512 } else {
35513 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35514
35515 /* reset the rts and dtr */
35516 /* do the actual close */
35517 - serial->port.count--;
35518 + atomic_dec(&serial->port.count);
35519
35520 - if (serial->port.count <= 0) {
35521 - serial->port.count = 0;
35522 + if (atomic_read(&serial->port.count) <= 0) {
35523 + atomic_set(&serial->port.count, 0);
35524 tty_port_tty_set(&serial->port, NULL);
35525 if (!usb_gone)
35526 hso_stop_serial_device(serial->parent);
35527 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35528
35529 /* the actual setup */
35530 spin_lock_irqsave(&serial->serial_lock, flags);
35531 - if (serial->port.count)
35532 + if (atomic_read(&serial->port.count))
35533 _hso_serial_set_termios(tty, old);
35534 else
35535 tty->termios = old;
35536 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35537 D1("Pending read interrupt on port %d\n", i);
35538 spin_lock(&serial->serial_lock);
35539 if (serial->rx_state == RX_IDLE &&
35540 - serial->port.count > 0) {
35541 + atomic_read(&serial->port.count) > 0) {
35542 /* Setup and send a ctrl req read on
35543 * port i */
35544 if (!serial->rx_urb_filled[0]) {
35545 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35546 /* Start all serial ports */
35547 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35548 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35549 - if (dev2ser(serial_table[i])->port.count) {
35550 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35551 result =
35552 hso_start_serial_device(serial_table[i], GFP_NOIO);
35553 hso_kick_transmit(dev2ser(serial_table[i]));
35554 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35555 index 6169fbd..40e8422 100644
35556 --- a/drivers/net/wireless/ath/ath.h
35557 +++ b/drivers/net/wireless/ath/ath.h
35558 @@ -119,6 +119,7 @@ struct ath_ops {
35559 void (*write_flush) (void *);
35560 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35561 };
35562 +typedef struct ath_ops __no_const ath_ops_no_const;
35563
35564 struct ath_common;
35565 struct ath_bus_ops;
35566 diff --git a/drivers/net/wireless/ath/ath5k/base.c b/drivers/net/wireless/ath/ath5k/base.c
35567 index 2aab20e..b761ef8 100644
35568 --- a/drivers/net/wireless/ath/ath5k/base.c
35569 +++ b/drivers/net/wireless/ath/ath5k/base.c
35570 @@ -1803,7 +1803,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35571 {
35572 int ret;
35573 struct ath5k_hw *ah = hw->priv;
35574 - struct ath5k_vif *avf = (void *)vif->drv_priv;
35575 + struct ath5k_vif *avf;
35576 struct sk_buff *skb;
35577
35578 if (WARN_ON(!vif)) {
35579 @@ -1818,6 +1818,7 @@ ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
35580 goto out;
35581 }
35582
35583 + avf = (void *)vif->drv_priv;
35584 ath5k_txbuf_free_skb(ah, avf->bbuf);
35585 avf->bbuf->skb = skb;
35586 ret = ath5k_beacon_setup(ah, avf->bbuf);
35587 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35588 index 8d78253..bebbb68 100644
35589 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35590 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35591 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35592 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35593 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35594
35595 - ACCESS_ONCE(ads->ds_link) = i->link;
35596 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35597 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35598 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35599
35600 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35601 ctl6 = SM(i->keytype, AR_EncrType);
35602 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35603
35604 if ((i->is_first || i->is_last) &&
35605 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35606 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35607 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35608 | set11nTries(i->rates, 1)
35609 | set11nTries(i->rates, 2)
35610 | set11nTries(i->rates, 3)
35611 | (i->dur_update ? AR_DurUpdateEna : 0)
35612 | SM(0, AR_BurstDur);
35613
35614 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35615 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35616 | set11nRate(i->rates, 1)
35617 | set11nRate(i->rates, 2)
35618 | set11nRate(i->rates, 3);
35619 } else {
35620 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35621 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35622 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35623 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35624 }
35625
35626 if (!i->is_first) {
35627 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35628 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35629 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35630 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35631 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35632 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35633 return;
35634 }
35635
35636 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35637 break;
35638 }
35639
35640 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35641 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35642 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35643 | SM(i->txpower, AR_XmitPower)
35644 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35645 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35646 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35647 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35648
35649 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35650 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35651 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35652 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35653
35654 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35655 return;
35656
35657 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35658 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35659 | set11nPktDurRTSCTS(i->rates, 1);
35660
35661 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35662 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35663 | set11nPktDurRTSCTS(i->rates, 3);
35664
35665 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35666 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35667 | set11nRateFlags(i->rates, 1)
35668 | set11nRateFlags(i->rates, 2)
35669 | set11nRateFlags(i->rates, 3)
35670 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35671 index 78816b8..1fcdfae 100644
35672 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35673 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35674 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35675 (i->qcu << AR_TxQcuNum_S) | desc_len;
35676
35677 checksum += val;
35678 - ACCESS_ONCE(ads->info) = val;
35679 + ACCESS_ONCE_RW(ads->info) = val;
35680
35681 checksum += i->link;
35682 - ACCESS_ONCE(ads->link) = i->link;
35683 + ACCESS_ONCE_RW(ads->link) = i->link;
35684
35685 checksum += i->buf_addr[0];
35686 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35687 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35688 checksum += i->buf_addr[1];
35689 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35690 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35691 checksum += i->buf_addr[2];
35692 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35693 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35694 checksum += i->buf_addr[3];
35695 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35696 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35697
35698 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35699 - ACCESS_ONCE(ads->ctl3) = val;
35700 + ACCESS_ONCE_RW(ads->ctl3) = val;
35701 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35702 - ACCESS_ONCE(ads->ctl5) = val;
35703 + ACCESS_ONCE_RW(ads->ctl5) = val;
35704 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35705 - ACCESS_ONCE(ads->ctl7) = val;
35706 + ACCESS_ONCE_RW(ads->ctl7) = val;
35707 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35708 - ACCESS_ONCE(ads->ctl9) = val;
35709 + ACCESS_ONCE_RW(ads->ctl9) = val;
35710
35711 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35712 - ACCESS_ONCE(ads->ctl10) = checksum;
35713 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35714
35715 if (i->is_first || i->is_last) {
35716 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35717 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35718 | set11nTries(i->rates, 1)
35719 | set11nTries(i->rates, 2)
35720 | set11nTries(i->rates, 3)
35721 | (i->dur_update ? AR_DurUpdateEna : 0)
35722 | SM(0, AR_BurstDur);
35723
35724 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35725 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35726 | set11nRate(i->rates, 1)
35727 | set11nRate(i->rates, 2)
35728 | set11nRate(i->rates, 3);
35729 } else {
35730 - ACCESS_ONCE(ads->ctl13) = 0;
35731 - ACCESS_ONCE(ads->ctl14) = 0;
35732 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35733 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35734 }
35735
35736 ads->ctl20 = 0;
35737 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35738
35739 ctl17 = SM(i->keytype, AR_EncrType);
35740 if (!i->is_first) {
35741 - ACCESS_ONCE(ads->ctl11) = 0;
35742 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35743 - ACCESS_ONCE(ads->ctl15) = 0;
35744 - ACCESS_ONCE(ads->ctl16) = 0;
35745 - ACCESS_ONCE(ads->ctl17) = ctl17;
35746 - ACCESS_ONCE(ads->ctl18) = 0;
35747 - ACCESS_ONCE(ads->ctl19) = 0;
35748 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35749 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35750 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35751 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35752 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35753 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35754 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35755 return;
35756 }
35757
35758 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35759 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35760 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35761 | SM(i->txpower, AR_XmitPower)
35762 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35763 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35764 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35765 ctl12 |= SM(val, AR_PAPRDChainMask);
35766
35767 - ACCESS_ONCE(ads->ctl12) = ctl12;
35768 - ACCESS_ONCE(ads->ctl17) = ctl17;
35769 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35770 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35771
35772 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35773 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35774 | set11nPktDurRTSCTS(i->rates, 1);
35775
35776 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35777 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35778 | set11nPktDurRTSCTS(i->rates, 3);
35779
35780 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35781 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35782 | set11nRateFlags(i->rates, 1)
35783 | set11nRateFlags(i->rates, 2)
35784 | set11nRateFlags(i->rates, 3)
35785 | SM(i->rtscts_rate, AR_RTSCTSRate);
35786
35787 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35788 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35789 }
35790
35791 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35792 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35793 index de6968f..29ac4c1 100644
35794 --- a/drivers/net/wireless/ath/ath9k/hw.h
35795 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35796 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35797
35798 /* ANI */
35799 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35800 -};
35801 +} __no_const;
35802
35803 /**
35804 * struct ath_hw_ops - callbacks used by hardware code and driver code
35805 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35806 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35807 struct ath_hw_antcomb_conf *antconf);
35808
35809 -};
35810 +} __no_const;
35811
35812 struct ath_nf_limits {
35813 s16 max;
35814 @@ -706,7 +706,7 @@ enum ath_cal_list {
35815 #define AH_FASTCC 0x4
35816
35817 struct ath_hw {
35818 - struct ath_ops reg_ops;
35819 + ath_ops_no_const reg_ops;
35820
35821 struct ieee80211_hw *hw;
35822 struct ath_common common;
35823 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35824 index af00e2c..ab04d34 100644
35825 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35826 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35827 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35828 void (*carrsuppr)(struct brcms_phy *);
35829 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35830 void (*detach)(struct brcms_phy *);
35831 -};
35832 +} __no_const;
35833
35834 struct brcms_phy {
35835 struct brcms_phy_pub pubpi_ro;
35836 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35837 index faec404..a5277f1 100644
35838 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35839 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35840 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35841 */
35842 if (il3945_mod_params.disable_hw_scan) {
35843 D_INFO("Disabling hw_scan\n");
35844 - il3945_mac_ops.hw_scan = NULL;
35845 + pax_open_kernel();
35846 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35847 + pax_close_kernel();
35848 }
35849
35850 D_INFO("*** LOAD DRIVER ***\n");
35851 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35852 index a47b306..297daf2 100644
35853 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35854 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35855 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35856 {
35857 struct iwl_priv *priv = file->private_data;
35858 char buf[64];
35859 - int buf_size;
35860 + size_t buf_size;
35861 u32 offset, len;
35862
35863 memset(buf, 0, sizeof(buf));
35864 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35865 struct iwl_priv *priv = file->private_data;
35866
35867 char buf[8];
35868 - int buf_size;
35869 + size_t buf_size;
35870 u32 reset_flag;
35871
35872 memset(buf, 0, sizeof(buf));
35873 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35874 {
35875 struct iwl_priv *priv = file->private_data;
35876 char buf[8];
35877 - int buf_size;
35878 + size_t buf_size;
35879 int ht40;
35880
35881 memset(buf, 0, sizeof(buf));
35882 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35883 {
35884 struct iwl_priv *priv = file->private_data;
35885 char buf[8];
35886 - int buf_size;
35887 + size_t buf_size;
35888 int value;
35889
35890 memset(buf, 0, sizeof(buf));
35891 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35892 {
35893 struct iwl_priv *priv = file->private_data;
35894 char buf[8];
35895 - int buf_size;
35896 + size_t buf_size;
35897 int clear;
35898
35899 memset(buf, 0, sizeof(buf));
35900 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35901 {
35902 struct iwl_priv *priv = file->private_data;
35903 char buf[8];
35904 - int buf_size;
35905 + size_t buf_size;
35906 int trace;
35907
35908 memset(buf, 0, sizeof(buf));
35909 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35910 {
35911 struct iwl_priv *priv = file->private_data;
35912 char buf[8];
35913 - int buf_size;
35914 + size_t buf_size;
35915 int missed;
35916
35917 memset(buf, 0, sizeof(buf));
35918 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35919
35920 struct iwl_priv *priv = file->private_data;
35921 char buf[8];
35922 - int buf_size;
35923 + size_t buf_size;
35924 int plcp;
35925
35926 memset(buf, 0, sizeof(buf));
35927 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35928
35929 struct iwl_priv *priv = file->private_data;
35930 char buf[8];
35931 - int buf_size;
35932 + size_t buf_size;
35933 int flush;
35934
35935 memset(buf, 0, sizeof(buf));
35936 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35937
35938 struct iwl_priv *priv = file->private_data;
35939 char buf[8];
35940 - int buf_size;
35941 + size_t buf_size;
35942 int rts;
35943
35944 if (!priv->cfg->ht_params)
35945 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35946 {
35947 struct iwl_priv *priv = file->private_data;
35948 char buf[8];
35949 - int buf_size;
35950 + size_t buf_size;
35951
35952 memset(buf, 0, sizeof(buf));
35953 buf_size = min(count, sizeof(buf) - 1);
35954 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35955 struct iwl_priv *priv = file->private_data;
35956 u32 event_log_flag;
35957 char buf[8];
35958 - int buf_size;
35959 + size_t buf_size;
35960
35961 /* check that the interface is up */
35962 if (!iwl_is_ready(priv))
35963 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35964 struct iwl_priv *priv = file->private_data;
35965 char buf[8];
35966 u32 calib_disabled;
35967 - int buf_size;
35968 + size_t buf_size;
35969
35970 memset(buf, 0, sizeof(buf));
35971 buf_size = min(count, sizeof(buf) - 1);
35972 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35973 index dbeebef..b45a152 100644
35974 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35975 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35976 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35977 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35978
35979 char buf[8];
35980 - int buf_size;
35981 + size_t buf_size;
35982 u32 reset_flag;
35983
35984 memset(buf, 0, sizeof(buf));
35985 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35986 {
35987 struct iwl_trans *trans = file->private_data;
35988 char buf[8];
35989 - int buf_size;
35990 + size_t buf_size;
35991 int csr;
35992
35993 memset(buf, 0, sizeof(buf));
35994 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35995 index 0083839..fcb7225 100644
35996 --- a/drivers/net/wireless/mac80211_hwsim.c
35997 +++ b/drivers/net/wireless/mac80211_hwsim.c
35998 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35999 return -EINVAL;
36000
36001 if (fake_hw_scan) {
36002 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36003 - mac80211_hwsim_ops.sw_scan_start = NULL;
36004 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36005 + pax_open_kernel();
36006 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36007 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36008 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36009 + pax_close_kernel();
36010 }
36011
36012 spin_lock_init(&hwsim_radio_lock);
36013 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36014 index e7c2a82..582e228 100644
36015 --- a/drivers/net/wireless/mwifiex/main.h
36016 +++ b/drivers/net/wireless/mwifiex/main.h
36017 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
36018 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36019 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36020 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36021 -};
36022 +} __no_const;
36023
36024 struct mwifiex_adapter {
36025 u8 iface_type;
36026 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36027 index 7a4ae9e..56e00bd 100644
36028 --- a/drivers/net/wireless/rndis_wlan.c
36029 +++ b/drivers/net/wireless/rndis_wlan.c
36030 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36031
36032 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36033
36034 - if (rts_threshold < 0 || rts_threshold > 2347)
36035 + if (rts_threshold > 2347)
36036 rts_threshold = 2347;
36037
36038 tmp = cpu_to_le32(rts_threshold);
36039 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36040 index 8afb546..0c0dc5c 100644
36041 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36042 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36043 @@ -397,7 +397,7 @@ struct rt2x00_intf {
36044 * for hardware which doesn't support hardware
36045 * sequence counting.
36046 */
36047 - atomic_t seqno;
36048 + atomic_unchecked_t seqno;
36049 };
36050
36051 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36052 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36053 index f7e74a0..da71431 100644
36054 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36055 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36056 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36057 * sequence counter given by mac80211.
36058 */
36059 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36060 - seqno = atomic_add_return(0x10, &intf->seqno);
36061 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36062 else
36063 - seqno = atomic_read(&intf->seqno);
36064 + seqno = atomic_read_unchecked(&intf->seqno);
36065
36066 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36067 hdr->seq_ctrl |= cpu_to_le16(seqno);
36068 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36069 index fd02060..74ee481 100644
36070 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36071 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36072 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36073 void (*reset)(struct wl1251 *wl);
36074 void (*enable_irq)(struct wl1251 *wl);
36075 void (*disable_irq)(struct wl1251 *wl);
36076 -};
36077 +} __no_const;
36078
36079 struct wl1251 {
36080 struct ieee80211_hw *hw;
36081 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36082 index 0ce7a8e..56a0ccf 100644
36083 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36084 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36085 @@ -81,7 +81,7 @@ struct wlcore_ops {
36086 struct ieee80211_sta *sta,
36087 struct ieee80211_key_conf *key_conf);
36088 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36089 -};
36090 +} __no_const;
36091
36092 enum wlcore_partitions {
36093 PART_DOWN,
36094 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36095 index f34b5b2..b5abb9f 100644
36096 --- a/drivers/oprofile/buffer_sync.c
36097 +++ b/drivers/oprofile/buffer_sync.c
36098 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36099 if (cookie == NO_COOKIE)
36100 offset = pc;
36101 if (cookie == INVALID_COOKIE) {
36102 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36103 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36104 offset = pc;
36105 }
36106 if (cookie != last_cookie) {
36107 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36108 /* add userspace sample */
36109
36110 if (!mm) {
36111 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36112 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36113 return 0;
36114 }
36115
36116 cookie = lookup_dcookie(mm, s->eip, &offset);
36117
36118 if (cookie == INVALID_COOKIE) {
36119 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36120 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36121 return 0;
36122 }
36123
36124 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36125 /* ignore backtraces if failed to add a sample */
36126 if (state == sb_bt_start) {
36127 state = sb_bt_ignore;
36128 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36129 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36130 }
36131 }
36132 release_mm(mm);
36133 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36134 index c0cc4e7..44d4e54 100644
36135 --- a/drivers/oprofile/event_buffer.c
36136 +++ b/drivers/oprofile/event_buffer.c
36137 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36138 }
36139
36140 if (buffer_pos == buffer_size) {
36141 - atomic_inc(&oprofile_stats.event_lost_overflow);
36142 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36143 return;
36144 }
36145
36146 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36147 index ed2c3ec..deda85a 100644
36148 --- a/drivers/oprofile/oprof.c
36149 +++ b/drivers/oprofile/oprof.c
36150 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36151 if (oprofile_ops.switch_events())
36152 return;
36153
36154 - atomic_inc(&oprofile_stats.multiplex_counter);
36155 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36156 start_switch_worker();
36157 }
36158
36159 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36160 index 917d28e..d62d981 100644
36161 --- a/drivers/oprofile/oprofile_stats.c
36162 +++ b/drivers/oprofile/oprofile_stats.c
36163 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36164 cpu_buf->sample_invalid_eip = 0;
36165 }
36166
36167 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36168 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36169 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36170 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36171 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36172 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36173 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36174 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36175 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36176 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36177 }
36178
36179
36180 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36181 index 38b6fc0..b5cbfce 100644
36182 --- a/drivers/oprofile/oprofile_stats.h
36183 +++ b/drivers/oprofile/oprofile_stats.h
36184 @@ -13,11 +13,11 @@
36185 #include <linux/atomic.h>
36186
36187 struct oprofile_stat_struct {
36188 - atomic_t sample_lost_no_mm;
36189 - atomic_t sample_lost_no_mapping;
36190 - atomic_t bt_lost_no_mapping;
36191 - atomic_t event_lost_overflow;
36192 - atomic_t multiplex_counter;
36193 + atomic_unchecked_t sample_lost_no_mm;
36194 + atomic_unchecked_t sample_lost_no_mapping;
36195 + atomic_unchecked_t bt_lost_no_mapping;
36196 + atomic_unchecked_t event_lost_overflow;
36197 + atomic_unchecked_t multiplex_counter;
36198 };
36199
36200 extern struct oprofile_stat_struct oprofile_stats;
36201 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36202 index 849357c..b83c1e0 100644
36203 --- a/drivers/oprofile/oprofilefs.c
36204 +++ b/drivers/oprofile/oprofilefs.c
36205 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36206
36207
36208 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36209 - char const *name, atomic_t *val)
36210 + char const *name, atomic_unchecked_t *val)
36211 {
36212 return __oprofilefs_create_file(sb, root, name,
36213 &atomic_ro_fops, 0444, val);
36214 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36215 index 3f56bc0..707d642 100644
36216 --- a/drivers/parport/procfs.c
36217 +++ b/drivers/parport/procfs.c
36218 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36219
36220 *ppos += len;
36221
36222 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36223 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36224 }
36225
36226 #ifdef CONFIG_PARPORT_1284
36227 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36228
36229 *ppos += len;
36230
36231 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36232 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36233 }
36234 #endif /* IEEE1284.3 support. */
36235
36236 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36237 index 9fff878..ad0ad53 100644
36238 --- a/drivers/pci/hotplug/cpci_hotplug.h
36239 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36240 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36241 int (*hardware_test) (struct slot* slot, u32 value);
36242 u8 (*get_power) (struct slot* slot);
36243 int (*set_power) (struct slot* slot, int value);
36244 -};
36245 +} __no_const;
36246
36247 struct cpci_hp_controller {
36248 unsigned int irq;
36249 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36250 index 76ba8a1..20ca857 100644
36251 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36252 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36253 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36254
36255 void compaq_nvram_init (void __iomem *rom_start)
36256 {
36257 +
36258 +#ifndef CONFIG_PAX_KERNEXEC
36259 if (rom_start) {
36260 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36261 }
36262 +#endif
36263 +
36264 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36265
36266 /* initialize our int15 lock */
36267 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36268 index b500840..d7159d3 100644
36269 --- a/drivers/pci/pcie/aspm.c
36270 +++ b/drivers/pci/pcie/aspm.c
36271 @@ -27,9 +27,9 @@
36272 #define MODULE_PARAM_PREFIX "pcie_aspm."
36273
36274 /* Note: those are not register definitions */
36275 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36276 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36277 -#define ASPM_STATE_L1 (4) /* L1 state */
36278 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36279 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36280 +#define ASPM_STATE_L1 (4U) /* L1 state */
36281 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36282 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36283
36284 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36285 index 61859d0..124539e 100644
36286 --- a/drivers/pci/probe.c
36287 +++ b/drivers/pci/probe.c
36288 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36289 struct pci_bus_region region;
36290 bool bar_too_big = false, bar_disabled = false;
36291
36292 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36293 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36294
36295 /* No printks while decoding is disabled! */
36296 if (!dev->mmio_always_on) {
36297 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36298 index 27911b5..5b6db88 100644
36299 --- a/drivers/pci/proc.c
36300 +++ b/drivers/pci/proc.c
36301 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36302 static int __init pci_proc_init(void)
36303 {
36304 struct pci_dev *dev = NULL;
36305 +
36306 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36307 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36308 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36309 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36310 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36311 +#endif
36312 +#else
36313 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36314 +#endif
36315 proc_create("devices", 0, proc_bus_pci_dir,
36316 &proc_bus_pci_dev_operations);
36317 proc_initialized = 1;
36318 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36319 index 52daaa8..d6b81eb 100644
36320 --- a/drivers/platform/x86/thinkpad_acpi.c
36321 +++ b/drivers/platform/x86/thinkpad_acpi.c
36322 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36323 return 0;
36324 }
36325
36326 -void static hotkey_mask_warn_incomplete_mask(void)
36327 +static void hotkey_mask_warn_incomplete_mask(void)
36328 {
36329 /* log only what the user can fix... */
36330 const u32 wantedmask = hotkey_driver_mask &
36331 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36332 }
36333 }
36334
36335 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36336 - struct tp_nvram_state *newn,
36337 - const u32 event_mask)
36338 -{
36339 -
36340 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36341 do { \
36342 if ((event_mask & (1 << __scancode)) && \
36343 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36344 tpacpi_hotkey_send_key(__scancode); \
36345 } while (0)
36346
36347 - void issue_volchange(const unsigned int oldvol,
36348 - const unsigned int newvol)
36349 - {
36350 - unsigned int i = oldvol;
36351 +static void issue_volchange(const unsigned int oldvol,
36352 + const unsigned int newvol,
36353 + const u32 event_mask)
36354 +{
36355 + unsigned int i = oldvol;
36356
36357 - while (i > newvol) {
36358 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36359 - i--;
36360 - }
36361 - while (i < newvol) {
36362 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36363 - i++;
36364 - }
36365 + while (i > newvol) {
36366 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36367 + i--;
36368 }
36369 + while (i < newvol) {
36370 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36371 + i++;
36372 + }
36373 +}
36374
36375 - void issue_brightnesschange(const unsigned int oldbrt,
36376 - const unsigned int newbrt)
36377 - {
36378 - unsigned int i = oldbrt;
36379 +static void issue_brightnesschange(const unsigned int oldbrt,
36380 + const unsigned int newbrt,
36381 + const u32 event_mask)
36382 +{
36383 + unsigned int i = oldbrt;
36384
36385 - while (i > newbrt) {
36386 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36387 - i--;
36388 - }
36389 - while (i < newbrt) {
36390 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36391 - i++;
36392 - }
36393 + while (i > newbrt) {
36394 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36395 + i--;
36396 + }
36397 + while (i < newbrt) {
36398 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36399 + i++;
36400 }
36401 +}
36402
36403 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36404 + struct tp_nvram_state *newn,
36405 + const u32 event_mask)
36406 +{
36407 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36408 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36409 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36410 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36411 oldn->volume_level != newn->volume_level) {
36412 /* recently muted, or repeated mute keypress, or
36413 * multiple presses ending in mute */
36414 - issue_volchange(oldn->volume_level, newn->volume_level);
36415 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36416 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36417 }
36418 } else {
36419 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36420 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36421 }
36422 if (oldn->volume_level != newn->volume_level) {
36423 - issue_volchange(oldn->volume_level, newn->volume_level);
36424 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36425 } else if (oldn->volume_toggle != newn->volume_toggle) {
36426 /* repeated vol up/down keypress at end of scale ? */
36427 if (newn->volume_level == 0)
36428 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36429 /* handle brightness */
36430 if (oldn->brightness_level != newn->brightness_level) {
36431 issue_brightnesschange(oldn->brightness_level,
36432 - newn->brightness_level);
36433 + newn->brightness_level,
36434 + event_mask);
36435 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36436 /* repeated key presses that didn't change state */
36437 if (newn->brightness_level == 0)
36438 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36439 && !tp_features.bright_unkfw)
36440 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36441 }
36442 +}
36443
36444 #undef TPACPI_COMPARE_KEY
36445 #undef TPACPI_MAY_SEND_KEY
36446 -}
36447
36448 /*
36449 * Polling driver
36450 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36451 index 769d265..a3a05ca 100644
36452 --- a/drivers/pnp/pnpbios/bioscalls.c
36453 +++ b/drivers/pnp/pnpbios/bioscalls.c
36454 @@ -58,7 +58,7 @@ do { \
36455 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36456 } while(0)
36457
36458 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36459 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36460 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36461
36462 /*
36463 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36464
36465 cpu = get_cpu();
36466 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36467 +
36468 + pax_open_kernel();
36469 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36470 + pax_close_kernel();
36471
36472 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36473 spin_lock_irqsave(&pnp_bios_lock, flags);
36474 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36475 :"memory");
36476 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36477
36478 + pax_open_kernel();
36479 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36480 + pax_close_kernel();
36481 +
36482 put_cpu();
36483
36484 /* If we get here and this is set then the PnP BIOS faulted on us. */
36485 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36486 return status;
36487 }
36488
36489 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36490 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36491 {
36492 int i;
36493
36494 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36495 pnp_bios_callpoint.offset = header->fields.pm16offset;
36496 pnp_bios_callpoint.segment = PNP_CS16;
36497
36498 + pax_open_kernel();
36499 +
36500 for_each_possible_cpu(i) {
36501 struct desc_struct *gdt = get_cpu_gdt_table(i);
36502 if (!gdt)
36503 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36504 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36505 (unsigned long)__va(header->fields.pm16dseg));
36506 }
36507 +
36508 + pax_close_kernel();
36509 }
36510 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36511 index b0ecacb..7c9da2e 100644
36512 --- a/drivers/pnp/resource.c
36513 +++ b/drivers/pnp/resource.c
36514 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36515 return 1;
36516
36517 /* check if the resource is valid */
36518 - if (*irq < 0 || *irq > 15)
36519 + if (*irq > 15)
36520 return 0;
36521
36522 /* check if the resource is reserved */
36523 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36524 return 1;
36525
36526 /* check if the resource is valid */
36527 - if (*dma < 0 || *dma == 4 || *dma > 7)
36528 + if (*dma == 4 || *dma > 7)
36529 return 0;
36530
36531 /* check if the resource is reserved */
36532 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36533 index 181ddec..774b6da 100644
36534 --- a/drivers/power/bq27x00_battery.c
36535 +++ b/drivers/power/bq27x00_battery.c
36536 @@ -80,7 +80,7 @@
36537 struct bq27x00_device_info;
36538 struct bq27x00_access_methods {
36539 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36540 -};
36541 +} __no_const;
36542
36543 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36544
36545 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36546 index 8d53174..04c65de 100644
36547 --- a/drivers/regulator/max8660.c
36548 +++ b/drivers/regulator/max8660.c
36549 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36550 max8660->shadow_regs[MAX8660_OVER1] = 5;
36551 } else {
36552 /* Otherwise devices can be toggled via software */
36553 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36554 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36555 + pax_open_kernel();
36556 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36557 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36558 + pax_close_kernel();
36559 }
36560
36561 /*
36562 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36563 index b388b74..ed82573 100644
36564 --- a/drivers/regulator/mc13892-regulator.c
36565 +++ b/drivers/regulator/mc13892-regulator.c
36566 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36567 }
36568 mc13xxx_unlock(mc13892);
36569
36570 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36571 + pax_open_kernel();
36572 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36573 = mc13892_vcam_set_mode;
36574 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36575 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36576 = mc13892_vcam_get_mode;
36577 + pax_close_kernel();
36578
36579 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36580 ARRAY_SIZE(mc13892_regulators));
36581 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36582 index cace6d3..f623fda 100644
36583 --- a/drivers/rtc/rtc-dev.c
36584 +++ b/drivers/rtc/rtc-dev.c
36585 @@ -14,6 +14,7 @@
36586 #include <linux/module.h>
36587 #include <linux/rtc.h>
36588 #include <linux/sched.h>
36589 +#include <linux/grsecurity.h>
36590 #include "rtc-core.h"
36591
36592 static dev_t rtc_devt;
36593 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36594 if (copy_from_user(&tm, uarg, sizeof(tm)))
36595 return -EFAULT;
36596
36597 + gr_log_timechange();
36598 +
36599 return rtc_set_time(rtc, &tm);
36600
36601 case RTC_PIE_ON:
36602 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36603 index 9e933a8..4f969f7 100644
36604 --- a/drivers/scsi/aacraid/aacraid.h
36605 +++ b/drivers/scsi/aacraid/aacraid.h
36606 @@ -503,7 +503,7 @@ struct adapter_ops
36607 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36608 /* Administrative operations */
36609 int (*adapter_comm)(struct aac_dev * dev, int comm);
36610 -};
36611 +} __no_const;
36612
36613 /*
36614 * Define which interrupt handler needs to be installed
36615 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36616 index 7199534..cb7f158 100644
36617 --- a/drivers/scsi/aacraid/linit.c
36618 +++ b/drivers/scsi/aacraid/linit.c
36619 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36620 #elif defined(__devinitconst)
36621 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36622 #else
36623 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36624 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36625 #endif
36626 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36627 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36628 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36629 index ff80552..1c4120c 100644
36630 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36631 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36632 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36633 .lldd_ata_set_dmamode = asd_set_dmamode,
36634 };
36635
36636 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36637 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36638 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36639 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36640 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36641 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36642 index 4ad7e36..d004679 100644
36643 --- a/drivers/scsi/bfa/bfa.h
36644 +++ b/drivers/scsi/bfa/bfa.h
36645 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36646 u32 *end);
36647 int cpe_vec_q0;
36648 int rme_vec_q0;
36649 -};
36650 +} __no_const;
36651 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36652
36653 struct bfa_faa_cbfn_s {
36654 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36655 index f0f80e2..8ec946b 100644
36656 --- a/drivers/scsi/bfa/bfa_fcpim.c
36657 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36658 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36659
36660 bfa_iotag_attach(fcp);
36661
36662 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36663 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36664 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36665 (fcp->num_itns * sizeof(struct bfa_itn_s));
36666 memset(fcp->itn_arr, 0,
36667 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36668 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36669 {
36670 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36671 - struct bfa_itn_s *itn;
36672 + bfa_itn_s_no_const *itn;
36673
36674 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36675 itn->isr = isr;
36676 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36677 index 36f26da..38a34a8 100644
36678 --- a/drivers/scsi/bfa/bfa_fcpim.h
36679 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36680 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36681 struct bfa_itn_s {
36682 bfa_isr_func_t isr;
36683 };
36684 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36685
36686 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36687 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36688 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36689 struct list_head iotag_tio_free_q; /* free IO resources */
36690 struct list_head iotag_unused_q; /* unused IO resources*/
36691 struct bfa_iotag_s *iotag_arr;
36692 - struct bfa_itn_s *itn_arr;
36693 + bfa_itn_s_no_const *itn_arr;
36694 int num_ioim_reqs;
36695 int num_fwtio_reqs;
36696 int num_itns;
36697 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36698 index 1a99d4b..e85d64b 100644
36699 --- a/drivers/scsi/bfa/bfa_ioc.h
36700 +++ b/drivers/scsi/bfa/bfa_ioc.h
36701 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36702 bfa_ioc_disable_cbfn_t disable_cbfn;
36703 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36704 bfa_ioc_reset_cbfn_t reset_cbfn;
36705 -};
36706 +} __no_const;
36707
36708 /*
36709 * IOC event notification mechanism.
36710 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36711 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36712 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36713 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36714 -};
36715 +} __no_const;
36716
36717 /*
36718 * Queue element to wait for room in request queue. FIFO order is
36719 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36720 index 593085a..47aa999 100644
36721 --- a/drivers/scsi/hosts.c
36722 +++ b/drivers/scsi/hosts.c
36723 @@ -42,7 +42,7 @@
36724 #include "scsi_logging.h"
36725
36726
36727 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36728 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36729
36730
36731 static void scsi_host_cls_release(struct device *dev)
36732 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36733 * subtract one because we increment first then return, but we need to
36734 * know what the next host number was before increment
36735 */
36736 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36737 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36738 shost->dma_channel = 0xff;
36739
36740 /* These three are default values which can be overridden */
36741 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36742 index f9823f2..7bc3e81 100644
36743 --- a/drivers/scsi/hpsa.c
36744 +++ b/drivers/scsi/hpsa.c
36745 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36746 unsigned long flags;
36747
36748 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36749 - return h->access.command_completed(h, q);
36750 + return h->access->command_completed(h, q);
36751
36752 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36753 a = rq->head[rq->current_entry];
36754 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36755 while (!list_empty(&h->reqQ)) {
36756 c = list_entry(h->reqQ.next, struct CommandList, list);
36757 /* can't do anything if fifo is full */
36758 - if ((h->access.fifo_full(h))) {
36759 + if ((h->access->fifo_full(h))) {
36760 dev_warn(&h->pdev->dev, "fifo full\n");
36761 break;
36762 }
36763 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36764
36765 /* Tell the controller execute command */
36766 spin_unlock_irqrestore(&h->lock, flags);
36767 - h->access.submit_command(h, c);
36768 + h->access->submit_command(h, c);
36769 spin_lock_irqsave(&h->lock, flags);
36770 }
36771 spin_unlock_irqrestore(&h->lock, flags);
36772 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36773
36774 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36775 {
36776 - return h->access.command_completed(h, q);
36777 + return h->access->command_completed(h, q);
36778 }
36779
36780 static inline bool interrupt_pending(struct ctlr_info *h)
36781 {
36782 - return h->access.intr_pending(h);
36783 + return h->access->intr_pending(h);
36784 }
36785
36786 static inline long interrupt_not_for_us(struct ctlr_info *h)
36787 {
36788 - return (h->access.intr_pending(h) == 0) ||
36789 + return (h->access->intr_pending(h) == 0) ||
36790 (h->interrupts_enabled == 0);
36791 }
36792
36793 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36794 if (prod_index < 0)
36795 return -ENODEV;
36796 h->product_name = products[prod_index].product_name;
36797 - h->access = *(products[prod_index].access);
36798 + h->access = products[prod_index].access;
36799
36800 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36801 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36802 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36803
36804 assert_spin_locked(&lockup_detector_lock);
36805 remove_ctlr_from_lockup_detector_list(h);
36806 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36807 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36808 spin_lock_irqsave(&h->lock, flags);
36809 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36810 spin_unlock_irqrestore(&h->lock, flags);
36811 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36812 }
36813
36814 /* make sure the board interrupts are off */
36815 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36816 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36817
36818 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36819 goto clean2;
36820 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36821 * fake ones to scoop up any residual completions.
36822 */
36823 spin_lock_irqsave(&h->lock, flags);
36824 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36825 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36826 spin_unlock_irqrestore(&h->lock, flags);
36827 free_irqs(h);
36828 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36829 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36830 dev_info(&h->pdev->dev, "Board READY.\n");
36831 dev_info(&h->pdev->dev,
36832 "Waiting for stale completions to drain.\n");
36833 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36834 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36835 msleep(10000);
36836 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36837 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36838
36839 rc = controller_reset_failed(h->cfgtable);
36840 if (rc)
36841 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36842 }
36843
36844 /* Turn the interrupts on so we can service requests */
36845 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36846 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36847
36848 hpsa_hba_inquiry(h);
36849 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36850 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36851 * To write all data in the battery backed cache to disks
36852 */
36853 hpsa_flush_cache(h);
36854 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36855 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36856 hpsa_free_irqs_and_disable_msix(h);
36857 }
36858
36859 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36860 return;
36861 }
36862 /* Change the access methods to the performant access methods */
36863 - h->access = SA5_performant_access;
36864 + h->access = &SA5_performant_access;
36865 h->transMethod = CFGTBL_Trans_Performant;
36866 }
36867
36868 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36869 index 9816479..c5d4e97 100644
36870 --- a/drivers/scsi/hpsa.h
36871 +++ b/drivers/scsi/hpsa.h
36872 @@ -79,7 +79,7 @@ struct ctlr_info {
36873 unsigned int msix_vector;
36874 unsigned int msi_vector;
36875 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36876 - struct access_method access;
36877 + struct access_method *access;
36878
36879 /* queue and queue Info */
36880 struct list_head reqQ;
36881 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36882 index f2df059..a3a9930 100644
36883 --- a/drivers/scsi/ips.h
36884 +++ b/drivers/scsi/ips.h
36885 @@ -1027,7 +1027,7 @@ typedef struct {
36886 int (*intr)(struct ips_ha *);
36887 void (*enableint)(struct ips_ha *);
36888 uint32_t (*statupd)(struct ips_ha *);
36889 -} ips_hw_func_t;
36890 +} __no_const ips_hw_func_t;
36891
36892 typedef struct ips_ha {
36893 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36894 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36895 index c772d8d..35c362c 100644
36896 --- a/drivers/scsi/libfc/fc_exch.c
36897 +++ b/drivers/scsi/libfc/fc_exch.c
36898 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36899 u16 pool_max_index;
36900
36901 struct {
36902 - atomic_t no_free_exch;
36903 - atomic_t no_free_exch_xid;
36904 - atomic_t xid_not_found;
36905 - atomic_t xid_busy;
36906 - atomic_t seq_not_found;
36907 - atomic_t non_bls_resp;
36908 + atomic_unchecked_t no_free_exch;
36909 + atomic_unchecked_t no_free_exch_xid;
36910 + atomic_unchecked_t xid_not_found;
36911 + atomic_unchecked_t xid_busy;
36912 + atomic_unchecked_t seq_not_found;
36913 + atomic_unchecked_t non_bls_resp;
36914 } stats;
36915 };
36916
36917 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36918 /* allocate memory for exchange */
36919 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36920 if (!ep) {
36921 - atomic_inc(&mp->stats.no_free_exch);
36922 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36923 goto out;
36924 }
36925 memset(ep, 0, sizeof(*ep));
36926 @@ -786,7 +786,7 @@ out:
36927 return ep;
36928 err:
36929 spin_unlock_bh(&pool->lock);
36930 - atomic_inc(&mp->stats.no_free_exch_xid);
36931 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36932 mempool_free(ep, mp->ep_pool);
36933 return NULL;
36934 }
36935 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36936 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36937 ep = fc_exch_find(mp, xid);
36938 if (!ep) {
36939 - atomic_inc(&mp->stats.xid_not_found);
36940 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36941 reject = FC_RJT_OX_ID;
36942 goto out;
36943 }
36944 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36945 ep = fc_exch_find(mp, xid);
36946 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36947 if (ep) {
36948 - atomic_inc(&mp->stats.xid_busy);
36949 + atomic_inc_unchecked(&mp->stats.xid_busy);
36950 reject = FC_RJT_RX_ID;
36951 goto rel;
36952 }
36953 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36954 }
36955 xid = ep->xid; /* get our XID */
36956 } else if (!ep) {
36957 - atomic_inc(&mp->stats.xid_not_found);
36958 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36959 reject = FC_RJT_RX_ID; /* XID not found */
36960 goto out;
36961 }
36962 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36963 } else {
36964 sp = &ep->seq;
36965 if (sp->id != fh->fh_seq_id) {
36966 - atomic_inc(&mp->stats.seq_not_found);
36967 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36968 if (f_ctl & FC_FC_END_SEQ) {
36969 /*
36970 * Update sequence_id based on incoming last
36971 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36972
36973 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36974 if (!ep) {
36975 - atomic_inc(&mp->stats.xid_not_found);
36976 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36977 goto out;
36978 }
36979 if (ep->esb_stat & ESB_ST_COMPLETE) {
36980 - atomic_inc(&mp->stats.xid_not_found);
36981 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36982 goto rel;
36983 }
36984 if (ep->rxid == FC_XID_UNKNOWN)
36985 ep->rxid = ntohs(fh->fh_rx_id);
36986 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36987 - atomic_inc(&mp->stats.xid_not_found);
36988 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36989 goto rel;
36990 }
36991 if (ep->did != ntoh24(fh->fh_s_id) &&
36992 ep->did != FC_FID_FLOGI) {
36993 - atomic_inc(&mp->stats.xid_not_found);
36994 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36995 goto rel;
36996 }
36997 sof = fr_sof(fp);
36998 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36999 sp->ssb_stat |= SSB_ST_RESP;
37000 sp->id = fh->fh_seq_id;
37001 } else if (sp->id != fh->fh_seq_id) {
37002 - atomic_inc(&mp->stats.seq_not_found);
37003 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37004 goto rel;
37005 }
37006
37007 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37008 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37009
37010 if (!sp)
37011 - atomic_inc(&mp->stats.xid_not_found);
37012 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37013 else
37014 - atomic_inc(&mp->stats.non_bls_resp);
37015 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37016
37017 fc_frame_free(fp);
37018 }
37019 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
37020
37021 list_for_each_entry(ema, &lport->ema_list, ema_list) {
37022 mp = ema->mp;
37023 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
37024 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
37025 st->fc_no_free_exch_xid +=
37026 - atomic_read(&mp->stats.no_free_exch_xid);
37027 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
37028 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
37029 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
37030 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
37031 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
37032 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
37033 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
37034 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
37035 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
37036 }
37037 }
37038 EXPORT_SYMBOL(fc_exch_update_stats);
37039 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37040 index a59fcdc..abe55f3 100644
37041 --- a/drivers/scsi/libsas/sas_ata.c
37042 +++ b/drivers/scsi/libsas/sas_ata.c
37043 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
37044 .postreset = ata_std_postreset,
37045 .error_handler = ata_std_error_handler,
37046 .post_internal_cmd = sas_ata_post_internal,
37047 - .qc_defer = ata_std_qc_defer,
37048 + .qc_defer = ata_std_qc_defer,
37049 .qc_prep = ata_noop_qc_prep,
37050 .qc_issue = sas_ata_qc_issue,
37051 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37052 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37053 index a65c05a..a39e402 100644
37054 --- a/drivers/scsi/lpfc/lpfc.h
37055 +++ b/drivers/scsi/lpfc/lpfc.h
37056 @@ -420,7 +420,7 @@ struct lpfc_vport {
37057 struct dentry *debug_nodelist;
37058 struct dentry *vport_debugfs_root;
37059 struct lpfc_debugfs_trc *disc_trc;
37060 - atomic_t disc_trc_cnt;
37061 + atomic_unchecked_t disc_trc_cnt;
37062 #endif
37063 uint8_t stat_data_enabled;
37064 uint8_t stat_data_blocked;
37065 @@ -834,8 +834,8 @@ struct lpfc_hba {
37066 struct timer_list fabric_block_timer;
37067 unsigned long bit_flags;
37068 #define FABRIC_COMANDS_BLOCKED 0
37069 - atomic_t num_rsrc_err;
37070 - atomic_t num_cmd_success;
37071 + atomic_unchecked_t num_rsrc_err;
37072 + atomic_unchecked_t num_cmd_success;
37073 unsigned long last_rsrc_error_time;
37074 unsigned long last_ramp_down_time;
37075 unsigned long last_ramp_up_time;
37076 @@ -871,7 +871,7 @@ struct lpfc_hba {
37077
37078 struct dentry *debug_slow_ring_trc;
37079 struct lpfc_debugfs_trc *slow_ring_trc;
37080 - atomic_t slow_ring_trc_cnt;
37081 + atomic_unchecked_t slow_ring_trc_cnt;
37082 /* iDiag debugfs sub-directory */
37083 struct dentry *idiag_root;
37084 struct dentry *idiag_pci_cfg;
37085 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37086 index 3217d63..c417981 100644
37087 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37088 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37089 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37090
37091 #include <linux/debugfs.h>
37092
37093 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37094 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37095 static unsigned long lpfc_debugfs_start_time = 0L;
37096
37097 /* iDiag */
37098 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37099 lpfc_debugfs_enable = 0;
37100
37101 len = 0;
37102 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37103 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37104 (lpfc_debugfs_max_disc_trc - 1);
37105 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37106 dtp = vport->disc_trc + i;
37107 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37108 lpfc_debugfs_enable = 0;
37109
37110 len = 0;
37111 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37112 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37113 (lpfc_debugfs_max_slow_ring_trc - 1);
37114 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37115 dtp = phba->slow_ring_trc + i;
37116 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37117 !vport || !vport->disc_trc)
37118 return;
37119
37120 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37121 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37122 (lpfc_debugfs_max_disc_trc - 1);
37123 dtp = vport->disc_trc + index;
37124 dtp->fmt = fmt;
37125 dtp->data1 = data1;
37126 dtp->data2 = data2;
37127 dtp->data3 = data3;
37128 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37129 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37130 dtp->jif = jiffies;
37131 #endif
37132 return;
37133 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37134 !phba || !phba->slow_ring_trc)
37135 return;
37136
37137 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37138 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37139 (lpfc_debugfs_max_slow_ring_trc - 1);
37140 dtp = phba->slow_ring_trc + index;
37141 dtp->fmt = fmt;
37142 dtp->data1 = data1;
37143 dtp->data2 = data2;
37144 dtp->data3 = data3;
37145 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37146 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37147 dtp->jif = jiffies;
37148 #endif
37149 return;
37150 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37151 "slow_ring buffer\n");
37152 goto debug_failed;
37153 }
37154 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37155 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37156 memset(phba->slow_ring_trc, 0,
37157 (sizeof(struct lpfc_debugfs_trc) *
37158 lpfc_debugfs_max_slow_ring_trc));
37159 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37160 "buffer\n");
37161 goto debug_failed;
37162 }
37163 - atomic_set(&vport->disc_trc_cnt, 0);
37164 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37165
37166 snprintf(name, sizeof(name), "discovery_trace");
37167 vport->debug_disc_trc =
37168 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37169 index 45c1520..35ba744 100644
37170 --- a/drivers/scsi/lpfc/lpfc_init.c
37171 +++ b/drivers/scsi/lpfc/lpfc_init.c
37172 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37173 "misc_register returned with status %d", error);
37174
37175 if (lpfc_enable_npiv) {
37176 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37177 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37178 + pax_open_kernel();
37179 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37180 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37181 + pax_close_kernel();
37182 }
37183 lpfc_transport_template =
37184 fc_attach_transport(&lpfc_transport_functions);
37185 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37186 index 925975d..0f1fc07 100644
37187 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37188 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37189 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37190 uint32_t evt_posted;
37191
37192 spin_lock_irqsave(&phba->hbalock, flags);
37193 - atomic_inc(&phba->num_rsrc_err);
37194 + atomic_inc_unchecked(&phba->num_rsrc_err);
37195 phba->last_rsrc_error_time = jiffies;
37196
37197 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37198 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37199 unsigned long flags;
37200 struct lpfc_hba *phba = vport->phba;
37201 uint32_t evt_posted;
37202 - atomic_inc(&phba->num_cmd_success);
37203 + atomic_inc_unchecked(&phba->num_cmd_success);
37204
37205 if (vport->cfg_lun_queue_depth <= queue_depth)
37206 return;
37207 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37208 unsigned long num_rsrc_err, num_cmd_success;
37209 int i;
37210
37211 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37212 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37213 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37214 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37215
37216 /*
37217 * The error and success command counters are global per
37218 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37219 }
37220 }
37221 lpfc_destroy_vport_work_array(phba, vports);
37222 - atomic_set(&phba->num_rsrc_err, 0);
37223 - atomic_set(&phba->num_cmd_success, 0);
37224 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37225 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37226 }
37227
37228 /**
37229 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37230 }
37231 }
37232 lpfc_destroy_vport_work_array(phba, vports);
37233 - atomic_set(&phba->num_rsrc_err, 0);
37234 - atomic_set(&phba->num_cmd_success, 0);
37235 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37236 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37237 }
37238
37239 /**
37240 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37241 index ea8a0b4..812a124 100644
37242 --- a/drivers/scsi/pmcraid.c
37243 +++ b/drivers/scsi/pmcraid.c
37244 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37245 res->scsi_dev = scsi_dev;
37246 scsi_dev->hostdata = res;
37247 res->change_detected = 0;
37248 - atomic_set(&res->read_failures, 0);
37249 - atomic_set(&res->write_failures, 0);
37250 + atomic_set_unchecked(&res->read_failures, 0);
37251 + atomic_set_unchecked(&res->write_failures, 0);
37252 rc = 0;
37253 }
37254 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37255 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37256
37257 /* If this was a SCSI read/write command keep count of errors */
37258 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37259 - atomic_inc(&res->read_failures);
37260 + atomic_inc_unchecked(&res->read_failures);
37261 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37262 - atomic_inc(&res->write_failures);
37263 + atomic_inc_unchecked(&res->write_failures);
37264
37265 if (!RES_IS_GSCSI(res->cfg_entry) &&
37266 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37267 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37268 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37269 * hrrq_id assigned here in queuecommand
37270 */
37271 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37272 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37273 pinstance->num_hrrq;
37274 cmd->cmd_done = pmcraid_io_done;
37275
37276 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37277 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37278 * hrrq_id assigned here in queuecommand
37279 */
37280 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37281 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37282 pinstance->num_hrrq;
37283
37284 if (request_size) {
37285 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37286
37287 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37288 /* add resources only after host is added into system */
37289 - if (!atomic_read(&pinstance->expose_resources))
37290 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37291 return;
37292
37293 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37294 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37295 init_waitqueue_head(&pinstance->reset_wait_q);
37296
37297 atomic_set(&pinstance->outstanding_cmds, 0);
37298 - atomic_set(&pinstance->last_message_id, 0);
37299 - atomic_set(&pinstance->expose_resources, 0);
37300 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37301 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37302
37303 INIT_LIST_HEAD(&pinstance->free_res_q);
37304 INIT_LIST_HEAD(&pinstance->used_res_q);
37305 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37306 /* Schedule worker thread to handle CCN and take care of adding and
37307 * removing devices to OS
37308 */
37309 - atomic_set(&pinstance->expose_resources, 1);
37310 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37311 schedule_work(&pinstance->worker_q);
37312 return rc;
37313
37314 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37315 index e1d150f..6c6df44 100644
37316 --- a/drivers/scsi/pmcraid.h
37317 +++ b/drivers/scsi/pmcraid.h
37318 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37319 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37320
37321 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37322 - atomic_t last_message_id;
37323 + atomic_unchecked_t last_message_id;
37324
37325 /* configuration table */
37326 struct pmcraid_config_table *cfg_table;
37327 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37328 atomic_t outstanding_cmds;
37329
37330 /* should add/delete resources to mid-layer now ?*/
37331 - atomic_t expose_resources;
37332 + atomic_unchecked_t expose_resources;
37333
37334
37335
37336 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37337 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37338 };
37339 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37340 - atomic_t read_failures; /* count of failed READ commands */
37341 - atomic_t write_failures; /* count of failed WRITE commands */
37342 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37343 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37344
37345 /* To indicate add/delete/modify during CCN */
37346 u8 change_detected;
37347 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37348 index 5ab9530..2dd80f7 100644
37349 --- a/drivers/scsi/qla2xxx/qla_attr.c
37350 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37351 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37352 return 0;
37353 }
37354
37355 -struct fc_function_template qla2xxx_transport_functions = {
37356 +fc_function_template_no_const qla2xxx_transport_functions = {
37357
37358 .show_host_node_name = 1,
37359 .show_host_port_name = 1,
37360 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37361 .bsg_timeout = qla24xx_bsg_timeout,
37362 };
37363
37364 -struct fc_function_template qla2xxx_transport_vport_functions = {
37365 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37366
37367 .show_host_node_name = 1,
37368 .show_host_port_name = 1,
37369 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37370 index 39007f5..7fafc64 100644
37371 --- a/drivers/scsi/qla2xxx/qla_def.h
37372 +++ b/drivers/scsi/qla2xxx/qla_def.h
37373 @@ -2284,7 +2284,7 @@ struct isp_operations {
37374 int (*start_scsi) (srb_t *);
37375 int (*abort_isp) (struct scsi_qla_host *);
37376 int (*iospace_config)(struct qla_hw_data*);
37377 -};
37378 +} __no_const;
37379
37380 /* MSI-X Support *************************************************************/
37381
37382 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37383 index 9eacd2d..d79629c 100644
37384 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37385 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37386 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37387 struct device_attribute;
37388 extern struct device_attribute *qla2x00_host_attrs[];
37389 struct fc_function_template;
37390 -extern struct fc_function_template qla2xxx_transport_functions;
37391 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37392 +extern fc_function_template_no_const qla2xxx_transport_functions;
37393 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37394 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37395 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37396 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37397 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37398 index 7fdba7f..1b4b2c2 100644
37399 --- a/drivers/scsi/qla4xxx/ql4_def.h
37400 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37401 @@ -268,7 +268,7 @@ struct ddb_entry {
37402 * (4000 only) */
37403 atomic_t relogin_timer; /* Max Time to wait for
37404 * relogin to complete */
37405 - atomic_t relogin_retry_count; /* Num of times relogin has been
37406 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37407 * retried */
37408 uint32_t default_time2wait; /* Default Min time between
37409 * relogins (+aens) */
37410 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37411 index 9da4266..377b3b6 100644
37412 --- a/drivers/scsi/qla4xxx/ql4_os.c
37413 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37414 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37415 */
37416 if (!iscsi_is_session_online(cls_sess)) {
37417 /* Reset retry relogin timer */
37418 - atomic_inc(&ddb_entry->relogin_retry_count);
37419 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37420 DEBUG2(ql4_printk(KERN_INFO, ha,
37421 "%s: index[%d] relogin timed out-retrying"
37422 " relogin (%d), retry (%d)\n", __func__,
37423 ddb_entry->fw_ddb_index,
37424 - atomic_read(&ddb_entry->relogin_retry_count),
37425 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37426 ddb_entry->default_time2wait + 4));
37427 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37428 atomic_set(&ddb_entry->retry_relogin_timer,
37429 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37430
37431 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37432 atomic_set(&ddb_entry->relogin_timer, 0);
37433 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37434 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37435 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37436 ddb_entry->default_relogin_timeout =
37437 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37438 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37439 index 2936b44..546ecdb 100644
37440 --- a/drivers/scsi/scsi.c
37441 +++ b/drivers/scsi/scsi.c
37442 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37443 unsigned long timeout;
37444 int rtn = 0;
37445
37446 - atomic_inc(&cmd->device->iorequest_cnt);
37447 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37448
37449 /* check if the device is still usable */
37450 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37451 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37452 index faa790f..7e351ddd 100644
37453 --- a/drivers/scsi/scsi_lib.c
37454 +++ b/drivers/scsi/scsi_lib.c
37455 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37456 shost = sdev->host;
37457 scsi_init_cmd_errh(cmd);
37458 cmd->result = DID_NO_CONNECT << 16;
37459 - atomic_inc(&cmd->device->iorequest_cnt);
37460 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37461
37462 /*
37463 * SCSI request completion path will do scsi_device_unbusy(),
37464 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37465
37466 INIT_LIST_HEAD(&cmd->eh_entry);
37467
37468 - atomic_inc(&cmd->device->iodone_cnt);
37469 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37470 if (cmd->result)
37471 - atomic_inc(&cmd->device->ioerr_cnt);
37472 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37473
37474 disposition = scsi_decide_disposition(cmd);
37475 if (disposition != SUCCESS &&
37476 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37477 index ce5224c..8c6d071 100644
37478 --- a/drivers/scsi/scsi_sysfs.c
37479 +++ b/drivers/scsi/scsi_sysfs.c
37480 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37481 char *buf) \
37482 { \
37483 struct scsi_device *sdev = to_scsi_device(dev); \
37484 - unsigned long long count = atomic_read(&sdev->field); \
37485 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37486 return snprintf(buf, 20, "0x%llx\n", count); \
37487 } \
37488 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37489 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37490 index 84a1fdf..693b0d6 100644
37491 --- a/drivers/scsi/scsi_tgt_lib.c
37492 +++ b/drivers/scsi/scsi_tgt_lib.c
37493 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37494 int err;
37495
37496 dprintk("%lx %u\n", uaddr, len);
37497 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37498 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37499 if (err) {
37500 /*
37501 * TODO: need to fixup sg_tablesize, max_segment_size,
37502 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37503 index e894ca7..de9d7660 100644
37504 --- a/drivers/scsi/scsi_transport_fc.c
37505 +++ b/drivers/scsi/scsi_transport_fc.c
37506 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37507 * Netlink Infrastructure
37508 */
37509
37510 -static atomic_t fc_event_seq;
37511 +static atomic_unchecked_t fc_event_seq;
37512
37513 /**
37514 * fc_get_event_number - Obtain the next sequential FC event number
37515 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37516 u32
37517 fc_get_event_number(void)
37518 {
37519 - return atomic_add_return(1, &fc_event_seq);
37520 + return atomic_add_return_unchecked(1, &fc_event_seq);
37521 }
37522 EXPORT_SYMBOL(fc_get_event_number);
37523
37524 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37525 {
37526 int error;
37527
37528 - atomic_set(&fc_event_seq, 0);
37529 + atomic_set_unchecked(&fc_event_seq, 0);
37530
37531 error = transport_class_register(&fc_host_class);
37532 if (error)
37533 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37534 char *cp;
37535
37536 *val = simple_strtoul(buf, &cp, 0);
37537 - if ((*cp && (*cp != '\n')) || (*val < 0))
37538 + if (*cp && (*cp != '\n'))
37539 return -EINVAL;
37540 /*
37541 * Check for overflow; dev_loss_tmo is u32
37542 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37543 index fa1dfaa..4bb620c 100644
37544 --- a/drivers/scsi/scsi_transport_iscsi.c
37545 +++ b/drivers/scsi/scsi_transport_iscsi.c
37546 @@ -79,7 +79,7 @@ struct iscsi_internal {
37547 struct transport_container session_cont;
37548 };
37549
37550 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37551 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37552 static struct workqueue_struct *iscsi_eh_timer_workq;
37553
37554 static DEFINE_IDA(iscsi_sess_ida);
37555 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37556 int err;
37557
37558 ihost = shost->shost_data;
37559 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37560 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37561
37562 if (target_id == ISCSI_MAX_TARGET) {
37563 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37564 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37565 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37566 ISCSI_TRANSPORT_VERSION);
37567
37568 - atomic_set(&iscsi_session_nr, 0);
37569 + atomic_set_unchecked(&iscsi_session_nr, 0);
37570
37571 err = class_register(&iscsi_transport_class);
37572 if (err)
37573 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37574 index 21a045e..ec89e03 100644
37575 --- a/drivers/scsi/scsi_transport_srp.c
37576 +++ b/drivers/scsi/scsi_transport_srp.c
37577 @@ -33,7 +33,7 @@
37578 #include "scsi_transport_srp_internal.h"
37579
37580 struct srp_host_attrs {
37581 - atomic_t next_port_id;
37582 + atomic_unchecked_t next_port_id;
37583 };
37584 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37585
37586 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37587 struct Scsi_Host *shost = dev_to_shost(dev);
37588 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37589
37590 - atomic_set(&srp_host->next_port_id, 0);
37591 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37592 return 0;
37593 }
37594
37595 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37596 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37597 rport->roles = ids->roles;
37598
37599 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37600 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37601 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37602
37603 transport_setup_device(&rport->dev);
37604 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37605 index 4df73e5..b691c58 100644
37606 --- a/drivers/scsi/sd.c
37607 +++ b/drivers/scsi/sd.c
37608 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37609 sdkp->disk = gd;
37610 sdkp->index = index;
37611 atomic_set(&sdkp->openers, 0);
37612 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37613 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37614
37615 if (!sdp->request_queue->rq_timeout) {
37616 if (sdp->type != TYPE_MOD)
37617 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37618 index 9c5c5f2..8414557 100644
37619 --- a/drivers/scsi/sg.c
37620 +++ b/drivers/scsi/sg.c
37621 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37622 sdp->disk->disk_name,
37623 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37624 NULL,
37625 - (char *)arg);
37626 + (char __user *)arg);
37627 case BLKTRACESTART:
37628 return blk_trace_startstop(sdp->device->request_queue, 1);
37629 case BLKTRACESTOP:
37630 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37631 index 84c2861..ece0a31 100644
37632 --- a/drivers/spi/spi.c
37633 +++ b/drivers/spi/spi.c
37634 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37635 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37636
37637 /* portable code must never pass more than 32 bytes */
37638 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37639 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37640
37641 static u8 *buf;
37642
37643 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37644 index 34afc16..ffe44dd 100644
37645 --- a/drivers/staging/octeon/ethernet-rx.c
37646 +++ b/drivers/staging/octeon/ethernet-rx.c
37647 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37648 /* Increment RX stats for virtual ports */
37649 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37650 #ifdef CONFIG_64BIT
37651 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37652 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37653 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37654 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37655 #else
37656 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37657 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37658 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37659 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37660 #endif
37661 }
37662 netif_receive_skb(skb);
37663 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37664 dev->name);
37665 */
37666 #ifdef CONFIG_64BIT
37667 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37668 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37669 #else
37670 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37671 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37672 #endif
37673 dev_kfree_skb_irq(skb);
37674 }
37675 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37676 index 683bedc..86dba9a 100644
37677 --- a/drivers/staging/octeon/ethernet.c
37678 +++ b/drivers/staging/octeon/ethernet.c
37679 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37680 * since the RX tasklet also increments it.
37681 */
37682 #ifdef CONFIG_64BIT
37683 - atomic64_add(rx_status.dropped_packets,
37684 - (atomic64_t *)&priv->stats.rx_dropped);
37685 + atomic64_add_unchecked(rx_status.dropped_packets,
37686 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37687 #else
37688 - atomic_add(rx_status.dropped_packets,
37689 - (atomic_t *)&priv->stats.rx_dropped);
37690 + atomic_add_unchecked(rx_status.dropped_packets,
37691 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37692 #endif
37693 }
37694
37695 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37696 index dc23395..cf7e9b1 100644
37697 --- a/drivers/staging/rtl8712/rtl871x_io.h
37698 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37699 @@ -108,7 +108,7 @@ struct _io_ops {
37700 u8 *pmem);
37701 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37702 u8 *pmem);
37703 -};
37704 +} __no_const;
37705
37706 struct io_req {
37707 struct list_head list;
37708 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37709 index c7b5e8b..783d6cb 100644
37710 --- a/drivers/staging/sbe-2t3e3/netdev.c
37711 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37712 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37713 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37714
37715 if (rlen)
37716 - if (copy_to_user(data, &resp, rlen))
37717 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37718 return -EFAULT;
37719
37720 return 0;
37721 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37722 index 5d89c0f..9261317 100644
37723 --- a/drivers/staging/usbip/usbip_common.h
37724 +++ b/drivers/staging/usbip/usbip_common.h
37725 @@ -289,7 +289,7 @@ struct usbip_device {
37726 void (*shutdown)(struct usbip_device *);
37727 void (*reset)(struct usbip_device *);
37728 void (*unusable)(struct usbip_device *);
37729 - } eh_ops;
37730 + } __no_const eh_ops;
37731 };
37732
37733 #define kthread_get_run(threadfn, data, namefmt, ...) \
37734 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37735 index c66b8b3..a4a035b 100644
37736 --- a/drivers/staging/usbip/vhci.h
37737 +++ b/drivers/staging/usbip/vhci.h
37738 @@ -83,7 +83,7 @@ struct vhci_hcd {
37739 unsigned resuming:1;
37740 unsigned long re_timeout;
37741
37742 - atomic_t seqnum;
37743 + atomic_unchecked_t seqnum;
37744
37745 /*
37746 * NOTE:
37747 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37748 index 12a9a5f..afd8295 100644
37749 --- a/drivers/staging/usbip/vhci_hcd.c
37750 +++ b/drivers/staging/usbip/vhci_hcd.c
37751 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37752 return;
37753 }
37754
37755 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37756 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37757 if (priv->seqnum == 0xffff)
37758 dev_info(&urb->dev->dev, "seqnum max\n");
37759
37760 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37761 return -ENOMEM;
37762 }
37763
37764 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37765 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37766 if (unlink->seqnum == 0xffff)
37767 pr_info("seqnum max\n");
37768
37769 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37770 vdev->rhport = rhport;
37771 }
37772
37773 - atomic_set(&vhci->seqnum, 0);
37774 + atomic_set_unchecked(&vhci->seqnum, 0);
37775 spin_lock_init(&vhci->lock);
37776
37777 hcd->power_budget = 0; /* no limit */
37778 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37779 index f0eaf04..5a82e06 100644
37780 --- a/drivers/staging/usbip/vhci_rx.c
37781 +++ b/drivers/staging/usbip/vhci_rx.c
37782 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37783 if (!urb) {
37784 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37785 pr_info("max seqnum %d\n",
37786 - atomic_read(&the_controller->seqnum));
37787 + atomic_read_unchecked(&the_controller->seqnum));
37788 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37789 return;
37790 }
37791 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37792 index 6ac6f45..1b208ba 100644
37793 --- a/drivers/staging/vt6655/hostap.c
37794 +++ b/drivers/staging/vt6655/hostap.c
37795 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37796 *
37797 */
37798
37799 +static net_device_ops_no_const apdev_netdev_ops;
37800 +
37801 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37802 {
37803 PSDevice apdev_priv;
37804 struct net_device *dev = pDevice->dev;
37805 int ret;
37806 - const struct net_device_ops apdev_netdev_ops = {
37807 - .ndo_start_xmit = pDevice->tx_80211,
37808 - };
37809
37810 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37811
37812 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37813 *apdev_priv = *pDevice;
37814 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37815
37816 + /* only half broken now */
37817 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37818 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37819
37820 pDevice->apdev->type = ARPHRD_IEEE80211;
37821 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37822 index 682002a..35ed5cf 100644
37823 --- a/drivers/staging/vt6656/hostap.c
37824 +++ b/drivers/staging/vt6656/hostap.c
37825 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37826 *
37827 */
37828
37829 +static net_device_ops_no_const apdev_netdev_ops;
37830 +
37831 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37832 {
37833 PSDevice apdev_priv;
37834 struct net_device *dev = pDevice->dev;
37835 int ret;
37836 - const struct net_device_ops apdev_netdev_ops = {
37837 - .ndo_start_xmit = pDevice->tx_80211,
37838 - };
37839
37840 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37841
37842 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37843 *apdev_priv = *pDevice;
37844 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37845
37846 + /* only half broken now */
37847 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37848 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37849
37850 pDevice->apdev->type = ARPHRD_IEEE80211;
37851 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37852 index 7843dfd..3db105f 100644
37853 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37854 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37855 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37856
37857 struct usbctlx_completor {
37858 int (*complete) (struct usbctlx_completor *);
37859 -};
37860 +} __no_const;
37861
37862 static int
37863 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37864 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37865 index eaa9021..43f023b 100644
37866 --- a/drivers/staging/zcache/tmem.c
37867 +++ b/drivers/staging/zcache/tmem.c
37868 @@ -39,7 +39,7 @@
37869 * A tmem host implementation must use this function to register callbacks
37870 * for memory allocation.
37871 */
37872 -static struct tmem_hostops tmem_hostops;
37873 +static tmem_hostops_no_const tmem_hostops;
37874
37875 static void tmem_objnode_tree_init(void);
37876
37877 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37878 * A tmem host implementation must use this function to register
37879 * callbacks for a page-accessible memory (PAM) implementation
37880 */
37881 -static struct tmem_pamops tmem_pamops;
37882 +static tmem_pamops_no_const tmem_pamops;
37883
37884 void tmem_register_pamops(struct tmem_pamops *m)
37885 {
37886 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37887 index 0d4aa82..f7832d4 100644
37888 --- a/drivers/staging/zcache/tmem.h
37889 +++ b/drivers/staging/zcache/tmem.h
37890 @@ -180,6 +180,7 @@ struct tmem_pamops {
37891 void (*new_obj)(struct tmem_obj *);
37892 int (*replace_in_obj)(void *, struct tmem_obj *);
37893 };
37894 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37895 extern void tmem_register_pamops(struct tmem_pamops *m);
37896
37897 /* memory allocation methods provided by the host implementation */
37898 @@ -189,6 +190,7 @@ struct tmem_hostops {
37899 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37900 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37901 };
37902 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37903 extern void tmem_register_hostops(struct tmem_hostops *m);
37904
37905 /* core tmem accessor functions */
37906 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
37907 index 9fc9a60..68d4c10 100644
37908 --- a/drivers/target/target_core_device.c
37909 +++ b/drivers/target/target_core_device.c
37910 @@ -850,20 +850,20 @@ int se_dev_check_shutdown(struct se_device *dev)
37911
37912 static u32 se_dev_align_max_sectors(u32 max_sectors, u32 block_size)
37913 {
37914 - u32 tmp, aligned_max_sectors;
37915 + u32 aligned_max_sectors;
37916 + u32 alignment;
37917 /*
37918 * Limit max_sectors to a PAGE_SIZE aligned value for modern
37919 * transport_allocate_data_tasks() operation.
37920 */
37921 - tmp = rounddown((max_sectors * block_size), PAGE_SIZE);
37922 - aligned_max_sectors = (tmp / block_size);
37923 - if (max_sectors != aligned_max_sectors) {
37924 - printk(KERN_INFO "Rounding down aligned max_sectors from %u"
37925 - " to %u\n", max_sectors, aligned_max_sectors);
37926 - return aligned_max_sectors;
37927 - }
37928 + alignment = max(1ul, PAGE_SIZE / block_size);
37929 + aligned_max_sectors = rounddown(max_sectors, alignment);
37930
37931 - return max_sectors;
37932 + if (max_sectors != aligned_max_sectors)
37933 + pr_info("Rounding down aligned max_sectors from %u to %u\n",
37934 + max_sectors, aligned_max_sectors);
37935 +
37936 + return aligned_max_sectors;
37937 }
37938
37939 void se_dev_set_default_attribs(
37940 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37941 index 269f544..32def0d 100644
37942 --- a/drivers/target/target_core_transport.c
37943 +++ b/drivers/target/target_core_transport.c
37944 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37945 spin_lock_init(&dev->se_port_lock);
37946 spin_lock_init(&dev->se_tmr_lock);
37947 spin_lock_init(&dev->qf_cmd_lock);
37948 - atomic_set(&dev->dev_ordered_id, 0);
37949 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37950
37951 se_dev_set_default_attribs(dev, dev_limits);
37952
37953 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37954 * Used to determine when ORDERED commands should go from
37955 * Dormant to Active status.
37956 */
37957 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37958 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37959 smp_mb__after_atomic_inc();
37960 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37961 cmd->se_ordered_id, cmd->sam_task_attr,
37962 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37963 index e61cabd..7617d26 100644
37964 --- a/drivers/tty/cyclades.c
37965 +++ b/drivers/tty/cyclades.c
37966 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37967 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37968 info->port.count);
37969 #endif
37970 - info->port.count++;
37971 + atomic_inc(&info->port.count);
37972 #ifdef CY_DEBUG_COUNT
37973 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37974 - current->pid, info->port.count);
37975 + current->pid, atomic_read(&info->port.count));
37976 #endif
37977
37978 /*
37979 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37980 for (j = 0; j < cy_card[i].nports; j++) {
37981 info = &cy_card[i].ports[j];
37982
37983 - if (info->port.count) {
37984 + if (atomic_read(&info->port.count)) {
37985 /* XXX is the ldisc num worth this? */
37986 struct tty_struct *tty;
37987 struct tty_ldisc *ld;
37988 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37989 index 2d691eb..be02ebd 100644
37990 --- a/drivers/tty/hvc/hvc_console.c
37991 +++ b/drivers/tty/hvc/hvc_console.c
37992 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37993
37994 spin_lock_irqsave(&hp->port.lock, flags);
37995 /* Check and then increment for fast path open. */
37996 - if (hp->port.count++ > 0) {
37997 + if (atomic_inc_return(&hp->port.count) > 1) {
37998 spin_unlock_irqrestore(&hp->port.lock, flags);
37999 hvc_kick();
38000 return 0;
38001 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38002
38003 spin_lock_irqsave(&hp->port.lock, flags);
38004
38005 - if (--hp->port.count == 0) {
38006 + if (atomic_dec_return(&hp->port.count) == 0) {
38007 spin_unlock_irqrestore(&hp->port.lock, flags);
38008 /* We are done with the tty pointer now. */
38009 tty_port_tty_set(&hp->port, NULL);
38010 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38011 */
38012 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38013 } else {
38014 - if (hp->port.count < 0)
38015 + if (atomic_read(&hp->port.count) < 0)
38016 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38017 - hp->vtermno, hp->port.count);
38018 + hp->vtermno, atomic_read(&hp->port.count));
38019 spin_unlock_irqrestore(&hp->port.lock, flags);
38020 }
38021
38022 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38023 * open->hangup case this can be called after the final close so prevent
38024 * that from happening for now.
38025 */
38026 - if (hp->port.count <= 0) {
38027 + if (atomic_read(&hp->port.count) <= 0) {
38028 spin_unlock_irqrestore(&hp->port.lock, flags);
38029 return;
38030 }
38031
38032 - temp_open_count = hp->port.count;
38033 - hp->port.count = 0;
38034 + temp_open_count = atomic_read(&hp->port.count);
38035 + atomic_set(&hp->port.count, 0);
38036 spin_unlock_irqrestore(&hp->port.lock, flags);
38037 tty_port_tty_set(&hp->port, NULL);
38038
38039 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38040 return -EPIPE;
38041
38042 /* FIXME what's this (unprotected) check for? */
38043 - if (hp->port.count <= 0)
38044 + if (atomic_read(&hp->port.count) <= 0)
38045 return -EIO;
38046
38047 spin_lock_irqsave(&hp->lock, flags);
38048 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38049 index d56788c..12d8f85 100644
38050 --- a/drivers/tty/hvc/hvcs.c
38051 +++ b/drivers/tty/hvc/hvcs.c
38052 @@ -83,6 +83,7 @@
38053 #include <asm/hvcserver.h>
38054 #include <asm/uaccess.h>
38055 #include <asm/vio.h>
38056 +#include <asm/local.h>
38057
38058 /*
38059 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38060 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38061
38062 spin_lock_irqsave(&hvcsd->lock, flags);
38063
38064 - if (hvcsd->port.count > 0) {
38065 + if (atomic_read(&hvcsd->port.count) > 0) {
38066 spin_unlock_irqrestore(&hvcsd->lock, flags);
38067 printk(KERN_INFO "HVCS: vterm state unchanged. "
38068 "The hvcs device node is still in use.\n");
38069 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38070 if ((retval = hvcs_partner_connect(hvcsd)))
38071 goto error_release;
38072
38073 - hvcsd->port.count = 1;
38074 + atomic_set(&hvcsd->port.count, 1);
38075 hvcsd->port.tty = tty;
38076 tty->driver_data = hvcsd;
38077
38078 @@ -1168,7 +1169,7 @@ fast_open:
38079
38080 spin_lock_irqsave(&hvcsd->lock, flags);
38081 tty_port_get(&hvcsd->port);
38082 - hvcsd->port.count++;
38083 + atomic_inc(&hvcsd->port.count);
38084 hvcsd->todo_mask |= HVCS_SCHED_READ;
38085 spin_unlock_irqrestore(&hvcsd->lock, flags);
38086
38087 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38088 hvcsd = tty->driver_data;
38089
38090 spin_lock_irqsave(&hvcsd->lock, flags);
38091 - if (--hvcsd->port.count == 0) {
38092 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38093
38094 vio_disable_interrupts(hvcsd->vdev);
38095
38096 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38097 free_irq(irq, hvcsd);
38098 tty_port_put(&hvcsd->port);
38099 return;
38100 - } else if (hvcsd->port.count < 0) {
38101 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38102 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38103 " is missmanaged.\n",
38104 - hvcsd->vdev->unit_address, hvcsd->port.count);
38105 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38106 }
38107
38108 spin_unlock_irqrestore(&hvcsd->lock, flags);
38109 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38110
38111 spin_lock_irqsave(&hvcsd->lock, flags);
38112 /* Preserve this so that we know how many kref refs to put */
38113 - temp_open_count = hvcsd->port.count;
38114 + temp_open_count = atomic_read(&hvcsd->port.count);
38115
38116 /*
38117 * Don't kref put inside the spinlock because the destruction
38118 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38119 tty->driver_data = NULL;
38120 hvcsd->port.tty = NULL;
38121
38122 - hvcsd->port.count = 0;
38123 + atomic_set(&hvcsd->port.count, 0);
38124
38125 /* This will drop any buffered data on the floor which is OK in a hangup
38126 * scenario. */
38127 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38128 * the middle of a write operation? This is a crummy place to do this
38129 * but we want to keep it all in the spinlock.
38130 */
38131 - if (hvcsd->port.count <= 0) {
38132 + if (atomic_read(&hvcsd->port.count) <= 0) {
38133 spin_unlock_irqrestore(&hvcsd->lock, flags);
38134 return -ENODEV;
38135 }
38136 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38137 {
38138 struct hvcs_struct *hvcsd = tty->driver_data;
38139
38140 - if (!hvcsd || hvcsd->port.count <= 0)
38141 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38142 return 0;
38143
38144 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38145 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38146 index f8b5fa0..4ba9f89 100644
38147 --- a/drivers/tty/ipwireless/tty.c
38148 +++ b/drivers/tty/ipwireless/tty.c
38149 @@ -29,6 +29,7 @@
38150 #include <linux/tty_driver.h>
38151 #include <linux/tty_flip.h>
38152 #include <linux/uaccess.h>
38153 +#include <asm/local.h>
38154
38155 #include "tty.h"
38156 #include "network.h"
38157 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38158 mutex_unlock(&tty->ipw_tty_mutex);
38159 return -ENODEV;
38160 }
38161 - if (tty->port.count == 0)
38162 + if (atomic_read(&tty->port.count) == 0)
38163 tty->tx_bytes_queued = 0;
38164
38165 - tty->port.count++;
38166 + atomic_inc(&tty->port.count);
38167
38168 tty->port.tty = linux_tty;
38169 linux_tty->driver_data = tty;
38170 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38171
38172 static void do_ipw_close(struct ipw_tty *tty)
38173 {
38174 - tty->port.count--;
38175 -
38176 - if (tty->port.count == 0) {
38177 + if (atomic_dec_return(&tty->port.count) == 0) {
38178 struct tty_struct *linux_tty = tty->port.tty;
38179
38180 if (linux_tty != NULL) {
38181 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38182 return;
38183
38184 mutex_lock(&tty->ipw_tty_mutex);
38185 - if (tty->port.count == 0) {
38186 + if (atomic_read(&tty->port.count) == 0) {
38187 mutex_unlock(&tty->ipw_tty_mutex);
38188 return;
38189 }
38190 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38191 return;
38192 }
38193
38194 - if (!tty->port.count) {
38195 + if (!atomic_read(&tty->port.count)) {
38196 mutex_unlock(&tty->ipw_tty_mutex);
38197 return;
38198 }
38199 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38200 return -ENODEV;
38201
38202 mutex_lock(&tty->ipw_tty_mutex);
38203 - if (!tty->port.count) {
38204 + if (!atomic_read(&tty->port.count)) {
38205 mutex_unlock(&tty->ipw_tty_mutex);
38206 return -EINVAL;
38207 }
38208 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38209 if (!tty)
38210 return -ENODEV;
38211
38212 - if (!tty->port.count)
38213 + if (!atomic_read(&tty->port.count))
38214 return -EINVAL;
38215
38216 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38217 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38218 if (!tty)
38219 return 0;
38220
38221 - if (!tty->port.count)
38222 + if (!atomic_read(&tty->port.count))
38223 return 0;
38224
38225 return tty->tx_bytes_queued;
38226 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38227 if (!tty)
38228 return -ENODEV;
38229
38230 - if (!tty->port.count)
38231 + if (!atomic_read(&tty->port.count))
38232 return -EINVAL;
38233
38234 return get_control_lines(tty);
38235 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38236 if (!tty)
38237 return -ENODEV;
38238
38239 - if (!tty->port.count)
38240 + if (!atomic_read(&tty->port.count))
38241 return -EINVAL;
38242
38243 return set_control_lines(tty, set, clear);
38244 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38245 if (!tty)
38246 return -ENODEV;
38247
38248 - if (!tty->port.count)
38249 + if (!atomic_read(&tty->port.count))
38250 return -EINVAL;
38251
38252 /* FIXME: Exactly how is the tty object locked here .. */
38253 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38254 * are gone */
38255 mutex_lock(&ttyj->ipw_tty_mutex);
38256 }
38257 - while (ttyj->port.count)
38258 + while (atomic_read(&ttyj->port.count))
38259 do_ipw_close(ttyj);
38260 ipwireless_disassociate_network_ttys(network,
38261 ttyj->channel_idx);
38262 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38263 index 324467d..504cc25 100644
38264 --- a/drivers/tty/moxa.c
38265 +++ b/drivers/tty/moxa.c
38266 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38267 }
38268
38269 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38270 - ch->port.count++;
38271 + atomic_inc(&ch->port.count);
38272 tty->driver_data = ch;
38273 tty_port_tty_set(&ch->port, tty);
38274 mutex_lock(&ch->port.mutex);
38275 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38276 index 90dff82..08119c3 100644
38277 --- a/drivers/tty/n_gsm.c
38278 +++ b/drivers/tty/n_gsm.c
38279 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38280 kref_init(&dlci->ref);
38281 mutex_init(&dlci->mutex);
38282 dlci->fifo = &dlci->_fifo;
38283 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38284 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38285 kfree(dlci);
38286 return NULL;
38287 }
38288 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38289 if (dlci == NULL)
38290 return -ENOMEM;
38291 port = &dlci->port;
38292 - port->count++;
38293 + atomic_inc(&port->count);
38294 tty->driver_data = dlci;
38295 dlci_get(dlci);
38296 dlci_get(dlci->gsm->dlci[0]);
38297 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38298 index 26f0d0e..b7c4273 100644
38299 --- a/drivers/tty/n_tty.c
38300 +++ b/drivers/tty/n_tty.c
38301 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38302 {
38303 *ops = tty_ldisc_N_TTY;
38304 ops->owner = NULL;
38305 - ops->refcount = ops->flags = 0;
38306 + atomic_set(&ops->refcount, 0);
38307 + ops->flags = 0;
38308 }
38309 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38310 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38311 index 5505ffc..7affff9 100644
38312 --- a/drivers/tty/pty.c
38313 +++ b/drivers/tty/pty.c
38314 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38315 panic("Couldn't register Unix98 pts driver");
38316
38317 /* Now create the /dev/ptmx special device */
38318 + pax_open_kernel();
38319 tty_default_fops(&ptmx_fops);
38320 - ptmx_fops.open = ptmx_open;
38321 + *(void **)&ptmx_fops.open = ptmx_open;
38322 + pax_close_kernel();
38323
38324 cdev_init(&ptmx_cdev, &ptmx_fops);
38325 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38326 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38327 index 777d5f9..56d67ca 100644
38328 --- a/drivers/tty/rocket.c
38329 +++ b/drivers/tty/rocket.c
38330 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38331 tty->driver_data = info;
38332 tty_port_tty_set(port, tty);
38333
38334 - if (port->count++ == 0) {
38335 + if (atomic_inc_return(&port->count) == 1) {
38336 atomic_inc(&rp_num_ports_open);
38337
38338 #ifdef ROCKET_DEBUG_OPEN
38339 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38340 #endif
38341 }
38342 #ifdef ROCKET_DEBUG_OPEN
38343 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38344 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38345 #endif
38346
38347 /*
38348 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38349 spin_unlock_irqrestore(&info->port.lock, flags);
38350 return;
38351 }
38352 - if (info->port.count)
38353 + if (atomic_read(&info->port.count))
38354 atomic_dec(&rp_num_ports_open);
38355 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38356 spin_unlock_irqrestore(&info->port.lock, flags);
38357 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38358 index 2b42a01..32a2ed3 100644
38359 --- a/drivers/tty/serial/kgdboc.c
38360 +++ b/drivers/tty/serial/kgdboc.c
38361 @@ -24,8 +24,9 @@
38362 #define MAX_CONFIG_LEN 40
38363
38364 static struct kgdb_io kgdboc_io_ops;
38365 +static struct kgdb_io kgdboc_io_ops_console;
38366
38367 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38368 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38369 static int configured = -1;
38370
38371 static char config[MAX_CONFIG_LEN];
38372 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38373 kgdboc_unregister_kbd();
38374 if (configured == 1)
38375 kgdb_unregister_io_module(&kgdboc_io_ops);
38376 + else if (configured == 2)
38377 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38378 }
38379
38380 static int configure_kgdboc(void)
38381 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38382 int err;
38383 char *cptr = config;
38384 struct console *cons;
38385 + int is_console = 0;
38386
38387 err = kgdboc_option_setup(config);
38388 if (err || !strlen(config) || isspace(config[0]))
38389 goto noconfig;
38390
38391 err = -ENODEV;
38392 - kgdboc_io_ops.is_console = 0;
38393 kgdb_tty_driver = NULL;
38394
38395 kgdboc_use_kms = 0;
38396 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38397 int idx;
38398 if (cons->device && cons->device(cons, &idx) == p &&
38399 idx == tty_line) {
38400 - kgdboc_io_ops.is_console = 1;
38401 + is_console = 1;
38402 break;
38403 }
38404 cons = cons->next;
38405 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38406 kgdb_tty_line = tty_line;
38407
38408 do_register:
38409 - err = kgdb_register_io_module(&kgdboc_io_ops);
38410 + if (is_console) {
38411 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38412 + configured = 2;
38413 + } else {
38414 + err = kgdb_register_io_module(&kgdboc_io_ops);
38415 + configured = 1;
38416 + }
38417 if (err)
38418 goto noconfig;
38419
38420 - configured = 1;
38421 -
38422 return 0;
38423
38424 noconfig:
38425 @@ -213,7 +220,7 @@ noconfig:
38426 static int __init init_kgdboc(void)
38427 {
38428 /* Already configured? */
38429 - if (configured == 1)
38430 + if (configured >= 1)
38431 return 0;
38432
38433 return configure_kgdboc();
38434 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38435 if (config[len - 1] == '\n')
38436 config[len - 1] = '\0';
38437
38438 - if (configured == 1)
38439 + if (configured >= 1)
38440 cleanup_kgdboc();
38441
38442 /* Go and configure with the new params. */
38443 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38444 .post_exception = kgdboc_post_exp_handler,
38445 };
38446
38447 +static struct kgdb_io kgdboc_io_ops_console = {
38448 + .name = "kgdboc",
38449 + .read_char = kgdboc_get_char,
38450 + .write_char = kgdboc_put_char,
38451 + .pre_exception = kgdboc_pre_exp_handler,
38452 + .post_exception = kgdboc_post_exp_handler,
38453 + .is_console = 1
38454 +};
38455 +
38456 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38457 /* This is only available if kgdboc is a built in for early debugging */
38458 static int __init kgdboc_early_init(char *opt)
38459 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38460 index a21dc8e..fe43e9e 100644
38461 --- a/drivers/tty/serial/serial_core.c
38462 +++ b/drivers/tty/serial/serial_core.c
38463 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38464 uart_flush_buffer(tty);
38465 uart_shutdown(tty, state);
38466 spin_lock_irqsave(&port->lock, flags);
38467 - port->count = 0;
38468 + atomic_set(&port->count, 0);
38469 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38470 spin_unlock_irqrestore(&port->lock, flags);
38471 tty_port_tty_set(port, NULL);
38472 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38473 goto end;
38474 }
38475
38476 - port->count++;
38477 + atomic_inc(&port->count);
38478 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38479 retval = -ENXIO;
38480 goto err_dec_count;
38481 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38482 /*
38483 * Make sure the device is in D0 state.
38484 */
38485 - if (port->count == 1)
38486 + if (atomic_read(&port->count) == 1)
38487 uart_change_pm(state, 0);
38488
38489 /*
38490 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38491 end:
38492 return retval;
38493 err_dec_count:
38494 - port->count--;
38495 + atomic_inc(&port->count);
38496 mutex_unlock(&port->mutex);
38497 goto end;
38498 }
38499 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38500 index 593d40a..bdc61f3 100644
38501 --- a/drivers/tty/synclink.c
38502 +++ b/drivers/tty/synclink.c
38503 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38504
38505 if (debug_level >= DEBUG_LEVEL_INFO)
38506 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38507 - __FILE__,__LINE__, info->device_name, info->port.count);
38508 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38509
38510 if (tty_port_close_start(&info->port, tty, filp) == 0)
38511 goto cleanup;
38512 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38513 cleanup:
38514 if (debug_level >= DEBUG_LEVEL_INFO)
38515 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38516 - tty->driver->name, info->port.count);
38517 + tty->driver->name, atomic_read(&info->port.count));
38518
38519 } /* end of mgsl_close() */
38520
38521 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38522
38523 mgsl_flush_buffer(tty);
38524 shutdown(info);
38525 -
38526 - info->port.count = 0;
38527 +
38528 + atomic_set(&info->port.count, 0);
38529 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38530 info->port.tty = NULL;
38531
38532 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38533
38534 if (debug_level >= DEBUG_LEVEL_INFO)
38535 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38536 - __FILE__,__LINE__, tty->driver->name, port->count );
38537 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38538
38539 spin_lock_irqsave(&info->irq_spinlock, flags);
38540 if (!tty_hung_up_p(filp)) {
38541 extra_count = true;
38542 - port->count--;
38543 + atomic_dec(&port->count);
38544 }
38545 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38546 port->blocked_open++;
38547 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38548
38549 if (debug_level >= DEBUG_LEVEL_INFO)
38550 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38551 - __FILE__,__LINE__, tty->driver->name, port->count );
38552 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38553
38554 tty_unlock();
38555 schedule();
38556 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38557
38558 /* FIXME: Racy on hangup during close wait */
38559 if (extra_count)
38560 - port->count++;
38561 + atomic_inc(&port->count);
38562 port->blocked_open--;
38563
38564 if (debug_level >= DEBUG_LEVEL_INFO)
38565 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38566 - __FILE__,__LINE__, tty->driver->name, port->count );
38567 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38568
38569 if (!retval)
38570 port->flags |= ASYNC_NORMAL_ACTIVE;
38571 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38572
38573 if (debug_level >= DEBUG_LEVEL_INFO)
38574 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38575 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38576 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38577
38578 /* If port is closing, signal caller to try again */
38579 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38580 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38581 spin_unlock_irqrestore(&info->netlock, flags);
38582 goto cleanup;
38583 }
38584 - info->port.count++;
38585 + atomic_inc(&info->port.count);
38586 spin_unlock_irqrestore(&info->netlock, flags);
38587
38588 - if (info->port.count == 1) {
38589 + if (atomic_read(&info->port.count) == 1) {
38590 /* 1st open on this device, init hardware */
38591 retval = startup(info);
38592 if (retval < 0)
38593 @@ -3444,8 +3444,8 @@ cleanup:
38594 if (retval) {
38595 if (tty->count == 1)
38596 info->port.tty = NULL; /* tty layer will release tty struct */
38597 - if(info->port.count)
38598 - info->port.count--;
38599 + if (atomic_read(&info->port.count))
38600 + atomic_dec(&info->port.count);
38601 }
38602
38603 return retval;
38604 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38605 unsigned short new_crctype;
38606
38607 /* return error if TTY interface open */
38608 - if (info->port.count)
38609 + if (atomic_read(&info->port.count))
38610 return -EBUSY;
38611
38612 switch (encoding)
38613 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38614
38615 /* arbitrate between network and tty opens */
38616 spin_lock_irqsave(&info->netlock, flags);
38617 - if (info->port.count != 0 || info->netcount != 0) {
38618 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38619 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38620 spin_unlock_irqrestore(&info->netlock, flags);
38621 return -EBUSY;
38622 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38623 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38624
38625 /* return error if TTY interface open */
38626 - if (info->port.count)
38627 + if (atomic_read(&info->port.count))
38628 return -EBUSY;
38629
38630 if (cmd != SIOCWANDEV)
38631 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38632 index aa1debf..9297a16 100644
38633 --- a/drivers/tty/synclink_gt.c
38634 +++ b/drivers/tty/synclink_gt.c
38635 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38636 tty->driver_data = info;
38637 info->port.tty = tty;
38638
38639 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38640 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38641
38642 /* If port is closing, signal caller to try again */
38643 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38644 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38645 mutex_unlock(&info->port.mutex);
38646 goto cleanup;
38647 }
38648 - info->port.count++;
38649 + atomic_inc(&info->port.count);
38650 spin_unlock_irqrestore(&info->netlock, flags);
38651
38652 - if (info->port.count == 1) {
38653 + if (atomic_read(&info->port.count) == 1) {
38654 /* 1st open on this device, init hardware */
38655 retval = startup(info);
38656 if (retval < 0) {
38657 @@ -716,8 +716,8 @@ cleanup:
38658 if (retval) {
38659 if (tty->count == 1)
38660 info->port.tty = NULL; /* tty layer will release tty struct */
38661 - if(info->port.count)
38662 - info->port.count--;
38663 + if(atomic_read(&info->port.count))
38664 + atomic_dec(&info->port.count);
38665 }
38666
38667 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38668 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38669
38670 if (sanity_check(info, tty->name, "close"))
38671 return;
38672 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38673 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38674
38675 if (tty_port_close_start(&info->port, tty, filp) == 0)
38676 goto cleanup;
38677 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38678 tty_port_close_end(&info->port, tty);
38679 info->port.tty = NULL;
38680 cleanup:
38681 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38682 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38683 }
38684
38685 static void hangup(struct tty_struct *tty)
38686 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38687 shutdown(info);
38688
38689 spin_lock_irqsave(&info->port.lock, flags);
38690 - info->port.count = 0;
38691 + atomic_set(&info->port.count, 0);
38692 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38693 info->port.tty = NULL;
38694 spin_unlock_irqrestore(&info->port.lock, flags);
38695 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38696 unsigned short new_crctype;
38697
38698 /* return error if TTY interface open */
38699 - if (info->port.count)
38700 + if (atomic_read(&info->port.count))
38701 return -EBUSY;
38702
38703 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38704 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38705
38706 /* arbitrate between network and tty opens */
38707 spin_lock_irqsave(&info->netlock, flags);
38708 - if (info->port.count != 0 || info->netcount != 0) {
38709 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38710 DBGINFO(("%s hdlc_open busy\n", dev->name));
38711 spin_unlock_irqrestore(&info->netlock, flags);
38712 return -EBUSY;
38713 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38714 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38715
38716 /* return error if TTY interface open */
38717 - if (info->port.count)
38718 + if (atomic_read(&info->port.count))
38719 return -EBUSY;
38720
38721 if (cmd != SIOCWANDEV)
38722 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38723 if (port == NULL)
38724 continue;
38725 spin_lock(&port->lock);
38726 - if ((port->port.count || port->netcount) &&
38727 + if ((atomic_read(&port->port.count) || port->netcount) &&
38728 port->pending_bh && !port->bh_running &&
38729 !port->bh_requested) {
38730 DBGISR(("%s bh queued\n", port->device_name));
38731 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38732 spin_lock_irqsave(&info->lock, flags);
38733 if (!tty_hung_up_p(filp)) {
38734 extra_count = true;
38735 - port->count--;
38736 + atomic_dec(&port->count);
38737 }
38738 spin_unlock_irqrestore(&info->lock, flags);
38739 port->blocked_open++;
38740 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38741 remove_wait_queue(&port->open_wait, &wait);
38742
38743 if (extra_count)
38744 - port->count++;
38745 + atomic_inc(&port->count);
38746 port->blocked_open--;
38747
38748 if (!retval)
38749 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38750 index a3dddc1..8905ab2 100644
38751 --- a/drivers/tty/synclinkmp.c
38752 +++ b/drivers/tty/synclinkmp.c
38753 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38754
38755 if (debug_level >= DEBUG_LEVEL_INFO)
38756 printk("%s(%d):%s open(), old ref count = %d\n",
38757 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38758 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38759
38760 /* If port is closing, signal caller to try again */
38761 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38762 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38763 spin_unlock_irqrestore(&info->netlock, flags);
38764 goto cleanup;
38765 }
38766 - info->port.count++;
38767 + atomic_inc(&info->port.count);
38768 spin_unlock_irqrestore(&info->netlock, flags);
38769
38770 - if (info->port.count == 1) {
38771 + if (atomic_read(&info->port.count) == 1) {
38772 /* 1st open on this device, init hardware */
38773 retval = startup(info);
38774 if (retval < 0)
38775 @@ -788,8 +788,8 @@ cleanup:
38776 if (retval) {
38777 if (tty->count == 1)
38778 info->port.tty = NULL; /* tty layer will release tty struct */
38779 - if(info->port.count)
38780 - info->port.count--;
38781 + if(atomic_read(&info->port.count))
38782 + atomic_dec(&info->port.count);
38783 }
38784
38785 return retval;
38786 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38787
38788 if (debug_level >= DEBUG_LEVEL_INFO)
38789 printk("%s(%d):%s close() entry, count=%d\n",
38790 - __FILE__,__LINE__, info->device_name, info->port.count);
38791 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38792
38793 if (tty_port_close_start(&info->port, tty, filp) == 0)
38794 goto cleanup;
38795 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38796 cleanup:
38797 if (debug_level >= DEBUG_LEVEL_INFO)
38798 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38799 - tty->driver->name, info->port.count);
38800 + tty->driver->name, atomic_read(&info->port.count));
38801 }
38802
38803 /* Called by tty_hangup() when a hangup is signaled.
38804 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38805 shutdown(info);
38806
38807 spin_lock_irqsave(&info->port.lock, flags);
38808 - info->port.count = 0;
38809 + atomic_set(&info->port.count, 0);
38810 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38811 info->port.tty = NULL;
38812 spin_unlock_irqrestore(&info->port.lock, flags);
38813 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38814 unsigned short new_crctype;
38815
38816 /* return error if TTY interface open */
38817 - if (info->port.count)
38818 + if (atomic_read(&info->port.count))
38819 return -EBUSY;
38820
38821 switch (encoding)
38822 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38823
38824 /* arbitrate between network and tty opens */
38825 spin_lock_irqsave(&info->netlock, flags);
38826 - if (info->port.count != 0 || info->netcount != 0) {
38827 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38828 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38829 spin_unlock_irqrestore(&info->netlock, flags);
38830 return -EBUSY;
38831 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38832 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38833
38834 /* return error if TTY interface open */
38835 - if (info->port.count)
38836 + if (atomic_read(&info->port.count))
38837 return -EBUSY;
38838
38839 if (cmd != SIOCWANDEV)
38840 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38841 * do not request bottom half processing if the
38842 * device is not open in a normal mode.
38843 */
38844 - if ( port && (port->port.count || port->netcount) &&
38845 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38846 port->pending_bh && !port->bh_running &&
38847 !port->bh_requested ) {
38848 if ( debug_level >= DEBUG_LEVEL_ISR )
38849 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38850
38851 if (debug_level >= DEBUG_LEVEL_INFO)
38852 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38853 - __FILE__,__LINE__, tty->driver->name, port->count );
38854 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38855
38856 spin_lock_irqsave(&info->lock, flags);
38857 if (!tty_hung_up_p(filp)) {
38858 extra_count = true;
38859 - port->count--;
38860 + atomic_dec(&port->count);
38861 }
38862 spin_unlock_irqrestore(&info->lock, flags);
38863 port->blocked_open++;
38864 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38865
38866 if (debug_level >= DEBUG_LEVEL_INFO)
38867 printk("%s(%d):%s block_til_ready() count=%d\n",
38868 - __FILE__,__LINE__, tty->driver->name, port->count );
38869 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38870
38871 tty_unlock();
38872 schedule();
38873 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38874 remove_wait_queue(&port->open_wait, &wait);
38875
38876 if (extra_count)
38877 - port->count++;
38878 + atomic_inc(&port->count);
38879 port->blocked_open--;
38880
38881 if (debug_level >= DEBUG_LEVEL_INFO)
38882 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38883 - __FILE__,__LINE__, tty->driver->name, port->count );
38884 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38885
38886 if (!retval)
38887 port->flags |= ASYNC_NORMAL_ACTIVE;
38888 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38889 index 05728894..b9d44c6 100644
38890 --- a/drivers/tty/sysrq.c
38891 +++ b/drivers/tty/sysrq.c
38892 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38893 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38894 size_t count, loff_t *ppos)
38895 {
38896 - if (count) {
38897 + if (count && capable(CAP_SYS_ADMIN)) {
38898 char c;
38899
38900 if (get_user(c, buf))
38901 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38902 index b425c79..08a3f06 100644
38903 --- a/drivers/tty/tty_io.c
38904 +++ b/drivers/tty/tty_io.c
38905 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38906
38907 void tty_default_fops(struct file_operations *fops)
38908 {
38909 - *fops = tty_fops;
38910 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38911 }
38912
38913 /*
38914 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38915 index 6f99c99..8947bc4 100644
38916 --- a/drivers/tty/tty_ldisc.c
38917 +++ b/drivers/tty/tty_ldisc.c
38918 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38919 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38920 struct tty_ldisc_ops *ldo = ld->ops;
38921
38922 - ldo->refcount--;
38923 + atomic_dec(&ldo->refcount);
38924 module_put(ldo->owner);
38925 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38926
38927 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38928 spin_lock_irqsave(&tty_ldisc_lock, flags);
38929 tty_ldiscs[disc] = new_ldisc;
38930 new_ldisc->num = disc;
38931 - new_ldisc->refcount = 0;
38932 + atomic_set(&new_ldisc->refcount, 0);
38933 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38934
38935 return ret;
38936 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38937 return -EINVAL;
38938
38939 spin_lock_irqsave(&tty_ldisc_lock, flags);
38940 - if (tty_ldiscs[disc]->refcount)
38941 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38942 ret = -EBUSY;
38943 else
38944 tty_ldiscs[disc] = NULL;
38945 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38946 if (ldops) {
38947 ret = ERR_PTR(-EAGAIN);
38948 if (try_module_get(ldops->owner)) {
38949 - ldops->refcount++;
38950 + atomic_inc(&ldops->refcount);
38951 ret = ldops;
38952 }
38953 }
38954 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38955 unsigned long flags;
38956
38957 spin_lock_irqsave(&tty_ldisc_lock, flags);
38958 - ldops->refcount--;
38959 + atomic_dec(&ldops->refcount);
38960 module_put(ldops->owner);
38961 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38962 }
38963 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38964 index bf6e238..d401c04 100644
38965 --- a/drivers/tty/tty_port.c
38966 +++ b/drivers/tty/tty_port.c
38967 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38968 unsigned long flags;
38969
38970 spin_lock_irqsave(&port->lock, flags);
38971 - port->count = 0;
38972 + atomic_set(&port->count, 0);
38973 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38974 if (port->tty) {
38975 set_bit(TTY_IO_ERROR, &port->tty->flags);
38976 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38977 /* The port lock protects the port counts */
38978 spin_lock_irqsave(&port->lock, flags);
38979 if (!tty_hung_up_p(filp))
38980 - port->count--;
38981 + atomic_dec(&port->count);
38982 port->blocked_open++;
38983 spin_unlock_irqrestore(&port->lock, flags);
38984
38985 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38986 we must not mess that up further */
38987 spin_lock_irqsave(&port->lock, flags);
38988 if (!tty_hung_up_p(filp))
38989 - port->count++;
38990 + atomic_inc(&port->count);
38991 port->blocked_open--;
38992 if (retval == 0)
38993 port->flags |= ASYNC_NORMAL_ACTIVE;
38994 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38995 return 0;
38996 }
38997
38998 - if (tty->count == 1 && port->count != 1) {
38999 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39000 printk(KERN_WARNING
39001 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39002 - port->count);
39003 - port->count = 1;
39004 + atomic_read(&port->count));
39005 + atomic_set(&port->count, 1);
39006 }
39007 - if (--port->count < 0) {
39008 + if (atomic_dec_return(&port->count) < 0) {
39009 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39010 - port->count);
39011 - port->count = 0;
39012 + atomic_read(&port->count));
39013 + atomic_set(&port->count, 0);
39014 }
39015
39016 - if (port->count) {
39017 + if (atomic_read(&port->count)) {
39018 spin_unlock_irqrestore(&port->lock, flags);
39019 if (port->ops->drop)
39020 port->ops->drop(port);
39021 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39022 {
39023 spin_lock_irq(&port->lock);
39024 if (!tty_hung_up_p(filp))
39025 - ++port->count;
39026 + atomic_inc(&port->count);
39027 spin_unlock_irq(&port->lock);
39028 tty_port_tty_set(port, tty);
39029
39030 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39031 index 770a854..e5d3db3 100644
39032 --- a/drivers/tty/vt/keyboard.c
39033 +++ b/drivers/tty/vt/keyboard.c
39034 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39035 kbd->kbdmode == VC_OFF) &&
39036 value != KVAL(K_SAK))
39037 return; /* SAK is allowed even in raw mode */
39038 +
39039 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39040 + {
39041 + void *func = fn_handler[value];
39042 + if (func == fn_show_state || func == fn_show_ptregs ||
39043 + func == fn_show_mem)
39044 + return;
39045 + }
39046 +#endif
39047 +
39048 fn_handler[value](vc);
39049 }
39050
39051 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39052 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39053 return -EFAULT;
39054
39055 - if (!capable(CAP_SYS_TTY_CONFIG))
39056 - perm = 0;
39057 -
39058 switch (cmd) {
39059 case KDGKBENT:
39060 /* Ensure another thread doesn't free it under us */
39061 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39062 spin_unlock_irqrestore(&kbd_event_lock, flags);
39063 return put_user(val, &user_kbe->kb_value);
39064 case KDSKBENT:
39065 + if (!capable(CAP_SYS_TTY_CONFIG))
39066 + perm = 0;
39067 +
39068 if (!perm)
39069 return -EPERM;
39070 if (!i && v == K_NOSUCHMAP) {
39071 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39072 int i, j, k;
39073 int ret;
39074
39075 - if (!capable(CAP_SYS_TTY_CONFIG))
39076 - perm = 0;
39077 -
39078 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39079 if (!kbs) {
39080 ret = -ENOMEM;
39081 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39082 kfree(kbs);
39083 return ((p && *p) ? -EOVERFLOW : 0);
39084 case KDSKBSENT:
39085 + if (!capable(CAP_SYS_TTY_CONFIG))
39086 + perm = 0;
39087 +
39088 if (!perm) {
39089 ret = -EPERM;
39090 goto reterr;
39091 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39092 index a783d53..cb30d94 100644
39093 --- a/drivers/uio/uio.c
39094 +++ b/drivers/uio/uio.c
39095 @@ -25,6 +25,7 @@
39096 #include <linux/kobject.h>
39097 #include <linux/cdev.h>
39098 #include <linux/uio_driver.h>
39099 +#include <asm/local.h>
39100
39101 #define UIO_MAX_DEVICES (1U << MINORBITS)
39102
39103 @@ -32,10 +33,10 @@ struct uio_device {
39104 struct module *owner;
39105 struct device *dev;
39106 int minor;
39107 - atomic_t event;
39108 + atomic_unchecked_t event;
39109 struct fasync_struct *async_queue;
39110 wait_queue_head_t wait;
39111 - int vma_count;
39112 + local_t vma_count;
39113 struct uio_info *info;
39114 struct kobject *map_dir;
39115 struct kobject *portio_dir;
39116 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39117 struct device_attribute *attr, char *buf)
39118 {
39119 struct uio_device *idev = dev_get_drvdata(dev);
39120 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39121 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39122 }
39123
39124 static struct device_attribute uio_class_attributes[] = {
39125 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39126 {
39127 struct uio_device *idev = info->uio_dev;
39128
39129 - atomic_inc(&idev->event);
39130 + atomic_inc_unchecked(&idev->event);
39131 wake_up_interruptible(&idev->wait);
39132 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39133 }
39134 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39135 }
39136
39137 listener->dev = idev;
39138 - listener->event_count = atomic_read(&idev->event);
39139 + listener->event_count = atomic_read_unchecked(&idev->event);
39140 filep->private_data = listener;
39141
39142 if (idev->info->open) {
39143 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39144 return -EIO;
39145
39146 poll_wait(filep, &idev->wait, wait);
39147 - if (listener->event_count != atomic_read(&idev->event))
39148 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39149 return POLLIN | POLLRDNORM;
39150 return 0;
39151 }
39152 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39153 do {
39154 set_current_state(TASK_INTERRUPTIBLE);
39155
39156 - event_count = atomic_read(&idev->event);
39157 + event_count = atomic_read_unchecked(&idev->event);
39158 if (event_count != listener->event_count) {
39159 if (copy_to_user(buf, &event_count, count))
39160 retval = -EFAULT;
39161 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39162 static void uio_vma_open(struct vm_area_struct *vma)
39163 {
39164 struct uio_device *idev = vma->vm_private_data;
39165 - idev->vma_count++;
39166 + local_inc(&idev->vma_count);
39167 }
39168
39169 static void uio_vma_close(struct vm_area_struct *vma)
39170 {
39171 struct uio_device *idev = vma->vm_private_data;
39172 - idev->vma_count--;
39173 + local_dec(&idev->vma_count);
39174 }
39175
39176 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39177 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39178 idev->owner = owner;
39179 idev->info = info;
39180 init_waitqueue_head(&idev->wait);
39181 - atomic_set(&idev->event, 0);
39182 + atomic_set_unchecked(&idev->event, 0);
39183
39184 ret = uio_get_minor(idev);
39185 if (ret)
39186 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39187 index b7eb86a..36d28af 100644
39188 --- a/drivers/usb/atm/cxacru.c
39189 +++ b/drivers/usb/atm/cxacru.c
39190 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39191 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39192 if (ret < 2)
39193 return -EINVAL;
39194 - if (index < 0 || index > 0x7f)
39195 + if (index > 0x7f)
39196 return -EINVAL;
39197 pos += tmp;
39198
39199 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39200 index ee62b35..b663594 100644
39201 --- a/drivers/usb/atm/usbatm.c
39202 +++ b/drivers/usb/atm/usbatm.c
39203 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39204 if (printk_ratelimit())
39205 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39206 __func__, vpi, vci);
39207 - atomic_inc(&vcc->stats->rx_err);
39208 + atomic_inc_unchecked(&vcc->stats->rx_err);
39209 return;
39210 }
39211
39212 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39213 if (length > ATM_MAX_AAL5_PDU) {
39214 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39215 __func__, length, vcc);
39216 - atomic_inc(&vcc->stats->rx_err);
39217 + atomic_inc_unchecked(&vcc->stats->rx_err);
39218 goto out;
39219 }
39220
39221 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39222 if (sarb->len < pdu_length) {
39223 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39224 __func__, pdu_length, sarb->len, vcc);
39225 - atomic_inc(&vcc->stats->rx_err);
39226 + atomic_inc_unchecked(&vcc->stats->rx_err);
39227 goto out;
39228 }
39229
39230 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39231 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39232 __func__, vcc);
39233 - atomic_inc(&vcc->stats->rx_err);
39234 + atomic_inc_unchecked(&vcc->stats->rx_err);
39235 goto out;
39236 }
39237
39238 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39239 if (printk_ratelimit())
39240 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39241 __func__, length);
39242 - atomic_inc(&vcc->stats->rx_drop);
39243 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39244 goto out;
39245 }
39246
39247 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39248
39249 vcc->push(vcc, skb);
39250
39251 - atomic_inc(&vcc->stats->rx);
39252 + atomic_inc_unchecked(&vcc->stats->rx);
39253 out:
39254 skb_trim(sarb, 0);
39255 }
39256 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39257 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39258
39259 usbatm_pop(vcc, skb);
39260 - atomic_inc(&vcc->stats->tx);
39261 + atomic_inc_unchecked(&vcc->stats->tx);
39262
39263 skb = skb_dequeue(&instance->sndqueue);
39264 }
39265 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39266 if (!left--)
39267 return sprintf(page,
39268 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39269 - atomic_read(&atm_dev->stats.aal5.tx),
39270 - atomic_read(&atm_dev->stats.aal5.tx_err),
39271 - atomic_read(&atm_dev->stats.aal5.rx),
39272 - atomic_read(&atm_dev->stats.aal5.rx_err),
39273 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39274 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39275 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39276 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39277 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39278 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39279
39280 if (!left--) {
39281 if (instance->disconnected)
39282 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39283 index 3440812..2a4ef1f 100644
39284 --- a/drivers/usb/core/devices.c
39285 +++ b/drivers/usb/core/devices.c
39286 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39287 * time it gets called.
39288 */
39289 static struct device_connect_event {
39290 - atomic_t count;
39291 + atomic_unchecked_t count;
39292 wait_queue_head_t wait;
39293 } device_event = {
39294 .count = ATOMIC_INIT(1),
39295 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39296
39297 void usbfs_conn_disc_event(void)
39298 {
39299 - atomic_add(2, &device_event.count);
39300 + atomic_add_unchecked(2, &device_event.count);
39301 wake_up(&device_event.wait);
39302 }
39303
39304 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39305
39306 poll_wait(file, &device_event.wait, wait);
39307
39308 - event_count = atomic_read(&device_event.count);
39309 + event_count = atomic_read_unchecked(&device_event.count);
39310 if (file->f_version != event_count) {
39311 file->f_version = event_count;
39312 return POLLIN | POLLRDNORM;
39313 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39314 index 89dcf15..481800b 100644
39315 --- a/drivers/usb/early/ehci-dbgp.c
39316 +++ b/drivers/usb/early/ehci-dbgp.c
39317 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39318
39319 #ifdef CONFIG_KGDB
39320 static struct kgdb_io kgdbdbgp_io_ops;
39321 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39322 +static struct kgdb_io kgdbdbgp_io_ops_console;
39323 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39324 #else
39325 #define dbgp_kgdb_mode (0)
39326 #endif
39327 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39328 .write_char = kgdbdbgp_write_char,
39329 };
39330
39331 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39332 + .name = "kgdbdbgp",
39333 + .read_char = kgdbdbgp_read_char,
39334 + .write_char = kgdbdbgp_write_char,
39335 + .is_console = 1
39336 +};
39337 +
39338 static int kgdbdbgp_wait_time;
39339
39340 static int __init kgdbdbgp_parse_config(char *str)
39341 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39342 ptr++;
39343 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39344 }
39345 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39346 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39347 + if (early_dbgp_console.index != -1)
39348 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39349 + else
39350 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39351
39352 return 0;
39353 }
39354 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39355 index da6d479..80ed10b 100644
39356 --- a/drivers/usb/gadget/u_serial.c
39357 +++ b/drivers/usb/gadget/u_serial.c
39358 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39359 spin_lock_irq(&port->port_lock);
39360
39361 /* already open? Great. */
39362 - if (port->port.count) {
39363 + if (atomic_read(&port->port.count)) {
39364 status = 0;
39365 - port->port.count++;
39366 + atomic_inc(&port->port.count);
39367
39368 /* currently opening/closing? wait ... */
39369 } else if (port->openclose) {
39370 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39371 tty->driver_data = port;
39372 port->port.tty = tty;
39373
39374 - port->port.count = 1;
39375 + atomic_set(&port->port.count, 1);
39376 port->openclose = false;
39377
39378 /* if connected, start the I/O stream */
39379 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39380
39381 spin_lock_irq(&port->port_lock);
39382
39383 - if (port->port.count != 1) {
39384 - if (port->port.count == 0)
39385 + if (atomic_read(&port->port.count) != 1) {
39386 + if (atomic_read(&port->port.count) == 0)
39387 WARN_ON(1);
39388 else
39389 - --port->port.count;
39390 + atomic_dec(&port->port.count);
39391 goto exit;
39392 }
39393
39394 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39395 * and sleep if necessary
39396 */
39397 port->openclose = true;
39398 - port->port.count = 0;
39399 + atomic_set(&port->port.count, 0);
39400
39401 gser = port->port_usb;
39402 if (gser && gser->disconnect)
39403 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39404 int cond;
39405
39406 spin_lock_irq(&port->port_lock);
39407 - cond = (port->port.count == 0) && !port->openclose;
39408 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39409 spin_unlock_irq(&port->port_lock);
39410 return cond;
39411 }
39412 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39413 /* if it's already open, start I/O ... and notify the serial
39414 * protocol about open/close status (connect/disconnect).
39415 */
39416 - if (port->port.count) {
39417 + if (atomic_read(&port->port.count)) {
39418 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39419 gs_start_io(port);
39420 if (gser->connect)
39421 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39422
39423 port->port_usb = NULL;
39424 gser->ioport = NULL;
39425 - if (port->port.count > 0 || port->openclose) {
39426 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39427 wake_up_interruptible(&port->drain_wait);
39428 if (port->port.tty)
39429 tty_hangup(port->port.tty);
39430 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39431
39432 /* finally, free any unused/unusable I/O buffers */
39433 spin_lock_irqsave(&port->port_lock, flags);
39434 - if (port->port.count == 0 && !port->openclose)
39435 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39436 gs_buf_free(&port->port_write_buf);
39437 gs_free_requests(gser->out, &port->read_pool, NULL);
39438 gs_free_requests(gser->out, &port->read_queue, NULL);
39439 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39440 index b9cca6d..75c75df 100644
39441 --- a/drivers/usb/serial/console.c
39442 +++ b/drivers/usb/serial/console.c
39443 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39444
39445 info->port = port;
39446
39447 - ++port->port.count;
39448 + atomic_inc(&port->port.count);
39449 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39450 if (serial->type->set_termios) {
39451 /*
39452 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39453 }
39454 /* Now that any required fake tty operations are completed restore
39455 * the tty port count */
39456 - --port->port.count;
39457 + atomic_dec(&port->port.count);
39458 /* The console is special in terms of closing the device so
39459 * indicate this port is now acting as a system console. */
39460 port->port.console = 1;
39461 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39462 free_tty:
39463 kfree(tty);
39464 reset_open_count:
39465 - port->port.count = 0;
39466 + atomic_set(&port->port.count, 0);
39467 usb_autopm_put_interface(serial->interface);
39468 error_get_interface:
39469 usb_serial_put(serial);
39470 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39471 index d6bea3e..60b250e 100644
39472 --- a/drivers/usb/wusbcore/wa-hc.h
39473 +++ b/drivers/usb/wusbcore/wa-hc.h
39474 @@ -192,7 +192,7 @@ struct wahc {
39475 struct list_head xfer_delayed_list;
39476 spinlock_t xfer_list_lock;
39477 struct work_struct xfer_work;
39478 - atomic_t xfer_id_count;
39479 + atomic_unchecked_t xfer_id_count;
39480 };
39481
39482
39483 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39484 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39485 spin_lock_init(&wa->xfer_list_lock);
39486 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39487 - atomic_set(&wa->xfer_id_count, 1);
39488 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39489 }
39490
39491 /**
39492 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39493 index 57c01ab..8a05959 100644
39494 --- a/drivers/usb/wusbcore/wa-xfer.c
39495 +++ b/drivers/usb/wusbcore/wa-xfer.c
39496 @@ -296,7 +296,7 @@ out:
39497 */
39498 static void wa_xfer_id_init(struct wa_xfer *xfer)
39499 {
39500 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39501 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39502 }
39503
39504 /*
39505 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39506 index ef82a0d..da8a0b3 100644
39507 --- a/drivers/vhost/vhost.c
39508 +++ b/drivers/vhost/vhost.c
39509 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39510 return 0;
39511 }
39512
39513 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39514 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39515 {
39516 struct file *eventfp, *filep = NULL,
39517 *pollstart = NULL, *pollstop = NULL;
39518 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39519 index 747442d..7c0c434 100644
39520 --- a/drivers/video/aty/aty128fb.c
39521 +++ b/drivers/video/aty/aty128fb.c
39522 @@ -149,7 +149,7 @@ enum {
39523 };
39524
39525 /* Must match above enum */
39526 -static const char *r128_family[] __devinitdata = {
39527 +static const char *r128_family[] __devinitconst = {
39528 "AGP",
39529 "PCI",
39530 "PRO AGP",
39531 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39532 index 5c3960d..15cf8fc 100644
39533 --- a/drivers/video/fbcmap.c
39534 +++ b/drivers/video/fbcmap.c
39535 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39536 rc = -ENODEV;
39537 goto out;
39538 }
39539 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39540 - !info->fbops->fb_setcmap)) {
39541 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39542 rc = -EINVAL;
39543 goto out1;
39544 }
39545 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39546 index 0dff12a..2ef47b3 100644
39547 --- a/drivers/video/fbmem.c
39548 +++ b/drivers/video/fbmem.c
39549 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39550 image->dx += image->width + 8;
39551 }
39552 } else if (rotate == FB_ROTATE_UD) {
39553 - for (x = 0; x < num && image->dx >= 0; x++) {
39554 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39555 info->fbops->fb_imageblit(info, image);
39556 image->dx -= image->width + 8;
39557 }
39558 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39559 image->dy += image->height + 8;
39560 }
39561 } else if (rotate == FB_ROTATE_CCW) {
39562 - for (x = 0; x < num && image->dy >= 0; x++) {
39563 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39564 info->fbops->fb_imageblit(info, image);
39565 image->dy -= image->height + 8;
39566 }
39567 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39568 return -EFAULT;
39569 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39570 return -EINVAL;
39571 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39572 + if (con2fb.framebuffer >= FB_MAX)
39573 return -EINVAL;
39574 if (!registered_fb[con2fb.framebuffer])
39575 request_module("fb%d", con2fb.framebuffer);
39576 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39577 index 5a5d092..265c5ed 100644
39578 --- a/drivers/video/geode/gx1fb_core.c
39579 +++ b/drivers/video/geode/gx1fb_core.c
39580 @@ -29,7 +29,7 @@ static int crt_option = 1;
39581 static char panel_option[32] = "";
39582
39583 /* Modes relevant to the GX1 (taken from modedb.c) */
39584 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39585 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39586 /* 640x480-60 VESA */
39587 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39588 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39589 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39590 index 0fad23f..0e9afa4 100644
39591 --- a/drivers/video/gxt4500.c
39592 +++ b/drivers/video/gxt4500.c
39593 @@ -156,7 +156,7 @@ struct gxt4500_par {
39594 static char *mode_option;
39595
39596 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39597 -static const struct fb_videomode defaultmode __devinitdata = {
39598 +static const struct fb_videomode defaultmode __devinitconst = {
39599 .refresh = 60,
39600 .xres = 1280,
39601 .yres = 1024,
39602 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39603 return 0;
39604 }
39605
39606 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39607 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39608 .id = "IBM GXT4500P",
39609 .type = FB_TYPE_PACKED_PIXELS,
39610 .visual = FB_VISUAL_PSEUDOCOLOR,
39611 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39612 index 7672d2e..b56437f 100644
39613 --- a/drivers/video/i810/i810_accel.c
39614 +++ b/drivers/video/i810/i810_accel.c
39615 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39616 }
39617 }
39618 printk("ringbuffer lockup!!!\n");
39619 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39620 i810_report_error(mmio);
39621 par->dev_flags |= LOCKUP;
39622 info->pixmap.scan_align = 1;
39623 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39624 index b83f361..2b05a91 100644
39625 --- a/drivers/video/i810/i810_main.c
39626 +++ b/drivers/video/i810/i810_main.c
39627 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39628 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39629
39630 /* PCI */
39631 -static const char *i810_pci_list[] __devinitdata = {
39632 +static const char *i810_pci_list[] __devinitconst = {
39633 "Intel(R) 810 Framebuffer Device" ,
39634 "Intel(R) 810-DC100 Framebuffer Device" ,
39635 "Intel(R) 810E Framebuffer Device" ,
39636 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39637 index de36693..3c63fc2 100644
39638 --- a/drivers/video/jz4740_fb.c
39639 +++ b/drivers/video/jz4740_fb.c
39640 @@ -136,7 +136,7 @@ struct jzfb {
39641 uint32_t pseudo_palette[16];
39642 };
39643
39644 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39645 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39646 .id = "JZ4740 FB",
39647 .type = FB_TYPE_PACKED_PIXELS,
39648 .visual = FB_VISUAL_TRUECOLOR,
39649 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39650 index 3c14e43..eafa544 100644
39651 --- a/drivers/video/logo/logo_linux_clut224.ppm
39652 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39653 @@ -1,1604 +1,1123 @@
39654 P3
39655 -# Standard 224-color Linux logo
39656 80 80
39657 255
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 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 10 10 10 10 10 10
39668 - 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 0 0 0 6 6 6 10 10 10 14 14 14
39687 - 22 22 22 26 26 26 30 30 30 34 34 34
39688 - 30 30 30 30 30 30 26 26 26 18 18 18
39689 - 14 14 14 10 10 10 6 6 6 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 0 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 1 0 0 1 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 6 6 6 14 14 14 26 26 26 42 42 42
39707 - 54 54 54 66 66 66 78 78 78 78 78 78
39708 - 78 78 78 74 74 74 66 66 66 54 54 54
39709 - 42 42 42 26 26 26 18 18 18 10 10 10
39710 - 6 6 6 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 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 0 0 0 0 0 0 0 0 0 0 0 0
39724 - 0 0 0 0 0 0 0 0 0 0 0 0
39725 - 0 0 0 0 0 0 0 0 0 10 10 10
39726 - 22 22 22 42 42 42 66 66 66 86 86 86
39727 - 66 66 66 38 38 38 38 38 38 22 22 22
39728 - 26 26 26 34 34 34 54 54 54 66 66 66
39729 - 86 86 86 70 70 70 46 46 46 26 26 26
39730 - 14 14 14 6 6 6 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 1 0 0 1 0 0 1 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 10 10 10 26 26 26
39746 - 50 50 50 82 82 82 58 58 58 6 6 6
39747 - 2 2 6 2 2 6 2 2 6 2 2 6
39748 - 2 2 6 2 2 6 2 2 6 2 2 6
39749 - 6 6 6 54 54 54 86 86 86 66 66 66
39750 - 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 6 6 6 22 22 22 50 50 50
39766 - 78 78 78 34 34 34 2 2 6 2 2 6
39767 - 2 2 6 2 2 6 2 2 6 2 2 6
39768 - 2 2 6 2 2 6 2 2 6 2 2 6
39769 - 2 2 6 2 2 6 6 6 6 70 70 70
39770 - 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 6 6 6 18 18 18 42 42 42 82 82 82
39786 - 26 26 26 2 2 6 2 2 6 2 2 6
39787 - 2 2 6 2 2 6 2 2 6 2 2 6
39788 - 2 2 6 2 2 6 2 2 6 14 14 14
39789 - 46 46 46 34 34 34 6 6 6 2 2 6
39790 - 42 42 42 78 78 78 42 42 42 18 18 18
39791 - 6 6 6 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 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 10 10 10 30 30 30 66 66 66 58 58 58
39806 - 2 2 6 2 2 6 2 2 6 2 2 6
39807 - 2 2 6 2 2 6 2 2 6 2 2 6
39808 - 2 2 6 2 2 6 2 2 6 26 26 26
39809 - 86 86 86 101 101 101 46 46 46 10 10 10
39810 - 2 2 6 58 58 58 70 70 70 34 34 34
39811 - 10 10 10 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 1 0 0 1 0 0 1 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 14 14 14 42 42 42 86 86 86 10 10 10
39826 - 2 2 6 2 2 6 2 2 6 2 2 6
39827 - 2 2 6 2 2 6 2 2 6 2 2 6
39828 - 2 2 6 2 2 6 2 2 6 30 30 30
39829 - 94 94 94 94 94 94 58 58 58 26 26 26
39830 - 2 2 6 6 6 6 78 78 78 54 54 54
39831 - 22 22 22 6 6 6 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 0 0 0 0 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 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 0 0 0 0 0 0 0 0 0 0 0 0
39843 - 0 0 0 0 0 0 0 0 0 0 0 0
39844 - 0 0 0 0 0 0 0 0 0 6 6 6
39845 - 22 22 22 62 62 62 62 62 62 2 2 6
39846 - 2 2 6 2 2 6 2 2 6 2 2 6
39847 - 2 2 6 2 2 6 2 2 6 2 2 6
39848 - 2 2 6 2 2 6 2 2 6 26 26 26
39849 - 54 54 54 38 38 38 18 18 18 10 10 10
39850 - 2 2 6 2 2 6 34 34 34 82 82 82
39851 - 38 38 38 14 14 14 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 0 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 1 0 0 1 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 6 6 6
39865 - 30 30 30 78 78 78 30 30 30 2 2 6
39866 - 2 2 6 2 2 6 2 2 6 2 2 6
39867 - 2 2 6 2 2 6 2 2 6 2 2 6
39868 - 2 2 6 2 2 6 2 2 6 10 10 10
39869 - 10 10 10 2 2 6 2 2 6 2 2 6
39870 - 2 2 6 2 2 6 2 2 6 78 78 78
39871 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 0 0 0
39882 - 0 0 0 0 0 0 0 0 0 0 0 0
39883 - 0 0 0 0 0 0 0 0 0 0 0 0
39884 - 0 0 0 0 0 0 0 0 0 10 10 10
39885 - 38 38 38 86 86 86 14 14 14 2 2 6
39886 - 2 2 6 2 2 6 2 2 6 2 2 6
39887 - 2 2 6 2 2 6 2 2 6 2 2 6
39888 - 2 2 6 2 2 6 2 2 6 2 2 6
39889 - 2 2 6 2 2 6 2 2 6 2 2 6
39890 - 2 2 6 2 2 6 2 2 6 54 54 54
39891 - 66 66 66 26 26 26 6 6 6 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 0 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 1 0 0 1 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 14 14 14
39905 - 42 42 42 82 82 82 2 2 6 2 2 6
39906 - 2 2 6 6 6 6 10 10 10 2 2 6
39907 - 2 2 6 2 2 6 2 2 6 2 2 6
39908 - 2 2 6 2 2 6 2 2 6 6 6 6
39909 - 14 14 14 10 10 10 2 2 6 2 2 6
39910 - 2 2 6 2 2 6 2 2 6 18 18 18
39911 - 82 82 82 34 34 34 10 10 10 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 0 0 0 0 0 0 0 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 1 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 14 14 14
39925 - 46 46 46 86 86 86 2 2 6 2 2 6
39926 - 6 6 6 6 6 6 22 22 22 34 34 34
39927 - 6 6 6 2 2 6 2 2 6 2 2 6
39928 - 2 2 6 2 2 6 18 18 18 34 34 34
39929 - 10 10 10 50 50 50 22 22 22 2 2 6
39930 - 2 2 6 2 2 6 2 2 6 10 10 10
39931 - 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 14 14 14
39945 - 46 46 46 86 86 86 2 2 6 2 2 6
39946 - 38 38 38 116 116 116 94 94 94 22 22 22
39947 - 22 22 22 2 2 6 2 2 6 2 2 6
39948 - 14 14 14 86 86 86 138 138 138 162 162 162
39949 -154 154 154 38 38 38 26 26 26 6 6 6
39950 - 2 2 6 2 2 6 2 2 6 2 2 6
39951 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0
39954 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 0 0 0
39962 - 0 0 0 0 0 0 0 0 0 0 0 0
39963 - 0 0 0 0 0 0 0 0 0 0 0 0
39964 - 0 0 0 0 0 0 0 0 0 14 14 14
39965 - 46 46 46 86 86 86 2 2 6 14 14 14
39966 -134 134 134 198 198 198 195 195 195 116 116 116
39967 - 10 10 10 2 2 6 2 2 6 6 6 6
39968 -101 98 89 187 187 187 210 210 210 218 218 218
39969 -214 214 214 134 134 134 14 14 14 6 6 6
39970 - 2 2 6 2 2 6 2 2 6 2 2 6
39971 - 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
39979 - 0 0 1 0 0 1 0 0 1 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 0 0 0
39982 - 0 0 0 0 0 0 0 0 0 0 0 0
39983 - 0 0 0 0 0 0 0 0 0 0 0 0
39984 - 0 0 0 0 0 0 0 0 0 14 14 14
39985 - 46 46 46 86 86 86 2 2 6 54 54 54
39986 -218 218 218 195 195 195 226 226 226 246 246 246
39987 - 58 58 58 2 2 6 2 2 6 30 30 30
39988 -210 210 210 253 253 253 174 174 174 123 123 123
39989 -221 221 221 234 234 234 74 74 74 2 2 6
39990 - 2 2 6 2 2 6 2 2 6 2 2 6
39991 - 70 70 70 58 58 58 22 22 22 6 6 6
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 14 14 14
40005 - 46 46 46 82 82 82 2 2 6 106 106 106
40006 -170 170 170 26 26 26 86 86 86 226 226 226
40007 -123 123 123 10 10 10 14 14 14 46 46 46
40008 -231 231 231 190 190 190 6 6 6 70 70 70
40009 - 90 90 90 238 238 238 158 158 158 2 2 6
40010 - 2 2 6 2 2 6 2 2 6 2 2 6
40011 - 70 70 70 58 58 58 22 22 22 6 6 6
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
40019 - 0 0 1 0 0 1 0 0 1 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 0 0 0
40022 - 0 0 0 0 0 0 0 0 0 0 0 0
40023 - 0 0 0 0 0 0 0 0 0 0 0 0
40024 - 0 0 0 0 0 0 0 0 0 14 14 14
40025 - 42 42 42 86 86 86 6 6 6 116 116 116
40026 -106 106 106 6 6 6 70 70 70 149 149 149
40027 -128 128 128 18 18 18 38 38 38 54 54 54
40028 -221 221 221 106 106 106 2 2 6 14 14 14
40029 - 46 46 46 190 190 190 198 198 198 2 2 6
40030 - 2 2 6 2 2 6 2 2 6 2 2 6
40031 - 74 74 74 62 62 62 22 22 22 6 6 6
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
40039 - 0 0 1 0 0 0 0 0 1 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 0 0 0
40042 - 0 0 0 0 0 0 0 0 0 0 0 0
40043 - 0 0 0 0 0 0 0 0 0 0 0 0
40044 - 0 0 0 0 0 0 0 0 0 14 14 14
40045 - 42 42 42 94 94 94 14 14 14 101 101 101
40046 -128 128 128 2 2 6 18 18 18 116 116 116
40047 -118 98 46 121 92 8 121 92 8 98 78 10
40048 -162 162 162 106 106 106 2 2 6 2 2 6
40049 - 2 2 6 195 195 195 195 195 195 6 6 6
40050 - 2 2 6 2 2 6 2 2 6 2 2 6
40051 - 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
40059 - 0 0 1 0 0 0 0 0 1 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 0 0 0
40062 - 0 0 0 0 0 0 0 0 0 0 0 0
40063 - 0 0 0 0 0 0 0 0 0 0 0 0
40064 - 0 0 0 0 0 0 0 0 0 10 10 10
40065 - 38 38 38 90 90 90 14 14 14 58 58 58
40066 -210 210 210 26 26 26 54 38 6 154 114 10
40067 -226 170 11 236 186 11 225 175 15 184 144 12
40068 -215 174 15 175 146 61 37 26 9 2 2 6
40069 - 70 70 70 246 246 246 138 138 138 2 2 6
40070 - 2 2 6 2 2 6 2 2 6 2 2 6
40071 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 10 10 10
40085 - 38 38 38 86 86 86 14 14 14 10 10 10
40086 -195 195 195 188 164 115 192 133 9 225 175 15
40087 -239 182 13 234 190 10 232 195 16 232 200 30
40088 -245 207 45 241 208 19 232 195 16 184 144 12
40089 -218 194 134 211 206 186 42 42 42 2 2 6
40090 - 2 2 6 2 2 6 2 2 6 2 2 6
40091 - 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 10 10 10
40105 - 34 34 34 86 86 86 14 14 14 2 2 6
40106 -121 87 25 192 133 9 219 162 10 239 182 13
40107 -236 186 11 232 195 16 241 208 19 244 214 54
40108 -246 218 60 246 218 38 246 215 20 241 208 19
40109 -241 208 19 226 184 13 121 87 25 2 2 6
40110 - 2 2 6 2 2 6 2 2 6 2 2 6
40111 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 10 10 10
40125 - 34 34 34 82 82 82 30 30 30 61 42 6
40126 -180 123 7 206 145 10 230 174 11 239 182 13
40127 -234 190 10 238 202 15 241 208 19 246 218 74
40128 -246 218 38 246 215 20 246 215 20 246 215 20
40129 -226 184 13 215 174 15 184 144 12 6 6 6
40130 - 2 2 6 2 2 6 2 2 6 2 2 6
40131 - 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 10 10 10
40145 - 30 30 30 78 78 78 50 50 50 104 69 6
40146 -192 133 9 216 158 10 236 178 12 236 186 11
40147 -232 195 16 241 208 19 244 214 54 245 215 43
40148 -246 215 20 246 215 20 241 208 19 198 155 10
40149 -200 144 11 216 158 10 156 118 10 2 2 6
40150 - 2 2 6 2 2 6 2 2 6 2 2 6
40151 - 6 6 6 90 90 90 54 54 54 18 18 18
40152 - 6 6 6 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 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 10 10 10
40165 - 30 30 30 78 78 78 46 46 46 22 22 22
40166 -137 92 6 210 162 10 239 182 13 238 190 10
40167 -238 202 15 241 208 19 246 215 20 246 215 20
40168 -241 208 19 203 166 17 185 133 11 210 150 10
40169 -216 158 10 210 150 10 102 78 10 2 2 6
40170 - 6 6 6 54 54 54 14 14 14 2 2 6
40171 - 2 2 6 62 62 62 74 74 74 30 30 30
40172 - 10 10 10 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 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 10 10 10
40185 - 34 34 34 78 78 78 50 50 50 6 6 6
40186 - 94 70 30 139 102 15 190 146 13 226 184 13
40187 -232 200 30 232 195 16 215 174 15 190 146 13
40188 -168 122 10 192 133 9 210 150 10 213 154 11
40189 -202 150 34 182 157 106 101 98 89 2 2 6
40190 - 2 2 6 78 78 78 116 116 116 58 58 58
40191 - 2 2 6 22 22 22 90 90 90 46 46 46
40192 - 18 18 18 6 6 6 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 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 10 10 10
40205 - 38 38 38 86 86 86 50 50 50 6 6 6
40206 -128 128 128 174 154 114 156 107 11 168 122 10
40207 -198 155 10 184 144 12 197 138 11 200 144 11
40208 -206 145 10 206 145 10 197 138 11 188 164 115
40209 -195 195 195 198 198 198 174 174 174 14 14 14
40210 - 2 2 6 22 22 22 116 116 116 116 116 116
40211 - 22 22 22 2 2 6 74 74 74 70 70 70
40212 - 30 30 30 10 10 10 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 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 6 6 6 18 18 18
40225 - 50 50 50 101 101 101 26 26 26 10 10 10
40226 -138 138 138 190 190 190 174 154 114 156 107 11
40227 -197 138 11 200 144 11 197 138 11 192 133 9
40228 -180 123 7 190 142 34 190 178 144 187 187 187
40229 -202 202 202 221 221 221 214 214 214 66 66 66
40230 - 2 2 6 2 2 6 50 50 50 62 62 62
40231 - 6 6 6 2 2 6 10 10 10 90 90 90
40232 - 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 10 10 10 34 34 34
40245 - 74 74 74 74 74 74 2 2 6 6 6 6
40246 -144 144 144 198 198 198 190 190 190 178 166 146
40247 -154 121 60 156 107 11 156 107 11 168 124 44
40248 -174 154 114 187 187 187 190 190 190 210 210 210
40249 -246 246 246 253 253 253 253 253 253 182 182 182
40250 - 6 6 6 2 2 6 2 2 6 2 2 6
40251 - 2 2 6 2 2 6 2 2 6 62 62 62
40252 - 74 74 74 34 34 34 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 10 10 10 22 22 22 54 54 54
40265 - 94 94 94 18 18 18 2 2 6 46 46 46
40266 -234 234 234 221 221 221 190 190 190 190 190 190
40267 -190 190 190 187 187 187 187 187 187 190 190 190
40268 -190 190 190 195 195 195 214 214 214 242 242 242
40269 -253 253 253 253 253 253 253 253 253 253 253 253
40270 - 82 82 82 2 2 6 2 2 6 2 2 6
40271 - 2 2 6 2 2 6 2 2 6 14 14 14
40272 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 6 6 6 18 18 18 46 46 46 90 90 90
40285 - 46 46 46 18 18 18 6 6 6 182 182 182
40286 -253 253 253 246 246 246 206 206 206 190 190 190
40287 -190 190 190 190 190 190 190 190 190 190 190 190
40288 -206 206 206 231 231 231 250 250 250 253 253 253
40289 -253 253 253 253 253 253 253 253 253 253 253 253
40290 -202 202 202 14 14 14 2 2 6 2 2 6
40291 - 2 2 6 2 2 6 2 2 6 2 2 6
40292 - 42 42 42 86 86 86 42 42 42 18 18 18
40293 - 6 6 6 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 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 6 6 6
40304 - 14 14 14 38 38 38 74 74 74 66 66 66
40305 - 2 2 6 6 6 6 90 90 90 250 250 250
40306 -253 253 253 253 253 253 238 238 238 198 198 198
40307 -190 190 190 190 190 190 195 195 195 221 221 221
40308 -246 246 246 253 253 253 253 253 253 253 253 253
40309 -253 253 253 253 253 253 253 253 253 253 253 253
40310 -253 253 253 82 82 82 2 2 6 2 2 6
40311 - 2 2 6 2 2 6 2 2 6 2 2 6
40312 - 2 2 6 78 78 78 70 70 70 34 34 34
40313 - 14 14 14 6 6 6 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 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 14 14 14
40324 - 34 34 34 66 66 66 78 78 78 6 6 6
40325 - 2 2 6 18 18 18 218 218 218 253 253 253
40326 -253 253 253 253 253 253 253 253 253 246 246 246
40327 -226 226 226 231 231 231 246 246 246 253 253 253
40328 -253 253 253 253 253 253 253 253 253 253 253 253
40329 -253 253 253 253 253 253 253 253 253 253 253 253
40330 -253 253 253 178 178 178 2 2 6 2 2 6
40331 - 2 2 6 2 2 6 2 2 6 2 2 6
40332 - 2 2 6 18 18 18 90 90 90 62 62 62
40333 - 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 10 10 10 26 26 26
40344 - 58 58 58 90 90 90 18 18 18 2 2 6
40345 - 2 2 6 110 110 110 253 253 253 253 253 253
40346 -253 253 253 253 253 253 253 253 253 253 253 253
40347 -250 250 250 253 253 253 253 253 253 253 253 253
40348 -253 253 253 253 253 253 253 253 253 253 253 253
40349 -253 253 253 253 253 253 253 253 253 253 253 253
40350 -253 253 253 231 231 231 18 18 18 2 2 6
40351 - 2 2 6 2 2 6 2 2 6 2 2 6
40352 - 2 2 6 2 2 6 18 18 18 94 94 94
40353 - 54 54 54 26 26 26 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 6 6 6 22 22 22 50 50 50
40364 - 90 90 90 26 26 26 2 2 6 2 2 6
40365 - 14 14 14 195 195 195 250 250 250 253 253 253
40366 -253 253 253 253 253 253 253 253 253 253 253 253
40367 -253 253 253 253 253 253 253 253 253 253 253 253
40368 -253 253 253 253 253 253 253 253 253 253 253 253
40369 -253 253 253 253 253 253 253 253 253 253 253 253
40370 -250 250 250 242 242 242 54 54 54 2 2 6
40371 - 2 2 6 2 2 6 2 2 6 2 2 6
40372 - 2 2 6 2 2 6 2 2 6 38 38 38
40373 - 86 86 86 50 50 50 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 6 6 6 14 14 14 38 38 38 82 82 82
40384 - 34 34 34 2 2 6 2 2 6 2 2 6
40385 - 42 42 42 195 195 195 246 246 246 253 253 253
40386 -253 253 253 253 253 253 253 253 253 250 250 250
40387 -242 242 242 242 242 242 250 250 250 253 253 253
40388 -253 253 253 253 253 253 253 253 253 253 253 253
40389 -253 253 253 250 250 250 246 246 246 238 238 238
40390 -226 226 226 231 231 231 101 101 101 6 6 6
40391 - 2 2 6 2 2 6 2 2 6 2 2 6
40392 - 2 2 6 2 2 6 2 2 6 2 2 6
40393 - 38 38 38 82 82 82 42 42 42 14 14 14
40394 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 10 10 10 26 26 26 62 62 62 66 66 66
40404 - 2 2 6 2 2 6 2 2 6 6 6 6
40405 - 70 70 70 170 170 170 206 206 206 234 234 234
40406 -246 246 246 250 250 250 250 250 250 238 238 238
40407 -226 226 226 231 231 231 238 238 238 250 250 250
40408 -250 250 250 250 250 250 246 246 246 231 231 231
40409 -214 214 214 206 206 206 202 202 202 202 202 202
40410 -198 198 198 202 202 202 182 182 182 18 18 18
40411 - 2 2 6 2 2 6 2 2 6 2 2 6
40412 - 2 2 6 2 2 6 2 2 6 2 2 6
40413 - 2 2 6 62 62 62 66 66 66 30 30 30
40414 - 10 10 10 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 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 14 14 14 42 42 42 82 82 82 18 18 18
40424 - 2 2 6 2 2 6 2 2 6 10 10 10
40425 - 94 94 94 182 182 182 218 218 218 242 242 242
40426 -250 250 250 253 253 253 253 253 253 250 250 250
40427 -234 234 234 253 253 253 253 253 253 253 253 253
40428 -253 253 253 253 253 253 253 253 253 246 246 246
40429 -238 238 238 226 226 226 210 210 210 202 202 202
40430 -195 195 195 195 195 195 210 210 210 158 158 158
40431 - 6 6 6 14 14 14 50 50 50 14 14 14
40432 - 2 2 6 2 2 6 2 2 6 2 2 6
40433 - 2 2 6 6 6 6 86 86 86 46 46 46
40434 - 18 18 18 6 6 6 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 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 6 6 6
40443 - 22 22 22 54 54 54 70 70 70 2 2 6
40444 - 2 2 6 10 10 10 2 2 6 22 22 22
40445 -166 166 166 231 231 231 250 250 250 253 253 253
40446 -253 253 253 253 253 253 253 253 253 250 250 250
40447 -242 242 242 253 253 253 253 253 253 253 253 253
40448 -253 253 253 253 253 253 253 253 253 253 253 253
40449 -253 253 253 253 253 253 253 253 253 246 246 246
40450 -231 231 231 206 206 206 198 198 198 226 226 226
40451 - 94 94 94 2 2 6 6 6 6 38 38 38
40452 - 30 30 30 2 2 6 2 2 6 2 2 6
40453 - 2 2 6 2 2 6 62 62 62 66 66 66
40454 - 26 26 26 10 10 10 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 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 10 10 10
40463 - 30 30 30 74 74 74 50 50 50 2 2 6
40464 - 26 26 26 26 26 26 2 2 6 106 106 106
40465 -238 238 238 253 253 253 253 253 253 253 253 253
40466 -253 253 253 253 253 253 253 253 253 253 253 253
40467 -253 253 253 253 253 253 253 253 253 253 253 253
40468 -253 253 253 253 253 253 253 253 253 253 253 253
40469 -253 253 253 253 253 253 253 253 253 253 253 253
40470 -253 253 253 246 246 246 218 218 218 202 202 202
40471 -210 210 210 14 14 14 2 2 6 2 2 6
40472 - 30 30 30 22 22 22 2 2 6 2 2 6
40473 - 2 2 6 2 2 6 18 18 18 86 86 86
40474 - 42 42 42 14 14 14 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 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 14 14 14
40483 - 42 42 42 90 90 90 22 22 22 2 2 6
40484 - 42 42 42 2 2 6 18 18 18 218 218 218
40485 -253 253 253 253 253 253 253 253 253 253 253 253
40486 -253 253 253 253 253 253 253 253 253 253 253 253
40487 -253 253 253 253 253 253 253 253 253 253 253 253
40488 -253 253 253 253 253 253 253 253 253 253 253 253
40489 -253 253 253 253 253 253 253 253 253 253 253 253
40490 -253 253 253 253 253 253 250 250 250 221 221 221
40491 -218 218 218 101 101 101 2 2 6 14 14 14
40492 - 18 18 18 38 38 38 10 10 10 2 2 6
40493 - 2 2 6 2 2 6 2 2 6 78 78 78
40494 - 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 6 6 6 18 18 18
40503 - 54 54 54 82 82 82 2 2 6 26 26 26
40504 - 22 22 22 2 2 6 123 123 123 253 253 253
40505 -253 253 253 253 253 253 253 253 253 253 253 253
40506 -253 253 253 253 253 253 253 253 253 253 253 253
40507 -253 253 253 253 253 253 253 253 253 253 253 253
40508 -253 253 253 253 253 253 253 253 253 253 253 253
40509 -253 253 253 253 253 253 253 253 253 253 253 253
40510 -253 253 253 253 253 253 253 253 253 250 250 250
40511 -238 238 238 198 198 198 6 6 6 38 38 38
40512 - 58 58 58 26 26 26 38 38 38 2 2 6
40513 - 2 2 6 2 2 6 2 2 6 46 46 46
40514 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 10 10 10 30 30 30
40523 - 74 74 74 58 58 58 2 2 6 42 42 42
40524 - 2 2 6 22 22 22 231 231 231 253 253 253
40525 -253 253 253 253 253 253 253 253 253 253 253 253
40526 -253 253 253 253 253 253 253 253 253 250 250 250
40527 -253 253 253 253 253 253 253 253 253 253 253 253
40528 -253 253 253 253 253 253 253 253 253 253 253 253
40529 -253 253 253 253 253 253 253 253 253 253 253 253
40530 -253 253 253 253 253 253 253 253 253 253 253 253
40531 -253 253 253 246 246 246 46 46 46 38 38 38
40532 - 42 42 42 14 14 14 38 38 38 14 14 14
40533 - 2 2 6 2 2 6 2 2 6 6 6 6
40534 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 6 6 6 14 14 14 42 42 42
40543 - 90 90 90 18 18 18 18 18 18 26 26 26
40544 - 2 2 6 116 116 116 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 250 250 250 238 238 238
40547 -253 253 253 253 253 253 253 253 253 253 253 253
40548 -253 253 253 253 253 253 253 253 253 253 253 253
40549 -253 253 253 253 253 253 253 253 253 253 253 253
40550 -253 253 253 253 253 253 253 253 253 253 253 253
40551 -253 253 253 253 253 253 94 94 94 6 6 6
40552 - 2 2 6 2 2 6 10 10 10 34 34 34
40553 - 2 2 6 2 2 6 2 2 6 2 2 6
40554 - 74 74 74 58 58 58 22 22 22 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 10 10 10 26 26 26 66 66 66
40563 - 82 82 82 2 2 6 38 38 38 6 6 6
40564 - 14 14 14 210 210 210 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 246 246 246 242 242 242
40567 -253 253 253 253 253 253 253 253 253 253 253 253
40568 -253 253 253 253 253 253 253 253 253 253 253 253
40569 -253 253 253 253 253 253 253 253 253 253 253 253
40570 -253 253 253 253 253 253 253 253 253 253 253 253
40571 -253 253 253 253 253 253 144 144 144 2 2 6
40572 - 2 2 6 2 2 6 2 2 6 46 46 46
40573 - 2 2 6 2 2 6 2 2 6 2 2 6
40574 - 42 42 42 74 74 74 30 30 30 10 10 10
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 - 0 0 0 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 - 6 6 6 14 14 14 42 42 42 90 90 90
40583 - 26 26 26 6 6 6 42 42 42 2 2 6
40584 - 74 74 74 250 250 250 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 242 242 242 242 242 242
40587 -253 253 253 253 253 253 253 253 253 253 253 253
40588 -253 253 253 253 253 253 253 253 253 253 253 253
40589 -253 253 253 253 253 253 253 253 253 253 253 253
40590 -253 253 253 253 253 253 253 253 253 253 253 253
40591 -253 253 253 253 253 253 182 182 182 2 2 6
40592 - 2 2 6 2 2 6 2 2 6 46 46 46
40593 - 2 2 6 2 2 6 2 2 6 2 2 6
40594 - 10 10 10 86 86 86 38 38 38 10 10 10
40595 - 0 0 0 0 0 0 0 0 0 0 0 0
40596 - 0 0 0 0 0 0 0 0 0 0 0 0
40597 - 0 0 0 0 0 0 0 0 0 0 0 0
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 0 0 0 0 0 0 0 0 0 0 0 0
40602 - 10 10 10 26 26 26 66 66 66 82 82 82
40603 - 2 2 6 22 22 22 18 18 18 2 2 6
40604 -149 149 149 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 234 234 234 242 242 242
40607 -253 253 253 253 253 253 253 253 253 253 253 253
40608 -253 253 253 253 253 253 253 253 253 253 253 253
40609 -253 253 253 253 253 253 253 253 253 253 253 253
40610 -253 253 253 253 253 253 253 253 253 253 253 253
40611 -253 253 253 253 253 253 206 206 206 2 2 6
40612 - 2 2 6 2 2 6 2 2 6 38 38 38
40613 - 2 2 6 2 2 6 2 2 6 2 2 6
40614 - 6 6 6 86 86 86 46 46 46 14 14 14
40615 - 0 0 0 0 0 0 0 0 0 0 0 0
40616 - 0 0 0 0 0 0 0 0 0 0 0 0
40617 - 0 0 0 0 0 0 0 0 0 0 0 0
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 0 0 0 0 0 0 0 0 0 6 6 6
40622 - 18 18 18 46 46 46 86 86 86 18 18 18
40623 - 2 2 6 34 34 34 10 10 10 6 6 6
40624 -210 210 210 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 234 234 234 242 242 242
40627 -253 253 253 253 253 253 253 253 253 253 253 253
40628 -253 253 253 253 253 253 253 253 253 253 253 253
40629 -253 253 253 253 253 253 253 253 253 253 253 253
40630 -253 253 253 253 253 253 253 253 253 253 253 253
40631 -253 253 253 253 253 253 221 221 221 6 6 6
40632 - 2 2 6 2 2 6 6 6 6 30 30 30
40633 - 2 2 6 2 2 6 2 2 6 2 2 6
40634 - 2 2 6 82 82 82 54 54 54 18 18 18
40635 - 6 6 6 0 0 0 0 0 0 0 0 0
40636 - 0 0 0 0 0 0 0 0 0 0 0 0
40637 - 0 0 0 0 0 0 0 0 0 0 0 0
40638 - 0 0 0 0 0 0 0 0 0 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 0 0 0 0 0 0 10 10 10
40642 - 26 26 26 66 66 66 62 62 62 2 2 6
40643 - 2 2 6 38 38 38 10 10 10 26 26 26
40644 -238 238 238 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 231 231 231 238 238 238
40647 -253 253 253 253 253 253 253 253 253 253 253 253
40648 -253 253 253 253 253 253 253 253 253 253 253 253
40649 -253 253 253 253 253 253 253 253 253 253 253 253
40650 -253 253 253 253 253 253 253 253 253 253 253 253
40651 -253 253 253 253 253 253 231 231 231 6 6 6
40652 - 2 2 6 2 2 6 10 10 10 30 30 30
40653 - 2 2 6 2 2 6 2 2 6 2 2 6
40654 - 2 2 6 66 66 66 58 58 58 22 22 22
40655 - 6 6 6 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 0 0 0 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 10 10 10
40662 - 38 38 38 78 78 78 6 6 6 2 2 6
40663 - 2 2 6 46 46 46 14 14 14 42 42 42
40664 -246 246 246 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 231 231 231 242 242 242
40667 -253 253 253 253 253 253 253 253 253 253 253 253
40668 -253 253 253 253 253 253 253 253 253 253 253 253
40669 -253 253 253 253 253 253 253 253 253 253 253 253
40670 -253 253 253 253 253 253 253 253 253 253 253 253
40671 -253 253 253 253 253 253 234 234 234 10 10 10
40672 - 2 2 6 2 2 6 22 22 22 14 14 14
40673 - 2 2 6 2 2 6 2 2 6 2 2 6
40674 - 2 2 6 66 66 66 62 62 62 22 22 22
40675 - 6 6 6 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 0 0 0 0 0 0 0 0 0
40681 - 0 0 0 0 0 0 6 6 6 18 18 18
40682 - 50 50 50 74 74 74 2 2 6 2 2 6
40683 - 14 14 14 70 70 70 34 34 34 62 62 62
40684 -250 250 250 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 231 231 231 246 246 246
40687 -253 253 253 253 253 253 253 253 253 253 253 253
40688 -253 253 253 253 253 253 253 253 253 253 253 253
40689 -253 253 253 253 253 253 253 253 253 253 253 253
40690 -253 253 253 253 253 253 253 253 253 253 253 253
40691 -253 253 253 253 253 253 234 234 234 14 14 14
40692 - 2 2 6 2 2 6 30 30 30 2 2 6
40693 - 2 2 6 2 2 6 2 2 6 2 2 6
40694 - 2 2 6 66 66 66 62 62 62 22 22 22
40695 - 6 6 6 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 0 0 0
40701 - 0 0 0 0 0 0 6 6 6 18 18 18
40702 - 54 54 54 62 62 62 2 2 6 2 2 6
40703 - 2 2 6 30 30 30 46 46 46 70 70 70
40704 -250 250 250 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 231 231 231 246 246 246
40707 -253 253 253 253 253 253 253 253 253 253 253 253
40708 -253 253 253 253 253 253 253 253 253 253 253 253
40709 -253 253 253 253 253 253 253 253 253 253 253 253
40710 -253 253 253 253 253 253 253 253 253 253 253 253
40711 -253 253 253 253 253 253 226 226 226 10 10 10
40712 - 2 2 6 6 6 6 30 30 30 2 2 6
40713 - 2 2 6 2 2 6 2 2 6 2 2 6
40714 - 2 2 6 66 66 66 58 58 58 22 22 22
40715 - 6 6 6 0 0 0 0 0 0 0 0 0
40716 - 0 0 0 0 0 0 0 0 0 0 0 0
40717 - 0 0 0 0 0 0 0 0 0 0 0 0
40718 - 0 0 0 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 0 0 0 0 0 0
40721 - 0 0 0 0 0 0 6 6 6 22 22 22
40722 - 58 58 58 62 62 62 2 2 6 2 2 6
40723 - 2 2 6 2 2 6 30 30 30 78 78 78
40724 -250 250 250 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 231 231 231 246 246 246
40727 -253 253 253 253 253 253 253 253 253 253 253 253
40728 -253 253 253 253 253 253 253 253 253 253 253 253
40729 -253 253 253 253 253 253 253 253 253 253 253 253
40730 -253 253 253 253 253 253 253 253 253 253 253 253
40731 -253 253 253 253 253 253 206 206 206 2 2 6
40732 - 22 22 22 34 34 34 18 14 6 22 22 22
40733 - 26 26 26 18 18 18 6 6 6 2 2 6
40734 - 2 2 6 82 82 82 54 54 54 18 18 18
40735 - 6 6 6 0 0 0 0 0 0 0 0 0
40736 - 0 0 0 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 0 0 0
40738 - 0 0 0 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 0 0 0
40741 - 0 0 0 0 0 0 6 6 6 26 26 26
40742 - 62 62 62 106 106 106 74 54 14 185 133 11
40743 -210 162 10 121 92 8 6 6 6 62 62 62
40744 -238 238 238 253 253 253 253 253 253 253 253 253
40745 -253 253 253 253 253 253 253 253 253 253 253 253
40746 -253 253 253 253 253 253 231 231 231 246 246 246
40747 -253 253 253 253 253 253 253 253 253 253 253 253
40748 -253 253 253 253 253 253 253 253 253 253 253 253
40749 -253 253 253 253 253 253 253 253 253 253 253 253
40750 -253 253 253 253 253 253 253 253 253 253 253 253
40751 -253 253 253 253 253 253 158 158 158 18 18 18
40752 - 14 14 14 2 2 6 2 2 6 2 2 6
40753 - 6 6 6 18 18 18 66 66 66 38 38 38
40754 - 6 6 6 94 94 94 50 50 50 18 18 18
40755 - 6 6 6 0 0 0 0 0 0 0 0 0
40756 - 0 0 0 0 0 0 0 0 0 0 0 0
40757 - 0 0 0 0 0 0 0 0 0 0 0 0
40758 - 0 0 0 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 6 6 6
40761 - 10 10 10 10 10 10 18 18 18 38 38 38
40762 - 78 78 78 142 134 106 216 158 10 242 186 14
40763 -246 190 14 246 190 14 156 118 10 10 10 10
40764 - 90 90 90 238 238 238 253 253 253 253 253 253
40765 -253 253 253 253 253 253 253 253 253 253 253 253
40766 -253 253 253 253 253 253 231 231 231 250 250 250
40767 -253 253 253 253 253 253 253 253 253 253 253 253
40768 -253 253 253 253 253 253 253 253 253 253 253 253
40769 -253 253 253 253 253 253 253 253 253 253 253 253
40770 -253 253 253 253 253 253 253 253 253 246 230 190
40771 -238 204 91 238 204 91 181 142 44 37 26 9
40772 - 2 2 6 2 2 6 2 2 6 2 2 6
40773 - 2 2 6 2 2 6 38 38 38 46 46 46
40774 - 26 26 26 106 106 106 54 54 54 18 18 18
40775 - 6 6 6 0 0 0 0 0 0 0 0 0
40776 - 0 0 0 0 0 0 0 0 0 0 0 0
40777 - 0 0 0 0 0 0 0 0 0 0 0 0
40778 - 0 0 0 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 6 6 6 14 14 14 22 22 22
40781 - 30 30 30 38 38 38 50 50 50 70 70 70
40782 -106 106 106 190 142 34 226 170 11 242 186 14
40783 -246 190 14 246 190 14 246 190 14 154 114 10
40784 - 6 6 6 74 74 74 226 226 226 253 253 253
40785 -253 253 253 253 253 253 253 253 253 253 253 253
40786 -253 253 253 253 253 253 231 231 231 250 250 250
40787 -253 253 253 253 253 253 253 253 253 253 253 253
40788 -253 253 253 253 253 253 253 253 253 253 253 253
40789 -253 253 253 253 253 253 253 253 253 253 253 253
40790 -253 253 253 253 253 253 253 253 253 228 184 62
40791 -241 196 14 241 208 19 232 195 16 38 30 10
40792 - 2 2 6 2 2 6 2 2 6 2 2 6
40793 - 2 2 6 6 6 6 30 30 30 26 26 26
40794 -203 166 17 154 142 90 66 66 66 26 26 26
40795 - 6 6 6 0 0 0 0 0 0 0 0 0
40796 - 0 0 0 0 0 0 0 0 0 0 0 0
40797 - 0 0 0 0 0 0 0 0 0 0 0 0
40798 - 0 0 0 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 6 6 6 18 18 18 38 38 38 58 58 58
40801 - 78 78 78 86 86 86 101 101 101 123 123 123
40802 -175 146 61 210 150 10 234 174 13 246 186 14
40803 -246 190 14 246 190 14 246 190 14 238 190 10
40804 -102 78 10 2 2 6 46 46 46 198 198 198
40805 -253 253 253 253 253 253 253 253 253 253 253 253
40806 -253 253 253 253 253 253 234 234 234 242 242 242
40807 -253 253 253 253 253 253 253 253 253 253 253 253
40808 -253 253 253 253 253 253 253 253 253 253 253 253
40809 -253 253 253 253 253 253 253 253 253 253 253 253
40810 -253 253 253 253 253 253 253 253 253 224 178 62
40811 -242 186 14 241 196 14 210 166 10 22 18 6
40812 - 2 2 6 2 2 6 2 2 6 2 2 6
40813 - 2 2 6 2 2 6 6 6 6 121 92 8
40814 -238 202 15 232 195 16 82 82 82 34 34 34
40815 - 10 10 10 0 0 0 0 0 0 0 0 0
40816 - 0 0 0 0 0 0 0 0 0 0 0 0
40817 - 0 0 0 0 0 0 0 0 0 0 0 0
40818 - 0 0 0 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 14 14 14 38 38 38 70 70 70 154 122 46
40821 -190 142 34 200 144 11 197 138 11 197 138 11
40822 -213 154 11 226 170 11 242 186 14 246 190 14
40823 -246 190 14 246 190 14 246 190 14 246 190 14
40824 -225 175 15 46 32 6 2 2 6 22 22 22
40825 -158 158 158 250 250 250 253 253 253 253 253 253
40826 -253 253 253 253 253 253 253 253 253 253 253 253
40827 -253 253 253 253 253 253 253 253 253 253 253 253
40828 -253 253 253 253 253 253 253 253 253 253 253 253
40829 -253 253 253 253 253 253 253 253 253 253 253 253
40830 -253 253 253 250 250 250 242 242 242 224 178 62
40831 -239 182 13 236 186 11 213 154 11 46 32 6
40832 - 2 2 6 2 2 6 2 2 6 2 2 6
40833 - 2 2 6 2 2 6 61 42 6 225 175 15
40834 -238 190 10 236 186 11 112 100 78 42 42 42
40835 - 14 14 14 0 0 0 0 0 0 0 0 0
40836 - 0 0 0 0 0 0 0 0 0 0 0 0
40837 - 0 0 0 0 0 0 0 0 0 0 0 0
40838 - 0 0 0 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 6 6 6
40840 - 22 22 22 54 54 54 154 122 46 213 154 11
40841 -226 170 11 230 174 11 226 170 11 226 170 11
40842 -236 178 12 242 186 14 246 190 14 246 190 14
40843 -246 190 14 246 190 14 246 190 14 246 190 14
40844 -241 196 14 184 144 12 10 10 10 2 2 6
40845 - 6 6 6 116 116 116 242 242 242 253 253 253
40846 -253 253 253 253 253 253 253 253 253 253 253 253
40847 -253 253 253 253 253 253 253 253 253 253 253 253
40848 -253 253 253 253 253 253 253 253 253 253 253 253
40849 -253 253 253 253 253 253 253 253 253 253 253 253
40850 -253 253 253 231 231 231 198 198 198 214 170 54
40851 -236 178 12 236 178 12 210 150 10 137 92 6
40852 - 18 14 6 2 2 6 2 2 6 2 2 6
40853 - 6 6 6 70 47 6 200 144 11 236 178 12
40854 -239 182 13 239 182 13 124 112 88 58 58 58
40855 - 22 22 22 6 6 6 0 0 0 0 0 0
40856 - 0 0 0 0 0 0 0 0 0 0 0 0
40857 - 0 0 0 0 0 0 0 0 0 0 0 0
40858 - 0 0 0 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 10 10 10
40860 - 30 30 30 70 70 70 180 133 36 226 170 11
40861 -239 182 13 242 186 14 242 186 14 246 186 14
40862 -246 190 14 246 190 14 246 190 14 246 190 14
40863 -246 190 14 246 190 14 246 190 14 246 190 14
40864 -246 190 14 232 195 16 98 70 6 2 2 6
40865 - 2 2 6 2 2 6 66 66 66 221 221 221
40866 -253 253 253 253 253 253 253 253 253 253 253 253
40867 -253 253 253 253 253 253 253 253 253 253 253 253
40868 -253 253 253 253 253 253 253 253 253 253 253 253
40869 -253 253 253 253 253 253 253 253 253 253 253 253
40870 -253 253 253 206 206 206 198 198 198 214 166 58
40871 -230 174 11 230 174 11 216 158 10 192 133 9
40872 -163 110 8 116 81 8 102 78 10 116 81 8
40873 -167 114 7 197 138 11 226 170 11 239 182 13
40874 -242 186 14 242 186 14 162 146 94 78 78 78
40875 - 34 34 34 14 14 14 6 6 6 0 0 0
40876 - 0 0 0 0 0 0 0 0 0 0 0 0
40877 - 0 0 0 0 0 0 0 0 0 0 0 0
40878 - 0 0 0 0 0 0 0 0 0 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 6 6 6
40880 - 30 30 30 78 78 78 190 142 34 226 170 11
40881 -239 182 13 246 190 14 246 190 14 246 190 14
40882 -246 190 14 246 190 14 246 190 14 246 190 14
40883 -246 190 14 246 190 14 246 190 14 246 190 14
40884 -246 190 14 241 196 14 203 166 17 22 18 6
40885 - 2 2 6 2 2 6 2 2 6 38 38 38
40886 -218 218 218 253 253 253 253 253 253 253 253 253
40887 -253 253 253 253 253 253 253 253 253 253 253 253
40888 -253 253 253 253 253 253 253 253 253 253 253 253
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -250 250 250 206 206 206 198 198 198 202 162 69
40891 -226 170 11 236 178 12 224 166 10 210 150 10
40892 -200 144 11 197 138 11 192 133 9 197 138 11
40893 -210 150 10 226 170 11 242 186 14 246 190 14
40894 -246 190 14 246 186 14 225 175 15 124 112 88
40895 - 62 62 62 30 30 30 14 14 14 6 6 6
40896 - 0 0 0 0 0 0 0 0 0 0 0 0
40897 - 0 0 0 0 0 0 0 0 0 0 0 0
40898 - 0 0 0 0 0 0 0 0 0 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 10 10 10
40900 - 30 30 30 78 78 78 174 135 50 224 166 10
40901 -239 182 13 246 190 14 246 190 14 246 190 14
40902 -246 190 14 246 190 14 246 190 14 246 190 14
40903 -246 190 14 246 190 14 246 190 14 246 190 14
40904 -246 190 14 246 190 14 241 196 14 139 102 15
40905 - 2 2 6 2 2 6 2 2 6 2 2 6
40906 - 78 78 78 250 250 250 253 253 253 253 253 253
40907 -253 253 253 253 253 253 253 253 253 253 253 253
40908 -253 253 253 253 253 253 253 253 253 253 253 253
40909 -253 253 253 253 253 253 253 253 253 253 253 253
40910 -250 250 250 214 214 214 198 198 198 190 150 46
40911 -219 162 10 236 178 12 234 174 13 224 166 10
40912 -216 158 10 213 154 11 213 154 11 216 158 10
40913 -226 170 11 239 182 13 246 190 14 246 190 14
40914 -246 190 14 246 190 14 242 186 14 206 162 42
40915 -101 101 101 58 58 58 30 30 30 14 14 14
40916 - 6 6 6 0 0 0 0 0 0 0 0 0
40917 - 0 0 0 0 0 0 0 0 0 0 0 0
40918 - 0 0 0 0 0 0 0 0 0 0 0 0
40919 - 0 0 0 0 0 0 0 0 0 10 10 10
40920 - 30 30 30 74 74 74 174 135 50 216 158 10
40921 -236 178 12 246 190 14 246 190 14 246 190 14
40922 -246 190 14 246 190 14 246 190 14 246 190 14
40923 -246 190 14 246 190 14 246 190 14 246 190 14
40924 -246 190 14 246 190 14 241 196 14 226 184 13
40925 - 61 42 6 2 2 6 2 2 6 2 2 6
40926 - 22 22 22 238 238 238 253 253 253 253 253 253
40927 -253 253 253 253 253 253 253 253 253 253 253 253
40928 -253 253 253 253 253 253 253 253 253 253 253 253
40929 -253 253 253 253 253 253 253 253 253 253 253 253
40930 -253 253 253 226 226 226 187 187 187 180 133 36
40931 -216 158 10 236 178 12 239 182 13 236 178 12
40932 -230 174 11 226 170 11 226 170 11 230 174 11
40933 -236 178 12 242 186 14 246 190 14 246 190 14
40934 -246 190 14 246 190 14 246 186 14 239 182 13
40935 -206 162 42 106 106 106 66 66 66 34 34 34
40936 - 14 14 14 6 6 6 0 0 0 0 0 0
40937 - 0 0 0 0 0 0 0 0 0 0 0 0
40938 - 0 0 0 0 0 0 0 0 0 0 0 0
40939 - 0 0 0 0 0 0 0 0 0 6 6 6
40940 - 26 26 26 70 70 70 163 133 67 213 154 11
40941 -236 178 12 246 190 14 246 190 14 246 190 14
40942 -246 190 14 246 190 14 246 190 14 246 190 14
40943 -246 190 14 246 190 14 246 190 14 246 190 14
40944 -246 190 14 246 190 14 246 190 14 241 196 14
40945 -190 146 13 18 14 6 2 2 6 2 2 6
40946 - 46 46 46 246 246 246 253 253 253 253 253 253
40947 -253 253 253 253 253 253 253 253 253 253 253 253
40948 -253 253 253 253 253 253 253 253 253 253 253 253
40949 -253 253 253 253 253 253 253 253 253 253 253 253
40950 -253 253 253 221 221 221 86 86 86 156 107 11
40951 -216 158 10 236 178 12 242 186 14 246 186 14
40952 -242 186 14 239 182 13 239 182 13 242 186 14
40953 -242 186 14 246 186 14 246 190 14 246 190 14
40954 -246 190 14 246 190 14 246 190 14 246 190 14
40955 -242 186 14 225 175 15 142 122 72 66 66 66
40956 - 30 30 30 10 10 10 0 0 0 0 0 0
40957 - 0 0 0 0 0 0 0 0 0 0 0 0
40958 - 0 0 0 0 0 0 0 0 0 0 0 0
40959 - 0 0 0 0 0 0 0 0 0 6 6 6
40960 - 26 26 26 70 70 70 163 133 67 210 150 10
40961 -236 178 12 246 190 14 246 190 14 246 190 14
40962 -246 190 14 246 190 14 246 190 14 246 190 14
40963 -246 190 14 246 190 14 246 190 14 246 190 14
40964 -246 190 14 246 190 14 246 190 14 246 190 14
40965 -232 195 16 121 92 8 34 34 34 106 106 106
40966 -221 221 221 253 253 253 253 253 253 253 253 253
40967 -253 253 253 253 253 253 253 253 253 253 253 253
40968 -253 253 253 253 253 253 253 253 253 253 253 253
40969 -253 253 253 253 253 253 253 253 253 253 253 253
40970 -242 242 242 82 82 82 18 14 6 163 110 8
40971 -216 158 10 236 178 12 242 186 14 246 190 14
40972 -246 190 14 246 190 14 246 190 14 246 190 14
40973 -246 190 14 246 190 14 246 190 14 246 190 14
40974 -246 190 14 246 190 14 246 190 14 246 190 14
40975 -246 190 14 246 190 14 242 186 14 163 133 67
40976 - 46 46 46 18 18 18 6 6 6 0 0 0
40977 - 0 0 0 0 0 0 0 0 0 0 0 0
40978 - 0 0 0 0 0 0 0 0 0 0 0 0
40979 - 0 0 0 0 0 0 0 0 0 10 10 10
40980 - 30 30 30 78 78 78 163 133 67 210 150 10
40981 -236 178 12 246 186 14 246 190 14 246 190 14
40982 -246 190 14 246 190 14 246 190 14 246 190 14
40983 -246 190 14 246 190 14 246 190 14 246 190 14
40984 -246 190 14 246 190 14 246 190 14 246 190 14
40985 -241 196 14 215 174 15 190 178 144 253 253 253
40986 -253 253 253 253 253 253 253 253 253 253 253 253
40987 -253 253 253 253 253 253 253 253 253 253 253 253
40988 -253 253 253 253 253 253 253 253 253 253 253 253
40989 -253 253 253 253 253 253 253 253 253 218 218 218
40990 - 58 58 58 2 2 6 22 18 6 167 114 7
40991 -216 158 10 236 178 12 246 186 14 246 190 14
40992 -246 190 14 246 190 14 246 190 14 246 190 14
40993 -246 190 14 246 190 14 246 190 14 246 190 14
40994 -246 190 14 246 190 14 246 190 14 246 190 14
40995 -246 190 14 246 186 14 242 186 14 190 150 46
40996 - 54 54 54 22 22 22 6 6 6 0 0 0
40997 - 0 0 0 0 0 0 0 0 0 0 0 0
40998 - 0 0 0 0 0 0 0 0 0 0 0 0
40999 - 0 0 0 0 0 0 0 0 0 14 14 14
41000 - 38 38 38 86 86 86 180 133 36 213 154 11
41001 -236 178 12 246 186 14 246 190 14 246 190 14
41002 -246 190 14 246 190 14 246 190 14 246 190 14
41003 -246 190 14 246 190 14 246 190 14 246 190 14
41004 -246 190 14 246 190 14 246 190 14 246 190 14
41005 -246 190 14 232 195 16 190 146 13 214 214 214
41006 -253 253 253 253 253 253 253 253 253 253 253 253
41007 -253 253 253 253 253 253 253 253 253 253 253 253
41008 -253 253 253 253 253 253 253 253 253 253 253 253
41009 -253 253 253 250 250 250 170 170 170 26 26 26
41010 - 2 2 6 2 2 6 37 26 9 163 110 8
41011 -219 162 10 239 182 13 246 186 14 246 190 14
41012 -246 190 14 246 190 14 246 190 14 246 190 14
41013 -246 190 14 246 190 14 246 190 14 246 190 14
41014 -246 190 14 246 190 14 246 190 14 246 190 14
41015 -246 186 14 236 178 12 224 166 10 142 122 72
41016 - 46 46 46 18 18 18 6 6 6 0 0 0
41017 - 0 0 0 0 0 0 0 0 0 0 0 0
41018 - 0 0 0 0 0 0 0 0 0 0 0 0
41019 - 0 0 0 0 0 0 6 6 6 18 18 18
41020 - 50 50 50 109 106 95 192 133 9 224 166 10
41021 -242 186 14 246 190 14 246 190 14 246 190 14
41022 -246 190 14 246 190 14 246 190 14 246 190 14
41023 -246 190 14 246 190 14 246 190 14 246 190 14
41024 -246 190 14 246 190 14 246 190 14 246 190 14
41025 -242 186 14 226 184 13 210 162 10 142 110 46
41026 -226 226 226 253 253 253 253 253 253 253 253 253
41027 -253 253 253 253 253 253 253 253 253 253 253 253
41028 -253 253 253 253 253 253 253 253 253 253 253 253
41029 -198 198 198 66 66 66 2 2 6 2 2 6
41030 - 2 2 6 2 2 6 50 34 6 156 107 11
41031 -219 162 10 239 182 13 246 186 14 246 190 14
41032 -246 190 14 246 190 14 246 190 14 246 190 14
41033 -246 190 14 246 190 14 246 190 14 246 190 14
41034 -246 190 14 246 190 14 246 190 14 242 186 14
41035 -234 174 13 213 154 11 154 122 46 66 66 66
41036 - 30 30 30 10 10 10 0 0 0 0 0 0
41037 - 0 0 0 0 0 0 0 0 0 0 0 0
41038 - 0 0 0 0 0 0 0 0 0 0 0 0
41039 - 0 0 0 0 0 0 6 6 6 22 22 22
41040 - 58 58 58 154 121 60 206 145 10 234 174 13
41041 -242 186 14 246 186 14 246 190 14 246 190 14
41042 -246 190 14 246 190 14 246 190 14 246 190 14
41043 -246 190 14 246 190 14 246 190 14 246 190 14
41044 -246 190 14 246 190 14 246 190 14 246 190 14
41045 -246 186 14 236 178 12 210 162 10 163 110 8
41046 - 61 42 6 138 138 138 218 218 218 250 250 250
41047 -253 253 253 253 253 253 253 253 253 250 250 250
41048 -242 242 242 210 210 210 144 144 144 66 66 66
41049 - 6 6 6 2 2 6 2 2 6 2 2 6
41050 - 2 2 6 2 2 6 61 42 6 163 110 8
41051 -216 158 10 236 178 12 246 190 14 246 190 14
41052 -246 190 14 246 190 14 246 190 14 246 190 14
41053 -246 190 14 246 190 14 246 190 14 246 190 14
41054 -246 190 14 239 182 13 230 174 11 216 158 10
41055 -190 142 34 124 112 88 70 70 70 38 38 38
41056 - 18 18 18 6 6 6 0 0 0 0 0 0
41057 - 0 0 0 0 0 0 0 0 0 0 0 0
41058 - 0 0 0 0 0 0 0 0 0 0 0 0
41059 - 0 0 0 0 0 0 6 6 6 22 22 22
41060 - 62 62 62 168 124 44 206 145 10 224 166 10
41061 -236 178 12 239 182 13 242 186 14 242 186 14
41062 -246 186 14 246 190 14 246 190 14 246 190 14
41063 -246 190 14 246 190 14 246 190 14 246 190 14
41064 -246 190 14 246 190 14 246 190 14 246 190 14
41065 -246 190 14 236 178 12 216 158 10 175 118 6
41066 - 80 54 7 2 2 6 6 6 6 30 30 30
41067 - 54 54 54 62 62 62 50 50 50 38 38 38
41068 - 14 14 14 2 2 6 2 2 6 2 2 6
41069 - 2 2 6 2 2 6 2 2 6 2 2 6
41070 - 2 2 6 6 6 6 80 54 7 167 114 7
41071 -213 154 11 236 178 12 246 190 14 246 190 14
41072 -246 190 14 246 190 14 246 190 14 246 190 14
41073 -246 190 14 242 186 14 239 182 13 239 182 13
41074 -230 174 11 210 150 10 174 135 50 124 112 88
41075 - 82 82 82 54 54 54 34 34 34 18 18 18
41076 - 6 6 6 0 0 0 0 0 0 0 0 0
41077 - 0 0 0 0 0 0 0 0 0 0 0 0
41078 - 0 0 0 0 0 0 0 0 0 0 0 0
41079 - 0 0 0 0 0 0 6 6 6 18 18 18
41080 - 50 50 50 158 118 36 192 133 9 200 144 11
41081 -216 158 10 219 162 10 224 166 10 226 170 11
41082 -230 174 11 236 178 12 239 182 13 239 182 13
41083 -242 186 14 246 186 14 246 190 14 246 190 14
41084 -246 190 14 246 190 14 246 190 14 246 190 14
41085 -246 186 14 230 174 11 210 150 10 163 110 8
41086 -104 69 6 10 10 10 2 2 6 2 2 6
41087 - 2 2 6 2 2 6 2 2 6 2 2 6
41088 - 2 2 6 2 2 6 2 2 6 2 2 6
41089 - 2 2 6 2 2 6 2 2 6 2 2 6
41090 - 2 2 6 6 6 6 91 60 6 167 114 7
41091 -206 145 10 230 174 11 242 186 14 246 190 14
41092 -246 190 14 246 190 14 246 186 14 242 186 14
41093 -239 182 13 230 174 11 224 166 10 213 154 11
41094 -180 133 36 124 112 88 86 86 86 58 58 58
41095 - 38 38 38 22 22 22 10 10 10 6 6 6
41096 - 0 0 0 0 0 0 0 0 0 0 0 0
41097 - 0 0 0 0 0 0 0 0 0 0 0 0
41098 - 0 0 0 0 0 0 0 0 0 0 0 0
41099 - 0 0 0 0 0 0 0 0 0 14 14 14
41100 - 34 34 34 70 70 70 138 110 50 158 118 36
41101 -167 114 7 180 123 7 192 133 9 197 138 11
41102 -200 144 11 206 145 10 213 154 11 219 162 10
41103 -224 166 10 230 174 11 239 182 13 242 186 14
41104 -246 186 14 246 186 14 246 186 14 246 186 14
41105 -239 182 13 216 158 10 185 133 11 152 99 6
41106 -104 69 6 18 14 6 2 2 6 2 2 6
41107 - 2 2 6 2 2 6 2 2 6 2 2 6
41108 - 2 2 6 2 2 6 2 2 6 2 2 6
41109 - 2 2 6 2 2 6 2 2 6 2 2 6
41110 - 2 2 6 6 6 6 80 54 7 152 99 6
41111 -192 133 9 219 162 10 236 178 12 239 182 13
41112 -246 186 14 242 186 14 239 182 13 236 178 12
41113 -224 166 10 206 145 10 192 133 9 154 121 60
41114 - 94 94 94 62 62 62 42 42 42 22 22 22
41115 - 14 14 14 6 6 6 0 0 0 0 0 0
41116 - 0 0 0 0 0 0 0 0 0 0 0 0
41117 - 0 0 0 0 0 0 0 0 0 0 0 0
41118 - 0 0 0 0 0 0 0 0 0 0 0 0
41119 - 0 0 0 0 0 0 0 0 0 6 6 6
41120 - 18 18 18 34 34 34 58 58 58 78 78 78
41121 -101 98 89 124 112 88 142 110 46 156 107 11
41122 -163 110 8 167 114 7 175 118 6 180 123 7
41123 -185 133 11 197 138 11 210 150 10 219 162 10
41124 -226 170 11 236 178 12 236 178 12 234 174 13
41125 -219 162 10 197 138 11 163 110 8 130 83 6
41126 - 91 60 6 10 10 10 2 2 6 2 2 6
41127 - 18 18 18 38 38 38 38 38 38 38 38 38
41128 - 38 38 38 38 38 38 38 38 38 38 38 38
41129 - 38 38 38 38 38 38 26 26 26 2 2 6
41130 - 2 2 6 6 6 6 70 47 6 137 92 6
41131 -175 118 6 200 144 11 219 162 10 230 174 11
41132 -234 174 13 230 174 11 219 162 10 210 150 10
41133 -192 133 9 163 110 8 124 112 88 82 82 82
41134 - 50 50 50 30 30 30 14 14 14 6 6 6
41135 - 0 0 0 0 0 0 0 0 0 0 0 0
41136 - 0 0 0 0 0 0 0 0 0 0 0 0
41137 - 0 0 0 0 0 0 0 0 0 0 0 0
41138 - 0 0 0 0 0 0 0 0 0 0 0 0
41139 - 0 0 0 0 0 0 0 0 0 0 0 0
41140 - 6 6 6 14 14 14 22 22 22 34 34 34
41141 - 42 42 42 58 58 58 74 74 74 86 86 86
41142 -101 98 89 122 102 70 130 98 46 121 87 25
41143 -137 92 6 152 99 6 163 110 8 180 123 7
41144 -185 133 11 197 138 11 206 145 10 200 144 11
41145 -180 123 7 156 107 11 130 83 6 104 69 6
41146 - 50 34 6 54 54 54 110 110 110 101 98 89
41147 - 86 86 86 82 82 82 78 78 78 78 78 78
41148 - 78 78 78 78 78 78 78 78 78 78 78 78
41149 - 78 78 78 82 82 82 86 86 86 94 94 94
41150 -106 106 106 101 101 101 86 66 34 124 80 6
41151 -156 107 11 180 123 7 192 133 9 200 144 11
41152 -206 145 10 200 144 11 192 133 9 175 118 6
41153 -139 102 15 109 106 95 70 70 70 42 42 42
41154 - 22 22 22 10 10 10 0 0 0 0 0 0
41155 - 0 0 0 0 0 0 0 0 0 0 0 0
41156 - 0 0 0 0 0 0 0 0 0 0 0 0
41157 - 0 0 0 0 0 0 0 0 0 0 0 0
41158 - 0 0 0 0 0 0 0 0 0 0 0 0
41159 - 0 0 0 0 0 0 0 0 0 0 0 0
41160 - 0 0 0 0 0 0 6 6 6 10 10 10
41161 - 14 14 14 22 22 22 30 30 30 38 38 38
41162 - 50 50 50 62 62 62 74 74 74 90 90 90
41163 -101 98 89 112 100 78 121 87 25 124 80 6
41164 -137 92 6 152 99 6 152 99 6 152 99 6
41165 -138 86 6 124 80 6 98 70 6 86 66 30
41166 -101 98 89 82 82 82 58 58 58 46 46 46
41167 - 38 38 38 34 34 34 34 34 34 34 34 34
41168 - 34 34 34 34 34 34 34 34 34 34 34 34
41169 - 34 34 34 34 34 34 38 38 38 42 42 42
41170 - 54 54 54 82 82 82 94 86 76 91 60 6
41171 -134 86 6 156 107 11 167 114 7 175 118 6
41172 -175 118 6 167 114 7 152 99 6 121 87 25
41173 -101 98 89 62 62 62 34 34 34 18 18 18
41174 - 6 6 6 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 0 0 0 0 0 0 0 0 0
41178 - 0 0 0 0 0 0 0 0 0 0 0 0
41179 - 0 0 0 0 0 0 0 0 0 0 0 0
41180 - 0 0 0 0 0 0 0 0 0 0 0 0
41181 - 0 0 0 6 6 6 6 6 6 10 10 10
41182 - 18 18 18 22 22 22 30 30 30 42 42 42
41183 - 50 50 50 66 66 66 86 86 86 101 98 89
41184 -106 86 58 98 70 6 104 69 6 104 69 6
41185 -104 69 6 91 60 6 82 62 34 90 90 90
41186 - 62 62 62 38 38 38 22 22 22 14 14 14
41187 - 10 10 10 10 10 10 10 10 10 10 10 10
41188 - 10 10 10 10 10 10 6 6 6 10 10 10
41189 - 10 10 10 10 10 10 10 10 10 14 14 14
41190 - 22 22 22 42 42 42 70 70 70 89 81 66
41191 - 80 54 7 104 69 6 124 80 6 137 92 6
41192 -134 86 6 116 81 8 100 82 52 86 86 86
41193 - 58 58 58 30 30 30 14 14 14 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
41199 - 0 0 0 0 0 0 0 0 0 0 0 0
41200 - 0 0 0 0 0 0 0 0 0 0 0 0
41201 - 0 0 0 0 0 0 0 0 0 0 0 0
41202 - 0 0 0 6 6 6 10 10 10 14 14 14
41203 - 18 18 18 26 26 26 38 38 38 54 54 54
41204 - 70 70 70 86 86 86 94 86 76 89 81 66
41205 - 89 81 66 86 86 86 74 74 74 50 50 50
41206 - 30 30 30 14 14 14 6 6 6 0 0 0
41207 - 0 0 0 0 0 0 0 0 0 0 0 0
41208 - 0 0 0 0 0 0 0 0 0 0 0 0
41209 - 0 0 0 0 0 0 0 0 0 0 0 0
41210 - 6 6 6 18 18 18 34 34 34 58 58 58
41211 - 82 82 82 89 81 66 89 81 66 89 81 66
41212 - 94 86 66 94 86 76 74 74 74 50 50 50
41213 - 26 26 26 14 14 14 6 6 6 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 0 0 0
41219 - 0 0 0 0 0 0 0 0 0 0 0 0
41220 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 6 6 6 14 14 14 18 18 18
41224 - 30 30 30 38 38 38 46 46 46 54 54 54
41225 - 50 50 50 42 42 42 30 30 30 18 18 18
41226 - 10 10 10 0 0 0 0 0 0 0 0 0
41227 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 14 14 14 26 26 26
41231 - 38 38 38 50 50 50 58 58 58 58 58 58
41232 - 54 54 54 42 42 42 30 30 30 18 18 18
41233 - 10 10 10 0 0 0 0 0 0 0 0 0
41234 - 0 0 0 0 0 0 0 0 0 0 0 0
41235 - 0 0 0 0 0 0 0 0 0 0 0 0
41236 - 0 0 0 0 0 0 0 0 0 0 0 0
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 0 0 0 0 0 0 0 0 0 0 0 0
41241 - 0 0 0 0 0 0 0 0 0 0 0 0
41242 - 0 0 0 0 0 0 0 0 0 0 0 0
41243 - 0 0 0 0 0 0 0 0 0 6 6 6
41244 - 6 6 6 10 10 10 14 14 14 18 18 18
41245 - 18 18 18 14 14 14 10 10 10 6 6 6
41246 - 0 0 0 0 0 0 0 0 0 0 0 0
41247 - 0 0 0 0 0 0 0 0 0 0 0 0
41248 - 0 0 0 0 0 0 0 0 0 0 0 0
41249 - 0 0 0 0 0 0 0 0 0 0 0 0
41250 - 0 0 0 0 0 0 0 0 0 6 6 6
41251 - 14 14 14 18 18 18 22 22 22 22 22 22
41252 - 18 18 18 14 14 14 10 10 10 6 6 6
41253 - 0 0 0 0 0 0 0 0 0 0 0 0
41254 - 0 0 0 0 0 0 0 0 0 0 0 0
41255 - 0 0 0 0 0 0 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
41327 +4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
41347 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41352 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
41361 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41362 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41365 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41366 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41367 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41368 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41369 +4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4 4 4 4 4 4 4 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 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41375 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41376 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41379 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41380 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41381 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41382 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41383 +4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41387 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41388 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41389 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41390 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41392 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41393 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41394 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41395 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41396 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41397 +4 4 4 4 4 4
41398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41401 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41402 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41403 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41404 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41405 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41406 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41407 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41408 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41409 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41410 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41411 +4 4 4 4 4 4
41412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41413 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41415 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41416 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41417 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41418 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41419 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41420 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41421 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41422 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41423 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41424 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41425 +4 4 4 4 4 4
41426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41428 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41429 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41430 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41431 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41432 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41433 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41434 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41435 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41436 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41437 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41438 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41439 +4 4 4 4 4 4
41440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41442 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41443 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41444 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41445 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41446 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41447 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41448 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41449 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41450 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41451 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41452 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41453 +4 4 4 4 4 4
41454 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41456 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41457 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41458 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41459 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41460 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41461 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41462 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41463 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41464 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41465 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41466 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41467 +4 4 4 4 4 4
41468 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41470 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41471 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41472 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41473 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41474 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41475 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41476 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41477 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41478 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41479 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41480 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41481 +4 4 4 4 4 4
41482 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41483 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41484 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41485 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41486 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41487 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41488 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41489 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41490 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41491 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41492 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41493 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41494 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41495 +4 4 4 4 4 4
41496 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41497 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41498 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41499 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41500 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41501 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41502 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41503 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41504 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41505 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41506 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41507 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41508 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41509 +0 0 0 4 4 4
41510 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41511 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41512 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41513 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41514 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41515 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41516 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41517 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41518 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41519 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41520 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41521 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41522 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41523 +2 0 0 0 0 0
41524 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41525 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41526 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41527 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41528 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41529 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41530 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41531 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41532 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41533 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41534 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41535 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41536 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41537 +37 38 37 0 0 0
41538 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41539 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41540 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41541 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41542 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41543 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41544 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41545 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41546 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41547 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41548 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41549 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41550 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41551 +85 115 134 4 0 0
41552 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41553 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41554 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41555 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41556 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41557 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41558 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41559 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41560 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41561 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41562 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41563 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41564 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41565 +60 73 81 4 0 0
41566 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41567 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41568 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41569 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41570 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41571 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41572 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41573 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41574 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41575 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41576 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41577 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41578 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41579 +16 19 21 4 0 0
41580 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41581 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41582 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41583 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41584 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41585 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41586 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41587 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41588 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41589 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41590 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41591 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41592 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41593 +4 0 0 4 3 3
41594 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41595 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41596 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41598 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41599 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41600 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41601 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41602 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41603 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41604 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41605 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41606 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41607 +3 2 2 4 4 4
41608 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41609 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41610 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41611 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41612 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41613 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41614 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41615 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41616 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41617 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41618 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41619 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41620 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41621 +4 4 4 4 4 4
41622 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41623 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41624 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41625 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41626 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41627 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41628 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41629 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41630 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41631 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41632 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41633 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41634 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41635 +4 4 4 4 4 4
41636 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41637 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41638 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41639 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41640 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41641 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41642 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41643 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41644 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41645 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41646 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41647 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41648 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41649 +5 5 5 5 5 5
41650 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41651 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41652 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41653 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41654 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41655 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41656 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41657 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41658 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41659 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41660 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41661 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41662 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41663 +5 5 5 4 4 4
41664 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41665 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41666 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41667 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41668 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41669 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41670 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41671 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41672 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41673 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41674 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41675 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41676 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41677 +4 4 4 4 4 4
41678 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41679 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41680 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41681 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41682 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41683 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41684 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41685 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41686 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41687 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41688 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41689 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41691 +4 4 4 4 4 4
41692 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41693 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41694 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41695 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41696 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41697 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41698 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41699 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41700 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41701 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41702 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41705 +4 4 4 4 4 4
41706 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41707 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41708 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41709 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41710 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41711 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41712 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41713 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41714 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41715 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41716 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41719 +4 4 4 4 4 4
41720 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41721 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41722 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41723 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41724 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41725 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41726 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41727 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41728 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41729 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41730 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41733 +4 4 4 4 4 4
41734 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41735 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41736 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41737 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41738 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41739 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41740 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41741 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41742 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41743 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41744 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41747 +4 4 4 4 4 4
41748 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41749 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41750 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41751 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41752 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41753 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41754 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41755 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41756 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41757 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41758 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41761 +4 4 4 4 4 4
41762 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41763 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41764 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41765 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41766 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41767 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41768 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41769 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41770 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41771 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41772 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41775 +4 4 4 4 4 4
41776 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41777 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41778 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41779 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41780 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41781 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41782 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41783 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41784 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41785 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41786 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41789 +4 4 4 4 4 4
41790 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41791 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41792 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41793 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41794 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41795 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41796 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41797 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41798 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41799 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41800 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41803 +4 4 4 4 4 4
41804 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41805 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41806 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41807 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41808 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41809 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41810 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41811 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41812 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41813 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41814 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41817 +4 4 4 4 4 4
41818 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41819 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41820 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41821 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41822 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41823 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41824 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41825 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41826 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41827 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41828 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41831 +4 4 4 4 4 4
41832 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41833 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41834 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41835 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41836 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41837 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41838 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41839 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41840 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41841 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41842 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41845 +4 4 4 4 4 4
41846 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41847 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41848 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41849 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41850 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41851 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41852 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41853 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41854 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41855 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41856 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41859 +4 4 4 4 4 4
41860 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41861 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41862 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41863 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41864 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41865 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41866 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41867 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41868 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41869 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41870 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41873 +4 4 4 4 4 4
41874 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41875 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41876 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41877 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41878 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41879 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41880 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41881 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41882 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41883 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41884 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41887 +4 4 4 4 4 4
41888 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41889 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41890 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41891 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41892 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41893 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41894 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41895 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41896 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41897 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41898 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41901 +4 4 4 4 4 4
41902 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41903 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41904 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41905 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41906 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41907 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41908 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41909 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41910 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41911 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41912 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41915 +4 4 4 4 4 4
41916 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41917 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41918 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41919 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41920 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41921 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41922 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41923 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41924 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41925 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41926 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41929 +4 4 4 4 4 4
41930 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41931 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41932 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41933 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41934 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41935 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41936 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41937 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41938 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41939 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41940 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41943 +4 4 4 4 4 4
41944 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41945 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41946 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41947 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41948 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41949 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41950 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41951 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41952 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41953 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41954 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41957 +4 4 4 4 4 4
41958 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41959 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41960 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41961 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41962 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41963 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41964 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41965 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41966 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41967 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41968 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41971 +4 4 4 4 4 4
41972 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41973 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41974 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41975 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41976 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41977 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41978 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41979 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41980 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41981 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41982 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41985 +4 4 4 4 4 4
41986 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41987 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41988 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41989 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41990 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41991 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41992 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41993 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41994 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41995 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41996 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41999 +4 4 4 4 4 4
42000 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42001 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42002 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42003 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42004 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42005 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42006 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42007 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42008 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42009 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42010 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42013 +4 4 4 4 4 4
42014 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42015 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42016 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42017 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42018 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42019 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42020 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42021 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42022 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42023 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42024 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42027 +4 4 4 4 4 4
42028 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42029 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42030 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42031 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42032 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42033 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42034 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42035 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42036 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42037 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42038 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42041 +4 4 4 4 4 4
42042 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42043 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42044 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42045 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42046 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42047 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42048 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42049 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42050 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42051 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42052 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42055 +4 4 4 4 4 4
42056 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42057 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42058 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42059 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42060 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42061 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42062 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42063 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42064 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42065 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42066 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42069 +4 4 4 4 4 4
42070 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42071 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42072 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42073 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42074 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42075 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42076 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42077 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42078 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42079 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42083 +4 4 4 4 4 4
42084 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42085 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42086 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42087 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42088 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42089 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42090 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42091 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42092 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42093 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42097 +4 4 4 4 4 4
42098 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42099 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42100 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42101 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42102 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42103 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42104 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42105 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42106 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42107 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42112 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42113 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42114 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42115 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42116 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42117 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42118 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42119 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42120 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42121 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42123 +4 4 4 4 4 4 4 4 4 4 4 4 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
42126 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42127 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42128 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42129 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42130 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42131 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42132 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42133 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42134 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42137 +4 4 4 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
42140 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42141 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42142 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42143 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42144 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42145 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42146 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42147 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42148 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42154 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42155 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42156 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42157 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42158 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42159 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42160 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42161 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42162 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164 +4 4 4 4 4 4 4 4 4 4 4 4 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
42168 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42169 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42170 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42171 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42172 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42173 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42174 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42175 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 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
42182 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42183 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42184 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42185 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42186 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42187 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42188 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42189 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 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
42196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42197 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42198 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42199 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42200 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42201 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42202 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42203 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 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
42210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42212 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42213 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42214 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42215 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42216 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42217 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 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
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 5 5 5 5 5 5 5 5 5
42226 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42227 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42228 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42229 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42230 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42231 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42241 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42242 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42243 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42244 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42245 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 4 4 4 5 5 5
42255 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42256 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42257 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42258 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42269 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42270 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42271 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42272 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42283 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42284 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42285 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42286 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42289 +4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42298 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42299 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42300 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42303 +4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42312 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42313 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42314 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42317 +4 4 4 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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42327 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42328 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42341 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42342 +5 5 5 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 4 4 4 4 4 4
42344 +4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
42353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42355 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42363 +4 4 4 4 4 4
42364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42369 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42377 +4 4 4 4 4 4
42378 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42379 index 38fcfff..0072dcd 100644
42380 --- a/drivers/video/udlfb.c
42381 +++ b/drivers/video/udlfb.c
42382 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42383 dlfb_urb_completion(urb);
42384
42385 error:
42386 - atomic_add(bytes_sent, &dev->bytes_sent);
42387 - atomic_add(bytes_identical, &dev->bytes_identical);
42388 - atomic_add(width*height*2, &dev->bytes_rendered);
42389 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42390 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42391 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42392 end_cycles = get_cycles();
42393 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42394 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42395 >> 10)), /* Kcycles */
42396 &dev->cpu_kcycles_used);
42397
42398 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42399 dlfb_urb_completion(urb);
42400
42401 error:
42402 - atomic_add(bytes_sent, &dev->bytes_sent);
42403 - atomic_add(bytes_identical, &dev->bytes_identical);
42404 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42405 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42406 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42407 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42408 end_cycles = get_cycles();
42409 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42410 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42411 >> 10)), /* Kcycles */
42412 &dev->cpu_kcycles_used);
42413 }
42414 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42415 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42416 struct dlfb_data *dev = fb_info->par;
42417 return snprintf(buf, PAGE_SIZE, "%u\n",
42418 - atomic_read(&dev->bytes_rendered));
42419 + atomic_read_unchecked(&dev->bytes_rendered));
42420 }
42421
42422 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42423 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42424 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42425 struct dlfb_data *dev = fb_info->par;
42426 return snprintf(buf, PAGE_SIZE, "%u\n",
42427 - atomic_read(&dev->bytes_identical));
42428 + atomic_read_unchecked(&dev->bytes_identical));
42429 }
42430
42431 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42432 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42433 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42434 struct dlfb_data *dev = fb_info->par;
42435 return snprintf(buf, PAGE_SIZE, "%u\n",
42436 - atomic_read(&dev->bytes_sent));
42437 + atomic_read_unchecked(&dev->bytes_sent));
42438 }
42439
42440 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42441 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42442 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42443 struct dlfb_data *dev = fb_info->par;
42444 return snprintf(buf, PAGE_SIZE, "%u\n",
42445 - atomic_read(&dev->cpu_kcycles_used));
42446 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42447 }
42448
42449 static ssize_t edid_show(
42450 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42451 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42452 struct dlfb_data *dev = fb_info->par;
42453
42454 - atomic_set(&dev->bytes_rendered, 0);
42455 - atomic_set(&dev->bytes_identical, 0);
42456 - atomic_set(&dev->bytes_sent, 0);
42457 - atomic_set(&dev->cpu_kcycles_used, 0);
42458 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42459 + atomic_set_unchecked(&dev->bytes_identical, 0);
42460 + atomic_set_unchecked(&dev->bytes_sent, 0);
42461 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42462
42463 return count;
42464 }
42465 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42466 index b0e2a42..e2df3ad 100644
42467 --- a/drivers/video/uvesafb.c
42468 +++ b/drivers/video/uvesafb.c
42469 @@ -19,6 +19,7 @@
42470 #include <linux/io.h>
42471 #include <linux/mutex.h>
42472 #include <linux/slab.h>
42473 +#include <linux/moduleloader.h>
42474 #include <video/edid.h>
42475 #include <video/uvesafb.h>
42476 #ifdef CONFIG_X86
42477 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42478 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42479 par->pmi_setpal = par->ypan = 0;
42480 } else {
42481 +
42482 +#ifdef CONFIG_PAX_KERNEXEC
42483 +#ifdef CONFIG_MODULES
42484 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42485 +#endif
42486 + if (!par->pmi_code) {
42487 + par->pmi_setpal = par->ypan = 0;
42488 + return 0;
42489 + }
42490 +#endif
42491 +
42492 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42493 + task->t.regs.edi);
42494 +
42495 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42496 + pax_open_kernel();
42497 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42498 + pax_close_kernel();
42499 +
42500 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42501 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42502 +#else
42503 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42504 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42505 +#endif
42506 +
42507 printk(KERN_INFO "uvesafb: protected mode interface info at "
42508 "%04x:%04x\n",
42509 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42510 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42511 par->ypan = ypan;
42512
42513 if (par->pmi_setpal || par->ypan) {
42514 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42515 if (__supported_pte_mask & _PAGE_NX) {
42516 par->pmi_setpal = par->ypan = 0;
42517 printk(KERN_WARNING "uvesafb: NX protection is actively."
42518 "We have better not to use the PMI.\n");
42519 - } else {
42520 + } else
42521 +#endif
42522 uvesafb_vbe_getpmi(task, par);
42523 - }
42524 }
42525 #else
42526 /* The protected mode interface is not available on non-x86. */
42527 @@ -1836,6 +1860,11 @@ out:
42528 if (par->vbe_modes)
42529 kfree(par->vbe_modes);
42530
42531 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42532 + if (par->pmi_code)
42533 + module_free_exec(NULL, par->pmi_code);
42534 +#endif
42535 +
42536 framebuffer_release(info);
42537 return err;
42538 }
42539 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42540 kfree(par->vbe_state_orig);
42541 if (par->vbe_state_saved)
42542 kfree(par->vbe_state_saved);
42543 +
42544 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42545 + if (par->pmi_code)
42546 + module_free_exec(NULL, par->pmi_code);
42547 +#endif
42548 +
42549 }
42550
42551 framebuffer_release(info);
42552 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42553 index 501b340..86bd4cf 100644
42554 --- a/drivers/video/vesafb.c
42555 +++ b/drivers/video/vesafb.c
42556 @@ -9,6 +9,7 @@
42557 */
42558
42559 #include <linux/module.h>
42560 +#include <linux/moduleloader.h>
42561 #include <linux/kernel.h>
42562 #include <linux/errno.h>
42563 #include <linux/string.h>
42564 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42565 static int vram_total __initdata; /* Set total amount of memory */
42566 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42567 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42568 -static void (*pmi_start)(void) __read_mostly;
42569 -static void (*pmi_pal) (void) __read_mostly;
42570 +static void (*pmi_start)(void) __read_only;
42571 +static void (*pmi_pal) (void) __read_only;
42572 static int depth __read_mostly;
42573 static int vga_compat __read_mostly;
42574 /* --------------------------------------------------------------------- */
42575 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42576 unsigned int size_vmode;
42577 unsigned int size_remap;
42578 unsigned int size_total;
42579 + void *pmi_code = NULL;
42580
42581 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42582 return -ENODEV;
42583 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42584 size_remap = size_total;
42585 vesafb_fix.smem_len = size_remap;
42586
42587 -#ifndef __i386__
42588 - screen_info.vesapm_seg = 0;
42589 -#endif
42590 -
42591 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42592 printk(KERN_WARNING
42593 "vesafb: cannot reserve video memory at 0x%lx\n",
42594 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42595 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42596 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42597
42598 +#ifdef __i386__
42599 +
42600 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42601 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42602 + if (!pmi_code)
42603 +#elif !defined(CONFIG_PAX_KERNEXEC)
42604 + if (0)
42605 +#endif
42606 +
42607 +#endif
42608 + screen_info.vesapm_seg = 0;
42609 +
42610 if (screen_info.vesapm_seg) {
42611 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42612 - screen_info.vesapm_seg,screen_info.vesapm_off);
42613 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42614 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42615 }
42616
42617 if (screen_info.vesapm_seg < 0xc000)
42618 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42619
42620 if (ypan || pmi_setpal) {
42621 unsigned short *pmi_base;
42622 +
42623 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42624 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42625 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42626 +
42627 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42628 + pax_open_kernel();
42629 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42630 +#else
42631 + pmi_code = pmi_base;
42632 +#endif
42633 +
42634 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42635 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42636 +
42637 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42638 + pmi_start = ktva_ktla(pmi_start);
42639 + pmi_pal = ktva_ktla(pmi_pal);
42640 + pax_close_kernel();
42641 +#endif
42642 +
42643 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42644 if (pmi_base[3]) {
42645 printk(KERN_INFO "vesafb: pmi: ports = ");
42646 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42647 info->node, info->fix.id);
42648 return 0;
42649 err:
42650 +
42651 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42652 + module_free_exec(NULL, pmi_code);
42653 +#endif
42654 +
42655 if (info->screen_base)
42656 iounmap(info->screen_base);
42657 framebuffer_release(info);
42658 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42659 index 88714ae..16c2e11 100644
42660 --- a/drivers/video/via/via_clock.h
42661 +++ b/drivers/video/via/via_clock.h
42662 @@ -56,7 +56,7 @@ struct via_clock {
42663
42664 void (*set_engine_pll_state)(u8 state);
42665 void (*set_engine_pll)(struct via_pll_config config);
42666 -};
42667 +} __no_const;
42668
42669
42670 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42671 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42672 index 453db0c..604973e 100644
42673 --- a/drivers/virtio/virtio_mmio.c
42674 +++ b/drivers/virtio/virtio_mmio.c
42675 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42676
42677 resources[0].end = memparse(device, &str) - 1;
42678
42679 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42680 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42681 &base, &resources[1].start, &consumed,
42682 &vm_cmdline_id, &consumed);
42683
42684 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42685 index e56c934..fc22f4b 100644
42686 --- a/drivers/xen/xen-pciback/conf_space.h
42687 +++ b/drivers/xen/xen-pciback/conf_space.h
42688 @@ -44,15 +44,15 @@ struct config_field {
42689 struct {
42690 conf_dword_write write;
42691 conf_dword_read read;
42692 - } dw;
42693 + } __no_const dw;
42694 struct {
42695 conf_word_write write;
42696 conf_word_read read;
42697 - } w;
42698 + } __no_const w;
42699 struct {
42700 conf_byte_write write;
42701 conf_byte_read read;
42702 - } b;
42703 + } __no_const b;
42704 } u;
42705 struct list_head list;
42706 };
42707 diff --git a/drivers/xen/xenbus/xenbus_dev_frontend.c b/drivers/xen/xenbus/xenbus_dev_frontend.c
42708 index 89f7625..ac72702 100644
42709 --- a/drivers/xen/xenbus/xenbus_dev_frontend.c
42710 +++ b/drivers/xen/xenbus/xenbus_dev_frontend.c
42711 @@ -458,7 +458,7 @@ static ssize_t xenbus_file_write(struct file *filp,
42712 goto out;
42713
42714 /* Can't write a xenbus message larger we can buffer */
42715 - if ((len + u->len) > sizeof(u->u.buffer)) {
42716 + if (len > sizeof(u->u.buffer) - u->len) {
42717 /* On error, dump existing buffer */
42718 u->len = 0;
42719 rc = -EINVAL;
42720 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42721 index cbf9dbb..35c3af7 100644
42722 --- a/fs/9p/vfs_inode.c
42723 +++ b/fs/9p/vfs_inode.c
42724 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42725 void
42726 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42727 {
42728 - char *s = nd_get_link(nd);
42729 + const char *s = nd_get_link(nd);
42730
42731 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42732 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42733 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42734 index 0225742..1cd4732 100644
42735 --- a/fs/Kconfig.binfmt
42736 +++ b/fs/Kconfig.binfmt
42737 @@ -89,7 +89,7 @@ config HAVE_AOUT
42738
42739 config BINFMT_AOUT
42740 tristate "Kernel support for a.out and ECOFF binaries"
42741 - depends on HAVE_AOUT
42742 + depends on HAVE_AOUT && BROKEN
42743 ---help---
42744 A.out (Assembler.OUTput) is a set of formats for libraries and
42745 executables used in the earliest versions of UNIX. Linux used
42746 diff --git a/fs/aio.c b/fs/aio.c
42747 index 71f613c..9d01f1f 100644
42748 --- a/fs/aio.c
42749 +++ b/fs/aio.c
42750 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42751 size += sizeof(struct io_event) * nr_events;
42752 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42753
42754 - if (nr_pages < 0)
42755 + if (nr_pages <= 0)
42756 return -EINVAL;
42757
42758 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42759 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42760 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42761 {
42762 ssize_t ret;
42763 + struct iovec iovstack;
42764
42765 #ifdef CONFIG_COMPAT
42766 if (compat)
42767 ret = compat_rw_copy_check_uvector(type,
42768 (struct compat_iovec __user *)kiocb->ki_buf,
42769 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42770 + kiocb->ki_nbytes, 1, &iovstack,
42771 &kiocb->ki_iovec);
42772 else
42773 #endif
42774 ret = rw_copy_check_uvector(type,
42775 (struct iovec __user *)kiocb->ki_buf,
42776 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42777 + kiocb->ki_nbytes, 1, &iovstack,
42778 &kiocb->ki_iovec);
42779 if (ret < 0)
42780 goto out;
42781 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42782 if (ret < 0)
42783 goto out;
42784
42785 + if (kiocb->ki_iovec == &iovstack) {
42786 + kiocb->ki_inline_vec = iovstack;
42787 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42788 + }
42789 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42790 kiocb->ki_cur_seg = 0;
42791 /* ki_nbytes/left now reflect bytes instead of segs */
42792 diff --git a/fs/attr.c b/fs/attr.c
42793 index 29e38a1..2bc037b 100644
42794 --- a/fs/attr.c
42795 +++ b/fs/attr.c
42796 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42797 unsigned long limit;
42798
42799 limit = rlimit(RLIMIT_FSIZE);
42800 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42801 if (limit != RLIM_INFINITY && offset > limit)
42802 goto out_sig;
42803 if (offset > inode->i_sb->s_maxbytes)
42804 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42805 index da8876d..4456166 100644
42806 --- a/fs/autofs4/waitq.c
42807 +++ b/fs/autofs4/waitq.c
42808 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42809 {
42810 unsigned long sigpipe, flags;
42811 mm_segment_t fs;
42812 - const char *data = (const char *)addr;
42813 + const char __user *data = (const char __force_user *)addr;
42814 ssize_t wr = 0;
42815
42816 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42817 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42818 return 1;
42819 }
42820
42821 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42822 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42823 +#endif
42824 +
42825 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42826 enum autofs_notify notify)
42827 {
42828 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42829
42830 /* If this is a direct mount request create a dummy name */
42831 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42832 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42833 + /* this name does get written to userland via autofs4_write() */
42834 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42835 +#else
42836 qstr.len = sprintf(name, "%p", dentry);
42837 +#endif
42838 else {
42839 qstr.len = autofs4_getpath(sbi, dentry, &name);
42840 if (!qstr.len) {
42841 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42842 index cf7f3c6..f61080d 100644
42843 --- a/fs/befs/linuxvfs.c
42844 +++ b/fs/befs/linuxvfs.c
42845 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42846 {
42847 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42848 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42849 - char *link = nd_get_link(nd);
42850 + const char *link = nd_get_link(nd);
42851 if (!IS_ERR(link))
42852 kfree(link);
42853 }
42854 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42855 index d146e18..12d1bd1 100644
42856 --- a/fs/binfmt_aout.c
42857 +++ b/fs/binfmt_aout.c
42858 @@ -16,6 +16,7 @@
42859 #include <linux/string.h>
42860 #include <linux/fs.h>
42861 #include <linux/file.h>
42862 +#include <linux/security.h>
42863 #include <linux/stat.h>
42864 #include <linux/fcntl.h>
42865 #include <linux/ptrace.h>
42866 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42867 #endif
42868 # define START_STACK(u) ((void __user *)u.start_stack)
42869
42870 + memset(&dump, 0, sizeof(dump));
42871 +
42872 fs = get_fs();
42873 set_fs(KERNEL_DS);
42874 has_dumped = 1;
42875 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42876
42877 /* If the size of the dump file exceeds the rlimit, then see what would happen
42878 if we wrote the stack, but not the data area. */
42879 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42880 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42881 dump.u_dsize = 0;
42882
42883 /* Make sure we have enough room to write the stack and data areas. */
42884 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42885 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42886 dump.u_ssize = 0;
42887
42888 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42889 rlim = rlimit(RLIMIT_DATA);
42890 if (rlim >= RLIM_INFINITY)
42891 rlim = ~0;
42892 +
42893 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42894 if (ex.a_data + ex.a_bss > rlim)
42895 return -ENOMEM;
42896
42897 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42898
42899 install_exec_creds(bprm);
42900
42901 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42902 + current->mm->pax_flags = 0UL;
42903 +#endif
42904 +
42905 +#ifdef CONFIG_PAX_PAGEEXEC
42906 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42907 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42908 +
42909 +#ifdef CONFIG_PAX_EMUTRAMP
42910 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42911 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42912 +#endif
42913 +
42914 +#ifdef CONFIG_PAX_MPROTECT
42915 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42916 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42917 +#endif
42918 +
42919 + }
42920 +#endif
42921 +
42922 if (N_MAGIC(ex) == OMAGIC) {
42923 unsigned long text_addr, map_size;
42924 loff_t pos;
42925 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42926 }
42927
42928 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42929 - PROT_READ | PROT_WRITE | PROT_EXEC,
42930 + PROT_READ | PROT_WRITE,
42931 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42932 fd_offset + ex.a_text);
42933 if (error != N_DATADDR(ex)) {
42934 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42935 index 0225fdd..08bda99 100644
42936 --- a/fs/binfmt_elf.c
42937 +++ b/fs/binfmt_elf.c
42938 @@ -32,6 +32,7 @@
42939 #include <linux/elf.h>
42940 #include <linux/utsname.h>
42941 #include <linux/coredump.h>
42942 +#include <linux/xattr.h>
42943 #include <asm/uaccess.h>
42944 #include <asm/param.h>
42945 #include <asm/page.h>
42946 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42947 #define elf_core_dump NULL
42948 #endif
42949
42950 +#ifdef CONFIG_PAX_MPROTECT
42951 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42952 +#endif
42953 +
42954 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42955 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42956 #else
42957 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42958 .load_binary = load_elf_binary,
42959 .load_shlib = load_elf_library,
42960 .core_dump = elf_core_dump,
42961 +
42962 +#ifdef CONFIG_PAX_MPROTECT
42963 + .handle_mprotect= elf_handle_mprotect,
42964 +#endif
42965 +
42966 .min_coredump = ELF_EXEC_PAGESIZE,
42967 };
42968
42969 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42970
42971 static int set_brk(unsigned long start, unsigned long end)
42972 {
42973 + unsigned long e = end;
42974 +
42975 start = ELF_PAGEALIGN(start);
42976 end = ELF_PAGEALIGN(end);
42977 if (end > start) {
42978 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42979 if (BAD_ADDR(addr))
42980 return addr;
42981 }
42982 - current->mm->start_brk = current->mm->brk = end;
42983 + current->mm->start_brk = current->mm->brk = e;
42984 return 0;
42985 }
42986
42987 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42988 elf_addr_t __user *u_rand_bytes;
42989 const char *k_platform = ELF_PLATFORM;
42990 const char *k_base_platform = ELF_BASE_PLATFORM;
42991 - unsigned char k_rand_bytes[16];
42992 + u32 k_rand_bytes[4];
42993 int items;
42994 elf_addr_t *elf_info;
42995 int ei_index = 0;
42996 const struct cred *cred = current_cred();
42997 struct vm_area_struct *vma;
42998 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42999
43000 /*
43001 * In some cases (e.g. Hyper-Threading), we want to avoid L1
43002 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43003 * Generate 16 random bytes for userspace PRNG seeding.
43004 */
43005 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
43006 - u_rand_bytes = (elf_addr_t __user *)
43007 - STACK_ALLOC(p, sizeof(k_rand_bytes));
43008 + srandom32(k_rand_bytes[0] ^ random32());
43009 + srandom32(k_rand_bytes[1] ^ random32());
43010 + srandom32(k_rand_bytes[2] ^ random32());
43011 + srandom32(k_rand_bytes[3] ^ random32());
43012 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43013 + u_rand_bytes = (elf_addr_t __user *) p;
43014 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43015 return -EFAULT;
43016
43017 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43018 return -EFAULT;
43019 current->mm->env_end = p;
43020
43021 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43022 +
43023 /* Put the elf_info on the stack in the right place. */
43024 sp = (elf_addr_t __user *)envp + 1;
43025 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43026 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43027 return -EFAULT;
43028 return 0;
43029 }
43030 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
43031 an ELF header */
43032
43033 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43034 - struct file *interpreter, unsigned long *interp_map_addr,
43035 - unsigned long no_base)
43036 + struct file *interpreter, unsigned long no_base)
43037 {
43038 struct elf_phdr *elf_phdata;
43039 struct elf_phdr *eppnt;
43040 - unsigned long load_addr = 0;
43041 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43042 int load_addr_set = 0;
43043 unsigned long last_bss = 0, elf_bss = 0;
43044 - unsigned long error = ~0UL;
43045 + unsigned long error = -EINVAL;
43046 unsigned long total_size;
43047 int retval, i, size;
43048
43049 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43050 goto out_close;
43051 }
43052
43053 +#ifdef CONFIG_PAX_SEGMEXEC
43054 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43055 + pax_task_size = SEGMEXEC_TASK_SIZE;
43056 +#endif
43057 +
43058 eppnt = elf_phdata;
43059 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43060 if (eppnt->p_type == PT_LOAD) {
43061 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43062 map_addr = elf_map(interpreter, load_addr + vaddr,
43063 eppnt, elf_prot, elf_type, total_size);
43064 total_size = 0;
43065 - if (!*interp_map_addr)
43066 - *interp_map_addr = map_addr;
43067 error = map_addr;
43068 if (BAD_ADDR(map_addr))
43069 goto out_close;
43070 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43071 k = load_addr + eppnt->p_vaddr;
43072 if (BAD_ADDR(k) ||
43073 eppnt->p_filesz > eppnt->p_memsz ||
43074 - eppnt->p_memsz > TASK_SIZE ||
43075 - TASK_SIZE - eppnt->p_memsz < k) {
43076 + eppnt->p_memsz > pax_task_size ||
43077 + pax_task_size - eppnt->p_memsz < k) {
43078 error = -ENOMEM;
43079 goto out_close;
43080 }
43081 @@ -523,6 +544,311 @@ out:
43082 return error;
43083 }
43084
43085 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43086 +#ifdef CONFIG_PAX_SOFTMODE
43087 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43088 +{
43089 + unsigned long pax_flags = 0UL;
43090 +
43091 +#ifdef CONFIG_PAX_PAGEEXEC
43092 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43093 + pax_flags |= MF_PAX_PAGEEXEC;
43094 +#endif
43095 +
43096 +#ifdef CONFIG_PAX_SEGMEXEC
43097 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43098 + pax_flags |= MF_PAX_SEGMEXEC;
43099 +#endif
43100 +
43101 +#ifdef CONFIG_PAX_EMUTRAMP
43102 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43103 + pax_flags |= MF_PAX_EMUTRAMP;
43104 +#endif
43105 +
43106 +#ifdef CONFIG_PAX_MPROTECT
43107 + if (elf_phdata->p_flags & PF_MPROTECT)
43108 + pax_flags |= MF_PAX_MPROTECT;
43109 +#endif
43110 +
43111 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43112 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43113 + pax_flags |= MF_PAX_RANDMMAP;
43114 +#endif
43115 +
43116 + return pax_flags;
43117 +}
43118 +#endif
43119 +
43120 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43121 +{
43122 + unsigned long pax_flags = 0UL;
43123 +
43124 +#ifdef CONFIG_PAX_PAGEEXEC
43125 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43126 + pax_flags |= MF_PAX_PAGEEXEC;
43127 +#endif
43128 +
43129 +#ifdef CONFIG_PAX_SEGMEXEC
43130 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43131 + pax_flags |= MF_PAX_SEGMEXEC;
43132 +#endif
43133 +
43134 +#ifdef CONFIG_PAX_EMUTRAMP
43135 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43136 + pax_flags |= MF_PAX_EMUTRAMP;
43137 +#endif
43138 +
43139 +#ifdef CONFIG_PAX_MPROTECT
43140 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43141 + pax_flags |= MF_PAX_MPROTECT;
43142 +#endif
43143 +
43144 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43145 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43146 + pax_flags |= MF_PAX_RANDMMAP;
43147 +#endif
43148 +
43149 + return pax_flags;
43150 +}
43151 +#endif
43152 +
43153 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43154 +#ifdef CONFIG_PAX_SOFTMODE
43155 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43156 +{
43157 + unsigned long pax_flags = 0UL;
43158 +
43159 +#ifdef CONFIG_PAX_PAGEEXEC
43160 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43161 + pax_flags |= MF_PAX_PAGEEXEC;
43162 +#endif
43163 +
43164 +#ifdef CONFIG_PAX_SEGMEXEC
43165 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43166 + pax_flags |= MF_PAX_SEGMEXEC;
43167 +#endif
43168 +
43169 +#ifdef CONFIG_PAX_EMUTRAMP
43170 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43171 + pax_flags |= MF_PAX_EMUTRAMP;
43172 +#endif
43173 +
43174 +#ifdef CONFIG_PAX_MPROTECT
43175 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43176 + pax_flags |= MF_PAX_MPROTECT;
43177 +#endif
43178 +
43179 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43180 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43181 + pax_flags |= MF_PAX_RANDMMAP;
43182 +#endif
43183 +
43184 + return pax_flags;
43185 +}
43186 +#endif
43187 +
43188 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43189 +{
43190 + unsigned long pax_flags = 0UL;
43191 +
43192 +#ifdef CONFIG_PAX_PAGEEXEC
43193 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43194 + pax_flags |= MF_PAX_PAGEEXEC;
43195 +#endif
43196 +
43197 +#ifdef CONFIG_PAX_SEGMEXEC
43198 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43199 + pax_flags |= MF_PAX_SEGMEXEC;
43200 +#endif
43201 +
43202 +#ifdef CONFIG_PAX_EMUTRAMP
43203 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43204 + pax_flags |= MF_PAX_EMUTRAMP;
43205 +#endif
43206 +
43207 +#ifdef CONFIG_PAX_MPROTECT
43208 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43209 + pax_flags |= MF_PAX_MPROTECT;
43210 +#endif
43211 +
43212 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43213 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43214 + pax_flags |= MF_PAX_RANDMMAP;
43215 +#endif
43216 +
43217 + return pax_flags;
43218 +}
43219 +#endif
43220 +
43221 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43222 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43223 +{
43224 + unsigned long pax_flags = 0UL;
43225 +
43226 +#ifdef CONFIG_PAX_EI_PAX
43227 +
43228 +#ifdef CONFIG_PAX_PAGEEXEC
43229 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43230 + pax_flags |= MF_PAX_PAGEEXEC;
43231 +#endif
43232 +
43233 +#ifdef CONFIG_PAX_SEGMEXEC
43234 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43235 + pax_flags |= MF_PAX_SEGMEXEC;
43236 +#endif
43237 +
43238 +#ifdef CONFIG_PAX_EMUTRAMP
43239 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43240 + pax_flags |= MF_PAX_EMUTRAMP;
43241 +#endif
43242 +
43243 +#ifdef CONFIG_PAX_MPROTECT
43244 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43245 + pax_flags |= MF_PAX_MPROTECT;
43246 +#endif
43247 +
43248 +#ifdef CONFIG_PAX_ASLR
43249 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43250 + pax_flags |= MF_PAX_RANDMMAP;
43251 +#endif
43252 +
43253 +#else
43254 +
43255 +#ifdef CONFIG_PAX_PAGEEXEC
43256 + pax_flags |= MF_PAX_PAGEEXEC;
43257 +#endif
43258 +
43259 +#ifdef CONFIG_PAX_SEGMEXEC
43260 + pax_flags |= MF_PAX_SEGMEXEC;
43261 +#endif
43262 +
43263 +#ifdef CONFIG_PAX_MPROTECT
43264 + pax_flags |= MF_PAX_MPROTECT;
43265 +#endif
43266 +
43267 +#ifdef CONFIG_PAX_RANDMMAP
43268 + if (randomize_va_space)
43269 + pax_flags |= MF_PAX_RANDMMAP;
43270 +#endif
43271 +
43272 +#endif
43273 +
43274 + return pax_flags;
43275 +}
43276 +
43277 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43278 +{
43279 +
43280 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43281 + unsigned long i;
43282 +
43283 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43284 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43285 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43286 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43287 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43288 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43289 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43290 + return ~0UL;
43291 +
43292 +#ifdef CONFIG_PAX_SOFTMODE
43293 + if (pax_softmode)
43294 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43295 + else
43296 +#endif
43297 +
43298 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43299 + break;
43300 + }
43301 +#endif
43302 +
43303 + return ~0UL;
43304 +}
43305 +
43306 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43307 +{
43308 +
43309 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43310 + ssize_t xattr_size, i;
43311 + unsigned char xattr_value[5];
43312 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43313 +
43314 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43315 + if (xattr_size <= 0)
43316 + return ~0UL;
43317 +
43318 + for (i = 0; i < xattr_size; i++)
43319 + switch (xattr_value[i]) {
43320 + default:
43321 + return ~0UL;
43322 +
43323 +#define parse_flag(option1, option2, flag) \
43324 + case option1: \
43325 + pax_flags_hardmode |= MF_PAX_##flag; \
43326 + break; \
43327 + case option2: \
43328 + pax_flags_softmode |= MF_PAX_##flag; \
43329 + break;
43330 +
43331 + parse_flag('p', 'P', PAGEEXEC);
43332 + parse_flag('e', 'E', EMUTRAMP);
43333 + parse_flag('m', 'M', MPROTECT);
43334 + parse_flag('r', 'R', RANDMMAP);
43335 + parse_flag('s', 'S', SEGMEXEC);
43336 +
43337 +#undef parse_flag
43338 + }
43339 +
43340 + if (pax_flags_hardmode & pax_flags_softmode)
43341 + return ~0UL;
43342 +
43343 +#ifdef CONFIG_PAX_SOFTMODE
43344 + if (pax_softmode)
43345 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43346 + else
43347 +#endif
43348 +
43349 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43350 +#else
43351 + return ~0UL;
43352 +#endif
43353 +
43354 +}
43355 +
43356 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43357 +{
43358 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43359 +
43360 + pax_flags = pax_parse_ei_pax(elf_ex);
43361 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43362 + xattr_pax_flags = pax_parse_xattr_pax(file);
43363 +
43364 + if (pt_pax_flags == ~0UL)
43365 + pt_pax_flags = xattr_pax_flags;
43366 + else if (xattr_pax_flags == ~0UL)
43367 + xattr_pax_flags = pt_pax_flags;
43368 + if (pt_pax_flags != xattr_pax_flags)
43369 + return -EINVAL;
43370 + if (pt_pax_flags != ~0UL)
43371 + pax_flags = pt_pax_flags;
43372 +
43373 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43374 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43375 + if ((__supported_pte_mask & _PAGE_NX))
43376 + pax_flags &= ~MF_PAX_SEGMEXEC;
43377 + else
43378 + pax_flags &= ~MF_PAX_PAGEEXEC;
43379 + }
43380 +#endif
43381 +
43382 + if (0 > pax_check_flags(&pax_flags))
43383 + return -EINVAL;
43384 +
43385 + current->mm->pax_flags = pax_flags;
43386 + return 0;
43387 +}
43388 +#endif
43389 +
43390 /*
43391 * These are the functions used to load ELF style executables and shared
43392 * libraries. There is no binary dependent code anywhere else.
43393 @@ -539,6 +865,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43394 {
43395 unsigned int random_variable = 0;
43396
43397 +#ifdef CONFIG_PAX_RANDUSTACK
43398 + if (randomize_va_space)
43399 + return stack_top - current->mm->delta_stack;
43400 +#endif
43401 +
43402 if ((current->flags & PF_RANDOMIZE) &&
43403 !(current->personality & ADDR_NO_RANDOMIZE)) {
43404 random_variable = get_random_int() & STACK_RND_MASK;
43405 @@ -557,7 +888,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43406 unsigned long load_addr = 0, load_bias = 0;
43407 int load_addr_set = 0;
43408 char * elf_interpreter = NULL;
43409 - unsigned long error;
43410 + unsigned long error = 0;
43411 struct elf_phdr *elf_ppnt, *elf_phdata;
43412 unsigned long elf_bss, elf_brk;
43413 int retval, i;
43414 @@ -567,11 +898,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43415 unsigned long start_code, end_code, start_data, end_data;
43416 unsigned long reloc_func_desc __maybe_unused = 0;
43417 int executable_stack = EXSTACK_DEFAULT;
43418 - unsigned long def_flags = 0;
43419 struct {
43420 struct elfhdr elf_ex;
43421 struct elfhdr interp_elf_ex;
43422 } *loc;
43423 + unsigned long pax_task_size = TASK_SIZE;
43424
43425 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43426 if (!loc) {
43427 @@ -707,11 +1038,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43428 goto out_free_dentry;
43429
43430 /* OK, This is the point of no return */
43431 - current->mm->def_flags = def_flags;
43432 +
43433 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43434 + current->mm->pax_flags = 0UL;
43435 +#endif
43436 +
43437 +#ifdef CONFIG_PAX_DLRESOLVE
43438 + current->mm->call_dl_resolve = 0UL;
43439 +#endif
43440 +
43441 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43442 + current->mm->call_syscall = 0UL;
43443 +#endif
43444 +
43445 +#ifdef CONFIG_PAX_ASLR
43446 + current->mm->delta_mmap = 0UL;
43447 + current->mm->delta_stack = 0UL;
43448 +#endif
43449 +
43450 + current->mm->def_flags = 0;
43451 +
43452 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43453 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43454 + send_sig(SIGKILL, current, 0);
43455 + goto out_free_dentry;
43456 + }
43457 +#endif
43458 +
43459 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43460 + pax_set_initial_flags(bprm);
43461 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43462 + if (pax_set_initial_flags_func)
43463 + (pax_set_initial_flags_func)(bprm);
43464 +#endif
43465 +
43466 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43467 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43468 + current->mm->context.user_cs_limit = PAGE_SIZE;
43469 + current->mm->def_flags |= VM_PAGEEXEC;
43470 + }
43471 +#endif
43472 +
43473 +#ifdef CONFIG_PAX_SEGMEXEC
43474 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43475 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43476 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43477 + pax_task_size = SEGMEXEC_TASK_SIZE;
43478 + current->mm->def_flags |= VM_NOHUGEPAGE;
43479 + }
43480 +#endif
43481 +
43482 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43483 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43484 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43485 + put_cpu();
43486 + }
43487 +#endif
43488
43489 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43490 may depend on the personality. */
43491 SET_PERSONALITY(loc->elf_ex);
43492 +
43493 +#ifdef CONFIG_PAX_ASLR
43494 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43495 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43496 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43497 + }
43498 +#endif
43499 +
43500 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43501 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43502 + executable_stack = EXSTACK_DISABLE_X;
43503 + current->personality &= ~READ_IMPLIES_EXEC;
43504 + } else
43505 +#endif
43506 +
43507 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43508 current->personality |= READ_IMPLIES_EXEC;
43509
43510 @@ -802,6 +1203,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43511 #else
43512 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43513 #endif
43514 +
43515 +#ifdef CONFIG_PAX_RANDMMAP
43516 + /* PaX: randomize base address at the default exe base if requested */
43517 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43518 +#ifdef CONFIG_SPARC64
43519 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43520 +#else
43521 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43522 +#endif
43523 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43524 + elf_flags |= MAP_FIXED;
43525 + }
43526 +#endif
43527 +
43528 }
43529
43530 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43531 @@ -834,9 +1249,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43532 * allowed task size. Note that p_filesz must always be
43533 * <= p_memsz so it is only necessary to check p_memsz.
43534 */
43535 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43536 - elf_ppnt->p_memsz > TASK_SIZE ||
43537 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43538 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43539 + elf_ppnt->p_memsz > pax_task_size ||
43540 + pax_task_size - elf_ppnt->p_memsz < k) {
43541 /* set_brk can never work. Avoid overflows. */
43542 send_sig(SIGKILL, current, 0);
43543 retval = -EINVAL;
43544 @@ -875,17 +1290,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43545 goto out_free_dentry;
43546 }
43547 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43548 - send_sig(SIGSEGV, current, 0);
43549 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43550 - goto out_free_dentry;
43551 + /*
43552 + * This bss-zeroing can fail if the ELF
43553 + * file specifies odd protections. So
43554 + * we don't check the return value
43555 + */
43556 }
43557
43558 +#ifdef CONFIG_PAX_RANDMMAP
43559 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43560 + unsigned long start, size;
43561 +
43562 + start = ELF_PAGEALIGN(elf_brk);
43563 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43564 + down_read(&current->mm->mmap_sem);
43565 + retval = -ENOMEM;
43566 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43567 + unsigned long prot = PROT_NONE;
43568 +
43569 + up_read(&current->mm->mmap_sem);
43570 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43571 +// if (current->personality & ADDR_NO_RANDOMIZE)
43572 +// prot = PROT_READ;
43573 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43574 + retval = IS_ERR_VALUE(start) ? start : 0;
43575 + } else
43576 + up_read(&current->mm->mmap_sem);
43577 + if (retval == 0)
43578 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43579 + if (retval < 0) {
43580 + send_sig(SIGKILL, current, 0);
43581 + goto out_free_dentry;
43582 + }
43583 + }
43584 +#endif
43585 +
43586 if (elf_interpreter) {
43587 - unsigned long uninitialized_var(interp_map_addr);
43588 -
43589 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43590 interpreter,
43591 - &interp_map_addr,
43592 load_bias);
43593 if (!IS_ERR((void *)elf_entry)) {
43594 /*
43595 @@ -1107,7 +1549,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43596 * Decide what to dump of a segment, part, all or none.
43597 */
43598 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43599 - unsigned long mm_flags)
43600 + unsigned long mm_flags, long signr)
43601 {
43602 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43603
43604 @@ -1144,7 +1586,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43605 if (vma->vm_file == NULL)
43606 return 0;
43607
43608 - if (FILTER(MAPPED_PRIVATE))
43609 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43610 goto whole;
43611
43612 /*
43613 @@ -1366,9 +1808,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43614 {
43615 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43616 int i = 0;
43617 - do
43618 + do {
43619 i += 2;
43620 - while (auxv[i - 2] != AT_NULL);
43621 + } while (auxv[i - 2] != AT_NULL);
43622 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43623 }
43624
43625 @@ -1879,14 +2321,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43626 }
43627
43628 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43629 - unsigned long mm_flags)
43630 + struct coredump_params *cprm)
43631 {
43632 struct vm_area_struct *vma;
43633 size_t size = 0;
43634
43635 for (vma = first_vma(current, gate_vma); vma != NULL;
43636 vma = next_vma(vma, gate_vma))
43637 - size += vma_dump_size(vma, mm_flags);
43638 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43639 return size;
43640 }
43641
43642 @@ -1980,7 +2422,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43643
43644 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43645
43646 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43647 + offset += elf_core_vma_data_size(gate_vma, cprm);
43648 offset += elf_core_extra_data_size();
43649 e_shoff = offset;
43650
43651 @@ -1994,10 +2436,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43652 offset = dataoff;
43653
43654 size += sizeof(*elf);
43655 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43656 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43657 goto end_coredump;
43658
43659 size += sizeof(*phdr4note);
43660 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43661 if (size > cprm->limit
43662 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43663 goto end_coredump;
43664 @@ -2011,7 +2455,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43665 phdr.p_offset = offset;
43666 phdr.p_vaddr = vma->vm_start;
43667 phdr.p_paddr = 0;
43668 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43669 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43670 phdr.p_memsz = vma->vm_end - vma->vm_start;
43671 offset += phdr.p_filesz;
43672 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43673 @@ -2022,6 +2466,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43674 phdr.p_align = ELF_EXEC_PAGESIZE;
43675
43676 size += sizeof(phdr);
43677 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43678 if (size > cprm->limit
43679 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43680 goto end_coredump;
43681 @@ -2046,7 +2491,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43682 unsigned long addr;
43683 unsigned long end;
43684
43685 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43686 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43687
43688 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43689 struct page *page;
43690 @@ -2055,6 +2500,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43691 page = get_dump_page(addr);
43692 if (page) {
43693 void *kaddr = kmap(page);
43694 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43695 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43696 !dump_write(cprm->file, kaddr,
43697 PAGE_SIZE);
43698 @@ -2072,6 +2518,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43699
43700 if (e_phnum == PN_XNUM) {
43701 size += sizeof(*shdr4extnum);
43702 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43703 if (size > cprm->limit
43704 || !dump_write(cprm->file, shdr4extnum,
43705 sizeof(*shdr4extnum)))
43706 @@ -2092,6 +2539,97 @@ out:
43707
43708 #endif /* CONFIG_ELF_CORE */
43709
43710 +#ifdef CONFIG_PAX_MPROTECT
43711 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43712 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43713 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43714 + *
43715 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43716 + * basis because we want to allow the common case and not the special ones.
43717 + */
43718 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43719 +{
43720 + struct elfhdr elf_h;
43721 + struct elf_phdr elf_p;
43722 + unsigned long i;
43723 + unsigned long oldflags;
43724 + bool is_textrel_rw, is_textrel_rx, is_relro;
43725 +
43726 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43727 + return;
43728 +
43729 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43730 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43731 +
43732 +#ifdef CONFIG_PAX_ELFRELOCS
43733 + /* possible TEXTREL */
43734 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43735 + 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);
43736 +#else
43737 + is_textrel_rw = false;
43738 + is_textrel_rx = false;
43739 +#endif
43740 +
43741 + /* possible RELRO */
43742 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43743 +
43744 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43745 + return;
43746 +
43747 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43748 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43749 +
43750 +#ifdef CONFIG_PAX_ETEXECRELOCS
43751 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43752 +#else
43753 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43754 +#endif
43755 +
43756 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43757 + !elf_check_arch(&elf_h) ||
43758 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43759 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43760 + return;
43761 +
43762 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43763 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43764 + return;
43765 + switch (elf_p.p_type) {
43766 + case PT_DYNAMIC:
43767 + if (!is_textrel_rw && !is_textrel_rx)
43768 + continue;
43769 + i = 0UL;
43770 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43771 + elf_dyn dyn;
43772 +
43773 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43774 + return;
43775 + if (dyn.d_tag == DT_NULL)
43776 + return;
43777 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43778 + gr_log_textrel(vma);
43779 + if (is_textrel_rw)
43780 + vma->vm_flags |= VM_MAYWRITE;
43781 + else
43782 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43783 + vma->vm_flags &= ~VM_MAYWRITE;
43784 + return;
43785 + }
43786 + i++;
43787 + }
43788 + return;
43789 +
43790 + case PT_GNU_RELRO:
43791 + if (!is_relro)
43792 + continue;
43793 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43794 + vma->vm_flags &= ~VM_MAYWRITE;
43795 + return;
43796 + }
43797 + }
43798 +}
43799 +#endif
43800 +
43801 static int __init init_elf_binfmt(void)
43802 {
43803 register_binfmt(&elf_format);
43804 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43805 index 178cb70..8972997 100644
43806 --- a/fs/binfmt_flat.c
43807 +++ b/fs/binfmt_flat.c
43808 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43809 realdatastart = (unsigned long) -ENOMEM;
43810 printk("Unable to allocate RAM for process data, errno %d\n",
43811 (int)-realdatastart);
43812 + down_write(&current->mm->mmap_sem);
43813 vm_munmap(textpos, text_len);
43814 + up_write(&current->mm->mmap_sem);
43815 ret = realdatastart;
43816 goto err;
43817 }
43818 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43819 }
43820 if (IS_ERR_VALUE(result)) {
43821 printk("Unable to read data+bss, errno %d\n", (int)-result);
43822 + down_write(&current->mm->mmap_sem);
43823 vm_munmap(textpos, text_len);
43824 vm_munmap(realdatastart, len);
43825 + up_write(&current->mm->mmap_sem);
43826 ret = result;
43827 goto err;
43828 }
43829 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43830 }
43831 if (IS_ERR_VALUE(result)) {
43832 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43833 + down_write(&current->mm->mmap_sem);
43834 vm_munmap(textpos, text_len + data_len + extra +
43835 MAX_SHARED_LIBS * sizeof(unsigned long));
43836 + up_write(&current->mm->mmap_sem);
43837 ret = result;
43838 goto err;
43839 }
43840 diff --git a/fs/bio.c b/fs/bio.c
43841 index 71072ab..439851b 100644
43842 --- a/fs/bio.c
43843 +++ b/fs/bio.c
43844 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43845 /*
43846 * Overflow, abort
43847 */
43848 - if (end < start)
43849 + if (end < start || end - start > INT_MAX - nr_pages)
43850 return ERR_PTR(-EINVAL);
43851
43852 nr_pages += end - start;
43853 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43854 /*
43855 * Overflow, abort
43856 */
43857 - if (end < start)
43858 + if (end < start || end - start > INT_MAX - nr_pages)
43859 return ERR_PTR(-EINVAL);
43860
43861 nr_pages += end - start;
43862 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43863 const int read = bio_data_dir(bio) == READ;
43864 struct bio_map_data *bmd = bio->bi_private;
43865 int i;
43866 - char *p = bmd->sgvecs[0].iov_base;
43867 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43868
43869 __bio_for_each_segment(bvec, bio, i, 0) {
43870 char *addr = page_address(bvec->bv_page);
43871 diff --git a/fs/block_dev.c b/fs/block_dev.c
43872 index 38e721b..7a9c5bc 100644
43873 --- a/fs/block_dev.c
43874 +++ b/fs/block_dev.c
43875 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43876 else if (bdev->bd_contains == bdev)
43877 return true; /* is a whole device which isn't held */
43878
43879 - else if (whole->bd_holder == bd_may_claim)
43880 + else if (whole->bd_holder == (void *)bd_may_claim)
43881 return true; /* is a partition of a device that is being partitioned */
43882 else if (whole->bd_holder != NULL)
43883 return false; /* is a partition of a held device */
43884 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43885 index 9197e2e..7f731f8 100644
43886 --- a/fs/btrfs/check-integrity.c
43887 +++ b/fs/btrfs/check-integrity.c
43888 @@ -155,7 +155,7 @@ struct btrfsic_block {
43889 union {
43890 bio_end_io_t *bio;
43891 bh_end_io_t *bh;
43892 - } orig_bio_bh_end_io;
43893 + } __no_const orig_bio_bh_end_io;
43894 int submit_bio_bh_rw;
43895 u64 flush_gen; /* only valid if !never_written */
43896 };
43897 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43898 index 6d183f6..f47cc7a 100644
43899 --- a/fs/btrfs/ctree.c
43900 +++ b/fs/btrfs/ctree.c
43901 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43902 free_extent_buffer(buf);
43903 add_root_to_dirty_list(root);
43904 } else {
43905 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43906 - parent_start = parent->start;
43907 - else
43908 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43909 + if (parent)
43910 + parent_start = parent->start;
43911 + else
43912 + parent_start = 0;
43913 + } else
43914 parent_start = 0;
43915
43916 WARN_ON(trans->transid != btrfs_header_generation(parent));
43917 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43918 index ec154f9..bf617a7 100644
43919 --- a/fs/btrfs/inode.c
43920 +++ b/fs/btrfs/inode.c
43921 @@ -7126,7 +7126,7 @@ fail:
43922 return -ENOMEM;
43923 }
43924
43925 -static int btrfs_getattr(struct vfsmount *mnt,
43926 +int btrfs_getattr(struct vfsmount *mnt,
43927 struct dentry *dentry, struct kstat *stat)
43928 {
43929 struct inode *inode = dentry->d_inode;
43930 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43931 return 0;
43932 }
43933
43934 +EXPORT_SYMBOL(btrfs_getattr);
43935 +
43936 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43937 +{
43938 + return BTRFS_I(inode)->root->anon_dev;
43939 +}
43940 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43941 +
43942 /*
43943 * If a file is moved, it will inherit the cow and compression flags of the new
43944 * directory.
43945 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43946 index 9df50fa..6cd20d0 100644
43947 --- a/fs/btrfs/ioctl.c
43948 +++ b/fs/btrfs/ioctl.c
43949 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43950 for (i = 0; i < num_types; i++) {
43951 struct btrfs_space_info *tmp;
43952
43953 + /* Don't copy in more than we allocated */
43954 if (!slot_count)
43955 break;
43956
43957 + slot_count--;
43958 +
43959 info = NULL;
43960 rcu_read_lock();
43961 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43962 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43963 memcpy(dest, &space, sizeof(space));
43964 dest++;
43965 space_args.total_spaces++;
43966 - slot_count--;
43967 }
43968 - if (!slot_count)
43969 - break;
43970 }
43971 up_read(&info->groups_sem);
43972 }
43973 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43974 index 4da0865..01c4778 100644
43975 --- a/fs/btrfs/relocation.c
43976 +++ b/fs/btrfs/relocation.c
43977 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43978 }
43979 spin_unlock(&rc->reloc_root_tree.lock);
43980
43981 - BUG_ON((struct btrfs_root *)node->data != root);
43982 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43983
43984 if (!del) {
43985 spin_lock(&rc->reloc_root_tree.lock);
43986 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43987 index 622f469..e8d2d55 100644
43988 --- a/fs/cachefiles/bind.c
43989 +++ b/fs/cachefiles/bind.c
43990 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43991 args);
43992
43993 /* start by checking things over */
43994 - ASSERT(cache->fstop_percent >= 0 &&
43995 - cache->fstop_percent < cache->fcull_percent &&
43996 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43997 cache->fcull_percent < cache->frun_percent &&
43998 cache->frun_percent < 100);
43999
44000 - ASSERT(cache->bstop_percent >= 0 &&
44001 - cache->bstop_percent < cache->bcull_percent &&
44002 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
44003 cache->bcull_percent < cache->brun_percent &&
44004 cache->brun_percent < 100);
44005
44006 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
44007 index 0a1467b..6a53245 100644
44008 --- a/fs/cachefiles/daemon.c
44009 +++ b/fs/cachefiles/daemon.c
44010 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
44011 if (n > buflen)
44012 return -EMSGSIZE;
44013
44014 - if (copy_to_user(_buffer, buffer, n) != 0)
44015 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
44016 return -EFAULT;
44017
44018 return n;
44019 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
44020 if (test_bit(CACHEFILES_DEAD, &cache->flags))
44021 return -EIO;
44022
44023 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
44024 + if (datalen > PAGE_SIZE - 1)
44025 return -EOPNOTSUPP;
44026
44027 /* drag the command string into the kernel so we can parse it */
44028 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
44029 if (args[0] != '%' || args[1] != '\0')
44030 return -EINVAL;
44031
44032 - if (fstop < 0 || fstop >= cache->fcull_percent)
44033 + if (fstop >= cache->fcull_percent)
44034 return cachefiles_daemon_range_error(cache, args);
44035
44036 cache->fstop_percent = fstop;
44037 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44038 if (args[0] != '%' || args[1] != '\0')
44039 return -EINVAL;
44040
44041 - if (bstop < 0 || bstop >= cache->bcull_percent)
44042 + if (bstop >= cache->bcull_percent)
44043 return cachefiles_daemon_range_error(cache, args);
44044
44045 cache->bstop_percent = bstop;
44046 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44047 index bd6bc1b..b627b53 100644
44048 --- a/fs/cachefiles/internal.h
44049 +++ b/fs/cachefiles/internal.h
44050 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44051 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44052 struct rb_root active_nodes; /* active nodes (can't be culled) */
44053 rwlock_t active_lock; /* lock for active_nodes */
44054 - atomic_t gravecounter; /* graveyard uniquifier */
44055 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44056 unsigned frun_percent; /* when to stop culling (% files) */
44057 unsigned fcull_percent; /* when to start culling (% files) */
44058 unsigned fstop_percent; /* when to stop allocating (% files) */
44059 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44060 * proc.c
44061 */
44062 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44063 -extern atomic_t cachefiles_lookup_histogram[HZ];
44064 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44065 -extern atomic_t cachefiles_create_histogram[HZ];
44066 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44067 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44068 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44069
44070 extern int __init cachefiles_proc_init(void);
44071 extern void cachefiles_proc_cleanup(void);
44072 static inline
44073 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44074 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44075 {
44076 unsigned long jif = jiffies - start_jif;
44077 if (jif >= HZ)
44078 jif = HZ - 1;
44079 - atomic_inc(&histogram[jif]);
44080 + atomic_inc_unchecked(&histogram[jif]);
44081 }
44082
44083 #else
44084 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44085 index b0b5f7c..039bb26 100644
44086 --- a/fs/cachefiles/namei.c
44087 +++ b/fs/cachefiles/namei.c
44088 @@ -318,7 +318,7 @@ try_again:
44089 /* first step is to make up a grave dentry in the graveyard */
44090 sprintf(nbuffer, "%08x%08x",
44091 (uint32_t) get_seconds(),
44092 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44093 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44094
44095 /* do the multiway lock magic */
44096 trap = lock_rename(cache->graveyard, dir);
44097 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44098 index eccd339..4c1d995 100644
44099 --- a/fs/cachefiles/proc.c
44100 +++ b/fs/cachefiles/proc.c
44101 @@ -14,9 +14,9 @@
44102 #include <linux/seq_file.h>
44103 #include "internal.h"
44104
44105 -atomic_t cachefiles_lookup_histogram[HZ];
44106 -atomic_t cachefiles_mkdir_histogram[HZ];
44107 -atomic_t cachefiles_create_histogram[HZ];
44108 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44109 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44110 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44111
44112 /*
44113 * display the latency histogram
44114 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44115 return 0;
44116 default:
44117 index = (unsigned long) v - 3;
44118 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44119 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44120 - z = atomic_read(&cachefiles_create_histogram[index]);
44121 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44122 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44123 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44124 if (x == 0 && y == 0 && z == 0)
44125 return 0;
44126
44127 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44128 index c994691..2a1537f 100644
44129 --- a/fs/cachefiles/rdwr.c
44130 +++ b/fs/cachefiles/rdwr.c
44131 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44132 old_fs = get_fs();
44133 set_fs(KERNEL_DS);
44134 ret = file->f_op->write(
44135 - file, (const void __user *) data, len, &pos);
44136 + file, (const void __force_user *) data, len, &pos);
44137 set_fs(old_fs);
44138 kunmap(page);
44139 if (ret != len)
44140 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44141 index e5b7731..b9c59fb 100644
44142 --- a/fs/ceph/dir.c
44143 +++ b/fs/ceph/dir.c
44144 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44145 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44146 struct ceph_mds_client *mdsc = fsc->mdsc;
44147 unsigned frag = fpos_frag(filp->f_pos);
44148 - int off = fpos_off(filp->f_pos);
44149 + unsigned int off = fpos_off(filp->f_pos);
44150 int err;
44151 u32 ftype;
44152 struct ceph_mds_reply_info_parsed *rinfo;
44153 diff --git a/fs/ceph/export.c b/fs/ceph/export.c
44154 index 02ce909..9349bb3 100644
44155 --- a/fs/ceph/export.c
44156 +++ b/fs/ceph/export.c
44157 @@ -90,6 +90,8 @@ static int ceph_encode_fh(struct inode *inode, u32 *rawfh, int *max_len,
44158 *max_len = handle_length;
44159 type = 255;
44160 }
44161 + if (dentry)
44162 + dput(dentry);
44163 return type;
44164 }
44165
44166 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44167 index d9ea6ed..1e6c8ac 100644
44168 --- a/fs/cifs/cifs_debug.c
44169 +++ b/fs/cifs/cifs_debug.c
44170 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44171
44172 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44173 #ifdef CONFIG_CIFS_STATS2
44174 - atomic_set(&totBufAllocCount, 0);
44175 - atomic_set(&totSmBufAllocCount, 0);
44176 + atomic_set_unchecked(&totBufAllocCount, 0);
44177 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44178 #endif /* CONFIG_CIFS_STATS2 */
44179 spin_lock(&cifs_tcp_ses_lock);
44180 list_for_each(tmp1, &cifs_tcp_ses_list) {
44181 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44182 tcon = list_entry(tmp3,
44183 struct cifs_tcon,
44184 tcon_list);
44185 - atomic_set(&tcon->num_smbs_sent, 0);
44186 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44187 if (server->ops->clear_stats)
44188 server->ops->clear_stats(tcon);
44189 }
44190 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44191 smBufAllocCount.counter, cifs_min_small);
44192 #ifdef CONFIG_CIFS_STATS2
44193 seq_printf(m, "Total Large %d Small %d Allocations\n",
44194 - atomic_read(&totBufAllocCount),
44195 - atomic_read(&totSmBufAllocCount));
44196 + atomic_read_unchecked(&totBufAllocCount),
44197 + atomic_read_unchecked(&totSmBufAllocCount));
44198 #endif /* CONFIG_CIFS_STATS2 */
44199
44200 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44201 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44202 if (tcon->need_reconnect)
44203 seq_puts(m, "\tDISCONNECTED ");
44204 seq_printf(m, "\nSMBs: %d",
44205 - atomic_read(&tcon->num_smbs_sent));
44206 + atomic_read_unchecked(&tcon->num_smbs_sent));
44207 if (server->ops->print_stats)
44208 server->ops->print_stats(m, tcon);
44209 }
44210 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44211 index db8a404..c712e2e 100644
44212 --- a/fs/cifs/cifsfs.c
44213 +++ b/fs/cifs/cifsfs.c
44214 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44215 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44216 cifs_req_cachep = kmem_cache_create("cifs_request",
44217 CIFSMaxBufSize + max_hdr_size, 0,
44218 - SLAB_HWCACHE_ALIGN, NULL);
44219 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44220 if (cifs_req_cachep == NULL)
44221 return -ENOMEM;
44222
44223 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44224 efficient to alloc 1 per page off the slab compared to 17K (5page)
44225 alloc of large cifs buffers even when page debugging is on */
44226 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44227 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44228 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44229 NULL);
44230 if (cifs_sm_req_cachep == NULL) {
44231 mempool_destroy(cifs_req_poolp);
44232 @@ -1115,8 +1115,8 @@ init_cifs(void)
44233 atomic_set(&bufAllocCount, 0);
44234 atomic_set(&smBufAllocCount, 0);
44235 #ifdef CONFIG_CIFS_STATS2
44236 - atomic_set(&totBufAllocCount, 0);
44237 - atomic_set(&totSmBufAllocCount, 0);
44238 + atomic_set_unchecked(&totBufAllocCount, 0);
44239 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44240 #endif /* CONFIG_CIFS_STATS2 */
44241
44242 atomic_set(&midCount, 0);
44243 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44244 index 977dc0e..ba48ab9 100644
44245 --- a/fs/cifs/cifsglob.h
44246 +++ b/fs/cifs/cifsglob.h
44247 @@ -590,35 +590,35 @@ struct cifs_tcon {
44248 __u16 Flags; /* optional support bits */
44249 enum statusEnum tidStatus;
44250 #ifdef CONFIG_CIFS_STATS
44251 - atomic_t num_smbs_sent;
44252 + atomic_unchecked_t num_smbs_sent;
44253 union {
44254 struct {
44255 - atomic_t num_writes;
44256 - atomic_t num_reads;
44257 - atomic_t num_flushes;
44258 - atomic_t num_oplock_brks;
44259 - atomic_t num_opens;
44260 - atomic_t num_closes;
44261 - atomic_t num_deletes;
44262 - atomic_t num_mkdirs;
44263 - atomic_t num_posixopens;
44264 - atomic_t num_posixmkdirs;
44265 - atomic_t num_rmdirs;
44266 - atomic_t num_renames;
44267 - atomic_t num_t2renames;
44268 - atomic_t num_ffirst;
44269 - atomic_t num_fnext;
44270 - atomic_t num_fclose;
44271 - atomic_t num_hardlinks;
44272 - atomic_t num_symlinks;
44273 - atomic_t num_locks;
44274 - atomic_t num_acl_get;
44275 - atomic_t num_acl_set;
44276 + atomic_unchecked_t num_writes;
44277 + atomic_unchecked_t num_reads;
44278 + atomic_unchecked_t num_flushes;
44279 + atomic_unchecked_t num_oplock_brks;
44280 + atomic_unchecked_t num_opens;
44281 + atomic_unchecked_t num_closes;
44282 + atomic_unchecked_t num_deletes;
44283 + atomic_unchecked_t num_mkdirs;
44284 + atomic_unchecked_t num_posixopens;
44285 + atomic_unchecked_t num_posixmkdirs;
44286 + atomic_unchecked_t num_rmdirs;
44287 + atomic_unchecked_t num_renames;
44288 + atomic_unchecked_t num_t2renames;
44289 + atomic_unchecked_t num_ffirst;
44290 + atomic_unchecked_t num_fnext;
44291 + atomic_unchecked_t num_fclose;
44292 + atomic_unchecked_t num_hardlinks;
44293 + atomic_unchecked_t num_symlinks;
44294 + atomic_unchecked_t num_locks;
44295 + atomic_unchecked_t num_acl_get;
44296 + atomic_unchecked_t num_acl_set;
44297 } cifs_stats;
44298 #ifdef CONFIG_CIFS_SMB2
44299 struct {
44300 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44301 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44302 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44303 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44304 } smb2_stats;
44305 #endif /* CONFIG_CIFS_SMB2 */
44306 } stats;
44307 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44308 }
44309
44310 #ifdef CONFIG_CIFS_STATS
44311 -#define cifs_stats_inc atomic_inc
44312 +#define cifs_stats_inc atomic_inc_unchecked
44313
44314 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44315 unsigned int bytes)
44316 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44317 /* Various Debug counters */
44318 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44319 #ifdef CONFIG_CIFS_STATS2
44320 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44321 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44322 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44323 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44324 #endif
44325 GLOBAL_EXTERN atomic_t smBufAllocCount;
44326 GLOBAL_EXTERN atomic_t midCount;
44327 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44328 index e6ce3b1..adc21fd 100644
44329 --- a/fs/cifs/link.c
44330 +++ b/fs/cifs/link.c
44331 @@ -602,7 +602,7 @@ symlink_exit:
44332
44333 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44334 {
44335 - char *p = nd_get_link(nd);
44336 + const char *p = nd_get_link(nd);
44337 if (!IS_ERR(p))
44338 kfree(p);
44339 }
44340 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44341 index ce41fee..ac0d27a 100644
44342 --- a/fs/cifs/misc.c
44343 +++ b/fs/cifs/misc.c
44344 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44345 memset(ret_buf, 0, buf_size + 3);
44346 atomic_inc(&bufAllocCount);
44347 #ifdef CONFIG_CIFS_STATS2
44348 - atomic_inc(&totBufAllocCount);
44349 + atomic_inc_unchecked(&totBufAllocCount);
44350 #endif /* CONFIG_CIFS_STATS2 */
44351 }
44352
44353 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44354 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44355 atomic_inc(&smBufAllocCount);
44356 #ifdef CONFIG_CIFS_STATS2
44357 - atomic_inc(&totSmBufAllocCount);
44358 + atomic_inc_unchecked(&totSmBufAllocCount);
44359 #endif /* CONFIG_CIFS_STATS2 */
44360
44361 }
44362 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44363 index 3129ac7..cc4a948 100644
44364 --- a/fs/cifs/smb1ops.c
44365 +++ b/fs/cifs/smb1ops.c
44366 @@ -524,27 +524,27 @@ static void
44367 cifs_clear_stats(struct cifs_tcon *tcon)
44368 {
44369 #ifdef CONFIG_CIFS_STATS
44370 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44371 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44372 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44373 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44374 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44375 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44376 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44377 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44378 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44379 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44380 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44381 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44382 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44383 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44384 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44385 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44386 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44387 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44388 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44389 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44390 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44391 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44392 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44393 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44394 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44395 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44396 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44397 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44398 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44399 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44400 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44401 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44402 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44403 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44404 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44405 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44406 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44407 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44408 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44409 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44410 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44411 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44412 #endif
44413 }
44414
44415 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44416 {
44417 #ifdef CONFIG_CIFS_STATS
44418 seq_printf(m, " Oplocks breaks: %d",
44419 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44420 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44421 seq_printf(m, "\nReads: %d Bytes: %llu",
44422 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44423 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44424 (long long)(tcon->bytes_read));
44425 seq_printf(m, "\nWrites: %d Bytes: %llu",
44426 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44427 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44428 (long long)(tcon->bytes_written));
44429 seq_printf(m, "\nFlushes: %d",
44430 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44431 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44432 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44433 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44434 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44435 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44436 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44437 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44438 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44439 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44440 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44441 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44442 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44443 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44444 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44445 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44446 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44447 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44448 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44449 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44450 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44451 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44452 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44453 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44454 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44455 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44456 seq_printf(m, "\nRenames: %d T2 Renames %d",
44457 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44458 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44459 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44460 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44461 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44462 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44463 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44464 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44465 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44466 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44467 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44468 #endif
44469 }
44470
44471 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44472 index 826209b..fa460f4 100644
44473 --- a/fs/cifs/smb2ops.c
44474 +++ b/fs/cifs/smb2ops.c
44475 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44476 #ifdef CONFIG_CIFS_STATS
44477 int i;
44478 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44479 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44480 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44481 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44482 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44483 }
44484 #endif
44485 }
44486 @@ -229,66 +229,66 @@ static void
44487 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44488 {
44489 #ifdef CONFIG_CIFS_STATS
44490 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44491 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44492 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44493 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44494 seq_printf(m, "\nNegotiates: %d sent %d failed",
44495 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44496 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44497 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44498 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44499 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44500 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44501 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44502 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44503 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44504 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44505 seq_printf(m, "\nLogoffs: %d sent %d failed",
44506 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44507 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44508 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44509 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44510 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44511 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44512 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44513 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44514 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44515 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44516 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44517 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44518 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44519 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44520 seq_printf(m, "\nCreates: %d sent %d failed",
44521 - atomic_read(&sent[SMB2_CREATE_HE]),
44522 - atomic_read(&failed[SMB2_CREATE_HE]));
44523 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44524 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44525 seq_printf(m, "\nCloses: %d sent %d failed",
44526 - atomic_read(&sent[SMB2_CLOSE_HE]),
44527 - atomic_read(&failed[SMB2_CLOSE_HE]));
44528 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44529 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44530 seq_printf(m, "\nFlushes: %d sent %d failed",
44531 - atomic_read(&sent[SMB2_FLUSH_HE]),
44532 - atomic_read(&failed[SMB2_FLUSH_HE]));
44533 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44534 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44535 seq_printf(m, "\nReads: %d sent %d failed",
44536 - atomic_read(&sent[SMB2_READ_HE]),
44537 - atomic_read(&failed[SMB2_READ_HE]));
44538 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44539 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44540 seq_printf(m, "\nWrites: %d sent %d failed",
44541 - atomic_read(&sent[SMB2_WRITE_HE]),
44542 - atomic_read(&failed[SMB2_WRITE_HE]));
44543 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44544 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44545 seq_printf(m, "\nLocks: %d sent %d failed",
44546 - atomic_read(&sent[SMB2_LOCK_HE]),
44547 - atomic_read(&failed[SMB2_LOCK_HE]));
44548 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44549 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44550 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44551 - atomic_read(&sent[SMB2_IOCTL_HE]),
44552 - atomic_read(&failed[SMB2_IOCTL_HE]));
44553 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44554 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44555 seq_printf(m, "\nCancels: %d sent %d failed",
44556 - atomic_read(&sent[SMB2_CANCEL_HE]),
44557 - atomic_read(&failed[SMB2_CANCEL_HE]));
44558 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44559 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44560 seq_printf(m, "\nEchos: %d sent %d failed",
44561 - atomic_read(&sent[SMB2_ECHO_HE]),
44562 - atomic_read(&failed[SMB2_ECHO_HE]));
44563 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44564 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44565 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44566 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44567 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44568 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44569 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44570 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44571 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44572 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44573 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44574 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44575 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44576 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44577 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44578 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44579 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44580 seq_printf(m, "\nSetInfos: %d sent %d failed",
44581 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44582 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44583 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44584 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44585 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44586 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44587 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44588 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44589 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44590 #endif
44591 }
44592
44593 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44594 index 958ae0e..505c9d0 100644
44595 --- a/fs/coda/cache.c
44596 +++ b/fs/coda/cache.c
44597 @@ -24,7 +24,7 @@
44598 #include "coda_linux.h"
44599 #include "coda_cache.h"
44600
44601 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44602 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44603
44604 /* replace or extend an acl cache hit */
44605 void coda_cache_enter(struct inode *inode, int mask)
44606 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44607 struct coda_inode_info *cii = ITOC(inode);
44608
44609 spin_lock(&cii->c_lock);
44610 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44611 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44612 if (cii->c_uid != current_fsuid()) {
44613 cii->c_uid = current_fsuid();
44614 cii->c_cached_perm = mask;
44615 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44616 {
44617 struct coda_inode_info *cii = ITOC(inode);
44618 spin_lock(&cii->c_lock);
44619 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44620 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44621 spin_unlock(&cii->c_lock);
44622 }
44623
44624 /* remove all acl caches */
44625 void coda_cache_clear_all(struct super_block *sb)
44626 {
44627 - atomic_inc(&permission_epoch);
44628 + atomic_inc_unchecked(&permission_epoch);
44629 }
44630
44631
44632 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44633 spin_lock(&cii->c_lock);
44634 hit = (mask & cii->c_cached_perm) == mask &&
44635 cii->c_uid == current_fsuid() &&
44636 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44637 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44638 spin_unlock(&cii->c_lock);
44639
44640 return hit;
44641 diff --git a/fs/compat.c b/fs/compat.c
44642 index 1bdb350..9f28287 100644
44643 --- a/fs/compat.c
44644 +++ b/fs/compat.c
44645 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44646
44647 set_fs(KERNEL_DS);
44648 /* The __user pointer cast is valid because of the set_fs() */
44649 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44650 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44651 set_fs(oldfs);
44652 /* truncating is ok because it's a user address */
44653 if (!ret)
44654 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44655 goto out;
44656
44657 ret = -EINVAL;
44658 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44659 + if (nr_segs > UIO_MAXIOV)
44660 goto out;
44661 if (nr_segs > fast_segs) {
44662 ret = -ENOMEM;
44663 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44664
44665 struct compat_readdir_callback {
44666 struct compat_old_linux_dirent __user *dirent;
44667 + struct file * file;
44668 int result;
44669 };
44670
44671 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44672 buf->result = -EOVERFLOW;
44673 return -EOVERFLOW;
44674 }
44675 +
44676 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44677 + return 0;
44678 +
44679 buf->result++;
44680 dirent = buf->dirent;
44681 if (!access_ok(VERIFY_WRITE, dirent,
44682 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44683
44684 buf.result = 0;
44685 buf.dirent = dirent;
44686 + buf.file = file;
44687
44688 error = vfs_readdir(file, compat_fillonedir, &buf);
44689 if (buf.result)
44690 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44691 struct compat_getdents_callback {
44692 struct compat_linux_dirent __user *current_dir;
44693 struct compat_linux_dirent __user *previous;
44694 + struct file * file;
44695 int count;
44696 int error;
44697 };
44698 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44699 buf->error = -EOVERFLOW;
44700 return -EOVERFLOW;
44701 }
44702 +
44703 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44704 + return 0;
44705 +
44706 dirent = buf->previous;
44707 if (dirent) {
44708 if (__put_user(offset, &dirent->d_off))
44709 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44710 buf.previous = NULL;
44711 buf.count = count;
44712 buf.error = 0;
44713 + buf.file = file;
44714
44715 error = vfs_readdir(file, compat_filldir, &buf);
44716 if (error >= 0)
44717 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44718 struct compat_getdents_callback64 {
44719 struct linux_dirent64 __user *current_dir;
44720 struct linux_dirent64 __user *previous;
44721 + struct file * file;
44722 int count;
44723 int error;
44724 };
44725 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44726 buf->error = -EINVAL; /* only used if we fail.. */
44727 if (reclen > buf->count)
44728 return -EINVAL;
44729 +
44730 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44731 + return 0;
44732 +
44733 dirent = buf->previous;
44734
44735 if (dirent) {
44736 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44737 buf.previous = NULL;
44738 buf.count = count;
44739 buf.error = 0;
44740 + buf.file = file;
44741
44742 error = vfs_readdir(file, compat_filldir64, &buf);
44743 if (error >= 0)
44744 error = buf.error;
44745 lastdirent = buf.previous;
44746 if (lastdirent) {
44747 - typeof(lastdirent->d_off) d_off = file->f_pos;
44748 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44749 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44750 error = -EFAULT;
44751 else
44752 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44753 index 112e45a..b59845b 100644
44754 --- a/fs/compat_binfmt_elf.c
44755 +++ b/fs/compat_binfmt_elf.c
44756 @@ -30,11 +30,13 @@
44757 #undef elf_phdr
44758 #undef elf_shdr
44759 #undef elf_note
44760 +#undef elf_dyn
44761 #undef elf_addr_t
44762 #define elfhdr elf32_hdr
44763 #define elf_phdr elf32_phdr
44764 #define elf_shdr elf32_shdr
44765 #define elf_note elf32_note
44766 +#define elf_dyn Elf32_Dyn
44767 #define elf_addr_t Elf32_Addr
44768
44769 /*
44770 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44771 index 5d2069f..75d31d4 100644
44772 --- a/fs/compat_ioctl.c
44773 +++ b/fs/compat_ioctl.c
44774 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44775 return -EFAULT;
44776 if (__get_user(udata, &ss32->iomem_base))
44777 return -EFAULT;
44778 - ss.iomem_base = compat_ptr(udata);
44779 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44780 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44781 __get_user(ss.port_high, &ss32->port_high))
44782 return -EFAULT;
44783 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44784 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44785 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44786 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44787 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44788 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44789 return -EFAULT;
44790
44791 return ioctl_preallocate(file, p);
44792 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44793 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44794 {
44795 unsigned int a, b;
44796 - a = *(unsigned int *)p;
44797 - b = *(unsigned int *)q;
44798 + a = *(const unsigned int *)p;
44799 + b = *(const unsigned int *)q;
44800 if (a > b)
44801 return 1;
44802 if (a < b)
44803 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44804 index 7414ae2..d98ad6d 100644
44805 --- a/fs/configfs/dir.c
44806 +++ b/fs/configfs/dir.c
44807 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44808 }
44809 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44810 struct configfs_dirent *next;
44811 - const char * name;
44812 + const unsigned char * name;
44813 + char d_name[sizeof(next->s_dentry->d_iname)];
44814 int len;
44815 struct inode *inode = NULL;
44816
44817 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44818 continue;
44819
44820 name = configfs_get_name(next);
44821 - len = strlen(name);
44822 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44823 + len = next->s_dentry->d_name.len;
44824 + memcpy(d_name, name, len);
44825 + name = d_name;
44826 + } else
44827 + len = strlen(name);
44828
44829 /*
44830 * We'll have a dentry and an inode for
44831 diff --git a/fs/dcache.c b/fs/dcache.c
44832 index 693f95b..95f1223 100644
44833 --- a/fs/dcache.c
44834 +++ b/fs/dcache.c
44835 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44836 mempages -= reserve;
44837
44838 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44839 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44840 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44841
44842 dcache_init();
44843 inode_init();
44844 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44845 index 4733eab..71ef6fa 100644
44846 --- a/fs/debugfs/inode.c
44847 +++ b/fs/debugfs/inode.c
44848 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44849 */
44850 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44851 {
44852 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44853 + return __create_file(name, S_IFDIR | S_IRWXU,
44854 +#else
44855 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44856 +#endif
44857 parent, NULL, NULL);
44858 }
44859 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44860 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44861 index cc7709e..7e7211f 100644
44862 --- a/fs/ecryptfs/inode.c
44863 +++ b/fs/ecryptfs/inode.c
44864 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44865 old_fs = get_fs();
44866 set_fs(get_ds());
44867 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44868 - (char __user *)lower_buf,
44869 + (char __force_user *)lower_buf,
44870 PATH_MAX);
44871 set_fs(old_fs);
44872 if (rc < 0)
44873 @@ -706,7 +706,7 @@ out:
44874 static void
44875 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44876 {
44877 - char *buf = nd_get_link(nd);
44878 + const char *buf = nd_get_link(nd);
44879 if (!IS_ERR(buf)) {
44880 /* Free the char* */
44881 kfree(buf);
44882 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44883 index 412e6ed..4292d22 100644
44884 --- a/fs/ecryptfs/miscdev.c
44885 +++ b/fs/ecryptfs/miscdev.c
44886 @@ -315,7 +315,7 @@ check_list:
44887 goto out_unlock_msg_ctx;
44888 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44889 if (msg_ctx->msg) {
44890 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44891 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44892 goto out_unlock_msg_ctx;
44893 i += packet_length_size;
44894 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44895 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44896 index b2a34a1..162fa69 100644
44897 --- a/fs/ecryptfs/read_write.c
44898 +++ b/fs/ecryptfs/read_write.c
44899 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44900 return -EIO;
44901 fs_save = get_fs();
44902 set_fs(get_ds());
44903 - rc = vfs_write(lower_file, data, size, &offset);
44904 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44905 set_fs(fs_save);
44906 mark_inode_dirty_sync(ecryptfs_inode);
44907 return rc;
44908 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44909 return -EIO;
44910 fs_save = get_fs();
44911 set_fs(get_ds());
44912 - rc = vfs_read(lower_file, data, size, &offset);
44913 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44914 set_fs(fs_save);
44915 return rc;
44916 }
44917 diff --git a/fs/exec.c b/fs/exec.c
44918 index fab2c6d..4fa20c0 100644
44919 --- a/fs/exec.c
44920 +++ b/fs/exec.c
44921 @@ -55,6 +55,15 @@
44922 #include <linux/pipe_fs_i.h>
44923 #include <linux/oom.h>
44924 #include <linux/compat.h>
44925 +#include <linux/random.h>
44926 +#include <linux/seq_file.h>
44927 +
44928 +#ifdef CONFIG_PAX_REFCOUNT
44929 +#include <linux/kallsyms.h>
44930 +#include <linux/kdebug.h>
44931 +#endif
44932 +
44933 +#include <trace/events/fs.h>
44934
44935 #include <asm/uaccess.h>
44936 #include <asm/mmu_context.h>
44937 @@ -66,6 +75,18 @@
44938
44939 #include <trace/events/sched.h>
44940
44941 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44942 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44943 +{
44944 + WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
44945 +}
44946 +#endif
44947 +
44948 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44949 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44950 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44951 +#endif
44952 +
44953 int core_uses_pid;
44954 char core_pattern[CORENAME_MAX_SIZE] = "core";
44955 unsigned int core_pipe_limit;
44956 @@ -75,7 +96,7 @@ struct core_name {
44957 char *corename;
44958 int used, size;
44959 };
44960 -static atomic_t call_count = ATOMIC_INIT(1);
44961 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44962
44963 /* The maximal length of core_pattern is also specified in sysctl.c */
44964
44965 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44966 int write)
44967 {
44968 struct page *page;
44969 - int ret;
44970
44971 -#ifdef CONFIG_STACK_GROWSUP
44972 - if (write) {
44973 - ret = expand_downwards(bprm->vma, pos);
44974 - if (ret < 0)
44975 - return NULL;
44976 - }
44977 -#endif
44978 - ret = get_user_pages(current, bprm->mm, pos,
44979 - 1, write, 1, &page, NULL);
44980 - if (ret <= 0)
44981 + if (0 > expand_downwards(bprm->vma, pos))
44982 + return NULL;
44983 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44984 return NULL;
44985
44986 if (write) {
44987 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44988 if (size <= ARG_MAX)
44989 return page;
44990
44991 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44992 + // only allow 512KB for argv+env on suid/sgid binaries
44993 + // to prevent easy ASLR exhaustion
44994 + if (((bprm->cred->euid != current_euid()) ||
44995 + (bprm->cred->egid != current_egid())) &&
44996 + (size > (512 * 1024))) {
44997 + put_page(page);
44998 + return NULL;
44999 + }
45000 +#endif
45001 +
45002 /*
45003 * Limit to 1/4-th the stack size for the argv+env strings.
45004 * This ensures that:
45005 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45006 vma->vm_end = STACK_TOP_MAX;
45007 vma->vm_start = vma->vm_end - PAGE_SIZE;
45008 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
45009 +
45010 +#ifdef CONFIG_PAX_SEGMEXEC
45011 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
45012 +#endif
45013 +
45014 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
45015 INIT_LIST_HEAD(&vma->anon_vma_chain);
45016
45017 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
45018 mm->stack_vm = mm->total_vm = 1;
45019 up_write(&mm->mmap_sem);
45020 bprm->p = vma->vm_end - sizeof(void *);
45021 +
45022 +#ifdef CONFIG_PAX_RANDUSTACK
45023 + if (randomize_va_space)
45024 + bprm->p ^= random32() & ~PAGE_MASK;
45025 +#endif
45026 +
45027 return 0;
45028 err:
45029 up_write(&mm->mmap_sem);
45030 @@ -395,19 +430,7 @@ err:
45031 return err;
45032 }
45033
45034 -struct user_arg_ptr {
45035 -#ifdef CONFIG_COMPAT
45036 - bool is_compat;
45037 -#endif
45038 - union {
45039 - const char __user *const __user *native;
45040 -#ifdef CONFIG_COMPAT
45041 - compat_uptr_t __user *compat;
45042 -#endif
45043 - } ptr;
45044 -};
45045 -
45046 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45047 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45048 {
45049 const char __user *native;
45050
45051 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
45052 compat_uptr_t compat;
45053
45054 if (get_user(compat, argv.ptr.compat + nr))
45055 - return ERR_PTR(-EFAULT);
45056 + return (const char __force_user *)ERR_PTR(-EFAULT);
45057
45058 return compat_ptr(compat);
45059 }
45060 #endif
45061
45062 if (get_user(native, argv.ptr.native + nr))
45063 - return ERR_PTR(-EFAULT);
45064 + return (const char __force_user *)ERR_PTR(-EFAULT);
45065
45066 return native;
45067 }
45068 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
45069 if (!p)
45070 break;
45071
45072 - if (IS_ERR(p))
45073 + if (IS_ERR((const char __force_kernel *)p))
45074 return -EFAULT;
45075
45076 if (i++ >= max)
45077 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
45078
45079 ret = -EFAULT;
45080 str = get_user_arg_ptr(argv, argc);
45081 - if (IS_ERR(str))
45082 + if (IS_ERR((const char __force_kernel *)str))
45083 goto out;
45084
45085 len = strnlen_user(str, MAX_ARG_STRLEN);
45086 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
45087 int r;
45088 mm_segment_t oldfs = get_fs();
45089 struct user_arg_ptr argv = {
45090 - .ptr.native = (const char __user *const __user *)__argv,
45091 + .ptr.native = (const char __force_user *const __force_user *)__argv,
45092 };
45093
45094 set_fs(KERNEL_DS);
45095 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45096 unsigned long new_end = old_end - shift;
45097 struct mmu_gather tlb;
45098
45099 - BUG_ON(new_start > new_end);
45100 + if (new_start >= new_end || new_start < mmap_min_addr)
45101 + return -ENOMEM;
45102
45103 /*
45104 * ensure there are no vmas between where we want to go
45105 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
45106 if (vma != find_vma(mm, new_start))
45107 return -EFAULT;
45108
45109 +#ifdef CONFIG_PAX_SEGMEXEC
45110 + BUG_ON(pax_find_mirror_vma(vma));
45111 +#endif
45112 +
45113 /*
45114 * cover the whole range: [new_start, old_end)
45115 */
45116 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45117 stack_top = arch_align_stack(stack_top);
45118 stack_top = PAGE_ALIGN(stack_top);
45119
45120 - if (unlikely(stack_top < mmap_min_addr) ||
45121 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
45122 - return -ENOMEM;
45123 -
45124 stack_shift = vma->vm_end - stack_top;
45125
45126 bprm->p -= stack_shift;
45127 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
45128 bprm->exec -= stack_shift;
45129
45130 down_write(&mm->mmap_sem);
45131 +
45132 + /* Move stack pages down in memory. */
45133 + if (stack_shift) {
45134 + ret = shift_arg_pages(vma, stack_shift);
45135 + if (ret)
45136 + goto out_unlock;
45137 + }
45138 +
45139 vm_flags = VM_STACK_FLAGS;
45140
45141 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45142 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45143 + vm_flags &= ~VM_EXEC;
45144 +
45145 +#ifdef CONFIG_PAX_MPROTECT
45146 + if (mm->pax_flags & MF_PAX_MPROTECT)
45147 + vm_flags &= ~VM_MAYEXEC;
45148 +#endif
45149 +
45150 + }
45151 +#endif
45152 +
45153 /*
45154 * Adjust stack execute permissions; explicitly enable for
45155 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45156 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45157 goto out_unlock;
45158 BUG_ON(prev != vma);
45159
45160 - /* Move stack pages down in memory. */
45161 - if (stack_shift) {
45162 - ret = shift_arg_pages(vma, stack_shift);
45163 - if (ret)
45164 - goto out_unlock;
45165 - }
45166 -
45167 /* mprotect_fixup is overkill to remove the temporary stack flags */
45168 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45169
45170 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45171
45172 fsnotify_open(file);
45173
45174 + trace_open_exec(name);
45175 +
45176 err = deny_write_access(file);
45177 if (err)
45178 goto exit;
45179 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45180 old_fs = get_fs();
45181 set_fs(get_ds());
45182 /* The cast to a user pointer is valid due to the set_fs() */
45183 - result = vfs_read(file, (void __user *)addr, count, &pos);
45184 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45185 set_fs(old_fs);
45186 return result;
45187 }
45188 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45189 }
45190 rcu_read_unlock();
45191
45192 - if (p->fs->users > n_fs) {
45193 + if (atomic_read(&p->fs->users) > n_fs) {
45194 bprm->unsafe |= LSM_UNSAFE_SHARE;
45195 } else {
45196 res = -EAGAIN;
45197 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45198
45199 EXPORT_SYMBOL(search_binary_handler);
45200
45201 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45202 +static DEFINE_PER_CPU(u64, exec_counter);
45203 +static int __init init_exec_counters(void)
45204 +{
45205 + unsigned int cpu;
45206 +
45207 + for_each_possible_cpu(cpu) {
45208 + per_cpu(exec_counter, cpu) = (u64)cpu;
45209 + }
45210 +
45211 + return 0;
45212 +}
45213 +early_initcall(init_exec_counters);
45214 +static inline void increment_exec_counter(void)
45215 +{
45216 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45217 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45218 +}
45219 +#else
45220 +static inline void increment_exec_counter(void) {}
45221 +#endif
45222 +
45223 /*
45224 * sys_execve() executes a new program.
45225 */
45226 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45227 struct user_arg_ptr envp,
45228 struct pt_regs *regs)
45229 {
45230 +#ifdef CONFIG_GRKERNSEC
45231 + struct file *old_exec_file;
45232 + struct acl_subject_label *old_acl;
45233 + struct rlimit old_rlim[RLIM_NLIMITS];
45234 +#endif
45235 struct linux_binprm *bprm;
45236 struct file *file;
45237 struct files_struct *displaced;
45238 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45239 int retval;
45240 const struct cred *cred = current_cred();
45241
45242 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45243 +
45244 /*
45245 * We move the actual failure in case of RLIMIT_NPROC excess from
45246 * set*uid() to execve() because too many poorly written programs
45247 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45248 if (IS_ERR(file))
45249 goto out_unmark;
45250
45251 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45252 + retval = -EPERM;
45253 + goto out_file;
45254 + }
45255 +
45256 sched_exec();
45257
45258 bprm->file = file;
45259 bprm->filename = filename;
45260 bprm->interp = filename;
45261
45262 + if (gr_process_user_ban()) {
45263 + retval = -EPERM;
45264 + goto out_file;
45265 + }
45266 +
45267 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45268 + retval = -EACCES;
45269 + goto out_file;
45270 + }
45271 +
45272 retval = bprm_mm_init(bprm);
45273 if (retval)
45274 goto out_file;
45275 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45276 if (retval < 0)
45277 goto out;
45278
45279 +#ifdef CONFIG_GRKERNSEC
45280 + old_acl = current->acl;
45281 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45282 + old_exec_file = current->exec_file;
45283 + get_file(file);
45284 + current->exec_file = file;
45285 +#endif
45286 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45287 + /* limit suid stack to 8MB
45288 + we saved the old limits above and will restore them if this exec fails
45289 + */
45290 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45291 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45292 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45293 +#endif
45294 +
45295 + if (!gr_tpe_allow(file)) {
45296 + retval = -EACCES;
45297 + goto out_fail;
45298 + }
45299 +
45300 + if (gr_check_crash_exec(file)) {
45301 + retval = -EACCES;
45302 + goto out_fail;
45303 + }
45304 +
45305 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45306 + bprm->unsafe);
45307 + if (retval < 0)
45308 + goto out_fail;
45309 +
45310 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45311 if (retval < 0)
45312 - goto out;
45313 + goto out_fail;
45314
45315 bprm->exec = bprm->p;
45316 retval = copy_strings(bprm->envc, envp, bprm);
45317 if (retval < 0)
45318 - goto out;
45319 + goto out_fail;
45320
45321 retval = copy_strings(bprm->argc, argv, bprm);
45322 if (retval < 0)
45323 - goto out;
45324 + goto out_fail;
45325 +
45326 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45327 +
45328 + gr_handle_exec_args(bprm, argv);
45329
45330 retval = search_binary_handler(bprm,regs);
45331 if (retval < 0)
45332 - goto out;
45333 + goto out_fail;
45334 +#ifdef CONFIG_GRKERNSEC
45335 + if (old_exec_file)
45336 + fput(old_exec_file);
45337 +#endif
45338
45339 /* execve succeeded */
45340 +
45341 + increment_exec_counter();
45342 current->fs->in_exec = 0;
45343 current->in_execve = 0;
45344 acct_update_integrals(current);
45345 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45346 put_files_struct(displaced);
45347 return retval;
45348
45349 +out_fail:
45350 +#ifdef CONFIG_GRKERNSEC
45351 + current->acl = old_acl;
45352 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45353 + fput(current->exec_file);
45354 + current->exec_file = old_exec_file;
45355 +#endif
45356 +
45357 out:
45358 if (bprm->mm) {
45359 acct_arg_size(bprm, 0);
45360 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45361 {
45362 char *old_corename = cn->corename;
45363
45364 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45365 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45366 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45367
45368 if (!cn->corename) {
45369 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45370 int pid_in_pattern = 0;
45371 int err = 0;
45372
45373 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45374 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45375 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45376 cn->used = 0;
45377
45378 @@ -1831,6 +1963,250 @@ out:
45379 return ispipe;
45380 }
45381
45382 +int pax_check_flags(unsigned long *flags)
45383 +{
45384 + int retval = 0;
45385 +
45386 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45387 + if (*flags & MF_PAX_SEGMEXEC)
45388 + {
45389 + *flags &= ~MF_PAX_SEGMEXEC;
45390 + retval = -EINVAL;
45391 + }
45392 +#endif
45393 +
45394 + if ((*flags & MF_PAX_PAGEEXEC)
45395 +
45396 +#ifdef CONFIG_PAX_PAGEEXEC
45397 + && (*flags & MF_PAX_SEGMEXEC)
45398 +#endif
45399 +
45400 + )
45401 + {
45402 + *flags &= ~MF_PAX_PAGEEXEC;
45403 + retval = -EINVAL;
45404 + }
45405 +
45406 + if ((*flags & MF_PAX_MPROTECT)
45407 +
45408 +#ifdef CONFIG_PAX_MPROTECT
45409 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45410 +#endif
45411 +
45412 + )
45413 + {
45414 + *flags &= ~MF_PAX_MPROTECT;
45415 + retval = -EINVAL;
45416 + }
45417 +
45418 + if ((*flags & MF_PAX_EMUTRAMP)
45419 +
45420 +#ifdef CONFIG_PAX_EMUTRAMP
45421 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45422 +#endif
45423 +
45424 + )
45425 + {
45426 + *flags &= ~MF_PAX_EMUTRAMP;
45427 + retval = -EINVAL;
45428 + }
45429 +
45430 + return retval;
45431 +}
45432 +
45433 +EXPORT_SYMBOL(pax_check_flags);
45434 +
45435 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45436 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45437 +{
45438 + struct task_struct *tsk = current;
45439 + struct mm_struct *mm = current->mm;
45440 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45441 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45442 + char *path_exec = NULL;
45443 + char *path_fault = NULL;
45444 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45445 +
45446 + if (buffer_exec && buffer_fault) {
45447 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45448 +
45449 + down_read(&mm->mmap_sem);
45450 + vma = mm->mmap;
45451 + while (vma && (!vma_exec || !vma_fault)) {
45452 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45453 + vma_exec = vma;
45454 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45455 + vma_fault = vma;
45456 + vma = vma->vm_next;
45457 + }
45458 + if (vma_exec) {
45459 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45460 + if (IS_ERR(path_exec))
45461 + path_exec = "<path too long>";
45462 + else {
45463 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45464 + if (path_exec) {
45465 + *path_exec = 0;
45466 + path_exec = buffer_exec;
45467 + } else
45468 + path_exec = "<path too long>";
45469 + }
45470 + }
45471 + if (vma_fault) {
45472 + start = vma_fault->vm_start;
45473 + end = vma_fault->vm_end;
45474 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45475 + if (vma_fault->vm_file) {
45476 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45477 + if (IS_ERR(path_fault))
45478 + path_fault = "<path too long>";
45479 + else {
45480 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45481 + if (path_fault) {
45482 + *path_fault = 0;
45483 + path_fault = buffer_fault;
45484 + } else
45485 + path_fault = "<path too long>";
45486 + }
45487 + } else
45488 + path_fault = "<anonymous mapping>";
45489 + }
45490 + up_read(&mm->mmap_sem);
45491 + }
45492 + if (tsk->signal->curr_ip)
45493 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45494 + else
45495 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45496 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45497 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45498 + task_uid(tsk), task_euid(tsk), pc, sp);
45499 + free_page((unsigned long)buffer_exec);
45500 + free_page((unsigned long)buffer_fault);
45501 + pax_report_insns(regs, pc, sp);
45502 + do_coredump(SIGKILL, SIGKILL, regs);
45503 +}
45504 +#endif
45505 +
45506 +#ifdef CONFIG_PAX_REFCOUNT
45507 +void pax_report_refcount_overflow(struct pt_regs *regs)
45508 +{
45509 + if (current->signal->curr_ip)
45510 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45511 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45512 + else
45513 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45514 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45515 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45516 + show_regs(regs);
45517 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45518 +}
45519 +#endif
45520 +
45521 +#ifdef CONFIG_PAX_USERCOPY
45522 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45523 +static noinline int check_stack_object(const void *obj, unsigned long len)
45524 +{
45525 + const void * const stack = task_stack_page(current);
45526 + const void * const stackend = stack + THREAD_SIZE;
45527 +
45528 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45529 + const void *frame = NULL;
45530 + const void *oldframe;
45531 +#endif
45532 +
45533 + if (obj + len < obj)
45534 + return -1;
45535 +
45536 + if (obj + len <= stack || stackend <= obj)
45537 + return 0;
45538 +
45539 + if (obj < stack || stackend < obj + len)
45540 + return -1;
45541 +
45542 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45543 + oldframe = __builtin_frame_address(1);
45544 + if (oldframe)
45545 + frame = __builtin_frame_address(2);
45546 + /*
45547 + low ----------------------------------------------> high
45548 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45549 + ^----------------^
45550 + allow copies only within here
45551 + */
45552 + while (stack <= frame && frame < stackend) {
45553 + /* if obj + len extends past the last frame, this
45554 + check won't pass and the next frame will be 0,
45555 + causing us to bail out and correctly report
45556 + the copy as invalid
45557 + */
45558 + if (obj + len <= frame)
45559 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45560 + oldframe = frame;
45561 + frame = *(const void * const *)frame;
45562 + }
45563 + return -1;
45564 +#else
45565 + return 1;
45566 +#endif
45567 +}
45568 +
45569 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45570 +{
45571 + if (current->signal->curr_ip)
45572 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45573 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45574 + else
45575 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45576 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45577 + dump_stack();
45578 + gr_handle_kernel_exploit();
45579 + do_group_exit(SIGKILL);
45580 +}
45581 +#endif
45582 +
45583 +void check_object_size(const void *ptr, unsigned long n, bool to)
45584 +{
45585 +
45586 +#ifdef CONFIG_PAX_USERCOPY
45587 + const char *type;
45588 +
45589 + if (!n)
45590 + return;
45591 +
45592 + type = check_heap_object(ptr, n, to);
45593 + if (!type) {
45594 + if (check_stack_object(ptr, n) != -1)
45595 + return;
45596 + type = "<process stack>";
45597 + }
45598 +
45599 + pax_report_usercopy(ptr, n, to, type);
45600 +#endif
45601 +
45602 +}
45603 +EXPORT_SYMBOL(check_object_size);
45604 +
45605 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45606 +void pax_track_stack(void)
45607 +{
45608 + unsigned long sp = (unsigned long)&sp;
45609 + if (sp < current_thread_info()->lowest_stack &&
45610 + sp > (unsigned long)task_stack_page(current))
45611 + current_thread_info()->lowest_stack = sp;
45612 +}
45613 +EXPORT_SYMBOL(pax_track_stack);
45614 +#endif
45615 +
45616 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45617 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45618 +{
45619 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45620 + dump_stack();
45621 + do_group_exit(SIGKILL);
45622 +}
45623 +EXPORT_SYMBOL(report_size_overflow);
45624 +#endif
45625 +
45626 static int zap_process(struct task_struct *start, int exit_code)
45627 {
45628 struct task_struct *t;
45629 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45630 pipe = file->f_path.dentry->d_inode->i_pipe;
45631
45632 pipe_lock(pipe);
45633 - pipe->readers++;
45634 - pipe->writers--;
45635 + atomic_inc(&pipe->readers);
45636 + atomic_dec(&pipe->writers);
45637
45638 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45639 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45640 wake_up_interruptible_sync(&pipe->wait);
45641 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45642 pipe_wait(pipe);
45643 }
45644
45645 - pipe->readers--;
45646 - pipe->writers++;
45647 + atomic_dec(&pipe->readers);
45648 + atomic_inc(&pipe->writers);
45649 pipe_unlock(pipe);
45650
45651 }
45652 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45653 int flag = 0;
45654 int ispipe;
45655 bool need_nonrelative = false;
45656 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45657 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45658 struct coredump_params cprm = {
45659 .signr = signr,
45660 .regs = regs,
45661 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45662
45663 audit_core_dumps(signr);
45664
45665 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45666 + gr_handle_brute_attach(current, cprm.mm_flags);
45667 +
45668 binfmt = mm->binfmt;
45669 if (!binfmt || !binfmt->core_dump)
45670 goto fail;
45671 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45672 }
45673 cprm.limit = RLIM_INFINITY;
45674
45675 - dump_count = atomic_inc_return(&core_dump_count);
45676 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45677 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45678 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45679 task_tgid_vnr(current), current->comm);
45680 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45681 } else {
45682 struct inode *inode;
45683
45684 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45685 +
45686 if (cprm.limit < binfmt->min_coredump)
45687 goto fail_unlock;
45688
45689 @@ -2269,7 +2650,7 @@ close_fail:
45690 filp_close(cprm.file, NULL);
45691 fail_dropcount:
45692 if (ispipe)
45693 - atomic_dec(&core_dump_count);
45694 + atomic_dec_unchecked(&core_dump_count);
45695 fail_unlock:
45696 kfree(cn.corename);
45697 fail_corename:
45698 @@ -2288,7 +2669,7 @@ fail:
45699 */
45700 int dump_write(struct file *file, const void *addr, int nr)
45701 {
45702 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45703 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45704 }
45705 EXPORT_SYMBOL(dump_write);
45706
45707 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45708 index 376aa77..59a129c 100644
45709 --- a/fs/ext2/balloc.c
45710 +++ b/fs/ext2/balloc.c
45711 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45712
45713 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45714 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45715 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45716 + if (free_blocks < root_blocks + 1 &&
45717 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45718 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45719 - !in_group_p (sbi->s_resgid))) {
45720 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45721 return 0;
45722 }
45723 return 1;
45724 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45725 index 90d901f..159975f 100644
45726 --- a/fs/ext3/balloc.c
45727 +++ b/fs/ext3/balloc.c
45728 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45729
45730 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45731 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45732 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45733 + if (free_blocks < root_blocks + 1 &&
45734 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45735 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45736 - !in_group_p (sbi->s_resgid))) {
45737 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45738 return 0;
45739 }
45740 return 1;
45741 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45742 index cf18217..8f6b9c3 100644
45743 --- a/fs/ext4/balloc.c
45744 +++ b/fs/ext4/balloc.c
45745 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45746 /* Hm, nope. Are (enough) root reserved clusters available? */
45747 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45748 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45749 - capable(CAP_SYS_RESOURCE) ||
45750 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45751 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45752 + capable_nolog(CAP_SYS_RESOURCE)) {
45753
45754 if (free_clusters >= (nclusters + dirty_clusters))
45755 return 1;
45756 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45757 index 5c69f2b..05dec7f 100644
45758 --- a/fs/ext4/ext4.h
45759 +++ b/fs/ext4/ext4.h
45760 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45761 unsigned long s_mb_last_start;
45762
45763 /* stats for buddy allocator */
45764 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45765 - atomic_t s_bal_success; /* we found long enough chunks */
45766 - atomic_t s_bal_allocated; /* in blocks */
45767 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45768 - atomic_t s_bal_goals; /* goal hits */
45769 - atomic_t s_bal_breaks; /* too long searches */
45770 - atomic_t s_bal_2orders; /* 2^order hits */
45771 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45772 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45773 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45774 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45775 + atomic_unchecked_t s_bal_goals; /* goal hits */
45776 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45777 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45778 spinlock_t s_bal_lock;
45779 unsigned long s_mb_buddies_generated;
45780 unsigned long long s_mb_generation_time;
45781 - atomic_t s_mb_lost_chunks;
45782 - atomic_t s_mb_preallocated;
45783 - atomic_t s_mb_discarded;
45784 + atomic_unchecked_t s_mb_lost_chunks;
45785 + atomic_unchecked_t s_mb_preallocated;
45786 + atomic_unchecked_t s_mb_discarded;
45787 atomic_t s_lock_busy;
45788
45789 /* locality groups */
45790 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
45791 index 8ce0076..cc2d77c 100644
45792 --- a/fs/ext4/ialloc.c
45793 +++ b/fs/ext4/ialloc.c
45794 @@ -716,6 +716,10 @@ repeat_in_this_group:
45795 "inode=%lu", ino + 1);
45796 continue;
45797 }
45798 + BUFFER_TRACE(inode_bitmap_bh, "get_write_access");
45799 + err = ext4_journal_get_write_access(handle, inode_bitmap_bh);
45800 + if (err)
45801 + goto fail;
45802 ext4_lock_group(sb, group);
45803 ret2 = ext4_test_and_set_bit(ino, inode_bitmap_bh->b_data);
45804 ext4_unlock_group(sb, group);
45805 @@ -729,6 +733,11 @@ repeat_in_this_group:
45806 goto out;
45807
45808 got:
45809 + BUFFER_TRACE(inode_bitmap_bh, "call ext4_handle_dirty_metadata");
45810 + err = ext4_handle_dirty_metadata(handle, NULL, inode_bitmap_bh);
45811 + if (err)
45812 + goto fail;
45813 +
45814 /* We may have to initialize the block bitmap if it isn't already */
45815 if (ext4_has_group_desc_csum(sb) &&
45816 gdp->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
45817 @@ -762,11 +771,6 @@ got:
45818 goto fail;
45819 }
45820
45821 - BUFFER_TRACE(inode_bitmap_bh, "get_write_access");
45822 - err = ext4_journal_get_write_access(handle, inode_bitmap_bh);
45823 - if (err)
45824 - goto fail;
45825 -
45826 BUFFER_TRACE(group_desc_bh, "get_write_access");
45827 err = ext4_journal_get_write_access(handle, group_desc_bh);
45828 if (err)
45829 @@ -814,11 +818,6 @@ got:
45830 }
45831 ext4_unlock_group(sb, group);
45832
45833 - BUFFER_TRACE(inode_bitmap_bh, "call ext4_handle_dirty_metadata");
45834 - err = ext4_handle_dirty_metadata(handle, NULL, inode_bitmap_bh);
45835 - if (err)
45836 - goto fail;
45837 -
45838 BUFFER_TRACE(group_desc_bh, "call ext4_handle_dirty_metadata");
45839 err = ext4_handle_dirty_metadata(handle, NULL, group_desc_bh);
45840 if (err)
45841 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45842 index b26410c..7383d90 100644
45843 --- a/fs/ext4/mballoc.c
45844 +++ b/fs/ext4/mballoc.c
45845 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45846 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45847
45848 if (EXT4_SB(sb)->s_mb_stats)
45849 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45850 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45851
45852 break;
45853 }
45854 @@ -2040,7 +2040,7 @@ repeat:
45855 ac->ac_status = AC_STATUS_CONTINUE;
45856 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45857 cr = 3;
45858 - atomic_inc(&sbi->s_mb_lost_chunks);
45859 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45860 goto repeat;
45861 }
45862 }
45863 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45864 if (sbi->s_mb_stats) {
45865 ext4_msg(sb, KERN_INFO,
45866 "mballoc: %u blocks %u reqs (%u success)",
45867 - atomic_read(&sbi->s_bal_allocated),
45868 - atomic_read(&sbi->s_bal_reqs),
45869 - atomic_read(&sbi->s_bal_success));
45870 + atomic_read_unchecked(&sbi->s_bal_allocated),
45871 + atomic_read_unchecked(&sbi->s_bal_reqs),
45872 + atomic_read_unchecked(&sbi->s_bal_success));
45873 ext4_msg(sb, KERN_INFO,
45874 "mballoc: %u extents scanned, %u goal hits, "
45875 "%u 2^N hits, %u breaks, %u lost",
45876 - atomic_read(&sbi->s_bal_ex_scanned),
45877 - atomic_read(&sbi->s_bal_goals),
45878 - atomic_read(&sbi->s_bal_2orders),
45879 - atomic_read(&sbi->s_bal_breaks),
45880 - atomic_read(&sbi->s_mb_lost_chunks));
45881 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45882 + atomic_read_unchecked(&sbi->s_bal_goals),
45883 + atomic_read_unchecked(&sbi->s_bal_2orders),
45884 + atomic_read_unchecked(&sbi->s_bal_breaks),
45885 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45886 ext4_msg(sb, KERN_INFO,
45887 "mballoc: %lu generated and it took %Lu",
45888 sbi->s_mb_buddies_generated,
45889 sbi->s_mb_generation_time);
45890 ext4_msg(sb, KERN_INFO,
45891 "mballoc: %u preallocated, %u discarded",
45892 - atomic_read(&sbi->s_mb_preallocated),
45893 - atomic_read(&sbi->s_mb_discarded));
45894 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45895 + atomic_read_unchecked(&sbi->s_mb_discarded));
45896 }
45897
45898 free_percpu(sbi->s_locality_groups);
45899 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45900 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45901
45902 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45903 - atomic_inc(&sbi->s_bal_reqs);
45904 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45905 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45906 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45907 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45908 - atomic_inc(&sbi->s_bal_success);
45909 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45910 + atomic_inc_unchecked(&sbi->s_bal_success);
45911 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45912 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45913 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45914 - atomic_inc(&sbi->s_bal_goals);
45915 + atomic_inc_unchecked(&sbi->s_bal_goals);
45916 if (ac->ac_found > sbi->s_mb_max_to_scan)
45917 - atomic_inc(&sbi->s_bal_breaks);
45918 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45919 }
45920
45921 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45922 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45923 trace_ext4_mb_new_inode_pa(ac, pa);
45924
45925 ext4_mb_use_inode_pa(ac, pa);
45926 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45927 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45928
45929 ei = EXT4_I(ac->ac_inode);
45930 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45931 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45932 trace_ext4_mb_new_group_pa(ac, pa);
45933
45934 ext4_mb_use_group_pa(ac, pa);
45935 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45936 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45937
45938 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45939 lg = ac->ac_lg;
45940 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45941 * from the bitmap and continue.
45942 */
45943 }
45944 - atomic_add(free, &sbi->s_mb_discarded);
45945 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45946
45947 return err;
45948 }
45949 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45950 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45951 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45952 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45953 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45954 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45955 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45956
45957 return 0;
45958 diff --git a/fs/fcntl.c b/fs/fcntl.c
45959 index 887b5ba..0e3f2c3 100644
45960 --- a/fs/fcntl.c
45961 +++ b/fs/fcntl.c
45962 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45963 if (err)
45964 return err;
45965
45966 + if (gr_handle_chroot_fowner(pid, type))
45967 + return -ENOENT;
45968 + if (gr_check_protected_task_fowner(pid, type))
45969 + return -EACCES;
45970 +
45971 f_modown(filp, pid, type, force);
45972 return 0;
45973 }
45974 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45975
45976 static int f_setown_ex(struct file *filp, unsigned long arg)
45977 {
45978 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45979 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45980 struct f_owner_ex owner;
45981 struct pid *pid;
45982 int type;
45983 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45984
45985 static int f_getown_ex(struct file *filp, unsigned long arg)
45986 {
45987 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45988 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45989 struct f_owner_ex owner;
45990 int ret = 0;
45991
45992 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45993 switch (cmd) {
45994 case F_DUPFD:
45995 case F_DUPFD_CLOEXEC:
45996 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45997 if (arg >= rlimit(RLIMIT_NOFILE))
45998 break;
45999 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
46000 diff --git a/fs/fifo.c b/fs/fifo.c
46001 index cf6f434..3d7942c 100644
46002 --- a/fs/fifo.c
46003 +++ b/fs/fifo.c
46004 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
46005 */
46006 filp->f_op = &read_pipefifo_fops;
46007 pipe->r_counter++;
46008 - if (pipe->readers++ == 0)
46009 + if (atomic_inc_return(&pipe->readers) == 1)
46010 wake_up_partner(inode);
46011
46012 - if (!pipe->writers) {
46013 + if (!atomic_read(&pipe->writers)) {
46014 if ((filp->f_flags & O_NONBLOCK)) {
46015 /* suppress POLLHUP until we have
46016 * seen a writer */
46017 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
46018 * errno=ENXIO when there is no process reading the FIFO.
46019 */
46020 ret = -ENXIO;
46021 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
46022 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
46023 goto err;
46024
46025 filp->f_op = &write_pipefifo_fops;
46026 pipe->w_counter++;
46027 - if (!pipe->writers++)
46028 + if (atomic_inc_return(&pipe->writers) == 1)
46029 wake_up_partner(inode);
46030
46031 - if (!pipe->readers) {
46032 + if (!atomic_read(&pipe->readers)) {
46033 if (wait_for_partner(inode, &pipe->r_counter))
46034 goto err_wr;
46035 }
46036 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
46037 */
46038 filp->f_op = &rdwr_pipefifo_fops;
46039
46040 - pipe->readers++;
46041 - pipe->writers++;
46042 + atomic_inc(&pipe->readers);
46043 + atomic_inc(&pipe->writers);
46044 pipe->r_counter++;
46045 pipe->w_counter++;
46046 - if (pipe->readers == 1 || pipe->writers == 1)
46047 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
46048 wake_up_partner(inode);
46049 break;
46050
46051 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
46052 return 0;
46053
46054 err_rd:
46055 - if (!--pipe->readers)
46056 + if (atomic_dec_and_test(&pipe->readers))
46057 wake_up_interruptible(&pipe->wait);
46058 ret = -ERESTARTSYS;
46059 goto err;
46060
46061 err_wr:
46062 - if (!--pipe->writers)
46063 + if (atomic_dec_and_test(&pipe->writers))
46064 wake_up_interruptible(&pipe->wait);
46065 ret = -ERESTARTSYS;
46066 goto err;
46067
46068 err:
46069 - if (!pipe->readers && !pipe->writers)
46070 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
46071 free_pipe_info(inode);
46072
46073 err_nocleanup:
46074 diff --git a/fs/file.c b/fs/file.c
46075 index ba3f605..fade102 100644
46076 --- a/fs/file.c
46077 +++ b/fs/file.c
46078 @@ -15,6 +15,7 @@
46079 #include <linux/slab.h>
46080 #include <linux/vmalloc.h>
46081 #include <linux/file.h>
46082 +#include <linux/security.h>
46083 #include <linux/fdtable.h>
46084 #include <linux/bitops.h>
46085 #include <linux/interrupt.h>
46086 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
46087 * N.B. For clone tasks sharing a files structure, this test
46088 * will limit the total number of files that can be opened.
46089 */
46090 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
46091 if (nr >= rlimit(RLIMIT_NOFILE))
46092 return -EMFILE;
46093
46094 diff --git a/fs/filesystems.c b/fs/filesystems.c
46095 index 96f2428..f5eeb8e 100644
46096 --- a/fs/filesystems.c
46097 +++ b/fs/filesystems.c
46098 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
46099 int len = dot ? dot - name : strlen(name);
46100
46101 fs = __get_fs_type(name, len);
46102 +
46103 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
46104 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
46105 +#else
46106 if (!fs && (request_module("%.*s", len, name) == 0))
46107 +#endif
46108 fs = __get_fs_type(name, len);
46109
46110 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
46111 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
46112 index 5df4775..9d9336f 100644
46113 --- a/fs/fs_struct.c
46114 +++ b/fs/fs_struct.c
46115 @@ -4,6 +4,7 @@
46116 #include <linux/path.h>
46117 #include <linux/slab.h>
46118 #include <linux/fs_struct.h>
46119 +#include <linux/grsecurity.h>
46120 #include "internal.h"
46121
46122 /*
46123 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46124 write_seqcount_begin(&fs->seq);
46125 old_root = fs->root;
46126 fs->root = *path;
46127 + gr_set_chroot_entries(current, path);
46128 write_seqcount_end(&fs->seq);
46129 spin_unlock(&fs->lock);
46130 if (old_root.dentry)
46131 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46132 return 1;
46133 }
46134
46135 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46136 +{
46137 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46138 + return 0;
46139 + *p = *new;
46140 +
46141 + /* This function is only called from pivot_root(). Leave our
46142 + gr_chroot_dentry and is_chrooted flags as-is, so that a
46143 + pivoted root isn't treated as a chroot
46144 + */
46145 + //gr_set_chroot_entries(task, new);
46146 +
46147 + return 1;
46148 +}
46149 +
46150 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46151 {
46152 struct task_struct *g, *p;
46153 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46154 int hits = 0;
46155 spin_lock(&fs->lock);
46156 write_seqcount_begin(&fs->seq);
46157 - hits += replace_path(&fs->root, old_root, new_root);
46158 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46159 hits += replace_path(&fs->pwd, old_root, new_root);
46160 write_seqcount_end(&fs->seq);
46161 while (hits--) {
46162 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
46163 task_lock(tsk);
46164 spin_lock(&fs->lock);
46165 tsk->fs = NULL;
46166 - kill = !--fs->users;
46167 + gr_clear_chroot_entries(tsk);
46168 + kill = !atomic_dec_return(&fs->users);
46169 spin_unlock(&fs->lock);
46170 task_unlock(tsk);
46171 if (kill)
46172 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46173 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46174 /* We don't need to lock fs - think why ;-) */
46175 if (fs) {
46176 - fs->users = 1;
46177 + atomic_set(&fs->users, 1);
46178 fs->in_exec = 0;
46179 spin_lock_init(&fs->lock);
46180 seqcount_init(&fs->seq);
46181 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46182 spin_lock(&old->lock);
46183 fs->root = old->root;
46184 path_get(&fs->root);
46185 + /* instead of calling gr_set_chroot_entries here,
46186 + we call it from every caller of this function
46187 + */
46188 fs->pwd = old->pwd;
46189 path_get(&fs->pwd);
46190 spin_unlock(&old->lock);
46191 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46192
46193 task_lock(current);
46194 spin_lock(&fs->lock);
46195 - kill = !--fs->users;
46196 + kill = !atomic_dec_return(&fs->users);
46197 current->fs = new_fs;
46198 + gr_set_chroot_entries(current, &new_fs->root);
46199 spin_unlock(&fs->lock);
46200 task_unlock(current);
46201
46202 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46203
46204 int current_umask(void)
46205 {
46206 - return current->fs->umask;
46207 + return current->fs->umask | gr_acl_umask();
46208 }
46209 EXPORT_SYMBOL(current_umask);
46210
46211 /* to be mentioned only in INIT_TASK */
46212 struct fs_struct init_fs = {
46213 - .users = 1,
46214 + .users = ATOMIC_INIT(1),
46215 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46216 .seq = SEQCNT_ZERO,
46217 .umask = 0022,
46218 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46219 task_lock(current);
46220
46221 spin_lock(&init_fs.lock);
46222 - init_fs.users++;
46223 + atomic_inc(&init_fs.users);
46224 spin_unlock(&init_fs.lock);
46225
46226 spin_lock(&fs->lock);
46227 current->fs = &init_fs;
46228 - kill = !--fs->users;
46229 + gr_set_chroot_entries(current, &current->fs->root);
46230 + kill = !atomic_dec_return(&fs->users);
46231 spin_unlock(&fs->lock);
46232
46233 task_unlock(current);
46234 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46235 index 9905350..02eaec4 100644
46236 --- a/fs/fscache/cookie.c
46237 +++ b/fs/fscache/cookie.c
46238 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46239 parent ? (char *) parent->def->name : "<no-parent>",
46240 def->name, netfs_data);
46241
46242 - fscache_stat(&fscache_n_acquires);
46243 + fscache_stat_unchecked(&fscache_n_acquires);
46244
46245 /* if there's no parent cookie, then we don't create one here either */
46246 if (!parent) {
46247 - fscache_stat(&fscache_n_acquires_null);
46248 + fscache_stat_unchecked(&fscache_n_acquires_null);
46249 _leave(" [no parent]");
46250 return NULL;
46251 }
46252 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46253 /* allocate and initialise a cookie */
46254 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46255 if (!cookie) {
46256 - fscache_stat(&fscache_n_acquires_oom);
46257 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46258 _leave(" [ENOMEM]");
46259 return NULL;
46260 }
46261 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46262
46263 switch (cookie->def->type) {
46264 case FSCACHE_COOKIE_TYPE_INDEX:
46265 - fscache_stat(&fscache_n_cookie_index);
46266 + fscache_stat_unchecked(&fscache_n_cookie_index);
46267 break;
46268 case FSCACHE_COOKIE_TYPE_DATAFILE:
46269 - fscache_stat(&fscache_n_cookie_data);
46270 + fscache_stat_unchecked(&fscache_n_cookie_data);
46271 break;
46272 default:
46273 - fscache_stat(&fscache_n_cookie_special);
46274 + fscache_stat_unchecked(&fscache_n_cookie_special);
46275 break;
46276 }
46277
46278 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46279 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46280 atomic_dec(&parent->n_children);
46281 __fscache_cookie_put(cookie);
46282 - fscache_stat(&fscache_n_acquires_nobufs);
46283 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46284 _leave(" = NULL");
46285 return NULL;
46286 }
46287 }
46288
46289 - fscache_stat(&fscache_n_acquires_ok);
46290 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46291 _leave(" = %p", cookie);
46292 return cookie;
46293 }
46294 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46295 cache = fscache_select_cache_for_object(cookie->parent);
46296 if (!cache) {
46297 up_read(&fscache_addremove_sem);
46298 - fscache_stat(&fscache_n_acquires_no_cache);
46299 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46300 _leave(" = -ENOMEDIUM [no cache]");
46301 return -ENOMEDIUM;
46302 }
46303 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46304 object = cache->ops->alloc_object(cache, cookie);
46305 fscache_stat_d(&fscache_n_cop_alloc_object);
46306 if (IS_ERR(object)) {
46307 - fscache_stat(&fscache_n_object_no_alloc);
46308 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46309 ret = PTR_ERR(object);
46310 goto error;
46311 }
46312
46313 - fscache_stat(&fscache_n_object_alloc);
46314 + fscache_stat_unchecked(&fscache_n_object_alloc);
46315
46316 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46317
46318 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46319 struct fscache_object *object;
46320 struct hlist_node *_p;
46321
46322 - fscache_stat(&fscache_n_updates);
46323 + fscache_stat_unchecked(&fscache_n_updates);
46324
46325 if (!cookie) {
46326 - fscache_stat(&fscache_n_updates_null);
46327 + fscache_stat_unchecked(&fscache_n_updates_null);
46328 _leave(" [no cookie]");
46329 return;
46330 }
46331 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46332 struct fscache_object *object;
46333 unsigned long event;
46334
46335 - fscache_stat(&fscache_n_relinquishes);
46336 + fscache_stat_unchecked(&fscache_n_relinquishes);
46337 if (retire)
46338 - fscache_stat(&fscache_n_relinquishes_retire);
46339 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46340
46341 if (!cookie) {
46342 - fscache_stat(&fscache_n_relinquishes_null);
46343 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46344 _leave(" [no cookie]");
46345 return;
46346 }
46347 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46348
46349 /* wait for the cookie to finish being instantiated (or to fail) */
46350 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46351 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46352 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46353 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46354 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46355 }
46356 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46357 index f6aad48..88dcf26 100644
46358 --- a/fs/fscache/internal.h
46359 +++ b/fs/fscache/internal.h
46360 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46361 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46362 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46363
46364 -extern atomic_t fscache_n_op_pend;
46365 -extern atomic_t fscache_n_op_run;
46366 -extern atomic_t fscache_n_op_enqueue;
46367 -extern atomic_t fscache_n_op_deferred_release;
46368 -extern atomic_t fscache_n_op_release;
46369 -extern atomic_t fscache_n_op_gc;
46370 -extern atomic_t fscache_n_op_cancelled;
46371 -extern atomic_t fscache_n_op_rejected;
46372 +extern atomic_unchecked_t fscache_n_op_pend;
46373 +extern atomic_unchecked_t fscache_n_op_run;
46374 +extern atomic_unchecked_t fscache_n_op_enqueue;
46375 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46376 +extern atomic_unchecked_t fscache_n_op_release;
46377 +extern atomic_unchecked_t fscache_n_op_gc;
46378 +extern atomic_unchecked_t fscache_n_op_cancelled;
46379 +extern atomic_unchecked_t fscache_n_op_rejected;
46380
46381 -extern atomic_t fscache_n_attr_changed;
46382 -extern atomic_t fscache_n_attr_changed_ok;
46383 -extern atomic_t fscache_n_attr_changed_nobufs;
46384 -extern atomic_t fscache_n_attr_changed_nomem;
46385 -extern atomic_t fscache_n_attr_changed_calls;
46386 +extern atomic_unchecked_t fscache_n_attr_changed;
46387 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46388 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46389 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46390 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46391
46392 -extern atomic_t fscache_n_allocs;
46393 -extern atomic_t fscache_n_allocs_ok;
46394 -extern atomic_t fscache_n_allocs_wait;
46395 -extern atomic_t fscache_n_allocs_nobufs;
46396 -extern atomic_t fscache_n_allocs_intr;
46397 -extern atomic_t fscache_n_allocs_object_dead;
46398 -extern atomic_t fscache_n_alloc_ops;
46399 -extern atomic_t fscache_n_alloc_op_waits;
46400 +extern atomic_unchecked_t fscache_n_allocs;
46401 +extern atomic_unchecked_t fscache_n_allocs_ok;
46402 +extern atomic_unchecked_t fscache_n_allocs_wait;
46403 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46404 +extern atomic_unchecked_t fscache_n_allocs_intr;
46405 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46406 +extern atomic_unchecked_t fscache_n_alloc_ops;
46407 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46408
46409 -extern atomic_t fscache_n_retrievals;
46410 -extern atomic_t fscache_n_retrievals_ok;
46411 -extern atomic_t fscache_n_retrievals_wait;
46412 -extern atomic_t fscache_n_retrievals_nodata;
46413 -extern atomic_t fscache_n_retrievals_nobufs;
46414 -extern atomic_t fscache_n_retrievals_intr;
46415 -extern atomic_t fscache_n_retrievals_nomem;
46416 -extern atomic_t fscache_n_retrievals_object_dead;
46417 -extern atomic_t fscache_n_retrieval_ops;
46418 -extern atomic_t fscache_n_retrieval_op_waits;
46419 +extern atomic_unchecked_t fscache_n_retrievals;
46420 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46421 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46422 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46423 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46424 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46425 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46426 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46427 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46428 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46429
46430 -extern atomic_t fscache_n_stores;
46431 -extern atomic_t fscache_n_stores_ok;
46432 -extern atomic_t fscache_n_stores_again;
46433 -extern atomic_t fscache_n_stores_nobufs;
46434 -extern atomic_t fscache_n_stores_oom;
46435 -extern atomic_t fscache_n_store_ops;
46436 -extern atomic_t fscache_n_store_calls;
46437 -extern atomic_t fscache_n_store_pages;
46438 -extern atomic_t fscache_n_store_radix_deletes;
46439 -extern atomic_t fscache_n_store_pages_over_limit;
46440 +extern atomic_unchecked_t fscache_n_stores;
46441 +extern atomic_unchecked_t fscache_n_stores_ok;
46442 +extern atomic_unchecked_t fscache_n_stores_again;
46443 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46444 +extern atomic_unchecked_t fscache_n_stores_oom;
46445 +extern atomic_unchecked_t fscache_n_store_ops;
46446 +extern atomic_unchecked_t fscache_n_store_calls;
46447 +extern atomic_unchecked_t fscache_n_store_pages;
46448 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46449 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46450
46451 -extern atomic_t fscache_n_store_vmscan_not_storing;
46452 -extern atomic_t fscache_n_store_vmscan_gone;
46453 -extern atomic_t fscache_n_store_vmscan_busy;
46454 -extern atomic_t fscache_n_store_vmscan_cancelled;
46455 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46456 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46457 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46458 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46459
46460 -extern atomic_t fscache_n_marks;
46461 -extern atomic_t fscache_n_uncaches;
46462 +extern atomic_unchecked_t fscache_n_marks;
46463 +extern atomic_unchecked_t fscache_n_uncaches;
46464
46465 -extern atomic_t fscache_n_acquires;
46466 -extern atomic_t fscache_n_acquires_null;
46467 -extern atomic_t fscache_n_acquires_no_cache;
46468 -extern atomic_t fscache_n_acquires_ok;
46469 -extern atomic_t fscache_n_acquires_nobufs;
46470 -extern atomic_t fscache_n_acquires_oom;
46471 +extern atomic_unchecked_t fscache_n_acquires;
46472 +extern atomic_unchecked_t fscache_n_acquires_null;
46473 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46474 +extern atomic_unchecked_t fscache_n_acquires_ok;
46475 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46476 +extern atomic_unchecked_t fscache_n_acquires_oom;
46477
46478 -extern atomic_t fscache_n_updates;
46479 -extern atomic_t fscache_n_updates_null;
46480 -extern atomic_t fscache_n_updates_run;
46481 +extern atomic_unchecked_t fscache_n_updates;
46482 +extern atomic_unchecked_t fscache_n_updates_null;
46483 +extern atomic_unchecked_t fscache_n_updates_run;
46484
46485 -extern atomic_t fscache_n_relinquishes;
46486 -extern atomic_t fscache_n_relinquishes_null;
46487 -extern atomic_t fscache_n_relinquishes_waitcrt;
46488 -extern atomic_t fscache_n_relinquishes_retire;
46489 +extern atomic_unchecked_t fscache_n_relinquishes;
46490 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46491 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46492 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46493
46494 -extern atomic_t fscache_n_cookie_index;
46495 -extern atomic_t fscache_n_cookie_data;
46496 -extern atomic_t fscache_n_cookie_special;
46497 +extern atomic_unchecked_t fscache_n_cookie_index;
46498 +extern atomic_unchecked_t fscache_n_cookie_data;
46499 +extern atomic_unchecked_t fscache_n_cookie_special;
46500
46501 -extern atomic_t fscache_n_object_alloc;
46502 -extern atomic_t fscache_n_object_no_alloc;
46503 -extern atomic_t fscache_n_object_lookups;
46504 -extern atomic_t fscache_n_object_lookups_negative;
46505 -extern atomic_t fscache_n_object_lookups_positive;
46506 -extern atomic_t fscache_n_object_lookups_timed_out;
46507 -extern atomic_t fscache_n_object_created;
46508 -extern atomic_t fscache_n_object_avail;
46509 -extern atomic_t fscache_n_object_dead;
46510 +extern atomic_unchecked_t fscache_n_object_alloc;
46511 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46512 +extern atomic_unchecked_t fscache_n_object_lookups;
46513 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46514 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46515 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46516 +extern atomic_unchecked_t fscache_n_object_created;
46517 +extern atomic_unchecked_t fscache_n_object_avail;
46518 +extern atomic_unchecked_t fscache_n_object_dead;
46519
46520 -extern atomic_t fscache_n_checkaux_none;
46521 -extern atomic_t fscache_n_checkaux_okay;
46522 -extern atomic_t fscache_n_checkaux_update;
46523 -extern atomic_t fscache_n_checkaux_obsolete;
46524 +extern atomic_unchecked_t fscache_n_checkaux_none;
46525 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46526 +extern atomic_unchecked_t fscache_n_checkaux_update;
46527 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46528
46529 extern atomic_t fscache_n_cop_alloc_object;
46530 extern atomic_t fscache_n_cop_lookup_object;
46531 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46532 atomic_inc(stat);
46533 }
46534
46535 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46536 +{
46537 + atomic_inc_unchecked(stat);
46538 +}
46539 +
46540 static inline void fscache_stat_d(atomic_t *stat)
46541 {
46542 atomic_dec(stat);
46543 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46544
46545 #define __fscache_stat(stat) (NULL)
46546 #define fscache_stat(stat) do {} while (0)
46547 +#define fscache_stat_unchecked(stat) do {} while (0)
46548 #define fscache_stat_d(stat) do {} while (0)
46549 #endif
46550
46551 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46552 index b6b897c..0ffff9c 100644
46553 --- a/fs/fscache/object.c
46554 +++ b/fs/fscache/object.c
46555 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46556 /* update the object metadata on disk */
46557 case FSCACHE_OBJECT_UPDATING:
46558 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46559 - fscache_stat(&fscache_n_updates_run);
46560 + fscache_stat_unchecked(&fscache_n_updates_run);
46561 fscache_stat(&fscache_n_cop_update_object);
46562 object->cache->ops->update_object(object);
46563 fscache_stat_d(&fscache_n_cop_update_object);
46564 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46565 spin_lock(&object->lock);
46566 object->state = FSCACHE_OBJECT_DEAD;
46567 spin_unlock(&object->lock);
46568 - fscache_stat(&fscache_n_object_dead);
46569 + fscache_stat_unchecked(&fscache_n_object_dead);
46570 goto terminal_transit;
46571
46572 /* handle the parent cache of this object being withdrawn from
46573 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46574 spin_lock(&object->lock);
46575 object->state = FSCACHE_OBJECT_DEAD;
46576 spin_unlock(&object->lock);
46577 - fscache_stat(&fscache_n_object_dead);
46578 + fscache_stat_unchecked(&fscache_n_object_dead);
46579 goto terminal_transit;
46580
46581 /* complain about the object being woken up once it is
46582 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46583 parent->cookie->def->name, cookie->def->name,
46584 object->cache->tag->name);
46585
46586 - fscache_stat(&fscache_n_object_lookups);
46587 + fscache_stat_unchecked(&fscache_n_object_lookups);
46588 fscache_stat(&fscache_n_cop_lookup_object);
46589 ret = object->cache->ops->lookup_object(object);
46590 fscache_stat_d(&fscache_n_cop_lookup_object);
46591 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46592 if (ret == -ETIMEDOUT) {
46593 /* probably stuck behind another object, so move this one to
46594 * the back of the queue */
46595 - fscache_stat(&fscache_n_object_lookups_timed_out);
46596 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46597 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46598 }
46599
46600 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46601
46602 spin_lock(&object->lock);
46603 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46604 - fscache_stat(&fscache_n_object_lookups_negative);
46605 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46606
46607 /* transit here to allow write requests to begin stacking up
46608 * and read requests to begin returning ENODATA */
46609 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46610 * result, in which case there may be data available */
46611 spin_lock(&object->lock);
46612 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46613 - fscache_stat(&fscache_n_object_lookups_positive);
46614 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46615
46616 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46617
46618 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46619 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46620 } else {
46621 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46622 - fscache_stat(&fscache_n_object_created);
46623 + fscache_stat_unchecked(&fscache_n_object_created);
46624
46625 object->state = FSCACHE_OBJECT_AVAILABLE;
46626 spin_unlock(&object->lock);
46627 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46628 fscache_enqueue_dependents(object);
46629
46630 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46631 - fscache_stat(&fscache_n_object_avail);
46632 + fscache_stat_unchecked(&fscache_n_object_avail);
46633
46634 _leave("");
46635 }
46636 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46637 enum fscache_checkaux result;
46638
46639 if (!object->cookie->def->check_aux) {
46640 - fscache_stat(&fscache_n_checkaux_none);
46641 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46642 return FSCACHE_CHECKAUX_OKAY;
46643 }
46644
46645 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46646 switch (result) {
46647 /* entry okay as is */
46648 case FSCACHE_CHECKAUX_OKAY:
46649 - fscache_stat(&fscache_n_checkaux_okay);
46650 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46651 break;
46652
46653 /* entry requires update */
46654 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46655 - fscache_stat(&fscache_n_checkaux_update);
46656 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46657 break;
46658
46659 /* entry requires deletion */
46660 case FSCACHE_CHECKAUX_OBSOLETE:
46661 - fscache_stat(&fscache_n_checkaux_obsolete);
46662 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46663 break;
46664
46665 default:
46666 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46667 index 30afdfa..2256596 100644
46668 --- a/fs/fscache/operation.c
46669 +++ b/fs/fscache/operation.c
46670 @@ -17,7 +17,7 @@
46671 #include <linux/slab.h>
46672 #include "internal.h"
46673
46674 -atomic_t fscache_op_debug_id;
46675 +atomic_unchecked_t fscache_op_debug_id;
46676 EXPORT_SYMBOL(fscache_op_debug_id);
46677
46678 /**
46679 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46680 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46681 ASSERTCMP(atomic_read(&op->usage), >, 0);
46682
46683 - fscache_stat(&fscache_n_op_enqueue);
46684 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46685 switch (op->flags & FSCACHE_OP_TYPE) {
46686 case FSCACHE_OP_ASYNC:
46687 _debug("queue async");
46688 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46689 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46690 if (op->processor)
46691 fscache_enqueue_operation(op);
46692 - fscache_stat(&fscache_n_op_run);
46693 + fscache_stat_unchecked(&fscache_n_op_run);
46694 }
46695
46696 /*
46697 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46698 if (object->n_ops > 1) {
46699 atomic_inc(&op->usage);
46700 list_add_tail(&op->pend_link, &object->pending_ops);
46701 - fscache_stat(&fscache_n_op_pend);
46702 + fscache_stat_unchecked(&fscache_n_op_pend);
46703 } else if (!list_empty(&object->pending_ops)) {
46704 atomic_inc(&op->usage);
46705 list_add_tail(&op->pend_link, &object->pending_ops);
46706 - fscache_stat(&fscache_n_op_pend);
46707 + fscache_stat_unchecked(&fscache_n_op_pend);
46708 fscache_start_operations(object);
46709 } else {
46710 ASSERTCMP(object->n_in_progress, ==, 0);
46711 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46712 object->n_exclusive++; /* reads and writes must wait */
46713 atomic_inc(&op->usage);
46714 list_add_tail(&op->pend_link, &object->pending_ops);
46715 - fscache_stat(&fscache_n_op_pend);
46716 + fscache_stat_unchecked(&fscache_n_op_pend);
46717 ret = 0;
46718 } else {
46719 /* not allowed to submit ops in any other state */
46720 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46721 if (object->n_exclusive > 0) {
46722 atomic_inc(&op->usage);
46723 list_add_tail(&op->pend_link, &object->pending_ops);
46724 - fscache_stat(&fscache_n_op_pend);
46725 + fscache_stat_unchecked(&fscache_n_op_pend);
46726 } else if (!list_empty(&object->pending_ops)) {
46727 atomic_inc(&op->usage);
46728 list_add_tail(&op->pend_link, &object->pending_ops);
46729 - fscache_stat(&fscache_n_op_pend);
46730 + fscache_stat_unchecked(&fscache_n_op_pend);
46731 fscache_start_operations(object);
46732 } else {
46733 ASSERTCMP(object->n_exclusive, ==, 0);
46734 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46735 object->n_ops++;
46736 atomic_inc(&op->usage);
46737 list_add_tail(&op->pend_link, &object->pending_ops);
46738 - fscache_stat(&fscache_n_op_pend);
46739 + fscache_stat_unchecked(&fscache_n_op_pend);
46740 ret = 0;
46741 } else if (object->state == FSCACHE_OBJECT_DYING ||
46742 object->state == FSCACHE_OBJECT_LC_DYING ||
46743 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46744 - fscache_stat(&fscache_n_op_rejected);
46745 + fscache_stat_unchecked(&fscache_n_op_rejected);
46746 ret = -ENOBUFS;
46747 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46748 fscache_report_unexpected_submission(object, op, ostate);
46749 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46750
46751 ret = -EBUSY;
46752 if (!list_empty(&op->pend_link)) {
46753 - fscache_stat(&fscache_n_op_cancelled);
46754 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46755 list_del_init(&op->pend_link);
46756 object->n_ops--;
46757 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46758 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46759 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46760 BUG();
46761
46762 - fscache_stat(&fscache_n_op_release);
46763 + fscache_stat_unchecked(&fscache_n_op_release);
46764
46765 if (op->release) {
46766 op->release(op);
46767 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46768 * lock, and defer it otherwise */
46769 if (!spin_trylock(&object->lock)) {
46770 _debug("defer put");
46771 - fscache_stat(&fscache_n_op_deferred_release);
46772 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46773
46774 cache = object->cache;
46775 spin_lock(&cache->op_gc_list_lock);
46776 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46777
46778 _debug("GC DEFERRED REL OBJ%x OP%x",
46779 object->debug_id, op->debug_id);
46780 - fscache_stat(&fscache_n_op_gc);
46781 + fscache_stat_unchecked(&fscache_n_op_gc);
46782
46783 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46784
46785 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46786 index 3f7a59b..cf196cc 100644
46787 --- a/fs/fscache/page.c
46788 +++ b/fs/fscache/page.c
46789 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46790 val = radix_tree_lookup(&cookie->stores, page->index);
46791 if (!val) {
46792 rcu_read_unlock();
46793 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46794 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46795 __fscache_uncache_page(cookie, page);
46796 return true;
46797 }
46798 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46799 spin_unlock(&cookie->stores_lock);
46800
46801 if (xpage) {
46802 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46803 - fscache_stat(&fscache_n_store_radix_deletes);
46804 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46805 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46806 ASSERTCMP(xpage, ==, page);
46807 } else {
46808 - fscache_stat(&fscache_n_store_vmscan_gone);
46809 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46810 }
46811
46812 wake_up_bit(&cookie->flags, 0);
46813 @@ -107,7 +107,7 @@ page_busy:
46814 /* we might want to wait here, but that could deadlock the allocator as
46815 * the work threads writing to the cache may all end up sleeping
46816 * on memory allocation */
46817 - fscache_stat(&fscache_n_store_vmscan_busy);
46818 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46819 return false;
46820 }
46821 EXPORT_SYMBOL(__fscache_maybe_release_page);
46822 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46823 FSCACHE_COOKIE_STORING_TAG);
46824 if (!radix_tree_tag_get(&cookie->stores, page->index,
46825 FSCACHE_COOKIE_PENDING_TAG)) {
46826 - fscache_stat(&fscache_n_store_radix_deletes);
46827 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46828 xpage = radix_tree_delete(&cookie->stores, page->index);
46829 }
46830 spin_unlock(&cookie->stores_lock);
46831 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46832
46833 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46834
46835 - fscache_stat(&fscache_n_attr_changed_calls);
46836 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46837
46838 if (fscache_object_is_active(object)) {
46839 fscache_stat(&fscache_n_cop_attr_changed);
46840 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46841
46842 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46843
46844 - fscache_stat(&fscache_n_attr_changed);
46845 + fscache_stat_unchecked(&fscache_n_attr_changed);
46846
46847 op = kzalloc(sizeof(*op), GFP_KERNEL);
46848 if (!op) {
46849 - fscache_stat(&fscache_n_attr_changed_nomem);
46850 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46851 _leave(" = -ENOMEM");
46852 return -ENOMEM;
46853 }
46854 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46855 if (fscache_submit_exclusive_op(object, op) < 0)
46856 goto nobufs;
46857 spin_unlock(&cookie->lock);
46858 - fscache_stat(&fscache_n_attr_changed_ok);
46859 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46860 fscache_put_operation(op);
46861 _leave(" = 0");
46862 return 0;
46863 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46864 nobufs:
46865 spin_unlock(&cookie->lock);
46866 kfree(op);
46867 - fscache_stat(&fscache_n_attr_changed_nobufs);
46868 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46869 _leave(" = %d", -ENOBUFS);
46870 return -ENOBUFS;
46871 }
46872 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46873 /* allocate a retrieval operation and attempt to submit it */
46874 op = kzalloc(sizeof(*op), GFP_NOIO);
46875 if (!op) {
46876 - fscache_stat(&fscache_n_retrievals_nomem);
46877 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46878 return NULL;
46879 }
46880
46881 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46882 return 0;
46883 }
46884
46885 - fscache_stat(&fscache_n_retrievals_wait);
46886 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46887
46888 jif = jiffies;
46889 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46890 fscache_wait_bit_interruptible,
46891 TASK_INTERRUPTIBLE) != 0) {
46892 - fscache_stat(&fscache_n_retrievals_intr);
46893 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46894 _leave(" = -ERESTARTSYS");
46895 return -ERESTARTSYS;
46896 }
46897 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46898 */
46899 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46900 struct fscache_retrieval *op,
46901 - atomic_t *stat_op_waits,
46902 - atomic_t *stat_object_dead)
46903 + atomic_unchecked_t *stat_op_waits,
46904 + atomic_unchecked_t *stat_object_dead)
46905 {
46906 int ret;
46907
46908 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46909 goto check_if_dead;
46910
46911 _debug(">>> WT");
46912 - fscache_stat(stat_op_waits);
46913 + fscache_stat_unchecked(stat_op_waits);
46914 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46915 fscache_wait_bit_interruptible,
46916 TASK_INTERRUPTIBLE) < 0) {
46917 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46918
46919 check_if_dead:
46920 if (unlikely(fscache_object_is_dead(object))) {
46921 - fscache_stat(stat_object_dead);
46922 + fscache_stat_unchecked(stat_object_dead);
46923 return -ENOBUFS;
46924 }
46925 return 0;
46926 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46927
46928 _enter("%p,%p,,,", cookie, page);
46929
46930 - fscache_stat(&fscache_n_retrievals);
46931 + fscache_stat_unchecked(&fscache_n_retrievals);
46932
46933 if (hlist_empty(&cookie->backing_objects))
46934 goto nobufs;
46935 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46936 goto nobufs_unlock;
46937 spin_unlock(&cookie->lock);
46938
46939 - fscache_stat(&fscache_n_retrieval_ops);
46940 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46941
46942 /* pin the netfs read context in case we need to do the actual netfs
46943 * read because we've encountered a cache read failure */
46944 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46945
46946 error:
46947 if (ret == -ENOMEM)
46948 - fscache_stat(&fscache_n_retrievals_nomem);
46949 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46950 else if (ret == -ERESTARTSYS)
46951 - fscache_stat(&fscache_n_retrievals_intr);
46952 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46953 else if (ret == -ENODATA)
46954 - fscache_stat(&fscache_n_retrievals_nodata);
46955 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46956 else if (ret < 0)
46957 - fscache_stat(&fscache_n_retrievals_nobufs);
46958 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46959 else
46960 - fscache_stat(&fscache_n_retrievals_ok);
46961 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46962
46963 fscache_put_retrieval(op);
46964 _leave(" = %d", ret);
46965 @@ -429,7 +429,7 @@ nobufs_unlock:
46966 spin_unlock(&cookie->lock);
46967 kfree(op);
46968 nobufs:
46969 - fscache_stat(&fscache_n_retrievals_nobufs);
46970 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46971 _leave(" = -ENOBUFS");
46972 return -ENOBUFS;
46973 }
46974 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46975
46976 _enter("%p,,%d,,,", cookie, *nr_pages);
46977
46978 - fscache_stat(&fscache_n_retrievals);
46979 + fscache_stat_unchecked(&fscache_n_retrievals);
46980
46981 if (hlist_empty(&cookie->backing_objects))
46982 goto nobufs;
46983 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46984 goto nobufs_unlock;
46985 spin_unlock(&cookie->lock);
46986
46987 - fscache_stat(&fscache_n_retrieval_ops);
46988 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46989
46990 /* pin the netfs read context in case we need to do the actual netfs
46991 * read because we've encountered a cache read failure */
46992 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46993
46994 error:
46995 if (ret == -ENOMEM)
46996 - fscache_stat(&fscache_n_retrievals_nomem);
46997 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46998 else if (ret == -ERESTARTSYS)
46999 - fscache_stat(&fscache_n_retrievals_intr);
47000 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
47001 else if (ret == -ENODATA)
47002 - fscache_stat(&fscache_n_retrievals_nodata);
47003 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
47004 else if (ret < 0)
47005 - fscache_stat(&fscache_n_retrievals_nobufs);
47006 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47007 else
47008 - fscache_stat(&fscache_n_retrievals_ok);
47009 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
47010
47011 fscache_put_retrieval(op);
47012 _leave(" = %d", ret);
47013 @@ -545,7 +545,7 @@ nobufs_unlock:
47014 spin_unlock(&cookie->lock);
47015 kfree(op);
47016 nobufs:
47017 - fscache_stat(&fscache_n_retrievals_nobufs);
47018 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
47019 _leave(" = -ENOBUFS");
47020 return -ENOBUFS;
47021 }
47022 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47023
47024 _enter("%p,%p,,,", cookie, page);
47025
47026 - fscache_stat(&fscache_n_allocs);
47027 + fscache_stat_unchecked(&fscache_n_allocs);
47028
47029 if (hlist_empty(&cookie->backing_objects))
47030 goto nobufs;
47031 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47032 goto nobufs_unlock;
47033 spin_unlock(&cookie->lock);
47034
47035 - fscache_stat(&fscache_n_alloc_ops);
47036 + fscache_stat_unchecked(&fscache_n_alloc_ops);
47037
47038 ret = fscache_wait_for_retrieval_activation(
47039 object, op,
47040 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
47041
47042 error:
47043 if (ret == -ERESTARTSYS)
47044 - fscache_stat(&fscache_n_allocs_intr);
47045 + fscache_stat_unchecked(&fscache_n_allocs_intr);
47046 else if (ret < 0)
47047 - fscache_stat(&fscache_n_allocs_nobufs);
47048 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47049 else
47050 - fscache_stat(&fscache_n_allocs_ok);
47051 + fscache_stat_unchecked(&fscache_n_allocs_ok);
47052
47053 fscache_put_retrieval(op);
47054 _leave(" = %d", ret);
47055 @@ -625,7 +625,7 @@ nobufs_unlock:
47056 spin_unlock(&cookie->lock);
47057 kfree(op);
47058 nobufs:
47059 - fscache_stat(&fscache_n_allocs_nobufs);
47060 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
47061 _leave(" = -ENOBUFS");
47062 return -ENOBUFS;
47063 }
47064 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47065
47066 spin_lock(&cookie->stores_lock);
47067
47068 - fscache_stat(&fscache_n_store_calls);
47069 + fscache_stat_unchecked(&fscache_n_store_calls);
47070
47071 /* find a page to store */
47072 page = NULL;
47073 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47074 page = results[0];
47075 _debug("gang %d [%lx]", n, page->index);
47076 if (page->index > op->store_limit) {
47077 - fscache_stat(&fscache_n_store_pages_over_limit);
47078 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
47079 goto superseded;
47080 }
47081
47082 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
47083 spin_unlock(&cookie->stores_lock);
47084 spin_unlock(&object->lock);
47085
47086 - fscache_stat(&fscache_n_store_pages);
47087 + fscache_stat_unchecked(&fscache_n_store_pages);
47088 fscache_stat(&fscache_n_cop_write_page);
47089 ret = object->cache->ops->write_page(op, page);
47090 fscache_stat_d(&fscache_n_cop_write_page);
47091 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47092 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47093 ASSERT(PageFsCache(page));
47094
47095 - fscache_stat(&fscache_n_stores);
47096 + fscache_stat_unchecked(&fscache_n_stores);
47097
47098 op = kzalloc(sizeof(*op), GFP_NOIO);
47099 if (!op)
47100 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47101 spin_unlock(&cookie->stores_lock);
47102 spin_unlock(&object->lock);
47103
47104 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
47105 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
47106 op->store_limit = object->store_limit;
47107
47108 if (fscache_submit_op(object, &op->op) < 0)
47109 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47110
47111 spin_unlock(&cookie->lock);
47112 radix_tree_preload_end();
47113 - fscache_stat(&fscache_n_store_ops);
47114 - fscache_stat(&fscache_n_stores_ok);
47115 + fscache_stat_unchecked(&fscache_n_store_ops);
47116 + fscache_stat_unchecked(&fscache_n_stores_ok);
47117
47118 /* the work queue now carries its own ref on the object */
47119 fscache_put_operation(&op->op);
47120 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
47121 return 0;
47122
47123 already_queued:
47124 - fscache_stat(&fscache_n_stores_again);
47125 + fscache_stat_unchecked(&fscache_n_stores_again);
47126 already_pending:
47127 spin_unlock(&cookie->stores_lock);
47128 spin_unlock(&object->lock);
47129 spin_unlock(&cookie->lock);
47130 radix_tree_preload_end();
47131 kfree(op);
47132 - fscache_stat(&fscache_n_stores_ok);
47133 + fscache_stat_unchecked(&fscache_n_stores_ok);
47134 _leave(" = 0");
47135 return 0;
47136
47137 @@ -851,14 +851,14 @@ nobufs:
47138 spin_unlock(&cookie->lock);
47139 radix_tree_preload_end();
47140 kfree(op);
47141 - fscache_stat(&fscache_n_stores_nobufs);
47142 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47143 _leave(" = -ENOBUFS");
47144 return -ENOBUFS;
47145
47146 nomem_free:
47147 kfree(op);
47148 nomem:
47149 - fscache_stat(&fscache_n_stores_oom);
47150 + fscache_stat_unchecked(&fscache_n_stores_oom);
47151 _leave(" = -ENOMEM");
47152 return -ENOMEM;
47153 }
47154 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47155 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47156 ASSERTCMP(page, !=, NULL);
47157
47158 - fscache_stat(&fscache_n_uncaches);
47159 + fscache_stat_unchecked(&fscache_n_uncaches);
47160
47161 /* cache withdrawal may beat us to it */
47162 if (!PageFsCache(page))
47163 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47164 unsigned long loop;
47165
47166 #ifdef CONFIG_FSCACHE_STATS
47167 - atomic_add(pagevec->nr, &fscache_n_marks);
47168 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47169 #endif
47170
47171 for (loop = 0; loop < pagevec->nr; loop++) {
47172 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47173 index 4765190..2a067f2 100644
47174 --- a/fs/fscache/stats.c
47175 +++ b/fs/fscache/stats.c
47176 @@ -18,95 +18,95 @@
47177 /*
47178 * operation counters
47179 */
47180 -atomic_t fscache_n_op_pend;
47181 -atomic_t fscache_n_op_run;
47182 -atomic_t fscache_n_op_enqueue;
47183 -atomic_t fscache_n_op_requeue;
47184 -atomic_t fscache_n_op_deferred_release;
47185 -atomic_t fscache_n_op_release;
47186 -atomic_t fscache_n_op_gc;
47187 -atomic_t fscache_n_op_cancelled;
47188 -atomic_t fscache_n_op_rejected;
47189 +atomic_unchecked_t fscache_n_op_pend;
47190 +atomic_unchecked_t fscache_n_op_run;
47191 +atomic_unchecked_t fscache_n_op_enqueue;
47192 +atomic_unchecked_t fscache_n_op_requeue;
47193 +atomic_unchecked_t fscache_n_op_deferred_release;
47194 +atomic_unchecked_t fscache_n_op_release;
47195 +atomic_unchecked_t fscache_n_op_gc;
47196 +atomic_unchecked_t fscache_n_op_cancelled;
47197 +atomic_unchecked_t fscache_n_op_rejected;
47198
47199 -atomic_t fscache_n_attr_changed;
47200 -atomic_t fscache_n_attr_changed_ok;
47201 -atomic_t fscache_n_attr_changed_nobufs;
47202 -atomic_t fscache_n_attr_changed_nomem;
47203 -atomic_t fscache_n_attr_changed_calls;
47204 +atomic_unchecked_t fscache_n_attr_changed;
47205 +atomic_unchecked_t fscache_n_attr_changed_ok;
47206 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47207 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47208 +atomic_unchecked_t fscache_n_attr_changed_calls;
47209
47210 -atomic_t fscache_n_allocs;
47211 -atomic_t fscache_n_allocs_ok;
47212 -atomic_t fscache_n_allocs_wait;
47213 -atomic_t fscache_n_allocs_nobufs;
47214 -atomic_t fscache_n_allocs_intr;
47215 -atomic_t fscache_n_allocs_object_dead;
47216 -atomic_t fscache_n_alloc_ops;
47217 -atomic_t fscache_n_alloc_op_waits;
47218 +atomic_unchecked_t fscache_n_allocs;
47219 +atomic_unchecked_t fscache_n_allocs_ok;
47220 +atomic_unchecked_t fscache_n_allocs_wait;
47221 +atomic_unchecked_t fscache_n_allocs_nobufs;
47222 +atomic_unchecked_t fscache_n_allocs_intr;
47223 +atomic_unchecked_t fscache_n_allocs_object_dead;
47224 +atomic_unchecked_t fscache_n_alloc_ops;
47225 +atomic_unchecked_t fscache_n_alloc_op_waits;
47226
47227 -atomic_t fscache_n_retrievals;
47228 -atomic_t fscache_n_retrievals_ok;
47229 -atomic_t fscache_n_retrievals_wait;
47230 -atomic_t fscache_n_retrievals_nodata;
47231 -atomic_t fscache_n_retrievals_nobufs;
47232 -atomic_t fscache_n_retrievals_intr;
47233 -atomic_t fscache_n_retrievals_nomem;
47234 -atomic_t fscache_n_retrievals_object_dead;
47235 -atomic_t fscache_n_retrieval_ops;
47236 -atomic_t fscache_n_retrieval_op_waits;
47237 +atomic_unchecked_t fscache_n_retrievals;
47238 +atomic_unchecked_t fscache_n_retrievals_ok;
47239 +atomic_unchecked_t fscache_n_retrievals_wait;
47240 +atomic_unchecked_t fscache_n_retrievals_nodata;
47241 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47242 +atomic_unchecked_t fscache_n_retrievals_intr;
47243 +atomic_unchecked_t fscache_n_retrievals_nomem;
47244 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47245 +atomic_unchecked_t fscache_n_retrieval_ops;
47246 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47247
47248 -atomic_t fscache_n_stores;
47249 -atomic_t fscache_n_stores_ok;
47250 -atomic_t fscache_n_stores_again;
47251 -atomic_t fscache_n_stores_nobufs;
47252 -atomic_t fscache_n_stores_oom;
47253 -atomic_t fscache_n_store_ops;
47254 -atomic_t fscache_n_store_calls;
47255 -atomic_t fscache_n_store_pages;
47256 -atomic_t fscache_n_store_radix_deletes;
47257 -atomic_t fscache_n_store_pages_over_limit;
47258 +atomic_unchecked_t fscache_n_stores;
47259 +atomic_unchecked_t fscache_n_stores_ok;
47260 +atomic_unchecked_t fscache_n_stores_again;
47261 +atomic_unchecked_t fscache_n_stores_nobufs;
47262 +atomic_unchecked_t fscache_n_stores_oom;
47263 +atomic_unchecked_t fscache_n_store_ops;
47264 +atomic_unchecked_t fscache_n_store_calls;
47265 +atomic_unchecked_t fscache_n_store_pages;
47266 +atomic_unchecked_t fscache_n_store_radix_deletes;
47267 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47268
47269 -atomic_t fscache_n_store_vmscan_not_storing;
47270 -atomic_t fscache_n_store_vmscan_gone;
47271 -atomic_t fscache_n_store_vmscan_busy;
47272 -atomic_t fscache_n_store_vmscan_cancelled;
47273 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47274 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47275 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47276 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47277
47278 -atomic_t fscache_n_marks;
47279 -atomic_t fscache_n_uncaches;
47280 +atomic_unchecked_t fscache_n_marks;
47281 +atomic_unchecked_t fscache_n_uncaches;
47282
47283 -atomic_t fscache_n_acquires;
47284 -atomic_t fscache_n_acquires_null;
47285 -atomic_t fscache_n_acquires_no_cache;
47286 -atomic_t fscache_n_acquires_ok;
47287 -atomic_t fscache_n_acquires_nobufs;
47288 -atomic_t fscache_n_acquires_oom;
47289 +atomic_unchecked_t fscache_n_acquires;
47290 +atomic_unchecked_t fscache_n_acquires_null;
47291 +atomic_unchecked_t fscache_n_acquires_no_cache;
47292 +atomic_unchecked_t fscache_n_acquires_ok;
47293 +atomic_unchecked_t fscache_n_acquires_nobufs;
47294 +atomic_unchecked_t fscache_n_acquires_oom;
47295
47296 -atomic_t fscache_n_updates;
47297 -atomic_t fscache_n_updates_null;
47298 -atomic_t fscache_n_updates_run;
47299 +atomic_unchecked_t fscache_n_updates;
47300 +atomic_unchecked_t fscache_n_updates_null;
47301 +atomic_unchecked_t fscache_n_updates_run;
47302
47303 -atomic_t fscache_n_relinquishes;
47304 -atomic_t fscache_n_relinquishes_null;
47305 -atomic_t fscache_n_relinquishes_waitcrt;
47306 -atomic_t fscache_n_relinquishes_retire;
47307 +atomic_unchecked_t fscache_n_relinquishes;
47308 +atomic_unchecked_t fscache_n_relinquishes_null;
47309 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47310 +atomic_unchecked_t fscache_n_relinquishes_retire;
47311
47312 -atomic_t fscache_n_cookie_index;
47313 -atomic_t fscache_n_cookie_data;
47314 -atomic_t fscache_n_cookie_special;
47315 +atomic_unchecked_t fscache_n_cookie_index;
47316 +atomic_unchecked_t fscache_n_cookie_data;
47317 +atomic_unchecked_t fscache_n_cookie_special;
47318
47319 -atomic_t fscache_n_object_alloc;
47320 -atomic_t fscache_n_object_no_alloc;
47321 -atomic_t fscache_n_object_lookups;
47322 -atomic_t fscache_n_object_lookups_negative;
47323 -atomic_t fscache_n_object_lookups_positive;
47324 -atomic_t fscache_n_object_lookups_timed_out;
47325 -atomic_t fscache_n_object_created;
47326 -atomic_t fscache_n_object_avail;
47327 -atomic_t fscache_n_object_dead;
47328 +atomic_unchecked_t fscache_n_object_alloc;
47329 +atomic_unchecked_t fscache_n_object_no_alloc;
47330 +atomic_unchecked_t fscache_n_object_lookups;
47331 +atomic_unchecked_t fscache_n_object_lookups_negative;
47332 +atomic_unchecked_t fscache_n_object_lookups_positive;
47333 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47334 +atomic_unchecked_t fscache_n_object_created;
47335 +atomic_unchecked_t fscache_n_object_avail;
47336 +atomic_unchecked_t fscache_n_object_dead;
47337
47338 -atomic_t fscache_n_checkaux_none;
47339 -atomic_t fscache_n_checkaux_okay;
47340 -atomic_t fscache_n_checkaux_update;
47341 -atomic_t fscache_n_checkaux_obsolete;
47342 +atomic_unchecked_t fscache_n_checkaux_none;
47343 +atomic_unchecked_t fscache_n_checkaux_okay;
47344 +atomic_unchecked_t fscache_n_checkaux_update;
47345 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47346
47347 atomic_t fscache_n_cop_alloc_object;
47348 atomic_t fscache_n_cop_lookup_object;
47349 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47350 seq_puts(m, "FS-Cache statistics\n");
47351
47352 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47353 - atomic_read(&fscache_n_cookie_index),
47354 - atomic_read(&fscache_n_cookie_data),
47355 - atomic_read(&fscache_n_cookie_special));
47356 + atomic_read_unchecked(&fscache_n_cookie_index),
47357 + atomic_read_unchecked(&fscache_n_cookie_data),
47358 + atomic_read_unchecked(&fscache_n_cookie_special));
47359
47360 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47361 - atomic_read(&fscache_n_object_alloc),
47362 - atomic_read(&fscache_n_object_no_alloc),
47363 - atomic_read(&fscache_n_object_avail),
47364 - atomic_read(&fscache_n_object_dead));
47365 + atomic_read_unchecked(&fscache_n_object_alloc),
47366 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47367 + atomic_read_unchecked(&fscache_n_object_avail),
47368 + atomic_read_unchecked(&fscache_n_object_dead));
47369 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47370 - atomic_read(&fscache_n_checkaux_none),
47371 - atomic_read(&fscache_n_checkaux_okay),
47372 - atomic_read(&fscache_n_checkaux_update),
47373 - atomic_read(&fscache_n_checkaux_obsolete));
47374 + atomic_read_unchecked(&fscache_n_checkaux_none),
47375 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47376 + atomic_read_unchecked(&fscache_n_checkaux_update),
47377 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47378
47379 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47380 - atomic_read(&fscache_n_marks),
47381 - atomic_read(&fscache_n_uncaches));
47382 + atomic_read_unchecked(&fscache_n_marks),
47383 + atomic_read_unchecked(&fscache_n_uncaches));
47384
47385 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47386 " oom=%u\n",
47387 - atomic_read(&fscache_n_acquires),
47388 - atomic_read(&fscache_n_acquires_null),
47389 - atomic_read(&fscache_n_acquires_no_cache),
47390 - atomic_read(&fscache_n_acquires_ok),
47391 - atomic_read(&fscache_n_acquires_nobufs),
47392 - atomic_read(&fscache_n_acquires_oom));
47393 + atomic_read_unchecked(&fscache_n_acquires),
47394 + atomic_read_unchecked(&fscache_n_acquires_null),
47395 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47396 + atomic_read_unchecked(&fscache_n_acquires_ok),
47397 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47398 + atomic_read_unchecked(&fscache_n_acquires_oom));
47399
47400 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47401 - atomic_read(&fscache_n_object_lookups),
47402 - atomic_read(&fscache_n_object_lookups_negative),
47403 - atomic_read(&fscache_n_object_lookups_positive),
47404 - atomic_read(&fscache_n_object_created),
47405 - atomic_read(&fscache_n_object_lookups_timed_out));
47406 + atomic_read_unchecked(&fscache_n_object_lookups),
47407 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47408 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47409 + atomic_read_unchecked(&fscache_n_object_created),
47410 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47411
47412 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47413 - atomic_read(&fscache_n_updates),
47414 - atomic_read(&fscache_n_updates_null),
47415 - atomic_read(&fscache_n_updates_run));
47416 + atomic_read_unchecked(&fscache_n_updates),
47417 + atomic_read_unchecked(&fscache_n_updates_null),
47418 + atomic_read_unchecked(&fscache_n_updates_run));
47419
47420 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47421 - atomic_read(&fscache_n_relinquishes),
47422 - atomic_read(&fscache_n_relinquishes_null),
47423 - atomic_read(&fscache_n_relinquishes_waitcrt),
47424 - atomic_read(&fscache_n_relinquishes_retire));
47425 + atomic_read_unchecked(&fscache_n_relinquishes),
47426 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47427 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47428 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47429
47430 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47431 - atomic_read(&fscache_n_attr_changed),
47432 - atomic_read(&fscache_n_attr_changed_ok),
47433 - atomic_read(&fscache_n_attr_changed_nobufs),
47434 - atomic_read(&fscache_n_attr_changed_nomem),
47435 - atomic_read(&fscache_n_attr_changed_calls));
47436 + atomic_read_unchecked(&fscache_n_attr_changed),
47437 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47438 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47439 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47440 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47441
47442 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47443 - atomic_read(&fscache_n_allocs),
47444 - atomic_read(&fscache_n_allocs_ok),
47445 - atomic_read(&fscache_n_allocs_wait),
47446 - atomic_read(&fscache_n_allocs_nobufs),
47447 - atomic_read(&fscache_n_allocs_intr));
47448 + atomic_read_unchecked(&fscache_n_allocs),
47449 + atomic_read_unchecked(&fscache_n_allocs_ok),
47450 + atomic_read_unchecked(&fscache_n_allocs_wait),
47451 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47452 + atomic_read_unchecked(&fscache_n_allocs_intr));
47453 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47454 - atomic_read(&fscache_n_alloc_ops),
47455 - atomic_read(&fscache_n_alloc_op_waits),
47456 - atomic_read(&fscache_n_allocs_object_dead));
47457 + atomic_read_unchecked(&fscache_n_alloc_ops),
47458 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47459 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47460
47461 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47462 " int=%u oom=%u\n",
47463 - atomic_read(&fscache_n_retrievals),
47464 - atomic_read(&fscache_n_retrievals_ok),
47465 - atomic_read(&fscache_n_retrievals_wait),
47466 - atomic_read(&fscache_n_retrievals_nodata),
47467 - atomic_read(&fscache_n_retrievals_nobufs),
47468 - atomic_read(&fscache_n_retrievals_intr),
47469 - atomic_read(&fscache_n_retrievals_nomem));
47470 + atomic_read_unchecked(&fscache_n_retrievals),
47471 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47472 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47473 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47474 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47475 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47476 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47477 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47478 - atomic_read(&fscache_n_retrieval_ops),
47479 - atomic_read(&fscache_n_retrieval_op_waits),
47480 - atomic_read(&fscache_n_retrievals_object_dead));
47481 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47482 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47483 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47484
47485 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47486 - atomic_read(&fscache_n_stores),
47487 - atomic_read(&fscache_n_stores_ok),
47488 - atomic_read(&fscache_n_stores_again),
47489 - atomic_read(&fscache_n_stores_nobufs),
47490 - atomic_read(&fscache_n_stores_oom));
47491 + atomic_read_unchecked(&fscache_n_stores),
47492 + atomic_read_unchecked(&fscache_n_stores_ok),
47493 + atomic_read_unchecked(&fscache_n_stores_again),
47494 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47495 + atomic_read_unchecked(&fscache_n_stores_oom));
47496 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47497 - atomic_read(&fscache_n_store_ops),
47498 - atomic_read(&fscache_n_store_calls),
47499 - atomic_read(&fscache_n_store_pages),
47500 - atomic_read(&fscache_n_store_radix_deletes),
47501 - atomic_read(&fscache_n_store_pages_over_limit));
47502 + atomic_read_unchecked(&fscache_n_store_ops),
47503 + atomic_read_unchecked(&fscache_n_store_calls),
47504 + atomic_read_unchecked(&fscache_n_store_pages),
47505 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47506 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47507
47508 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47509 - atomic_read(&fscache_n_store_vmscan_not_storing),
47510 - atomic_read(&fscache_n_store_vmscan_gone),
47511 - atomic_read(&fscache_n_store_vmscan_busy),
47512 - atomic_read(&fscache_n_store_vmscan_cancelled));
47513 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47514 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47515 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47516 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47517
47518 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47519 - atomic_read(&fscache_n_op_pend),
47520 - atomic_read(&fscache_n_op_run),
47521 - atomic_read(&fscache_n_op_enqueue),
47522 - atomic_read(&fscache_n_op_cancelled),
47523 - atomic_read(&fscache_n_op_rejected));
47524 + atomic_read_unchecked(&fscache_n_op_pend),
47525 + atomic_read_unchecked(&fscache_n_op_run),
47526 + atomic_read_unchecked(&fscache_n_op_enqueue),
47527 + atomic_read_unchecked(&fscache_n_op_cancelled),
47528 + atomic_read_unchecked(&fscache_n_op_rejected));
47529 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47530 - atomic_read(&fscache_n_op_deferred_release),
47531 - atomic_read(&fscache_n_op_release),
47532 - atomic_read(&fscache_n_op_gc));
47533 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47534 + atomic_read_unchecked(&fscache_n_op_release),
47535 + atomic_read_unchecked(&fscache_n_op_gc));
47536
47537 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47538 atomic_read(&fscache_n_cop_alloc_object),
47539 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47540 index ee8d550..7189d8c 100644
47541 --- a/fs/fuse/cuse.c
47542 +++ b/fs/fuse/cuse.c
47543 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47544 INIT_LIST_HEAD(&cuse_conntbl[i]);
47545
47546 /* inherit and extend fuse_dev_operations */
47547 - cuse_channel_fops = fuse_dev_operations;
47548 - cuse_channel_fops.owner = THIS_MODULE;
47549 - cuse_channel_fops.open = cuse_channel_open;
47550 - cuse_channel_fops.release = cuse_channel_release;
47551 + pax_open_kernel();
47552 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47553 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47554 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47555 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47556 + pax_close_kernel();
47557
47558 cuse_class = class_create(THIS_MODULE, "cuse");
47559 if (IS_ERR(cuse_class))
47560 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47561 index f4246cf..b4aed1d 100644
47562 --- a/fs/fuse/dev.c
47563 +++ b/fs/fuse/dev.c
47564 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47565 ret = 0;
47566 pipe_lock(pipe);
47567
47568 - if (!pipe->readers) {
47569 + if (!atomic_read(&pipe->readers)) {
47570 send_sig(SIGPIPE, current, 0);
47571 if (!ret)
47572 ret = -EPIPE;
47573 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47574 index 324bc08..4fdd56e 100644
47575 --- a/fs/fuse/dir.c
47576 +++ b/fs/fuse/dir.c
47577 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47578 return link;
47579 }
47580
47581 -static void free_link(char *link)
47582 +static void free_link(const char *link)
47583 {
47584 if (!IS_ERR(link))
47585 free_page((unsigned long) link);
47586 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47587 index 753af3d..f7b021a 100644
47588 --- a/fs/gfs2/inode.c
47589 +++ b/fs/gfs2/inode.c
47590 @@ -1498,7 +1498,7 @@ out:
47591
47592 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47593 {
47594 - char *s = nd_get_link(nd);
47595 + const char *s = nd_get_link(nd);
47596 if (!IS_ERR(s))
47597 kfree(s);
47598 }
47599 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47600 index 8349a89..51a0254 100644
47601 --- a/fs/hugetlbfs/inode.c
47602 +++ b/fs/hugetlbfs/inode.c
47603 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47604 .kill_sb = kill_litter_super,
47605 };
47606
47607 -static struct vfsmount *hugetlbfs_vfsmount;
47608 +struct vfsmount *hugetlbfs_vfsmount;
47609
47610 static int can_do_hugetlb_shm(void)
47611 {
47612 diff --git a/fs/inode.c b/fs/inode.c
47613 index ac8d904..9f45d40 100644
47614 --- a/fs/inode.c
47615 +++ b/fs/inode.c
47616 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47617
47618 #ifdef CONFIG_SMP
47619 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47620 - static atomic_t shared_last_ino;
47621 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47622 + static atomic_unchecked_t shared_last_ino;
47623 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47624
47625 res = next - LAST_INO_BATCH;
47626 }
47627 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47628 index 4a6cf28..d3a29d3 100644
47629 --- a/fs/jffs2/erase.c
47630 +++ b/fs/jffs2/erase.c
47631 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47632 struct jffs2_unknown_node marker = {
47633 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47634 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47635 - .totlen = cpu_to_je32(c->cleanmarker_size)
47636 + .totlen = cpu_to_je32(c->cleanmarker_size),
47637 + .hdr_crc = cpu_to_je32(0)
47638 };
47639
47640 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47641 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47642 index a6597d6..41b30ec 100644
47643 --- a/fs/jffs2/wbuf.c
47644 +++ b/fs/jffs2/wbuf.c
47645 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47646 {
47647 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47648 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47649 - .totlen = constant_cpu_to_je32(8)
47650 + .totlen = constant_cpu_to_je32(8),
47651 + .hdr_crc = constant_cpu_to_je32(0)
47652 };
47653
47654 /*
47655 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47656 index c55c745..f67ee56 100644
47657 --- a/fs/jfs/super.c
47658 +++ b/fs/jfs/super.c
47659 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47660
47661 jfs_inode_cachep =
47662 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47663 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47664 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47665 init_once);
47666 if (jfs_inode_cachep == NULL)
47667 return -ENOMEM;
47668 diff --git a/fs/libfs.c b/fs/libfs.c
47669 index a74cb17..37fcbe4 100644
47670 --- a/fs/libfs.c
47671 +++ b/fs/libfs.c
47672 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47673
47674 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47675 struct dentry *next;
47676 + char d_name[sizeof(next->d_iname)];
47677 + const unsigned char *name;
47678 +
47679 next = list_entry(p, struct dentry, d_u.d_child);
47680 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47681 if (!simple_positive(next)) {
47682 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47683
47684 spin_unlock(&next->d_lock);
47685 spin_unlock(&dentry->d_lock);
47686 - if (filldir(dirent, next->d_name.name,
47687 + name = next->d_name.name;
47688 + if (name == next->d_iname) {
47689 + memcpy(d_name, name, next->d_name.len);
47690 + name = d_name;
47691 + }
47692 + if (filldir(dirent, name,
47693 next->d_name.len, filp->f_pos,
47694 next->d_inode->i_ino,
47695 dt_type(next->d_inode)) < 0)
47696 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47697 index 05d2912..760abfa 100644
47698 --- a/fs/lockd/clntproc.c
47699 +++ b/fs/lockd/clntproc.c
47700 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47701 /*
47702 * Cookie counter for NLM requests
47703 */
47704 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47705 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47706
47707 void nlmclnt_next_cookie(struct nlm_cookie *c)
47708 {
47709 - u32 cookie = atomic_inc_return(&nlm_cookie);
47710 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47711
47712 memcpy(c->data, &cookie, 4);
47713 c->len=4;
47714 diff --git a/fs/locks.c b/fs/locks.c
47715 index 7e81bfc..c3649aa 100644
47716 --- a/fs/locks.c
47717 +++ b/fs/locks.c
47718 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47719 return;
47720
47721 if (filp->f_op && filp->f_op->flock) {
47722 - struct file_lock fl = {
47723 + struct file_lock flock = {
47724 .fl_pid = current->tgid,
47725 .fl_file = filp,
47726 .fl_flags = FL_FLOCK,
47727 .fl_type = F_UNLCK,
47728 .fl_end = OFFSET_MAX,
47729 };
47730 - filp->f_op->flock(filp, F_SETLKW, &fl);
47731 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47732 - fl.fl_ops->fl_release_private(&fl);
47733 + filp->f_op->flock(filp, F_SETLKW, &flock);
47734 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47735 + flock.fl_ops->fl_release_private(&flock);
47736 }
47737
47738 lock_flocks();
47739 diff --git a/fs/namei.c b/fs/namei.c
47740 index 091c4b7..c6d7e26 100644
47741 --- a/fs/namei.c
47742 +++ b/fs/namei.c
47743 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47744 if (ret != -EACCES)
47745 return ret;
47746
47747 +#ifdef CONFIG_GRKERNSEC
47748 + /* we'll block if we have to log due to a denied capability use */
47749 + if (mask & MAY_NOT_BLOCK)
47750 + return -ECHILD;
47751 +#endif
47752 +
47753 if (S_ISDIR(inode->i_mode)) {
47754 /* DACs are overridable for directories */
47755 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47756 - return 0;
47757 if (!(mask & MAY_WRITE))
47758 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47759 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47760 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47761 return 0;
47762 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47763 + return 0;
47764 return -EACCES;
47765 }
47766 /*
47767 + * Searching includes executable on directories, else just read.
47768 + */
47769 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47770 + if (mask == MAY_READ)
47771 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47772 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47773 + return 0;
47774 +
47775 + /*
47776 * Read/write DACs are always overridable.
47777 * Executable DACs are overridable when there is
47778 * at least one exec bit set.
47779 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47780 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47781 return 0;
47782
47783 - /*
47784 - * Searching includes executable on directories, else just read.
47785 - */
47786 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47787 - if (mask == MAY_READ)
47788 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47789 - return 0;
47790 -
47791 return -EACCES;
47792 }
47793
47794 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47795 {
47796 struct dentry *dentry = link->dentry;
47797 int error;
47798 - char *s;
47799 + const char *s;
47800
47801 BUG_ON(nd->flags & LOOKUP_RCU);
47802
47803 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47804 if (error)
47805 goto out_put_nd_path;
47806
47807 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47808 + dentry->d_inode, dentry, nd->path.mnt)) {
47809 + error = -EACCES;
47810 + goto out_put_nd_path;
47811 + }
47812 +
47813 nd->last_type = LAST_BIND;
47814 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47815 error = PTR_ERR(*p);
47816 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47817 break;
47818 res = walk_component(nd, path, &nd->last,
47819 nd->last_type, LOOKUP_FOLLOW);
47820 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47821 + res = -EACCES;
47822 put_link(nd, &link, cookie);
47823 } while (res > 0);
47824
47825 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47826 if (err)
47827 break;
47828 err = lookup_last(nd, &path);
47829 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47830 + err = -EACCES;
47831 put_link(nd, &link, cookie);
47832 }
47833 }
47834 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47835 if (!err)
47836 err = complete_walk(nd);
47837
47838 + if (!(nd->flags & LOOKUP_PARENT)) {
47839 +#ifdef CONFIG_GRKERNSEC
47840 + if (flags & LOOKUP_RCU) {
47841 + if (!err)
47842 + path_put(&nd->path);
47843 + err = -ECHILD;
47844 + } else
47845 +#endif
47846 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47847 + if (!err)
47848 + path_put(&nd->path);
47849 + err = -ENOENT;
47850 + }
47851 + }
47852 +
47853 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47854 if (!nd->inode->i_op->lookup) {
47855 path_put(&nd->path);
47856 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47857 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47858
47859 if (likely(!retval)) {
47860 + if (*name != '/' && nd->path.dentry && nd->inode) {
47861 +#ifdef CONFIG_GRKERNSEC
47862 + if (flags & LOOKUP_RCU)
47863 + return -ECHILD;
47864 +#endif
47865 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47866 + return -ENOENT;
47867 + }
47868 +
47869 if (unlikely(!audit_dummy_context())) {
47870 if (nd->path.dentry && nd->inode)
47871 audit_inode(name, nd->path.dentry);
47872 @@ -2336,6 +2378,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 @@ -2557,7 +2606,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 @@ -2592,6 +2641,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 @@ -2613,6 +2673,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 @@ -2627,7 +2689,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, const char *pathname)
47930 {
47931 @@ -2656,16 +2718,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(pathname, nd->path.dentry);
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(pathname, dir);
47974 goto finish_open;
47975 }
47976 @@ -2714,7 +2804,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 @@ -2738,11 +2828,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(pathname, path->dentry);
48011 + }
48012
48013 /*
48014 * If atomic_open() acquired write access it is dropped now due to
48015 @@ -2783,6 +2890,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 @@ -2792,7 +2904,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 @@ -2801,6 +2912,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 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *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 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *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 @@ -3006,8 +3133,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 @@ -3058,6 +3189,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, char **to, int is_dir)
48095 +{
48096 + char *tmp = getname(pathname);
48097 + struct dentry *res;
48098 + if (IS_ERR(tmp))
48099 + return ERR_CAST(tmp);
48100 + res = kern_path_create(dfd, tmp, 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 @@ -3119,6 +3264,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 @@ -3135,6 +3291,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 @@ -3181,9 +3339,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 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48158 char * name;
48159 struct dentry *dentry;
48160 struct nameidata nd;
48161 + ino_t saved_ino = 0;
48162 + dev_t saved_dev = 0;
48163
48164 error = user_path_parent(dfd, pathname, &nd, &name);
48165 if (error)
48166 @@ -3291,10 +3460,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 @@ -3356,6 +3536,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 error = user_path_parent(dfd, pathname, &nd, &name);
48196 if (error)
48197 @@ -3381,10 +3563,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 @@ -3456,9 +3650,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);
48230 if (!error)
48231 error = vfs_symlink(path.dentry->d_inode, dentry, from);
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 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48239 {
48240 struct dentry *new_dentry;
48241 struct path old_path, new_path;
48242 + char *to = NULL;
48243 int how = 0;
48244 int error;
48245
48246 @@ -3551,7 +3754,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 @@ -3562,11 +3765,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 @@ -3802,12 +4022,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 @@ -3832,6 +4061,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 @@ -3841,7 +4072,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 7bdf790..eb79c4b 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(char *dev_name, char *dir_name, char *type_page,
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(char *dev_name, char *dir_name, char *type_page,
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 9b47610..066975e 100644
48396 --- a/fs/nfs/inode.c
48397 +++ b/fs/nfs/inode.c
48398 @@ -1026,16 +1026,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 a9269f1..5490437 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, 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 d438036..0ecadde 100644
48451 --- a/fs/notify/fanotify/fanotify_user.c
48452 +++ b/fs/notify/fanotify/fanotify_user.c
48453 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48454 goto out_close_fd;
48455
48456 ret = -EFAULT;
48457 - if (copy_to_user(buf, &fanotify_event_metadata,
48458 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48459 + copy_to_user(buf, &fanotify_event_metadata,
48460 fanotify_event_metadata.event_len))
48461 goto out_kill_access_response;
48462
48463 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48464 index c887b13..0fdf472 100644
48465 --- a/fs/notify/notification.c
48466 +++ b/fs/notify/notification.c
48467 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48468 * get set to 0 so it will never get 'freed'
48469 */
48470 static struct fsnotify_event *q_overflow_event;
48471 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48472 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48473
48474 /**
48475 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48476 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48477 */
48478 u32 fsnotify_get_cookie(void)
48479 {
48480 - return atomic_inc_return(&fsnotify_sync_cookie);
48481 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48482 }
48483 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48484
48485 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48486 index 99e3610..02c1068 100644
48487 --- a/fs/ntfs/dir.c
48488 +++ b/fs/ntfs/dir.c
48489 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48490 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48491 ~(s64)(ndir->itype.index.block_size - 1)));
48492 /* Bounds checks. */
48493 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48494 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48495 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48496 "inode 0x%lx or driver bug.", vdir->i_ino);
48497 goto err_out;
48498 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48499 index 1ecf464..e1ff8bf 100644
48500 --- a/fs/ntfs/file.c
48501 +++ b/fs/ntfs/file.c
48502 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48503 #endif /* NTFS_RW */
48504 };
48505
48506 -const struct file_operations ntfs_empty_file_ops = {};
48507 +const struct file_operations ntfs_empty_file_ops __read_only;
48508
48509 -const struct inode_operations ntfs_empty_inode_ops = {};
48510 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48511 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48512 index a9f78c7..ed8a381 100644
48513 --- a/fs/ocfs2/localalloc.c
48514 +++ b/fs/ocfs2/localalloc.c
48515 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48516 goto bail;
48517 }
48518
48519 - atomic_inc(&osb->alloc_stats.moves);
48520 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48521
48522 bail:
48523 if (handle)
48524 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48525 index d355e6e..578d905 100644
48526 --- a/fs/ocfs2/ocfs2.h
48527 +++ b/fs/ocfs2/ocfs2.h
48528 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48529
48530 struct ocfs2_alloc_stats
48531 {
48532 - atomic_t moves;
48533 - atomic_t local_data;
48534 - atomic_t bitmap_data;
48535 - atomic_t bg_allocs;
48536 - atomic_t bg_extends;
48537 + atomic_unchecked_t moves;
48538 + atomic_unchecked_t local_data;
48539 + atomic_unchecked_t bitmap_data;
48540 + atomic_unchecked_t bg_allocs;
48541 + atomic_unchecked_t bg_extends;
48542 };
48543
48544 enum ocfs2_local_alloc_state
48545 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48546 index f169da4..9112253 100644
48547 --- a/fs/ocfs2/suballoc.c
48548 +++ b/fs/ocfs2/suballoc.c
48549 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48550 mlog_errno(status);
48551 goto bail;
48552 }
48553 - atomic_inc(&osb->alloc_stats.bg_extends);
48554 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48555
48556 /* You should never ask for this much metadata */
48557 BUG_ON(bits_wanted >
48558 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48559 mlog_errno(status);
48560 goto bail;
48561 }
48562 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48563 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48564
48565 *suballoc_loc = res.sr_bg_blkno;
48566 *suballoc_bit_start = res.sr_bit_offset;
48567 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48568 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48569 res->sr_bits);
48570
48571 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48572 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48573
48574 BUG_ON(res->sr_bits != 1);
48575
48576 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48577 mlog_errno(status);
48578 goto bail;
48579 }
48580 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48581 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48582
48583 BUG_ON(res.sr_bits != 1);
48584
48585 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48586 cluster_start,
48587 num_clusters);
48588 if (!status)
48589 - atomic_inc(&osb->alloc_stats.local_data);
48590 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48591 } else {
48592 if (min_clusters > (osb->bitmap_cpg - 1)) {
48593 /* The only paths asking for contiguousness
48594 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48595 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48596 res.sr_bg_blkno,
48597 res.sr_bit_offset);
48598 - atomic_inc(&osb->alloc_stats.bitmap_data);
48599 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48600 *num_clusters = res.sr_bits;
48601 }
48602 }
48603 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48604 index 68f4541..89cfe6a 100644
48605 --- a/fs/ocfs2/super.c
48606 +++ b/fs/ocfs2/super.c
48607 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48608 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48609 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48610 "Stats",
48611 - atomic_read(&osb->alloc_stats.bitmap_data),
48612 - atomic_read(&osb->alloc_stats.local_data),
48613 - atomic_read(&osb->alloc_stats.bg_allocs),
48614 - atomic_read(&osb->alloc_stats.moves),
48615 - atomic_read(&osb->alloc_stats.bg_extends));
48616 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48617 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48618 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48619 + atomic_read_unchecked(&osb->alloc_stats.moves),
48620 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48621
48622 out += snprintf(buf + out, len - out,
48623 "%10s => State: %u Descriptor: %llu Size: %u bits "
48624 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48625 spin_lock_init(&osb->osb_xattr_lock);
48626 ocfs2_init_steal_slots(osb);
48627
48628 - atomic_set(&osb->alloc_stats.moves, 0);
48629 - atomic_set(&osb->alloc_stats.local_data, 0);
48630 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48631 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48632 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48633 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48634 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48635 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48636 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48637 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48638
48639 /* Copy the blockcheck stats from the superblock probe */
48640 osb->osb_ecc_stats = *stats;
48641 diff --git a/fs/open.c b/fs/open.c
48642 index e1f2cdb..3bd5f39 100644
48643 --- a/fs/open.c
48644 +++ b/fs/open.c
48645 @@ -31,6 +31,8 @@
48646 #include <linux/ima.h>
48647 #include <linux/dnotify.h>
48648
48649 +#define CREATE_TRACE_POINTS
48650 +#include <trace/events/fs.h>
48651 #include "internal.h"
48652
48653 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48654 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48655 error = locks_verify_truncate(inode, NULL, length);
48656 if (!error)
48657 error = security_path_truncate(&path);
48658 +
48659 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48660 + error = -EACCES;
48661 +
48662 if (!error)
48663 error = do_truncate(path.dentry, length, 0, NULL);
48664
48665 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48666 if (__mnt_is_readonly(path.mnt))
48667 res = -EROFS;
48668
48669 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48670 + res = -EACCES;
48671 +
48672 out_path_release:
48673 path_put(&path);
48674 out:
48675 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48676 if (error)
48677 goto dput_and_out;
48678
48679 + gr_log_chdir(path.dentry, path.mnt);
48680 +
48681 set_fs_pwd(current->fs, &path);
48682
48683 dput_and_out:
48684 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48685 goto out_putf;
48686
48687 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48688 +
48689 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48690 + error = -EPERM;
48691 +
48692 + if (!error)
48693 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48694 +
48695 if (!error)
48696 set_fs_pwd(current->fs, &file->f_path);
48697 out_putf:
48698 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48699 if (error)
48700 goto dput_and_out;
48701
48702 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48703 + goto dput_and_out;
48704 +
48705 set_fs_root(current->fs, &path);
48706 +
48707 + gr_handle_chroot_chdir(&path);
48708 +
48709 error = 0;
48710 dput_and_out:
48711 path_put(&path);
48712 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48713 if (error)
48714 return error;
48715 mutex_lock(&inode->i_mutex);
48716 +
48717 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48718 + error = -EACCES;
48719 + goto out_unlock;
48720 + }
48721 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48722 + error = -EACCES;
48723 + goto out_unlock;
48724 + }
48725 +
48726 error = security_path_chmod(path, mode);
48727 if (error)
48728 goto out_unlock;
48729 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48730 uid = make_kuid(current_user_ns(), user);
48731 gid = make_kgid(current_user_ns(), group);
48732
48733 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48734 + return -EACCES;
48735 +
48736 newattrs.ia_valid = ATTR_CTIME;
48737 if (user != (uid_t) -1) {
48738 if (!uid_valid(uid))
48739 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48740 } else {
48741 fsnotify_open(f);
48742 fd_install(fd, f);
48743 + trace_do_sys_open(tmp, flags, mode);
48744 }
48745 }
48746 putname(tmp);
48747 diff --git a/fs/pipe.c b/fs/pipe.c
48748 index 8d85d70..581036b 100644
48749 --- a/fs/pipe.c
48750 +++ b/fs/pipe.c
48751 @@ -438,9 +438,9 @@ redo:
48752 }
48753 if (bufs) /* More to do? */
48754 continue;
48755 - if (!pipe->writers)
48756 + if (!atomic_read(&pipe->writers))
48757 break;
48758 - if (!pipe->waiting_writers) {
48759 + if (!atomic_read(&pipe->waiting_writers)) {
48760 /* syscall merging: Usually we must not sleep
48761 * if O_NONBLOCK is set, or if we got some data.
48762 * But if a writer sleeps in kernel space, then
48763 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48764 mutex_lock(&inode->i_mutex);
48765 pipe = inode->i_pipe;
48766
48767 - if (!pipe->readers) {
48768 + if (!atomic_read(&pipe->readers)) {
48769 send_sig(SIGPIPE, current, 0);
48770 ret = -EPIPE;
48771 goto out;
48772 @@ -553,7 +553,7 @@ redo1:
48773 for (;;) {
48774 int bufs;
48775
48776 - if (!pipe->readers) {
48777 + if (!atomic_read(&pipe->readers)) {
48778 send_sig(SIGPIPE, current, 0);
48779 if (!ret)
48780 ret = -EPIPE;
48781 @@ -644,9 +644,9 @@ redo2:
48782 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48783 do_wakeup = 0;
48784 }
48785 - pipe->waiting_writers++;
48786 + atomic_inc(&pipe->waiting_writers);
48787 pipe_wait(pipe);
48788 - pipe->waiting_writers--;
48789 + atomic_dec(&pipe->waiting_writers);
48790 }
48791 out:
48792 mutex_unlock(&inode->i_mutex);
48793 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48794 mask = 0;
48795 if (filp->f_mode & FMODE_READ) {
48796 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48797 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48798 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48799 mask |= POLLHUP;
48800 }
48801
48802 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48803 * Most Unices do not set POLLERR for FIFOs but on Linux they
48804 * behave exactly like pipes for poll().
48805 */
48806 - if (!pipe->readers)
48807 + if (!atomic_read(&pipe->readers))
48808 mask |= POLLERR;
48809 }
48810
48811 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48812
48813 mutex_lock(&inode->i_mutex);
48814 pipe = inode->i_pipe;
48815 - pipe->readers -= decr;
48816 - pipe->writers -= decw;
48817 + atomic_sub(decr, &pipe->readers);
48818 + atomic_sub(decw, &pipe->writers);
48819
48820 - if (!pipe->readers && !pipe->writers) {
48821 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48822 free_pipe_info(inode);
48823 } else {
48824 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48825 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48826
48827 if (inode->i_pipe) {
48828 ret = 0;
48829 - inode->i_pipe->readers++;
48830 + atomic_inc(&inode->i_pipe->readers);
48831 }
48832
48833 mutex_unlock(&inode->i_mutex);
48834 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48835
48836 if (inode->i_pipe) {
48837 ret = 0;
48838 - inode->i_pipe->writers++;
48839 + atomic_inc(&inode->i_pipe->writers);
48840 }
48841
48842 mutex_unlock(&inode->i_mutex);
48843 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48844 if (inode->i_pipe) {
48845 ret = 0;
48846 if (filp->f_mode & FMODE_READ)
48847 - inode->i_pipe->readers++;
48848 + atomic_inc(&inode->i_pipe->readers);
48849 if (filp->f_mode & FMODE_WRITE)
48850 - inode->i_pipe->writers++;
48851 + atomic_inc(&inode->i_pipe->writers);
48852 }
48853
48854 mutex_unlock(&inode->i_mutex);
48855 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48856 inode->i_pipe = NULL;
48857 }
48858
48859 -static struct vfsmount *pipe_mnt __read_mostly;
48860 +struct vfsmount *pipe_mnt __read_mostly;
48861
48862 /*
48863 * pipefs_dname() is called from d_path().
48864 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48865 goto fail_iput;
48866 inode->i_pipe = pipe;
48867
48868 - pipe->readers = pipe->writers = 1;
48869 + atomic_set(&pipe->readers, 1);
48870 + atomic_set(&pipe->writers, 1);
48871 inode->i_fop = &rdwr_pipefifo_fops;
48872
48873 /*
48874 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48875 index 15af622..0e9f4467 100644
48876 --- a/fs/proc/Kconfig
48877 +++ b/fs/proc/Kconfig
48878 @@ -30,12 +30,12 @@ config PROC_FS
48879
48880 config PROC_KCORE
48881 bool "/proc/kcore support" if !ARM
48882 - depends on PROC_FS && MMU
48883 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48884
48885 config PROC_VMCORE
48886 bool "/proc/vmcore support"
48887 - depends on PROC_FS && CRASH_DUMP
48888 - default y
48889 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48890 + default n
48891 help
48892 Exports the dump image of crashed kernel in ELF format.
48893
48894 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48895 limited in memory.
48896
48897 config PROC_PAGE_MONITOR
48898 - default y
48899 - depends on PROC_FS && MMU
48900 + default n
48901 + depends on PROC_FS && MMU && !GRKERNSEC
48902 bool "Enable /proc page monitoring" if EXPERT
48903 help
48904 Various /proc files exist to monitor process memory utilization:
48905 diff --git a/fs/proc/array.c b/fs/proc/array.c
48906 index c1c207c..01ce725 100644
48907 --- a/fs/proc/array.c
48908 +++ b/fs/proc/array.c
48909 @@ -60,6 +60,7 @@
48910 #include <linux/tty.h>
48911 #include <linux/string.h>
48912 #include <linux/mman.h>
48913 +#include <linux/grsecurity.h>
48914 #include <linux/proc_fs.h>
48915 #include <linux/ioport.h>
48916 #include <linux/uaccess.h>
48917 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48918 seq_putc(m, '\n');
48919 }
48920
48921 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48922 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48923 +{
48924 + if (p->mm)
48925 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48926 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48927 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48928 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48929 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48930 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48931 + else
48932 + seq_printf(m, "PaX:\t-----\n");
48933 +}
48934 +#endif
48935 +
48936 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48937 struct pid *pid, struct task_struct *task)
48938 {
48939 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48940 task_cpus_allowed(m, task);
48941 cpuset_task_status_allowed(m, task);
48942 task_context_switch_counts(m, task);
48943 +
48944 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48945 + task_pax(m, task);
48946 +#endif
48947 +
48948 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48949 + task_grsec_rbac(m, task);
48950 +#endif
48951 +
48952 return 0;
48953 }
48954
48955 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48956 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48957 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48958 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48959 +#endif
48960 +
48961 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48962 struct pid *pid, struct task_struct *task, int whole)
48963 {
48964 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48965 char tcomm[sizeof(task->comm)];
48966 unsigned long flags;
48967
48968 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48969 + if (current->exec_id != m->exec_id) {
48970 + gr_log_badprocpid("stat");
48971 + return 0;
48972 + }
48973 +#endif
48974 +
48975 state = *get_task_state(task);
48976 vsize = eip = esp = 0;
48977 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48978 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48979 gtime = task->gtime;
48980 }
48981
48982 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48983 + if (PAX_RAND_FLAGS(mm)) {
48984 + eip = 0;
48985 + esp = 0;
48986 + wchan = 0;
48987 + }
48988 +#endif
48989 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48990 + wchan = 0;
48991 + eip =0;
48992 + esp =0;
48993 +#endif
48994 +
48995 /* scale priority and nice values from timeslices to -20..20 */
48996 /* to make it look like a "normal" Unix priority/nice value */
48997 priority = task_prio(task);
48998 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48999 seq_put_decimal_ull(m, ' ', vsize);
49000 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
49001 seq_put_decimal_ull(m, ' ', rsslim);
49002 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49003 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
49004 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
49005 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
49006 +#else
49007 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
49008 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
49009 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
49010 +#endif
49011 seq_put_decimal_ull(m, ' ', esp);
49012 seq_put_decimal_ull(m, ' ', eip);
49013 /* The signal information here is obsolete.
49014 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
49015 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
49016 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
49017
49018 - if (mm && permitted) {
49019 + if (mm && permitted
49020 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49021 + && !PAX_RAND_FLAGS(mm)
49022 +#endif
49023 + ) {
49024 seq_put_decimal_ull(m, ' ', mm->start_data);
49025 seq_put_decimal_ull(m, ' ', mm->end_data);
49026 seq_put_decimal_ull(m, ' ', mm->start_brk);
49027 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49028 struct pid *pid, struct task_struct *task)
49029 {
49030 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
49031 - struct mm_struct *mm = get_task_mm(task);
49032 + struct mm_struct *mm;
49033
49034 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49035 + if (current->exec_id != m->exec_id) {
49036 + gr_log_badprocpid("statm");
49037 + return 0;
49038 + }
49039 +#endif
49040 + mm = get_task_mm(task);
49041 if (mm) {
49042 size = task_statm(mm, &shared, &text, &data, &resident);
49043 mmput(mm);
49044 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49045 return 0;
49046 }
49047
49048 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49049 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
49050 +{
49051 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
49052 +}
49053 +#endif
49054 +
49055 #ifdef CONFIG_CHECKPOINT_RESTORE
49056 static struct pid *
49057 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
49058 diff --git a/fs/proc/base.c b/fs/proc/base.c
49059 index 1b6c84c..66b738b 100644
49060 --- a/fs/proc/base.c
49061 +++ b/fs/proc/base.c
49062 @@ -110,6 +110,14 @@ struct pid_entry {
49063 union proc_op op;
49064 };
49065
49066 +struct getdents_callback {
49067 + struct linux_dirent __user * current_dir;
49068 + struct linux_dirent __user * previous;
49069 + struct file * file;
49070 + int count;
49071 + int error;
49072 +};
49073 +
49074 #define NOD(NAME, MODE, IOP, FOP, OP) { \
49075 .name = (NAME), \
49076 .len = sizeof(NAME) - 1, \
49077 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
49078 if (!mm->arg_end)
49079 goto out_mm; /* Shh! No looking before we're done */
49080
49081 + if (gr_acl_handle_procpidmem(task))
49082 + goto out_mm;
49083 +
49084 len = mm->arg_end - mm->arg_start;
49085
49086 if (len > PAGE_SIZE)
49087 @@ -236,12 +247,28 @@ out:
49088 return res;
49089 }
49090
49091 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49092 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49093 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49094 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49095 +#endif
49096 +
49097 static int proc_pid_auxv(struct task_struct *task, char *buffer)
49098 {
49099 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
49100 int res = PTR_ERR(mm);
49101 if (mm && !IS_ERR(mm)) {
49102 unsigned int nwords = 0;
49103 +
49104 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49105 + /* allow if we're currently ptracing this task */
49106 + if (PAX_RAND_FLAGS(mm) &&
49107 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
49108 + mmput(mm);
49109 + return 0;
49110 + }
49111 +#endif
49112 +
49113 do {
49114 nwords += 2;
49115 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
49116 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
49117 }
49118
49119
49120 -#ifdef CONFIG_KALLSYMS
49121 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49122 /*
49123 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
49124 * Returns the resolved symbol. If that fails, simply return the address.
49125 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49126 mutex_unlock(&task->signal->cred_guard_mutex);
49127 }
49128
49129 -#ifdef CONFIG_STACKTRACE
49130 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49131
49132 #define MAX_STACK_TRACE_DEPTH 64
49133
49134 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49135 return count;
49136 }
49137
49138 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49139 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49140 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49141 {
49142 long nr;
49143 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49144 /************************************************************************/
49145
49146 /* permission checks */
49147 -static int proc_fd_access_allowed(struct inode *inode)
49148 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49149 {
49150 struct task_struct *task;
49151 int allowed = 0;
49152 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49153 */
49154 task = get_proc_task(inode);
49155 if (task) {
49156 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49157 + if (log)
49158 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49159 + else
49160 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49161 put_task_struct(task);
49162 }
49163 return allowed;
49164 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49165 struct task_struct *task,
49166 int hide_pid_min)
49167 {
49168 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49169 + return false;
49170 +
49171 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49172 + rcu_read_lock();
49173 + {
49174 + const struct cred *tmpcred = current_cred();
49175 + const struct cred *cred = __task_cred(task);
49176 +
49177 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49178 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49179 + || in_group_p(grsec_proc_gid)
49180 +#endif
49181 + ) {
49182 + rcu_read_unlock();
49183 + return true;
49184 + }
49185 + }
49186 + rcu_read_unlock();
49187 +
49188 + if (!pid->hide_pid)
49189 + return false;
49190 +#endif
49191 +
49192 if (pid->hide_pid < hide_pid_min)
49193 return true;
49194 if (in_group_p(pid->pid_gid))
49195 return true;
49196 +
49197 return ptrace_may_access(task, PTRACE_MODE_READ);
49198 }
49199
49200 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49201 put_task_struct(task);
49202
49203 if (!has_perms) {
49204 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49205 + {
49206 +#else
49207 if (pid->hide_pid == 2) {
49208 +#endif
49209 /*
49210 * Let's make getdents(), stat(), and open()
49211 * consistent with each other. If a process
49212 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49213 if (!task)
49214 return -ESRCH;
49215
49216 + if (gr_acl_handle_procpidmem(task)) {
49217 + put_task_struct(task);
49218 + return -EPERM;
49219 + }
49220 +
49221 mm = mm_access(task, mode);
49222 put_task_struct(task);
49223
49224 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49225
49226 file->private_data = mm;
49227
49228 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49229 + file->f_version = current->exec_id;
49230 +#endif
49231 +
49232 return 0;
49233 }
49234
49235 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49236 ssize_t copied;
49237 char *page;
49238
49239 +#ifdef CONFIG_GRKERNSEC
49240 + if (write)
49241 + return -EPERM;
49242 +#endif
49243 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49244 + if (file->f_version != current->exec_id) {
49245 + gr_log_badprocpid("mem");
49246 + return 0;
49247 + }
49248 +#endif
49249 +
49250 if (!mm)
49251 return 0;
49252
49253 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49254 if (!mm)
49255 return 0;
49256
49257 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49258 + if (file->f_version != current->exec_id) {
49259 + gr_log_badprocpid("environ");
49260 + return 0;
49261 + }
49262 +#endif
49263 +
49264 page = (char *)__get_free_page(GFP_TEMPORARY);
49265 if (!page)
49266 return -ENOMEM;
49267 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49268 int error = -EACCES;
49269
49270 /* Are we allowed to snoop on the tasks file descriptors? */
49271 - if (!proc_fd_access_allowed(inode))
49272 + if (!proc_fd_access_allowed(inode, 0))
49273 goto out;
49274
49275 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49276 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49277 struct path path;
49278
49279 /* Are we allowed to snoop on the tasks file descriptors? */
49280 - if (!proc_fd_access_allowed(inode))
49281 - goto out;
49282 + /* logging this is needed for learning on chromium to work properly,
49283 + but we don't want to flood the logs from 'ps' which does a readlink
49284 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49285 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49286 + */
49287 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49288 + if (!proc_fd_access_allowed(inode,0))
49289 + goto out;
49290 + } else {
49291 + if (!proc_fd_access_allowed(inode,1))
49292 + goto out;
49293 + }
49294
49295 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49296 if (error)
49297 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49298 rcu_read_lock();
49299 cred = __task_cred(task);
49300 inode->i_uid = cred->euid;
49301 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49302 + inode->i_gid = grsec_proc_gid;
49303 +#else
49304 inode->i_gid = cred->egid;
49305 +#endif
49306 rcu_read_unlock();
49307 }
49308 security_task_to_inode(task, inode);
49309 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49310 return -ENOENT;
49311 }
49312 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49313 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49314 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49315 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49316 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49317 +#endif
49318 task_dumpable(task)) {
49319 cred = __task_cred(task);
49320 stat->uid = cred->euid;
49321 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49322 + stat->gid = grsec_proc_gid;
49323 +#else
49324 stat->gid = cred->egid;
49325 +#endif
49326 }
49327 }
49328 rcu_read_unlock();
49329 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49330
49331 if (task) {
49332 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49333 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49334 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49335 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49336 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49337 +#endif
49338 task_dumpable(task)) {
49339 rcu_read_lock();
49340 cred = __task_cred(task);
49341 inode->i_uid = cred->euid;
49342 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49343 + inode->i_gid = grsec_proc_gid;
49344 +#else
49345 inode->i_gid = cred->egid;
49346 +#endif
49347 rcu_read_unlock();
49348 } else {
49349 inode->i_uid = GLOBAL_ROOT_UID;
49350 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49351 int fd = proc_fd(inode);
49352
49353 if (task) {
49354 - files = get_files_struct(task);
49355 + if (!gr_acl_handle_procpidmem(task))
49356 + files = get_files_struct(task);
49357 put_task_struct(task);
49358 }
49359 if (files) {
49360 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49361 */
49362 static int proc_fd_permission(struct inode *inode, int mask)
49363 {
49364 + struct task_struct *task;
49365 int rv = generic_permission(inode, mask);
49366 - if (rv == 0)
49367 - return 0;
49368 +
49369 if (task_pid(current) == proc_pid(inode))
49370 rv = 0;
49371 +
49372 + task = get_proc_task(inode);
49373 + if (task == NULL)
49374 + return rv;
49375 +
49376 + if (gr_acl_handle_procpidmem(task))
49377 + rv = -EACCES;
49378 +
49379 + put_task_struct(task);
49380 +
49381 return rv;
49382 }
49383
49384 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49385 if (!task)
49386 goto out_no_task;
49387
49388 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49389 + goto out;
49390 +
49391 /*
49392 * Yes, it does not scale. And it should not. Don't add
49393 * new entries into /proc/<tgid>/ without very good reasons.
49394 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49395 if (!task)
49396 goto out_no_task;
49397
49398 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49399 + goto out;
49400 +
49401 ret = 0;
49402 i = filp->f_pos;
49403 switch (i) {
49404 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49405 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49406 void *cookie)
49407 {
49408 - char *s = nd_get_link(nd);
49409 + const char *s = nd_get_link(nd);
49410 if (!IS_ERR(s))
49411 __putname(s);
49412 }
49413 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49414 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49415 #endif
49416 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49417 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49418 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49419 INF("syscall", S_IRUGO, proc_pid_syscall),
49420 #endif
49421 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49422 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49423 #ifdef CONFIG_SECURITY
49424 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49425 #endif
49426 -#ifdef CONFIG_KALLSYMS
49427 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49428 INF("wchan", S_IRUGO, proc_pid_wchan),
49429 #endif
49430 -#ifdef CONFIG_STACKTRACE
49431 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49432 ONE("stack", S_IRUGO, proc_pid_stack),
49433 #endif
49434 #ifdef CONFIG_SCHEDSTATS
49435 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49436 #ifdef CONFIG_HARDWALL
49437 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49438 #endif
49439 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49440 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49441 +#endif
49442 #ifdef CONFIG_USER_NS
49443 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49444 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49445 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49446 if (!inode)
49447 goto out;
49448
49449 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49450 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49451 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49452 + inode->i_gid = grsec_proc_gid;
49453 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49454 +#else
49455 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49456 +#endif
49457 inode->i_op = &proc_tgid_base_inode_operations;
49458 inode->i_fop = &proc_tgid_base_operations;
49459 inode->i_flags|=S_IMMUTABLE;
49460 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49461 if (!task)
49462 goto out;
49463
49464 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49465 + goto out_put_task;
49466 +
49467 result = proc_pid_instantiate(dir, dentry, task, NULL);
49468 +out_put_task:
49469 put_task_struct(task);
49470 out:
49471 return result;
49472 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49473 static int fake_filldir(void *buf, const char *name, int namelen,
49474 loff_t offset, u64 ino, unsigned d_type)
49475 {
49476 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49477 + __buf->error = -EINVAL;
49478 return 0;
49479 }
49480
49481 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49482 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49483 #endif
49484 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49485 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49486 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49487 INF("syscall", S_IRUGO, proc_pid_syscall),
49488 #endif
49489 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49490 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49491 #ifdef CONFIG_SECURITY
49492 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49493 #endif
49494 -#ifdef CONFIG_KALLSYMS
49495 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49496 INF("wchan", S_IRUGO, proc_pid_wchan),
49497 #endif
49498 -#ifdef CONFIG_STACKTRACE
49499 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49500 ONE("stack", S_IRUGO, proc_pid_stack),
49501 #endif
49502 #ifdef CONFIG_SCHEDSTATS
49503 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49504 index 82676e3..5f8518a 100644
49505 --- a/fs/proc/cmdline.c
49506 +++ b/fs/proc/cmdline.c
49507 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49508
49509 static int __init proc_cmdline_init(void)
49510 {
49511 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49512 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49513 +#else
49514 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49515 +#endif
49516 return 0;
49517 }
49518 module_init(proc_cmdline_init);
49519 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49520 index b143471..bb105e5 100644
49521 --- a/fs/proc/devices.c
49522 +++ b/fs/proc/devices.c
49523 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49524
49525 static int __init proc_devices_init(void)
49526 {
49527 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49528 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49529 +#else
49530 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49531 +#endif
49532 return 0;
49533 }
49534 module_init(proc_devices_init);
49535 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49536 index 7ac817b..c5c9eb0 100644
49537 --- a/fs/proc/inode.c
49538 +++ b/fs/proc/inode.c
49539 @@ -21,11 +21,17 @@
49540 #include <linux/seq_file.h>
49541 #include <linux/slab.h>
49542 #include <linux/mount.h>
49543 +#include <linux/grsecurity.h>
49544
49545 #include <asm/uaccess.h>
49546
49547 #include "internal.h"
49548
49549 +#ifdef CONFIG_PROC_SYSCTL
49550 +extern const struct inode_operations proc_sys_inode_operations;
49551 +extern const struct inode_operations proc_sys_dir_operations;
49552 +#endif
49553 +
49554 static void proc_evict_inode(struct inode *inode)
49555 {
49556 struct proc_dir_entry *de;
49557 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49558 ns_ops = PROC_I(inode)->ns_ops;
49559 if (ns_ops && ns_ops->put)
49560 ns_ops->put(PROC_I(inode)->ns);
49561 +
49562 +#ifdef CONFIG_PROC_SYSCTL
49563 + if (inode->i_op == &proc_sys_inode_operations ||
49564 + inode->i_op == &proc_sys_dir_operations)
49565 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49566 +#endif
49567 +
49568 }
49569
49570 static struct kmem_cache * proc_inode_cachep;
49571 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49572 if (de->mode) {
49573 inode->i_mode = de->mode;
49574 inode->i_uid = de->uid;
49575 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49576 + inode->i_gid = grsec_proc_gid;
49577 +#else
49578 inode->i_gid = de->gid;
49579 +#endif
49580 }
49581 if (de->size)
49582 inode->i_size = de->size;
49583 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49584 index e1167a1..bd24f20 100644
49585 --- a/fs/proc/internal.h
49586 +++ b/fs/proc/internal.h
49587 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49588 struct pid *pid, struct task_struct *task);
49589 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49590 struct pid *pid, struct task_struct *task);
49591 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49592 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49593 +#endif
49594 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49595
49596 extern const struct file_operations proc_tid_children_operations;
49597 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49598 index 86c67ee..cdca321 100644
49599 --- a/fs/proc/kcore.c
49600 +++ b/fs/proc/kcore.c
49601 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49602 * the addresses in the elf_phdr on our list.
49603 */
49604 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49605 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49606 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49607 + if (tsz > buflen)
49608 tsz = buflen;
49609 -
49610 +
49611 while (buflen) {
49612 struct kcore_list *m;
49613
49614 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49615 kfree(elf_buf);
49616 } else {
49617 if (kern_addr_valid(start)) {
49618 - unsigned long n;
49619 + char *elf_buf;
49620 + mm_segment_t oldfs;
49621
49622 - n = copy_to_user(buffer, (char *)start, tsz);
49623 - /*
49624 - * We cannot distinguish between fault on source
49625 - * and fault on destination. When this happens
49626 - * we clear too and hope it will trigger the
49627 - * EFAULT again.
49628 - */
49629 - if (n) {
49630 - if (clear_user(buffer + tsz - n,
49631 - n))
49632 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49633 + if (!elf_buf)
49634 + return -ENOMEM;
49635 + oldfs = get_fs();
49636 + set_fs(KERNEL_DS);
49637 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49638 + set_fs(oldfs);
49639 + if (copy_to_user(buffer, elf_buf, tsz)) {
49640 + kfree(elf_buf);
49641 return -EFAULT;
49642 + }
49643 }
49644 + set_fs(oldfs);
49645 + kfree(elf_buf);
49646 } else {
49647 if (clear_user(buffer, tsz))
49648 return -EFAULT;
49649 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49650
49651 static int open_kcore(struct inode *inode, struct file *filp)
49652 {
49653 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49654 + return -EPERM;
49655 +#endif
49656 if (!capable(CAP_SYS_RAWIO))
49657 return -EPERM;
49658 if (kcore_need_update)
49659 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49660 index 80e4645..53e5fcf 100644
49661 --- a/fs/proc/meminfo.c
49662 +++ b/fs/proc/meminfo.c
49663 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49664 vmi.used >> 10,
49665 vmi.largest_chunk >> 10
49666 #ifdef CONFIG_MEMORY_FAILURE
49667 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49668 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49669 #endif
49670 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49671 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49672 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49673 index b1822dd..df622cb 100644
49674 --- a/fs/proc/nommu.c
49675 +++ b/fs/proc/nommu.c
49676 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49677 if (len < 1)
49678 len = 1;
49679 seq_printf(m, "%*c", len, ' ');
49680 - seq_path(m, &file->f_path, "");
49681 + seq_path(m, &file->f_path, "\n\\");
49682 }
49683
49684 seq_putc(m, '\n');
49685 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49686 index fe72cd0..cb9b67d 100644
49687 --- a/fs/proc/proc_net.c
49688 +++ b/fs/proc/proc_net.c
49689 @@ -23,6 +23,7 @@
49690 #include <linux/nsproxy.h>
49691 #include <net/net_namespace.h>
49692 #include <linux/seq_file.h>
49693 +#include <linux/grsecurity.h>
49694
49695 #include "internal.h"
49696
49697 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49698 struct task_struct *task;
49699 struct nsproxy *ns;
49700 struct net *net = NULL;
49701 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49702 + const struct cred *cred = current_cred();
49703 +#endif
49704 +
49705 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49706 + if (cred->fsuid)
49707 + return net;
49708 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49709 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49710 + return net;
49711 +#endif
49712
49713 rcu_read_lock();
49714 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49715 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49716 index eb7cc91..7327a46 100644
49717 --- a/fs/proc/proc_sysctl.c
49718 +++ b/fs/proc/proc_sysctl.c
49719 @@ -12,11 +12,15 @@
49720 #include <linux/module.h>
49721 #include "internal.h"
49722
49723 +extern int gr_handle_chroot_sysctl(const int op);
49724 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49725 + const int op);
49726 +
49727 static const struct dentry_operations proc_sys_dentry_operations;
49728 static const struct file_operations proc_sys_file_operations;
49729 -static const struct inode_operations proc_sys_inode_operations;
49730 +const struct inode_operations proc_sys_inode_operations;
49731 static const struct file_operations proc_sys_dir_file_operations;
49732 -static const struct inode_operations proc_sys_dir_operations;
49733 +const struct inode_operations proc_sys_dir_operations;
49734
49735 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49736 {
49737 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49738
49739 err = NULL;
49740 d_set_d_op(dentry, &proc_sys_dentry_operations);
49741 +
49742 + gr_handle_proc_create(dentry, inode);
49743 +
49744 d_add(dentry, inode);
49745
49746 out:
49747 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49748 struct inode *inode = filp->f_path.dentry->d_inode;
49749 struct ctl_table_header *head = grab_header(inode);
49750 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49751 + int op = write ? MAY_WRITE : MAY_READ;
49752 ssize_t error;
49753 size_t res;
49754
49755 if (IS_ERR(head))
49756 return PTR_ERR(head);
49757
49758 +
49759 /*
49760 * At this point we know that the sysctl was not unregistered
49761 * and won't be until we finish.
49762 */
49763 error = -EPERM;
49764 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49765 + if (sysctl_perm(head->root, table, op))
49766 goto out;
49767
49768 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49769 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49770 if (!table->proc_handler)
49771 goto out;
49772
49773 +#ifdef CONFIG_GRKERNSEC
49774 + error = -EPERM;
49775 + if (gr_handle_chroot_sysctl(op))
49776 + goto out;
49777 + dget(filp->f_path.dentry);
49778 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49779 + dput(filp->f_path.dentry);
49780 + goto out;
49781 + }
49782 + dput(filp->f_path.dentry);
49783 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49784 + goto out;
49785 + if (write && !capable(CAP_SYS_ADMIN))
49786 + goto out;
49787 +#endif
49788 +
49789 /* careful: calling conventions are nasty here */
49790 res = count;
49791 error = table->proc_handler(table, write, buf, &res, ppos);
49792 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49793 return -ENOMEM;
49794 } else {
49795 d_set_d_op(child, &proc_sys_dentry_operations);
49796 +
49797 + gr_handle_proc_create(child, inode);
49798 +
49799 d_add(child, inode);
49800 }
49801 } else {
49802 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49803 if ((*pos)++ < file->f_pos)
49804 return 0;
49805
49806 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49807 + return 0;
49808 +
49809 if (unlikely(S_ISLNK(table->mode)))
49810 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49811 else
49812 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49813 if (IS_ERR(head))
49814 return PTR_ERR(head);
49815
49816 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49817 + return -ENOENT;
49818 +
49819 generic_fillattr(inode, stat);
49820 if (table)
49821 stat->mode = (stat->mode & S_IFMT) | table->mode;
49822 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49823 .llseek = generic_file_llseek,
49824 };
49825
49826 -static const struct inode_operations proc_sys_inode_operations = {
49827 +const struct inode_operations proc_sys_inode_operations = {
49828 .permission = proc_sys_permission,
49829 .setattr = proc_sys_setattr,
49830 .getattr = proc_sys_getattr,
49831 };
49832
49833 -static const struct inode_operations proc_sys_dir_operations = {
49834 +const struct inode_operations proc_sys_dir_operations = {
49835 .lookup = proc_sys_lookup,
49836 .permission = proc_sys_permission,
49837 .setattr = proc_sys_setattr,
49838 diff --git a/fs/proc/root.c b/fs/proc/root.c
49839 index 9a2d9fd..ddfc92a 100644
49840 --- a/fs/proc/root.c
49841 +++ b/fs/proc/root.c
49842 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49843 #ifdef CONFIG_PROC_DEVICETREE
49844 proc_device_tree_init();
49845 #endif
49846 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49847 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49848 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49849 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49850 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49851 +#endif
49852 +#else
49853 proc_mkdir("bus", NULL);
49854 +#endif
49855 proc_sys_init();
49856 }
49857
49858 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49859 index 4540b8f..1b9772f 100644
49860 --- a/fs/proc/task_mmu.c
49861 +++ b/fs/proc/task_mmu.c
49862 @@ -11,12 +11,19 @@
49863 #include <linux/rmap.h>
49864 #include <linux/swap.h>
49865 #include <linux/swapops.h>
49866 +#include <linux/grsecurity.h>
49867
49868 #include <asm/elf.h>
49869 #include <asm/uaccess.h>
49870 #include <asm/tlbflush.h>
49871 #include "internal.h"
49872
49873 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49874 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49875 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49876 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49877 +#endif
49878 +
49879 void task_mem(struct seq_file *m, struct mm_struct *mm)
49880 {
49881 unsigned long data, text, lib, swap;
49882 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49883 "VmExe:\t%8lu kB\n"
49884 "VmLib:\t%8lu kB\n"
49885 "VmPTE:\t%8lu kB\n"
49886 - "VmSwap:\t%8lu kB\n",
49887 - hiwater_vm << (PAGE_SHIFT-10),
49888 + "VmSwap:\t%8lu kB\n"
49889 +
49890 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49891 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49892 +#endif
49893 +
49894 + ,hiwater_vm << (PAGE_SHIFT-10),
49895 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49896 mm->locked_vm << (PAGE_SHIFT-10),
49897 mm->pinned_vm << (PAGE_SHIFT-10),
49898 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49899 data << (PAGE_SHIFT-10),
49900 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49901 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49902 - swap << (PAGE_SHIFT-10));
49903 + swap << (PAGE_SHIFT-10)
49904 +
49905 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49906 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49907 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49908 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49909 +#else
49910 + , mm->context.user_cs_base
49911 + , mm->context.user_cs_limit
49912 +#endif
49913 +#endif
49914 +
49915 + );
49916 }
49917
49918 unsigned long task_vsize(struct mm_struct *mm)
49919 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49920 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49921 }
49922
49923 - /* We don't show the stack guard page in /proc/maps */
49924 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49925 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49926 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49927 +#else
49928 start = vma->vm_start;
49929 - if (stack_guard_page_start(vma, start))
49930 - start += PAGE_SIZE;
49931 end = vma->vm_end;
49932 - if (stack_guard_page_end(vma, end))
49933 - end -= PAGE_SIZE;
49934 +#endif
49935
49936 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49937 start,
49938 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49939 flags & VM_WRITE ? 'w' : '-',
49940 flags & VM_EXEC ? 'x' : '-',
49941 flags & VM_MAYSHARE ? 's' : 'p',
49942 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49943 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49944 +#else
49945 pgoff,
49946 +#endif
49947 MAJOR(dev), MINOR(dev), ino, &len);
49948
49949 /*
49950 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49951 */
49952 if (file) {
49953 pad_len_spaces(m, len);
49954 - seq_path(m, &file->f_path, "\n");
49955 + seq_path(m, &file->f_path, "\n\\");
49956 goto done;
49957 }
49958
49959 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49960 * Thread stack in /proc/PID/task/TID/maps or
49961 * the main process stack.
49962 */
49963 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49964 - vma->vm_end >= mm->start_stack)) {
49965 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49966 + (vma->vm_start <= mm->start_stack &&
49967 + vma->vm_end >= mm->start_stack)) {
49968 name = "[stack]";
49969 } else {
49970 /* Thread stack in /proc/PID/maps */
49971 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49972 struct proc_maps_private *priv = m->private;
49973 struct task_struct *task = priv->task;
49974
49975 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49976 + if (current->exec_id != m->exec_id) {
49977 + gr_log_badprocpid("maps");
49978 + return 0;
49979 + }
49980 +#endif
49981 +
49982 show_map_vma(m, vma, is_pid);
49983
49984 if (m->count < m->size) /* vma is copied successfully */
49985 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49986 .private = &mss,
49987 };
49988
49989 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49990 + if (current->exec_id != m->exec_id) {
49991 + gr_log_badprocpid("smaps");
49992 + return 0;
49993 + }
49994 +#endif
49995 memset(&mss, 0, sizeof mss);
49996 - mss.vma = vma;
49997 - /* mmap_sem is held in m_start */
49998 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49999 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50000 -
50001 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50002 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
50003 +#endif
50004 + mss.vma = vma;
50005 + /* mmap_sem is held in m_start */
50006 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
50007 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
50008 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50009 + }
50010 +#endif
50011 show_map_vma(m, vma, is_pid);
50012
50013 seq_printf(m,
50014 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
50015 "KernelPageSize: %8lu kB\n"
50016 "MMUPageSize: %8lu kB\n"
50017 "Locked: %8lu kB\n",
50018 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50019 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
50020 +#else
50021 (vma->vm_end - vma->vm_start) >> 10,
50022 +#endif
50023 mss.resident >> 10,
50024 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
50025 mss.shared_clean >> 10,
50026 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50027 int n;
50028 char buffer[50];
50029
50030 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50031 + if (current->exec_id != m->exec_id) {
50032 + gr_log_badprocpid("numa_maps");
50033 + return 0;
50034 + }
50035 +#endif
50036 +
50037 if (!mm)
50038 return 0;
50039
50040 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
50041 mpol_to_str(buffer, sizeof(buffer), pol, 0);
50042 mpol_cond_put(pol);
50043
50044 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50045 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
50046 +#else
50047 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
50048 +#endif
50049
50050 if (file) {
50051 seq_printf(m, " file=");
50052 - seq_path(m, &file->f_path, "\n\t= ");
50053 + seq_path(m, &file->f_path, "\n\t\\= ");
50054 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
50055 seq_printf(m, " heap");
50056 } else {
50057 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
50058 index 1ccfa53..0848f95 100644
50059 --- a/fs/proc/task_nommu.c
50060 +++ b/fs/proc/task_nommu.c
50061 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
50062 else
50063 bytes += kobjsize(mm);
50064
50065 - if (current->fs && current->fs->users > 1)
50066 + if (current->fs && atomic_read(&current->fs->users) > 1)
50067 sbytes += kobjsize(current->fs);
50068 else
50069 bytes += kobjsize(current->fs);
50070 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
50071
50072 if (file) {
50073 pad_len_spaces(m, len);
50074 - seq_path(m, &file->f_path, "");
50075 + seq_path(m, &file->f_path, "\n\\");
50076 } else if (mm) {
50077 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
50078
50079 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
50080 index d67908b..d13f6a6 100644
50081 --- a/fs/quota/netlink.c
50082 +++ b/fs/quota/netlink.c
50083 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
50084 void quota_send_warning(short type, unsigned int id, dev_t dev,
50085 const char warntype)
50086 {
50087 - static atomic_t seq;
50088 + static atomic_unchecked_t seq;
50089 struct sk_buff *skb;
50090 void *msg_head;
50091 int ret;
50092 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50093 "VFS: Not enough memory to send quota warning.\n");
50094 return;
50095 }
50096 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50097 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50098 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50099 if (!msg_head) {
50100 printk(KERN_ERR
50101 diff --git a/fs/readdir.c b/fs/readdir.c
50102 index 39e3370..20d446d 100644
50103 --- a/fs/readdir.c
50104 +++ b/fs/readdir.c
50105 @@ -17,6 +17,7 @@
50106 #include <linux/security.h>
50107 #include <linux/syscalls.h>
50108 #include <linux/unistd.h>
50109 +#include <linux/namei.h>
50110
50111 #include <asm/uaccess.h>
50112
50113 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50114
50115 struct readdir_callback {
50116 struct old_linux_dirent __user * dirent;
50117 + struct file * file;
50118 int result;
50119 };
50120
50121 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50122 buf->result = -EOVERFLOW;
50123 return -EOVERFLOW;
50124 }
50125 +
50126 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50127 + return 0;
50128 +
50129 buf->result++;
50130 dirent = buf->dirent;
50131 if (!access_ok(VERIFY_WRITE, dirent,
50132 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50133
50134 buf.result = 0;
50135 buf.dirent = dirent;
50136 + buf.file = file;
50137
50138 error = vfs_readdir(file, fillonedir, &buf);
50139 if (buf.result)
50140 @@ -141,6 +148,7 @@ struct linux_dirent {
50141 struct getdents_callback {
50142 struct linux_dirent __user * current_dir;
50143 struct linux_dirent __user * previous;
50144 + struct file * file;
50145 int count;
50146 int error;
50147 };
50148 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50149 buf->error = -EOVERFLOW;
50150 return -EOVERFLOW;
50151 }
50152 +
50153 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50154 + return 0;
50155 +
50156 dirent = buf->previous;
50157 if (dirent) {
50158 if (__put_user(offset, &dirent->d_off))
50159 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50160 buf.previous = NULL;
50161 buf.count = count;
50162 buf.error = 0;
50163 + buf.file = file;
50164
50165 error = vfs_readdir(file, filldir, &buf);
50166 if (error >= 0)
50167 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50168 struct getdents_callback64 {
50169 struct linux_dirent64 __user * current_dir;
50170 struct linux_dirent64 __user * previous;
50171 + struct file *file;
50172 int count;
50173 int error;
50174 };
50175 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50176 buf->error = -EINVAL; /* only used if we fail.. */
50177 if (reclen > buf->count)
50178 return -EINVAL;
50179 +
50180 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50181 + return 0;
50182 +
50183 dirent = buf->previous;
50184 if (dirent) {
50185 if (__put_user(offset, &dirent->d_off))
50186 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50187
50188 buf.current_dir = dirent;
50189 buf.previous = NULL;
50190 + buf.file = file;
50191 buf.count = count;
50192 buf.error = 0;
50193
50194 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50195 error = buf.error;
50196 lastdirent = buf.previous;
50197 if (lastdirent) {
50198 - typeof(lastdirent->d_off) d_off = file->f_pos;
50199 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50200 if (__put_user(d_off, &lastdirent->d_off))
50201 error = -EFAULT;
50202 else
50203 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50204 index 2b7882b..1c5ef48 100644
50205 --- a/fs/reiserfs/do_balan.c
50206 +++ b/fs/reiserfs/do_balan.c
50207 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50208 return;
50209 }
50210
50211 - atomic_inc(&(fs_generation(tb->tb_sb)));
50212 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50213 do_balance_starts(tb);
50214
50215 /* balance leaf returns 0 except if combining L R and S into
50216 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50217 index e60e870..f40ac16 100644
50218 --- a/fs/reiserfs/procfs.c
50219 +++ b/fs/reiserfs/procfs.c
50220 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50221 "SMALL_TAILS " : "NO_TAILS ",
50222 replay_only(sb) ? "REPLAY_ONLY " : "",
50223 convert_reiserfs(sb) ? "CONV " : "",
50224 - atomic_read(&r->s_generation_counter),
50225 + atomic_read_unchecked(&r->s_generation_counter),
50226 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50227 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50228 SF(s_good_search_by_key_reada), SF(s_bmaps),
50229 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50230 index 33215f5..c5d427a 100644
50231 --- a/fs/reiserfs/reiserfs.h
50232 +++ b/fs/reiserfs/reiserfs.h
50233 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50234 /* Comment? -Hans */
50235 wait_queue_head_t s_wait;
50236 /* To be obsoleted soon by per buffer seals.. -Hans */
50237 - atomic_t s_generation_counter; // increased by one every time the
50238 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50239 // tree gets re-balanced
50240 unsigned long s_properties; /* File system properties. Currently holds
50241 on-disk FS format */
50242 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50243 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50244
50245 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50246 -#define get_generation(s) atomic_read (&fs_generation(s))
50247 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50248 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50249 #define __fs_changed(gen,s) (gen != get_generation (s))
50250 #define fs_changed(gen,s) \
50251 diff --git a/fs/select.c b/fs/select.c
50252 index db14c78..3aae1bd 100644
50253 --- a/fs/select.c
50254 +++ b/fs/select.c
50255 @@ -20,6 +20,7 @@
50256 #include <linux/export.h>
50257 #include <linux/slab.h>
50258 #include <linux/poll.h>
50259 +#include <linux/security.h>
50260 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50261 #include <linux/file.h>
50262 #include <linux/fdtable.h>
50263 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50264 struct poll_list *walk = head;
50265 unsigned long todo = nfds;
50266
50267 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50268 if (nfds > rlimit(RLIMIT_NOFILE))
50269 return -EINVAL;
50270
50271 diff --git a/fs/seq_file.c b/fs/seq_file.c
50272 index 14cf9de..adc4d5b 100644
50273 --- a/fs/seq_file.c
50274 +++ b/fs/seq_file.c
50275 @@ -9,6 +9,7 @@
50276 #include <linux/export.h>
50277 #include <linux/seq_file.h>
50278 #include <linux/slab.h>
50279 +#include <linux/sched.h>
50280
50281 #include <asm/uaccess.h>
50282 #include <asm/page.h>
50283 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50284 memset(p, 0, sizeof(*p));
50285 mutex_init(&p->lock);
50286 p->op = op;
50287 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50288 + p->exec_id = current->exec_id;
50289 +#endif
50290
50291 /*
50292 * Wrappers around seq_open(e.g. swaps_open) need to be
50293 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50294 return 0;
50295 }
50296 if (!m->buf) {
50297 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50298 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50299 if (!m->buf)
50300 return -ENOMEM;
50301 }
50302 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50303 Eoverflow:
50304 m->op->stop(m, p);
50305 kfree(m->buf);
50306 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50307 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50308 return !m->buf ? -ENOMEM : -EAGAIN;
50309 }
50310
50311 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50312
50313 /* grab buffer if we didn't have one */
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 goto Enomem;
50319 }
50320 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50321 goto Fill;
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 if (!m->buf)
50327 goto Enomem;
50328 m->count = 0;
50329 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50330 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50331 void *data)
50332 {
50333 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50334 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50335 int res = -ENOMEM;
50336
50337 if (op) {
50338 diff --git a/fs/splice.c b/fs/splice.c
50339 index 41514dd..6564a93 100644
50340 --- a/fs/splice.c
50341 +++ b/fs/splice.c
50342 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50343 pipe_lock(pipe);
50344
50345 for (;;) {
50346 - if (!pipe->readers) {
50347 + if (!atomic_read(&pipe->readers)) {
50348 send_sig(SIGPIPE, current, 0);
50349 if (!ret)
50350 ret = -EPIPE;
50351 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50352 do_wakeup = 0;
50353 }
50354
50355 - pipe->waiting_writers++;
50356 + atomic_inc(&pipe->waiting_writers);
50357 pipe_wait(pipe);
50358 - pipe->waiting_writers--;
50359 + atomic_dec(&pipe->waiting_writers);
50360 }
50361
50362 pipe_unlock(pipe);
50363 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50364 old_fs = get_fs();
50365 set_fs(get_ds());
50366 /* The cast to a user pointer is valid due to the set_fs() */
50367 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50368 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50369 set_fs(old_fs);
50370
50371 return res;
50372 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50373 old_fs = get_fs();
50374 set_fs(get_ds());
50375 /* The cast to a user pointer is valid due to the set_fs() */
50376 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50377 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50378 set_fs(old_fs);
50379
50380 return res;
50381 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50382 goto err;
50383
50384 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50385 - vec[i].iov_base = (void __user *) page_address(page);
50386 + vec[i].iov_base = (void __force_user *) page_address(page);
50387 vec[i].iov_len = this_len;
50388 spd.pages[i] = page;
50389 spd.nr_pages++;
50390 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50391 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50392 {
50393 while (!pipe->nrbufs) {
50394 - if (!pipe->writers)
50395 + if (!atomic_read(&pipe->writers))
50396 return 0;
50397
50398 - if (!pipe->waiting_writers && sd->num_spliced)
50399 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50400 return 0;
50401
50402 if (sd->flags & SPLICE_F_NONBLOCK)
50403 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50404 * out of the pipe right after the splice_to_pipe(). So set
50405 * PIPE_READERS appropriately.
50406 */
50407 - pipe->readers = 1;
50408 + atomic_set(&pipe->readers, 1);
50409
50410 current->splice_pipe = pipe;
50411 }
50412 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50413 ret = -ERESTARTSYS;
50414 break;
50415 }
50416 - if (!pipe->writers)
50417 + if (!atomic_read(&pipe->writers))
50418 break;
50419 - if (!pipe->waiting_writers) {
50420 + if (!atomic_read(&pipe->waiting_writers)) {
50421 if (flags & SPLICE_F_NONBLOCK) {
50422 ret = -EAGAIN;
50423 break;
50424 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50425 pipe_lock(pipe);
50426
50427 while (pipe->nrbufs >= pipe->buffers) {
50428 - if (!pipe->readers) {
50429 + if (!atomic_read(&pipe->readers)) {
50430 send_sig(SIGPIPE, current, 0);
50431 ret = -EPIPE;
50432 break;
50433 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50434 ret = -ERESTARTSYS;
50435 break;
50436 }
50437 - pipe->waiting_writers++;
50438 + atomic_inc(&pipe->waiting_writers);
50439 pipe_wait(pipe);
50440 - pipe->waiting_writers--;
50441 + atomic_dec(&pipe->waiting_writers);
50442 }
50443
50444 pipe_unlock(pipe);
50445 @@ -1828,14 +1828,14 @@ retry:
50446 pipe_double_lock(ipipe, opipe);
50447
50448 do {
50449 - if (!opipe->readers) {
50450 + if (!atomic_read(&opipe->readers)) {
50451 send_sig(SIGPIPE, current, 0);
50452 if (!ret)
50453 ret = -EPIPE;
50454 break;
50455 }
50456
50457 - if (!ipipe->nrbufs && !ipipe->writers)
50458 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50459 break;
50460
50461 /*
50462 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50463 pipe_double_lock(ipipe, opipe);
50464
50465 do {
50466 - if (!opipe->readers) {
50467 + if (!atomic_read(&opipe->readers)) {
50468 send_sig(SIGPIPE, current, 0);
50469 if (!ret)
50470 ret = -EPIPE;
50471 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50472 * return EAGAIN if we have the potential of some data in the
50473 * future, otherwise just return 0
50474 */
50475 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50476 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50477 ret = -EAGAIN;
50478
50479 pipe_unlock(ipipe);
50480 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50481 index 2fbdff6..5530a61 100644
50482 --- a/fs/sysfs/dir.c
50483 +++ b/fs/sysfs/dir.c
50484 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50485 struct sysfs_dirent *sd;
50486 int rc;
50487
50488 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50489 + const char *parent_name = parent_sd->s_name;
50490 +
50491 + mode = S_IFDIR | S_IRWXU;
50492 +
50493 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50494 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50495 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50496 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50497 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50498 +#endif
50499 +
50500 /* allocate */
50501 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50502 if (!sd)
50503 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50504 index 00012e3..8392349 100644
50505 --- a/fs/sysfs/file.c
50506 +++ b/fs/sysfs/file.c
50507 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50508
50509 struct sysfs_open_dirent {
50510 atomic_t refcnt;
50511 - atomic_t event;
50512 + atomic_unchecked_t event;
50513 wait_queue_head_t poll;
50514 struct list_head buffers; /* goes through sysfs_buffer.list */
50515 };
50516 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50517 if (!sysfs_get_active(attr_sd))
50518 return -ENODEV;
50519
50520 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50521 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50522 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50523
50524 sysfs_put_active(attr_sd);
50525 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50526 return -ENOMEM;
50527
50528 atomic_set(&new_od->refcnt, 0);
50529 - atomic_set(&new_od->event, 1);
50530 + atomic_set_unchecked(&new_od->event, 1);
50531 init_waitqueue_head(&new_od->poll);
50532 INIT_LIST_HEAD(&new_od->buffers);
50533 goto retry;
50534 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50535
50536 sysfs_put_active(attr_sd);
50537
50538 - if (buffer->event != atomic_read(&od->event))
50539 + if (buffer->event != atomic_read_unchecked(&od->event))
50540 goto trigger;
50541
50542 return DEFAULT_POLLMASK;
50543 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50544
50545 od = sd->s_attr.open;
50546 if (od) {
50547 - atomic_inc(&od->event);
50548 + atomic_inc_unchecked(&od->event);
50549 wake_up_interruptible(&od->poll);
50550 }
50551
50552 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50553 index a7ac78f..02158e1 100644
50554 --- a/fs/sysfs/symlink.c
50555 +++ b/fs/sysfs/symlink.c
50556 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50557
50558 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50559 {
50560 - char *page = nd_get_link(nd);
50561 + const char *page = nd_get_link(nd);
50562 if (!IS_ERR(page))
50563 free_page((unsigned long)page);
50564 }
50565 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50566 index c175b4d..8f36a16 100644
50567 --- a/fs/udf/misc.c
50568 +++ b/fs/udf/misc.c
50569 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50570
50571 u8 udf_tag_checksum(const struct tag *t)
50572 {
50573 - u8 *data = (u8 *)t;
50574 + const u8 *data = (const u8 *)t;
50575 u8 checksum = 0;
50576 int i;
50577 for (i = 0; i < sizeof(struct tag); ++i)
50578 diff --git a/fs/utimes.c b/fs/utimes.c
50579 index fa4dbe4..e12d1b9 100644
50580 --- a/fs/utimes.c
50581 +++ b/fs/utimes.c
50582 @@ -1,6 +1,7 @@
50583 #include <linux/compiler.h>
50584 #include <linux/file.h>
50585 #include <linux/fs.h>
50586 +#include <linux/security.h>
50587 #include <linux/linkage.h>
50588 #include <linux/mount.h>
50589 #include <linux/namei.h>
50590 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50591 goto mnt_drop_write_and_out;
50592 }
50593 }
50594 +
50595 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50596 + error = -EACCES;
50597 + goto mnt_drop_write_and_out;
50598 + }
50599 +
50600 mutex_lock(&inode->i_mutex);
50601 error = notify_change(path->dentry, &newattrs);
50602 mutex_unlock(&inode->i_mutex);
50603 diff --git a/fs/xattr.c b/fs/xattr.c
50604 index 4d45b71..2ec08e10 100644
50605 --- a/fs/xattr.c
50606 +++ b/fs/xattr.c
50607 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50608 * Extended attribute SET operations
50609 */
50610 static long
50611 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50612 +setxattr(struct path *path, const char __user *name, const void __user *value,
50613 size_t size, int flags)
50614 {
50615 int error;
50616 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50617 }
50618 }
50619
50620 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50621 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50622 + error = -EACCES;
50623 + goto out;
50624 + }
50625 +
50626 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50627 out:
50628 if (vvalue)
50629 vfree(vvalue);
50630 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50631 return error;
50632 error = mnt_want_write(path.mnt);
50633 if (!error) {
50634 - error = setxattr(path.dentry, name, value, size, flags);
50635 + error = setxattr(&path, name, value, size, flags);
50636 mnt_drop_write(path.mnt);
50637 }
50638 path_put(&path);
50639 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50640 return error;
50641 error = mnt_want_write(path.mnt);
50642 if (!error) {
50643 - error = setxattr(path.dentry, name, value, size, flags);
50644 + error = setxattr(&path, name, value, size, flags);
50645 mnt_drop_write(path.mnt);
50646 }
50647 path_put(&path);
50648 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50649 {
50650 int fput_needed;
50651 struct file *f;
50652 - struct dentry *dentry;
50653 int error = -EBADF;
50654
50655 f = fget_light(fd, &fput_needed);
50656 if (!f)
50657 return error;
50658 - dentry = f->f_path.dentry;
50659 - audit_inode(NULL, dentry);
50660 + audit_inode(NULL, f->f_path.dentry);
50661 error = mnt_want_write_file(f);
50662 if (!error) {
50663 - error = setxattr(dentry, name, value, size, flags);
50664 + error = setxattr(&f->f_path, name, value, size, flags);
50665 mnt_drop_write_file(f);
50666 }
50667 fput_light(f, fput_needed);
50668 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50669 index 69d06b0..c0996e5 100644
50670 --- a/fs/xattr_acl.c
50671 +++ b/fs/xattr_acl.c
50672 @@ -17,8 +17,8 @@
50673 struct posix_acl *
50674 posix_acl_from_xattr(const void *value, size_t size)
50675 {
50676 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50677 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50678 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50679 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50680 int count;
50681 struct posix_acl *acl;
50682 struct posix_acl_entry *acl_e;
50683 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50684 index 848ffa7..1f249bf 100644
50685 --- a/fs/xfs/xfs_bmap.c
50686 +++ b/fs/xfs/xfs_bmap.c
50687 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50688 int nmap,
50689 int ret_nmap);
50690 #else
50691 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50692 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50693 #endif /* DEBUG */
50694
50695 STATIC int
50696 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50697 index 1b9fc3e..e1bdde0 100644
50698 --- a/fs/xfs/xfs_dir2_sf.c
50699 +++ b/fs/xfs/xfs_dir2_sf.c
50700 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50701 }
50702
50703 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50704 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50705 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50706 + char name[sfep->namelen];
50707 + memcpy(name, sfep->name, sfep->namelen);
50708 + if (filldir(dirent, name, sfep->namelen,
50709 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50710 + *offset = off & 0x7fffffff;
50711 + return 0;
50712 + }
50713 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50714 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50715 *offset = off & 0x7fffffff;
50716 return 0;
50717 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50718 index 0e0232c..fa5c3fe 100644
50719 --- a/fs/xfs/xfs_ioctl.c
50720 +++ b/fs/xfs/xfs_ioctl.c
50721 @@ -126,7 +126,7 @@ xfs_find_handle(
50722 }
50723
50724 error = -EFAULT;
50725 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50726 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50727 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50728 goto out_put;
50729
50730 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50731 index 4e00cf0..3374374 100644
50732 --- a/fs/xfs/xfs_iops.c
50733 +++ b/fs/xfs/xfs_iops.c
50734 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50735 struct nameidata *nd,
50736 void *p)
50737 {
50738 - char *s = nd_get_link(nd);
50739 + const char *s = nd_get_link(nd);
50740
50741 if (!IS_ERR(s))
50742 kfree(s);
50743 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50744 new file mode 100644
50745 index 0000000..d38b430
50746 --- /dev/null
50747 +++ b/grsecurity/Kconfig
50748 @@ -0,0 +1,947 @@
50749 +#
50750 +# grecurity configuration
50751 +#
50752 +menu "Memory Protections"
50753 +depends on GRKERNSEC
50754 +
50755 +config GRKERNSEC_KMEM
50756 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50757 + default y if GRKERNSEC_CONFIG_AUTO
50758 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50759 + help
50760 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50761 + be written to or read from to modify or leak the contents of the running
50762 + kernel. /dev/port will also not be allowed to be opened. If you have module
50763 + support disabled, enabling this will close up four ways that are
50764 + currently used to insert malicious code into the running kernel.
50765 + Even with all these features enabled, we still highly recommend that
50766 + you use the RBAC system, as it is still possible for an attacker to
50767 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50768 + If you are not using XFree86, you may be able to stop this additional
50769 + case by enabling the 'Disable privileged I/O' option. Though nothing
50770 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50771 + but only to video memory, which is the only writing we allow in this
50772 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50773 + not be allowed to mprotect it with PROT_WRITE later.
50774 + It is highly recommended that you say Y here if you meet all the
50775 + conditions above.
50776 +
50777 +config GRKERNSEC_VM86
50778 + bool "Restrict VM86 mode"
50779 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50780 + depends on X86_32
50781 +
50782 + help
50783 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50784 + make use of a special execution mode on 32bit x86 processors called
50785 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50786 + video cards and will still work with this option enabled. The purpose
50787 + of the option is to prevent exploitation of emulation errors in
50788 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50789 + Nearly all users should be able to enable this option.
50790 +
50791 +config GRKERNSEC_IO
50792 + bool "Disable privileged I/O"
50793 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50794 + depends on X86
50795 + select RTC_CLASS
50796 + select RTC_INTF_DEV
50797 + select RTC_DRV_CMOS
50798 +
50799 + help
50800 + If you say Y here, all ioperm and iopl calls will return an error.
50801 + Ioperm and iopl can be used to modify the running kernel.
50802 + Unfortunately, some programs need this access to operate properly,
50803 + the most notable of which are XFree86 and hwclock. hwclock can be
50804 + remedied by having RTC support in the kernel, so real-time
50805 + clock support is enabled if this option is enabled, to ensure
50806 + that hwclock operates correctly. XFree86 still will not
50807 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50808 + IF YOU USE XFree86. If you use XFree86 and you still want to
50809 + protect your kernel against modification, use the RBAC system.
50810 +
50811 +config GRKERNSEC_PROC_MEMMAP
50812 + bool "Harden ASLR against information leaks and entropy reduction"
50813 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50814 + depends on PAX_NOEXEC || PAX_ASLR
50815 + help
50816 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50817 + give no information about the addresses of its mappings if
50818 + PaX features that rely on random addresses are enabled on the task.
50819 + In addition to sanitizing this information and disabling other
50820 + dangerous sources of information, this option causes reads of sensitive
50821 + /proc/<pid> entries where the file descriptor was opened in a different
50822 + task than the one performing the read. Such attempts are logged.
50823 + This option also limits argv/env strings for suid/sgid binaries
50824 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50825 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50826 + binaries to prevent alternative mmap layouts from being abused.
50827 +
50828 + If you use PaX it is essential that you say Y here as it closes up
50829 + several holes that make full ASLR useless locally.
50830 +
50831 +config GRKERNSEC_BRUTE
50832 + bool "Deter exploit bruteforcing"
50833 + default y if GRKERNSEC_CONFIG_AUTO
50834 + help
50835 + If you say Y here, attempts to bruteforce exploits against forking
50836 + daemons such as apache or sshd, as well as against suid/sgid binaries
50837 + will be deterred. When a child of a forking daemon is killed by PaX
50838 + or crashes due to an illegal instruction or other suspicious signal,
50839 + the parent process will be delayed 30 seconds upon every subsequent
50840 + fork until the administrator is able to assess the situation and
50841 + restart the daemon.
50842 + In the suid/sgid case, the attempt is logged, the user has all their
50843 + processes terminated, and they are prevented from executing any further
50844 + processes for 15 minutes.
50845 + It is recommended that you also enable signal logging in the auditing
50846 + section so that logs are generated when a process triggers a suspicious
50847 + signal.
50848 + If the sysctl option is enabled, a sysctl option with name
50849 + "deter_bruteforce" is created.
50850 +
50851 +
50852 +config GRKERNSEC_MODHARDEN
50853 + bool "Harden module auto-loading"
50854 + default y if GRKERNSEC_CONFIG_AUTO
50855 + depends on MODULES
50856 + help
50857 + If you say Y here, module auto-loading in response to use of some
50858 + feature implemented by an unloaded module will be restricted to
50859 + root users. Enabling this option helps defend against attacks
50860 + by unprivileged users who abuse the auto-loading behavior to
50861 + cause a vulnerable module to load that is then exploited.
50862 +
50863 + If this option prevents a legitimate use of auto-loading for a
50864 + non-root user, the administrator can execute modprobe manually
50865 + with the exact name of the module mentioned in the alert log.
50866 + Alternatively, the administrator can add the module to the list
50867 + of modules loaded at boot by modifying init scripts.
50868 +
50869 + Modification of init scripts will most likely be needed on
50870 + Ubuntu servers with encrypted home directory support enabled,
50871 + as the first non-root user logging in will cause the ecb(aes),
50872 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50873 +
50874 +config GRKERNSEC_HIDESYM
50875 + bool "Hide kernel symbols"
50876 + default y if GRKERNSEC_CONFIG_AUTO
50877 + select PAX_USERCOPY_SLABS
50878 + help
50879 + If you say Y here, getting information on loaded modules, and
50880 + displaying all kernel symbols through a syscall will be restricted
50881 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50882 + /proc/kallsyms will be restricted to the root user. The RBAC
50883 + system can hide that entry even from root.
50884 +
50885 + This option also prevents leaking of kernel addresses through
50886 + several /proc entries.
50887 +
50888 + Note that this option is only effective provided the following
50889 + conditions are met:
50890 + 1) The kernel using grsecurity is not precompiled by some distribution
50891 + 2) You have also enabled GRKERNSEC_DMESG
50892 + 3) You are using the RBAC system and hiding other files such as your
50893 + kernel image and System.map. Alternatively, enabling this option
50894 + causes the permissions on /boot, /lib/modules, and the kernel
50895 + source directory to change at compile time to prevent
50896 + reading by non-root users.
50897 + If the above conditions are met, this option will aid in providing a
50898 + useful protection against local kernel exploitation of overflows
50899 + and arbitrary read/write vulnerabilities.
50900 +
50901 +config GRKERNSEC_KERN_LOCKOUT
50902 + bool "Active kernel exploit response"
50903 + default y if GRKERNSEC_CONFIG_AUTO
50904 + depends on X86 || ARM || PPC || SPARC
50905 + help
50906 + If you say Y here, when a PaX alert is triggered due to suspicious
50907 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50908 + or an OOPS occurs due to bad memory accesses, instead of just
50909 + terminating the offending process (and potentially allowing
50910 + a subsequent exploit from the same user), we will take one of two
50911 + actions:
50912 + If the user was root, we will panic the system
50913 + If the user was non-root, we will log the attempt, terminate
50914 + all processes owned by the user, then prevent them from creating
50915 + any new processes until the system is restarted
50916 + This deters repeated kernel exploitation/bruteforcing attempts
50917 + and is useful for later forensics.
50918 +
50919 +endmenu
50920 +menu "Role Based Access Control Options"
50921 +depends on GRKERNSEC
50922 +
50923 +config GRKERNSEC_RBAC_DEBUG
50924 + bool
50925 +
50926 +config GRKERNSEC_NO_RBAC
50927 + bool "Disable RBAC system"
50928 + help
50929 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50930 + preventing the RBAC system from being enabled. You should only say Y
50931 + here if you have no intention of using the RBAC system, so as to prevent
50932 + an attacker with root access from misusing the RBAC system to hide files
50933 + and processes when loadable module support and /dev/[k]mem have been
50934 + locked down.
50935 +
50936 +config GRKERNSEC_ACL_HIDEKERN
50937 + bool "Hide kernel processes"
50938 + help
50939 + If you say Y here, all kernel threads will be hidden to all
50940 + processes but those whose subject has the "view hidden processes"
50941 + flag.
50942 +
50943 +config GRKERNSEC_ACL_MAXTRIES
50944 + int "Maximum tries before password lockout"
50945 + default 3
50946 + help
50947 + This option enforces the maximum number of times a user can attempt
50948 + to authorize themselves with the grsecurity RBAC system before being
50949 + denied the ability to attempt authorization again for a specified time.
50950 + The lower the number, the harder it will be to brute-force a password.
50951 +
50952 +config GRKERNSEC_ACL_TIMEOUT
50953 + int "Time to wait after max password tries, in seconds"
50954 + default 30
50955 + help
50956 + This option specifies the time the user must wait after attempting to
50957 + authorize to the RBAC system with the maximum number of invalid
50958 + passwords. The higher the number, the harder it will be to brute-force
50959 + a password.
50960 +
50961 +endmenu
50962 +menu "Filesystem Protections"
50963 +depends on GRKERNSEC
50964 +
50965 +config GRKERNSEC_PROC
50966 + bool "Proc restrictions"
50967 + default y if GRKERNSEC_CONFIG_AUTO
50968 + help
50969 + If you say Y here, the permissions of the /proc filesystem
50970 + will be altered to enhance system security and privacy. You MUST
50971 + choose either a user only restriction or a user and group restriction.
50972 + Depending upon the option you choose, you can either restrict users to
50973 + see only the processes they themselves run, or choose a group that can
50974 + view all processes and files normally restricted to root if you choose
50975 + the "restrict to user only" option. NOTE: If you're running identd or
50976 + ntpd as a non-root user, you will have to run it as the group you
50977 + specify here.
50978 +
50979 +config GRKERNSEC_PROC_USER
50980 + bool "Restrict /proc to user only"
50981 + depends on GRKERNSEC_PROC
50982 + help
50983 + If you say Y here, non-root users will only be able to view their own
50984 + processes, and restricts them from viewing network-related information,
50985 + and viewing kernel symbol and module information.
50986 +
50987 +config GRKERNSEC_PROC_USERGROUP
50988 + bool "Allow special group"
50989 + default y if GRKERNSEC_CONFIG_AUTO
50990 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50991 + help
50992 + If you say Y here, you will be able to select a group that will be
50993 + able to view all processes and network-related information. If you've
50994 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50995 + remain hidden. This option is useful if you want to run identd as
50996 + a non-root user. The group you select may also be chosen at boot time
50997 + via "grsec_proc_gid=" on the kernel commandline.
50998 +
50999 +config GRKERNSEC_PROC_GID
51000 + int "GID for special group"
51001 + depends on GRKERNSEC_PROC_USERGROUP
51002 + default 1001
51003 +
51004 +config GRKERNSEC_PROC_ADD
51005 + bool "Additional restrictions"
51006 + default y if GRKERNSEC_CONFIG_AUTO
51007 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
51008 + help
51009 + If you say Y here, additional restrictions will be placed on
51010 + /proc that keep normal users from viewing device information and
51011 + slabinfo information that could be useful for exploits.
51012 +
51013 +config GRKERNSEC_LINK
51014 + bool "Linking restrictions"
51015 + default y if GRKERNSEC_CONFIG_AUTO
51016 + help
51017 + If you say Y here, /tmp race exploits will be prevented, since users
51018 + will no longer be able to follow symlinks owned by other users in
51019 + world-writable +t directories (e.g. /tmp), unless the owner of the
51020 + symlink is the owner of the directory. users will also not be
51021 + able to hardlink to files they do not own. If the sysctl option is
51022 + enabled, a sysctl option with name "linking_restrictions" is created.
51023 +
51024 +config GRKERNSEC_SYMLINKOWN
51025 + bool "Kernel-enforced SymlinksIfOwnerMatch"
51026 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51027 + help
51028 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
51029 + that prevents it from being used as a security feature. As Apache
51030 + verifies the symlink by performing a stat() against the target of
51031 + the symlink before it is followed, an attacker can setup a symlink
51032 + to point to a same-owned file, then replace the symlink with one
51033 + that targets another user's file just after Apache "validates" the
51034 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
51035 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
51036 + will be in place for the group you specify. If the sysctl option
51037 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
51038 + created.
51039 +
51040 +config GRKERNSEC_SYMLINKOWN_GID
51041 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
51042 + depends on GRKERNSEC_SYMLINKOWN
51043 + default 1006
51044 + help
51045 + Setting this GID determines what group kernel-enforced
51046 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51047 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51048 +
51049 +config GRKERNSEC_FIFO
51050 + bool "FIFO restrictions"
51051 + default y if GRKERNSEC_CONFIG_AUTO
51052 + help
51053 + If you say Y here, users will not be able to write to FIFOs they don't
51054 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51055 + the FIFO is the same owner of the directory it's held in. If the sysctl
51056 + option is enabled, a sysctl option with name "fifo_restrictions" is
51057 + created.
51058 +
51059 +config GRKERNSEC_SYSFS_RESTRICT
51060 + bool "Sysfs/debugfs restriction"
51061 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51062 + depends on SYSFS
51063 + help
51064 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51065 + any filesystem normally mounted under it (e.g. debugfs) will be
51066 + mostly accessible only by root. These filesystems generally provide access
51067 + to hardware and debug information that isn't appropriate for unprivileged
51068 + users of the system. Sysfs and debugfs have also become a large source
51069 + of new vulnerabilities, ranging from infoleaks to local compromise.
51070 + There has been very little oversight with an eye toward security involved
51071 + in adding new exporters of information to these filesystems, so their
51072 + use is discouraged.
51073 + For reasons of compatibility, a few directories have been whitelisted
51074 + for access by non-root users:
51075 + /sys/fs/selinux
51076 + /sys/fs/fuse
51077 + /sys/devices/system/cpu
51078 +
51079 +config GRKERNSEC_ROFS
51080 + bool "Runtime read-only mount protection"
51081 + help
51082 + If you say Y here, a sysctl option with name "romount_protect" will
51083 + be created. By setting this option to 1 at runtime, filesystems
51084 + will be protected in the following ways:
51085 + * No new writable mounts will be allowed
51086 + * Existing read-only mounts won't be able to be remounted read/write
51087 + * Write operations will be denied on all block devices
51088 + This option acts independently of grsec_lock: once it is set to 1,
51089 + it cannot be turned off. Therefore, please be mindful of the resulting
51090 + behavior if this option is enabled in an init script on a read-only
51091 + filesystem. This feature is mainly intended for secure embedded systems.
51092 +
51093 +config GRKERNSEC_CHROOT
51094 + bool "Chroot jail restrictions"
51095 + default y if GRKERNSEC_CONFIG_AUTO
51096 + help
51097 + If you say Y here, you will be able to choose several options that will
51098 + make breaking out of a chrooted jail much more difficult. If you
51099 + encounter no software incompatibilities with the following options, it
51100 + is recommended that you enable each one.
51101 +
51102 +config GRKERNSEC_CHROOT_MOUNT
51103 + bool "Deny mounts"
51104 + default y if GRKERNSEC_CONFIG_AUTO
51105 + depends on GRKERNSEC_CHROOT
51106 + help
51107 + If you say Y here, processes inside a chroot will not be able to
51108 + mount or remount filesystems. If the sysctl option is enabled, a
51109 + sysctl option with name "chroot_deny_mount" is created.
51110 +
51111 +config GRKERNSEC_CHROOT_DOUBLE
51112 + bool "Deny double-chroots"
51113 + default y if GRKERNSEC_CONFIG_AUTO
51114 + depends on GRKERNSEC_CHROOT
51115 + help
51116 + If you say Y here, processes inside a chroot will not be able to chroot
51117 + again outside the chroot. This is a widely used method of breaking
51118 + out of a chroot jail and should not be allowed. If the sysctl
51119 + option is enabled, a sysctl option with name
51120 + "chroot_deny_chroot" is created.
51121 +
51122 +config GRKERNSEC_CHROOT_PIVOT
51123 + bool "Deny pivot_root in chroot"
51124 + default y if GRKERNSEC_CONFIG_AUTO
51125 + depends on GRKERNSEC_CHROOT
51126 + help
51127 + If you say Y here, processes inside a chroot will not be able to use
51128 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51129 + works similar to chroot in that it changes the root filesystem. This
51130 + function could be misused in a chrooted process to attempt to break out
51131 + of the chroot, and therefore should not be allowed. If the sysctl
51132 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51133 + created.
51134 +
51135 +config GRKERNSEC_CHROOT_CHDIR
51136 + bool "Enforce chdir(\"/\") on all chroots"
51137 + default y if GRKERNSEC_CONFIG_AUTO
51138 + depends on GRKERNSEC_CHROOT
51139 + help
51140 + If you say Y here, the current working directory of all newly-chrooted
51141 + applications will be set to the the root directory of the chroot.
51142 + The man page on chroot(2) states:
51143 + Note that this call does not change the current working
51144 + directory, so that `.' can be outside the tree rooted at
51145 + `/'. In particular, the super-user can escape from a
51146 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51147 +
51148 + It is recommended that you say Y here, since it's not known to break
51149 + any software. If the sysctl option is enabled, a sysctl option with
51150 + name "chroot_enforce_chdir" is created.
51151 +
51152 +config GRKERNSEC_CHROOT_CHMOD
51153 + bool "Deny (f)chmod +s"
51154 + default y if GRKERNSEC_CONFIG_AUTO
51155 + depends on GRKERNSEC_CHROOT
51156 + help
51157 + If you say Y here, processes inside a chroot will not be able to chmod
51158 + or fchmod files to make them have suid or sgid bits. This protects
51159 + against another published method of breaking a chroot. If the sysctl
51160 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51161 + created.
51162 +
51163 +config GRKERNSEC_CHROOT_FCHDIR
51164 + bool "Deny fchdir out of chroot"
51165 + default y if GRKERNSEC_CONFIG_AUTO
51166 + depends on GRKERNSEC_CHROOT
51167 + help
51168 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51169 + to a file descriptor of the chrooting process that points to a directory
51170 + outside the filesystem will be stopped. If the sysctl option
51171 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51172 +
51173 +config GRKERNSEC_CHROOT_MKNOD
51174 + bool "Deny mknod"
51175 + default y if GRKERNSEC_CONFIG_AUTO
51176 + depends on GRKERNSEC_CHROOT
51177 + help
51178 + If you say Y here, processes inside a chroot will not be allowed to
51179 + mknod. The problem with using mknod inside a chroot is that it
51180 + would allow an attacker to create a device entry that is the same
51181 + as one on the physical root of your system, which could range from
51182 + anything from the console device to a device for your harddrive (which
51183 + they could then use to wipe the drive or steal data). It is recommended
51184 + that you say Y here, unless you run into software incompatibilities.
51185 + If the sysctl option is enabled, a sysctl option with name
51186 + "chroot_deny_mknod" is created.
51187 +
51188 +config GRKERNSEC_CHROOT_SHMAT
51189 + bool "Deny shmat() out of chroot"
51190 + default y if GRKERNSEC_CONFIG_AUTO
51191 + depends on GRKERNSEC_CHROOT
51192 + help
51193 + If you say Y here, processes inside a chroot will not be able to attach
51194 + to shared memory segments that were created outside of the chroot jail.
51195 + It is recommended that you say Y here. If the sysctl option is enabled,
51196 + a sysctl option with name "chroot_deny_shmat" is created.
51197 +
51198 +config GRKERNSEC_CHROOT_UNIX
51199 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51200 + default y if GRKERNSEC_CONFIG_AUTO
51201 + depends on GRKERNSEC_CHROOT
51202 + help
51203 + If you say Y here, processes inside a chroot will not be able to
51204 + connect to abstract (meaning not belonging to a filesystem) Unix
51205 + domain sockets that were bound outside of a chroot. It is recommended
51206 + that you say Y here. If the sysctl option is enabled, a sysctl option
51207 + with name "chroot_deny_unix" is created.
51208 +
51209 +config GRKERNSEC_CHROOT_FINDTASK
51210 + bool "Protect outside processes"
51211 + default y if GRKERNSEC_CONFIG_AUTO
51212 + depends on GRKERNSEC_CHROOT
51213 + help
51214 + If you say Y here, processes inside a chroot will not be able to
51215 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51216 + getsid, or view any process outside of the chroot. If the sysctl
51217 + option is enabled, a sysctl option with name "chroot_findtask" is
51218 + created.
51219 +
51220 +config GRKERNSEC_CHROOT_NICE
51221 + bool "Restrict priority changes"
51222 + default y if GRKERNSEC_CONFIG_AUTO
51223 + depends on GRKERNSEC_CHROOT
51224 + help
51225 + If you say Y here, processes inside a chroot will not be able to raise
51226 + the priority of processes in the chroot, or alter the priority of
51227 + processes outside the chroot. This provides more security than simply
51228 + removing CAP_SYS_NICE from the process' capability set. If the
51229 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51230 + is created.
51231 +
51232 +config GRKERNSEC_CHROOT_SYSCTL
51233 + bool "Deny sysctl writes"
51234 + default y if GRKERNSEC_CONFIG_AUTO
51235 + depends on GRKERNSEC_CHROOT
51236 + help
51237 + If you say Y here, an attacker in a chroot will not be able to
51238 + write to sysctl entries, either by sysctl(2) or through a /proc
51239 + interface. It is strongly recommended that you say Y here. If the
51240 + sysctl option is enabled, a sysctl option with name
51241 + "chroot_deny_sysctl" is created.
51242 +
51243 +config GRKERNSEC_CHROOT_CAPS
51244 + bool "Capability restrictions"
51245 + default y if GRKERNSEC_CONFIG_AUTO
51246 + depends on GRKERNSEC_CHROOT
51247 + help
51248 + If you say Y here, the capabilities on all processes within a
51249 + chroot jail will be lowered to stop module insertion, raw i/o,
51250 + system and net admin tasks, rebooting the system, modifying immutable
51251 + files, modifying IPC owned by another, and changing the system time.
51252 + This is left an option because it can break some apps. Disable this
51253 + if your chrooted apps are having problems performing those kinds of
51254 + tasks. If the sysctl option is enabled, a sysctl option with
51255 + name "chroot_caps" is created.
51256 +
51257 +endmenu
51258 +menu "Kernel Auditing"
51259 +depends on GRKERNSEC
51260 +
51261 +config GRKERNSEC_AUDIT_GROUP
51262 + bool "Single group for auditing"
51263 + help
51264 + If you say Y here, the exec, chdir, and (un)mount logging features
51265 + will only operate on a group you specify. This option is recommended
51266 + if you only want to watch certain users instead of having a large
51267 + amount of logs from the entire system. If the sysctl option is enabled,
51268 + a sysctl option with name "audit_group" is created.
51269 +
51270 +config GRKERNSEC_AUDIT_GID
51271 + int "GID for auditing"
51272 + depends on GRKERNSEC_AUDIT_GROUP
51273 + default 1007
51274 +
51275 +config GRKERNSEC_EXECLOG
51276 + bool "Exec logging"
51277 + help
51278 + If you say Y here, all execve() calls will be logged (since the
51279 + other exec*() calls are frontends to execve(), all execution
51280 + will be logged). Useful for shell-servers that like to keep track
51281 + of their users. If the sysctl option is enabled, a sysctl option with
51282 + name "exec_logging" is created.
51283 + WARNING: This option when enabled will produce a LOT of logs, especially
51284 + on an active system.
51285 +
51286 +config GRKERNSEC_RESLOG
51287 + bool "Resource logging"
51288 + default y if GRKERNSEC_CONFIG_AUTO
51289 + help
51290 + If you say Y here, all attempts to overstep resource limits will
51291 + be logged with the resource name, the requested size, and the current
51292 + limit. It is highly recommended that you say Y here. If the sysctl
51293 + option is enabled, a sysctl option with name "resource_logging" is
51294 + created. If the RBAC system is enabled, the sysctl value is ignored.
51295 +
51296 +config GRKERNSEC_CHROOT_EXECLOG
51297 + bool "Log execs within chroot"
51298 + help
51299 + If you say Y here, all executions inside a chroot jail will be logged
51300 + to syslog. This can cause a large amount of logs if certain
51301 + applications (eg. djb's daemontools) are installed on the system, and
51302 + is therefore left as an option. If the sysctl option is enabled, a
51303 + sysctl option with name "chroot_execlog" is created.
51304 +
51305 +config GRKERNSEC_AUDIT_PTRACE
51306 + bool "Ptrace logging"
51307 + help
51308 + If you say Y here, all attempts to attach to a process via ptrace
51309 + will be logged. If the sysctl option is enabled, a sysctl option
51310 + with name "audit_ptrace" is created.
51311 +
51312 +config GRKERNSEC_AUDIT_CHDIR
51313 + bool "Chdir logging"
51314 + help
51315 + If you say Y here, all chdir() calls will be logged. If the sysctl
51316 + option is enabled, a sysctl option with name "audit_chdir" is created.
51317 +
51318 +config GRKERNSEC_AUDIT_MOUNT
51319 + bool "(Un)Mount logging"
51320 + help
51321 + If you say Y here, all mounts and unmounts will be logged. If the
51322 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51323 + created.
51324 +
51325 +config GRKERNSEC_SIGNAL
51326 + bool "Signal logging"
51327 + default y if GRKERNSEC_CONFIG_AUTO
51328 + help
51329 + If you say Y here, certain important signals will be logged, such as
51330 + SIGSEGV, which will as a result inform you of when a error in a program
51331 + occurred, which in some cases could mean a possible exploit attempt.
51332 + If the sysctl option is enabled, a sysctl option with name
51333 + "signal_logging" is created.
51334 +
51335 +config GRKERNSEC_FORKFAIL
51336 + bool "Fork failure logging"
51337 + help
51338 + If you say Y here, all failed fork() attempts will be logged.
51339 + This could suggest a fork bomb, or someone attempting to overstep
51340 + their process limit. If the sysctl option is enabled, a sysctl option
51341 + with name "forkfail_logging" is created.
51342 +
51343 +config GRKERNSEC_TIME
51344 + bool "Time change logging"
51345 + default y if GRKERNSEC_CONFIG_AUTO
51346 + help
51347 + If you say Y here, any changes of the system clock will be logged.
51348 + If the sysctl option is enabled, a sysctl option with name
51349 + "timechange_logging" is created.
51350 +
51351 +config GRKERNSEC_PROC_IPADDR
51352 + bool "/proc/<pid>/ipaddr support"
51353 + default y if GRKERNSEC_CONFIG_AUTO
51354 + help
51355 + If you say Y here, a new entry will be added to each /proc/<pid>
51356 + directory that contains the IP address of the person using the task.
51357 + The IP is carried across local TCP and AF_UNIX stream sockets.
51358 + This information can be useful for IDS/IPSes to perform remote response
51359 + to a local attack. The entry is readable by only the owner of the
51360 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51361 + the RBAC system), and thus does not create privacy concerns.
51362 +
51363 +config GRKERNSEC_RWXMAP_LOG
51364 + bool 'Denied RWX mmap/mprotect logging'
51365 + default y if GRKERNSEC_CONFIG_AUTO
51366 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51367 + help
51368 + If you say Y here, calls to mmap() and mprotect() with explicit
51369 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51370 + denied by the PAX_MPROTECT feature. If the sysctl option is
51371 + enabled, a sysctl option with name "rwxmap_logging" is created.
51372 +
51373 +config GRKERNSEC_AUDIT_TEXTREL
51374 + bool 'ELF text relocations logging (READ HELP)'
51375 + depends on PAX_MPROTECT
51376 + help
51377 + If you say Y here, text relocations will be logged with the filename
51378 + of the offending library or binary. The purpose of the feature is
51379 + to help Linux distribution developers get rid of libraries and
51380 + binaries that need text relocations which hinder the future progress
51381 + of PaX. Only Linux distribution developers should say Y here, and
51382 + never on a production machine, as this option creates an information
51383 + leak that could aid an attacker in defeating the randomization of
51384 + a single memory region. If the sysctl option is enabled, a sysctl
51385 + option with name "audit_textrel" is created.
51386 +
51387 +endmenu
51388 +
51389 +menu "Executable Protections"
51390 +depends on GRKERNSEC
51391 +
51392 +config GRKERNSEC_DMESG
51393 + bool "Dmesg(8) restriction"
51394 + default y if GRKERNSEC_CONFIG_AUTO
51395 + help
51396 + If you say Y here, non-root users will not be able to use dmesg(8)
51397 + to view up to the last 4kb of messages in the kernel's log buffer.
51398 + The kernel's log buffer often contains kernel addresses and other
51399 + identifying information useful to an attacker in fingerprinting a
51400 + system for a targeted exploit.
51401 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51402 + created.
51403 +
51404 +config GRKERNSEC_HARDEN_PTRACE
51405 + bool "Deter ptrace-based process snooping"
51406 + default y if GRKERNSEC_CONFIG_AUTO
51407 + help
51408 + If you say Y here, TTY sniffers and other malicious monitoring
51409 + programs implemented through ptrace will be defeated. If you
51410 + have been using the RBAC system, this option has already been
51411 + enabled for several years for all users, with the ability to make
51412 + fine-grained exceptions.
51413 +
51414 + This option only affects the ability of non-root users to ptrace
51415 + processes that are not a descendent of the ptracing process.
51416 + This means that strace ./binary and gdb ./binary will still work,
51417 + but attaching to arbitrary processes will not. If the sysctl
51418 + option is enabled, a sysctl option with name "harden_ptrace" is
51419 + created.
51420 +
51421 +config GRKERNSEC_PTRACE_READEXEC
51422 + bool "Require read access to ptrace sensitive binaries"
51423 + default y if GRKERNSEC_CONFIG_AUTO
51424 + help
51425 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51426 + binaries. This option is useful in environments that
51427 + remove the read bits (e.g. file mode 4711) from suid binaries to
51428 + prevent infoleaking of their contents. This option adds
51429 + consistency to the use of that file mode, as the binary could normally
51430 + be read out when run without privileges while ptracing.
51431 +
51432 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51433 + is created.
51434 +
51435 +config GRKERNSEC_SETXID
51436 + bool "Enforce consistent multithreaded privileges"
51437 + default y if GRKERNSEC_CONFIG_AUTO
51438 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51439 + help
51440 + If you say Y here, a change from a root uid to a non-root uid
51441 + in a multithreaded application will cause the resulting uids,
51442 + gids, supplementary groups, and capabilities in that thread
51443 + to be propagated to the other threads of the process. In most
51444 + cases this is unnecessary, as glibc will emulate this behavior
51445 + on behalf of the application. Other libcs do not act in the
51446 + same way, allowing the other threads of the process to continue
51447 + running with root privileges. If the sysctl option is enabled,
51448 + a sysctl option with name "consistent_setxid" is created.
51449 +
51450 +config GRKERNSEC_TPE
51451 + bool "Trusted Path Execution (TPE)"
51452 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51453 + help
51454 + If you say Y here, you will be able to choose a gid to add to the
51455 + supplementary groups of users you want to mark as "untrusted."
51456 + These users will not be able to execute any files that are not in
51457 + root-owned directories writable only by root. If the sysctl option
51458 + is enabled, a sysctl option with name "tpe" is created.
51459 +
51460 +config GRKERNSEC_TPE_ALL
51461 + bool "Partially restrict all non-root users"
51462 + depends on GRKERNSEC_TPE
51463 + help
51464 + If you say Y here, all non-root users will be covered under
51465 + a weaker TPE restriction. This is separate from, and in addition to,
51466 + the main TPE options that you have selected elsewhere. Thus, if a
51467 + "trusted" GID is chosen, this restriction applies to even that GID.
51468 + Under this restriction, all non-root users will only be allowed to
51469 + execute files in directories they own that are not group or
51470 + world-writable, or in directories owned by root and writable only by
51471 + root. If the sysctl option is enabled, a sysctl option with name
51472 + "tpe_restrict_all" is created.
51473 +
51474 +config GRKERNSEC_TPE_INVERT
51475 + bool "Invert GID option"
51476 + depends on GRKERNSEC_TPE
51477 + help
51478 + If you say Y here, the group you specify in the TPE configuration will
51479 + decide what group TPE restrictions will be *disabled* for. This
51480 + option is useful if you want TPE restrictions to be applied to most
51481 + users on the system. If the sysctl option is enabled, a sysctl option
51482 + with name "tpe_invert" is created. Unlike other sysctl options, this
51483 + entry will default to on for backward-compatibility.
51484 +
51485 +config GRKERNSEC_TPE_GID
51486 + int
51487 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51488 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51489 +
51490 +config GRKERNSEC_TPE_UNTRUSTED_GID
51491 + int "GID for TPE-untrusted users"
51492 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51493 + default 1005
51494 + help
51495 + Setting this GID determines what group TPE restrictions will be
51496 + *enabled* for. If the sysctl option is enabled, a sysctl option
51497 + with name "tpe_gid" is created.
51498 +
51499 +config GRKERNSEC_TPE_TRUSTED_GID
51500 + int "GID for TPE-trusted users"
51501 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51502 + default 1005
51503 + help
51504 + Setting this GID determines what group TPE restrictions will be
51505 + *disabled* for. If the sysctl option is enabled, a sysctl option
51506 + with name "tpe_gid" is created.
51507 +
51508 +endmenu
51509 +menu "Network Protections"
51510 +depends on GRKERNSEC
51511 +
51512 +config GRKERNSEC_RANDNET
51513 + bool "Larger entropy pools"
51514 + default y if GRKERNSEC_CONFIG_AUTO
51515 + help
51516 + If you say Y here, the entropy pools used for many features of Linux
51517 + and grsecurity will be doubled in size. Since several grsecurity
51518 + features use additional randomness, it is recommended that you say Y
51519 + here. Saying Y here has a similar effect as modifying
51520 + /proc/sys/kernel/random/poolsize.
51521 +
51522 +config GRKERNSEC_BLACKHOLE
51523 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51524 + default y if GRKERNSEC_CONFIG_AUTO
51525 + depends on NET
51526 + help
51527 + If you say Y here, neither TCP resets nor ICMP
51528 + destination-unreachable packets will be sent in response to packets
51529 + sent to ports for which no associated listening process exists.
51530 + This feature supports both IPV4 and IPV6 and exempts the
51531 + loopback interface from blackholing. Enabling this feature
51532 + makes a host more resilient to DoS attacks and reduces network
51533 + visibility against scanners.
51534 +
51535 + The blackhole feature as-implemented is equivalent to the FreeBSD
51536 + blackhole feature, as it prevents RST responses to all packets, not
51537 + just SYNs. Under most application behavior this causes no
51538 + problems, but applications (like haproxy) may not close certain
51539 + connections in a way that cleanly terminates them on the remote
51540 + end, leaving the remote host in LAST_ACK state. Because of this
51541 + side-effect and to prevent intentional LAST_ACK DoSes, this
51542 + feature also adds automatic mitigation against such attacks.
51543 + The mitigation drastically reduces the amount of time a socket
51544 + can spend in LAST_ACK state. If you're using haproxy and not
51545 + all servers it connects to have this option enabled, consider
51546 + disabling this feature on the haproxy host.
51547 +
51548 + If the sysctl option is enabled, two sysctl options with names
51549 + "ip_blackhole" and "lastack_retries" will be created.
51550 + While "ip_blackhole" takes the standard zero/non-zero on/off
51551 + toggle, "lastack_retries" uses the same kinds of values as
51552 + "tcp_retries1" and "tcp_retries2". The default value of 4
51553 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51554 + state.
51555 +
51556 +config GRKERNSEC_SOCKET
51557 + bool "Socket restrictions"
51558 + depends on NET
51559 + help
51560 + If you say Y here, you will be able to choose from several options.
51561 + If you assign a GID on your system and add it to the supplementary
51562 + groups of users you want to restrict socket access to, this patch
51563 + will perform up to three things, based on the option(s) you choose.
51564 +
51565 +config GRKERNSEC_SOCKET_ALL
51566 + bool "Deny any sockets to group"
51567 + depends on GRKERNSEC_SOCKET
51568 + help
51569 + If you say Y here, you will be able to choose a GID of whose users will
51570 + be unable to connect to other hosts from your machine or run server
51571 + applications from your machine. If the sysctl option is enabled, a
51572 + sysctl option with name "socket_all" is created.
51573 +
51574 +config GRKERNSEC_SOCKET_ALL_GID
51575 + int "GID to deny all sockets for"
51576 + depends on GRKERNSEC_SOCKET_ALL
51577 + default 1004
51578 + help
51579 + Here you can choose the GID to disable socket access for. Remember to
51580 + add the users you want socket access disabled for to the GID
51581 + specified here. If the sysctl option is enabled, a sysctl option
51582 + with name "socket_all_gid" is created.
51583 +
51584 +config GRKERNSEC_SOCKET_CLIENT
51585 + bool "Deny client sockets to group"
51586 + depends on GRKERNSEC_SOCKET
51587 + help
51588 + If you say Y here, you will be able to choose a GID of whose users will
51589 + be unable to connect to other hosts from your machine, but will be
51590 + able to run servers. If this option is enabled, all users in the group
51591 + you specify will have to use passive mode when initiating ftp transfers
51592 + from the shell on your machine. If the sysctl option is enabled, a
51593 + sysctl option with name "socket_client" is created.
51594 +
51595 +config GRKERNSEC_SOCKET_CLIENT_GID
51596 + int "GID to deny client sockets for"
51597 + depends on GRKERNSEC_SOCKET_CLIENT
51598 + default 1003
51599 + help
51600 + Here you can choose the GID to disable client socket access for.
51601 + Remember to add the users you want client socket access disabled for to
51602 + the GID specified here. If the sysctl option is enabled, a sysctl
51603 + option with name "socket_client_gid" is created.
51604 +
51605 +config GRKERNSEC_SOCKET_SERVER
51606 + bool "Deny server sockets to group"
51607 + depends on GRKERNSEC_SOCKET
51608 + help
51609 + If you say Y here, you will be able to choose a GID of whose users will
51610 + be unable to run server applications from your machine. If the sysctl
51611 + option is enabled, a sysctl option with name "socket_server" is created.
51612 +
51613 +config GRKERNSEC_SOCKET_SERVER_GID
51614 + int "GID to deny server sockets for"
51615 + depends on GRKERNSEC_SOCKET_SERVER
51616 + default 1002
51617 + help
51618 + Here you can choose the GID to disable server socket access for.
51619 + Remember to add the users you want server socket access disabled for to
51620 + the GID specified here. If the sysctl option is enabled, a sysctl
51621 + option with name "socket_server_gid" is created.
51622 +
51623 +endmenu
51624 +menu "Sysctl Support"
51625 +depends on GRKERNSEC && SYSCTL
51626 +
51627 +config GRKERNSEC_SYSCTL
51628 + bool "Sysctl support"
51629 + default y if GRKERNSEC_CONFIG_AUTO
51630 + help
51631 + If you say Y here, you will be able to change the options that
51632 + grsecurity runs with at bootup, without having to recompile your
51633 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51634 + to enable (1) or disable (0) various features. All the sysctl entries
51635 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51636 + All features enabled in the kernel configuration are disabled at boot
51637 + if you do not say Y to the "Turn on features by default" option.
51638 + All options should be set at startup, and the grsec_lock entry should
51639 + be set to a non-zero value after all the options are set.
51640 + *THIS IS EXTREMELY IMPORTANT*
51641 +
51642 +config GRKERNSEC_SYSCTL_DISTRO
51643 + bool "Extra sysctl support for distro makers (READ HELP)"
51644 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51645 + help
51646 + If you say Y here, additional sysctl options will be created
51647 + for features that affect processes running as root. Therefore,
51648 + it is critical when using this option that the grsec_lock entry be
51649 + enabled after boot. Only distros with prebuilt kernel packages
51650 + with this option enabled that can ensure grsec_lock is enabled
51651 + after boot should use this option.
51652 + *Failure to set grsec_lock after boot makes all grsec features
51653 + this option covers useless*
51654 +
51655 + Currently this option creates the following sysctl entries:
51656 + "Disable Privileged I/O": "disable_priv_io"
51657 +
51658 +config GRKERNSEC_SYSCTL_ON
51659 + bool "Turn on features by default"
51660 + default y if GRKERNSEC_CONFIG_AUTO
51661 + depends on GRKERNSEC_SYSCTL
51662 + help
51663 + If you say Y here, instead of having all features enabled in the
51664 + kernel configuration disabled at boot time, the features will be
51665 + enabled at boot time. It is recommended you say Y here unless
51666 + there is some reason you would want all sysctl-tunable features to
51667 + be disabled by default. As mentioned elsewhere, it is important
51668 + to enable the grsec_lock entry once you have finished modifying
51669 + the sysctl entries.
51670 +
51671 +endmenu
51672 +menu "Logging Options"
51673 +depends on GRKERNSEC
51674 +
51675 +config GRKERNSEC_FLOODTIME
51676 + int "Seconds in between log messages (minimum)"
51677 + default 10
51678 + help
51679 + This option allows you to enforce the number of seconds between
51680 + grsecurity log messages. The default should be suitable for most
51681 + people, however, if you choose to change it, choose a value small enough
51682 + to allow informative logs to be produced, but large enough to
51683 + prevent flooding.
51684 +
51685 +config GRKERNSEC_FLOODBURST
51686 + int "Number of messages in a burst (maximum)"
51687 + default 6
51688 + help
51689 + This option allows you to choose the maximum number of messages allowed
51690 + within the flood time interval you chose in a separate option. The
51691 + default should be suitable for most people, however if you find that
51692 + many of your logs are being interpreted as flooding, you may want to
51693 + raise this value.
51694 +
51695 +endmenu
51696 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51697 new file mode 100644
51698 index 0000000..1b9afa9
51699 --- /dev/null
51700 +++ b/grsecurity/Makefile
51701 @@ -0,0 +1,38 @@
51702 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51703 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51704 +# into an RBAC system
51705 +#
51706 +# All code in this directory and various hooks inserted throughout the kernel
51707 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51708 +# under the GPL v2 or higher
51709 +
51710 +KBUILD_CFLAGS += -Werror
51711 +
51712 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51713 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51714 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51715 +
51716 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51717 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51718 + gracl_learn.o grsec_log.o
51719 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51720 +
51721 +ifdef CONFIG_NET
51722 +obj-y += grsec_sock.o
51723 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51724 +endif
51725 +
51726 +ifndef CONFIG_GRKERNSEC
51727 +obj-y += grsec_disabled.o
51728 +endif
51729 +
51730 +ifdef CONFIG_GRKERNSEC_HIDESYM
51731 +extra-y := grsec_hidesym.o
51732 +$(obj)/grsec_hidesym.o:
51733 + @-chmod -f 500 /boot
51734 + @-chmod -f 500 /lib/modules
51735 + @-chmod -f 500 /lib64/modules
51736 + @-chmod -f 500 /lib32/modules
51737 + @-chmod -f 700 .
51738 + @echo ' grsec: protected kernel image paths'
51739 +endif
51740 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51741 new file mode 100644
51742 index 0000000..3d58260
51743 --- /dev/null
51744 +++ b/grsecurity/gracl.c
51745 @@ -0,0 +1,4029 @@
51746 +#include <linux/kernel.h>
51747 +#include <linux/module.h>
51748 +#include <linux/sched.h>
51749 +#include <linux/mm.h>
51750 +#include <linux/file.h>
51751 +#include <linux/fs.h>
51752 +#include <linux/namei.h>
51753 +#include <linux/mount.h>
51754 +#include <linux/tty.h>
51755 +#include <linux/proc_fs.h>
51756 +#include <linux/lglock.h>
51757 +#include <linux/slab.h>
51758 +#include <linux/vmalloc.h>
51759 +#include <linux/types.h>
51760 +#include <linux/sysctl.h>
51761 +#include <linux/netdevice.h>
51762 +#include <linux/ptrace.h>
51763 +#include <linux/gracl.h>
51764 +#include <linux/gralloc.h>
51765 +#include <linux/security.h>
51766 +#include <linux/grinternal.h>
51767 +#include <linux/pid_namespace.h>
51768 +#include <linux/stop_machine.h>
51769 +#include <linux/fdtable.h>
51770 +#include <linux/percpu.h>
51771 +#include <linux/lglock.h>
51772 +#include "../fs/mount.h"
51773 +
51774 +#include <asm/uaccess.h>
51775 +#include <asm/errno.h>
51776 +#include <asm/mman.h>
51777 +
51778 +extern struct lglock vfsmount_lock;
51779 +
51780 +static struct acl_role_db acl_role_set;
51781 +static struct name_db name_set;
51782 +static struct inodev_db inodev_set;
51783 +
51784 +/* for keeping track of userspace pointers used for subjects, so we
51785 + can share references in the kernel as well
51786 +*/
51787 +
51788 +static struct path real_root;
51789 +
51790 +static struct acl_subj_map_db subj_map_set;
51791 +
51792 +static struct acl_role_label *default_role;
51793 +
51794 +static struct acl_role_label *role_list;
51795 +
51796 +static u16 acl_sp_role_value;
51797 +
51798 +extern char *gr_shared_page[4];
51799 +static DEFINE_MUTEX(gr_dev_mutex);
51800 +DEFINE_RWLOCK(gr_inode_lock);
51801 +
51802 +struct gr_arg *gr_usermode;
51803 +
51804 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51805 +
51806 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51807 +extern void gr_clear_learn_entries(void);
51808 +
51809 +#ifdef CONFIG_GRKERNSEC_RESLOG
51810 +extern void gr_log_resource(const struct task_struct *task,
51811 + const int res, const unsigned long wanted, const int gt);
51812 +#endif
51813 +
51814 +unsigned char *gr_system_salt;
51815 +unsigned char *gr_system_sum;
51816 +
51817 +static struct sprole_pw **acl_special_roles = NULL;
51818 +static __u16 num_sprole_pws = 0;
51819 +
51820 +static struct acl_role_label *kernel_role = NULL;
51821 +
51822 +static unsigned int gr_auth_attempts = 0;
51823 +static unsigned long gr_auth_expires = 0UL;
51824 +
51825 +#ifdef CONFIG_NET
51826 +extern struct vfsmount *sock_mnt;
51827 +#endif
51828 +
51829 +extern struct vfsmount *pipe_mnt;
51830 +extern struct vfsmount *shm_mnt;
51831 +#ifdef CONFIG_HUGETLBFS
51832 +extern struct vfsmount *hugetlbfs_vfsmount;
51833 +#endif
51834 +
51835 +static struct acl_object_label *fakefs_obj_rw;
51836 +static struct acl_object_label *fakefs_obj_rwx;
51837 +
51838 +extern int gr_init_uidset(void);
51839 +extern void gr_free_uidset(void);
51840 +extern void gr_remove_uid(uid_t uid);
51841 +extern int gr_find_uid(uid_t uid);
51842 +
51843 +__inline__ int
51844 +gr_acl_is_enabled(void)
51845 +{
51846 + return (gr_status & GR_READY);
51847 +}
51848 +
51849 +#ifdef CONFIG_BTRFS_FS
51850 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51851 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51852 +#endif
51853 +
51854 +static inline dev_t __get_dev(const struct dentry *dentry)
51855 +{
51856 +#ifdef CONFIG_BTRFS_FS
51857 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51858 + return get_btrfs_dev_from_inode(dentry->d_inode);
51859 + else
51860 +#endif
51861 + return dentry->d_inode->i_sb->s_dev;
51862 +}
51863 +
51864 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51865 +{
51866 + return __get_dev(dentry);
51867 +}
51868 +
51869 +static char gr_task_roletype_to_char(struct task_struct *task)
51870 +{
51871 + switch (task->role->roletype &
51872 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51873 + GR_ROLE_SPECIAL)) {
51874 + case GR_ROLE_DEFAULT:
51875 + return 'D';
51876 + case GR_ROLE_USER:
51877 + return 'U';
51878 + case GR_ROLE_GROUP:
51879 + return 'G';
51880 + case GR_ROLE_SPECIAL:
51881 + return 'S';
51882 + }
51883 +
51884 + return 'X';
51885 +}
51886 +
51887 +char gr_roletype_to_char(void)
51888 +{
51889 + return gr_task_roletype_to_char(current);
51890 +}
51891 +
51892 +__inline__ int
51893 +gr_acl_tpe_check(void)
51894 +{
51895 + if (unlikely(!(gr_status & GR_READY)))
51896 + return 0;
51897 + if (current->role->roletype & GR_ROLE_TPE)
51898 + return 1;
51899 + else
51900 + return 0;
51901 +}
51902 +
51903 +int
51904 +gr_handle_rawio(const struct inode *inode)
51905 +{
51906 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51907 + if (inode && S_ISBLK(inode->i_mode) &&
51908 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51909 + !capable(CAP_SYS_RAWIO))
51910 + return 1;
51911 +#endif
51912 + return 0;
51913 +}
51914 +
51915 +static int
51916 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51917 +{
51918 + if (likely(lena != lenb))
51919 + return 0;
51920 +
51921 + return !memcmp(a, b, lena);
51922 +}
51923 +
51924 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51925 +{
51926 + *buflen -= namelen;
51927 + if (*buflen < 0)
51928 + return -ENAMETOOLONG;
51929 + *buffer -= namelen;
51930 + memcpy(*buffer, str, namelen);
51931 + return 0;
51932 +}
51933 +
51934 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51935 +{
51936 + return prepend(buffer, buflen, name->name, name->len);
51937 +}
51938 +
51939 +static int prepend_path(const struct path *path, struct path *root,
51940 + char **buffer, int *buflen)
51941 +{
51942 + struct dentry *dentry = path->dentry;
51943 + struct vfsmount *vfsmnt = path->mnt;
51944 + struct mount *mnt = real_mount(vfsmnt);
51945 + bool slash = false;
51946 + int error = 0;
51947 +
51948 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51949 + struct dentry * parent;
51950 +
51951 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51952 + /* Global root? */
51953 + if (!mnt_has_parent(mnt)) {
51954 + goto out;
51955 + }
51956 + dentry = mnt->mnt_mountpoint;
51957 + mnt = mnt->mnt_parent;
51958 + vfsmnt = &mnt->mnt;
51959 + continue;
51960 + }
51961 + parent = dentry->d_parent;
51962 + prefetch(parent);
51963 + spin_lock(&dentry->d_lock);
51964 + error = prepend_name(buffer, buflen, &dentry->d_name);
51965 + spin_unlock(&dentry->d_lock);
51966 + if (!error)
51967 + error = prepend(buffer, buflen, "/", 1);
51968 + if (error)
51969 + break;
51970 +
51971 + slash = true;
51972 + dentry = parent;
51973 + }
51974 +
51975 +out:
51976 + if (!error && !slash)
51977 + error = prepend(buffer, buflen, "/", 1);
51978 +
51979 + return error;
51980 +}
51981 +
51982 +/* this must be called with vfsmount_lock and rename_lock held */
51983 +
51984 +static char *__our_d_path(const struct path *path, struct path *root,
51985 + char *buf, int buflen)
51986 +{
51987 + char *res = buf + buflen;
51988 + int error;
51989 +
51990 + prepend(&res, &buflen, "\0", 1);
51991 + error = prepend_path(path, root, &res, &buflen);
51992 + if (error)
51993 + return ERR_PTR(error);
51994 +
51995 + return res;
51996 +}
51997 +
51998 +static char *
51999 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
52000 +{
52001 + char *retval;
52002 +
52003 + retval = __our_d_path(path, root, buf, buflen);
52004 + if (unlikely(IS_ERR(retval)))
52005 + retval = strcpy(buf, "<path too long>");
52006 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
52007 + retval[1] = '\0';
52008 +
52009 + return retval;
52010 +}
52011 +
52012 +static char *
52013 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52014 + char *buf, int buflen)
52015 +{
52016 + struct path path;
52017 + char *res;
52018 +
52019 + path.dentry = (struct dentry *)dentry;
52020 + path.mnt = (struct vfsmount *)vfsmnt;
52021 +
52022 + /* we can use real_root.dentry, real_root.mnt, because this is only called
52023 + by the RBAC system */
52024 + res = gen_full_path(&path, &real_root, buf, buflen);
52025 +
52026 + return res;
52027 +}
52028 +
52029 +static char *
52030 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
52031 + char *buf, int buflen)
52032 +{
52033 + char *res;
52034 + struct path path;
52035 + struct path root;
52036 + struct task_struct *reaper = init_pid_ns.child_reaper;
52037 +
52038 + path.dentry = (struct dentry *)dentry;
52039 + path.mnt = (struct vfsmount *)vfsmnt;
52040 +
52041 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
52042 + get_fs_root(reaper->fs, &root);
52043 +
52044 + write_seqlock(&rename_lock);
52045 + br_read_lock(&vfsmount_lock);
52046 + res = gen_full_path(&path, &root, buf, buflen);
52047 + br_read_unlock(&vfsmount_lock);
52048 + write_sequnlock(&rename_lock);
52049 +
52050 + path_put(&root);
52051 + return res;
52052 +}
52053 +
52054 +static char *
52055 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52056 +{
52057 + char *ret;
52058 + write_seqlock(&rename_lock);
52059 + br_read_lock(&vfsmount_lock);
52060 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52061 + PAGE_SIZE);
52062 + br_read_unlock(&vfsmount_lock);
52063 + write_sequnlock(&rename_lock);
52064 + return ret;
52065 +}
52066 +
52067 +static char *
52068 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52069 +{
52070 + char *ret;
52071 + char *buf;
52072 + int buflen;
52073 +
52074 + write_seqlock(&rename_lock);
52075 + br_read_lock(&vfsmount_lock);
52076 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52077 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52078 + buflen = (int)(ret - buf);
52079 + if (buflen >= 5)
52080 + prepend(&ret, &buflen, "/proc", 5);
52081 + else
52082 + ret = strcpy(buf, "<path too long>");
52083 + br_read_unlock(&vfsmount_lock);
52084 + write_sequnlock(&rename_lock);
52085 + return ret;
52086 +}
52087 +
52088 +char *
52089 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52090 +{
52091 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52092 + PAGE_SIZE);
52093 +}
52094 +
52095 +char *
52096 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52097 +{
52098 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52099 + PAGE_SIZE);
52100 +}
52101 +
52102 +char *
52103 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52104 +{
52105 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52106 + PAGE_SIZE);
52107 +}
52108 +
52109 +char *
52110 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52111 +{
52112 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52113 + PAGE_SIZE);
52114 +}
52115 +
52116 +char *
52117 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52118 +{
52119 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52120 + PAGE_SIZE);
52121 +}
52122 +
52123 +__inline__ __u32
52124 +to_gr_audit(const __u32 reqmode)
52125 +{
52126 + /* masks off auditable permission flags, then shifts them to create
52127 + auditing flags, and adds the special case of append auditing if
52128 + we're requesting write */
52129 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52130 +}
52131 +
52132 +struct acl_subject_label *
52133 +lookup_subject_map(const struct acl_subject_label *userp)
52134 +{
52135 + unsigned int index = shash(userp, subj_map_set.s_size);
52136 + struct subject_map *match;
52137 +
52138 + match = subj_map_set.s_hash[index];
52139 +
52140 + while (match && match->user != userp)
52141 + match = match->next;
52142 +
52143 + if (match != NULL)
52144 + return match->kernel;
52145 + else
52146 + return NULL;
52147 +}
52148 +
52149 +static void
52150 +insert_subj_map_entry(struct subject_map *subjmap)
52151 +{
52152 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52153 + struct subject_map **curr;
52154 +
52155 + subjmap->prev = NULL;
52156 +
52157 + curr = &subj_map_set.s_hash[index];
52158 + if (*curr != NULL)
52159 + (*curr)->prev = subjmap;
52160 +
52161 + subjmap->next = *curr;
52162 + *curr = subjmap;
52163 +
52164 + return;
52165 +}
52166 +
52167 +static struct acl_role_label *
52168 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52169 + const gid_t gid)
52170 +{
52171 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52172 + struct acl_role_label *match;
52173 + struct role_allowed_ip *ipp;
52174 + unsigned int x;
52175 + u32 curr_ip = task->signal->curr_ip;
52176 +
52177 + task->signal->saved_ip = curr_ip;
52178 +
52179 + match = acl_role_set.r_hash[index];
52180 +
52181 + while (match) {
52182 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52183 + for (x = 0; x < match->domain_child_num; x++) {
52184 + if (match->domain_children[x] == uid)
52185 + goto found;
52186 + }
52187 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52188 + break;
52189 + match = match->next;
52190 + }
52191 +found:
52192 + if (match == NULL) {
52193 + try_group:
52194 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52195 + match = acl_role_set.r_hash[index];
52196 +
52197 + while (match) {
52198 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52199 + for (x = 0; x < match->domain_child_num; x++) {
52200 + if (match->domain_children[x] == gid)
52201 + goto found2;
52202 + }
52203 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52204 + break;
52205 + match = match->next;
52206 + }
52207 +found2:
52208 + if (match == NULL)
52209 + match = default_role;
52210 + if (match->allowed_ips == NULL)
52211 + return match;
52212 + else {
52213 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52214 + if (likely
52215 + ((ntohl(curr_ip) & ipp->netmask) ==
52216 + (ntohl(ipp->addr) & ipp->netmask)))
52217 + return match;
52218 + }
52219 + match = default_role;
52220 + }
52221 + } else if (match->allowed_ips == NULL) {
52222 + return match;
52223 + } else {
52224 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52225 + if (likely
52226 + ((ntohl(curr_ip) & ipp->netmask) ==
52227 + (ntohl(ipp->addr) & ipp->netmask)))
52228 + return match;
52229 + }
52230 + goto try_group;
52231 + }
52232 +
52233 + return match;
52234 +}
52235 +
52236 +struct acl_subject_label *
52237 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52238 + const struct acl_role_label *role)
52239 +{
52240 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52241 + struct acl_subject_label *match;
52242 +
52243 + match = role->subj_hash[index];
52244 +
52245 + while (match && (match->inode != ino || match->device != dev ||
52246 + (match->mode & GR_DELETED))) {
52247 + match = match->next;
52248 + }
52249 +
52250 + if (match && !(match->mode & GR_DELETED))
52251 + return match;
52252 + else
52253 + return NULL;
52254 +}
52255 +
52256 +struct acl_subject_label *
52257 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52258 + const struct acl_role_label *role)
52259 +{
52260 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52261 + struct acl_subject_label *match;
52262 +
52263 + match = role->subj_hash[index];
52264 +
52265 + while (match && (match->inode != ino || match->device != dev ||
52266 + !(match->mode & GR_DELETED))) {
52267 + match = match->next;
52268 + }
52269 +
52270 + if (match && (match->mode & GR_DELETED))
52271 + return match;
52272 + else
52273 + return NULL;
52274 +}
52275 +
52276 +static struct acl_object_label *
52277 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52278 + const struct acl_subject_label *subj)
52279 +{
52280 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52281 + struct acl_object_label *match;
52282 +
52283 + match = subj->obj_hash[index];
52284 +
52285 + while (match && (match->inode != ino || match->device != dev ||
52286 + (match->mode & GR_DELETED))) {
52287 + match = match->next;
52288 + }
52289 +
52290 + if (match && !(match->mode & GR_DELETED))
52291 + return match;
52292 + else
52293 + return NULL;
52294 +}
52295 +
52296 +static struct acl_object_label *
52297 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52298 + const struct acl_subject_label *subj)
52299 +{
52300 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52301 + struct acl_object_label *match;
52302 +
52303 + match = subj->obj_hash[index];
52304 +
52305 + while (match && (match->inode != ino || match->device != dev ||
52306 + !(match->mode & GR_DELETED))) {
52307 + match = match->next;
52308 + }
52309 +
52310 + if (match && (match->mode & GR_DELETED))
52311 + return match;
52312 +
52313 + match = subj->obj_hash[index];
52314 +
52315 + while (match && (match->inode != ino || match->device != dev ||
52316 + (match->mode & GR_DELETED))) {
52317 + match = match->next;
52318 + }
52319 +
52320 + if (match && !(match->mode & GR_DELETED))
52321 + return match;
52322 + else
52323 + return NULL;
52324 +}
52325 +
52326 +static struct name_entry *
52327 +lookup_name_entry(const char *name)
52328 +{
52329 + unsigned int len = strlen(name);
52330 + unsigned int key = full_name_hash(name, len);
52331 + unsigned int index = key % name_set.n_size;
52332 + struct name_entry *match;
52333 +
52334 + match = name_set.n_hash[index];
52335 +
52336 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52337 + match = match->next;
52338 +
52339 + return match;
52340 +}
52341 +
52342 +static struct name_entry *
52343 +lookup_name_entry_create(const char *name)
52344 +{
52345 + unsigned int len = strlen(name);
52346 + unsigned int key = full_name_hash(name, len);
52347 + unsigned int index = key % name_set.n_size;
52348 + struct name_entry *match;
52349 +
52350 + match = name_set.n_hash[index];
52351 +
52352 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52353 + !match->deleted))
52354 + match = match->next;
52355 +
52356 + if (match && match->deleted)
52357 + return match;
52358 +
52359 + match = name_set.n_hash[index];
52360 +
52361 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52362 + match->deleted))
52363 + match = match->next;
52364 +
52365 + if (match && !match->deleted)
52366 + return match;
52367 + else
52368 + return NULL;
52369 +}
52370 +
52371 +static struct inodev_entry *
52372 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52373 +{
52374 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52375 + struct inodev_entry *match;
52376 +
52377 + match = inodev_set.i_hash[index];
52378 +
52379 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52380 + match = match->next;
52381 +
52382 + return match;
52383 +}
52384 +
52385 +static void
52386 +insert_inodev_entry(struct inodev_entry *entry)
52387 +{
52388 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52389 + inodev_set.i_size);
52390 + struct inodev_entry **curr;
52391 +
52392 + entry->prev = NULL;
52393 +
52394 + curr = &inodev_set.i_hash[index];
52395 + if (*curr != NULL)
52396 + (*curr)->prev = entry;
52397 +
52398 + entry->next = *curr;
52399 + *curr = entry;
52400 +
52401 + return;
52402 +}
52403 +
52404 +static void
52405 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52406 +{
52407 + unsigned int index =
52408 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52409 + struct acl_role_label **curr;
52410 + struct acl_role_label *tmp, *tmp2;
52411 +
52412 + curr = &acl_role_set.r_hash[index];
52413 +
52414 + /* simple case, slot is empty, just set it to our role */
52415 + if (*curr == NULL) {
52416 + *curr = role;
52417 + } else {
52418 + /* example:
52419 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52420 + 2 -> 3
52421 + */
52422 + /* first check to see if we can already be reached via this slot */
52423 + tmp = *curr;
52424 + while (tmp && tmp != role)
52425 + tmp = tmp->next;
52426 + if (tmp == role) {
52427 + /* we don't need to add ourselves to this slot's chain */
52428 + return;
52429 + }
52430 + /* we need to add ourselves to this chain, two cases */
52431 + if (role->next == NULL) {
52432 + /* simple case, append the current chain to our role */
52433 + role->next = *curr;
52434 + *curr = role;
52435 + } else {
52436 + /* 1 -> 2 -> 3 -> 4
52437 + 2 -> 3 -> 4
52438 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52439 + */
52440 + /* trickier case: walk our role's chain until we find
52441 + the role for the start of the current slot's chain */
52442 + tmp = role;
52443 + tmp2 = *curr;
52444 + while (tmp->next && tmp->next != tmp2)
52445 + tmp = tmp->next;
52446 + if (tmp->next == tmp2) {
52447 + /* from example above, we found 3, so just
52448 + replace this slot's chain with ours */
52449 + *curr = role;
52450 + } else {
52451 + /* we didn't find a subset of our role's chain
52452 + in the current slot's chain, so append their
52453 + chain to ours, and set us as the first role in
52454 + the slot's chain
52455 +
52456 + we could fold this case with the case above,
52457 + but making it explicit for clarity
52458 + */
52459 + tmp->next = tmp2;
52460 + *curr = role;
52461 + }
52462 + }
52463 + }
52464 +
52465 + return;
52466 +}
52467 +
52468 +static void
52469 +insert_acl_role_label(struct acl_role_label *role)
52470 +{
52471 + int i;
52472 +
52473 + if (role_list == NULL) {
52474 + role_list = role;
52475 + role->prev = NULL;
52476 + } else {
52477 + role->prev = role_list;
52478 + role_list = role;
52479 + }
52480 +
52481 + /* used for hash chains */
52482 + role->next = NULL;
52483 +
52484 + if (role->roletype & GR_ROLE_DOMAIN) {
52485 + for (i = 0; i < role->domain_child_num; i++)
52486 + __insert_acl_role_label(role, role->domain_children[i]);
52487 + } else
52488 + __insert_acl_role_label(role, role->uidgid);
52489 +}
52490 +
52491 +static int
52492 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52493 +{
52494 + struct name_entry **curr, *nentry;
52495 + struct inodev_entry *ientry;
52496 + unsigned int len = strlen(name);
52497 + unsigned int key = full_name_hash(name, len);
52498 + unsigned int index = key % name_set.n_size;
52499 +
52500 + curr = &name_set.n_hash[index];
52501 +
52502 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52503 + curr = &((*curr)->next);
52504 +
52505 + if (*curr != NULL)
52506 + return 1;
52507 +
52508 + nentry = acl_alloc(sizeof (struct name_entry));
52509 + if (nentry == NULL)
52510 + return 0;
52511 + ientry = acl_alloc(sizeof (struct inodev_entry));
52512 + if (ientry == NULL)
52513 + return 0;
52514 + ientry->nentry = nentry;
52515 +
52516 + nentry->key = key;
52517 + nentry->name = name;
52518 + nentry->inode = inode;
52519 + nentry->device = device;
52520 + nentry->len = len;
52521 + nentry->deleted = deleted;
52522 +
52523 + nentry->prev = NULL;
52524 + curr = &name_set.n_hash[index];
52525 + if (*curr != NULL)
52526 + (*curr)->prev = nentry;
52527 + nentry->next = *curr;
52528 + *curr = nentry;
52529 +
52530 + /* insert us into the table searchable by inode/dev */
52531 + insert_inodev_entry(ientry);
52532 +
52533 + return 1;
52534 +}
52535 +
52536 +static void
52537 +insert_acl_obj_label(struct acl_object_label *obj,
52538 + struct acl_subject_label *subj)
52539 +{
52540 + unsigned int index =
52541 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52542 + struct acl_object_label **curr;
52543 +
52544 +
52545 + obj->prev = NULL;
52546 +
52547 + curr = &subj->obj_hash[index];
52548 + if (*curr != NULL)
52549 + (*curr)->prev = obj;
52550 +
52551 + obj->next = *curr;
52552 + *curr = obj;
52553 +
52554 + return;
52555 +}
52556 +
52557 +static void
52558 +insert_acl_subj_label(struct acl_subject_label *obj,
52559 + struct acl_role_label *role)
52560 +{
52561 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52562 + struct acl_subject_label **curr;
52563 +
52564 + obj->prev = NULL;
52565 +
52566 + curr = &role->subj_hash[index];
52567 + if (*curr != NULL)
52568 + (*curr)->prev = obj;
52569 +
52570 + obj->next = *curr;
52571 + *curr = obj;
52572 +
52573 + return;
52574 +}
52575 +
52576 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52577 +
52578 +static void *
52579 +create_table(__u32 * len, int elementsize)
52580 +{
52581 + unsigned int table_sizes[] = {
52582 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52583 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52584 + 4194301, 8388593, 16777213, 33554393, 67108859
52585 + };
52586 + void *newtable = NULL;
52587 + unsigned int pwr = 0;
52588 +
52589 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52590 + table_sizes[pwr] <= *len)
52591 + pwr++;
52592 +
52593 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52594 + return newtable;
52595 +
52596 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52597 + newtable =
52598 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52599 + else
52600 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52601 +
52602 + *len = table_sizes[pwr];
52603 +
52604 + return newtable;
52605 +}
52606 +
52607 +static int
52608 +init_variables(const struct gr_arg *arg)
52609 +{
52610 + struct task_struct *reaper = init_pid_ns.child_reaper;
52611 + unsigned int stacksize;
52612 +
52613 + subj_map_set.s_size = arg->role_db.num_subjects;
52614 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52615 + name_set.n_size = arg->role_db.num_objects;
52616 + inodev_set.i_size = arg->role_db.num_objects;
52617 +
52618 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52619 + !name_set.n_size || !inodev_set.i_size)
52620 + return 1;
52621 +
52622 + if (!gr_init_uidset())
52623 + return 1;
52624 +
52625 + /* set up the stack that holds allocation info */
52626 +
52627 + stacksize = arg->role_db.num_pointers + 5;
52628 +
52629 + if (!acl_alloc_stack_init(stacksize))
52630 + return 1;
52631 +
52632 + /* grab reference for the real root dentry and vfsmount */
52633 + get_fs_root(reaper->fs, &real_root);
52634 +
52635 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52636 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52637 +#endif
52638 +
52639 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52640 + if (fakefs_obj_rw == NULL)
52641 + return 1;
52642 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52643 +
52644 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52645 + if (fakefs_obj_rwx == NULL)
52646 + return 1;
52647 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52648 +
52649 + subj_map_set.s_hash =
52650 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52651 + acl_role_set.r_hash =
52652 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52653 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52654 + inodev_set.i_hash =
52655 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52656 +
52657 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52658 + !name_set.n_hash || !inodev_set.i_hash)
52659 + return 1;
52660 +
52661 + memset(subj_map_set.s_hash, 0,
52662 + sizeof(struct subject_map *) * subj_map_set.s_size);
52663 + memset(acl_role_set.r_hash, 0,
52664 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52665 + memset(name_set.n_hash, 0,
52666 + sizeof (struct name_entry *) * name_set.n_size);
52667 + memset(inodev_set.i_hash, 0,
52668 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52669 +
52670 + return 0;
52671 +}
52672 +
52673 +/* free information not needed after startup
52674 + currently contains user->kernel pointer mappings for subjects
52675 +*/
52676 +
52677 +static void
52678 +free_init_variables(void)
52679 +{
52680 + __u32 i;
52681 +
52682 + if (subj_map_set.s_hash) {
52683 + for (i = 0; i < subj_map_set.s_size; i++) {
52684 + if (subj_map_set.s_hash[i]) {
52685 + kfree(subj_map_set.s_hash[i]);
52686 + subj_map_set.s_hash[i] = NULL;
52687 + }
52688 + }
52689 +
52690 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52691 + PAGE_SIZE)
52692 + kfree(subj_map_set.s_hash);
52693 + else
52694 + vfree(subj_map_set.s_hash);
52695 + }
52696 +
52697 + return;
52698 +}
52699 +
52700 +static void
52701 +free_variables(void)
52702 +{
52703 + struct acl_subject_label *s;
52704 + struct acl_role_label *r;
52705 + struct task_struct *task, *task2;
52706 + unsigned int x;
52707 +
52708 + gr_clear_learn_entries();
52709 +
52710 + read_lock(&tasklist_lock);
52711 + do_each_thread(task2, task) {
52712 + task->acl_sp_role = 0;
52713 + task->acl_role_id = 0;
52714 + task->acl = NULL;
52715 + task->role = NULL;
52716 + } while_each_thread(task2, task);
52717 + read_unlock(&tasklist_lock);
52718 +
52719 + /* release the reference to the real root dentry and vfsmount */
52720 + path_put(&real_root);
52721 + memset(&real_root, 0, sizeof(real_root));
52722 +
52723 + /* free all object hash tables */
52724 +
52725 + FOR_EACH_ROLE_START(r)
52726 + if (r->subj_hash == NULL)
52727 + goto next_role;
52728 + FOR_EACH_SUBJECT_START(r, s, x)
52729 + if (s->obj_hash == NULL)
52730 + break;
52731 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52732 + kfree(s->obj_hash);
52733 + else
52734 + vfree(s->obj_hash);
52735 + FOR_EACH_SUBJECT_END(s, x)
52736 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52737 + if (s->obj_hash == NULL)
52738 + break;
52739 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52740 + kfree(s->obj_hash);
52741 + else
52742 + vfree(s->obj_hash);
52743 + FOR_EACH_NESTED_SUBJECT_END(s)
52744 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52745 + kfree(r->subj_hash);
52746 + else
52747 + vfree(r->subj_hash);
52748 + r->subj_hash = NULL;
52749 +next_role:
52750 + FOR_EACH_ROLE_END(r)
52751 +
52752 + acl_free_all();
52753 +
52754 + if (acl_role_set.r_hash) {
52755 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52756 + PAGE_SIZE)
52757 + kfree(acl_role_set.r_hash);
52758 + else
52759 + vfree(acl_role_set.r_hash);
52760 + }
52761 + if (name_set.n_hash) {
52762 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52763 + PAGE_SIZE)
52764 + kfree(name_set.n_hash);
52765 + else
52766 + vfree(name_set.n_hash);
52767 + }
52768 +
52769 + if (inodev_set.i_hash) {
52770 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52771 + PAGE_SIZE)
52772 + kfree(inodev_set.i_hash);
52773 + else
52774 + vfree(inodev_set.i_hash);
52775 + }
52776 +
52777 + gr_free_uidset();
52778 +
52779 + memset(&name_set, 0, sizeof (struct name_db));
52780 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52781 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52782 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52783 +
52784 + default_role = NULL;
52785 + kernel_role = NULL;
52786 + role_list = NULL;
52787 +
52788 + return;
52789 +}
52790 +
52791 +static __u32
52792 +count_user_objs(struct acl_object_label *userp)
52793 +{
52794 + struct acl_object_label o_tmp;
52795 + __u32 num = 0;
52796 +
52797 + while (userp) {
52798 + if (copy_from_user(&o_tmp, userp,
52799 + sizeof (struct acl_object_label)))
52800 + break;
52801 +
52802 + userp = o_tmp.prev;
52803 + num++;
52804 + }
52805 +
52806 + return num;
52807 +}
52808 +
52809 +static struct acl_subject_label *
52810 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52811 +
52812 +static int
52813 +copy_user_glob(struct acl_object_label *obj)
52814 +{
52815 + struct acl_object_label *g_tmp, **guser;
52816 + unsigned int len;
52817 + char *tmp;
52818 +
52819 + if (obj->globbed == NULL)
52820 + return 0;
52821 +
52822 + guser = &obj->globbed;
52823 + while (*guser) {
52824 + g_tmp = (struct acl_object_label *)
52825 + acl_alloc(sizeof (struct acl_object_label));
52826 + if (g_tmp == NULL)
52827 + return -ENOMEM;
52828 +
52829 + if (copy_from_user(g_tmp, *guser,
52830 + sizeof (struct acl_object_label)))
52831 + return -EFAULT;
52832 +
52833 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52834 +
52835 + if (!len || len >= PATH_MAX)
52836 + return -EINVAL;
52837 +
52838 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52839 + return -ENOMEM;
52840 +
52841 + if (copy_from_user(tmp, g_tmp->filename, len))
52842 + return -EFAULT;
52843 + tmp[len-1] = '\0';
52844 + g_tmp->filename = tmp;
52845 +
52846 + *guser = g_tmp;
52847 + guser = &(g_tmp->next);
52848 + }
52849 +
52850 + return 0;
52851 +}
52852 +
52853 +static int
52854 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52855 + struct acl_role_label *role)
52856 +{
52857 + struct acl_object_label *o_tmp;
52858 + unsigned int len;
52859 + int ret;
52860 + char *tmp;
52861 +
52862 + while (userp) {
52863 + if ((o_tmp = (struct acl_object_label *)
52864 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52865 + return -ENOMEM;
52866 +
52867 + if (copy_from_user(o_tmp, userp,
52868 + sizeof (struct acl_object_label)))
52869 + return -EFAULT;
52870 +
52871 + userp = o_tmp->prev;
52872 +
52873 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52874 +
52875 + if (!len || len >= PATH_MAX)
52876 + return -EINVAL;
52877 +
52878 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52879 + return -ENOMEM;
52880 +
52881 + if (copy_from_user(tmp, o_tmp->filename, len))
52882 + return -EFAULT;
52883 + tmp[len-1] = '\0';
52884 + o_tmp->filename = tmp;
52885 +
52886 + insert_acl_obj_label(o_tmp, subj);
52887 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52888 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52889 + return -ENOMEM;
52890 +
52891 + ret = copy_user_glob(o_tmp);
52892 + if (ret)
52893 + return ret;
52894 +
52895 + if (o_tmp->nested) {
52896 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52897 + if (IS_ERR(o_tmp->nested))
52898 + return PTR_ERR(o_tmp->nested);
52899 +
52900 + /* insert into nested subject list */
52901 + o_tmp->nested->next = role->hash->first;
52902 + role->hash->first = o_tmp->nested;
52903 + }
52904 + }
52905 +
52906 + return 0;
52907 +}
52908 +
52909 +static __u32
52910 +count_user_subjs(struct acl_subject_label *userp)
52911 +{
52912 + struct acl_subject_label s_tmp;
52913 + __u32 num = 0;
52914 +
52915 + while (userp) {
52916 + if (copy_from_user(&s_tmp, userp,
52917 + sizeof (struct acl_subject_label)))
52918 + break;
52919 +
52920 + userp = s_tmp.prev;
52921 + /* do not count nested subjects against this count, since
52922 + they are not included in the hash table, but are
52923 + attached to objects. We have already counted
52924 + the subjects in userspace for the allocation
52925 + stack
52926 + */
52927 + if (!(s_tmp.mode & GR_NESTED))
52928 + num++;
52929 + }
52930 +
52931 + return num;
52932 +}
52933 +
52934 +static int
52935 +copy_user_allowedips(struct acl_role_label *rolep)
52936 +{
52937 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52938 +
52939 + ruserip = rolep->allowed_ips;
52940 +
52941 + while (ruserip) {
52942 + rlast = rtmp;
52943 +
52944 + if ((rtmp = (struct role_allowed_ip *)
52945 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52946 + return -ENOMEM;
52947 +
52948 + if (copy_from_user(rtmp, ruserip,
52949 + sizeof (struct role_allowed_ip)))
52950 + return -EFAULT;
52951 +
52952 + ruserip = rtmp->prev;
52953 +
52954 + if (!rlast) {
52955 + rtmp->prev = NULL;
52956 + rolep->allowed_ips = rtmp;
52957 + } else {
52958 + rlast->next = rtmp;
52959 + rtmp->prev = rlast;
52960 + }
52961 +
52962 + if (!ruserip)
52963 + rtmp->next = NULL;
52964 + }
52965 +
52966 + return 0;
52967 +}
52968 +
52969 +static int
52970 +copy_user_transitions(struct acl_role_label *rolep)
52971 +{
52972 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52973 +
52974 + unsigned int len;
52975 + char *tmp;
52976 +
52977 + rusertp = rolep->transitions;
52978 +
52979 + while (rusertp) {
52980 + rlast = rtmp;
52981 +
52982 + if ((rtmp = (struct role_transition *)
52983 + acl_alloc(sizeof (struct role_transition))) == NULL)
52984 + return -ENOMEM;
52985 +
52986 + if (copy_from_user(rtmp, rusertp,
52987 + sizeof (struct role_transition)))
52988 + return -EFAULT;
52989 +
52990 + rusertp = rtmp->prev;
52991 +
52992 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52993 +
52994 + if (!len || len >= GR_SPROLE_LEN)
52995 + return -EINVAL;
52996 +
52997 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52998 + return -ENOMEM;
52999 +
53000 + if (copy_from_user(tmp, rtmp->rolename, len))
53001 + return -EFAULT;
53002 + tmp[len-1] = '\0';
53003 + rtmp->rolename = tmp;
53004 +
53005 + if (!rlast) {
53006 + rtmp->prev = NULL;
53007 + rolep->transitions = rtmp;
53008 + } else {
53009 + rlast->next = rtmp;
53010 + rtmp->prev = rlast;
53011 + }
53012 +
53013 + if (!rusertp)
53014 + rtmp->next = NULL;
53015 + }
53016 +
53017 + return 0;
53018 +}
53019 +
53020 +static struct acl_subject_label *
53021 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
53022 +{
53023 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
53024 + unsigned int len;
53025 + char *tmp;
53026 + __u32 num_objs;
53027 + struct acl_ip_label **i_tmp, *i_utmp2;
53028 + struct gr_hash_struct ghash;
53029 + struct subject_map *subjmap;
53030 + unsigned int i_num;
53031 + int err;
53032 +
53033 + s_tmp = lookup_subject_map(userp);
53034 +
53035 + /* we've already copied this subject into the kernel, just return
53036 + the reference to it, and don't copy it over again
53037 + */
53038 + if (s_tmp)
53039 + return(s_tmp);
53040 +
53041 + if ((s_tmp = (struct acl_subject_label *)
53042 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53043 + return ERR_PTR(-ENOMEM);
53044 +
53045 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53046 + if (subjmap == NULL)
53047 + return ERR_PTR(-ENOMEM);
53048 +
53049 + subjmap->user = userp;
53050 + subjmap->kernel = s_tmp;
53051 + insert_subj_map_entry(subjmap);
53052 +
53053 + if (copy_from_user(s_tmp, userp,
53054 + sizeof (struct acl_subject_label)))
53055 + return ERR_PTR(-EFAULT);
53056 +
53057 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53058 +
53059 + if (!len || len >= PATH_MAX)
53060 + return ERR_PTR(-EINVAL);
53061 +
53062 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53063 + return ERR_PTR(-ENOMEM);
53064 +
53065 + if (copy_from_user(tmp, s_tmp->filename, len))
53066 + return ERR_PTR(-EFAULT);
53067 + tmp[len-1] = '\0';
53068 + s_tmp->filename = tmp;
53069 +
53070 + if (!strcmp(s_tmp->filename, "/"))
53071 + role->root_label = s_tmp;
53072 +
53073 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53074 + return ERR_PTR(-EFAULT);
53075 +
53076 + /* copy user and group transition tables */
53077 +
53078 + if (s_tmp->user_trans_num) {
53079 + uid_t *uidlist;
53080 +
53081 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53082 + if (uidlist == NULL)
53083 + return ERR_PTR(-ENOMEM);
53084 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53085 + return ERR_PTR(-EFAULT);
53086 +
53087 + s_tmp->user_transitions = uidlist;
53088 + }
53089 +
53090 + if (s_tmp->group_trans_num) {
53091 + gid_t *gidlist;
53092 +
53093 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53094 + if (gidlist == NULL)
53095 + return ERR_PTR(-ENOMEM);
53096 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53097 + return ERR_PTR(-EFAULT);
53098 +
53099 + s_tmp->group_transitions = gidlist;
53100 + }
53101 +
53102 + /* set up object hash table */
53103 + num_objs = count_user_objs(ghash.first);
53104 +
53105 + s_tmp->obj_hash_size = num_objs;
53106 + s_tmp->obj_hash =
53107 + (struct acl_object_label **)
53108 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53109 +
53110 + if (!s_tmp->obj_hash)
53111 + return ERR_PTR(-ENOMEM);
53112 +
53113 + memset(s_tmp->obj_hash, 0,
53114 + s_tmp->obj_hash_size *
53115 + sizeof (struct acl_object_label *));
53116 +
53117 + /* add in objects */
53118 + err = copy_user_objs(ghash.first, s_tmp, role);
53119 +
53120 + if (err)
53121 + return ERR_PTR(err);
53122 +
53123 + /* set pointer for parent subject */
53124 + if (s_tmp->parent_subject) {
53125 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
53126 +
53127 + if (IS_ERR(s_tmp2))
53128 + return s_tmp2;
53129 +
53130 + s_tmp->parent_subject = s_tmp2;
53131 + }
53132 +
53133 + /* add in ip acls */
53134 +
53135 + if (!s_tmp->ip_num) {
53136 + s_tmp->ips = NULL;
53137 + goto insert;
53138 + }
53139 +
53140 + i_tmp =
53141 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53142 + sizeof (struct acl_ip_label *));
53143 +
53144 + if (!i_tmp)
53145 + return ERR_PTR(-ENOMEM);
53146 +
53147 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53148 + *(i_tmp + i_num) =
53149 + (struct acl_ip_label *)
53150 + acl_alloc(sizeof (struct acl_ip_label));
53151 + if (!*(i_tmp + i_num))
53152 + return ERR_PTR(-ENOMEM);
53153 +
53154 + if (copy_from_user
53155 + (&i_utmp2, s_tmp->ips + i_num,
53156 + sizeof (struct acl_ip_label *)))
53157 + return ERR_PTR(-EFAULT);
53158 +
53159 + if (copy_from_user
53160 + (*(i_tmp + i_num), i_utmp2,
53161 + sizeof (struct acl_ip_label)))
53162 + return ERR_PTR(-EFAULT);
53163 +
53164 + if ((*(i_tmp + i_num))->iface == NULL)
53165 + continue;
53166 +
53167 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53168 + if (!len || len >= IFNAMSIZ)
53169 + return ERR_PTR(-EINVAL);
53170 + tmp = acl_alloc(len);
53171 + if (tmp == NULL)
53172 + return ERR_PTR(-ENOMEM);
53173 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53174 + return ERR_PTR(-EFAULT);
53175 + (*(i_tmp + i_num))->iface = tmp;
53176 + }
53177 +
53178 + s_tmp->ips = i_tmp;
53179 +
53180 +insert:
53181 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53182 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53183 + return ERR_PTR(-ENOMEM);
53184 +
53185 + return s_tmp;
53186 +}
53187 +
53188 +static int
53189 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53190 +{
53191 + struct acl_subject_label s_pre;
53192 + struct acl_subject_label * ret;
53193 + int err;
53194 +
53195 + while (userp) {
53196 + if (copy_from_user(&s_pre, userp,
53197 + sizeof (struct acl_subject_label)))
53198 + return -EFAULT;
53199 +
53200 + /* do not add nested subjects here, add
53201 + while parsing objects
53202 + */
53203 +
53204 + if (s_pre.mode & GR_NESTED) {
53205 + userp = s_pre.prev;
53206 + continue;
53207 + }
53208 +
53209 + ret = do_copy_user_subj(userp, role);
53210 +
53211 + err = PTR_ERR(ret);
53212 + if (IS_ERR(ret))
53213 + return err;
53214 +
53215 + insert_acl_subj_label(ret, role);
53216 +
53217 + userp = s_pre.prev;
53218 + }
53219 +
53220 + return 0;
53221 +}
53222 +
53223 +static int
53224 +copy_user_acl(struct gr_arg *arg)
53225 +{
53226 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53227 + struct acl_subject_label *subj_list;
53228 + struct sprole_pw *sptmp;
53229 + struct gr_hash_struct *ghash;
53230 + uid_t *domainlist;
53231 + unsigned int r_num;
53232 + unsigned int len;
53233 + char *tmp;
53234 + int err = 0;
53235 + __u16 i;
53236 + __u32 num_subjs;
53237 +
53238 + /* we need a default and kernel role */
53239 + if (arg->role_db.num_roles < 2)
53240 + return -EINVAL;
53241 +
53242 + /* copy special role authentication info from userspace */
53243 +
53244 + num_sprole_pws = arg->num_sprole_pws;
53245 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53246 +
53247 + if (!acl_special_roles && num_sprole_pws)
53248 + return -ENOMEM;
53249 +
53250 + for (i = 0; i < num_sprole_pws; i++) {
53251 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53252 + if (!sptmp)
53253 + return -ENOMEM;
53254 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53255 + sizeof (struct sprole_pw)))
53256 + return -EFAULT;
53257 +
53258 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53259 +
53260 + if (!len || len >= GR_SPROLE_LEN)
53261 + return -EINVAL;
53262 +
53263 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53264 + return -ENOMEM;
53265 +
53266 + if (copy_from_user(tmp, sptmp->rolename, len))
53267 + return -EFAULT;
53268 +
53269 + tmp[len-1] = '\0';
53270 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53271 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53272 +#endif
53273 + sptmp->rolename = tmp;
53274 + acl_special_roles[i] = sptmp;
53275 + }
53276 +
53277 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53278 +
53279 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53280 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53281 +
53282 + if (!r_tmp)
53283 + return -ENOMEM;
53284 +
53285 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53286 + sizeof (struct acl_role_label *)))
53287 + return -EFAULT;
53288 +
53289 + if (copy_from_user(r_tmp, r_utmp2,
53290 + sizeof (struct acl_role_label)))
53291 + return -EFAULT;
53292 +
53293 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53294 +
53295 + if (!len || len >= PATH_MAX)
53296 + return -EINVAL;
53297 +
53298 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53299 + return -ENOMEM;
53300 +
53301 + if (copy_from_user(tmp, r_tmp->rolename, len))
53302 + return -EFAULT;
53303 +
53304 + tmp[len-1] = '\0';
53305 + r_tmp->rolename = tmp;
53306 +
53307 + if (!strcmp(r_tmp->rolename, "default")
53308 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53309 + default_role = r_tmp;
53310 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53311 + kernel_role = r_tmp;
53312 + }
53313 +
53314 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53315 + return -ENOMEM;
53316 +
53317 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53318 + return -EFAULT;
53319 +
53320 + r_tmp->hash = ghash;
53321 +
53322 + num_subjs = count_user_subjs(r_tmp->hash->first);
53323 +
53324 + r_tmp->subj_hash_size = num_subjs;
53325 + r_tmp->subj_hash =
53326 + (struct acl_subject_label **)
53327 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53328 +
53329 + if (!r_tmp->subj_hash)
53330 + return -ENOMEM;
53331 +
53332 + err = copy_user_allowedips(r_tmp);
53333 + if (err)
53334 + return err;
53335 +
53336 + /* copy domain info */
53337 + if (r_tmp->domain_children != NULL) {
53338 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53339 + if (domainlist == NULL)
53340 + return -ENOMEM;
53341 +
53342 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53343 + return -EFAULT;
53344 +
53345 + r_tmp->domain_children = domainlist;
53346 + }
53347 +
53348 + err = copy_user_transitions(r_tmp);
53349 + if (err)
53350 + return err;
53351 +
53352 + memset(r_tmp->subj_hash, 0,
53353 + r_tmp->subj_hash_size *
53354 + sizeof (struct acl_subject_label *));
53355 +
53356 + /* acquire the list of subjects, then NULL out
53357 + the list prior to parsing the subjects for this role,
53358 + as during this parsing the list is replaced with a list
53359 + of *nested* subjects for the role
53360 + */
53361 + subj_list = r_tmp->hash->first;
53362 +
53363 + /* set nested subject list to null */
53364 + r_tmp->hash->first = NULL;
53365 +
53366 + err = copy_user_subjs(subj_list, r_tmp);
53367 +
53368 + if (err)
53369 + return err;
53370 +
53371 + insert_acl_role_label(r_tmp);
53372 + }
53373 +
53374 + if (default_role == NULL || kernel_role == NULL)
53375 + return -EINVAL;
53376 +
53377 + return err;
53378 +}
53379 +
53380 +static int
53381 +gracl_init(struct gr_arg *args)
53382 +{
53383 + int error = 0;
53384 +
53385 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53386 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53387 +
53388 + if (init_variables(args)) {
53389 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53390 + error = -ENOMEM;
53391 + free_variables();
53392 + goto out;
53393 + }
53394 +
53395 + error = copy_user_acl(args);
53396 + free_init_variables();
53397 + if (error) {
53398 + free_variables();
53399 + goto out;
53400 + }
53401 +
53402 + if ((error = gr_set_acls(0))) {
53403 + free_variables();
53404 + goto out;
53405 + }
53406 +
53407 + pax_open_kernel();
53408 + gr_status |= GR_READY;
53409 + pax_close_kernel();
53410 +
53411 + out:
53412 + return error;
53413 +}
53414 +
53415 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53416 +
53417 +static int
53418 +glob_match(const char *p, const char *n)
53419 +{
53420 + char c;
53421 +
53422 + while ((c = *p++) != '\0') {
53423 + switch (c) {
53424 + case '?':
53425 + if (*n == '\0')
53426 + return 1;
53427 + else if (*n == '/')
53428 + return 1;
53429 + break;
53430 + case '\\':
53431 + if (*n != c)
53432 + return 1;
53433 + break;
53434 + case '*':
53435 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53436 + if (*n == '/')
53437 + return 1;
53438 + else if (c == '?') {
53439 + if (*n == '\0')
53440 + return 1;
53441 + else
53442 + ++n;
53443 + }
53444 + }
53445 + if (c == '\0') {
53446 + return 0;
53447 + } else {
53448 + const char *endp;
53449 +
53450 + if ((endp = strchr(n, '/')) == NULL)
53451 + endp = n + strlen(n);
53452 +
53453 + if (c == '[') {
53454 + for (--p; n < endp; ++n)
53455 + if (!glob_match(p, n))
53456 + return 0;
53457 + } else if (c == '/') {
53458 + while (*n != '\0' && *n != '/')
53459 + ++n;
53460 + if (*n == '/' && !glob_match(p, n + 1))
53461 + return 0;
53462 + } else {
53463 + for (--p; n < endp; ++n)
53464 + if (*n == c && !glob_match(p, n))
53465 + return 0;
53466 + }
53467 +
53468 + return 1;
53469 + }
53470 + case '[':
53471 + {
53472 + int not;
53473 + char cold;
53474 +
53475 + if (*n == '\0' || *n == '/')
53476 + return 1;
53477 +
53478 + not = (*p == '!' || *p == '^');
53479 + if (not)
53480 + ++p;
53481 +
53482 + c = *p++;
53483 + for (;;) {
53484 + unsigned char fn = (unsigned char)*n;
53485 +
53486 + if (c == '\0')
53487 + return 1;
53488 + else {
53489 + if (c == fn)
53490 + goto matched;
53491 + cold = c;
53492 + c = *p++;
53493 +
53494 + if (c == '-' && *p != ']') {
53495 + unsigned char cend = *p++;
53496 +
53497 + if (cend == '\0')
53498 + return 1;
53499 +
53500 + if (cold <= fn && fn <= cend)
53501 + goto matched;
53502 +
53503 + c = *p++;
53504 + }
53505 + }
53506 +
53507 + if (c == ']')
53508 + break;
53509 + }
53510 + if (!not)
53511 + return 1;
53512 + break;
53513 + matched:
53514 + while (c != ']') {
53515 + if (c == '\0')
53516 + return 1;
53517 +
53518 + c = *p++;
53519 + }
53520 + if (not)
53521 + return 1;
53522 + }
53523 + break;
53524 + default:
53525 + if (c != *n)
53526 + return 1;
53527 + }
53528 +
53529 + ++n;
53530 + }
53531 +
53532 + if (*n == '\0')
53533 + return 0;
53534 +
53535 + if (*n == '/')
53536 + return 0;
53537 +
53538 + return 1;
53539 +}
53540 +
53541 +static struct acl_object_label *
53542 +chk_glob_label(struct acl_object_label *globbed,
53543 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53544 +{
53545 + struct acl_object_label *tmp;
53546 +
53547 + if (*path == NULL)
53548 + *path = gr_to_filename_nolock(dentry, mnt);
53549 +
53550 + tmp = globbed;
53551 +
53552 + while (tmp) {
53553 + if (!glob_match(tmp->filename, *path))
53554 + return tmp;
53555 + tmp = tmp->next;
53556 + }
53557 +
53558 + return NULL;
53559 +}
53560 +
53561 +static struct acl_object_label *
53562 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53563 + const ino_t curr_ino, const dev_t curr_dev,
53564 + const struct acl_subject_label *subj, char **path, const int checkglob)
53565 +{
53566 + struct acl_subject_label *tmpsubj;
53567 + struct acl_object_label *retval;
53568 + struct acl_object_label *retval2;
53569 +
53570 + tmpsubj = (struct acl_subject_label *) subj;
53571 + read_lock(&gr_inode_lock);
53572 + do {
53573 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53574 + if (retval) {
53575 + if (checkglob && retval->globbed) {
53576 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53577 + if (retval2)
53578 + retval = retval2;
53579 + }
53580 + break;
53581 + }
53582 + } while ((tmpsubj = tmpsubj->parent_subject));
53583 + read_unlock(&gr_inode_lock);
53584 +
53585 + return retval;
53586 +}
53587 +
53588 +static __inline__ struct acl_object_label *
53589 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53590 + struct dentry *curr_dentry,
53591 + const struct acl_subject_label *subj, char **path, const int checkglob)
53592 +{
53593 + int newglob = checkglob;
53594 + ino_t inode;
53595 + dev_t device;
53596 +
53597 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53598 + as we don't want a / * rule to match instead of the / object
53599 + don't do this for create lookups that call this function though, since they're looking up
53600 + on the parent and thus need globbing checks on all paths
53601 + */
53602 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53603 + newglob = GR_NO_GLOB;
53604 +
53605 + spin_lock(&curr_dentry->d_lock);
53606 + inode = curr_dentry->d_inode->i_ino;
53607 + device = __get_dev(curr_dentry);
53608 + spin_unlock(&curr_dentry->d_lock);
53609 +
53610 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53611 +}
53612 +
53613 +static struct acl_object_label *
53614 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53615 + const struct acl_subject_label *subj, char *path, const int checkglob)
53616 +{
53617 + struct dentry *dentry = (struct dentry *) l_dentry;
53618 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53619 + struct mount *real_mnt = real_mount(mnt);
53620 + struct acl_object_label *retval;
53621 + struct dentry *parent;
53622 +
53623 + write_seqlock(&rename_lock);
53624 + br_read_lock(&vfsmount_lock);
53625 +
53626 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53627 +#ifdef CONFIG_NET
53628 + mnt == sock_mnt ||
53629 +#endif
53630 +#ifdef CONFIG_HUGETLBFS
53631 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53632 +#endif
53633 + /* ignore Eric Biederman */
53634 + IS_PRIVATE(l_dentry->d_inode))) {
53635 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53636 + goto out;
53637 + }
53638 +
53639 + for (;;) {
53640 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53641 + break;
53642 +
53643 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53644 + if (!mnt_has_parent(real_mnt))
53645 + break;
53646 +
53647 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53648 + if (retval != NULL)
53649 + goto out;
53650 +
53651 + dentry = real_mnt->mnt_mountpoint;
53652 + real_mnt = real_mnt->mnt_parent;
53653 + mnt = &real_mnt->mnt;
53654 + continue;
53655 + }
53656 +
53657 + parent = dentry->d_parent;
53658 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53659 + if (retval != NULL)
53660 + goto out;
53661 +
53662 + dentry = parent;
53663 + }
53664 +
53665 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53666 +
53667 + /* real_root is pinned so we don't have to hold a reference */
53668 + if (retval == NULL)
53669 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53670 +out:
53671 + br_read_unlock(&vfsmount_lock);
53672 + write_sequnlock(&rename_lock);
53673 +
53674 + BUG_ON(retval == NULL);
53675 +
53676 + return retval;
53677 +}
53678 +
53679 +static __inline__ struct acl_object_label *
53680 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53681 + const struct acl_subject_label *subj)
53682 +{
53683 + char *path = NULL;
53684 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53685 +}
53686 +
53687 +static __inline__ struct acl_object_label *
53688 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53689 + const struct acl_subject_label *subj)
53690 +{
53691 + char *path = NULL;
53692 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53693 +}
53694 +
53695 +static __inline__ struct acl_object_label *
53696 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53697 + const struct acl_subject_label *subj, char *path)
53698 +{
53699 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53700 +}
53701 +
53702 +static struct acl_subject_label *
53703 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53704 + const struct acl_role_label *role)
53705 +{
53706 + struct dentry *dentry = (struct dentry *) l_dentry;
53707 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53708 + struct mount *real_mnt = real_mount(mnt);
53709 + struct acl_subject_label *retval;
53710 + struct dentry *parent;
53711 +
53712 + write_seqlock(&rename_lock);
53713 + br_read_lock(&vfsmount_lock);
53714 +
53715 + for (;;) {
53716 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53717 + break;
53718 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53719 + if (!mnt_has_parent(real_mnt))
53720 + break;
53721 +
53722 + spin_lock(&dentry->d_lock);
53723 + read_lock(&gr_inode_lock);
53724 + retval =
53725 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53726 + __get_dev(dentry), role);
53727 + read_unlock(&gr_inode_lock);
53728 + spin_unlock(&dentry->d_lock);
53729 + if (retval != NULL)
53730 + goto out;
53731 +
53732 + dentry = real_mnt->mnt_mountpoint;
53733 + real_mnt = real_mnt->mnt_parent;
53734 + mnt = &real_mnt->mnt;
53735 + continue;
53736 + }
53737 +
53738 + spin_lock(&dentry->d_lock);
53739 + read_lock(&gr_inode_lock);
53740 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53741 + __get_dev(dentry), role);
53742 + read_unlock(&gr_inode_lock);
53743 + parent = dentry->d_parent;
53744 + spin_unlock(&dentry->d_lock);
53745 +
53746 + if (retval != NULL)
53747 + goto out;
53748 +
53749 + dentry = parent;
53750 + }
53751 +
53752 + spin_lock(&dentry->d_lock);
53753 + read_lock(&gr_inode_lock);
53754 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53755 + __get_dev(dentry), role);
53756 + read_unlock(&gr_inode_lock);
53757 + spin_unlock(&dentry->d_lock);
53758 +
53759 + if (unlikely(retval == NULL)) {
53760 + /* real_root is pinned, we don't need to hold a reference */
53761 + read_lock(&gr_inode_lock);
53762 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53763 + __get_dev(real_root.dentry), role);
53764 + read_unlock(&gr_inode_lock);
53765 + }
53766 +out:
53767 + br_read_unlock(&vfsmount_lock);
53768 + write_sequnlock(&rename_lock);
53769 +
53770 + BUG_ON(retval == NULL);
53771 +
53772 + return retval;
53773 +}
53774 +
53775 +static void
53776 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53777 +{
53778 + struct task_struct *task = current;
53779 + const struct cred *cred = current_cred();
53780 +
53781 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53782 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53783 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53784 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53785 +
53786 + return;
53787 +}
53788 +
53789 +static void
53790 +gr_log_learn_id_change(const char type, const unsigned int real,
53791 + const unsigned int effective, const unsigned int fs)
53792 +{
53793 + struct task_struct *task = current;
53794 + const struct cred *cred = current_cred();
53795 +
53796 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53797 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53798 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53799 + type, real, effective, fs, &task->signal->saved_ip);
53800 +
53801 + return;
53802 +}
53803 +
53804 +__u32
53805 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53806 + const struct vfsmount * mnt)
53807 +{
53808 + __u32 retval = mode;
53809 + struct acl_subject_label *curracl;
53810 + struct acl_object_label *currobj;
53811 +
53812 + if (unlikely(!(gr_status & GR_READY)))
53813 + return (mode & ~GR_AUDITS);
53814 +
53815 + curracl = current->acl;
53816 +
53817 + currobj = chk_obj_label(dentry, mnt, curracl);
53818 + retval = currobj->mode & mode;
53819 +
53820 + /* if we're opening a specified transfer file for writing
53821 + (e.g. /dev/initctl), then transfer our role to init
53822 + */
53823 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53824 + current->role->roletype & GR_ROLE_PERSIST)) {
53825 + struct task_struct *task = init_pid_ns.child_reaper;
53826 +
53827 + if (task->role != current->role) {
53828 + task->acl_sp_role = 0;
53829 + task->acl_role_id = current->acl_role_id;
53830 + task->role = current->role;
53831 + rcu_read_lock();
53832 + read_lock(&grsec_exec_file_lock);
53833 + gr_apply_subject_to_task(task);
53834 + read_unlock(&grsec_exec_file_lock);
53835 + rcu_read_unlock();
53836 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53837 + }
53838 + }
53839 +
53840 + if (unlikely
53841 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53842 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53843 + __u32 new_mode = mode;
53844 +
53845 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53846 +
53847 + retval = new_mode;
53848 +
53849 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53850 + new_mode |= GR_INHERIT;
53851 +
53852 + if (!(mode & GR_NOLEARN))
53853 + gr_log_learn(dentry, mnt, new_mode);
53854 + }
53855 +
53856 + return retval;
53857 +}
53858 +
53859 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53860 + const struct dentry *parent,
53861 + const struct vfsmount *mnt)
53862 +{
53863 + struct name_entry *match;
53864 + struct acl_object_label *matchpo;
53865 + struct acl_subject_label *curracl;
53866 + char *path;
53867 +
53868 + if (unlikely(!(gr_status & GR_READY)))
53869 + return NULL;
53870 +
53871 + preempt_disable();
53872 + path = gr_to_filename_rbac(new_dentry, mnt);
53873 + match = lookup_name_entry_create(path);
53874 +
53875 + curracl = current->acl;
53876 +
53877 + if (match) {
53878 + read_lock(&gr_inode_lock);
53879 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53880 + read_unlock(&gr_inode_lock);
53881 +
53882 + if (matchpo) {
53883 + preempt_enable();
53884 + return matchpo;
53885 + }
53886 + }
53887 +
53888 + // lookup parent
53889 +
53890 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53891 +
53892 + preempt_enable();
53893 + return matchpo;
53894 +}
53895 +
53896 +__u32
53897 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53898 + const struct vfsmount * mnt, const __u32 mode)
53899 +{
53900 + struct acl_object_label *matchpo;
53901 + __u32 retval;
53902 +
53903 + if (unlikely(!(gr_status & GR_READY)))
53904 + return (mode & ~GR_AUDITS);
53905 +
53906 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53907 +
53908 + retval = matchpo->mode & mode;
53909 +
53910 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53911 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53912 + __u32 new_mode = mode;
53913 +
53914 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53915 +
53916 + gr_log_learn(new_dentry, mnt, new_mode);
53917 + return new_mode;
53918 + }
53919 +
53920 + return retval;
53921 +}
53922 +
53923 +__u32
53924 +gr_check_link(const struct dentry * new_dentry,
53925 + const struct dentry * parent_dentry,
53926 + const struct vfsmount * parent_mnt,
53927 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53928 +{
53929 + struct acl_object_label *obj;
53930 + __u32 oldmode, newmode;
53931 + __u32 needmode;
53932 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53933 + GR_DELETE | GR_INHERIT;
53934 +
53935 + if (unlikely(!(gr_status & GR_READY)))
53936 + return (GR_CREATE | GR_LINK);
53937 +
53938 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53939 + oldmode = obj->mode;
53940 +
53941 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53942 + newmode = obj->mode;
53943 +
53944 + needmode = newmode & checkmodes;
53945 +
53946 + // old name for hardlink must have at least the permissions of the new name
53947 + if ((oldmode & needmode) != needmode)
53948 + goto bad;
53949 +
53950 + // if old name had restrictions/auditing, make sure the new name does as well
53951 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53952 +
53953 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53954 + if (is_privileged_binary(old_dentry))
53955 + needmode |= GR_SETID;
53956 +
53957 + if ((newmode & needmode) != needmode)
53958 + goto bad;
53959 +
53960 + // enforce minimum permissions
53961 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53962 + return newmode;
53963 +bad:
53964 + needmode = oldmode;
53965 + if (is_privileged_binary(old_dentry))
53966 + needmode |= GR_SETID;
53967 +
53968 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53969 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53970 + return (GR_CREATE | GR_LINK);
53971 + } else if (newmode & GR_SUPPRESS)
53972 + return GR_SUPPRESS;
53973 + else
53974 + return 0;
53975 +}
53976 +
53977 +int
53978 +gr_check_hidden_task(const struct task_struct *task)
53979 +{
53980 + if (unlikely(!(gr_status & GR_READY)))
53981 + return 0;
53982 +
53983 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53984 + return 1;
53985 +
53986 + return 0;
53987 +}
53988 +
53989 +int
53990 +gr_check_protected_task(const struct task_struct *task)
53991 +{
53992 + if (unlikely(!(gr_status & GR_READY) || !task))
53993 + return 0;
53994 +
53995 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53996 + task->acl != current->acl)
53997 + return 1;
53998 +
53999 + return 0;
54000 +}
54001 +
54002 +int
54003 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
54004 +{
54005 + struct task_struct *p;
54006 + int ret = 0;
54007 +
54008 + if (unlikely(!(gr_status & GR_READY) || !pid))
54009 + return ret;
54010 +
54011 + read_lock(&tasklist_lock);
54012 + do_each_pid_task(pid, type, p) {
54013 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
54014 + p->acl != current->acl) {
54015 + ret = 1;
54016 + goto out;
54017 + }
54018 + } while_each_pid_task(pid, type, p);
54019 +out:
54020 + read_unlock(&tasklist_lock);
54021 +
54022 + return ret;
54023 +}
54024 +
54025 +void
54026 +gr_copy_label(struct task_struct *tsk)
54027 +{
54028 + tsk->signal->used_accept = 0;
54029 + tsk->acl_sp_role = 0;
54030 + tsk->acl_role_id = current->acl_role_id;
54031 + tsk->acl = current->acl;
54032 + tsk->role = current->role;
54033 + tsk->signal->curr_ip = current->signal->curr_ip;
54034 + tsk->signal->saved_ip = current->signal->saved_ip;
54035 + if (current->exec_file)
54036 + get_file(current->exec_file);
54037 + tsk->exec_file = current->exec_file;
54038 + tsk->is_writable = current->is_writable;
54039 + if (unlikely(current->signal->used_accept)) {
54040 + current->signal->curr_ip = 0;
54041 + current->signal->saved_ip = 0;
54042 + }
54043 +
54044 + return;
54045 +}
54046 +
54047 +static void
54048 +gr_set_proc_res(struct task_struct *task)
54049 +{
54050 + struct acl_subject_label *proc;
54051 + unsigned short i;
54052 +
54053 + proc = task->acl;
54054 +
54055 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54056 + return;
54057 +
54058 + for (i = 0; i < RLIM_NLIMITS; i++) {
54059 + if (!(proc->resmask & (1 << i)))
54060 + continue;
54061 +
54062 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54063 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54064 + }
54065 +
54066 + return;
54067 +}
54068 +
54069 +extern int __gr_process_user_ban(struct user_struct *user);
54070 +
54071 +int
54072 +gr_check_user_change(int real, int effective, int fs)
54073 +{
54074 + unsigned int i;
54075 + __u16 num;
54076 + uid_t *uidlist;
54077 + int curuid;
54078 + int realok = 0;
54079 + int effectiveok = 0;
54080 + int fsok = 0;
54081 +
54082 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54083 + struct user_struct *user;
54084 +
54085 + if (real == -1)
54086 + goto skipit;
54087 +
54088 + user = find_user(real);
54089 + if (user == NULL)
54090 + goto skipit;
54091 +
54092 + if (__gr_process_user_ban(user)) {
54093 + /* for find_user */
54094 + free_uid(user);
54095 + return 1;
54096 + }
54097 +
54098 + /* for find_user */
54099 + free_uid(user);
54100 +
54101 +skipit:
54102 +#endif
54103 +
54104 + if (unlikely(!(gr_status & GR_READY)))
54105 + return 0;
54106 +
54107 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54108 + gr_log_learn_id_change('u', real, effective, fs);
54109 +
54110 + num = current->acl->user_trans_num;
54111 + uidlist = current->acl->user_transitions;
54112 +
54113 + if (uidlist == NULL)
54114 + return 0;
54115 +
54116 + if (real == -1)
54117 + realok = 1;
54118 + if (effective == -1)
54119 + effectiveok = 1;
54120 + if (fs == -1)
54121 + fsok = 1;
54122 +
54123 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54124 + for (i = 0; i < num; i++) {
54125 + curuid = (int)uidlist[i];
54126 + if (real == curuid)
54127 + realok = 1;
54128 + if (effective == curuid)
54129 + effectiveok = 1;
54130 + if (fs == curuid)
54131 + fsok = 1;
54132 + }
54133 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54134 + for (i = 0; i < num; i++) {
54135 + curuid = (int)uidlist[i];
54136 + if (real == curuid)
54137 + break;
54138 + if (effective == curuid)
54139 + break;
54140 + if (fs == curuid)
54141 + break;
54142 + }
54143 + /* not in deny list */
54144 + if (i == num) {
54145 + realok = 1;
54146 + effectiveok = 1;
54147 + fsok = 1;
54148 + }
54149 + }
54150 +
54151 + if (realok && effectiveok && fsok)
54152 + return 0;
54153 + else {
54154 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54155 + return 1;
54156 + }
54157 +}
54158 +
54159 +int
54160 +gr_check_group_change(int real, int effective, int fs)
54161 +{
54162 + unsigned int i;
54163 + __u16 num;
54164 + gid_t *gidlist;
54165 + int curgid;
54166 + int realok = 0;
54167 + int effectiveok = 0;
54168 + int fsok = 0;
54169 +
54170 + if (unlikely(!(gr_status & GR_READY)))
54171 + return 0;
54172 +
54173 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54174 + gr_log_learn_id_change('g', real, effective, fs);
54175 +
54176 + num = current->acl->group_trans_num;
54177 + gidlist = current->acl->group_transitions;
54178 +
54179 + if (gidlist == NULL)
54180 + return 0;
54181 +
54182 + if (real == -1)
54183 + realok = 1;
54184 + if (effective == -1)
54185 + effectiveok = 1;
54186 + if (fs == -1)
54187 + fsok = 1;
54188 +
54189 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54190 + for (i = 0; i < num; i++) {
54191 + curgid = (int)gidlist[i];
54192 + if (real == curgid)
54193 + realok = 1;
54194 + if (effective == curgid)
54195 + effectiveok = 1;
54196 + if (fs == curgid)
54197 + fsok = 1;
54198 + }
54199 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54200 + for (i = 0; i < num; i++) {
54201 + curgid = (int)gidlist[i];
54202 + if (real == curgid)
54203 + break;
54204 + if (effective == curgid)
54205 + break;
54206 + if (fs == curgid)
54207 + break;
54208 + }
54209 + /* not in deny list */
54210 + if (i == num) {
54211 + realok = 1;
54212 + effectiveok = 1;
54213 + fsok = 1;
54214 + }
54215 + }
54216 +
54217 + if (realok && effectiveok && fsok)
54218 + return 0;
54219 + else {
54220 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54221 + return 1;
54222 + }
54223 +}
54224 +
54225 +extern int gr_acl_is_capable(const int cap);
54226 +
54227 +void
54228 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54229 +{
54230 + struct acl_role_label *role = task->role;
54231 + struct acl_subject_label *subj = NULL;
54232 + struct acl_object_label *obj;
54233 + struct file *filp;
54234 +
54235 + if (unlikely(!(gr_status & GR_READY)))
54236 + return;
54237 +
54238 + filp = task->exec_file;
54239 +
54240 + /* kernel process, we'll give them the kernel role */
54241 + if (unlikely(!filp)) {
54242 + task->role = kernel_role;
54243 + task->acl = kernel_role->root_label;
54244 + return;
54245 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54246 + role = lookup_acl_role_label(task, uid, gid);
54247 +
54248 + /* don't change the role if we're not a privileged process */
54249 + if (role && task->role != role &&
54250 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54251 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54252 + return;
54253 +
54254 + /* perform subject lookup in possibly new role
54255 + we can use this result below in the case where role == task->role
54256 + */
54257 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54258 +
54259 + /* if we changed uid/gid, but result in the same role
54260 + and are using inheritance, don't lose the inherited subject
54261 + if current subject is other than what normal lookup
54262 + would result in, we arrived via inheritance, don't
54263 + lose subject
54264 + */
54265 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54266 + (subj == task->acl)))
54267 + task->acl = subj;
54268 +
54269 + task->role = role;
54270 +
54271 + task->is_writable = 0;
54272 +
54273 + /* ignore additional mmap checks for processes that are writable
54274 + by the default ACL */
54275 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54276 + if (unlikely(obj->mode & GR_WRITE))
54277 + task->is_writable = 1;
54278 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54279 + if (unlikely(obj->mode & GR_WRITE))
54280 + task->is_writable = 1;
54281 +
54282 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54283 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54284 +#endif
54285 +
54286 + gr_set_proc_res(task);
54287 +
54288 + return;
54289 +}
54290 +
54291 +int
54292 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54293 + const int unsafe_flags)
54294 +{
54295 + struct task_struct *task = current;
54296 + struct acl_subject_label *newacl;
54297 + struct acl_object_label *obj;
54298 + __u32 retmode;
54299 +
54300 + if (unlikely(!(gr_status & GR_READY)))
54301 + return 0;
54302 +
54303 + newacl = chk_subj_label(dentry, mnt, task->role);
54304 +
54305 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54306 + did an exec
54307 + */
54308 + rcu_read_lock();
54309 + read_lock(&tasklist_lock);
54310 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54311 + (task->parent->acl->mode & GR_POVERRIDE))) {
54312 + read_unlock(&tasklist_lock);
54313 + rcu_read_unlock();
54314 + goto skip_check;
54315 + }
54316 + read_unlock(&tasklist_lock);
54317 + rcu_read_unlock();
54318 +
54319 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54320 + !(task->role->roletype & GR_ROLE_GOD) &&
54321 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54322 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54323 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54324 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54325 + else
54326 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54327 + return -EACCES;
54328 + }
54329 +
54330 +skip_check:
54331 +
54332 + obj = chk_obj_label(dentry, mnt, task->acl);
54333 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54334 +
54335 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54336 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54337 + if (obj->nested)
54338 + task->acl = obj->nested;
54339 + else
54340 + task->acl = newacl;
54341 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54342 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54343 +
54344 + task->is_writable = 0;
54345 +
54346 + /* ignore additional mmap checks for processes that are writable
54347 + by the default ACL */
54348 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54349 + if (unlikely(obj->mode & GR_WRITE))
54350 + task->is_writable = 1;
54351 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54352 + if (unlikely(obj->mode & GR_WRITE))
54353 + task->is_writable = 1;
54354 +
54355 + gr_set_proc_res(task);
54356 +
54357 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54358 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54359 +#endif
54360 + return 0;
54361 +}
54362 +
54363 +/* always called with valid inodev ptr */
54364 +static void
54365 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54366 +{
54367 + struct acl_object_label *matchpo;
54368 + struct acl_subject_label *matchps;
54369 + struct acl_subject_label *subj;
54370 + struct acl_role_label *role;
54371 + unsigned int x;
54372 +
54373 + FOR_EACH_ROLE_START(role)
54374 + FOR_EACH_SUBJECT_START(role, subj, x)
54375 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54376 + matchpo->mode |= GR_DELETED;
54377 + FOR_EACH_SUBJECT_END(subj,x)
54378 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54379 + /* nested subjects aren't in the role's subj_hash table */
54380 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54381 + matchpo->mode |= GR_DELETED;
54382 + FOR_EACH_NESTED_SUBJECT_END(subj)
54383 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54384 + matchps->mode |= GR_DELETED;
54385 + FOR_EACH_ROLE_END(role)
54386 +
54387 + inodev->nentry->deleted = 1;
54388 +
54389 + return;
54390 +}
54391 +
54392 +void
54393 +gr_handle_delete(const ino_t ino, const dev_t dev)
54394 +{
54395 + struct inodev_entry *inodev;
54396 +
54397 + if (unlikely(!(gr_status & GR_READY)))
54398 + return;
54399 +
54400 + write_lock(&gr_inode_lock);
54401 + inodev = lookup_inodev_entry(ino, dev);
54402 + if (inodev != NULL)
54403 + do_handle_delete(inodev, ino, dev);
54404 + write_unlock(&gr_inode_lock);
54405 +
54406 + return;
54407 +}
54408 +
54409 +static void
54410 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54411 + const ino_t newinode, const dev_t newdevice,
54412 + struct acl_subject_label *subj)
54413 +{
54414 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54415 + struct acl_object_label *match;
54416 +
54417 + match = subj->obj_hash[index];
54418 +
54419 + while (match && (match->inode != oldinode ||
54420 + match->device != olddevice ||
54421 + !(match->mode & GR_DELETED)))
54422 + match = match->next;
54423 +
54424 + if (match && (match->inode == oldinode)
54425 + && (match->device == olddevice)
54426 + && (match->mode & GR_DELETED)) {
54427 + if (match->prev == NULL) {
54428 + subj->obj_hash[index] = match->next;
54429 + if (match->next != NULL)
54430 + match->next->prev = NULL;
54431 + } else {
54432 + match->prev->next = match->next;
54433 + if (match->next != NULL)
54434 + match->next->prev = match->prev;
54435 + }
54436 + match->prev = NULL;
54437 + match->next = NULL;
54438 + match->inode = newinode;
54439 + match->device = newdevice;
54440 + match->mode &= ~GR_DELETED;
54441 +
54442 + insert_acl_obj_label(match, subj);
54443 + }
54444 +
54445 + return;
54446 +}
54447 +
54448 +static void
54449 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54450 + const ino_t newinode, const dev_t newdevice,
54451 + struct acl_role_label *role)
54452 +{
54453 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54454 + struct acl_subject_label *match;
54455 +
54456 + match = role->subj_hash[index];
54457 +
54458 + while (match && (match->inode != oldinode ||
54459 + match->device != olddevice ||
54460 + !(match->mode & GR_DELETED)))
54461 + match = match->next;
54462 +
54463 + if (match && (match->inode == oldinode)
54464 + && (match->device == olddevice)
54465 + && (match->mode & GR_DELETED)) {
54466 + if (match->prev == NULL) {
54467 + role->subj_hash[index] = match->next;
54468 + if (match->next != NULL)
54469 + match->next->prev = NULL;
54470 + } else {
54471 + match->prev->next = match->next;
54472 + if (match->next != NULL)
54473 + match->next->prev = match->prev;
54474 + }
54475 + match->prev = NULL;
54476 + match->next = NULL;
54477 + match->inode = newinode;
54478 + match->device = newdevice;
54479 + match->mode &= ~GR_DELETED;
54480 +
54481 + insert_acl_subj_label(match, role);
54482 + }
54483 +
54484 + return;
54485 +}
54486 +
54487 +static void
54488 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54489 + const ino_t newinode, const dev_t newdevice)
54490 +{
54491 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54492 + struct inodev_entry *match;
54493 +
54494 + match = inodev_set.i_hash[index];
54495 +
54496 + while (match && (match->nentry->inode != oldinode ||
54497 + match->nentry->device != olddevice || !match->nentry->deleted))
54498 + match = match->next;
54499 +
54500 + if (match && (match->nentry->inode == oldinode)
54501 + && (match->nentry->device == olddevice) &&
54502 + match->nentry->deleted) {
54503 + if (match->prev == NULL) {
54504 + inodev_set.i_hash[index] = match->next;
54505 + if (match->next != NULL)
54506 + match->next->prev = NULL;
54507 + } else {
54508 + match->prev->next = match->next;
54509 + if (match->next != NULL)
54510 + match->next->prev = match->prev;
54511 + }
54512 + match->prev = NULL;
54513 + match->next = NULL;
54514 + match->nentry->inode = newinode;
54515 + match->nentry->device = newdevice;
54516 + match->nentry->deleted = 0;
54517 +
54518 + insert_inodev_entry(match);
54519 + }
54520 +
54521 + return;
54522 +}
54523 +
54524 +static void
54525 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54526 +{
54527 + struct acl_subject_label *subj;
54528 + struct acl_role_label *role;
54529 + unsigned int x;
54530 +
54531 + FOR_EACH_ROLE_START(role)
54532 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54533 +
54534 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54535 + if ((subj->inode == ino) && (subj->device == dev)) {
54536 + subj->inode = ino;
54537 + subj->device = dev;
54538 + }
54539 + /* nested subjects aren't in the role's subj_hash table */
54540 + update_acl_obj_label(matchn->inode, matchn->device,
54541 + ino, dev, subj);
54542 + FOR_EACH_NESTED_SUBJECT_END(subj)
54543 + FOR_EACH_SUBJECT_START(role, subj, x)
54544 + update_acl_obj_label(matchn->inode, matchn->device,
54545 + ino, dev, subj);
54546 + FOR_EACH_SUBJECT_END(subj,x)
54547 + FOR_EACH_ROLE_END(role)
54548 +
54549 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54550 +
54551 + return;
54552 +}
54553 +
54554 +static void
54555 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54556 + const struct vfsmount *mnt)
54557 +{
54558 + ino_t ino = dentry->d_inode->i_ino;
54559 + dev_t dev = __get_dev(dentry);
54560 +
54561 + __do_handle_create(matchn, ino, dev);
54562 +
54563 + return;
54564 +}
54565 +
54566 +void
54567 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54568 +{
54569 + struct name_entry *matchn;
54570 +
54571 + if (unlikely(!(gr_status & GR_READY)))
54572 + return;
54573 +
54574 + preempt_disable();
54575 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54576 +
54577 + if (unlikely((unsigned long)matchn)) {
54578 + write_lock(&gr_inode_lock);
54579 + do_handle_create(matchn, dentry, mnt);
54580 + write_unlock(&gr_inode_lock);
54581 + }
54582 + preempt_enable();
54583 +
54584 + return;
54585 +}
54586 +
54587 +void
54588 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54589 +{
54590 + struct name_entry *matchn;
54591 +
54592 + if (unlikely(!(gr_status & GR_READY)))
54593 + return;
54594 +
54595 + preempt_disable();
54596 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54597 +
54598 + if (unlikely((unsigned long)matchn)) {
54599 + write_lock(&gr_inode_lock);
54600 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54601 + write_unlock(&gr_inode_lock);
54602 + }
54603 + preempt_enable();
54604 +
54605 + return;
54606 +}
54607 +
54608 +void
54609 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54610 + struct dentry *old_dentry,
54611 + struct dentry *new_dentry,
54612 + struct vfsmount *mnt, const __u8 replace)
54613 +{
54614 + struct name_entry *matchn;
54615 + struct inodev_entry *inodev;
54616 + struct inode *inode = new_dentry->d_inode;
54617 + ino_t old_ino = old_dentry->d_inode->i_ino;
54618 + dev_t old_dev = __get_dev(old_dentry);
54619 +
54620 + /* vfs_rename swaps the name and parent link for old_dentry and
54621 + new_dentry
54622 + at this point, old_dentry has the new name, parent link, and inode
54623 + for the renamed file
54624 + if a file is being replaced by a rename, new_dentry has the inode
54625 + and name for the replaced file
54626 + */
54627 +
54628 + if (unlikely(!(gr_status & GR_READY)))
54629 + return;
54630 +
54631 + preempt_disable();
54632 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54633 +
54634 + /* we wouldn't have to check d_inode if it weren't for
54635 + NFS silly-renaming
54636 + */
54637 +
54638 + write_lock(&gr_inode_lock);
54639 + if (unlikely(replace && inode)) {
54640 + ino_t new_ino = inode->i_ino;
54641 + dev_t new_dev = __get_dev(new_dentry);
54642 +
54643 + inodev = lookup_inodev_entry(new_ino, new_dev);
54644 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54645 + do_handle_delete(inodev, new_ino, new_dev);
54646 + }
54647 +
54648 + inodev = lookup_inodev_entry(old_ino, old_dev);
54649 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54650 + do_handle_delete(inodev, old_ino, old_dev);
54651 +
54652 + if (unlikely((unsigned long)matchn))
54653 + do_handle_create(matchn, old_dentry, mnt);
54654 +
54655 + write_unlock(&gr_inode_lock);
54656 + preempt_enable();
54657 +
54658 + return;
54659 +}
54660 +
54661 +static int
54662 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54663 + unsigned char **sum)
54664 +{
54665 + struct acl_role_label *r;
54666 + struct role_allowed_ip *ipp;
54667 + struct role_transition *trans;
54668 + unsigned int i;
54669 + int found = 0;
54670 + u32 curr_ip = current->signal->curr_ip;
54671 +
54672 + current->signal->saved_ip = curr_ip;
54673 +
54674 + /* check transition table */
54675 +
54676 + for (trans = current->role->transitions; trans; trans = trans->next) {
54677 + if (!strcmp(rolename, trans->rolename)) {
54678 + found = 1;
54679 + break;
54680 + }
54681 + }
54682 +
54683 + if (!found)
54684 + return 0;
54685 +
54686 + /* handle special roles that do not require authentication
54687 + and check ip */
54688 +
54689 + FOR_EACH_ROLE_START(r)
54690 + if (!strcmp(rolename, r->rolename) &&
54691 + (r->roletype & GR_ROLE_SPECIAL)) {
54692 + found = 0;
54693 + if (r->allowed_ips != NULL) {
54694 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54695 + if ((ntohl(curr_ip) & ipp->netmask) ==
54696 + (ntohl(ipp->addr) & ipp->netmask))
54697 + found = 1;
54698 + }
54699 + } else
54700 + found = 2;
54701 + if (!found)
54702 + return 0;
54703 +
54704 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54705 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54706 + *salt = NULL;
54707 + *sum = NULL;
54708 + return 1;
54709 + }
54710 + }
54711 + FOR_EACH_ROLE_END(r)
54712 +
54713 + for (i = 0; i < num_sprole_pws; i++) {
54714 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54715 + *salt = acl_special_roles[i]->salt;
54716 + *sum = acl_special_roles[i]->sum;
54717 + return 1;
54718 + }
54719 + }
54720 +
54721 + return 0;
54722 +}
54723 +
54724 +static void
54725 +assign_special_role(char *rolename)
54726 +{
54727 + struct acl_object_label *obj;
54728 + struct acl_role_label *r;
54729 + struct acl_role_label *assigned = NULL;
54730 + struct task_struct *tsk;
54731 + struct file *filp;
54732 +
54733 + FOR_EACH_ROLE_START(r)
54734 + if (!strcmp(rolename, r->rolename) &&
54735 + (r->roletype & GR_ROLE_SPECIAL)) {
54736 + assigned = r;
54737 + break;
54738 + }
54739 + FOR_EACH_ROLE_END(r)
54740 +
54741 + if (!assigned)
54742 + return;
54743 +
54744 + read_lock(&tasklist_lock);
54745 + read_lock(&grsec_exec_file_lock);
54746 +
54747 + tsk = current->real_parent;
54748 + if (tsk == NULL)
54749 + goto out_unlock;
54750 +
54751 + filp = tsk->exec_file;
54752 + if (filp == NULL)
54753 + goto out_unlock;
54754 +
54755 + tsk->is_writable = 0;
54756 +
54757 + tsk->acl_sp_role = 1;
54758 + tsk->acl_role_id = ++acl_sp_role_value;
54759 + tsk->role = assigned;
54760 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54761 +
54762 + /* ignore additional mmap checks for processes that are writable
54763 + by the default ACL */
54764 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54765 + if (unlikely(obj->mode & GR_WRITE))
54766 + tsk->is_writable = 1;
54767 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54768 + if (unlikely(obj->mode & GR_WRITE))
54769 + tsk->is_writable = 1;
54770 +
54771 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54772 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54773 +#endif
54774 +
54775 +out_unlock:
54776 + read_unlock(&grsec_exec_file_lock);
54777 + read_unlock(&tasklist_lock);
54778 + return;
54779 +}
54780 +
54781 +int gr_check_secure_terminal(struct task_struct *task)
54782 +{
54783 + struct task_struct *p, *p2, *p3;
54784 + struct files_struct *files;
54785 + struct fdtable *fdt;
54786 + struct file *our_file = NULL, *file;
54787 + int i;
54788 +
54789 + if (task->signal->tty == NULL)
54790 + return 1;
54791 +
54792 + files = get_files_struct(task);
54793 + if (files != NULL) {
54794 + rcu_read_lock();
54795 + fdt = files_fdtable(files);
54796 + for (i=0; i < fdt->max_fds; i++) {
54797 + file = fcheck_files(files, i);
54798 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54799 + get_file(file);
54800 + our_file = file;
54801 + }
54802 + }
54803 + rcu_read_unlock();
54804 + put_files_struct(files);
54805 + }
54806 +
54807 + if (our_file == NULL)
54808 + return 1;
54809 +
54810 + read_lock(&tasklist_lock);
54811 + do_each_thread(p2, p) {
54812 + files = get_files_struct(p);
54813 + if (files == NULL ||
54814 + (p->signal && p->signal->tty == task->signal->tty)) {
54815 + if (files != NULL)
54816 + put_files_struct(files);
54817 + continue;
54818 + }
54819 + rcu_read_lock();
54820 + fdt = files_fdtable(files);
54821 + for (i=0; i < fdt->max_fds; i++) {
54822 + file = fcheck_files(files, i);
54823 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54824 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54825 + p3 = task;
54826 + while (p3->pid > 0) {
54827 + if (p3 == p)
54828 + break;
54829 + p3 = p3->real_parent;
54830 + }
54831 + if (p3 == p)
54832 + break;
54833 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54834 + gr_handle_alertkill(p);
54835 + rcu_read_unlock();
54836 + put_files_struct(files);
54837 + read_unlock(&tasklist_lock);
54838 + fput(our_file);
54839 + return 0;
54840 + }
54841 + }
54842 + rcu_read_unlock();
54843 + put_files_struct(files);
54844 + } while_each_thread(p2, p);
54845 + read_unlock(&tasklist_lock);
54846 +
54847 + fput(our_file);
54848 + return 1;
54849 +}
54850 +
54851 +static int gr_rbac_disable(void *unused)
54852 +{
54853 + pax_open_kernel();
54854 + gr_status &= ~GR_READY;
54855 + pax_close_kernel();
54856 +
54857 + return 0;
54858 +}
54859 +
54860 +ssize_t
54861 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54862 +{
54863 + struct gr_arg_wrapper uwrap;
54864 + unsigned char *sprole_salt = NULL;
54865 + unsigned char *sprole_sum = NULL;
54866 + int error = sizeof (struct gr_arg_wrapper);
54867 + int error2 = 0;
54868 +
54869 + mutex_lock(&gr_dev_mutex);
54870 +
54871 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54872 + error = -EPERM;
54873 + goto out;
54874 + }
54875 +
54876 + if (count != sizeof (struct gr_arg_wrapper)) {
54877 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54878 + error = -EINVAL;
54879 + goto out;
54880 + }
54881 +
54882 +
54883 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54884 + gr_auth_expires = 0;
54885 + gr_auth_attempts = 0;
54886 + }
54887 +
54888 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54889 + error = -EFAULT;
54890 + goto out;
54891 + }
54892 +
54893 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54894 + error = -EINVAL;
54895 + goto out;
54896 + }
54897 +
54898 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54899 + error = -EFAULT;
54900 + goto out;
54901 + }
54902 +
54903 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54904 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54905 + time_after(gr_auth_expires, get_seconds())) {
54906 + error = -EBUSY;
54907 + goto out;
54908 + }
54909 +
54910 + /* if non-root trying to do anything other than use a special role,
54911 + do not attempt authentication, do not count towards authentication
54912 + locking
54913 + */
54914 +
54915 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54916 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54917 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54918 + error = -EPERM;
54919 + goto out;
54920 + }
54921 +
54922 + /* ensure pw and special role name are null terminated */
54923 +
54924 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54925 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54926 +
54927 + /* Okay.
54928 + * We have our enough of the argument structure..(we have yet
54929 + * to copy_from_user the tables themselves) . Copy the tables
54930 + * only if we need them, i.e. for loading operations. */
54931 +
54932 + switch (gr_usermode->mode) {
54933 + case GR_STATUS:
54934 + if (gr_status & GR_READY) {
54935 + error = 1;
54936 + if (!gr_check_secure_terminal(current))
54937 + error = 3;
54938 + } else
54939 + error = 2;
54940 + goto out;
54941 + case GR_SHUTDOWN:
54942 + if ((gr_status & GR_READY)
54943 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54944 + stop_machine(gr_rbac_disable, NULL, NULL);
54945 + free_variables();
54946 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54947 + memset(gr_system_salt, 0, GR_SALT_LEN);
54948 + memset(gr_system_sum, 0, GR_SHA_LEN);
54949 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54950 + } else if (gr_status & GR_READY) {
54951 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54952 + error = -EPERM;
54953 + } else {
54954 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54955 + error = -EAGAIN;
54956 + }
54957 + break;
54958 + case GR_ENABLE:
54959 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54960 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54961 + else {
54962 + if (gr_status & GR_READY)
54963 + error = -EAGAIN;
54964 + else
54965 + error = error2;
54966 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54967 + }
54968 + break;
54969 + case GR_RELOAD:
54970 + if (!(gr_status & GR_READY)) {
54971 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54972 + error = -EAGAIN;
54973 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54974 + stop_machine(gr_rbac_disable, NULL, NULL);
54975 + free_variables();
54976 + error2 = gracl_init(gr_usermode);
54977 + if (!error2)
54978 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54979 + else {
54980 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54981 + error = error2;
54982 + }
54983 + } else {
54984 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54985 + error = -EPERM;
54986 + }
54987 + break;
54988 + case GR_SEGVMOD:
54989 + if (unlikely(!(gr_status & GR_READY))) {
54990 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54991 + error = -EAGAIN;
54992 + break;
54993 + }
54994 +
54995 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54996 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54997 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54998 + struct acl_subject_label *segvacl;
54999 + segvacl =
55000 + lookup_acl_subj_label(gr_usermode->segv_inode,
55001 + gr_usermode->segv_device,
55002 + current->role);
55003 + if (segvacl) {
55004 + segvacl->crashes = 0;
55005 + segvacl->expires = 0;
55006 + }
55007 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
55008 + gr_remove_uid(gr_usermode->segv_uid);
55009 + }
55010 + } else {
55011 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
55012 + error = -EPERM;
55013 + }
55014 + break;
55015 + case GR_SPROLE:
55016 + case GR_SPROLEPAM:
55017 + if (unlikely(!(gr_status & GR_READY))) {
55018 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
55019 + error = -EAGAIN;
55020 + break;
55021 + }
55022 +
55023 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
55024 + current->role->expires = 0;
55025 + current->role->auth_attempts = 0;
55026 + }
55027 +
55028 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
55029 + time_after(current->role->expires, get_seconds())) {
55030 + error = -EBUSY;
55031 + goto out;
55032 + }
55033 +
55034 + if (lookup_special_role_auth
55035 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
55036 + && ((!sprole_salt && !sprole_sum)
55037 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
55038 + char *p = "";
55039 + assign_special_role(gr_usermode->sp_role);
55040 + read_lock(&tasklist_lock);
55041 + if (current->real_parent)
55042 + p = current->real_parent->role->rolename;
55043 + read_unlock(&tasklist_lock);
55044 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
55045 + p, acl_sp_role_value);
55046 + } else {
55047 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
55048 + error = -EPERM;
55049 + if(!(current->role->auth_attempts++))
55050 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55051 +
55052 + goto out;
55053 + }
55054 + break;
55055 + case GR_UNSPROLE:
55056 + if (unlikely(!(gr_status & GR_READY))) {
55057 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55058 + error = -EAGAIN;
55059 + break;
55060 + }
55061 +
55062 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55063 + char *p = "";
55064 + int i = 0;
55065 +
55066 + read_lock(&tasklist_lock);
55067 + if (current->real_parent) {
55068 + p = current->real_parent->role->rolename;
55069 + i = current->real_parent->acl_role_id;
55070 + }
55071 + read_unlock(&tasklist_lock);
55072 +
55073 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55074 + gr_set_acls(1);
55075 + } else {
55076 + error = -EPERM;
55077 + goto out;
55078 + }
55079 + break;
55080 + default:
55081 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55082 + error = -EINVAL;
55083 + break;
55084 + }
55085 +
55086 + if (error != -EPERM)
55087 + goto out;
55088 +
55089 + if(!(gr_auth_attempts++))
55090 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55091 +
55092 + out:
55093 + mutex_unlock(&gr_dev_mutex);
55094 + return error;
55095 +}
55096 +
55097 +/* must be called with
55098 + rcu_read_lock();
55099 + read_lock(&tasklist_lock);
55100 + read_lock(&grsec_exec_file_lock);
55101 +*/
55102 +int gr_apply_subject_to_task(struct task_struct *task)
55103 +{
55104 + struct acl_object_label *obj;
55105 + char *tmpname;
55106 + struct acl_subject_label *tmpsubj;
55107 + struct file *filp;
55108 + struct name_entry *nmatch;
55109 +
55110 + filp = task->exec_file;
55111 + if (filp == NULL)
55112 + return 0;
55113 +
55114 + /* the following is to apply the correct subject
55115 + on binaries running when the RBAC system
55116 + is enabled, when the binaries have been
55117 + replaced or deleted since their execution
55118 + -----
55119 + when the RBAC system starts, the inode/dev
55120 + from exec_file will be one the RBAC system
55121 + is unaware of. It only knows the inode/dev
55122 + of the present file on disk, or the absence
55123 + of it.
55124 + */
55125 + preempt_disable();
55126 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55127 +
55128 + nmatch = lookup_name_entry(tmpname);
55129 + preempt_enable();
55130 + tmpsubj = NULL;
55131 + if (nmatch) {
55132 + if (nmatch->deleted)
55133 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55134 + else
55135 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55136 + if (tmpsubj != NULL)
55137 + task->acl = tmpsubj;
55138 + }
55139 + if (tmpsubj == NULL)
55140 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55141 + task->role);
55142 + if (task->acl) {
55143 + task->is_writable = 0;
55144 + /* ignore additional mmap checks for processes that are writable
55145 + by the default ACL */
55146 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55147 + if (unlikely(obj->mode & GR_WRITE))
55148 + task->is_writable = 1;
55149 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55150 + if (unlikely(obj->mode & GR_WRITE))
55151 + task->is_writable = 1;
55152 +
55153 + gr_set_proc_res(task);
55154 +
55155 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55156 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55157 +#endif
55158 + } else {
55159 + return 1;
55160 + }
55161 +
55162 + return 0;
55163 +}
55164 +
55165 +int
55166 +gr_set_acls(const int type)
55167 +{
55168 + struct task_struct *task, *task2;
55169 + struct acl_role_label *role = current->role;
55170 + __u16 acl_role_id = current->acl_role_id;
55171 + const struct cred *cred;
55172 + int ret;
55173 +
55174 + rcu_read_lock();
55175 + read_lock(&tasklist_lock);
55176 + read_lock(&grsec_exec_file_lock);
55177 + do_each_thread(task2, task) {
55178 + /* check to see if we're called from the exit handler,
55179 + if so, only replace ACLs that have inherited the admin
55180 + ACL */
55181 +
55182 + if (type && (task->role != role ||
55183 + task->acl_role_id != acl_role_id))
55184 + continue;
55185 +
55186 + task->acl_role_id = 0;
55187 + task->acl_sp_role = 0;
55188 +
55189 + if (task->exec_file) {
55190 + cred = __task_cred(task);
55191 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55192 + ret = gr_apply_subject_to_task(task);
55193 + if (ret) {
55194 + read_unlock(&grsec_exec_file_lock);
55195 + read_unlock(&tasklist_lock);
55196 + rcu_read_unlock();
55197 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55198 + return ret;
55199 + }
55200 + } else {
55201 + // it's a kernel process
55202 + task->role = kernel_role;
55203 + task->acl = kernel_role->root_label;
55204 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55205 + task->acl->mode &= ~GR_PROCFIND;
55206 +#endif
55207 + }
55208 + } while_each_thread(task2, task);
55209 + read_unlock(&grsec_exec_file_lock);
55210 + read_unlock(&tasklist_lock);
55211 + rcu_read_unlock();
55212 +
55213 + return 0;
55214 +}
55215 +
55216 +void
55217 +gr_learn_resource(const struct task_struct *task,
55218 + const int res, const unsigned long wanted, const int gt)
55219 +{
55220 + struct acl_subject_label *acl;
55221 + const struct cred *cred;
55222 +
55223 + if (unlikely((gr_status & GR_READY) &&
55224 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55225 + goto skip_reslog;
55226 +
55227 +#ifdef CONFIG_GRKERNSEC_RESLOG
55228 + gr_log_resource(task, res, wanted, gt);
55229 +#endif
55230 + skip_reslog:
55231 +
55232 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55233 + return;
55234 +
55235 + acl = task->acl;
55236 +
55237 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55238 + !(acl->resmask & (1 << (unsigned short) res))))
55239 + return;
55240 +
55241 + if (wanted >= acl->res[res].rlim_cur) {
55242 + unsigned long res_add;
55243 +
55244 + res_add = wanted;
55245 + switch (res) {
55246 + case RLIMIT_CPU:
55247 + res_add += GR_RLIM_CPU_BUMP;
55248 + break;
55249 + case RLIMIT_FSIZE:
55250 + res_add += GR_RLIM_FSIZE_BUMP;
55251 + break;
55252 + case RLIMIT_DATA:
55253 + res_add += GR_RLIM_DATA_BUMP;
55254 + break;
55255 + case RLIMIT_STACK:
55256 + res_add += GR_RLIM_STACK_BUMP;
55257 + break;
55258 + case RLIMIT_CORE:
55259 + res_add += GR_RLIM_CORE_BUMP;
55260 + break;
55261 + case RLIMIT_RSS:
55262 + res_add += GR_RLIM_RSS_BUMP;
55263 + break;
55264 + case RLIMIT_NPROC:
55265 + res_add += GR_RLIM_NPROC_BUMP;
55266 + break;
55267 + case RLIMIT_NOFILE:
55268 + res_add += GR_RLIM_NOFILE_BUMP;
55269 + break;
55270 + case RLIMIT_MEMLOCK:
55271 + res_add += GR_RLIM_MEMLOCK_BUMP;
55272 + break;
55273 + case RLIMIT_AS:
55274 + res_add += GR_RLIM_AS_BUMP;
55275 + break;
55276 + case RLIMIT_LOCKS:
55277 + res_add += GR_RLIM_LOCKS_BUMP;
55278 + break;
55279 + case RLIMIT_SIGPENDING:
55280 + res_add += GR_RLIM_SIGPENDING_BUMP;
55281 + break;
55282 + case RLIMIT_MSGQUEUE:
55283 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55284 + break;
55285 + case RLIMIT_NICE:
55286 + res_add += GR_RLIM_NICE_BUMP;
55287 + break;
55288 + case RLIMIT_RTPRIO:
55289 + res_add += GR_RLIM_RTPRIO_BUMP;
55290 + break;
55291 + case RLIMIT_RTTIME:
55292 + res_add += GR_RLIM_RTTIME_BUMP;
55293 + break;
55294 + }
55295 +
55296 + acl->res[res].rlim_cur = res_add;
55297 +
55298 + if (wanted > acl->res[res].rlim_max)
55299 + acl->res[res].rlim_max = res_add;
55300 +
55301 + /* only log the subject filename, since resource logging is supported for
55302 + single-subject learning only */
55303 + rcu_read_lock();
55304 + cred = __task_cred(task);
55305 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55306 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55307 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55308 + "", (unsigned long) res, &task->signal->saved_ip);
55309 + rcu_read_unlock();
55310 + }
55311 +
55312 + return;
55313 +}
55314 +
55315 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55316 +void
55317 +pax_set_initial_flags(struct linux_binprm *bprm)
55318 +{
55319 + struct task_struct *task = current;
55320 + struct acl_subject_label *proc;
55321 + unsigned long flags;
55322 +
55323 + if (unlikely(!(gr_status & GR_READY)))
55324 + return;
55325 +
55326 + flags = pax_get_flags(task);
55327 +
55328 + proc = task->acl;
55329 +
55330 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55331 + flags &= ~MF_PAX_PAGEEXEC;
55332 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55333 + flags &= ~MF_PAX_SEGMEXEC;
55334 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55335 + flags &= ~MF_PAX_RANDMMAP;
55336 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55337 + flags &= ~MF_PAX_EMUTRAMP;
55338 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55339 + flags &= ~MF_PAX_MPROTECT;
55340 +
55341 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55342 + flags |= MF_PAX_PAGEEXEC;
55343 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55344 + flags |= MF_PAX_SEGMEXEC;
55345 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55346 + flags |= MF_PAX_RANDMMAP;
55347 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55348 + flags |= MF_PAX_EMUTRAMP;
55349 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55350 + flags |= MF_PAX_MPROTECT;
55351 +
55352 + pax_set_flags(task, flags);
55353 +
55354 + return;
55355 +}
55356 +#endif
55357 +
55358 +int
55359 +gr_handle_proc_ptrace(struct task_struct *task)
55360 +{
55361 + struct file *filp;
55362 + struct task_struct *tmp = task;
55363 + struct task_struct *curtemp = current;
55364 + __u32 retmode;
55365 +
55366 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55367 + if (unlikely(!(gr_status & GR_READY)))
55368 + return 0;
55369 +#endif
55370 +
55371 + read_lock(&tasklist_lock);
55372 + read_lock(&grsec_exec_file_lock);
55373 + filp = task->exec_file;
55374 +
55375 + while (tmp->pid > 0) {
55376 + if (tmp == curtemp)
55377 + break;
55378 + tmp = tmp->real_parent;
55379 + }
55380 +
55381 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55382 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55383 + read_unlock(&grsec_exec_file_lock);
55384 + read_unlock(&tasklist_lock);
55385 + return 1;
55386 + }
55387 +
55388 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55389 + if (!(gr_status & GR_READY)) {
55390 + read_unlock(&grsec_exec_file_lock);
55391 + read_unlock(&tasklist_lock);
55392 + return 0;
55393 + }
55394 +#endif
55395 +
55396 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55397 + read_unlock(&grsec_exec_file_lock);
55398 + read_unlock(&tasklist_lock);
55399 +
55400 + if (retmode & GR_NOPTRACE)
55401 + return 1;
55402 +
55403 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55404 + && (current->acl != task->acl || (current->acl != current->role->root_label
55405 + && current->pid != task->pid)))
55406 + return 1;
55407 +
55408 + return 0;
55409 +}
55410 +
55411 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55412 +{
55413 + if (unlikely(!(gr_status & GR_READY)))
55414 + return;
55415 +
55416 + if (!(current->role->roletype & GR_ROLE_GOD))
55417 + return;
55418 +
55419 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55420 + p->role->rolename, gr_task_roletype_to_char(p),
55421 + p->acl->filename);
55422 +}
55423 +
55424 +int
55425 +gr_handle_ptrace(struct task_struct *task, const long request)
55426 +{
55427 + struct task_struct *tmp = task;
55428 + struct task_struct *curtemp = current;
55429 + __u32 retmode;
55430 +
55431 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55432 + if (unlikely(!(gr_status & GR_READY)))
55433 + return 0;
55434 +#endif
55435 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55436 + read_lock(&tasklist_lock);
55437 + while (tmp->pid > 0) {
55438 + if (tmp == curtemp)
55439 + break;
55440 + tmp = tmp->real_parent;
55441 + }
55442 +
55443 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55444 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55445 + read_unlock(&tasklist_lock);
55446 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55447 + return 1;
55448 + }
55449 + read_unlock(&tasklist_lock);
55450 + }
55451 +
55452 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55453 + if (!(gr_status & GR_READY))
55454 + return 0;
55455 +#endif
55456 +
55457 + read_lock(&grsec_exec_file_lock);
55458 + if (unlikely(!task->exec_file)) {
55459 + read_unlock(&grsec_exec_file_lock);
55460 + return 0;
55461 + }
55462 +
55463 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55464 + read_unlock(&grsec_exec_file_lock);
55465 +
55466 + if (retmode & GR_NOPTRACE) {
55467 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55468 + return 1;
55469 + }
55470 +
55471 + if (retmode & GR_PTRACERD) {
55472 + switch (request) {
55473 + case PTRACE_SEIZE:
55474 + case PTRACE_POKETEXT:
55475 + case PTRACE_POKEDATA:
55476 + case PTRACE_POKEUSR:
55477 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55478 + case PTRACE_SETREGS:
55479 + case PTRACE_SETFPREGS:
55480 +#endif
55481 +#ifdef CONFIG_X86
55482 + case PTRACE_SETFPXREGS:
55483 +#endif
55484 +#ifdef CONFIG_ALTIVEC
55485 + case PTRACE_SETVRREGS:
55486 +#endif
55487 + return 1;
55488 + default:
55489 + return 0;
55490 + }
55491 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55492 + !(current->role->roletype & GR_ROLE_GOD) &&
55493 + (current->acl != task->acl)) {
55494 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55495 + return 1;
55496 + }
55497 +
55498 + return 0;
55499 +}
55500 +
55501 +static int is_writable_mmap(const struct file *filp)
55502 +{
55503 + struct task_struct *task = current;
55504 + struct acl_object_label *obj, *obj2;
55505 +
55506 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55507 + !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))) {
55508 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55509 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55510 + task->role->root_label);
55511 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55512 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55513 + return 1;
55514 + }
55515 + }
55516 + return 0;
55517 +}
55518 +
55519 +int
55520 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55521 +{
55522 + __u32 mode;
55523 +
55524 + if (unlikely(!file || !(prot & PROT_EXEC)))
55525 + return 1;
55526 +
55527 + if (is_writable_mmap(file))
55528 + return 0;
55529 +
55530 + mode =
55531 + gr_search_file(file->f_path.dentry,
55532 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55533 + file->f_path.mnt);
55534 +
55535 + if (!gr_tpe_allow(file))
55536 + return 0;
55537 +
55538 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55539 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55540 + return 0;
55541 + } else if (unlikely(!(mode & GR_EXEC))) {
55542 + return 0;
55543 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55544 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55545 + return 1;
55546 + }
55547 +
55548 + return 1;
55549 +}
55550 +
55551 +int
55552 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55553 +{
55554 + __u32 mode;
55555 +
55556 + if (unlikely(!file || !(prot & PROT_EXEC)))
55557 + return 1;
55558 +
55559 + if (is_writable_mmap(file))
55560 + return 0;
55561 +
55562 + mode =
55563 + gr_search_file(file->f_path.dentry,
55564 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55565 + file->f_path.mnt);
55566 +
55567 + if (!gr_tpe_allow(file))
55568 + return 0;
55569 +
55570 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55571 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55572 + return 0;
55573 + } else if (unlikely(!(mode & GR_EXEC))) {
55574 + return 0;
55575 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55576 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55577 + return 1;
55578 + }
55579 +
55580 + return 1;
55581 +}
55582 +
55583 +void
55584 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55585 +{
55586 + unsigned long runtime;
55587 + unsigned long cputime;
55588 + unsigned int wday, cday;
55589 + __u8 whr, chr;
55590 + __u8 wmin, cmin;
55591 + __u8 wsec, csec;
55592 + struct timespec timeval;
55593 +
55594 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55595 + !(task->acl->mode & GR_PROCACCT)))
55596 + return;
55597 +
55598 + do_posix_clock_monotonic_gettime(&timeval);
55599 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55600 + wday = runtime / (3600 * 24);
55601 + runtime -= wday * (3600 * 24);
55602 + whr = runtime / 3600;
55603 + runtime -= whr * 3600;
55604 + wmin = runtime / 60;
55605 + runtime -= wmin * 60;
55606 + wsec = runtime;
55607 +
55608 + cputime = (task->utime + task->stime) / HZ;
55609 + cday = cputime / (3600 * 24);
55610 + cputime -= cday * (3600 * 24);
55611 + chr = cputime / 3600;
55612 + cputime -= chr * 3600;
55613 + cmin = cputime / 60;
55614 + cputime -= cmin * 60;
55615 + csec = cputime;
55616 +
55617 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55618 +
55619 + return;
55620 +}
55621 +
55622 +void gr_set_kernel_label(struct task_struct *task)
55623 +{
55624 + if (gr_status & GR_READY) {
55625 + task->role = kernel_role;
55626 + task->acl = kernel_role->root_label;
55627 + }
55628 + return;
55629 +}
55630 +
55631 +#ifdef CONFIG_TASKSTATS
55632 +int gr_is_taskstats_denied(int pid)
55633 +{
55634 + struct task_struct *task;
55635 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55636 + const struct cred *cred;
55637 +#endif
55638 + int ret = 0;
55639 +
55640 + /* restrict taskstats viewing to un-chrooted root users
55641 + who have the 'view' subject flag if the RBAC system is enabled
55642 + */
55643 +
55644 + rcu_read_lock();
55645 + read_lock(&tasklist_lock);
55646 + task = find_task_by_vpid(pid);
55647 + if (task) {
55648 +#ifdef CONFIG_GRKERNSEC_CHROOT
55649 + if (proc_is_chrooted(task))
55650 + ret = -EACCES;
55651 +#endif
55652 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55653 + cred = __task_cred(task);
55654 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55655 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55656 + ret = -EACCES;
55657 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55658 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55659 + ret = -EACCES;
55660 +#endif
55661 +#endif
55662 + if (gr_status & GR_READY) {
55663 + if (!(task->acl->mode & GR_VIEW))
55664 + ret = -EACCES;
55665 + }
55666 + } else
55667 + ret = -ENOENT;
55668 +
55669 + read_unlock(&tasklist_lock);
55670 + rcu_read_unlock();
55671 +
55672 + return ret;
55673 +}
55674 +#endif
55675 +
55676 +/* AUXV entries are filled via a descendant of search_binary_handler
55677 + after we've already applied the subject for the target
55678 +*/
55679 +int gr_acl_enable_at_secure(void)
55680 +{
55681 + if (unlikely(!(gr_status & GR_READY)))
55682 + return 0;
55683 +
55684 + if (current->acl->mode & GR_ATSECURE)
55685 + return 1;
55686 +
55687 + return 0;
55688 +}
55689 +
55690 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55691 +{
55692 + struct task_struct *task = current;
55693 + struct dentry *dentry = file->f_path.dentry;
55694 + struct vfsmount *mnt = file->f_path.mnt;
55695 + struct acl_object_label *obj, *tmp;
55696 + struct acl_subject_label *subj;
55697 + unsigned int bufsize;
55698 + int is_not_root;
55699 + char *path;
55700 + dev_t dev = __get_dev(dentry);
55701 +
55702 + if (unlikely(!(gr_status & GR_READY)))
55703 + return 1;
55704 +
55705 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55706 + return 1;
55707 +
55708 + /* ignore Eric Biederman */
55709 + if (IS_PRIVATE(dentry->d_inode))
55710 + return 1;
55711 +
55712 + subj = task->acl;
55713 + read_lock(&gr_inode_lock);
55714 + do {
55715 + obj = lookup_acl_obj_label(ino, dev, subj);
55716 + if (obj != NULL) {
55717 + read_unlock(&gr_inode_lock);
55718 + return (obj->mode & GR_FIND) ? 1 : 0;
55719 + }
55720 + } while ((subj = subj->parent_subject));
55721 + read_unlock(&gr_inode_lock);
55722 +
55723 + /* this is purely an optimization since we're looking for an object
55724 + for the directory we're doing a readdir on
55725 + if it's possible for any globbed object to match the entry we're
55726 + filling into the directory, then the object we find here will be
55727 + an anchor point with attached globbed objects
55728 + */
55729 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55730 + if (obj->globbed == NULL)
55731 + return (obj->mode & GR_FIND) ? 1 : 0;
55732 +
55733 + is_not_root = ((obj->filename[0] == '/') &&
55734 + (obj->filename[1] == '\0')) ? 0 : 1;
55735 + bufsize = PAGE_SIZE - namelen - is_not_root;
55736 +
55737 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55738 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55739 + return 1;
55740 +
55741 + preempt_disable();
55742 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55743 + bufsize);
55744 +
55745 + bufsize = strlen(path);
55746 +
55747 + /* if base is "/", don't append an additional slash */
55748 + if (is_not_root)
55749 + *(path + bufsize) = '/';
55750 + memcpy(path + bufsize + is_not_root, name, namelen);
55751 + *(path + bufsize + namelen + is_not_root) = '\0';
55752 +
55753 + tmp = obj->globbed;
55754 + while (tmp) {
55755 + if (!glob_match(tmp->filename, path)) {
55756 + preempt_enable();
55757 + return (tmp->mode & GR_FIND) ? 1 : 0;
55758 + }
55759 + tmp = tmp->next;
55760 + }
55761 + preempt_enable();
55762 + return (obj->mode & GR_FIND) ? 1 : 0;
55763 +}
55764 +
55765 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55766 +EXPORT_SYMBOL(gr_acl_is_enabled);
55767 +#endif
55768 +EXPORT_SYMBOL(gr_learn_resource);
55769 +EXPORT_SYMBOL(gr_set_kernel_label);
55770 +#ifdef CONFIG_SECURITY
55771 +EXPORT_SYMBOL(gr_check_user_change);
55772 +EXPORT_SYMBOL(gr_check_group_change);
55773 +#endif
55774 +
55775 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55776 new file mode 100644
55777 index 0000000..34fefda
55778 --- /dev/null
55779 +++ b/grsecurity/gracl_alloc.c
55780 @@ -0,0 +1,105 @@
55781 +#include <linux/kernel.h>
55782 +#include <linux/mm.h>
55783 +#include <linux/slab.h>
55784 +#include <linux/vmalloc.h>
55785 +#include <linux/gracl.h>
55786 +#include <linux/grsecurity.h>
55787 +
55788 +static unsigned long alloc_stack_next = 1;
55789 +static unsigned long alloc_stack_size = 1;
55790 +static void **alloc_stack;
55791 +
55792 +static __inline__ int
55793 +alloc_pop(void)
55794 +{
55795 + if (alloc_stack_next == 1)
55796 + return 0;
55797 +
55798 + kfree(alloc_stack[alloc_stack_next - 2]);
55799 +
55800 + alloc_stack_next--;
55801 +
55802 + return 1;
55803 +}
55804 +
55805 +static __inline__ int
55806 +alloc_push(void *buf)
55807 +{
55808 + if (alloc_stack_next >= alloc_stack_size)
55809 + return 1;
55810 +
55811 + alloc_stack[alloc_stack_next - 1] = buf;
55812 +
55813 + alloc_stack_next++;
55814 +
55815 + return 0;
55816 +}
55817 +
55818 +void *
55819 +acl_alloc(unsigned long len)
55820 +{
55821 + void *ret = NULL;
55822 +
55823 + if (!len || len > PAGE_SIZE)
55824 + goto out;
55825 +
55826 + ret = kmalloc(len, GFP_KERNEL);
55827 +
55828 + if (ret) {
55829 + if (alloc_push(ret)) {
55830 + kfree(ret);
55831 + ret = NULL;
55832 + }
55833 + }
55834 +
55835 +out:
55836 + return ret;
55837 +}
55838 +
55839 +void *
55840 +acl_alloc_num(unsigned long num, unsigned long len)
55841 +{
55842 + if (!len || (num > (PAGE_SIZE / len)))
55843 + return NULL;
55844 +
55845 + return acl_alloc(num * len);
55846 +}
55847 +
55848 +void
55849 +acl_free_all(void)
55850 +{
55851 + if (gr_acl_is_enabled() || !alloc_stack)
55852 + return;
55853 +
55854 + while (alloc_pop()) ;
55855 +
55856 + if (alloc_stack) {
55857 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55858 + kfree(alloc_stack);
55859 + else
55860 + vfree(alloc_stack);
55861 + }
55862 +
55863 + alloc_stack = NULL;
55864 + alloc_stack_size = 1;
55865 + alloc_stack_next = 1;
55866 +
55867 + return;
55868 +}
55869 +
55870 +int
55871 +acl_alloc_stack_init(unsigned long size)
55872 +{
55873 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55874 + alloc_stack =
55875 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55876 + else
55877 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55878 +
55879 + alloc_stack_size = size;
55880 +
55881 + if (!alloc_stack)
55882 + return 0;
55883 + else
55884 + return 1;
55885 +}
55886 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55887 new file mode 100644
55888 index 0000000..6d21049
55889 --- /dev/null
55890 +++ b/grsecurity/gracl_cap.c
55891 @@ -0,0 +1,110 @@
55892 +#include <linux/kernel.h>
55893 +#include <linux/module.h>
55894 +#include <linux/sched.h>
55895 +#include <linux/gracl.h>
55896 +#include <linux/grsecurity.h>
55897 +#include <linux/grinternal.h>
55898 +
55899 +extern const char *captab_log[];
55900 +extern int captab_log_entries;
55901 +
55902 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55903 +{
55904 + struct acl_subject_label *curracl;
55905 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55906 + kernel_cap_t cap_audit = __cap_empty_set;
55907 +
55908 + if (!gr_acl_is_enabled())
55909 + return 1;
55910 +
55911 + curracl = task->acl;
55912 +
55913 + cap_drop = curracl->cap_lower;
55914 + cap_mask = curracl->cap_mask;
55915 + cap_audit = curracl->cap_invert_audit;
55916 +
55917 + while ((curracl = curracl->parent_subject)) {
55918 + /* if the cap isn't specified in the current computed mask but is specified in the
55919 + current level subject, and is lowered in the current level subject, then add
55920 + it to the set of dropped capabilities
55921 + otherwise, add the current level subject's mask to the current computed mask
55922 + */
55923 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55924 + cap_raise(cap_mask, cap);
55925 + if (cap_raised(curracl->cap_lower, cap))
55926 + cap_raise(cap_drop, cap);
55927 + if (cap_raised(curracl->cap_invert_audit, cap))
55928 + cap_raise(cap_audit, cap);
55929 + }
55930 + }
55931 +
55932 + if (!cap_raised(cap_drop, cap)) {
55933 + if (cap_raised(cap_audit, cap))
55934 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55935 + return 1;
55936 + }
55937 +
55938 + curracl = task->acl;
55939 +
55940 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55941 + && cap_raised(cred->cap_effective, cap)) {
55942 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55943 + task->role->roletype, cred->uid,
55944 + cred->gid, task->exec_file ?
55945 + gr_to_filename(task->exec_file->f_path.dentry,
55946 + task->exec_file->f_path.mnt) : curracl->filename,
55947 + curracl->filename, 0UL,
55948 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55949 + return 1;
55950 + }
55951 +
55952 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55953 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55954 +
55955 + return 0;
55956 +}
55957 +
55958 +int
55959 +gr_acl_is_capable(const int cap)
55960 +{
55961 + return gr_task_acl_is_capable(current, current_cred(), cap);
55962 +}
55963 +
55964 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55965 +{
55966 + struct acl_subject_label *curracl;
55967 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __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 +
55977 + while ((curracl = curracl->parent_subject)) {
55978 + /* if the cap isn't specified in the current computed mask but is specified in the
55979 + current level subject, and is lowered in the current level subject, then add
55980 + it to the set of dropped capabilities
55981 + otherwise, add the current level subject's mask to the current computed mask
55982 + */
55983 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55984 + cap_raise(cap_mask, cap);
55985 + if (cap_raised(curracl->cap_lower, cap))
55986 + cap_raise(cap_drop, cap);
55987 + }
55988 + }
55989 +
55990 + if (!cap_raised(cap_drop, cap))
55991 + return 1;
55992 +
55993 + return 0;
55994 +}
55995 +
55996 +int
55997 +gr_acl_is_capable_nolog(const int cap)
55998 +{
55999 + return gr_task_acl_is_capable_nolog(current, cap);
56000 +}
56001 +
56002 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
56003 new file mode 100644
56004 index 0000000..d28e241
56005 --- /dev/null
56006 +++ b/grsecurity/gracl_fs.c
56007 @@ -0,0 +1,437 @@
56008 +#include <linux/kernel.h>
56009 +#include <linux/sched.h>
56010 +#include <linux/types.h>
56011 +#include <linux/fs.h>
56012 +#include <linux/file.h>
56013 +#include <linux/stat.h>
56014 +#include <linux/grsecurity.h>
56015 +#include <linux/grinternal.h>
56016 +#include <linux/gracl.h>
56017 +
56018 +umode_t
56019 +gr_acl_umask(void)
56020 +{
56021 + if (unlikely(!gr_acl_is_enabled()))
56022 + return 0;
56023 +
56024 + return current->role->umask;
56025 +}
56026 +
56027 +__u32
56028 +gr_acl_handle_hidden_file(const struct dentry * dentry,
56029 + const struct vfsmount * mnt)
56030 +{
56031 + __u32 mode;
56032 +
56033 + if (unlikely(!dentry->d_inode))
56034 + return GR_FIND;
56035 +
56036 + mode =
56037 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
56038 +
56039 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
56040 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56041 + return mode;
56042 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
56043 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
56044 + return 0;
56045 + } else if (unlikely(!(mode & GR_FIND)))
56046 + return 0;
56047 +
56048 + return GR_FIND;
56049 +}
56050 +
56051 +__u32
56052 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
56053 + int acc_mode)
56054 +{
56055 + __u32 reqmode = GR_FIND;
56056 + __u32 mode;
56057 +
56058 + if (unlikely(!dentry->d_inode))
56059 + return reqmode;
56060 +
56061 + if (acc_mode & MAY_APPEND)
56062 + reqmode |= GR_APPEND;
56063 + else if (acc_mode & MAY_WRITE)
56064 + reqmode |= GR_WRITE;
56065 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56066 + reqmode |= GR_READ;
56067 +
56068 + mode =
56069 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56070 + mnt);
56071 +
56072 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56073 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56074 + reqmode & GR_READ ? " reading" : "",
56075 + reqmode & GR_WRITE ? " writing" : reqmode &
56076 + GR_APPEND ? " appending" : "");
56077 + return reqmode;
56078 + } else
56079 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56080 + {
56081 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56082 + reqmode & GR_READ ? " reading" : "",
56083 + reqmode & GR_WRITE ? " writing" : reqmode &
56084 + GR_APPEND ? " appending" : "");
56085 + return 0;
56086 + } else if (unlikely((mode & reqmode) != reqmode))
56087 + return 0;
56088 +
56089 + return reqmode;
56090 +}
56091 +
56092 +__u32
56093 +gr_acl_handle_creat(const struct dentry * dentry,
56094 + const struct dentry * p_dentry,
56095 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56096 + const int imode)
56097 +{
56098 + __u32 reqmode = GR_WRITE | GR_CREATE;
56099 + __u32 mode;
56100 +
56101 + if (acc_mode & MAY_APPEND)
56102 + reqmode |= GR_APPEND;
56103 + // if a directory was required or the directory already exists, then
56104 + // don't count this open as a read
56105 + if ((acc_mode & MAY_READ) &&
56106 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56107 + reqmode |= GR_READ;
56108 + if ((open_flags & O_CREAT) &&
56109 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56110 + reqmode |= GR_SETID;
56111 +
56112 + mode =
56113 + gr_check_create(dentry, p_dentry, p_mnt,
56114 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56115 +
56116 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56117 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56118 + reqmode & GR_READ ? " reading" : "",
56119 + reqmode & GR_WRITE ? " writing" : reqmode &
56120 + GR_APPEND ? " appending" : "");
56121 + return reqmode;
56122 + } else
56123 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56124 + {
56125 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56126 + reqmode & GR_READ ? " reading" : "",
56127 + reqmode & GR_WRITE ? " writing" : reqmode &
56128 + GR_APPEND ? " appending" : "");
56129 + return 0;
56130 + } else if (unlikely((mode & reqmode) != reqmode))
56131 + return 0;
56132 +
56133 + return reqmode;
56134 +}
56135 +
56136 +__u32
56137 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56138 + const int fmode)
56139 +{
56140 + __u32 mode, reqmode = GR_FIND;
56141 +
56142 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56143 + reqmode |= GR_EXEC;
56144 + if (fmode & S_IWOTH)
56145 + reqmode |= GR_WRITE;
56146 + if (fmode & S_IROTH)
56147 + reqmode |= GR_READ;
56148 +
56149 + mode =
56150 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56151 + mnt);
56152 +
56153 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56154 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56155 + reqmode & GR_READ ? " reading" : "",
56156 + reqmode & GR_WRITE ? " writing" : "",
56157 + reqmode & GR_EXEC ? " executing" : "");
56158 + return reqmode;
56159 + } else
56160 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56161 + {
56162 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56163 + reqmode & GR_READ ? " reading" : "",
56164 + reqmode & GR_WRITE ? " writing" : "",
56165 + reqmode & GR_EXEC ? " executing" : "");
56166 + return 0;
56167 + } else if (unlikely((mode & reqmode) != reqmode))
56168 + return 0;
56169 +
56170 + return reqmode;
56171 +}
56172 +
56173 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56174 +{
56175 + __u32 mode;
56176 +
56177 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56178 +
56179 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56180 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56181 + return mode;
56182 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56183 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56184 + return 0;
56185 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56186 + return 0;
56187 +
56188 + return (reqmode);
56189 +}
56190 +
56191 +__u32
56192 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56193 +{
56194 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56195 +}
56196 +
56197 +__u32
56198 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56199 +{
56200 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56201 +}
56202 +
56203 +__u32
56204 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56205 +{
56206 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56207 +}
56208 +
56209 +__u32
56210 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56211 +{
56212 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56213 +}
56214 +
56215 +__u32
56216 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56217 + umode_t *modeptr)
56218 +{
56219 + umode_t mode;
56220 +
56221 + *modeptr &= ~gr_acl_umask();
56222 + mode = *modeptr;
56223 +
56224 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56225 + return 1;
56226 +
56227 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56228 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56229 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56230 + GR_CHMOD_ACL_MSG);
56231 + } else {
56232 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56233 + }
56234 +}
56235 +
56236 +__u32
56237 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56238 +{
56239 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56240 +}
56241 +
56242 +__u32
56243 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56244 +{
56245 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56246 +}
56247 +
56248 +__u32
56249 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56250 +{
56251 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56252 +}
56253 +
56254 +__u32
56255 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56256 +{
56257 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56258 + GR_UNIXCONNECT_ACL_MSG);
56259 +}
56260 +
56261 +/* hardlinks require at minimum create and link permission,
56262 + any additional privilege required is based on the
56263 + privilege of the file being linked to
56264 +*/
56265 +__u32
56266 +gr_acl_handle_link(const struct dentry * new_dentry,
56267 + const struct dentry * parent_dentry,
56268 + const struct vfsmount * parent_mnt,
56269 + const struct dentry * old_dentry,
56270 + const struct vfsmount * old_mnt, const char *to)
56271 +{
56272 + __u32 mode;
56273 + __u32 needmode = GR_CREATE | GR_LINK;
56274 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56275 +
56276 + mode =
56277 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56278 + old_mnt);
56279 +
56280 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56281 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56282 + return mode;
56283 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56284 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56285 + return 0;
56286 + } else if (unlikely((mode & needmode) != needmode))
56287 + return 0;
56288 +
56289 + return 1;
56290 +}
56291 +
56292 +__u32
56293 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56294 + const struct dentry * parent_dentry,
56295 + const struct vfsmount * parent_mnt, const char *from)
56296 +{
56297 + __u32 needmode = GR_WRITE | GR_CREATE;
56298 + __u32 mode;
56299 +
56300 + mode =
56301 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56302 + GR_CREATE | GR_AUDIT_CREATE |
56303 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56304 +
56305 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56306 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56307 + return mode;
56308 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56309 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56310 + return 0;
56311 + } else if (unlikely((mode & needmode) != needmode))
56312 + return 0;
56313 +
56314 + return (GR_WRITE | GR_CREATE);
56315 +}
56316 +
56317 +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)
56318 +{
56319 + __u32 mode;
56320 +
56321 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56322 +
56323 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56324 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56325 + return mode;
56326 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56327 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56328 + return 0;
56329 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56330 + return 0;
56331 +
56332 + return (reqmode);
56333 +}
56334 +
56335 +__u32
56336 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56337 + const struct dentry * parent_dentry,
56338 + const struct vfsmount * parent_mnt,
56339 + const int mode)
56340 +{
56341 + __u32 reqmode = GR_WRITE | GR_CREATE;
56342 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56343 + reqmode |= GR_SETID;
56344 +
56345 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56346 + reqmode, GR_MKNOD_ACL_MSG);
56347 +}
56348 +
56349 +__u32
56350 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56351 + const struct dentry *parent_dentry,
56352 + const struct vfsmount *parent_mnt)
56353 +{
56354 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56355 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56356 +}
56357 +
56358 +#define RENAME_CHECK_SUCCESS(old, new) \
56359 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56360 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56361 +
56362 +int
56363 +gr_acl_handle_rename(struct dentry *new_dentry,
56364 + struct dentry *parent_dentry,
56365 + const struct vfsmount *parent_mnt,
56366 + struct dentry *old_dentry,
56367 + struct inode *old_parent_inode,
56368 + struct vfsmount *old_mnt, const char *newname)
56369 +{
56370 + __u32 comp1, comp2;
56371 + int error = 0;
56372 +
56373 + if (unlikely(!gr_acl_is_enabled()))
56374 + return 0;
56375 +
56376 + if (!new_dentry->d_inode) {
56377 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56378 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56379 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56380 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56381 + GR_DELETE | GR_AUDIT_DELETE |
56382 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56383 + GR_SUPPRESS, old_mnt);
56384 + } else {
56385 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56386 + GR_CREATE | GR_DELETE |
56387 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56388 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56389 + GR_SUPPRESS, parent_mnt);
56390 + comp2 =
56391 + gr_search_file(old_dentry,
56392 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56393 + GR_DELETE | GR_AUDIT_DELETE |
56394 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56395 + }
56396 +
56397 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56398 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56399 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56400 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56401 + && !(comp2 & GR_SUPPRESS)) {
56402 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56403 + error = -EACCES;
56404 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56405 + error = -EACCES;
56406 +
56407 + return error;
56408 +}
56409 +
56410 +void
56411 +gr_acl_handle_exit(void)
56412 +{
56413 + u16 id;
56414 + char *rolename;
56415 + struct file *exec_file;
56416 +
56417 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56418 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56419 + id = current->acl_role_id;
56420 + rolename = current->role->rolename;
56421 + gr_set_acls(1);
56422 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56423 + }
56424 +
56425 + write_lock(&grsec_exec_file_lock);
56426 + exec_file = current->exec_file;
56427 + current->exec_file = NULL;
56428 + write_unlock(&grsec_exec_file_lock);
56429 +
56430 + if (exec_file)
56431 + fput(exec_file);
56432 +}
56433 +
56434 +int
56435 +gr_acl_handle_procpidmem(const struct task_struct *task)
56436 +{
56437 + if (unlikely(!gr_acl_is_enabled()))
56438 + return 0;
56439 +
56440 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56441 + return -EACCES;
56442 +
56443 + return 0;
56444 +}
56445 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56446 new file mode 100644
56447 index 0000000..58800a7
56448 --- /dev/null
56449 +++ b/grsecurity/gracl_ip.c
56450 @@ -0,0 +1,384 @@
56451 +#include <linux/kernel.h>
56452 +#include <asm/uaccess.h>
56453 +#include <asm/errno.h>
56454 +#include <net/sock.h>
56455 +#include <linux/file.h>
56456 +#include <linux/fs.h>
56457 +#include <linux/net.h>
56458 +#include <linux/in.h>
56459 +#include <linux/skbuff.h>
56460 +#include <linux/ip.h>
56461 +#include <linux/udp.h>
56462 +#include <linux/types.h>
56463 +#include <linux/sched.h>
56464 +#include <linux/netdevice.h>
56465 +#include <linux/inetdevice.h>
56466 +#include <linux/gracl.h>
56467 +#include <linux/grsecurity.h>
56468 +#include <linux/grinternal.h>
56469 +
56470 +#define GR_BIND 0x01
56471 +#define GR_CONNECT 0x02
56472 +#define GR_INVERT 0x04
56473 +#define GR_BINDOVERRIDE 0x08
56474 +#define GR_CONNECTOVERRIDE 0x10
56475 +#define GR_SOCK_FAMILY 0x20
56476 +
56477 +static const char * gr_protocols[IPPROTO_MAX] = {
56478 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56479 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56480 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56481 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56482 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56483 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56484 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56485 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56486 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56487 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56488 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56489 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56490 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56491 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56492 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56493 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56494 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56495 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56496 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56497 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56498 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56499 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56500 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56501 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56502 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56503 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56504 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56505 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56506 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56507 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56508 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56509 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56510 + };
56511 +
56512 +static const char * gr_socktypes[SOCK_MAX] = {
56513 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56514 + "unknown:7", "unknown:8", "unknown:9", "packet"
56515 + };
56516 +
56517 +static const char * gr_sockfamilies[AF_MAX+1] = {
56518 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56519 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56520 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56521 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56522 + };
56523 +
56524 +const char *
56525 +gr_proto_to_name(unsigned char proto)
56526 +{
56527 + return gr_protocols[proto];
56528 +}
56529 +
56530 +const char *
56531 +gr_socktype_to_name(unsigned char type)
56532 +{
56533 + return gr_socktypes[type];
56534 +}
56535 +
56536 +const char *
56537 +gr_sockfamily_to_name(unsigned char family)
56538 +{
56539 + return gr_sockfamilies[family];
56540 +}
56541 +
56542 +int
56543 +gr_search_socket(const int domain, const int type, const int protocol)
56544 +{
56545 + struct acl_subject_label *curr;
56546 + const struct cred *cred = current_cred();
56547 +
56548 + if (unlikely(!gr_acl_is_enabled()))
56549 + goto exit;
56550 +
56551 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56552 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56553 + goto exit; // let the kernel handle it
56554 +
56555 + curr = current->acl;
56556 +
56557 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56558 + /* the family is allowed, if this is PF_INET allow it only if
56559 + the extra sock type/protocol checks pass */
56560 + if (domain == PF_INET)
56561 + goto inet_check;
56562 + goto exit;
56563 + } else {
56564 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56565 + __u32 fakeip = 0;
56566 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56567 + current->role->roletype, cred->uid,
56568 + cred->gid, current->exec_file ?
56569 + gr_to_filename(current->exec_file->f_path.dentry,
56570 + current->exec_file->f_path.mnt) :
56571 + curr->filename, curr->filename,
56572 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56573 + &current->signal->saved_ip);
56574 + goto exit;
56575 + }
56576 + goto exit_fail;
56577 + }
56578 +
56579 +inet_check:
56580 + /* the rest of this checking is for IPv4 only */
56581 + if (!curr->ips)
56582 + goto exit;
56583 +
56584 + if ((curr->ip_type & (1 << type)) &&
56585 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56586 + goto exit;
56587 +
56588 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56589 + /* we don't place acls on raw sockets , and sometimes
56590 + dgram/ip sockets are opened for ioctl and not
56591 + bind/connect, so we'll fake a bind learn log */
56592 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56593 + __u32 fakeip = 0;
56594 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56595 + current->role->roletype, cred->uid,
56596 + cred->gid, current->exec_file ?
56597 + gr_to_filename(current->exec_file->f_path.dentry,
56598 + current->exec_file->f_path.mnt) :
56599 + curr->filename, curr->filename,
56600 + &fakeip, 0, type,
56601 + protocol, GR_CONNECT, &current->signal->saved_ip);
56602 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56603 + __u32 fakeip = 0;
56604 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56605 + current->role->roletype, cred->uid,
56606 + cred->gid, current->exec_file ?
56607 + gr_to_filename(current->exec_file->f_path.dentry,
56608 + current->exec_file->f_path.mnt) :
56609 + curr->filename, curr->filename,
56610 + &fakeip, 0, type,
56611 + protocol, GR_BIND, &current->signal->saved_ip);
56612 + }
56613 + /* we'll log when they use connect or bind */
56614 + goto exit;
56615 + }
56616 +
56617 +exit_fail:
56618 + if (domain == PF_INET)
56619 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56620 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56621 + else
56622 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56623 + gr_socktype_to_name(type), protocol);
56624 +
56625 + return 0;
56626 +exit:
56627 + return 1;
56628 +}
56629 +
56630 +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)
56631 +{
56632 + if ((ip->mode & mode) &&
56633 + (ip_port >= ip->low) &&
56634 + (ip_port <= ip->high) &&
56635 + ((ntohl(ip_addr) & our_netmask) ==
56636 + (ntohl(our_addr) & our_netmask))
56637 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56638 + && (ip->type & (1 << type))) {
56639 + if (ip->mode & GR_INVERT)
56640 + return 2; // specifically denied
56641 + else
56642 + return 1; // allowed
56643 + }
56644 +
56645 + return 0; // not specifically allowed, may continue parsing
56646 +}
56647 +
56648 +static int
56649 +gr_search_connectbind(const int full_mode, struct sock *sk,
56650 + struct sockaddr_in *addr, const int type)
56651 +{
56652 + char iface[IFNAMSIZ] = {0};
56653 + struct acl_subject_label *curr;
56654 + struct acl_ip_label *ip;
56655 + struct inet_sock *isk;
56656 + struct net_device *dev;
56657 + struct in_device *idev;
56658 + unsigned long i;
56659 + int ret;
56660 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56661 + __u32 ip_addr = 0;
56662 + __u32 our_addr;
56663 + __u32 our_netmask;
56664 + char *p;
56665 + __u16 ip_port = 0;
56666 + const struct cred *cred = current_cred();
56667 +
56668 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56669 + return 0;
56670 +
56671 + curr = current->acl;
56672 + isk = inet_sk(sk);
56673 +
56674 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56675 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56676 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56677 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56678 + struct sockaddr_in saddr;
56679 + int err;
56680 +
56681 + saddr.sin_family = AF_INET;
56682 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56683 + saddr.sin_port = isk->inet_sport;
56684 +
56685 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56686 + if (err)
56687 + return err;
56688 +
56689 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56690 + if (err)
56691 + return err;
56692 + }
56693 +
56694 + if (!curr->ips)
56695 + return 0;
56696 +
56697 + ip_addr = addr->sin_addr.s_addr;
56698 + ip_port = ntohs(addr->sin_port);
56699 +
56700 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56701 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56702 + current->role->roletype, cred->uid,
56703 + cred->gid, current->exec_file ?
56704 + gr_to_filename(current->exec_file->f_path.dentry,
56705 + current->exec_file->f_path.mnt) :
56706 + curr->filename, curr->filename,
56707 + &ip_addr, ip_port, type,
56708 + sk->sk_protocol, mode, &current->signal->saved_ip);
56709 + return 0;
56710 + }
56711 +
56712 + for (i = 0; i < curr->ip_num; i++) {
56713 + ip = *(curr->ips + i);
56714 + if (ip->iface != NULL) {
56715 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56716 + p = strchr(iface, ':');
56717 + if (p != NULL)
56718 + *p = '\0';
56719 + dev = dev_get_by_name(sock_net(sk), iface);
56720 + if (dev == NULL)
56721 + continue;
56722 + idev = in_dev_get(dev);
56723 + if (idev == NULL) {
56724 + dev_put(dev);
56725 + continue;
56726 + }
56727 + rcu_read_lock();
56728 + for_ifa(idev) {
56729 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56730 + our_addr = ifa->ifa_address;
56731 + our_netmask = 0xffffffff;
56732 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56733 + if (ret == 1) {
56734 + rcu_read_unlock();
56735 + in_dev_put(idev);
56736 + dev_put(dev);
56737 + return 0;
56738 + } else if (ret == 2) {
56739 + rcu_read_unlock();
56740 + in_dev_put(idev);
56741 + dev_put(dev);
56742 + goto denied;
56743 + }
56744 + }
56745 + } endfor_ifa(idev);
56746 + rcu_read_unlock();
56747 + in_dev_put(idev);
56748 + dev_put(dev);
56749 + } else {
56750 + our_addr = ip->addr;
56751 + our_netmask = ip->netmask;
56752 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56753 + if (ret == 1)
56754 + return 0;
56755 + else if (ret == 2)
56756 + goto denied;
56757 + }
56758 + }
56759 +
56760 +denied:
56761 + if (mode == GR_BIND)
56762 + 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));
56763 + else if (mode == GR_CONNECT)
56764 + 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));
56765 +
56766 + return -EACCES;
56767 +}
56768 +
56769 +int
56770 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56771 +{
56772 + /* always allow disconnection of dgram sockets with connect */
56773 + if (addr->sin_family == AF_UNSPEC)
56774 + return 0;
56775 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56776 +}
56777 +
56778 +int
56779 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56780 +{
56781 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56782 +}
56783 +
56784 +int gr_search_listen(struct socket *sock)
56785 +{
56786 + struct sock *sk = sock->sk;
56787 + struct sockaddr_in addr;
56788 +
56789 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56790 + addr.sin_port = inet_sk(sk)->inet_sport;
56791 +
56792 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56793 +}
56794 +
56795 +int gr_search_accept(struct socket *sock)
56796 +{
56797 + struct sock *sk = sock->sk;
56798 + struct sockaddr_in addr;
56799 +
56800 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56801 + addr.sin_port = inet_sk(sk)->inet_sport;
56802 +
56803 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56804 +}
56805 +
56806 +int
56807 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56808 +{
56809 + if (addr)
56810 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56811 + else {
56812 + struct sockaddr_in sin;
56813 + const struct inet_sock *inet = inet_sk(sk);
56814 +
56815 + sin.sin_addr.s_addr = inet->inet_daddr;
56816 + sin.sin_port = inet->inet_dport;
56817 +
56818 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56819 + }
56820 +}
56821 +
56822 +int
56823 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56824 +{
56825 + struct sockaddr_in sin;
56826 +
56827 + if (unlikely(skb->len < sizeof (struct udphdr)))
56828 + return 0; // skip this packet
56829 +
56830 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56831 + sin.sin_port = udp_hdr(skb)->source;
56832 +
56833 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56834 +}
56835 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56836 new file mode 100644
56837 index 0000000..25f54ef
56838 --- /dev/null
56839 +++ b/grsecurity/gracl_learn.c
56840 @@ -0,0 +1,207 @@
56841 +#include <linux/kernel.h>
56842 +#include <linux/mm.h>
56843 +#include <linux/sched.h>
56844 +#include <linux/poll.h>
56845 +#include <linux/string.h>
56846 +#include <linux/file.h>
56847 +#include <linux/types.h>
56848 +#include <linux/vmalloc.h>
56849 +#include <linux/grinternal.h>
56850 +
56851 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56852 + size_t count, loff_t *ppos);
56853 +extern int gr_acl_is_enabled(void);
56854 +
56855 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56856 +static int gr_learn_attached;
56857 +
56858 +/* use a 512k buffer */
56859 +#define LEARN_BUFFER_SIZE (512 * 1024)
56860 +
56861 +static DEFINE_SPINLOCK(gr_learn_lock);
56862 +static DEFINE_MUTEX(gr_learn_user_mutex);
56863 +
56864 +/* we need to maintain two buffers, so that the kernel context of grlearn
56865 + uses a semaphore around the userspace copying, and the other kernel contexts
56866 + use a spinlock when copying into the buffer, since they cannot sleep
56867 +*/
56868 +static char *learn_buffer;
56869 +static char *learn_buffer_user;
56870 +static int learn_buffer_len;
56871 +static int learn_buffer_user_len;
56872 +
56873 +static ssize_t
56874 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56875 +{
56876 + DECLARE_WAITQUEUE(wait, current);
56877 + ssize_t retval = 0;
56878 +
56879 + add_wait_queue(&learn_wait, &wait);
56880 + set_current_state(TASK_INTERRUPTIBLE);
56881 + do {
56882 + mutex_lock(&gr_learn_user_mutex);
56883 + spin_lock(&gr_learn_lock);
56884 + if (learn_buffer_len)
56885 + break;
56886 + spin_unlock(&gr_learn_lock);
56887 + mutex_unlock(&gr_learn_user_mutex);
56888 + if (file->f_flags & O_NONBLOCK) {
56889 + retval = -EAGAIN;
56890 + goto out;
56891 + }
56892 + if (signal_pending(current)) {
56893 + retval = -ERESTARTSYS;
56894 + goto out;
56895 + }
56896 +
56897 + schedule();
56898 + } while (1);
56899 +
56900 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56901 + learn_buffer_user_len = learn_buffer_len;
56902 + retval = learn_buffer_len;
56903 + learn_buffer_len = 0;
56904 +
56905 + spin_unlock(&gr_learn_lock);
56906 +
56907 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56908 + retval = -EFAULT;
56909 +
56910 + mutex_unlock(&gr_learn_user_mutex);
56911 +out:
56912 + set_current_state(TASK_RUNNING);
56913 + remove_wait_queue(&learn_wait, &wait);
56914 + return retval;
56915 +}
56916 +
56917 +static unsigned int
56918 +poll_learn(struct file * file, poll_table * wait)
56919 +{
56920 + poll_wait(file, &learn_wait, wait);
56921 +
56922 + if (learn_buffer_len)
56923 + return (POLLIN | POLLRDNORM);
56924 +
56925 + return 0;
56926 +}
56927 +
56928 +void
56929 +gr_clear_learn_entries(void)
56930 +{
56931 + char *tmp;
56932 +
56933 + mutex_lock(&gr_learn_user_mutex);
56934 + spin_lock(&gr_learn_lock);
56935 + tmp = learn_buffer;
56936 + learn_buffer = NULL;
56937 + spin_unlock(&gr_learn_lock);
56938 + if (tmp)
56939 + vfree(tmp);
56940 + if (learn_buffer_user != NULL) {
56941 + vfree(learn_buffer_user);
56942 + learn_buffer_user = NULL;
56943 + }
56944 + learn_buffer_len = 0;
56945 + mutex_unlock(&gr_learn_user_mutex);
56946 +
56947 + return;
56948 +}
56949 +
56950 +void
56951 +gr_add_learn_entry(const char *fmt, ...)
56952 +{
56953 + va_list args;
56954 + unsigned int len;
56955 +
56956 + if (!gr_learn_attached)
56957 + return;
56958 +
56959 + spin_lock(&gr_learn_lock);
56960 +
56961 + /* leave a gap at the end so we know when it's "full" but don't have to
56962 + compute the exact length of the string we're trying to append
56963 + */
56964 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56965 + spin_unlock(&gr_learn_lock);
56966 + wake_up_interruptible(&learn_wait);
56967 + return;
56968 + }
56969 + if (learn_buffer == NULL) {
56970 + spin_unlock(&gr_learn_lock);
56971 + return;
56972 + }
56973 +
56974 + va_start(args, fmt);
56975 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56976 + va_end(args);
56977 +
56978 + learn_buffer_len += len + 1;
56979 +
56980 + spin_unlock(&gr_learn_lock);
56981 + wake_up_interruptible(&learn_wait);
56982 +
56983 + return;
56984 +}
56985 +
56986 +static int
56987 +open_learn(struct inode *inode, struct file *file)
56988 +{
56989 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56990 + return -EBUSY;
56991 + if (file->f_mode & FMODE_READ) {
56992 + int retval = 0;
56993 + mutex_lock(&gr_learn_user_mutex);
56994 + if (learn_buffer == NULL)
56995 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56996 + if (learn_buffer_user == NULL)
56997 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56998 + if (learn_buffer == NULL) {
56999 + retval = -ENOMEM;
57000 + goto out_error;
57001 + }
57002 + if (learn_buffer_user == NULL) {
57003 + retval = -ENOMEM;
57004 + goto out_error;
57005 + }
57006 + learn_buffer_len = 0;
57007 + learn_buffer_user_len = 0;
57008 + gr_learn_attached = 1;
57009 +out_error:
57010 + mutex_unlock(&gr_learn_user_mutex);
57011 + return retval;
57012 + }
57013 + return 0;
57014 +}
57015 +
57016 +static int
57017 +close_learn(struct inode *inode, struct file *file)
57018 +{
57019 + if (file->f_mode & FMODE_READ) {
57020 + char *tmp = NULL;
57021 + mutex_lock(&gr_learn_user_mutex);
57022 + spin_lock(&gr_learn_lock);
57023 + tmp = learn_buffer;
57024 + learn_buffer = NULL;
57025 + spin_unlock(&gr_learn_lock);
57026 + if (tmp)
57027 + vfree(tmp);
57028 + if (learn_buffer_user != NULL) {
57029 + vfree(learn_buffer_user);
57030 + learn_buffer_user = NULL;
57031 + }
57032 + learn_buffer_len = 0;
57033 + learn_buffer_user_len = 0;
57034 + gr_learn_attached = 0;
57035 + mutex_unlock(&gr_learn_user_mutex);
57036 + }
57037 +
57038 + return 0;
57039 +}
57040 +
57041 +const struct file_operations grsec_fops = {
57042 + .read = read_learn,
57043 + .write = write_grsec_handler,
57044 + .open = open_learn,
57045 + .release = close_learn,
57046 + .poll = poll_learn,
57047 +};
57048 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
57049 new file mode 100644
57050 index 0000000..39645c9
57051 --- /dev/null
57052 +++ b/grsecurity/gracl_res.c
57053 @@ -0,0 +1,68 @@
57054 +#include <linux/kernel.h>
57055 +#include <linux/sched.h>
57056 +#include <linux/gracl.h>
57057 +#include <linux/grinternal.h>
57058 +
57059 +static const char *restab_log[] = {
57060 + [RLIMIT_CPU] = "RLIMIT_CPU",
57061 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57062 + [RLIMIT_DATA] = "RLIMIT_DATA",
57063 + [RLIMIT_STACK] = "RLIMIT_STACK",
57064 + [RLIMIT_CORE] = "RLIMIT_CORE",
57065 + [RLIMIT_RSS] = "RLIMIT_RSS",
57066 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57067 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57068 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57069 + [RLIMIT_AS] = "RLIMIT_AS",
57070 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57071 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57072 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57073 + [RLIMIT_NICE] = "RLIMIT_NICE",
57074 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57075 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57076 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57077 +};
57078 +
57079 +void
57080 +gr_log_resource(const struct task_struct *task,
57081 + const int res, const unsigned long wanted, const int gt)
57082 +{
57083 + const struct cred *cred;
57084 + unsigned long rlim;
57085 +
57086 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57087 + return;
57088 +
57089 + // not yet supported resource
57090 + if (unlikely(!restab_log[res]))
57091 + return;
57092 +
57093 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57094 + rlim = task_rlimit_max(task, res);
57095 + else
57096 + rlim = task_rlimit(task, res);
57097 +
57098 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57099 + return;
57100 +
57101 + rcu_read_lock();
57102 + cred = __task_cred(task);
57103 +
57104 + if (res == RLIMIT_NPROC &&
57105 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57106 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57107 + goto out_rcu_unlock;
57108 + else if (res == RLIMIT_MEMLOCK &&
57109 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57110 + goto out_rcu_unlock;
57111 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57112 + goto out_rcu_unlock;
57113 + rcu_read_unlock();
57114 +
57115 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57116 +
57117 + return;
57118 +out_rcu_unlock:
57119 + rcu_read_unlock();
57120 + return;
57121 +}
57122 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57123 new file mode 100644
57124 index 0000000..25197e9
57125 --- /dev/null
57126 +++ b/grsecurity/gracl_segv.c
57127 @@ -0,0 +1,299 @@
57128 +#include <linux/kernel.h>
57129 +#include <linux/mm.h>
57130 +#include <asm/uaccess.h>
57131 +#include <asm/errno.h>
57132 +#include <asm/mman.h>
57133 +#include <net/sock.h>
57134 +#include <linux/file.h>
57135 +#include <linux/fs.h>
57136 +#include <linux/net.h>
57137 +#include <linux/in.h>
57138 +#include <linux/slab.h>
57139 +#include <linux/types.h>
57140 +#include <linux/sched.h>
57141 +#include <linux/timer.h>
57142 +#include <linux/gracl.h>
57143 +#include <linux/grsecurity.h>
57144 +#include <linux/grinternal.h>
57145 +
57146 +static struct crash_uid *uid_set;
57147 +static unsigned short uid_used;
57148 +static DEFINE_SPINLOCK(gr_uid_lock);
57149 +extern rwlock_t gr_inode_lock;
57150 +extern struct acl_subject_label *
57151 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57152 + struct acl_role_label *role);
57153 +
57154 +#ifdef CONFIG_BTRFS_FS
57155 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57156 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57157 +#endif
57158 +
57159 +static inline dev_t __get_dev(const struct dentry *dentry)
57160 +{
57161 +#ifdef CONFIG_BTRFS_FS
57162 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57163 + return get_btrfs_dev_from_inode(dentry->d_inode);
57164 + else
57165 +#endif
57166 + return dentry->d_inode->i_sb->s_dev;
57167 +}
57168 +
57169 +int
57170 +gr_init_uidset(void)
57171 +{
57172 + uid_set =
57173 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57174 + uid_used = 0;
57175 +
57176 + return uid_set ? 1 : 0;
57177 +}
57178 +
57179 +void
57180 +gr_free_uidset(void)
57181 +{
57182 + if (uid_set)
57183 + kfree(uid_set);
57184 +
57185 + return;
57186 +}
57187 +
57188 +int
57189 +gr_find_uid(const uid_t uid)
57190 +{
57191 + struct crash_uid *tmp = uid_set;
57192 + uid_t buid;
57193 + int low = 0, high = uid_used - 1, mid;
57194 +
57195 + while (high >= low) {
57196 + mid = (low + high) >> 1;
57197 + buid = tmp[mid].uid;
57198 + if (buid == uid)
57199 + return mid;
57200 + if (buid > uid)
57201 + high = mid - 1;
57202 + if (buid < uid)
57203 + low = mid + 1;
57204 + }
57205 +
57206 + return -1;
57207 +}
57208 +
57209 +static __inline__ void
57210 +gr_insertsort(void)
57211 +{
57212 + unsigned short i, j;
57213 + struct crash_uid index;
57214 +
57215 + for (i = 1; i < uid_used; i++) {
57216 + index = uid_set[i];
57217 + j = i;
57218 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57219 + uid_set[j] = uid_set[j - 1];
57220 + j--;
57221 + }
57222 + uid_set[j] = index;
57223 + }
57224 +
57225 + return;
57226 +}
57227 +
57228 +static __inline__ void
57229 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57230 +{
57231 + int loc;
57232 +
57233 + if (uid_used == GR_UIDTABLE_MAX)
57234 + return;
57235 +
57236 + loc = gr_find_uid(uid);
57237 +
57238 + if (loc >= 0) {
57239 + uid_set[loc].expires = expires;
57240 + return;
57241 + }
57242 +
57243 + uid_set[uid_used].uid = uid;
57244 + uid_set[uid_used].expires = expires;
57245 + uid_used++;
57246 +
57247 + gr_insertsort();
57248 +
57249 + return;
57250 +}
57251 +
57252 +void
57253 +gr_remove_uid(const unsigned short loc)
57254 +{
57255 + unsigned short i;
57256 +
57257 + for (i = loc + 1; i < uid_used; i++)
57258 + uid_set[i - 1] = uid_set[i];
57259 +
57260 + uid_used--;
57261 +
57262 + return;
57263 +}
57264 +
57265 +int
57266 +gr_check_crash_uid(const uid_t uid)
57267 +{
57268 + int loc;
57269 + int ret = 0;
57270 +
57271 + if (unlikely(!gr_acl_is_enabled()))
57272 + return 0;
57273 +
57274 + spin_lock(&gr_uid_lock);
57275 + loc = gr_find_uid(uid);
57276 +
57277 + if (loc < 0)
57278 + goto out_unlock;
57279 +
57280 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57281 + gr_remove_uid(loc);
57282 + else
57283 + ret = 1;
57284 +
57285 +out_unlock:
57286 + spin_unlock(&gr_uid_lock);
57287 + return ret;
57288 +}
57289 +
57290 +static __inline__ int
57291 +proc_is_setxid(const struct cred *cred)
57292 +{
57293 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57294 + !uid_eq(cred->uid, cred->fsuid))
57295 + return 1;
57296 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57297 + !uid_eq(cred->gid, cred->fsgid))
57298 + return 1;
57299 +
57300 + return 0;
57301 +}
57302 +
57303 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57304 +
57305 +void
57306 +gr_handle_crash(struct task_struct *task, const int sig)
57307 +{
57308 + struct acl_subject_label *curr;
57309 + struct task_struct *tsk, *tsk2;
57310 + const struct cred *cred;
57311 + const struct cred *cred2;
57312 +
57313 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57314 + return;
57315 +
57316 + if (unlikely(!gr_acl_is_enabled()))
57317 + return;
57318 +
57319 + curr = task->acl;
57320 +
57321 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57322 + return;
57323 +
57324 + if (time_before_eq(curr->expires, get_seconds())) {
57325 + curr->expires = 0;
57326 + curr->crashes = 0;
57327 + }
57328 +
57329 + curr->crashes++;
57330 +
57331 + if (!curr->expires)
57332 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57333 +
57334 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57335 + time_after(curr->expires, get_seconds())) {
57336 + rcu_read_lock();
57337 + cred = __task_cred(task);
57338 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57339 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57340 + spin_lock(&gr_uid_lock);
57341 + gr_insert_uid(cred->uid, curr->expires);
57342 + spin_unlock(&gr_uid_lock);
57343 + curr->expires = 0;
57344 + curr->crashes = 0;
57345 + read_lock(&tasklist_lock);
57346 + do_each_thread(tsk2, tsk) {
57347 + cred2 = __task_cred(tsk);
57348 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57349 + gr_fake_force_sig(SIGKILL, tsk);
57350 + } while_each_thread(tsk2, tsk);
57351 + read_unlock(&tasklist_lock);
57352 + } else {
57353 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57354 + read_lock(&tasklist_lock);
57355 + read_lock(&grsec_exec_file_lock);
57356 + do_each_thread(tsk2, tsk) {
57357 + if (likely(tsk != task)) {
57358 + // if this thread has the same subject as the one that triggered
57359 + // RES_CRASH and it's the same binary, kill it
57360 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57361 + gr_fake_force_sig(SIGKILL, tsk);
57362 + }
57363 + } while_each_thread(tsk2, tsk);
57364 + read_unlock(&grsec_exec_file_lock);
57365 + read_unlock(&tasklist_lock);
57366 + }
57367 + rcu_read_unlock();
57368 + }
57369 +
57370 + return;
57371 +}
57372 +
57373 +int
57374 +gr_check_crash_exec(const struct file *filp)
57375 +{
57376 + struct acl_subject_label *curr;
57377 +
57378 + if (unlikely(!gr_acl_is_enabled()))
57379 + return 0;
57380 +
57381 + read_lock(&gr_inode_lock);
57382 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57383 + __get_dev(filp->f_path.dentry),
57384 + current->role);
57385 + read_unlock(&gr_inode_lock);
57386 +
57387 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57388 + (!curr->crashes && !curr->expires))
57389 + return 0;
57390 +
57391 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57392 + time_after(curr->expires, get_seconds()))
57393 + return 1;
57394 + else if (time_before_eq(curr->expires, get_seconds())) {
57395 + curr->crashes = 0;
57396 + curr->expires = 0;
57397 + }
57398 +
57399 + return 0;
57400 +}
57401 +
57402 +void
57403 +gr_handle_alertkill(struct task_struct *task)
57404 +{
57405 + struct acl_subject_label *curracl;
57406 + __u32 curr_ip;
57407 + struct task_struct *p, *p2;
57408 +
57409 + if (unlikely(!gr_acl_is_enabled()))
57410 + return;
57411 +
57412 + curracl = task->acl;
57413 + curr_ip = task->signal->curr_ip;
57414 +
57415 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57416 + read_lock(&tasklist_lock);
57417 + do_each_thread(p2, p) {
57418 + if (p->signal->curr_ip == curr_ip)
57419 + gr_fake_force_sig(SIGKILL, p);
57420 + } while_each_thread(p2, p);
57421 + read_unlock(&tasklist_lock);
57422 + } else if (curracl->mode & GR_KILLPROC)
57423 + gr_fake_force_sig(SIGKILL, task);
57424 +
57425 + return;
57426 +}
57427 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57428 new file mode 100644
57429 index 0000000..9d83a69
57430 --- /dev/null
57431 +++ b/grsecurity/gracl_shm.c
57432 @@ -0,0 +1,40 @@
57433 +#include <linux/kernel.h>
57434 +#include <linux/mm.h>
57435 +#include <linux/sched.h>
57436 +#include <linux/file.h>
57437 +#include <linux/ipc.h>
57438 +#include <linux/gracl.h>
57439 +#include <linux/grsecurity.h>
57440 +#include <linux/grinternal.h>
57441 +
57442 +int
57443 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57444 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57445 +{
57446 + struct task_struct *task;
57447 +
57448 + if (!gr_acl_is_enabled())
57449 + return 1;
57450 +
57451 + rcu_read_lock();
57452 + read_lock(&tasklist_lock);
57453 +
57454 + task = find_task_by_vpid(shm_cprid);
57455 +
57456 + if (unlikely(!task))
57457 + task = find_task_by_vpid(shm_lapid);
57458 +
57459 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57460 + (task->pid == shm_lapid)) &&
57461 + (task->acl->mode & GR_PROTSHM) &&
57462 + (task->acl != current->acl))) {
57463 + read_unlock(&tasklist_lock);
57464 + rcu_read_unlock();
57465 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57466 + return 0;
57467 + }
57468 + read_unlock(&tasklist_lock);
57469 + rcu_read_unlock();
57470 +
57471 + return 1;
57472 +}
57473 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57474 new file mode 100644
57475 index 0000000..bc0be01
57476 --- /dev/null
57477 +++ b/grsecurity/grsec_chdir.c
57478 @@ -0,0 +1,19 @@
57479 +#include <linux/kernel.h>
57480 +#include <linux/sched.h>
57481 +#include <linux/fs.h>
57482 +#include <linux/file.h>
57483 +#include <linux/grsecurity.h>
57484 +#include <linux/grinternal.h>
57485 +
57486 +void
57487 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57488 +{
57489 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57490 + if ((grsec_enable_chdir && grsec_enable_group &&
57491 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57492 + !grsec_enable_group)) {
57493 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57494 + }
57495 +#endif
57496 + return;
57497 +}
57498 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57499 new file mode 100644
57500 index 0000000..9807ee2
57501 --- /dev/null
57502 +++ b/grsecurity/grsec_chroot.c
57503 @@ -0,0 +1,368 @@
57504 +#include <linux/kernel.h>
57505 +#include <linux/module.h>
57506 +#include <linux/sched.h>
57507 +#include <linux/file.h>
57508 +#include <linux/fs.h>
57509 +#include <linux/mount.h>
57510 +#include <linux/types.h>
57511 +#include "../fs/mount.h"
57512 +#include <linux/grsecurity.h>
57513 +#include <linux/grinternal.h>
57514 +
57515 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57516 +{
57517 +#ifdef CONFIG_GRKERNSEC
57518 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57519 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57520 + task->gr_is_chrooted = 1;
57521 + else
57522 + task->gr_is_chrooted = 0;
57523 +
57524 + task->gr_chroot_dentry = path->dentry;
57525 +#endif
57526 + return;
57527 +}
57528 +
57529 +void gr_clear_chroot_entries(struct task_struct *task)
57530 +{
57531 +#ifdef CONFIG_GRKERNSEC
57532 + task->gr_is_chrooted = 0;
57533 + task->gr_chroot_dentry = NULL;
57534 +#endif
57535 + return;
57536 +}
57537 +
57538 +int
57539 +gr_handle_chroot_unix(const pid_t pid)
57540 +{
57541 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57542 + struct task_struct *p;
57543 +
57544 + if (unlikely(!grsec_enable_chroot_unix))
57545 + return 1;
57546 +
57547 + if (likely(!proc_is_chrooted(current)))
57548 + return 1;
57549 +
57550 + rcu_read_lock();
57551 + read_lock(&tasklist_lock);
57552 + p = find_task_by_vpid_unrestricted(pid);
57553 + if (unlikely(p && !have_same_root(current, p))) {
57554 + read_unlock(&tasklist_lock);
57555 + rcu_read_unlock();
57556 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57557 + return 0;
57558 + }
57559 + read_unlock(&tasklist_lock);
57560 + rcu_read_unlock();
57561 +#endif
57562 + return 1;
57563 +}
57564 +
57565 +int
57566 +gr_handle_chroot_nice(void)
57567 +{
57568 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57569 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57570 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57571 + return -EPERM;
57572 + }
57573 +#endif
57574 + return 0;
57575 +}
57576 +
57577 +int
57578 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57579 +{
57580 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57581 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57582 + && proc_is_chrooted(current)) {
57583 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57584 + return -EACCES;
57585 + }
57586 +#endif
57587 + return 0;
57588 +}
57589 +
57590 +int
57591 +gr_handle_chroot_rawio(const struct inode *inode)
57592 +{
57593 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57594 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57595 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57596 + return 1;
57597 +#endif
57598 + return 0;
57599 +}
57600 +
57601 +int
57602 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57603 +{
57604 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57605 + struct task_struct *p;
57606 + int ret = 0;
57607 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57608 + return ret;
57609 +
57610 + read_lock(&tasklist_lock);
57611 + do_each_pid_task(pid, type, p) {
57612 + if (!have_same_root(current, p)) {
57613 + ret = 1;
57614 + goto out;
57615 + }
57616 + } while_each_pid_task(pid, type, p);
57617 +out:
57618 + read_unlock(&tasklist_lock);
57619 + return ret;
57620 +#endif
57621 + return 0;
57622 +}
57623 +
57624 +int
57625 +gr_pid_is_chrooted(struct task_struct *p)
57626 +{
57627 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57628 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57629 + return 0;
57630 +
57631 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57632 + !have_same_root(current, p)) {
57633 + return 1;
57634 + }
57635 +#endif
57636 + return 0;
57637 +}
57638 +
57639 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57640 +
57641 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57642 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57643 +{
57644 + struct path path, currentroot;
57645 + int ret = 0;
57646 +
57647 + path.dentry = (struct dentry *)u_dentry;
57648 + path.mnt = (struct vfsmount *)u_mnt;
57649 + get_fs_root(current->fs, &currentroot);
57650 + if (path_is_under(&path, &currentroot))
57651 + ret = 1;
57652 + path_put(&currentroot);
57653 +
57654 + return ret;
57655 +}
57656 +#endif
57657 +
57658 +int
57659 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57660 +{
57661 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57662 + if (!grsec_enable_chroot_fchdir)
57663 + return 1;
57664 +
57665 + if (!proc_is_chrooted(current))
57666 + return 1;
57667 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57668 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57669 + return 0;
57670 + }
57671 +#endif
57672 + return 1;
57673 +}
57674 +
57675 +int
57676 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57677 + const time_t shm_createtime)
57678 +{
57679 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57680 + struct task_struct *p;
57681 + time_t starttime;
57682 +
57683 + if (unlikely(!grsec_enable_chroot_shmat))
57684 + return 1;
57685 +
57686 + if (likely(!proc_is_chrooted(current)))
57687 + return 1;
57688 +
57689 + rcu_read_lock();
57690 + read_lock(&tasklist_lock);
57691 +
57692 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57693 + starttime = p->start_time.tv_sec;
57694 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57695 + if (have_same_root(current, p)) {
57696 + goto allow;
57697 + } else {
57698 + read_unlock(&tasklist_lock);
57699 + rcu_read_unlock();
57700 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57701 + return 0;
57702 + }
57703 + }
57704 + /* creator exited, pid reuse, fall through to next check */
57705 + }
57706 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57707 + if (unlikely(!have_same_root(current, p))) {
57708 + read_unlock(&tasklist_lock);
57709 + rcu_read_unlock();
57710 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57711 + return 0;
57712 + }
57713 + }
57714 +
57715 +allow:
57716 + read_unlock(&tasklist_lock);
57717 + rcu_read_unlock();
57718 +#endif
57719 + return 1;
57720 +}
57721 +
57722 +void
57723 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57724 +{
57725 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57726 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57727 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57728 +#endif
57729 + return;
57730 +}
57731 +
57732 +int
57733 +gr_handle_chroot_mknod(const struct dentry *dentry,
57734 + const struct vfsmount *mnt, const int mode)
57735 +{
57736 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57737 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57738 + proc_is_chrooted(current)) {
57739 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57740 + return -EPERM;
57741 + }
57742 +#endif
57743 + return 0;
57744 +}
57745 +
57746 +int
57747 +gr_handle_chroot_mount(const struct dentry *dentry,
57748 + const struct vfsmount *mnt, const char *dev_name)
57749 +{
57750 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57751 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57752 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57753 + return -EPERM;
57754 + }
57755 +#endif
57756 + return 0;
57757 +}
57758 +
57759 +int
57760 +gr_handle_chroot_pivot(void)
57761 +{
57762 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57763 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57764 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57765 + return -EPERM;
57766 + }
57767 +#endif
57768 + return 0;
57769 +}
57770 +
57771 +int
57772 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57773 +{
57774 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57775 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57776 + !gr_is_outside_chroot(dentry, mnt)) {
57777 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57778 + return -EPERM;
57779 + }
57780 +#endif
57781 + return 0;
57782 +}
57783 +
57784 +extern const char *captab_log[];
57785 +extern int captab_log_entries;
57786 +
57787 +int
57788 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57789 +{
57790 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57791 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57792 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57793 + if (cap_raised(chroot_caps, cap)) {
57794 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57795 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57796 + }
57797 + return 0;
57798 + }
57799 + }
57800 +#endif
57801 + return 1;
57802 +}
57803 +
57804 +int
57805 +gr_chroot_is_capable(const int cap)
57806 +{
57807 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57808 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57809 +#endif
57810 + return 1;
57811 +}
57812 +
57813 +int
57814 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57815 +{
57816 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57817 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57818 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57819 + if (cap_raised(chroot_caps, cap)) {
57820 + return 0;
57821 + }
57822 + }
57823 +#endif
57824 + return 1;
57825 +}
57826 +
57827 +int
57828 +gr_chroot_is_capable_nolog(const int cap)
57829 +{
57830 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57831 + return gr_task_chroot_is_capable_nolog(current, cap);
57832 +#endif
57833 + return 1;
57834 +}
57835 +
57836 +int
57837 +gr_handle_chroot_sysctl(const int op)
57838 +{
57839 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57840 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57841 + proc_is_chrooted(current))
57842 + return -EACCES;
57843 +#endif
57844 + return 0;
57845 +}
57846 +
57847 +void
57848 +gr_handle_chroot_chdir(struct path *path)
57849 +{
57850 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57851 + if (grsec_enable_chroot_chdir)
57852 + set_fs_pwd(current->fs, path);
57853 +#endif
57854 + return;
57855 +}
57856 +
57857 +int
57858 +gr_handle_chroot_chmod(const struct dentry *dentry,
57859 + const struct vfsmount *mnt, const int mode)
57860 +{
57861 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57862 + /* allow chmod +s on directories, but not files */
57863 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57864 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57865 + proc_is_chrooted(current)) {
57866 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57867 + return -EPERM;
57868 + }
57869 +#endif
57870 + return 0;
57871 +}
57872 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57873 new file mode 100644
57874 index 0000000..213ad8b
57875 --- /dev/null
57876 +++ b/grsecurity/grsec_disabled.c
57877 @@ -0,0 +1,437 @@
57878 +#include <linux/kernel.h>
57879 +#include <linux/module.h>
57880 +#include <linux/sched.h>
57881 +#include <linux/file.h>
57882 +#include <linux/fs.h>
57883 +#include <linux/kdev_t.h>
57884 +#include <linux/net.h>
57885 +#include <linux/in.h>
57886 +#include <linux/ip.h>
57887 +#include <linux/skbuff.h>
57888 +#include <linux/sysctl.h>
57889 +
57890 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57891 +void
57892 +pax_set_initial_flags(struct linux_binprm *bprm)
57893 +{
57894 + return;
57895 +}
57896 +#endif
57897 +
57898 +#ifdef CONFIG_SYSCTL
57899 +__u32
57900 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57901 +{
57902 + return 0;
57903 +}
57904 +#endif
57905 +
57906 +#ifdef CONFIG_TASKSTATS
57907 +int gr_is_taskstats_denied(int pid)
57908 +{
57909 + return 0;
57910 +}
57911 +#endif
57912 +
57913 +int
57914 +gr_acl_is_enabled(void)
57915 +{
57916 + return 0;
57917 +}
57918 +
57919 +void
57920 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57921 +{
57922 + return;
57923 +}
57924 +
57925 +int
57926 +gr_handle_rawio(const struct inode *inode)
57927 +{
57928 + return 0;
57929 +}
57930 +
57931 +void
57932 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57933 +{
57934 + return;
57935 +}
57936 +
57937 +int
57938 +gr_handle_ptrace(struct task_struct *task, const long request)
57939 +{
57940 + return 0;
57941 +}
57942 +
57943 +int
57944 +gr_handle_proc_ptrace(struct task_struct *task)
57945 +{
57946 + return 0;
57947 +}
57948 +
57949 +void
57950 +gr_learn_resource(const struct task_struct *task,
57951 + const int res, const unsigned long wanted, const int gt)
57952 +{
57953 + return;
57954 +}
57955 +
57956 +int
57957 +gr_set_acls(const int type)
57958 +{
57959 + return 0;
57960 +}
57961 +
57962 +int
57963 +gr_check_hidden_task(const struct task_struct *tsk)
57964 +{
57965 + return 0;
57966 +}
57967 +
57968 +int
57969 +gr_check_protected_task(const struct task_struct *task)
57970 +{
57971 + return 0;
57972 +}
57973 +
57974 +int
57975 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57976 +{
57977 + return 0;
57978 +}
57979 +
57980 +void
57981 +gr_copy_label(struct task_struct *tsk)
57982 +{
57983 + return;
57984 +}
57985 +
57986 +void
57987 +gr_set_pax_flags(struct task_struct *task)
57988 +{
57989 + return;
57990 +}
57991 +
57992 +int
57993 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57994 + const int unsafe_share)
57995 +{
57996 + return 0;
57997 +}
57998 +
57999 +void
58000 +gr_handle_delete(const ino_t ino, const dev_t dev)
58001 +{
58002 + return;
58003 +}
58004 +
58005 +void
58006 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
58007 +{
58008 + return;
58009 +}
58010 +
58011 +void
58012 +gr_handle_crash(struct task_struct *task, const int sig)
58013 +{
58014 + return;
58015 +}
58016 +
58017 +int
58018 +gr_check_crash_exec(const struct file *filp)
58019 +{
58020 + return 0;
58021 +}
58022 +
58023 +int
58024 +gr_check_crash_uid(const uid_t uid)
58025 +{
58026 + return 0;
58027 +}
58028 +
58029 +void
58030 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
58031 + struct dentry *old_dentry,
58032 + struct dentry *new_dentry,
58033 + struct vfsmount *mnt, const __u8 replace)
58034 +{
58035 + return;
58036 +}
58037 +
58038 +int
58039 +gr_search_socket(const int family, const int type, const int protocol)
58040 +{
58041 + return 1;
58042 +}
58043 +
58044 +int
58045 +gr_search_connectbind(const int mode, const struct socket *sock,
58046 + const struct sockaddr_in *addr)
58047 +{
58048 + return 0;
58049 +}
58050 +
58051 +void
58052 +gr_handle_alertkill(struct task_struct *task)
58053 +{
58054 + return;
58055 +}
58056 +
58057 +__u32
58058 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58059 +{
58060 + return 1;
58061 +}
58062 +
58063 +__u32
58064 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58065 + const struct vfsmount * mnt)
58066 +{
58067 + return 1;
58068 +}
58069 +
58070 +__u32
58071 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58072 + int acc_mode)
58073 +{
58074 + return 1;
58075 +}
58076 +
58077 +__u32
58078 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58079 +{
58080 + return 1;
58081 +}
58082 +
58083 +__u32
58084 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58085 +{
58086 + return 1;
58087 +}
58088 +
58089 +int
58090 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58091 + unsigned int *vm_flags)
58092 +{
58093 + return 1;
58094 +}
58095 +
58096 +__u32
58097 +gr_acl_handle_truncate(const struct dentry * dentry,
58098 + const struct vfsmount * mnt)
58099 +{
58100 + return 1;
58101 +}
58102 +
58103 +__u32
58104 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58105 +{
58106 + return 1;
58107 +}
58108 +
58109 +__u32
58110 +gr_acl_handle_access(const struct dentry * dentry,
58111 + const struct vfsmount * mnt, const int fmode)
58112 +{
58113 + return 1;
58114 +}
58115 +
58116 +__u32
58117 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58118 + umode_t *mode)
58119 +{
58120 + return 1;
58121 +}
58122 +
58123 +__u32
58124 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58125 +{
58126 + return 1;
58127 +}
58128 +
58129 +__u32
58130 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58131 +{
58132 + return 1;
58133 +}
58134 +
58135 +void
58136 +grsecurity_init(void)
58137 +{
58138 + return;
58139 +}
58140 +
58141 +umode_t gr_acl_umask(void)
58142 +{
58143 + return 0;
58144 +}
58145 +
58146 +__u32
58147 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58148 + const struct dentry * parent_dentry,
58149 + const struct vfsmount * parent_mnt,
58150 + const int mode)
58151 +{
58152 + return 1;
58153 +}
58154 +
58155 +__u32
58156 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58157 + const struct dentry * parent_dentry,
58158 + const struct vfsmount * parent_mnt)
58159 +{
58160 + return 1;
58161 +}
58162 +
58163 +__u32
58164 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58165 + const struct dentry * parent_dentry,
58166 + const struct vfsmount * parent_mnt, const char *from)
58167 +{
58168 + return 1;
58169 +}
58170 +
58171 +__u32
58172 +gr_acl_handle_link(const struct dentry * new_dentry,
58173 + const struct dentry * parent_dentry,
58174 + const struct vfsmount * parent_mnt,
58175 + const struct dentry * old_dentry,
58176 + const struct vfsmount * old_mnt, const char *to)
58177 +{
58178 + return 1;
58179 +}
58180 +
58181 +int
58182 +gr_acl_handle_rename(const struct dentry *new_dentry,
58183 + const struct dentry *parent_dentry,
58184 + const struct vfsmount *parent_mnt,
58185 + const struct dentry *old_dentry,
58186 + const struct inode *old_parent_inode,
58187 + const struct vfsmount *old_mnt, const char *newname)
58188 +{
58189 + return 0;
58190 +}
58191 +
58192 +int
58193 +gr_acl_handle_filldir(const struct file *file, const char *name,
58194 + const int namelen, const ino_t ino)
58195 +{
58196 + return 1;
58197 +}
58198 +
58199 +int
58200 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58201 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58202 +{
58203 + return 1;
58204 +}
58205 +
58206 +int
58207 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58208 +{
58209 + return 0;
58210 +}
58211 +
58212 +int
58213 +gr_search_accept(const struct socket *sock)
58214 +{
58215 + return 0;
58216 +}
58217 +
58218 +int
58219 +gr_search_listen(const struct socket *sock)
58220 +{
58221 + return 0;
58222 +}
58223 +
58224 +int
58225 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58226 +{
58227 + return 0;
58228 +}
58229 +
58230 +__u32
58231 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58232 +{
58233 + return 1;
58234 +}
58235 +
58236 +__u32
58237 +gr_acl_handle_creat(const struct dentry * dentry,
58238 + const struct dentry * p_dentry,
58239 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58240 + const int imode)
58241 +{
58242 + return 1;
58243 +}
58244 +
58245 +void
58246 +gr_acl_handle_exit(void)
58247 +{
58248 + return;
58249 +}
58250 +
58251 +int
58252 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58253 +{
58254 + return 1;
58255 +}
58256 +
58257 +void
58258 +gr_set_role_label(const uid_t uid, const gid_t gid)
58259 +{
58260 + return;
58261 +}
58262 +
58263 +int
58264 +gr_acl_handle_procpidmem(const struct task_struct *task)
58265 +{
58266 + return 0;
58267 +}
58268 +
58269 +int
58270 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58271 +{
58272 + return 0;
58273 +}
58274 +
58275 +int
58276 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58277 +{
58278 + return 0;
58279 +}
58280 +
58281 +void
58282 +gr_set_kernel_label(struct task_struct *task)
58283 +{
58284 + return;
58285 +}
58286 +
58287 +int
58288 +gr_check_user_change(int real, int effective, int fs)
58289 +{
58290 + return 0;
58291 +}
58292 +
58293 +int
58294 +gr_check_group_change(int real, int effective, int fs)
58295 +{
58296 + return 0;
58297 +}
58298 +
58299 +int gr_acl_enable_at_secure(void)
58300 +{
58301 + return 0;
58302 +}
58303 +
58304 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58305 +{
58306 + return dentry->d_inode->i_sb->s_dev;
58307 +}
58308 +
58309 +EXPORT_SYMBOL(gr_learn_resource);
58310 +EXPORT_SYMBOL(gr_set_kernel_label);
58311 +#ifdef CONFIG_SECURITY
58312 +EXPORT_SYMBOL(gr_check_user_change);
58313 +EXPORT_SYMBOL(gr_check_group_change);
58314 +#endif
58315 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58316 new file mode 100644
58317 index 0000000..abfa971
58318 --- /dev/null
58319 +++ b/grsecurity/grsec_exec.c
58320 @@ -0,0 +1,174 @@
58321 +#include <linux/kernel.h>
58322 +#include <linux/sched.h>
58323 +#include <linux/file.h>
58324 +#include <linux/binfmts.h>
58325 +#include <linux/fs.h>
58326 +#include <linux/types.h>
58327 +#include <linux/grdefs.h>
58328 +#include <linux/grsecurity.h>
58329 +#include <linux/grinternal.h>
58330 +#include <linux/capability.h>
58331 +#include <linux/module.h>
58332 +
58333 +#include <asm/uaccess.h>
58334 +
58335 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58336 +static char gr_exec_arg_buf[132];
58337 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58338 +#endif
58339 +
58340 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58341 +
58342 +void
58343 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58344 +{
58345 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58346 + char *grarg = gr_exec_arg_buf;
58347 + unsigned int i, x, execlen = 0;
58348 + char c;
58349 +
58350 + if (!((grsec_enable_execlog && grsec_enable_group &&
58351 + in_group_p(grsec_audit_gid))
58352 + || (grsec_enable_execlog && !grsec_enable_group)))
58353 + return;
58354 +
58355 + mutex_lock(&gr_exec_arg_mutex);
58356 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58357 +
58358 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58359 + const char __user *p;
58360 + unsigned int len;
58361 +
58362 + p = get_user_arg_ptr(argv, i);
58363 + if (IS_ERR(p))
58364 + goto log;
58365 +
58366 + len = strnlen_user(p, 128 - execlen);
58367 + if (len > 128 - execlen)
58368 + len = 128 - execlen;
58369 + else if (len > 0)
58370 + len--;
58371 + if (copy_from_user(grarg + execlen, p, len))
58372 + goto log;
58373 +
58374 + /* rewrite unprintable characters */
58375 + for (x = 0; x < len; x++) {
58376 + c = *(grarg + execlen + x);
58377 + if (c < 32 || c > 126)
58378 + *(grarg + execlen + x) = ' ';
58379 + }
58380 +
58381 + execlen += len;
58382 + *(grarg + execlen) = ' ';
58383 + *(grarg + execlen + 1) = '\0';
58384 + execlen++;
58385 + }
58386 +
58387 + log:
58388 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58389 + bprm->file->f_path.mnt, grarg);
58390 + mutex_unlock(&gr_exec_arg_mutex);
58391 +#endif
58392 + return;
58393 +}
58394 +
58395 +#ifdef CONFIG_GRKERNSEC
58396 +extern int gr_acl_is_capable(const int cap);
58397 +extern int gr_acl_is_capable_nolog(const int cap);
58398 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58399 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58400 +extern int gr_chroot_is_capable(const int cap);
58401 +extern int gr_chroot_is_capable_nolog(const int cap);
58402 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58403 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58404 +#endif
58405 +
58406 +const char *captab_log[] = {
58407 + "CAP_CHOWN",
58408 + "CAP_DAC_OVERRIDE",
58409 + "CAP_DAC_READ_SEARCH",
58410 + "CAP_FOWNER",
58411 + "CAP_FSETID",
58412 + "CAP_KILL",
58413 + "CAP_SETGID",
58414 + "CAP_SETUID",
58415 + "CAP_SETPCAP",
58416 + "CAP_LINUX_IMMUTABLE",
58417 + "CAP_NET_BIND_SERVICE",
58418 + "CAP_NET_BROADCAST",
58419 + "CAP_NET_ADMIN",
58420 + "CAP_NET_RAW",
58421 + "CAP_IPC_LOCK",
58422 + "CAP_IPC_OWNER",
58423 + "CAP_SYS_MODULE",
58424 + "CAP_SYS_RAWIO",
58425 + "CAP_SYS_CHROOT",
58426 + "CAP_SYS_PTRACE",
58427 + "CAP_SYS_PACCT",
58428 + "CAP_SYS_ADMIN",
58429 + "CAP_SYS_BOOT",
58430 + "CAP_SYS_NICE",
58431 + "CAP_SYS_RESOURCE",
58432 + "CAP_SYS_TIME",
58433 + "CAP_SYS_TTY_CONFIG",
58434 + "CAP_MKNOD",
58435 + "CAP_LEASE",
58436 + "CAP_AUDIT_WRITE",
58437 + "CAP_AUDIT_CONTROL",
58438 + "CAP_SETFCAP",
58439 + "CAP_MAC_OVERRIDE",
58440 + "CAP_MAC_ADMIN",
58441 + "CAP_SYSLOG",
58442 + "CAP_WAKE_ALARM"
58443 +};
58444 +
58445 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58446 +
58447 +int gr_is_capable(const int cap)
58448 +{
58449 +#ifdef CONFIG_GRKERNSEC
58450 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58451 + return 1;
58452 + return 0;
58453 +#else
58454 + return 1;
58455 +#endif
58456 +}
58457 +
58458 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58459 +{
58460 +#ifdef CONFIG_GRKERNSEC
58461 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58462 + return 1;
58463 + return 0;
58464 +#else
58465 + return 1;
58466 +#endif
58467 +}
58468 +
58469 +int gr_is_capable_nolog(const int cap)
58470 +{
58471 +#ifdef CONFIG_GRKERNSEC
58472 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58473 + return 1;
58474 + return 0;
58475 +#else
58476 + return 1;
58477 +#endif
58478 +}
58479 +
58480 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58481 +{
58482 +#ifdef CONFIG_GRKERNSEC
58483 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58484 + return 1;
58485 + return 0;
58486 +#else
58487 + return 1;
58488 +#endif
58489 +}
58490 +
58491 +EXPORT_SYMBOL(gr_is_capable);
58492 +EXPORT_SYMBOL(gr_is_capable_nolog);
58493 +EXPORT_SYMBOL(gr_task_is_capable);
58494 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58495 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58496 new file mode 100644
58497 index 0000000..d3ee748
58498 --- /dev/null
58499 +++ b/grsecurity/grsec_fifo.c
58500 @@ -0,0 +1,24 @@
58501 +#include <linux/kernel.h>
58502 +#include <linux/sched.h>
58503 +#include <linux/fs.h>
58504 +#include <linux/file.h>
58505 +#include <linux/grinternal.h>
58506 +
58507 +int
58508 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58509 + const struct dentry *dir, const int flag, const int acc_mode)
58510 +{
58511 +#ifdef CONFIG_GRKERNSEC_FIFO
58512 + const struct cred *cred = current_cred();
58513 +
58514 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58515 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58516 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58517 + (cred->fsuid != dentry->d_inode->i_uid)) {
58518 + if (!inode_permission(dentry->d_inode, acc_mode))
58519 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58520 + return -EACCES;
58521 + }
58522 +#endif
58523 + return 0;
58524 +}
58525 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58526 new file mode 100644
58527 index 0000000..8ca18bf
58528 --- /dev/null
58529 +++ b/grsecurity/grsec_fork.c
58530 @@ -0,0 +1,23 @@
58531 +#include <linux/kernel.h>
58532 +#include <linux/sched.h>
58533 +#include <linux/grsecurity.h>
58534 +#include <linux/grinternal.h>
58535 +#include <linux/errno.h>
58536 +
58537 +void
58538 +gr_log_forkfail(const int retval)
58539 +{
58540 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58541 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58542 + switch (retval) {
58543 + case -EAGAIN:
58544 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58545 + break;
58546 + case -ENOMEM:
58547 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58548 + break;
58549 + }
58550 + }
58551 +#endif
58552 + return;
58553 +}
58554 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58555 new file mode 100644
58556 index 0000000..05a6015
58557 --- /dev/null
58558 +++ b/grsecurity/grsec_init.c
58559 @@ -0,0 +1,283 @@
58560 +#include <linux/kernel.h>
58561 +#include <linux/sched.h>
58562 +#include <linux/mm.h>
58563 +#include <linux/gracl.h>
58564 +#include <linux/slab.h>
58565 +#include <linux/vmalloc.h>
58566 +#include <linux/percpu.h>
58567 +#include <linux/module.h>
58568 +
58569 +int grsec_enable_ptrace_readexec;
58570 +int grsec_enable_setxid;
58571 +int grsec_enable_symlinkown;
58572 +int grsec_symlinkown_gid;
58573 +int grsec_enable_brute;
58574 +int grsec_enable_link;
58575 +int grsec_enable_dmesg;
58576 +int grsec_enable_harden_ptrace;
58577 +int grsec_enable_fifo;
58578 +int grsec_enable_execlog;
58579 +int grsec_enable_signal;
58580 +int grsec_enable_forkfail;
58581 +int grsec_enable_audit_ptrace;
58582 +int grsec_enable_time;
58583 +int grsec_enable_audit_textrel;
58584 +int grsec_enable_group;
58585 +int grsec_audit_gid;
58586 +int grsec_enable_chdir;
58587 +int grsec_enable_mount;
58588 +int grsec_enable_rofs;
58589 +int grsec_enable_chroot_findtask;
58590 +int grsec_enable_chroot_mount;
58591 +int grsec_enable_chroot_shmat;
58592 +int grsec_enable_chroot_fchdir;
58593 +int grsec_enable_chroot_double;
58594 +int grsec_enable_chroot_pivot;
58595 +int grsec_enable_chroot_chdir;
58596 +int grsec_enable_chroot_chmod;
58597 +int grsec_enable_chroot_mknod;
58598 +int grsec_enable_chroot_nice;
58599 +int grsec_enable_chroot_execlog;
58600 +int grsec_enable_chroot_caps;
58601 +int grsec_enable_chroot_sysctl;
58602 +int grsec_enable_chroot_unix;
58603 +int grsec_enable_tpe;
58604 +int grsec_tpe_gid;
58605 +int grsec_enable_blackhole;
58606 +#ifdef CONFIG_IPV6_MODULE
58607 +EXPORT_SYMBOL(grsec_enable_blackhole);
58608 +#endif
58609 +int grsec_lastack_retries;
58610 +int grsec_enable_tpe_all;
58611 +int grsec_enable_tpe_invert;
58612 +int grsec_enable_socket_all;
58613 +int grsec_socket_all_gid;
58614 +int grsec_enable_socket_client;
58615 +int grsec_socket_client_gid;
58616 +int grsec_enable_socket_server;
58617 +int grsec_socket_server_gid;
58618 +int grsec_resource_logging;
58619 +int grsec_disable_privio;
58620 +int grsec_enable_log_rwxmaps;
58621 +int grsec_lock;
58622 +
58623 +DEFINE_SPINLOCK(grsec_alert_lock);
58624 +unsigned long grsec_alert_wtime = 0;
58625 +unsigned long grsec_alert_fyet = 0;
58626 +
58627 +DEFINE_SPINLOCK(grsec_audit_lock);
58628 +
58629 +DEFINE_RWLOCK(grsec_exec_file_lock);
58630 +
58631 +char *gr_shared_page[4];
58632 +
58633 +char *gr_alert_log_fmt;
58634 +char *gr_audit_log_fmt;
58635 +char *gr_alert_log_buf;
58636 +char *gr_audit_log_buf;
58637 +
58638 +extern struct gr_arg *gr_usermode;
58639 +extern unsigned char *gr_system_salt;
58640 +extern unsigned char *gr_system_sum;
58641 +
58642 +void __init
58643 +grsecurity_init(void)
58644 +{
58645 + int j;
58646 + /* create the per-cpu shared pages */
58647 +
58648 +#ifdef CONFIG_X86
58649 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58650 +#endif
58651 +
58652 + for (j = 0; j < 4; j++) {
58653 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58654 + if (gr_shared_page[j] == NULL) {
58655 + panic("Unable to allocate grsecurity shared page");
58656 + return;
58657 + }
58658 + }
58659 +
58660 + /* allocate log buffers */
58661 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58662 + if (!gr_alert_log_fmt) {
58663 + panic("Unable to allocate grsecurity alert log format buffer");
58664 + return;
58665 + }
58666 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58667 + if (!gr_audit_log_fmt) {
58668 + panic("Unable to allocate grsecurity audit log format buffer");
58669 + return;
58670 + }
58671 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58672 + if (!gr_alert_log_buf) {
58673 + panic("Unable to allocate grsecurity alert log buffer");
58674 + return;
58675 + }
58676 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58677 + if (!gr_audit_log_buf) {
58678 + panic("Unable to allocate grsecurity audit log buffer");
58679 + return;
58680 + }
58681 +
58682 + /* allocate memory for authentication structure */
58683 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58684 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58685 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58686 +
58687 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58688 + panic("Unable to allocate grsecurity authentication structure");
58689 + return;
58690 + }
58691 +
58692 +
58693 +#ifdef CONFIG_GRKERNSEC_IO
58694 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58695 + grsec_disable_privio = 1;
58696 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58697 + grsec_disable_privio = 1;
58698 +#else
58699 + grsec_disable_privio = 0;
58700 +#endif
58701 +#endif
58702 +
58703 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58704 + /* for backward compatibility, tpe_invert always defaults to on if
58705 + enabled in the kernel
58706 + */
58707 + grsec_enable_tpe_invert = 1;
58708 +#endif
58709 +
58710 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58711 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58712 + grsec_lock = 1;
58713 +#endif
58714 +
58715 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58716 + grsec_enable_audit_textrel = 1;
58717 +#endif
58718 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58719 + grsec_enable_log_rwxmaps = 1;
58720 +#endif
58721 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58722 + grsec_enable_group = 1;
58723 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58724 +#endif
58725 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58726 + grsec_enable_ptrace_readexec = 1;
58727 +#endif
58728 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58729 + grsec_enable_chdir = 1;
58730 +#endif
58731 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58732 + grsec_enable_harden_ptrace = 1;
58733 +#endif
58734 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58735 + grsec_enable_mount = 1;
58736 +#endif
58737 +#ifdef CONFIG_GRKERNSEC_LINK
58738 + grsec_enable_link = 1;
58739 +#endif
58740 +#ifdef CONFIG_GRKERNSEC_BRUTE
58741 + grsec_enable_brute = 1;
58742 +#endif
58743 +#ifdef CONFIG_GRKERNSEC_DMESG
58744 + grsec_enable_dmesg = 1;
58745 +#endif
58746 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58747 + grsec_enable_blackhole = 1;
58748 + grsec_lastack_retries = 4;
58749 +#endif
58750 +#ifdef CONFIG_GRKERNSEC_FIFO
58751 + grsec_enable_fifo = 1;
58752 +#endif
58753 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58754 + grsec_enable_execlog = 1;
58755 +#endif
58756 +#ifdef CONFIG_GRKERNSEC_SETXID
58757 + grsec_enable_setxid = 1;
58758 +#endif
58759 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58760 + grsec_enable_signal = 1;
58761 +#endif
58762 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58763 + grsec_enable_forkfail = 1;
58764 +#endif
58765 +#ifdef CONFIG_GRKERNSEC_TIME
58766 + grsec_enable_time = 1;
58767 +#endif
58768 +#ifdef CONFIG_GRKERNSEC_RESLOG
58769 + grsec_resource_logging = 1;
58770 +#endif
58771 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58772 + grsec_enable_chroot_findtask = 1;
58773 +#endif
58774 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58775 + grsec_enable_chroot_unix = 1;
58776 +#endif
58777 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58778 + grsec_enable_chroot_mount = 1;
58779 +#endif
58780 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58781 + grsec_enable_chroot_fchdir = 1;
58782 +#endif
58783 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58784 + grsec_enable_chroot_shmat = 1;
58785 +#endif
58786 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58787 + grsec_enable_audit_ptrace = 1;
58788 +#endif
58789 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58790 + grsec_enable_chroot_double = 1;
58791 +#endif
58792 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58793 + grsec_enable_chroot_pivot = 1;
58794 +#endif
58795 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58796 + grsec_enable_chroot_chdir = 1;
58797 +#endif
58798 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58799 + grsec_enable_chroot_chmod = 1;
58800 +#endif
58801 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58802 + grsec_enable_chroot_mknod = 1;
58803 +#endif
58804 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58805 + grsec_enable_chroot_nice = 1;
58806 +#endif
58807 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58808 + grsec_enable_chroot_execlog = 1;
58809 +#endif
58810 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58811 + grsec_enable_chroot_caps = 1;
58812 +#endif
58813 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58814 + grsec_enable_chroot_sysctl = 1;
58815 +#endif
58816 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58817 + grsec_enable_symlinkown = 1;
58818 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58819 +#endif
58820 +#ifdef CONFIG_GRKERNSEC_TPE
58821 + grsec_enable_tpe = 1;
58822 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58823 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58824 + grsec_enable_tpe_all = 1;
58825 +#endif
58826 +#endif
58827 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58828 + grsec_enable_socket_all = 1;
58829 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58830 +#endif
58831 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58832 + grsec_enable_socket_client = 1;
58833 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58834 +#endif
58835 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58836 + grsec_enable_socket_server = 1;
58837 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58838 +#endif
58839 +#endif
58840 +
58841 + return;
58842 +}
58843 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58844 new file mode 100644
58845 index 0000000..589481f
58846 --- /dev/null
58847 +++ b/grsecurity/grsec_link.c
58848 @@ -0,0 +1,58 @@
58849 +#include <linux/kernel.h>
58850 +#include <linux/sched.h>
58851 +#include <linux/fs.h>
58852 +#include <linux/file.h>
58853 +#include <linux/grinternal.h>
58854 +
58855 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58856 +{
58857 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58858 + const struct inode *link_inode = link->dentry->d_inode;
58859 +
58860 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58861 + /* ignore root-owned links, e.g. /proc/self */
58862 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58863 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58864 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58865 + return 1;
58866 + }
58867 +#endif
58868 + return 0;
58869 +}
58870 +
58871 +int
58872 +gr_handle_follow_link(const struct inode *parent,
58873 + const struct inode *inode,
58874 + const struct dentry *dentry, const struct vfsmount *mnt)
58875 +{
58876 +#ifdef CONFIG_GRKERNSEC_LINK
58877 + const struct cred *cred = current_cred();
58878 +
58879 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58880 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58881 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58882 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58883 + return -EACCES;
58884 + }
58885 +#endif
58886 + return 0;
58887 +}
58888 +
58889 +int
58890 +gr_handle_hardlink(const struct dentry *dentry,
58891 + const struct vfsmount *mnt,
58892 + struct inode *inode, const int mode, const char *to)
58893 +{
58894 +#ifdef CONFIG_GRKERNSEC_LINK
58895 + const struct cred *cred = current_cred();
58896 +
58897 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58898 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58899 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58900 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58901 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58902 + return -EPERM;
58903 + }
58904 +#endif
58905 + return 0;
58906 +}
58907 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58908 new file mode 100644
58909 index 0000000..a45d2e9
58910 --- /dev/null
58911 +++ b/grsecurity/grsec_log.c
58912 @@ -0,0 +1,322 @@
58913 +#include <linux/kernel.h>
58914 +#include <linux/sched.h>
58915 +#include <linux/file.h>
58916 +#include <linux/tty.h>
58917 +#include <linux/fs.h>
58918 +#include <linux/grinternal.h>
58919 +
58920 +#ifdef CONFIG_TREE_PREEMPT_RCU
58921 +#define DISABLE_PREEMPT() preempt_disable()
58922 +#define ENABLE_PREEMPT() preempt_enable()
58923 +#else
58924 +#define DISABLE_PREEMPT()
58925 +#define ENABLE_PREEMPT()
58926 +#endif
58927 +
58928 +#define BEGIN_LOCKS(x) \
58929 + DISABLE_PREEMPT(); \
58930 + rcu_read_lock(); \
58931 + read_lock(&tasklist_lock); \
58932 + read_lock(&grsec_exec_file_lock); \
58933 + if (x != GR_DO_AUDIT) \
58934 + spin_lock(&grsec_alert_lock); \
58935 + else \
58936 + spin_lock(&grsec_audit_lock)
58937 +
58938 +#define END_LOCKS(x) \
58939 + if (x != GR_DO_AUDIT) \
58940 + spin_unlock(&grsec_alert_lock); \
58941 + else \
58942 + spin_unlock(&grsec_audit_lock); \
58943 + read_unlock(&grsec_exec_file_lock); \
58944 + read_unlock(&tasklist_lock); \
58945 + rcu_read_unlock(); \
58946 + ENABLE_PREEMPT(); \
58947 + if (x == GR_DONT_AUDIT) \
58948 + gr_handle_alertkill(current)
58949 +
58950 +enum {
58951 + FLOODING,
58952 + NO_FLOODING
58953 +};
58954 +
58955 +extern char *gr_alert_log_fmt;
58956 +extern char *gr_audit_log_fmt;
58957 +extern char *gr_alert_log_buf;
58958 +extern char *gr_audit_log_buf;
58959 +
58960 +static int gr_log_start(int audit)
58961 +{
58962 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58963 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58964 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58965 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58966 + unsigned long curr_secs = get_seconds();
58967 +
58968 + if (audit == GR_DO_AUDIT)
58969 + goto set_fmt;
58970 +
58971 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58972 + grsec_alert_wtime = curr_secs;
58973 + grsec_alert_fyet = 0;
58974 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58975 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58976 + grsec_alert_fyet++;
58977 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58978 + grsec_alert_wtime = curr_secs;
58979 + grsec_alert_fyet++;
58980 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58981 + return FLOODING;
58982 + }
58983 + else return FLOODING;
58984 +
58985 +set_fmt:
58986 +#endif
58987 + memset(buf, 0, PAGE_SIZE);
58988 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58989 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58990 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58991 + } else if (current->signal->curr_ip) {
58992 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58993 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58994 + } else if (gr_acl_is_enabled()) {
58995 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58996 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58997 + } else {
58998 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58999 + strcpy(buf, fmt);
59000 + }
59001 +
59002 + return NO_FLOODING;
59003 +}
59004 +
59005 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59006 + __attribute__ ((format (printf, 2, 0)));
59007 +
59008 +static void gr_log_middle(int audit, const char *msg, va_list ap)
59009 +{
59010 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59011 + unsigned int len = strlen(buf);
59012 +
59013 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59014 +
59015 + return;
59016 +}
59017 +
59018 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59019 + __attribute__ ((format (printf, 2, 3)));
59020 +
59021 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
59022 +{
59023 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59024 + unsigned int len = strlen(buf);
59025 + va_list ap;
59026 +
59027 + va_start(ap, msg);
59028 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
59029 + va_end(ap);
59030 +
59031 + return;
59032 +}
59033 +
59034 +static void gr_log_end(int audit, int append_default)
59035 +{
59036 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
59037 +
59038 + if (append_default) {
59039 + unsigned int len = strlen(buf);
59040 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
59041 + }
59042 +
59043 + printk("%s\n", buf);
59044 +
59045 + return;
59046 +}
59047 +
59048 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
59049 +{
59050 + int logtype;
59051 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
59052 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
59053 + void *voidptr = NULL;
59054 + int num1 = 0, num2 = 0;
59055 + unsigned long ulong1 = 0, ulong2 = 0;
59056 + struct dentry *dentry = NULL;
59057 + struct vfsmount *mnt = NULL;
59058 + struct file *file = NULL;
59059 + struct task_struct *task = NULL;
59060 + const struct cred *cred, *pcred;
59061 + va_list ap;
59062 +
59063 + BEGIN_LOCKS(audit);
59064 + logtype = gr_log_start(audit);
59065 + if (logtype == FLOODING) {
59066 + END_LOCKS(audit);
59067 + return;
59068 + }
59069 + va_start(ap, argtypes);
59070 + switch (argtypes) {
59071 + case GR_TTYSNIFF:
59072 + task = va_arg(ap, struct task_struct *);
59073 + 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);
59074 + break;
59075 + case GR_SYSCTL_HIDDEN:
59076 + str1 = va_arg(ap, char *);
59077 + gr_log_middle_varargs(audit, msg, result, str1);
59078 + break;
59079 + case GR_RBAC:
59080 + dentry = va_arg(ap, struct dentry *);
59081 + mnt = va_arg(ap, struct vfsmount *);
59082 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59083 + break;
59084 + case GR_RBAC_STR:
59085 + dentry = va_arg(ap, struct dentry *);
59086 + mnt = va_arg(ap, struct vfsmount *);
59087 + str1 = va_arg(ap, char *);
59088 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59089 + break;
59090 + case GR_STR_RBAC:
59091 + str1 = va_arg(ap, char *);
59092 + dentry = va_arg(ap, struct dentry *);
59093 + mnt = va_arg(ap, struct vfsmount *);
59094 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59095 + break;
59096 + case GR_RBAC_MODE2:
59097 + dentry = va_arg(ap, struct dentry *);
59098 + mnt = va_arg(ap, struct vfsmount *);
59099 + str1 = va_arg(ap, char *);
59100 + str2 = va_arg(ap, char *);
59101 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59102 + break;
59103 + case GR_RBAC_MODE3:
59104 + dentry = va_arg(ap, struct dentry *);
59105 + mnt = va_arg(ap, struct vfsmount *);
59106 + str1 = va_arg(ap, char *);
59107 + str2 = va_arg(ap, char *);
59108 + str3 = va_arg(ap, char *);
59109 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59110 + break;
59111 + case GR_FILENAME:
59112 + dentry = va_arg(ap, struct dentry *);
59113 + mnt = va_arg(ap, struct vfsmount *);
59114 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59115 + break;
59116 + case GR_STR_FILENAME:
59117 + str1 = va_arg(ap, char *);
59118 + dentry = va_arg(ap, struct dentry *);
59119 + mnt = va_arg(ap, struct vfsmount *);
59120 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59121 + break;
59122 + case GR_FILENAME_STR:
59123 + dentry = va_arg(ap, struct dentry *);
59124 + mnt = va_arg(ap, struct vfsmount *);
59125 + str1 = va_arg(ap, char *);
59126 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59127 + break;
59128 + case GR_FILENAME_TWO_INT:
59129 + dentry = va_arg(ap, struct dentry *);
59130 + mnt = va_arg(ap, struct vfsmount *);
59131 + num1 = va_arg(ap, int);
59132 + num2 = va_arg(ap, int);
59133 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59134 + break;
59135 + case GR_FILENAME_TWO_INT_STR:
59136 + dentry = va_arg(ap, struct dentry *);
59137 + mnt = va_arg(ap, struct vfsmount *);
59138 + num1 = va_arg(ap, int);
59139 + num2 = va_arg(ap, int);
59140 + str1 = va_arg(ap, char *);
59141 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59142 + break;
59143 + case GR_TEXTREL:
59144 + file = va_arg(ap, struct file *);
59145 + ulong1 = va_arg(ap, unsigned long);
59146 + ulong2 = va_arg(ap, unsigned long);
59147 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59148 + break;
59149 + case GR_PTRACE:
59150 + task = va_arg(ap, struct task_struct *);
59151 + 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);
59152 + break;
59153 + case GR_RESOURCE:
59154 + task = va_arg(ap, struct task_struct *);
59155 + cred = __task_cred(task);
59156 + pcred = __task_cred(task->real_parent);
59157 + ulong1 = va_arg(ap, unsigned long);
59158 + str1 = va_arg(ap, char *);
59159 + ulong2 = va_arg(ap, unsigned long);
59160 + 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);
59161 + break;
59162 + case GR_CAP:
59163 + task = va_arg(ap, struct task_struct *);
59164 + cred = __task_cred(task);
59165 + pcred = __task_cred(task->real_parent);
59166 + str1 = va_arg(ap, char *);
59167 + 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);
59168 + break;
59169 + case GR_SIG:
59170 + str1 = va_arg(ap, char *);
59171 + voidptr = va_arg(ap, void *);
59172 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59173 + break;
59174 + case GR_SIG2:
59175 + task = va_arg(ap, struct task_struct *);
59176 + cred = __task_cred(task);
59177 + pcred = __task_cred(task->real_parent);
59178 + num1 = va_arg(ap, int);
59179 + 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);
59180 + break;
59181 + case GR_CRASH1:
59182 + task = va_arg(ap, struct task_struct *);
59183 + cred = __task_cred(task);
59184 + pcred = __task_cred(task->real_parent);
59185 + ulong1 = va_arg(ap, unsigned long);
59186 + 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);
59187 + break;
59188 + case GR_CRASH2:
59189 + task = va_arg(ap, struct task_struct *);
59190 + cred = __task_cred(task);
59191 + pcred = __task_cred(task->real_parent);
59192 + ulong1 = va_arg(ap, unsigned long);
59193 + 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);
59194 + break;
59195 + case GR_RWXMAP:
59196 + file = va_arg(ap, struct file *);
59197 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59198 + break;
59199 + case GR_PSACCT:
59200 + {
59201 + unsigned int wday, cday;
59202 + __u8 whr, chr;
59203 + __u8 wmin, cmin;
59204 + __u8 wsec, csec;
59205 + char cur_tty[64] = { 0 };
59206 + char parent_tty[64] = { 0 };
59207 +
59208 + task = va_arg(ap, struct task_struct *);
59209 + wday = va_arg(ap, unsigned int);
59210 + cday = va_arg(ap, unsigned int);
59211 + whr = va_arg(ap, int);
59212 + chr = va_arg(ap, int);
59213 + wmin = va_arg(ap, int);
59214 + cmin = va_arg(ap, int);
59215 + wsec = va_arg(ap, int);
59216 + csec = va_arg(ap, int);
59217 + ulong1 = va_arg(ap, unsigned long);
59218 + cred = __task_cred(task);
59219 + pcred = __task_cred(task->real_parent);
59220 +
59221 + 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);
59222 + }
59223 + break;
59224 + default:
59225 + gr_log_middle(audit, msg, ap);
59226 + }
59227 + va_end(ap);
59228 + // these don't need DEFAULTSECARGS printed on the end
59229 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59230 + gr_log_end(audit, 0);
59231 + else
59232 + gr_log_end(audit, 1);
59233 + END_LOCKS(audit);
59234 +}
59235 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59236 new file mode 100644
59237 index 0000000..f536303
59238 --- /dev/null
59239 +++ b/grsecurity/grsec_mem.c
59240 @@ -0,0 +1,40 @@
59241 +#include <linux/kernel.h>
59242 +#include <linux/sched.h>
59243 +#include <linux/mm.h>
59244 +#include <linux/mman.h>
59245 +#include <linux/grinternal.h>
59246 +
59247 +void
59248 +gr_handle_ioperm(void)
59249 +{
59250 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59251 + return;
59252 +}
59253 +
59254 +void
59255 +gr_handle_iopl(void)
59256 +{
59257 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59258 + return;
59259 +}
59260 +
59261 +void
59262 +gr_handle_mem_readwrite(u64 from, u64 to)
59263 +{
59264 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59265 + return;
59266 +}
59267 +
59268 +void
59269 +gr_handle_vm86(void)
59270 +{
59271 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59272 + return;
59273 +}
59274 +
59275 +void
59276 +gr_log_badprocpid(const char *entry)
59277 +{
59278 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59279 + return;
59280 +}
59281 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59282 new file mode 100644
59283 index 0000000..2131422
59284 --- /dev/null
59285 +++ b/grsecurity/grsec_mount.c
59286 @@ -0,0 +1,62 @@
59287 +#include <linux/kernel.h>
59288 +#include <linux/sched.h>
59289 +#include <linux/mount.h>
59290 +#include <linux/grsecurity.h>
59291 +#include <linux/grinternal.h>
59292 +
59293 +void
59294 +gr_log_remount(const char *devname, const int retval)
59295 +{
59296 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59297 + if (grsec_enable_mount && (retval >= 0))
59298 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59299 +#endif
59300 + return;
59301 +}
59302 +
59303 +void
59304 +gr_log_unmount(const char *devname, const int retval)
59305 +{
59306 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59307 + if (grsec_enable_mount && (retval >= 0))
59308 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59309 +#endif
59310 + return;
59311 +}
59312 +
59313 +void
59314 +gr_log_mount(const char *from, const char *to, const int retval)
59315 +{
59316 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59317 + if (grsec_enable_mount && (retval >= 0))
59318 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59319 +#endif
59320 + return;
59321 +}
59322 +
59323 +int
59324 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59325 +{
59326 +#ifdef CONFIG_GRKERNSEC_ROFS
59327 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59328 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59329 + return -EPERM;
59330 + } else
59331 + return 0;
59332 +#endif
59333 + return 0;
59334 +}
59335 +
59336 +int
59337 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59338 +{
59339 +#ifdef CONFIG_GRKERNSEC_ROFS
59340 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59341 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59342 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59343 + return -EPERM;
59344 + } else
59345 + return 0;
59346 +#endif
59347 + return 0;
59348 +}
59349 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59350 new file mode 100644
59351 index 0000000..a3b12a0
59352 --- /dev/null
59353 +++ b/grsecurity/grsec_pax.c
59354 @@ -0,0 +1,36 @@
59355 +#include <linux/kernel.h>
59356 +#include <linux/sched.h>
59357 +#include <linux/mm.h>
59358 +#include <linux/file.h>
59359 +#include <linux/grinternal.h>
59360 +#include <linux/grsecurity.h>
59361 +
59362 +void
59363 +gr_log_textrel(struct vm_area_struct * vma)
59364 +{
59365 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59366 + if (grsec_enable_audit_textrel)
59367 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59368 +#endif
59369 + return;
59370 +}
59371 +
59372 +void
59373 +gr_log_rwxmmap(struct file *file)
59374 +{
59375 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59376 + if (grsec_enable_log_rwxmaps)
59377 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59378 +#endif
59379 + return;
59380 +}
59381 +
59382 +void
59383 +gr_log_rwxmprotect(struct file *file)
59384 +{
59385 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59386 + if (grsec_enable_log_rwxmaps)
59387 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59388 +#endif
59389 + return;
59390 +}
59391 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59392 new file mode 100644
59393 index 0000000..f7f29aa
59394 --- /dev/null
59395 +++ b/grsecurity/grsec_ptrace.c
59396 @@ -0,0 +1,30 @@
59397 +#include <linux/kernel.h>
59398 +#include <linux/sched.h>
59399 +#include <linux/grinternal.h>
59400 +#include <linux/security.h>
59401 +
59402 +void
59403 +gr_audit_ptrace(struct task_struct *task)
59404 +{
59405 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59406 + if (grsec_enable_audit_ptrace)
59407 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59408 +#endif
59409 + return;
59410 +}
59411 +
59412 +int
59413 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59414 +{
59415 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59416 + const struct dentry *dentry = file->f_path.dentry;
59417 + const struct vfsmount *mnt = file->f_path.mnt;
59418 +
59419 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59420 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59421 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59422 + return -EACCES;
59423 + }
59424 +#endif
59425 + return 0;
59426 +}
59427 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59428 new file mode 100644
59429 index 0000000..b4ac94c
59430 --- /dev/null
59431 +++ b/grsecurity/grsec_sig.c
59432 @@ -0,0 +1,209 @@
59433 +#include <linux/kernel.h>
59434 +#include <linux/sched.h>
59435 +#include <linux/delay.h>
59436 +#include <linux/grsecurity.h>
59437 +#include <linux/grinternal.h>
59438 +#include <linux/hardirq.h>
59439 +
59440 +char *signames[] = {
59441 + [SIGSEGV] = "Segmentation fault",
59442 + [SIGILL] = "Illegal instruction",
59443 + [SIGABRT] = "Abort",
59444 + [SIGBUS] = "Invalid alignment/Bus error"
59445 +};
59446 +
59447 +void
59448 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59449 +{
59450 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59451 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59452 + (sig == SIGABRT) || (sig == SIGBUS))) {
59453 + if (t->pid == current->pid) {
59454 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59455 + } else {
59456 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59457 + }
59458 + }
59459 +#endif
59460 + return;
59461 +}
59462 +
59463 +int
59464 +gr_handle_signal(const struct task_struct *p, const int sig)
59465 +{
59466 +#ifdef CONFIG_GRKERNSEC
59467 + /* ignore the 0 signal for protected task checks */
59468 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59469 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59470 + return -EPERM;
59471 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59472 + return -EPERM;
59473 + }
59474 +#endif
59475 + return 0;
59476 +}
59477 +
59478 +#ifdef CONFIG_GRKERNSEC
59479 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59480 +
59481 +int gr_fake_force_sig(int sig, struct task_struct *t)
59482 +{
59483 + unsigned long int flags;
59484 + int ret, blocked, ignored;
59485 + struct k_sigaction *action;
59486 +
59487 + spin_lock_irqsave(&t->sighand->siglock, flags);
59488 + action = &t->sighand->action[sig-1];
59489 + ignored = action->sa.sa_handler == SIG_IGN;
59490 + blocked = sigismember(&t->blocked, sig);
59491 + if (blocked || ignored) {
59492 + action->sa.sa_handler = SIG_DFL;
59493 + if (blocked) {
59494 + sigdelset(&t->blocked, sig);
59495 + recalc_sigpending_and_wake(t);
59496 + }
59497 + }
59498 + if (action->sa.sa_handler == SIG_DFL)
59499 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59500 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59501 +
59502 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59503 +
59504 + return ret;
59505 +}
59506 +#endif
59507 +
59508 +#ifdef CONFIG_GRKERNSEC_BRUTE
59509 +#define GR_USER_BAN_TIME (15 * 60)
59510 +
59511 +static int __get_dumpable(unsigned long mm_flags)
59512 +{
59513 + int ret;
59514 +
59515 + ret = mm_flags & MMF_DUMPABLE_MASK;
59516 + return (ret >= 2) ? 2 : ret;
59517 +}
59518 +#endif
59519 +
59520 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59521 +{
59522 +#ifdef CONFIG_GRKERNSEC_BRUTE
59523 + kuid_t uid = GLOBAL_ROOT_UID;
59524 +
59525 + if (!grsec_enable_brute)
59526 + return;
59527 +
59528 + rcu_read_lock();
59529 + read_lock(&tasklist_lock);
59530 + read_lock(&grsec_exec_file_lock);
59531 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59532 + p->real_parent->brute = 1;
59533 + else {
59534 + const struct cred *cred = __task_cred(p), *cred2;
59535 + struct task_struct *tsk, *tsk2;
59536 +
59537 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59538 + struct user_struct *user;
59539 +
59540 + uid = cred->uid;
59541 +
59542 + /* this is put upon execution past expiration */
59543 + user = find_user(uid);
59544 + if (user == NULL)
59545 + goto unlock;
59546 + user->banned = 1;
59547 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59548 + if (user->ban_expires == ~0UL)
59549 + user->ban_expires--;
59550 +
59551 + do_each_thread(tsk2, tsk) {
59552 + cred2 = __task_cred(tsk);
59553 + if (tsk != p && uid_eq(cred2->uid, uid))
59554 + gr_fake_force_sig(SIGKILL, tsk);
59555 + } while_each_thread(tsk2, tsk);
59556 + }
59557 + }
59558 +unlock:
59559 + read_unlock(&grsec_exec_file_lock);
59560 + read_unlock(&tasklist_lock);
59561 + rcu_read_unlock();
59562 +
59563 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59564 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59565 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59566 +
59567 +#endif
59568 + return;
59569 +}
59570 +
59571 +void gr_handle_brute_check(void)
59572 +{
59573 +#ifdef CONFIG_GRKERNSEC_BRUTE
59574 + if (current->brute)
59575 + msleep(30 * 1000);
59576 +#endif
59577 + return;
59578 +}
59579 +
59580 +void gr_handle_kernel_exploit(void)
59581 +{
59582 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59583 + const struct cred *cred;
59584 + struct task_struct *tsk, *tsk2;
59585 + struct user_struct *user;
59586 + kuid_t uid;
59587 +
59588 + if (in_irq() || in_serving_softirq() || in_nmi())
59589 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59590 +
59591 + uid = current_uid();
59592 +
59593 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59594 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59595 + else {
59596 + /* kill all the processes of this user, hold a reference
59597 + to their creds struct, and prevent them from creating
59598 + another process until system reset
59599 + */
59600 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59601 + from_kuid_munged(&init_user_ns, uid));
59602 + /* we intentionally leak this ref */
59603 + user = get_uid(current->cred->user);
59604 + if (user) {
59605 + user->banned = 1;
59606 + user->ban_expires = ~0UL;
59607 + }
59608 +
59609 + read_lock(&tasklist_lock);
59610 + do_each_thread(tsk2, tsk) {
59611 + cred = __task_cred(tsk);
59612 + if (uid_eq(cred->uid, uid))
59613 + gr_fake_force_sig(SIGKILL, tsk);
59614 + } while_each_thread(tsk2, tsk);
59615 + read_unlock(&tasklist_lock);
59616 + }
59617 +#endif
59618 +}
59619 +
59620 +int __gr_process_user_ban(struct user_struct *user)
59621 +{
59622 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59623 + if (unlikely(user->banned)) {
59624 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59625 + user->banned = 0;
59626 + user->ban_expires = 0;
59627 + free_uid(user);
59628 + } else
59629 + return -EPERM;
59630 + }
59631 +#endif
59632 + return 0;
59633 +}
59634 +
59635 +int gr_process_user_ban(void)
59636 +{
59637 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59638 + return __gr_process_user_ban(current->cred->user);
59639 +#endif
59640 + return 0;
59641 +}
59642 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59643 new file mode 100644
59644 index 0000000..4030d57
59645 --- /dev/null
59646 +++ b/grsecurity/grsec_sock.c
59647 @@ -0,0 +1,244 @@
59648 +#include <linux/kernel.h>
59649 +#include <linux/module.h>
59650 +#include <linux/sched.h>
59651 +#include <linux/file.h>
59652 +#include <linux/net.h>
59653 +#include <linux/in.h>
59654 +#include <linux/ip.h>
59655 +#include <net/sock.h>
59656 +#include <net/inet_sock.h>
59657 +#include <linux/grsecurity.h>
59658 +#include <linux/grinternal.h>
59659 +#include <linux/gracl.h>
59660 +
59661 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59662 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59663 +
59664 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59665 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59666 +
59667 +#ifdef CONFIG_UNIX_MODULE
59668 +EXPORT_SYMBOL(gr_acl_handle_unix);
59669 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59670 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59671 +EXPORT_SYMBOL(gr_handle_create);
59672 +#endif
59673 +
59674 +#ifdef CONFIG_GRKERNSEC
59675 +#define gr_conn_table_size 32749
59676 +struct conn_table_entry {
59677 + struct conn_table_entry *next;
59678 + struct signal_struct *sig;
59679 +};
59680 +
59681 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59682 +DEFINE_SPINLOCK(gr_conn_table_lock);
59683 +
59684 +extern const char * gr_socktype_to_name(unsigned char type);
59685 +extern const char * gr_proto_to_name(unsigned char proto);
59686 +extern const char * gr_sockfamily_to_name(unsigned char family);
59687 +
59688 +static __inline__ int
59689 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59690 +{
59691 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59692 +}
59693 +
59694 +static __inline__ int
59695 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59696 + __u16 sport, __u16 dport)
59697 +{
59698 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59699 + sig->gr_sport == sport && sig->gr_dport == dport))
59700 + return 1;
59701 + else
59702 + return 0;
59703 +}
59704 +
59705 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59706 +{
59707 + struct conn_table_entry **match;
59708 + unsigned int index;
59709 +
59710 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59711 + sig->gr_sport, sig->gr_dport,
59712 + gr_conn_table_size);
59713 +
59714 + newent->sig = sig;
59715 +
59716 + match = &gr_conn_table[index];
59717 + newent->next = *match;
59718 + *match = newent;
59719 +
59720 + return;
59721 +}
59722 +
59723 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59724 +{
59725 + struct conn_table_entry *match, *last = NULL;
59726 + unsigned int index;
59727 +
59728 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59729 + sig->gr_sport, sig->gr_dport,
59730 + gr_conn_table_size);
59731 +
59732 + match = gr_conn_table[index];
59733 + while (match && !conn_match(match->sig,
59734 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59735 + sig->gr_dport)) {
59736 + last = match;
59737 + match = match->next;
59738 + }
59739 +
59740 + if (match) {
59741 + if (last)
59742 + last->next = match->next;
59743 + else
59744 + gr_conn_table[index] = NULL;
59745 + kfree(match);
59746 + }
59747 +
59748 + return;
59749 +}
59750 +
59751 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59752 + __u16 sport, __u16 dport)
59753 +{
59754 + struct conn_table_entry *match;
59755 + unsigned int index;
59756 +
59757 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59758 +
59759 + match = gr_conn_table[index];
59760 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59761 + match = match->next;
59762 +
59763 + if (match)
59764 + return match->sig;
59765 + else
59766 + return NULL;
59767 +}
59768 +
59769 +#endif
59770 +
59771 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59772 +{
59773 +#ifdef CONFIG_GRKERNSEC
59774 + struct signal_struct *sig = task->signal;
59775 + struct conn_table_entry *newent;
59776 +
59777 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59778 + if (newent == NULL)
59779 + return;
59780 + /* no bh lock needed since we are called with bh disabled */
59781 + spin_lock(&gr_conn_table_lock);
59782 + gr_del_task_from_ip_table_nolock(sig);
59783 + sig->gr_saddr = inet->inet_rcv_saddr;
59784 + sig->gr_daddr = inet->inet_daddr;
59785 + sig->gr_sport = inet->inet_sport;
59786 + sig->gr_dport = inet->inet_dport;
59787 + gr_add_to_task_ip_table_nolock(sig, newent);
59788 + spin_unlock(&gr_conn_table_lock);
59789 +#endif
59790 + return;
59791 +}
59792 +
59793 +void gr_del_task_from_ip_table(struct task_struct *task)
59794 +{
59795 +#ifdef CONFIG_GRKERNSEC
59796 + spin_lock_bh(&gr_conn_table_lock);
59797 + gr_del_task_from_ip_table_nolock(task->signal);
59798 + spin_unlock_bh(&gr_conn_table_lock);
59799 +#endif
59800 + return;
59801 +}
59802 +
59803 +void
59804 +gr_attach_curr_ip(const struct sock *sk)
59805 +{
59806 +#ifdef CONFIG_GRKERNSEC
59807 + struct signal_struct *p, *set;
59808 + const struct inet_sock *inet = inet_sk(sk);
59809 +
59810 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59811 + return;
59812 +
59813 + set = current->signal;
59814 +
59815 + spin_lock_bh(&gr_conn_table_lock);
59816 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59817 + inet->inet_dport, inet->inet_sport);
59818 + if (unlikely(p != NULL)) {
59819 + set->curr_ip = p->curr_ip;
59820 + set->used_accept = 1;
59821 + gr_del_task_from_ip_table_nolock(p);
59822 + spin_unlock_bh(&gr_conn_table_lock);
59823 + return;
59824 + }
59825 + spin_unlock_bh(&gr_conn_table_lock);
59826 +
59827 + set->curr_ip = inet->inet_daddr;
59828 + set->used_accept = 1;
59829 +#endif
59830 + return;
59831 +}
59832 +
59833 +int
59834 +gr_handle_sock_all(const int family, const int type, const int protocol)
59835 +{
59836 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59837 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59838 + (family != AF_UNIX)) {
59839 + if (family == AF_INET)
59840 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59841 + else
59842 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59843 + return -EACCES;
59844 + }
59845 +#endif
59846 + return 0;
59847 +}
59848 +
59849 +int
59850 +gr_handle_sock_server(const struct sockaddr *sck)
59851 +{
59852 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59853 + if (grsec_enable_socket_server &&
59854 + in_group_p(grsec_socket_server_gid) &&
59855 + sck && (sck->sa_family != AF_UNIX) &&
59856 + (sck->sa_family != AF_LOCAL)) {
59857 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59858 + return -EACCES;
59859 + }
59860 +#endif
59861 + return 0;
59862 +}
59863 +
59864 +int
59865 +gr_handle_sock_server_other(const struct sock *sck)
59866 +{
59867 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59868 + if (grsec_enable_socket_server &&
59869 + in_group_p(grsec_socket_server_gid) &&
59870 + sck && (sck->sk_family != AF_UNIX) &&
59871 + (sck->sk_family != AF_LOCAL)) {
59872 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59873 + return -EACCES;
59874 + }
59875 +#endif
59876 + return 0;
59877 +}
59878 +
59879 +int
59880 +gr_handle_sock_client(const struct sockaddr *sck)
59881 +{
59882 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59883 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59884 + sck && (sck->sa_family != AF_UNIX) &&
59885 + (sck->sa_family != AF_LOCAL)) {
59886 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59887 + return -EACCES;
59888 + }
59889 +#endif
59890 + return 0;
59891 +}
59892 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59893 new file mode 100644
59894 index 0000000..f55ef0f
59895 --- /dev/null
59896 +++ b/grsecurity/grsec_sysctl.c
59897 @@ -0,0 +1,469 @@
59898 +#include <linux/kernel.h>
59899 +#include <linux/sched.h>
59900 +#include <linux/sysctl.h>
59901 +#include <linux/grsecurity.h>
59902 +#include <linux/grinternal.h>
59903 +
59904 +int
59905 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59906 +{
59907 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59908 + if (dirname == NULL || name == NULL)
59909 + return 0;
59910 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59911 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59912 + return -EACCES;
59913 + }
59914 +#endif
59915 + return 0;
59916 +}
59917 +
59918 +#ifdef CONFIG_GRKERNSEC_ROFS
59919 +static int __maybe_unused one = 1;
59920 +#endif
59921 +
59922 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59923 +struct ctl_table grsecurity_table[] = {
59924 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59925 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59926 +#ifdef CONFIG_GRKERNSEC_IO
59927 + {
59928 + .procname = "disable_priv_io",
59929 + .data = &grsec_disable_privio,
59930 + .maxlen = sizeof(int),
59931 + .mode = 0600,
59932 + .proc_handler = &proc_dointvec,
59933 + },
59934 +#endif
59935 +#endif
59936 +#ifdef CONFIG_GRKERNSEC_LINK
59937 + {
59938 + .procname = "linking_restrictions",
59939 + .data = &grsec_enable_link,
59940 + .maxlen = sizeof(int),
59941 + .mode = 0600,
59942 + .proc_handler = &proc_dointvec,
59943 + },
59944 +#endif
59945 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59946 + {
59947 + .procname = "enforce_symlinksifowner",
59948 + .data = &grsec_enable_symlinkown,
59949 + .maxlen = sizeof(int),
59950 + .mode = 0600,
59951 + .proc_handler = &proc_dointvec,
59952 + },
59953 + {
59954 + .procname = "symlinkown_gid",
59955 + .data = &grsec_symlinkown_gid,
59956 + .maxlen = sizeof(int),
59957 + .mode = 0600,
59958 + .proc_handler = &proc_dointvec,
59959 + },
59960 +#endif
59961 +#ifdef CONFIG_GRKERNSEC_BRUTE
59962 + {
59963 + .procname = "deter_bruteforce",
59964 + .data = &grsec_enable_brute,
59965 + .maxlen = sizeof(int),
59966 + .mode = 0600,
59967 + .proc_handler = &proc_dointvec,
59968 + },
59969 +#endif
59970 +#ifdef CONFIG_GRKERNSEC_FIFO
59971 + {
59972 + .procname = "fifo_restrictions",
59973 + .data = &grsec_enable_fifo,
59974 + .maxlen = sizeof(int),
59975 + .mode = 0600,
59976 + .proc_handler = &proc_dointvec,
59977 + },
59978 +#endif
59979 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59980 + {
59981 + .procname = "ptrace_readexec",
59982 + .data = &grsec_enable_ptrace_readexec,
59983 + .maxlen = sizeof(int),
59984 + .mode = 0600,
59985 + .proc_handler = &proc_dointvec,
59986 + },
59987 +#endif
59988 +#ifdef CONFIG_GRKERNSEC_SETXID
59989 + {
59990 + .procname = "consistent_setxid",
59991 + .data = &grsec_enable_setxid,
59992 + .maxlen = sizeof(int),
59993 + .mode = 0600,
59994 + .proc_handler = &proc_dointvec,
59995 + },
59996 +#endif
59997 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59998 + {
59999 + .procname = "ip_blackhole",
60000 + .data = &grsec_enable_blackhole,
60001 + .maxlen = sizeof(int),
60002 + .mode = 0600,
60003 + .proc_handler = &proc_dointvec,
60004 + },
60005 + {
60006 + .procname = "lastack_retries",
60007 + .data = &grsec_lastack_retries,
60008 + .maxlen = sizeof(int),
60009 + .mode = 0600,
60010 + .proc_handler = &proc_dointvec,
60011 + },
60012 +#endif
60013 +#ifdef CONFIG_GRKERNSEC_EXECLOG
60014 + {
60015 + .procname = "exec_logging",
60016 + .data = &grsec_enable_execlog,
60017 + .maxlen = sizeof(int),
60018 + .mode = 0600,
60019 + .proc_handler = &proc_dointvec,
60020 + },
60021 +#endif
60022 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60023 + {
60024 + .procname = "rwxmap_logging",
60025 + .data = &grsec_enable_log_rwxmaps,
60026 + .maxlen = sizeof(int),
60027 + .mode = 0600,
60028 + .proc_handler = &proc_dointvec,
60029 + },
60030 +#endif
60031 +#ifdef CONFIG_GRKERNSEC_SIGNAL
60032 + {
60033 + .procname = "signal_logging",
60034 + .data = &grsec_enable_signal,
60035 + .maxlen = sizeof(int),
60036 + .mode = 0600,
60037 + .proc_handler = &proc_dointvec,
60038 + },
60039 +#endif
60040 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
60041 + {
60042 + .procname = "forkfail_logging",
60043 + .data = &grsec_enable_forkfail,
60044 + .maxlen = sizeof(int),
60045 + .mode = 0600,
60046 + .proc_handler = &proc_dointvec,
60047 + },
60048 +#endif
60049 +#ifdef CONFIG_GRKERNSEC_TIME
60050 + {
60051 + .procname = "timechange_logging",
60052 + .data = &grsec_enable_time,
60053 + .maxlen = sizeof(int),
60054 + .mode = 0600,
60055 + .proc_handler = &proc_dointvec,
60056 + },
60057 +#endif
60058 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60059 + {
60060 + .procname = "chroot_deny_shmat",
60061 + .data = &grsec_enable_chroot_shmat,
60062 + .maxlen = sizeof(int),
60063 + .mode = 0600,
60064 + .proc_handler = &proc_dointvec,
60065 + },
60066 +#endif
60067 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60068 + {
60069 + .procname = "chroot_deny_unix",
60070 + .data = &grsec_enable_chroot_unix,
60071 + .maxlen = sizeof(int),
60072 + .mode = 0600,
60073 + .proc_handler = &proc_dointvec,
60074 + },
60075 +#endif
60076 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60077 + {
60078 + .procname = "chroot_deny_mount",
60079 + .data = &grsec_enable_chroot_mount,
60080 + .maxlen = sizeof(int),
60081 + .mode = 0600,
60082 + .proc_handler = &proc_dointvec,
60083 + },
60084 +#endif
60085 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60086 + {
60087 + .procname = "chroot_deny_fchdir",
60088 + .data = &grsec_enable_chroot_fchdir,
60089 + .maxlen = sizeof(int),
60090 + .mode = 0600,
60091 + .proc_handler = &proc_dointvec,
60092 + },
60093 +#endif
60094 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60095 + {
60096 + .procname = "chroot_deny_chroot",
60097 + .data = &grsec_enable_chroot_double,
60098 + .maxlen = sizeof(int),
60099 + .mode = 0600,
60100 + .proc_handler = &proc_dointvec,
60101 + },
60102 +#endif
60103 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60104 + {
60105 + .procname = "chroot_deny_pivot",
60106 + .data = &grsec_enable_chroot_pivot,
60107 + .maxlen = sizeof(int),
60108 + .mode = 0600,
60109 + .proc_handler = &proc_dointvec,
60110 + },
60111 +#endif
60112 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60113 + {
60114 + .procname = "chroot_enforce_chdir",
60115 + .data = &grsec_enable_chroot_chdir,
60116 + .maxlen = sizeof(int),
60117 + .mode = 0600,
60118 + .proc_handler = &proc_dointvec,
60119 + },
60120 +#endif
60121 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60122 + {
60123 + .procname = "chroot_deny_chmod",
60124 + .data = &grsec_enable_chroot_chmod,
60125 + .maxlen = sizeof(int),
60126 + .mode = 0600,
60127 + .proc_handler = &proc_dointvec,
60128 + },
60129 +#endif
60130 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60131 + {
60132 + .procname = "chroot_deny_mknod",
60133 + .data = &grsec_enable_chroot_mknod,
60134 + .maxlen = sizeof(int),
60135 + .mode = 0600,
60136 + .proc_handler = &proc_dointvec,
60137 + },
60138 +#endif
60139 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60140 + {
60141 + .procname = "chroot_restrict_nice",
60142 + .data = &grsec_enable_chroot_nice,
60143 + .maxlen = sizeof(int),
60144 + .mode = 0600,
60145 + .proc_handler = &proc_dointvec,
60146 + },
60147 +#endif
60148 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60149 + {
60150 + .procname = "chroot_execlog",
60151 + .data = &grsec_enable_chroot_execlog,
60152 + .maxlen = sizeof(int),
60153 + .mode = 0600,
60154 + .proc_handler = &proc_dointvec,
60155 + },
60156 +#endif
60157 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60158 + {
60159 + .procname = "chroot_caps",
60160 + .data = &grsec_enable_chroot_caps,
60161 + .maxlen = sizeof(int),
60162 + .mode = 0600,
60163 + .proc_handler = &proc_dointvec,
60164 + },
60165 +#endif
60166 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60167 + {
60168 + .procname = "chroot_deny_sysctl",
60169 + .data = &grsec_enable_chroot_sysctl,
60170 + .maxlen = sizeof(int),
60171 + .mode = 0600,
60172 + .proc_handler = &proc_dointvec,
60173 + },
60174 +#endif
60175 +#ifdef CONFIG_GRKERNSEC_TPE
60176 + {
60177 + .procname = "tpe",
60178 + .data = &grsec_enable_tpe,
60179 + .maxlen = sizeof(int),
60180 + .mode = 0600,
60181 + .proc_handler = &proc_dointvec,
60182 + },
60183 + {
60184 + .procname = "tpe_gid",
60185 + .data = &grsec_tpe_gid,
60186 + .maxlen = sizeof(int),
60187 + .mode = 0600,
60188 + .proc_handler = &proc_dointvec,
60189 + },
60190 +#endif
60191 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60192 + {
60193 + .procname = "tpe_invert",
60194 + .data = &grsec_enable_tpe_invert,
60195 + .maxlen = sizeof(int),
60196 + .mode = 0600,
60197 + .proc_handler = &proc_dointvec,
60198 + },
60199 +#endif
60200 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60201 + {
60202 + .procname = "tpe_restrict_all",
60203 + .data = &grsec_enable_tpe_all,
60204 + .maxlen = sizeof(int),
60205 + .mode = 0600,
60206 + .proc_handler = &proc_dointvec,
60207 + },
60208 +#endif
60209 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60210 + {
60211 + .procname = "socket_all",
60212 + .data = &grsec_enable_socket_all,
60213 + .maxlen = sizeof(int),
60214 + .mode = 0600,
60215 + .proc_handler = &proc_dointvec,
60216 + },
60217 + {
60218 + .procname = "socket_all_gid",
60219 + .data = &grsec_socket_all_gid,
60220 + .maxlen = sizeof(int),
60221 + .mode = 0600,
60222 + .proc_handler = &proc_dointvec,
60223 + },
60224 +#endif
60225 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60226 + {
60227 + .procname = "socket_client",
60228 + .data = &grsec_enable_socket_client,
60229 + .maxlen = sizeof(int),
60230 + .mode = 0600,
60231 + .proc_handler = &proc_dointvec,
60232 + },
60233 + {
60234 + .procname = "socket_client_gid",
60235 + .data = &grsec_socket_client_gid,
60236 + .maxlen = sizeof(int),
60237 + .mode = 0600,
60238 + .proc_handler = &proc_dointvec,
60239 + },
60240 +#endif
60241 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60242 + {
60243 + .procname = "socket_server",
60244 + .data = &grsec_enable_socket_server,
60245 + .maxlen = sizeof(int),
60246 + .mode = 0600,
60247 + .proc_handler = &proc_dointvec,
60248 + },
60249 + {
60250 + .procname = "socket_server_gid",
60251 + .data = &grsec_socket_server_gid,
60252 + .maxlen = sizeof(int),
60253 + .mode = 0600,
60254 + .proc_handler = &proc_dointvec,
60255 + },
60256 +#endif
60257 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60258 + {
60259 + .procname = "audit_group",
60260 + .data = &grsec_enable_group,
60261 + .maxlen = sizeof(int),
60262 + .mode = 0600,
60263 + .proc_handler = &proc_dointvec,
60264 + },
60265 + {
60266 + .procname = "audit_gid",
60267 + .data = &grsec_audit_gid,
60268 + .maxlen = sizeof(int),
60269 + .mode = 0600,
60270 + .proc_handler = &proc_dointvec,
60271 + },
60272 +#endif
60273 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60274 + {
60275 + .procname = "audit_chdir",
60276 + .data = &grsec_enable_chdir,
60277 + .maxlen = sizeof(int),
60278 + .mode = 0600,
60279 + .proc_handler = &proc_dointvec,
60280 + },
60281 +#endif
60282 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60283 + {
60284 + .procname = "audit_mount",
60285 + .data = &grsec_enable_mount,
60286 + .maxlen = sizeof(int),
60287 + .mode = 0600,
60288 + .proc_handler = &proc_dointvec,
60289 + },
60290 +#endif
60291 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60292 + {
60293 + .procname = "audit_textrel",
60294 + .data = &grsec_enable_audit_textrel,
60295 + .maxlen = sizeof(int),
60296 + .mode = 0600,
60297 + .proc_handler = &proc_dointvec,
60298 + },
60299 +#endif
60300 +#ifdef CONFIG_GRKERNSEC_DMESG
60301 + {
60302 + .procname = "dmesg",
60303 + .data = &grsec_enable_dmesg,
60304 + .maxlen = sizeof(int),
60305 + .mode = 0600,
60306 + .proc_handler = &proc_dointvec,
60307 + },
60308 +#endif
60309 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60310 + {
60311 + .procname = "chroot_findtask",
60312 + .data = &grsec_enable_chroot_findtask,
60313 + .maxlen = sizeof(int),
60314 + .mode = 0600,
60315 + .proc_handler = &proc_dointvec,
60316 + },
60317 +#endif
60318 +#ifdef CONFIG_GRKERNSEC_RESLOG
60319 + {
60320 + .procname = "resource_logging",
60321 + .data = &grsec_resource_logging,
60322 + .maxlen = sizeof(int),
60323 + .mode = 0600,
60324 + .proc_handler = &proc_dointvec,
60325 + },
60326 +#endif
60327 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60328 + {
60329 + .procname = "audit_ptrace",
60330 + .data = &grsec_enable_audit_ptrace,
60331 + .maxlen = sizeof(int),
60332 + .mode = 0600,
60333 + .proc_handler = &proc_dointvec,
60334 + },
60335 +#endif
60336 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60337 + {
60338 + .procname = "harden_ptrace",
60339 + .data = &grsec_enable_harden_ptrace,
60340 + .maxlen = sizeof(int),
60341 + .mode = 0600,
60342 + .proc_handler = &proc_dointvec,
60343 + },
60344 +#endif
60345 + {
60346 + .procname = "grsec_lock",
60347 + .data = &grsec_lock,
60348 + .maxlen = sizeof(int),
60349 + .mode = 0600,
60350 + .proc_handler = &proc_dointvec,
60351 + },
60352 +#endif
60353 +#ifdef CONFIG_GRKERNSEC_ROFS
60354 + {
60355 + .procname = "romount_protect",
60356 + .data = &grsec_enable_rofs,
60357 + .maxlen = sizeof(int),
60358 + .mode = 0600,
60359 + .proc_handler = &proc_dointvec_minmax,
60360 + .extra1 = &one,
60361 + .extra2 = &one,
60362 + },
60363 +#endif
60364 + { }
60365 +};
60366 +#endif
60367 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60368 new file mode 100644
60369 index 0000000..0dc13c3
60370 --- /dev/null
60371 +++ b/grsecurity/grsec_time.c
60372 @@ -0,0 +1,16 @@
60373 +#include <linux/kernel.h>
60374 +#include <linux/sched.h>
60375 +#include <linux/grinternal.h>
60376 +#include <linux/module.h>
60377 +
60378 +void
60379 +gr_log_timechange(void)
60380 +{
60381 +#ifdef CONFIG_GRKERNSEC_TIME
60382 + if (grsec_enable_time)
60383 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60384 +#endif
60385 + return;
60386 +}
60387 +
60388 +EXPORT_SYMBOL(gr_log_timechange);
60389 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60390 new file mode 100644
60391 index 0000000..07e0dc0
60392 --- /dev/null
60393 +++ b/grsecurity/grsec_tpe.c
60394 @@ -0,0 +1,73 @@
60395 +#include <linux/kernel.h>
60396 +#include <linux/sched.h>
60397 +#include <linux/file.h>
60398 +#include <linux/fs.h>
60399 +#include <linux/grinternal.h>
60400 +
60401 +extern int gr_acl_tpe_check(void);
60402 +
60403 +int
60404 +gr_tpe_allow(const struct file *file)
60405 +{
60406 +#ifdef CONFIG_GRKERNSEC
60407 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60408 + const struct cred *cred = current_cred();
60409 + char *msg = NULL;
60410 + char *msg2 = NULL;
60411 +
60412 + // never restrict root
60413 + if (!cred->uid)
60414 + return 1;
60415 +
60416 + if (grsec_enable_tpe) {
60417 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60418 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60419 + msg = "not being in trusted group";
60420 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60421 + msg = "being in untrusted group";
60422 +#else
60423 + if (in_group_p(grsec_tpe_gid))
60424 + msg = "being in untrusted group";
60425 +#endif
60426 + }
60427 + if (!msg && gr_acl_tpe_check())
60428 + msg = "being in untrusted role";
60429 +
60430 + // not in any affected group/role
60431 + if (!msg)
60432 + goto next_check;
60433 +
60434 + if (inode->i_uid)
60435 + msg2 = "file in non-root-owned directory";
60436 + else if (inode->i_mode & S_IWOTH)
60437 + msg2 = "file in world-writable directory";
60438 + else if (inode->i_mode & S_IWGRP)
60439 + msg2 = "file in group-writable directory";
60440 +
60441 + if (msg && msg2) {
60442 + char fullmsg[70] = {0};
60443 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60444 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60445 + return 0;
60446 + }
60447 + msg = NULL;
60448 +next_check:
60449 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60450 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60451 + return 1;
60452 +
60453 + if (inode->i_uid && (inode->i_uid != cred->uid))
60454 + msg = "directory not owned by user";
60455 + else if (inode->i_mode & S_IWOTH)
60456 + msg = "file in world-writable directory";
60457 + else if (inode->i_mode & S_IWGRP)
60458 + msg = "file in group-writable directory";
60459 +
60460 + if (msg) {
60461 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60462 + return 0;
60463 + }
60464 +#endif
60465 +#endif
60466 + return 1;
60467 +}
60468 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60469 new file mode 100644
60470 index 0000000..9f7b1ac
60471 --- /dev/null
60472 +++ b/grsecurity/grsum.c
60473 @@ -0,0 +1,61 @@
60474 +#include <linux/err.h>
60475 +#include <linux/kernel.h>
60476 +#include <linux/sched.h>
60477 +#include <linux/mm.h>
60478 +#include <linux/scatterlist.h>
60479 +#include <linux/crypto.h>
60480 +#include <linux/gracl.h>
60481 +
60482 +
60483 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60484 +#error "crypto and sha256 must be built into the kernel"
60485 +#endif
60486 +
60487 +int
60488 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60489 +{
60490 + char *p;
60491 + struct crypto_hash *tfm;
60492 + struct hash_desc desc;
60493 + struct scatterlist sg;
60494 + unsigned char temp_sum[GR_SHA_LEN];
60495 + volatile int retval = 0;
60496 + volatile int dummy = 0;
60497 + unsigned int i;
60498 +
60499 + sg_init_table(&sg, 1);
60500 +
60501 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60502 + if (IS_ERR(tfm)) {
60503 + /* should never happen, since sha256 should be built in */
60504 + return 1;
60505 + }
60506 +
60507 + desc.tfm = tfm;
60508 + desc.flags = 0;
60509 +
60510 + crypto_hash_init(&desc);
60511 +
60512 + p = salt;
60513 + sg_set_buf(&sg, p, GR_SALT_LEN);
60514 + crypto_hash_update(&desc, &sg, sg.length);
60515 +
60516 + p = entry->pw;
60517 + sg_set_buf(&sg, p, strlen(p));
60518 +
60519 + crypto_hash_update(&desc, &sg, sg.length);
60520 +
60521 + crypto_hash_final(&desc, temp_sum);
60522 +
60523 + memset(entry->pw, 0, GR_PW_LEN);
60524 +
60525 + for (i = 0; i < GR_SHA_LEN; i++)
60526 + if (sum[i] != temp_sum[i])
60527 + retval = 1;
60528 + else
60529 + dummy = 1; // waste a cycle
60530 +
60531 + crypto_free_hash(tfm);
60532 +
60533 + return retval;
60534 +}
60535 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60536 index bde976e..a1cc32a 100644
60537 --- a/include/acpi/acpi_bus.h
60538 +++ b/include/acpi/acpi_bus.h
60539 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60540 acpi_op_bind bind;
60541 acpi_op_unbind unbind;
60542 acpi_op_notify notify;
60543 -};
60544 +} __no_const;
60545
60546 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60547
60548 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60549 index 77ff547..181834f 100644
60550 --- a/include/asm-generic/4level-fixup.h
60551 +++ b/include/asm-generic/4level-fixup.h
60552 @@ -13,8 +13,10 @@
60553 #define pmd_alloc(mm, pud, address) \
60554 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60555 NULL: pmd_offset(pud, address))
60556 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60557
60558 #define pud_alloc(mm, pgd, address) (pgd)
60559 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60560 #define pud_offset(pgd, start) (pgd)
60561 #define pud_none(pud) 0
60562 #define pud_bad(pud) 0
60563 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60564 index b7babf0..3ba8aee 100644
60565 --- a/include/asm-generic/atomic-long.h
60566 +++ b/include/asm-generic/atomic-long.h
60567 @@ -22,6 +22,12 @@
60568
60569 typedef atomic64_t atomic_long_t;
60570
60571 +#ifdef CONFIG_PAX_REFCOUNT
60572 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60573 +#else
60574 +typedef atomic64_t atomic_long_unchecked_t;
60575 +#endif
60576 +
60577 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60578
60579 static inline long atomic_long_read(atomic_long_t *l)
60580 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60581 return (long)atomic64_read(v);
60582 }
60583
60584 +#ifdef CONFIG_PAX_REFCOUNT
60585 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60586 +{
60587 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60588 +
60589 + return (long)atomic64_read_unchecked(v);
60590 +}
60591 +#endif
60592 +
60593 static inline void atomic_long_set(atomic_long_t *l, long i)
60594 {
60595 atomic64_t *v = (atomic64_t *)l;
60596 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60597 atomic64_set(v, i);
60598 }
60599
60600 +#ifdef CONFIG_PAX_REFCOUNT
60601 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60602 +{
60603 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60604 +
60605 + atomic64_set_unchecked(v, i);
60606 +}
60607 +#endif
60608 +
60609 static inline void atomic_long_inc(atomic_long_t *l)
60610 {
60611 atomic64_t *v = (atomic64_t *)l;
60612 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60613 atomic64_inc(v);
60614 }
60615
60616 +#ifdef CONFIG_PAX_REFCOUNT
60617 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60618 +{
60619 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60620 +
60621 + atomic64_inc_unchecked(v);
60622 +}
60623 +#endif
60624 +
60625 static inline void atomic_long_dec(atomic_long_t *l)
60626 {
60627 atomic64_t *v = (atomic64_t *)l;
60628 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60629 atomic64_dec(v);
60630 }
60631
60632 +#ifdef CONFIG_PAX_REFCOUNT
60633 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60634 +{
60635 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60636 +
60637 + atomic64_dec_unchecked(v);
60638 +}
60639 +#endif
60640 +
60641 static inline void atomic_long_add(long i, atomic_long_t *l)
60642 {
60643 atomic64_t *v = (atomic64_t *)l;
60644 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60645 atomic64_add(i, v);
60646 }
60647
60648 +#ifdef CONFIG_PAX_REFCOUNT
60649 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60650 +{
60651 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60652 +
60653 + atomic64_add_unchecked(i, v);
60654 +}
60655 +#endif
60656 +
60657 static inline void atomic_long_sub(long i, atomic_long_t *l)
60658 {
60659 atomic64_t *v = (atomic64_t *)l;
60660 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60661 atomic64_sub(i, v);
60662 }
60663
60664 +#ifdef CONFIG_PAX_REFCOUNT
60665 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60666 +{
60667 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60668 +
60669 + atomic64_sub_unchecked(i, v);
60670 +}
60671 +#endif
60672 +
60673 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60674 {
60675 atomic64_t *v = (atomic64_t *)l;
60676 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60677 return (long)atomic64_inc_return(v);
60678 }
60679
60680 +#ifdef CONFIG_PAX_REFCOUNT
60681 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60682 +{
60683 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60684 +
60685 + return (long)atomic64_inc_return_unchecked(v);
60686 +}
60687 +#endif
60688 +
60689 static inline long atomic_long_dec_return(atomic_long_t *l)
60690 {
60691 atomic64_t *v = (atomic64_t *)l;
60692 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60693
60694 typedef atomic_t atomic_long_t;
60695
60696 +#ifdef CONFIG_PAX_REFCOUNT
60697 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60698 +#else
60699 +typedef atomic_t atomic_long_unchecked_t;
60700 +#endif
60701 +
60702 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60703 static inline long atomic_long_read(atomic_long_t *l)
60704 {
60705 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60706 return (long)atomic_read(v);
60707 }
60708
60709 +#ifdef CONFIG_PAX_REFCOUNT
60710 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60711 +{
60712 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60713 +
60714 + return (long)atomic_read_unchecked(v);
60715 +}
60716 +#endif
60717 +
60718 static inline void atomic_long_set(atomic_long_t *l, long i)
60719 {
60720 atomic_t *v = (atomic_t *)l;
60721 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60722 atomic_set(v, i);
60723 }
60724
60725 +#ifdef CONFIG_PAX_REFCOUNT
60726 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60727 +{
60728 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60729 +
60730 + atomic_set_unchecked(v, i);
60731 +}
60732 +#endif
60733 +
60734 static inline void atomic_long_inc(atomic_long_t *l)
60735 {
60736 atomic_t *v = (atomic_t *)l;
60737 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60738 atomic_inc(v);
60739 }
60740
60741 +#ifdef CONFIG_PAX_REFCOUNT
60742 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60743 +{
60744 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60745 +
60746 + atomic_inc_unchecked(v);
60747 +}
60748 +#endif
60749 +
60750 static inline void atomic_long_dec(atomic_long_t *l)
60751 {
60752 atomic_t *v = (atomic_t *)l;
60753 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60754 atomic_dec(v);
60755 }
60756
60757 +#ifdef CONFIG_PAX_REFCOUNT
60758 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60759 +{
60760 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60761 +
60762 + atomic_dec_unchecked(v);
60763 +}
60764 +#endif
60765 +
60766 static inline void atomic_long_add(long i, atomic_long_t *l)
60767 {
60768 atomic_t *v = (atomic_t *)l;
60769 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60770 atomic_add(i, v);
60771 }
60772
60773 +#ifdef CONFIG_PAX_REFCOUNT
60774 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60775 +{
60776 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60777 +
60778 + atomic_add_unchecked(i, v);
60779 +}
60780 +#endif
60781 +
60782 static inline void atomic_long_sub(long i, atomic_long_t *l)
60783 {
60784 atomic_t *v = (atomic_t *)l;
60785 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60786 atomic_sub(i, v);
60787 }
60788
60789 +#ifdef CONFIG_PAX_REFCOUNT
60790 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60791 +{
60792 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60793 +
60794 + atomic_sub_unchecked(i, v);
60795 +}
60796 +#endif
60797 +
60798 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60799 {
60800 atomic_t *v = (atomic_t *)l;
60801 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60802 return (long)atomic_inc_return(v);
60803 }
60804
60805 +#ifdef CONFIG_PAX_REFCOUNT
60806 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60807 +{
60808 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60809 +
60810 + return (long)atomic_inc_return_unchecked(v);
60811 +}
60812 +#endif
60813 +
60814 static inline long atomic_long_dec_return(atomic_long_t *l)
60815 {
60816 atomic_t *v = (atomic_t *)l;
60817 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60818
60819 #endif /* BITS_PER_LONG == 64 */
60820
60821 +#ifdef CONFIG_PAX_REFCOUNT
60822 +static inline void pax_refcount_needs_these_functions(void)
60823 +{
60824 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60825 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60826 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60827 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60828 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60829 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60830 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60831 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60832 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60833 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60834 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60835 +#ifdef CONFIG_X86
60836 + atomic_clear_mask_unchecked(0, NULL);
60837 + atomic_set_mask_unchecked(0, NULL);
60838 +#endif
60839 +
60840 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60841 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60842 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60843 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60844 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60845 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60846 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60847 +}
60848 +#else
60849 +#define atomic_read_unchecked(v) atomic_read(v)
60850 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60851 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60852 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60853 +#define atomic_inc_unchecked(v) atomic_inc(v)
60854 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60855 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60856 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60857 +#define atomic_dec_unchecked(v) atomic_dec(v)
60858 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60859 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60860 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60861 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60862 +
60863 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60864 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60865 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60866 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60867 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60868 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60869 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60870 +#endif
60871 +
60872 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60873 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60874 index 1ced641..c896ee8 100644
60875 --- a/include/asm-generic/atomic.h
60876 +++ b/include/asm-generic/atomic.h
60877 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60878 * Atomically clears the bits set in @mask from @v
60879 */
60880 #ifndef atomic_clear_mask
60881 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60882 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60883 {
60884 unsigned long flags;
60885
60886 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60887 index b18ce4f..2ee2843 100644
60888 --- a/include/asm-generic/atomic64.h
60889 +++ b/include/asm-generic/atomic64.h
60890 @@ -16,6 +16,8 @@ typedef struct {
60891 long long counter;
60892 } atomic64_t;
60893
60894 +typedef atomic64_t atomic64_unchecked_t;
60895 +
60896 #define ATOMIC64_INIT(i) { (i) }
60897
60898 extern long long atomic64_read(const atomic64_t *v);
60899 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60900 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60901 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60902
60903 +#define atomic64_read_unchecked(v) atomic64_read(v)
60904 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60905 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60906 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60907 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60908 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60909 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60910 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60911 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60912 +
60913 #endif /* _ASM_GENERIC_ATOMIC64_H */
60914 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60915 index 1bfcfe5..e04c5c9 100644
60916 --- a/include/asm-generic/cache.h
60917 +++ b/include/asm-generic/cache.h
60918 @@ -6,7 +6,7 @@
60919 * cache lines need to provide their own cache.h.
60920 */
60921
60922 -#define L1_CACHE_SHIFT 5
60923 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60924 +#define L1_CACHE_SHIFT 5UL
60925 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60926
60927 #endif /* __ASM_GENERIC_CACHE_H */
60928 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60929 index 0d68a1e..b74a761 100644
60930 --- a/include/asm-generic/emergency-restart.h
60931 +++ b/include/asm-generic/emergency-restart.h
60932 @@ -1,7 +1,7 @@
60933 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60934 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60935
60936 -static inline void machine_emergency_restart(void)
60937 +static inline __noreturn void machine_emergency_restart(void)
60938 {
60939 machine_restart(NULL);
60940 }
60941 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60942 index 90f99c7..00ce236 100644
60943 --- a/include/asm-generic/kmap_types.h
60944 +++ b/include/asm-generic/kmap_types.h
60945 @@ -2,9 +2,9 @@
60946 #define _ASM_GENERIC_KMAP_TYPES_H
60947
60948 #ifdef __WITH_KM_FENCE
60949 -# define KM_TYPE_NR 41
60950 +# define KM_TYPE_NR 42
60951 #else
60952 -# define KM_TYPE_NR 20
60953 +# define KM_TYPE_NR 21
60954 #endif
60955
60956 #endif
60957 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60958 index 9ceb03b..2efbcbd 100644
60959 --- a/include/asm-generic/local.h
60960 +++ b/include/asm-generic/local.h
60961 @@ -39,6 +39,7 @@ typedef struct
60962 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60963 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60964 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60965 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60966
60967 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60968 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60969 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60970 index 725612b..9cc513a 100644
60971 --- a/include/asm-generic/pgtable-nopmd.h
60972 +++ b/include/asm-generic/pgtable-nopmd.h
60973 @@ -1,14 +1,19 @@
60974 #ifndef _PGTABLE_NOPMD_H
60975 #define _PGTABLE_NOPMD_H
60976
60977 -#ifndef __ASSEMBLY__
60978 -
60979 #include <asm-generic/pgtable-nopud.h>
60980
60981 -struct mm_struct;
60982 -
60983 #define __PAGETABLE_PMD_FOLDED
60984
60985 +#define PMD_SHIFT PUD_SHIFT
60986 +#define PTRS_PER_PMD 1
60987 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60988 +#define PMD_MASK (~(PMD_SIZE-1))
60989 +
60990 +#ifndef __ASSEMBLY__
60991 +
60992 +struct mm_struct;
60993 +
60994 /*
60995 * Having the pmd type consist of a pud gets the size right, and allows
60996 * us to conceptually access the pud entry that this pmd is folded into
60997 @@ -16,11 +21,6 @@ struct mm_struct;
60998 */
60999 typedef struct { pud_t pud; } pmd_t;
61000
61001 -#define PMD_SHIFT PUD_SHIFT
61002 -#define PTRS_PER_PMD 1
61003 -#define PMD_SIZE (1UL << PMD_SHIFT)
61004 -#define PMD_MASK (~(PMD_SIZE-1))
61005 -
61006 /*
61007 * The "pud_xxx()" functions here are trivial for a folded two-level
61008 * setup: the pmd is never bad, and a pmd always exists (as it's folded
61009 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
61010 index 810431d..0ec4804f 100644
61011 --- a/include/asm-generic/pgtable-nopud.h
61012 +++ b/include/asm-generic/pgtable-nopud.h
61013 @@ -1,10 +1,15 @@
61014 #ifndef _PGTABLE_NOPUD_H
61015 #define _PGTABLE_NOPUD_H
61016
61017 -#ifndef __ASSEMBLY__
61018 -
61019 #define __PAGETABLE_PUD_FOLDED
61020
61021 +#define PUD_SHIFT PGDIR_SHIFT
61022 +#define PTRS_PER_PUD 1
61023 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
61024 +#define PUD_MASK (~(PUD_SIZE-1))
61025 +
61026 +#ifndef __ASSEMBLY__
61027 +
61028 /*
61029 * Having the pud type consist of a pgd gets the size right, and allows
61030 * us to conceptually access the pgd entry that this pud is folded into
61031 @@ -12,11 +17,6 @@
61032 */
61033 typedef struct { pgd_t pgd; } pud_t;
61034
61035 -#define PUD_SHIFT PGDIR_SHIFT
61036 -#define PTRS_PER_PUD 1
61037 -#define PUD_SIZE (1UL << PUD_SHIFT)
61038 -#define PUD_MASK (~(PUD_SIZE-1))
61039 -
61040 /*
61041 * The "pgd_xxx()" functions here are trivial for a folded two-level
61042 * setup: the pud is never bad, and a pud always exists (as it's folded
61043 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
61044 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
61045
61046 #define pgd_populate(mm, pgd, pud) do { } while (0)
61047 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
61048 /*
61049 * (puds are folded into pgds so this doesn't get actually called,
61050 * but the define is needed for a generic inline function.)
61051 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
61052 index ff4947b..f48183f 100644
61053 --- a/include/asm-generic/pgtable.h
61054 +++ b/include/asm-generic/pgtable.h
61055 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61056 #endif
61057 }
61058
61059 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61060 +static inline unsigned long pax_open_kernel(void) { return 0; }
61061 +#endif
61062 +
61063 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61064 +static inline unsigned long pax_close_kernel(void) { return 0; }
61065 +#endif
61066 +
61067 #endif /* CONFIG_MMU */
61068
61069 #endif /* !__ASSEMBLY__ */
61070 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61071 index 4e2e1cc..12c266b 100644
61072 --- a/include/asm-generic/vmlinux.lds.h
61073 +++ b/include/asm-generic/vmlinux.lds.h
61074 @@ -218,6 +218,7 @@
61075 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61076 VMLINUX_SYMBOL(__start_rodata) = .; \
61077 *(.rodata) *(.rodata.*) \
61078 + *(.data..read_only) \
61079 *(__vermagic) /* Kernel version magic */ \
61080 . = ALIGN(8); \
61081 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61082 @@ -716,17 +717,18 @@
61083 * section in the linker script will go there too. @phdr should have
61084 * a leading colon.
61085 *
61086 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61087 + * Note that this macros defines per_cpu_load as an absolute symbol.
61088 * If there is no need to put the percpu section at a predetermined
61089 * address, use PERCPU_SECTION.
61090 */
61091 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61092 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61093 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61094 + per_cpu_load = .; \
61095 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61096 - LOAD_OFFSET) { \
61097 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61098 PERCPU_INPUT(cacheline) \
61099 } phdr \
61100 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61101 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61102
61103 /**
61104 * PERCPU_SECTION - define output section for percpu area, simple version
61105 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61106 index d6b67bb..a272c29 100644
61107 --- a/include/drm/drmP.h
61108 +++ b/include/drm/drmP.h
61109 @@ -72,6 +72,7 @@
61110 #include <linux/workqueue.h>
61111 #include <linux/poll.h>
61112 #include <asm/pgalloc.h>
61113 +#include <asm/local.h>
61114 #include "drm.h"
61115
61116 #include <linux/idr.h>
61117 @@ -1067,7 +1068,7 @@ struct drm_device {
61118
61119 /** \name Usage Counters */
61120 /*@{ */
61121 - int open_count; /**< Outstanding files open */
61122 + local_t open_count; /**< Outstanding files open */
61123 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61124 atomic_t vma_count; /**< Outstanding vma areas open */
61125 int buf_use; /**< Buffers in use -- cannot alloc */
61126 @@ -1078,7 +1079,7 @@ struct drm_device {
61127 /*@{ */
61128 unsigned long counters;
61129 enum drm_stat_type types[15];
61130 - atomic_t counts[15];
61131 + atomic_unchecked_t counts[15];
61132 /*@} */
61133
61134 struct list_head filelist;
61135 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61136 index e01cc80..319855d 100644
61137 --- a/include/drm/drm_crtc_helper.h
61138 +++ b/include/drm/drm_crtc_helper.h
61139 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61140
61141 /* disable crtc when not in use - more explicit than dpms off */
61142 void (*disable)(struct drm_crtc *crtc);
61143 -};
61144 +} __no_const;
61145
61146 /**
61147 * drm_encoder_helper_funcs - helper operations for encoders
61148 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61149 struct drm_connector *connector);
61150 /* disable encoder when not in use - more explicit than dpms off */
61151 void (*disable)(struct drm_encoder *encoder);
61152 -};
61153 +} __no_const;
61154
61155 /**
61156 * drm_connector_helper_funcs - helper operations for connectors
61157 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61158 index d6d1da4..fdd1ac5 100644
61159 --- a/include/drm/ttm/ttm_memory.h
61160 +++ b/include/drm/ttm/ttm_memory.h
61161 @@ -48,7 +48,7 @@
61162
61163 struct ttm_mem_shrink {
61164 int (*do_shrink) (struct ttm_mem_shrink *);
61165 -};
61166 +} __no_const;
61167
61168 /**
61169 * struct ttm_mem_global - Global memory accounting structure.
61170 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61171 index e86dfca..40cc55f 100644
61172 --- a/include/linux/a.out.h
61173 +++ b/include/linux/a.out.h
61174 @@ -39,6 +39,14 @@ enum machine_type {
61175 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61176 };
61177
61178 +/* Constants for the N_FLAGS field */
61179 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61180 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61181 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61182 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61183 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61184 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61185 +
61186 #if !defined (N_MAGIC)
61187 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61188 #endif
61189 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61190 index 06fd4bb..1caec0d 100644
61191 --- a/include/linux/atmdev.h
61192 +++ b/include/linux/atmdev.h
61193 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61194 #endif
61195
61196 struct k_atm_aal_stats {
61197 -#define __HANDLE_ITEM(i) atomic_t i
61198 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61199 __AAL_STAT_ITEMS
61200 #undef __HANDLE_ITEM
61201 };
61202 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61203 index 366422b..1fa7f84 100644
61204 --- a/include/linux/binfmts.h
61205 +++ b/include/linux/binfmts.h
61206 @@ -89,6 +89,7 @@ struct linux_binfmt {
61207 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61208 int (*load_shlib)(struct file *);
61209 int (*core_dump)(struct coredump_params *cprm);
61210 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61211 unsigned long min_coredump; /* minimal dump size */
61212 };
61213
61214 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61215 index 4a2ab7c..a2de7a8 100644
61216 --- a/include/linux/blkdev.h
61217 +++ b/include/linux/blkdev.h
61218 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61219 /* this callback is with swap_lock and sometimes page table lock held */
61220 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61221 struct module *owner;
61222 -};
61223 +} __do_const;
61224
61225 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61226 unsigned long);
61227 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61228 index 4d1a074..88f929a 100644
61229 --- a/include/linux/blktrace_api.h
61230 +++ b/include/linux/blktrace_api.h
61231 @@ -162,7 +162,7 @@ struct blk_trace {
61232 struct dentry *dir;
61233 struct dentry *dropped_file;
61234 struct dentry *msg_file;
61235 - atomic_t dropped;
61236 + atomic_unchecked_t dropped;
61237 };
61238
61239 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61240 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61241 index 83195fb..0b0f77d 100644
61242 --- a/include/linux/byteorder/little_endian.h
61243 +++ b/include/linux/byteorder/little_endian.h
61244 @@ -42,51 +42,51 @@
61245
61246 static inline __le64 __cpu_to_le64p(const __u64 *p)
61247 {
61248 - return (__force __le64)*p;
61249 + return (__force const __le64)*p;
61250 }
61251 static inline __u64 __le64_to_cpup(const __le64 *p)
61252 {
61253 - return (__force __u64)*p;
61254 + return (__force const __u64)*p;
61255 }
61256 static inline __le32 __cpu_to_le32p(const __u32 *p)
61257 {
61258 - return (__force __le32)*p;
61259 + return (__force const __le32)*p;
61260 }
61261 static inline __u32 __le32_to_cpup(const __le32 *p)
61262 {
61263 - return (__force __u32)*p;
61264 + return (__force const __u32)*p;
61265 }
61266 static inline __le16 __cpu_to_le16p(const __u16 *p)
61267 {
61268 - return (__force __le16)*p;
61269 + return (__force const __le16)*p;
61270 }
61271 static inline __u16 __le16_to_cpup(const __le16 *p)
61272 {
61273 - return (__force __u16)*p;
61274 + return (__force const __u16)*p;
61275 }
61276 static inline __be64 __cpu_to_be64p(const __u64 *p)
61277 {
61278 - return (__force __be64)__swab64p(p);
61279 + return (__force const __be64)__swab64p(p);
61280 }
61281 static inline __u64 __be64_to_cpup(const __be64 *p)
61282 {
61283 - return __swab64p((__u64 *)p);
61284 + return __swab64p((const __u64 *)p);
61285 }
61286 static inline __be32 __cpu_to_be32p(const __u32 *p)
61287 {
61288 - return (__force __be32)__swab32p(p);
61289 + return (__force const __be32)__swab32p(p);
61290 }
61291 static inline __u32 __be32_to_cpup(const __be32 *p)
61292 {
61293 - return __swab32p((__u32 *)p);
61294 + return __swab32p((const __u32 *)p);
61295 }
61296 static inline __be16 __cpu_to_be16p(const __u16 *p)
61297 {
61298 - return (__force __be16)__swab16p(p);
61299 + return (__force const __be16)__swab16p(p);
61300 }
61301 static inline __u16 __be16_to_cpup(const __be16 *p)
61302 {
61303 - return __swab16p((__u16 *)p);
61304 + return __swab16p((const __u16 *)p);
61305 }
61306 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61307 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61308 diff --git a/include/linux/cache.h b/include/linux/cache.h
61309 index 4c57065..4307975 100644
61310 --- a/include/linux/cache.h
61311 +++ b/include/linux/cache.h
61312 @@ -16,6 +16,10 @@
61313 #define __read_mostly
61314 #endif
61315
61316 +#ifndef __read_only
61317 +#define __read_only __read_mostly
61318 +#endif
61319 +
61320 #ifndef ____cacheline_aligned
61321 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61322 #endif
61323 diff --git a/include/linux/capability.h b/include/linux/capability.h
61324 index d10b7ed..0288b79 100644
61325 --- a/include/linux/capability.h
61326 +++ b/include/linux/capability.h
61327 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61328 extern bool ns_capable(struct user_namespace *ns, int cap);
61329 extern bool nsown_capable(int cap);
61330 extern bool inode_capable(const struct inode *inode, int cap);
61331 +extern bool capable_nolog(int cap);
61332 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61333 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61334
61335 /* audit system wants to get cap info from files as well */
61336 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61337
61338 +extern int is_privileged_binary(const struct dentry *dentry);
61339 +
61340 #endif /* __KERNEL__ */
61341
61342 #endif /* !_LINUX_CAPABILITY_H */
61343 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61344 index 42e55de..1cd0e66 100644
61345 --- a/include/linux/cleancache.h
61346 +++ b/include/linux/cleancache.h
61347 @@ -31,7 +31,7 @@ struct cleancache_ops {
61348 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61349 void (*invalidate_inode)(int, struct cleancache_filekey);
61350 void (*invalidate_fs)(int);
61351 -};
61352 +} __no_const;
61353
61354 extern struct cleancache_ops
61355 cleancache_register_ops(struct cleancache_ops *ops);
61356 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61357 index 77335fa..6cbe7dd 100644
61358 --- a/include/linux/clk-provider.h
61359 +++ b/include/linux/clk-provider.h
61360 @@ -111,6 +111,7 @@ struct clk_ops {
61361 unsigned long);
61362 void (*init)(struct clk_hw *hw);
61363 };
61364 +typedef struct clk_ops __no_const clk_ops_no_const;
61365
61366 /**
61367 * struct clk_init_data - holds init data that's common to all clocks and is
61368 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61369 index 934bc34..1b47129 100644
61370 --- a/include/linux/compiler-gcc4.h
61371 +++ b/include/linux/compiler-gcc4.h
61372 @@ -32,6 +32,21 @@
61373 #define __linktime_error(message) __attribute__((__error__(message)))
61374
61375 #if __GNUC_MINOR__ >= 5
61376 +
61377 +#ifdef CONSTIFY_PLUGIN
61378 +#define __no_const __attribute__((no_const))
61379 +#define __do_const __attribute__((do_const))
61380 +#endif
61381 +
61382 +#ifdef SIZE_OVERFLOW_PLUGIN
61383 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61384 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61385 +#endif
61386 +
61387 +#ifdef LATENT_ENTROPY_PLUGIN
61388 +#define __latent_entropy __attribute__((latent_entropy))
61389 +#endif
61390 +
61391 /*
61392 * Mark a position in code as unreachable. This can be used to
61393 * suppress control flow warnings after asm blocks that transfer
61394 @@ -47,6 +62,11 @@
61395 #define __noclone __attribute__((__noclone__))
61396
61397 #endif
61398 +
61399 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61400 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61401 +#define __bos0(ptr) __bos((ptr), 0)
61402 +#define __bos1(ptr) __bos((ptr), 1)
61403 #endif
61404
61405 #if __GNUC_MINOR__ >= 6
61406 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61407 index f430e41..38be90f 100644
61408 --- a/include/linux/compiler.h
61409 +++ b/include/linux/compiler.h
61410 @@ -5,31 +5,62 @@
61411
61412 #ifdef __CHECKER__
61413 # define __user __attribute__((noderef, address_space(1)))
61414 +# define __force_user __force __user
61415 # define __kernel __attribute__((address_space(0)))
61416 +# define __force_kernel __force __kernel
61417 # define __safe __attribute__((safe))
61418 # define __force __attribute__((force))
61419 # define __nocast __attribute__((nocast))
61420 # define __iomem __attribute__((noderef, address_space(2)))
61421 +# define __force_iomem __force __iomem
61422 # define __acquires(x) __attribute__((context(x,0,1)))
61423 # define __releases(x) __attribute__((context(x,1,0)))
61424 # define __acquire(x) __context__(x,1)
61425 # define __release(x) __context__(x,-1)
61426 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61427 # define __percpu __attribute__((noderef, address_space(3)))
61428 +# define __force_percpu __force __percpu
61429 #ifdef CONFIG_SPARSE_RCU_POINTER
61430 # define __rcu __attribute__((noderef, address_space(4)))
61431 +# define __force_rcu __force __rcu
61432 #else
61433 # define __rcu
61434 +# define __force_rcu
61435 #endif
61436 extern void __chk_user_ptr(const volatile void __user *);
61437 extern void __chk_io_ptr(const volatile void __iomem *);
61438 +#elif defined(CHECKER_PLUGIN)
61439 +//# define __user
61440 +//# define __force_user
61441 +//# define __kernel
61442 +//# define __force_kernel
61443 +# define __safe
61444 +# define __force
61445 +# define __nocast
61446 +# define __iomem
61447 +# define __force_iomem
61448 +# define __chk_user_ptr(x) (void)0
61449 +# define __chk_io_ptr(x) (void)0
61450 +# define __builtin_warning(x, y...) (1)
61451 +# define __acquires(x)
61452 +# define __releases(x)
61453 +# define __acquire(x) (void)0
61454 +# define __release(x) (void)0
61455 +# define __cond_lock(x,c) (c)
61456 +# define __percpu
61457 +# define __force_percpu
61458 +# define __rcu
61459 +# define __force_rcu
61460 #else
61461 # define __user
61462 +# define __force_user
61463 # define __kernel
61464 +# define __force_kernel
61465 # define __safe
61466 # define __force
61467 # define __nocast
61468 # define __iomem
61469 +# define __force_iomem
61470 # define __chk_user_ptr(x) (void)0
61471 # define __chk_io_ptr(x) (void)0
61472 # define __builtin_warning(x, y...) (1)
61473 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61474 # define __release(x) (void)0
61475 # define __cond_lock(x,c) (c)
61476 # define __percpu
61477 +# define __force_percpu
61478 # define __rcu
61479 +# define __force_rcu
61480 #endif
61481
61482 #ifdef __KERNEL__
61483 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61484 # define __attribute_const__ /* unimplemented */
61485 #endif
61486
61487 +#ifndef __no_const
61488 +# define __no_const
61489 +#endif
61490 +
61491 +#ifndef __do_const
61492 +# define __do_const
61493 +#endif
61494 +
61495 +#ifndef __size_overflow
61496 +# define __size_overflow(...)
61497 +#endif
61498 +
61499 +#ifndef __intentional_overflow
61500 +# define __intentional_overflow(...)
61501 +#endif
61502 +
61503 +#ifndef __latent_entropy
61504 +# define __latent_entropy
61505 +#endif
61506 +
61507 /*
61508 * Tell gcc if a function is cold. The compiler will assume any path
61509 * directly leading to the call is unlikely.
61510 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61511 #define __cold
61512 #endif
61513
61514 +#ifndef __alloc_size
61515 +#define __alloc_size(...)
61516 +#endif
61517 +
61518 +#ifndef __bos
61519 +#define __bos(ptr, arg)
61520 +#endif
61521 +
61522 +#ifndef __bos0
61523 +#define __bos0(ptr)
61524 +#endif
61525 +
61526 +#ifndef __bos1
61527 +#define __bos1(ptr)
61528 +#endif
61529 +
61530 /* Simple shorthand for a section definition */
61531 #ifndef __section
61532 # define __section(S) __attribute__ ((__section__(#S)))
61533 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61534 * use is to mediate communication between process-level code and irq/NMI
61535 * handlers, all running on the same CPU.
61536 */
61537 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61538 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61539 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61540
61541 #endif /* __LINUX_COMPILER_H */
61542 diff --git a/include/linux/cred.h b/include/linux/cred.h
61543 index ebbed2c..908cc2c 100644
61544 --- a/include/linux/cred.h
61545 +++ b/include/linux/cred.h
61546 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61547 static inline void validate_process_creds(void)
61548 {
61549 }
61550 +static inline void validate_task_creds(struct task_struct *task)
61551 +{
61552 +}
61553 #endif
61554
61555 /**
61556 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61557 index b92eadf..b4ecdc1 100644
61558 --- a/include/linux/crypto.h
61559 +++ b/include/linux/crypto.h
61560 @@ -373,7 +373,7 @@ struct cipher_tfm {
61561 const u8 *key, unsigned int keylen);
61562 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61563 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61564 -};
61565 +} __no_const;
61566
61567 struct hash_tfm {
61568 int (*init)(struct hash_desc *desc);
61569 @@ -394,13 +394,13 @@ struct compress_tfm {
61570 int (*cot_decompress)(struct crypto_tfm *tfm,
61571 const u8 *src, unsigned int slen,
61572 u8 *dst, unsigned int *dlen);
61573 -};
61574 +} __no_const;
61575
61576 struct rng_tfm {
61577 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61578 unsigned int dlen);
61579 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61580 -};
61581 +} __no_const;
61582
61583 #define crt_ablkcipher crt_u.ablkcipher
61584 #define crt_aead crt_u.aead
61585 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61586 index 7925bf0..d5143d2 100644
61587 --- a/include/linux/decompress/mm.h
61588 +++ b/include/linux/decompress/mm.h
61589 @@ -77,7 +77,7 @@ static void free(void *where)
61590 * warnings when not needed (indeed large_malloc / large_free are not
61591 * needed by inflate */
61592
61593 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61594 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61595 #define free(a) kfree(a)
61596
61597 #define large_malloc(a) vmalloc(a)
61598 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61599 index 94af418..b1ca7a2 100644
61600 --- a/include/linux/dma-mapping.h
61601 +++ b/include/linux/dma-mapping.h
61602 @@ -54,7 +54,7 @@ struct dma_map_ops {
61603 u64 (*get_required_mask)(struct device *dev);
61604 #endif
61605 int is_phys;
61606 -};
61607 +} __do_const;
61608
61609 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61610
61611 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61612 index 9c02a45..89fdd73 100644
61613 --- a/include/linux/dmaengine.h
61614 +++ b/include/linux/dmaengine.h
61615 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61616 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61617 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61618
61619 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61620 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61621 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61622 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61623 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61624 struct dma_pinned_list *pinned_list, struct page *page,
61625 unsigned int offset, size_t len);
61626
61627 diff --git a/include/linux/efi.h b/include/linux/efi.h
61628 index 5782114..e9b1ba1 100644
61629 --- a/include/linux/efi.h
61630 +++ b/include/linux/efi.h
61631 @@ -640,7 +640,7 @@ struct efivar_operations {
61632 efi_get_variable_t *get_variable;
61633 efi_get_next_variable_t *get_next_variable;
61634 efi_set_variable_t *set_variable;
61635 -};
61636 +} __no_const;
61637
61638 struct efivars {
61639 /*
61640 diff --git a/include/linux/elf.h b/include/linux/elf.h
61641 index 999b4f5..57753b4 100644
61642 --- a/include/linux/elf.h
61643 +++ b/include/linux/elf.h
61644 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61645 #define PT_GNU_EH_FRAME 0x6474e550
61646
61647 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61648 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61649 +
61650 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61651 +
61652 +/* Constants for the e_flags field */
61653 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61654 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61655 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61656 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61657 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61658 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61659
61660 /*
61661 * Extended Numbering
61662 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61663 #define DT_DEBUG 21
61664 #define DT_TEXTREL 22
61665 #define DT_JMPREL 23
61666 +#define DT_FLAGS 30
61667 + #define DF_TEXTREL 0x00000004
61668 #define DT_ENCODING 32
61669 #define OLD_DT_LOOS 0x60000000
61670 #define DT_LOOS 0x6000000d
61671 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61672 #define PF_W 0x2
61673 #define PF_X 0x1
61674
61675 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61676 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61677 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61678 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61679 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61680 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61681 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61682 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61683 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61684 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61685 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61686 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61687 +
61688 typedef struct elf32_phdr{
61689 Elf32_Word p_type;
61690 Elf32_Off p_offset;
61691 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61692 #define EI_OSABI 7
61693 #define EI_PAD 8
61694
61695 +#define EI_PAX 14
61696 +
61697 #define ELFMAG0 0x7f /* EI_MAG */
61698 #define ELFMAG1 'E'
61699 #define ELFMAG2 'L'
61700 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61701 #define elf_note elf32_note
61702 #define elf_addr_t Elf32_Off
61703 #define Elf_Half Elf32_Half
61704 +#define elf_dyn Elf32_Dyn
61705
61706 #else
61707
61708 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61709 #define elf_note elf64_note
61710 #define elf_addr_t Elf64_Off
61711 #define Elf_Half Elf64_Half
61712 +#define elf_dyn Elf64_Dyn
61713
61714 #endif
61715
61716 diff --git a/include/linux/filter.h b/include/linux/filter.h
61717 index 82b0135..917914d 100644
61718 --- a/include/linux/filter.h
61719 +++ b/include/linux/filter.h
61720 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61721
61722 struct sk_buff;
61723 struct sock;
61724 +struct bpf_jit_work;
61725
61726 struct sk_filter
61727 {
61728 @@ -153,6 +154,9 @@ struct sk_filter
61729 unsigned int len; /* Number of filter blocks */
61730 unsigned int (*bpf_func)(const struct sk_buff *skb,
61731 const struct sock_filter *filter);
61732 +#ifdef CONFIG_BPF_JIT
61733 + struct bpf_jit_work *work;
61734 +#endif
61735 struct rcu_head rcu;
61736 struct sock_filter insns[0];
61737 };
61738 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61739 index db04ec5..f6ed627 100644
61740 --- a/include/linux/firewire.h
61741 +++ b/include/linux/firewire.h
61742 @@ -430,7 +430,7 @@ struct fw_iso_context {
61743 union {
61744 fw_iso_callback_t sc;
61745 fw_iso_mc_callback_t mc;
61746 - } callback;
61747 + } __no_const callback;
61748 void *callback_data;
61749 };
61750
61751 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61752 index 0e4e2ee..4ff4312 100644
61753 --- a/include/linux/frontswap.h
61754 +++ b/include/linux/frontswap.h
61755 @@ -11,7 +11,7 @@ struct frontswap_ops {
61756 int (*load)(unsigned, pgoff_t, struct page *);
61757 void (*invalidate_page)(unsigned, pgoff_t);
61758 void (*invalidate_area)(unsigned);
61759 -};
61760 +} __no_const;
61761
61762 extern bool frontswap_enabled;
61763 extern struct frontswap_ops
61764 diff --git a/include/linux/fs.h b/include/linux/fs.h
61765 index aa11047..7d046d0 100644
61766 --- a/include/linux/fs.h
61767 +++ b/include/linux/fs.h
61768 @@ -1802,7 +1802,8 @@ struct file_operations {
61769 int (*setlease)(struct file *, long, struct file_lock **);
61770 long (*fallocate)(struct file *file, int mode, loff_t offset,
61771 loff_t len);
61772 -};
61773 +} __do_const;
61774 +typedef struct file_operations __no_const file_operations_no_const;
61775
61776 struct inode_operations {
61777 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61778 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61779 index 003dc0f..3c4ea97 100644
61780 --- a/include/linux/fs_struct.h
61781 +++ b/include/linux/fs_struct.h
61782 @@ -6,7 +6,7 @@
61783 #include <linux/seqlock.h>
61784
61785 struct fs_struct {
61786 - int users;
61787 + atomic_t users;
61788 spinlock_t lock;
61789 seqcount_t seq;
61790 int umask;
61791 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61792 index ce31408..b1ad003 100644
61793 --- a/include/linux/fscache-cache.h
61794 +++ b/include/linux/fscache-cache.h
61795 @@ -102,7 +102,7 @@ struct fscache_operation {
61796 fscache_operation_release_t release;
61797 };
61798
61799 -extern atomic_t fscache_op_debug_id;
61800 +extern atomic_unchecked_t fscache_op_debug_id;
61801 extern void fscache_op_work_func(struct work_struct *work);
61802
61803 extern void fscache_enqueue_operation(struct fscache_operation *);
61804 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61805 {
61806 INIT_WORK(&op->work, fscache_op_work_func);
61807 atomic_set(&op->usage, 1);
61808 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61809 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61810 op->processor = processor;
61811 op->release = release;
61812 INIT_LIST_HEAD(&op->pend_link);
61813 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61814 index a6dfe69..569586df 100644
61815 --- a/include/linux/fsnotify.h
61816 +++ b/include/linux/fsnotify.h
61817 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61818 */
61819 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61820 {
61821 - return kstrdup(name, GFP_KERNEL);
61822 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61823 }
61824
61825 /*
61826 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61827 index 63d966d..cdcb717 100644
61828 --- a/include/linux/fsnotify_backend.h
61829 +++ b/include/linux/fsnotify_backend.h
61830 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61831 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61832 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61833 };
61834 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61835
61836 /*
61837 * A group is a "thing" that wants to receive notification about filesystem
61838 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61839 index 642928c..e6c83a7 100644
61840 --- a/include/linux/ftrace_event.h
61841 +++ b/include/linux/ftrace_event.h
61842 @@ -97,7 +97,7 @@ struct trace_event_functions {
61843 trace_print_func raw;
61844 trace_print_func hex;
61845 trace_print_func binary;
61846 -};
61847 +} __no_const;
61848
61849 struct trace_event {
61850 struct hlist_node node;
61851 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61852 extern int trace_add_event_call(struct ftrace_event_call *call);
61853 extern void trace_remove_event_call(struct ftrace_event_call *call);
61854
61855 -#define is_signed_type(type) (((type)(-1)) < 0)
61856 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61857
61858 int trace_set_clr_event(const char *system, const char *event, int set);
61859
61860 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61861 index 4f440b3..342233a 100644
61862 --- a/include/linux/genhd.h
61863 +++ b/include/linux/genhd.h
61864 @@ -190,7 +190,7 @@ struct gendisk {
61865 struct kobject *slave_dir;
61866
61867 struct timer_rand_state *random;
61868 - atomic_t sync_io; /* RAID */
61869 + atomic_unchecked_t sync_io; /* RAID */
61870 struct disk_events *ev;
61871 #ifdef CONFIG_BLK_DEV_INTEGRITY
61872 struct blk_integrity *integrity;
61873 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61874 index 4883f39..26688a8 100644
61875 --- a/include/linux/gfp.h
61876 +++ b/include/linux/gfp.h
61877 @@ -39,6 +39,12 @@ struct vm_area_struct;
61878 #define ___GFP_OTHER_NODE 0x800000u
61879 #define ___GFP_WRITE 0x1000000u
61880
61881 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61882 +#define ___GFP_USERCOPY 0x2000000u
61883 +#else
61884 +#define ___GFP_USERCOPY 0
61885 +#endif
61886 +
61887 /*
61888 * GFP bitmasks..
61889 *
61890 @@ -93,6 +99,7 @@ struct vm_area_struct;
61891 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61892 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61893 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61894 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61895
61896 /*
61897 * This may seem redundant, but it's a way of annotating false positives vs.
61898 @@ -100,7 +107,7 @@ struct vm_area_struct;
61899 */
61900 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61901
61902 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61903 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61904 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61905
61906 /* This equals 0, but use constants in case they ever change */
61907 @@ -154,6 +161,8 @@ struct vm_area_struct;
61908 /* 4GB DMA on some platforms */
61909 #define GFP_DMA32 __GFP_DMA32
61910
61911 +#define GFP_USERCOPY __GFP_USERCOPY
61912 +
61913 /* Convert GFP flags to their corresponding migrate type */
61914 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61915 {
61916 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61917 new file mode 100644
61918 index 0000000..c938b1f
61919 --- /dev/null
61920 +++ b/include/linux/gracl.h
61921 @@ -0,0 +1,319 @@
61922 +#ifndef GR_ACL_H
61923 +#define GR_ACL_H
61924 +
61925 +#include <linux/grdefs.h>
61926 +#include <linux/resource.h>
61927 +#include <linux/capability.h>
61928 +#include <linux/dcache.h>
61929 +#include <asm/resource.h>
61930 +
61931 +/* Major status information */
61932 +
61933 +#define GR_VERSION "grsecurity 2.9.1"
61934 +#define GRSECURITY_VERSION 0x2901
61935 +
61936 +enum {
61937 + GR_SHUTDOWN = 0,
61938 + GR_ENABLE = 1,
61939 + GR_SPROLE = 2,
61940 + GR_RELOAD = 3,
61941 + GR_SEGVMOD = 4,
61942 + GR_STATUS = 5,
61943 + GR_UNSPROLE = 6,
61944 + GR_PASSSET = 7,
61945 + GR_SPROLEPAM = 8,
61946 +};
61947 +
61948 +/* Password setup definitions
61949 + * kernel/grhash.c */
61950 +enum {
61951 + GR_PW_LEN = 128,
61952 + GR_SALT_LEN = 16,
61953 + GR_SHA_LEN = 32,
61954 +};
61955 +
61956 +enum {
61957 + GR_SPROLE_LEN = 64,
61958 +};
61959 +
61960 +enum {
61961 + GR_NO_GLOB = 0,
61962 + GR_REG_GLOB,
61963 + GR_CREATE_GLOB
61964 +};
61965 +
61966 +#define GR_NLIMITS 32
61967 +
61968 +/* Begin Data Structures */
61969 +
61970 +struct sprole_pw {
61971 + unsigned char *rolename;
61972 + unsigned char salt[GR_SALT_LEN];
61973 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61974 +};
61975 +
61976 +struct name_entry {
61977 + __u32 key;
61978 + ino_t inode;
61979 + dev_t device;
61980 + char *name;
61981 + __u16 len;
61982 + __u8 deleted;
61983 + struct name_entry *prev;
61984 + struct name_entry *next;
61985 +};
61986 +
61987 +struct inodev_entry {
61988 + struct name_entry *nentry;
61989 + struct inodev_entry *prev;
61990 + struct inodev_entry *next;
61991 +};
61992 +
61993 +struct acl_role_db {
61994 + struct acl_role_label **r_hash;
61995 + __u32 r_size;
61996 +};
61997 +
61998 +struct inodev_db {
61999 + struct inodev_entry **i_hash;
62000 + __u32 i_size;
62001 +};
62002 +
62003 +struct name_db {
62004 + struct name_entry **n_hash;
62005 + __u32 n_size;
62006 +};
62007 +
62008 +struct crash_uid {
62009 + uid_t uid;
62010 + unsigned long expires;
62011 +};
62012 +
62013 +struct gr_hash_struct {
62014 + void **table;
62015 + void **nametable;
62016 + void *first;
62017 + __u32 table_size;
62018 + __u32 used_size;
62019 + int type;
62020 +};
62021 +
62022 +/* Userspace Grsecurity ACL data structures */
62023 +
62024 +struct acl_subject_label {
62025 + char *filename;
62026 + ino_t inode;
62027 + dev_t device;
62028 + __u32 mode;
62029 + kernel_cap_t cap_mask;
62030 + kernel_cap_t cap_lower;
62031 + kernel_cap_t cap_invert_audit;
62032 +
62033 + struct rlimit res[GR_NLIMITS];
62034 + __u32 resmask;
62035 +
62036 + __u8 user_trans_type;
62037 + __u8 group_trans_type;
62038 + uid_t *user_transitions;
62039 + gid_t *group_transitions;
62040 + __u16 user_trans_num;
62041 + __u16 group_trans_num;
62042 +
62043 + __u32 sock_families[2];
62044 + __u32 ip_proto[8];
62045 + __u32 ip_type;
62046 + struct acl_ip_label **ips;
62047 + __u32 ip_num;
62048 + __u32 inaddr_any_override;
62049 +
62050 + __u32 crashes;
62051 + unsigned long expires;
62052 +
62053 + struct acl_subject_label *parent_subject;
62054 + struct gr_hash_struct *hash;
62055 + struct acl_subject_label *prev;
62056 + struct acl_subject_label *next;
62057 +
62058 + struct acl_object_label **obj_hash;
62059 + __u32 obj_hash_size;
62060 + __u16 pax_flags;
62061 +};
62062 +
62063 +struct role_allowed_ip {
62064 + __u32 addr;
62065 + __u32 netmask;
62066 +
62067 + struct role_allowed_ip *prev;
62068 + struct role_allowed_ip *next;
62069 +};
62070 +
62071 +struct role_transition {
62072 + char *rolename;
62073 +
62074 + struct role_transition *prev;
62075 + struct role_transition *next;
62076 +};
62077 +
62078 +struct acl_role_label {
62079 + char *rolename;
62080 + uid_t uidgid;
62081 + __u16 roletype;
62082 +
62083 + __u16 auth_attempts;
62084 + unsigned long expires;
62085 +
62086 + struct acl_subject_label *root_label;
62087 + struct gr_hash_struct *hash;
62088 +
62089 + struct acl_role_label *prev;
62090 + struct acl_role_label *next;
62091 +
62092 + struct role_transition *transitions;
62093 + struct role_allowed_ip *allowed_ips;
62094 + uid_t *domain_children;
62095 + __u16 domain_child_num;
62096 +
62097 + umode_t umask;
62098 +
62099 + struct acl_subject_label **subj_hash;
62100 + __u32 subj_hash_size;
62101 +};
62102 +
62103 +struct user_acl_role_db {
62104 + struct acl_role_label **r_table;
62105 + __u32 num_pointers; /* Number of allocations to track */
62106 + __u32 num_roles; /* Number of roles */
62107 + __u32 num_domain_children; /* Number of domain children */
62108 + __u32 num_subjects; /* Number of subjects */
62109 + __u32 num_objects; /* Number of objects */
62110 +};
62111 +
62112 +struct acl_object_label {
62113 + char *filename;
62114 + ino_t inode;
62115 + dev_t device;
62116 + __u32 mode;
62117 +
62118 + struct acl_subject_label *nested;
62119 + struct acl_object_label *globbed;
62120 +
62121 + /* next two structures not used */
62122 +
62123 + struct acl_object_label *prev;
62124 + struct acl_object_label *next;
62125 +};
62126 +
62127 +struct acl_ip_label {
62128 + char *iface;
62129 + __u32 addr;
62130 + __u32 netmask;
62131 + __u16 low, high;
62132 + __u8 mode;
62133 + __u32 type;
62134 + __u32 proto[8];
62135 +
62136 + /* next two structures not used */
62137 +
62138 + struct acl_ip_label *prev;
62139 + struct acl_ip_label *next;
62140 +};
62141 +
62142 +struct gr_arg {
62143 + struct user_acl_role_db role_db;
62144 + unsigned char pw[GR_PW_LEN];
62145 + unsigned char salt[GR_SALT_LEN];
62146 + unsigned char sum[GR_SHA_LEN];
62147 + unsigned char sp_role[GR_SPROLE_LEN];
62148 + struct sprole_pw *sprole_pws;
62149 + dev_t segv_device;
62150 + ino_t segv_inode;
62151 + uid_t segv_uid;
62152 + __u16 num_sprole_pws;
62153 + __u16 mode;
62154 +};
62155 +
62156 +struct gr_arg_wrapper {
62157 + struct gr_arg *arg;
62158 + __u32 version;
62159 + __u32 size;
62160 +};
62161 +
62162 +struct subject_map {
62163 + struct acl_subject_label *user;
62164 + struct acl_subject_label *kernel;
62165 + struct subject_map *prev;
62166 + struct subject_map *next;
62167 +};
62168 +
62169 +struct acl_subj_map_db {
62170 + struct subject_map **s_hash;
62171 + __u32 s_size;
62172 +};
62173 +
62174 +/* End Data Structures Section */
62175 +
62176 +/* Hash functions generated by empirical testing by Brad Spengler
62177 + Makes good use of the low bits of the inode. Generally 0-1 times
62178 + in loop for successful match. 0-3 for unsuccessful match.
62179 + Shift/add algorithm with modulus of table size and an XOR*/
62180 +
62181 +static __inline__ unsigned int
62182 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62183 +{
62184 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62185 +}
62186 +
62187 + static __inline__ unsigned int
62188 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62189 +{
62190 + return ((const unsigned long)userp % sz);
62191 +}
62192 +
62193 +static __inline__ unsigned int
62194 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62195 +{
62196 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62197 +}
62198 +
62199 +static __inline__ unsigned int
62200 +nhash(const char *name, const __u16 len, const unsigned int sz)
62201 +{
62202 + return full_name_hash((const unsigned char *)name, len) % sz;
62203 +}
62204 +
62205 +#define FOR_EACH_ROLE_START(role) \
62206 + role = role_list; \
62207 + while (role) {
62208 +
62209 +#define FOR_EACH_ROLE_END(role) \
62210 + role = role->prev; \
62211 + }
62212 +
62213 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62214 + subj = NULL; \
62215 + iter = 0; \
62216 + while (iter < role->subj_hash_size) { \
62217 + if (subj == NULL) \
62218 + subj = role->subj_hash[iter]; \
62219 + if (subj == NULL) { \
62220 + iter++; \
62221 + continue; \
62222 + }
62223 +
62224 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62225 + subj = subj->next; \
62226 + if (subj == NULL) \
62227 + iter++; \
62228 + }
62229 +
62230 +
62231 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62232 + subj = role->hash->first; \
62233 + while (subj != NULL) {
62234 +
62235 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62236 + subj = subj->next; \
62237 + }
62238 +
62239 +#endif
62240 +
62241 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62242 new file mode 100644
62243 index 0000000..323ecf2
62244 --- /dev/null
62245 +++ b/include/linux/gralloc.h
62246 @@ -0,0 +1,9 @@
62247 +#ifndef __GRALLOC_H
62248 +#define __GRALLOC_H
62249 +
62250 +void acl_free_all(void);
62251 +int acl_alloc_stack_init(unsigned long size);
62252 +void *acl_alloc(unsigned long len);
62253 +void *acl_alloc_num(unsigned long num, unsigned long len);
62254 +
62255 +#endif
62256 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62257 new file mode 100644
62258 index 0000000..b30e9bc
62259 --- /dev/null
62260 +++ b/include/linux/grdefs.h
62261 @@ -0,0 +1,140 @@
62262 +#ifndef GRDEFS_H
62263 +#define GRDEFS_H
62264 +
62265 +/* Begin grsecurity status declarations */
62266 +
62267 +enum {
62268 + GR_READY = 0x01,
62269 + GR_STATUS_INIT = 0x00 // disabled state
62270 +};
62271 +
62272 +/* Begin ACL declarations */
62273 +
62274 +/* Role flags */
62275 +
62276 +enum {
62277 + GR_ROLE_USER = 0x0001,
62278 + GR_ROLE_GROUP = 0x0002,
62279 + GR_ROLE_DEFAULT = 0x0004,
62280 + GR_ROLE_SPECIAL = 0x0008,
62281 + GR_ROLE_AUTH = 0x0010,
62282 + GR_ROLE_NOPW = 0x0020,
62283 + GR_ROLE_GOD = 0x0040,
62284 + GR_ROLE_LEARN = 0x0080,
62285 + GR_ROLE_TPE = 0x0100,
62286 + GR_ROLE_DOMAIN = 0x0200,
62287 + GR_ROLE_PAM = 0x0400,
62288 + GR_ROLE_PERSIST = 0x0800
62289 +};
62290 +
62291 +/* ACL Subject and Object mode flags */
62292 +enum {
62293 + GR_DELETED = 0x80000000
62294 +};
62295 +
62296 +/* ACL Object-only mode flags */
62297 +enum {
62298 + GR_READ = 0x00000001,
62299 + GR_APPEND = 0x00000002,
62300 + GR_WRITE = 0x00000004,
62301 + GR_EXEC = 0x00000008,
62302 + GR_FIND = 0x00000010,
62303 + GR_INHERIT = 0x00000020,
62304 + GR_SETID = 0x00000040,
62305 + GR_CREATE = 0x00000080,
62306 + GR_DELETE = 0x00000100,
62307 + GR_LINK = 0x00000200,
62308 + GR_AUDIT_READ = 0x00000400,
62309 + GR_AUDIT_APPEND = 0x00000800,
62310 + GR_AUDIT_WRITE = 0x00001000,
62311 + GR_AUDIT_EXEC = 0x00002000,
62312 + GR_AUDIT_FIND = 0x00004000,
62313 + GR_AUDIT_INHERIT= 0x00008000,
62314 + GR_AUDIT_SETID = 0x00010000,
62315 + GR_AUDIT_CREATE = 0x00020000,
62316 + GR_AUDIT_DELETE = 0x00040000,
62317 + GR_AUDIT_LINK = 0x00080000,
62318 + GR_PTRACERD = 0x00100000,
62319 + GR_NOPTRACE = 0x00200000,
62320 + GR_SUPPRESS = 0x00400000,
62321 + GR_NOLEARN = 0x00800000,
62322 + GR_INIT_TRANSFER= 0x01000000
62323 +};
62324 +
62325 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62326 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62327 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62328 +
62329 +/* ACL subject-only mode flags */
62330 +enum {
62331 + GR_KILL = 0x00000001,
62332 + GR_VIEW = 0x00000002,
62333 + GR_PROTECTED = 0x00000004,
62334 + GR_LEARN = 0x00000008,
62335 + GR_OVERRIDE = 0x00000010,
62336 + /* just a placeholder, this mode is only used in userspace */
62337 + GR_DUMMY = 0x00000020,
62338 + GR_PROTSHM = 0x00000040,
62339 + GR_KILLPROC = 0x00000080,
62340 + GR_KILLIPPROC = 0x00000100,
62341 + /* just a placeholder, this mode is only used in userspace */
62342 + GR_NOTROJAN = 0x00000200,
62343 + GR_PROTPROCFD = 0x00000400,
62344 + GR_PROCACCT = 0x00000800,
62345 + GR_RELAXPTRACE = 0x00001000,
62346 + GR_NESTED = 0x00002000,
62347 + GR_INHERITLEARN = 0x00004000,
62348 + GR_PROCFIND = 0x00008000,
62349 + GR_POVERRIDE = 0x00010000,
62350 + GR_KERNELAUTH = 0x00020000,
62351 + GR_ATSECURE = 0x00040000,
62352 + GR_SHMEXEC = 0x00080000
62353 +};
62354 +
62355 +enum {
62356 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62357 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62358 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62359 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62360 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62361 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62362 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62363 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62364 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62365 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62366 +};
62367 +
62368 +enum {
62369 + GR_ID_USER = 0x01,
62370 + GR_ID_GROUP = 0x02,
62371 +};
62372 +
62373 +enum {
62374 + GR_ID_ALLOW = 0x01,
62375 + GR_ID_DENY = 0x02,
62376 +};
62377 +
62378 +#define GR_CRASH_RES 31
62379 +#define GR_UIDTABLE_MAX 500
62380 +
62381 +/* begin resource learning section */
62382 +enum {
62383 + GR_RLIM_CPU_BUMP = 60,
62384 + GR_RLIM_FSIZE_BUMP = 50000,
62385 + GR_RLIM_DATA_BUMP = 10000,
62386 + GR_RLIM_STACK_BUMP = 1000,
62387 + GR_RLIM_CORE_BUMP = 10000,
62388 + GR_RLIM_RSS_BUMP = 500000,
62389 + GR_RLIM_NPROC_BUMP = 1,
62390 + GR_RLIM_NOFILE_BUMP = 5,
62391 + GR_RLIM_MEMLOCK_BUMP = 50000,
62392 + GR_RLIM_AS_BUMP = 500000,
62393 + GR_RLIM_LOCKS_BUMP = 2,
62394 + GR_RLIM_SIGPENDING_BUMP = 5,
62395 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62396 + GR_RLIM_NICE_BUMP = 1,
62397 + GR_RLIM_RTPRIO_BUMP = 1,
62398 + GR_RLIM_RTTIME_BUMP = 1000000
62399 +};
62400 +
62401 +#endif
62402 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62403 new file mode 100644
62404 index 0000000..c9292f7
62405 --- /dev/null
62406 +++ b/include/linux/grinternal.h
62407 @@ -0,0 +1,223 @@
62408 +#ifndef __GRINTERNAL_H
62409 +#define __GRINTERNAL_H
62410 +
62411 +#ifdef CONFIG_GRKERNSEC
62412 +
62413 +#include <linux/fs.h>
62414 +#include <linux/mnt_namespace.h>
62415 +#include <linux/nsproxy.h>
62416 +#include <linux/gracl.h>
62417 +#include <linux/grdefs.h>
62418 +#include <linux/grmsg.h>
62419 +
62420 +void gr_add_learn_entry(const char *fmt, ...)
62421 + __attribute__ ((format (printf, 1, 2)));
62422 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62423 + const struct vfsmount *mnt);
62424 +__u32 gr_check_create(const struct dentry *new_dentry,
62425 + const struct dentry *parent,
62426 + const struct vfsmount *mnt, const __u32 mode);
62427 +int gr_check_protected_task(const struct task_struct *task);
62428 +__u32 to_gr_audit(const __u32 reqmode);
62429 +int gr_set_acls(const int type);
62430 +int gr_apply_subject_to_task(struct task_struct *task);
62431 +int gr_acl_is_enabled(void);
62432 +char gr_roletype_to_char(void);
62433 +
62434 +void gr_handle_alertkill(struct task_struct *task);
62435 +char *gr_to_filename(const struct dentry *dentry,
62436 + const struct vfsmount *mnt);
62437 +char *gr_to_filename1(const struct dentry *dentry,
62438 + const struct vfsmount *mnt);
62439 +char *gr_to_filename2(const struct dentry *dentry,
62440 + const struct vfsmount *mnt);
62441 +char *gr_to_filename3(const struct dentry *dentry,
62442 + const struct vfsmount *mnt);
62443 +
62444 +extern int grsec_enable_ptrace_readexec;
62445 +extern int grsec_enable_harden_ptrace;
62446 +extern int grsec_enable_link;
62447 +extern int grsec_enable_fifo;
62448 +extern int grsec_enable_execve;
62449 +extern int grsec_enable_shm;
62450 +extern int grsec_enable_execlog;
62451 +extern int grsec_enable_signal;
62452 +extern int grsec_enable_audit_ptrace;
62453 +extern int grsec_enable_forkfail;
62454 +extern int grsec_enable_time;
62455 +extern int grsec_enable_rofs;
62456 +extern int grsec_enable_chroot_shmat;
62457 +extern int grsec_enable_chroot_mount;
62458 +extern int grsec_enable_chroot_double;
62459 +extern int grsec_enable_chroot_pivot;
62460 +extern int grsec_enable_chroot_chdir;
62461 +extern int grsec_enable_chroot_chmod;
62462 +extern int grsec_enable_chroot_mknod;
62463 +extern int grsec_enable_chroot_fchdir;
62464 +extern int grsec_enable_chroot_nice;
62465 +extern int grsec_enable_chroot_execlog;
62466 +extern int grsec_enable_chroot_caps;
62467 +extern int grsec_enable_chroot_sysctl;
62468 +extern int grsec_enable_chroot_unix;
62469 +extern int grsec_enable_symlinkown;
62470 +extern int grsec_symlinkown_gid;
62471 +extern int grsec_enable_tpe;
62472 +extern int grsec_tpe_gid;
62473 +extern int grsec_enable_tpe_all;
62474 +extern int grsec_enable_tpe_invert;
62475 +extern int grsec_enable_socket_all;
62476 +extern int grsec_socket_all_gid;
62477 +extern int grsec_enable_socket_client;
62478 +extern int grsec_socket_client_gid;
62479 +extern int grsec_enable_socket_server;
62480 +extern int grsec_socket_server_gid;
62481 +extern int grsec_audit_gid;
62482 +extern int grsec_enable_group;
62483 +extern int grsec_enable_audit_textrel;
62484 +extern int grsec_enable_log_rwxmaps;
62485 +extern int grsec_enable_mount;
62486 +extern int grsec_enable_chdir;
62487 +extern int grsec_resource_logging;
62488 +extern int grsec_enable_blackhole;
62489 +extern int grsec_lastack_retries;
62490 +extern int grsec_enable_brute;
62491 +extern int grsec_lock;
62492 +
62493 +extern spinlock_t grsec_alert_lock;
62494 +extern unsigned long grsec_alert_wtime;
62495 +extern unsigned long grsec_alert_fyet;
62496 +
62497 +extern spinlock_t grsec_audit_lock;
62498 +
62499 +extern rwlock_t grsec_exec_file_lock;
62500 +
62501 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62502 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62503 + (tsk)->exec_file->f_vfsmnt) : "/")
62504 +
62505 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62506 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62507 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62508 +
62509 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62510 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62511 + (tsk)->exec_file->f_vfsmnt) : "/")
62512 +
62513 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62514 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62515 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62516 +
62517 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62518 +
62519 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62520 +
62521 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62522 + (task)->pid, (cred)->uid, \
62523 + (cred)->euid, (cred)->gid, (cred)->egid, \
62524 + gr_parent_task_fullpath(task), \
62525 + (task)->real_parent->comm, (task)->real_parent->pid, \
62526 + (pcred)->uid, (pcred)->euid, \
62527 + (pcred)->gid, (pcred)->egid
62528 +
62529 +#define GR_CHROOT_CAPS {{ \
62530 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62531 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62532 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62533 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62534 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62535 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62536 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62537 +
62538 +#define security_learn(normal_msg,args...) \
62539 +({ \
62540 + read_lock(&grsec_exec_file_lock); \
62541 + gr_add_learn_entry(normal_msg "\n", ## args); \
62542 + read_unlock(&grsec_exec_file_lock); \
62543 +})
62544 +
62545 +enum {
62546 + GR_DO_AUDIT,
62547 + GR_DONT_AUDIT,
62548 + /* used for non-audit messages that we shouldn't kill the task on */
62549 + GR_DONT_AUDIT_GOOD
62550 +};
62551 +
62552 +enum {
62553 + GR_TTYSNIFF,
62554 + GR_RBAC,
62555 + GR_RBAC_STR,
62556 + GR_STR_RBAC,
62557 + GR_RBAC_MODE2,
62558 + GR_RBAC_MODE3,
62559 + GR_FILENAME,
62560 + GR_SYSCTL_HIDDEN,
62561 + GR_NOARGS,
62562 + GR_ONE_INT,
62563 + GR_ONE_INT_TWO_STR,
62564 + GR_ONE_STR,
62565 + GR_STR_INT,
62566 + GR_TWO_STR_INT,
62567 + GR_TWO_INT,
62568 + GR_TWO_U64,
62569 + GR_THREE_INT,
62570 + GR_FIVE_INT_TWO_STR,
62571 + GR_TWO_STR,
62572 + GR_THREE_STR,
62573 + GR_FOUR_STR,
62574 + GR_STR_FILENAME,
62575 + GR_FILENAME_STR,
62576 + GR_FILENAME_TWO_INT,
62577 + GR_FILENAME_TWO_INT_STR,
62578 + GR_TEXTREL,
62579 + GR_PTRACE,
62580 + GR_RESOURCE,
62581 + GR_CAP,
62582 + GR_SIG,
62583 + GR_SIG2,
62584 + GR_CRASH1,
62585 + GR_CRASH2,
62586 + GR_PSACCT,
62587 + GR_RWXMAP
62588 +};
62589 +
62590 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62591 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62592 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62593 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62594 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62595 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62596 +#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)
62597 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62598 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62599 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62600 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62601 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62602 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62603 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62604 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62605 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62606 +#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)
62607 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62608 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62609 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62610 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62611 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62612 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62613 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62614 +#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)
62615 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62616 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62617 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62618 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62619 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62620 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62621 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62622 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62623 +#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)
62624 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62625 +
62626 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62627 +
62628 +#endif
62629 +
62630 +#endif
62631 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62632 new file mode 100644
62633 index 0000000..54f4e85
62634 --- /dev/null
62635 +++ b/include/linux/grmsg.h
62636 @@ -0,0 +1,110 @@
62637 +#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"
62638 +#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"
62639 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62640 +#define GR_STOPMOD_MSG "denied modification of module state by "
62641 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62642 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62643 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62644 +#define GR_IOPL_MSG "denied use of iopl() by "
62645 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62646 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62647 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62648 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62649 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62650 +#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"
62651 +#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"
62652 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62653 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62654 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62655 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62656 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62657 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62658 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62659 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62660 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62661 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62662 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62663 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62664 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62665 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62666 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62667 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62668 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62669 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62670 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62671 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62672 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62673 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62674 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62675 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62676 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62677 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62678 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62679 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62680 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62681 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62682 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62683 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62684 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62685 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62686 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62687 +#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"
62688 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62689 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62690 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62691 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62692 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62693 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62694 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62695 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62696 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62697 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62698 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62699 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62700 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62701 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62702 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62703 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62704 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62705 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62706 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62707 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62708 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62709 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62710 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62711 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62712 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62713 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62714 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62715 +#define GR_TIME_MSG "time set by "
62716 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62717 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62718 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62719 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62720 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62721 +#define GR_BIND_MSG "denied bind() by "
62722 +#define GR_CONNECT_MSG "denied connect() by "
62723 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62724 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62725 +#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"
62726 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62727 +#define GR_CAP_ACL_MSG "use of %s denied for "
62728 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62729 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62730 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62731 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62732 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62733 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62734 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62735 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62736 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62737 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62738 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62739 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62740 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62741 +#define GR_VM86_MSG "denied use of vm86 by "
62742 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62743 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62744 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62745 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62746 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62747 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62748 new file mode 100644
62749 index 0000000..f9b9a21
62750 --- /dev/null
62751 +++ b/include/linux/grsecurity.h
62752 @@ -0,0 +1,238 @@
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 + compat_uptr_t __user *compat;
62784 +#endif
62785 + } ptr;
62786 +};
62787 +
62788 +void gr_handle_brute_attach(struct task_struct *p, 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 char *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 char *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 char *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 char *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 +
62966 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62967 +
62968 +#ifdef CONFIG_GRKERNSEC
62969 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62970 +void gr_handle_vm86(void);
62971 +void gr_handle_mem_readwrite(u64 from, u64 to);
62972 +
62973 +void gr_log_badprocpid(const char *entry);
62974 +
62975 +extern int grsec_enable_dmesg;
62976 +extern int grsec_disable_privio;
62977 +
62978 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62979 +extern int grsec_proc_gid;
62980 +#endif
62981 +
62982 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62983 +extern int grsec_enable_chroot_findtask;
62984 +#endif
62985 +#ifdef CONFIG_GRKERNSEC_SETXID
62986 +extern int grsec_enable_setxid;
62987 +#endif
62988 +#endif
62989 +
62990 +#endif
62991 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62992 new file mode 100644
62993 index 0000000..e7ffaaf
62994 --- /dev/null
62995 +++ b/include/linux/grsock.h
62996 @@ -0,0 +1,19 @@
62997 +#ifndef __GRSOCK_H
62998 +#define __GRSOCK_H
62999 +
63000 +extern void gr_attach_curr_ip(const struct sock *sk);
63001 +extern int gr_handle_sock_all(const int family, const int type,
63002 + const int protocol);
63003 +extern int gr_handle_sock_server(const struct sockaddr *sck);
63004 +extern int gr_handle_sock_server_other(const struct sock *sck);
63005 +extern int gr_handle_sock_client(const struct sockaddr *sck);
63006 +extern int gr_search_connect(struct socket * sock,
63007 + struct sockaddr_in * addr);
63008 +extern int gr_search_bind(struct socket * sock,
63009 + struct sockaddr_in * addr);
63010 +extern int gr_search_listen(struct socket * sock);
63011 +extern int gr_search_accept(struct socket * sock);
63012 +extern int gr_search_socket(const int domain, const int type,
63013 + const int protocol);
63014 +
63015 +#endif
63016 diff --git a/include/linux/hid.h b/include/linux/hid.h
63017 index 42970de..5db3c92 100644
63018 --- a/include/linux/hid.h
63019 +++ b/include/linux/hid.h
63020 @@ -705,7 +705,7 @@ struct hid_ll_driver {
63021 unsigned int code, int value);
63022
63023 int (*parse)(struct hid_device *hdev);
63024 -};
63025 +} __no_const;
63026
63027 #define PM_HINT_FULLON 1<<5
63028 #define PM_HINT_NORMAL 1<<1
63029 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
63030 index ef788b5..ac41b7b 100644
63031 --- a/include/linux/highmem.h
63032 +++ b/include/linux/highmem.h
63033 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
63034 kunmap_atomic(kaddr);
63035 }
63036
63037 +static inline void sanitize_highpage(struct page *page)
63038 +{
63039 + void *kaddr;
63040 + unsigned long flags;
63041 +
63042 + local_irq_save(flags);
63043 + kaddr = kmap_atomic(page);
63044 + clear_page(kaddr);
63045 + kunmap_atomic(kaddr);
63046 + local_irq_restore(flags);
63047 +}
63048 +
63049 static inline void zero_user_segments(struct page *page,
63050 unsigned start1, unsigned end1,
63051 unsigned start2, unsigned end2)
63052 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
63053 index 5970266..1c48c3b 100644
63054 --- a/include/linux/i2c.h
63055 +++ b/include/linux/i2c.h
63056 @@ -369,6 +369,7 @@ struct i2c_algorithm {
63057 /* To determine what the adapter supports */
63058 u32 (*functionality) (struct i2c_adapter *);
63059 };
63060 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63061
63062 /*
63063 * i2c_adapter is the structure used to identify a physical i2c bus along
63064 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63065 index d23c3c2..eb63c81 100644
63066 --- a/include/linux/i2o.h
63067 +++ b/include/linux/i2o.h
63068 @@ -565,7 +565,7 @@ struct i2o_controller {
63069 struct i2o_device *exec; /* Executive */
63070 #if BITS_PER_LONG == 64
63071 spinlock_t context_list_lock; /* lock for context_list */
63072 - atomic_t context_list_counter; /* needed for unique contexts */
63073 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63074 struct list_head context_list; /* list of context id's
63075 and pointers */
63076 #endif
63077 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63078 index aa2e167..84024ce 100644
63079 --- a/include/linux/if_team.h
63080 +++ b/include/linux/if_team.h
63081 @@ -109,6 +109,7 @@ struct team_mode_ops {
63082 void (*port_enabled)(struct team *team, struct team_port *port);
63083 void (*port_disabled)(struct team *team, struct team_port *port);
63084 };
63085 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63086
63087 enum team_option_type {
63088 TEAM_OPTION_TYPE_U32,
63089 @@ -181,7 +182,7 @@ struct team {
63090 struct list_head option_inst_list; /* list of option instances */
63091
63092 const struct team_mode *mode;
63093 - struct team_mode_ops ops;
63094 + team_mode_ops_no_const ops;
63095 long mode_priv[TEAM_MODE_PRIV_LONGS];
63096 };
63097
63098 diff --git a/include/linux/init.h b/include/linux/init.h
63099 index 5e664f6..0a1225c 100644
63100 --- a/include/linux/init.h
63101 +++ b/include/linux/init.h
63102 @@ -39,9 +39,15 @@
63103 * Also note, that this data cannot be "const".
63104 */
63105
63106 +#ifdef MODULE
63107 +#define add_latent_entropy
63108 +#else
63109 +#define add_latent_entropy __latent_entropy
63110 +#endif
63111 +
63112 /* These are for everybody (although not all archs will actually
63113 discard it in modules) */
63114 -#define __init __section(.init.text) __cold notrace
63115 +#define __init __section(.init.text) __cold notrace add_latent_entropy
63116 #define __initdata __section(.init.data)
63117 #define __initconst __section(.init.rodata)
63118 #define __exitdata __section(.exit.data)
63119 @@ -83,7 +89,7 @@
63120 #define __exit __section(.exit.text) __exitused __cold notrace
63121
63122 /* Used for HOTPLUG */
63123 -#define __devinit __section(.devinit.text) __cold notrace
63124 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63125 #define __devinitdata __section(.devinit.data)
63126 #define __devinitconst __section(.devinit.rodata)
63127 #define __devexit __section(.devexit.text) __exitused __cold notrace
63128 @@ -91,7 +97,7 @@
63129 #define __devexitconst __section(.devexit.rodata)
63130
63131 /* Used for HOTPLUG_CPU */
63132 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63133 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63134 #define __cpuinitdata __section(.cpuinit.data)
63135 #define __cpuinitconst __section(.cpuinit.rodata)
63136 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63137 @@ -99,7 +105,7 @@
63138 #define __cpuexitconst __section(.cpuexit.rodata)
63139
63140 /* Used for MEMORY_HOTPLUG */
63141 -#define __meminit __section(.meminit.text) __cold notrace
63142 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63143 #define __meminitdata __section(.meminit.data)
63144 #define __meminitconst __section(.meminit.rodata)
63145 #define __memexit __section(.memexit.text) __exitused __cold notrace
63146 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63147 index 89f1cb1..7986c0f 100644
63148 --- a/include/linux/init_task.h
63149 +++ b/include/linux/init_task.h
63150 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63151
63152 #define INIT_TASK_COMM "swapper"
63153
63154 +#ifdef CONFIG_X86
63155 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63156 +#else
63157 +#define INIT_TASK_THREAD_INFO
63158 +#endif
63159 +
63160 /*
63161 * INIT_TASK is used to set up the first task table, touch at
63162 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63163 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63164 RCU_POINTER_INITIALIZER(cred, &init_cred), \
63165 .comm = INIT_TASK_COMM, \
63166 .thread = INIT_THREAD, \
63167 + INIT_TASK_THREAD_INFO \
63168 .fs = &init_fs, \
63169 .files = &init_files, \
63170 .signal = &init_signals, \
63171 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63172 index 78e2ada..745564d 100644
63173 --- a/include/linux/intel-iommu.h
63174 +++ b/include/linux/intel-iommu.h
63175 @@ -296,7 +296,7 @@ struct iommu_flush {
63176 u8 fm, u64 type);
63177 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63178 unsigned int size_order, u64 type);
63179 -};
63180 +} __no_const;
63181
63182 enum {
63183 SR_DMAR_FECTL_REG,
63184 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63185 index c5f856a..d29c117 100644
63186 --- a/include/linux/interrupt.h
63187 +++ b/include/linux/interrupt.h
63188 @@ -433,7 +433,7 @@ enum
63189 /* map softirq index to softirq name. update 'softirq_to_name' in
63190 * kernel/softirq.c when adding a new softirq.
63191 */
63192 -extern char *softirq_to_name[NR_SOFTIRQS];
63193 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63194
63195 /* softirq mask and active fields moved to irq_cpustat_t in
63196 * asm/hardirq.h to get better cache usage. KAO
63197 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63198
63199 struct softirq_action
63200 {
63201 - void (*action)(struct softirq_action *);
63202 + void (*action)(void);
63203 };
63204
63205 asmlinkage void do_softirq(void);
63206 asmlinkage void __do_softirq(void);
63207 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63208 +extern void open_softirq(int nr, void (*action)(void));
63209 extern void softirq_init(void);
63210 extern void __raise_softirq_irqoff(unsigned int nr);
63211
63212 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63213 index 6883e19..06992b1 100644
63214 --- a/include/linux/kallsyms.h
63215 +++ b/include/linux/kallsyms.h
63216 @@ -15,7 +15,8 @@
63217
63218 struct module;
63219
63220 -#ifdef CONFIG_KALLSYMS
63221 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63222 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63223 /* Lookup the address for a symbol. Returns 0 if not found. */
63224 unsigned long kallsyms_lookup_name(const char *name);
63225
63226 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63227 /* Stupid that this does nothing, but I didn't create this mess. */
63228 #define __print_symbol(fmt, addr)
63229 #endif /*CONFIG_KALLSYMS*/
63230 +#else /* when included by kallsyms.c, vsnprintf.c, or
63231 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63232 +extern void __print_symbol(const char *fmt, unsigned long address);
63233 +extern int sprint_backtrace(char *buffer, unsigned long address);
63234 +extern int sprint_symbol(char *buffer, unsigned long address);
63235 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63236 +const char *kallsyms_lookup(unsigned long addr,
63237 + unsigned long *symbolsize,
63238 + unsigned long *offset,
63239 + char **modname, char *namebuf);
63240 +#endif
63241
63242 /* This macro allows us to keep printk typechecking */
63243 static __printf(1, 2)
63244 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63245 index c4d2fc1..5df9c19 100644
63246 --- a/include/linux/kgdb.h
63247 +++ b/include/linux/kgdb.h
63248 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63249 extern int kgdb_io_module_registered;
63250
63251 extern atomic_t kgdb_setting_breakpoint;
63252 -extern atomic_t kgdb_cpu_doing_single_step;
63253 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63254
63255 extern struct task_struct *kgdb_usethread;
63256 extern struct task_struct *kgdb_contthread;
63257 @@ -252,7 +252,7 @@ struct kgdb_arch {
63258 void (*disable_hw_break)(struct pt_regs *regs);
63259 void (*remove_all_hw_break)(void);
63260 void (*correct_hw_break)(void);
63261 -};
63262 +} __do_const;
63263
63264 /**
63265 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63266 @@ -277,7 +277,7 @@ struct kgdb_io {
63267 void (*pre_exception) (void);
63268 void (*post_exception) (void);
63269 int is_console;
63270 -};
63271 +} __do_const;
63272
63273 extern struct kgdb_arch arch_kgdb_ops;
63274
63275 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63276 index 5398d58..5883a34 100644
63277 --- a/include/linux/kmod.h
63278 +++ b/include/linux/kmod.h
63279 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63280 * usually useless though. */
63281 extern __printf(2, 3)
63282 int __request_module(bool wait, const char *name, ...);
63283 +extern __printf(3, 4)
63284 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63285 #define request_module(mod...) __request_module(true, mod)
63286 #define request_module_nowait(mod...) __request_module(false, mod)
63287 #define try_then_request_module(x, mod...) \
63288 diff --git a/include/linux/kref.h b/include/linux/kref.h
63289 index 65af688..0592677 100644
63290 --- a/include/linux/kref.h
63291 +++ b/include/linux/kref.h
63292 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63293 static inline int kref_sub(struct kref *kref, unsigned int count,
63294 void (*release)(struct kref *kref))
63295 {
63296 - WARN_ON(release == NULL);
63297 + BUG_ON(release == NULL);
63298
63299 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63300 release(kref);
63301 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63302 index b70b48b..0d7153b 100644
63303 --- a/include/linux/kvm_host.h
63304 +++ b/include/linux/kvm_host.h
63305 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63306 void vcpu_load(struct kvm_vcpu *vcpu);
63307 void vcpu_put(struct kvm_vcpu *vcpu);
63308
63309 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63310 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63311 struct module *module);
63312 void kvm_exit(void);
63313
63314 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63315 struct kvm_guest_debug *dbg);
63316 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63317
63318 -int kvm_arch_init(void *opaque);
63319 +int kvm_arch_init(const void *opaque);
63320 void kvm_arch_exit(void);
63321
63322 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63323 diff --git a/include/linux/libata.h b/include/linux/libata.h
63324 index 64f90e1..32b945b 100644
63325 --- a/include/linux/libata.h
63326 +++ b/include/linux/libata.h
63327 @@ -909,7 +909,7 @@ struct ata_port_operations {
63328 * fields must be pointers.
63329 */
63330 const struct ata_port_operations *inherits;
63331 -};
63332 +} __do_const;
63333
63334 struct ata_port_info {
63335 unsigned long flags;
63336 diff --git a/include/linux/memory.h b/include/linux/memory.h
63337 index ff9a9f8..c715deb 100644
63338 --- a/include/linux/memory.h
63339 +++ b/include/linux/memory.h
63340 @@ -143,7 +143,7 @@ struct memory_accessor {
63341 size_t count);
63342 ssize_t (*write)(struct memory_accessor *, const char *buf,
63343 off_t offset, size_t count);
63344 -};
63345 +} __no_const;
63346
63347 /*
63348 * Kernel text modification mutex, used for code patching. Users of this lock
63349 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63350 index 1318ca6..7521340 100644
63351 --- a/include/linux/mfd/abx500.h
63352 +++ b/include/linux/mfd/abx500.h
63353 @@ -452,6 +452,7 @@ struct abx500_ops {
63354 int (*event_registers_startup_state_get) (struct device *, u8 *);
63355 int (*startup_irq_enabled) (struct device *, unsigned int);
63356 };
63357 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63358
63359 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63360 void abx500_remove_ops(struct device *dev);
63361 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63362 index 9b07725..3d55001 100644
63363 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63364 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63365 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63366 int (*enable) (struct ux500_charger *, int, int, int);
63367 int (*kick_wd) (struct ux500_charger *);
63368 int (*update_curr) (struct ux500_charger *, int);
63369 -};
63370 +} __no_const;
63371
63372 /**
63373 * struct ux500_charger - power supply ux500 charger sub class
63374 diff --git a/include/linux/mm.h b/include/linux/mm.h
63375 index 311be90..5f1638c 100644
63376 --- a/include/linux/mm.h
63377 +++ b/include/linux/mm.h
63378 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63379
63380 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63381 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63382 +
63383 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63384 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63385 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63386 +#else
63387 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63388 +#endif
63389 +
63390 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63391 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63392
63393 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63394 int set_page_dirty_lock(struct page *page);
63395 int clear_page_dirty_for_io(struct page *page);
63396
63397 -/* Is the vma a continuation of the stack vma above it? */
63398 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63399 -{
63400 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63401 -}
63402 -
63403 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63404 - unsigned long addr)
63405 -{
63406 - return (vma->vm_flags & VM_GROWSDOWN) &&
63407 - (vma->vm_start == addr) &&
63408 - !vma_growsdown(vma->vm_prev, addr);
63409 -}
63410 -
63411 -/* Is the vma a continuation of the stack vma below it? */
63412 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63413 -{
63414 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63415 -}
63416 -
63417 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63418 - unsigned long addr)
63419 -{
63420 - return (vma->vm_flags & VM_GROWSUP) &&
63421 - (vma->vm_end == addr) &&
63422 - !vma_growsup(vma->vm_next, addr);
63423 -}
63424 -
63425 extern pid_t
63426 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63427
63428 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63429 }
63430 #endif
63431
63432 +#ifdef CONFIG_MMU
63433 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63434 +#else
63435 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63436 +{
63437 + return __pgprot(0);
63438 +}
63439 +#endif
63440 +
63441 int vma_wants_writenotify(struct vm_area_struct *vma);
63442
63443 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63444 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63445 {
63446 return 0;
63447 }
63448 +
63449 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63450 + unsigned long address)
63451 +{
63452 + return 0;
63453 +}
63454 #else
63455 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63456 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63457 #endif
63458
63459 #ifdef __PAGETABLE_PMD_FOLDED
63460 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63461 {
63462 return 0;
63463 }
63464 +
63465 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63466 + unsigned long address)
63467 +{
63468 + return 0;
63469 +}
63470 #else
63471 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63472 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63473 #endif
63474
63475 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63476 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63477 NULL: pud_offset(pgd, address);
63478 }
63479
63480 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63481 +{
63482 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63483 + NULL: pud_offset(pgd, address);
63484 +}
63485 +
63486 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63487 {
63488 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63489 NULL: pmd_offset(pud, address);
63490 }
63491 +
63492 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63493 +{
63494 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63495 + NULL: pmd_offset(pud, address);
63496 +}
63497 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63498
63499 #if USE_SPLIT_PTLOCKS
63500 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63501 unsigned long, unsigned long,
63502 unsigned long, unsigned long);
63503 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63504 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63505
63506 /* These take the mm semaphore themselves */
63507 extern unsigned long vm_brk(unsigned long, unsigned long);
63508 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63509 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63510 struct vm_area_struct **pprev);
63511
63512 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63513 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63514 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63515 +
63516 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63517 NULL if none. Assume start_addr < end_addr. */
63518 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63519 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63520 return vma;
63521 }
63522
63523 -#ifdef CONFIG_MMU
63524 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63525 -#else
63526 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63527 -{
63528 - return __pgprot(0);
63529 -}
63530 -#endif
63531 -
63532 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63533 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63534 unsigned long pfn, unsigned long size, pgprot_t);
63535 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63536 extern int sysctl_memory_failure_early_kill;
63537 extern int sysctl_memory_failure_recovery;
63538 extern void shake_page(struct page *p, int access);
63539 -extern atomic_long_t mce_bad_pages;
63540 +extern atomic_long_unchecked_t mce_bad_pages;
63541 extern int soft_offline_page(struct page *page, int flags);
63542
63543 extern void dump_page(struct page *page);
63544 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63545 static inline bool page_is_guard(struct page *page) { return false; }
63546 #endif /* CONFIG_DEBUG_PAGEALLOC */
63547
63548 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63549 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63550 +#else
63551 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63552 +#endif
63553 +
63554 #endif /* __KERNEL__ */
63555 #endif /* _LINUX_MM_H */
63556 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63557 index bf78672..debc693 100644
63558 --- a/include/linux/mm_types.h
63559 +++ b/include/linux/mm_types.h
63560 @@ -279,6 +279,8 @@ struct vm_area_struct {
63561 #ifdef CONFIG_NUMA
63562 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63563 #endif
63564 +
63565 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63566 };
63567
63568 struct core_thread {
63569 @@ -353,7 +355,7 @@ struct mm_struct {
63570 unsigned long def_flags;
63571 unsigned long nr_ptes; /* Page table pages */
63572 unsigned long start_code, end_code, start_data, end_data;
63573 - unsigned long start_brk, brk, start_stack;
63574 + unsigned long brk_gap, start_brk, brk, start_stack;
63575 unsigned long arg_start, arg_end, env_start, env_end;
63576
63577 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63578 @@ -405,6 +407,24 @@ struct mm_struct {
63579 struct cpumask cpumask_allocation;
63580 #endif
63581 struct uprobes_state uprobes_state;
63582 +
63583 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63584 + unsigned long pax_flags;
63585 +#endif
63586 +
63587 +#ifdef CONFIG_PAX_DLRESOLVE
63588 + unsigned long call_dl_resolve;
63589 +#endif
63590 +
63591 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63592 + unsigned long call_syscall;
63593 +#endif
63594 +
63595 +#ifdef CONFIG_PAX_ASLR
63596 + unsigned long delta_mmap; /* randomized offset */
63597 + unsigned long delta_stack; /* randomized offset */
63598 +#endif
63599 +
63600 };
63601
63602 static inline void mm_init_cpumask(struct mm_struct *mm)
63603 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63604 index 1d1b1e1..2a13c78 100644
63605 --- a/include/linux/mmu_notifier.h
63606 +++ b/include/linux/mmu_notifier.h
63607 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63608 */
63609 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63610 ({ \
63611 - pte_t __pte; \
63612 + pte_t ___pte; \
63613 struct vm_area_struct *___vma = __vma; \
63614 unsigned long ___address = __address; \
63615 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63616 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63617 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63618 - __pte; \
63619 + ___pte; \
63620 })
63621
63622 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63623 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63624 index 2daa54f..bfdf2f5 100644
63625 --- a/include/linux/mmzone.h
63626 +++ b/include/linux/mmzone.h
63627 @@ -414,7 +414,7 @@ struct zone {
63628 unsigned long flags; /* zone flags, see below */
63629
63630 /* Zone statistics */
63631 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63632 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63633
63634 /*
63635 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63636 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63637 index 6955045..ebdb7cd 100644
63638 --- a/include/linux/mod_devicetable.h
63639 +++ b/include/linux/mod_devicetable.h
63640 @@ -12,7 +12,7 @@
63641 typedef unsigned long kernel_ulong_t;
63642 #endif
63643
63644 -#define PCI_ANY_ID (~0)
63645 +#define PCI_ANY_ID ((__u16)~0)
63646
63647 struct pci_device_id {
63648 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63649 @@ -139,7 +139,7 @@ struct usb_device_id {
63650 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63651 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63652
63653 -#define HID_ANY_ID (~0)
63654 +#define HID_ANY_ID (~0U)
63655 #define HID_BUS_ANY 0xffff
63656 #define HID_GROUP_ANY 0x0000
63657
63658 diff --git a/include/linux/module.h b/include/linux/module.h
63659 index fbcafe2..e5d9587 100644
63660 --- a/include/linux/module.h
63661 +++ b/include/linux/module.h
63662 @@ -17,6 +17,7 @@
63663 #include <linux/moduleparam.h>
63664 #include <linux/tracepoint.h>
63665 #include <linux/export.h>
63666 +#include <linux/fs.h>
63667
63668 #include <linux/percpu.h>
63669 #include <asm/module.h>
63670 @@ -273,19 +274,16 @@ struct module
63671 int (*init)(void);
63672
63673 /* If this is non-NULL, vfree after init() returns */
63674 - void *module_init;
63675 + void *module_init_rx, *module_init_rw;
63676
63677 /* Here is the actual code + data, vfree'd on unload. */
63678 - void *module_core;
63679 + void *module_core_rx, *module_core_rw;
63680
63681 /* Here are the sizes of the init and core sections */
63682 - unsigned int init_size, core_size;
63683 + unsigned int init_size_rw, core_size_rw;
63684
63685 /* The size of the executable code in each section. */
63686 - unsigned int init_text_size, core_text_size;
63687 -
63688 - /* Size of RO sections of the module (text+rodata) */
63689 - unsigned int init_ro_size, core_ro_size;
63690 + unsigned int init_size_rx, core_size_rx;
63691
63692 /* Arch-specific module values */
63693 struct mod_arch_specific arch;
63694 @@ -341,6 +339,10 @@ struct module
63695 #ifdef CONFIG_EVENT_TRACING
63696 struct ftrace_event_call **trace_events;
63697 unsigned int num_trace_events;
63698 + struct file_operations trace_id;
63699 + struct file_operations trace_enable;
63700 + struct file_operations trace_format;
63701 + struct file_operations trace_filter;
63702 #endif
63703 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63704 unsigned int num_ftrace_callsites;
63705 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63706 bool is_module_percpu_address(unsigned long addr);
63707 bool is_module_text_address(unsigned long addr);
63708
63709 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63710 +{
63711 +
63712 +#ifdef CONFIG_PAX_KERNEXEC
63713 + if (ktla_ktva(addr) >= (unsigned long)start &&
63714 + ktla_ktva(addr) < (unsigned long)start + size)
63715 + return 1;
63716 +#endif
63717 +
63718 + return ((void *)addr >= start && (void *)addr < start + size);
63719 +}
63720 +
63721 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63722 +{
63723 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63724 +}
63725 +
63726 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63727 +{
63728 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63729 +}
63730 +
63731 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63732 +{
63733 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63734 +}
63735 +
63736 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63737 +{
63738 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63739 +}
63740 +
63741 static inline int within_module_core(unsigned long addr, struct module *mod)
63742 {
63743 - return (unsigned long)mod->module_core <= addr &&
63744 - addr < (unsigned long)mod->module_core + mod->core_size;
63745 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63746 }
63747
63748 static inline int within_module_init(unsigned long addr, struct module *mod)
63749 {
63750 - return (unsigned long)mod->module_init <= addr &&
63751 - addr < (unsigned long)mod->module_init + mod->init_size;
63752 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63753 }
63754
63755 /* Search for module by name: must hold module_mutex. */
63756 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63757 index b2be02e..72d2f78 100644
63758 --- a/include/linux/moduleloader.h
63759 +++ b/include/linux/moduleloader.h
63760 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63761
63762 /* Allocator used for allocating struct module, core sections and init
63763 sections. Returns NULL on failure. */
63764 -void *module_alloc(unsigned long size);
63765 +void *module_alloc(unsigned long size) __size_overflow(1);
63766 +
63767 +#ifdef CONFIG_PAX_KERNEXEC
63768 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63769 +#else
63770 +#define module_alloc_exec(x) module_alloc(x)
63771 +#endif
63772
63773 /* Free memory returned from module_alloc. */
63774 void module_free(struct module *mod, void *module_region);
63775
63776 +#ifdef CONFIG_PAX_KERNEXEC
63777 +void module_free_exec(struct module *mod, void *module_region);
63778 +#else
63779 +#define module_free_exec(x, y) module_free((x), (y))
63780 +#endif
63781 +
63782 /* Apply the given relocation to the (simplified) ELF. Return -error
63783 or 0. */
63784 int apply_relocate(Elf_Shdr *sechdrs,
63785 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63786 index d6a5806..7c13347 100644
63787 --- a/include/linux/moduleparam.h
63788 +++ b/include/linux/moduleparam.h
63789 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63790 * @len is usually just sizeof(string).
63791 */
63792 #define module_param_string(name, string, len, perm) \
63793 - static const struct kparam_string __param_string_##name \
63794 + static const struct kparam_string __param_string_##name __used \
63795 = { len, string }; \
63796 __module_param_call(MODULE_PARAM_PREFIX, name, \
63797 &param_ops_string, \
63798 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63799 */
63800 #define module_param_array_named(name, array, type, nump, perm) \
63801 param_check_##type(name, &(array)[0]); \
63802 - static const struct kparam_array __param_arr_##name \
63803 + static const struct kparam_array __param_arr_##name __used \
63804 = { .max = ARRAY_SIZE(array), .num = nump, \
63805 .ops = &param_ops_##type, \
63806 .elemsize = sizeof(array[0]), .elem = array }; \
63807 diff --git a/include/linux/namei.h b/include/linux/namei.h
63808 index 4bf19d8..5268cea 100644
63809 --- a/include/linux/namei.h
63810 +++ b/include/linux/namei.h
63811 @@ -18,7 +18,7 @@ struct nameidata {
63812 unsigned seq;
63813 int last_type;
63814 unsigned depth;
63815 - char *saved_names[MAX_NESTED_LINKS + 1];
63816 + const char *saved_names[MAX_NESTED_LINKS + 1];
63817 };
63818
63819 /*
63820 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63821
63822 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63823
63824 -static inline void nd_set_link(struct nameidata *nd, char *path)
63825 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63826 {
63827 nd->saved_names[nd->depth] = path;
63828 }
63829
63830 -static inline char *nd_get_link(struct nameidata *nd)
63831 +static inline const char *nd_get_link(const struct nameidata *nd)
63832 {
63833 return nd->saved_names[nd->depth];
63834 }
63835 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63836 index 59dc05f3..c905a34 100644
63837 --- a/include/linux/netdevice.h
63838 +++ b/include/linux/netdevice.h
63839 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63840 struct net_device *dev,
63841 int idx);
63842 };
63843 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63844
63845 /*
63846 * The DEVICE structure.
63847 @@ -1087,7 +1088,7 @@ struct net_device {
63848 int iflink;
63849
63850 struct net_device_stats stats;
63851 - atomic_long_t rx_dropped; /* dropped packets by core network
63852 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63853 * Do not use this in drivers.
63854 */
63855
63856 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63857 new file mode 100644
63858 index 0000000..33f4af8
63859 --- /dev/null
63860 +++ b/include/linux/netfilter/xt_gradm.h
63861 @@ -0,0 +1,9 @@
63862 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63863 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63864 +
63865 +struct xt_gradm_mtinfo {
63866 + __u16 flags;
63867 + __u16 invflags;
63868 +};
63869 +
63870 +#endif
63871 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63872 index c65a18a..0c05f3a 100644
63873 --- a/include/linux/of_pdt.h
63874 +++ b/include/linux/of_pdt.h
63875 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63876
63877 /* return 0 on success; fill in 'len' with number of bytes in path */
63878 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63879 -};
63880 +} __no_const;
63881
63882 extern void *prom_early_alloc(unsigned long size);
63883
63884 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63885 index a4c5624..79d6d88 100644
63886 --- a/include/linux/oprofile.h
63887 +++ b/include/linux/oprofile.h
63888 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63889 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63890 char const * name, ulong * val);
63891
63892 -/** Create a file for read-only access to an atomic_t. */
63893 +/** Create a file for read-only access to an atomic_unchecked_t. */
63894 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63895 - char const * name, atomic_t * val);
63896 + char const * name, atomic_unchecked_t * val);
63897
63898 /** create a directory */
63899 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63900 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63901 index bdb4161..f373d41 100644
63902 --- a/include/linux/perf_event.h
63903 +++ b/include/linux/perf_event.h
63904 @@ -882,8 +882,8 @@ struct perf_event {
63905
63906 enum perf_event_active_state state;
63907 unsigned int attach_state;
63908 - local64_t count;
63909 - atomic64_t child_count;
63910 + local64_t count; /* PaX: fix it one day */
63911 + atomic64_unchecked_t child_count;
63912
63913 /*
63914 * These are the total time in nanoseconds that the event
63915 @@ -934,8 +934,8 @@ struct perf_event {
63916 * These accumulate total time (in nanoseconds) that children
63917 * events have been enabled and running, respectively.
63918 */
63919 - atomic64_t child_total_time_enabled;
63920 - atomic64_t child_total_time_running;
63921 + atomic64_unchecked_t child_total_time_enabled;
63922 + atomic64_unchecked_t child_total_time_running;
63923
63924 /*
63925 * Protect attach/detach and child_list:
63926 diff --git a/include/linux/personality.h b/include/linux/personality.h
63927 index 8fc7dd1a..c19d89e 100644
63928 --- a/include/linux/personality.h
63929 +++ b/include/linux/personality.h
63930 @@ -44,6 +44,7 @@ enum {
63931 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63932 ADDR_NO_RANDOMIZE | \
63933 ADDR_COMPAT_LAYOUT | \
63934 + ADDR_LIMIT_3GB | \
63935 MMAP_PAGE_ZERO)
63936
63937 /*
63938 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63939 index ad1a427..6419649 100644
63940 --- a/include/linux/pipe_fs_i.h
63941 +++ b/include/linux/pipe_fs_i.h
63942 @@ -45,9 +45,9 @@ struct pipe_buffer {
63943 struct pipe_inode_info {
63944 wait_queue_head_t wait;
63945 unsigned int nrbufs, curbuf, buffers;
63946 - unsigned int readers;
63947 - unsigned int writers;
63948 - unsigned int waiting_writers;
63949 + atomic_t readers;
63950 + atomic_t writers;
63951 + atomic_t waiting_writers;
63952 unsigned int r_counter;
63953 unsigned int w_counter;
63954 struct page *tmp_page;
63955 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63956 index f271860..6b3bec5 100644
63957 --- a/include/linux/pm_runtime.h
63958 +++ b/include/linux/pm_runtime.h
63959 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63960
63961 static inline void pm_runtime_mark_last_busy(struct device *dev)
63962 {
63963 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63964 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63965 }
63966
63967 #else /* !CONFIG_PM_RUNTIME */
63968 diff --git a/include/linux/poison.h b/include/linux/poison.h
63969 index 2110a81..13a11bb 100644
63970 --- a/include/linux/poison.h
63971 +++ b/include/linux/poison.h
63972 @@ -19,8 +19,8 @@
63973 * under normal circumstances, used to verify that nobody uses
63974 * non-initialized list entries.
63975 */
63976 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63977 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63978 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63979 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63980
63981 /********** include/linux/timer.h **********/
63982 /*
63983 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63984 index 5a710b9..0b0dab9 100644
63985 --- a/include/linux/preempt.h
63986 +++ b/include/linux/preempt.h
63987 @@ -126,7 +126,7 @@ struct preempt_ops {
63988 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63989 void (*sched_out)(struct preempt_notifier *notifier,
63990 struct task_struct *next);
63991 -};
63992 +} __no_const;
63993
63994 /**
63995 * preempt_notifier - key for installing preemption notifiers
63996 diff --git a/include/linux/printk.h b/include/linux/printk.h
63997 index 9afc01e..92c32e8 100644
63998 --- a/include/linux/printk.h
63999 +++ b/include/linux/printk.h
64000 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
64001 extern int printk_needs_cpu(int cpu);
64002 extern void printk_tick(void);
64003
64004 +extern int kptr_restrict;
64005 +
64006 #ifdef CONFIG_PRINTK
64007 asmlinkage __printf(5, 0)
64008 int vprintk_emit(int facility, int level,
64009 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
64010
64011 extern int printk_delay_msec;
64012 extern int dmesg_restrict;
64013 -extern int kptr_restrict;
64014
64015 void log_buf_kexec_setup(void);
64016 void __init setup_log_buf(int early);
64017 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
64018 index 3fd2e87..d93a721 100644
64019 --- a/include/linux/proc_fs.h
64020 +++ b/include/linux/proc_fs.h
64021 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
64022 return proc_create_data(name, mode, parent, proc_fops, NULL);
64023 }
64024
64025 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
64026 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
64027 +{
64028 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64029 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
64030 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64031 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
64032 +#else
64033 + return proc_create_data(name, mode, parent, proc_fops, NULL);
64034 +#endif
64035 +}
64036 +
64037 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
64038 umode_t mode, struct proc_dir_entry *base,
64039 read_proc_t *read_proc, void * data)
64040 @@ -258,7 +270,7 @@ union proc_op {
64041 int (*proc_show)(struct seq_file *m,
64042 struct pid_namespace *ns, struct pid *pid,
64043 struct task_struct *task);
64044 -};
64045 +} __no_const;
64046
64047 struct ctl_table_header;
64048 struct ctl_table;
64049 diff --git a/include/linux/random.h b/include/linux/random.h
64050 index ac621ce..c1215f3 100644
64051 --- a/include/linux/random.h
64052 +++ b/include/linux/random.h
64053 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64054 unsigned int value);
64055 extern void add_interrupt_randomness(int irq, int irq_flags);
64056
64057 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64058 +extern void transfer_latent_entropy(void);
64059 +#endif
64060 +
64061 extern void get_random_bytes(void *buf, int nbytes);
64062 extern void get_random_bytes_arch(void *buf, int nbytes);
64063 void generate_random_uuid(unsigned char uuid_out[16]);
64064 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64065
64066 u32 prandom32(struct rnd_state *);
64067
64068 +static inline unsigned long pax_get_random_long(void)
64069 +{
64070 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64071 +}
64072 +
64073 /*
64074 * Handle minimum values for seeds
64075 */
64076 static inline u32 __seed(u32 x, u32 m)
64077 {
64078 - return (x < m) ? x + m : x;
64079 + return (x <= m) ? x + m + 1 : x;
64080 }
64081
64082 /**
64083 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64084 index e0879a7..a12f962 100644
64085 --- a/include/linux/reboot.h
64086 +++ b/include/linux/reboot.h
64087 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64088 * Architecture-specific implementations of sys_reboot commands.
64089 */
64090
64091 -extern void machine_restart(char *cmd);
64092 -extern void machine_halt(void);
64093 -extern void machine_power_off(void);
64094 +extern void machine_restart(char *cmd) __noreturn;
64095 +extern void machine_halt(void) __noreturn;
64096 +extern void machine_power_off(void) __noreturn;
64097
64098 extern void machine_shutdown(void);
64099 struct pt_regs;
64100 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64101 */
64102
64103 extern void kernel_restart_prepare(char *cmd);
64104 -extern void kernel_restart(char *cmd);
64105 -extern void kernel_halt(void);
64106 -extern void kernel_power_off(void);
64107 +extern void kernel_restart(char *cmd) __noreturn;
64108 +extern void kernel_halt(void) __noreturn;
64109 +extern void kernel_power_off(void) __noreturn;
64110
64111 extern int C_A_D; /* for sysctl */
64112 void ctrl_alt_del(void);
64113 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64114 * Emergency restart, callable from an interrupt handler.
64115 */
64116
64117 -extern void emergency_restart(void);
64118 +extern void emergency_restart(void) __noreturn;
64119 #include <asm/emergency-restart.h>
64120
64121 #endif
64122 diff --git a/include/linux/relay.h b/include/linux/relay.h
64123 index 91cacc3..b55ff74 100644
64124 --- a/include/linux/relay.h
64125 +++ b/include/linux/relay.h
64126 @@ -160,7 +160,7 @@ struct rchan_callbacks
64127 * The callback should return 0 if successful, negative if not.
64128 */
64129 int (*remove_buf_file)(struct dentry *dentry);
64130 -};
64131 +} __no_const;
64132
64133 /*
64134 * CONFIG_RELAY kernel API, kernel/relay.c
64135 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64136 index 6fdf027..ff72610 100644
64137 --- a/include/linux/rfkill.h
64138 +++ b/include/linux/rfkill.h
64139 @@ -147,6 +147,7 @@ struct rfkill_ops {
64140 void (*query)(struct rfkill *rfkill, void *data);
64141 int (*set_block)(void *data, bool blocked);
64142 };
64143 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64144
64145 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64146 /**
64147 diff --git a/include/linux/rio.h b/include/linux/rio.h
64148 index a90ebad..fd87b5d 100644
64149 --- a/include/linux/rio.h
64150 +++ b/include/linux/rio.h
64151 @@ -321,7 +321,7 @@ struct rio_ops {
64152 int mbox, void *buffer, size_t len);
64153 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64154 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64155 -};
64156 +} __no_const;
64157
64158 #define RIO_RESOURCE_MEM 0x00000100
64159 #define RIO_RESOURCE_DOORBELL 0x00000200
64160 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64161 index 3fce545..b4fed6e 100644
64162 --- a/include/linux/rmap.h
64163 +++ b/include/linux/rmap.h
64164 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64165 void anon_vma_init(void); /* create anon_vma_cachep */
64166 int anon_vma_prepare(struct vm_area_struct *);
64167 void unlink_anon_vmas(struct vm_area_struct *);
64168 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64169 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64170 void anon_vma_moveto_tail(struct vm_area_struct *);
64171 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64172 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64173
64174 static inline void anon_vma_merge(struct vm_area_struct *vma,
64175 struct vm_area_struct *next)
64176 diff --git a/include/linux/sched.h b/include/linux/sched.h
64177 index 23bddac..5976055 100644
64178 --- a/include/linux/sched.h
64179 +++ b/include/linux/sched.h
64180 @@ -101,6 +101,7 @@ struct bio_list;
64181 struct fs_struct;
64182 struct perf_event_context;
64183 struct blk_plug;
64184 +struct linux_binprm;
64185
64186 /*
64187 * List of flags we want to share for kernel threads,
64188 @@ -384,10 +385,13 @@ struct user_namespace;
64189 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64190
64191 extern int sysctl_max_map_count;
64192 +extern unsigned long sysctl_heap_stack_gap;
64193
64194 #include <linux/aio.h>
64195
64196 #ifdef CONFIG_MMU
64197 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64198 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64199 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64200 extern unsigned long
64201 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64202 @@ -651,6 +655,17 @@ struct signal_struct {
64203 #ifdef CONFIG_TASKSTATS
64204 struct taskstats *stats;
64205 #endif
64206 +
64207 +#ifdef CONFIG_GRKERNSEC
64208 + u32 curr_ip;
64209 + u32 saved_ip;
64210 + u32 gr_saddr;
64211 + u32 gr_daddr;
64212 + u16 gr_sport;
64213 + u16 gr_dport;
64214 + u8 used_accept:1;
64215 +#endif
64216 +
64217 #ifdef CONFIG_AUDIT
64218 unsigned audit_tty;
64219 struct tty_audit_buf *tty_audit_buf;
64220 @@ -734,6 +749,11 @@ struct user_struct {
64221 struct key *session_keyring; /* UID's default session keyring */
64222 #endif
64223
64224 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64225 + unsigned int banned;
64226 + unsigned long ban_expires;
64227 +#endif
64228 +
64229 /* Hash table maintenance information */
64230 struct hlist_node uidhash_node;
64231 kuid_t uid;
64232 @@ -1356,8 +1376,8 @@ struct task_struct {
64233 struct list_head thread_group;
64234
64235 struct completion *vfork_done; /* for vfork() */
64236 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64237 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64238 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64239 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64240
64241 cputime_t utime, stime, utimescaled, stimescaled;
64242 cputime_t gtime;
64243 @@ -1373,11 +1393,6 @@ struct task_struct {
64244 struct task_cputime cputime_expires;
64245 struct list_head cpu_timers[3];
64246
64247 -/* process credentials */
64248 - const struct cred __rcu *real_cred; /* objective and real subjective task
64249 - * credentials (COW) */
64250 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64251 - * credentials (COW) */
64252 char comm[TASK_COMM_LEN]; /* executable name excluding path
64253 - access with [gs]et_task_comm (which lock
64254 it with task_lock())
64255 @@ -1394,6 +1409,10 @@ struct task_struct {
64256 #endif
64257 /* CPU-specific state of this task */
64258 struct thread_struct thread;
64259 +/* thread_info moved to task_struct */
64260 +#ifdef CONFIG_X86
64261 + struct thread_info tinfo;
64262 +#endif
64263 /* filesystem information */
64264 struct fs_struct *fs;
64265 /* open file information */
64266 @@ -1467,6 +1486,10 @@ struct task_struct {
64267 gfp_t lockdep_reclaim_gfp;
64268 #endif
64269
64270 +/* process credentials */
64271 + const struct cred __rcu *real_cred; /* objective and real subjective task
64272 + * credentials (COW) */
64273 +
64274 /* journalling filesystem info */
64275 void *journal_info;
64276
64277 @@ -1505,6 +1528,10 @@ struct task_struct {
64278 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64279 struct list_head cg_list;
64280 #endif
64281 +
64282 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64283 + * credentials (COW) */
64284 +
64285 #ifdef CONFIG_FUTEX
64286 struct robust_list_head __user *robust_list;
64287 #ifdef CONFIG_COMPAT
64288 @@ -1589,8 +1616,74 @@ struct task_struct {
64289 #ifdef CONFIG_UPROBES
64290 struct uprobe_task *utask;
64291 #endif
64292 +
64293 +#ifdef CONFIG_GRKERNSEC
64294 + /* grsecurity */
64295 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64296 + u64 exec_id;
64297 +#endif
64298 +#ifdef CONFIG_GRKERNSEC_SETXID
64299 + const struct cred *delayed_cred;
64300 +#endif
64301 + struct dentry *gr_chroot_dentry;
64302 + struct acl_subject_label *acl;
64303 + struct acl_role_label *role;
64304 + struct file *exec_file;
64305 + u16 acl_role_id;
64306 + /* is this the task that authenticated to the special role */
64307 + u8 acl_sp_role;
64308 + u8 is_writable;
64309 + u8 brute;
64310 + u8 gr_is_chrooted;
64311 +#endif
64312 +
64313 };
64314
64315 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64316 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64317 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64318 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64319 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64320 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64321 +
64322 +#ifdef CONFIG_PAX_SOFTMODE
64323 +extern int pax_softmode;
64324 +#endif
64325 +
64326 +extern int pax_check_flags(unsigned long *);
64327 +
64328 +/* if tsk != current then task_lock must be held on it */
64329 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64330 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64331 +{
64332 + if (likely(tsk->mm))
64333 + return tsk->mm->pax_flags;
64334 + else
64335 + return 0UL;
64336 +}
64337 +
64338 +/* if tsk != current then task_lock must be held on it */
64339 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64340 +{
64341 + if (likely(tsk->mm)) {
64342 + tsk->mm->pax_flags = flags;
64343 + return 0;
64344 + }
64345 + return -EINVAL;
64346 +}
64347 +#endif
64348 +
64349 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64350 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64351 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64352 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64353 +#endif
64354 +
64355 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64356 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64357 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64358 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64359 +
64360 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64361 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64362
64363 @@ -2125,7 +2218,9 @@ void yield(void);
64364 extern struct exec_domain default_exec_domain;
64365
64366 union thread_union {
64367 +#ifndef CONFIG_X86
64368 struct thread_info thread_info;
64369 +#endif
64370 unsigned long stack[THREAD_SIZE/sizeof(long)];
64371 };
64372
64373 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64374 */
64375
64376 extern struct task_struct *find_task_by_vpid(pid_t nr);
64377 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64378 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64379 struct pid_namespace *ns);
64380
64381 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64382 extern void exit_itimers(struct signal_struct *);
64383 extern void flush_itimer_signals(void);
64384
64385 -extern void do_group_exit(int);
64386 +extern __noreturn void do_group_exit(int);
64387
64388 extern void daemonize(const char *, ...);
64389 extern int allow_signal(int);
64390 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64391
64392 #endif
64393
64394 -static inline int object_is_on_stack(void *obj)
64395 +static inline int object_starts_on_stack(void *obj)
64396 {
64397 - void *stack = task_stack_page(current);
64398 + const void *stack = task_stack_page(current);
64399
64400 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64401 }
64402 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64403 index 899fbb4..1cb4138 100644
64404 --- a/include/linux/screen_info.h
64405 +++ b/include/linux/screen_info.h
64406 @@ -43,7 +43,8 @@ struct screen_info {
64407 __u16 pages; /* 0x32 */
64408 __u16 vesa_attributes; /* 0x34 */
64409 __u32 capabilities; /* 0x36 */
64410 - __u8 _reserved[6]; /* 0x3a */
64411 + __u16 vesapm_size; /* 0x3a */
64412 + __u8 _reserved[4]; /* 0x3c */
64413 } __attribute__((packed));
64414
64415 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64416 diff --git a/include/linux/security.h b/include/linux/security.h
64417 index d143b8e..9f27b95 100644
64418 --- a/include/linux/security.h
64419 +++ b/include/linux/security.h
64420 @@ -26,6 +26,7 @@
64421 #include <linux/capability.h>
64422 #include <linux/slab.h>
64423 #include <linux/err.h>
64424 +#include <linux/grsecurity.h>
64425
64426 struct linux_binprm;
64427 struct cred;
64428 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64429 index 83c44ee..e8a9eba 100644
64430 --- a/include/linux/seq_file.h
64431 +++ b/include/linux/seq_file.h
64432 @@ -25,6 +25,9 @@ struct seq_file {
64433 struct mutex lock;
64434 const struct seq_operations *op;
64435 int poll_event;
64436 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64437 + u64 exec_id;
64438 +#endif
64439 void *private;
64440 };
64441
64442 @@ -34,6 +37,7 @@ struct seq_operations {
64443 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64444 int (*show) (struct seq_file *m, void *v);
64445 };
64446 +typedef struct seq_operations __no_const seq_operations_no_const;
64447
64448 #define SEQ_SKIP 1
64449
64450 diff --git a/include/linux/shm.h b/include/linux/shm.h
64451 index edd0868..f98feee 100644
64452 --- a/include/linux/shm.h
64453 +++ b/include/linux/shm.h
64454 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64455
64456 /* The task created the shm object. NULL if the task is dead. */
64457 struct task_struct *shm_creator;
64458 +#ifdef CONFIG_GRKERNSEC
64459 + time_t shm_createtime;
64460 + pid_t shm_lapid;
64461 +#endif
64462 };
64463
64464 /* shm_mode upper byte flags */
64465 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64466 index f3165d2..2cb3cb7 100644
64467 --- a/include/linux/skbuff.h
64468 +++ b/include/linux/skbuff.h
64469 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64470 extern struct sk_buff *__alloc_skb(unsigned int size,
64471 gfp_t priority, int flags, int node);
64472 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64473 -static inline struct sk_buff *alloc_skb(unsigned int size,
64474 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64475 gfp_t priority)
64476 {
64477 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64478 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64479 */
64480 static inline int skb_queue_empty(const struct sk_buff_head *list)
64481 {
64482 - return list->next == (struct sk_buff *)list;
64483 + return list->next == (const struct sk_buff *)list;
64484 }
64485
64486 /**
64487 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64488 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64489 const struct sk_buff *skb)
64490 {
64491 - return skb->next == (struct sk_buff *)list;
64492 + return skb->next == (const struct sk_buff *)list;
64493 }
64494
64495 /**
64496 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64497 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64498 const struct sk_buff *skb)
64499 {
64500 - return skb->prev == (struct sk_buff *)list;
64501 + return skb->prev == (const struct sk_buff *)list;
64502 }
64503
64504 /**
64505 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64506 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64507 */
64508 #ifndef NET_SKB_PAD
64509 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64510 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64511 #endif
64512
64513 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64514 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64515 int noblock, int *err);
64516 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64517 struct poll_table_struct *wait);
64518 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64519 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64520 int offset, struct iovec *to,
64521 int size);
64522 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64523 diff --git a/include/linux/slab.h b/include/linux/slab.h
64524 index 0dd2dfa..2b8677c 100644
64525 --- a/include/linux/slab.h
64526 +++ b/include/linux/slab.h
64527 @@ -11,12 +11,20 @@
64528
64529 #include <linux/gfp.h>
64530 #include <linux/types.h>
64531 +#include <linux/err.h>
64532
64533 /*
64534 * Flags to pass to kmem_cache_create().
64535 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64536 */
64537 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64538 +
64539 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64540 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64541 +#else
64542 +#define SLAB_USERCOPY 0x00000000UL
64543 +#endif
64544 +
64545 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64546 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64547 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64548 @@ -87,10 +95,13 @@
64549 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64550 * Both make kfree a no-op.
64551 */
64552 -#define ZERO_SIZE_PTR ((void *)16)
64553 +#define ZERO_SIZE_PTR \
64554 +({ \
64555 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64556 + (void *)(-MAX_ERRNO-1L); \
64557 +})
64558
64559 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64560 - (unsigned long)ZERO_SIZE_PTR)
64561 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64562
64563 /*
64564 * Common fields provided in kmem_cache by all slab allocators
64565 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64566 void kfree(const void *);
64567 void kzfree(const void *);
64568 size_t ksize(const void *);
64569 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64570 +bool is_usercopy_object(const void *ptr);
64571
64572 /*
64573 * Allocator specific definitions. These are mainly used to establish optimized
64574 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64575 */
64576 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64577 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64578 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64579 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64580 #define kmalloc_track_caller(size, flags) \
64581 __kmalloc_track_caller(size, flags, _RET_IP_)
64582 #else
64583 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64584 */
64585 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64586 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64587 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64588 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64589 #define kmalloc_node_track_caller(size, flags, node) \
64590 __kmalloc_node_track_caller(size, flags, node, \
64591 _RET_IP_)
64592 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64593 index 0c634fa..8616300 100644
64594 --- a/include/linux/slab_def.h
64595 +++ b/include/linux/slab_def.h
64596 @@ -69,10 +69,10 @@ struct kmem_cache {
64597 unsigned long node_allocs;
64598 unsigned long node_frees;
64599 unsigned long node_overflow;
64600 - atomic_t allochit;
64601 - atomic_t allocmiss;
64602 - atomic_t freehit;
64603 - atomic_t freemiss;
64604 + atomic_unchecked_t allochit;
64605 + atomic_unchecked_t allocmiss;
64606 + atomic_unchecked_t freehit;
64607 + atomic_unchecked_t freemiss;
64608
64609 /*
64610 * If debugging is enabled, then the allocator can add additional
64611 @@ -105,11 +105,16 @@ struct cache_sizes {
64612 #ifdef CONFIG_ZONE_DMA
64613 struct kmem_cache *cs_dmacachep;
64614 #endif
64615 +
64616 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64617 + struct kmem_cache *cs_usercopycachep;
64618 +#endif
64619 +
64620 };
64621 extern struct cache_sizes malloc_sizes[];
64622
64623 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64624 -void *__kmalloc(size_t size, gfp_t flags);
64625 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64626
64627 #ifdef CONFIG_TRACING
64628 extern void *kmem_cache_alloc_trace(size_t size,
64629 @@ -152,6 +157,13 @@ found:
64630 cachep = malloc_sizes[i].cs_dmacachep;
64631 else
64632 #endif
64633 +
64634 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64635 + if (flags & GFP_USERCOPY)
64636 + cachep = malloc_sizes[i].cs_usercopycachep;
64637 + else
64638 +#endif
64639 +
64640 cachep = malloc_sizes[i].cs_cachep;
64641
64642 ret = kmem_cache_alloc_trace(size, cachep, flags);
64643 @@ -162,7 +174,7 @@ found:
64644 }
64645
64646 #ifdef CONFIG_NUMA
64647 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64648 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64649 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64650
64651 #ifdef CONFIG_TRACING
64652 @@ -205,6 +217,13 @@ found:
64653 cachep = malloc_sizes[i].cs_dmacachep;
64654 else
64655 #endif
64656 +
64657 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64658 + if (flags & GFP_USERCOPY)
64659 + cachep = malloc_sizes[i].cs_usercopycachep;
64660 + else
64661 +#endif
64662 +
64663 cachep = malloc_sizes[i].cs_cachep;
64664
64665 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64666 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64667 index 0ec00b3..22b4715 100644
64668 --- a/include/linux/slob_def.h
64669 +++ b/include/linux/slob_def.h
64670 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64671 return kmem_cache_alloc_node(cachep, flags, -1);
64672 }
64673
64674 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64675 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64676
64677 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64678 {
64679 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64680 return __kmalloc_node(size, flags, -1);
64681 }
64682
64683 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64684 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64685 {
64686 return kmalloc(size, flags);
64687 }
64688 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64689 index df448ad..b99e7f6 100644
64690 --- a/include/linux/slub_def.h
64691 +++ b/include/linux/slub_def.h
64692 @@ -91,7 +91,7 @@ struct kmem_cache {
64693 struct kmem_cache_order_objects max;
64694 struct kmem_cache_order_objects min;
64695 gfp_t allocflags; /* gfp flags to use on each alloc */
64696 - int refcount; /* Refcount for slab cache destroy */
64697 + atomic_t refcount; /* Refcount for slab cache destroy */
64698 void (*ctor)(void *);
64699 int inuse; /* Offset to metadata */
64700 int align; /* Alignment */
64701 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64702 * Sorry that the following has to be that ugly but some versions of GCC
64703 * have trouble with constant propagation and loops.
64704 */
64705 -static __always_inline int kmalloc_index(size_t size)
64706 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64707 {
64708 if (!size)
64709 return 0;
64710 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64711 }
64712
64713 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64714 -void *__kmalloc(size_t size, gfp_t flags);
64715 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64716
64717 static __always_inline void *
64718 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64719 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64720 }
64721 #endif
64722
64723 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64724 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64725 {
64726 unsigned int order = get_order(size);
64727 return kmalloc_order_trace(size, flags, order);
64728 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64729 }
64730
64731 #ifdef CONFIG_NUMA
64732 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64733 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64734 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64735
64736 #ifdef CONFIG_TRACING
64737 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64738 index de8832d..0147b46 100644
64739 --- a/include/linux/sonet.h
64740 +++ b/include/linux/sonet.h
64741 @@ -61,7 +61,7 @@ struct sonet_stats {
64742 #include <linux/atomic.h>
64743
64744 struct k_sonet_stats {
64745 -#define __HANDLE_ITEM(i) atomic_t i
64746 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64747 __SONET_ITEMS
64748 #undef __HANDLE_ITEM
64749 };
64750 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64751 index 523547e..2cb7140 100644
64752 --- a/include/linux/sunrpc/clnt.h
64753 +++ b/include/linux/sunrpc/clnt.h
64754 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64755 {
64756 switch (sap->sa_family) {
64757 case AF_INET:
64758 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64759 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64760 case AF_INET6:
64761 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64762 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64763 }
64764 return 0;
64765 }
64766 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64767 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64768 const struct sockaddr *src)
64769 {
64770 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64771 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64772 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64773
64774 dsin->sin_family = ssin->sin_family;
64775 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64776 if (sa->sa_family != AF_INET6)
64777 return 0;
64778
64779 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64780 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64781 }
64782
64783 #endif /* __KERNEL__ */
64784 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64785 index dc0c3cc..8503fb6 100644
64786 --- a/include/linux/sunrpc/sched.h
64787 +++ b/include/linux/sunrpc/sched.h
64788 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64789 void (*rpc_count_stats)(struct rpc_task *, void *);
64790 void (*rpc_release)(void *);
64791 };
64792 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64793
64794 struct rpc_task_setup {
64795 struct rpc_task *task;
64796 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64797 index 0b8e3e6..33e0a01 100644
64798 --- a/include/linux/sunrpc/svc_rdma.h
64799 +++ b/include/linux/sunrpc/svc_rdma.h
64800 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64801 extern unsigned int svcrdma_max_requests;
64802 extern unsigned int svcrdma_max_req_size;
64803
64804 -extern atomic_t rdma_stat_recv;
64805 -extern atomic_t rdma_stat_read;
64806 -extern atomic_t rdma_stat_write;
64807 -extern atomic_t rdma_stat_sq_starve;
64808 -extern atomic_t rdma_stat_rq_starve;
64809 -extern atomic_t rdma_stat_rq_poll;
64810 -extern atomic_t rdma_stat_rq_prod;
64811 -extern atomic_t rdma_stat_sq_poll;
64812 -extern atomic_t rdma_stat_sq_prod;
64813 +extern atomic_unchecked_t rdma_stat_recv;
64814 +extern atomic_unchecked_t rdma_stat_read;
64815 +extern atomic_unchecked_t rdma_stat_write;
64816 +extern atomic_unchecked_t rdma_stat_sq_starve;
64817 +extern atomic_unchecked_t rdma_stat_rq_starve;
64818 +extern atomic_unchecked_t rdma_stat_rq_poll;
64819 +extern atomic_unchecked_t rdma_stat_rq_prod;
64820 +extern atomic_unchecked_t rdma_stat_sq_poll;
64821 +extern atomic_unchecked_t rdma_stat_sq_prod;
64822
64823 #define RPCRDMA_VERSION 1
64824
64825 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64826 index c34b4c8..a65b67d 100644
64827 --- a/include/linux/sysctl.h
64828 +++ b/include/linux/sysctl.h
64829 @@ -155,7 +155,11 @@ enum
64830 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64831 };
64832
64833 -
64834 +#ifdef CONFIG_PAX_SOFTMODE
64835 +enum {
64836 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64837 +};
64838 +#endif
64839
64840 /* CTL_VM names: */
64841 enum
64842 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64843
64844 extern int proc_dostring(struct ctl_table *, int,
64845 void __user *, size_t *, loff_t *);
64846 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64847 + void __user *, size_t *, loff_t *);
64848 extern int proc_dointvec(struct ctl_table *, int,
64849 void __user *, size_t *, loff_t *);
64850 extern int proc_dointvec_minmax(struct ctl_table *, int,
64851 diff --git a/include/linux/tty.h b/include/linux/tty.h
64852 index 9f47ab5..73da944 100644
64853 --- a/include/linux/tty.h
64854 +++ b/include/linux/tty.h
64855 @@ -225,7 +225,7 @@ struct tty_port {
64856 const struct tty_port_operations *ops; /* Port operations */
64857 spinlock_t lock; /* Lock protecting tty field */
64858 int blocked_open; /* Waiting to open */
64859 - int count; /* Usage count */
64860 + atomic_t count; /* Usage count */
64861 wait_queue_head_t open_wait; /* Open waiters */
64862 wait_queue_head_t close_wait; /* Close waiters */
64863 wait_queue_head_t delta_msr_wait; /* Modem status change */
64864 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64865 struct tty_struct *tty, struct file *filp);
64866 static inline int tty_port_users(struct tty_port *port)
64867 {
64868 - return port->count + port->blocked_open;
64869 + return atomic_read(&port->count) + port->blocked_open;
64870 }
64871
64872 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64873 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64874 index fb79dd8d..07d4773 100644
64875 --- a/include/linux/tty_ldisc.h
64876 +++ b/include/linux/tty_ldisc.h
64877 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64878
64879 struct module *owner;
64880
64881 - int refcount;
64882 + atomic_t refcount;
64883 };
64884
64885 struct tty_ldisc {
64886 diff --git a/include/linux/types.h b/include/linux/types.h
64887 index bf0dd75..a1f23aaa 100644
64888 --- a/include/linux/types.h
64889 +++ b/include/linux/types.h
64890 @@ -220,10 +220,26 @@ typedef struct {
64891 int counter;
64892 } atomic_t;
64893
64894 +#ifdef CONFIG_PAX_REFCOUNT
64895 +typedef struct {
64896 + int counter;
64897 +} atomic_unchecked_t;
64898 +#else
64899 +typedef atomic_t atomic_unchecked_t;
64900 +#endif
64901 +
64902 #ifdef CONFIG_64BIT
64903 typedef struct {
64904 long counter;
64905 } atomic64_t;
64906 +
64907 +#ifdef CONFIG_PAX_REFCOUNT
64908 +typedef struct {
64909 + long counter;
64910 +} atomic64_unchecked_t;
64911 +#else
64912 +typedef atomic64_t atomic64_unchecked_t;
64913 +#endif
64914 #endif
64915
64916 struct list_head {
64917 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64918 index 5ca0951..ab496a5 100644
64919 --- a/include/linux/uaccess.h
64920 +++ b/include/linux/uaccess.h
64921 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64922 long ret; \
64923 mm_segment_t old_fs = get_fs(); \
64924 \
64925 - set_fs(KERNEL_DS); \
64926 pagefault_disable(); \
64927 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64928 - pagefault_enable(); \
64929 + set_fs(KERNEL_DS); \
64930 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64931 set_fs(old_fs); \
64932 + pagefault_enable(); \
64933 ret; \
64934 })
64935
64936 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64937 index 99c1b4d..bb94261 100644
64938 --- a/include/linux/unaligned/access_ok.h
64939 +++ b/include/linux/unaligned/access_ok.h
64940 @@ -6,32 +6,32 @@
64941
64942 static inline u16 get_unaligned_le16(const void *p)
64943 {
64944 - return le16_to_cpup((__le16 *)p);
64945 + return le16_to_cpup((const __le16 *)p);
64946 }
64947
64948 static inline u32 get_unaligned_le32(const void *p)
64949 {
64950 - return le32_to_cpup((__le32 *)p);
64951 + return le32_to_cpup((const __le32 *)p);
64952 }
64953
64954 static inline u64 get_unaligned_le64(const void *p)
64955 {
64956 - return le64_to_cpup((__le64 *)p);
64957 + return le64_to_cpup((const __le64 *)p);
64958 }
64959
64960 static inline u16 get_unaligned_be16(const void *p)
64961 {
64962 - return be16_to_cpup((__be16 *)p);
64963 + return be16_to_cpup((const __be16 *)p);
64964 }
64965
64966 static inline u32 get_unaligned_be32(const void *p)
64967 {
64968 - return be32_to_cpup((__be32 *)p);
64969 + return be32_to_cpup((const __be32 *)p);
64970 }
64971
64972 static inline u64 get_unaligned_be64(const void *p)
64973 {
64974 - return be64_to_cpup((__be64 *)p);
64975 + return be64_to_cpup((const __be64 *)p);
64976 }
64977
64978 static inline void put_unaligned_le16(u16 val, void *p)
64979 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64980 index c5d36c6..8478c90 100644
64981 --- a/include/linux/usb/renesas_usbhs.h
64982 +++ b/include/linux/usb/renesas_usbhs.h
64983 @@ -39,7 +39,7 @@ enum {
64984 */
64985 struct renesas_usbhs_driver_callback {
64986 int (*notify_hotplug)(struct platform_device *pdev);
64987 -};
64988 +} __no_const;
64989
64990 /*
64991 * callback functions for platform
64992 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64993 * VBUS control is needed for Host
64994 */
64995 int (*set_vbus)(struct platform_device *pdev, int enable);
64996 -};
64997 +} __no_const;
64998
64999 /*
65000 * parameters for renesas usbhs
65001 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
65002 index 6f8fbcf..8259001 100644
65003 --- a/include/linux/vermagic.h
65004 +++ b/include/linux/vermagic.h
65005 @@ -25,9 +25,35 @@
65006 #define MODULE_ARCH_VERMAGIC ""
65007 #endif
65008
65009 +#ifdef CONFIG_PAX_REFCOUNT
65010 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
65011 +#else
65012 +#define MODULE_PAX_REFCOUNT ""
65013 +#endif
65014 +
65015 +#ifdef CONSTIFY_PLUGIN
65016 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
65017 +#else
65018 +#define MODULE_CONSTIFY_PLUGIN ""
65019 +#endif
65020 +
65021 +#ifdef STACKLEAK_PLUGIN
65022 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
65023 +#else
65024 +#define MODULE_STACKLEAK_PLUGIN ""
65025 +#endif
65026 +
65027 +#ifdef CONFIG_GRKERNSEC
65028 +#define MODULE_GRSEC "GRSEC "
65029 +#else
65030 +#define MODULE_GRSEC ""
65031 +#endif
65032 +
65033 #define VERMAGIC_STRING \
65034 UTS_RELEASE " " \
65035 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
65036 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
65037 - MODULE_ARCH_VERMAGIC
65038 + MODULE_ARCH_VERMAGIC \
65039 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
65040 + MODULE_GRSEC
65041
65042 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65043 index 6071e91..ca6a489 100644
65044 --- a/include/linux/vmalloc.h
65045 +++ b/include/linux/vmalloc.h
65046 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65047 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65048 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65049 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65050 +
65051 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65052 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65053 +#endif
65054 +
65055 /* bits [20..32] reserved for arch specific ioremap internals */
65056
65057 /*
65058 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65059 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65060 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65061 unsigned long start, unsigned long end, gfp_t gfp_mask,
65062 - pgprot_t prot, int node, const void *caller);
65063 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
65064 extern void vfree(const void *addr);
65065
65066 extern void *vmap(struct page **pages, unsigned int count,
65067 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65068 extern void free_vm_area(struct vm_struct *area);
65069
65070 /* for /dev/kmem */
65071 -extern long vread(char *buf, char *addr, unsigned long count);
65072 -extern long vwrite(char *buf, char *addr, unsigned long count);
65073 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65074 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65075
65076 /*
65077 * Internals. Dont't use..
65078 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65079 index ad2cfd5..74c94ad 100644
65080 --- a/include/linux/vmstat.h
65081 +++ b/include/linux/vmstat.h
65082 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65083 /*
65084 * Zone based page accounting with per cpu differentials.
65085 */
65086 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65087 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65088
65089 static inline void zone_page_state_add(long x, struct zone *zone,
65090 enum zone_stat_item item)
65091 {
65092 - atomic_long_add(x, &zone->vm_stat[item]);
65093 - atomic_long_add(x, &vm_stat[item]);
65094 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65095 + atomic_long_add_unchecked(x, &vm_stat[item]);
65096 }
65097
65098 static inline unsigned long global_page_state(enum zone_stat_item item)
65099 {
65100 - long x = atomic_long_read(&vm_stat[item]);
65101 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65102 #ifdef CONFIG_SMP
65103 if (x < 0)
65104 x = 0;
65105 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65106 static inline unsigned long zone_page_state(struct zone *zone,
65107 enum zone_stat_item item)
65108 {
65109 - long x = atomic_long_read(&zone->vm_stat[item]);
65110 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65111 #ifdef CONFIG_SMP
65112 if (x < 0)
65113 x = 0;
65114 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65115 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65116 enum zone_stat_item item)
65117 {
65118 - long x = atomic_long_read(&zone->vm_stat[item]);
65119 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65120
65121 #ifdef CONFIG_SMP
65122 int cpu;
65123 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65124
65125 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65126 {
65127 - atomic_long_inc(&zone->vm_stat[item]);
65128 - atomic_long_inc(&vm_stat[item]);
65129 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65130 + atomic_long_inc_unchecked(&vm_stat[item]);
65131 }
65132
65133 static inline void __inc_zone_page_state(struct page *page,
65134 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
65135
65136 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65137 {
65138 - atomic_long_dec(&zone->vm_stat[item]);
65139 - atomic_long_dec(&vm_stat[item]);
65140 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65141 + atomic_long_dec_unchecked(&vm_stat[item]);
65142 }
65143
65144 static inline void __dec_zone_page_state(struct page *page,
65145 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65146 index e5d1220..ef6e406 100644
65147 --- a/include/linux/xattr.h
65148 +++ b/include/linux/xattr.h
65149 @@ -57,6 +57,11 @@
65150 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65151 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65152
65153 +/* User namespace */
65154 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65155 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65156 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65157 +
65158 #ifdef __KERNEL__
65159
65160 #include <linux/types.h>
65161 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65162 index 944ecdf..a3994fc 100644
65163 --- a/include/media/saa7146_vv.h
65164 +++ b/include/media/saa7146_vv.h
65165 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65166 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65167
65168 /* the extension can override this */
65169 - struct v4l2_ioctl_ops vid_ops;
65170 - struct v4l2_ioctl_ops vbi_ops;
65171 + v4l2_ioctl_ops_no_const vid_ops;
65172 + v4l2_ioctl_ops_no_const vbi_ops;
65173 /* pointer to the saa7146 core ops */
65174 const struct v4l2_ioctl_ops *core_ops;
65175
65176 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65177 index 5c416cd..20021aa 100644
65178 --- a/include/media/v4l2-dev.h
65179 +++ b/include/media/v4l2-dev.h
65180 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65181 int (*mmap) (struct file *, struct vm_area_struct *);
65182 int (*open) (struct file *);
65183 int (*release) (struct file *);
65184 -};
65185 +} __do_const;
65186 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65187
65188 /*
65189 * Newer version of video_device, handled by videodev2.c
65190 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65191 index e614c9c..20602b7 100644
65192 --- a/include/media/v4l2-ioctl.h
65193 +++ b/include/media/v4l2-ioctl.h
65194 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65195 long (*vidioc_default) (struct file *file, void *fh,
65196 bool valid_prio, int cmd, void *arg);
65197 };
65198 -
65199 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65200
65201 /* v4l debugging and diagnostics */
65202
65203 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65204 index bcb9cc3..f4ec722e 100644
65205 --- a/include/net/caif/caif_hsi.h
65206 +++ b/include/net/caif/caif_hsi.h
65207 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65208 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65209 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65210 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65211 -};
65212 +} __no_const;
65213
65214 /* Structure implemented by HSI device. */
65215 struct cfhsi_ops {
65216 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65217 index 9e5425b..8136ffc 100644
65218 --- a/include/net/caif/cfctrl.h
65219 +++ b/include/net/caif/cfctrl.h
65220 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65221 void (*radioset_rsp)(void);
65222 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65223 struct cflayer *client_layer);
65224 -};
65225 +} __no_const;
65226
65227 /* Link Setup Parameters for CAIF-Links. */
65228 struct cfctrl_link_param {
65229 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65230 struct cfctrl {
65231 struct cfsrvl serv;
65232 struct cfctrl_rsp res;
65233 - atomic_t req_seq_no;
65234 - atomic_t rsp_seq_no;
65235 + atomic_unchecked_t req_seq_no;
65236 + atomic_unchecked_t rsp_seq_no;
65237 struct list_head list;
65238 /* Protects from simultaneous access to first_req list */
65239 spinlock_t info_list_lock;
65240 diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
65241 index f10553c..fb5204b 100644
65242 --- a/include/net/cfg80211.h
65243 +++ b/include/net/cfg80211.h
65244 @@ -2633,6 +2633,15 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb);
65245 unsigned int __attribute_const__ ieee80211_hdrlen(__le16 fc);
65246
65247 /**
65248 + * ieee80211_get_mesh_hdrlen - get mesh extension header length
65249 + * @meshhdr: the mesh extension header, only the flags field
65250 + * (first byte) will be accessed
65251 + * Returns the length of the extension header, which is always at
65252 + * least 6 bytes and at most 18 if address 5 and 6 are present.
65253 + */
65254 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr);
65255 +
65256 +/**
65257 * DOC: Data path helpers
65258 *
65259 * In addition to generic utilities, cfg80211 also offers
65260 diff --git a/include/net/flow.h b/include/net/flow.h
65261 index 628e11b..4c475df 100644
65262 --- a/include/net/flow.h
65263 +++ b/include/net/flow.h
65264 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65265
65266 extern void flow_cache_flush(void);
65267 extern void flow_cache_flush_deferred(void);
65268 -extern atomic_t flow_cache_genid;
65269 +extern atomic_unchecked_t flow_cache_genid;
65270
65271 #endif
65272 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65273 index 53f464d..ba76aaa 100644
65274 --- a/include/net/inetpeer.h
65275 +++ b/include/net/inetpeer.h
65276 @@ -47,8 +47,8 @@ struct inet_peer {
65277 */
65278 union {
65279 struct {
65280 - atomic_t rid; /* Frag reception counter */
65281 - atomic_t ip_id_count; /* IP ID for the next packet */
65282 + atomic_unchecked_t rid; /* Frag reception counter */
65283 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65284 };
65285 struct rcu_head rcu;
65286 struct inet_peer *gc_next;
65287 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65288 more++;
65289 inet_peer_refcheck(p);
65290 do {
65291 - old = atomic_read(&p->ip_id_count);
65292 + old = atomic_read_unchecked(&p->ip_id_count);
65293 new = old + more;
65294 if (!new)
65295 new = 1;
65296 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65297 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65298 return new;
65299 }
65300
65301 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65302 index 9497be1..5a4fafe 100644
65303 --- a/include/net/ip_fib.h
65304 +++ b/include/net/ip_fib.h
65305 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65306
65307 #define FIB_RES_SADDR(net, res) \
65308 ((FIB_RES_NH(res).nh_saddr_genid == \
65309 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65310 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65311 FIB_RES_NH(res).nh_saddr : \
65312 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65313 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65314 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65315 index 95374d1..2300e36 100644
65316 --- a/include/net/ip_vs.h
65317 +++ b/include/net/ip_vs.h
65318 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65319 struct ip_vs_conn *control; /* Master control connection */
65320 atomic_t n_control; /* Number of controlled ones */
65321 struct ip_vs_dest *dest; /* real server */
65322 - atomic_t in_pkts; /* incoming packet counter */
65323 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65324
65325 /* packet transmitter for different forwarding methods. If it
65326 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65327 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65328 __be16 port; /* port number of the server */
65329 union nf_inet_addr addr; /* IP address of the server */
65330 volatile unsigned int flags; /* dest status flags */
65331 - atomic_t conn_flags; /* flags to copy to conn */
65332 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65333 atomic_t weight; /* server weight */
65334
65335 atomic_t refcnt; /* reference counter */
65336 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65337 index 69b610a..fe3962c 100644
65338 --- a/include/net/irda/ircomm_core.h
65339 +++ b/include/net/irda/ircomm_core.h
65340 @@ -51,7 +51,7 @@ typedef struct {
65341 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65342 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65343 struct ircomm_info *);
65344 -} call_t;
65345 +} __no_const call_t;
65346
65347 struct ircomm_cb {
65348 irda_queue_t queue;
65349 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65350 index 59ba38bc..d515662 100644
65351 --- a/include/net/irda/ircomm_tty.h
65352 +++ b/include/net/irda/ircomm_tty.h
65353 @@ -35,6 +35,7 @@
65354 #include <linux/termios.h>
65355 #include <linux/timer.h>
65356 #include <linux/tty.h> /* struct tty_struct */
65357 +#include <asm/local.h>
65358
65359 #include <net/irda/irias_object.h>
65360 #include <net/irda/ircomm_core.h>
65361 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65362 unsigned short close_delay;
65363 unsigned short closing_wait; /* time to wait before closing */
65364
65365 - int open_count;
65366 - int blocked_open; /* # of blocked opens */
65367 + local_t open_count;
65368 + local_t blocked_open; /* # of blocked opens */
65369
65370 /* Protect concurent access to :
65371 * o self->open_count
65372 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65373 index cc7c197..9f2da2a 100644
65374 --- a/include/net/iucv/af_iucv.h
65375 +++ b/include/net/iucv/af_iucv.h
65376 @@ -141,7 +141,7 @@ struct iucv_sock {
65377 struct iucv_sock_list {
65378 struct hlist_head head;
65379 rwlock_t lock;
65380 - atomic_t autobind_name;
65381 + atomic_unchecked_t autobind_name;
65382 };
65383
65384 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65385 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65386 index 344d898..2ae1302 100644
65387 --- a/include/net/neighbour.h
65388 +++ b/include/net/neighbour.h
65389 @@ -123,7 +123,7 @@ struct neigh_ops {
65390 void (*error_report)(struct neighbour *, struct sk_buff *);
65391 int (*output)(struct neighbour *, struct sk_buff *);
65392 int (*connected_output)(struct neighbour *, struct sk_buff *);
65393 -};
65394 +} __do_const;
65395
65396 struct pneigh_entry {
65397 struct pneigh_entry *next;
65398 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65399 index fd87963..312a11f 100644
65400 --- a/include/net/net_namespace.h
65401 +++ b/include/net/net_namespace.h
65402 @@ -102,7 +102,7 @@ struct net {
65403 #endif
65404 struct netns_ipvs *ipvs;
65405 struct sock *diag_nlsk;
65406 - atomic_t rt_genid;
65407 + atomic_unchecked_t rt_genid;
65408 };
65409
65410
65411 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65412
65413 static inline int rt_genid(struct net *net)
65414 {
65415 - return atomic_read(&net->rt_genid);
65416 + return atomic_read_unchecked(&net->rt_genid);
65417 }
65418
65419 static inline void rt_genid_bump(struct net *net)
65420 {
65421 - atomic_inc(&net->rt_genid);
65422 + atomic_inc_unchecked(&net->rt_genid);
65423 }
65424
65425 #endif /* __NET_NET_NAMESPACE_H */
65426 diff --git a/include/net/netdma.h b/include/net/netdma.h
65427 index 8ba8ce2..99b7fff 100644
65428 --- a/include/net/netdma.h
65429 +++ b/include/net/netdma.h
65430 @@ -24,7 +24,7 @@
65431 #include <linux/dmaengine.h>
65432 #include <linux/skbuff.h>
65433
65434 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65435 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65436 struct sk_buff *skb, int offset, struct iovec *to,
65437 size_t len, struct dma_pinned_list *pinned_list);
65438
65439 diff --git a/include/net/netlink.h b/include/net/netlink.h
65440 index 785f37a..c81dc0c 100644
65441 --- a/include/net/netlink.h
65442 +++ b/include/net/netlink.h
65443 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65444 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65445 {
65446 if (mark)
65447 - skb_trim(skb, (unsigned char *) mark - skb->data);
65448 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65449 }
65450
65451 /**
65452 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65453 index eb24dbc..567d6ed 100644
65454 --- a/include/net/netns/ipv4.h
65455 +++ b/include/net/netns/ipv4.h
65456 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65457 unsigned int sysctl_ping_group_range[2];
65458 long sysctl_tcp_mem[3];
65459
65460 - atomic_t dev_addr_genid;
65461 + atomic_unchecked_t dev_addr_genid;
65462
65463 #ifdef CONFIG_IP_MROUTE
65464 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65465 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65466 index ff49964..1411fee 100644
65467 --- a/include/net/sctp/sctp.h
65468 +++ b/include/net/sctp/sctp.h
65469 @@ -320,9 +320,9 @@ do { \
65470
65471 #else /* SCTP_DEBUG */
65472
65473 -#define SCTP_DEBUG_PRINTK(whatever...)
65474 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65475 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65476 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65477 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65478 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65479 #define SCTP_ENABLE_DEBUG
65480 #define SCTP_DISABLE_DEBUG
65481 #define SCTP_ASSERT(expr, str, func)
65482 diff --git a/include/net/sock.h b/include/net/sock.h
65483 index adb7da2..1100002 100644
65484 --- a/include/net/sock.h
65485 +++ b/include/net/sock.h
65486 @@ -305,7 +305,7 @@ struct sock {
65487 #ifdef CONFIG_RPS
65488 __u32 sk_rxhash;
65489 #endif
65490 - atomic_t sk_drops;
65491 + atomic_unchecked_t sk_drops;
65492 int sk_rcvbuf;
65493
65494 struct sk_filter __rcu *sk_filter;
65495 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65496 }
65497
65498 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65499 - char __user *from, char *to,
65500 + char __user *from, unsigned char *to,
65501 int copy, int offset)
65502 {
65503 if (skb->ip_summed == CHECKSUM_NONE) {
65504 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65505 }
65506 }
65507
65508 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65509 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65510
65511 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65512 {
65513 diff --git a/include/net/tcp.h b/include/net/tcp.h
65514 index 1f000ff..e5a8dfb 100644
65515 --- a/include/net/tcp.h
65516 +++ b/include/net/tcp.h
65517 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65518 extern void tcp_xmit_retransmit_queue(struct sock *);
65519 extern void tcp_simple_retransmit(struct sock *);
65520 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65521 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65522 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65523
65524 extern void tcp_send_probe0(struct sock *);
65525 extern void tcp_send_partial(struct sock *);
65526 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65527 struct inet6_skb_parm h6;
65528 #endif
65529 } header; /* For incoming frames */
65530 - __u32 seq; /* Starting sequence number */
65531 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65532 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65533 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65534 __u32 when; /* used to compute rtt's */
65535 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65536
65537 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65538
65539 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65540 /* 1 byte hole */
65541 - __u32 ack_seq; /* Sequence number ACK'd */
65542 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65543 };
65544
65545 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65546 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65547 char *name;
65548 sa_family_t family;
65549 const struct file_operations *seq_fops;
65550 - struct seq_operations seq_ops;
65551 + seq_operations_no_const seq_ops;
65552 };
65553
65554 struct tcp_iter_state {
65555 diff --git a/include/net/udp.h b/include/net/udp.h
65556 index 065f379..b661b40 100644
65557 --- a/include/net/udp.h
65558 +++ b/include/net/udp.h
65559 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65560 sa_family_t family;
65561 struct udp_table *udp_table;
65562 const struct file_operations *seq_fops;
65563 - struct seq_operations seq_ops;
65564 + seq_operations_no_const seq_ops;
65565 };
65566
65567 struct udp_iter_state {
65568 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65569 index 639dd13..15b206c 100644
65570 --- a/include/net/xfrm.h
65571 +++ b/include/net/xfrm.h
65572 @@ -514,7 +514,7 @@ struct xfrm_policy {
65573 struct timer_list timer;
65574
65575 struct flow_cache_object flo;
65576 - atomic_t genid;
65577 + atomic_unchecked_t genid;
65578 u32 priority;
65579 u32 index;
65580 struct xfrm_mark mark;
65581 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65582 index 1a046b1..ee0bef0 100644
65583 --- a/include/rdma/iw_cm.h
65584 +++ b/include/rdma/iw_cm.h
65585 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65586 int backlog);
65587
65588 int (*destroy_listen)(struct iw_cm_id *cm_id);
65589 -};
65590 +} __no_const;
65591
65592 /**
65593 * iw_create_cm_id - Create an IW CM identifier.
65594 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65595 index 399162b..b337f1a 100644
65596 --- a/include/scsi/libfc.h
65597 +++ b/include/scsi/libfc.h
65598 @@ -762,6 +762,7 @@ struct libfc_function_template {
65599 */
65600 void (*disc_stop_final) (struct fc_lport *);
65601 };
65602 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65603
65604 /**
65605 * struct fc_disc - Discovery context
65606 @@ -866,7 +867,7 @@ struct fc_lport {
65607 struct fc_vport *vport;
65608
65609 /* Operational Information */
65610 - struct libfc_function_template tt;
65611 + libfc_function_template_no_const tt;
65612 u8 link_up;
65613 u8 qfull;
65614 enum fc_lport_state state;
65615 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65616 index 9895f69..f1418f0 100644
65617 --- a/include/scsi/scsi_device.h
65618 +++ b/include/scsi/scsi_device.h
65619 @@ -166,9 +166,9 @@ struct scsi_device {
65620 unsigned int max_device_blocked; /* what device_blocked counts down from */
65621 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65622
65623 - atomic_t iorequest_cnt;
65624 - atomic_t iodone_cnt;
65625 - atomic_t ioerr_cnt;
65626 + atomic_unchecked_t iorequest_cnt;
65627 + atomic_unchecked_t iodone_cnt;
65628 + atomic_unchecked_t ioerr_cnt;
65629
65630 struct device sdev_gendev,
65631 sdev_dev;
65632 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65633 index b797e8f..8e2c3aa 100644
65634 --- a/include/scsi/scsi_transport_fc.h
65635 +++ b/include/scsi/scsi_transport_fc.h
65636 @@ -751,7 +751,8 @@ struct fc_function_template {
65637 unsigned long show_host_system_hostname:1;
65638
65639 unsigned long disable_target_scan:1;
65640 -};
65641 +} __do_const;
65642 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65643
65644
65645 /**
65646 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65647 index 030b87c..98a6954 100644
65648 --- a/include/sound/ak4xxx-adda.h
65649 +++ b/include/sound/ak4xxx-adda.h
65650 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65651 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65652 unsigned char val);
65653 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65654 -};
65655 +} __no_const;
65656
65657 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65658
65659 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65660 index 8c05e47..2b5df97 100644
65661 --- a/include/sound/hwdep.h
65662 +++ b/include/sound/hwdep.h
65663 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65664 struct snd_hwdep_dsp_status *status);
65665 int (*dsp_load)(struct snd_hwdep *hw,
65666 struct snd_hwdep_dsp_image *image);
65667 -};
65668 +} __no_const;
65669
65670 struct snd_hwdep {
65671 struct snd_card *card;
65672 diff --git a/include/sound/info.h b/include/sound/info.h
65673 index 9ca1a49..aba1728 100644
65674 --- a/include/sound/info.h
65675 +++ b/include/sound/info.h
65676 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65677 struct snd_info_buffer *buffer);
65678 void (*write)(struct snd_info_entry *entry,
65679 struct snd_info_buffer *buffer);
65680 -};
65681 +} __no_const;
65682
65683 struct snd_info_entry_ops {
65684 int (*open)(struct snd_info_entry *entry,
65685 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65686 index cdca2ab..10bbe05 100644
65687 --- a/include/sound/pcm.h
65688 +++ b/include/sound/pcm.h
65689 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65690 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65691 int (*ack)(struct snd_pcm_substream *substream);
65692 };
65693 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65694
65695 /*
65696 *
65697 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65698 index af1b49e..a5d55a5 100644
65699 --- a/include/sound/sb16_csp.h
65700 +++ b/include/sound/sb16_csp.h
65701 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65702 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65703 int (*csp_stop) (struct snd_sb_csp * p);
65704 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65705 -};
65706 +} __no_const;
65707
65708 /*
65709 * CSP private data
65710 diff --git a/include/sound/soc.h b/include/sound/soc.h
65711 index e063380..e8077d5 100644
65712 --- a/include/sound/soc.h
65713 +++ b/include/sound/soc.h
65714 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65715 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65716 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65717 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65718 -};
65719 +} __do_const;
65720
65721 struct snd_soc_platform {
65722 const char *name;
65723 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65724 struct snd_soc_dai_link *dai_link;
65725 struct mutex pcm_mutex;
65726 enum snd_soc_pcm_subclass pcm_subclass;
65727 - struct snd_pcm_ops ops;
65728 + snd_pcm_ops_no_const ops;
65729
65730 unsigned int dev_registered:1;
65731
65732 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65733 index fe8590c..aaed363 100644
65734 --- a/include/sound/tea575x-tuner.h
65735 +++ b/include/sound/tea575x-tuner.h
65736 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65737
65738 struct snd_tea575x {
65739 struct v4l2_device *v4l2_dev;
65740 - struct v4l2_file_operations fops;
65741 + v4l2_file_operations_no_const fops;
65742 struct video_device vd; /* video device */
65743 int radio_nr; /* radio_nr */
65744 bool tea5759; /* 5759 chip is present */
65745 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65746 index 5be8937..a8e46e9 100644
65747 --- a/include/target/target_core_base.h
65748 +++ b/include/target/target_core_base.h
65749 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65750 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65751 int (*t10_pr_register)(struct se_cmd *);
65752 int (*t10_pr_clear)(struct se_cmd *);
65753 -};
65754 +} __no_const;
65755
65756 struct t10_reservation {
65757 /* Reservation effects all target ports */
65758 @@ -758,7 +758,7 @@ struct se_device {
65759 spinlock_t stats_lock;
65760 /* Active commands on this virtual SE device */
65761 atomic_t simple_cmds;
65762 - atomic_t dev_ordered_id;
65763 + atomic_unchecked_t dev_ordered_id;
65764 atomic_t dev_ordered_sync;
65765 atomic_t dev_qf_count;
65766 struct se_obj dev_obj;
65767 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65768 new file mode 100644
65769 index 0000000..2efe49d
65770 --- /dev/null
65771 +++ b/include/trace/events/fs.h
65772 @@ -0,0 +1,53 @@
65773 +#undef TRACE_SYSTEM
65774 +#define TRACE_SYSTEM fs
65775 +
65776 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65777 +#define _TRACE_FS_H
65778 +
65779 +#include <linux/fs.h>
65780 +#include <linux/tracepoint.h>
65781 +
65782 +TRACE_EVENT(do_sys_open,
65783 +
65784 + TP_PROTO(char *filename, int flags, int mode),
65785 +
65786 + TP_ARGS(filename, flags, mode),
65787 +
65788 + TP_STRUCT__entry(
65789 + __string( filename, filename )
65790 + __field( int, flags )
65791 + __field( int, mode )
65792 + ),
65793 +
65794 + TP_fast_assign(
65795 + __assign_str(filename, filename);
65796 + __entry->flags = flags;
65797 + __entry->mode = mode;
65798 + ),
65799 +
65800 + TP_printk("\"%s\" %x %o",
65801 + __get_str(filename), __entry->flags, __entry->mode)
65802 +);
65803 +
65804 +TRACE_EVENT(open_exec,
65805 +
65806 + TP_PROTO(const char *filename),
65807 +
65808 + TP_ARGS(filename),
65809 +
65810 + TP_STRUCT__entry(
65811 + __string( filename, filename )
65812 + ),
65813 +
65814 + TP_fast_assign(
65815 + __assign_str(filename, filename);
65816 + ),
65817 +
65818 + TP_printk("\"%s\"",
65819 + __get_str(filename))
65820 +);
65821 +
65822 +#endif /* _TRACE_FS_H */
65823 +
65824 +/* This part must be outside protection */
65825 +#include <trace/define_trace.h>
65826 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65827 index 1c09820..7f5ec79 100644
65828 --- a/include/trace/events/irq.h
65829 +++ b/include/trace/events/irq.h
65830 @@ -36,7 +36,7 @@ struct softirq_action;
65831 */
65832 TRACE_EVENT(irq_handler_entry,
65833
65834 - TP_PROTO(int irq, struct irqaction *action),
65835 + TP_PROTO(int irq, const struct irqaction *action),
65836
65837 TP_ARGS(irq, action),
65838
65839 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65840 */
65841 TRACE_EVENT(irq_handler_exit,
65842
65843 - TP_PROTO(int irq, struct irqaction *action, int ret),
65844 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65845
65846 TP_ARGS(irq, action, ret),
65847
65848 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65849 index f9466fa..f4e2b81 100644
65850 --- a/include/video/udlfb.h
65851 +++ b/include/video/udlfb.h
65852 @@ -53,10 +53,10 @@ struct dlfb_data {
65853 u32 pseudo_palette[256];
65854 int blank_mode; /*one of FB_BLANK_ */
65855 /* blit-only rendering path metrics, exposed through sysfs */
65856 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65857 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65858 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65859 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65860 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65861 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65862 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65863 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65864 };
65865
65866 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65867 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65868 index 0993a22..32ba2fe 100644
65869 --- a/include/video/uvesafb.h
65870 +++ b/include/video/uvesafb.h
65871 @@ -177,6 +177,7 @@ struct uvesafb_par {
65872 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65873 u8 pmi_setpal; /* PMI for palette changes */
65874 u16 *pmi_base; /* protected mode interface location */
65875 + u8 *pmi_code; /* protected mode code location */
65876 void *pmi_start;
65877 void *pmi_pal;
65878 u8 *vbe_state_orig; /*
65879 diff --git a/init/Kconfig b/init/Kconfig
65880 index af6c7f8..5c188f8 100644
65881 --- a/init/Kconfig
65882 +++ b/init/Kconfig
65883 @@ -850,6 +850,7 @@ endif # CGROUPS
65884
65885 config CHECKPOINT_RESTORE
65886 bool "Checkpoint/restore support" if EXPERT
65887 + depends on !GRKERNSEC
65888 default n
65889 help
65890 Enables additional kernel features in a sake of checkpoint/restore.
65891 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65892 # Security modules
65893 depends on SECURITY_TOMOYO = n
65894 depends on SECURITY_APPARMOR = n
65895 + depends on GRKERNSEC = n
65896
65897 config UIDGID_STRICT_TYPE_CHECKS
65898 bool "Require conversions between uid/gids and their internal representation"
65899 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65900
65901 config COMPAT_BRK
65902 bool "Disable heap randomization"
65903 - default y
65904 + default n
65905 help
65906 Randomizing heap placement makes heap exploits harder, but it
65907 also breaks ancient binaries (including anything libc5 based).
65908 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65909 config STOP_MACHINE
65910 bool
65911 default y
65912 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65913 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65914 help
65915 Need stop_machine() primitive.
65916
65917 diff --git a/init/Makefile b/init/Makefile
65918 index 7bc47ee..6da2dc7 100644
65919 --- a/init/Makefile
65920 +++ b/init/Makefile
65921 @@ -2,6 +2,9 @@
65922 # Makefile for the linux kernel.
65923 #
65924
65925 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65926 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65927 +
65928 obj-y := main.o version.o mounts.o
65929 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65930 obj-y += noinitramfs.o
65931 diff --git a/init/do_mounts.c b/init/do_mounts.c
65932 index d3f0aee..c9322f5 100644
65933 --- a/init/do_mounts.c
65934 +++ b/init/do_mounts.c
65935 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65936 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65937 {
65938 struct super_block *s;
65939 - int err = sys_mount(name, "/root", fs, flags, data);
65940 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65941 if (err)
65942 return err;
65943
65944 - sys_chdir("/root");
65945 + sys_chdir((const char __force_user *)"/root");
65946 s = current->fs->pwd.dentry->d_sb;
65947 ROOT_DEV = s->s_dev;
65948 printk(KERN_INFO
65949 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65950 va_start(args, fmt);
65951 vsprintf(buf, fmt, args);
65952 va_end(args);
65953 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65954 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65955 if (fd >= 0) {
65956 sys_ioctl(fd, FDEJECT, 0);
65957 sys_close(fd);
65958 }
65959 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65960 - fd = sys_open("/dev/console", O_RDWR, 0);
65961 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65962 if (fd >= 0) {
65963 sys_ioctl(fd, TCGETS, (long)&termios);
65964 termios.c_lflag &= ~ICANON;
65965 sys_ioctl(fd, TCSETSF, (long)&termios);
65966 - sys_read(fd, &c, 1);
65967 + sys_read(fd, (char __user *)&c, 1);
65968 termios.c_lflag |= ICANON;
65969 sys_ioctl(fd, TCSETSF, (long)&termios);
65970 sys_close(fd);
65971 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65972 mount_root();
65973 out:
65974 devtmpfs_mount("dev");
65975 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65976 - sys_chroot(".");
65977 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65978 + sys_chroot((const char __force_user *)".");
65979 }
65980 diff --git a/init/do_mounts.h b/init/do_mounts.h
65981 index f5b978a..69dbfe8 100644
65982 --- a/init/do_mounts.h
65983 +++ b/init/do_mounts.h
65984 @@ -15,15 +15,15 @@ extern int root_mountflags;
65985
65986 static inline int create_dev(char *name, dev_t dev)
65987 {
65988 - sys_unlink(name);
65989 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65990 + sys_unlink((char __force_user *)name);
65991 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65992 }
65993
65994 #if BITS_PER_LONG == 32
65995 static inline u32 bstat(char *name)
65996 {
65997 struct stat64 stat;
65998 - if (sys_stat64(name, &stat) != 0)
65999 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
66000 return 0;
66001 if (!S_ISBLK(stat.st_mode))
66002 return 0;
66003 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
66004 static inline u32 bstat(char *name)
66005 {
66006 struct stat stat;
66007 - if (sys_newstat(name, &stat) != 0)
66008 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
66009 return 0;
66010 if (!S_ISBLK(stat.st_mode))
66011 return 0;
66012 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
66013 index 135959a2..28a3f43 100644
66014 --- a/init/do_mounts_initrd.c
66015 +++ b/init/do_mounts_initrd.c
66016 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
66017 create_dev("/dev/root.old", Root_RAM0);
66018 /* mount initrd on rootfs' /root */
66019 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
66020 - sys_mkdir("/old", 0700);
66021 - root_fd = sys_open("/", 0, 0);
66022 - old_fd = sys_open("/old", 0, 0);
66023 + sys_mkdir((const char __force_user *)"/old", 0700);
66024 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
66025 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
66026 /* move initrd over / and chdir/chroot in initrd root */
66027 - sys_chdir("/root");
66028 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
66029 - sys_chroot(".");
66030 + sys_chdir((const char __force_user *)"/root");
66031 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
66032 + sys_chroot((const char __force_user *)".");
66033
66034 /*
66035 * In case that a resume from disk is carried out by linuxrc or one of
66036 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
66037
66038 /* move initrd to rootfs' /old */
66039 sys_fchdir(old_fd);
66040 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
66041 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
66042 /* switch root and cwd back to / of rootfs */
66043 sys_fchdir(root_fd);
66044 - sys_chroot(".");
66045 + sys_chroot((const char __force_user *)".");
66046 sys_close(old_fd);
66047 sys_close(root_fd);
66048
66049 if (new_decode_dev(real_root_dev) == Root_RAM0) {
66050 - sys_chdir("/old");
66051 + sys_chdir((const char __force_user *)"/old");
66052 return;
66053 }
66054
66055 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
66056 mount_root();
66057
66058 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
66059 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
66060 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66061 if (!error)
66062 printk("okay\n");
66063 else {
66064 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66065 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66066 if (error == -ENOENT)
66067 printk("/initrd does not exist. Ignored.\n");
66068 else
66069 printk("failed\n");
66070 printk(KERN_NOTICE "Unmounting old root\n");
66071 - sys_umount("/old", MNT_DETACH);
66072 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66073 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66074 if (fd < 0) {
66075 error = fd;
66076 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66077 * mounted in the normal path.
66078 */
66079 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66080 - sys_unlink("/initrd.image");
66081 + sys_unlink((const char __force_user *)"/initrd.image");
66082 handle_initrd();
66083 return 1;
66084 }
66085 }
66086 - sys_unlink("/initrd.image");
66087 + sys_unlink((const char __force_user *)"/initrd.image");
66088 return 0;
66089 }
66090 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66091 index 8cb6db5..d729f50 100644
66092 --- a/init/do_mounts_md.c
66093 +++ b/init/do_mounts_md.c
66094 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66095 partitioned ? "_d" : "", minor,
66096 md_setup_args[ent].device_names);
66097
66098 - fd = sys_open(name, 0, 0);
66099 + fd = sys_open((char __force_user *)name, 0, 0);
66100 if (fd < 0) {
66101 printk(KERN_ERR "md: open failed - cannot start "
66102 "array %s\n", name);
66103 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66104 * array without it
66105 */
66106 sys_close(fd);
66107 - fd = sys_open(name, 0, 0);
66108 + fd = sys_open((char __force_user *)name, 0, 0);
66109 sys_ioctl(fd, BLKRRPART, 0);
66110 }
66111 sys_close(fd);
66112 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66113
66114 wait_for_device_probe();
66115
66116 - fd = sys_open("/dev/md0", 0, 0);
66117 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66118 if (fd >= 0) {
66119 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66120 sys_close(fd);
66121 diff --git a/init/init_task.c b/init/init_task.c
66122 index 8b2f399..f0797c9 100644
66123 --- a/init/init_task.c
66124 +++ b/init/init_task.c
66125 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66126 * Initial thread structure. Alignment of this is handled by a special
66127 * linker map entry.
66128 */
66129 +#ifdef CONFIG_X86
66130 +union thread_union init_thread_union __init_task_data;
66131 +#else
66132 union thread_union init_thread_union __init_task_data =
66133 { INIT_THREAD_INFO(init_task) };
66134 +#endif
66135 diff --git a/init/initramfs.c b/init/initramfs.c
66136 index 84c6bf1..8899338 100644
66137 --- a/init/initramfs.c
66138 +++ b/init/initramfs.c
66139 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66140 }
66141 }
66142
66143 -static long __init do_utime(char *filename, time_t mtime)
66144 +static long __init do_utime(char __force_user *filename, time_t mtime)
66145 {
66146 struct timespec t[2];
66147
66148 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66149 struct dir_entry *de, *tmp;
66150 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66151 list_del(&de->list);
66152 - do_utime(de->name, de->mtime);
66153 + do_utime((char __force_user *)de->name, de->mtime);
66154 kfree(de->name);
66155 kfree(de);
66156 }
66157 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66158 if (nlink >= 2) {
66159 char *old = find_link(major, minor, ino, mode, collected);
66160 if (old)
66161 - return (sys_link(old, collected) < 0) ? -1 : 1;
66162 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66163 }
66164 return 0;
66165 }
66166 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66167 {
66168 struct stat st;
66169
66170 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66171 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66172 if (S_ISDIR(st.st_mode))
66173 - sys_rmdir(path);
66174 + sys_rmdir((char __force_user *)path);
66175 else
66176 - sys_unlink(path);
66177 + sys_unlink((char __force_user *)path);
66178 }
66179 }
66180
66181 @@ -315,7 +315,7 @@ static int __init do_name(void)
66182 int openflags = O_WRONLY|O_CREAT;
66183 if (ml != 1)
66184 openflags |= O_TRUNC;
66185 - wfd = sys_open(collected, openflags, mode);
66186 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66187
66188 if (wfd >= 0) {
66189 sys_fchown(wfd, uid, gid);
66190 @@ -327,17 +327,17 @@ static int __init do_name(void)
66191 }
66192 }
66193 } else if (S_ISDIR(mode)) {
66194 - sys_mkdir(collected, mode);
66195 - sys_chown(collected, uid, gid);
66196 - sys_chmod(collected, mode);
66197 + sys_mkdir((char __force_user *)collected, mode);
66198 + sys_chown((char __force_user *)collected, uid, gid);
66199 + sys_chmod((char __force_user *)collected, mode);
66200 dir_add(collected, mtime);
66201 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66202 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66203 if (maybe_link() == 0) {
66204 - sys_mknod(collected, mode, rdev);
66205 - sys_chown(collected, uid, gid);
66206 - sys_chmod(collected, mode);
66207 - do_utime(collected, mtime);
66208 + sys_mknod((char __force_user *)collected, mode, rdev);
66209 + sys_chown((char __force_user *)collected, uid, gid);
66210 + sys_chmod((char __force_user *)collected, mode);
66211 + do_utime((char __force_user *)collected, mtime);
66212 }
66213 }
66214 return 0;
66215 @@ -346,15 +346,15 @@ static int __init do_name(void)
66216 static int __init do_copy(void)
66217 {
66218 if (count >= body_len) {
66219 - sys_write(wfd, victim, body_len);
66220 + sys_write(wfd, (char __force_user *)victim, body_len);
66221 sys_close(wfd);
66222 - do_utime(vcollected, mtime);
66223 + do_utime((char __force_user *)vcollected, mtime);
66224 kfree(vcollected);
66225 eat(body_len);
66226 state = SkipIt;
66227 return 0;
66228 } else {
66229 - sys_write(wfd, victim, count);
66230 + sys_write(wfd, (char __force_user *)victim, count);
66231 body_len -= count;
66232 eat(count);
66233 return 1;
66234 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66235 {
66236 collected[N_ALIGN(name_len) + body_len] = '\0';
66237 clean_path(collected, 0);
66238 - sys_symlink(collected + N_ALIGN(name_len), collected);
66239 - sys_lchown(collected, uid, gid);
66240 - do_utime(collected, mtime);
66241 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66242 + sys_lchown((char __force_user *)collected, uid, gid);
66243 + do_utime((char __force_user *)collected, mtime);
66244 state = SkipIt;
66245 next_state = Reset;
66246 return 0;
66247 diff --git a/init/main.c b/init/main.c
66248 index d61ec54..bd3144f 100644
66249 --- a/init/main.c
66250 +++ b/init/main.c
66251 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66252 extern void tc_init(void);
66253 #endif
66254
66255 +extern void grsecurity_init(void);
66256 +
66257 /*
66258 * Debug helper: via this flag we know that we are in 'early bootup code'
66259 * where only the boot processor is running with IRQ disabled. This means
66260 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66261
66262 __setup("reset_devices", set_reset_devices);
66263
66264 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66265 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66266 +static int __init setup_grsec_proc_gid(char *str)
66267 +{
66268 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66269 + return 1;
66270 +}
66271 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66272 +#endif
66273 +
66274 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66275 +extern char pax_enter_kernel_user[];
66276 +extern char pax_exit_kernel_user[];
66277 +extern pgdval_t clone_pgd_mask;
66278 +#endif
66279 +
66280 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66281 +static int __init setup_pax_nouderef(char *str)
66282 +{
66283 +#ifdef CONFIG_X86_32
66284 + unsigned int cpu;
66285 + struct desc_struct *gdt;
66286 +
66287 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66288 + gdt = get_cpu_gdt_table(cpu);
66289 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66290 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66291 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66292 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66293 + }
66294 + loadsegment(ds, __KERNEL_DS);
66295 + loadsegment(es, __KERNEL_DS);
66296 + loadsegment(ss, __KERNEL_DS);
66297 +#else
66298 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66299 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66300 + clone_pgd_mask = ~(pgdval_t)0UL;
66301 +#endif
66302 +
66303 + return 0;
66304 +}
66305 +early_param("pax_nouderef", setup_pax_nouderef);
66306 +#endif
66307 +
66308 +#ifdef CONFIG_PAX_SOFTMODE
66309 +int pax_softmode;
66310 +
66311 +static int __init setup_pax_softmode(char *str)
66312 +{
66313 + get_option(&str, &pax_softmode);
66314 + return 1;
66315 +}
66316 +__setup("pax_softmode=", setup_pax_softmode);
66317 +#endif
66318 +
66319 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66320 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66321 static const char *panic_later, *panic_param;
66322 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66323 {
66324 int count = preempt_count();
66325 int ret;
66326 + const char *msg1 = "", *msg2 = "";
66327
66328 if (initcall_debug)
66329 ret = do_one_initcall_debug(fn);
66330 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66331 sprintf(msgbuf, "error code %d ", ret);
66332
66333 if (preempt_count() != count) {
66334 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66335 + msg1 = " preemption imbalance";
66336 preempt_count() = count;
66337 }
66338 if (irqs_disabled()) {
66339 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66340 + msg2 = " disabled interrupts";
66341 local_irq_enable();
66342 }
66343 - if (msgbuf[0]) {
66344 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66345 + if (msgbuf[0] || *msg1 || *msg2) {
66346 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66347 }
66348
66349 return ret;
66350 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66351 level, level,
66352 &repair_env_string);
66353
66354 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66355 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66356 do_one_initcall(*fn);
66357 +
66358 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66359 + transfer_latent_entropy();
66360 +#endif
66361 +
66362 + }
66363 }
66364
66365 static void __init do_initcalls(void)
66366 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66367 {
66368 initcall_t *fn;
66369
66370 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66371 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66372 do_one_initcall(*fn);
66373 +
66374 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66375 + transfer_latent_entropy();
66376 +#endif
66377 +
66378 + }
66379 }
66380
66381 static void run_init_process(const char *init_filename)
66382 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66383 do_basic_setup();
66384
66385 /* Open the /dev/console on the rootfs, this should never fail */
66386 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66387 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66388 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66389
66390 (void) sys_dup(0);
66391 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66392 if (!ramdisk_execute_command)
66393 ramdisk_execute_command = "/init";
66394
66395 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66396 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66397 ramdisk_execute_command = NULL;
66398 prepare_namespace();
66399 }
66400
66401 + grsecurity_init();
66402 +
66403 /*
66404 * Ok, we have completed the initial bootup, and
66405 * we're essentially up and running. Get rid of the
66406 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66407 index 9a08acc..e65ebe7 100644
66408 --- a/ipc/mqueue.c
66409 +++ b/ipc/mqueue.c
66410 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66411 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66412 info->attr.mq_msgsize);
66413
66414 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66415 spin_lock(&mq_lock);
66416 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66417 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66418 diff --git a/ipc/msg.c b/ipc/msg.c
66419 index 7385de2..a8180e08 100644
66420 --- a/ipc/msg.c
66421 +++ b/ipc/msg.c
66422 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66423 return security_msg_queue_associate(msq, msgflg);
66424 }
66425
66426 +static struct ipc_ops msg_ops = {
66427 + .getnew = newque,
66428 + .associate = msg_security,
66429 + .more_checks = NULL
66430 +};
66431 +
66432 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66433 {
66434 struct ipc_namespace *ns;
66435 - struct ipc_ops msg_ops;
66436 struct ipc_params msg_params;
66437
66438 ns = current->nsproxy->ipc_ns;
66439
66440 - msg_ops.getnew = newque;
66441 - msg_ops.associate = msg_security;
66442 - msg_ops.more_checks = NULL;
66443 -
66444 msg_params.key = key;
66445 msg_params.flg = msgflg;
66446
66447 diff --git a/ipc/sem.c b/ipc/sem.c
66448 index 5215a81..cfc0cac 100644
66449 --- a/ipc/sem.c
66450 +++ b/ipc/sem.c
66451 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66452 return 0;
66453 }
66454
66455 +static struct ipc_ops sem_ops = {
66456 + .getnew = newary,
66457 + .associate = sem_security,
66458 + .more_checks = sem_more_checks
66459 +};
66460 +
66461 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66462 {
66463 struct ipc_namespace *ns;
66464 - struct ipc_ops sem_ops;
66465 struct ipc_params sem_params;
66466
66467 ns = current->nsproxy->ipc_ns;
66468 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66469 if (nsems < 0 || nsems > ns->sc_semmsl)
66470 return -EINVAL;
66471
66472 - sem_ops.getnew = newary;
66473 - sem_ops.associate = sem_security;
66474 - sem_ops.more_checks = sem_more_checks;
66475 -
66476 sem_params.key = key;
66477 sem_params.flg = semflg;
66478 sem_params.u.nsems = nsems;
66479 diff --git a/ipc/shm.c b/ipc/shm.c
66480 index 00faa05..7040960 100644
66481 --- a/ipc/shm.c
66482 +++ b/ipc/shm.c
66483 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66484 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66485 #endif
66486
66487 +#ifdef CONFIG_GRKERNSEC
66488 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66489 + const time_t shm_createtime, const uid_t cuid,
66490 + const int shmid);
66491 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66492 + const time_t shm_createtime);
66493 +#endif
66494 +
66495 void shm_init_ns(struct ipc_namespace *ns)
66496 {
66497 ns->shm_ctlmax = SHMMAX;
66498 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66499 shp->shm_lprid = 0;
66500 shp->shm_atim = shp->shm_dtim = 0;
66501 shp->shm_ctim = get_seconds();
66502 +#ifdef CONFIG_GRKERNSEC
66503 + {
66504 + struct timespec timeval;
66505 + do_posix_clock_monotonic_gettime(&timeval);
66506 +
66507 + shp->shm_createtime = timeval.tv_sec;
66508 + }
66509 +#endif
66510 shp->shm_segsz = size;
66511 shp->shm_nattch = 0;
66512 shp->shm_file = file;
66513 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66514 return 0;
66515 }
66516
66517 +static struct ipc_ops shm_ops = {
66518 + .getnew = newseg,
66519 + .associate = shm_security,
66520 + .more_checks = shm_more_checks
66521 +};
66522 +
66523 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66524 {
66525 struct ipc_namespace *ns;
66526 - struct ipc_ops shm_ops;
66527 struct ipc_params shm_params;
66528
66529 ns = current->nsproxy->ipc_ns;
66530
66531 - shm_ops.getnew = newseg;
66532 - shm_ops.associate = shm_security;
66533 - shm_ops.more_checks = shm_more_checks;
66534 -
66535 shm_params.key = key;
66536 shm_params.flg = shmflg;
66537 shm_params.u.size = size;
66538 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66539 f_mode = FMODE_READ | FMODE_WRITE;
66540 }
66541 if (shmflg & SHM_EXEC) {
66542 +
66543 +#ifdef CONFIG_PAX_MPROTECT
66544 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66545 + goto out;
66546 +#endif
66547 +
66548 prot |= PROT_EXEC;
66549 acc_mode |= S_IXUGO;
66550 }
66551 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66552 if (err)
66553 goto out_unlock;
66554
66555 +#ifdef CONFIG_GRKERNSEC
66556 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66557 + shp->shm_perm.cuid, shmid) ||
66558 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66559 + err = -EACCES;
66560 + goto out_unlock;
66561 + }
66562 +#endif
66563 +
66564 path = shp->shm_file->f_path;
66565 path_get(&path);
66566 shp->shm_nattch++;
66567 +#ifdef CONFIG_GRKERNSEC
66568 + shp->shm_lapid = current->pid;
66569 +#endif
66570 size = i_size_read(path.dentry->d_inode);
66571 shm_unlock(shp);
66572
66573 diff --git a/kernel/acct.c b/kernel/acct.c
66574 index 02e6167..54824f7 100644
66575 --- a/kernel/acct.c
66576 +++ b/kernel/acct.c
66577 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66578 */
66579 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66580 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66581 - file->f_op->write(file, (char *)&ac,
66582 + file->f_op->write(file, (char __force_user *)&ac,
66583 sizeof(acct_t), &file->f_pos);
66584 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66585 set_fs(fs);
66586 diff --git a/kernel/audit.c b/kernel/audit.c
66587 index a8c84be..8bd034c 100644
66588 --- a/kernel/audit.c
66589 +++ b/kernel/audit.c
66590 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66591 3) suppressed due to audit_rate_limit
66592 4) suppressed due to audit_backlog_limit
66593 */
66594 -static atomic_t audit_lost = ATOMIC_INIT(0);
66595 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66596
66597 /* The netlink socket. */
66598 static struct sock *audit_sock;
66599 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66600 unsigned long now;
66601 int print;
66602
66603 - atomic_inc(&audit_lost);
66604 + atomic_inc_unchecked(&audit_lost);
66605
66606 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66607
66608 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66609 printk(KERN_WARNING
66610 "audit: audit_lost=%d audit_rate_limit=%d "
66611 "audit_backlog_limit=%d\n",
66612 - atomic_read(&audit_lost),
66613 + atomic_read_unchecked(&audit_lost),
66614 audit_rate_limit,
66615 audit_backlog_limit);
66616 audit_panic(message);
66617 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66618 status_set.pid = audit_pid;
66619 status_set.rate_limit = audit_rate_limit;
66620 status_set.backlog_limit = audit_backlog_limit;
66621 - status_set.lost = atomic_read(&audit_lost);
66622 + status_set.lost = atomic_read_unchecked(&audit_lost);
66623 status_set.backlog = skb_queue_len(&audit_skb_queue);
66624 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66625 &status_set, sizeof(status_set));
66626 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66627 index 4b96415..d8c16ee 100644
66628 --- a/kernel/auditsc.c
66629 +++ b/kernel/auditsc.c
66630 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66631 }
66632
66633 /* global counter which is incremented every time something logs in */
66634 -static atomic_t session_id = ATOMIC_INIT(0);
66635 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66636
66637 /**
66638 * audit_set_loginuid - set current task's audit_context loginuid
66639 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66640 return -EPERM;
66641 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66642
66643 - sessionid = atomic_inc_return(&session_id);
66644 + sessionid = atomic_inc_return_unchecked(&session_id);
66645 if (context && context->in_syscall) {
66646 struct audit_buffer *ab;
66647
66648 diff --git a/kernel/capability.c b/kernel/capability.c
66649 index 493d972..ea17248 100644
66650 --- a/kernel/capability.c
66651 +++ b/kernel/capability.c
66652 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66653 * before modification is attempted and the application
66654 * fails.
66655 */
66656 + if (tocopy > ARRAY_SIZE(kdata))
66657 + return -EFAULT;
66658 +
66659 if (copy_to_user(dataptr, kdata, tocopy
66660 * sizeof(struct __user_cap_data_struct))) {
66661 return -EFAULT;
66662 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66663 int ret;
66664
66665 rcu_read_lock();
66666 - ret = security_capable(__task_cred(t), ns, cap);
66667 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66668 + gr_task_is_capable(t, __task_cred(t), cap);
66669 rcu_read_unlock();
66670
66671 - return (ret == 0);
66672 + return ret;
66673 }
66674
66675 /**
66676 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66677 int ret;
66678
66679 rcu_read_lock();
66680 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66681 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66682 rcu_read_unlock();
66683
66684 - return (ret == 0);
66685 + return ret;
66686 }
66687
66688 /**
66689 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66690 BUG();
66691 }
66692
66693 - if (security_capable(current_cred(), ns, cap) == 0) {
66694 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66695 current->flags |= PF_SUPERPRIV;
66696 return true;
66697 }
66698 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66699 }
66700 EXPORT_SYMBOL(ns_capable);
66701
66702 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66703 +{
66704 + if (unlikely(!cap_valid(cap))) {
66705 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66706 + BUG();
66707 + }
66708 +
66709 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66710 + current->flags |= PF_SUPERPRIV;
66711 + return true;
66712 + }
66713 + return false;
66714 +}
66715 +EXPORT_SYMBOL(ns_capable_nolog);
66716 +
66717 /**
66718 * capable - Determine if the current task has a superior capability in effect
66719 * @cap: The capability to be tested for
66720 @@ -408,6 +427,12 @@ bool capable(int cap)
66721 }
66722 EXPORT_SYMBOL(capable);
66723
66724 +bool capable_nolog(int cap)
66725 +{
66726 + return ns_capable_nolog(&init_user_ns, cap);
66727 +}
66728 +EXPORT_SYMBOL(capable_nolog);
66729 +
66730 /**
66731 * nsown_capable - Check superior capability to one's own user_ns
66732 * @cap: The capability in question
66733 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66734
66735 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66736 }
66737 +
66738 +bool inode_capable_nolog(const struct inode *inode, int cap)
66739 +{
66740 + struct user_namespace *ns = current_user_ns();
66741 +
66742 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66743 +}
66744 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66745 index ff2bce5..a41e8f9 100644
66746 --- a/kernel/cgroup.c
66747 +++ b/kernel/cgroup.c
66748 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66749 struct css_set *cg = link->cg;
66750 struct task_struct *task;
66751 int count = 0;
66752 - seq_printf(seq, "css_set %p\n", cg);
66753 + seq_printf(seq, "css_set %pK\n", cg);
66754 list_for_each_entry(task, &cg->tasks, cg_list) {
66755 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66756 seq_puts(seq, " ...\n");
66757 diff --git a/kernel/compat.c b/kernel/compat.c
66758 index c28a306..b4d0cf3 100644
66759 --- a/kernel/compat.c
66760 +++ b/kernel/compat.c
66761 @@ -13,6 +13,7 @@
66762
66763 #include <linux/linkage.h>
66764 #include <linux/compat.h>
66765 +#include <linux/module.h>
66766 #include <linux/errno.h>
66767 #include <linux/time.h>
66768 #include <linux/signal.h>
66769 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66770 mm_segment_t oldfs;
66771 long ret;
66772
66773 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66774 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66775 oldfs = get_fs();
66776 set_fs(KERNEL_DS);
66777 ret = hrtimer_nanosleep_restart(restart);
66778 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66779 oldfs = get_fs();
66780 set_fs(KERNEL_DS);
66781 ret = hrtimer_nanosleep(&tu,
66782 - rmtp ? (struct timespec __user *)&rmt : NULL,
66783 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66784 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66785 set_fs(oldfs);
66786
66787 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66788 mm_segment_t old_fs = get_fs();
66789
66790 set_fs(KERNEL_DS);
66791 - ret = sys_sigpending((old_sigset_t __user *) &s);
66792 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66793 set_fs(old_fs);
66794 if (ret == 0)
66795 ret = put_user(s, set);
66796 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66797 mm_segment_t old_fs = get_fs();
66798
66799 set_fs(KERNEL_DS);
66800 - ret = sys_old_getrlimit(resource, &r);
66801 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66802 set_fs(old_fs);
66803
66804 if (!ret) {
66805 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66806 mm_segment_t old_fs = get_fs();
66807
66808 set_fs(KERNEL_DS);
66809 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66810 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66811 set_fs(old_fs);
66812
66813 if (ret)
66814 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66815 set_fs (KERNEL_DS);
66816 ret = sys_wait4(pid,
66817 (stat_addr ?
66818 - (unsigned int __user *) &status : NULL),
66819 - options, (struct rusage __user *) &r);
66820 + (unsigned int __force_user *) &status : NULL),
66821 + options, (struct rusage __force_user *) &r);
66822 set_fs (old_fs);
66823
66824 if (ret > 0) {
66825 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66826 memset(&info, 0, sizeof(info));
66827
66828 set_fs(KERNEL_DS);
66829 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66830 - uru ? (struct rusage __user *)&ru : NULL);
66831 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66832 + uru ? (struct rusage __force_user *)&ru : NULL);
66833 set_fs(old_fs);
66834
66835 if ((ret < 0) || (info.si_signo == 0))
66836 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66837 oldfs = get_fs();
66838 set_fs(KERNEL_DS);
66839 err = sys_timer_settime(timer_id, flags,
66840 - (struct itimerspec __user *) &newts,
66841 - (struct itimerspec __user *) &oldts);
66842 + (struct itimerspec __force_user *) &newts,
66843 + (struct itimerspec __force_user *) &oldts);
66844 set_fs(oldfs);
66845 if (!err && old && put_compat_itimerspec(old, &oldts))
66846 return -EFAULT;
66847 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66848 oldfs = get_fs();
66849 set_fs(KERNEL_DS);
66850 err = sys_timer_gettime(timer_id,
66851 - (struct itimerspec __user *) &ts);
66852 + (struct itimerspec __force_user *) &ts);
66853 set_fs(oldfs);
66854 if (!err && put_compat_itimerspec(setting, &ts))
66855 return -EFAULT;
66856 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66857 oldfs = get_fs();
66858 set_fs(KERNEL_DS);
66859 err = sys_clock_settime(which_clock,
66860 - (struct timespec __user *) &ts);
66861 + (struct timespec __force_user *) &ts);
66862 set_fs(oldfs);
66863 return err;
66864 }
66865 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66866 oldfs = get_fs();
66867 set_fs(KERNEL_DS);
66868 err = sys_clock_gettime(which_clock,
66869 - (struct timespec __user *) &ts);
66870 + (struct timespec __force_user *) &ts);
66871 set_fs(oldfs);
66872 if (!err && put_compat_timespec(&ts, tp))
66873 return -EFAULT;
66874 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66875
66876 oldfs = get_fs();
66877 set_fs(KERNEL_DS);
66878 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66879 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66880 set_fs(oldfs);
66881
66882 err = compat_put_timex(utp, &txc);
66883 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66884 oldfs = get_fs();
66885 set_fs(KERNEL_DS);
66886 err = sys_clock_getres(which_clock,
66887 - (struct timespec __user *) &ts);
66888 + (struct timespec __force_user *) &ts);
66889 set_fs(oldfs);
66890 if (!err && tp && put_compat_timespec(&ts, tp))
66891 return -EFAULT;
66892 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66893 long err;
66894 mm_segment_t oldfs;
66895 struct timespec tu;
66896 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66897 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66898
66899 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66900 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66901 oldfs = get_fs();
66902 set_fs(KERNEL_DS);
66903 err = clock_nanosleep_restart(restart);
66904 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66905 oldfs = get_fs();
66906 set_fs(KERNEL_DS);
66907 err = sys_clock_nanosleep(which_clock, flags,
66908 - (struct timespec __user *) &in,
66909 - (struct timespec __user *) &out);
66910 + (struct timespec __force_user *) &in,
66911 + (struct timespec __force_user *) &out);
66912 set_fs(oldfs);
66913
66914 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66915 diff --git a/kernel/configs.c b/kernel/configs.c
66916 index 42e8fa0..9e7406b 100644
66917 --- a/kernel/configs.c
66918 +++ b/kernel/configs.c
66919 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66920 struct proc_dir_entry *entry;
66921
66922 /* create the current config file */
66923 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66924 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66925 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66926 + &ikconfig_file_ops);
66927 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66928 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66929 + &ikconfig_file_ops);
66930 +#endif
66931 +#else
66932 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66933 &ikconfig_file_ops);
66934 +#endif
66935 +
66936 if (!entry)
66937 return -ENOMEM;
66938
66939 diff --git a/kernel/cred.c b/kernel/cred.c
66940 index de728ac..e3c267c 100644
66941 --- a/kernel/cred.c
66942 +++ b/kernel/cred.c
66943 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66944 validate_creds(cred);
66945 alter_cred_subscribers(cred, -1);
66946 put_cred(cred);
66947 +
66948 +#ifdef CONFIG_GRKERNSEC_SETXID
66949 + cred = (struct cred *) tsk->delayed_cred;
66950 + if (cred != NULL) {
66951 + tsk->delayed_cred = NULL;
66952 + validate_creds(cred);
66953 + alter_cred_subscribers(cred, -1);
66954 + put_cred(cred);
66955 + }
66956 +#endif
66957 }
66958
66959 /**
66960 @@ -469,7 +479,7 @@ error_put:
66961 * Always returns 0 thus allowing this function to be tail-called at the end
66962 * of, say, sys_setgid().
66963 */
66964 -int commit_creds(struct cred *new)
66965 +static int __commit_creds(struct cred *new)
66966 {
66967 struct task_struct *task = current;
66968 const struct cred *old = task->real_cred;
66969 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66970
66971 get_cred(new); /* we will require a ref for the subj creds too */
66972
66973 + gr_set_role_label(task, new->uid, new->gid);
66974 +
66975 /* dumpability changes */
66976 if (!uid_eq(old->euid, new->euid) ||
66977 !gid_eq(old->egid, new->egid) ||
66978 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66979 put_cred(old);
66980 return 0;
66981 }
66982 +#ifdef CONFIG_GRKERNSEC_SETXID
66983 +extern int set_user(struct cred *new);
66984 +
66985 +void gr_delayed_cred_worker(void)
66986 +{
66987 + const struct cred *new = current->delayed_cred;
66988 + struct cred *ncred;
66989 +
66990 + current->delayed_cred = NULL;
66991 +
66992 + if (current_uid() && new != NULL) {
66993 + // from doing get_cred on it when queueing this
66994 + put_cred(new);
66995 + return;
66996 + } else if (new == NULL)
66997 + return;
66998 +
66999 + ncred = prepare_creds();
67000 + if (!ncred)
67001 + goto die;
67002 + // uids
67003 + ncred->uid = new->uid;
67004 + ncred->euid = new->euid;
67005 + ncred->suid = new->suid;
67006 + ncred->fsuid = new->fsuid;
67007 + // gids
67008 + ncred->gid = new->gid;
67009 + ncred->egid = new->egid;
67010 + ncred->sgid = new->sgid;
67011 + ncred->fsgid = new->fsgid;
67012 + // groups
67013 + if (set_groups(ncred, new->group_info) < 0) {
67014 + abort_creds(ncred);
67015 + goto die;
67016 + }
67017 + // caps
67018 + ncred->securebits = new->securebits;
67019 + ncred->cap_inheritable = new->cap_inheritable;
67020 + ncred->cap_permitted = new->cap_permitted;
67021 + ncred->cap_effective = new->cap_effective;
67022 + ncred->cap_bset = new->cap_bset;
67023 +
67024 + if (set_user(ncred)) {
67025 + abort_creds(ncred);
67026 + goto die;
67027 + }
67028 +
67029 + // from doing get_cred on it when queueing this
67030 + put_cred(new);
67031 +
67032 + __commit_creds(ncred);
67033 + return;
67034 +die:
67035 + // from doing get_cred on it when queueing this
67036 + put_cred(new);
67037 + do_group_exit(SIGKILL);
67038 +}
67039 +#endif
67040 +
67041 +int commit_creds(struct cred *new)
67042 +{
67043 +#ifdef CONFIG_GRKERNSEC_SETXID
67044 + int ret;
67045 + int schedule_it = 0;
67046 + struct task_struct *t;
67047 +
67048 + /* we won't get called with tasklist_lock held for writing
67049 + and interrupts disabled as the cred struct in that case is
67050 + init_cred
67051 + */
67052 + if (grsec_enable_setxid && !current_is_single_threaded() &&
67053 + !current_uid() && new->uid) {
67054 + schedule_it = 1;
67055 + }
67056 + ret = __commit_creds(new);
67057 + if (schedule_it) {
67058 + rcu_read_lock();
67059 + read_lock(&tasklist_lock);
67060 + for (t = next_thread(current); t != current;
67061 + t = next_thread(t)) {
67062 + if (t->delayed_cred == NULL) {
67063 + t->delayed_cred = get_cred(new);
67064 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
67065 + set_tsk_need_resched(t);
67066 + }
67067 + }
67068 + read_unlock(&tasklist_lock);
67069 + rcu_read_unlock();
67070 + }
67071 + return ret;
67072 +#else
67073 + return __commit_creds(new);
67074 +#endif
67075 +}
67076 +
67077 EXPORT_SYMBOL(commit_creds);
67078
67079 /**
67080 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67081 index 0557f24..1a00d9a 100644
67082 --- a/kernel/debug/debug_core.c
67083 +++ b/kernel/debug/debug_core.c
67084 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67085 */
67086 static atomic_t masters_in_kgdb;
67087 static atomic_t slaves_in_kgdb;
67088 -static atomic_t kgdb_break_tasklet_var;
67089 +static atomic_unchecked_t kgdb_break_tasklet_var;
67090 atomic_t kgdb_setting_breakpoint;
67091
67092 struct task_struct *kgdb_usethread;
67093 @@ -132,7 +132,7 @@ int kgdb_single_step;
67094 static pid_t kgdb_sstep_pid;
67095
67096 /* to keep track of the CPU which is doing the single stepping*/
67097 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67098 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67099
67100 /*
67101 * If you are debugging a problem where roundup (the collection of
67102 @@ -540,7 +540,7 @@ return_normal:
67103 * kernel will only try for the value of sstep_tries before
67104 * giving up and continuing on.
67105 */
67106 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67107 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67108 (kgdb_info[cpu].task &&
67109 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67110 atomic_set(&kgdb_active, -1);
67111 @@ -634,8 +634,8 @@ cpu_master_loop:
67112 }
67113
67114 kgdb_restore:
67115 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67116 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67117 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67118 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67119 if (kgdb_info[sstep_cpu].task)
67120 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67121 else
67122 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67123 static void kgdb_tasklet_bpt(unsigned long ing)
67124 {
67125 kgdb_breakpoint();
67126 - atomic_set(&kgdb_break_tasklet_var, 0);
67127 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67128 }
67129
67130 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67131
67132 void kgdb_schedule_breakpoint(void)
67133 {
67134 - if (atomic_read(&kgdb_break_tasklet_var) ||
67135 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67136 atomic_read(&kgdb_active) != -1 ||
67137 atomic_read(&kgdb_setting_breakpoint))
67138 return;
67139 - atomic_inc(&kgdb_break_tasklet_var);
67140 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67141 tasklet_schedule(&kgdb_tasklet_breakpoint);
67142 }
67143 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67144 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67145 index 31df170..bc98840 100644
67146 --- a/kernel/debug/kdb/kdb_main.c
67147 +++ b/kernel/debug/kdb/kdb_main.c
67148 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
67149 list_for_each_entry(mod, kdb_modules, list) {
67150
67151 kdb_printf("%-20s%8u 0x%p ", mod->name,
67152 - mod->core_size, (void *)mod);
67153 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67154 #ifdef CONFIG_MODULE_UNLOAD
67155 kdb_printf("%4ld ", module_refcount(mod));
67156 #endif
67157 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
67158 kdb_printf(" (Loading)");
67159 else
67160 kdb_printf(" (Live)");
67161 - kdb_printf(" 0x%p", mod->module_core);
67162 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67163
67164 #ifdef CONFIG_MODULE_UNLOAD
67165 {
67166 diff --git a/kernel/events/core.c b/kernel/events/core.c
67167 index 7fee567..8affa2c 100644
67168 --- a/kernel/events/core.c
67169 +++ b/kernel/events/core.c
67170 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67171 return 0;
67172 }
67173
67174 -static atomic64_t perf_event_id;
67175 +static atomic64_unchecked_t perf_event_id;
67176
67177 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67178 enum event_type_t event_type);
67179 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
67180
67181 static inline u64 perf_event_count(struct perf_event *event)
67182 {
67183 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67184 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67185 }
67186
67187 static u64 perf_event_read(struct perf_event *event)
67188 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67189 mutex_lock(&event->child_mutex);
67190 total += perf_event_read(event);
67191 *enabled += event->total_time_enabled +
67192 - atomic64_read(&event->child_total_time_enabled);
67193 + atomic64_read_unchecked(&event->child_total_time_enabled);
67194 *running += event->total_time_running +
67195 - atomic64_read(&event->child_total_time_running);
67196 + atomic64_read_unchecked(&event->child_total_time_running);
67197
67198 list_for_each_entry(child, &event->child_list, child_list) {
67199 total += perf_event_read(child);
67200 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
67201 userpg->offset -= local64_read(&event->hw.prev_count);
67202
67203 userpg->time_enabled = enabled +
67204 - atomic64_read(&event->child_total_time_enabled);
67205 + atomic64_read_unchecked(&event->child_total_time_enabled);
67206
67207 userpg->time_running = running +
67208 - atomic64_read(&event->child_total_time_running);
67209 + atomic64_read_unchecked(&event->child_total_time_running);
67210
67211 arch_perf_update_userpage(userpg, now);
67212
67213 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67214 values[n++] = perf_event_count(event);
67215 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67216 values[n++] = enabled +
67217 - atomic64_read(&event->child_total_time_enabled);
67218 + atomic64_read_unchecked(&event->child_total_time_enabled);
67219 }
67220 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67221 values[n++] = running +
67222 - atomic64_read(&event->child_total_time_running);
67223 + atomic64_read_unchecked(&event->child_total_time_running);
67224 }
67225 if (read_format & PERF_FORMAT_ID)
67226 values[n++] = primary_event_id(event);
67227 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67228 * need to add enough zero bytes after the string to handle
67229 * the 64bit alignment we do later.
67230 */
67231 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67232 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67233 if (!buf) {
67234 name = strncpy(tmp, "//enomem", sizeof(tmp));
67235 goto got_name;
67236 }
67237 - name = d_path(&file->f_path, buf, PATH_MAX);
67238 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67239 if (IS_ERR(name)) {
67240 name = strncpy(tmp, "//toolong", sizeof(tmp));
67241 goto got_name;
67242 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67243 event->parent = parent_event;
67244
67245 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67246 - event->id = atomic64_inc_return(&perf_event_id);
67247 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67248
67249 event->state = PERF_EVENT_STATE_INACTIVE;
67250
67251 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67252 /*
67253 * Add back the child's count to the parent's count:
67254 */
67255 - atomic64_add(child_val, &parent_event->child_count);
67256 - atomic64_add(child_event->total_time_enabled,
67257 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67258 + atomic64_add_unchecked(child_event->total_time_enabled,
67259 &parent_event->child_total_time_enabled);
67260 - atomic64_add(child_event->total_time_running,
67261 + atomic64_add_unchecked(child_event->total_time_running,
67262 &parent_event->child_total_time_running);
67263
67264 /*
67265 diff --git a/kernel/exit.c b/kernel/exit.c
67266 index f65345f9..9c28dab 100644
67267 --- a/kernel/exit.c
67268 +++ b/kernel/exit.c
67269 @@ -59,6 +59,10 @@
67270 #include <asm/pgtable.h>
67271 #include <asm/mmu_context.h>
67272
67273 +#ifdef CONFIG_GRKERNSEC
67274 +extern rwlock_t grsec_exec_file_lock;
67275 +#endif
67276 +
67277 static void exit_mm(struct task_struct * tsk);
67278
67279 static void __unhash_process(struct task_struct *p, bool group_dead)
67280 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67281 struct task_struct *leader;
67282 int zap_leader;
67283 repeat:
67284 +#ifdef CONFIG_NET
67285 + gr_del_task_from_ip_table(p);
67286 +#endif
67287 +
67288 /* don't need to get the RCU readlock here - the process is dead and
67289 * can't be modifying its own credentials. But shut RCU-lockdep up */
67290 rcu_read_lock();
67291 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67292 * know it'll be handled, so that they don't get converted to
67293 * SIGKILL or just silently dropped.
67294 */
67295 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67296 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67297 recalc_sigpending();
67298 spin_unlock_irq(&current->sighand->siglock);
67299 return 0;
67300 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67301 vsnprintf(current->comm, sizeof(current->comm), name, args);
67302 va_end(args);
67303
67304 +#ifdef CONFIG_GRKERNSEC
67305 + write_lock(&grsec_exec_file_lock);
67306 + if (current->exec_file) {
67307 + fput(current->exec_file);
67308 + current->exec_file = NULL;
67309 + }
67310 + write_unlock(&grsec_exec_file_lock);
67311 +#endif
67312 +
67313 + gr_set_kernel_label(current);
67314 +
67315 /*
67316 * If we were started as result of loading a module, close all of the
67317 * user space pages. We don't need them, and if we didn't close them
67318 @@ -907,6 +926,8 @@ void do_exit(long code)
67319 struct task_struct *tsk = current;
67320 int group_dead;
67321
67322 + set_fs(USER_DS);
67323 +
67324 profile_task_exit(tsk);
67325
67326 WARN_ON(blk_needs_flush_plug(tsk));
67327 @@ -923,7 +944,6 @@ void do_exit(long code)
67328 * mm_release()->clear_child_tid() from writing to a user-controlled
67329 * kernel address.
67330 */
67331 - set_fs(USER_DS);
67332
67333 ptrace_event(PTRACE_EVENT_EXIT, code);
67334
67335 @@ -982,6 +1002,9 @@ void do_exit(long code)
67336 tsk->exit_code = code;
67337 taskstats_exit(tsk, group_dead);
67338
67339 + gr_acl_handle_psacct(tsk, code);
67340 + gr_acl_handle_exit();
67341 +
67342 exit_mm(tsk);
67343
67344 if (group_dead)
67345 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67346 * Take down every thread in the group. This is called by fatal signals
67347 * as well as by sys_exit_group (below).
67348 */
67349 -void
67350 +__noreturn void
67351 do_group_exit(int exit_code)
67352 {
67353 struct signal_struct *sig = current->signal;
67354 diff --git a/kernel/fork.c b/kernel/fork.c
67355 index 2c8857e..288c9c7 100644
67356 --- a/kernel/fork.c
67357 +++ b/kernel/fork.c
67358 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67359 *stackend = STACK_END_MAGIC; /* for overflow detection */
67360
67361 #ifdef CONFIG_CC_STACKPROTECTOR
67362 - tsk->stack_canary = get_random_int();
67363 + tsk->stack_canary = pax_get_random_long();
67364 #endif
67365
67366 /*
67367 @@ -343,13 +343,78 @@ free_tsk:
67368 }
67369
67370 #ifdef CONFIG_MMU
67371 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67372 +{
67373 + struct vm_area_struct *tmp;
67374 + unsigned long charge;
67375 + struct mempolicy *pol;
67376 + struct file *file;
67377 +
67378 + charge = 0;
67379 + if (mpnt->vm_flags & VM_ACCOUNT) {
67380 + unsigned long len = vma_pages(mpnt);
67381 +
67382 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67383 + goto fail_nomem;
67384 + charge = len;
67385 + }
67386 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67387 + if (!tmp)
67388 + goto fail_nomem;
67389 + *tmp = *mpnt;
67390 + tmp->vm_mm = mm;
67391 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67392 + pol = mpol_dup(vma_policy(mpnt));
67393 + if (IS_ERR(pol))
67394 + goto fail_nomem_policy;
67395 + vma_set_policy(tmp, pol);
67396 + if (anon_vma_fork(tmp, mpnt))
67397 + goto fail_nomem_anon_vma_fork;
67398 + tmp->vm_flags &= ~VM_LOCKED;
67399 + tmp->vm_next = tmp->vm_prev = NULL;
67400 + tmp->vm_mirror = NULL;
67401 + file = tmp->vm_file;
67402 + if (file) {
67403 + struct inode *inode = file->f_path.dentry->d_inode;
67404 + struct address_space *mapping = file->f_mapping;
67405 +
67406 + get_file(file);
67407 + if (tmp->vm_flags & VM_DENYWRITE)
67408 + atomic_dec(&inode->i_writecount);
67409 + mutex_lock(&mapping->i_mmap_mutex);
67410 + if (tmp->vm_flags & VM_SHARED)
67411 + mapping->i_mmap_writable++;
67412 + flush_dcache_mmap_lock(mapping);
67413 + /* insert tmp into the share list, just after mpnt */
67414 + vma_prio_tree_add(tmp, mpnt);
67415 + flush_dcache_mmap_unlock(mapping);
67416 + mutex_unlock(&mapping->i_mmap_mutex);
67417 + }
67418 +
67419 + /*
67420 + * Clear hugetlb-related page reserves for children. This only
67421 + * affects MAP_PRIVATE mappings. Faults generated by the child
67422 + * are not guaranteed to succeed, even if read-only
67423 + */
67424 + if (is_vm_hugetlb_page(tmp))
67425 + reset_vma_resv_huge_pages(tmp);
67426 +
67427 + return tmp;
67428 +
67429 +fail_nomem_anon_vma_fork:
67430 + mpol_put(pol);
67431 +fail_nomem_policy:
67432 + kmem_cache_free(vm_area_cachep, tmp);
67433 +fail_nomem:
67434 + vm_unacct_memory(charge);
67435 + return NULL;
67436 +}
67437 +
67438 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67439 {
67440 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67441 struct rb_node **rb_link, *rb_parent;
67442 int retval;
67443 - unsigned long charge;
67444 - struct mempolicy *pol;
67445
67446 down_write(&oldmm->mmap_sem);
67447 flush_cache_dup_mm(oldmm);
67448 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67449 mm->locked_vm = 0;
67450 mm->mmap = NULL;
67451 mm->mmap_cache = NULL;
67452 - mm->free_area_cache = oldmm->mmap_base;
67453 - mm->cached_hole_size = ~0UL;
67454 + mm->free_area_cache = oldmm->free_area_cache;
67455 + mm->cached_hole_size = oldmm->cached_hole_size;
67456 mm->map_count = 0;
67457 cpumask_clear(mm_cpumask(mm));
67458 mm->mm_rb = RB_ROOT;
67459 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67460
67461 prev = NULL;
67462 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67463 - struct file *file;
67464 -
67465 if (mpnt->vm_flags & VM_DONTCOPY) {
67466 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67467 -vma_pages(mpnt));
67468 continue;
67469 }
67470 - charge = 0;
67471 - if (mpnt->vm_flags & VM_ACCOUNT) {
67472 - unsigned long len = vma_pages(mpnt);
67473 -
67474 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67475 - goto fail_nomem;
67476 - charge = len;
67477 - }
67478 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67479 - if (!tmp)
67480 - goto fail_nomem;
67481 - *tmp = *mpnt;
67482 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67483 - pol = mpol_dup(vma_policy(mpnt));
67484 - retval = PTR_ERR(pol);
67485 - if (IS_ERR(pol))
67486 - goto fail_nomem_policy;
67487 - vma_set_policy(tmp, pol);
67488 - tmp->vm_mm = mm;
67489 - if (anon_vma_fork(tmp, mpnt))
67490 - goto fail_nomem_anon_vma_fork;
67491 - tmp->vm_flags &= ~VM_LOCKED;
67492 - tmp->vm_next = tmp->vm_prev = NULL;
67493 - file = tmp->vm_file;
67494 - if (file) {
67495 - struct inode *inode = file->f_path.dentry->d_inode;
67496 - struct address_space *mapping = file->f_mapping;
67497 -
67498 - get_file(file);
67499 - if (tmp->vm_flags & VM_DENYWRITE)
67500 - atomic_dec(&inode->i_writecount);
67501 - mutex_lock(&mapping->i_mmap_mutex);
67502 - if (tmp->vm_flags & VM_SHARED)
67503 - mapping->i_mmap_writable++;
67504 - flush_dcache_mmap_lock(mapping);
67505 - /* insert tmp into the share list, just after mpnt */
67506 - vma_prio_tree_add(tmp, mpnt);
67507 - flush_dcache_mmap_unlock(mapping);
67508 - mutex_unlock(&mapping->i_mmap_mutex);
67509 + tmp = dup_vma(mm, oldmm, mpnt);
67510 + if (!tmp) {
67511 + retval = -ENOMEM;
67512 + goto out;
67513 }
67514
67515 /*
67516 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67517 if (retval)
67518 goto out;
67519
67520 - if (file)
67521 + if (tmp->vm_file)
67522 uprobe_mmap(tmp);
67523 }
67524 +
67525 +#ifdef CONFIG_PAX_SEGMEXEC
67526 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67527 + struct vm_area_struct *mpnt_m;
67528 +
67529 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67530 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67531 +
67532 + if (!mpnt->vm_mirror)
67533 + continue;
67534 +
67535 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67536 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67537 + mpnt->vm_mirror = mpnt_m;
67538 + } else {
67539 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67540 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67541 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67542 + mpnt->vm_mirror->vm_mirror = mpnt;
67543 + }
67544 + }
67545 + BUG_ON(mpnt_m);
67546 + }
67547 +#endif
67548 +
67549 /* a new mm has just been created */
67550 arch_dup_mmap(oldmm, mm);
67551 retval = 0;
67552 @@ -466,14 +519,6 @@ out:
67553 flush_tlb_mm(oldmm);
67554 up_write(&oldmm->mmap_sem);
67555 return retval;
67556 -fail_nomem_anon_vma_fork:
67557 - mpol_put(pol);
67558 -fail_nomem_policy:
67559 - kmem_cache_free(vm_area_cachep, tmp);
67560 -fail_nomem:
67561 - retval = -ENOMEM;
67562 - vm_unacct_memory(charge);
67563 - goto out;
67564 }
67565
67566 static inline int mm_alloc_pgd(struct mm_struct *mm)
67567 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67568 return ERR_PTR(err);
67569
67570 mm = get_task_mm(task);
67571 - if (mm && mm != current->mm &&
67572 - !ptrace_may_access(task, mode)) {
67573 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67574 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67575 mmput(mm);
67576 mm = ERR_PTR(-EACCES);
67577 }
67578 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67579 spin_unlock(&fs->lock);
67580 return -EAGAIN;
67581 }
67582 - fs->users++;
67583 + atomic_inc(&fs->users);
67584 spin_unlock(&fs->lock);
67585 return 0;
67586 }
67587 tsk->fs = copy_fs_struct(fs);
67588 if (!tsk->fs)
67589 return -ENOMEM;
67590 + /* Carry through gr_chroot_dentry and is_chrooted instead
67591 + of recomputing it here. Already copied when the task struct
67592 + is duplicated. This allows pivot_root to not be treated as
67593 + a chroot
67594 + */
67595 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67596 +
67597 return 0;
67598 }
67599
67600 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67601 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67602 #endif
67603 retval = -EAGAIN;
67604 +
67605 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67606 +
67607 if (atomic_read(&p->real_cred->user->processes) >=
67608 task_rlimit(p, RLIMIT_NPROC)) {
67609 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67610 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67611 /* Need tasklist lock for parent etc handling! */
67612 write_lock_irq(&tasklist_lock);
67613
67614 + /* synchronizes with gr_set_acls() */
67615 + gr_copy_label(p);
67616 +
67617 /* CLONE_PARENT re-uses the old parent */
67618 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67619 p->real_parent = current->real_parent;
67620 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67621 bad_fork_free:
67622 free_task(p);
67623 fork_out:
67624 + gr_log_forkfail(retval);
67625 +
67626 return ERR_PTR(retval);
67627 }
67628
67629 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67630 if (clone_flags & CLONE_PARENT_SETTID)
67631 put_user(nr, parent_tidptr);
67632
67633 + gr_handle_brute_check();
67634 +
67635 if (clone_flags & CLONE_VFORK) {
67636 p->vfork_done = &vfork;
67637 init_completion(&vfork);
67638 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67639 return 0;
67640
67641 /* don't need lock here; in the worst case we'll do useless copy */
67642 - if (fs->users == 1)
67643 + if (atomic_read(&fs->users) == 1)
67644 return 0;
67645
67646 *new_fsp = copy_fs_struct(fs);
67647 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67648 fs = current->fs;
67649 spin_lock(&fs->lock);
67650 current->fs = new_fs;
67651 - if (--fs->users)
67652 + gr_set_chroot_entries(current, &current->fs->root);
67653 + if (atomic_dec_return(&fs->users))
67654 new_fs = NULL;
67655 else
67656 new_fs = fs;
67657 diff --git a/kernel/futex.c b/kernel/futex.c
67658 index 3717e7b..473c750 100644
67659 --- a/kernel/futex.c
67660 +++ b/kernel/futex.c
67661 @@ -54,6 +54,7 @@
67662 #include <linux/mount.h>
67663 #include <linux/pagemap.h>
67664 #include <linux/syscalls.h>
67665 +#include <linux/ptrace.h>
67666 #include <linux/signal.h>
67667 #include <linux/export.h>
67668 #include <linux/magic.h>
67669 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67670 struct page *page, *page_head;
67671 int err, ro = 0;
67672
67673 +#ifdef CONFIG_PAX_SEGMEXEC
67674 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67675 + return -EFAULT;
67676 +#endif
67677 +
67678 /*
67679 * The futex address must be "naturally" aligned.
67680 */
67681 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67682 {
67683 u32 curval;
67684 int i;
67685 + mm_segment_t oldfs;
67686
67687 /*
67688 * This will fail and we want it. Some arch implementations do
67689 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67690 * implementation, the non-functional ones will return
67691 * -ENOSYS.
67692 */
67693 + oldfs = get_fs();
67694 + set_fs(USER_DS);
67695 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67696 futex_cmpxchg_enabled = 1;
67697 + set_fs(oldfs);
67698
67699 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67700 plist_head_init(&futex_queues[i].chain);
67701 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67702 index 9b22d03..6295b62 100644
67703 --- a/kernel/gcov/base.c
67704 +++ b/kernel/gcov/base.c
67705 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67706 }
67707
67708 #ifdef CONFIG_MODULES
67709 -static inline int within(void *addr, void *start, unsigned long size)
67710 -{
67711 - return ((addr >= start) && (addr < start + size));
67712 -}
67713 -
67714 /* Update list and generate events when modules are unloaded. */
67715 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67716 void *data)
67717 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67718 prev = NULL;
67719 /* Remove entries located in module from linked list. */
67720 for (info = gcov_info_head; info; info = info->next) {
67721 - if (within(info, mod->module_core, mod->core_size)) {
67722 + if (within_module_core_rw((unsigned long)info, mod)) {
67723 if (prev)
67724 prev->next = info->next;
67725 else
67726 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67727 index 6db7a5e..25b6648 100644
67728 --- a/kernel/hrtimer.c
67729 +++ b/kernel/hrtimer.c
67730 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67731 local_irq_restore(flags);
67732 }
67733
67734 -static void run_hrtimer_softirq(struct softirq_action *h)
67735 +static void run_hrtimer_softirq(void)
67736 {
67737 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67738
67739 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67740 index 4304919..408c4c0 100644
67741 --- a/kernel/jump_label.c
67742 +++ b/kernel/jump_label.c
67743 @@ -13,6 +13,7 @@
67744 #include <linux/sort.h>
67745 #include <linux/err.h>
67746 #include <linux/static_key.h>
67747 +#include <linux/mm.h>
67748
67749 #ifdef HAVE_JUMP_LABEL
67750
67751 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67752
67753 size = (((unsigned long)stop - (unsigned long)start)
67754 / sizeof(struct jump_entry));
67755 + pax_open_kernel();
67756 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67757 + pax_close_kernel();
67758 }
67759
67760 static void jump_label_update(struct static_key *key, int enable);
67761 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67762 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67763 struct jump_entry *iter;
67764
67765 + pax_open_kernel();
67766 for (iter = iter_start; iter < iter_stop; iter++) {
67767 if (within_module_init(iter->code, mod))
67768 iter->code = 0;
67769 }
67770 + pax_close_kernel();
67771 }
67772
67773 static int
67774 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67775 index 2169fee..45c017a 100644
67776 --- a/kernel/kallsyms.c
67777 +++ b/kernel/kallsyms.c
67778 @@ -11,6 +11,9 @@
67779 * Changed the compression method from stem compression to "table lookup"
67780 * compression (see scripts/kallsyms.c for a more complete description)
67781 */
67782 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67783 +#define __INCLUDED_BY_HIDESYM 1
67784 +#endif
67785 #include <linux/kallsyms.h>
67786 #include <linux/module.h>
67787 #include <linux/init.h>
67788 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67789
67790 static inline int is_kernel_inittext(unsigned long addr)
67791 {
67792 + if (system_state != SYSTEM_BOOTING)
67793 + return 0;
67794 +
67795 if (addr >= (unsigned long)_sinittext
67796 && addr <= (unsigned long)_einittext)
67797 return 1;
67798 return 0;
67799 }
67800
67801 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67802 +#ifdef CONFIG_MODULES
67803 +static inline int is_module_text(unsigned long addr)
67804 +{
67805 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67806 + return 1;
67807 +
67808 + addr = ktla_ktva(addr);
67809 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67810 +}
67811 +#else
67812 +static inline int is_module_text(unsigned long addr)
67813 +{
67814 + return 0;
67815 +}
67816 +#endif
67817 +#endif
67818 +
67819 static inline int is_kernel_text(unsigned long addr)
67820 {
67821 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67822 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67823
67824 static inline int is_kernel(unsigned long addr)
67825 {
67826 +
67827 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67828 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67829 + return 1;
67830 +
67831 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67832 +#else
67833 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67834 +#endif
67835 +
67836 return 1;
67837 return in_gate_area_no_mm(addr);
67838 }
67839
67840 static int is_ksym_addr(unsigned long addr)
67841 {
67842 +
67843 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67844 + if (is_module_text(addr))
67845 + return 0;
67846 +#endif
67847 +
67848 if (all_var)
67849 return is_kernel(addr);
67850
67851 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67852
67853 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67854 {
67855 - iter->name[0] = '\0';
67856 iter->nameoff = get_symbol_offset(new_pos);
67857 iter->pos = new_pos;
67858 }
67859 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67860 {
67861 struct kallsym_iter *iter = m->private;
67862
67863 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67864 + if (current_uid())
67865 + return 0;
67866 +#endif
67867 +
67868 /* Some debugging symbols have no name. Ignore them. */
67869 if (!iter->name[0])
67870 return 0;
67871 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67872 */
67873 type = iter->exported ? toupper(iter->type) :
67874 tolower(iter->type);
67875 +
67876 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67877 type, iter->name, iter->module_name);
67878 } else
67879 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67880 struct kallsym_iter *iter;
67881 int ret;
67882
67883 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67884 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67885 if (!iter)
67886 return -ENOMEM;
67887 reset_iter(iter, 0);
67888 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67889 index 30b7b22..c726387 100644
67890 --- a/kernel/kcmp.c
67891 +++ b/kernel/kcmp.c
67892 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67893 struct task_struct *task1, *task2;
67894 int ret;
67895
67896 +#ifdef CONFIG_GRKERNSEC
67897 + return -ENOSYS;
67898 +#endif
67899 +
67900 rcu_read_lock();
67901
67902 /*
67903 diff --git a/kernel/kexec.c b/kernel/kexec.c
67904 index 0668d58..591b6fc 100644
67905 --- a/kernel/kexec.c
67906 +++ b/kernel/kexec.c
67907 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67908 unsigned long flags)
67909 {
67910 struct compat_kexec_segment in;
67911 - struct kexec_segment out, __user *ksegments;
67912 + struct kexec_segment out;
67913 + struct kexec_segment __user *ksegments;
67914 unsigned long i, result;
67915
67916 /* Don't allow clients that don't understand the native
67917 diff --git a/kernel/kmod.c b/kernel/kmod.c
67918 index 6f99aea..eb6e3a0 100644
67919 --- a/kernel/kmod.c
67920 +++ b/kernel/kmod.c
67921 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67922 kfree(info->argv);
67923 }
67924
67925 -static int call_modprobe(char *module_name, int wait)
67926 +static int call_modprobe(char *module_name, char *module_param, int wait)
67927 {
67928 static char *envp[] = {
67929 "HOME=/",
67930 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67931 NULL
67932 };
67933
67934 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67935 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67936 if (!argv)
67937 goto out;
67938
67939 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67940 argv[1] = "-q";
67941 argv[2] = "--";
67942 argv[3] = module_name; /* check free_modprobe_argv() */
67943 - argv[4] = NULL;
67944 + argv[4] = module_param;
67945 + argv[5] = NULL;
67946
67947 return call_usermodehelper_fns(modprobe_path, argv, envp,
67948 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67949 @@ -119,9 +120,8 @@ out:
67950 * If module auto-loading support is disabled then this function
67951 * becomes a no-operation.
67952 */
67953 -int __request_module(bool wait, const char *fmt, ...)
67954 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67955 {
67956 - va_list args;
67957 char module_name[MODULE_NAME_LEN];
67958 unsigned int max_modprobes;
67959 int ret;
67960 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67961 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67962 static int kmod_loop_msg;
67963
67964 - va_start(args, fmt);
67965 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67966 - va_end(args);
67967 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67968 if (ret >= MODULE_NAME_LEN)
67969 return -ENAMETOOLONG;
67970
67971 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67972 if (ret)
67973 return ret;
67974
67975 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67976 + if (!current_uid()) {
67977 + /* hack to workaround consolekit/udisks stupidity */
67978 + read_lock(&tasklist_lock);
67979 + if (!strcmp(current->comm, "mount") &&
67980 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67981 + read_unlock(&tasklist_lock);
67982 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67983 + return -EPERM;
67984 + }
67985 + read_unlock(&tasklist_lock);
67986 + }
67987 +#endif
67988 +
67989 /* If modprobe needs a service that is in a module, we get a recursive
67990 * loop. Limit the number of running kmod threads to max_threads/2 or
67991 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67992 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67993
67994 trace_module_request(module_name, wait, _RET_IP_);
67995
67996 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67997 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67998
67999 atomic_dec(&kmod_concurrent);
68000 return ret;
68001 }
68002 +
68003 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
68004 +{
68005 + va_list args;
68006 + int ret;
68007 +
68008 + va_start(args, fmt);
68009 + ret = ____request_module(wait, module_param, fmt, args);
68010 + va_end(args);
68011 +
68012 + return ret;
68013 +}
68014 +
68015 +int __request_module(bool wait, const char *fmt, ...)
68016 +{
68017 + va_list args;
68018 + int ret;
68019 +
68020 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68021 + if (current_uid()) {
68022 + char module_param[MODULE_NAME_LEN];
68023 +
68024 + memset(module_param, 0, sizeof(module_param));
68025 +
68026 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
68027 +
68028 + va_start(args, fmt);
68029 + ret = ____request_module(wait, module_param, fmt, args);
68030 + va_end(args);
68031 +
68032 + return ret;
68033 + }
68034 +#endif
68035 +
68036 + va_start(args, fmt);
68037 + ret = ____request_module(wait, NULL, fmt, args);
68038 + va_end(args);
68039 +
68040 + return ret;
68041 +}
68042 +
68043 EXPORT_SYMBOL(__request_module);
68044 #endif /* CONFIG_MODULES */
68045
68046 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
68047 *
68048 * Thus the __user pointer cast is valid here.
68049 */
68050 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
68051 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
68052
68053 /*
68054 * If ret is 0, either ____call_usermodehelper failed and the
68055 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
68056 index c62b854..6fc810d 100644
68057 --- a/kernel/kprobes.c
68058 +++ b/kernel/kprobes.c
68059 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
68060 * kernel image and loaded module images reside. This is required
68061 * so x86_64 can correctly handle the %rip-relative fixups.
68062 */
68063 - kip->insns = module_alloc(PAGE_SIZE);
68064 + kip->insns = module_alloc_exec(PAGE_SIZE);
68065 if (!kip->insns) {
68066 kfree(kip);
68067 return NULL;
68068 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
68069 */
68070 if (!list_is_singular(&kip->list)) {
68071 list_del(&kip->list);
68072 - module_free(NULL, kip->insns);
68073 + module_free_exec(NULL, kip->insns);
68074 kfree(kip);
68075 }
68076 return 1;
68077 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
68078 {
68079 int i, err = 0;
68080 unsigned long offset = 0, size = 0;
68081 - char *modname, namebuf[128];
68082 + char *modname, namebuf[KSYM_NAME_LEN];
68083 const char *symbol_name;
68084 void *addr;
68085 struct kprobe_blackpoint *kb;
68086 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
68087 kprobe_type = "k";
68088
68089 if (sym)
68090 - seq_printf(pi, "%p %s %s+0x%x %s ",
68091 + seq_printf(pi, "%pK %s %s+0x%x %s ",
68092 p->addr, kprobe_type, sym, offset,
68093 (modname ? modname : " "));
68094 else
68095 - seq_printf(pi, "%p %s %p ",
68096 + seq_printf(pi, "%pK %s %pK ",
68097 p->addr, kprobe_type, p->addr);
68098
68099 if (!pp)
68100 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68101 const char *sym = NULL;
68102 unsigned int i = *(loff_t *) v;
68103 unsigned long offset = 0;
68104 - char *modname, namebuf[128];
68105 + char *modname, namebuf[KSYM_NAME_LEN];
68106
68107 head = &kprobe_table[i];
68108 preempt_disable();
68109 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68110 index 4e316e1..5501eef 100644
68111 --- a/kernel/ksysfs.c
68112 +++ b/kernel/ksysfs.c
68113 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68114 {
68115 if (count+1 > UEVENT_HELPER_PATH_LEN)
68116 return -ENOENT;
68117 + if (!capable(CAP_SYS_ADMIN))
68118 + return -EPERM;
68119 memcpy(uevent_helper, buf, count);
68120 uevent_helper[count] = '\0';
68121 if (count && uevent_helper[count-1] == '\n')
68122 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68123 index ea9ee45..67ebc8f 100644
68124 --- a/kernel/lockdep.c
68125 +++ b/kernel/lockdep.c
68126 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68127 end = (unsigned long) &_end,
68128 addr = (unsigned long) obj;
68129
68130 +#ifdef CONFIG_PAX_KERNEXEC
68131 + start = ktla_ktva(start);
68132 +#endif
68133 +
68134 /*
68135 * static variable?
68136 */
68137 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68138 if (!static_obj(lock->key)) {
68139 debug_locks_off();
68140 printk("INFO: trying to register non-static key.\n");
68141 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68142 printk("the code is fine but needs lockdep annotation.\n");
68143 printk("turning off the locking correctness validator.\n");
68144 dump_stack();
68145 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68146 if (!class)
68147 return 0;
68148 }
68149 - atomic_inc((atomic_t *)&class->ops);
68150 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68151 if (very_verbose(class)) {
68152 printk("\nacquire class [%p] %s", class->key, class->name);
68153 if (class->name_version > 1)
68154 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68155 index 91c32a0..7b88d63 100644
68156 --- a/kernel/lockdep_proc.c
68157 +++ b/kernel/lockdep_proc.c
68158 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68159
68160 static void print_name(struct seq_file *m, struct lock_class *class)
68161 {
68162 - char str[128];
68163 + char str[KSYM_NAME_LEN];
68164 const char *name = class->name;
68165
68166 if (!name) {
68167 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
68168 return 0;
68169 }
68170
68171 - seq_printf(m, "%p", class->key);
68172 + seq_printf(m, "%pK", class->key);
68173 #ifdef CONFIG_DEBUG_LOCKDEP
68174 seq_printf(m, " OPS:%8ld", class->ops);
68175 #endif
68176 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
68177
68178 list_for_each_entry(entry, &class->locks_after, entry) {
68179 if (entry->distance == 1) {
68180 - seq_printf(m, " -> [%p] ", entry->class->key);
68181 + seq_printf(m, " -> [%pK] ", entry->class->key);
68182 print_name(m, entry->class);
68183 seq_puts(m, "\n");
68184 }
68185 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
68186 if (!class->key)
68187 continue;
68188
68189 - seq_printf(m, "[%p] ", class->key);
68190 + seq_printf(m, "[%pK] ", class->key);
68191 print_name(m, class);
68192 seq_puts(m, "\n");
68193 }
68194 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68195 if (!i)
68196 seq_line(m, '-', 40-namelen, namelen);
68197
68198 - snprintf(ip, sizeof(ip), "[<%p>]",
68199 + snprintf(ip, sizeof(ip), "[<%pK>]",
68200 (void *)class->contention_point[i]);
68201 seq_printf(m, "%40s %14lu %29s %pS\n",
68202 name, stats->contention_point[i],
68203 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
68204 if (!i)
68205 seq_line(m, '-', 40-namelen, namelen);
68206
68207 - snprintf(ip, sizeof(ip), "[<%p>]",
68208 + snprintf(ip, sizeof(ip), "[<%pK>]",
68209 (void *)class->contending_point[i]);
68210 seq_printf(m, "%40s %14lu %29s %pS\n",
68211 name, stats->contending_point[i],
68212 diff --git a/kernel/module.c b/kernel/module.c
68213 index 9ad9ee9..de7a157 100644
68214 --- a/kernel/module.c
68215 +++ b/kernel/module.c
68216 @@ -58,6 +58,7 @@
68217 #include <linux/jump_label.h>
68218 #include <linux/pfn.h>
68219 #include <linux/bsearch.h>
68220 +#include <linux/grsecurity.h>
68221
68222 #define CREATE_TRACE_POINTS
68223 #include <trace/events/module.h>
68224 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68225
68226 /* Bounds of module allocation, for speeding __module_address.
68227 * Protected by module_mutex. */
68228 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68229 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68230 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68231
68232 int register_module_notifier(struct notifier_block * nb)
68233 {
68234 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68235 return true;
68236
68237 list_for_each_entry_rcu(mod, &modules, list) {
68238 - struct symsearch arr[] = {
68239 + struct symsearch modarr[] = {
68240 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68241 NOT_GPL_ONLY, false },
68242 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68243 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68244 #endif
68245 };
68246
68247 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68248 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68249 return true;
68250 }
68251 return false;
68252 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68253 static int percpu_modalloc(struct module *mod,
68254 unsigned long size, unsigned long align)
68255 {
68256 - if (align > PAGE_SIZE) {
68257 + if (align-1 >= PAGE_SIZE) {
68258 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68259 mod->name, align, PAGE_SIZE);
68260 align = PAGE_SIZE;
68261 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68262 static ssize_t show_coresize(struct module_attribute *mattr,
68263 struct module_kobject *mk, char *buffer)
68264 {
68265 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68266 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68267 }
68268
68269 static struct module_attribute modinfo_coresize =
68270 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68271 static ssize_t show_initsize(struct module_attribute *mattr,
68272 struct module_kobject *mk, char *buffer)
68273 {
68274 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68275 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68276 }
68277
68278 static struct module_attribute modinfo_initsize =
68279 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68280 */
68281 #ifdef CONFIG_SYSFS
68282
68283 -#ifdef CONFIG_KALLSYMS
68284 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68285 static inline bool sect_empty(const Elf_Shdr *sect)
68286 {
68287 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68288 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68289
68290 static void unset_module_core_ro_nx(struct module *mod)
68291 {
68292 - set_page_attributes(mod->module_core + mod->core_text_size,
68293 - mod->module_core + mod->core_size,
68294 + set_page_attributes(mod->module_core_rw,
68295 + mod->module_core_rw + mod->core_size_rw,
68296 set_memory_x);
68297 - set_page_attributes(mod->module_core,
68298 - mod->module_core + mod->core_ro_size,
68299 + set_page_attributes(mod->module_core_rx,
68300 + mod->module_core_rx + mod->core_size_rx,
68301 set_memory_rw);
68302 }
68303
68304 static void unset_module_init_ro_nx(struct module *mod)
68305 {
68306 - set_page_attributes(mod->module_init + mod->init_text_size,
68307 - mod->module_init + mod->init_size,
68308 + set_page_attributes(mod->module_init_rw,
68309 + mod->module_init_rw + mod->init_size_rw,
68310 set_memory_x);
68311 - set_page_attributes(mod->module_init,
68312 - mod->module_init + mod->init_ro_size,
68313 + set_page_attributes(mod->module_init_rx,
68314 + mod->module_init_rx + mod->init_size_rx,
68315 set_memory_rw);
68316 }
68317
68318 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68319
68320 mutex_lock(&module_mutex);
68321 list_for_each_entry_rcu(mod, &modules, list) {
68322 - if ((mod->module_core) && (mod->core_text_size)) {
68323 - set_page_attributes(mod->module_core,
68324 - mod->module_core + mod->core_text_size,
68325 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68326 + set_page_attributes(mod->module_core_rx,
68327 + mod->module_core_rx + mod->core_size_rx,
68328 set_memory_rw);
68329 }
68330 - if ((mod->module_init) && (mod->init_text_size)) {
68331 - set_page_attributes(mod->module_init,
68332 - mod->module_init + mod->init_text_size,
68333 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68334 + set_page_attributes(mod->module_init_rx,
68335 + mod->module_init_rx + mod->init_size_rx,
68336 set_memory_rw);
68337 }
68338 }
68339 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68340
68341 mutex_lock(&module_mutex);
68342 list_for_each_entry_rcu(mod, &modules, list) {
68343 - if ((mod->module_core) && (mod->core_text_size)) {
68344 - set_page_attributes(mod->module_core,
68345 - mod->module_core + mod->core_text_size,
68346 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68347 + set_page_attributes(mod->module_core_rx,
68348 + mod->module_core_rx + mod->core_size_rx,
68349 set_memory_ro);
68350 }
68351 - if ((mod->module_init) && (mod->init_text_size)) {
68352 - set_page_attributes(mod->module_init,
68353 - mod->module_init + mod->init_text_size,
68354 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68355 + set_page_attributes(mod->module_init_rx,
68356 + mod->module_init_rx + mod->init_size_rx,
68357 set_memory_ro);
68358 }
68359 }
68360 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68361
68362 /* This may be NULL, but that's OK */
68363 unset_module_init_ro_nx(mod);
68364 - module_free(mod, mod->module_init);
68365 + module_free(mod, mod->module_init_rw);
68366 + module_free_exec(mod, mod->module_init_rx);
68367 kfree(mod->args);
68368 percpu_modfree(mod);
68369
68370 /* Free lock-classes: */
68371 - lockdep_free_key_range(mod->module_core, mod->core_size);
68372 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68373 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68374
68375 /* Finally, free the core (containing the module structure) */
68376 unset_module_core_ro_nx(mod);
68377 - module_free(mod, mod->module_core);
68378 + module_free_exec(mod, mod->module_core_rx);
68379 + module_free(mod, mod->module_core_rw);
68380
68381 #ifdef CONFIG_MPU
68382 update_protections(current->mm);
68383 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68384 int ret = 0;
68385 const struct kernel_symbol *ksym;
68386
68387 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68388 + int is_fs_load = 0;
68389 + int register_filesystem_found = 0;
68390 + char *p;
68391 +
68392 + p = strstr(mod->args, "grsec_modharden_fs");
68393 + if (p) {
68394 + char *endptr = p + strlen("grsec_modharden_fs");
68395 + /* copy \0 as well */
68396 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68397 + is_fs_load = 1;
68398 + }
68399 +#endif
68400 +
68401 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68402 const char *name = info->strtab + sym[i].st_name;
68403
68404 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68405 + /* it's a real shame this will never get ripped and copied
68406 + upstream! ;(
68407 + */
68408 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68409 + register_filesystem_found = 1;
68410 +#endif
68411 +
68412 switch (sym[i].st_shndx) {
68413 case SHN_COMMON:
68414 /* We compiled with -fno-common. These are not
68415 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68416 ksym = resolve_symbol_wait(mod, info, name);
68417 /* Ok if resolved. */
68418 if (ksym && !IS_ERR(ksym)) {
68419 + pax_open_kernel();
68420 sym[i].st_value = ksym->value;
68421 + pax_close_kernel();
68422 break;
68423 }
68424
68425 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68426 secbase = (unsigned long)mod_percpu(mod);
68427 else
68428 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68429 + pax_open_kernel();
68430 sym[i].st_value += secbase;
68431 + pax_close_kernel();
68432 break;
68433 }
68434 }
68435
68436 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68437 + if (is_fs_load && !register_filesystem_found) {
68438 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68439 + ret = -EPERM;
68440 + }
68441 +#endif
68442 +
68443 return ret;
68444 }
68445
68446 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68447 || s->sh_entsize != ~0UL
68448 || strstarts(sname, ".init"))
68449 continue;
68450 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68451 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68452 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68453 + else
68454 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68455 pr_debug("\t%s\n", sname);
68456 }
68457 - switch (m) {
68458 - case 0: /* executable */
68459 - mod->core_size = debug_align(mod->core_size);
68460 - mod->core_text_size = mod->core_size;
68461 - break;
68462 - case 1: /* RO: text and ro-data */
68463 - mod->core_size = debug_align(mod->core_size);
68464 - mod->core_ro_size = mod->core_size;
68465 - break;
68466 - case 3: /* whole core */
68467 - mod->core_size = debug_align(mod->core_size);
68468 - break;
68469 - }
68470 }
68471
68472 pr_debug("Init section allocation order:\n");
68473 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68474 || s->sh_entsize != ~0UL
68475 || !strstarts(sname, ".init"))
68476 continue;
68477 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68478 - | INIT_OFFSET_MASK);
68479 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68480 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68481 + else
68482 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68483 + s->sh_entsize |= INIT_OFFSET_MASK;
68484 pr_debug("\t%s\n", sname);
68485 }
68486 - switch (m) {
68487 - case 0: /* executable */
68488 - mod->init_size = debug_align(mod->init_size);
68489 - mod->init_text_size = mod->init_size;
68490 - break;
68491 - case 1: /* RO: text and ro-data */
68492 - mod->init_size = debug_align(mod->init_size);
68493 - mod->init_ro_size = mod->init_size;
68494 - break;
68495 - case 3: /* whole init */
68496 - mod->init_size = debug_align(mod->init_size);
68497 - break;
68498 - }
68499 }
68500 }
68501
68502 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68503
68504 /* Put symbol section at end of init part of module. */
68505 symsect->sh_flags |= SHF_ALLOC;
68506 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68507 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68508 info->index.sym) | INIT_OFFSET_MASK;
68509 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68510
68511 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68512 }
68513
68514 /* Append room for core symbols at end of core part. */
68515 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68516 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68517 - mod->core_size += strtab_size;
68518 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68519 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68520 + mod->core_size_rx += strtab_size;
68521
68522 /* Put string table section at end of init part of module. */
68523 strsect->sh_flags |= SHF_ALLOC;
68524 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68525 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68526 info->index.str) | INIT_OFFSET_MASK;
68527 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68528 }
68529 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68530 /* Make sure we get permanent strtab: don't use info->strtab. */
68531 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68532
68533 + pax_open_kernel();
68534 +
68535 /* Set types up while we still have access to sections. */
68536 for (i = 0; i < mod->num_symtab; i++)
68537 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68538
68539 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68540 - mod->core_strtab = s = mod->module_core + info->stroffs;
68541 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68542 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68543 src = mod->symtab;
68544 *dst = *src;
68545 *s++ = 0;
68546 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68547 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68548 }
68549 mod->core_num_syms = ndst;
68550 +
68551 + pax_close_kernel();
68552 }
68553 #else
68554 static inline void layout_symtab(struct module *mod, struct load_info *info)
68555 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68556 return size == 0 ? NULL : vmalloc_exec(size);
68557 }
68558
68559 -static void *module_alloc_update_bounds(unsigned long size)
68560 +static void *module_alloc_update_bounds_rw(unsigned long size)
68561 {
68562 void *ret = module_alloc(size);
68563
68564 if (ret) {
68565 mutex_lock(&module_mutex);
68566 /* Update module bounds. */
68567 - if ((unsigned long)ret < module_addr_min)
68568 - module_addr_min = (unsigned long)ret;
68569 - if ((unsigned long)ret + size > module_addr_max)
68570 - module_addr_max = (unsigned long)ret + size;
68571 + if ((unsigned long)ret < module_addr_min_rw)
68572 + module_addr_min_rw = (unsigned long)ret;
68573 + if ((unsigned long)ret + size > module_addr_max_rw)
68574 + module_addr_max_rw = (unsigned long)ret + size;
68575 + mutex_unlock(&module_mutex);
68576 + }
68577 + return ret;
68578 +}
68579 +
68580 +static void *module_alloc_update_bounds_rx(unsigned long size)
68581 +{
68582 + void *ret = module_alloc_exec(size);
68583 +
68584 + if (ret) {
68585 + mutex_lock(&module_mutex);
68586 + /* Update module bounds. */
68587 + if ((unsigned long)ret < module_addr_min_rx)
68588 + module_addr_min_rx = (unsigned long)ret;
68589 + if ((unsigned long)ret + size > module_addr_max_rx)
68590 + module_addr_max_rx = (unsigned long)ret + size;
68591 mutex_unlock(&module_mutex);
68592 }
68593 return ret;
68594 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68595 static int check_modinfo(struct module *mod, struct load_info *info)
68596 {
68597 const char *modmagic = get_modinfo(info, "vermagic");
68598 + const char *license = get_modinfo(info, "license");
68599 int err;
68600
68601 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68602 + if (!license || !license_is_gpl_compatible(license))
68603 + return -ENOEXEC;
68604 +#endif
68605 +
68606 /* This is allowed: modprobe --force will invalidate it. */
68607 if (!modmagic) {
68608 err = try_to_force_load(mod, "bad vermagic");
68609 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68610 }
68611
68612 /* Set up license info based on the info section */
68613 - set_license(mod, get_modinfo(info, "license"));
68614 + set_license(mod, license);
68615
68616 return 0;
68617 }
68618 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68619 void *ptr;
68620
68621 /* Do the allocs. */
68622 - ptr = module_alloc_update_bounds(mod->core_size);
68623 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68624 /*
68625 * The pointer to this block is stored in the module structure
68626 * which is inside the block. Just mark it as not being a
68627 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68628 if (!ptr)
68629 return -ENOMEM;
68630
68631 - memset(ptr, 0, mod->core_size);
68632 - mod->module_core = ptr;
68633 + memset(ptr, 0, mod->core_size_rw);
68634 + mod->module_core_rw = ptr;
68635
68636 - ptr = module_alloc_update_bounds(mod->init_size);
68637 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68638 /*
68639 * The pointer to this block is stored in the module structure
68640 * which is inside the block. This block doesn't need to be
68641 * scanned as it contains data and code that will be freed
68642 * after the module is initialized.
68643 */
68644 - kmemleak_ignore(ptr);
68645 - if (!ptr && mod->init_size) {
68646 - module_free(mod, mod->module_core);
68647 + kmemleak_not_leak(ptr);
68648 + if (!ptr && mod->init_size_rw) {
68649 + module_free(mod, mod->module_core_rw);
68650 return -ENOMEM;
68651 }
68652 - memset(ptr, 0, mod->init_size);
68653 - mod->module_init = ptr;
68654 + memset(ptr, 0, mod->init_size_rw);
68655 + mod->module_init_rw = ptr;
68656 +
68657 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68658 + kmemleak_not_leak(ptr);
68659 + if (!ptr) {
68660 + module_free(mod, mod->module_init_rw);
68661 + module_free(mod, mod->module_core_rw);
68662 + return -ENOMEM;
68663 + }
68664 +
68665 + pax_open_kernel();
68666 + memset(ptr, 0, mod->core_size_rx);
68667 + pax_close_kernel();
68668 + mod->module_core_rx = ptr;
68669 +
68670 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68671 + kmemleak_not_leak(ptr);
68672 + if (!ptr && mod->init_size_rx) {
68673 + module_free_exec(mod, mod->module_core_rx);
68674 + module_free(mod, mod->module_init_rw);
68675 + module_free(mod, mod->module_core_rw);
68676 + return -ENOMEM;
68677 + }
68678 +
68679 + pax_open_kernel();
68680 + memset(ptr, 0, mod->init_size_rx);
68681 + pax_close_kernel();
68682 + mod->module_init_rx = ptr;
68683
68684 /* Transfer each section which specifies SHF_ALLOC */
68685 pr_debug("final section addresses:\n");
68686 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68687 if (!(shdr->sh_flags & SHF_ALLOC))
68688 continue;
68689
68690 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68691 - dest = mod->module_init
68692 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68693 - else
68694 - dest = mod->module_core + shdr->sh_entsize;
68695 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68696 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68697 + dest = mod->module_init_rw
68698 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68699 + else
68700 + dest = mod->module_init_rx
68701 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68702 + } else {
68703 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68704 + dest = mod->module_core_rw + shdr->sh_entsize;
68705 + else
68706 + dest = mod->module_core_rx + shdr->sh_entsize;
68707 + }
68708 +
68709 + if (shdr->sh_type != SHT_NOBITS) {
68710 +
68711 +#ifdef CONFIG_PAX_KERNEXEC
68712 +#ifdef CONFIG_X86_64
68713 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68714 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68715 +#endif
68716 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68717 + pax_open_kernel();
68718 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68719 + pax_close_kernel();
68720 + } else
68721 +#endif
68722
68723 - if (shdr->sh_type != SHT_NOBITS)
68724 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68725 + }
68726 /* Update sh_addr to point to copy in image. */
68727 - shdr->sh_addr = (unsigned long)dest;
68728 +
68729 +#ifdef CONFIG_PAX_KERNEXEC
68730 + if (shdr->sh_flags & SHF_EXECINSTR)
68731 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68732 + else
68733 +#endif
68734 +
68735 + shdr->sh_addr = (unsigned long)dest;
68736 pr_debug("\t0x%lx %s\n",
68737 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68738 }
68739 @@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68740 * Do it before processing of module parameters, so the module
68741 * can provide parameter accessor functions of its own.
68742 */
68743 - if (mod->module_init)
68744 - flush_icache_range((unsigned long)mod->module_init,
68745 - (unsigned long)mod->module_init
68746 - + mod->init_size);
68747 - flush_icache_range((unsigned long)mod->module_core,
68748 - (unsigned long)mod->module_core + mod->core_size);
68749 + if (mod->module_init_rx)
68750 + flush_icache_range((unsigned long)mod->module_init_rx,
68751 + (unsigned long)mod->module_init_rx
68752 + + mod->init_size_rx);
68753 + flush_icache_range((unsigned long)mod->module_core_rx,
68754 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68755
68756 set_fs(old_fs);
68757 }
68758 @@ -2838,8 +2938,10 @@ out:
68759 static void module_deallocate(struct module *mod, struct load_info *info)
68760 {
68761 percpu_modfree(mod);
68762 - module_free(mod, mod->module_init);
68763 - module_free(mod, mod->module_core);
68764 + module_free_exec(mod, mod->module_init_rx);
68765 + module_free_exec(mod, mod->module_core_rx);
68766 + module_free(mod, mod->module_init_rw);
68767 + module_free(mod, mod->module_core_rw);
68768 }
68769
68770 int __weak module_finalize(const Elf_Ehdr *hdr,
68771 @@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68772 static int post_relocation(struct module *mod, const struct load_info *info)
68773 {
68774 /* Sort exception table now relocations are done. */
68775 + pax_open_kernel();
68776 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68777 + pax_close_kernel();
68778
68779 /* Copy relocated percpu area over. */
68780 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68781 @@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68782 if (err)
68783 goto free_unload;
68784
68785 + /* Now copy in args */
68786 + mod->args = strndup_user(uargs, ~0UL >> 1);
68787 + if (IS_ERR(mod->args)) {
68788 + err = PTR_ERR(mod->args);
68789 + goto free_unload;
68790 + }
68791 +
68792 /* Set up MODINFO_ATTR fields */
68793 setup_modinfo(mod, &info);
68794
68795 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68796 + {
68797 + char *p, *p2;
68798 +
68799 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68800 + 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);
68801 + err = -EPERM;
68802 + goto free_modinfo;
68803 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68804 + p += strlen("grsec_modharden_normal");
68805 + p2 = strstr(p, "_");
68806 + if (p2) {
68807 + *p2 = '\0';
68808 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68809 + *p2 = '_';
68810 + }
68811 + err = -EPERM;
68812 + goto free_modinfo;
68813 + }
68814 + }
68815 +#endif
68816 +
68817 /* Fix up syms, so that st_value is a pointer to location. */
68818 err = simplify_symbols(mod, &info);
68819 if (err < 0)
68820 @@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68821
68822 flush_module_icache(mod);
68823
68824 - /* Now copy in args */
68825 - mod->args = strndup_user(uargs, ~0UL >> 1);
68826 - if (IS_ERR(mod->args)) {
68827 - err = PTR_ERR(mod->args);
68828 - goto free_arch_cleanup;
68829 - }
68830 -
68831 /* Mark state as coming so strong_try_module_get() ignores us. */
68832 mod->state = MODULE_STATE_COMING;
68833
68834 @@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68835 unlock:
68836 mutex_unlock(&module_mutex);
68837 synchronize_sched();
68838 - kfree(mod->args);
68839 - free_arch_cleanup:
68840 module_arch_cleanup(mod);
68841 free_modinfo:
68842 free_modinfo(mod);
68843 + kfree(mod->args);
68844 free_unload:
68845 module_unload_free(mod);
68846 free_module:
68847 @@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68848 MODULE_STATE_COMING, mod);
68849
68850 /* Set RO and NX regions for core */
68851 - set_section_ro_nx(mod->module_core,
68852 - mod->core_text_size,
68853 - mod->core_ro_size,
68854 - mod->core_size);
68855 + set_section_ro_nx(mod->module_core_rx,
68856 + mod->core_size_rx,
68857 + mod->core_size_rx,
68858 + mod->core_size_rx);
68859
68860 /* Set RO and NX regions for init */
68861 - set_section_ro_nx(mod->module_init,
68862 - mod->init_text_size,
68863 - mod->init_ro_size,
68864 - mod->init_size);
68865 + set_section_ro_nx(mod->module_init_rx,
68866 + mod->init_size_rx,
68867 + mod->init_size_rx,
68868 + mod->init_size_rx);
68869
68870 do_mod_ctors(mod);
68871 /* Start the module */
68872 @@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68873 mod->strtab = mod->core_strtab;
68874 #endif
68875 unset_module_init_ro_nx(mod);
68876 - module_free(mod, mod->module_init);
68877 - mod->module_init = NULL;
68878 - mod->init_size = 0;
68879 - mod->init_ro_size = 0;
68880 - mod->init_text_size = 0;
68881 + module_free(mod, mod->module_init_rw);
68882 + module_free_exec(mod, mod->module_init_rx);
68883 + mod->module_init_rw = NULL;
68884 + mod->module_init_rx = NULL;
68885 + mod->init_size_rw = 0;
68886 + mod->init_size_rx = 0;
68887 mutex_unlock(&module_mutex);
68888
68889 return 0;
68890 @@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68891 unsigned long nextval;
68892
68893 /* At worse, next value is at end of module */
68894 - if (within_module_init(addr, mod))
68895 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68896 + if (within_module_init_rx(addr, mod))
68897 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68898 + else if (within_module_init_rw(addr, mod))
68899 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68900 + else if (within_module_core_rx(addr, mod))
68901 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68902 + else if (within_module_core_rw(addr, mod))
68903 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68904 else
68905 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68906 + return NULL;
68907
68908 /* Scan for closest preceding symbol, and next symbol. (ELF
68909 starts real symbols at 1). */
68910 @@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68911 char buf[8];
68912
68913 seq_printf(m, "%s %u",
68914 - mod->name, mod->init_size + mod->core_size);
68915 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68916 print_unload_info(m, mod);
68917
68918 /* Informative for users. */
68919 @@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68920 mod->state == MODULE_STATE_COMING ? "Loading":
68921 "Live");
68922 /* Used by oprofile and other similar tools. */
68923 - seq_printf(m, " 0x%pK", mod->module_core);
68924 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68925
68926 /* Taints info */
68927 if (mod->taints)
68928 @@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68929
68930 static int __init proc_modules_init(void)
68931 {
68932 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68933 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68934 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68935 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68936 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68937 +#else
68938 proc_create("modules", 0, NULL, &proc_modules_operations);
68939 +#endif
68940 +#else
68941 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68942 +#endif
68943 return 0;
68944 }
68945 module_init(proc_modules_init);
68946 @@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68947 {
68948 struct module *mod;
68949
68950 - if (addr < module_addr_min || addr > module_addr_max)
68951 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68952 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68953 return NULL;
68954
68955 list_for_each_entry_rcu(mod, &modules, list)
68956 - if (within_module_core(addr, mod)
68957 - || within_module_init(addr, mod))
68958 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68959 return mod;
68960 return NULL;
68961 }
68962 @@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68963 */
68964 struct module *__module_text_address(unsigned long addr)
68965 {
68966 - struct module *mod = __module_address(addr);
68967 + struct module *mod;
68968 +
68969 +#ifdef CONFIG_X86_32
68970 + addr = ktla_ktva(addr);
68971 +#endif
68972 +
68973 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68974 + return NULL;
68975 +
68976 + mod = __module_address(addr);
68977 +
68978 if (mod) {
68979 /* Make sure it's within the text section. */
68980 - if (!within(addr, mod->module_init, mod->init_text_size)
68981 - && !within(addr, mod->module_core, mod->core_text_size))
68982 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68983 mod = NULL;
68984 }
68985 return mod;
68986 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68987 index 7e3443f..b2a1e6b 100644
68988 --- a/kernel/mutex-debug.c
68989 +++ b/kernel/mutex-debug.c
68990 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68991 }
68992
68993 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68994 - struct thread_info *ti)
68995 + struct task_struct *task)
68996 {
68997 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68998
68999 /* Mark the current thread as blocked on the lock: */
69000 - ti->task->blocked_on = waiter;
69001 + task->blocked_on = waiter;
69002 }
69003
69004 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69005 - struct thread_info *ti)
69006 + struct task_struct *task)
69007 {
69008 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
69009 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
69010 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
69011 - ti->task->blocked_on = NULL;
69012 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
69013 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
69014 + task->blocked_on = NULL;
69015
69016 list_del_init(&waiter->list);
69017 waiter->task = NULL;
69018 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
69019 index 0799fd3..d06ae3b 100644
69020 --- a/kernel/mutex-debug.h
69021 +++ b/kernel/mutex-debug.h
69022 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
69023 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
69024 extern void debug_mutex_add_waiter(struct mutex *lock,
69025 struct mutex_waiter *waiter,
69026 - struct thread_info *ti);
69027 + struct task_struct *task);
69028 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
69029 - struct thread_info *ti);
69030 + struct task_struct *task);
69031 extern void debug_mutex_unlock(struct mutex *lock);
69032 extern void debug_mutex_init(struct mutex *lock, const char *name,
69033 struct lock_class_key *key);
69034 diff --git a/kernel/mutex.c b/kernel/mutex.c
69035 index a307cc9..27fd2e9 100644
69036 --- a/kernel/mutex.c
69037 +++ b/kernel/mutex.c
69038 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69039 spin_lock_mutex(&lock->wait_lock, flags);
69040
69041 debug_mutex_lock_common(lock, &waiter);
69042 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
69043 + debug_mutex_add_waiter(lock, &waiter, task);
69044
69045 /* add waiting tasks to the end of the waitqueue (FIFO): */
69046 list_add_tail(&waiter.list, &lock->wait_list);
69047 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69048 * TASK_UNINTERRUPTIBLE case.)
69049 */
69050 if (unlikely(signal_pending_state(state, task))) {
69051 - mutex_remove_waiter(lock, &waiter,
69052 - task_thread_info(task));
69053 + mutex_remove_waiter(lock, &waiter, task);
69054 mutex_release(&lock->dep_map, 1, ip);
69055 spin_unlock_mutex(&lock->wait_lock, flags);
69056
69057 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
69058 done:
69059 lock_acquired(&lock->dep_map, ip);
69060 /* got the lock - rejoice! */
69061 - mutex_remove_waiter(lock, &waiter, current_thread_info());
69062 + mutex_remove_waiter(lock, &waiter, task);
69063 mutex_set_owner(lock);
69064
69065 /* set it to 0 if there are no waiters left: */
69066 diff --git a/kernel/panic.c b/kernel/panic.c
69067 index e1b2822..5edc1d9 100644
69068 --- a/kernel/panic.c
69069 +++ b/kernel/panic.c
69070 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
69071 const char *board;
69072
69073 printk(KERN_WARNING "------------[ cut here ]------------\n");
69074 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
69075 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
69076 board = dmi_get_system_info(DMI_PRODUCT_NAME);
69077 if (board)
69078 printk(KERN_WARNING "Hardware name: %s\n", board);
69079 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
69080 */
69081 void __stack_chk_fail(void)
69082 {
69083 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
69084 + dump_stack();
69085 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
69086 __builtin_return_address(0));
69087 }
69088 EXPORT_SYMBOL(__stack_chk_fail);
69089 diff --git a/kernel/pid.c b/kernel/pid.c
69090 index e86b291a..e8b0fb5 100644
69091 --- a/kernel/pid.c
69092 +++ b/kernel/pid.c
69093 @@ -33,6 +33,7 @@
69094 #include <linux/rculist.h>
69095 #include <linux/bootmem.h>
69096 #include <linux/hash.h>
69097 +#include <linux/security.h>
69098 #include <linux/pid_namespace.h>
69099 #include <linux/init_task.h>
69100 #include <linux/syscalls.h>
69101 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
69102
69103 int pid_max = PID_MAX_DEFAULT;
69104
69105 -#define RESERVED_PIDS 300
69106 +#define RESERVED_PIDS 500
69107
69108 int pid_max_min = RESERVED_PIDS + 1;
69109 int pid_max_max = PID_MAX_LIMIT;
69110 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
69111 */
69112 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
69113 {
69114 + struct task_struct *task;
69115 +
69116 rcu_lockdep_assert(rcu_read_lock_held(),
69117 "find_task_by_pid_ns() needs rcu_read_lock()"
69118 " protection");
69119 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69120 +
69121 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
69122 +
69123 + if (gr_pid_is_chrooted(task))
69124 + return NULL;
69125 +
69126 + return task;
69127 }
69128
69129 struct task_struct *find_task_by_vpid(pid_t vnr)
69130 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69131 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69132 }
69133
69134 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69135 +{
69136 + rcu_lockdep_assert(rcu_read_lock_held(),
69137 + "find_task_by_pid_ns() needs rcu_read_lock()"
69138 + " protection");
69139 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69140 +}
69141 +
69142 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69143 {
69144 struct pid *pid;
69145 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69146 index 125cb67..a4d1c30 100644
69147 --- a/kernel/posix-cpu-timers.c
69148 +++ b/kernel/posix-cpu-timers.c
69149 @@ -6,6 +6,7 @@
69150 #include <linux/posix-timers.h>
69151 #include <linux/errno.h>
69152 #include <linux/math64.h>
69153 +#include <linux/security.h>
69154 #include <asm/uaccess.h>
69155 #include <linux/kernel_stat.h>
69156 #include <trace/events/timer.h>
69157 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69158
69159 static __init int init_posix_cpu_timers(void)
69160 {
69161 - struct k_clock process = {
69162 + static struct k_clock process = {
69163 .clock_getres = process_cpu_clock_getres,
69164 .clock_get = process_cpu_clock_get,
69165 .timer_create = process_cpu_timer_create,
69166 .nsleep = process_cpu_nsleep,
69167 .nsleep_restart = process_cpu_nsleep_restart,
69168 };
69169 - struct k_clock thread = {
69170 + static struct k_clock thread = {
69171 .clock_getres = thread_cpu_clock_getres,
69172 .clock_get = thread_cpu_clock_get,
69173 .timer_create = thread_cpu_timer_create,
69174 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69175 index 69185ae..cc2847a 100644
69176 --- a/kernel/posix-timers.c
69177 +++ b/kernel/posix-timers.c
69178 @@ -43,6 +43,7 @@
69179 #include <linux/idr.h>
69180 #include <linux/posix-clock.h>
69181 #include <linux/posix-timers.h>
69182 +#include <linux/grsecurity.h>
69183 #include <linux/syscalls.h>
69184 #include <linux/wait.h>
69185 #include <linux/workqueue.h>
69186 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69187 * which we beg off on and pass to do_sys_settimeofday().
69188 */
69189
69190 -static struct k_clock posix_clocks[MAX_CLOCKS];
69191 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69192
69193 /*
69194 * These ones are defined below.
69195 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69196 */
69197 static __init int init_posix_timers(void)
69198 {
69199 - struct k_clock clock_realtime = {
69200 + static struct k_clock clock_realtime = {
69201 .clock_getres = hrtimer_get_res,
69202 .clock_get = posix_clock_realtime_get,
69203 .clock_set = posix_clock_realtime_set,
69204 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69205 .timer_get = common_timer_get,
69206 .timer_del = common_timer_del,
69207 };
69208 - struct k_clock clock_monotonic = {
69209 + static struct k_clock clock_monotonic = {
69210 .clock_getres = hrtimer_get_res,
69211 .clock_get = posix_ktime_get_ts,
69212 .nsleep = common_nsleep,
69213 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69214 .timer_get = common_timer_get,
69215 .timer_del = common_timer_del,
69216 };
69217 - struct k_clock clock_monotonic_raw = {
69218 + static struct k_clock clock_monotonic_raw = {
69219 .clock_getres = hrtimer_get_res,
69220 .clock_get = posix_get_monotonic_raw,
69221 };
69222 - struct k_clock clock_realtime_coarse = {
69223 + static struct k_clock clock_realtime_coarse = {
69224 .clock_getres = posix_get_coarse_res,
69225 .clock_get = posix_get_realtime_coarse,
69226 };
69227 - struct k_clock clock_monotonic_coarse = {
69228 + static struct k_clock clock_monotonic_coarse = {
69229 .clock_getres = posix_get_coarse_res,
69230 .clock_get = posix_get_monotonic_coarse,
69231 };
69232 - struct k_clock clock_boottime = {
69233 + static struct k_clock clock_boottime = {
69234 .clock_getres = hrtimer_get_res,
69235 .clock_get = posix_get_boottime,
69236 .nsleep = common_nsleep,
69237 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69238 return;
69239 }
69240
69241 - posix_clocks[clock_id] = *new_clock;
69242 + posix_clocks[clock_id] = new_clock;
69243 }
69244 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69245
69246 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69247 return (id & CLOCKFD_MASK) == CLOCKFD ?
69248 &clock_posix_dynamic : &clock_posix_cpu;
69249
69250 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69251 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69252 return NULL;
69253 - return &posix_clocks[id];
69254 + return posix_clocks[id];
69255 }
69256
69257 static int common_timer_create(struct k_itimer *new_timer)
69258 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69259 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69260 return -EFAULT;
69261
69262 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69263 + have their clock_set fptr set to a nosettime dummy function
69264 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69265 + call common_clock_set, which calls do_sys_settimeofday, which
69266 + we hook
69267 + */
69268 +
69269 return kc->clock_set(which_clock, &new_tp);
69270 }
69271
69272 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69273 index d523593..68197a4 100644
69274 --- a/kernel/power/poweroff.c
69275 +++ b/kernel/power/poweroff.c
69276 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69277 .enable_mask = SYSRQ_ENABLE_BOOT,
69278 };
69279
69280 -static int pm_sysrq_init(void)
69281 +static int __init pm_sysrq_init(void)
69282 {
69283 register_sysrq_key('o', &sysrq_poweroff_op);
69284 return 0;
69285 diff --git a/kernel/power/process.c b/kernel/power/process.c
69286 index 19db29f..33b52b6 100644
69287 --- a/kernel/power/process.c
69288 +++ b/kernel/power/process.c
69289 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69290 u64 elapsed_csecs64;
69291 unsigned int elapsed_csecs;
69292 bool wakeup = false;
69293 + bool timedout = false;
69294
69295 do_gettimeofday(&start);
69296
69297 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69298
69299 while (true) {
69300 todo = 0;
69301 + if (time_after(jiffies, end_time))
69302 + timedout = true;
69303 read_lock(&tasklist_lock);
69304 do_each_thread(g, p) {
69305 if (p == current || !freeze_task(p))
69306 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69307 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69308 * transition can't race with task state testing here.
69309 */
69310 - if (!task_is_stopped_or_traced(p) &&
69311 - !freezer_should_skip(p))
69312 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69313 todo++;
69314 + if (timedout) {
69315 + printk(KERN_ERR "Task refusing to freeze:\n");
69316 + sched_show_task(p);
69317 + }
69318 + }
69319 } while_each_thread(g, p);
69320 read_unlock(&tasklist_lock);
69321
69322 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69323 todo += wq_busy;
69324 }
69325
69326 - if (!todo || time_after(jiffies, end_time))
69327 + if (!todo || timedout)
69328 break;
69329
69330 if (pm_wakeup_pending()) {
69331 diff --git a/kernel/printk.c b/kernel/printk.c
69332 index 66a2ea3..10f3a01 100644
69333 --- a/kernel/printk.c
69334 +++ b/kernel/printk.c
69335 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69336 if (from_file && type != SYSLOG_ACTION_OPEN)
69337 return 0;
69338
69339 +#ifdef CONFIG_GRKERNSEC_DMESG
69340 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69341 + return -EPERM;
69342 +#endif
69343 +
69344 if (syslog_action_restricted(type)) {
69345 if (capable(CAP_SYSLOG))
69346 return 0;
69347 diff --git a/kernel/profile.c b/kernel/profile.c
69348 index 76b8e77..a2930e8 100644
69349 --- a/kernel/profile.c
69350 +++ b/kernel/profile.c
69351 @@ -39,7 +39,7 @@ struct profile_hit {
69352 /* Oprofile timer tick hook */
69353 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69354
69355 -static atomic_t *prof_buffer;
69356 +static atomic_unchecked_t *prof_buffer;
69357 static unsigned long prof_len, prof_shift;
69358
69359 int prof_on __read_mostly;
69360 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69361 hits[i].pc = 0;
69362 continue;
69363 }
69364 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69365 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69366 hits[i].hits = hits[i].pc = 0;
69367 }
69368 }
69369 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69370 * Add the current hit(s) and flush the write-queue out
69371 * to the global buffer:
69372 */
69373 - atomic_add(nr_hits, &prof_buffer[pc]);
69374 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69375 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69376 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69377 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69378 hits[i].pc = hits[i].hits = 0;
69379 }
69380 out:
69381 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69382 {
69383 unsigned long pc;
69384 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69385 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69386 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69387 }
69388 #endif /* !CONFIG_SMP */
69389
69390 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69391 return -EFAULT;
69392 buf++; p++; count--; read++;
69393 }
69394 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69395 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69396 if (copy_to_user(buf, (void *)pnt, count))
69397 return -EFAULT;
69398 read += count;
69399 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69400 }
69401 #endif
69402 profile_discard_flip_buffers();
69403 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69404 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69405 return count;
69406 }
69407
69408 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69409 index a232bb5..2a65ef9 100644
69410 --- a/kernel/ptrace.c
69411 +++ b/kernel/ptrace.c
69412 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69413
69414 if (seize)
69415 flags |= PT_SEIZED;
69416 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69417 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69418 flags |= PT_PTRACE_CAP;
69419 task->ptrace = flags;
69420
69421 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69422 break;
69423 return -EIO;
69424 }
69425 - if (copy_to_user(dst, buf, retval))
69426 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69427 return -EFAULT;
69428 copied += retval;
69429 src += retval;
69430 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69431 bool seized = child->ptrace & PT_SEIZED;
69432 int ret = -EIO;
69433 siginfo_t siginfo, *si;
69434 - void __user *datavp = (void __user *) data;
69435 + void __user *datavp = (__force void __user *) data;
69436 unsigned long __user *datalp = datavp;
69437 unsigned long flags;
69438
69439 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69440 goto out;
69441 }
69442
69443 + if (gr_handle_ptrace(child, request)) {
69444 + ret = -EPERM;
69445 + goto out_put_task_struct;
69446 + }
69447 +
69448 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69449 ret = ptrace_attach(child, request, addr, data);
69450 /*
69451 * Some architectures need to do book-keeping after
69452 * a ptrace attach.
69453 */
69454 - if (!ret)
69455 + if (!ret) {
69456 arch_ptrace_attach(child);
69457 + gr_audit_ptrace(child);
69458 + }
69459 goto out_put_task_struct;
69460 }
69461
69462 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69463 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69464 if (copied != sizeof(tmp))
69465 return -EIO;
69466 - return put_user(tmp, (unsigned long __user *)data);
69467 + return put_user(tmp, (__force unsigned long __user *)data);
69468 }
69469
69470 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69471 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69472 goto out;
69473 }
69474
69475 + if (gr_handle_ptrace(child, request)) {
69476 + ret = -EPERM;
69477 + goto out_put_task_struct;
69478 + }
69479 +
69480 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69481 ret = ptrace_attach(child, request, addr, data);
69482 /*
69483 * Some architectures need to do book-keeping after
69484 * a ptrace attach.
69485 */
69486 - if (!ret)
69487 + if (!ret) {
69488 arch_ptrace_attach(child);
69489 + gr_audit_ptrace(child);
69490 + }
69491 goto out_put_task_struct;
69492 }
69493
69494 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69495 index 547b1fe..65e874e 100644
69496 --- a/kernel/rcutiny.c
69497 +++ b/kernel/rcutiny.c
69498 @@ -46,7 +46,7 @@
69499 struct rcu_ctrlblk;
69500 static void invoke_rcu_callbacks(void);
69501 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69502 -static void rcu_process_callbacks(struct softirq_action *unused);
69503 +static void rcu_process_callbacks(void);
69504 static void __call_rcu(struct rcu_head *head,
69505 void (*func)(struct rcu_head *rcu),
69506 struct rcu_ctrlblk *rcp);
69507 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69508 rcu_is_callbacks_kthread()));
69509 }
69510
69511 -static void rcu_process_callbacks(struct softirq_action *unused)
69512 +static void rcu_process_callbacks(void)
69513 {
69514 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69515 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69516 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69517 index 918fd1e..85089bb 100644
69518 --- a/kernel/rcutiny_plugin.h
69519 +++ b/kernel/rcutiny_plugin.h
69520 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69521 have_rcu_kthread_work = morework;
69522 local_irq_restore(flags);
69523 if (work)
69524 - rcu_process_callbacks(NULL);
69525 + rcu_process_callbacks();
69526 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69527 }
69528
69529 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69530 index 25b1503..1988a74 100644
69531 --- a/kernel/rcutorture.c
69532 +++ b/kernel/rcutorture.c
69533 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69534 { 0 };
69535 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69536 { 0 };
69537 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69538 -static atomic_t n_rcu_torture_alloc;
69539 -static atomic_t n_rcu_torture_alloc_fail;
69540 -static atomic_t n_rcu_torture_free;
69541 -static atomic_t n_rcu_torture_mberror;
69542 -static atomic_t n_rcu_torture_error;
69543 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69544 +static atomic_unchecked_t n_rcu_torture_alloc;
69545 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69546 +static atomic_unchecked_t n_rcu_torture_free;
69547 +static atomic_unchecked_t n_rcu_torture_mberror;
69548 +static atomic_unchecked_t n_rcu_torture_error;
69549 static long n_rcu_torture_barrier_error;
69550 static long n_rcu_torture_boost_ktrerror;
69551 static long n_rcu_torture_boost_rterror;
69552 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69553
69554 spin_lock_bh(&rcu_torture_lock);
69555 if (list_empty(&rcu_torture_freelist)) {
69556 - atomic_inc(&n_rcu_torture_alloc_fail);
69557 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69558 spin_unlock_bh(&rcu_torture_lock);
69559 return NULL;
69560 }
69561 - atomic_inc(&n_rcu_torture_alloc);
69562 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69563 p = rcu_torture_freelist.next;
69564 list_del_init(p);
69565 spin_unlock_bh(&rcu_torture_lock);
69566 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69567 static void
69568 rcu_torture_free(struct rcu_torture *p)
69569 {
69570 - atomic_inc(&n_rcu_torture_free);
69571 + atomic_inc_unchecked(&n_rcu_torture_free);
69572 spin_lock_bh(&rcu_torture_lock);
69573 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69574 spin_unlock_bh(&rcu_torture_lock);
69575 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69576 i = rp->rtort_pipe_count;
69577 if (i > RCU_TORTURE_PIPE_LEN)
69578 i = RCU_TORTURE_PIPE_LEN;
69579 - atomic_inc(&rcu_torture_wcount[i]);
69580 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69581 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69582 rp->rtort_mbtest = 0;
69583 rcu_torture_free(rp);
69584 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69585 i = rp->rtort_pipe_count;
69586 if (i > RCU_TORTURE_PIPE_LEN)
69587 i = RCU_TORTURE_PIPE_LEN;
69588 - atomic_inc(&rcu_torture_wcount[i]);
69589 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69590 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69591 rp->rtort_mbtest = 0;
69592 list_del(&rp->rtort_free);
69593 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69594 i = old_rp->rtort_pipe_count;
69595 if (i > RCU_TORTURE_PIPE_LEN)
69596 i = RCU_TORTURE_PIPE_LEN;
69597 - atomic_inc(&rcu_torture_wcount[i]);
69598 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69599 old_rp->rtort_pipe_count++;
69600 cur_ops->deferred_free(old_rp);
69601 }
69602 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69603 }
69604 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69605 if (p->rtort_mbtest == 0)
69606 - atomic_inc(&n_rcu_torture_mberror);
69607 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69608 spin_lock(&rand_lock);
69609 cur_ops->read_delay(&rand);
69610 n_rcu_torture_timers++;
69611 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69612 }
69613 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69614 if (p->rtort_mbtest == 0)
69615 - atomic_inc(&n_rcu_torture_mberror);
69616 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69617 cur_ops->read_delay(&rand);
69618 preempt_disable();
69619 pipe_count = p->rtort_pipe_count;
69620 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69621 rcu_torture_current,
69622 rcu_torture_current_version,
69623 list_empty(&rcu_torture_freelist),
69624 - atomic_read(&n_rcu_torture_alloc),
69625 - atomic_read(&n_rcu_torture_alloc_fail),
69626 - atomic_read(&n_rcu_torture_free));
69627 + atomic_read_unchecked(&n_rcu_torture_alloc),
69628 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69629 + atomic_read_unchecked(&n_rcu_torture_free));
69630 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69631 - atomic_read(&n_rcu_torture_mberror),
69632 + atomic_read_unchecked(&n_rcu_torture_mberror),
69633 n_rcu_torture_boost_ktrerror,
69634 n_rcu_torture_boost_rterror);
69635 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69636 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69637 n_barrier_attempts,
69638 n_rcu_torture_barrier_error);
69639 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69640 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69641 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69642 n_rcu_torture_barrier_error != 0 ||
69643 n_rcu_torture_boost_ktrerror != 0 ||
69644 n_rcu_torture_boost_rterror != 0 ||
69645 n_rcu_torture_boost_failure != 0 ||
69646 i > 1) {
69647 cnt += sprintf(&page[cnt], "!!! ");
69648 - atomic_inc(&n_rcu_torture_error);
69649 + atomic_inc_unchecked(&n_rcu_torture_error);
69650 WARN_ON_ONCE(1);
69651 }
69652 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69653 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69654 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69655 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69656 cnt += sprintf(&page[cnt], " %d",
69657 - atomic_read(&rcu_torture_wcount[i]));
69658 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69659 }
69660 cnt += sprintf(&page[cnt], "\n");
69661 if (cur_ops->stats)
69662 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69663
69664 if (cur_ops->cleanup)
69665 cur_ops->cleanup();
69666 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69667 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69668 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69669 else if (n_online_successes != n_online_attempts ||
69670 n_offline_successes != n_offline_attempts)
69671 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69672
69673 rcu_torture_current = NULL;
69674 rcu_torture_current_version = 0;
69675 - atomic_set(&n_rcu_torture_alloc, 0);
69676 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69677 - atomic_set(&n_rcu_torture_free, 0);
69678 - atomic_set(&n_rcu_torture_mberror, 0);
69679 - atomic_set(&n_rcu_torture_error, 0);
69680 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69681 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69682 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69683 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69684 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69685 n_rcu_torture_barrier_error = 0;
69686 n_rcu_torture_boost_ktrerror = 0;
69687 n_rcu_torture_boost_rterror = 0;
69688 n_rcu_torture_boost_failure = 0;
69689 n_rcu_torture_boosts = 0;
69690 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69691 - atomic_set(&rcu_torture_wcount[i], 0);
69692 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69693 for_each_possible_cpu(cpu) {
69694 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69695 per_cpu(rcu_torture_count, cpu)[i] = 0;
69696 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69697 index f7bcd9e..8973e14 100644
69698 --- a/kernel/rcutree.c
69699 +++ b/kernel/rcutree.c
69700 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69701 rcu_prepare_for_idle(smp_processor_id());
69702 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69703 smp_mb__before_atomic_inc(); /* See above. */
69704 - atomic_inc(&rdtp->dynticks);
69705 + atomic_inc_unchecked(&rdtp->dynticks);
69706 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69707 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69708 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69709
69710 /*
69711 * The idle task is not permitted to enter the idle loop while
69712 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69713 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69714 {
69715 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69716 - atomic_inc(&rdtp->dynticks);
69717 + atomic_inc_unchecked(&rdtp->dynticks);
69718 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69719 smp_mb__after_atomic_inc(); /* See above. */
69720 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69721 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69722 rcu_cleanup_after_idle(smp_processor_id());
69723 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69724 if (!is_idle_task(current)) {
69725 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69726 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69727
69728 if (rdtp->dynticks_nmi_nesting == 0 &&
69729 - (atomic_read(&rdtp->dynticks) & 0x1))
69730 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69731 return;
69732 rdtp->dynticks_nmi_nesting++;
69733 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69734 - atomic_inc(&rdtp->dynticks);
69735 + atomic_inc_unchecked(&rdtp->dynticks);
69736 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69737 smp_mb__after_atomic_inc(); /* See above. */
69738 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69739 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69740 }
69741
69742 /**
69743 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69744 return;
69745 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69746 smp_mb__before_atomic_inc(); /* See above. */
69747 - atomic_inc(&rdtp->dynticks);
69748 + atomic_inc_unchecked(&rdtp->dynticks);
69749 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69750 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69751 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69752 }
69753
69754 /**
69755 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69756 int ret;
69757
69758 preempt_disable();
69759 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69760 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69761 preempt_enable();
69762 return ret;
69763 }
69764 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69765 */
69766 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69767 {
69768 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69769 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69770 return (rdp->dynticks_snap & 0x1) == 0;
69771 }
69772
69773 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69774 unsigned int curr;
69775 unsigned int snap;
69776
69777 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69778 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69779 snap = (unsigned int)rdp->dynticks_snap;
69780
69781 /*
69782 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69783 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69784 */
69785 if (till_stall_check < 3) {
69786 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69787 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69788 till_stall_check = 3;
69789 } else if (till_stall_check > 300) {
69790 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69791 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69792 till_stall_check = 300;
69793 }
69794 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69795 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69796 rsp->qlen += rdp->qlen;
69797 rdp->n_cbs_orphaned += rdp->qlen;
69798 rdp->qlen_lazy = 0;
69799 - ACCESS_ONCE(rdp->qlen) = 0;
69800 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69801 }
69802
69803 /*
69804 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69805 }
69806 smp_mb(); /* List handling before counting for rcu_barrier(). */
69807 rdp->qlen_lazy -= count_lazy;
69808 - ACCESS_ONCE(rdp->qlen) -= count;
69809 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69810 rdp->n_cbs_invoked += count;
69811
69812 /* Reinstate batch limit if we have worked down the excess. */
69813 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69814 /*
69815 * Do RCU core processing for the current CPU.
69816 */
69817 -static void rcu_process_callbacks(struct softirq_action *unused)
69818 +static void rcu_process_callbacks(void)
69819 {
69820 struct rcu_state *rsp;
69821
69822 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69823 rdp = this_cpu_ptr(rsp->rda);
69824
69825 /* Add the callback to our list. */
69826 - ACCESS_ONCE(rdp->qlen)++;
69827 + ACCESS_ONCE_RW(rdp->qlen)++;
69828 if (lazy)
69829 rdp->qlen_lazy++;
69830 else
69831 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69832 }
69833 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69834
69835 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69836 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69837 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69838 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69839
69840 static int synchronize_sched_expedited_cpu_stop(void *data)
69841 {
69842 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69843 int firstsnap, s, snap, trycount = 0;
69844
69845 /* Note that atomic_inc_return() implies full memory barrier. */
69846 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69847 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69848 get_online_cpus();
69849 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69850
69851 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69852 }
69853
69854 /* Check to see if someone else did our work for us. */
69855 - s = atomic_read(&sync_sched_expedited_done);
69856 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69857 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69858 smp_mb(); /* ensure test happens before caller kfree */
69859 return;
69860 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69861 * grace period works for us.
69862 */
69863 get_online_cpus();
69864 - snap = atomic_read(&sync_sched_expedited_started);
69865 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69866 smp_mb(); /* ensure read is before try_stop_cpus(). */
69867 }
69868
69869 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69870 * than we did beat us to the punch.
69871 */
69872 do {
69873 - s = atomic_read(&sync_sched_expedited_done);
69874 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69875 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69876 smp_mb(); /* ensure test happens before caller kfree */
69877 break;
69878 }
69879 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69880 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69881
69882 put_online_cpus();
69883 }
69884 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69885 * ACCESS_ONCE() to prevent the compiler from speculating
69886 * the increment to precede the early-exit check.
69887 */
69888 - ACCESS_ONCE(rsp->n_barrier_done)++;
69889 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69890 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69891 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69892 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69893 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69894
69895 /* Increment ->n_barrier_done to prevent duplicate work. */
69896 smp_mb(); /* Keep increment after above mechanism. */
69897 - ACCESS_ONCE(rsp->n_barrier_done)++;
69898 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69899 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69900 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69901 smp_mb(); /* Keep increment before caller's subsequent code. */
69902 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69903 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69904 init_callback_list(rdp);
69905 rdp->qlen_lazy = 0;
69906 - ACCESS_ONCE(rdp->qlen) = 0;
69907 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69908 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69909 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69910 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69911 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69912 rdp->cpu = cpu;
69913 rdp->rsp = rsp;
69914 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69915 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69916 rdp->n_force_qs_snap = rsp->n_force_qs;
69917 rdp->blimit = blimit;
69918 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69919 - atomic_set(&rdp->dynticks->dynticks,
69920 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69921 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69922 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69923 rcu_prepare_for_idle_init(cpu);
69924 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69925
69926 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69927 index 4d29169..d104a3c 100644
69928 --- a/kernel/rcutree.h
69929 +++ b/kernel/rcutree.h
69930 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69931 long long dynticks_nesting; /* Track irq/process nesting level. */
69932 /* Process level is worth LLONG_MAX/2. */
69933 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69934 - atomic_t dynticks; /* Even value for idle, else odd. */
69935 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69936 #ifdef CONFIG_RCU_FAST_NO_HZ
69937 int dyntick_drain; /* Prepare-for-idle state variable. */
69938 unsigned long dyntick_holdoff;
69939 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69940 index 7f3244c..417d606 100644
69941 --- a/kernel/rcutree_plugin.h
69942 +++ b/kernel/rcutree_plugin.h
69943 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69944
69945 /* Clean up and exit. */
69946 smp_mb(); /* ensure expedited GP seen before counter increment. */
69947 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69948 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69949 unlock_mb_ret:
69950 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69951 mb_ret:
69952 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69953 index abffb48..cbfa6d3 100644
69954 --- a/kernel/rcutree_trace.c
69955 +++ b/kernel/rcutree_trace.c
69956 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69957 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69958 rdp->qs_pending);
69959 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69960 - atomic_read(&rdp->dynticks->dynticks),
69961 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69962 rdp->dynticks->dynticks_nesting,
69963 rdp->dynticks->dynticks_nmi_nesting,
69964 rdp->dynticks_fqs);
69965 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69966 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69967 rdp->qs_pending);
69968 seq_printf(m, ",%d,%llx,%d,%lu",
69969 - atomic_read(&rdp->dynticks->dynticks),
69970 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69971 rdp->dynticks->dynticks_nesting,
69972 rdp->dynticks->dynticks_nmi_nesting,
69973 rdp->dynticks_fqs);
69974 diff --git a/kernel/resource.c b/kernel/resource.c
69975 index 34d4588..10baa6a 100644
69976 --- a/kernel/resource.c
69977 +++ b/kernel/resource.c
69978 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69979
69980 static int __init ioresources_init(void)
69981 {
69982 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69983 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69984 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69985 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69986 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69987 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69988 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69989 +#endif
69990 +#else
69991 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69992 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69993 +#endif
69994 return 0;
69995 }
69996 __initcall(ioresources_init);
69997 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69998 index 98ec494..4241d6d 100644
69999 --- a/kernel/rtmutex-tester.c
70000 +++ b/kernel/rtmutex-tester.c
70001 @@ -20,7 +20,7 @@
70002 #define MAX_RT_TEST_MUTEXES 8
70003
70004 static spinlock_t rttest_lock;
70005 -static atomic_t rttest_event;
70006 +static atomic_unchecked_t rttest_event;
70007
70008 struct test_thread_data {
70009 int opcode;
70010 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70011
70012 case RTTEST_LOCKCONT:
70013 td->mutexes[td->opdata] = 1;
70014 - td->event = atomic_add_return(1, &rttest_event);
70015 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70016 return 0;
70017
70018 case RTTEST_RESET:
70019 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70020 return 0;
70021
70022 case RTTEST_RESETEVENT:
70023 - atomic_set(&rttest_event, 0);
70024 + atomic_set_unchecked(&rttest_event, 0);
70025 return 0;
70026
70027 default:
70028 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70029 return ret;
70030
70031 td->mutexes[id] = 1;
70032 - td->event = atomic_add_return(1, &rttest_event);
70033 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70034 rt_mutex_lock(&mutexes[id]);
70035 - td->event = atomic_add_return(1, &rttest_event);
70036 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70037 td->mutexes[id] = 4;
70038 return 0;
70039
70040 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70041 return ret;
70042
70043 td->mutexes[id] = 1;
70044 - td->event = atomic_add_return(1, &rttest_event);
70045 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70046 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
70047 - td->event = atomic_add_return(1, &rttest_event);
70048 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70049 td->mutexes[id] = ret ? 0 : 4;
70050 return ret ? -EINTR : 0;
70051
70052 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
70053 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
70054 return ret;
70055
70056 - td->event = atomic_add_return(1, &rttest_event);
70057 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70058 rt_mutex_unlock(&mutexes[id]);
70059 - td->event = atomic_add_return(1, &rttest_event);
70060 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70061 td->mutexes[id] = 0;
70062 return 0;
70063
70064 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70065 break;
70066
70067 td->mutexes[dat] = 2;
70068 - td->event = atomic_add_return(1, &rttest_event);
70069 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70070 break;
70071
70072 default:
70073 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70074 return;
70075
70076 td->mutexes[dat] = 3;
70077 - td->event = atomic_add_return(1, &rttest_event);
70078 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70079 break;
70080
70081 case RTTEST_LOCKNOWAIT:
70082 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
70083 return;
70084
70085 td->mutexes[dat] = 1;
70086 - td->event = atomic_add_return(1, &rttest_event);
70087 + td->event = atomic_add_return_unchecked(1, &rttest_event);
70088 return;
70089
70090 default:
70091 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
70092 index 0984a21..939f183 100644
70093 --- a/kernel/sched/auto_group.c
70094 +++ b/kernel/sched/auto_group.c
70095 @@ -11,7 +11,7 @@
70096
70097 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
70098 static struct autogroup autogroup_default;
70099 -static atomic_t autogroup_seq_nr;
70100 +static atomic_unchecked_t autogroup_seq_nr;
70101
70102 void __init autogroup_init(struct task_struct *init_task)
70103 {
70104 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
70105
70106 kref_init(&ag->kref);
70107 init_rwsem(&ag->lock);
70108 - ag->id = atomic_inc_return(&autogroup_seq_nr);
70109 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
70110 ag->tg = tg;
70111 #ifdef CONFIG_RT_GROUP_SCHED
70112 /*
70113 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
70114 index 1a48cdb..d3949ff 100644
70115 --- a/kernel/sched/core.c
70116 +++ b/kernel/sched/core.c
70117 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
70118 /* convert nice value [19,-20] to rlimit style value [1,40] */
70119 int nice_rlim = 20 - nice;
70120
70121 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
70122 +
70123 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
70124 capable(CAP_SYS_NICE));
70125 }
70126 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
70127 if (nice > 19)
70128 nice = 19;
70129
70130 - if (increment < 0 && !can_nice(current, nice))
70131 + if (increment < 0 && (!can_nice(current, nice) ||
70132 + gr_handle_chroot_nice()))
70133 return -EPERM;
70134
70135 retval = security_task_setnice(current, nice);
70136 @@ -4290,6 +4293,7 @@ recheck:
70137 unsigned long rlim_rtprio =
70138 task_rlimit(p, RLIMIT_RTPRIO);
70139
70140 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
70141 /* can't set/change the rt policy */
70142 if (policy != p->policy && !rlim_rtprio)
70143 return -EPERM;
70144 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
70145 index 96e2b18..bb31eec 100644
70146 --- a/kernel/sched/fair.c
70147 +++ b/kernel/sched/fair.c
70148 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
70149 * run_rebalance_domains is triggered when needed from the scheduler tick.
70150 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
70151 */
70152 -static void run_rebalance_domains(struct softirq_action *h)
70153 +static void run_rebalance_domains(void)
70154 {
70155 int this_cpu = smp_processor_id();
70156 struct rq *this_rq = cpu_rq(this_cpu);
70157 diff --git a/kernel/signal.c b/kernel/signal.c
70158 index be4f856..453401c 100644
70159 --- a/kernel/signal.c
70160 +++ b/kernel/signal.c
70161 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70162
70163 int print_fatal_signals __read_mostly;
70164
70165 -static void __user *sig_handler(struct task_struct *t, int sig)
70166 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70167 {
70168 return t->sighand->action[sig - 1].sa.sa_handler;
70169 }
70170
70171 -static int sig_handler_ignored(void __user *handler, int sig)
70172 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70173 {
70174 /* Is it explicitly or implicitly ignored? */
70175 return handler == SIG_IGN ||
70176 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70177
70178 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70179 {
70180 - void __user *handler;
70181 + __sighandler_t handler;
70182
70183 handler = sig_handler(t, sig);
70184
70185 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70186 atomic_inc(&user->sigpending);
70187 rcu_read_unlock();
70188
70189 + if (!override_rlimit)
70190 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70191 +
70192 if (override_rlimit ||
70193 atomic_read(&user->sigpending) <=
70194 task_rlimit(t, RLIMIT_SIGPENDING)) {
70195 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70196
70197 int unhandled_signal(struct task_struct *tsk, int sig)
70198 {
70199 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70200 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70201 if (is_global_init(tsk))
70202 return 1;
70203 if (handler != SIG_IGN && handler != SIG_DFL)
70204 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70205 }
70206 }
70207
70208 + /* allow glibc communication via tgkill to other threads in our
70209 + thread group */
70210 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70211 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70212 + && gr_handle_signal(t, sig))
70213 + return -EPERM;
70214 +
70215 return security_task_kill(t, info, sig, 0);
70216 }
70217
70218 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70219 return send_signal(sig, info, p, 1);
70220 }
70221
70222 -static int
70223 +int
70224 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70225 {
70226 return send_signal(sig, info, t, 0);
70227 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70228 unsigned long int flags;
70229 int ret, blocked, ignored;
70230 struct k_sigaction *action;
70231 + int is_unhandled = 0;
70232
70233 spin_lock_irqsave(&t->sighand->siglock, flags);
70234 action = &t->sighand->action[sig-1];
70235 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70236 }
70237 if (action->sa.sa_handler == SIG_DFL)
70238 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70239 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70240 + is_unhandled = 1;
70241 ret = specific_send_sig_info(sig, info, t);
70242 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70243
70244 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70245 + normal operation */
70246 + if (is_unhandled) {
70247 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70248 + gr_handle_crash(t, sig);
70249 + }
70250 +
70251 return ret;
70252 }
70253
70254 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70255 ret = check_kill_permission(sig, info, p);
70256 rcu_read_unlock();
70257
70258 - if (!ret && sig)
70259 + if (!ret && sig) {
70260 ret = do_send_sig_info(sig, info, p, true);
70261 + if (!ret)
70262 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70263 + }
70264
70265 return ret;
70266 }
70267 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70268 int error = -ESRCH;
70269
70270 rcu_read_lock();
70271 - p = find_task_by_vpid(pid);
70272 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70273 + /* allow glibc communication via tgkill to other threads in our
70274 + thread group */
70275 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70276 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70277 + p = find_task_by_vpid_unrestricted(pid);
70278 + else
70279 +#endif
70280 + p = find_task_by_vpid(pid);
70281 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70282 error = check_kill_permission(sig, info, p);
70283 /*
70284 diff --git a/kernel/softirq.c b/kernel/softirq.c
70285 index b73e681..645ab62 100644
70286 --- a/kernel/softirq.c
70287 +++ b/kernel/softirq.c
70288 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70289
70290 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70291
70292 -char *softirq_to_name[NR_SOFTIRQS] = {
70293 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70294 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70295 "TASKLET", "SCHED", "HRTIMER", "RCU"
70296 };
70297 @@ -243,7 +243,7 @@ restart:
70298 kstat_incr_softirqs_this_cpu(vec_nr);
70299
70300 trace_softirq_entry(vec_nr);
70301 - h->action(h);
70302 + h->action();
70303 trace_softirq_exit(vec_nr);
70304 if (unlikely(prev_count != preempt_count())) {
70305 printk(KERN_ERR "huh, entered softirq %u %s %p"
70306 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70307 or_softirq_pending(1UL << nr);
70308 }
70309
70310 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70311 +void open_softirq(int nr, void (*action)(void))
70312 {
70313 - softirq_vec[nr].action = action;
70314 + pax_open_kernel();
70315 + *(void **)&softirq_vec[nr].action = action;
70316 + pax_close_kernel();
70317 }
70318
70319 /*
70320 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70321
70322 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70323
70324 -static void tasklet_action(struct softirq_action *a)
70325 +static void tasklet_action(void)
70326 {
70327 struct tasklet_struct *list;
70328
70329 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70330 }
70331 }
70332
70333 -static void tasklet_hi_action(struct softirq_action *a)
70334 +static void tasklet_hi_action(void)
70335 {
70336 struct tasklet_struct *list;
70337
70338 diff --git a/kernel/srcu.c b/kernel/srcu.c
70339 index 2095be3..9a5b89d 100644
70340 --- a/kernel/srcu.c
70341 +++ b/kernel/srcu.c
70342 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70343 preempt_disable();
70344 idx = rcu_dereference_index_check(sp->completed,
70345 rcu_read_lock_sched_held()) & 0x1;
70346 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70347 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70348 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70349 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70350 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70351 preempt_enable();
70352 return idx;
70353 }
70354 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70355 {
70356 preempt_disable();
70357 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70358 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70359 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70360 preempt_enable();
70361 }
70362 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70363 diff --git a/kernel/sys.c b/kernel/sys.c
70364 index 909148a..cd51acf 100644
70365 --- a/kernel/sys.c
70366 +++ b/kernel/sys.c
70367 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70368 error = -EACCES;
70369 goto out;
70370 }
70371 +
70372 + if (gr_handle_chroot_setpriority(p, niceval)) {
70373 + error = -EACCES;
70374 + goto out;
70375 + }
70376 +
70377 no_nice = security_task_setnice(p, niceval);
70378 if (no_nice) {
70379 error = no_nice;
70380 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70381 goto error;
70382 }
70383
70384 + if (gr_check_group_change(new->gid, new->egid, -1))
70385 + goto error;
70386 +
70387 if (rgid != (gid_t) -1 ||
70388 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70389 new->sgid = new->egid;
70390 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70391 old = current_cred();
70392
70393 retval = -EPERM;
70394 +
70395 + if (gr_check_group_change(kgid, kgid, kgid))
70396 + goto error;
70397 +
70398 if (nsown_capable(CAP_SETGID))
70399 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70400 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70401 @@ -647,7 +660,7 @@ error:
70402 /*
70403 * change the user struct in a credentials set to match the new UID
70404 */
70405 -static int set_user(struct cred *new)
70406 +int set_user(struct cred *new)
70407 {
70408 struct user_struct *new_user;
70409
70410 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70411 goto error;
70412 }
70413
70414 + if (gr_check_user_change(new->uid, new->euid, -1))
70415 + goto error;
70416 +
70417 if (!uid_eq(new->uid, old->uid)) {
70418 retval = set_user(new);
70419 if (retval < 0)
70420 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70421 old = current_cred();
70422
70423 retval = -EPERM;
70424 +
70425 + if (gr_check_crash_uid(kuid))
70426 + goto error;
70427 + if (gr_check_user_change(kuid, kuid, kuid))
70428 + goto error;
70429 +
70430 if (nsown_capable(CAP_SETUID)) {
70431 new->suid = new->uid = kuid;
70432 if (!uid_eq(kuid, old->uid)) {
70433 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70434 goto error;
70435 }
70436
70437 + if (gr_check_user_change(kruid, keuid, -1))
70438 + goto error;
70439 +
70440 if (ruid != (uid_t) -1) {
70441 new->uid = kruid;
70442 if (!uid_eq(kruid, old->uid)) {
70443 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70444 goto error;
70445 }
70446
70447 + if (gr_check_group_change(krgid, kegid, -1))
70448 + goto error;
70449 +
70450 if (rgid != (gid_t) -1)
70451 new->gid = krgid;
70452 if (egid != (gid_t) -1)
70453 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70454 if (!uid_valid(kuid))
70455 return old_fsuid;
70456
70457 + if (gr_check_user_change(-1, -1, kuid))
70458 + goto error;
70459 +
70460 new = prepare_creds();
70461 if (!new)
70462 return old_fsuid;
70463 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70464 }
70465 }
70466
70467 +error:
70468 abort_creds(new);
70469 return old_fsuid;
70470
70471 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70472 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70473 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70474 nsown_capable(CAP_SETGID)) {
70475 + if (gr_check_group_change(-1, -1, kgid))
70476 + goto error;
70477 +
70478 if (!gid_eq(kgid, old->fsgid)) {
70479 new->fsgid = kgid;
70480 goto change_okay;
70481 }
70482 }
70483
70484 +error:
70485 abort_creds(new);
70486 return old_fsgid;
70487
70488 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70489 return -EFAULT;
70490
70491 down_read(&uts_sem);
70492 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70493 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70494 __OLD_UTS_LEN);
70495 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70496 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70497 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70498 __OLD_UTS_LEN);
70499 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70500 - error |= __copy_to_user(&name->release, &utsname()->release,
70501 + error |= __copy_to_user(name->release, &utsname()->release,
70502 __OLD_UTS_LEN);
70503 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70504 - error |= __copy_to_user(&name->version, &utsname()->version,
70505 + error |= __copy_to_user(name->version, &utsname()->version,
70506 __OLD_UTS_LEN);
70507 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70508 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70509 + error |= __copy_to_user(name->machine, &utsname()->machine,
70510 __OLD_UTS_LEN);
70511 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70512 up_read(&uts_sem);
70513 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70514 error = get_dumpable(me->mm);
70515 break;
70516 case PR_SET_DUMPABLE:
70517 - if (arg2 < 0 || arg2 > 1) {
70518 + if (arg2 > 1) {
70519 error = -EINVAL;
70520 break;
70521 }
70522 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70523 index 87174ef..68cbb82 100644
70524 --- a/kernel/sysctl.c
70525 +++ b/kernel/sysctl.c
70526 @@ -92,7 +92,6 @@
70527
70528
70529 #if defined(CONFIG_SYSCTL)
70530 -
70531 /* External variables not in a header file. */
70532 extern int sysctl_overcommit_memory;
70533 extern int sysctl_overcommit_ratio;
70534 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70535 void __user *buffer, size_t *lenp, loff_t *ppos);
70536 #endif
70537
70538 -#ifdef CONFIG_PRINTK
70539 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70540 void __user *buffer, size_t *lenp, loff_t *ppos);
70541 -#endif
70542
70543 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70544 void __user *buffer, size_t *lenp, loff_t *ppos);
70545 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70546
70547 #endif
70548
70549 +extern struct ctl_table grsecurity_table[];
70550 +
70551 static struct ctl_table kern_table[];
70552 static struct ctl_table vm_table[];
70553 static struct ctl_table fs_table[];
70554 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70555 int sysctl_legacy_va_layout;
70556 #endif
70557
70558 +#ifdef CONFIG_PAX_SOFTMODE
70559 +static ctl_table pax_table[] = {
70560 + {
70561 + .procname = "softmode",
70562 + .data = &pax_softmode,
70563 + .maxlen = sizeof(unsigned int),
70564 + .mode = 0600,
70565 + .proc_handler = &proc_dointvec,
70566 + },
70567 +
70568 + { }
70569 +};
70570 +#endif
70571 +
70572 /* The default sysctl tables: */
70573
70574 static struct ctl_table sysctl_base_table[] = {
70575 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70576 #endif
70577
70578 static struct ctl_table kern_table[] = {
70579 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70580 + {
70581 + .procname = "grsecurity",
70582 + .mode = 0500,
70583 + .child = grsecurity_table,
70584 + },
70585 +#endif
70586 +
70587 +#ifdef CONFIG_PAX_SOFTMODE
70588 + {
70589 + .procname = "pax",
70590 + .mode = 0500,
70591 + .child = pax_table,
70592 + },
70593 +#endif
70594 +
70595 {
70596 .procname = "sched_child_runs_first",
70597 .data = &sysctl_sched_child_runs_first,
70598 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70599 .data = &modprobe_path,
70600 .maxlen = KMOD_PATH_LEN,
70601 .mode = 0644,
70602 - .proc_handler = proc_dostring,
70603 + .proc_handler = proc_dostring_modpriv,
70604 },
70605 {
70606 .procname = "modules_disabled",
70607 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70608 .extra1 = &zero,
70609 .extra2 = &one,
70610 },
70611 +#endif
70612 {
70613 .procname = "kptr_restrict",
70614 .data = &kptr_restrict,
70615 .maxlen = sizeof(int),
70616 .mode = 0644,
70617 .proc_handler = proc_dointvec_minmax_sysadmin,
70618 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70619 + .extra1 = &two,
70620 +#else
70621 .extra1 = &zero,
70622 +#endif
70623 .extra2 = &two,
70624 },
70625 -#endif
70626 {
70627 .procname = "ngroups_max",
70628 .data = &ngroups_max,
70629 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70630 .proc_handler = proc_dointvec_minmax,
70631 .extra1 = &zero,
70632 },
70633 + {
70634 + .procname = "heap_stack_gap",
70635 + .data = &sysctl_heap_stack_gap,
70636 + .maxlen = sizeof(sysctl_heap_stack_gap),
70637 + .mode = 0644,
70638 + .proc_handler = proc_doulongvec_minmax,
70639 + },
70640 #else
70641 {
70642 .procname = "nr_trim_pages",
70643 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70644 buffer, lenp, ppos);
70645 }
70646
70647 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70648 + void __user *buffer, size_t *lenp, loff_t *ppos)
70649 +{
70650 + if (write && !capable(CAP_SYS_MODULE))
70651 + return -EPERM;
70652 +
70653 + return _proc_do_string(table->data, table->maxlen, write,
70654 + buffer, lenp, ppos);
70655 +}
70656 +
70657 static size_t proc_skip_spaces(char **buf)
70658 {
70659 size_t ret;
70660 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70661 len = strlen(tmp);
70662 if (len > *size)
70663 len = *size;
70664 + if (len > sizeof(tmp))
70665 + len = sizeof(tmp);
70666 if (copy_to_user(*buf, tmp, len))
70667 return -EFAULT;
70668 *size -= len;
70669 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70670 return err;
70671 }
70672
70673 -#ifdef CONFIG_PRINTK
70674 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70675 void __user *buffer, size_t *lenp, loff_t *ppos)
70676 {
70677 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70678
70679 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70680 }
70681 -#endif
70682
70683 struct do_proc_dointvec_minmax_conv_param {
70684 int *min;
70685 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70686 *i = val;
70687 } else {
70688 val = convdiv * (*i) / convmul;
70689 - if (!first)
70690 + if (!first) {
70691 err = proc_put_char(&buffer, &left, '\t');
70692 + if (err)
70693 + break;
70694 + }
70695 err = proc_put_long(&buffer, &left, val, false);
70696 if (err)
70697 break;
70698 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70699 return -ENOSYS;
70700 }
70701
70702 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70703 + void __user *buffer, size_t *lenp, loff_t *ppos)
70704 +{
70705 + return -ENOSYS;
70706 +}
70707 +
70708 int proc_dointvec(struct ctl_table *table, int write,
70709 void __user *buffer, size_t *lenp, loff_t *ppos)
70710 {
70711 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70712 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70713 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70714 EXPORT_SYMBOL(proc_dostring);
70715 +EXPORT_SYMBOL(proc_dostring_modpriv);
70716 EXPORT_SYMBOL(proc_doulongvec_minmax);
70717 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70718 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70719 index 65bdcf1..21eb831 100644
70720 --- a/kernel/sysctl_binary.c
70721 +++ b/kernel/sysctl_binary.c
70722 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70723 int i;
70724
70725 set_fs(KERNEL_DS);
70726 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70727 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70728 set_fs(old_fs);
70729 if (result < 0)
70730 goto out_kfree;
70731 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70732 }
70733
70734 set_fs(KERNEL_DS);
70735 - result = vfs_write(file, buffer, str - buffer, &pos);
70736 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70737 set_fs(old_fs);
70738 if (result < 0)
70739 goto out_kfree;
70740 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70741 int i;
70742
70743 set_fs(KERNEL_DS);
70744 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70745 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70746 set_fs(old_fs);
70747 if (result < 0)
70748 goto out_kfree;
70749 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70750 }
70751
70752 set_fs(KERNEL_DS);
70753 - result = vfs_write(file, buffer, str - buffer, &pos);
70754 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70755 set_fs(old_fs);
70756 if (result < 0)
70757 goto out_kfree;
70758 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70759 int i;
70760
70761 set_fs(KERNEL_DS);
70762 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70763 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70764 set_fs(old_fs);
70765 if (result < 0)
70766 goto out;
70767 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70768 __le16 dnaddr;
70769
70770 set_fs(KERNEL_DS);
70771 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70772 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70773 set_fs(old_fs);
70774 if (result < 0)
70775 goto out;
70776 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70777 le16_to_cpu(dnaddr) & 0x3ff);
70778
70779 set_fs(KERNEL_DS);
70780 - result = vfs_write(file, buf, len, &pos);
70781 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70782 set_fs(old_fs);
70783 if (result < 0)
70784 goto out;
70785 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70786 index d0a3279..db0ad99 100644
70787 --- a/kernel/taskstats.c
70788 +++ b/kernel/taskstats.c
70789 @@ -27,9 +27,12 @@
70790 #include <linux/cgroup.h>
70791 #include <linux/fs.h>
70792 #include <linux/file.h>
70793 +#include <linux/grsecurity.h>
70794 #include <net/genetlink.h>
70795 #include <linux/atomic.h>
70796
70797 +extern int gr_is_taskstats_denied(int pid);
70798 +
70799 /*
70800 * Maximum length of a cpumask that can be specified in
70801 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70802 @@ -561,6 +564,9 @@ err:
70803
70804 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70805 {
70806 + if (gr_is_taskstats_denied(current->pid))
70807 + return -EACCES;
70808 +
70809 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70810 return cmd_attr_register_cpumask(info);
70811 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70812 diff --git a/kernel/time.c b/kernel/time.c
70813 index ba744cf..267b7c5 100644
70814 --- a/kernel/time.c
70815 +++ b/kernel/time.c
70816 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70817 return error;
70818
70819 if (tz) {
70820 + /* we log in do_settimeofday called below, so don't log twice
70821 + */
70822 + if (!tv)
70823 + gr_log_timechange();
70824 +
70825 sys_tz = *tz;
70826 update_vsyscall_tz();
70827 if (firsttime) {
70828 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70829 index aa27d39..34d221c 100644
70830 --- a/kernel/time/alarmtimer.c
70831 +++ b/kernel/time/alarmtimer.c
70832 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70833 struct platform_device *pdev;
70834 int error = 0;
70835 int i;
70836 - struct k_clock alarm_clock = {
70837 + static struct k_clock alarm_clock = {
70838 .clock_getres = alarm_clock_getres,
70839 .clock_get = alarm_clock_get,
70840 .timer_create = alarm_timer_create,
70841 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70842 index f113755..ec24223 100644
70843 --- a/kernel/time/tick-broadcast.c
70844 +++ b/kernel/time/tick-broadcast.c
70845 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70846 * then clear the broadcast bit.
70847 */
70848 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70849 - int cpu = smp_processor_id();
70850 + cpu = smp_processor_id();
70851
70852 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70853 tick_broadcast_clear_oneshot(cpu);
70854 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70855 index f791637..00051de 100644
70856 --- a/kernel/time/timekeeping.c
70857 +++ b/kernel/time/timekeeping.c
70858 @@ -14,6 +14,7 @@
70859 #include <linux/init.h>
70860 #include <linux/mm.h>
70861 #include <linux/sched.h>
70862 +#include <linux/grsecurity.h>
70863 #include <linux/syscore_ops.h>
70864 #include <linux/clocksource.h>
70865 #include <linux/jiffies.h>
70866 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70867 if (!timespec_valid_strict(tv))
70868 return -EINVAL;
70869
70870 + gr_log_timechange();
70871 +
70872 write_seqlock_irqsave(&tk->lock, flags);
70873
70874 timekeeping_forward_now(tk);
70875 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70876 index af5a7e9..715611a 100644
70877 --- a/kernel/time/timer_list.c
70878 +++ b/kernel/time/timer_list.c
70879 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70880
70881 static void print_name_offset(struct seq_file *m, void *sym)
70882 {
70883 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70884 + SEQ_printf(m, "<%p>", NULL);
70885 +#else
70886 char symname[KSYM_NAME_LEN];
70887
70888 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70889 SEQ_printf(m, "<%pK>", sym);
70890 else
70891 SEQ_printf(m, "%s", symname);
70892 +#endif
70893 }
70894
70895 static void
70896 @@ -112,7 +116,11 @@ next_one:
70897 static void
70898 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70899 {
70900 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70901 + SEQ_printf(m, " .base: %p\n", NULL);
70902 +#else
70903 SEQ_printf(m, " .base: %pK\n", base);
70904 +#endif
70905 SEQ_printf(m, " .index: %d\n",
70906 base->index);
70907 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70908 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70909 {
70910 struct proc_dir_entry *pe;
70911
70912 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70913 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70914 +#else
70915 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70916 +#endif
70917 if (!pe)
70918 return -ENOMEM;
70919 return 0;
70920 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70921 index 0b537f2..40d6c20 100644
70922 --- a/kernel/time/timer_stats.c
70923 +++ b/kernel/time/timer_stats.c
70924 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70925 static unsigned long nr_entries;
70926 static struct entry entries[MAX_ENTRIES];
70927
70928 -static atomic_t overflow_count;
70929 +static atomic_unchecked_t overflow_count;
70930
70931 /*
70932 * The entries are in a hash-table, for fast lookup:
70933 @@ -140,7 +140,7 @@ static void reset_entries(void)
70934 nr_entries = 0;
70935 memset(entries, 0, sizeof(entries));
70936 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70937 - atomic_set(&overflow_count, 0);
70938 + atomic_set_unchecked(&overflow_count, 0);
70939 }
70940
70941 static struct entry *alloc_entry(void)
70942 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70943 if (likely(entry))
70944 entry->count++;
70945 else
70946 - atomic_inc(&overflow_count);
70947 + atomic_inc_unchecked(&overflow_count);
70948
70949 out_unlock:
70950 raw_spin_unlock_irqrestore(lock, flags);
70951 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70952
70953 static void print_name_offset(struct seq_file *m, unsigned long addr)
70954 {
70955 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70956 + seq_printf(m, "<%p>", NULL);
70957 +#else
70958 char symname[KSYM_NAME_LEN];
70959
70960 if (lookup_symbol_name(addr, symname) < 0)
70961 - seq_printf(m, "<%p>", (void *)addr);
70962 + seq_printf(m, "<%pK>", (void *)addr);
70963 else
70964 seq_printf(m, "%s", symname);
70965 +#endif
70966 }
70967
70968 static int tstats_show(struct seq_file *m, void *v)
70969 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70970
70971 seq_puts(m, "Timer Stats Version: v0.2\n");
70972 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70973 - if (atomic_read(&overflow_count))
70974 + if (atomic_read_unchecked(&overflow_count))
70975 seq_printf(m, "Overflow: %d entries\n",
70976 - atomic_read(&overflow_count));
70977 + atomic_read_unchecked(&overflow_count));
70978
70979 for (i = 0; i < nr_entries; i++) {
70980 entry = entries + i;
70981 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70982 {
70983 struct proc_dir_entry *pe;
70984
70985 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70986 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70987 +#else
70988 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70989 +#endif
70990 if (!pe)
70991 return -ENOMEM;
70992 return 0;
70993 diff --git a/kernel/timer.c b/kernel/timer.c
70994 index 46ef2b1..ad081f144 100644
70995 --- a/kernel/timer.c
70996 +++ b/kernel/timer.c
70997 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
70998 /*
70999 * This function runs timers and the timer-tq in bottom half context.
71000 */
71001 -static void run_timer_softirq(struct softirq_action *h)
71002 +static void run_timer_softirq(void)
71003 {
71004 struct tvec_base *base = __this_cpu_read(tvec_bases);
71005
71006 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
71007 index c0bd030..62a1927 100644
71008 --- a/kernel/trace/blktrace.c
71009 +++ b/kernel/trace/blktrace.c
71010 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
71011 struct blk_trace *bt = filp->private_data;
71012 char buf[16];
71013
71014 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
71015 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
71016
71017 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
71018 }
71019 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
71020 return 1;
71021
71022 bt = buf->chan->private_data;
71023 - atomic_inc(&bt->dropped);
71024 + atomic_inc_unchecked(&bt->dropped);
71025 return 0;
71026 }
71027
71028 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
71029
71030 bt->dir = dir;
71031 bt->dev = dev;
71032 - atomic_set(&bt->dropped, 0);
71033 + atomic_set_unchecked(&bt->dropped, 0);
71034
71035 ret = -EIO;
71036 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
71037 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71038 index b4f20fb..483c5fa 100644
71039 --- a/kernel/trace/ftrace.c
71040 +++ b/kernel/trace/ftrace.c
71041 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71042 if (unlikely(ftrace_disabled))
71043 return 0;
71044
71045 + ret = ftrace_arch_code_modify_prepare();
71046 + FTRACE_WARN_ON(ret);
71047 + if (ret)
71048 + return 0;
71049 +
71050 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71051 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71052 if (ret) {
71053 ftrace_bug(ret, ip);
71054 - return 0;
71055 }
71056 - return 1;
71057 + return ret ? 0 : 1;
71058 }
71059
71060 /*
71061 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71062
71063 int
71064 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71065 - void *data)
71066 + void *data)
71067 {
71068 struct ftrace_func_probe *entry;
71069 struct ftrace_page *pg;
71070 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71071 if (!count)
71072 return 0;
71073
71074 + pax_open_kernel();
71075 sort(start, count, sizeof(*start),
71076 ftrace_cmp_ips, ftrace_swap_ips);
71077 + pax_close_kernel();
71078
71079 start_pg = ftrace_allocate_pages(count);
71080 if (!start_pg)
71081 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71082 index 5c38c81..88012af 100644
71083 --- a/kernel/trace/trace.c
71084 +++ b/kernel/trace/trace.c
71085 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71086 };
71087 #endif
71088
71089 -static struct dentry *d_tracer;
71090 -
71091 struct dentry *tracing_init_dentry(void)
71092 {
71093 + static struct dentry *d_tracer;
71094 static int once;
71095
71096 if (d_tracer)
71097 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
71098 return d_tracer;
71099 }
71100
71101 -static struct dentry *d_percpu;
71102 -
71103 struct dentry *tracing_dentry_percpu(void)
71104 {
71105 + static struct dentry *d_percpu;
71106 static int once;
71107 struct dentry *d_tracer;
71108
71109 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71110 index 29111da..d190fe2 100644
71111 --- a/kernel/trace/trace_events.c
71112 +++ b/kernel/trace/trace_events.c
71113 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71114 struct ftrace_module_file_ops {
71115 struct list_head list;
71116 struct module *mod;
71117 - struct file_operations id;
71118 - struct file_operations enable;
71119 - struct file_operations format;
71120 - struct file_operations filter;
71121 };
71122
71123 static struct ftrace_module_file_ops *
71124 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71125
71126 file_ops->mod = mod;
71127
71128 - file_ops->id = ftrace_event_id_fops;
71129 - file_ops->id.owner = mod;
71130 -
71131 - file_ops->enable = ftrace_enable_fops;
71132 - file_ops->enable.owner = mod;
71133 -
71134 - file_ops->filter = ftrace_event_filter_fops;
71135 - file_ops->filter.owner = mod;
71136 -
71137 - file_ops->format = ftrace_event_format_fops;
71138 - file_ops->format.owner = mod;
71139 + pax_open_kernel();
71140 + *(void **)&mod->trace_id.owner = mod;
71141 + *(void **)&mod->trace_enable.owner = mod;
71142 + *(void **)&mod->trace_filter.owner = mod;
71143 + *(void **)&mod->trace_format.owner = mod;
71144 + pax_close_kernel();
71145
71146 list_add(&file_ops->list, &ftrace_module_file_list);
71147
71148 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71149
71150 for_each_event(call, start, end) {
71151 __trace_add_event_call(*call, mod,
71152 - &file_ops->id, &file_ops->enable,
71153 - &file_ops->filter, &file_ops->format);
71154 + &mod->trace_id, &mod->trace_enable,
71155 + &mod->trace_filter, &mod->trace_format);
71156 }
71157 }
71158
71159 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71160 index fd3c8aa..5f324a6 100644
71161 --- a/kernel/trace/trace_mmiotrace.c
71162 +++ b/kernel/trace/trace_mmiotrace.c
71163 @@ -24,7 +24,7 @@ struct header_iter {
71164 static struct trace_array *mmio_trace_array;
71165 static bool overrun_detected;
71166 static unsigned long prev_overruns;
71167 -static atomic_t dropped_count;
71168 +static atomic_unchecked_t dropped_count;
71169
71170 static void mmio_reset_data(struct trace_array *tr)
71171 {
71172 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71173
71174 static unsigned long count_overruns(struct trace_iterator *iter)
71175 {
71176 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71177 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71178 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71179
71180 if (over > prev_overruns)
71181 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71182 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71183 sizeof(*entry), 0, pc);
71184 if (!event) {
71185 - atomic_inc(&dropped_count);
71186 + atomic_inc_unchecked(&dropped_count);
71187 return;
71188 }
71189 entry = ring_buffer_event_data(event);
71190 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71191 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71192 sizeof(*entry), 0, pc);
71193 if (!event) {
71194 - atomic_inc(&dropped_count);
71195 + atomic_inc_unchecked(&dropped_count);
71196 return;
71197 }
71198 entry = ring_buffer_event_data(event);
71199 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71200 index 123b189..97b81f5 100644
71201 --- a/kernel/trace/trace_output.c
71202 +++ b/kernel/trace/trace_output.c
71203 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71204
71205 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71206 if (!IS_ERR(p)) {
71207 - p = mangle_path(s->buffer + s->len, p, "\n");
71208 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71209 if (p) {
71210 s->len = p - s->buffer;
71211 return 1;
71212 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71213 index d4545f4..a9010a1 100644
71214 --- a/kernel/trace/trace_stack.c
71215 +++ b/kernel/trace/trace_stack.c
71216 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71217 return;
71218
71219 /* we do not handle interrupt stacks yet */
71220 - if (!object_is_on_stack(&this_size))
71221 + if (!object_starts_on_stack(&this_size))
71222 return;
71223
71224 local_irq_save(flags);
71225 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71226 index 872bd6d..31601a2 100644
71227 --- a/kernel/workqueue.c
71228 +++ b/kernel/workqueue.c
71229 @@ -1422,7 +1422,7 @@ retry:
71230 /* morph UNBOUND to REBIND atomically */
71231 worker_flags &= ~WORKER_UNBOUND;
71232 worker_flags |= WORKER_REBIND;
71233 - ACCESS_ONCE(worker->flags) = worker_flags;
71234 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71235
71236 idle_rebind.cnt++;
71237 worker->idle_rebind = &idle_rebind;
71238 @@ -1448,7 +1448,7 @@ retry:
71239 /* morph UNBOUND to REBIND atomically */
71240 worker_flags &= ~WORKER_UNBOUND;
71241 worker_flags |= WORKER_REBIND;
71242 - ACCESS_ONCE(worker->flags) = worker_flags;
71243 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71244
71245 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71246 work_data_bits(rebind_work)))
71247 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71248 index 2403a63..5c4be4c 100644
71249 --- a/lib/Kconfig.debug
71250 +++ b/lib/Kconfig.debug
71251 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71252 depends on DEBUG_KERNEL
71253 depends on STACKTRACE_SUPPORT
71254 depends on PROC_FS
71255 + depends on !GRKERNSEC_HIDESYM
71256 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71257 select KALLSYMS
71258 select KALLSYMS_ALL
71259 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71260
71261 config PROVIDE_OHCI1394_DMA_INIT
71262 bool "Remote debugging over FireWire early on boot"
71263 - depends on PCI && X86
71264 + depends on PCI && X86 && !GRKERNSEC
71265 help
71266 If you want to debug problems which hang or crash the kernel early
71267 on boot and the crashing machine has a FireWire port, you can use
71268 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71269
71270 config FIREWIRE_OHCI_REMOTE_DMA
71271 bool "Remote debugging over FireWire with firewire-ohci"
71272 - depends on FIREWIRE_OHCI
71273 + depends on FIREWIRE_OHCI && !GRKERNSEC
71274 help
71275 This option lets you use the FireWire bus for remote debugging
71276 with help of the firewire-ohci driver. It enables unfiltered
71277 diff --git a/lib/bitmap.c b/lib/bitmap.c
71278 index 06fdfa1..97c5c7d 100644
71279 --- a/lib/bitmap.c
71280 +++ b/lib/bitmap.c
71281 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71282 {
71283 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71284 u32 chunk;
71285 - const char __user __force *ubuf = (const char __user __force *)buf;
71286 + const char __user *ubuf = (const char __force_user *)buf;
71287
71288 bitmap_zero(maskp, nmaskbits);
71289
71290 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71291 {
71292 if (!access_ok(VERIFY_READ, ubuf, ulen))
71293 return -EFAULT;
71294 - return __bitmap_parse((const char __force *)ubuf,
71295 + return __bitmap_parse((const char __force_kernel *)ubuf,
71296 ulen, 1, maskp, nmaskbits);
71297
71298 }
71299 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71300 {
71301 unsigned a, b;
71302 int c, old_c, totaldigits;
71303 - const char __user __force *ubuf = (const char __user __force *)buf;
71304 + const char __user *ubuf = (const char __force_user *)buf;
71305 int exp_digit, in_range;
71306
71307 totaldigits = c = 0;
71308 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71309 {
71310 if (!access_ok(VERIFY_READ, ubuf, ulen))
71311 return -EFAULT;
71312 - return __bitmap_parselist((const char __force *)ubuf,
71313 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71314 ulen, 1, maskp, nmaskbits);
71315 }
71316 EXPORT_SYMBOL(bitmap_parselist_user);
71317 diff --git a/lib/bug.c b/lib/bug.c
71318 index a28c141..2bd3d95 100644
71319 --- a/lib/bug.c
71320 +++ b/lib/bug.c
71321 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71322 return BUG_TRAP_TYPE_NONE;
71323
71324 bug = find_bug(bugaddr);
71325 + if (!bug)
71326 + return BUG_TRAP_TYPE_NONE;
71327
71328 file = NULL;
71329 line = 0;
71330 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71331 index d11808c..dc2d6f8 100644
71332 --- a/lib/debugobjects.c
71333 +++ b/lib/debugobjects.c
71334 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71335 if (limit > 4)
71336 return;
71337
71338 - is_on_stack = object_is_on_stack(addr);
71339 + is_on_stack = object_starts_on_stack(addr);
71340 if (is_on_stack == onstack)
71341 return;
71342
71343 diff --git a/lib/devres.c b/lib/devres.c
71344 index 80b9c76..9e32279 100644
71345 --- a/lib/devres.c
71346 +++ b/lib/devres.c
71347 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71348 void devm_iounmap(struct device *dev, void __iomem *addr)
71349 {
71350 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71351 - (void *)addr));
71352 + (void __force *)addr));
71353 iounmap(addr);
71354 }
71355 EXPORT_SYMBOL(devm_iounmap);
71356 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71357 {
71358 ioport_unmap(addr);
71359 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71360 - devm_ioport_map_match, (void *)addr));
71361 + devm_ioport_map_match, (void __force *)addr));
71362 }
71363 EXPORT_SYMBOL(devm_ioport_unmap);
71364
71365 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71366 index 66ce414..6f0a0dd 100644
71367 --- a/lib/dma-debug.c
71368 +++ b/lib/dma-debug.c
71369 @@ -924,7 +924,7 @@ out:
71370
71371 static void check_for_stack(struct device *dev, void *addr)
71372 {
71373 - if (object_is_on_stack(addr))
71374 + if (object_starts_on_stack(addr))
71375 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71376 "stack [addr=%p]\n", addr);
71377 }
71378 diff --git a/lib/inflate.c b/lib/inflate.c
71379 index 013a761..c28f3fc 100644
71380 --- a/lib/inflate.c
71381 +++ b/lib/inflate.c
71382 @@ -269,7 +269,7 @@ static void free(void *where)
71383 malloc_ptr = free_mem_ptr;
71384 }
71385 #else
71386 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71387 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71388 #define free(a) kfree(a)
71389 #endif
71390
71391 diff --git a/lib/ioremap.c b/lib/ioremap.c
71392 index 0c9216c..863bd89 100644
71393 --- a/lib/ioremap.c
71394 +++ b/lib/ioremap.c
71395 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71396 unsigned long next;
71397
71398 phys_addr -= addr;
71399 - pmd = pmd_alloc(&init_mm, pud, addr);
71400 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71401 if (!pmd)
71402 return -ENOMEM;
71403 do {
71404 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71405 unsigned long next;
71406
71407 phys_addr -= addr;
71408 - pud = pud_alloc(&init_mm, pgd, addr);
71409 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71410 if (!pud)
71411 return -ENOMEM;
71412 do {
71413 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71414 index bd2bea9..6b3c95e 100644
71415 --- a/lib/is_single_threaded.c
71416 +++ b/lib/is_single_threaded.c
71417 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71418 struct task_struct *p, *t;
71419 bool ret;
71420
71421 + if (!mm)
71422 + return true;
71423 +
71424 if (atomic_read(&task->signal->live) != 1)
71425 return false;
71426
71427 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71428 index e796429..6e38f9f 100644
71429 --- a/lib/radix-tree.c
71430 +++ b/lib/radix-tree.c
71431 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71432 int nr;
71433 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71434 };
71435 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71436 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71437
71438 static inline void *ptr_to_indirect(void *ptr)
71439 {
71440 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71441 index 0e33754..50a0e63 100644
71442 --- a/lib/vsprintf.c
71443 +++ b/lib/vsprintf.c
71444 @@ -16,6 +16,9 @@
71445 * - scnprintf and vscnprintf
71446 */
71447
71448 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71449 +#define __INCLUDED_BY_HIDESYM 1
71450 +#endif
71451 #include <stdarg.h>
71452 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71453 #include <linux/types.h>
71454 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71455 char sym[KSYM_SYMBOL_LEN];
71456 if (ext == 'B')
71457 sprint_backtrace(sym, value);
71458 - else if (ext != 'f' && ext != 's')
71459 + else if (ext != 'f' && ext != 's' && ext != 'a')
71460 sprint_symbol(sym, value);
71461 else
71462 sprint_symbol_no_offset(sym, value);
71463 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71464 return number(buf, end, *(const netdev_features_t *)addr, spec);
71465 }
71466
71467 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71468 +int kptr_restrict __read_mostly = 2;
71469 +#else
71470 int kptr_restrict __read_mostly;
71471 +#endif
71472
71473 /*
71474 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71475 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71476 * - 'S' For symbolic direct pointers with offset
71477 * - 's' For symbolic direct pointers without offset
71478 * - 'B' For backtraced symbolic direct pointers with offset
71479 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71480 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71481 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71482 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71483 * - 'M' For a 6-byte MAC address, it prints the address in the
71484 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71485
71486 if (!ptr && *fmt != 'K') {
71487 /*
71488 - * Print (null) with the same width as a pointer so it makes
71489 + * Print (nil) with the same width as a pointer so it makes
71490 * tabular output look nice.
71491 */
71492 if (spec.field_width == -1)
71493 spec.field_width = default_width;
71494 - return string(buf, end, "(null)", spec);
71495 + return string(buf, end, "(nil)", spec);
71496 }
71497
71498 switch (*fmt) {
71499 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71500 /* Fallthrough */
71501 case 'S':
71502 case 's':
71503 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71504 + break;
71505 +#else
71506 + return symbol_string(buf, end, ptr, spec, *fmt);
71507 +#endif
71508 + case 'A':
71509 + case 'a':
71510 case 'B':
71511 return symbol_string(buf, end, ptr, spec, *fmt);
71512 case 'R':
71513 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71514 va_end(va);
71515 return buf;
71516 }
71517 + case 'P':
71518 + break;
71519 case 'K':
71520 /*
71521 * %pK cannot be used in IRQ context because its test
71522 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71523 }
71524 break;
71525 }
71526 +
71527 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71528 + /* 'P' = approved pointers to copy to userland,
71529 + as in the /proc/kallsyms case, as we make it display nothing
71530 + for non-root users, and the real contents for root users
71531 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71532 + above
71533 + */
71534 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71535 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71536 + dump_stack();
71537 + ptr = NULL;
71538 + }
71539 +#endif
71540 +
71541 spec.flags |= SMALL;
71542 if (spec.field_width == -1) {
71543 spec.field_width = default_width;
71544 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71545 typeof(type) value; \
71546 if (sizeof(type) == 8) { \
71547 args = PTR_ALIGN(args, sizeof(u32)); \
71548 - *(u32 *)&value = *(u32 *)args; \
71549 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71550 + *(u32 *)&value = *(const u32 *)args; \
71551 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71552 } else { \
71553 args = PTR_ALIGN(args, sizeof(type)); \
71554 - value = *(typeof(type) *)args; \
71555 + value = *(const typeof(type) *)args; \
71556 } \
71557 args += sizeof(type); \
71558 value; \
71559 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71560 case FORMAT_TYPE_STR: {
71561 const char *str_arg = args;
71562 args += strlen(str_arg) + 1;
71563 - str = string(str, end, (char *)str_arg, spec);
71564 + str = string(str, end, str_arg, spec);
71565 break;
71566 }
71567
71568 diff --git a/localversion-grsec b/localversion-grsec
71569 new file mode 100644
71570 index 0000000..7cd6065
71571 --- /dev/null
71572 +++ b/localversion-grsec
71573 @@ -0,0 +1 @@
71574 +-grsec
71575 diff --git a/mm/Kconfig b/mm/Kconfig
71576 index d5c8019..f513038 100644
71577 --- a/mm/Kconfig
71578 +++ b/mm/Kconfig
71579 @@ -251,10 +251,10 @@ config KSM
71580 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71581
71582 config DEFAULT_MMAP_MIN_ADDR
71583 - int "Low address space to protect from user allocation"
71584 + int "Low address space to protect from user allocation"
71585 depends on MMU
71586 - default 4096
71587 - help
71588 + default 65536
71589 + help
71590 This is the portion of low virtual memory which should be protected
71591 from userspace allocation. Keeping a user from writing to low pages
71592 can help reduce the impact of kernel NULL pointer bugs.
71593 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71594
71595 config HWPOISON_INJECT
71596 tristate "HWPoison pages injector"
71597 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71598 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71599 select PROC_PAGE_MONITOR
71600
71601 config NOMMU_INITIAL_TRIM_EXCESS
71602 diff --git a/mm/filemap.c b/mm/filemap.c
71603 index 3843445..4fe6833 100644
71604 --- a/mm/filemap.c
71605 +++ b/mm/filemap.c
71606 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71607 struct address_space *mapping = file->f_mapping;
71608
71609 if (!mapping->a_ops->readpage)
71610 - return -ENOEXEC;
71611 + return -ENODEV;
71612 file_accessed(file);
71613 vma->vm_ops = &generic_file_vm_ops;
71614 vma->vm_flags |= VM_CAN_NONLINEAR;
71615 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71616 *pos = i_size_read(inode);
71617
71618 if (limit != RLIM_INFINITY) {
71619 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71620 if (*pos >= limit) {
71621 send_sig(SIGXFSZ, current, 0);
71622 return -EFBIG;
71623 diff --git a/mm/fremap.c b/mm/fremap.c
71624 index 9ed4fd4..c42648d 100644
71625 --- a/mm/fremap.c
71626 +++ b/mm/fremap.c
71627 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71628 retry:
71629 vma = find_vma(mm, start);
71630
71631 +#ifdef CONFIG_PAX_SEGMEXEC
71632 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71633 + goto out;
71634 +#endif
71635 +
71636 /*
71637 * Make sure the vma is shared, that it supports prefaulting,
71638 * and that the remapped range is valid and fully within
71639 diff --git a/mm/highmem.c b/mm/highmem.c
71640 index d517cd1..006a1c5 100644
71641 --- a/mm/highmem.c
71642 +++ b/mm/highmem.c
71643 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71644 * So no dangers, even with speculative execution.
71645 */
71646 page = pte_page(pkmap_page_table[i]);
71647 + pax_open_kernel();
71648 pte_clear(&init_mm, (unsigned long)page_address(page),
71649 &pkmap_page_table[i]);
71650 -
71651 + pax_close_kernel();
71652 set_page_address(page, NULL);
71653 need_flush = 1;
71654 }
71655 @@ -198,9 +199,11 @@ start:
71656 }
71657 }
71658 vaddr = PKMAP_ADDR(last_pkmap_nr);
71659 +
71660 + pax_open_kernel();
71661 set_pte_at(&init_mm, vaddr,
71662 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71663 -
71664 + pax_close_kernel();
71665 pkmap_count[last_pkmap_nr] = 1;
71666 set_page_address(page, (void *)vaddr);
71667
71668 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71669 index 141dbb6..ebff057 100644
71670 --- a/mm/huge_memory.c
71671 +++ b/mm/huge_memory.c
71672 @@ -735,7 +735,7 @@ out:
71673 * run pte_offset_map on the pmd, if an huge pmd could
71674 * materialize from under us from a different thread.
71675 */
71676 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71677 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71678 return VM_FAULT_OOM;
71679 /* if an huge pmd materialized from under us just retry later */
71680 if (unlikely(pmd_trans_huge(*pmd)))
71681 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71682 index 3adceaf..dccfea3 100644
71683 --- a/mm/hugetlb.c
71684 +++ b/mm/hugetlb.c
71685 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71686 return 1;
71687 }
71688
71689 +#ifdef CONFIG_PAX_SEGMEXEC
71690 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71691 +{
71692 + struct mm_struct *mm = vma->vm_mm;
71693 + struct vm_area_struct *vma_m;
71694 + unsigned long address_m;
71695 + pte_t *ptep_m;
71696 +
71697 + vma_m = pax_find_mirror_vma(vma);
71698 + if (!vma_m)
71699 + return;
71700 +
71701 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71702 + address_m = address + SEGMEXEC_TASK_SIZE;
71703 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71704 + get_page(page_m);
71705 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71706 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71707 +}
71708 +#endif
71709 +
71710 /*
71711 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71712 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71713 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71714 make_huge_pte(vma, new_page, 1));
71715 page_remove_rmap(old_page);
71716 hugepage_add_new_anon_rmap(new_page, vma, address);
71717 +
71718 +#ifdef CONFIG_PAX_SEGMEXEC
71719 + pax_mirror_huge_pte(vma, address, new_page);
71720 +#endif
71721 +
71722 /* Make the old page be freed below */
71723 new_page = old_page;
71724 mmu_notifier_invalidate_range_end(mm,
71725 @@ -2786,6 +2812,10 @@ retry:
71726 && (vma->vm_flags & VM_SHARED)));
71727 set_huge_pte_at(mm, address, ptep, new_pte);
71728
71729 +#ifdef CONFIG_PAX_SEGMEXEC
71730 + pax_mirror_huge_pte(vma, address, page);
71731 +#endif
71732 +
71733 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71734 /* Optimization, do the COW without a second fault */
71735 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71736 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71737 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71738 struct hstate *h = hstate_vma(vma);
71739
71740 +#ifdef CONFIG_PAX_SEGMEXEC
71741 + struct vm_area_struct *vma_m;
71742 +#endif
71743 +
71744 address &= huge_page_mask(h);
71745
71746 ptep = huge_pte_offset(mm, address);
71747 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71748 VM_FAULT_SET_HINDEX(hstate_index(h));
71749 }
71750
71751 +#ifdef CONFIG_PAX_SEGMEXEC
71752 + vma_m = pax_find_mirror_vma(vma);
71753 + if (vma_m) {
71754 + unsigned long address_m;
71755 +
71756 + if (vma->vm_start > vma_m->vm_start) {
71757 + address_m = address;
71758 + address -= SEGMEXEC_TASK_SIZE;
71759 + vma = vma_m;
71760 + h = hstate_vma(vma);
71761 + } else
71762 + address_m = address + SEGMEXEC_TASK_SIZE;
71763 +
71764 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71765 + return VM_FAULT_OOM;
71766 + address_m &= HPAGE_MASK;
71767 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71768 + }
71769 +#endif
71770 +
71771 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71772 if (!ptep)
71773 return VM_FAULT_OOM;
71774 diff --git a/mm/internal.h b/mm/internal.h
71775 index b8c91b3..93e95a3 100644
71776 --- a/mm/internal.h
71777 +++ b/mm/internal.h
71778 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71779 * in mm/page_alloc.c
71780 */
71781 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71782 +extern void free_compound_page(struct page *page);
71783 extern void prep_compound_page(struct page *page, unsigned long order);
71784 #ifdef CONFIG_MEMORY_FAILURE
71785 extern bool is_free_buddy_page(struct page *page);
71786 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71787 index 45eb621..6ccd8ea 100644
71788 --- a/mm/kmemleak.c
71789 +++ b/mm/kmemleak.c
71790 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71791
71792 for (i = 0; i < object->trace_len; i++) {
71793 void *ptr = (void *)object->trace[i];
71794 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71795 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71796 }
71797 }
71798
71799 diff --git a/mm/maccess.c b/mm/maccess.c
71800 index d53adf9..03a24bf 100644
71801 --- a/mm/maccess.c
71802 +++ b/mm/maccess.c
71803 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71804 set_fs(KERNEL_DS);
71805 pagefault_disable();
71806 ret = __copy_from_user_inatomic(dst,
71807 - (__force const void __user *)src, size);
71808 + (const void __force_user *)src, size);
71809 pagefault_enable();
71810 set_fs(old_fs);
71811
71812 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71813
71814 set_fs(KERNEL_DS);
71815 pagefault_disable();
71816 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71817 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71818 pagefault_enable();
71819 set_fs(old_fs);
71820
71821 diff --git a/mm/madvise.c b/mm/madvise.c
71822 index 14d260f..b2a80fd 100644
71823 --- a/mm/madvise.c
71824 +++ b/mm/madvise.c
71825 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71826 pgoff_t pgoff;
71827 unsigned long new_flags = vma->vm_flags;
71828
71829 +#ifdef CONFIG_PAX_SEGMEXEC
71830 + struct vm_area_struct *vma_m;
71831 +#endif
71832 +
71833 switch (behavior) {
71834 case MADV_NORMAL:
71835 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71836 @@ -119,6 +123,13 @@ success:
71837 /*
71838 * vm_flags is protected by the mmap_sem held in write mode.
71839 */
71840 +
71841 +#ifdef CONFIG_PAX_SEGMEXEC
71842 + vma_m = pax_find_mirror_vma(vma);
71843 + if (vma_m)
71844 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71845 +#endif
71846 +
71847 vma->vm_flags = new_flags;
71848
71849 out:
71850 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71851 struct vm_area_struct ** prev,
71852 unsigned long start, unsigned long end)
71853 {
71854 +
71855 +#ifdef CONFIG_PAX_SEGMEXEC
71856 + struct vm_area_struct *vma_m;
71857 +#endif
71858 +
71859 *prev = vma;
71860 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71861 return -EINVAL;
71862 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71863 zap_page_range(vma, start, end - start, &details);
71864 } else
71865 zap_page_range(vma, start, end - start, NULL);
71866 +
71867 +#ifdef CONFIG_PAX_SEGMEXEC
71868 + vma_m = pax_find_mirror_vma(vma);
71869 + if (vma_m) {
71870 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71871 + struct zap_details details = {
71872 + .nonlinear_vma = vma_m,
71873 + .last_index = ULONG_MAX,
71874 + };
71875 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71876 + } else
71877 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71878 + }
71879 +#endif
71880 +
71881 return 0;
71882 }
71883
71884 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71885 if (end < start)
71886 goto out;
71887
71888 +#ifdef CONFIG_PAX_SEGMEXEC
71889 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71890 + if (end > SEGMEXEC_TASK_SIZE)
71891 + goto out;
71892 + } else
71893 +#endif
71894 +
71895 + if (end > TASK_SIZE)
71896 + goto out;
71897 +
71898 error = 0;
71899 if (end == start)
71900 goto out;
71901 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71902 index a6e2141..eaf5aad 100644
71903 --- a/mm/memory-failure.c
71904 +++ b/mm/memory-failure.c
71905 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71906
71907 int sysctl_memory_failure_recovery __read_mostly = 1;
71908
71909 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71910 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71911
71912 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71913
71914 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71915 pfn, t->comm, t->pid);
71916 si.si_signo = SIGBUS;
71917 si.si_errno = 0;
71918 - si.si_addr = (void *)addr;
71919 + si.si_addr = (void __user *)addr;
71920 #ifdef __ARCH_SI_TRAPNO
71921 si.si_trapno = trapno;
71922 #endif
71923 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71924 }
71925
71926 nr_pages = 1 << compound_trans_order(hpage);
71927 - atomic_long_add(nr_pages, &mce_bad_pages);
71928 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71929
71930 /*
71931 * We need/can do nothing about count=0 pages.
71932 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71933 if (!PageHWPoison(hpage)
71934 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71935 || (p != hpage && TestSetPageHWPoison(hpage))) {
71936 - atomic_long_sub(nr_pages, &mce_bad_pages);
71937 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71938 return 0;
71939 }
71940 set_page_hwpoison_huge_page(hpage);
71941 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71942 }
71943 if (hwpoison_filter(p)) {
71944 if (TestClearPageHWPoison(p))
71945 - atomic_long_sub(nr_pages, &mce_bad_pages);
71946 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71947 unlock_page(hpage);
71948 put_page(hpage);
71949 return 0;
71950 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71951 return 0;
71952 }
71953 if (TestClearPageHWPoison(p))
71954 - atomic_long_sub(nr_pages, &mce_bad_pages);
71955 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71956 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71957 return 0;
71958 }
71959 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71960 */
71961 if (TestClearPageHWPoison(page)) {
71962 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71963 - atomic_long_sub(nr_pages, &mce_bad_pages);
71964 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71965 freeit = 1;
71966 if (PageHuge(page))
71967 clear_page_hwpoison_huge_page(page);
71968 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71969 }
71970 done:
71971 if (!PageHWPoison(hpage))
71972 - atomic_long_add(1 << compound_trans_order(hpage),
71973 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71974 &mce_bad_pages);
71975 set_page_hwpoison_huge_page(hpage);
71976 dequeue_hwpoisoned_huge_page(hpage);
71977 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71978 return ret;
71979
71980 done:
71981 - atomic_long_add(1, &mce_bad_pages);
71982 + atomic_long_add_unchecked(1, &mce_bad_pages);
71983 SetPageHWPoison(page);
71984 /* keep elevated page count for bad page */
71985 return ret;
71986 diff --git a/mm/memory.c b/mm/memory.c
71987 index 5736170..8e04800 100644
71988 --- a/mm/memory.c
71989 +++ b/mm/memory.c
71990 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71991 free_pte_range(tlb, pmd, addr);
71992 } while (pmd++, addr = next, addr != end);
71993
71994 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71995 start &= PUD_MASK;
71996 if (start < floor)
71997 return;
71998 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71999 pmd = pmd_offset(pud, start);
72000 pud_clear(pud);
72001 pmd_free_tlb(tlb, pmd, start);
72002 +#endif
72003 +
72004 }
72005
72006 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72007 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72008 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
72009 } while (pud++, addr = next, addr != end);
72010
72011 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
72012 start &= PGDIR_MASK;
72013 if (start < floor)
72014 return;
72015 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
72016 pud = pud_offset(pgd, start);
72017 pgd_clear(pgd);
72018 pud_free_tlb(tlb, pud, start);
72019 +#endif
72020 +
72021 }
72022
72023 /*
72024 @@ -1614,12 +1620,6 @@ no_page_table:
72025 return page;
72026 }
72027
72028 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
72029 -{
72030 - return stack_guard_page_start(vma, addr) ||
72031 - stack_guard_page_end(vma, addr+PAGE_SIZE);
72032 -}
72033 -
72034 /**
72035 * __get_user_pages() - pin user pages in memory
72036 * @tsk: task_struct of target task
72037 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72038 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
72039 i = 0;
72040
72041 - do {
72042 + while (nr_pages) {
72043 struct vm_area_struct *vma;
72044
72045 - vma = find_extend_vma(mm, start);
72046 + vma = find_vma(mm, start);
72047 if (!vma && in_gate_area(mm, start)) {
72048 unsigned long pg = start & PAGE_MASK;
72049 pgd_t *pgd;
72050 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72051 goto next_page;
72052 }
72053
72054 - if (!vma ||
72055 + if (!vma || start < vma->vm_start ||
72056 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72057 !(vm_flags & vma->vm_flags))
72058 return i ? : -EFAULT;
72059 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72060 int ret;
72061 unsigned int fault_flags = 0;
72062
72063 - /* For mlock, just skip the stack guard page. */
72064 - if (foll_flags & FOLL_MLOCK) {
72065 - if (stack_guard_page(vma, start))
72066 - goto next_page;
72067 - }
72068 if (foll_flags & FOLL_WRITE)
72069 fault_flags |= FAULT_FLAG_WRITE;
72070 if (nonblocking)
72071 @@ -1848,7 +1843,7 @@ next_page:
72072 start += PAGE_SIZE;
72073 nr_pages--;
72074 } while (nr_pages && start < vma->vm_end);
72075 - } while (nr_pages);
72076 + }
72077 return i;
72078 }
72079 EXPORT_SYMBOL(__get_user_pages);
72080 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72081 page_add_file_rmap(page);
72082 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72083
72084 +#ifdef CONFIG_PAX_SEGMEXEC
72085 + pax_mirror_file_pte(vma, addr, page, ptl);
72086 +#endif
72087 +
72088 retval = 0;
72089 pte_unmap_unlock(pte, ptl);
72090 return retval;
72091 @@ -2089,10 +2088,22 @@ out:
72092 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72093 struct page *page)
72094 {
72095 +
72096 +#ifdef CONFIG_PAX_SEGMEXEC
72097 + struct vm_area_struct *vma_m;
72098 +#endif
72099 +
72100 if (addr < vma->vm_start || addr >= vma->vm_end)
72101 return -EFAULT;
72102 if (!page_count(page))
72103 return -EINVAL;
72104 +
72105 +#ifdef CONFIG_PAX_SEGMEXEC
72106 + vma_m = pax_find_mirror_vma(vma);
72107 + if (vma_m)
72108 + vma_m->vm_flags |= VM_INSERTPAGE;
72109 +#endif
72110 +
72111 vma->vm_flags |= VM_INSERTPAGE;
72112 return insert_page(vma, addr, page, vma->vm_page_prot);
72113 }
72114 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72115 unsigned long pfn)
72116 {
72117 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72118 + BUG_ON(vma->vm_mirror);
72119
72120 if (addr < vma->vm_start || addr >= vma->vm_end)
72121 return -EFAULT;
72122 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72123
72124 BUG_ON(pud_huge(*pud));
72125
72126 - pmd = pmd_alloc(mm, pud, addr);
72127 + pmd = (mm == &init_mm) ?
72128 + pmd_alloc_kernel(mm, pud, addr) :
72129 + pmd_alloc(mm, pud, addr);
72130 if (!pmd)
72131 return -ENOMEM;
72132 do {
72133 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72134 unsigned long next;
72135 int err;
72136
72137 - pud = pud_alloc(mm, pgd, addr);
72138 + pud = (mm == &init_mm) ?
72139 + pud_alloc_kernel(mm, pgd, addr) :
72140 + pud_alloc(mm, pgd, addr);
72141 if (!pud)
72142 return -ENOMEM;
72143 do {
72144 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72145 copy_user_highpage(dst, src, va, vma);
72146 }
72147
72148 +#ifdef CONFIG_PAX_SEGMEXEC
72149 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72150 +{
72151 + struct mm_struct *mm = vma->vm_mm;
72152 + spinlock_t *ptl;
72153 + pte_t *pte, entry;
72154 +
72155 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72156 + entry = *pte;
72157 + if (!pte_present(entry)) {
72158 + if (!pte_none(entry)) {
72159 + BUG_ON(pte_file(entry));
72160 + free_swap_and_cache(pte_to_swp_entry(entry));
72161 + pte_clear_not_present_full(mm, address, pte, 0);
72162 + }
72163 + } else {
72164 + struct page *page;
72165 +
72166 + flush_cache_page(vma, address, pte_pfn(entry));
72167 + entry = ptep_clear_flush(vma, address, pte);
72168 + BUG_ON(pte_dirty(entry));
72169 + page = vm_normal_page(vma, address, entry);
72170 + if (page) {
72171 + update_hiwater_rss(mm);
72172 + if (PageAnon(page))
72173 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72174 + else
72175 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72176 + page_remove_rmap(page);
72177 + page_cache_release(page);
72178 + }
72179 + }
72180 + pte_unmap_unlock(pte, ptl);
72181 +}
72182 +
72183 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72184 + *
72185 + * the ptl of the lower mapped page is held on entry and is not released on exit
72186 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72187 + */
72188 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72189 +{
72190 + struct mm_struct *mm = vma->vm_mm;
72191 + unsigned long address_m;
72192 + spinlock_t *ptl_m;
72193 + struct vm_area_struct *vma_m;
72194 + pmd_t *pmd_m;
72195 + pte_t *pte_m, entry_m;
72196 +
72197 + BUG_ON(!page_m || !PageAnon(page_m));
72198 +
72199 + vma_m = pax_find_mirror_vma(vma);
72200 + if (!vma_m)
72201 + return;
72202 +
72203 + BUG_ON(!PageLocked(page_m));
72204 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72205 + address_m = address + SEGMEXEC_TASK_SIZE;
72206 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72207 + pte_m = pte_offset_map(pmd_m, address_m);
72208 + ptl_m = pte_lockptr(mm, pmd_m);
72209 + if (ptl != ptl_m) {
72210 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72211 + if (!pte_none(*pte_m))
72212 + goto out;
72213 + }
72214 +
72215 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72216 + page_cache_get(page_m);
72217 + page_add_anon_rmap(page_m, vma_m, address_m);
72218 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72219 + set_pte_at(mm, address_m, pte_m, entry_m);
72220 + update_mmu_cache(vma_m, address_m, entry_m);
72221 +out:
72222 + if (ptl != ptl_m)
72223 + spin_unlock(ptl_m);
72224 + pte_unmap(pte_m);
72225 + unlock_page(page_m);
72226 +}
72227 +
72228 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72229 +{
72230 + struct mm_struct *mm = vma->vm_mm;
72231 + unsigned long address_m;
72232 + spinlock_t *ptl_m;
72233 + struct vm_area_struct *vma_m;
72234 + pmd_t *pmd_m;
72235 + pte_t *pte_m, entry_m;
72236 +
72237 + BUG_ON(!page_m || PageAnon(page_m));
72238 +
72239 + vma_m = pax_find_mirror_vma(vma);
72240 + if (!vma_m)
72241 + return;
72242 +
72243 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72244 + address_m = address + SEGMEXEC_TASK_SIZE;
72245 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72246 + pte_m = pte_offset_map(pmd_m, address_m);
72247 + ptl_m = pte_lockptr(mm, pmd_m);
72248 + if (ptl != ptl_m) {
72249 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72250 + if (!pte_none(*pte_m))
72251 + goto out;
72252 + }
72253 +
72254 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72255 + page_cache_get(page_m);
72256 + page_add_file_rmap(page_m);
72257 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72258 + set_pte_at(mm, address_m, pte_m, entry_m);
72259 + update_mmu_cache(vma_m, address_m, entry_m);
72260 +out:
72261 + if (ptl != ptl_m)
72262 + spin_unlock(ptl_m);
72263 + pte_unmap(pte_m);
72264 +}
72265 +
72266 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72267 +{
72268 + struct mm_struct *mm = vma->vm_mm;
72269 + unsigned long address_m;
72270 + spinlock_t *ptl_m;
72271 + struct vm_area_struct *vma_m;
72272 + pmd_t *pmd_m;
72273 + pte_t *pte_m, entry_m;
72274 +
72275 + vma_m = pax_find_mirror_vma(vma);
72276 + if (!vma_m)
72277 + return;
72278 +
72279 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72280 + address_m = address + SEGMEXEC_TASK_SIZE;
72281 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72282 + pte_m = pte_offset_map(pmd_m, address_m);
72283 + ptl_m = pte_lockptr(mm, pmd_m);
72284 + if (ptl != ptl_m) {
72285 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72286 + if (!pte_none(*pte_m))
72287 + goto out;
72288 + }
72289 +
72290 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72291 + set_pte_at(mm, address_m, pte_m, entry_m);
72292 +out:
72293 + if (ptl != ptl_m)
72294 + spin_unlock(ptl_m);
72295 + pte_unmap(pte_m);
72296 +}
72297 +
72298 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72299 +{
72300 + struct page *page_m;
72301 + pte_t entry;
72302 +
72303 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72304 + goto out;
72305 +
72306 + entry = *pte;
72307 + page_m = vm_normal_page(vma, address, entry);
72308 + if (!page_m)
72309 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72310 + else if (PageAnon(page_m)) {
72311 + if (pax_find_mirror_vma(vma)) {
72312 + pte_unmap_unlock(pte, ptl);
72313 + lock_page(page_m);
72314 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72315 + if (pte_same(entry, *pte))
72316 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72317 + else
72318 + unlock_page(page_m);
72319 + }
72320 + } else
72321 + pax_mirror_file_pte(vma, address, page_m, ptl);
72322 +
72323 +out:
72324 + pte_unmap_unlock(pte, ptl);
72325 +}
72326 +#endif
72327 +
72328 /*
72329 * This routine handles present pages, when users try to write
72330 * to a shared page. It is done by copying the page to a new address
72331 @@ -2703,6 +2899,12 @@ gotten:
72332 */
72333 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72334 if (likely(pte_same(*page_table, orig_pte))) {
72335 +
72336 +#ifdef CONFIG_PAX_SEGMEXEC
72337 + if (pax_find_mirror_vma(vma))
72338 + BUG_ON(!trylock_page(new_page));
72339 +#endif
72340 +
72341 if (old_page) {
72342 if (!PageAnon(old_page)) {
72343 dec_mm_counter_fast(mm, MM_FILEPAGES);
72344 @@ -2754,6 +2956,10 @@ gotten:
72345 page_remove_rmap(old_page);
72346 }
72347
72348 +#ifdef CONFIG_PAX_SEGMEXEC
72349 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72350 +#endif
72351 +
72352 /* Free the old page.. */
72353 new_page = old_page;
72354 ret |= VM_FAULT_WRITE;
72355 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72356 swap_free(entry);
72357 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72358 try_to_free_swap(page);
72359 +
72360 +#ifdef CONFIG_PAX_SEGMEXEC
72361 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72362 +#endif
72363 +
72364 unlock_page(page);
72365 if (swapcache) {
72366 /*
72367 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72368
72369 /* No need to invalidate - it was non-present before */
72370 update_mmu_cache(vma, address, page_table);
72371 +
72372 +#ifdef CONFIG_PAX_SEGMEXEC
72373 + pax_mirror_anon_pte(vma, address, page, ptl);
72374 +#endif
72375 +
72376 unlock:
72377 pte_unmap_unlock(page_table, ptl);
72378 out:
72379 @@ -3075,40 +3291,6 @@ out_release:
72380 }
72381
72382 /*
72383 - * This is like a special single-page "expand_{down|up}wards()",
72384 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72385 - * doesn't hit another vma.
72386 - */
72387 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72388 -{
72389 - address &= PAGE_MASK;
72390 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72391 - struct vm_area_struct *prev = vma->vm_prev;
72392 -
72393 - /*
72394 - * Is there a mapping abutting this one below?
72395 - *
72396 - * That's only ok if it's the same stack mapping
72397 - * that has gotten split..
72398 - */
72399 - if (prev && prev->vm_end == address)
72400 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72401 -
72402 - expand_downwards(vma, address - PAGE_SIZE);
72403 - }
72404 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72405 - struct vm_area_struct *next = vma->vm_next;
72406 -
72407 - /* As VM_GROWSDOWN but s/below/above/ */
72408 - if (next && next->vm_start == address + PAGE_SIZE)
72409 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72410 -
72411 - expand_upwards(vma, address + PAGE_SIZE);
72412 - }
72413 - return 0;
72414 -}
72415 -
72416 -/*
72417 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72418 * but allow concurrent faults), and pte mapped but not yet locked.
72419 * We return with mmap_sem still held, but pte unmapped and unlocked.
72420 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72421 unsigned long address, pte_t *page_table, pmd_t *pmd,
72422 unsigned int flags)
72423 {
72424 - struct page *page;
72425 + struct page *page = NULL;
72426 spinlock_t *ptl;
72427 pte_t entry;
72428
72429 - pte_unmap(page_table);
72430 -
72431 - /* Check if we need to add a guard page to the stack */
72432 - if (check_stack_guard_page(vma, address) < 0)
72433 - return VM_FAULT_SIGBUS;
72434 -
72435 - /* Use the zero-page for reads */
72436 if (!(flags & FAULT_FLAG_WRITE)) {
72437 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72438 vma->vm_page_prot));
72439 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72440 + ptl = pte_lockptr(mm, pmd);
72441 + spin_lock(ptl);
72442 if (!pte_none(*page_table))
72443 goto unlock;
72444 goto setpte;
72445 }
72446
72447 /* Allocate our own private page. */
72448 + pte_unmap(page_table);
72449 +
72450 if (unlikely(anon_vma_prepare(vma)))
72451 goto oom;
72452 page = alloc_zeroed_user_highpage_movable(vma, address);
72453 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72454 if (!pte_none(*page_table))
72455 goto release;
72456
72457 +#ifdef CONFIG_PAX_SEGMEXEC
72458 + if (pax_find_mirror_vma(vma))
72459 + BUG_ON(!trylock_page(page));
72460 +#endif
72461 +
72462 inc_mm_counter_fast(mm, MM_ANONPAGES);
72463 page_add_new_anon_rmap(page, vma, address);
72464 setpte:
72465 @@ -3163,6 +3346,12 @@ setpte:
72466
72467 /* No need to invalidate - it was non-present before */
72468 update_mmu_cache(vma, address, page_table);
72469 +
72470 +#ifdef CONFIG_PAX_SEGMEXEC
72471 + if (page)
72472 + pax_mirror_anon_pte(vma, address, page, ptl);
72473 +#endif
72474 +
72475 unlock:
72476 pte_unmap_unlock(page_table, ptl);
72477 return 0;
72478 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72479 */
72480 /* Only go through if we didn't race with anybody else... */
72481 if (likely(pte_same(*page_table, orig_pte))) {
72482 +
72483 +#ifdef CONFIG_PAX_SEGMEXEC
72484 + if (anon && pax_find_mirror_vma(vma))
72485 + BUG_ON(!trylock_page(page));
72486 +#endif
72487 +
72488 flush_icache_page(vma, page);
72489 entry = mk_pte(page, vma->vm_page_prot);
72490 if (flags & FAULT_FLAG_WRITE)
72491 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72492
72493 /* no need to invalidate: a not-present page won't be cached */
72494 update_mmu_cache(vma, address, page_table);
72495 +
72496 +#ifdef CONFIG_PAX_SEGMEXEC
72497 + if (anon)
72498 + pax_mirror_anon_pte(vma, address, page, ptl);
72499 + else
72500 + pax_mirror_file_pte(vma, address, page, ptl);
72501 +#endif
72502 +
72503 } else {
72504 if (cow_page)
72505 mem_cgroup_uncharge_page(cow_page);
72506 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72507 if (flags & FAULT_FLAG_WRITE)
72508 flush_tlb_fix_spurious_fault(vma, address);
72509 }
72510 +
72511 +#ifdef CONFIG_PAX_SEGMEXEC
72512 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72513 + return 0;
72514 +#endif
72515 +
72516 unlock:
72517 pte_unmap_unlock(pte, ptl);
72518 return 0;
72519 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72520 pmd_t *pmd;
72521 pte_t *pte;
72522
72523 +#ifdef CONFIG_PAX_SEGMEXEC
72524 + struct vm_area_struct *vma_m;
72525 +#endif
72526 +
72527 __set_current_state(TASK_RUNNING);
72528
72529 count_vm_event(PGFAULT);
72530 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72531 if (unlikely(is_vm_hugetlb_page(vma)))
72532 return hugetlb_fault(mm, vma, address, flags);
72533
72534 +#ifdef CONFIG_PAX_SEGMEXEC
72535 + vma_m = pax_find_mirror_vma(vma);
72536 + if (vma_m) {
72537 + unsigned long address_m;
72538 + pgd_t *pgd_m;
72539 + pud_t *pud_m;
72540 + pmd_t *pmd_m;
72541 +
72542 + if (vma->vm_start > vma_m->vm_start) {
72543 + address_m = address;
72544 + address -= SEGMEXEC_TASK_SIZE;
72545 + vma = vma_m;
72546 + } else
72547 + address_m = address + SEGMEXEC_TASK_SIZE;
72548 +
72549 + pgd_m = pgd_offset(mm, address_m);
72550 + pud_m = pud_alloc(mm, pgd_m, address_m);
72551 + if (!pud_m)
72552 + return VM_FAULT_OOM;
72553 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72554 + if (!pmd_m)
72555 + return VM_FAULT_OOM;
72556 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72557 + return VM_FAULT_OOM;
72558 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72559 + }
72560 +#endif
72561 +
72562 retry:
72563 pgd = pgd_offset(mm, address);
72564 pud = pud_alloc(mm, pgd, address);
72565 @@ -3547,7 +3788,7 @@ retry:
72566 * run pte_offset_map on the pmd, if an huge pmd could
72567 * materialize from under us from a different thread.
72568 */
72569 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72570 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72571 return VM_FAULT_OOM;
72572 /* if an huge pmd materialized from under us just retry later */
72573 if (unlikely(pmd_trans_huge(*pmd)))
72574 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72575 spin_unlock(&mm->page_table_lock);
72576 return 0;
72577 }
72578 +
72579 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72580 +{
72581 + pud_t *new = pud_alloc_one(mm, address);
72582 + if (!new)
72583 + return -ENOMEM;
72584 +
72585 + smp_wmb(); /* See comment in __pte_alloc */
72586 +
72587 + spin_lock(&mm->page_table_lock);
72588 + if (pgd_present(*pgd)) /* Another has populated it */
72589 + pud_free(mm, new);
72590 + else
72591 + pgd_populate_kernel(mm, pgd, new);
72592 + spin_unlock(&mm->page_table_lock);
72593 + return 0;
72594 +}
72595 #endif /* __PAGETABLE_PUD_FOLDED */
72596
72597 #ifndef __PAGETABLE_PMD_FOLDED
72598 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72599 spin_unlock(&mm->page_table_lock);
72600 return 0;
72601 }
72602 +
72603 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72604 +{
72605 + pmd_t *new = pmd_alloc_one(mm, address);
72606 + if (!new)
72607 + return -ENOMEM;
72608 +
72609 + smp_wmb(); /* See comment in __pte_alloc */
72610 +
72611 + spin_lock(&mm->page_table_lock);
72612 +#ifndef __ARCH_HAS_4LEVEL_HACK
72613 + if (pud_present(*pud)) /* Another has populated it */
72614 + pmd_free(mm, new);
72615 + else
72616 + pud_populate_kernel(mm, pud, new);
72617 +#else
72618 + if (pgd_present(*pud)) /* Another has populated it */
72619 + pmd_free(mm, new);
72620 + else
72621 + pgd_populate_kernel(mm, pud, new);
72622 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72623 + spin_unlock(&mm->page_table_lock);
72624 + return 0;
72625 +}
72626 #endif /* __PAGETABLE_PMD_FOLDED */
72627
72628 int make_pages_present(unsigned long addr, unsigned long end)
72629 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72630 gate_vma.vm_start = FIXADDR_USER_START;
72631 gate_vma.vm_end = FIXADDR_USER_END;
72632 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72633 - gate_vma.vm_page_prot = __P101;
72634 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72635
72636 return 0;
72637 }
72638 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72639 index 3d64b36..c6ab69c 100644
72640 --- a/mm/mempolicy.c
72641 +++ b/mm/mempolicy.c
72642 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72643 unsigned long vmstart;
72644 unsigned long vmend;
72645
72646 +#ifdef CONFIG_PAX_SEGMEXEC
72647 + struct vm_area_struct *vma_m;
72648 +#endif
72649 +
72650 vma = find_vma(mm, start);
72651 if (!vma || vma->vm_start > start)
72652 return -EFAULT;
72653 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72654 if (err)
72655 goto out;
72656 }
72657 +
72658 err = vma_replace_policy(vma, new_pol);
72659 if (err)
72660 goto out;
72661 +
72662 +#ifdef CONFIG_PAX_SEGMEXEC
72663 + vma_m = pax_find_mirror_vma(vma);
72664 + if (vma_m) {
72665 + err = vma_replace_policy(vma_m, new_pol);
72666 + if (err)
72667 + goto out;
72668 + }
72669 +#endif
72670 +
72671 }
72672
72673 out:
72674 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72675
72676 if (end < start)
72677 return -EINVAL;
72678 +
72679 +#ifdef CONFIG_PAX_SEGMEXEC
72680 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72681 + if (end > SEGMEXEC_TASK_SIZE)
72682 + return -EINVAL;
72683 + } else
72684 +#endif
72685 +
72686 + if (end > TASK_SIZE)
72687 + return -EINVAL;
72688 +
72689 if (end == start)
72690 return 0;
72691
72692 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72693 */
72694 tcred = __task_cred(task);
72695 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72696 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72697 - !capable(CAP_SYS_NICE)) {
72698 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72699 rcu_read_unlock();
72700 err = -EPERM;
72701 goto out_put;
72702 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72703 goto out;
72704 }
72705
72706 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72707 + if (mm != current->mm &&
72708 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72709 + mmput(mm);
72710 + err = -EPERM;
72711 + goto out;
72712 + }
72713 +#endif
72714 +
72715 err = do_migrate_pages(mm, old, new,
72716 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72717
72718 diff --git a/mm/migrate.c b/mm/migrate.c
72719 index 77ed2d7..317d528 100644
72720 --- a/mm/migrate.c
72721 +++ b/mm/migrate.c
72722 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72723 */
72724 tcred = __task_cred(task);
72725 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72726 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72727 - !capable(CAP_SYS_NICE)) {
72728 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72729 rcu_read_unlock();
72730 err = -EPERM;
72731 goto out;
72732 diff --git a/mm/mlock.c b/mm/mlock.c
72733 index ef726e8..cd7f1ec 100644
72734 --- a/mm/mlock.c
72735 +++ b/mm/mlock.c
72736 @@ -13,6 +13,7 @@
72737 #include <linux/pagemap.h>
72738 #include <linux/mempolicy.h>
72739 #include <linux/syscalls.h>
72740 +#include <linux/security.h>
72741 #include <linux/sched.h>
72742 #include <linux/export.h>
72743 #include <linux/rmap.h>
72744 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72745 {
72746 unsigned long nstart, end, tmp;
72747 struct vm_area_struct * vma, * prev;
72748 - int error;
72749 + int error = 0;
72750
72751 VM_BUG_ON(start & ~PAGE_MASK);
72752 VM_BUG_ON(len != PAGE_ALIGN(len));
72753 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72754 return -EINVAL;
72755 if (end == start)
72756 return 0;
72757 + if (end > TASK_SIZE)
72758 + return -EINVAL;
72759 +
72760 vma = find_vma(current->mm, start);
72761 if (!vma || vma->vm_start > start)
72762 return -ENOMEM;
72763 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72764 for (nstart = start ; ; ) {
72765 vm_flags_t newflags;
72766
72767 +#ifdef CONFIG_PAX_SEGMEXEC
72768 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72769 + break;
72770 +#endif
72771 +
72772 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72773
72774 newflags = vma->vm_flags | VM_LOCKED;
72775 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72776 lock_limit >>= PAGE_SHIFT;
72777
72778 /* check against resource limits */
72779 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72780 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72781 error = do_mlock(start, len, 1);
72782 up_write(&current->mm->mmap_sem);
72783 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72784 static int do_mlockall(int flags)
72785 {
72786 struct vm_area_struct * vma, * prev = NULL;
72787 - unsigned int def_flags = 0;
72788
72789 if (flags & MCL_FUTURE)
72790 - def_flags = VM_LOCKED;
72791 - current->mm->def_flags = def_flags;
72792 + current->mm->def_flags |= VM_LOCKED;
72793 + else
72794 + current->mm->def_flags &= ~VM_LOCKED;
72795 if (flags == MCL_FUTURE)
72796 goto out;
72797
72798 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72799 vm_flags_t newflags;
72800
72801 +#ifdef CONFIG_PAX_SEGMEXEC
72802 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72803 + break;
72804 +#endif
72805 +
72806 + BUG_ON(vma->vm_end > TASK_SIZE);
72807 newflags = vma->vm_flags | VM_LOCKED;
72808 if (!(flags & MCL_CURRENT))
72809 newflags &= ~VM_LOCKED;
72810 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72811 lock_limit >>= PAGE_SHIFT;
72812
72813 ret = -ENOMEM;
72814 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72815 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72816 capable(CAP_IPC_LOCK))
72817 ret = do_mlockall(flags);
72818 diff --git a/mm/mmap.c b/mm/mmap.c
72819 index ae18a48..86cf99e 100644
72820 --- a/mm/mmap.c
72821 +++ b/mm/mmap.c
72822 @@ -47,6 +47,16 @@
72823 #define arch_rebalance_pgtables(addr, len) (addr)
72824 #endif
72825
72826 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72827 +{
72828 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72829 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72830 + up_read(&mm->mmap_sem);
72831 + BUG();
72832 + }
72833 +#endif
72834 +}
72835 +
72836 static void unmap_region(struct mm_struct *mm,
72837 struct vm_area_struct *vma, struct vm_area_struct *prev,
72838 unsigned long start, unsigned long end);
72839 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72840 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72841 *
72842 */
72843 -pgprot_t protection_map[16] = {
72844 +pgprot_t protection_map[16] __read_only = {
72845 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72846 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72847 };
72848
72849 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72850 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72851 {
72852 - return __pgprot(pgprot_val(protection_map[vm_flags &
72853 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72854 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72855 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72856 +
72857 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72858 + if (!(__supported_pte_mask & _PAGE_NX) &&
72859 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72860 + (vm_flags & (VM_READ | VM_WRITE)))
72861 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72862 +#endif
72863 +
72864 + return prot;
72865 }
72866 EXPORT_SYMBOL(vm_get_page_prot);
72867
72868 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72869 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72870 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72871 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72872 /*
72873 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72874 * other variables. It can be updated by several CPUs frequently.
72875 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72876 struct vm_area_struct *next = vma->vm_next;
72877
72878 might_sleep();
72879 + BUG_ON(vma->vm_mirror);
72880 if (vma->vm_ops && vma->vm_ops->close)
72881 vma->vm_ops->close(vma);
72882 if (vma->vm_file) {
72883 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72884 * not page aligned -Ram Gupta
72885 */
72886 rlim = rlimit(RLIMIT_DATA);
72887 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72888 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72889 (mm->end_data - mm->start_data) > rlim)
72890 goto out;
72891 @@ -708,6 +730,12 @@ static int
72892 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72893 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72894 {
72895 +
72896 +#ifdef CONFIG_PAX_SEGMEXEC
72897 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72898 + return 0;
72899 +#endif
72900 +
72901 if (is_mergeable_vma(vma, file, vm_flags) &&
72902 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72903 if (vma->vm_pgoff == vm_pgoff)
72904 @@ -727,6 +755,12 @@ static int
72905 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72906 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72907 {
72908 +
72909 +#ifdef CONFIG_PAX_SEGMEXEC
72910 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72911 + return 0;
72912 +#endif
72913 +
72914 if (is_mergeable_vma(vma, file, vm_flags) &&
72915 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72916 pgoff_t vm_pglen;
72917 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72918 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72919 struct vm_area_struct *prev, unsigned long addr,
72920 unsigned long end, unsigned long vm_flags,
72921 - struct anon_vma *anon_vma, struct file *file,
72922 + struct anon_vma *anon_vma, struct file *file,
72923 pgoff_t pgoff, struct mempolicy *policy)
72924 {
72925 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72926 struct vm_area_struct *area, *next;
72927 int err;
72928
72929 +#ifdef CONFIG_PAX_SEGMEXEC
72930 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72931 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72932 +
72933 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72934 +#endif
72935 +
72936 /*
72937 * We later require that vma->vm_flags == vm_flags,
72938 * so this tests vma->vm_flags & VM_SPECIAL, too.
72939 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72940 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72941 next = next->vm_next;
72942
72943 +#ifdef CONFIG_PAX_SEGMEXEC
72944 + if (prev)
72945 + prev_m = pax_find_mirror_vma(prev);
72946 + if (area)
72947 + area_m = pax_find_mirror_vma(area);
72948 + if (next)
72949 + next_m = pax_find_mirror_vma(next);
72950 +#endif
72951 +
72952 /*
72953 * Can it merge with the predecessor?
72954 */
72955 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72956 /* cases 1, 6 */
72957 err = vma_adjust(prev, prev->vm_start,
72958 next->vm_end, prev->vm_pgoff, NULL);
72959 - } else /* cases 2, 5, 7 */
72960 +
72961 +#ifdef CONFIG_PAX_SEGMEXEC
72962 + if (!err && prev_m)
72963 + err = vma_adjust(prev_m, prev_m->vm_start,
72964 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72965 +#endif
72966 +
72967 + } else { /* cases 2, 5, 7 */
72968 err = vma_adjust(prev, prev->vm_start,
72969 end, prev->vm_pgoff, NULL);
72970 +
72971 +#ifdef CONFIG_PAX_SEGMEXEC
72972 + if (!err && prev_m)
72973 + err = vma_adjust(prev_m, prev_m->vm_start,
72974 + end_m, prev_m->vm_pgoff, NULL);
72975 +#endif
72976 +
72977 + }
72978 if (err)
72979 return NULL;
72980 khugepaged_enter_vma_merge(prev);
72981 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72982 mpol_equal(policy, vma_policy(next)) &&
72983 can_vma_merge_before(next, vm_flags,
72984 anon_vma, file, pgoff+pglen)) {
72985 - if (prev && addr < prev->vm_end) /* case 4 */
72986 + if (prev && addr < prev->vm_end) { /* case 4 */
72987 err = vma_adjust(prev, prev->vm_start,
72988 addr, prev->vm_pgoff, NULL);
72989 - else /* cases 3, 8 */
72990 +
72991 +#ifdef CONFIG_PAX_SEGMEXEC
72992 + if (!err && prev_m)
72993 + err = vma_adjust(prev_m, prev_m->vm_start,
72994 + addr_m, prev_m->vm_pgoff, NULL);
72995 +#endif
72996 +
72997 + } else { /* cases 3, 8 */
72998 err = vma_adjust(area, addr, next->vm_end,
72999 next->vm_pgoff - pglen, NULL);
73000 +
73001 +#ifdef CONFIG_PAX_SEGMEXEC
73002 + if (!err && area_m)
73003 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
73004 + next_m->vm_pgoff - pglen, NULL);
73005 +#endif
73006 +
73007 + }
73008 if (err)
73009 return NULL;
73010 khugepaged_enter_vma_merge(area);
73011 @@ -940,16 +1020,13 @@ none:
73012 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
73013 struct file *file, long pages)
73014 {
73015 - const unsigned long stack_flags
73016 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
73017 -
73018 mm->total_vm += pages;
73019
73020 if (file) {
73021 mm->shared_vm += pages;
73022 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
73023 mm->exec_vm += pages;
73024 - } else if (flags & stack_flags)
73025 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
73026 mm->stack_vm += pages;
73027 if (flags & (VM_RESERVED|VM_IO))
73028 mm->reserved_vm += pages;
73029 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73030 * (the exception is when the underlying filesystem is noexec
73031 * mounted, in which case we dont add PROT_EXEC.)
73032 */
73033 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
73034 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
73035 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
73036 prot |= PROT_EXEC;
73037
73038 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73039 /* Obtain the address to map to. we verify (or select) it and ensure
73040 * that it represents a valid section of the address space.
73041 */
73042 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
73043 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
73044 if (addr & ~PAGE_MASK)
73045 return addr;
73046
73047 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73048 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
73049 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
73050
73051 +#ifdef CONFIG_PAX_MPROTECT
73052 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73053 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73054 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
73055 + gr_log_rwxmmap(file);
73056 +
73057 +#ifdef CONFIG_PAX_EMUPLT
73058 + vm_flags &= ~VM_EXEC;
73059 +#else
73060 + return -EPERM;
73061 +#endif
73062 +
73063 + }
73064 +
73065 + if (!(vm_flags & VM_EXEC))
73066 + vm_flags &= ~VM_MAYEXEC;
73067 +#else
73068 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73069 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73070 +#endif
73071 + else
73072 + vm_flags &= ~VM_MAYWRITE;
73073 + }
73074 +#endif
73075 +
73076 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73077 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73078 + vm_flags &= ~VM_PAGEEXEC;
73079 +#endif
73080 +
73081 if (flags & MAP_LOCKED)
73082 if (!can_do_mlock())
73083 return -EPERM;
73084 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73085 locked += mm->locked_vm;
73086 lock_limit = rlimit(RLIMIT_MEMLOCK);
73087 lock_limit >>= PAGE_SHIFT;
73088 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73089 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73090 return -EAGAIN;
73091 }
73092 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73093 }
73094 }
73095
73096 + if (!gr_acl_handle_mmap(file, prot))
73097 + return -EACCES;
73098 +
73099 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73100 }
73101
73102 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73103 vm_flags_t vm_flags = vma->vm_flags;
73104
73105 /* If it was private or non-writable, the write bit is already clear */
73106 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73107 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73108 return 0;
73109
73110 /* The backer wishes to know when pages are first written to? */
73111 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73112 unsigned long charged = 0;
73113 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73114
73115 +#ifdef CONFIG_PAX_SEGMEXEC
73116 + struct vm_area_struct *vma_m = NULL;
73117 +#endif
73118 +
73119 + /*
73120 + * mm->mmap_sem is required to protect against another thread
73121 + * changing the mappings in case we sleep.
73122 + */
73123 + verify_mm_writelocked(mm);
73124 +
73125 /* Clear old maps */
73126 error = -ENOMEM;
73127 -munmap_back:
73128 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73129 if (vma && vma->vm_start < addr + len) {
73130 if (do_munmap(mm, addr, len))
73131 return -ENOMEM;
73132 - goto munmap_back;
73133 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73134 + BUG_ON(vma && vma->vm_start < addr + len);
73135 }
73136
73137 /* Check against address space limit. */
73138 @@ -1282,6 +1403,16 @@ munmap_back:
73139 goto unacct_error;
73140 }
73141
73142 +#ifdef CONFIG_PAX_SEGMEXEC
73143 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73144 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73145 + if (!vma_m) {
73146 + error = -ENOMEM;
73147 + goto free_vma;
73148 + }
73149 + }
73150 +#endif
73151 +
73152 vma->vm_mm = mm;
73153 vma->vm_start = addr;
73154 vma->vm_end = addr + len;
73155 @@ -1306,6 +1437,19 @@ munmap_back:
73156 error = file->f_op->mmap(file, vma);
73157 if (error)
73158 goto unmap_and_free_vma;
73159 +
73160 +#ifdef CONFIG_PAX_SEGMEXEC
73161 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73162 + added_exe_file_vma(mm);
73163 +#endif
73164 +
73165 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73166 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73167 + vma->vm_flags |= VM_PAGEEXEC;
73168 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73169 + }
73170 +#endif
73171 +
73172 if (vm_flags & VM_EXECUTABLE)
73173 added_exe_file_vma(mm);
73174
73175 @@ -1343,6 +1487,11 @@ munmap_back:
73176 vma_link(mm, vma, prev, rb_link, rb_parent);
73177 file = vma->vm_file;
73178
73179 +#ifdef CONFIG_PAX_SEGMEXEC
73180 + if (vma_m)
73181 + BUG_ON(pax_mirror_vma(vma_m, vma));
73182 +#endif
73183 +
73184 /* Once vma denies write, undo our temporary denial count */
73185 if (correct_wcount)
73186 atomic_inc(&inode->i_writecount);
73187 @@ -1350,6 +1499,7 @@ out:
73188 perf_event_mmap(vma);
73189
73190 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73191 + track_exec_limit(mm, addr, addr + len, vm_flags);
73192 if (vm_flags & VM_LOCKED) {
73193 if (!mlock_vma_pages_range(vma, addr, addr + len))
73194 mm->locked_vm += (len >> PAGE_SHIFT);
73195 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73196 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73197 charged = 0;
73198 free_vma:
73199 +
73200 +#ifdef CONFIG_PAX_SEGMEXEC
73201 + if (vma_m)
73202 + kmem_cache_free(vm_area_cachep, vma_m);
73203 +#endif
73204 +
73205 kmem_cache_free(vm_area_cachep, vma);
73206 unacct_error:
73207 if (charged)
73208 @@ -1378,6 +1534,44 @@ unacct_error:
73209 return error;
73210 }
73211
73212 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73213 +{
73214 + if (!vma) {
73215 +#ifdef CONFIG_STACK_GROWSUP
73216 + if (addr > sysctl_heap_stack_gap)
73217 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73218 + else
73219 + vma = find_vma(current->mm, 0);
73220 + if (vma && (vma->vm_flags & VM_GROWSUP))
73221 + return false;
73222 +#endif
73223 + return true;
73224 + }
73225 +
73226 + if (addr + len > vma->vm_start)
73227 + return false;
73228 +
73229 + if (vma->vm_flags & VM_GROWSDOWN)
73230 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73231 +#ifdef CONFIG_STACK_GROWSUP
73232 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73233 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73234 +#endif
73235 +
73236 + return true;
73237 +}
73238 +
73239 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73240 +{
73241 + if (vma->vm_start < len)
73242 + return -ENOMEM;
73243 + if (!(vma->vm_flags & VM_GROWSDOWN))
73244 + return vma->vm_start - len;
73245 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73246 + return vma->vm_start - len - sysctl_heap_stack_gap;
73247 + return -ENOMEM;
73248 +}
73249 +
73250 /* Get an address range which is currently unmapped.
73251 * For shmat() with addr=0.
73252 *
73253 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73254 if (flags & MAP_FIXED)
73255 return addr;
73256
73257 +#ifdef CONFIG_PAX_RANDMMAP
73258 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73259 +#endif
73260 +
73261 if (addr) {
73262 addr = PAGE_ALIGN(addr);
73263 - vma = find_vma(mm, addr);
73264 - if (TASK_SIZE - len >= addr &&
73265 - (!vma || addr + len <= vma->vm_start))
73266 - return addr;
73267 + if (TASK_SIZE - len >= addr) {
73268 + vma = find_vma(mm, addr);
73269 + if (check_heap_stack_gap(vma, addr, len))
73270 + return addr;
73271 + }
73272 }
73273 if (len > mm->cached_hole_size) {
73274 - start_addr = addr = mm->free_area_cache;
73275 + start_addr = addr = mm->free_area_cache;
73276 } else {
73277 - start_addr = addr = TASK_UNMAPPED_BASE;
73278 - mm->cached_hole_size = 0;
73279 + start_addr = addr = mm->mmap_base;
73280 + mm->cached_hole_size = 0;
73281 }
73282
73283 full_search:
73284 @@ -1426,34 +1625,40 @@ full_search:
73285 * Start a new search - just in case we missed
73286 * some holes.
73287 */
73288 - if (start_addr != TASK_UNMAPPED_BASE) {
73289 - addr = TASK_UNMAPPED_BASE;
73290 - start_addr = addr;
73291 + if (start_addr != mm->mmap_base) {
73292 + start_addr = addr = mm->mmap_base;
73293 mm->cached_hole_size = 0;
73294 goto full_search;
73295 }
73296 return -ENOMEM;
73297 }
73298 - if (!vma || addr + len <= vma->vm_start) {
73299 - /*
73300 - * Remember the place where we stopped the search:
73301 - */
73302 - mm->free_area_cache = addr + len;
73303 - return addr;
73304 - }
73305 + if (check_heap_stack_gap(vma, addr, len))
73306 + break;
73307 if (addr + mm->cached_hole_size < vma->vm_start)
73308 mm->cached_hole_size = vma->vm_start - addr;
73309 addr = vma->vm_end;
73310 }
73311 +
73312 + /*
73313 + * Remember the place where we stopped the search:
73314 + */
73315 + mm->free_area_cache = addr + len;
73316 + return addr;
73317 }
73318 #endif
73319
73320 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73321 {
73322 +
73323 +#ifdef CONFIG_PAX_SEGMEXEC
73324 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73325 + return;
73326 +#endif
73327 +
73328 /*
73329 * Is this a new hole at the lowest possible address?
73330 */
73331 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73332 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73333 mm->free_area_cache = addr;
73334 }
73335
73336 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73337 {
73338 struct vm_area_struct *vma;
73339 struct mm_struct *mm = current->mm;
73340 - unsigned long addr = addr0, start_addr;
73341 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73342
73343 /* requested length too big for entire address space */
73344 if (len > TASK_SIZE)
73345 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73346 if (flags & MAP_FIXED)
73347 return addr;
73348
73349 +#ifdef CONFIG_PAX_RANDMMAP
73350 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73351 +#endif
73352 +
73353 /* requesting a specific address */
73354 if (addr) {
73355 addr = PAGE_ALIGN(addr);
73356 - vma = find_vma(mm, addr);
73357 - if (TASK_SIZE - len >= addr &&
73358 - (!vma || addr + len <= vma->vm_start))
73359 - return addr;
73360 + if (TASK_SIZE - len >= addr) {
73361 + vma = find_vma(mm, addr);
73362 + if (check_heap_stack_gap(vma, addr, len))
73363 + return addr;
73364 + }
73365 }
73366
73367 /* check if free_area_cache is useful for us */
73368 @@ -1508,7 +1718,7 @@ try_again:
73369 * return with success:
73370 */
73371 vma = find_vma(mm, addr);
73372 - if (!vma || addr+len <= vma->vm_start)
73373 + if (check_heap_stack_gap(vma, addr, len))
73374 /* remember the address as a hint for next time */
73375 return (mm->free_area_cache = addr);
73376
73377 @@ -1517,8 +1727,8 @@ try_again:
73378 mm->cached_hole_size = vma->vm_start - addr;
73379
73380 /* try just below the current vma->vm_start */
73381 - addr = vma->vm_start-len;
73382 - } while (len < vma->vm_start);
73383 + addr = skip_heap_stack_gap(vma, len);
73384 + } while (!IS_ERR_VALUE(addr));
73385
73386 fail:
73387 /*
73388 @@ -1541,13 +1751,21 @@ fail:
73389 * can happen with large stack limits and large mmap()
73390 * allocations.
73391 */
73392 + mm->mmap_base = TASK_UNMAPPED_BASE;
73393 +
73394 +#ifdef CONFIG_PAX_RANDMMAP
73395 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73396 + mm->mmap_base += mm->delta_mmap;
73397 +#endif
73398 +
73399 + mm->free_area_cache = mm->mmap_base;
73400 mm->cached_hole_size = ~0UL;
73401 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73402 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73403 /*
73404 * Restore the topdown base:
73405 */
73406 - mm->free_area_cache = mm->mmap_base;
73407 + mm->mmap_base = base;
73408 + mm->free_area_cache = base;
73409 mm->cached_hole_size = ~0UL;
73410
73411 return addr;
73412 @@ -1556,6 +1774,12 @@ fail:
73413
73414 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73415 {
73416 +
73417 +#ifdef CONFIG_PAX_SEGMEXEC
73418 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73419 + return;
73420 +#endif
73421 +
73422 /*
73423 * Is this a new hole at the highest possible address?
73424 */
73425 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73426 mm->free_area_cache = addr;
73427
73428 /* dont allow allocations above current base */
73429 - if (mm->free_area_cache > mm->mmap_base)
73430 + if (mm->free_area_cache > mm->mmap_base) {
73431 mm->free_area_cache = mm->mmap_base;
73432 + mm->cached_hole_size = ~0UL;
73433 + }
73434 }
73435
73436 unsigned long
73437 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73438 return vma;
73439 }
73440
73441 +#ifdef CONFIG_PAX_SEGMEXEC
73442 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73443 +{
73444 + struct vm_area_struct *vma_m;
73445 +
73446 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73447 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73448 + BUG_ON(vma->vm_mirror);
73449 + return NULL;
73450 + }
73451 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73452 + vma_m = vma->vm_mirror;
73453 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73454 + BUG_ON(vma->vm_file != vma_m->vm_file);
73455 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73456 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73457 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73458 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73459 + return vma_m;
73460 +}
73461 +#endif
73462 +
73463 /*
73464 * Verify that the stack growth is acceptable and
73465 * update accounting. This is shared with both the
73466 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73467 return -ENOMEM;
73468
73469 /* Stack limit test */
73470 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73471 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73472 return -ENOMEM;
73473
73474 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73475 locked = mm->locked_vm + grow;
73476 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73477 limit >>= PAGE_SHIFT;
73478 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73479 if (locked > limit && !capable(CAP_IPC_LOCK))
73480 return -ENOMEM;
73481 }
73482 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73483 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73484 * vma is the last one with address > vma->vm_end. Have to extend vma.
73485 */
73486 +#ifndef CONFIG_IA64
73487 +static
73488 +#endif
73489 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73490 {
73491 int error;
73492 + bool locknext;
73493
73494 if (!(vma->vm_flags & VM_GROWSUP))
73495 return -EFAULT;
73496
73497 + /* Also guard against wrapping around to address 0. */
73498 + if (address < PAGE_ALIGN(address+1))
73499 + address = PAGE_ALIGN(address+1);
73500 + else
73501 + return -ENOMEM;
73502 +
73503 /*
73504 * We must make sure the anon_vma is allocated
73505 * so that the anon_vma locking is not a noop.
73506 */
73507 if (unlikely(anon_vma_prepare(vma)))
73508 return -ENOMEM;
73509 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73510 + if (locknext && anon_vma_prepare(vma->vm_next))
73511 + return -ENOMEM;
73512 vma_lock_anon_vma(vma);
73513 + if (locknext)
73514 + vma_lock_anon_vma(vma->vm_next);
73515
73516 /*
73517 * vma->vm_start/vm_end cannot change under us because the caller
73518 * is required to hold the mmap_sem in read mode. We need the
73519 - * anon_vma lock to serialize against concurrent expand_stacks.
73520 - * Also guard against wrapping around to address 0.
73521 + * anon_vma locks to serialize against concurrent expand_stacks
73522 + * and expand_upwards.
73523 */
73524 - if (address < PAGE_ALIGN(address+4))
73525 - address = PAGE_ALIGN(address+4);
73526 - else {
73527 - vma_unlock_anon_vma(vma);
73528 - return -ENOMEM;
73529 - }
73530 error = 0;
73531
73532 /* Somebody else might have raced and expanded it already */
73533 - if (address > vma->vm_end) {
73534 + 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)
73535 + error = -ENOMEM;
73536 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73537 unsigned long size, grow;
73538
73539 size = address - vma->vm_start;
73540 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73541 }
73542 }
73543 }
73544 + if (locknext)
73545 + vma_unlock_anon_vma(vma->vm_next);
73546 vma_unlock_anon_vma(vma);
73547 khugepaged_enter_vma_merge(vma);
73548 return error;
73549 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73550 unsigned long address)
73551 {
73552 int error;
73553 + bool lockprev = false;
73554 + struct vm_area_struct *prev;
73555
73556 /*
73557 * We must make sure the anon_vma is allocated
73558 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73559 if (error)
73560 return error;
73561
73562 + prev = vma->vm_prev;
73563 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73564 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73565 +#endif
73566 + if (lockprev && anon_vma_prepare(prev))
73567 + return -ENOMEM;
73568 + if (lockprev)
73569 + vma_lock_anon_vma(prev);
73570 +
73571 vma_lock_anon_vma(vma);
73572
73573 /*
73574 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73575 */
73576
73577 /* Somebody else might have raced and expanded it already */
73578 - if (address < vma->vm_start) {
73579 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73580 + error = -ENOMEM;
73581 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73582 unsigned long size, grow;
73583
73584 +#ifdef CONFIG_PAX_SEGMEXEC
73585 + struct vm_area_struct *vma_m;
73586 +
73587 + vma_m = pax_find_mirror_vma(vma);
73588 +#endif
73589 +
73590 size = vma->vm_end - address;
73591 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73592
73593 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73594 if (!error) {
73595 vma->vm_start = address;
73596 vma->vm_pgoff -= grow;
73597 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73598 +
73599 +#ifdef CONFIG_PAX_SEGMEXEC
73600 + if (vma_m) {
73601 + vma_m->vm_start -= grow << PAGE_SHIFT;
73602 + vma_m->vm_pgoff -= grow;
73603 + }
73604 +#endif
73605 +
73606 perf_event_mmap(vma);
73607 }
73608 }
73609 }
73610 vma_unlock_anon_vma(vma);
73611 + if (lockprev)
73612 + vma_unlock_anon_vma(prev);
73613 khugepaged_enter_vma_merge(vma);
73614 return error;
73615 }
73616 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73617 do {
73618 long nrpages = vma_pages(vma);
73619
73620 +#ifdef CONFIG_PAX_SEGMEXEC
73621 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73622 + vma = remove_vma(vma);
73623 + continue;
73624 + }
73625 +#endif
73626 +
73627 if (vma->vm_flags & VM_ACCOUNT)
73628 nr_accounted += nrpages;
73629 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73630 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73631 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73632 vma->vm_prev = NULL;
73633 do {
73634 +
73635 +#ifdef CONFIG_PAX_SEGMEXEC
73636 + if (vma->vm_mirror) {
73637 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73638 + vma->vm_mirror->vm_mirror = NULL;
73639 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73640 + vma->vm_mirror = NULL;
73641 + }
73642 +#endif
73643 +
73644 rb_erase(&vma->vm_rb, &mm->mm_rb);
73645 mm->map_count--;
73646 tail_vma = vma;
73647 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73648 struct vm_area_struct *new;
73649 int err = -ENOMEM;
73650
73651 +#ifdef CONFIG_PAX_SEGMEXEC
73652 + struct vm_area_struct *vma_m, *new_m = NULL;
73653 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73654 +#endif
73655 +
73656 if (is_vm_hugetlb_page(vma) && (addr &
73657 ~(huge_page_mask(hstate_vma(vma)))))
73658 return -EINVAL;
73659
73660 +#ifdef CONFIG_PAX_SEGMEXEC
73661 + vma_m = pax_find_mirror_vma(vma);
73662 +#endif
73663 +
73664 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73665 if (!new)
73666 goto out_err;
73667
73668 +#ifdef CONFIG_PAX_SEGMEXEC
73669 + if (vma_m) {
73670 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73671 + if (!new_m) {
73672 + kmem_cache_free(vm_area_cachep, new);
73673 + goto out_err;
73674 + }
73675 + }
73676 +#endif
73677 +
73678 /* most fields are the same, copy all, and then fixup */
73679 *new = *vma;
73680
73681 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73682 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73683 }
73684
73685 +#ifdef CONFIG_PAX_SEGMEXEC
73686 + if (vma_m) {
73687 + *new_m = *vma_m;
73688 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73689 + new_m->vm_mirror = new;
73690 + new->vm_mirror = new_m;
73691 +
73692 + if (new_below)
73693 + new_m->vm_end = addr_m;
73694 + else {
73695 + new_m->vm_start = addr_m;
73696 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73697 + }
73698 + }
73699 +#endif
73700 +
73701 pol = mpol_dup(vma_policy(vma));
73702 if (IS_ERR(pol)) {
73703 err = PTR_ERR(pol);
73704 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73705 else
73706 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73707
73708 +#ifdef CONFIG_PAX_SEGMEXEC
73709 + if (!err && vma_m) {
73710 + if (anon_vma_clone(new_m, vma_m))
73711 + goto out_free_mpol;
73712 +
73713 + mpol_get(pol);
73714 + vma_set_policy(new_m, pol);
73715 +
73716 + if (new_m->vm_file) {
73717 + get_file(new_m->vm_file);
73718 + if (vma_m->vm_flags & VM_EXECUTABLE)
73719 + added_exe_file_vma(mm);
73720 + }
73721 +
73722 + if (new_m->vm_ops && new_m->vm_ops->open)
73723 + new_m->vm_ops->open(new_m);
73724 +
73725 + if (new_below)
73726 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73727 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73728 + else
73729 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73730 +
73731 + if (err) {
73732 + if (new_m->vm_ops && new_m->vm_ops->close)
73733 + new_m->vm_ops->close(new_m);
73734 + if (new_m->vm_file) {
73735 + if (vma_m->vm_flags & VM_EXECUTABLE)
73736 + removed_exe_file_vma(mm);
73737 + fput(new_m->vm_file);
73738 + }
73739 + mpol_put(pol);
73740 + }
73741 + }
73742 +#endif
73743 +
73744 /* Success. */
73745 if (!err)
73746 return 0;
73747 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73748 removed_exe_file_vma(mm);
73749 fput(new->vm_file);
73750 }
73751 - unlink_anon_vmas(new);
73752 out_free_mpol:
73753 mpol_put(pol);
73754 out_free_vma:
73755 +
73756 +#ifdef CONFIG_PAX_SEGMEXEC
73757 + if (new_m) {
73758 + unlink_anon_vmas(new_m);
73759 + kmem_cache_free(vm_area_cachep, new_m);
73760 + }
73761 +#endif
73762 +
73763 + unlink_anon_vmas(new);
73764 kmem_cache_free(vm_area_cachep, new);
73765 out_err:
73766 return err;
73767 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73768 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73769 unsigned long addr, int new_below)
73770 {
73771 +
73772 +#ifdef CONFIG_PAX_SEGMEXEC
73773 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73774 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73775 + if (mm->map_count >= sysctl_max_map_count-1)
73776 + return -ENOMEM;
73777 + } else
73778 +#endif
73779 +
73780 if (mm->map_count >= sysctl_max_map_count)
73781 return -ENOMEM;
73782
73783 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73784 * work. This now handles partial unmappings.
73785 * Jeremy Fitzhardinge <jeremy@goop.org>
73786 */
73787 +#ifdef CONFIG_PAX_SEGMEXEC
73788 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73789 {
73790 + int ret = __do_munmap(mm, start, len);
73791 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73792 + return ret;
73793 +
73794 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73795 +}
73796 +
73797 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73798 +#else
73799 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73800 +#endif
73801 +{
73802 unsigned long end;
73803 struct vm_area_struct *vma, *prev, *last;
73804
73805 + /*
73806 + * mm->mmap_sem is required to protect against another thread
73807 + * changing the mappings in case we sleep.
73808 + */
73809 + verify_mm_writelocked(mm);
73810 +
73811 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73812 return -EINVAL;
73813
73814 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73815 /* Fix up all other VM information */
73816 remove_vma_list(mm, vma);
73817
73818 + track_exec_limit(mm, start, end, 0UL);
73819 +
73820 return 0;
73821 }
73822
73823 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73824 int ret;
73825 struct mm_struct *mm = current->mm;
73826
73827 +
73828 +#ifdef CONFIG_PAX_SEGMEXEC
73829 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73830 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73831 + return -EINVAL;
73832 +#endif
73833 +
73834 down_write(&mm->mmap_sem);
73835 ret = do_munmap(mm, start, len);
73836 up_write(&mm->mmap_sem);
73837 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73838 return vm_munmap(addr, len);
73839 }
73840
73841 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73842 -{
73843 -#ifdef CONFIG_DEBUG_VM
73844 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73845 - WARN_ON(1);
73846 - up_read(&mm->mmap_sem);
73847 - }
73848 -#endif
73849 -}
73850 -
73851 /*
73852 * this is really a simplified "do_mmap". it only handles
73853 * anonymous maps. eventually we may be able to do some
73854 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73855 struct rb_node ** rb_link, * rb_parent;
73856 pgoff_t pgoff = addr >> PAGE_SHIFT;
73857 int error;
73858 + unsigned long charged;
73859
73860 len = PAGE_ALIGN(len);
73861 if (!len)
73862 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73863
73864 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73865
73866 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73867 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73868 + flags &= ~VM_EXEC;
73869 +
73870 +#ifdef CONFIG_PAX_MPROTECT
73871 + if (mm->pax_flags & MF_PAX_MPROTECT)
73872 + flags &= ~VM_MAYEXEC;
73873 +#endif
73874 +
73875 + }
73876 +#endif
73877 +
73878 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73879 if (error & ~PAGE_MASK)
73880 return error;
73881
73882 + charged = len >> PAGE_SHIFT;
73883 +
73884 /*
73885 * mlock MCL_FUTURE?
73886 */
73887 if (mm->def_flags & VM_LOCKED) {
73888 unsigned long locked, lock_limit;
73889 - locked = len >> PAGE_SHIFT;
73890 + locked = charged;
73891 locked += mm->locked_vm;
73892 lock_limit = rlimit(RLIMIT_MEMLOCK);
73893 lock_limit >>= PAGE_SHIFT;
73894 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73895 /*
73896 * Clear old maps. this also does some error checking for us
73897 */
73898 - munmap_back:
73899 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73900 if (vma && vma->vm_start < addr + len) {
73901 if (do_munmap(mm, addr, len))
73902 return -ENOMEM;
73903 - goto munmap_back;
73904 - }
73905 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73906 + BUG_ON(vma && vma->vm_start < addr + len);
73907 + }
73908
73909 /* Check against address space limits *after* clearing old maps... */
73910 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73911 + if (!may_expand_vm(mm, charged))
73912 return -ENOMEM;
73913
73914 if (mm->map_count > sysctl_max_map_count)
73915 return -ENOMEM;
73916
73917 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73918 + if (security_vm_enough_memory_mm(mm, charged))
73919 return -ENOMEM;
73920
73921 /* Can we just expand an old private anonymous mapping? */
73922 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73923 */
73924 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73925 if (!vma) {
73926 - vm_unacct_memory(len >> PAGE_SHIFT);
73927 + vm_unacct_memory(charged);
73928 return -ENOMEM;
73929 }
73930
73931 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73932 vma_link(mm, vma, prev, rb_link, rb_parent);
73933 out:
73934 perf_event_mmap(vma);
73935 - mm->total_vm += len >> PAGE_SHIFT;
73936 + mm->total_vm += charged;
73937 if (flags & VM_LOCKED) {
73938 if (!mlock_vma_pages_range(vma, addr, addr + len))
73939 - mm->locked_vm += (len >> PAGE_SHIFT);
73940 + mm->locked_vm += charged;
73941 }
73942 + track_exec_limit(mm, addr, addr + len, flags);
73943 return addr;
73944 }
73945
73946 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73947 while (vma) {
73948 if (vma->vm_flags & VM_ACCOUNT)
73949 nr_accounted += vma_pages(vma);
73950 + vma->vm_mirror = NULL;
73951 vma = remove_vma(vma);
73952 }
73953 vm_unacct_memory(nr_accounted);
73954 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73955 struct vm_area_struct * __vma, * prev;
73956 struct rb_node ** rb_link, * rb_parent;
73957
73958 +#ifdef CONFIG_PAX_SEGMEXEC
73959 + struct vm_area_struct *vma_m = NULL;
73960 +#endif
73961 +
73962 + if (security_mmap_addr(vma->vm_start))
73963 + return -EPERM;
73964 +
73965 /*
73966 * The vm_pgoff of a purely anonymous vma should be irrelevant
73967 * until its first write fault, when page's anon_vma and index
73968 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73969 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73970 return -ENOMEM;
73971
73972 +#ifdef CONFIG_PAX_SEGMEXEC
73973 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73974 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73975 + if (!vma_m)
73976 + return -ENOMEM;
73977 + }
73978 +#endif
73979 +
73980 vma_link(mm, vma, prev, rb_link, rb_parent);
73981 +
73982 +#ifdef CONFIG_PAX_SEGMEXEC
73983 + if (vma_m)
73984 + BUG_ON(pax_mirror_vma(vma_m, vma));
73985 +#endif
73986 +
73987 return 0;
73988 }
73989
73990 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73991 struct mempolicy *pol;
73992 bool faulted_in_anon_vma = true;
73993
73994 + BUG_ON(vma->vm_mirror);
73995 +
73996 /*
73997 * If anonymous vma has not yet been faulted, update new pgoff
73998 * to match new location, to increase its chance of merging.
73999 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
74000 return NULL;
74001 }
74002
74003 +#ifdef CONFIG_PAX_SEGMEXEC
74004 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
74005 +{
74006 + struct vm_area_struct *prev_m;
74007 + struct rb_node **rb_link_m, *rb_parent_m;
74008 + struct mempolicy *pol_m;
74009 +
74010 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
74011 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
74012 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
74013 + *vma_m = *vma;
74014 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
74015 + if (anon_vma_clone(vma_m, vma))
74016 + return -ENOMEM;
74017 + pol_m = vma_policy(vma_m);
74018 + mpol_get(pol_m);
74019 + vma_set_policy(vma_m, pol_m);
74020 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
74021 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
74022 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
74023 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
74024 + if (vma_m->vm_file)
74025 + get_file(vma_m->vm_file);
74026 + if (vma_m->vm_ops && vma_m->vm_ops->open)
74027 + vma_m->vm_ops->open(vma_m);
74028 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
74029 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
74030 + vma_m->vm_mirror = vma;
74031 + vma->vm_mirror = vma_m;
74032 + return 0;
74033 +}
74034 +#endif
74035 +
74036 /*
74037 * Return true if the calling process may expand its vm space by the passed
74038 * number of pages
74039 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
74040
74041 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
74042
74043 +#ifdef CONFIG_PAX_RANDMMAP
74044 + if (mm->pax_flags & MF_PAX_RANDMMAP)
74045 + cur -= mm->brk_gap;
74046 +#endif
74047 +
74048 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
74049 if (cur + npages > lim)
74050 return 0;
74051 return 1;
74052 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
74053 vma->vm_start = addr;
74054 vma->vm_end = addr + len;
74055
74056 +#ifdef CONFIG_PAX_MPROTECT
74057 + if (mm->pax_flags & MF_PAX_MPROTECT) {
74058 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
74059 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
74060 + return -EPERM;
74061 + if (!(vm_flags & VM_EXEC))
74062 + vm_flags &= ~VM_MAYEXEC;
74063 +#else
74064 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
74065 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
74066 +#endif
74067 + else
74068 + vm_flags &= ~VM_MAYWRITE;
74069 + }
74070 +#endif
74071 +
74072 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74073 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74074
74075 diff --git a/mm/mprotect.c b/mm/mprotect.c
74076 index a409926..8b32e6d 100644
74077 --- a/mm/mprotect.c
74078 +++ b/mm/mprotect.c
74079 @@ -23,10 +23,17 @@
74080 #include <linux/mmu_notifier.h>
74081 #include <linux/migrate.h>
74082 #include <linux/perf_event.h>
74083 +
74084 +#ifdef CONFIG_PAX_MPROTECT
74085 +#include <linux/elf.h>
74086 +#include <linux/binfmts.h>
74087 +#endif
74088 +
74089 #include <asm/uaccess.h>
74090 #include <asm/pgtable.h>
74091 #include <asm/cacheflush.h>
74092 #include <asm/tlbflush.h>
74093 +#include <asm/mmu_context.h>
74094
74095 #ifndef pgprot_modify
74096 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74097 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74098 flush_tlb_range(vma, start, end);
74099 }
74100
74101 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74102 +/* called while holding the mmap semaphor for writing except stack expansion */
74103 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74104 +{
74105 + unsigned long oldlimit, newlimit = 0UL;
74106 +
74107 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74108 + return;
74109 +
74110 + spin_lock(&mm->page_table_lock);
74111 + oldlimit = mm->context.user_cs_limit;
74112 + if ((prot & VM_EXEC) && oldlimit < end)
74113 + /* USER_CS limit moved up */
74114 + newlimit = end;
74115 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74116 + /* USER_CS limit moved down */
74117 + newlimit = start;
74118 +
74119 + if (newlimit) {
74120 + mm->context.user_cs_limit = newlimit;
74121 +
74122 +#ifdef CONFIG_SMP
74123 + wmb();
74124 + cpus_clear(mm->context.cpu_user_cs_mask);
74125 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74126 +#endif
74127 +
74128 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74129 + }
74130 + spin_unlock(&mm->page_table_lock);
74131 + if (newlimit == end) {
74132 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74133 +
74134 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74135 + if (is_vm_hugetlb_page(vma))
74136 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74137 + else
74138 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74139 + }
74140 +}
74141 +#endif
74142 +
74143 int
74144 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74145 unsigned long start, unsigned long end, unsigned long newflags)
74146 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74147 int error;
74148 int dirty_accountable = 0;
74149
74150 +#ifdef CONFIG_PAX_SEGMEXEC
74151 + struct vm_area_struct *vma_m = NULL;
74152 + unsigned long start_m, end_m;
74153 +
74154 + start_m = start + SEGMEXEC_TASK_SIZE;
74155 + end_m = end + SEGMEXEC_TASK_SIZE;
74156 +#endif
74157 +
74158 if (newflags == oldflags) {
74159 *pprev = vma;
74160 return 0;
74161 }
74162
74163 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74164 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74165 +
74166 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74167 + return -ENOMEM;
74168 +
74169 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74170 + return -ENOMEM;
74171 + }
74172 +
74173 /*
74174 * If we make a private mapping writable we increase our commit;
74175 * but (without finer accounting) cannot reduce our commit if we
74176 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74177 }
74178 }
74179
74180 +#ifdef CONFIG_PAX_SEGMEXEC
74181 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74182 + if (start != vma->vm_start) {
74183 + error = split_vma(mm, vma, start, 1);
74184 + if (error)
74185 + goto fail;
74186 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74187 + *pprev = (*pprev)->vm_next;
74188 + }
74189 +
74190 + if (end != vma->vm_end) {
74191 + error = split_vma(mm, vma, end, 0);
74192 + if (error)
74193 + goto fail;
74194 + }
74195 +
74196 + if (pax_find_mirror_vma(vma)) {
74197 + error = __do_munmap(mm, start_m, end_m - start_m);
74198 + if (error)
74199 + goto fail;
74200 + } else {
74201 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74202 + if (!vma_m) {
74203 + error = -ENOMEM;
74204 + goto fail;
74205 + }
74206 + vma->vm_flags = newflags;
74207 + error = pax_mirror_vma(vma_m, vma);
74208 + if (error) {
74209 + vma->vm_flags = oldflags;
74210 + goto fail;
74211 + }
74212 + }
74213 + }
74214 +#endif
74215 +
74216 /*
74217 * First try to merge with previous and/or next vma.
74218 */
74219 @@ -204,9 +307,21 @@ success:
74220 * vm_flags and vm_page_prot are protected by the mmap_sem
74221 * held in write mode.
74222 */
74223 +
74224 +#ifdef CONFIG_PAX_SEGMEXEC
74225 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74226 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74227 +#endif
74228 +
74229 vma->vm_flags = newflags;
74230 +
74231 +#ifdef CONFIG_PAX_MPROTECT
74232 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74233 + mm->binfmt->handle_mprotect(vma, newflags);
74234 +#endif
74235 +
74236 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74237 - vm_get_page_prot(newflags));
74238 + vm_get_page_prot(vma->vm_flags));
74239
74240 if (vma_wants_writenotify(vma)) {
74241 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74242 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74243 end = start + len;
74244 if (end <= start)
74245 return -ENOMEM;
74246 +
74247 +#ifdef CONFIG_PAX_SEGMEXEC
74248 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74249 + if (end > SEGMEXEC_TASK_SIZE)
74250 + return -EINVAL;
74251 + } else
74252 +#endif
74253 +
74254 + if (end > TASK_SIZE)
74255 + return -EINVAL;
74256 +
74257 if (!arch_validate_prot(prot))
74258 return -EINVAL;
74259
74260 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74261 /*
74262 * Does the application expect PROT_READ to imply PROT_EXEC:
74263 */
74264 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74265 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74266 prot |= PROT_EXEC;
74267
74268 vm_flags = calc_vm_prot_bits(prot);
74269 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74270 if (start > vma->vm_start)
74271 prev = vma;
74272
74273 +#ifdef CONFIG_PAX_MPROTECT
74274 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74275 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74276 +#endif
74277 +
74278 for (nstart = start ; ; ) {
74279 unsigned long newflags;
74280
74281 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74282
74283 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74284 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74285 + if (prot & (PROT_WRITE | PROT_EXEC))
74286 + gr_log_rwxmprotect(vma->vm_file);
74287 +
74288 + error = -EACCES;
74289 + goto out;
74290 + }
74291 +
74292 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74293 error = -EACCES;
74294 goto out;
74295 }
74296 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74297 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74298 if (error)
74299 goto out;
74300 +
74301 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74302 +
74303 nstart = tmp;
74304
74305 if (nstart < prev->vm_end)
74306 diff --git a/mm/mremap.c b/mm/mremap.c
74307 index cc06d0e..40b5d18 100644
74308 --- a/mm/mremap.c
74309 +++ b/mm/mremap.c
74310 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74311 continue;
74312 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74313 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74314 +
74315 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74316 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74317 + pte = pte_exprotect(pte);
74318 +#endif
74319 +
74320 set_pte_at(mm, new_addr, new_pte, pte);
74321 }
74322
74323 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74324 if (is_vm_hugetlb_page(vma))
74325 goto Einval;
74326
74327 +#ifdef CONFIG_PAX_SEGMEXEC
74328 + if (pax_find_mirror_vma(vma))
74329 + goto Einval;
74330 +#endif
74331 +
74332 /* We can't remap across vm area boundaries */
74333 if (old_len > vma->vm_end - addr)
74334 goto Efault;
74335 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74336 unsigned long ret = -EINVAL;
74337 unsigned long charged = 0;
74338 unsigned long map_flags;
74339 + unsigned long pax_task_size = TASK_SIZE;
74340
74341 if (new_addr & ~PAGE_MASK)
74342 goto out;
74343
74344 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74345 +#ifdef CONFIG_PAX_SEGMEXEC
74346 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74347 + pax_task_size = SEGMEXEC_TASK_SIZE;
74348 +#endif
74349 +
74350 + pax_task_size -= PAGE_SIZE;
74351 +
74352 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74353 goto out;
74354
74355 /* Check if the location we're moving into overlaps the
74356 * old location at all, and fail if it does.
74357 */
74358 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74359 - goto out;
74360 -
74361 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74362 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74363 goto out;
74364
74365 ret = do_munmap(mm, new_addr, new_len);
74366 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74367 struct vm_area_struct *vma;
74368 unsigned long ret = -EINVAL;
74369 unsigned long charged = 0;
74370 + unsigned long pax_task_size = TASK_SIZE;
74371
74372 down_write(&current->mm->mmap_sem);
74373
74374 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74375 if (!new_len)
74376 goto out;
74377
74378 +#ifdef CONFIG_PAX_SEGMEXEC
74379 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74380 + pax_task_size = SEGMEXEC_TASK_SIZE;
74381 +#endif
74382 +
74383 + pax_task_size -= PAGE_SIZE;
74384 +
74385 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74386 + old_len > pax_task_size || addr > pax_task_size-old_len)
74387 + goto out;
74388 +
74389 if (flags & MREMAP_FIXED) {
74390 if (flags & MREMAP_MAYMOVE)
74391 ret = mremap_to(addr, old_len, new_addr, new_len);
74392 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74393 addr + new_len);
74394 }
74395 ret = addr;
74396 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74397 goto out;
74398 }
74399 }
74400 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74401 goto out;
74402 }
74403
74404 + map_flags = vma->vm_flags;
74405 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74406 + if (!(ret & ~PAGE_MASK)) {
74407 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74408 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74409 + }
74410 }
74411 out:
74412 if (ret & ~PAGE_MASK)
74413 diff --git a/mm/nommu.c b/mm/nommu.c
74414 index d4b0c10..ed421b5 100644
74415 --- a/mm/nommu.c
74416 +++ b/mm/nommu.c
74417 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74418 int sysctl_overcommit_ratio = 50; /* default is 50% */
74419 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74420 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74421 -int heap_stack_gap = 0;
74422
74423 atomic_long_t mmap_pages_allocated;
74424
74425 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74426 EXPORT_SYMBOL(find_vma);
74427
74428 /*
74429 - * find a VMA
74430 - * - we don't extend stack VMAs under NOMMU conditions
74431 - */
74432 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74433 -{
74434 - return find_vma(mm, addr);
74435 -}
74436 -
74437 -/*
74438 * expand a stack to a given address
74439 * - not supported under NOMMU conditions
74440 */
74441 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74442
74443 /* most fields are the same, copy all, and then fixup */
74444 *new = *vma;
74445 + INIT_LIST_HEAD(&new->anon_vma_chain);
74446 *region = *vma->vm_region;
74447 new->vm_region = region;
74448
74449 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74450 index c13ea75..081ab2c 100644
74451 --- a/mm/page_alloc.c
74452 +++ b/mm/page_alloc.c
74453 @@ -340,7 +340,7 @@ out:
74454 * This usage means that zero-order pages may not be compound.
74455 */
74456
74457 -static void free_compound_page(struct page *page)
74458 +void free_compound_page(struct page *page)
74459 {
74460 __free_pages_ok(page, compound_order(page));
74461 }
74462 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74463 int i;
74464 int bad = 0;
74465
74466 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74467 + unsigned long index = 1UL << order;
74468 +#endif
74469 +
74470 trace_mm_page_free(page, order);
74471 kmemcheck_free_shadow(page, order);
74472
74473 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74474 debug_check_no_obj_freed(page_address(page),
74475 PAGE_SIZE << order);
74476 }
74477 +
74478 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74479 + for (; index; --index)
74480 + sanitize_highpage(page + index - 1);
74481 +#endif
74482 +
74483 arch_free_page(page, order);
74484 kernel_map_pages(page, 1 << order, 0);
74485
74486 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74487 arch_alloc_page(page, order);
74488 kernel_map_pages(page, 1 << order, 1);
74489
74490 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74491 if (gfp_flags & __GFP_ZERO)
74492 prep_zero_page(page, order, gfp_flags);
74493 +#endif
74494
74495 if (order && (gfp_flags & __GFP_COMP))
74496 prep_compound_page(page, order);
74497 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74498 unsigned long pfn;
74499
74500 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74501 +#ifdef CONFIG_X86_32
74502 + /* boot failures in VMware 8 on 32bit vanilla since
74503 + this change */
74504 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74505 +#else
74506 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74507 +#endif
74508 return 1;
74509 }
74510 return 0;
74511 diff --git a/mm/percpu.c b/mm/percpu.c
74512 index bb4be74..a43ea85 100644
74513 --- a/mm/percpu.c
74514 +++ b/mm/percpu.c
74515 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74516 static unsigned int pcpu_high_unit_cpu __read_mostly;
74517
74518 /* the address of the first chunk which starts with the kernel static area */
74519 -void *pcpu_base_addr __read_mostly;
74520 +void *pcpu_base_addr __read_only;
74521 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74522
74523 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74524 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74525 index 926b466..b23df53 100644
74526 --- a/mm/process_vm_access.c
74527 +++ b/mm/process_vm_access.c
74528 @@ -13,6 +13,7 @@
74529 #include <linux/uio.h>
74530 #include <linux/sched.h>
74531 #include <linux/highmem.h>
74532 +#include <linux/security.h>
74533 #include <linux/ptrace.h>
74534 #include <linux/slab.h>
74535 #include <linux/syscalls.h>
74536 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74537 size_t iov_l_curr_offset = 0;
74538 ssize_t iov_len;
74539
74540 + return -ENOSYS; // PaX: until properly audited
74541 +
74542 /*
74543 * Work out how many pages of struct pages we're going to need
74544 * when eventually calling get_user_pages
74545 */
74546 for (i = 0; i < riovcnt; i++) {
74547 iov_len = rvec[i].iov_len;
74548 - if (iov_len > 0) {
74549 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74550 - + iov_len)
74551 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74552 - / PAGE_SIZE + 1;
74553 - nr_pages = max(nr_pages, nr_pages_iov);
74554 - }
74555 + if (iov_len <= 0)
74556 + continue;
74557 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74558 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74559 + nr_pages = max(nr_pages, nr_pages_iov);
74560 }
74561
74562 if (nr_pages == 0)
74563 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74564 goto free_proc_pages;
74565 }
74566
74567 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74568 + rc = -EPERM;
74569 + goto put_task_struct;
74570 + }
74571 +
74572 mm = mm_access(task, PTRACE_MODE_ATTACH);
74573 if (!mm || IS_ERR(mm)) {
74574 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74575 diff --git a/mm/rmap.c b/mm/rmap.c
74576 index aa95e59..b681a63 100644
74577 --- a/mm/rmap.c
74578 +++ b/mm/rmap.c
74579 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74580 struct anon_vma *anon_vma = vma->anon_vma;
74581 struct anon_vma_chain *avc;
74582
74583 +#ifdef CONFIG_PAX_SEGMEXEC
74584 + struct anon_vma_chain *avc_m = NULL;
74585 +#endif
74586 +
74587 might_sleep();
74588 if (unlikely(!anon_vma)) {
74589 struct mm_struct *mm = vma->vm_mm;
74590 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74591 if (!avc)
74592 goto out_enomem;
74593
74594 +#ifdef CONFIG_PAX_SEGMEXEC
74595 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74596 + if (!avc_m)
74597 + goto out_enomem_free_avc;
74598 +#endif
74599 +
74600 anon_vma = find_mergeable_anon_vma(vma);
74601 allocated = NULL;
74602 if (!anon_vma) {
74603 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74604 /* page_table_lock to protect against threads */
74605 spin_lock(&mm->page_table_lock);
74606 if (likely(!vma->anon_vma)) {
74607 +
74608 +#ifdef CONFIG_PAX_SEGMEXEC
74609 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74610 +
74611 + if (vma_m) {
74612 + BUG_ON(vma_m->anon_vma);
74613 + vma_m->anon_vma = anon_vma;
74614 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74615 + avc_m = NULL;
74616 + }
74617 +#endif
74618 +
74619 vma->anon_vma = anon_vma;
74620 anon_vma_chain_link(vma, avc, anon_vma);
74621 allocated = NULL;
74622 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74623
74624 if (unlikely(allocated))
74625 put_anon_vma(allocated);
74626 +
74627 +#ifdef CONFIG_PAX_SEGMEXEC
74628 + if (unlikely(avc_m))
74629 + anon_vma_chain_free(avc_m);
74630 +#endif
74631 +
74632 if (unlikely(avc))
74633 anon_vma_chain_free(avc);
74634 }
74635 return 0;
74636
74637 out_enomem_free_avc:
74638 +
74639 +#ifdef CONFIG_PAX_SEGMEXEC
74640 + if (avc_m)
74641 + anon_vma_chain_free(avc_m);
74642 +#endif
74643 +
74644 anon_vma_chain_free(avc);
74645 out_enomem:
74646 return -ENOMEM;
74647 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74648 * Attach the anon_vmas from src to dst.
74649 * Returns 0 on success, -ENOMEM on failure.
74650 */
74651 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74652 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74653 {
74654 struct anon_vma_chain *avc, *pavc;
74655 struct anon_vma *root = NULL;
74656 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74657 * the corresponding VMA in the parent process is attached to.
74658 * Returns 0 on success, non-zero on failure.
74659 */
74660 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74661 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74662 {
74663 struct anon_vma_chain *avc;
74664 struct anon_vma *anon_vma;
74665 diff --git a/mm/shmem.c b/mm/shmem.c
74666 index d2eeca1..3f160be 100644
74667 --- a/mm/shmem.c
74668 +++ b/mm/shmem.c
74669 @@ -31,7 +31,7 @@
74670 #include <linux/export.h>
74671 #include <linux/swap.h>
74672
74673 -static struct vfsmount *shm_mnt;
74674 +struct vfsmount *shm_mnt;
74675
74676 #ifdef CONFIG_SHMEM
74677 /*
74678 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74679 #define BOGO_DIRENT_SIZE 20
74680
74681 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74682 -#define SHORT_SYMLINK_LEN 128
74683 +#define SHORT_SYMLINK_LEN 64
74684
74685 struct shmem_xattr {
74686 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74687 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74688 int err = -ENOMEM;
74689
74690 /* Round up to L1_CACHE_BYTES to resist false sharing */
74691 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74692 - L1_CACHE_BYTES), GFP_KERNEL);
74693 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74694 if (!sbinfo)
74695 return -ENOMEM;
74696
74697 diff --git a/mm/slab.c b/mm/slab.c
74698 index d066037..5bb78d9 100644
74699 --- a/mm/slab.c
74700 +++ b/mm/slab.c
74701 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74702
74703 /* Legal flag mask for kmem_cache_create(). */
74704 #if DEBUG
74705 -# define CREATE_MASK (SLAB_RED_ZONE | \
74706 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74707 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74708 SLAB_CACHE_DMA | \
74709 SLAB_STORE_USER | \
74710 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74711 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74712 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74713 #else
74714 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74715 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74716 SLAB_CACHE_DMA | \
74717 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74718 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74719 @@ -322,7 +322,7 @@ struct kmem_list3 {
74720 * Need this for bootstrapping a per node allocator.
74721 */
74722 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74723 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74724 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74725 #define CACHE_CACHE 0
74726 #define SIZE_AC MAX_NUMNODES
74727 #define SIZE_L3 (2 * MAX_NUMNODES)
74728 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74729 if ((x)->max_freeable < i) \
74730 (x)->max_freeable = i; \
74731 } while (0)
74732 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74733 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74734 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74735 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74736 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74737 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74738 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74739 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74740 #else
74741 #define STATS_INC_ACTIVE(x) do { } while (0)
74742 #define STATS_DEC_ACTIVE(x) do { } while (0)
74743 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74744 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74745 */
74746 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74747 - const struct slab *slab, void *obj)
74748 + const struct slab *slab, const void *obj)
74749 {
74750 u32 offset = (obj - slab->s_mem);
74751 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74752 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74753 struct cache_names {
74754 char *name;
74755 char *name_dma;
74756 + char *name_usercopy;
74757 };
74758
74759 static struct cache_names __initdata cache_names[] = {
74760 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74761 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74762 #include <linux/kmalloc_sizes.h>
74763 - {NULL,}
74764 + {NULL}
74765 #undef CACHE
74766 };
74767
74768 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74769 if (unlikely(gfpflags & GFP_DMA))
74770 return csizep->cs_dmacachep;
74771 #endif
74772 +
74773 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74774 + if (unlikely(gfpflags & GFP_USERCOPY))
74775 + return csizep->cs_usercopycachep;
74776 +#endif
74777 +
74778 return csizep->cs_cachep;
74779 }
74780
74781 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74782 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74783 sizes[INDEX_AC].cs_size,
74784 ARCH_KMALLOC_MINALIGN,
74785 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74786 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74787 NULL);
74788
74789 if (INDEX_AC != INDEX_L3) {
74790 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74791 __kmem_cache_create(names[INDEX_L3].name,
74792 sizes[INDEX_L3].cs_size,
74793 ARCH_KMALLOC_MINALIGN,
74794 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74795 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74796 NULL);
74797 }
74798
74799 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74800 sizes->cs_cachep = __kmem_cache_create(names->name,
74801 sizes->cs_size,
74802 ARCH_KMALLOC_MINALIGN,
74803 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74804 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74805 NULL);
74806 }
74807 #ifdef CONFIG_ZONE_DMA
74808 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74809 SLAB_PANIC,
74810 NULL);
74811 #endif
74812 +
74813 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74814 + sizes->cs_usercopycachep = kmem_cache_create(
74815 + names->name_usercopy,
74816 + sizes->cs_size,
74817 + ARCH_KMALLOC_MINALIGN,
74818 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74819 + NULL);
74820 +#endif
74821 +
74822 sizes++;
74823 names++;
74824 }
74825 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74826 }
74827 /* cpu stats */
74828 {
74829 - unsigned long allochit = atomic_read(&cachep->allochit);
74830 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74831 - unsigned long freehit = atomic_read(&cachep->freehit);
74832 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74833 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74834 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74835 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74836 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74837
74838 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74839 allochit, allocmiss, freehit, freemiss);
74840 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74841 {
74842 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74843 #ifdef CONFIG_DEBUG_SLAB_LEAK
74844 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74845 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74846 #endif
74847 return 0;
74848 }
74849 module_init(slab_proc_init);
74850 #endif
74851
74852 +bool is_usercopy_object(const void *ptr)
74853 +{
74854 + struct page *page;
74855 + struct kmem_cache *cachep;
74856 +
74857 + if (ZERO_OR_NULL_PTR(ptr))
74858 + return false;
74859 +
74860 + if (!slab_is_available())
74861 + return false;
74862 +
74863 + if (!virt_addr_valid(ptr))
74864 + return false;
74865 +
74866 + page = virt_to_head_page(ptr);
74867 +
74868 + if (!PageSlab(page))
74869 + return false;
74870 +
74871 + cachep = page_get_cache(page);
74872 + return cachep->flags & SLAB_USERCOPY;
74873 +}
74874 +
74875 +#ifdef CONFIG_PAX_USERCOPY
74876 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74877 +{
74878 + struct page *page;
74879 + struct kmem_cache *cachep;
74880 + struct slab *slabp;
74881 + unsigned int objnr;
74882 + unsigned long offset;
74883 +
74884 + if (ZERO_OR_NULL_PTR(ptr))
74885 + return "<null>";
74886 +
74887 + if (!virt_addr_valid(ptr))
74888 + return NULL;
74889 +
74890 + page = virt_to_head_page(ptr);
74891 +
74892 + if (!PageSlab(page))
74893 + return NULL;
74894 +
74895 + cachep = page_get_cache(page);
74896 + if (!(cachep->flags & SLAB_USERCOPY))
74897 + return cachep->name;
74898 +
74899 + slabp = page->slab_page;
74900 + objnr = obj_to_index(cachep, slabp, ptr);
74901 + BUG_ON(objnr >= cachep->num);
74902 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74903 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74904 + return NULL;
74905 +
74906 + return cachep->name;
74907 +}
74908 +#endif
74909 +
74910 /**
74911 * ksize - get the actual amount of memory allocated for a given object
74912 * @objp: Pointer to the object
74913 diff --git a/mm/slob.c b/mm/slob.c
74914 index 45d4ca7..88943c1 100644
74915 --- a/mm/slob.c
74916 +++ b/mm/slob.c
74917 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74918 /*
74919 * Return the size of a slob block.
74920 */
74921 -static slobidx_t slob_units(slob_t *s)
74922 +static slobidx_t slob_units(const slob_t *s)
74923 {
74924 if (s->units > 0)
74925 return s->units;
74926 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74927 /*
74928 * Return the next free slob block pointer after this one.
74929 */
74930 -static slob_t *slob_next(slob_t *s)
74931 +static slob_t *slob_next(const slob_t *s)
74932 {
74933 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74934 slobidx_t next;
74935 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74936 /*
74937 * Returns true if s is the last free block in its page.
74938 */
74939 -static int slob_last(slob_t *s)
74940 +static int slob_last(const slob_t *s)
74941 {
74942 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74943 }
74944
74945 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74946 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74947 {
74948 - void *page;
74949 + struct page *page;
74950
74951 #ifdef CONFIG_NUMA
74952 if (node != -1)
74953 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74954 if (!page)
74955 return NULL;
74956
74957 - return page_address(page);
74958 + __SetPageSlab(page);
74959 + return page;
74960 }
74961
74962 -static void slob_free_pages(void *b, int order)
74963 +static void slob_free_pages(struct page *sp, int order)
74964 {
74965 if (current->reclaim_state)
74966 current->reclaim_state->reclaimed_slab += 1 << order;
74967 - free_pages((unsigned long)b, order);
74968 + __ClearPageSlab(sp);
74969 + reset_page_mapcount(sp);
74970 + sp->private = 0;
74971 + __free_pages(sp, order);
74972 }
74973
74974 /*
74975 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74976
74977 /* Not enough space: must allocate a new page */
74978 if (!b) {
74979 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74980 - if (!b)
74981 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74982 + if (!sp)
74983 return NULL;
74984 - sp = virt_to_page(b);
74985 - __SetPageSlab(sp);
74986 + b = page_address(sp);
74987
74988 spin_lock_irqsave(&slob_lock, flags);
74989 sp->units = SLOB_UNITS(PAGE_SIZE);
74990 sp->freelist = b;
74991 + sp->private = 0;
74992 INIT_LIST_HEAD(&sp->list);
74993 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74994 set_slob_page_free(sp, slob_list);
74995 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74996 if (slob_page_free(sp))
74997 clear_slob_page_free(sp);
74998 spin_unlock_irqrestore(&slob_lock, flags);
74999 - __ClearPageSlab(sp);
75000 - reset_page_mapcount(sp);
75001 - slob_free_pages(b, 0);
75002 + slob_free_pages(sp, 0);
75003 return;
75004 }
75005
75006 @@ -425,11 +427,10 @@ out:
75007 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
75008 */
75009
75010 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75011 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
75012 {
75013 - unsigned int *m;
75014 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75015 - void *ret;
75016 + slob_t *m;
75017 + void *ret = NULL;
75018
75019 gfp &= gfp_allowed_mask;
75020
75021 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75022
75023 if (!m)
75024 return NULL;
75025 - *m = size;
75026 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
75027 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
75028 + m[0].units = size;
75029 + m[1].units = align;
75030 ret = (void *)m + align;
75031
75032 trace_kmalloc_node(_RET_IP_, ret,
75033 size, size + align, gfp, node);
75034 } else {
75035 unsigned int order = get_order(size);
75036 + struct page *page;
75037
75038 if (likely(order))
75039 gfp |= __GFP_COMP;
75040 - ret = slob_new_pages(gfp, order, node);
75041 - if (ret) {
75042 - struct page *page;
75043 - page = virt_to_page(ret);
75044 + page = slob_new_pages(gfp, order, node);
75045 + if (page) {
75046 + ret = page_address(page);
75047 page->private = size;
75048 }
75049
75050 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75051 size, PAGE_SIZE << order, gfp, node);
75052 }
75053
75054 - kmemleak_alloc(ret, size, 1, gfp);
75055 + return ret;
75056 +}
75057 +
75058 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
75059 +{
75060 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75061 + void *ret = __kmalloc_node_align(size, gfp, node, align);
75062 +
75063 + if (!ZERO_OR_NULL_PTR(ret))
75064 + kmemleak_alloc(ret, size, 1, gfp);
75065 return ret;
75066 }
75067 EXPORT_SYMBOL(__kmalloc_node);
75068 @@ -480,15 +493,91 @@ void kfree(const void *block)
75069 kmemleak_free(block);
75070
75071 sp = virt_to_page(block);
75072 - if (PageSlab(sp)) {
75073 + VM_BUG_ON(!PageSlab(sp));
75074 + if (!sp->private) {
75075 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75076 - unsigned int *m = (unsigned int *)(block - align);
75077 - slob_free(m, *m + align);
75078 - } else
75079 + slob_t *m = (slob_t *)(block - align);
75080 + slob_free(m, m[0].units + align);
75081 + } else {
75082 + __ClearPageSlab(sp);
75083 + reset_page_mapcount(sp);
75084 + sp->private = 0;
75085 put_page(sp);
75086 + }
75087 }
75088 EXPORT_SYMBOL(kfree);
75089
75090 +bool is_usercopy_object(const void *ptr)
75091 +{
75092 + if (!slab_is_available())
75093 + return false;
75094 +
75095 + // PAX: TODO
75096 +
75097 + return false;
75098 +}
75099 +
75100 +#ifdef CONFIG_PAX_USERCOPY
75101 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75102 +{
75103 + struct page *page;
75104 + const slob_t *free;
75105 + const void *base;
75106 + unsigned long flags;
75107 +
75108 + if (ZERO_OR_NULL_PTR(ptr))
75109 + return "<null>";
75110 +
75111 + if (!virt_addr_valid(ptr))
75112 + return NULL;
75113 +
75114 + page = virt_to_head_page(ptr);
75115 + if (!PageSlab(page))
75116 + return NULL;
75117 +
75118 + if (page->private) {
75119 + base = page;
75120 + if (base <= ptr && n <= page->private - (ptr - base))
75121 + return NULL;
75122 + return "<slob>";
75123 + }
75124 +
75125 + /* some tricky double walking to find the chunk */
75126 + spin_lock_irqsave(&slob_lock, flags);
75127 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75128 + free = page->freelist;
75129 +
75130 + while (!slob_last(free) && (void *)free <= ptr) {
75131 + base = free + slob_units(free);
75132 + free = slob_next(free);
75133 + }
75134 +
75135 + while (base < (void *)free) {
75136 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75137 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75138 + int offset;
75139 +
75140 + if (ptr < base + align)
75141 + break;
75142 +
75143 + offset = ptr - base - align;
75144 + if (offset >= m) {
75145 + base += size;
75146 + continue;
75147 + }
75148 +
75149 + if (n > m - offset)
75150 + break;
75151 +
75152 + spin_unlock_irqrestore(&slob_lock, flags);
75153 + return NULL;
75154 + }
75155 +
75156 + spin_unlock_irqrestore(&slob_lock, flags);
75157 + return "<slob>";
75158 +}
75159 +#endif
75160 +
75161 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75162 size_t ksize(const void *block)
75163 {
75164 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
75165 return 0;
75166
75167 sp = virt_to_page(block);
75168 - if (PageSlab(sp)) {
75169 + VM_BUG_ON(!PageSlab(sp));
75170 + if (!sp->private) {
75171 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75172 - unsigned int *m = (unsigned int *)(block - align);
75173 - return SLOB_UNITS(*m) * SLOB_UNIT;
75174 + slob_t *m = (slob_t *)(block - align);
75175 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75176 } else
75177 return sp->private;
75178 }
75179 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75180 {
75181 struct kmem_cache *c;
75182
75183 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75184 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75185 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75186 +#else
75187 c = slob_alloc(sizeof(struct kmem_cache),
75188 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75189 +#endif
75190
75191 if (c) {
75192 c->name = name;
75193 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75194
75195 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75196 {
75197 - void *b;
75198 + void *b = NULL;
75199
75200 flags &= gfp_allowed_mask;
75201
75202 lockdep_trace_alloc(flags);
75203
75204 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75205 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75206 +#else
75207 if (c->size < PAGE_SIZE) {
75208 b = slob_alloc(c->size, flags, c->align, node);
75209 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75210 SLOB_UNITS(c->size) * SLOB_UNIT,
75211 flags, node);
75212 } else {
75213 - b = slob_new_pages(flags, get_order(c->size), node);
75214 + struct page *sp;
75215 +
75216 + sp = slob_new_pages(flags, get_order(c->size), node);
75217 + if (sp) {
75218 + b = page_address(sp);
75219 + sp->private = c->size;
75220 + }
75221 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75222 PAGE_SIZE << get_order(c->size),
75223 flags, node);
75224 }
75225 +#endif
75226
75227 if (c->ctor)
75228 c->ctor(b);
75229 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75230
75231 static void __kmem_cache_free(void *b, int size)
75232 {
75233 - if (size < PAGE_SIZE)
75234 + struct page *sp;
75235 +
75236 + sp = virt_to_page(b);
75237 + BUG_ON(!PageSlab(sp));
75238 + if (!sp->private)
75239 slob_free(b, size);
75240 else
75241 - slob_free_pages(b, get_order(size));
75242 + slob_free_pages(sp, get_order(size));
75243 }
75244
75245 static void kmem_rcu_free(struct rcu_head *head)
75246 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75247
75248 void kmem_cache_free(struct kmem_cache *c, void *b)
75249 {
75250 + int size = c->size;
75251 +
75252 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75253 + if (size + c->align < PAGE_SIZE) {
75254 + size += c->align;
75255 + b -= c->align;
75256 + }
75257 +#endif
75258 +
75259 kmemleak_free_recursive(b, c->flags);
75260 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75261 struct slob_rcu *slob_rcu;
75262 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75263 - slob_rcu->size = c->size;
75264 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75265 + slob_rcu->size = size;
75266 call_rcu(&slob_rcu->head, kmem_rcu_free);
75267 } else {
75268 - __kmem_cache_free(b, c->size);
75269 + __kmem_cache_free(b, size);
75270 }
75271
75272 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75273 + trace_kfree(_RET_IP_, b);
75274 +#else
75275 trace_kmem_cache_free(_RET_IP_, b);
75276 +#endif
75277 +
75278 }
75279 EXPORT_SYMBOL(kmem_cache_free);
75280
75281 diff --git a/mm/slub.c b/mm/slub.c
75282 index 2fdd96f..1e2f893 100644
75283 --- a/mm/slub.c
75284 +++ b/mm/slub.c
75285 @@ -201,7 +201,7 @@ struct track {
75286
75287 enum track_item { TRACK_ALLOC, TRACK_FREE };
75288
75289 -#ifdef CONFIG_SYSFS
75290 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75291 static int sysfs_slab_add(struct kmem_cache *);
75292 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75293 static void sysfs_slab_remove(struct kmem_cache *);
75294 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75295 if (!t->addr)
75296 return;
75297
75298 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75299 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75300 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75301 #ifdef CONFIG_STACKTRACE
75302 {
75303 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75304
75305 page = virt_to_head_page(x);
75306
75307 + BUG_ON(!PageSlab(page));
75308 +
75309 slab_free(s, page, x, _RET_IP_);
75310
75311 trace_kmem_cache_free(_RET_IP_, x);
75312 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75313 * Merge control. If this is set then no merging of slab caches will occur.
75314 * (Could be removed. This was introduced to pacify the merge skeptics.)
75315 */
75316 -static int slub_nomerge;
75317 +static int slub_nomerge = 1;
75318
75319 /*
75320 * Calculate the order of allocation given an slab object size.
75321 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75322 else
75323 s->cpu_partial = 30;
75324
75325 - s->refcount = 1;
75326 + atomic_set(&s->refcount, 1);
75327 #ifdef CONFIG_NUMA
75328 s->remote_node_defrag_ratio = 1000;
75329 #endif
75330 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75331 void kmem_cache_destroy(struct kmem_cache *s)
75332 {
75333 mutex_lock(&slab_mutex);
75334 - s->refcount--;
75335 - if (!s->refcount) {
75336 + if (atomic_dec_and_test(&s->refcount)) {
75337 list_del(&s->list);
75338 mutex_unlock(&slab_mutex);
75339 if (kmem_cache_close(s)) {
75340 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75341 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75342 #endif
75343
75344 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75345 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75346 +#endif
75347 +
75348 static int __init setup_slub_min_order(char *str)
75349 {
75350 get_option(&str, &slub_min_order);
75351 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75352 return kmalloc_dma_caches[index];
75353
75354 #endif
75355 +
75356 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75357 + if (flags & SLAB_USERCOPY)
75358 + return kmalloc_usercopy_caches[index];
75359 +
75360 +#endif
75361 +
75362 return kmalloc_caches[index];
75363 }
75364
75365 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75366 EXPORT_SYMBOL(__kmalloc_node);
75367 #endif
75368
75369 +bool is_usercopy_object(const void *ptr)
75370 +{
75371 + struct page *page;
75372 + struct kmem_cache *s;
75373 +
75374 + if (ZERO_OR_NULL_PTR(ptr))
75375 + return false;
75376 +
75377 + if (!slab_is_available())
75378 + return false;
75379 +
75380 + if (!virt_addr_valid(ptr))
75381 + return false;
75382 +
75383 + page = virt_to_head_page(ptr);
75384 +
75385 + if (!PageSlab(page))
75386 + return false;
75387 +
75388 + s = page->slab;
75389 + return s->flags & SLAB_USERCOPY;
75390 +}
75391 +
75392 +#ifdef CONFIG_PAX_USERCOPY
75393 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75394 +{
75395 + struct page *page;
75396 + struct kmem_cache *s;
75397 + unsigned long offset;
75398 +
75399 + if (ZERO_OR_NULL_PTR(ptr))
75400 + return "<null>";
75401 +
75402 + if (!virt_addr_valid(ptr))
75403 + return NULL;
75404 +
75405 + page = virt_to_head_page(ptr);
75406 +
75407 + if (!PageSlab(page))
75408 + return NULL;
75409 +
75410 + s = page->slab;
75411 + if (!(s->flags & SLAB_USERCOPY))
75412 + return s->name;
75413 +
75414 + offset = (ptr - page_address(page)) % s->size;
75415 + if (offset <= s->object_size && n <= s->object_size - offset)
75416 + return NULL;
75417 +
75418 + return s->name;
75419 +}
75420 +#endif
75421 +
75422 size_t ksize(const void *object)
75423 {
75424 struct page *page;
75425 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75426 int node;
75427
75428 list_add(&s->list, &slab_caches);
75429 - s->refcount = -1;
75430 + atomic_set(&s->refcount, -1);
75431
75432 for_each_node_state(node, N_NORMAL_MEMORY) {
75433 struct kmem_cache_node *n = get_node(s, node);
75434 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75435
75436 /* Caches that are not of the two-to-the-power-of size */
75437 if (KMALLOC_MIN_SIZE <= 32) {
75438 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75439 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75440 caches++;
75441 }
75442
75443 if (KMALLOC_MIN_SIZE <= 64) {
75444 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75445 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75446 caches++;
75447 }
75448
75449 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75450 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75451 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75452 caches++;
75453 }
75454
75455 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75456 }
75457 }
75458 #endif
75459 +
75460 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75461 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75462 + struct kmem_cache *s = kmalloc_caches[i];
75463 +
75464 + if (s && s->size) {
75465 + char *name = kasprintf(GFP_NOWAIT,
75466 + "usercopy-kmalloc-%d", s->object_size);
75467 +
75468 + BUG_ON(!name);
75469 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75470 + s->object_size, SLAB_USERCOPY);
75471 + }
75472 + }
75473 +#endif
75474 +
75475 printk(KERN_INFO
75476 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75477 " CPUs=%d, Nodes=%d\n",
75478 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75479 /*
75480 * We may have set a slab to be unmergeable during bootstrap.
75481 */
75482 - if (s->refcount < 0)
75483 + if (atomic_read(&s->refcount) < 0)
75484 return 1;
75485
75486 return 0;
75487 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75488
75489 s = find_mergeable(size, align, flags, name, ctor);
75490 if (s) {
75491 - s->refcount++;
75492 + atomic_inc(&s->refcount);
75493 /*
75494 * Adjust the object sizes so that we clear
75495 * the complete object on kzalloc.
75496 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75497 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75498
75499 if (sysfs_slab_alias(s, name)) {
75500 - s->refcount--;
75501 + atomic_dec(&s->refcount);
75502 return NULL;
75503 }
75504 return s;
75505 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75506 }
75507 #endif
75508
75509 -#ifdef CONFIG_SYSFS
75510 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75511 static int count_inuse(struct page *page)
75512 {
75513 return page->inuse;
75514 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75515 validate_slab_cache(kmalloc_caches[9]);
75516 }
75517 #else
75518 -#ifdef CONFIG_SYSFS
75519 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75520 static void resiliency_test(void) {};
75521 #endif
75522 #endif
75523
75524 -#ifdef CONFIG_SYSFS
75525 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75526 enum slab_stat_type {
75527 SL_ALL, /* All slabs */
75528 SL_PARTIAL, /* Only partially allocated slabs */
75529 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75530
75531 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75532 {
75533 - return sprintf(buf, "%d\n", s->refcount - 1);
75534 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75535 }
75536 SLAB_ATTR_RO(aliases);
75537
75538 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75539 return name;
75540 }
75541
75542 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75543 static int sysfs_slab_add(struct kmem_cache *s)
75544 {
75545 int err;
75546 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75547 kobject_del(&s->kobj);
75548 kobject_put(&s->kobj);
75549 }
75550 +#endif
75551
75552 /*
75553 * Need to buffer aliases during bootup until sysfs becomes
75554 @@ -5354,6 +5437,7 @@ struct saved_alias {
75555
75556 static struct saved_alias *alias_list;
75557
75558 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75559 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75560 {
75561 struct saved_alias *al;
75562 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75563 alias_list = al;
75564 return 0;
75565 }
75566 +#endif
75567
75568 static int __init slab_sysfs_init(void)
75569 {
75570 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75571 index 1b7e22a..3fcd4f3 100644
75572 --- a/mm/sparse-vmemmap.c
75573 +++ b/mm/sparse-vmemmap.c
75574 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75575 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75576 if (!p)
75577 return NULL;
75578 - pud_populate(&init_mm, pud, p);
75579 + pud_populate_kernel(&init_mm, pud, p);
75580 }
75581 return pud;
75582 }
75583 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75584 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75585 if (!p)
75586 return NULL;
75587 - pgd_populate(&init_mm, pgd, p);
75588 + pgd_populate_kernel(&init_mm, pgd, p);
75589 }
75590 return pgd;
75591 }
75592 diff --git a/mm/swap.c b/mm/swap.c
75593 index 7782588..228c784 100644
75594 --- a/mm/swap.c
75595 +++ b/mm/swap.c
75596 @@ -30,6 +30,7 @@
75597 #include <linux/backing-dev.h>
75598 #include <linux/memcontrol.h>
75599 #include <linux/gfp.h>
75600 +#include <linux/hugetlb.h>
75601
75602 #include "internal.h"
75603
75604 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75605
75606 __page_cache_release(page);
75607 dtor = get_compound_page_dtor(page);
75608 + if (!PageHuge(page))
75609 + BUG_ON(dtor != free_compound_page);
75610 (*dtor)(page);
75611 }
75612
75613 diff --git a/mm/swapfile.c b/mm/swapfile.c
75614 index 14e254c..a6af32c 100644
75615 --- a/mm/swapfile.c
75616 +++ b/mm/swapfile.c
75617 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75618
75619 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75620 /* Activity counter to indicate that a swapon or swapoff has occurred */
75621 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75622 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75623
75624 static inline unsigned char swap_count(unsigned char ent)
75625 {
75626 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75627 }
75628 filp_close(swap_file, NULL);
75629 err = 0;
75630 - atomic_inc(&proc_poll_event);
75631 + atomic_inc_unchecked(&proc_poll_event);
75632 wake_up_interruptible(&proc_poll_wait);
75633
75634 out_dput:
75635 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75636
75637 poll_wait(file, &proc_poll_wait, wait);
75638
75639 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75640 - seq->poll_event = atomic_read(&proc_poll_event);
75641 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75642 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75643 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75644 }
75645
75646 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75647 return ret;
75648
75649 seq = file->private_data;
75650 - seq->poll_event = atomic_read(&proc_poll_event);
75651 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75652 return 0;
75653 }
75654
75655 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75656 (frontswap_map) ? "FS" : "");
75657
75658 mutex_unlock(&swapon_mutex);
75659 - atomic_inc(&proc_poll_event);
75660 + atomic_inc_unchecked(&proc_poll_event);
75661 wake_up_interruptible(&proc_poll_wait);
75662
75663 if (S_ISREG(inode->i_mode))
75664 diff --git a/mm/util.c b/mm/util.c
75665 index 8c7265a..c96d884 100644
75666 --- a/mm/util.c
75667 +++ b/mm/util.c
75668 @@ -285,6 +285,12 @@ done:
75669 void arch_pick_mmap_layout(struct mm_struct *mm)
75670 {
75671 mm->mmap_base = TASK_UNMAPPED_BASE;
75672 +
75673 +#ifdef CONFIG_PAX_RANDMMAP
75674 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75675 + mm->mmap_base += mm->delta_mmap;
75676 +#endif
75677 +
75678 mm->get_unmapped_area = arch_get_unmapped_area;
75679 mm->unmap_area = arch_unmap_area;
75680 }
75681 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75682 index 2bb90b1..ed47e53 100644
75683 --- a/mm/vmalloc.c
75684 +++ b/mm/vmalloc.c
75685 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75686
75687 pte = pte_offset_kernel(pmd, addr);
75688 do {
75689 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75690 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75691 +
75692 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75693 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75694 + BUG_ON(!pte_exec(*pte));
75695 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75696 + continue;
75697 + }
75698 +#endif
75699 +
75700 + {
75701 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75702 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75703 + }
75704 } while (pte++, addr += PAGE_SIZE, addr != end);
75705 }
75706
75707 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75708 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75709 {
75710 pte_t *pte;
75711 + int ret = -ENOMEM;
75712
75713 /*
75714 * nr is a running index into the array which helps higher level
75715 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75716 pte = pte_alloc_kernel(pmd, addr);
75717 if (!pte)
75718 return -ENOMEM;
75719 +
75720 + pax_open_kernel();
75721 do {
75722 struct page *page = pages[*nr];
75723
75724 - if (WARN_ON(!pte_none(*pte)))
75725 - return -EBUSY;
75726 - if (WARN_ON(!page))
75727 - return -ENOMEM;
75728 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75729 + if (pgprot_val(prot) & _PAGE_NX)
75730 +#endif
75731 +
75732 + if (WARN_ON(!pte_none(*pte))) {
75733 + ret = -EBUSY;
75734 + goto out;
75735 + }
75736 + if (WARN_ON(!page)) {
75737 + ret = -ENOMEM;
75738 + goto out;
75739 + }
75740 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75741 (*nr)++;
75742 } while (pte++, addr += PAGE_SIZE, addr != end);
75743 - return 0;
75744 + ret = 0;
75745 +out:
75746 + pax_close_kernel();
75747 + return ret;
75748 }
75749
75750 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75751 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75752 pmd_t *pmd;
75753 unsigned long next;
75754
75755 - pmd = pmd_alloc(&init_mm, pud, addr);
75756 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75757 if (!pmd)
75758 return -ENOMEM;
75759 do {
75760 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75761 pud_t *pud;
75762 unsigned long next;
75763
75764 - pud = pud_alloc(&init_mm, pgd, addr);
75765 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75766 if (!pud)
75767 return -ENOMEM;
75768 do {
75769 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75770 * and fall back on vmalloc() if that fails. Others
75771 * just put it in the vmalloc space.
75772 */
75773 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75774 +#ifdef CONFIG_MODULES
75775 +#ifdef MODULES_VADDR
75776 unsigned long addr = (unsigned long)x;
75777 if (addr >= MODULES_VADDR && addr < MODULES_END)
75778 return 1;
75779 #endif
75780 +
75781 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75782 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75783 + return 1;
75784 +#endif
75785 +
75786 +#endif
75787 +
75788 return is_vmalloc_addr(x);
75789 }
75790
75791 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75792
75793 if (!pgd_none(*pgd)) {
75794 pud_t *pud = pud_offset(pgd, addr);
75795 +#ifdef CONFIG_X86
75796 + if (!pud_large(*pud))
75797 +#endif
75798 if (!pud_none(*pud)) {
75799 pmd_t *pmd = pmd_offset(pud, addr);
75800 +#ifdef CONFIG_X86
75801 + if (!pmd_large(*pmd))
75802 +#endif
75803 if (!pmd_none(*pmd)) {
75804 pte_t *ptep, pte;
75805
75806 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75807 * Allocate a region of KVA of the specified size and alignment, within the
75808 * vstart and vend.
75809 */
75810 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75811 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75812 unsigned long align,
75813 unsigned long vstart, unsigned long vend,
75814 int node, gfp_t gfp_mask)
75815 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75816 struct vm_struct *area;
75817
75818 BUG_ON(in_interrupt());
75819 +
75820 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75821 + if (flags & VM_KERNEXEC) {
75822 + if (start != VMALLOC_START || end != VMALLOC_END)
75823 + return NULL;
75824 + start = (unsigned long)MODULES_EXEC_VADDR;
75825 + end = (unsigned long)MODULES_EXEC_END;
75826 + }
75827 +#endif
75828 +
75829 if (flags & VM_IOREMAP) {
75830 int bit = fls(size);
75831
75832 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75833 if (count > totalram_pages)
75834 return NULL;
75835
75836 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75837 + if (!(pgprot_val(prot) & _PAGE_NX))
75838 + flags |= VM_KERNEXEC;
75839 +#endif
75840 +
75841 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75842 __builtin_return_address(0));
75843 if (!area)
75844 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75845 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75846 goto fail;
75847
75848 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75849 + if (!(pgprot_val(prot) & _PAGE_NX))
75850 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75851 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75852 + else
75853 +#endif
75854 +
75855 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75856 start, end, node, gfp_mask, caller);
75857 if (!area)
75858 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75859 * For tight control over page level allocator and protection flags
75860 * use __vmalloc() instead.
75861 */
75862 -
75863 void *vmalloc_exec(unsigned long size)
75864 {
75865 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75866 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75867 -1, __builtin_return_address(0));
75868 }
75869
75870 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75871 unsigned long uaddr = vma->vm_start;
75872 unsigned long usize = vma->vm_end - vma->vm_start;
75873
75874 + BUG_ON(vma->vm_mirror);
75875 +
75876 if ((PAGE_SIZE-1) & (unsigned long)addr)
75877 return -EINVAL;
75878
75879 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75880 {
75881 struct vm_struct *v = p;
75882
75883 - seq_printf(m, "0x%p-0x%p %7ld",
75884 + seq_printf(m, "0x%pK-0x%pK %7ld",
75885 v->addr, v->addr + v->size, v->size);
75886
75887 if (v->caller)
75888 diff --git a/mm/vmstat.c b/mm/vmstat.c
75889 index df7a674..8b4a4f3 100644
75890 --- a/mm/vmstat.c
75891 +++ b/mm/vmstat.c
75892 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75893 *
75894 * vm_stat contains the global counters
75895 */
75896 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75897 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75898 EXPORT_SYMBOL(vm_stat);
75899
75900 #ifdef CONFIG_SMP
75901 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75902 v = p->vm_stat_diff[i];
75903 p->vm_stat_diff[i] = 0;
75904 local_irq_restore(flags);
75905 - atomic_long_add(v, &zone->vm_stat[i]);
75906 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75907 global_diff[i] += v;
75908 #ifdef CONFIG_NUMA
75909 /* 3 seconds idle till flush */
75910 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75911
75912 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75913 if (global_diff[i])
75914 - atomic_long_add(global_diff[i], &vm_stat[i]);
75915 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75916 }
75917
75918 #endif
75919 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75920 start_cpu_timer(cpu);
75921 #endif
75922 #ifdef CONFIG_PROC_FS
75923 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75924 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75925 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75926 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75927 + {
75928 + mode_t gr_mode = S_IRUGO;
75929 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75930 + gr_mode = S_IRUSR;
75931 +#endif
75932 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75933 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75934 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75935 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75936 +#else
75937 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75938 +#endif
75939 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75940 + }
75941 #endif
75942 return 0;
75943 }
75944 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75945 index 9096bcb..43ed7bb 100644
75946 --- a/net/8021q/vlan.c
75947 +++ b/net/8021q/vlan.c
75948 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75949 err = -EPERM;
75950 if (!capable(CAP_NET_ADMIN))
75951 break;
75952 - if ((args.u.name_type >= 0) &&
75953 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75954 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75955 struct vlan_net *vn;
75956
75957 vn = net_generic(net, vlan_net_id);
75958 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75959 index 6449bae..8c1f454 100644
75960 --- a/net/9p/trans_fd.c
75961 +++ b/net/9p/trans_fd.c
75962 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75963 oldfs = get_fs();
75964 set_fs(get_ds());
75965 /* The cast to a user pointer is valid due to the set_fs() */
75966 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75967 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75968 set_fs(oldfs);
75969
75970 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75971 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75972 index 876fbe8..8bbea9f 100644
75973 --- a/net/atm/atm_misc.c
75974 +++ b/net/atm/atm_misc.c
75975 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75976 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75977 return 1;
75978 atm_return(vcc, truesize);
75979 - atomic_inc(&vcc->stats->rx_drop);
75980 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75981 return 0;
75982 }
75983 EXPORT_SYMBOL(atm_charge);
75984 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75985 }
75986 }
75987 atm_return(vcc, guess);
75988 - atomic_inc(&vcc->stats->rx_drop);
75989 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75990 return NULL;
75991 }
75992 EXPORT_SYMBOL(atm_alloc_charge);
75993 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75994
75995 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75996 {
75997 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75998 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75999 __SONET_ITEMS
76000 #undef __HANDLE_ITEM
76001 }
76002 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
76003
76004 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
76005 {
76006 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76007 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
76008 __SONET_ITEMS
76009 #undef __HANDLE_ITEM
76010 }
76011 diff --git a/net/atm/lec.h b/net/atm/lec.h
76012 index a86aff9..3a0d6f6 100644
76013 --- a/net/atm/lec.h
76014 +++ b/net/atm/lec.h
76015 @@ -48,7 +48,7 @@ struct lane2_ops {
76016 const u8 *tlvs, u32 sizeoftlvs);
76017 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
76018 const u8 *tlvs, u32 sizeoftlvs);
76019 -};
76020 +} __no_const;
76021
76022 /*
76023 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
76024 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
76025 index 0919a88..a23d54e 100644
76026 --- a/net/atm/mpc.h
76027 +++ b/net/atm/mpc.h
76028 @@ -33,7 +33,7 @@ struct mpoa_client {
76029 struct mpc_parameters parameters; /* parameters for this client */
76030
76031 const struct net_device_ops *old_ops;
76032 - struct net_device_ops new_ops;
76033 + net_device_ops_no_const new_ops;
76034 };
76035
76036
76037 diff --git a/net/atm/proc.c b/net/atm/proc.c
76038 index 0d020de..011c7bb 100644
76039 --- a/net/atm/proc.c
76040 +++ b/net/atm/proc.c
76041 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
76042 const struct k_atm_aal_stats *stats)
76043 {
76044 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
76045 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
76046 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
76047 - atomic_read(&stats->rx_drop));
76048 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
76049 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
76050 + atomic_read_unchecked(&stats->rx_drop));
76051 }
76052
76053 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
76054 diff --git a/net/atm/resources.c b/net/atm/resources.c
76055 index 23f45ce..c748f1a 100644
76056 --- a/net/atm/resources.c
76057 +++ b/net/atm/resources.c
76058 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
76059 static void copy_aal_stats(struct k_atm_aal_stats *from,
76060 struct atm_aal_stats *to)
76061 {
76062 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
76063 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
76064 __AAL_STAT_ITEMS
76065 #undef __HANDLE_ITEM
76066 }
76067 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
76068 static void subtract_aal_stats(struct k_atm_aal_stats *from,
76069 struct atm_aal_stats *to)
76070 {
76071 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
76072 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
76073 __AAL_STAT_ITEMS
76074 #undef __HANDLE_ITEM
76075 }
76076 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
76077 index 469daab..9fc7f8d 100644
76078 --- a/net/batman-adv/bat_iv_ogm.c
76079 +++ b/net/batman-adv/bat_iv_ogm.c
76080 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
76081
76082 /* randomize initial seqno to avoid collision */
76083 get_random_bytes(&random_seqno, sizeof(random_seqno));
76084 - atomic_set(&hard_iface->seqno, random_seqno);
76085 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76086
76087 hard_iface->packet_len = BATADV_OGM_HLEN;
76088 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76089 @@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
76090 "Sending own" :
76091 "Forwarding"));
76092 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
76093 - "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
76094 + "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
76095 fwd_str, (packet_num > 0 ? "aggregated " : ""),
76096 batadv_ogm_packet->orig,
76097 ntohl(batadv_ogm_packet->seqno),
76098 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
76099
76100 /* change sequence number to network order */
76101 batadv_ogm_packet->seqno =
76102 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76103 - atomic_inc(&hard_iface->seqno);
76104 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76105 + atomic_inc_unchecked(&hard_iface->seqno);
76106
76107 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76108 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
76109 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
76110 return;
76111
76112 /* could be changed by schedule_own_packet() */
76113 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76114 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76115
76116 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
76117 has_directlink_flag = 1;
76118 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76119 index 282bf6e..4b2603d 100644
76120 --- a/net/batman-adv/hard-interface.c
76121 +++ b/net/batman-adv/hard-interface.c
76122 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
76123 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76124 dev_add_pack(&hard_iface->batman_adv_ptype);
76125
76126 - atomic_set(&hard_iface->frag_seqno, 1);
76127 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76128 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
76129 hard_iface->net_dev->name);
76130
76131 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
76132 /* This can't be called via a bat_priv callback because
76133 * we have no bat_priv yet.
76134 */
76135 - atomic_set(&hard_iface->seqno, 1);
76136 + atomic_set_unchecked(&hard_iface->seqno, 1);
76137 hard_iface->packet_buff = NULL;
76138
76139 return hard_iface;
76140 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76141 index 21c5357..768be1a 100644
76142 --- a/net/batman-adv/soft-interface.c
76143 +++ b/net/batman-adv/soft-interface.c
76144 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
76145
76146 /* set broadcast sequence number */
76147 bcast_packet->seqno =
76148 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76149 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76150
76151 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
76152
76153 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
76154 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
76155
76156 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
76157 - atomic_set(&bat_priv->bcast_seqno, 1);
76158 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76159 atomic_set(&bat_priv->ttvn, 0);
76160 atomic_set(&bat_priv->tt_local_changes, 0);
76161 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76162 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76163 index 12635fd..d99d837 100644
76164 --- a/net/batman-adv/types.h
76165 +++ b/net/batman-adv/types.h
76166 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
76167 int16_t if_num;
76168 char if_status;
76169 struct net_device *net_dev;
76170 - atomic_t seqno;
76171 - atomic_t frag_seqno;
76172 + atomic_unchecked_t seqno;
76173 + atomic_unchecked_t frag_seqno;
76174 unsigned char *packet_buff;
76175 int packet_len;
76176 struct kobject *hardif_obj;
76177 @@ -176,7 +176,7 @@ struct batadv_priv {
76178 atomic_t orig_interval; /* uint */
76179 atomic_t hop_penalty; /* uint */
76180 atomic_t log_level; /* uint */
76181 - atomic_t bcast_seqno;
76182 + atomic_unchecked_t bcast_seqno;
76183 atomic_t bcast_queue_left;
76184 atomic_t batman_queue_left;
76185 atomic_t ttvn; /* translation table version number */
76186 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76187 index 0016464..0ef3e53 100644
76188 --- a/net/batman-adv/unicast.c
76189 +++ b/net/batman-adv/unicast.c
76190 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
76191 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
76192 frag2->flags = large_tail;
76193
76194 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76195 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76196 frag1->seqno = htons(seqno - 1);
76197 frag2->seqno = htons(seqno);
76198
76199 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76200 index d5ace1e..231c4bf 100644
76201 --- a/net/bluetooth/hci_sock.c
76202 +++ b/net/bluetooth/hci_sock.c
76203 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76204 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76205 }
76206
76207 - len = min_t(unsigned int, len, sizeof(uf));
76208 + len = min((size_t)len, sizeof(uf));
76209 if (copy_from_user(&uf, optval, len)) {
76210 err = -EFAULT;
76211 break;
76212 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76213 index 38c00f1..e9d566e 100644
76214 --- a/net/bluetooth/l2cap_core.c
76215 +++ b/net/bluetooth/l2cap_core.c
76216 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76217 break;
76218
76219 case L2CAP_CONF_RFC:
76220 - if (olen == sizeof(rfc))
76221 - memcpy(&rfc, (void *)val, olen);
76222 + if (olen != sizeof(rfc))
76223 + break;
76224 +
76225 + memcpy(&rfc, (void *)val, olen);
76226
76227 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76228 rfc.mode != chan->mode)
76229 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76230 index 34bbe1c..451c19b 100644
76231 --- a/net/bluetooth/l2cap_sock.c
76232 +++ b/net/bluetooth/l2cap_sock.c
76233 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76234 struct sock *sk = sock->sk;
76235 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76236 struct l2cap_options opts;
76237 - int len, err = 0;
76238 + int err = 0;
76239 + size_t len = optlen;
76240 u32 opt;
76241
76242 BT_DBG("sk %p", sk);
76243 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76244 opts.max_tx = chan->max_tx;
76245 opts.txwin_size = chan->tx_win;
76246
76247 - len = min_t(unsigned int, sizeof(opts), optlen);
76248 + len = min(sizeof(opts), len);
76249 if (copy_from_user((char *) &opts, optval, len)) {
76250 err = -EFAULT;
76251 break;
76252 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76253 struct bt_security sec;
76254 struct bt_power pwr;
76255 struct l2cap_conn *conn;
76256 - int len, err = 0;
76257 + int err = 0;
76258 + size_t len = optlen;
76259 u32 opt;
76260
76261 BT_DBG("sk %p", sk);
76262 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76263
76264 sec.level = BT_SECURITY_LOW;
76265
76266 - len = min_t(unsigned int, sizeof(sec), optlen);
76267 + len = min(sizeof(sec), len);
76268 if (copy_from_user((char *) &sec, optval, len)) {
76269 err = -EFAULT;
76270 break;
76271 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76272
76273 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76274
76275 - len = min_t(unsigned int, sizeof(pwr), optlen);
76276 + len = min(sizeof(pwr), len);
76277 if (copy_from_user((char *) &pwr, optval, len)) {
76278 err = -EFAULT;
76279 break;
76280 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76281 index 1a17850..65a3129 100644
76282 --- a/net/bluetooth/rfcomm/sock.c
76283 +++ b/net/bluetooth/rfcomm/sock.c
76284 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76285 struct sock *sk = sock->sk;
76286 struct bt_security sec;
76287 int err = 0;
76288 - size_t len;
76289 + size_t len = optlen;
76290 u32 opt;
76291
76292 BT_DBG("sk %p", sk);
76293 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76294
76295 sec.level = BT_SECURITY_LOW;
76296
76297 - len = min_t(unsigned int, sizeof(sec), optlen);
76298 + len = min(sizeof(sec), len);
76299 if (copy_from_user((char *) &sec, optval, len)) {
76300 err = -EFAULT;
76301 break;
76302 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76303 index 56f1823..da44330 100644
76304 --- a/net/bluetooth/rfcomm/tty.c
76305 +++ b/net/bluetooth/rfcomm/tty.c
76306 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76307 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76308
76309 spin_lock_irqsave(&dev->port.lock, flags);
76310 - if (dev->port.count > 0) {
76311 + if (atomic_read(&dev->port.count) > 0) {
76312 spin_unlock_irqrestore(&dev->port.lock, flags);
76313 return;
76314 }
76315 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76316 return -ENODEV;
76317
76318 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76319 - dev->channel, dev->port.count);
76320 + dev->channel, atomic_read(&dev->port.count));
76321
76322 spin_lock_irqsave(&dev->port.lock, flags);
76323 - if (++dev->port.count > 1) {
76324 + if (atomic_inc_return(&dev->port.count) > 1) {
76325 spin_unlock_irqrestore(&dev->port.lock, flags);
76326 return 0;
76327 }
76328 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76329 return;
76330
76331 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76332 - dev->port.count);
76333 + atomic_read(&dev->port.count));
76334
76335 spin_lock_irqsave(&dev->port.lock, flags);
76336 - if (!--dev->port.count) {
76337 + if (!atomic_dec_return(&dev->port.count)) {
76338 spin_unlock_irqrestore(&dev->port.lock, flags);
76339 if (dev->tty_dev->parent)
76340 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76341 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76342 index 5fe2ff3..121d696 100644
76343 --- a/net/bridge/netfilter/ebtables.c
76344 +++ b/net/bridge/netfilter/ebtables.c
76345 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76346 tmp.valid_hooks = t->table->valid_hooks;
76347 }
76348 mutex_unlock(&ebt_mutex);
76349 - if (copy_to_user(user, &tmp, *len) != 0){
76350 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76351 BUGPRINT("c2u Didn't work\n");
76352 ret = -EFAULT;
76353 break;
76354 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76355 goto out;
76356 tmp.valid_hooks = t->valid_hooks;
76357
76358 - if (copy_to_user(user, &tmp, *len) != 0) {
76359 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76360 ret = -EFAULT;
76361 break;
76362 }
76363 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76364 tmp.entries_size = t->table->entries_size;
76365 tmp.valid_hooks = t->table->valid_hooks;
76366
76367 - if (copy_to_user(user, &tmp, *len) != 0) {
76368 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76369 ret = -EFAULT;
76370 break;
76371 }
76372 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76373 index 44f270f..1f5602d 100644
76374 --- a/net/caif/cfctrl.c
76375 +++ b/net/caif/cfctrl.c
76376 @@ -10,6 +10,7 @@
76377 #include <linux/spinlock.h>
76378 #include <linux/slab.h>
76379 #include <linux/pkt_sched.h>
76380 +#include <linux/sched.h>
76381 #include <net/caif/caif_layer.h>
76382 #include <net/caif/cfpkt.h>
76383 #include <net/caif/cfctrl.h>
76384 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76385 memset(&dev_info, 0, sizeof(dev_info));
76386 dev_info.id = 0xff;
76387 cfsrvl_init(&this->serv, 0, &dev_info, false);
76388 - atomic_set(&this->req_seq_no, 1);
76389 - atomic_set(&this->rsp_seq_no, 1);
76390 + atomic_set_unchecked(&this->req_seq_no, 1);
76391 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76392 this->serv.layer.receive = cfctrl_recv;
76393 sprintf(this->serv.layer.name, "ctrl");
76394 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76395 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76396 struct cfctrl_request_info *req)
76397 {
76398 spin_lock_bh(&ctrl->info_list_lock);
76399 - atomic_inc(&ctrl->req_seq_no);
76400 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76401 + atomic_inc_unchecked(&ctrl->req_seq_no);
76402 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76403 list_add_tail(&req->list, &ctrl->list);
76404 spin_unlock_bh(&ctrl->info_list_lock);
76405 }
76406 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76407 if (p != first)
76408 pr_warn("Requests are not received in order\n");
76409
76410 - atomic_set(&ctrl->rsp_seq_no,
76411 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76412 p->sequence_no);
76413 list_del(&p->list);
76414 goto out;
76415 diff --git a/net/can/gw.c b/net/can/gw.c
76416 index b54d5e6..91c3b25 100644
76417 --- a/net/can/gw.c
76418 +++ b/net/can/gw.c
76419 @@ -96,7 +96,7 @@ struct cf_mod {
76420 struct {
76421 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76422 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76423 - } csumfunc;
76424 + } __no_const csumfunc;
76425 };
76426
76427
76428 diff --git a/net/compat.c b/net/compat.c
76429 index 74ed1d7..3695bd9 100644
76430 --- a/net/compat.c
76431 +++ b/net/compat.c
76432 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76433 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76434 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76435 return -EFAULT;
76436 - kmsg->msg_name = compat_ptr(tmp1);
76437 - kmsg->msg_iov = compat_ptr(tmp2);
76438 - kmsg->msg_control = compat_ptr(tmp3);
76439 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76440 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76441 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76442 return 0;
76443 }
76444
76445 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76446
76447 if (kern_msg->msg_namelen) {
76448 if (mode == VERIFY_READ) {
76449 - int err = move_addr_to_kernel(kern_msg->msg_name,
76450 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76451 kern_msg->msg_namelen,
76452 kern_address);
76453 if (err < 0)
76454 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76455 kern_msg->msg_name = NULL;
76456
76457 tot_len = iov_from_user_compat_to_kern(kern_iov,
76458 - (struct compat_iovec __user *)kern_msg->msg_iov,
76459 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76460 kern_msg->msg_iovlen);
76461 if (tot_len >= 0)
76462 kern_msg->msg_iov = kern_iov;
76463 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76464
76465 #define CMSG_COMPAT_FIRSTHDR(msg) \
76466 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76467 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76468 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76469 (struct compat_cmsghdr __user *)NULL)
76470
76471 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76472 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76473 (ucmlen) <= (unsigned long) \
76474 ((mhdr)->msg_controllen - \
76475 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76476 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76477
76478 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76479 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76480 {
76481 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76482 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76483 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76484 msg->msg_controllen)
76485 return NULL;
76486 return (struct compat_cmsghdr __user *)ptr;
76487 @@ -219,7 +219,7 @@ Efault:
76488
76489 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76490 {
76491 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76492 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76493 struct compat_cmsghdr cmhdr;
76494 struct compat_timeval ctv;
76495 struct compat_timespec cts[3];
76496 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76497
76498 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76499 {
76500 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76501 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76502 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76503 int fdnum = scm->fp->count;
76504 struct file **fp = scm->fp->fp;
76505 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76506 return -EFAULT;
76507 old_fs = get_fs();
76508 set_fs(KERNEL_DS);
76509 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76510 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76511 set_fs(old_fs);
76512
76513 return err;
76514 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76515 len = sizeof(ktime);
76516 old_fs = get_fs();
76517 set_fs(KERNEL_DS);
76518 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76519 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76520 set_fs(old_fs);
76521
76522 if (!err) {
76523 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76524 case MCAST_JOIN_GROUP:
76525 case MCAST_LEAVE_GROUP:
76526 {
76527 - struct compat_group_req __user *gr32 = (void *)optval;
76528 + struct compat_group_req __user *gr32 = (void __user *)optval;
76529 struct group_req __user *kgr =
76530 compat_alloc_user_space(sizeof(struct group_req));
76531 u32 interface;
76532 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76533 case MCAST_BLOCK_SOURCE:
76534 case MCAST_UNBLOCK_SOURCE:
76535 {
76536 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76537 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76538 struct group_source_req __user *kgsr = compat_alloc_user_space(
76539 sizeof(struct group_source_req));
76540 u32 interface;
76541 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76542 }
76543 case MCAST_MSFILTER:
76544 {
76545 - struct compat_group_filter __user *gf32 = (void *)optval;
76546 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76547 struct group_filter __user *kgf;
76548 u32 interface, fmode, numsrc;
76549
76550 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76551 char __user *optval, int __user *optlen,
76552 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76553 {
76554 - struct compat_group_filter __user *gf32 = (void *)optval;
76555 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76556 struct group_filter __user *kgf;
76557 int __user *koptlen;
76558 u32 interface, fmode, numsrc;
76559 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76560
76561 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76562 return -EINVAL;
76563 - if (copy_from_user(a, args, nas[call]))
76564 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76565 return -EFAULT;
76566 a0 = a[0];
76567 a1 = a[1];
76568 diff --git a/net/core/datagram.c b/net/core/datagram.c
76569 index 0337e2b..47914a0 100644
76570 --- a/net/core/datagram.c
76571 +++ b/net/core/datagram.c
76572 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76573 }
76574
76575 kfree_skb(skb);
76576 - atomic_inc(&sk->sk_drops);
76577 + atomic_inc_unchecked(&sk->sk_drops);
76578 sk_mem_reclaim_partial(sk);
76579
76580 return err;
76581 diff --git a/net/core/dev.c b/net/core/dev.c
76582 index 2fb9f59..d9a07df 100644
76583 --- a/net/core/dev.c
76584 +++ b/net/core/dev.c
76585 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76586 if (no_module && capable(CAP_NET_ADMIN))
76587 no_module = request_module("netdev-%s", name);
76588 if (no_module && capable(CAP_SYS_MODULE)) {
76589 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76590 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76591 +#else
76592 if (!request_module("%s", name))
76593 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76594 name);
76595 +#endif
76596 }
76597 }
76598 EXPORT_SYMBOL(dev_load);
76599 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76600 {
76601 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76602 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76603 - atomic_long_inc(&dev->rx_dropped);
76604 + atomic_long_inc_unchecked(&dev->rx_dropped);
76605 kfree_skb(skb);
76606 return NET_RX_DROP;
76607 }
76608 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76609 nf_reset(skb);
76610
76611 if (unlikely(!is_skb_forwardable(dev, skb))) {
76612 - atomic_long_inc(&dev->rx_dropped);
76613 + atomic_long_inc_unchecked(&dev->rx_dropped);
76614 kfree_skb(skb);
76615 return NET_RX_DROP;
76616 }
76617 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76618
76619 struct dev_gso_cb {
76620 void (*destructor)(struct sk_buff *skb);
76621 -};
76622 +} __no_const;
76623
76624 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76625
76626 @@ -2928,7 +2932,7 @@ enqueue:
76627
76628 local_irq_restore(flags);
76629
76630 - atomic_long_inc(&skb->dev->rx_dropped);
76631 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76632 kfree_skb(skb);
76633 return NET_RX_DROP;
76634 }
76635 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76636 }
76637 EXPORT_SYMBOL(netif_rx_ni);
76638
76639 -static void net_tx_action(struct softirq_action *h)
76640 +static void net_tx_action(void)
76641 {
76642 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76643
76644 @@ -3331,7 +3335,7 @@ ncls:
76645 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76646 } else {
76647 drop:
76648 - atomic_long_inc(&skb->dev->rx_dropped);
76649 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76650 kfree_skb(skb);
76651 /* Jamal, now you will not able to escape explaining
76652 * me how you were going to use this. :-)
76653 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76654 }
76655 EXPORT_SYMBOL(netif_napi_del);
76656
76657 -static void net_rx_action(struct softirq_action *h)
76658 +static void net_rx_action(void)
76659 {
76660 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76661 unsigned long time_limit = jiffies + 2;
76662 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76663 else
76664 seq_printf(seq, "%04x", ntohs(pt->type));
76665
76666 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76667 + seq_printf(seq, " %-8s %p\n",
76668 + pt->dev ? pt->dev->name : "", NULL);
76669 +#else
76670 seq_printf(seq, " %-8s %pF\n",
76671 pt->dev ? pt->dev->name : "", pt->func);
76672 +#endif
76673 }
76674
76675 return 0;
76676 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76677 } else {
76678 netdev_stats_to_stats64(storage, &dev->stats);
76679 }
76680 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76681 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76682 return storage;
76683 }
76684 EXPORT_SYMBOL(dev_get_stats);
76685 diff --git a/net/core/flow.c b/net/core/flow.c
76686 index e318c7e..168b1d0 100644
76687 --- a/net/core/flow.c
76688 +++ b/net/core/flow.c
76689 @@ -61,7 +61,7 @@ struct flow_cache {
76690 struct timer_list rnd_timer;
76691 };
76692
76693 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76694 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76695 EXPORT_SYMBOL(flow_cache_genid);
76696 static struct flow_cache flow_cache_global;
76697 static struct kmem_cache *flow_cachep __read_mostly;
76698 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76699
76700 static int flow_entry_valid(struct flow_cache_entry *fle)
76701 {
76702 - if (atomic_read(&flow_cache_genid) != fle->genid)
76703 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76704 return 0;
76705 if (fle->object && !fle->object->ops->check(fle->object))
76706 return 0;
76707 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76708 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76709 fcp->hash_count++;
76710 }
76711 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76712 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76713 flo = fle->object;
76714 if (!flo)
76715 goto ret_object;
76716 @@ -280,7 +280,7 @@ nocache:
76717 }
76718 flo = resolver(net, key, family, dir, flo, ctx);
76719 if (fle) {
76720 - fle->genid = atomic_read(&flow_cache_genid);
76721 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76722 if (!IS_ERR(flo))
76723 fle->object = flo;
76724 else
76725 diff --git a/net/core/iovec.c b/net/core/iovec.c
76726 index 7e7aeb0..2a998cb 100644
76727 --- a/net/core/iovec.c
76728 +++ b/net/core/iovec.c
76729 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76730 if (m->msg_namelen) {
76731 if (mode == VERIFY_READ) {
76732 void __user *namep;
76733 - namep = (void __user __force *) m->msg_name;
76734 + namep = (void __force_user *) m->msg_name;
76735 err = move_addr_to_kernel(namep, m->msg_namelen,
76736 address);
76737 if (err < 0)
76738 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76739 }
76740
76741 size = m->msg_iovlen * sizeof(struct iovec);
76742 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76743 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76744 return -EFAULT;
76745
76746 m->msg_iov = iov;
76747 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76748 index 2c5a0a0..a45f90c 100644
76749 --- a/net/core/rtnetlink.c
76750 +++ b/net/core/rtnetlink.c
76751 @@ -58,7 +58,7 @@ struct rtnl_link {
76752 rtnl_doit_func doit;
76753 rtnl_dumpit_func dumpit;
76754 rtnl_calcit_func calcit;
76755 -};
76756 +} __no_const;
76757
76758 static DEFINE_MUTEX(rtnl_mutex);
76759
76760 diff --git a/net/core/scm.c b/net/core/scm.c
76761 index 040cebe..5b1e312 100644
76762 --- a/net/core/scm.c
76763 +++ b/net/core/scm.c
76764 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76765 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76766 {
76767 struct cmsghdr __user *cm
76768 - = (__force struct cmsghdr __user *)msg->msg_control;
76769 + = (struct cmsghdr __force_user *)msg->msg_control;
76770 struct cmsghdr cmhdr;
76771 int cmlen = CMSG_LEN(len);
76772 int err;
76773 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76774 err = -EFAULT;
76775 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76776 goto out;
76777 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76778 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76779 goto out;
76780 cmlen = CMSG_SPACE(len);
76781 if (msg->msg_controllen < cmlen)
76782 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76783 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76784 {
76785 struct cmsghdr __user *cm
76786 - = (__force struct cmsghdr __user*)msg->msg_control;
76787 + = (struct cmsghdr __force_user *)msg->msg_control;
76788
76789 int fdmax = 0;
76790 int fdnum = scm->fp->count;
76791 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76792 if (fdnum < fdmax)
76793 fdmax = fdnum;
76794
76795 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76796 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76797 i++, cmfptr++)
76798 {
76799 struct socket *sock;
76800 diff --git a/net/core/sock.c b/net/core/sock.c
76801 index a6000fb..d4aee72 100644
76802 --- a/net/core/sock.c
76803 +++ b/net/core/sock.c
76804 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76805 struct sk_buff_head *list = &sk->sk_receive_queue;
76806
76807 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76808 - atomic_inc(&sk->sk_drops);
76809 + atomic_inc_unchecked(&sk->sk_drops);
76810 trace_sock_rcvqueue_full(sk, skb);
76811 return -ENOMEM;
76812 }
76813 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76814 return err;
76815
76816 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76817 - atomic_inc(&sk->sk_drops);
76818 + atomic_inc_unchecked(&sk->sk_drops);
76819 return -ENOBUFS;
76820 }
76821
76822 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76823 skb_dst_force(skb);
76824
76825 spin_lock_irqsave(&list->lock, flags);
76826 - skb->dropcount = atomic_read(&sk->sk_drops);
76827 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76828 __skb_queue_tail(list, skb);
76829 spin_unlock_irqrestore(&list->lock, flags);
76830
76831 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76832 skb->dev = NULL;
76833
76834 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76835 - atomic_inc(&sk->sk_drops);
76836 + atomic_inc_unchecked(&sk->sk_drops);
76837 goto discard_and_relse;
76838 }
76839 if (nested)
76840 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76841 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76842 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76843 bh_unlock_sock(sk);
76844 - atomic_inc(&sk->sk_drops);
76845 + atomic_inc_unchecked(&sk->sk_drops);
76846 goto discard_and_relse;
76847 }
76848
76849 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76850 struct timeval tm;
76851 } v;
76852
76853 - int lv = sizeof(int);
76854 - int len;
76855 + unsigned int lv = sizeof(int);
76856 + unsigned int len;
76857
76858 if (get_user(len, optlen))
76859 return -EFAULT;
76860 - if (len < 0)
76861 + if (len > INT_MAX)
76862 return -EINVAL;
76863
76864 memset(&v, 0, sizeof(v));
76865 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76866
76867 case SO_PEERNAME:
76868 {
76869 - char address[128];
76870 + char address[_K_SS_MAXSIZE];
76871
76872 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76873 return -ENOTCONN;
76874 - if (lv < len)
76875 + if (lv < len || sizeof address < len)
76876 return -EINVAL;
76877 if (copy_to_user(optval, address, len))
76878 return -EFAULT;
76879 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76880
76881 if (len > lv)
76882 len = lv;
76883 - if (copy_to_user(optval, &v, len))
76884 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76885 return -EFAULT;
76886 lenout:
76887 if (put_user(len, optlen))
76888 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76889 */
76890 smp_wmb();
76891 atomic_set(&sk->sk_refcnt, 1);
76892 - atomic_set(&sk->sk_drops, 0);
76893 + atomic_set_unchecked(&sk->sk_drops, 0);
76894 }
76895 EXPORT_SYMBOL(sock_init_data);
76896
76897 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76898 index 9d8755e..26de8bc 100644
76899 --- a/net/core/sock_diag.c
76900 +++ b/net/core/sock_diag.c
76901 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76902
76903 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76904 {
76905 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76906 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76907 cookie[1] != INET_DIAG_NOCOOKIE) &&
76908 ((u32)(unsigned long)sk != cookie[0] ||
76909 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76910 return -ESTALE;
76911 else
76912 +#endif
76913 return 0;
76914 }
76915 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76916
76917 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76918 {
76919 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76920 + cookie[0] = 0;
76921 + cookie[1] = 0;
76922 +#else
76923 cookie[0] = (u32)(unsigned long)sk;
76924 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76925 +#endif
76926 }
76927 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76928
76929 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76930 index a55eecc..dd8428c 100644
76931 --- a/net/decnet/sysctl_net_decnet.c
76932 +++ b/net/decnet/sysctl_net_decnet.c
76933 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76934
76935 if (len > *lenp) len = *lenp;
76936
76937 - if (copy_to_user(buffer, addr, len))
76938 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76939 return -EFAULT;
76940
76941 *lenp = len;
76942 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76943
76944 if (len > *lenp) len = *lenp;
76945
76946 - if (copy_to_user(buffer, devname, len))
76947 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76948 return -EFAULT;
76949
76950 *lenp = len;
76951 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76952 index f444ac7..b7bdda9 100644
76953 --- a/net/ipv4/fib_frontend.c
76954 +++ b/net/ipv4/fib_frontend.c
76955 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76956 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76957 fib_sync_up(dev);
76958 #endif
76959 - atomic_inc(&net->ipv4.dev_addr_genid);
76960 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76961 rt_cache_flush(dev_net(dev));
76962 break;
76963 case NETDEV_DOWN:
76964 fib_del_ifaddr(ifa, NULL);
76965 - atomic_inc(&net->ipv4.dev_addr_genid);
76966 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76967 if (ifa->ifa_dev->ifa_list == NULL) {
76968 /* Last address was deleted from this interface.
76969 * Disable IP.
76970 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76971 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76972 fib_sync_up(dev);
76973 #endif
76974 - atomic_inc(&net->ipv4.dev_addr_genid);
76975 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76976 rt_cache_flush(dev_net(dev));
76977 break;
76978 case NETDEV_DOWN:
76979 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76980 index 9633661..4e0bc08 100644
76981 --- a/net/ipv4/fib_semantics.c
76982 +++ b/net/ipv4/fib_semantics.c
76983 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76984 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76985 nh->nh_gw,
76986 nh->nh_parent->fib_scope);
76987 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76988 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76989
76990 return nh->nh_saddr;
76991 }
76992 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76993 index 7880af9..70f92a3 100644
76994 --- a/net/ipv4/inet_hashtables.c
76995 +++ b/net/ipv4/inet_hashtables.c
76996 @@ -18,12 +18,15 @@
76997 #include <linux/sched.h>
76998 #include <linux/slab.h>
76999 #include <linux/wait.h>
77000 +#include <linux/security.h>
77001
77002 #include <net/inet_connection_sock.h>
77003 #include <net/inet_hashtables.h>
77004 #include <net/secure_seq.h>
77005 #include <net/ip.h>
77006
77007 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
77008 +
77009 /*
77010 * Allocate and initialize a new local port bind bucket.
77011 * The bindhash mutex for snum's hash chain must be held here.
77012 @@ -530,6 +533,8 @@ ok:
77013 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
77014 spin_unlock(&head->lock);
77015
77016 + gr_update_task_in_ip_table(current, inet_sk(sk));
77017 +
77018 if (tw) {
77019 inet_twsk_deschedule(tw, death_row);
77020 while (twrefcnt) {
77021 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
77022 index c7527f6..d8bba61 100644
77023 --- a/net/ipv4/inetpeer.c
77024 +++ b/net/ipv4/inetpeer.c
77025 @@ -503,8 +503,8 @@ relookup:
77026 if (p) {
77027 p->daddr = *daddr;
77028 atomic_set(&p->refcnt, 1);
77029 - atomic_set(&p->rid, 0);
77030 - atomic_set(&p->ip_id_count,
77031 + atomic_set_unchecked(&p->rid, 0);
77032 + atomic_set_unchecked(&p->ip_id_count,
77033 (daddr->family == AF_INET) ?
77034 secure_ip_id(daddr->addr.a4) :
77035 secure_ipv6_id(daddr->addr.a6));
77036 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
77037 index 8d07c97..d0812ef 100644
77038 --- a/net/ipv4/ip_fragment.c
77039 +++ b/net/ipv4/ip_fragment.c
77040 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
77041 return 0;
77042
77043 start = qp->rid;
77044 - end = atomic_inc_return(&peer->rid);
77045 + end = atomic_inc_return_unchecked(&peer->rid);
77046 qp->rid = end;
77047
77048 rc = qp->q.fragments && (end - start) > max;
77049 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
77050 index 5eea4a8..49819c2 100644
77051 --- a/net/ipv4/ip_sockglue.c
77052 +++ b/net/ipv4/ip_sockglue.c
77053 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77054 len = min_t(unsigned int, len, opt->optlen);
77055 if (put_user(len, optlen))
77056 return -EFAULT;
77057 - if (copy_to_user(optval, opt->__data, len))
77058 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77059 + copy_to_user(optval, opt->__data, len))
77060 return -EFAULT;
77061 return 0;
77062 }
77063 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77064 if (sk->sk_type != SOCK_STREAM)
77065 return -ENOPROTOOPT;
77066
77067 - msg.msg_control = optval;
77068 + msg.msg_control = (void __force_kernel *)optval;
77069 msg.msg_controllen = len;
77070 msg.msg_flags = flags;
77071
77072 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77073 index 67e8a6b..386764d 100644
77074 --- a/net/ipv4/ipconfig.c
77075 +++ b/net/ipv4/ipconfig.c
77076 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77077
77078 mm_segment_t oldfs = get_fs();
77079 set_fs(get_ds());
77080 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77081 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77082 set_fs(oldfs);
77083 return res;
77084 }
77085 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77086
77087 mm_segment_t oldfs = get_fs();
77088 set_fs(get_ds());
77089 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77090 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77091 set_fs(oldfs);
77092 return res;
77093 }
77094 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77095
77096 mm_segment_t oldfs = get_fs();
77097 set_fs(get_ds());
77098 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77099 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77100 set_fs(oldfs);
77101 return res;
77102 }
77103 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77104 index 97e61ea..cac1bbb 100644
77105 --- a/net/ipv4/netfilter/arp_tables.c
77106 +++ b/net/ipv4/netfilter/arp_tables.c
77107 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77108 #endif
77109
77110 static int get_info(struct net *net, void __user *user,
77111 - const int *len, int compat)
77112 + int len, int compat)
77113 {
77114 char name[XT_TABLE_MAXNAMELEN];
77115 struct xt_table *t;
77116 int ret;
77117
77118 - if (*len != sizeof(struct arpt_getinfo)) {
77119 - duprintf("length %u != %Zu\n", *len,
77120 + if (len != sizeof(struct arpt_getinfo)) {
77121 + duprintf("length %u != %Zu\n", len,
77122 sizeof(struct arpt_getinfo));
77123 return -EINVAL;
77124 }
77125 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77126 info.size = private->size;
77127 strcpy(info.name, name);
77128
77129 - if (copy_to_user(user, &info, *len) != 0)
77130 + if (copy_to_user(user, &info, len) != 0)
77131 ret = -EFAULT;
77132 else
77133 ret = 0;
77134 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77135
77136 switch (cmd) {
77137 case ARPT_SO_GET_INFO:
77138 - ret = get_info(sock_net(sk), user, len, 1);
77139 + ret = get_info(sock_net(sk), user, *len, 1);
77140 break;
77141 case ARPT_SO_GET_ENTRIES:
77142 ret = compat_get_entries(sock_net(sk), user, len);
77143 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77144
77145 switch (cmd) {
77146 case ARPT_SO_GET_INFO:
77147 - ret = get_info(sock_net(sk), user, len, 0);
77148 + ret = get_info(sock_net(sk), user, *len, 0);
77149 break;
77150
77151 case ARPT_SO_GET_ENTRIES:
77152 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77153 index 170b1fd..6105b91 100644
77154 --- a/net/ipv4/netfilter/ip_tables.c
77155 +++ b/net/ipv4/netfilter/ip_tables.c
77156 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77157 #endif
77158
77159 static int get_info(struct net *net, void __user *user,
77160 - const int *len, int compat)
77161 + int len, int compat)
77162 {
77163 char name[XT_TABLE_MAXNAMELEN];
77164 struct xt_table *t;
77165 int ret;
77166
77167 - if (*len != sizeof(struct ipt_getinfo)) {
77168 - duprintf("length %u != %zu\n", *len,
77169 + if (len != sizeof(struct ipt_getinfo)) {
77170 + duprintf("length %u != %zu\n", len,
77171 sizeof(struct ipt_getinfo));
77172 return -EINVAL;
77173 }
77174 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77175 info.size = private->size;
77176 strcpy(info.name, name);
77177
77178 - if (copy_to_user(user, &info, *len) != 0)
77179 + if (copy_to_user(user, &info, len) != 0)
77180 ret = -EFAULT;
77181 else
77182 ret = 0;
77183 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77184
77185 switch (cmd) {
77186 case IPT_SO_GET_INFO:
77187 - ret = get_info(sock_net(sk), user, len, 1);
77188 + ret = get_info(sock_net(sk), user, *len, 1);
77189 break;
77190 case IPT_SO_GET_ENTRIES:
77191 ret = compat_get_entries(sock_net(sk), user, len);
77192 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77193
77194 switch (cmd) {
77195 case IPT_SO_GET_INFO:
77196 - ret = get_info(sock_net(sk), user, len, 0);
77197 + ret = get_info(sock_net(sk), user, *len, 0);
77198 break;
77199
77200 case IPT_SO_GET_ENTRIES:
77201 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77202 index 6232d47..6b88607 100644
77203 --- a/net/ipv4/ping.c
77204 +++ b/net/ipv4/ping.c
77205 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77206 sk_rmem_alloc_get(sp),
77207 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77208 atomic_read(&sp->sk_refcnt), sp,
77209 - atomic_read(&sp->sk_drops), len);
77210 + atomic_read_unchecked(&sp->sk_drops), len);
77211 }
77212
77213 static int ping_seq_show(struct seq_file *seq, void *v)
77214 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77215 index d23c657..cb69cc2 100644
77216 --- a/net/ipv4/raw.c
77217 +++ b/net/ipv4/raw.c
77218 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77219 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77220 {
77221 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77222 - atomic_inc(&sk->sk_drops);
77223 + atomic_inc_unchecked(&sk->sk_drops);
77224 kfree_skb(skb);
77225 return NET_RX_DROP;
77226 }
77227 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77228
77229 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77230 {
77231 + struct icmp_filter filter;
77232 +
77233 if (optlen > sizeof(struct icmp_filter))
77234 optlen = sizeof(struct icmp_filter);
77235 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77236 + if (copy_from_user(&filter, optval, optlen))
77237 return -EFAULT;
77238 + raw_sk(sk)->filter = filter;
77239 return 0;
77240 }
77241
77242 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77243 {
77244 int len, ret = -EFAULT;
77245 + struct icmp_filter filter;
77246
77247 if (get_user(len, optlen))
77248 goto out;
77249 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77250 if (len > sizeof(struct icmp_filter))
77251 len = sizeof(struct icmp_filter);
77252 ret = -EFAULT;
77253 - if (put_user(len, optlen) ||
77254 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77255 + filter = raw_sk(sk)->filter;
77256 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77257 goto out;
77258 ret = 0;
77259 out: return ret;
77260 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77261 sk_wmem_alloc_get(sp),
77262 sk_rmem_alloc_get(sp),
77263 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77264 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77265 + atomic_read(&sp->sk_refcnt),
77266 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77267 + NULL,
77268 +#else
77269 + sp,
77270 +#endif
77271 + atomic_read_unchecked(&sp->sk_drops));
77272 }
77273
77274 static int raw_seq_show(struct seq_file *seq, void *v)
77275 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77276 index 2a1383c..ff99572 100644
77277 --- a/net/ipv4/route.c
77278 +++ b/net/ipv4/route.c
77279 @@ -2523,7 +2523,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77280
77281 static __net_init int rt_genid_init(struct net *net)
77282 {
77283 - atomic_set(&net->rt_genid, 0);
77284 + atomic_set_unchecked(&net->rt_genid, 0);
77285 get_random_bytes(&net->ipv4.dev_addr_genid,
77286 sizeof(net->ipv4.dev_addr_genid));
77287 return 0;
77288 diff --git a/net/ipv4/tcp_illinois.c b/net/ipv4/tcp_illinois.c
77289 index 813b43a..834857f 100644
77290 --- a/net/ipv4/tcp_illinois.c
77291 +++ b/net/ipv4/tcp_illinois.c
77292 @@ -313,11 +313,13 @@ static void tcp_illinois_info(struct sock *sk, u32 ext,
77293 .tcpv_rttcnt = ca->cnt_rtt,
77294 .tcpv_minrtt = ca->base_rtt,
77295 };
77296 - u64 t = ca->sum_rtt;
77297
77298 - do_div(t, ca->cnt_rtt);
77299 - info.tcpv_rtt = t;
77300 + if (info.tcpv_rttcnt > 0) {
77301 + u64 t = ca->sum_rtt;
77302
77303 + do_div(t, info.tcpv_rttcnt);
77304 + info.tcpv_rtt = t;
77305 + }
77306 nla_put(skb, INET_DIAG_VEGASINFO, sizeof(info), &info);
77307 }
77308 }
77309 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77310 index d377f48..f19e3ec 100644
77311 --- a/net/ipv4/tcp_input.c
77312 +++ b/net/ipv4/tcp_input.c
77313 @@ -4556,6 +4556,9 @@ int tcp_send_rcvq(struct sock *sk, struct msghdr *msg, size_t size)
77314 struct tcphdr *th;
77315 bool fragstolen;
77316
77317 + if (size == 0)
77318 + return 0;
77319 +
77320 skb = alloc_skb(size + sizeof(*th), sk->sk_allocation);
77321 if (!skb)
77322 goto err;
77323 @@ -4728,7 +4731,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77324 * simplifies code)
77325 */
77326 static void
77327 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77328 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77329 struct sk_buff *head, struct sk_buff *tail,
77330 u32 start, u32 end)
77331 {
77332 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77333 index db7bfad..bfea796 100644
77334 --- a/net/ipv4/tcp_ipv4.c
77335 +++ b/net/ipv4/tcp_ipv4.c
77336 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77337 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77338
77339
77340 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77341 +extern int grsec_enable_blackhole;
77342 +#endif
77343 +
77344 #ifdef CONFIG_TCP_MD5SIG
77345 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77346 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77347 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77348 return 0;
77349
77350 reset:
77351 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77352 + if (!grsec_enable_blackhole)
77353 +#endif
77354 tcp_v4_send_reset(rsk, skb);
77355 discard:
77356 kfree_skb(skb);
77357 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77358 TCP_SKB_CB(skb)->sacked = 0;
77359
77360 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77361 - if (!sk)
77362 + if (!sk) {
77363 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77364 + ret = 1;
77365 +#endif
77366 goto no_tcp_socket;
77367 -
77368 + }
77369 process:
77370 - if (sk->sk_state == TCP_TIME_WAIT)
77371 + if (sk->sk_state == TCP_TIME_WAIT) {
77372 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77373 + ret = 2;
77374 +#endif
77375 goto do_time_wait;
77376 + }
77377
77378 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77379 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77380 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77381 bad_packet:
77382 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77383 } else {
77384 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77385 + if (!grsec_enable_blackhole || (ret == 1 &&
77386 + (skb->dev->flags & IFF_LOOPBACK)))
77387 +#endif
77388 tcp_v4_send_reset(NULL, skb);
77389 }
77390
77391 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77392 0, /* non standard timer */
77393 0, /* open_requests have no inode */
77394 atomic_read(&sk->sk_refcnt),
77395 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77396 + NULL,
77397 +#else
77398 req,
77399 +#endif
77400 len);
77401 }
77402
77403 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77404 sock_i_uid(sk),
77405 icsk->icsk_probes_out,
77406 sock_i_ino(sk),
77407 - atomic_read(&sk->sk_refcnt), sk,
77408 + atomic_read(&sk->sk_refcnt),
77409 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77410 + NULL,
77411 +#else
77412 + sk,
77413 +#endif
77414 jiffies_to_clock_t(icsk->icsk_rto),
77415 jiffies_to_clock_t(icsk->icsk_ack.ato),
77416 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77417 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77418 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77419 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77420 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77421 - atomic_read(&tw->tw_refcnt), tw, len);
77422 + atomic_read(&tw->tw_refcnt),
77423 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77424 + NULL,
77425 +#else
77426 + tw,
77427 +#endif
77428 + len);
77429 }
77430
77431 #define TMPSZ 150
77432 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77433 index 6ff7f10..38de56e 100644
77434 --- a/net/ipv4/tcp_minisocks.c
77435 +++ b/net/ipv4/tcp_minisocks.c
77436 @@ -27,6 +27,10 @@
77437 #include <net/inet_common.h>
77438 #include <net/xfrm.h>
77439
77440 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77441 +extern int grsec_enable_blackhole;
77442 +#endif
77443 +
77444 int sysctl_tcp_syncookies __read_mostly = 1;
77445 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77446
77447 @@ -707,6 +711,10 @@ listen_overflow:
77448
77449 embryonic_reset:
77450 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77451 +
77452 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77453 + if (!grsec_enable_blackhole)
77454 +#endif
77455 if (!(flg & TCP_FLAG_RST))
77456 req->rsk_ops->send_reset(sk, skb);
77457
77458 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77459 index 4526fe6..1a34e43 100644
77460 --- a/net/ipv4/tcp_probe.c
77461 +++ b/net/ipv4/tcp_probe.c
77462 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77463 if (cnt + width >= len)
77464 break;
77465
77466 - if (copy_to_user(buf + cnt, tbuf, width))
77467 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77468 return -EFAULT;
77469 cnt += width;
77470 }
77471 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77472 index b774a03..3873efe 100644
77473 --- a/net/ipv4/tcp_timer.c
77474 +++ b/net/ipv4/tcp_timer.c
77475 @@ -22,6 +22,10 @@
77476 #include <linux/gfp.h>
77477 #include <net/tcp.h>
77478
77479 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77480 +extern int grsec_lastack_retries;
77481 +#endif
77482 +
77483 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77484 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77485 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77486 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77487 }
77488 }
77489
77490 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77491 + if ((sk->sk_state == TCP_LAST_ACK) &&
77492 + (grsec_lastack_retries > 0) &&
77493 + (grsec_lastack_retries < retry_until))
77494 + retry_until = grsec_lastack_retries;
77495 +#endif
77496 +
77497 if (retransmits_timed_out(sk, retry_until,
77498 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77499 /* Has it gone just too far? */
77500 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77501 index 2814f66..fa2b223 100644
77502 --- a/net/ipv4/udp.c
77503 +++ b/net/ipv4/udp.c
77504 @@ -87,6 +87,7 @@
77505 #include <linux/types.h>
77506 #include <linux/fcntl.h>
77507 #include <linux/module.h>
77508 +#include <linux/security.h>
77509 #include <linux/socket.h>
77510 #include <linux/sockios.h>
77511 #include <linux/igmp.h>
77512 @@ -111,6 +112,10 @@
77513 #include <trace/events/skb.h>
77514 #include "udp_impl.h"
77515
77516 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77517 +extern int grsec_enable_blackhole;
77518 +#endif
77519 +
77520 struct udp_table udp_table __read_mostly;
77521 EXPORT_SYMBOL(udp_table);
77522
77523 @@ -569,6 +574,9 @@ found:
77524 return s;
77525 }
77526
77527 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77528 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77529 +
77530 /*
77531 * This routine is called by the ICMP module when it gets some
77532 * sort of error condition. If err < 0 then the socket should
77533 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77534 dport = usin->sin_port;
77535 if (dport == 0)
77536 return -EINVAL;
77537 +
77538 + err = gr_search_udp_sendmsg(sk, usin);
77539 + if (err)
77540 + return err;
77541 } else {
77542 if (sk->sk_state != TCP_ESTABLISHED)
77543 return -EDESTADDRREQ;
77544 +
77545 + err = gr_search_udp_sendmsg(sk, NULL);
77546 + if (err)
77547 + return err;
77548 +
77549 daddr = inet->inet_daddr;
77550 dport = inet->inet_dport;
77551 /* Open fast path for connected socket.
77552 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77553 udp_lib_checksum_complete(skb)) {
77554 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77555 IS_UDPLITE(sk));
77556 - atomic_inc(&sk->sk_drops);
77557 + atomic_inc_unchecked(&sk->sk_drops);
77558 __skb_unlink(skb, rcvq);
77559 __skb_queue_tail(&list_kill, skb);
77560 }
77561 @@ -1194,6 +1211,10 @@ try_again:
77562 if (!skb)
77563 goto out;
77564
77565 + err = gr_search_udp_recvmsg(sk, skb);
77566 + if (err)
77567 + goto out_free;
77568 +
77569 ulen = skb->len - sizeof(struct udphdr);
77570 copied = len;
77571 if (copied > ulen)
77572 @@ -1227,7 +1248,7 @@ try_again:
77573 if (unlikely(err)) {
77574 trace_kfree_skb(skb, udp_recvmsg);
77575 if (!peeked) {
77576 - atomic_inc(&sk->sk_drops);
77577 + atomic_inc_unchecked(&sk->sk_drops);
77578 UDP_INC_STATS_USER(sock_net(sk),
77579 UDP_MIB_INERRORS, is_udplite);
77580 }
77581 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77582
77583 drop:
77584 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77585 - atomic_inc(&sk->sk_drops);
77586 + atomic_inc_unchecked(&sk->sk_drops);
77587 kfree_skb(skb);
77588 return -1;
77589 }
77590 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77591 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77592
77593 if (!skb1) {
77594 - atomic_inc(&sk->sk_drops);
77595 + atomic_inc_unchecked(&sk->sk_drops);
77596 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77597 IS_UDPLITE(sk));
77598 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77599 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77600 goto csum_error;
77601
77602 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77603 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77604 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77605 +#endif
77606 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77607
77608 /*
77609 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77610 sk_wmem_alloc_get(sp),
77611 sk_rmem_alloc_get(sp),
77612 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77613 - atomic_read(&sp->sk_refcnt), sp,
77614 - atomic_read(&sp->sk_drops), len);
77615 + atomic_read(&sp->sk_refcnt),
77616 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77617 + NULL,
77618 +#else
77619 + sp,
77620 +#endif
77621 + atomic_read_unchecked(&sp->sk_drops), len);
77622 }
77623
77624 int udp4_seq_show(struct seq_file *seq, void *v)
77625 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77626 index b10374d..0baa1f9 100644
77627 --- a/net/ipv6/addrconf.c
77628 +++ b/net/ipv6/addrconf.c
77629 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77630 p.iph.ihl = 5;
77631 p.iph.protocol = IPPROTO_IPV6;
77632 p.iph.ttl = 64;
77633 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77634 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77635
77636 if (ops->ndo_do_ioctl) {
77637 mm_segment_t oldfs = get_fs();
77638 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77639 index ba6d13d..6899122 100644
77640 --- a/net/ipv6/ipv6_sockglue.c
77641 +++ b/net/ipv6/ipv6_sockglue.c
77642 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77643 if (sk->sk_type != SOCK_STREAM)
77644 return -ENOPROTOOPT;
77645
77646 - msg.msg_control = optval;
77647 + msg.msg_control = (void __force_kernel *)optval;
77648 msg.msg_controllen = len;
77649 msg.msg_flags = flags;
77650
77651 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77652 index d7cb045..8c0ded6 100644
77653 --- a/net/ipv6/netfilter/ip6_tables.c
77654 +++ b/net/ipv6/netfilter/ip6_tables.c
77655 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77656 #endif
77657
77658 static int get_info(struct net *net, void __user *user,
77659 - const int *len, int compat)
77660 + int len, int compat)
77661 {
77662 char name[XT_TABLE_MAXNAMELEN];
77663 struct xt_table *t;
77664 int ret;
77665
77666 - if (*len != sizeof(struct ip6t_getinfo)) {
77667 - duprintf("length %u != %zu\n", *len,
77668 + if (len != sizeof(struct ip6t_getinfo)) {
77669 + duprintf("length %u != %zu\n", len,
77670 sizeof(struct ip6t_getinfo));
77671 return -EINVAL;
77672 }
77673 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77674 info.size = private->size;
77675 strcpy(info.name, name);
77676
77677 - if (copy_to_user(user, &info, *len) != 0)
77678 + if (copy_to_user(user, &info, len) != 0)
77679 ret = -EFAULT;
77680 else
77681 ret = 0;
77682 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77683
77684 switch (cmd) {
77685 case IP6T_SO_GET_INFO:
77686 - ret = get_info(sock_net(sk), user, len, 1);
77687 + ret = get_info(sock_net(sk), user, *len, 1);
77688 break;
77689 case IP6T_SO_GET_ENTRIES:
77690 ret = compat_get_entries(sock_net(sk), user, len);
77691 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77692
77693 switch (cmd) {
77694 case IP6T_SO_GET_INFO:
77695 - ret = get_info(sock_net(sk), user, len, 0);
77696 + ret = get_info(sock_net(sk), user, *len, 0);
77697 break;
77698
77699 case IP6T_SO_GET_ENTRIES:
77700 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77701 index 4a5f78b..3f22ebe 100644
77702 --- a/net/ipv6/raw.c
77703 +++ b/net/ipv6/raw.c
77704 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77705 {
77706 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77707 skb_checksum_complete(skb)) {
77708 - atomic_inc(&sk->sk_drops);
77709 + atomic_inc_unchecked(&sk->sk_drops);
77710 kfree_skb(skb);
77711 return NET_RX_DROP;
77712 }
77713 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77714 struct raw6_sock *rp = raw6_sk(sk);
77715
77716 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77717 - atomic_inc(&sk->sk_drops);
77718 + atomic_inc_unchecked(&sk->sk_drops);
77719 kfree_skb(skb);
77720 return NET_RX_DROP;
77721 }
77722 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77723
77724 if (inet->hdrincl) {
77725 if (skb_checksum_complete(skb)) {
77726 - atomic_inc(&sk->sk_drops);
77727 + atomic_inc_unchecked(&sk->sk_drops);
77728 kfree_skb(skb);
77729 return NET_RX_DROP;
77730 }
77731 @@ -604,7 +604,7 @@ out:
77732 return err;
77733 }
77734
77735 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77736 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77737 struct flowi6 *fl6, struct dst_entry **dstp,
77738 unsigned int flags)
77739 {
77740 @@ -916,12 +916,15 @@ do_confirm:
77741 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77742 char __user *optval, int optlen)
77743 {
77744 + struct icmp6_filter filter;
77745 +
77746 switch (optname) {
77747 case ICMPV6_FILTER:
77748 if (optlen > sizeof(struct icmp6_filter))
77749 optlen = sizeof(struct icmp6_filter);
77750 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77751 + if (copy_from_user(&filter, optval, optlen))
77752 return -EFAULT;
77753 + raw6_sk(sk)->filter = filter;
77754 return 0;
77755 default:
77756 return -ENOPROTOOPT;
77757 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77758 char __user *optval, int __user *optlen)
77759 {
77760 int len;
77761 + struct icmp6_filter filter;
77762
77763 switch (optname) {
77764 case ICMPV6_FILTER:
77765 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77766 len = sizeof(struct icmp6_filter);
77767 if (put_user(len, optlen))
77768 return -EFAULT;
77769 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77770 + filter = raw6_sk(sk)->filter;
77771 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77772 return -EFAULT;
77773 return 0;
77774 default:
77775 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77776 0, 0L, 0,
77777 sock_i_uid(sp), 0,
77778 sock_i_ino(sp),
77779 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77780 + atomic_read(&sp->sk_refcnt),
77781 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77782 + NULL,
77783 +#else
77784 + sp,
77785 +#endif
77786 + atomic_read_unchecked(&sp->sk_drops));
77787 }
77788
77789 static int raw6_seq_show(struct seq_file *seq, void *v)
77790 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77791 index 7e32d42..5d975ba 100644
77792 --- a/net/ipv6/tcp_ipv6.c
77793 +++ b/net/ipv6/tcp_ipv6.c
77794 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77795 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77796 }
77797
77798 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77799 +extern int grsec_enable_blackhole;
77800 +#endif
77801 +
77802 static void tcp_v6_hash(struct sock *sk)
77803 {
77804 if (sk->sk_state != TCP_CLOSE) {
77805 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77806 return 0;
77807
77808 reset:
77809 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77810 + if (!grsec_enable_blackhole)
77811 +#endif
77812 tcp_v6_send_reset(sk, skb);
77813 discard:
77814 if (opt_skb)
77815 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77816 TCP_SKB_CB(skb)->sacked = 0;
77817
77818 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77819 - if (!sk)
77820 + if (!sk) {
77821 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77822 + ret = 1;
77823 +#endif
77824 goto no_tcp_socket;
77825 + }
77826
77827 process:
77828 - if (sk->sk_state == TCP_TIME_WAIT)
77829 + if (sk->sk_state == TCP_TIME_WAIT) {
77830 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77831 + ret = 2;
77832 +#endif
77833 goto do_time_wait;
77834 + }
77835
77836 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77837 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77838 @@ -1646,6 +1661,10 @@ no_tcp_socket:
77839 bad_packet:
77840 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77841 } else {
77842 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77843 + if (!grsec_enable_blackhole || (ret == 1 &&
77844 + (skb->dev->flags & IFF_LOOPBACK)))
77845 +#endif
77846 tcp_v6_send_reset(NULL, skb);
77847 }
77848
77849 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
77850 uid,
77851 0, /* non standard timer */
77852 0, /* open_requests have no inode */
77853 - 0, req);
77854 + 0,
77855 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77856 + NULL
77857 +#else
77858 + req
77859 +#endif
77860 + );
77861 }
77862
77863 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77864 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77865 sock_i_uid(sp),
77866 icsk->icsk_probes_out,
77867 sock_i_ino(sp),
77868 - atomic_read(&sp->sk_refcnt), sp,
77869 + atomic_read(&sp->sk_refcnt),
77870 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77871 + NULL,
77872 +#else
77873 + sp,
77874 +#endif
77875 jiffies_to_clock_t(icsk->icsk_rto),
77876 jiffies_to_clock_t(icsk->icsk_ack.ato),
77877 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77878 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77879 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77880 tw->tw_substate, 0, 0,
77881 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77882 - atomic_read(&tw->tw_refcnt), tw);
77883 + atomic_read(&tw->tw_refcnt),
77884 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77885 + NULL
77886 +#else
77887 + tw
77888 +#endif
77889 + );
77890 }
77891
77892 static int tcp6_seq_show(struct seq_file *seq, void *v)
77893 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77894 index 07e2bfe..328dae8 100644
77895 --- a/net/ipv6/udp.c
77896 +++ b/net/ipv6/udp.c
77897 @@ -51,6 +51,10 @@
77898 #include <trace/events/skb.h>
77899 #include "udp_impl.h"
77900
77901 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77902 +extern int grsec_enable_blackhole;
77903 +#endif
77904 +
77905 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77906 {
77907 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77908 @@ -395,7 +399,7 @@ try_again:
77909 if (unlikely(err)) {
77910 trace_kfree_skb(skb, udpv6_recvmsg);
77911 if (!peeked) {
77912 - atomic_inc(&sk->sk_drops);
77913 + atomic_inc_unchecked(&sk->sk_drops);
77914 if (is_udp4)
77915 UDP_INC_STATS_USER(sock_net(sk),
77916 UDP_MIB_INERRORS,
77917 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77918 return rc;
77919 drop:
77920 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77921 - atomic_inc(&sk->sk_drops);
77922 + atomic_inc_unchecked(&sk->sk_drops);
77923 kfree_skb(skb);
77924 return -1;
77925 }
77926 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77927 if (likely(skb1 == NULL))
77928 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77929 if (!skb1) {
77930 - atomic_inc(&sk->sk_drops);
77931 + atomic_inc_unchecked(&sk->sk_drops);
77932 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77933 IS_UDPLITE(sk));
77934 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77935 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77936 goto discard;
77937
77938 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77939 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77940 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77941 +#endif
77942 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77943
77944 kfree_skb(skb);
77945 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77946 0, 0L, 0,
77947 sock_i_uid(sp), 0,
77948 sock_i_ino(sp),
77949 - atomic_read(&sp->sk_refcnt), sp,
77950 - atomic_read(&sp->sk_drops));
77951 + atomic_read(&sp->sk_refcnt),
77952 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77953 + NULL,
77954 +#else
77955 + sp,
77956 +#endif
77957 + atomic_read_unchecked(&sp->sk_drops));
77958 }
77959
77960 int udp6_seq_show(struct seq_file *seq, void *v)
77961 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77962 index 6b9d5a0..4dffaf1 100644
77963 --- a/net/irda/ircomm/ircomm_tty.c
77964 +++ b/net/irda/ircomm/ircomm_tty.c
77965 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77966 add_wait_queue(&self->open_wait, &wait);
77967
77968 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77969 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77970 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77971
77972 /* As far as I can see, we protect open_count - Jean II */
77973 spin_lock_irqsave(&self->spinlock, flags);
77974 if (!tty_hung_up_p(filp)) {
77975 extra_count = 1;
77976 - self->open_count--;
77977 + local_dec(&self->open_count);
77978 }
77979 spin_unlock_irqrestore(&self->spinlock, flags);
77980 - self->blocked_open++;
77981 + local_inc(&self->blocked_open);
77982
77983 while (1) {
77984 if (tty->termios->c_cflag & CBAUD) {
77985 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77986 }
77987
77988 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77989 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77990 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77991
77992 schedule();
77993 }
77994 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77995 if (extra_count) {
77996 /* ++ is not atomic, so this should be protected - Jean II */
77997 spin_lock_irqsave(&self->spinlock, flags);
77998 - self->open_count++;
77999 + local_inc(&self->open_count);
78000 spin_unlock_irqrestore(&self->spinlock, flags);
78001 }
78002 - self->blocked_open--;
78003 + local_dec(&self->blocked_open);
78004
78005 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
78006 - __FILE__,__LINE__, tty->driver->name, self->open_count);
78007 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
78008
78009 if (!retval)
78010 self->flags |= ASYNC_NORMAL_ACTIVE;
78011 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
78012 }
78013 /* ++ is not atomic, so this should be protected - Jean II */
78014 spin_lock_irqsave(&self->spinlock, flags);
78015 - self->open_count++;
78016 + local_inc(&self->open_count);
78017
78018 tty->driver_data = self;
78019 self->tty = tty;
78020 spin_unlock_irqrestore(&self->spinlock, flags);
78021
78022 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
78023 - self->line, self->open_count);
78024 + self->line, local_read(&self->open_count));
78025
78026 /* Not really used by us, but lets do it anyway */
78027 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
78028 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78029 return;
78030 }
78031
78032 - if ((tty->count == 1) && (self->open_count != 1)) {
78033 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
78034 /*
78035 * Uh, oh. tty->count is 1, which means that the tty
78036 * structure will be freed. state->count should always
78037 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78038 */
78039 IRDA_DEBUG(0, "%s(), bad serial port count; "
78040 "tty->count is 1, state->count is %d\n", __func__ ,
78041 - self->open_count);
78042 - self->open_count = 1;
78043 + local_read(&self->open_count));
78044 + local_set(&self->open_count, 1);
78045 }
78046
78047 - if (--self->open_count < 0) {
78048 + if (local_dec_return(&self->open_count) < 0) {
78049 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78050 - __func__, self->line, self->open_count);
78051 - self->open_count = 0;
78052 + __func__, self->line, local_read(&self->open_count));
78053 + local_set(&self->open_count, 0);
78054 }
78055 - if (self->open_count) {
78056 + if (local_read(&self->open_count)) {
78057 spin_unlock_irqrestore(&self->spinlock, flags);
78058
78059 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78060 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78061 tty->closing = 0;
78062 self->tty = NULL;
78063
78064 - if (self->blocked_open) {
78065 + if (local_read(&self->blocked_open)) {
78066 if (self->close_delay)
78067 schedule_timeout_interruptible(self->close_delay);
78068 wake_up_interruptible(&self->open_wait);
78069 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78070 spin_lock_irqsave(&self->spinlock, flags);
78071 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78072 self->tty = NULL;
78073 - self->open_count = 0;
78074 + local_set(&self->open_count, 0);
78075 spin_unlock_irqrestore(&self->spinlock, flags);
78076
78077 wake_up_interruptible(&self->open_wait);
78078 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78079 seq_putc(m, '\n');
78080
78081 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78082 - seq_printf(m, "Open count: %d\n", self->open_count);
78083 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78084 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78085 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78086
78087 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78088 index cd6f7a9..e63fe89 100644
78089 --- a/net/iucv/af_iucv.c
78090 +++ b/net/iucv/af_iucv.c
78091 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78092
78093 write_lock_bh(&iucv_sk_list.lock);
78094
78095 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78096 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78097 while (__iucv_get_sock_by_name(name)) {
78098 sprintf(name, "%08x",
78099 - atomic_inc_return(&iucv_sk_list.autobind_name));
78100 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78101 }
78102
78103 write_unlock_bh(&iucv_sk_list.lock);
78104 diff --git a/net/key/af_key.c b/net/key/af_key.c
78105 index 34e4185..8823368 100644
78106 --- a/net/key/af_key.c
78107 +++ b/net/key/af_key.c
78108 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78109 static u32 get_acqseq(void)
78110 {
78111 u32 res;
78112 - static atomic_t acqseq;
78113 + static atomic_unchecked_t acqseq;
78114
78115 do {
78116 - res = atomic_inc_return(&acqseq);
78117 + res = atomic_inc_return_unchecked(&acqseq);
78118 } while (!res);
78119 return res;
78120 }
78121 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
78122 index 3bfb34a..69bf48d 100644
78123 --- a/net/l2tp/l2tp_eth.c
78124 +++ b/net/l2tp/l2tp_eth.c
78125 @@ -290,6 +290,7 @@ static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id, u32 p
78126
78127 out_del_dev:
78128 free_netdev(dev);
78129 + spriv->dev = NULL;
78130 out_del_session:
78131 l2tp_session_delete(session);
78132 out:
78133 diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
78134 index 5746d62..327aa07 100644
78135 --- a/net/mac80211/ibss.c
78136 +++ b/net/mac80211/ibss.c
78137 @@ -1074,7 +1074,7 @@ int ieee80211_ibss_join(struct ieee80211_sub_if_data *sdata,
78138 sdata->u.ibss.state = IEEE80211_IBSS_MLME_SEARCH;
78139 sdata->u.ibss.ibss_join_req = jiffies;
78140
78141 - memcpy(sdata->u.ibss.ssid, params->ssid, IEEE80211_MAX_SSID_LEN);
78142 + memcpy(sdata->u.ibss.ssid, params->ssid, params->ssid_len);
78143 sdata->u.ibss.ssid_len = params->ssid_len;
78144
78145 mutex_unlock(&sdata->u.ibss.mtx);
78146 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78147 index bb61f77..3788d63 100644
78148 --- a/net/mac80211/ieee80211_i.h
78149 +++ b/net/mac80211/ieee80211_i.h
78150 @@ -28,6 +28,7 @@
78151 #include <net/ieee80211_radiotap.h>
78152 #include <net/cfg80211.h>
78153 #include <net/mac80211.h>
78154 +#include <asm/local.h>
78155 #include "key.h"
78156 #include "sta_info.h"
78157 #include "debug.h"
78158 @@ -840,7 +841,7 @@ struct ieee80211_local {
78159 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78160 spinlock_t queue_stop_reason_lock;
78161
78162 - int open_count;
78163 + local_t open_count;
78164 int monitors, cooked_mntrs;
78165 /* number of interfaces with corresponding FIF_ flags */
78166 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78167 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78168 index c93d395..a305570 100644
78169 --- a/net/mac80211/iface.c
78170 +++ b/net/mac80211/iface.c
78171 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78172 break;
78173 }
78174
78175 - if (local->open_count == 0) {
78176 + if (local_read(&local->open_count) == 0) {
78177 res = drv_start(local);
78178 if (res)
78179 goto err_del_bss;
78180 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78181 break;
78182 }
78183
78184 - if (local->monitors == 0 && local->open_count == 0) {
78185 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78186 res = ieee80211_add_virtual_monitor(local);
78187 if (res)
78188 goto err_stop;
78189 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78190 mutex_unlock(&local->mtx);
78191
78192 if (coming_up)
78193 - local->open_count++;
78194 + local_inc(&local->open_count);
78195
78196 if (hw_reconf_flags)
78197 ieee80211_hw_config(local, hw_reconf_flags);
78198 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78199 err_del_interface:
78200 drv_remove_interface(local, sdata);
78201 err_stop:
78202 - if (!local->open_count)
78203 + if (!local_read(&local->open_count))
78204 drv_stop(local);
78205 err_del_bss:
78206 sdata->bss = NULL;
78207 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78208 }
78209
78210 if (going_down)
78211 - local->open_count--;
78212 + local_dec(&local->open_count);
78213
78214 switch (sdata->vif.type) {
78215 case NL80211_IFTYPE_AP_VLAN:
78216 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78217
78218 ieee80211_recalc_ps(local, -1);
78219
78220 - if (local->open_count == 0) {
78221 + if (local_read(&local->open_count) == 0) {
78222 if (local->ops->napi_poll)
78223 napi_disable(&local->napi);
78224 ieee80211_clear_tx_pending(local);
78225 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78226 }
78227 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78228
78229 - if (local->monitors == local->open_count && local->monitors > 0)
78230 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78231 ieee80211_add_virtual_monitor(local);
78232 }
78233
78234 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78235 index c26e231..8916637 100644
78236 --- a/net/mac80211/main.c
78237 +++ b/net/mac80211/main.c
78238 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78239 local->hw.conf.power_level = power;
78240 }
78241
78242 - if (changed && local->open_count) {
78243 + if (changed && local_read(&local->open_count)) {
78244 ret = drv_config(local, changed);
78245 /*
78246 * Goal:
78247 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78248 index 5c572e7..ecf75ce 100644
78249 --- a/net/mac80211/pm.c
78250 +++ b/net/mac80211/pm.c
78251 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78252 struct ieee80211_sub_if_data *sdata;
78253 struct sta_info *sta;
78254
78255 - if (!local->open_count)
78256 + if (!local_read(&local->open_count))
78257 goto suspend;
78258
78259 ieee80211_scan_cancel(local);
78260 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78261 cancel_work_sync(&local->dynamic_ps_enable_work);
78262 del_timer_sync(&local->dynamic_ps_timer);
78263
78264 - local->wowlan = wowlan && local->open_count;
78265 + local->wowlan = wowlan && local_read(&local->open_count);
78266 if (local->wowlan) {
78267 int err = drv_suspend(local, wowlan);
78268 if (err < 0) {
78269 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78270 drv_remove_interface(local, sdata);
78271
78272 /* stop hardware - this must stop RX */
78273 - if (local->open_count)
78274 + if (local_read(&local->open_count))
78275 ieee80211_stop_device(local);
78276
78277 suspend:
78278 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78279 index 3313c11..bec9f17 100644
78280 --- a/net/mac80211/rate.c
78281 +++ b/net/mac80211/rate.c
78282 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78283
78284 ASSERT_RTNL();
78285
78286 - if (local->open_count)
78287 + if (local_read(&local->open_count))
78288 return -EBUSY;
78289
78290 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78291 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78292 index c97a065..ff61928 100644
78293 --- a/net/mac80211/rc80211_pid_debugfs.c
78294 +++ b/net/mac80211/rc80211_pid_debugfs.c
78295 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78296
78297 spin_unlock_irqrestore(&events->lock, status);
78298
78299 - if (copy_to_user(buf, pb, p))
78300 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78301 return -EFAULT;
78302
78303 return p;
78304 diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
78305 index 0cb4ede..884155d 100644
78306 --- a/net/mac80211/rx.c
78307 +++ b/net/mac80211/rx.c
78308 @@ -491,6 +491,11 @@ ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
78309
78310 if (ieee80211_is_action(hdr->frame_control)) {
78311 u8 category;
78312 +
78313 + /* make sure category field is present */
78314 + if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
78315 + return RX_DROP_MONITOR;
78316 +
78317 mgmt = (struct ieee80211_mgmt *)hdr;
78318 category = mgmt->u.action.category;
78319 if (category != WLAN_CATEGORY_MESH_ACTION &&
78320 @@ -1426,7 +1431,6 @@ ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
78321 frag = sc & IEEE80211_SCTL_FRAG;
78322
78323 if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
78324 - (rx->skb)->len < 24 ||
78325 is_multicast_ether_addr(hdr->addr1))) {
78326 /* not fragmented */
78327 goto out;
78328 @@ -1849,6 +1853,20 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
78329
78330 hdr = (struct ieee80211_hdr *) skb->data;
78331 hdrlen = ieee80211_hdrlen(hdr->frame_control);
78332 +
78333 + /* make sure fixed part of mesh header is there, also checks skb len */
78334 + if (!pskb_may_pull(rx->skb, hdrlen + 6))
78335 + return RX_DROP_MONITOR;
78336 +
78337 + mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
78338 +
78339 + /* make sure full mesh header is there, also checks skb len */
78340 + if (!pskb_may_pull(rx->skb,
78341 + hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
78342 + return RX_DROP_MONITOR;
78343 +
78344 + /* reload pointers */
78345 + hdr = (struct ieee80211_hdr *) skb->data;
78346 mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
78347
78348 /* frame is in RMC, don't forward */
78349 @@ -1871,9 +1889,12 @@ ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
78350 if (is_multicast_ether_addr(hdr->addr1)) {
78351 mpp_addr = hdr->addr3;
78352 proxied_addr = mesh_hdr->eaddr1;
78353 - } else {
78354 + } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
78355 + /* has_a4 already checked in ieee80211_rx_mesh_check */
78356 mpp_addr = hdr->addr4;
78357 proxied_addr = mesh_hdr->eaddr2;
78358 + } else {
78359 + return RX_DROP_MONITOR;
78360 }
78361
78362 rcu_read_lock();
78363 @@ -2313,6 +2334,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
78364 }
78365 break;
78366 case WLAN_CATEGORY_SELF_PROTECTED:
78367 + if (len < (IEEE80211_MIN_ACTION_SIZE +
78368 + sizeof(mgmt->u.action.u.self_prot.action_code)))
78369 + break;
78370 +
78371 switch (mgmt->u.action.u.self_prot.action_code) {
78372 case WLAN_SP_MESH_PEERING_OPEN:
78373 case WLAN_SP_MESH_PEERING_CLOSE:
78374 @@ -2331,6 +2356,10 @@ ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
78375 }
78376 break;
78377 case WLAN_CATEGORY_MESH_ACTION:
78378 + if (len < (IEEE80211_MIN_ACTION_SIZE +
78379 + sizeof(mgmt->u.action.u.mesh_action.action_code)))
78380 + break;
78381 +
78382 if (!ieee80211_vif_is_mesh(&sdata->vif))
78383 break;
78384 if (mesh_action_is_path_sel(mgmt) &&
78385 @@ -2865,10 +2894,15 @@ static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
78386 if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
78387 local->dot11ReceivedFragmentCount++;
78388
78389 - if (ieee80211_is_mgmt(fc))
78390 - err = skb_linearize(skb);
78391 - else
78392 + if (ieee80211_is_mgmt(fc)) {
78393 + /* drop frame if too short for header */
78394 + if (skb->len < ieee80211_hdrlen(fc))
78395 + err = -ENOBUFS;
78396 + else
78397 + err = skb_linearize(skb);
78398 + } else {
78399 err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
78400 + }
78401
78402 if (err) {
78403 dev_kfree_skb(skb);
78404 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78405 index c9b52f7..4da1014 100644
78406 --- a/net/mac80211/util.c
78407 +++ b/net/mac80211/util.c
78408 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78409 }
78410 #endif
78411 /* everything else happens only if HW was up & running */
78412 - if (!local->open_count)
78413 + if (!local_read(&local->open_count))
78414 goto wake_up;
78415
78416 /*
78417 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78418 index c19b214..471fad1 100644
78419 --- a/net/netfilter/Kconfig
78420 +++ b/net/netfilter/Kconfig
78421 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78422
78423 To compile it as a module, choose M here. If unsure, say N.
78424
78425 +config NETFILTER_XT_MATCH_GRADM
78426 + tristate '"gradm" match support'
78427 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78428 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78429 + ---help---
78430 + The gradm match allows to match on grsecurity RBAC being enabled.
78431 + It is useful when iptables rules are applied early on bootup to
78432 + prevent connections to the machine (except from a trusted host)
78433 + while the RBAC system is disabled.
78434 +
78435 config NETFILTER_XT_MATCH_HASHLIMIT
78436 tristate '"hashlimit" match support'
78437 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78438 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78439 index 1c5160f..145ae21 100644
78440 --- a/net/netfilter/Makefile
78441 +++ b/net/netfilter/Makefile
78442 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78443 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78444 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78445 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78446 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78447 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78448 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78449 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78450 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78451 index 1548df9..98ad9b4 100644
78452 --- a/net/netfilter/ipvs/ip_vs_conn.c
78453 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78454 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78455 /* Increase the refcnt counter of the dest */
78456 atomic_inc(&dest->refcnt);
78457
78458 - conn_flags = atomic_read(&dest->conn_flags);
78459 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78460 if (cp->protocol != IPPROTO_UDP)
78461 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78462 flags = cp->flags;
78463 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78464 atomic_set(&cp->refcnt, 1);
78465
78466 atomic_set(&cp->n_control, 0);
78467 - atomic_set(&cp->in_pkts, 0);
78468 + atomic_set_unchecked(&cp->in_pkts, 0);
78469
78470 atomic_inc(&ipvs->conn_count);
78471 if (flags & IP_VS_CONN_F_NO_CPORT)
78472 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78473
78474 /* Don't drop the entry if its number of incoming packets is not
78475 located in [0, 8] */
78476 - i = atomic_read(&cp->in_pkts);
78477 + i = atomic_read_unchecked(&cp->in_pkts);
78478 if (i > 8 || i < 0) return 0;
78479
78480 if (!todrop_rate[i]) return 0;
78481 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78482 index b54ecce..fc5f6cf 100644
78483 --- a/net/netfilter/ipvs/ip_vs_core.c
78484 +++ b/net/netfilter/ipvs/ip_vs_core.c
78485 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78486 ret = cp->packet_xmit(skb, cp, pd->pp);
78487 /* do not touch skb anymore */
78488
78489 - atomic_inc(&cp->in_pkts);
78490 + atomic_inc_unchecked(&cp->in_pkts);
78491 ip_vs_conn_put(cp);
78492 return ret;
78493 }
78494 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78495 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78496 pkts = sysctl_sync_threshold(ipvs);
78497 else
78498 - pkts = atomic_add_return(1, &cp->in_pkts);
78499 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78500
78501 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78502 ip_vs_sync_conn(net, cp, pkts);
78503 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78504 index f51013c..c99ee52 100644
78505 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78506 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78507 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78508 ip_vs_rs_hash(ipvs, dest);
78509 write_unlock_bh(&ipvs->rs_lock);
78510 }
78511 - atomic_set(&dest->conn_flags, conn_flags);
78512 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78513
78514 /* bind the service */
78515 if (!dest->svc) {
78516 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78517 " %-7s %-6d %-10d %-10d\n",
78518 &dest->addr.in6,
78519 ntohs(dest->port),
78520 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78521 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78522 atomic_read(&dest->weight),
78523 atomic_read(&dest->activeconns),
78524 atomic_read(&dest->inactconns));
78525 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78526 "%-7s %-6d %-10d %-10d\n",
78527 ntohl(dest->addr.ip),
78528 ntohs(dest->port),
78529 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78530 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78531 atomic_read(&dest->weight),
78532 atomic_read(&dest->activeconns),
78533 atomic_read(&dest->inactconns));
78534 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78535
78536 entry.addr = dest->addr.ip;
78537 entry.port = dest->port;
78538 - entry.conn_flags = atomic_read(&dest->conn_flags);
78539 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78540 entry.weight = atomic_read(&dest->weight);
78541 entry.u_threshold = dest->u_threshold;
78542 entry.l_threshold = dest->l_threshold;
78543 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78544 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78545 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78546 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78547 - (atomic_read(&dest->conn_flags) &
78548 + (atomic_read_unchecked(&dest->conn_flags) &
78549 IP_VS_CONN_F_FWD_MASK)) ||
78550 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78551 atomic_read(&dest->weight)) ||
78552 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78553 index effa10c..9058928 100644
78554 --- a/net/netfilter/ipvs/ip_vs_sync.c
78555 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78556 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78557 cp = cp->control;
78558 if (cp) {
78559 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78560 - pkts = atomic_add_return(1, &cp->in_pkts);
78561 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78562 else
78563 pkts = sysctl_sync_threshold(ipvs);
78564 ip_vs_sync_conn(net, cp->control, pkts);
78565 @@ -758,7 +758,7 @@ control:
78566 if (!cp)
78567 return;
78568 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78569 - pkts = atomic_add_return(1, &cp->in_pkts);
78570 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78571 else
78572 pkts = sysctl_sync_threshold(ipvs);
78573 goto sloop;
78574 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78575
78576 if (opt)
78577 memcpy(&cp->in_seq, opt, sizeof(*opt));
78578 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78579 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78580 cp->state = state;
78581 cp->old_state = cp->state;
78582 /*
78583 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78584 index c3c6291..3376d73 100644
78585 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78586 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78587 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78588 else
78589 rc = NF_ACCEPT;
78590 /* do not touch skb anymore */
78591 - atomic_inc(&cp->in_pkts);
78592 + atomic_inc_unchecked(&cp->in_pkts);
78593 goto out;
78594 }
78595
78596 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78597 else
78598 rc = NF_ACCEPT;
78599 /* do not touch skb anymore */
78600 - atomic_inc(&cp->in_pkts);
78601 + atomic_inc_unchecked(&cp->in_pkts);
78602 goto out;
78603 }
78604
78605 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78606 index 2ceec64..a5b8a61 100644
78607 --- a/net/netfilter/nf_conntrack_core.c
78608 +++ b/net/netfilter/nf_conntrack_core.c
78609 @@ -1529,6 +1529,10 @@ err_extend:
78610 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78611 #define DYING_NULLS_VAL ((1<<30)+1)
78612
78613 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78614 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78615 +#endif
78616 +
78617 static int nf_conntrack_init_net(struct net *net)
78618 {
78619 int ret;
78620 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78621 goto err_stat;
78622 }
78623
78624 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78625 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78626 +#else
78627 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78628 +#endif
78629 if (!net->ct.slabname) {
78630 ret = -ENOMEM;
78631 goto err_slabname;
78632 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78633 index 5cfb5be..217c6d8 100644
78634 --- a/net/netfilter/nfnetlink_log.c
78635 +++ b/net/netfilter/nfnetlink_log.c
78636 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78637 };
78638
78639 static DEFINE_SPINLOCK(instances_lock);
78640 -static atomic_t global_seq;
78641 +static atomic_unchecked_t global_seq;
78642
78643 #define INSTANCE_BUCKETS 16
78644 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78645 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78646 /* global sequence number */
78647 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78648 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78649 - htonl(atomic_inc_return(&global_seq))))
78650 + htonl(atomic_inc_return_unchecked(&global_seq))))
78651 goto nla_put_failure;
78652
78653 if (data_len) {
78654 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78655 new file mode 100644
78656 index 0000000..6905327
78657 --- /dev/null
78658 +++ b/net/netfilter/xt_gradm.c
78659 @@ -0,0 +1,51 @@
78660 +/*
78661 + * gradm match for netfilter
78662 + * Copyright © Zbigniew Krzystolik, 2010
78663 + *
78664 + * This program is free software; you can redistribute it and/or modify
78665 + * it under the terms of the GNU General Public License; either version
78666 + * 2 or 3 as published by the Free Software Foundation.
78667 + */
78668 +#include <linux/module.h>
78669 +#include <linux/moduleparam.h>
78670 +#include <linux/skbuff.h>
78671 +#include <linux/netfilter/x_tables.h>
78672 +#include <linux/grsecurity.h>
78673 +#include <linux/netfilter/xt_gradm.h>
78674 +
78675 +static bool
78676 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78677 +{
78678 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78679 + bool retval = false;
78680 + if (gr_acl_is_enabled())
78681 + retval = true;
78682 + return retval ^ info->invflags;
78683 +}
78684 +
78685 +static struct xt_match gradm_mt_reg __read_mostly = {
78686 + .name = "gradm",
78687 + .revision = 0,
78688 + .family = NFPROTO_UNSPEC,
78689 + .match = gradm_mt,
78690 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78691 + .me = THIS_MODULE,
78692 +};
78693 +
78694 +static int __init gradm_mt_init(void)
78695 +{
78696 + return xt_register_match(&gradm_mt_reg);
78697 +}
78698 +
78699 +static void __exit gradm_mt_exit(void)
78700 +{
78701 + xt_unregister_match(&gradm_mt_reg);
78702 +}
78703 +
78704 +module_init(gradm_mt_init);
78705 +module_exit(gradm_mt_exit);
78706 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78707 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78708 +MODULE_LICENSE("GPL");
78709 +MODULE_ALIAS("ipt_gradm");
78710 +MODULE_ALIAS("ip6t_gradm");
78711 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78712 index 4fe4fb4..87a89e5 100644
78713 --- a/net/netfilter/xt_statistic.c
78714 +++ b/net/netfilter/xt_statistic.c
78715 @@ -19,7 +19,7 @@
78716 #include <linux/module.h>
78717
78718 struct xt_statistic_priv {
78719 - atomic_t count;
78720 + atomic_unchecked_t count;
78721 } ____cacheline_aligned_in_smp;
78722
78723 MODULE_LICENSE("GPL");
78724 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78725 break;
78726 case XT_STATISTIC_MODE_NTH:
78727 do {
78728 - oval = atomic_read(&info->master->count);
78729 + oval = atomic_read_unchecked(&info->master->count);
78730 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78731 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78732 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78733 if (nval == 0)
78734 ret = !ret;
78735 break;
78736 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78737 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78738 if (info->master == NULL)
78739 return -ENOMEM;
78740 - atomic_set(&info->master->count, info->u.nth.count);
78741 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78742
78743 return 0;
78744 }
78745 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78746 index 9172179..a4035c4 100644
78747 --- a/net/netlink/af_netlink.c
78748 +++ b/net/netlink/af_netlink.c
78749 @@ -769,7 +769,7 @@ static void netlink_overrun(struct sock *sk)
78750 sk->sk_error_report(sk);
78751 }
78752 }
78753 - atomic_inc(&sk->sk_drops);
78754 + atomic_inc_unchecked(&sk->sk_drops);
78755 }
78756
78757 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78758 @@ -2059,7 +2059,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78759 sk_wmem_alloc_get(s),
78760 nlk->cb,
78761 atomic_read(&s->sk_refcnt),
78762 - atomic_read(&s->sk_drops),
78763 + atomic_read_unchecked(&s->sk_drops),
78764 sock_i_ino(s)
78765 );
78766
78767 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78768 index 7261eb8..44e8ac6 100644
78769 --- a/net/netrom/af_netrom.c
78770 +++ b/net/netrom/af_netrom.c
78771 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78772 struct sock *sk = sock->sk;
78773 struct nr_sock *nr = nr_sk(sk);
78774
78775 + memset(sax, 0, sizeof(*sax));
78776 lock_sock(sk);
78777 if (peer != 0) {
78778 if (sk->sk_state != TCP_ESTABLISHED) {
78779 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78780 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78781 } else {
78782 sax->fsa_ax25.sax25_family = AF_NETROM;
78783 - sax->fsa_ax25.sax25_ndigis = 0;
78784 sax->fsa_ax25.sax25_call = nr->source_addr;
78785 *uaddr_len = sizeof(struct sockaddr_ax25);
78786 }
78787 diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
78788 index ddeb9aa..e18fffd 100644
78789 --- a/net/nfc/llcp/sock.c
78790 +++ b/net/nfc/llcp/sock.c
78791 @@ -443,15 +443,11 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
78792 pr_debug("sock %p sk %p flags 0x%x\n", sock, sk, flags);
78793
78794 if (!addr || len < sizeof(struct sockaddr_nfc) ||
78795 - addr->sa_family != AF_NFC) {
78796 - pr_err("Invalid socket\n");
78797 + addr->sa_family != AF_NFC)
78798 return -EINVAL;
78799 - }
78800
78801 - if (addr->service_name_len == 0 && addr->dsap == 0) {
78802 - pr_err("Missing service name or dsap\n");
78803 + if (addr->service_name_len == 0 && addr->dsap == 0)
78804 return -EINVAL;
78805 - }
78806
78807 pr_debug("addr dev_idx=%u target_idx=%u protocol=%u\n", addr->dev_idx,
78808 addr->target_idx, addr->nfc_protocol);
78809 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78810 index c5c9e2a..4814ab1 100644
78811 --- a/net/packet/af_packet.c
78812 +++ b/net/packet/af_packet.c
78813 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78814
78815 spin_lock(&sk->sk_receive_queue.lock);
78816 po->stats.tp_packets++;
78817 - skb->dropcount = atomic_read(&sk->sk_drops);
78818 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78819 __skb_queue_tail(&sk->sk_receive_queue, skb);
78820 spin_unlock(&sk->sk_receive_queue.lock);
78821 sk->sk_data_ready(sk, skb->len);
78822 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78823 drop_n_acct:
78824 spin_lock(&sk->sk_receive_queue.lock);
78825 po->stats.tp_drops++;
78826 - atomic_inc(&sk->sk_drops);
78827 + atomic_inc_unchecked(&sk->sk_drops);
78828 spin_unlock(&sk->sk_receive_queue.lock);
78829
78830 drop_n_restore:
78831 @@ -2642,6 +2642,7 @@ out:
78832
78833 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78834 {
78835 + struct sock_extended_err ee;
78836 struct sock_exterr_skb *serr;
78837 struct sk_buff *skb, *skb2;
78838 int copied, err;
78839 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78840 sock_recv_timestamp(msg, sk, skb);
78841
78842 serr = SKB_EXT_ERR(skb);
78843 + ee = serr->ee;
78844 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78845 - sizeof(serr->ee), &serr->ee);
78846 + sizeof ee, &ee);
78847
78848 msg->msg_flags |= MSG_ERRQUEUE;
78849 err = copied;
78850 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78851 case PACKET_HDRLEN:
78852 if (len > sizeof(int))
78853 len = sizeof(int);
78854 - if (copy_from_user(&val, optval, len))
78855 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78856 return -EFAULT;
78857 switch (val) {
78858 case TPACKET_V1:
78859 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78860 len = lv;
78861 if (put_user(len, optlen))
78862 return -EFAULT;
78863 - if (copy_to_user(optval, data, len))
78864 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78865 return -EFAULT;
78866 return 0;
78867 }
78868 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78869 index 5a940db..f0b9c12 100644
78870 --- a/net/phonet/af_phonet.c
78871 +++ b/net/phonet/af_phonet.c
78872 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78873 {
78874 struct phonet_protocol *pp;
78875
78876 - if (protocol >= PHONET_NPROTO)
78877 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78878 return NULL;
78879
78880 rcu_read_lock();
78881 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78882 {
78883 int err = 0;
78884
78885 - if (protocol >= PHONET_NPROTO)
78886 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78887 return -EINVAL;
78888
78889 err = proto_register(pp->prot, 1);
78890 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78891 index 576f22c..bc7a71b 100644
78892 --- a/net/phonet/pep.c
78893 +++ b/net/phonet/pep.c
78894 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78895
78896 case PNS_PEP_CTRL_REQ:
78897 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78898 - atomic_inc(&sk->sk_drops);
78899 + atomic_inc_unchecked(&sk->sk_drops);
78900 break;
78901 }
78902 __skb_pull(skb, 4);
78903 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78904 }
78905
78906 if (pn->rx_credits == 0) {
78907 - atomic_inc(&sk->sk_drops);
78908 + atomic_inc_unchecked(&sk->sk_drops);
78909 err = -ENOBUFS;
78910 break;
78911 }
78912 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78913 }
78914
78915 if (pn->rx_credits == 0) {
78916 - atomic_inc(&sk->sk_drops);
78917 + atomic_inc_unchecked(&sk->sk_drops);
78918 err = NET_RX_DROP;
78919 break;
78920 }
78921 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78922 index 0acc943..c727611 100644
78923 --- a/net/phonet/socket.c
78924 +++ b/net/phonet/socket.c
78925 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78926 pn->resource, sk->sk_state,
78927 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78928 sock_i_uid(sk), sock_i_ino(sk),
78929 - atomic_read(&sk->sk_refcnt), sk,
78930 - atomic_read(&sk->sk_drops), &len);
78931 + atomic_read(&sk->sk_refcnt),
78932 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78933 + NULL,
78934 +#else
78935 + sk,
78936 +#endif
78937 + atomic_read_unchecked(&sk->sk_drops), &len);
78938 }
78939 seq_printf(seq, "%*s\n", 127 - len, "");
78940 return 0;
78941 diff --git a/net/rds/cong.c b/net/rds/cong.c
78942 index e5b65ac..f3b6fb7 100644
78943 --- a/net/rds/cong.c
78944 +++ b/net/rds/cong.c
78945 @@ -78,7 +78,7 @@
78946 * finds that the saved generation number is smaller than the global generation
78947 * number, it wakes up the process.
78948 */
78949 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78950 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78951
78952 /*
78953 * Congestion monitoring
78954 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78955 rdsdebug("waking map %p for %pI4\n",
78956 map, &map->m_addr);
78957 rds_stats_inc(s_cong_update_received);
78958 - atomic_inc(&rds_cong_generation);
78959 + atomic_inc_unchecked(&rds_cong_generation);
78960 if (waitqueue_active(&map->m_waitq))
78961 wake_up(&map->m_waitq);
78962 if (waitqueue_active(&rds_poll_waitq))
78963 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78964
78965 int rds_cong_updated_since(unsigned long *recent)
78966 {
78967 - unsigned long gen = atomic_read(&rds_cong_generation);
78968 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78969
78970 if (likely(*recent == gen))
78971 return 0;
78972 diff --git a/net/rds/ib.h b/net/rds/ib.h
78973 index 8d2b3d5..227ec5b 100644
78974 --- a/net/rds/ib.h
78975 +++ b/net/rds/ib.h
78976 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78977 /* sending acks */
78978 unsigned long i_ack_flags;
78979 #ifdef KERNEL_HAS_ATOMIC64
78980 - atomic64_t i_ack_next; /* next ACK to send */
78981 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78982 #else
78983 spinlock_t i_ack_lock; /* protect i_ack_next */
78984 u64 i_ack_next; /* next ACK to send */
78985 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78986 index a1e1162..265e129 100644
78987 --- a/net/rds/ib_cm.c
78988 +++ b/net/rds/ib_cm.c
78989 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78990 /* Clear the ACK state */
78991 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78992 #ifdef KERNEL_HAS_ATOMIC64
78993 - atomic64_set(&ic->i_ack_next, 0);
78994 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78995 #else
78996 ic->i_ack_next = 0;
78997 #endif
78998 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78999 index 8d19491..05a3e65 100644
79000 --- a/net/rds/ib_recv.c
79001 +++ b/net/rds/ib_recv.c
79002 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79003 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
79004 int ack_required)
79005 {
79006 - atomic64_set(&ic->i_ack_next, seq);
79007 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79008 if (ack_required) {
79009 smp_mb__before_clear_bit();
79010 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79011 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
79012 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79013 smp_mb__after_clear_bit();
79014
79015 - return atomic64_read(&ic->i_ack_next);
79016 + return atomic64_read_unchecked(&ic->i_ack_next);
79017 }
79018 #endif
79019
79020 diff --git a/net/rds/iw.h b/net/rds/iw.h
79021 index 04ce3b1..48119a6 100644
79022 --- a/net/rds/iw.h
79023 +++ b/net/rds/iw.h
79024 @@ -134,7 +134,7 @@ struct rds_iw_connection {
79025 /* sending acks */
79026 unsigned long i_ack_flags;
79027 #ifdef KERNEL_HAS_ATOMIC64
79028 - atomic64_t i_ack_next; /* next ACK to send */
79029 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
79030 #else
79031 spinlock_t i_ack_lock; /* protect i_ack_next */
79032 u64 i_ack_next; /* next ACK to send */
79033 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
79034 index a91e1db..cf3053f 100644
79035 --- a/net/rds/iw_cm.c
79036 +++ b/net/rds/iw_cm.c
79037 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
79038 /* Clear the ACK state */
79039 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
79040 #ifdef KERNEL_HAS_ATOMIC64
79041 - atomic64_set(&ic->i_ack_next, 0);
79042 + atomic64_set_unchecked(&ic->i_ack_next, 0);
79043 #else
79044 ic->i_ack_next = 0;
79045 #endif
79046 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
79047 index 4503335..db566b4 100644
79048 --- a/net/rds/iw_recv.c
79049 +++ b/net/rds/iw_recv.c
79050 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79051 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
79052 int ack_required)
79053 {
79054 - atomic64_set(&ic->i_ack_next, seq);
79055 + atomic64_set_unchecked(&ic->i_ack_next, seq);
79056 if (ack_required) {
79057 smp_mb__before_clear_bit();
79058 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79059 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
79060 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
79061 smp_mb__after_clear_bit();
79062
79063 - return atomic64_read(&ic->i_ack_next);
79064 + return atomic64_read_unchecked(&ic->i_ack_next);
79065 }
79066 #endif
79067
79068 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
79069 index edac9ef..16bcb98 100644
79070 --- a/net/rds/tcp.c
79071 +++ b/net/rds/tcp.c
79072 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
79073 int val = 1;
79074
79075 set_fs(KERNEL_DS);
79076 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
79077 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
79078 sizeof(val));
79079 set_fs(oldfs);
79080 }
79081 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
79082 index 1b4fd68..2234175 100644
79083 --- a/net/rds/tcp_send.c
79084 +++ b/net/rds/tcp_send.c
79085 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
79086
79087 oldfs = get_fs();
79088 set_fs(KERNEL_DS);
79089 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
79090 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
79091 sizeof(val));
79092 set_fs(oldfs);
79093 }
79094 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
79095 index 05996d0..5a1dfe0 100644
79096 --- a/net/rxrpc/af_rxrpc.c
79097 +++ b/net/rxrpc/af_rxrpc.c
79098 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
79099 __be32 rxrpc_epoch;
79100
79101 /* current debugging ID */
79102 -atomic_t rxrpc_debug_id;
79103 +atomic_unchecked_t rxrpc_debug_id;
79104
79105 /* count of skbs currently in use */
79106 atomic_t rxrpc_n_skbs;
79107 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
79108 index e4d9cbc..b229649 100644
79109 --- a/net/rxrpc/ar-ack.c
79110 +++ b/net/rxrpc/ar-ack.c
79111 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79112
79113 _enter("{%d,%d,%d,%d},",
79114 call->acks_hard, call->acks_unacked,
79115 - atomic_read(&call->sequence),
79116 + atomic_read_unchecked(&call->sequence),
79117 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
79118
79119 stop = 0;
79120 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
79121
79122 /* each Tx packet has a new serial number */
79123 sp->hdr.serial =
79124 - htonl(atomic_inc_return(&call->conn->serial));
79125 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
79126
79127 hdr = (struct rxrpc_header *) txb->head;
79128 hdr->serial = sp->hdr.serial;
79129 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
79130 */
79131 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
79132 {
79133 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
79134 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
79135 }
79136
79137 /*
79138 @@ -629,7 +629,7 @@ process_further:
79139
79140 latest = ntohl(sp->hdr.serial);
79141 hard = ntohl(ack.firstPacket);
79142 - tx = atomic_read(&call->sequence);
79143 + tx = atomic_read_unchecked(&call->sequence);
79144
79145 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79146 latest,
79147 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79148 goto maybe_reschedule;
79149
79150 send_ACK_with_skew:
79151 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79152 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79153 ntohl(ack.serial));
79154 send_ACK:
79155 mtu = call->conn->trans->peer->if_mtu;
79156 @@ -1173,7 +1173,7 @@ send_ACK:
79157 ackinfo.rxMTU = htonl(5692);
79158 ackinfo.jumbo_max = htonl(4);
79159
79160 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79161 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79162 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79163 ntohl(hdr.serial),
79164 ntohs(ack.maxSkew),
79165 @@ -1191,7 +1191,7 @@ send_ACK:
79166 send_message:
79167 _debug("send message");
79168
79169 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79170 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79171 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79172 send_message_2:
79173
79174 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79175 index a3bbb36..3341fb9 100644
79176 --- a/net/rxrpc/ar-call.c
79177 +++ b/net/rxrpc/ar-call.c
79178 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79179 spin_lock_init(&call->lock);
79180 rwlock_init(&call->state_lock);
79181 atomic_set(&call->usage, 1);
79182 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79183 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79184 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79185
79186 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79187 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79188 index 4106ca9..a338d7a 100644
79189 --- a/net/rxrpc/ar-connection.c
79190 +++ b/net/rxrpc/ar-connection.c
79191 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79192 rwlock_init(&conn->lock);
79193 spin_lock_init(&conn->state_lock);
79194 atomic_set(&conn->usage, 1);
79195 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79196 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79197 conn->avail_calls = RXRPC_MAXCALLS;
79198 conn->size_align = 4;
79199 conn->header_size = sizeof(struct rxrpc_header);
79200 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79201 index e7ed43a..6afa140 100644
79202 --- a/net/rxrpc/ar-connevent.c
79203 +++ b/net/rxrpc/ar-connevent.c
79204 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79205
79206 len = iov[0].iov_len + iov[1].iov_len;
79207
79208 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79209 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79210 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79211
79212 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79213 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79214 index 529572f..c758ca7 100644
79215 --- a/net/rxrpc/ar-input.c
79216 +++ b/net/rxrpc/ar-input.c
79217 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79218 /* track the latest serial number on this connection for ACK packet
79219 * information */
79220 serial = ntohl(sp->hdr.serial);
79221 - hi_serial = atomic_read(&call->conn->hi_serial);
79222 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79223 while (serial > hi_serial)
79224 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79225 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79226 serial);
79227
79228 /* request ACK generation for any ACK or DATA packet that requests
79229 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79230 index a693aca..81e7293 100644
79231 --- a/net/rxrpc/ar-internal.h
79232 +++ b/net/rxrpc/ar-internal.h
79233 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79234 int error; /* error code for local abort */
79235 int debug_id; /* debug ID for printks */
79236 unsigned int call_counter; /* call ID counter */
79237 - atomic_t serial; /* packet serial number counter */
79238 - atomic_t hi_serial; /* highest serial number received */
79239 + atomic_unchecked_t serial; /* packet serial number counter */
79240 + atomic_unchecked_t hi_serial; /* highest serial number received */
79241 u8 avail_calls; /* number of calls available */
79242 u8 size_align; /* data size alignment (for security) */
79243 u8 header_size; /* rxrpc + security header size */
79244 @@ -346,7 +346,7 @@ struct rxrpc_call {
79245 spinlock_t lock;
79246 rwlock_t state_lock; /* lock for state transition */
79247 atomic_t usage;
79248 - atomic_t sequence; /* Tx data packet sequence counter */
79249 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79250 u32 abort_code; /* local/remote abort code */
79251 enum { /* current state of call */
79252 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79253 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79254 */
79255 extern atomic_t rxrpc_n_skbs;
79256 extern __be32 rxrpc_epoch;
79257 -extern atomic_t rxrpc_debug_id;
79258 +extern atomic_unchecked_t rxrpc_debug_id;
79259 extern struct workqueue_struct *rxrpc_workqueue;
79260
79261 /*
79262 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79263 index 87f7135..74d3703 100644
79264 --- a/net/rxrpc/ar-local.c
79265 +++ b/net/rxrpc/ar-local.c
79266 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79267 spin_lock_init(&local->lock);
79268 rwlock_init(&local->services_lock);
79269 atomic_set(&local->usage, 1);
79270 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79271 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79272 memcpy(&local->srx, srx, sizeof(*srx));
79273 }
79274
79275 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79276 index e1ac183..b43e10e 100644
79277 --- a/net/rxrpc/ar-output.c
79278 +++ b/net/rxrpc/ar-output.c
79279 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79280 sp->hdr.cid = call->cid;
79281 sp->hdr.callNumber = call->call_id;
79282 sp->hdr.seq =
79283 - htonl(atomic_inc_return(&call->sequence));
79284 + htonl(atomic_inc_return_unchecked(&call->sequence));
79285 sp->hdr.serial =
79286 - htonl(atomic_inc_return(&conn->serial));
79287 + htonl(atomic_inc_return_unchecked(&conn->serial));
79288 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79289 sp->hdr.userStatus = 0;
79290 sp->hdr.securityIndex = conn->security_ix;
79291 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79292 index bebaa43..2644591 100644
79293 --- a/net/rxrpc/ar-peer.c
79294 +++ b/net/rxrpc/ar-peer.c
79295 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79296 INIT_LIST_HEAD(&peer->error_targets);
79297 spin_lock_init(&peer->lock);
79298 atomic_set(&peer->usage, 1);
79299 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79300 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79301 memcpy(&peer->srx, srx, sizeof(*srx));
79302
79303 rxrpc_assess_MTU_size(peer);
79304 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79305 index 38047f7..9f48511 100644
79306 --- a/net/rxrpc/ar-proc.c
79307 +++ b/net/rxrpc/ar-proc.c
79308 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79309 atomic_read(&conn->usage),
79310 rxrpc_conn_states[conn->state],
79311 key_serial(conn->key),
79312 - atomic_read(&conn->serial),
79313 - atomic_read(&conn->hi_serial));
79314 + atomic_read_unchecked(&conn->serial),
79315 + atomic_read_unchecked(&conn->hi_serial));
79316
79317 return 0;
79318 }
79319 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79320 index 92df566..87ec1bf 100644
79321 --- a/net/rxrpc/ar-transport.c
79322 +++ b/net/rxrpc/ar-transport.c
79323 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79324 spin_lock_init(&trans->client_lock);
79325 rwlock_init(&trans->conn_lock);
79326 atomic_set(&trans->usage, 1);
79327 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79328 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79329
79330 if (peer->srx.transport.family == AF_INET) {
79331 switch (peer->srx.transport_type) {
79332 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79333 index f226709..0e735a8 100644
79334 --- a/net/rxrpc/rxkad.c
79335 +++ b/net/rxrpc/rxkad.c
79336 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79337
79338 len = iov[0].iov_len + iov[1].iov_len;
79339
79340 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79341 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79342 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79343
79344 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79345 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79346
79347 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79348
79349 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79350 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79351 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79352
79353 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79354 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79355 index 1e2eee8..ce3967e 100644
79356 --- a/net/sctp/proc.c
79357 +++ b/net/sctp/proc.c
79358 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79359 seq_printf(seq,
79360 "%8pK %8pK %-3d %-3d %-2d %-4d "
79361 "%4d %8d %8d %7d %5lu %-5d %5d ",
79362 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79363 + assoc, sk,
79364 + sctp_sk(sk)->type, sk->sk_state,
79365 assoc->state, hash,
79366 assoc->assoc_id,
79367 assoc->sndbuf_used,
79368 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79369 index 5e25981..dbda919 100644
79370 --- a/net/sctp/socket.c
79371 +++ b/net/sctp/socket.c
79372 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79373 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79374 if (space_left < addrlen)
79375 return -ENOMEM;
79376 + if (addrlen > sizeof(temp) || addrlen < 0)
79377 + return -EFAULT;
79378 if (copy_to_user(to, &temp, addrlen))
79379 return -EFAULT;
79380 to += addrlen;
79381 diff --git a/net/socket.c b/net/socket.c
79382 index edc3c4a..4b4e4a8 100644
79383 --- a/net/socket.c
79384 +++ b/net/socket.c
79385 @@ -88,6 +88,7 @@
79386 #include <linux/nsproxy.h>
79387 #include <linux/magic.h>
79388 #include <linux/slab.h>
79389 +#include <linux/in.h>
79390
79391 #include <asm/uaccess.h>
79392 #include <asm/unistd.h>
79393 @@ -105,6 +106,8 @@
79394 #include <linux/sockios.h>
79395 #include <linux/atalk.h>
79396
79397 +#include <linux/grsock.h>
79398 +
79399 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79400 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79401 unsigned long nr_segs, loff_t pos);
79402 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79403 &sockfs_dentry_operations, SOCKFS_MAGIC);
79404 }
79405
79406 -static struct vfsmount *sock_mnt __read_mostly;
79407 +struct vfsmount *sock_mnt __read_mostly;
79408
79409 static struct file_system_type sock_fs_type = {
79410 .name = "sockfs",
79411 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79412 return -EAFNOSUPPORT;
79413 if (type < 0 || type >= SOCK_MAX)
79414 return -EINVAL;
79415 + if (protocol < 0)
79416 + return -EINVAL;
79417
79418 /* Compatibility.
79419
79420 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79421 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79422 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79423
79424 + if(!gr_search_socket(family, type, protocol)) {
79425 + retval = -EACCES;
79426 + goto out;
79427 + }
79428 +
79429 + if (gr_handle_sock_all(family, type, protocol)) {
79430 + retval = -EACCES;
79431 + goto out;
79432 + }
79433 +
79434 retval = sock_create(family, type, protocol, &sock);
79435 if (retval < 0)
79436 goto out;
79437 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79438 if (sock) {
79439 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79440 if (err >= 0) {
79441 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79442 + err = -EACCES;
79443 + goto error;
79444 + }
79445 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79446 + if (err)
79447 + goto error;
79448 +
79449 err = security_socket_bind(sock,
79450 (struct sockaddr *)&address,
79451 addrlen);
79452 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79453 (struct sockaddr *)
79454 &address, addrlen);
79455 }
79456 +error:
79457 fput_light(sock->file, fput_needed);
79458 }
79459 return err;
79460 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79461 if ((unsigned int)backlog > somaxconn)
79462 backlog = somaxconn;
79463
79464 + if (gr_handle_sock_server_other(sock->sk)) {
79465 + err = -EPERM;
79466 + goto error;
79467 + }
79468 +
79469 + err = gr_search_listen(sock);
79470 + if (err)
79471 + goto error;
79472 +
79473 err = security_socket_listen(sock, backlog);
79474 if (!err)
79475 err = sock->ops->listen(sock, backlog);
79476
79477 +error:
79478 fput_light(sock->file, fput_needed);
79479 }
79480 return err;
79481 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79482 newsock->type = sock->type;
79483 newsock->ops = sock->ops;
79484
79485 + if (gr_handle_sock_server_other(sock->sk)) {
79486 + err = -EPERM;
79487 + sock_release(newsock);
79488 + goto out_put;
79489 + }
79490 +
79491 + err = gr_search_accept(sock);
79492 + if (err) {
79493 + sock_release(newsock);
79494 + goto out_put;
79495 + }
79496 +
79497 /*
79498 * We don't need try_module_get here, as the listening socket (sock)
79499 * has the protocol module (sock->ops->owner) held.
79500 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79501 fd_install(newfd, newfile);
79502 err = newfd;
79503
79504 + gr_attach_curr_ip(newsock->sk);
79505 +
79506 out_put:
79507 fput_light(sock->file, fput_needed);
79508 out:
79509 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79510 int, addrlen)
79511 {
79512 struct socket *sock;
79513 + struct sockaddr *sck;
79514 struct sockaddr_storage address;
79515 int err, fput_needed;
79516
79517 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79518 if (err < 0)
79519 goto out_put;
79520
79521 + sck = (struct sockaddr *)&address;
79522 +
79523 + if (gr_handle_sock_client(sck)) {
79524 + err = -EACCES;
79525 + goto out_put;
79526 + }
79527 +
79528 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79529 + if (err)
79530 + goto out_put;
79531 +
79532 err =
79533 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79534 if (err)
79535 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79536 * checking falls down on this.
79537 */
79538 if (copy_from_user(ctl_buf,
79539 - (void __user __force *)msg_sys->msg_control,
79540 + (void __force_user *)msg_sys->msg_control,
79541 ctl_len))
79542 goto out_freectl;
79543 msg_sys->msg_control = ctl_buf;
79544 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79545 * kernel msghdr to use the kernel address space)
79546 */
79547
79548 - uaddr = (__force void __user *)msg_sys->msg_name;
79549 + uaddr = (void __force_user *)msg_sys->msg_name;
79550 uaddr_len = COMPAT_NAMELEN(msg);
79551 if (MSG_CMSG_COMPAT & flags) {
79552 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79553 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79554 }
79555
79556 ifr = compat_alloc_user_space(buf_size);
79557 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79558 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79559
79560 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79561 return -EFAULT;
79562 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79563 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79564
79565 if (copy_in_user(rxnfc, compat_rxnfc,
79566 - (void *)(&rxnfc->fs.m_ext + 1) -
79567 - (void *)rxnfc) ||
79568 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79569 + (void __user *)rxnfc) ||
79570 copy_in_user(&rxnfc->fs.ring_cookie,
79571 &compat_rxnfc->fs.ring_cookie,
79572 - (void *)(&rxnfc->fs.location + 1) -
79573 - (void *)&rxnfc->fs.ring_cookie) ||
79574 + (void __user *)(&rxnfc->fs.location + 1) -
79575 + (void __user *)&rxnfc->fs.ring_cookie) ||
79576 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79577 sizeof(rxnfc->rule_cnt)))
79578 return -EFAULT;
79579 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79580
79581 if (convert_out) {
79582 if (copy_in_user(compat_rxnfc, rxnfc,
79583 - (const void *)(&rxnfc->fs.m_ext + 1) -
79584 - (const void *)rxnfc) ||
79585 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79586 + (const void __user *)rxnfc) ||
79587 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79588 &rxnfc->fs.ring_cookie,
79589 - (const void *)(&rxnfc->fs.location + 1) -
79590 - (const void *)&rxnfc->fs.ring_cookie) ||
79591 + (const void __user *)(&rxnfc->fs.location + 1) -
79592 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79593 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79594 sizeof(rxnfc->rule_cnt)))
79595 return -EFAULT;
79596 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79597 old_fs = get_fs();
79598 set_fs(KERNEL_DS);
79599 err = dev_ioctl(net, cmd,
79600 - (struct ifreq __user __force *) &kifr);
79601 + (struct ifreq __force_user *) &kifr);
79602 set_fs(old_fs);
79603
79604 return err;
79605 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79606
79607 old_fs = get_fs();
79608 set_fs(KERNEL_DS);
79609 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79610 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79611 set_fs(old_fs);
79612
79613 if (cmd == SIOCGIFMAP && !err) {
79614 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79615 ret |= __get_user(rtdev, &(ur4->rt_dev));
79616 if (rtdev) {
79617 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79618 - r4.rt_dev = (char __user __force *)devname;
79619 + r4.rt_dev = (char __force_user *)devname;
79620 devname[15] = 0;
79621 } else
79622 r4.rt_dev = NULL;
79623 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79624 int __user *uoptlen;
79625 int err;
79626
79627 - uoptval = (char __user __force *) optval;
79628 - uoptlen = (int __user __force *) optlen;
79629 + uoptval = (char __force_user *) optval;
79630 + uoptlen = (int __force_user *) optlen;
79631
79632 set_fs(KERNEL_DS);
79633 if (level == SOL_SOCKET)
79634 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79635 char __user *uoptval;
79636 int err;
79637
79638 - uoptval = (char __user __force *) optval;
79639 + uoptval = (char __force_user *) optval;
79640
79641 set_fs(KERNEL_DS);
79642 if (level == SOL_SOCKET)
79643 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79644 index 128494e..775d0e0 100644
79645 --- a/net/sunrpc/sched.c
79646 +++ b/net/sunrpc/sched.c
79647 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79648 #ifdef RPC_DEBUG
79649 static void rpc_task_set_debuginfo(struct rpc_task *task)
79650 {
79651 - static atomic_t rpc_pid;
79652 + static atomic_unchecked_t rpc_pid;
79653
79654 - task->tk_pid = atomic_inc_return(&rpc_pid);
79655 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79656 }
79657 #else
79658 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79659 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79660 index 8343737..677025e 100644
79661 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79662 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79663 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79664 static unsigned int min_max_inline = 4096;
79665 static unsigned int max_max_inline = 65536;
79666
79667 -atomic_t rdma_stat_recv;
79668 -atomic_t rdma_stat_read;
79669 -atomic_t rdma_stat_write;
79670 -atomic_t rdma_stat_sq_starve;
79671 -atomic_t rdma_stat_rq_starve;
79672 -atomic_t rdma_stat_rq_poll;
79673 -atomic_t rdma_stat_rq_prod;
79674 -atomic_t rdma_stat_sq_poll;
79675 -atomic_t rdma_stat_sq_prod;
79676 +atomic_unchecked_t rdma_stat_recv;
79677 +atomic_unchecked_t rdma_stat_read;
79678 +atomic_unchecked_t rdma_stat_write;
79679 +atomic_unchecked_t rdma_stat_sq_starve;
79680 +atomic_unchecked_t rdma_stat_rq_starve;
79681 +atomic_unchecked_t rdma_stat_rq_poll;
79682 +atomic_unchecked_t rdma_stat_rq_prod;
79683 +atomic_unchecked_t rdma_stat_sq_poll;
79684 +atomic_unchecked_t rdma_stat_sq_prod;
79685
79686 /* Temporary NFS request map and context caches */
79687 struct kmem_cache *svc_rdma_map_cachep;
79688 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79689 len -= *ppos;
79690 if (len > *lenp)
79691 len = *lenp;
79692 - if (len && copy_to_user(buffer, str_buf, len))
79693 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79694 return -EFAULT;
79695 *lenp = len;
79696 *ppos += len;
79697 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79698 {
79699 .procname = "rdma_stat_read",
79700 .data = &rdma_stat_read,
79701 - .maxlen = sizeof(atomic_t),
79702 + .maxlen = sizeof(atomic_unchecked_t),
79703 .mode = 0644,
79704 .proc_handler = read_reset_stat,
79705 },
79706 {
79707 .procname = "rdma_stat_recv",
79708 .data = &rdma_stat_recv,
79709 - .maxlen = sizeof(atomic_t),
79710 + .maxlen = sizeof(atomic_unchecked_t),
79711 .mode = 0644,
79712 .proc_handler = read_reset_stat,
79713 },
79714 {
79715 .procname = "rdma_stat_write",
79716 .data = &rdma_stat_write,
79717 - .maxlen = sizeof(atomic_t),
79718 + .maxlen = sizeof(atomic_unchecked_t),
79719 .mode = 0644,
79720 .proc_handler = read_reset_stat,
79721 },
79722 {
79723 .procname = "rdma_stat_sq_starve",
79724 .data = &rdma_stat_sq_starve,
79725 - .maxlen = sizeof(atomic_t),
79726 + .maxlen = sizeof(atomic_unchecked_t),
79727 .mode = 0644,
79728 .proc_handler = read_reset_stat,
79729 },
79730 {
79731 .procname = "rdma_stat_rq_starve",
79732 .data = &rdma_stat_rq_starve,
79733 - .maxlen = sizeof(atomic_t),
79734 + .maxlen = sizeof(atomic_unchecked_t),
79735 .mode = 0644,
79736 .proc_handler = read_reset_stat,
79737 },
79738 {
79739 .procname = "rdma_stat_rq_poll",
79740 .data = &rdma_stat_rq_poll,
79741 - .maxlen = sizeof(atomic_t),
79742 + .maxlen = sizeof(atomic_unchecked_t),
79743 .mode = 0644,
79744 .proc_handler = read_reset_stat,
79745 },
79746 {
79747 .procname = "rdma_stat_rq_prod",
79748 .data = &rdma_stat_rq_prod,
79749 - .maxlen = sizeof(atomic_t),
79750 + .maxlen = sizeof(atomic_unchecked_t),
79751 .mode = 0644,
79752 .proc_handler = read_reset_stat,
79753 },
79754 {
79755 .procname = "rdma_stat_sq_poll",
79756 .data = &rdma_stat_sq_poll,
79757 - .maxlen = sizeof(atomic_t),
79758 + .maxlen = sizeof(atomic_unchecked_t),
79759 .mode = 0644,
79760 .proc_handler = read_reset_stat,
79761 },
79762 {
79763 .procname = "rdma_stat_sq_prod",
79764 .data = &rdma_stat_sq_prod,
79765 - .maxlen = sizeof(atomic_t),
79766 + .maxlen = sizeof(atomic_unchecked_t),
79767 .mode = 0644,
79768 .proc_handler = read_reset_stat,
79769 },
79770 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79771 index 41cb63b..c4a1489 100644
79772 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79773 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79774 @@ -501,7 +501,7 @@ next_sge:
79775 svc_rdma_put_context(ctxt, 0);
79776 goto out;
79777 }
79778 - atomic_inc(&rdma_stat_read);
79779 + atomic_inc_unchecked(&rdma_stat_read);
79780
79781 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79782 chl_map->ch[ch_no].count -= read_wr.num_sge;
79783 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79784 dto_q);
79785 list_del_init(&ctxt->dto_q);
79786 } else {
79787 - atomic_inc(&rdma_stat_rq_starve);
79788 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79789 clear_bit(XPT_DATA, &xprt->xpt_flags);
79790 ctxt = NULL;
79791 }
79792 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79793 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79794 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79795 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79796 - atomic_inc(&rdma_stat_recv);
79797 + atomic_inc_unchecked(&rdma_stat_recv);
79798
79799 /* Build up the XDR from the receive buffers. */
79800 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79801 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79802 index 42eb7ba..c887c45 100644
79803 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79804 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79805 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79806 write_wr.wr.rdma.remote_addr = to;
79807
79808 /* Post It */
79809 - atomic_inc(&rdma_stat_write);
79810 + atomic_inc_unchecked(&rdma_stat_write);
79811 if (svc_rdma_send(xprt, &write_wr))
79812 goto err;
79813 return 0;
79814 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79815 index 73b428b..5f3f8f3 100644
79816 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79817 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79818 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79819 return;
79820
79821 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79822 - atomic_inc(&rdma_stat_rq_poll);
79823 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79824
79825 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79826 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79827 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79828 }
79829
79830 if (ctxt)
79831 - atomic_inc(&rdma_stat_rq_prod);
79832 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79833
79834 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79835 /*
79836 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79837 return;
79838
79839 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79840 - atomic_inc(&rdma_stat_sq_poll);
79841 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79842 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79843 if (wc.status != IB_WC_SUCCESS)
79844 /* Close the transport */
79845 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79846 }
79847
79848 if (ctxt)
79849 - atomic_inc(&rdma_stat_sq_prod);
79850 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79851 }
79852
79853 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79854 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79855 spin_lock_bh(&xprt->sc_lock);
79856 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79857 spin_unlock_bh(&xprt->sc_lock);
79858 - atomic_inc(&rdma_stat_sq_starve);
79859 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79860
79861 /* See if we can opportunistically reap SQ WR to make room */
79862 sq_cq_reap(xprt);
79863 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79864 index e3a6e37..be2ea77 100644
79865 --- a/net/sysctl_net.c
79866 +++ b/net/sysctl_net.c
79867 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79868 struct ctl_table *table)
79869 {
79870 /* Allow network administrator to have same access as root. */
79871 - if (capable(CAP_NET_ADMIN)) {
79872 + if (capable_nolog(CAP_NET_ADMIN)) {
79873 int mode = (table->mode >> 6) & 7;
79874 return (mode << 6) | (mode << 3) | mode;
79875 }
79876 diff --git a/net/tipc/link.c b/net/tipc/link.c
79877 index 1c1e615..113e0ae 100644
79878 --- a/net/tipc/link.c
79879 +++ b/net/tipc/link.c
79880 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79881 struct tipc_msg fragm_hdr;
79882 struct sk_buff *buf, *buf_chain, *prev;
79883 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79884 - const unchar *sect_crs;
79885 + const unchar __user *sect_crs;
79886 int curr_sect;
79887 u32 fragm_no;
79888
79889 @@ -1212,7 +1212,7 @@ again:
79890
79891 if (!sect_rest) {
79892 sect_rest = msg_sect[++curr_sect].iov_len;
79893 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79894 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79895 }
79896
79897 if (sect_rest < fragm_rest)
79898 @@ -1231,7 +1231,7 @@ error:
79899 }
79900 } else
79901 skb_copy_to_linear_data_offset(buf, fragm_crs,
79902 - sect_crs, sz);
79903 + (const void __force_kernel *)sect_crs, sz);
79904 sect_crs += sz;
79905 sect_rest -= sz;
79906 fragm_crs += sz;
79907 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79908 index f2db8a8..9245aa4 100644
79909 --- a/net/tipc/msg.c
79910 +++ b/net/tipc/msg.c
79911 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79912 msg_sect[cnt].iov_len);
79913 else
79914 skb_copy_to_linear_data_offset(*buf, pos,
79915 - msg_sect[cnt].iov_base,
79916 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79917 msg_sect[cnt].iov_len);
79918 pos += msg_sect[cnt].iov_len;
79919 }
79920 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79921 index 5ed5965..90abe34 100644
79922 --- a/net/tipc/subscr.c
79923 +++ b/net/tipc/subscr.c
79924 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79925 {
79926 struct iovec msg_sect;
79927
79928 - msg_sect.iov_base = (void *)&sub->evt;
79929 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79930 msg_sect.iov_len = sizeof(struct tipc_event);
79931
79932 sub->evt.event = htohl(event, sub->swap);
79933 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79934 index c5ee4ff..e905948 100644
79935 --- a/net/unix/af_unix.c
79936 +++ b/net/unix/af_unix.c
79937 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79938 err = -ECONNREFUSED;
79939 if (!S_ISSOCK(inode->i_mode))
79940 goto put_fail;
79941 +
79942 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79943 + err = -EACCES;
79944 + goto put_fail;
79945 + }
79946 +
79947 u = unix_find_socket_byinode(inode);
79948 if (!u)
79949 goto put_fail;
79950 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79951 if (u) {
79952 struct dentry *dentry;
79953 dentry = unix_sk(u)->path.dentry;
79954 +
79955 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79956 + err = -EPERM;
79957 + sock_put(u);
79958 + goto fail;
79959 + }
79960 +
79961 if (dentry)
79962 touch_atime(&unix_sk(u)->path);
79963 } else
79964 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79965 */
79966 err = security_path_mknod(&path, dentry, mode, 0);
79967 if (!err) {
79968 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79969 + err = -EACCES;
79970 + goto out;
79971 + }
79972 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79973 if (!err) {
79974 res->mnt = mntget(path.mnt);
79975 res->dentry = dget(dentry);
79976 + gr_handle_create(dentry, path.mnt);
79977 }
79978 }
79979 +out:
79980 done_path_create(&path, dentry);
79981 return err;
79982 }
79983 diff --git a/net/wireless/core.h b/net/wireless/core.h
79984 index bc7430b..35349de 100644
79985 --- a/net/wireless/core.h
79986 +++ b/net/wireless/core.h
79987 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79988 struct mutex mtx;
79989
79990 /* rfkill support */
79991 - struct rfkill_ops rfkill_ops;
79992 + rfkill_ops_no_const rfkill_ops;
79993 struct rfkill *rfkill;
79994 struct work_struct rfkill_sync;
79995
79996 diff --git a/net/wireless/util.c b/net/wireless/util.c
79997 index 994e2f0..f67aeb1 100644
79998 --- a/net/wireless/util.c
79999 +++ b/net/wireless/util.c
80000 @@ -309,7 +309,7 @@ unsigned int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
80001 }
80002 EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
80003
80004 -static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
80005 +unsigned int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
80006 {
80007 int ae = meshhdr->flags & MESH_FLAGS_AE;
80008 /* 7.1.3.5a.2 */
80009 @@ -326,6 +326,7 @@ static int ieee80211_get_mesh_hdrlen(struct ieee80211s_hdr *meshhdr)
80010 return 6;
80011 }
80012 }
80013 +EXPORT_SYMBOL(ieee80211_get_mesh_hdrlen);
80014
80015 int ieee80211_data_to_8023(struct sk_buff *skb, const u8 *addr,
80016 enum nl80211_iftype iftype)
80017 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
80018 index b0eb7aa..7d73e82 100644
80019 --- a/net/wireless/wext-core.c
80020 +++ b/net/wireless/wext-core.c
80021 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80022 */
80023
80024 /* Support for very large requests */
80025 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
80026 - (user_length > descr->max_tokens)) {
80027 + if (user_length > descr->max_tokens) {
80028 /* Allow userspace to GET more than max so
80029 * we can support any size GET requests.
80030 * There is still a limit : -ENOMEM.
80031 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
80032 }
80033 }
80034
80035 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
80036 - /*
80037 - * If this is a GET, but not NOMAX, it means that the extra
80038 - * data is not bounded by userspace, but by max_tokens. Thus
80039 - * set the length to max_tokens. This matches the extra data
80040 - * allocation.
80041 - * The driver should fill it with the number of tokens it
80042 - * provided, and it may check iwp->length rather than having
80043 - * knowledge of max_tokens. If the driver doesn't change the
80044 - * iwp->length, this ioctl just copies back max_token tokens
80045 - * filled with zeroes. Hopefully the driver isn't claiming
80046 - * them to be valid data.
80047 - */
80048 - iwp->length = descr->max_tokens;
80049 - }
80050 -
80051 err = handler(dev, info, (union iwreq_data *) iwp, extra);
80052
80053 iwp->length += essid_compat;
80054 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
80055 index 387848e..a6667a2 100644
80056 --- a/net/xfrm/xfrm_policy.c
80057 +++ b/net/xfrm/xfrm_policy.c
80058 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
80059 {
80060 policy->walk.dead = 1;
80061
80062 - atomic_inc(&policy->genid);
80063 + atomic_inc_unchecked(&policy->genid);
80064
80065 if (del_timer(&policy->timer))
80066 xfrm_pol_put(policy);
80067 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
80068 hlist_add_head(&policy->bydst, chain);
80069 xfrm_pol_hold(policy);
80070 net->xfrm.policy_count[dir]++;
80071 - atomic_inc(&flow_cache_genid);
80072 + atomic_inc_unchecked(&flow_cache_genid);
80073 rt_genid_bump(net);
80074 if (delpol)
80075 __xfrm_policy_unlink(delpol, dir);
80076 @@ -1533,7 +1533,7 @@ free_dst:
80077 goto out;
80078 }
80079
80080 -static int inline
80081 +static inline int
80082 xfrm_dst_alloc_copy(void **target, const void *src, int size)
80083 {
80084 if (!*target) {
80085 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
80086 return 0;
80087 }
80088
80089 -static int inline
80090 +static inline int
80091 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80092 {
80093 #ifdef CONFIG_XFRM_SUB_POLICY
80094 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
80095 #endif
80096 }
80097
80098 -static int inline
80099 +static inline int
80100 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
80101 {
80102 #ifdef CONFIG_XFRM_SUB_POLICY
80103 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
80104
80105 xdst->num_pols = num_pols;
80106 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
80107 - xdst->policy_genid = atomic_read(&pols[0]->genid);
80108 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
80109
80110 return xdst;
80111 }
80112 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
80113 if (xdst->xfrm_genid != dst->xfrm->genid)
80114 return 0;
80115 if (xdst->num_pols > 0 &&
80116 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
80117 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
80118 return 0;
80119
80120 mtu = dst_mtu(dst->child);
80121 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
80122 sizeof(pol->xfrm_vec[i].saddr));
80123 pol->xfrm_vec[i].encap_family = mp->new_family;
80124 /* flush bundles */
80125 - atomic_inc(&pol->genid);
80126 + atomic_inc_unchecked(&pol->genid);
80127 }
80128 }
80129
80130 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80131 index ff1720d..ed8475e 100644
80132 --- a/scripts/Makefile.build
80133 +++ b/scripts/Makefile.build
80134 @@ -111,7 +111,7 @@ endif
80135 endif
80136
80137 # Do not include host rules unless needed
80138 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80139 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80140 include scripts/Makefile.host
80141 endif
80142
80143 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80144 index 686cb0d..9d653bf 100644
80145 --- a/scripts/Makefile.clean
80146 +++ b/scripts/Makefile.clean
80147 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80148 __clean-files := $(extra-y) $(always) \
80149 $(targets) $(clean-files) \
80150 $(host-progs) \
80151 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80152 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80153 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80154
80155 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80156
80157 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80158 index 1ac414f..38575f7 100644
80159 --- a/scripts/Makefile.host
80160 +++ b/scripts/Makefile.host
80161 @@ -31,6 +31,8 @@
80162 # Note: Shared libraries consisting of C++ files are not supported
80163
80164 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80165 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80166 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80167
80168 # C code
80169 # Executables compiled from a single .c file
80170 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80171 # Shared libaries (only .c supported)
80172 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80173 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80174 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80175 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80176 # Remove .so files from "xxx-objs"
80177 host-cobjs := $(filter-out %.so,$(host-cobjs))
80178 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80179
80180 -#Object (.o) files used by the shared libaries
80181 +# Object (.o) files used by the shared libaries
80182 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80183 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80184
80185 # output directory for programs/.o files
80186 # hostprogs-y := tools/build may have been specified. Retrieve directory
80187 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80188 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80189 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80190 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80191 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80192 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80193 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80194 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80195
80196 obj-dirs += $(host-objdirs)
80197 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80198 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80199 $(call if_changed_dep,host-cshobjs)
80200
80201 +# Compile .c file, create position independent .o file
80202 +# host-cxxshobjs -> .o
80203 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80204 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80205 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80206 + $(call if_changed_dep,host-cxxshobjs)
80207 +
80208 # Link a shared library, based on position independent .o files
80209 # *.o -> .so shared library (host-cshlib)
80210 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80211 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80212 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80213 $(call if_changed,host-cshlib)
80214
80215 +# Link a shared library, based on position independent .o files
80216 +# *.o -> .so shared library (host-cxxshlib)
80217 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80218 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80219 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80220 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80221 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80222 + $(call if_changed,host-cxxshlib)
80223 +
80224 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80225 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80226 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80227
80228 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80229 index cb1f50c..cef2a7c 100644
80230 --- a/scripts/basic/fixdep.c
80231 +++ b/scripts/basic/fixdep.c
80232 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80233 /*
80234 * Lookup a value in the configuration string.
80235 */
80236 -static int is_defined_config(const char *name, int len, unsigned int hash)
80237 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80238 {
80239 struct item *aux;
80240
80241 @@ -211,10 +211,10 @@ static void clear_config(void)
80242 /*
80243 * Record the use of a CONFIG_* word.
80244 */
80245 -static void use_config(const char *m, int slen)
80246 +static void use_config(const char *m, unsigned int slen)
80247 {
80248 unsigned int hash = strhash(m, slen);
80249 - int c, i;
80250 + unsigned int c, i;
80251
80252 if (is_defined_config(m, slen, hash))
80253 return;
80254 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80255
80256 static void parse_config_file(const char *map, size_t len)
80257 {
80258 - const int *end = (const int *) (map + len);
80259 + const unsigned int *end = (const unsigned int *) (map + len);
80260 /* start at +1, so that p can never be < map */
80261 - const int *m = (const int *) map + 1;
80262 + const unsigned int *m = (const unsigned int *) map + 1;
80263 const char *p, *q;
80264
80265 for (; m < end; m++) {
80266 @@ -406,7 +406,7 @@ static void print_deps(void)
80267 static void traps(void)
80268 {
80269 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80270 - int *p = (int *)test;
80271 + unsigned int *p = (unsigned int *)test;
80272
80273 if (*p != INT_CONF) {
80274 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80275 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80276 new file mode 100644
80277 index 0000000..008ac1a
80278 --- /dev/null
80279 +++ b/scripts/gcc-plugin.sh
80280 @@ -0,0 +1,17 @@
80281 +#!/bin/bash
80282 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80283 +#include "gcc-plugin.h"
80284 +#include "tree.h"
80285 +#include "tm.h"
80286 +#include "rtl.h"
80287 +#ifdef ENABLE_BUILD_WITH_CXX
80288 +#warning $2
80289 +#else
80290 +#warning $1
80291 +#endif
80292 +EOF`
80293 +if [ $? -eq 0 ]
80294 +then
80295 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80296 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80297 +fi
80298 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80299 index b3d907e..a4782ab 100644
80300 --- a/scripts/link-vmlinux.sh
80301 +++ b/scripts/link-vmlinux.sh
80302 @@ -152,7 +152,7 @@ else
80303 fi;
80304
80305 # final build of init/
80306 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80307 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80308
80309 kallsymso=""
80310 kallsyms_vmlinux=""
80311 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80312 index 7ed6864..b6e90e6 100644
80313 --- a/scripts/mod/file2alias.c
80314 +++ b/scripts/mod/file2alias.c
80315 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80316 unsigned long size, unsigned long id_size,
80317 void *symval)
80318 {
80319 - int i;
80320 + unsigned int i;
80321
80322 if (size % id_size || size < id_size) {
80323 if (cross_build != 0)
80324 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80325 /* USB is special because the bcdDevice can be matched against a numeric range */
80326 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
80327 static void do_usb_entry(struct usb_device_id *id,
80328 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80329 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80330 unsigned char range_lo, unsigned char range_hi,
80331 unsigned char max, struct module *mod)
80332 {
80333 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80334 {
80335 unsigned int devlo, devhi;
80336 unsigned char chi, clo, max;
80337 - int ndigits;
80338 + unsigned int ndigits;
80339
80340 id->match_flags = TO_NATIVE(id->match_flags);
80341 id->idVendor = TO_NATIVE(id->idVendor);
80342 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80343 for (i = 0; i < count; i++) {
80344 const char *id = (char *)devs[i].id;
80345 char acpi_id[sizeof(devs[0].id)];
80346 - int j;
80347 + unsigned int j;
80348
80349 buf_printf(&mod->dev_table_buf,
80350 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80351 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80352
80353 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80354 const char *id = (char *)card->devs[j].id;
80355 - int i2, j2;
80356 + unsigned int i2, j2;
80357 int dup = 0;
80358
80359 if (!id[0])
80360 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80361 /* add an individual alias for every device entry */
80362 if (!dup) {
80363 char acpi_id[sizeof(card->devs[0].id)];
80364 - int k;
80365 + unsigned int k;
80366
80367 buf_printf(&mod->dev_table_buf,
80368 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80369 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80370 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80371 char *alias)
80372 {
80373 - int i, j;
80374 + unsigned int i, j;
80375
80376 sprintf(alias, "dmi*");
80377
80378 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80379 index 68e9f5e..ac7759b 100644
80380 --- a/scripts/mod/modpost.c
80381 +++ b/scripts/mod/modpost.c
80382 @@ -930,6 +930,7 @@ enum mismatch {
80383 ANY_INIT_TO_ANY_EXIT,
80384 ANY_EXIT_TO_ANY_INIT,
80385 EXPORT_TO_INIT_EXIT,
80386 + DATA_TO_TEXT
80387 };
80388
80389 struct sectioncheck {
80390 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
80391 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80392 .mismatch = EXPORT_TO_INIT_EXIT,
80393 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80394 +},
80395 +/* Do not reference code from writable data */
80396 +{
80397 + .fromsec = { DATA_SECTIONS, NULL },
80398 + .tosec = { TEXT_SECTIONS, NULL },
80399 + .mismatch = DATA_TO_TEXT
80400 }
80401 };
80402
80403 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80404 continue;
80405 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80406 continue;
80407 - if (sym->st_value == addr)
80408 - return sym;
80409 /* Find a symbol nearby - addr are maybe negative */
80410 d = sym->st_value - addr;
80411 + if (d == 0)
80412 + return sym;
80413 if (d < 0)
80414 d = addr - sym->st_value;
80415 if (d < distance) {
80416 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80417 tosym, prl_to, prl_to, tosym);
80418 free(prl_to);
80419 break;
80420 + case DATA_TO_TEXT:
80421 +#if 0
80422 + fprintf(stderr,
80423 + "The %s %s:%s references\n"
80424 + "the %s %s:%s%s\n",
80425 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80426 +#endif
80427 + break;
80428 }
80429 fprintf(stderr, "\n");
80430 }
80431 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80432 static void check_sec_ref(struct module *mod, const char *modname,
80433 struct elf_info *elf)
80434 {
80435 - int i;
80436 + unsigned int i;
80437 Elf_Shdr *sechdrs = elf->sechdrs;
80438
80439 /* Walk through all sections */
80440 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80441 va_end(ap);
80442 }
80443
80444 -void buf_write(struct buffer *buf, const char *s, int len)
80445 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80446 {
80447 if (buf->size - buf->pos < len) {
80448 buf->size += len + SZ;
80449 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80450 if (fstat(fileno(file), &st) < 0)
80451 goto close_write;
80452
80453 - if (st.st_size != b->pos)
80454 + if (st.st_size != (off_t)b->pos)
80455 goto close_write;
80456
80457 tmp = NOFAIL(malloc(b->pos));
80458 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80459 index 51207e4..f7d603d 100644
80460 --- a/scripts/mod/modpost.h
80461 +++ b/scripts/mod/modpost.h
80462 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80463
80464 struct buffer {
80465 char *p;
80466 - int pos;
80467 - int size;
80468 + unsigned int pos;
80469 + unsigned int size;
80470 };
80471
80472 void __attribute__((format(printf, 2, 3)))
80473 buf_printf(struct buffer *buf, const char *fmt, ...);
80474
80475 void
80476 -buf_write(struct buffer *buf, const char *s, int len);
80477 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80478
80479 struct module {
80480 struct module *next;
80481 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80482 index 9dfcd6d..099068e 100644
80483 --- a/scripts/mod/sumversion.c
80484 +++ b/scripts/mod/sumversion.c
80485 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80486 goto out;
80487 }
80488
80489 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80490 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80491 warn("writing sum in %s failed: %s\n",
80492 filename, strerror(errno));
80493 goto out;
80494 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80495 index 5c11312..72742b5 100644
80496 --- a/scripts/pnmtologo.c
80497 +++ b/scripts/pnmtologo.c
80498 @@ -237,14 +237,14 @@ static void write_header(void)
80499 fprintf(out, " * Linux logo %s\n", logoname);
80500 fputs(" */\n\n", out);
80501 fputs("#include <linux/linux_logo.h>\n\n", out);
80502 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80503 + fprintf(out, "static unsigned char %s_data[] = {\n",
80504 logoname);
80505 }
80506
80507 static void write_footer(void)
80508 {
80509 fputs("\n};\n\n", out);
80510 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80511 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80512 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80513 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80514 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80515 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80516 fputs("\n};\n\n", out);
80517
80518 /* write logo clut */
80519 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80520 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80521 logoname);
80522 write_hex_cnt = 0;
80523 for (i = 0; i < logo_clutsize; i++) {
80524 diff --git a/security/Kconfig b/security/Kconfig
80525 index e9c6ac7..e7feb0d 100644
80526 --- a/security/Kconfig
80527 +++ b/security/Kconfig
80528 @@ -4,6 +4,896 @@
80529
80530 menu "Security options"
80531
80532 +menu "Grsecurity"
80533 +
80534 + config ARCH_TRACK_EXEC_LIMIT
80535 + bool
80536 +
80537 + config PAX_KERNEXEC_PLUGIN
80538 + bool
80539 +
80540 + config PAX_PER_CPU_PGD
80541 + bool
80542 +
80543 + config TASK_SIZE_MAX_SHIFT
80544 + int
80545 + depends on X86_64
80546 + default 47 if !PAX_PER_CPU_PGD
80547 + default 42 if PAX_PER_CPU_PGD
80548 +
80549 + config PAX_ENABLE_PAE
80550 + bool
80551 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80552 +
80553 + config PAX_USERCOPY_SLABS
80554 + bool
80555 +
80556 +config GRKERNSEC
80557 + bool "Grsecurity"
80558 + select CRYPTO
80559 + select CRYPTO_SHA256
80560 + select PROC_FS
80561 + select STOP_MACHINE
80562 + help
80563 + If you say Y here, you will be able to configure many features
80564 + that will enhance the security of your system. It is highly
80565 + recommended that you say Y here and read through the help
80566 + for each option so that you fully understand the features and
80567 + can evaluate their usefulness for your machine.
80568 +
80569 +choice
80570 + prompt "Configuration Method"
80571 + depends on GRKERNSEC
80572 + default GRKERNSEC_CONFIG_CUSTOM
80573 + help
80574 +
80575 +config GRKERNSEC_CONFIG_AUTO
80576 + bool "Automatic"
80577 + help
80578 + If you choose this configuration method, you'll be able to answer a small
80579 + number of simple questions about how you plan to use this kernel.
80580 + The settings of grsecurity and PaX will be automatically configured for
80581 + the highest commonly-used settings within the provided constraints.
80582 +
80583 + If you require additional configuration, custom changes can still be made
80584 + from the "custom configuration" menu.
80585 +
80586 +config GRKERNSEC_CONFIG_CUSTOM
80587 + bool "Custom"
80588 + help
80589 + If you choose this configuration method, you'll be able to configure all
80590 + grsecurity and PaX settings manually. Via this method, no options are
80591 + automatically enabled.
80592 +
80593 +endchoice
80594 +
80595 +choice
80596 + prompt "Usage Type"
80597 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80598 + default GRKERNSEC_CONFIG_SERVER
80599 + help
80600 +
80601 +config GRKERNSEC_CONFIG_SERVER
80602 + bool "Server"
80603 + help
80604 + Choose this option if you plan to use this kernel on a server.
80605 +
80606 +config GRKERNSEC_CONFIG_DESKTOP
80607 + bool "Desktop"
80608 + help
80609 + Choose this option if you plan to use this kernel on a desktop.
80610 +
80611 +endchoice
80612 +
80613 +choice
80614 + prompt "Virtualization Type"
80615 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80616 + default GRKERNSEC_CONFIG_VIRT_NONE
80617 + help
80618 +
80619 +config GRKERNSEC_CONFIG_VIRT_NONE
80620 + bool "None"
80621 + help
80622 + Choose this option if this kernel will be run on bare metal.
80623 +
80624 +config GRKERNSEC_CONFIG_VIRT_GUEST
80625 + bool "Guest"
80626 + help
80627 + Choose this option if this kernel will be run as a VM guest.
80628 +
80629 +config GRKERNSEC_CONFIG_VIRT_HOST
80630 + bool "Host"
80631 + help
80632 + Choose this option if this kernel will be run as a VM host.
80633 +
80634 +endchoice
80635 +
80636 +choice
80637 + prompt "Virtualization Hardware"
80638 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80639 + help
80640 +
80641 +config GRKERNSEC_CONFIG_VIRT_EPT
80642 + bool "EPT/RVI Processor Support"
80643 + depends on X86
80644 + help
80645 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80646 + hardware virtualization. This allows for additional kernel hardening protections
80647 + to operate without additional performance impact.
80648 +
80649 + To see if your Intel processor supports EPT, see:
80650 + http://ark.intel.com/Products/VirtualizationTechnology
80651 + (Most Core i3/5/7 support EPT)
80652 +
80653 + To see if your AMD processor supports RVI, see:
80654 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80655 +
80656 +config GRKERNSEC_CONFIG_VIRT_SOFT
80657 + bool "First-gen/No Hardware Virtualization"
80658 + help
80659 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80660 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80661 +
80662 +endchoice
80663 +
80664 +choice
80665 + prompt "Virtualization Software"
80666 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80667 + help
80668 +
80669 +config GRKERNSEC_CONFIG_VIRT_XEN
80670 + bool "Xen"
80671 + help
80672 + Choose this option if this kernel is running as a Xen guest or host.
80673 +
80674 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80675 + bool "VMWare"
80676 + help
80677 + Choose this option if this kernel is running as a VMWare guest or host.
80678 +
80679 +config GRKERNSEC_CONFIG_VIRT_KVM
80680 + bool "KVM"
80681 + help
80682 + Choose this option if this kernel is running as a KVM guest or host.
80683 +
80684 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80685 + bool "VirtualBox"
80686 + help
80687 + Choose this option if this kernel is running as a VirtualBox guest or host.
80688 +
80689 +endchoice
80690 +
80691 +choice
80692 + prompt "Required Priorities"
80693 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80694 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80695 + help
80696 +
80697 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80698 + bool "Performance"
80699 + help
80700 + Choose this option if performance is of highest priority for this deployment
80701 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80702 + and freed memory sanitizing will be disabled.
80703 +
80704 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80705 + bool "Security"
80706 + help
80707 + Choose this option if security is of highest priority for this deployment of
80708 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80709 + be enabled for this kernel. In a worst-case scenario, these features can
80710 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80711 +
80712 +endchoice
80713 +
80714 +menu "Default Special Groups"
80715 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80716 +
80717 +config GRKERNSEC_PROC_GID
80718 + int "GID exempted from /proc restrictions"
80719 + default 1001
80720 + help
80721 + Setting this GID determines which group will be exempted from
80722 + grsecurity's /proc restrictions, allowing users of the specified
80723 + group to view network statistics and the existence of other users'
80724 + processes on the system. This GID may also be chosen at boot time
80725 + via "grsec_proc_gid=" on the kernel commandline.
80726 +
80727 +config GRKERNSEC_TPE_UNTRUSTED_GID
80728 + int "GID for TPE-untrusted users"
80729 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80730 + default 1005
80731 + help
80732 + Setting this GID determines which group untrusted users should
80733 + be added to. These users will be placed under grsecurity's Trusted Path
80734 + Execution mechanism, preventing them from executing their own binaries.
80735 + The users will only be able to execute binaries in directories owned and
80736 + writable only by the root user. If the sysctl option is enabled, a sysctl
80737 + option with name "tpe_gid" is created.
80738 +
80739 +config GRKERNSEC_TPE_TRUSTED_GID
80740 + int "GID for TPE-trusted users"
80741 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80742 + default 1005
80743 + help
80744 + Setting this GID determines what group TPE restrictions will be
80745 + *disabled* for. If the sysctl option is enabled, a sysctl option
80746 + with name "tpe_gid" is created.
80747 +
80748 +config GRKERNSEC_SYMLINKOWN_GID
80749 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80750 + depends on GRKERNSEC_CONFIG_SERVER
80751 + default 1006
80752 + help
80753 + Setting this GID determines what group kernel-enforced
80754 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80755 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80756 +
80757 +
80758 +endmenu
80759 +
80760 +menu "Customize Configuration"
80761 +depends on GRKERNSEC
80762 +
80763 +menu "PaX"
80764 +
80765 +config PAX
80766 + bool "Enable various PaX features"
80767 + default y if GRKERNSEC_CONFIG_AUTO
80768 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80769 + help
80770 + This allows you to enable various PaX features. PaX adds
80771 + intrusion prevention mechanisms to the kernel that reduce
80772 + the risks posed by exploitable memory corruption bugs.
80773 +
80774 +menu "PaX Control"
80775 + depends on PAX
80776 +
80777 +config PAX_SOFTMODE
80778 + bool 'Support soft mode'
80779 + help
80780 + Enabling this option will allow you to run PaX in soft mode, that
80781 + is, PaX features will not be enforced by default, only on executables
80782 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80783 + support as they are the only way to mark executables for soft mode use.
80784 +
80785 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80786 + line option on boot. Furthermore you can control various PaX features
80787 + at runtime via the entries in /proc/sys/kernel/pax.
80788 +
80789 +config PAX_EI_PAX
80790 + bool 'Use legacy ELF header marking'
80791 + default y if GRKERNSEC_CONFIG_AUTO
80792 + help
80793 + Enabling this option will allow you to control PaX features on
80794 + a per executable basis via the 'chpax' utility available at
80795 + http://pax.grsecurity.net/. The control flags will be read from
80796 + an otherwise reserved part of the ELF header. This marking has
80797 + numerous drawbacks (no support for soft-mode, toolchain does not
80798 + know about the non-standard use of the ELF header) therefore it
80799 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80800 + support.
80801 +
80802 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80803 + support as well, they will override the legacy EI_PAX marks.
80804 +
80805 + If you enable none of the marking options then all applications
80806 + will run with PaX enabled on them by default.
80807 +
80808 +config PAX_PT_PAX_FLAGS
80809 + bool 'Use ELF program header marking'
80810 + default y if GRKERNSEC_CONFIG_AUTO
80811 + help
80812 + Enabling this option will allow you to control PaX features on
80813 + a per executable basis via the 'paxctl' utility available at
80814 + http://pax.grsecurity.net/. The control flags will be read from
80815 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80816 + has the benefits of supporting both soft mode and being fully
80817 + integrated into the toolchain (the binutils patch is available
80818 + from http://pax.grsecurity.net).
80819 +
80820 + Note that if you enable the legacy EI_PAX marking support as well,
80821 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80822 +
80823 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80824 + must make sure that the marks are the same if a binary has both marks.
80825 +
80826 + If you enable none of the marking options then all applications
80827 + will run with PaX enabled on them by default.
80828 +
80829 +config PAX_XATTR_PAX_FLAGS
80830 + bool 'Use filesystem extended attributes marking'
80831 + default y if GRKERNSEC_CONFIG_AUTO
80832 + select CIFS_XATTR if CIFS
80833 + select EXT2_FS_XATTR if EXT2_FS
80834 + select EXT3_FS_XATTR if EXT3_FS
80835 + select EXT4_FS_XATTR if EXT4_FS
80836 + select JFFS2_FS_XATTR if JFFS2_FS
80837 + select REISERFS_FS_XATTR if REISERFS_FS
80838 + select SQUASHFS_XATTR if SQUASHFS
80839 + select TMPFS_XATTR if TMPFS
80840 + select UBIFS_FS_XATTR if UBIFS_FS
80841 + help
80842 + Enabling this option will allow you to control PaX features on
80843 + a per executable basis via the 'setfattr' utility. The control
80844 + flags will be read from the user.pax.flags extended attribute of
80845 + the file. This marking has the benefit of supporting binary-only
80846 + applications that self-check themselves (e.g., skype) and would
80847 + not tolerate chpax/paxctl changes. The main drawback is that
80848 + extended attributes are not supported by some filesystems (e.g.,
80849 + isofs, udf, vfat) so copying files through such filesystems will
80850 + lose the extended attributes and these PaX markings.
80851 +
80852 + Note that if you enable the legacy EI_PAX marking support as well,
80853 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80854 +
80855 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80856 + must make sure that the marks are the same if a binary has both marks.
80857 +
80858 + If you enable none of the marking options then all applications
80859 + will run with PaX enabled on them by default.
80860 +
80861 +choice
80862 + prompt 'MAC system integration'
80863 + default PAX_HAVE_ACL_FLAGS
80864 + help
80865 + Mandatory Access Control systems have the option of controlling
80866 + PaX flags on a per executable basis, choose the method supported
80867 + by your particular system.
80868 +
80869 + - "none": if your MAC system does not interact with PaX,
80870 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80871 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80872 +
80873 + NOTE: this option is for developers/integrators only.
80874 +
80875 + config PAX_NO_ACL_FLAGS
80876 + bool 'none'
80877 +
80878 + config PAX_HAVE_ACL_FLAGS
80879 + bool 'direct'
80880 +
80881 + config PAX_HOOK_ACL_FLAGS
80882 + bool 'hook'
80883 +endchoice
80884 +
80885 +endmenu
80886 +
80887 +menu "Non-executable pages"
80888 + depends on PAX
80889 +
80890 +config PAX_NOEXEC
80891 + bool "Enforce non-executable pages"
80892 + default y if GRKERNSEC_CONFIG_AUTO
80893 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80894 + help
80895 + By design some architectures do not allow for protecting memory
80896 + pages against execution or even if they do, Linux does not make
80897 + use of this feature. In practice this means that if a page is
80898 + readable (such as the stack or heap) it is also executable.
80899 +
80900 + There is a well known exploit technique that makes use of this
80901 + fact and a common programming mistake where an attacker can
80902 + introduce code of his choice somewhere in the attacked program's
80903 + memory (typically the stack or the heap) and then execute it.
80904 +
80905 + If the attacked program was running with different (typically
80906 + higher) privileges than that of the attacker, then he can elevate
80907 + his own privilege level (e.g. get a root shell, write to files for
80908 + which he does not have write access to, etc).
80909 +
80910 + Enabling this option will let you choose from various features
80911 + that prevent the injection and execution of 'foreign' code in
80912 + a program.
80913 +
80914 + This will also break programs that rely on the old behaviour and
80915 + expect that dynamically allocated memory via the malloc() family
80916 + of functions is executable (which it is not). Notable examples
80917 + are the XFree86 4.x server, the java runtime and wine.
80918 +
80919 +config PAX_PAGEEXEC
80920 + bool "Paging based non-executable pages"
80921 + default y if GRKERNSEC_CONFIG_AUTO
80922 + 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)
80923 + select S390_SWITCH_AMODE if S390
80924 + select S390_EXEC_PROTECT if S390
80925 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80926 + help
80927 + This implementation is based on the paging feature of the CPU.
80928 + On i386 without hardware non-executable bit support there is a
80929 + variable but usually low performance impact, however on Intel's
80930 + P4 core based CPUs it is very high so you should not enable this
80931 + for kernels meant to be used on such CPUs.
80932 +
80933 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80934 + with hardware non-executable bit support there is no performance
80935 + impact, on ppc the impact is negligible.
80936 +
80937 + Note that several architectures require various emulations due to
80938 + badly designed userland ABIs, this will cause a performance impact
80939 + but will disappear as soon as userland is fixed. For example, ppc
80940 + userland MUST have been built with secure-plt by a recent toolchain.
80941 +
80942 +config PAX_SEGMEXEC
80943 + bool "Segmentation based non-executable pages"
80944 + default y if GRKERNSEC_CONFIG_AUTO
80945 + depends on PAX_NOEXEC && X86_32
80946 + help
80947 + This implementation is based on the segmentation feature of the
80948 + CPU and has a very small performance impact, however applications
80949 + will be limited to a 1.5 GB address space instead of the normal
80950 + 3 GB.
80951 +
80952 +config PAX_EMUTRAMP
80953 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80954 + default y if PARISC
80955 + help
80956 + There are some programs and libraries that for one reason or
80957 + another attempt to execute special small code snippets from
80958 + non-executable memory pages. Most notable examples are the
80959 + signal handler return code generated by the kernel itself and
80960 + the GCC trampolines.
80961 +
80962 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80963 + such programs will no longer work under your kernel.
80964 +
80965 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80966 + utilities to enable trampoline emulation for the affected programs
80967 + yet still have the protection provided by the non-executable pages.
80968 +
80969 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80970 + your system will not even boot.
80971 +
80972 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80973 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80974 + for the affected files.
80975 +
80976 + NOTE: enabling this feature *may* open up a loophole in the
80977 + protection provided by non-executable pages that an attacker
80978 + could abuse. Therefore the best solution is to not have any
80979 + files on your system that would require this option. This can
80980 + be achieved by not using libc5 (which relies on the kernel
80981 + signal handler return code) and not using or rewriting programs
80982 + that make use of the nested function implementation of GCC.
80983 + Skilled users can just fix GCC itself so that it implements
80984 + nested function calls in a way that does not interfere with PaX.
80985 +
80986 +config PAX_EMUSIGRT
80987 + bool "Automatically emulate sigreturn trampolines"
80988 + depends on PAX_EMUTRAMP && PARISC
80989 + default y
80990 + help
80991 + Enabling this option will have the kernel automatically detect
80992 + and emulate signal return trampolines executing on the stack
80993 + that would otherwise lead to task termination.
80994 +
80995 + This solution is intended as a temporary one for users with
80996 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80997 + Modula-3 runtime, etc) or executables linked to such, basically
80998 + everything that does not specify its own SA_RESTORER function in
80999 + normal executable memory like glibc 2.1+ does.
81000 +
81001 + On parisc you MUST enable this option, otherwise your system will
81002 + not even boot.
81003 +
81004 + NOTE: this feature cannot be disabled on a per executable basis
81005 + and since it *does* open up a loophole in the protection provided
81006 + by non-executable pages, the best solution is to not have any
81007 + files on your system that would require this option.
81008 +
81009 +config PAX_MPROTECT
81010 + bool "Restrict mprotect()"
81011 + default y if GRKERNSEC_CONFIG_AUTO
81012 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81013 + help
81014 + Enabling this option will prevent programs from
81015 + - changing the executable status of memory pages that were
81016 + not originally created as executable,
81017 + - making read-only executable pages writable again,
81018 + - creating executable pages from anonymous memory,
81019 + - making read-only-after-relocations (RELRO) data pages writable again.
81020 +
81021 + You should say Y here to complete the protection provided by
81022 + the enforcement of non-executable pages.
81023 +
81024 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81025 + this feature on a per file basis.
81026 +
81027 +config PAX_MPROTECT_COMPAT
81028 + bool "Use legacy/compat protection demoting (read help)"
81029 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81030 + depends on PAX_MPROTECT
81031 + help
81032 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81033 + by sending the proper error code to the application. For some broken
81034 + userland, this can cause problems with Python or other applications. The
81035 + current implementation however allows for applications like clamav to
81036 + detect if JIT compilation/execution is allowed and to fall back gracefully
81037 + to an interpreter-based mode if it does not. While we encourage everyone
81038 + to use the current implementation as-is and push upstream to fix broken
81039 + userland (note that the RWX logging option can assist with this), in some
81040 + environments this may not be possible. Having to disable MPROTECT
81041 + completely on certain binaries reduces the security benefit of PaX,
81042 + so this option is provided for those environments to revert to the old
81043 + behavior.
81044 +
81045 +config PAX_ELFRELOCS
81046 + bool "Allow ELF text relocations (read help)"
81047 + depends on PAX_MPROTECT
81048 + default n
81049 + help
81050 + Non-executable pages and mprotect() restrictions are effective
81051 + in preventing the introduction of new executable code into an
81052 + attacked task's address space. There remain only two venues
81053 + for this kind of attack: if the attacker can execute already
81054 + existing code in the attacked task then he can either have it
81055 + create and mmap() a file containing his code or have it mmap()
81056 + an already existing ELF library that does not have position
81057 + independent code in it and use mprotect() on it to make it
81058 + writable and copy his code there. While protecting against
81059 + the former approach is beyond PaX, the latter can be prevented
81060 + by having only PIC ELF libraries on one's system (which do not
81061 + need to relocate their code). If you are sure this is your case,
81062 + as is the case with all modern Linux distributions, then leave
81063 + this option disabled. You should say 'n' here.
81064 +
81065 +config PAX_ETEXECRELOCS
81066 + bool "Allow ELF ET_EXEC text relocations"
81067 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81068 + select PAX_ELFRELOCS
81069 + default y
81070 + help
81071 + On some architectures there are incorrectly created applications
81072 + that require text relocations and would not work without enabling
81073 + this option. If you are an alpha, ia64 or parisc user, you should
81074 + enable this option and disable it once you have made sure that
81075 + none of your applications need it.
81076 +
81077 +config PAX_EMUPLT
81078 + bool "Automatically emulate ELF PLT"
81079 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81080 + default y
81081 + help
81082 + Enabling this option will have the kernel automatically detect
81083 + and emulate the Procedure Linkage Table entries in ELF files.
81084 + On some architectures such entries are in writable memory, and
81085 + become non-executable leading to task termination. Therefore
81086 + it is mandatory that you enable this option on alpha, parisc,
81087 + sparc and sparc64, otherwise your system would not even boot.
81088 +
81089 + NOTE: this feature *does* open up a loophole in the protection
81090 + provided by the non-executable pages, therefore the proper
81091 + solution is to modify the toolchain to produce a PLT that does
81092 + not need to be writable.
81093 +
81094 +config PAX_DLRESOLVE
81095 + bool 'Emulate old glibc resolver stub'
81096 + depends on PAX_EMUPLT && SPARC
81097 + default n
81098 + help
81099 + This option is needed if userland has an old glibc (before 2.4)
81100 + that puts a 'save' instruction into the runtime generated resolver
81101 + stub that needs special emulation.
81102 +
81103 +config PAX_KERNEXEC
81104 + bool "Enforce non-executable kernel pages"
81105 + 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))
81106 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81107 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81108 + select PAX_KERNEXEC_PLUGIN if X86_64
81109 + help
81110 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81111 + that is, enabling this option will make it harder to inject
81112 + and execute 'foreign' code in kernel memory itself.
81113 +
81114 +choice
81115 + prompt "Return Address Instrumentation Method"
81116 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81117 + depends on PAX_KERNEXEC_PLUGIN
81118 + help
81119 + Select the method used to instrument function pointer dereferences.
81120 + Note that binary modules cannot be instrumented by this approach.
81121 +
81122 + Note that the implementation requires a gcc with plugin support,
81123 + i.e., gcc 4.5 or newer. You may need to install the supporting
81124 + headers explicitly in addition to the normal gcc package.
81125 +
81126 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81127 + bool "bts"
81128 + help
81129 + This method is compatible with binary only modules but has
81130 + a higher runtime overhead.
81131 +
81132 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81133 + bool "or"
81134 + depends on !PARAVIRT
81135 + help
81136 + This method is incompatible with binary only modules but has
81137 + a lower runtime overhead.
81138 +endchoice
81139 +
81140 +config PAX_KERNEXEC_PLUGIN_METHOD
81141 + string
81142 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81143 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81144 + default ""
81145 +
81146 +config PAX_KERNEXEC_MODULE_TEXT
81147 + int "Minimum amount of memory reserved for module code"
81148 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81149 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81150 + depends on PAX_KERNEXEC && X86_32 && MODULES
81151 + help
81152 + Due to implementation details the kernel must reserve a fixed
81153 + amount of memory for module code at compile time that cannot be
81154 + changed at runtime. Here you can specify the minimum amount
81155 + in MB that will be reserved. Due to the same implementation
81156 + details this size will always be rounded up to the next 2/4 MB
81157 + boundary (depends on PAE) so the actually available memory for
81158 + module code will usually be more than this minimum.
81159 +
81160 + The default 4 MB should be enough for most users but if you have
81161 + an excessive number of modules (e.g., most distribution configs
81162 + compile many drivers as modules) or use huge modules such as
81163 + nvidia's kernel driver, you will need to adjust this amount.
81164 + A good rule of thumb is to look at your currently loaded kernel
81165 + modules and add up their sizes.
81166 +
81167 +endmenu
81168 +
81169 +menu "Address Space Layout Randomization"
81170 + depends on PAX
81171 +
81172 +config PAX_ASLR
81173 + bool "Address Space Layout Randomization"
81174 + default y if GRKERNSEC_CONFIG_AUTO
81175 + help
81176 + Many if not most exploit techniques rely on the knowledge of
81177 + certain addresses in the attacked program. The following options
81178 + will allow the kernel to apply a certain amount of randomization
81179 + to specific parts of the program thereby forcing an attacker to
81180 + guess them in most cases. Any failed guess will most likely crash
81181 + the attacked program which allows the kernel to detect such attempts
81182 + and react on them. PaX itself provides no reaction mechanisms,
81183 + instead it is strongly encouraged that you make use of Nergal's
81184 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81185 + (http://www.grsecurity.net/) built-in crash detection features or
81186 + develop one yourself.
81187 +
81188 + By saying Y here you can choose to randomize the following areas:
81189 + - top of the task's kernel stack
81190 + - top of the task's userland stack
81191 + - base address for mmap() requests that do not specify one
81192 + (this includes all libraries)
81193 + - base address of the main executable
81194 +
81195 + It is strongly recommended to say Y here as address space layout
81196 + randomization has negligible impact on performance yet it provides
81197 + a very effective protection.
81198 +
81199 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81200 + this feature on a per file basis.
81201 +
81202 +config PAX_RANDKSTACK
81203 + bool "Randomize kernel stack base"
81204 + default y if GRKERNSEC_CONFIG_AUTO
81205 + depends on X86_TSC && X86
81206 + help
81207 + By saying Y here the kernel will randomize every task's kernel
81208 + stack on every system call. This will not only force an attacker
81209 + to guess it but also prevent him from making use of possible
81210 + leaked information about it.
81211 +
81212 + Since the kernel stack is a rather scarce resource, randomization
81213 + may cause unexpected stack overflows, therefore you should very
81214 + carefully test your system. Note that once enabled in the kernel
81215 + configuration, this feature cannot be disabled on a per file basis.
81216 +
81217 +config PAX_RANDUSTACK
81218 + bool "Randomize user stack base"
81219 + default y if GRKERNSEC_CONFIG_AUTO
81220 + depends on PAX_ASLR
81221 + help
81222 + By saying Y here the kernel will randomize every task's userland
81223 + stack. The randomization is done in two steps where the second
81224 + one may apply a big amount of shift to the top of the stack and
81225 + cause problems for programs that want to use lots of memory (more
81226 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81227 + For this reason the second step can be controlled by 'chpax' or
81228 + 'paxctl' on a per file basis.
81229 +
81230 +config PAX_RANDMMAP
81231 + bool "Randomize mmap() base"
81232 + default y if GRKERNSEC_CONFIG_AUTO
81233 + depends on PAX_ASLR
81234 + help
81235 + By saying Y here the kernel will use a randomized base address for
81236 + mmap() requests that do not specify one themselves. As a result
81237 + all dynamically loaded libraries will appear at random addresses
81238 + and therefore be harder to exploit by a technique where an attacker
81239 + attempts to execute library code for his purposes (e.g. spawn a
81240 + shell from an exploited program that is running at an elevated
81241 + privilege level).
81242 +
81243 + Furthermore, if a program is relinked as a dynamic ELF file, its
81244 + base address will be randomized as well, completing the full
81245 + randomization of the address space layout. Attacking such programs
81246 + becomes a guess game. You can find an example of doing this at
81247 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81248 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81249 +
81250 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81251 + feature on a per file basis.
81252 +
81253 +endmenu
81254 +
81255 +menu "Miscellaneous hardening features"
81256 +
81257 +config PAX_MEMORY_SANITIZE
81258 + bool "Sanitize all freed memory"
81259 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81260 + depends on !HIBERNATION
81261 + help
81262 + By saying Y here the kernel will erase memory pages as soon as they
81263 + are freed. This in turn reduces the lifetime of data stored in the
81264 + pages, making it less likely that sensitive information such as
81265 + passwords, cryptographic secrets, etc stay in memory for too long.
81266 +
81267 + This is especially useful for programs whose runtime is short, long
81268 + lived processes and the kernel itself benefit from this as long as
81269 + they operate on whole memory pages and ensure timely freeing of pages
81270 + that may hold sensitive information.
81271 +
81272 + The tradeoff is performance impact, on a single CPU system kernel
81273 + compilation sees a 3% slowdown, other systems and workloads may vary
81274 + and you are advised to test this feature on your expected workload
81275 + before deploying it.
81276 +
81277 + Note that this feature does not protect data stored in live pages,
81278 + e.g., process memory swapped to disk may stay there for a long time.
81279 +
81280 +config PAX_MEMORY_STACKLEAK
81281 + bool "Sanitize kernel stack"
81282 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81283 + depends on X86
81284 + help
81285 + By saying Y here the kernel will erase the kernel stack before it
81286 + returns from a system call. This in turn reduces the information
81287 + that a kernel stack leak bug can reveal.
81288 +
81289 + Note that such a bug can still leak information that was put on
81290 + the stack by the current system call (the one eventually triggering
81291 + the bug) but traces of earlier system calls on the kernel stack
81292 + cannot leak anymore.
81293 +
81294 + The tradeoff is performance impact: on a single CPU system kernel
81295 + compilation sees a 1% slowdown, other systems and workloads may vary
81296 + and you are advised to test this feature on your expected workload
81297 + before deploying it.
81298 +
81299 + Note that the full feature requires a gcc with plugin support,
81300 + i.e., gcc 4.5 or newer. You may need to install the supporting
81301 + headers explicitly in addition to the normal gcc package. Using
81302 + older gcc versions means that functions with large enough stack
81303 + frames may leave uninitialized memory behind that may be exposed
81304 + to a later syscall leaking the stack.
81305 +
81306 +config PAX_MEMORY_UDEREF
81307 + bool "Prevent invalid userland pointer dereference"
81308 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81309 + depends on X86 && !UML_X86 && !XEN
81310 + select PAX_PER_CPU_PGD if X86_64
81311 + help
81312 + By saying Y here the kernel will be prevented from dereferencing
81313 + userland pointers in contexts where the kernel expects only kernel
81314 + pointers. This is both a useful runtime debugging feature and a
81315 + security measure that prevents exploiting a class of kernel bugs.
81316 +
81317 + The tradeoff is that some virtualization solutions may experience
81318 + a huge slowdown and therefore you should not enable this feature
81319 + for kernels meant to run in such environments. Whether a given VM
81320 + solution is affected or not is best determined by simply trying it
81321 + out, the performance impact will be obvious right on boot as this
81322 + mechanism engages from very early on. A good rule of thumb is that
81323 + VMs running on CPUs without hardware virtualization support (i.e.,
81324 + the majority of IA-32 CPUs) will likely experience the slowdown.
81325 +
81326 +config PAX_REFCOUNT
81327 + bool "Prevent various kernel object reference counter overflows"
81328 + default y if GRKERNSEC_CONFIG_AUTO
81329 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81330 + help
81331 + By saying Y here the kernel will detect and prevent overflowing
81332 + various (but not all) kinds of object reference counters. Such
81333 + overflows can normally occur due to bugs only and are often, if
81334 + not always, exploitable.
81335 +
81336 + The tradeoff is that data structures protected by an overflowed
81337 + refcount will never be freed and therefore will leak memory. Note
81338 + that this leak also happens even without this protection but in
81339 + that case the overflow can eventually trigger the freeing of the
81340 + data structure while it is still being used elsewhere, resulting
81341 + in the exploitable situation that this feature prevents.
81342 +
81343 + Since this has a negligible performance impact, you should enable
81344 + this feature.
81345 +
81346 +config PAX_USERCOPY
81347 + bool "Harden heap object copies between kernel and userland"
81348 + default y if GRKERNSEC_CONFIG_AUTO
81349 + depends on X86 || PPC || SPARC || ARM
81350 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81351 + select PAX_USERCOPY_SLABS
81352 + help
81353 + By saying Y here the kernel will enforce the size of heap objects
81354 + when they are copied in either direction between the kernel and
81355 + userland, even if only a part of the heap object is copied.
81356 +
81357 + Specifically, this checking prevents information leaking from the
81358 + kernel heap during kernel to userland copies (if the kernel heap
81359 + object is otherwise fully initialized) and prevents kernel heap
81360 + overflows during userland to kernel copies.
81361 +
81362 + Note that the current implementation provides the strictest bounds
81363 + checks for the SLUB allocator.
81364 +
81365 + Enabling this option also enables per-slab cache protection against
81366 + data in a given cache being copied into/out of via userland
81367 + accessors. Though the whitelist of regions will be reduced over
81368 + time, it notably protects important data structures like task structs.
81369 +
81370 + If frame pointers are enabled on x86, this option will also restrict
81371 + copies into and out of the kernel stack to local variables within a
81372 + single frame.
81373 +
81374 + Since this has a negligible performance impact, you should enable
81375 + this feature.
81376 +
81377 +config PAX_SIZE_OVERFLOW
81378 + bool "Prevent various integer overflows in function size parameters"
81379 + default y if GRKERNSEC_CONFIG_AUTO
81380 + depends on X86
81381 + help
81382 + By saying Y here the kernel recomputes expressions of function
81383 + arguments marked by a size_overflow attribute with double integer
81384 + precision (DImode/TImode for 32/64 bit integer types).
81385 +
81386 + The recomputed argument is checked against TYPE_MAX and an event
81387 + is logged on overflow and the triggering process is killed.
81388 +
81389 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81390 +
81391 + Note that the implementation requires a gcc with plugin support,
81392 + i.e., gcc 4.5 or newer. You may need to install the supporting
81393 + headers explicitly in addition to the normal gcc package.
81394 +
81395 +config PAX_LATENT_ENTROPY
81396 + bool "Generate some entropy during boot"
81397 + default y if GRKERNSEC_CONFIG_AUTO
81398 + help
81399 + By saying Y here the kernel will instrument early boot code to
81400 + extract some entropy from both original and artificially created
81401 + program state. This will help especially embedded systems where
81402 + there is little 'natural' source of entropy normally. The cost
81403 + is some slowdown of the boot process.
81404 +
81405 + Note that the implementation requires a gcc with plugin support,
81406 + i.e., gcc 4.5 or newer. You may need to install the supporting
81407 + headers explicitly in addition to the normal gcc package.
81408 +
81409 + Note that entropy extracted this way is not cryptographically
81410 + secure!
81411 +
81412 +endmenu
81413 +
81414 +endmenu
81415 +
81416 +source grsecurity/Kconfig
81417 +
81418 +endmenu
81419 +
81420 +endmenu
81421 +
81422 source security/keys/Kconfig
81423
81424 config SECURITY_DMESG_RESTRICT
81425 @@ -103,7 +993,7 @@ config INTEL_TXT
81426 config LSM_MMAP_MIN_ADDR
81427 int "Low address space for LSM to protect from user allocation"
81428 depends on SECURITY && SECURITY_SELINUX
81429 - default 32768 if ARM
81430 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81431 default 65536
81432 help
81433 This is the portion of low virtual memory which should be protected
81434 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81435 index 8ea39aa..8569ac5 100644
81436 --- a/security/apparmor/lsm.c
81437 +++ b/security/apparmor/lsm.c
81438 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81439 return error;
81440 }
81441
81442 -static struct security_operations apparmor_ops = {
81443 +static struct security_operations apparmor_ops __read_only = {
81444 .name = "apparmor",
81445
81446 .ptrace_access_check = apparmor_ptrace_access_check,
81447 diff --git a/security/commoncap.c b/security/commoncap.c
81448 index 6dbae46..d5611fd 100644
81449 --- a/security/commoncap.c
81450 +++ b/security/commoncap.c
81451 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81452 return 0;
81453 }
81454
81455 +/* returns:
81456 + 1 for suid privilege
81457 + 2 for sgid privilege
81458 + 3 for fscap privilege
81459 +*/
81460 +int is_privileged_binary(const struct dentry *dentry)
81461 +{
81462 + struct cpu_vfs_cap_data capdata;
81463 + struct inode *inode = dentry->d_inode;
81464 +
81465 + if (!inode || S_ISDIR(inode->i_mode))
81466 + return 0;
81467 +
81468 + if (inode->i_mode & S_ISUID)
81469 + return 1;
81470 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81471 + return 2;
81472 +
81473 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81474 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81475 + return 3;
81476 + }
81477 +
81478 + return 0;
81479 +}
81480 +
81481 /*
81482 * Attempt to get the on-exec apply capability sets for an executable file from
81483 * its xattrs and, if present, apply them to the proposed credentials being
81484 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81485 const struct cred *cred = current_cred();
81486 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81487
81488 + if (gr_acl_enable_at_secure())
81489 + return 1;
81490 +
81491 if (!uid_eq(cred->uid, root_uid)) {
81492 if (bprm->cap_effective)
81493 return 1;
81494 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81495 index e7c99fd..5b2fa24 100644
81496 --- a/security/integrity/ima/ima.h
81497 +++ b/security/integrity/ima/ima.h
81498 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81499 extern spinlock_t ima_queue_lock;
81500
81501 struct ima_h_table {
81502 - atomic_long_t len; /* number of stored measurements in the list */
81503 - atomic_long_t violations;
81504 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81505 + atomic_long_unchecked_t violations;
81506 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81507 };
81508 extern struct ima_h_table ima_htable;
81509 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81510 index 032ff03..c428a74 100644
81511 --- a/security/integrity/ima/ima_api.c
81512 +++ b/security/integrity/ima/ima_api.c
81513 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81514 int result;
81515
81516 /* can overflow, only indicator */
81517 - atomic_long_inc(&ima_htable.violations);
81518 + atomic_long_inc_unchecked(&ima_htable.violations);
81519
81520 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81521 if (!entry) {
81522 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81523 index 38477c9..87a60c7 100644
81524 --- a/security/integrity/ima/ima_fs.c
81525 +++ b/security/integrity/ima/ima_fs.c
81526 @@ -28,12 +28,12 @@
81527 static int valid_policy = 1;
81528 #define TMPBUFLEN 12
81529 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81530 - loff_t *ppos, atomic_long_t *val)
81531 + loff_t *ppos, atomic_long_unchecked_t *val)
81532 {
81533 char tmpbuf[TMPBUFLEN];
81534 ssize_t len;
81535
81536 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81537 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81538 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81539 }
81540
81541 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81542 index 55a6271..ad829c3 100644
81543 --- a/security/integrity/ima/ima_queue.c
81544 +++ b/security/integrity/ima/ima_queue.c
81545 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81546 INIT_LIST_HEAD(&qe->later);
81547 list_add_tail_rcu(&qe->later, &ima_measurements);
81548
81549 - atomic_long_inc(&ima_htable.len);
81550 + atomic_long_inc_unchecked(&ima_htable.len);
81551 key = ima_hash_key(entry->digest);
81552 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81553 return 0;
81554 diff --git a/security/keys/compat.c b/security/keys/compat.c
81555 index 1c26176..64a1ba2 100644
81556 --- a/security/keys/compat.c
81557 +++ b/security/keys/compat.c
81558 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81559 if (ret == 0)
81560 goto no_payload_free;
81561
81562 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81563 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81564
81565 if (iov != iovstack)
81566 kfree(iov);
81567 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81568 index 3364fbf..1f10f31 100644
81569 --- a/security/keys/keyctl.c
81570 +++ b/security/keys/keyctl.c
81571 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81572 /*
81573 * Copy the iovec data from userspace
81574 */
81575 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81576 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81577 unsigned ioc)
81578 {
81579 for (; ioc > 0; ioc--) {
81580 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81581 * If successful, 0 will be returned.
81582 */
81583 long keyctl_instantiate_key_common(key_serial_t id,
81584 - const struct iovec *payload_iov,
81585 + const struct iovec __user *payload_iov,
81586 unsigned ioc,
81587 size_t plen,
81588 key_serial_t ringid)
81589 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81590 [0].iov_len = plen
81591 };
81592
81593 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81594 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81595 }
81596
81597 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81598 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81599 if (ret == 0)
81600 goto no_payload_free;
81601
81602 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81603 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81604
81605 if (iov != iovstack)
81606 kfree(iov);
81607 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81608 index 81e7852..2b2ecc3 100644
81609 --- a/security/keys/keyring.c
81610 +++ b/security/keys/keyring.c
81611 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81612 ret = -EFAULT;
81613
81614 for (loop = 0; loop < klist->nkeys; loop++) {
81615 + key_serial_t serial;
81616 key = rcu_deref_link_locked(klist, loop,
81617 keyring);
81618 + serial = key->serial;
81619
81620 tmp = sizeof(key_serial_t);
81621 if (tmp > buflen)
81622 tmp = buflen;
81623
81624 - if (copy_to_user(buffer,
81625 - &key->serial,
81626 - tmp) != 0)
81627 + if (copy_to_user(buffer, &serial, tmp))
81628 goto error;
81629
81630 buflen -= tmp;
81631 diff --git a/security/min_addr.c b/security/min_addr.c
81632 index f728728..6457a0c 100644
81633 --- a/security/min_addr.c
81634 +++ b/security/min_addr.c
81635 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81636 */
81637 static void update_mmap_min_addr(void)
81638 {
81639 +#ifndef SPARC
81640 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81641 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81642 mmap_min_addr = dac_mmap_min_addr;
81643 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81644 #else
81645 mmap_min_addr = dac_mmap_min_addr;
81646 #endif
81647 +#endif
81648 }
81649
81650 /*
81651 diff --git a/security/security.c b/security/security.c
81652 index 860aeb3..45765c0 100644
81653 --- a/security/security.c
81654 +++ b/security/security.c
81655 @@ -20,6 +20,7 @@
81656 #include <linux/ima.h>
81657 #include <linux/evm.h>
81658 #include <linux/fsnotify.h>
81659 +#include <linux/mm.h>
81660 #include <linux/mman.h>
81661 #include <linux/mount.h>
81662 #include <linux/personality.h>
81663 @@ -32,8 +33,8 @@
81664 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81665 CONFIG_DEFAULT_SECURITY;
81666
81667 -static struct security_operations *security_ops;
81668 -static struct security_operations default_security_ops = {
81669 +static struct security_operations *security_ops __read_only;
81670 +static struct security_operations default_security_ops __read_only = {
81671 .name = "default",
81672 };
81673
81674 @@ -74,7 +75,9 @@ int __init security_init(void)
81675
81676 void reset_security_ops(void)
81677 {
81678 + pax_open_kernel();
81679 security_ops = &default_security_ops;
81680 + pax_close_kernel();
81681 }
81682
81683 /* Save user chosen LSM */
81684 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81685 index 6c77f63..7496c76 100644
81686 --- a/security/selinux/hooks.c
81687 +++ b/security/selinux/hooks.c
81688 @@ -95,8 +95,6 @@
81689
81690 #define NUM_SEL_MNT_OPTS 5
81691
81692 -extern struct security_operations *security_ops;
81693 -
81694 /* SECMARK reference count */
81695 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81696
81697 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81698
81699 #endif
81700
81701 -static struct security_operations selinux_ops = {
81702 +static struct security_operations selinux_ops __read_only = {
81703 .name = "selinux",
81704
81705 .ptrace_access_check = selinux_ptrace_access_check,
81706 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81707 index 65f67cb..3f141ef 100644
81708 --- a/security/selinux/include/xfrm.h
81709 +++ b/security/selinux/include/xfrm.h
81710 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81711
81712 static inline void selinux_xfrm_notify_policyload(void)
81713 {
81714 - atomic_inc(&flow_cache_genid);
81715 + atomic_inc_unchecked(&flow_cache_genid);
81716 rt_genid_bump(&init_net);
81717 }
81718 #else
81719 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81720 index 8221514..5c4775f 100644
81721 --- a/security/smack/smack_lsm.c
81722 +++ b/security/smack/smack_lsm.c
81723 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81724 return 0;
81725 }
81726
81727 -struct security_operations smack_ops = {
81728 +struct security_operations smack_ops __read_only = {
81729 .name = "smack",
81730
81731 .ptrace_access_check = smack_ptrace_access_check,
81732 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81733 index c2d04a5..e6a1aeb 100644
81734 --- a/security/tomoyo/tomoyo.c
81735 +++ b/security/tomoyo/tomoyo.c
81736 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81737 * tomoyo_security_ops is a "struct security_operations" which is used for
81738 * registering TOMOYO.
81739 */
81740 -static struct security_operations tomoyo_security_ops = {
81741 +static struct security_operations tomoyo_security_ops __read_only = {
81742 .name = "tomoyo",
81743 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81744 .cred_prepare = tomoyo_cred_prepare,
81745 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81746 index 51d6709..1f3dbe2 100644
81747 --- a/security/yama/Kconfig
81748 +++ b/security/yama/Kconfig
81749 @@ -1,6 +1,6 @@
81750 config SECURITY_YAMA
81751 bool "Yama support"
81752 - depends on SECURITY
81753 + depends on SECURITY && !GRKERNSEC
81754 select SECURITYFS
81755 select SECURITY_PATH
81756 default n
81757 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81758 index 4cedc69..e59d8a3 100644
81759 --- a/sound/aoa/codecs/onyx.c
81760 +++ b/sound/aoa/codecs/onyx.c
81761 @@ -54,7 +54,7 @@ struct onyx {
81762 spdif_locked:1,
81763 analog_locked:1,
81764 original_mute:2;
81765 - int open_count;
81766 + local_t open_count;
81767 struct codec_info *codec_info;
81768
81769 /* mutex serializes concurrent access to the device
81770 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81771 struct onyx *onyx = cii->codec_data;
81772
81773 mutex_lock(&onyx->mutex);
81774 - onyx->open_count++;
81775 + local_inc(&onyx->open_count);
81776 mutex_unlock(&onyx->mutex);
81777
81778 return 0;
81779 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81780 struct onyx *onyx = cii->codec_data;
81781
81782 mutex_lock(&onyx->mutex);
81783 - onyx->open_count--;
81784 - if (!onyx->open_count)
81785 + if (local_dec_and_test(&onyx->open_count))
81786 onyx->spdif_locked = onyx->analog_locked = 0;
81787 mutex_unlock(&onyx->mutex);
81788
81789 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81790 index ffd2025..df062c9 100644
81791 --- a/sound/aoa/codecs/onyx.h
81792 +++ b/sound/aoa/codecs/onyx.h
81793 @@ -11,6 +11,7 @@
81794 #include <linux/i2c.h>
81795 #include <asm/pmac_low_i2c.h>
81796 #include <asm/prom.h>
81797 +#include <asm/local.h>
81798
81799 /* PCM3052 register definitions */
81800
81801 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81802 index 08fde00..0bf641a 100644
81803 --- a/sound/core/oss/pcm_oss.c
81804 +++ b/sound/core/oss/pcm_oss.c
81805 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81806 if (in_kernel) {
81807 mm_segment_t fs;
81808 fs = snd_enter_user();
81809 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81810 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81811 snd_leave_user(fs);
81812 } else {
81813 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81814 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81815 }
81816 if (ret != -EPIPE && ret != -ESTRPIPE)
81817 break;
81818 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81819 if (in_kernel) {
81820 mm_segment_t fs;
81821 fs = snd_enter_user();
81822 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81823 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81824 snd_leave_user(fs);
81825 } else {
81826 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81827 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81828 }
81829 if (ret == -EPIPE) {
81830 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81831 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81832 struct snd_pcm_plugin_channel *channels;
81833 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81834 if (!in_kernel) {
81835 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81836 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81837 return -EFAULT;
81838 buf = runtime->oss.buffer;
81839 }
81840 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81841 }
81842 } else {
81843 tmp = snd_pcm_oss_write2(substream,
81844 - (const char __force *)buf,
81845 + (const char __force_kernel *)buf,
81846 runtime->oss.period_bytes, 0);
81847 if (tmp <= 0)
81848 goto err;
81849 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81850 struct snd_pcm_runtime *runtime = substream->runtime;
81851 snd_pcm_sframes_t frames, frames1;
81852 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81853 - char __user *final_dst = (char __force __user *)buf;
81854 + char __user *final_dst = (char __force_user *)buf;
81855 if (runtime->oss.plugin_first) {
81856 struct snd_pcm_plugin_channel *channels;
81857 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81858 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81859 xfer += tmp;
81860 runtime->oss.buffer_used -= tmp;
81861 } else {
81862 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81863 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81864 runtime->oss.period_bytes, 0);
81865 if (tmp <= 0)
81866 goto err;
81867 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81868 size1);
81869 size1 /= runtime->channels; /* frames */
81870 fs = snd_enter_user();
81871 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81872 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81873 snd_leave_user(fs);
81874 }
81875 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81876 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81877 index 91cdf94..4085161 100644
81878 --- a/sound/core/pcm_compat.c
81879 +++ b/sound/core/pcm_compat.c
81880 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81881 int err;
81882
81883 fs = snd_enter_user();
81884 - err = snd_pcm_delay(substream, &delay);
81885 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81886 snd_leave_user(fs);
81887 if (err < 0)
81888 return err;
81889 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81890 index 53b5ada..2db94c8 100644
81891 --- a/sound/core/pcm_native.c
81892 +++ b/sound/core/pcm_native.c
81893 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81894 switch (substream->stream) {
81895 case SNDRV_PCM_STREAM_PLAYBACK:
81896 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81897 - (void __user *)arg);
81898 + (void __force_user *)arg);
81899 break;
81900 case SNDRV_PCM_STREAM_CAPTURE:
81901 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81902 - (void __user *)arg);
81903 + (void __force_user *)arg);
81904 break;
81905 default:
81906 result = -EINVAL;
81907 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81908 index 5cf8d65..912a79c 100644
81909 --- a/sound/core/seq/seq_device.c
81910 +++ b/sound/core/seq/seq_device.c
81911 @@ -64,7 +64,7 @@ struct ops_list {
81912 int argsize; /* argument size */
81913
81914 /* operators */
81915 - struct snd_seq_dev_ops ops;
81916 + struct snd_seq_dev_ops *ops;
81917
81918 /* registred devices */
81919 struct list_head dev_list; /* list of devices */
81920 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81921
81922 mutex_lock(&ops->reg_mutex);
81923 /* copy driver operators */
81924 - ops->ops = *entry;
81925 + ops->ops = entry;
81926 ops->driver |= DRIVER_LOADED;
81927 ops->argsize = argsize;
81928
81929 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81930 dev->name, ops->id, ops->argsize, dev->argsize);
81931 return -EINVAL;
81932 }
81933 - if (ops->ops.init_device(dev) >= 0) {
81934 + if (ops->ops->init_device(dev) >= 0) {
81935 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81936 ops->num_init_devices++;
81937 } else {
81938 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81939 dev->name, ops->id, ops->argsize, dev->argsize);
81940 return -EINVAL;
81941 }
81942 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81943 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81944 dev->status = SNDRV_SEQ_DEVICE_FREE;
81945 dev->driver_data = NULL;
81946 ops->num_init_devices--;
81947 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81948 index 2d5514b..3afae9c 100644
81949 --- a/sound/drivers/mts64.c
81950 +++ b/sound/drivers/mts64.c
81951 @@ -29,6 +29,7 @@
81952 #include <sound/initval.h>
81953 #include <sound/rawmidi.h>
81954 #include <sound/control.h>
81955 +#include <asm/local.h>
81956
81957 #define CARD_NAME "Miditerminal 4140"
81958 #define DRIVER_NAME "MTS64"
81959 @@ -67,7 +68,7 @@ struct mts64 {
81960 struct pardevice *pardev;
81961 int pardev_claimed;
81962
81963 - int open_count;
81964 + local_t open_count;
81965 int current_midi_output_port;
81966 int current_midi_input_port;
81967 u8 mode[MTS64_NUM_INPUT_PORTS];
81968 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81969 {
81970 struct mts64 *mts = substream->rmidi->private_data;
81971
81972 - if (mts->open_count == 0) {
81973 + if (local_read(&mts->open_count) == 0) {
81974 /* We don't need a spinlock here, because this is just called
81975 if the device has not been opened before.
81976 So there aren't any IRQs from the device */
81977 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81978
81979 msleep(50);
81980 }
81981 - ++(mts->open_count);
81982 + local_inc(&mts->open_count);
81983
81984 return 0;
81985 }
81986 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81987 struct mts64 *mts = substream->rmidi->private_data;
81988 unsigned long flags;
81989
81990 - --(mts->open_count);
81991 - if (mts->open_count == 0) {
81992 + if (local_dec_return(&mts->open_count) == 0) {
81993 /* We need the spinlock_irqsave here because we can still
81994 have IRQs at this point */
81995 spin_lock_irqsave(&mts->lock, flags);
81996 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81997
81998 msleep(500);
81999
82000 - } else if (mts->open_count < 0)
82001 - mts->open_count = 0;
82002 + } else if (local_read(&mts->open_count) < 0)
82003 + local_set(&mts->open_count, 0);
82004
82005 return 0;
82006 }
82007 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82008 index b953fb4..1999c01 100644
82009 --- a/sound/drivers/opl4/opl4_lib.c
82010 +++ b/sound/drivers/opl4/opl4_lib.c
82011 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82012 MODULE_DESCRIPTION("OPL4 driver");
82013 MODULE_LICENSE("GPL");
82014
82015 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82016 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82017 {
82018 int timeout = 10;
82019 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82020 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82021 index 8364855..59f2e2b 100644
82022 --- a/sound/drivers/portman2x4.c
82023 +++ b/sound/drivers/portman2x4.c
82024 @@ -48,6 +48,7 @@
82025 #include <sound/initval.h>
82026 #include <sound/rawmidi.h>
82027 #include <sound/control.h>
82028 +#include <asm/local.h>
82029
82030 #define CARD_NAME "Portman 2x4"
82031 #define DRIVER_NAME "portman"
82032 @@ -85,7 +86,7 @@ struct portman {
82033 struct pardevice *pardev;
82034 int pardev_claimed;
82035
82036 - int open_count;
82037 + local_t open_count;
82038 int mode[PORTMAN_NUM_INPUT_PORTS];
82039 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82040 };
82041 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82042 index ea995af..f1bfa37 100644
82043 --- a/sound/firewire/amdtp.c
82044 +++ b/sound/firewire/amdtp.c
82045 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82046 ptr = s->pcm_buffer_pointer + data_blocks;
82047 if (ptr >= pcm->runtime->buffer_size)
82048 ptr -= pcm->runtime->buffer_size;
82049 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82050 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82051
82052 s->pcm_period_pointer += data_blocks;
82053 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82054 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82055 */
82056 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82057 {
82058 - ACCESS_ONCE(s->source_node_id_field) =
82059 + ACCESS_ONCE_RW(s->source_node_id_field) =
82060 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82061 }
82062 EXPORT_SYMBOL(amdtp_out_stream_update);
82063 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82064 index b680c5e..061b7a0 100644
82065 --- a/sound/firewire/amdtp.h
82066 +++ b/sound/firewire/amdtp.h
82067 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82068 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82069 struct snd_pcm_substream *pcm)
82070 {
82071 - ACCESS_ONCE(s->pcm) = pcm;
82072 + ACCESS_ONCE_RW(s->pcm) = pcm;
82073 }
82074
82075 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82076 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82077 index d428ffe..751ef78 100644
82078 --- a/sound/firewire/isight.c
82079 +++ b/sound/firewire/isight.c
82080 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82081 ptr += count;
82082 if (ptr >= runtime->buffer_size)
82083 ptr -= runtime->buffer_size;
82084 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82085 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82086
82087 isight->period_counter += count;
82088 if (isight->period_counter >= runtime->period_size) {
82089 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82090 if (err < 0)
82091 return err;
82092
82093 - ACCESS_ONCE(isight->pcm_active) = true;
82094 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82095
82096 return 0;
82097 }
82098 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82099 {
82100 struct isight *isight = substream->private_data;
82101
82102 - ACCESS_ONCE(isight->pcm_active) = false;
82103 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82104
82105 mutex_lock(&isight->mutex);
82106 isight_stop_streaming(isight);
82107 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82108
82109 switch (cmd) {
82110 case SNDRV_PCM_TRIGGER_START:
82111 - ACCESS_ONCE(isight->pcm_running) = true;
82112 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82113 break;
82114 case SNDRV_PCM_TRIGGER_STOP:
82115 - ACCESS_ONCE(isight->pcm_running) = false;
82116 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82117 break;
82118 default:
82119 return -EINVAL;
82120 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82121 index 7bd5e33..1fcab12 100644
82122 --- a/sound/isa/cmi8330.c
82123 +++ b/sound/isa/cmi8330.c
82124 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82125
82126 struct snd_pcm *pcm;
82127 struct snd_cmi8330_stream {
82128 - struct snd_pcm_ops ops;
82129 + snd_pcm_ops_no_const ops;
82130 snd_pcm_open_callback_t open;
82131 void *private_data; /* sb or wss */
82132 } streams[2];
82133 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82134 index b2b3c01..e1c1e1f 100644
82135 --- a/sound/oss/sb_audio.c
82136 +++ b/sound/oss/sb_audio.c
82137 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
82138 buf16 = (signed short *)(localbuf + localoffs);
82139 while (c)
82140 {
82141 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82142 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82143 if (copy_from_user(lbuf8,
82144 userbuf+useroffs + p,
82145 locallen))
82146 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82147 index 7d8803a..559f8d0 100644
82148 --- a/sound/oss/swarm_cs4297a.c
82149 +++ b/sound/oss/swarm_cs4297a.c
82150 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
82151 {
82152 struct cs4297a_state *s;
82153 u32 pwr, id;
82154 - mm_segment_t fs;
82155 int rval;
82156 #ifndef CONFIG_BCM_CS4297A_CSWARM
82157 u64 cfg;
82158 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
82159 if (!rval) {
82160 char *sb1250_duart_present;
82161
82162 +#if 0
82163 + mm_segment_t fs;
82164 fs = get_fs();
82165 set_fs(KERNEL_DS);
82166 -#if 0
82167 val = SOUND_MASK_LINE;
82168 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82169 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82170 val = initvol[i].vol;
82171 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82172 }
82173 + set_fs(fs);
82174 // cs4297a_write_ac97(s, 0x18, 0x0808);
82175 #else
82176 // cs4297a_write_ac97(s, 0x5e, 0x180);
82177 cs4297a_write_ac97(s, 0x02, 0x0808);
82178 cs4297a_write_ac97(s, 0x18, 0x0808);
82179 #endif
82180 - set_fs(fs);
82181
82182 list_add(&s->list, &cs4297a_devs);
82183
82184 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82185 index e5a7e19..4049063 100644
82186 --- a/sound/pci/hda/hda_codec.h
82187 +++ b/sound/pci/hda/hda_codec.h
82188 @@ -614,7 +614,7 @@ struct hda_bus_ops {
82189 /* notify power-up/down from codec to controller */
82190 void (*pm_notify)(struct hda_bus *bus);
82191 #endif
82192 -};
82193 +} __no_const;
82194
82195 /* template to pass to the bus constructor */
82196 struct hda_bus_template {
82197 @@ -714,6 +714,7 @@ struct hda_codec_ops {
82198 #endif
82199 void (*reboot_notify)(struct hda_codec *codec);
82200 };
82201 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82202
82203 /* record for amp information cache */
82204 struct hda_cache_head {
82205 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
82206 struct snd_pcm_substream *substream);
82207 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82208 struct snd_pcm_substream *substream);
82209 -};
82210 +} __no_const;
82211
82212 /* PCM information for each substream */
82213 struct hda_pcm_stream {
82214 @@ -802,7 +803,7 @@ struct hda_codec {
82215 const char *modelname; /* model name for preset */
82216
82217 /* set by patch */
82218 - struct hda_codec_ops patch_ops;
82219 + hda_codec_ops_no_const patch_ops;
82220
82221 /* PCM to create, set by patch_ops.build_pcms callback */
82222 unsigned int num_pcms;
82223 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82224 index 0da778a..bc38b84 100644
82225 --- a/sound/pci/ice1712/ice1712.h
82226 +++ b/sound/pci/ice1712/ice1712.h
82227 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82228 unsigned int mask_flags; /* total mask bits */
82229 struct snd_akm4xxx_ops {
82230 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82231 - } ops;
82232 + } __no_const ops;
82233 };
82234
82235 struct snd_ice1712_spdif {
82236 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82237 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82238 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82239 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82240 - } ops;
82241 + } __no_const ops;
82242 };
82243
82244
82245 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
82246 index bddc405..2c0733c 100644
82247 --- a/sound/pci/ymfpci/ymfpci.h
82248 +++ b/sound/pci/ymfpci/ymfpci.h
82249 @@ -358,7 +358,7 @@ struct snd_ymfpci {
82250 spinlock_t reg_lock;
82251 spinlock_t voice_lock;
82252 wait_queue_head_t interrupt_sleep;
82253 - atomic_t interrupt_sleep_count;
82254 + atomic_unchecked_t interrupt_sleep_count;
82255 struct snd_info_entry *proc_entry;
82256 const struct firmware *dsp_microcode;
82257 const struct firmware *controller_microcode;
82258 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82259 index 62b2363..ee77972 100644
82260 --- a/sound/pci/ymfpci/ymfpci_main.c
82261 +++ b/sound/pci/ymfpci/ymfpci_main.c
82262 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82263 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82264 break;
82265 }
82266 - if (atomic_read(&chip->interrupt_sleep_count)) {
82267 - atomic_set(&chip->interrupt_sleep_count, 0);
82268 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82269 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82270 wake_up(&chip->interrupt_sleep);
82271 }
82272 __end:
82273 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82274 continue;
82275 init_waitqueue_entry(&wait, current);
82276 add_wait_queue(&chip->interrupt_sleep, &wait);
82277 - atomic_inc(&chip->interrupt_sleep_count);
82278 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82279 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82280 remove_wait_queue(&chip->interrupt_sleep, &wait);
82281 }
82282 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82283 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82284 spin_unlock(&chip->reg_lock);
82285
82286 - if (atomic_read(&chip->interrupt_sleep_count)) {
82287 - atomic_set(&chip->interrupt_sleep_count, 0);
82288 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82289 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82290 wake_up(&chip->interrupt_sleep);
82291 }
82292 }
82293 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82294 spin_lock_init(&chip->reg_lock);
82295 spin_lock_init(&chip->voice_lock);
82296 init_waitqueue_head(&chip->interrupt_sleep);
82297 - atomic_set(&chip->interrupt_sleep_count, 0);
82298 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82299 chip->card = card;
82300 chip->pci = pci;
82301 chip->irq = -1;
82302 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82303 new file mode 100644
82304 index 0000000..50f2f2f
82305 --- /dev/null
82306 +++ b/tools/gcc/.gitignore
82307 @@ -0,0 +1 @@
82308 +size_overflow_hash.h
82309 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82310 new file mode 100644
82311 index 0000000..1d09b7e
82312 --- /dev/null
82313 +++ b/tools/gcc/Makefile
82314 @@ -0,0 +1,43 @@
82315 +#CC := gcc
82316 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82317 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82318 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82319 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82320 +
82321 +ifeq ($(PLUGINCC),$(HOSTCC))
82322 +HOSTLIBS := hostlibs
82323 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82324 +else
82325 +HOSTLIBS := hostcxxlibs
82326 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82327 +endif
82328 +
82329 +$(HOSTLIBS)-y := constify_plugin.so
82330 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82331 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82332 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82333 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82334 +$(HOSTLIBS)-y += colorize_plugin.so
82335 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82336 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82337 +
82338 +always := $($(HOSTLIBS)-y)
82339 +
82340 +constify_plugin-objs := constify_plugin.o
82341 +stackleak_plugin-objs := stackleak_plugin.o
82342 +kallocstat_plugin-objs := kallocstat_plugin.o
82343 +kernexec_plugin-objs := kernexec_plugin.o
82344 +checker_plugin-objs := checker_plugin.o
82345 +colorize_plugin-objs := colorize_plugin.o
82346 +size_overflow_plugin-objs := size_overflow_plugin.o
82347 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82348 +
82349 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82350 +
82351 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82352 + cmd_build_size_overflow_hash = \
82353 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82354 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82355 + $(call if_changed,build_size_overflow_hash)
82356 +
82357 +targets += size_overflow_hash.h
82358 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82359 new file mode 100644
82360 index 0000000..d41b5af
82361 --- /dev/null
82362 +++ b/tools/gcc/checker_plugin.c
82363 @@ -0,0 +1,171 @@
82364 +/*
82365 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82366 + * Licensed under the GPL v2
82367 + *
82368 + * Note: the choice of the license means that the compilation process is
82369 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82370 + * but for the kernel it doesn't matter since it doesn't link against
82371 + * any of the gcc libraries
82372 + *
82373 + * gcc plugin to implement various sparse (source code checker) features
82374 + *
82375 + * TODO:
82376 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82377 + *
82378 + * BUGS:
82379 + * - none known
82380 + */
82381 +#include "gcc-plugin.h"
82382 +#include "config.h"
82383 +#include "system.h"
82384 +#include "coretypes.h"
82385 +#include "tree.h"
82386 +#include "tree-pass.h"
82387 +#include "flags.h"
82388 +#include "intl.h"
82389 +#include "toplev.h"
82390 +#include "plugin.h"
82391 +//#include "expr.h" where are you...
82392 +#include "diagnostic.h"
82393 +#include "plugin-version.h"
82394 +#include "tm.h"
82395 +#include "function.h"
82396 +#include "basic-block.h"
82397 +#include "gimple.h"
82398 +#include "rtl.h"
82399 +#include "emit-rtl.h"
82400 +#include "tree-flow.h"
82401 +#include "target.h"
82402 +
82403 +extern void c_register_addr_space (const char *str, addr_space_t as);
82404 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82405 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82406 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82407 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82408 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82409 +
82410 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82411 +extern rtx emit_move_insn(rtx x, rtx y);
82412 +
82413 +int plugin_is_GPL_compatible;
82414 +
82415 +static struct plugin_info checker_plugin_info = {
82416 + .version = "201111150100",
82417 +};
82418 +
82419 +#define ADDR_SPACE_KERNEL 0
82420 +#define ADDR_SPACE_FORCE_KERNEL 1
82421 +#define ADDR_SPACE_USER 2
82422 +#define ADDR_SPACE_FORCE_USER 3
82423 +#define ADDR_SPACE_IOMEM 0
82424 +#define ADDR_SPACE_FORCE_IOMEM 0
82425 +#define ADDR_SPACE_PERCPU 0
82426 +#define ADDR_SPACE_FORCE_PERCPU 0
82427 +#define ADDR_SPACE_RCU 0
82428 +#define ADDR_SPACE_FORCE_RCU 0
82429 +
82430 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82431 +{
82432 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82433 +}
82434 +
82435 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82436 +{
82437 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82438 +}
82439 +
82440 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82441 +{
82442 + return default_addr_space_valid_pointer_mode(mode, as);
82443 +}
82444 +
82445 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82446 +{
82447 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82448 +}
82449 +
82450 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82451 +{
82452 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82453 +}
82454 +
82455 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82456 +{
82457 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82458 + return true;
82459 +
82460 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82461 + return true;
82462 +
82463 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82464 + return true;
82465 +
82466 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82467 + return true;
82468 +
82469 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82470 + return true;
82471 +
82472 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82473 + return true;
82474 +
82475 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82476 + return true;
82477 +
82478 + return subset == superset;
82479 +}
82480 +
82481 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82482 +{
82483 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82484 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82485 +
82486 + return op;
82487 +}
82488 +
82489 +static void register_checker_address_spaces(void *event_data, void *data)
82490 +{
82491 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82492 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82493 + c_register_addr_space("__user", ADDR_SPACE_USER);
82494 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82495 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82496 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82497 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82498 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82499 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82500 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82501 +
82502 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82503 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82504 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82505 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82506 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82507 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82508 + targetm.addr_space.convert = checker_addr_space_convert;
82509 +}
82510 +
82511 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82512 +{
82513 + const char * const plugin_name = plugin_info->base_name;
82514 + const int argc = plugin_info->argc;
82515 + const struct plugin_argument * const argv = plugin_info->argv;
82516 + int i;
82517 +
82518 + if (!plugin_default_version_check(version, &gcc_version)) {
82519 + error(G_("incompatible gcc/plugin versions"));
82520 + return 1;
82521 + }
82522 +
82523 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82524 +
82525 + for (i = 0; i < argc; ++i)
82526 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82527 +
82528 + if (TARGET_64BIT == 0)
82529 + return 0;
82530 +
82531 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82532 +
82533 + return 0;
82534 +}
82535 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82536 new file mode 100644
82537 index 0000000..846aeb0
82538 --- /dev/null
82539 +++ b/tools/gcc/colorize_plugin.c
82540 @@ -0,0 +1,148 @@
82541 +/*
82542 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82543 + * Licensed under the GPL v2
82544 + *
82545 + * Note: the choice of the license means that the compilation process is
82546 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82547 + * but for the kernel it doesn't matter since it doesn't link against
82548 + * any of the gcc libraries
82549 + *
82550 + * gcc plugin to colorize diagnostic output
82551 + *
82552 + */
82553 +
82554 +#include "gcc-plugin.h"
82555 +#include "config.h"
82556 +#include "system.h"
82557 +#include "coretypes.h"
82558 +#include "tree.h"
82559 +#include "tree-pass.h"
82560 +#include "flags.h"
82561 +#include "intl.h"
82562 +#include "toplev.h"
82563 +#include "plugin.h"
82564 +#include "diagnostic.h"
82565 +#include "plugin-version.h"
82566 +#include "tm.h"
82567 +
82568 +int plugin_is_GPL_compatible;
82569 +
82570 +static struct plugin_info colorize_plugin_info = {
82571 + .version = "201203092200",
82572 + .help = NULL,
82573 +};
82574 +
82575 +#define GREEN "\033[32m\033[2m"
82576 +#define LIGHTGREEN "\033[32m\033[1m"
82577 +#define YELLOW "\033[33m\033[2m"
82578 +#define LIGHTYELLOW "\033[33m\033[1m"
82579 +#define RED "\033[31m\033[2m"
82580 +#define LIGHTRED "\033[31m\033[1m"
82581 +#define BLUE "\033[34m\033[2m"
82582 +#define LIGHTBLUE "\033[34m\033[1m"
82583 +#define BRIGHT "\033[m\033[1m"
82584 +#define NORMAL "\033[m"
82585 +
82586 +static diagnostic_starter_fn old_starter;
82587 +static diagnostic_finalizer_fn old_finalizer;
82588 +
82589 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82590 +{
82591 + const char *color;
82592 + char *newprefix;
82593 +
82594 + switch (diagnostic->kind) {
82595 + case DK_NOTE:
82596 + color = LIGHTBLUE;
82597 + break;
82598 +
82599 + case DK_PEDWARN:
82600 + case DK_WARNING:
82601 + color = LIGHTYELLOW;
82602 + break;
82603 +
82604 + case DK_ERROR:
82605 + case DK_FATAL:
82606 + case DK_ICE:
82607 + case DK_PERMERROR:
82608 + case DK_SORRY:
82609 + color = LIGHTRED;
82610 + break;
82611 +
82612 + default:
82613 + color = NORMAL;
82614 + }
82615 +
82616 + old_starter(context, diagnostic);
82617 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82618 + return;
82619 + pp_destroy_prefix(context->printer);
82620 + pp_set_prefix(context->printer, newprefix);
82621 +}
82622 +
82623 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82624 +{
82625 + old_finalizer(context, diagnostic);
82626 +}
82627 +
82628 +static void colorize_arm(void)
82629 +{
82630 + old_starter = diagnostic_starter(global_dc);
82631 + old_finalizer = diagnostic_finalizer(global_dc);
82632 +
82633 + diagnostic_starter(global_dc) = start_colorize;
82634 + diagnostic_finalizer(global_dc) = finalize_colorize;
82635 +}
82636 +
82637 +static unsigned int execute_colorize_rearm(void)
82638 +{
82639 + if (diagnostic_starter(global_dc) == start_colorize)
82640 + return 0;
82641 +
82642 + colorize_arm();
82643 + return 0;
82644 +}
82645 +
82646 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82647 + .pass = {
82648 + .type = SIMPLE_IPA_PASS,
82649 + .name = "colorize_rearm",
82650 + .gate = NULL,
82651 + .execute = execute_colorize_rearm,
82652 + .sub = NULL,
82653 + .next = NULL,
82654 + .static_pass_number = 0,
82655 + .tv_id = TV_NONE,
82656 + .properties_required = 0,
82657 + .properties_provided = 0,
82658 + .properties_destroyed = 0,
82659 + .todo_flags_start = 0,
82660 + .todo_flags_finish = 0
82661 + }
82662 +};
82663 +
82664 +static void colorize_start_unit(void *gcc_data, void *user_data)
82665 +{
82666 + colorize_arm();
82667 +}
82668 +
82669 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82670 +{
82671 + const char * const plugin_name = plugin_info->base_name;
82672 + struct register_pass_info colorize_rearm_pass_info = {
82673 + .pass = &pass_ipa_colorize_rearm.pass,
82674 + .reference_pass_name = "*free_lang_data",
82675 + .ref_pass_instance_number = 1,
82676 + .pos_op = PASS_POS_INSERT_AFTER
82677 + };
82678 +
82679 + if (!plugin_default_version_check(version, &gcc_version)) {
82680 + error(G_("incompatible gcc/plugin versions"));
82681 + return 1;
82682 + }
82683 +
82684 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82685 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82686 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82687 + return 0;
82688 +}
82689 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82690 new file mode 100644
82691 index 0000000..92ed719
82692 --- /dev/null
82693 +++ b/tools/gcc/constify_plugin.c
82694 @@ -0,0 +1,331 @@
82695 +/*
82696 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82697 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82698 + * Licensed under the GPL v2, or (at your option) v3
82699 + *
82700 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82701 + *
82702 + * Homepage:
82703 + * http://www.grsecurity.net/~ephox/const_plugin/
82704 + *
82705 + * Usage:
82706 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82707 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82708 + */
82709 +
82710 +#include "gcc-plugin.h"
82711 +#include "config.h"
82712 +#include "system.h"
82713 +#include "coretypes.h"
82714 +#include "tree.h"
82715 +#include "tree-pass.h"
82716 +#include "flags.h"
82717 +#include "intl.h"
82718 +#include "toplev.h"
82719 +#include "plugin.h"
82720 +#include "diagnostic.h"
82721 +#include "plugin-version.h"
82722 +#include "tm.h"
82723 +#include "function.h"
82724 +#include "basic-block.h"
82725 +#include "gimple.h"
82726 +#include "rtl.h"
82727 +#include "emit-rtl.h"
82728 +#include "tree-flow.h"
82729 +
82730 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82731 +
82732 +int plugin_is_GPL_compatible;
82733 +
82734 +static struct plugin_info const_plugin_info = {
82735 + .version = "201205300030",
82736 + .help = "no-constify\tturn off constification\n",
82737 +};
82738 +
82739 +static void deconstify_tree(tree node);
82740 +
82741 +static void deconstify_type(tree type)
82742 +{
82743 + tree field;
82744 +
82745 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82746 + tree type = TREE_TYPE(field);
82747 +
82748 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82749 + continue;
82750 + if (!TYPE_READONLY(type))
82751 + continue;
82752 +
82753 + deconstify_tree(field);
82754 + }
82755 + TYPE_READONLY(type) = 0;
82756 + C_TYPE_FIELDS_READONLY(type) = 0;
82757 +}
82758 +
82759 +static void deconstify_tree(tree node)
82760 +{
82761 + tree old_type, new_type, field;
82762 +
82763 + old_type = TREE_TYPE(node);
82764 +
82765 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82766 +
82767 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82768 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82769 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82770 + DECL_FIELD_CONTEXT(field) = new_type;
82771 +
82772 + deconstify_type(new_type);
82773 +
82774 + TREE_READONLY(node) = 0;
82775 + TREE_TYPE(node) = new_type;
82776 +}
82777 +
82778 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82779 +{
82780 + tree type;
82781 +
82782 + *no_add_attrs = true;
82783 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82784 + error("%qE attribute does not apply to functions", name);
82785 + return NULL_TREE;
82786 + }
82787 +
82788 + if (TREE_CODE(*node) == VAR_DECL) {
82789 + error("%qE attribute does not apply to variables", name);
82790 + return NULL_TREE;
82791 + }
82792 +
82793 + if (TYPE_P(*node)) {
82794 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82795 + *no_add_attrs = false;
82796 + else
82797 + error("%qE attribute applies to struct and union types only", name);
82798 + return NULL_TREE;
82799 + }
82800 +
82801 + type = TREE_TYPE(*node);
82802 +
82803 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82804 + error("%qE attribute applies to struct and union types only", name);
82805 + return NULL_TREE;
82806 + }
82807 +
82808 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82809 + error("%qE attribute is already applied to the type", name);
82810 + return NULL_TREE;
82811 + }
82812 +
82813 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82814 + error("%qE attribute used on type that is not constified", name);
82815 + return NULL_TREE;
82816 + }
82817 +
82818 + if (TREE_CODE(*node) == TYPE_DECL) {
82819 + deconstify_tree(*node);
82820 + return NULL_TREE;
82821 + }
82822 +
82823 + return NULL_TREE;
82824 +}
82825 +
82826 +static void constify_type(tree type)
82827 +{
82828 + TYPE_READONLY(type) = 1;
82829 + C_TYPE_FIELDS_READONLY(type) = 1;
82830 +}
82831 +
82832 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82833 +{
82834 + *no_add_attrs = true;
82835 + if (!TYPE_P(*node)) {
82836 + error("%qE attribute applies to types only", name);
82837 + return NULL_TREE;
82838 + }
82839 +
82840 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82841 + error("%qE attribute applies to struct and union types only", name);
82842 + return NULL_TREE;
82843 + }
82844 +
82845 + *no_add_attrs = false;
82846 + constify_type(*node);
82847 + return NULL_TREE;
82848 +}
82849 +
82850 +static struct attribute_spec no_const_attr = {
82851 + .name = "no_const",
82852 + .min_length = 0,
82853 + .max_length = 0,
82854 + .decl_required = false,
82855 + .type_required = false,
82856 + .function_type_required = false,
82857 + .handler = handle_no_const_attribute,
82858 +#if BUILDING_GCC_VERSION >= 4007
82859 + .affects_type_identity = true
82860 +#endif
82861 +};
82862 +
82863 +static struct attribute_spec do_const_attr = {
82864 + .name = "do_const",
82865 + .min_length = 0,
82866 + .max_length = 0,
82867 + .decl_required = false,
82868 + .type_required = false,
82869 + .function_type_required = false,
82870 + .handler = handle_do_const_attribute,
82871 +#if BUILDING_GCC_VERSION >= 4007
82872 + .affects_type_identity = true
82873 +#endif
82874 +};
82875 +
82876 +static void register_attributes(void *event_data, void *data)
82877 +{
82878 + register_attribute(&no_const_attr);
82879 + register_attribute(&do_const_attr);
82880 +}
82881 +
82882 +static bool is_fptr(tree field)
82883 +{
82884 + tree ptr = TREE_TYPE(field);
82885 +
82886 + if (TREE_CODE(ptr) != POINTER_TYPE)
82887 + return false;
82888 +
82889 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82890 +}
82891 +
82892 +static bool walk_struct(tree node)
82893 +{
82894 + tree field;
82895 +
82896 + if (TYPE_FIELDS(node) == NULL_TREE)
82897 + return false;
82898 +
82899 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82900 + gcc_assert(!TYPE_READONLY(node));
82901 + deconstify_type(node);
82902 + return false;
82903 + }
82904 +
82905 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82906 + tree type = TREE_TYPE(field);
82907 + enum tree_code code = TREE_CODE(type);
82908 +
82909 + if (node == type)
82910 + return false;
82911 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82912 + if (!(walk_struct(type)))
82913 + return false;
82914 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82915 + return false;
82916 + }
82917 + return true;
82918 +}
82919 +
82920 +static void finish_type(void *event_data, void *data)
82921 +{
82922 + tree type = (tree)event_data;
82923 +
82924 + if (type == NULL_TREE || type == error_mark_node)
82925 + return;
82926 +
82927 + if (TYPE_READONLY(type))
82928 + return;
82929 +
82930 + if (walk_struct(type))
82931 + constify_type(type);
82932 +}
82933 +
82934 +static unsigned int check_local_variables(void);
82935 +
82936 +struct gimple_opt_pass pass_local_variable = {
82937 + {
82938 + .type = GIMPLE_PASS,
82939 + .name = "check_local_variables",
82940 + .gate = NULL,
82941 + .execute = check_local_variables,
82942 + .sub = NULL,
82943 + .next = NULL,
82944 + .static_pass_number = 0,
82945 + .tv_id = TV_NONE,
82946 + .properties_required = 0,
82947 + .properties_provided = 0,
82948 + .properties_destroyed = 0,
82949 + .todo_flags_start = 0,
82950 + .todo_flags_finish = 0
82951 + }
82952 +};
82953 +
82954 +static unsigned int check_local_variables(void)
82955 +{
82956 + tree var;
82957 + referenced_var_iterator rvi;
82958 +
82959 +#if BUILDING_GCC_VERSION == 4005
82960 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82961 +#else
82962 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82963 +#endif
82964 + tree type = TREE_TYPE(var);
82965 +
82966 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82967 + continue;
82968 +
82969 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82970 + continue;
82971 +
82972 + if (!TYPE_READONLY(type))
82973 + continue;
82974 +
82975 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82976 +// continue;
82977 +
82978 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82979 +// continue;
82980 +
82981 + if (walk_struct(type)) {
82982 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82983 + return 1;
82984 + }
82985 + }
82986 + return 0;
82987 +}
82988 +
82989 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82990 +{
82991 + const char * const plugin_name = plugin_info->base_name;
82992 + const int argc = plugin_info->argc;
82993 + const struct plugin_argument * const argv = plugin_info->argv;
82994 + int i;
82995 + bool constify = true;
82996 +
82997 + struct register_pass_info local_variable_pass_info = {
82998 + .pass = &pass_local_variable.pass,
82999 + .reference_pass_name = "*referenced_vars",
83000 + .ref_pass_instance_number = 1,
83001 + .pos_op = PASS_POS_INSERT_AFTER
83002 + };
83003 +
83004 + if (!plugin_default_version_check(version, &gcc_version)) {
83005 + error(G_("incompatible gcc/plugin versions"));
83006 + return 1;
83007 + }
83008 +
83009 + for (i = 0; i < argc; ++i) {
83010 + if (!(strcmp(argv[i].key, "no-constify"))) {
83011 + constify = false;
83012 + continue;
83013 + }
83014 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83015 + }
83016 +
83017 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83018 + if (constify) {
83019 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83020 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83021 + }
83022 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83023 +
83024 + return 0;
83025 +}
83026 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83027 new file mode 100644
83028 index 0000000..02c6bec
83029 --- /dev/null
83030 +++ b/tools/gcc/generate_size_overflow_hash.sh
83031 @@ -0,0 +1,94 @@
83032 +#!/bin/bash
83033 +
83034 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83035 +
83036 +header1="size_overflow_hash.h"
83037 +database="size_overflow_hash.data"
83038 +n=65536
83039 +
83040 +usage() {
83041 +cat <<EOF
83042 +usage: $0 options
83043 +OPTIONS:
83044 + -h|--help help
83045 + -o header file
83046 + -d database file
83047 + -n hash array size
83048 +EOF
83049 + return 0
83050 +}
83051 +
83052 +while true
83053 +do
83054 + case "$1" in
83055 + -h|--help) usage && exit 0;;
83056 + -n) n=$2; shift 2;;
83057 + -o) header1="$2"; shift 2;;
83058 + -d) database="$2"; shift 2;;
83059 + --) shift 1; break ;;
83060 + *) break ;;
83061 + esac
83062 +done
83063 +
83064 +create_defines() {
83065 + for i in `seq 1 32`
83066 + do
83067 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83068 + done
83069 + echo >> "$header1"
83070 +}
83071 +
83072 +create_structs () {
83073 + rm -f "$header1"
83074 +
83075 + create_defines
83076 +
83077 + cat "$database" | while read data
83078 + do
83079 + data_array=($data)
83080 + struct_hash_name="${data_array[0]}"
83081 + funcn="${data_array[1]}"
83082 + params="${data_array[2]}"
83083 + next="${data_array[5]}"
83084 +
83085 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83086 +
83087 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83088 + echo -en "\t.param\t= " >> "$header1"
83089 + line=
83090 + for param_num in ${params//-/ };
83091 + do
83092 + line="${line}PARAM"$param_num"|"
83093 + done
83094 +
83095 + echo -e "${line%?},\n};\n" >> "$header1"
83096 + done
83097 +}
83098 +
83099 +create_headers () {
83100 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83101 +}
83102 +
83103 +create_array_elements () {
83104 + index=0
83105 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83106 + do
83107 + data_array=($data)
83108 + i="${data_array[3]}"
83109 + hash="${data_array[4]}"
83110 + while [[ $index -lt $i ]]
83111 + do
83112 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83113 + index=$(($index + 1))
83114 + done
83115 + index=$(($index + 1))
83116 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83117 + done
83118 + echo '};' >> $header1
83119 +}
83120 +
83121 +create_structs
83122 +create_headers
83123 +create_array_elements
83124 +
83125 +exit 0
83126 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83127 new file mode 100644
83128 index 0000000..a86e422
83129 --- /dev/null
83130 +++ b/tools/gcc/kallocstat_plugin.c
83131 @@ -0,0 +1,167 @@
83132 +/*
83133 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83134 + * Licensed under the GPL v2
83135 + *
83136 + * Note: the choice of the license means that the compilation process is
83137 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83138 + * but for the kernel it doesn't matter since it doesn't link against
83139 + * any of the gcc libraries
83140 + *
83141 + * gcc plugin to find the distribution of k*alloc sizes
83142 + *
83143 + * TODO:
83144 + *
83145 + * BUGS:
83146 + * - none known
83147 + */
83148 +#include "gcc-plugin.h"
83149 +#include "config.h"
83150 +#include "system.h"
83151 +#include "coretypes.h"
83152 +#include "tree.h"
83153 +#include "tree-pass.h"
83154 +#include "flags.h"
83155 +#include "intl.h"
83156 +#include "toplev.h"
83157 +#include "plugin.h"
83158 +//#include "expr.h" where are you...
83159 +#include "diagnostic.h"
83160 +#include "plugin-version.h"
83161 +#include "tm.h"
83162 +#include "function.h"
83163 +#include "basic-block.h"
83164 +#include "gimple.h"
83165 +#include "rtl.h"
83166 +#include "emit-rtl.h"
83167 +
83168 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83169 +
83170 +int plugin_is_GPL_compatible;
83171 +
83172 +static const char * const kalloc_functions[] = {
83173 + "__kmalloc",
83174 + "kmalloc",
83175 + "kmalloc_large",
83176 + "kmalloc_node",
83177 + "kmalloc_order",
83178 + "kmalloc_order_trace",
83179 + "kmalloc_slab",
83180 + "kzalloc",
83181 + "kzalloc_node",
83182 +};
83183 +
83184 +static struct plugin_info kallocstat_plugin_info = {
83185 + .version = "201111150100",
83186 +};
83187 +
83188 +static unsigned int execute_kallocstat(void);
83189 +
83190 +static struct gimple_opt_pass kallocstat_pass = {
83191 + .pass = {
83192 + .type = GIMPLE_PASS,
83193 + .name = "kallocstat",
83194 + .gate = NULL,
83195 + .execute = execute_kallocstat,
83196 + .sub = NULL,
83197 + .next = NULL,
83198 + .static_pass_number = 0,
83199 + .tv_id = TV_NONE,
83200 + .properties_required = 0,
83201 + .properties_provided = 0,
83202 + .properties_destroyed = 0,
83203 + .todo_flags_start = 0,
83204 + .todo_flags_finish = 0
83205 + }
83206 +};
83207 +
83208 +static bool is_kalloc(const char *fnname)
83209 +{
83210 + size_t i;
83211 +
83212 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83213 + if (!strcmp(fnname, kalloc_functions[i]))
83214 + return true;
83215 + return false;
83216 +}
83217 +
83218 +static unsigned int execute_kallocstat(void)
83219 +{
83220 + basic_block bb;
83221 +
83222 + // 1. loop through BBs and GIMPLE statements
83223 + FOR_EACH_BB(bb) {
83224 + gimple_stmt_iterator gsi;
83225 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83226 + // gimple match:
83227 + tree fndecl, size;
83228 + gimple call_stmt;
83229 + const char *fnname;
83230 +
83231 + // is it a call
83232 + call_stmt = gsi_stmt(gsi);
83233 + if (!is_gimple_call(call_stmt))
83234 + continue;
83235 + fndecl = gimple_call_fndecl(call_stmt);
83236 + if (fndecl == NULL_TREE)
83237 + continue;
83238 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83239 + continue;
83240 +
83241 + // is it a call to k*alloc
83242 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83243 + if (!is_kalloc(fnname))
83244 + continue;
83245 +
83246 + // is the size arg the result of a simple const assignment
83247 + size = gimple_call_arg(call_stmt, 0);
83248 + while (true) {
83249 + gimple def_stmt;
83250 + expanded_location xloc;
83251 + size_t size_val;
83252 +
83253 + if (TREE_CODE(size) != SSA_NAME)
83254 + break;
83255 + def_stmt = SSA_NAME_DEF_STMT(size);
83256 + if (!def_stmt || !is_gimple_assign(def_stmt))
83257 + break;
83258 + if (gimple_num_ops(def_stmt) != 2)
83259 + break;
83260 + size = gimple_assign_rhs1(def_stmt);
83261 + if (!TREE_CONSTANT(size))
83262 + continue;
83263 + xloc = expand_location(gimple_location(def_stmt));
83264 + if (!xloc.file)
83265 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83266 + size_val = TREE_INT_CST_LOW(size);
83267 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83268 + break;
83269 + }
83270 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83271 +//debug_tree(gimple_call_fn(call_stmt));
83272 +//print_node(stderr, "pax", fndecl, 4);
83273 + }
83274 + }
83275 +
83276 + return 0;
83277 +}
83278 +
83279 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83280 +{
83281 + const char * const plugin_name = plugin_info->base_name;
83282 + struct register_pass_info kallocstat_pass_info = {
83283 + .pass = &kallocstat_pass.pass,
83284 + .reference_pass_name = "ssa",
83285 + .ref_pass_instance_number = 1,
83286 + .pos_op = PASS_POS_INSERT_AFTER
83287 + };
83288 +
83289 + if (!plugin_default_version_check(version, &gcc_version)) {
83290 + error(G_("incompatible gcc/plugin versions"));
83291 + return 1;
83292 + }
83293 +
83294 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83295 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83296 +
83297 + return 0;
83298 +}
83299 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83300 new file mode 100644
83301 index 0000000..98011fa
83302 --- /dev/null
83303 +++ b/tools/gcc/kernexec_plugin.c
83304 @@ -0,0 +1,427 @@
83305 +/*
83306 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83307 + * Licensed under the GPL v2
83308 + *
83309 + * Note: the choice of the license means that the compilation process is
83310 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83311 + * but for the kernel it doesn't matter since it doesn't link against
83312 + * any of the gcc libraries
83313 + *
83314 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83315 + *
83316 + * TODO:
83317 + *
83318 + * BUGS:
83319 + * - none known
83320 + */
83321 +#include "gcc-plugin.h"
83322 +#include "config.h"
83323 +#include "system.h"
83324 +#include "coretypes.h"
83325 +#include "tree.h"
83326 +#include "tree-pass.h"
83327 +#include "flags.h"
83328 +#include "intl.h"
83329 +#include "toplev.h"
83330 +#include "plugin.h"
83331 +//#include "expr.h" where are you...
83332 +#include "diagnostic.h"
83333 +#include "plugin-version.h"
83334 +#include "tm.h"
83335 +#include "function.h"
83336 +#include "basic-block.h"
83337 +#include "gimple.h"
83338 +#include "rtl.h"
83339 +#include "emit-rtl.h"
83340 +#include "tree-flow.h"
83341 +
83342 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83343 +extern rtx emit_move_insn(rtx x, rtx y);
83344 +
83345 +int plugin_is_GPL_compatible;
83346 +
83347 +static struct plugin_info kernexec_plugin_info = {
83348 + .version = "201111291120",
83349 + .help = "method=[bts|or]\tinstrumentation method\n"
83350 +};
83351 +
83352 +static unsigned int execute_kernexec_reload(void);
83353 +static unsigned int execute_kernexec_fptr(void);
83354 +static unsigned int execute_kernexec_retaddr(void);
83355 +static bool kernexec_cmodel_check(void);
83356 +
83357 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83358 +static void (*kernexec_instrument_retaddr)(rtx);
83359 +
83360 +static struct gimple_opt_pass kernexec_reload_pass = {
83361 + .pass = {
83362 + .type = GIMPLE_PASS,
83363 + .name = "kernexec_reload",
83364 + .gate = kernexec_cmodel_check,
83365 + .execute = execute_kernexec_reload,
83366 + .sub = NULL,
83367 + .next = NULL,
83368 + .static_pass_number = 0,
83369 + .tv_id = TV_NONE,
83370 + .properties_required = 0,
83371 + .properties_provided = 0,
83372 + .properties_destroyed = 0,
83373 + .todo_flags_start = 0,
83374 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83375 + }
83376 +};
83377 +
83378 +static struct gimple_opt_pass kernexec_fptr_pass = {
83379 + .pass = {
83380 + .type = GIMPLE_PASS,
83381 + .name = "kernexec_fptr",
83382 + .gate = kernexec_cmodel_check,
83383 + .execute = execute_kernexec_fptr,
83384 + .sub = NULL,
83385 + .next = NULL,
83386 + .static_pass_number = 0,
83387 + .tv_id = TV_NONE,
83388 + .properties_required = 0,
83389 + .properties_provided = 0,
83390 + .properties_destroyed = 0,
83391 + .todo_flags_start = 0,
83392 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83393 + }
83394 +};
83395 +
83396 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83397 + .pass = {
83398 + .type = RTL_PASS,
83399 + .name = "kernexec_retaddr",
83400 + .gate = kernexec_cmodel_check,
83401 + .execute = execute_kernexec_retaddr,
83402 + .sub = NULL,
83403 + .next = NULL,
83404 + .static_pass_number = 0,
83405 + .tv_id = TV_NONE,
83406 + .properties_required = 0,
83407 + .properties_provided = 0,
83408 + .properties_destroyed = 0,
83409 + .todo_flags_start = 0,
83410 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83411 + }
83412 +};
83413 +
83414 +static bool kernexec_cmodel_check(void)
83415 +{
83416 + tree section;
83417 +
83418 + if (ix86_cmodel != CM_KERNEL)
83419 + return false;
83420 +
83421 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83422 + if (!section || !TREE_VALUE(section))
83423 + return true;
83424 +
83425 + section = TREE_VALUE(TREE_VALUE(section));
83426 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83427 + return true;
83428 +
83429 + return false;
83430 +}
83431 +
83432 +/*
83433 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83434 + */
83435 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83436 +{
83437 + gimple asm_movabs_stmt;
83438 +
83439 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83440 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83441 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83442 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83443 + update_stmt(asm_movabs_stmt);
83444 +}
83445 +
83446 +/*
83447 + * find all asm() stmts that clobber r10 and add a reload of r10
83448 + */
83449 +static unsigned int execute_kernexec_reload(void)
83450 +{
83451 + basic_block bb;
83452 +
83453 + // 1. loop through BBs and GIMPLE statements
83454 + FOR_EACH_BB(bb) {
83455 + gimple_stmt_iterator gsi;
83456 +
83457 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83458 + // gimple match: __asm__ ("" : : : "r10");
83459 + gimple asm_stmt;
83460 + size_t nclobbers;
83461 +
83462 + // is it an asm ...
83463 + asm_stmt = gsi_stmt(gsi);
83464 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83465 + continue;
83466 +
83467 + // ... clobbering r10
83468 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83469 + while (nclobbers--) {
83470 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83471 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83472 + continue;
83473 + kernexec_reload_fptr_mask(&gsi);
83474 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83475 + break;
83476 + }
83477 + }
83478 + }
83479 +
83480 + return 0;
83481 +}
83482 +
83483 +/*
83484 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83485 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83486 + */
83487 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83488 +{
83489 + gimple assign_intptr, assign_new_fptr, call_stmt;
83490 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83491 +
83492 + call_stmt = gsi_stmt(*gsi);
83493 + old_fptr = gimple_call_fn(call_stmt);
83494 +
83495 + // create temporary unsigned long variable used for bitops and cast fptr to it
83496 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83497 + add_referenced_var(intptr);
83498 + mark_sym_for_renaming(intptr);
83499 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83500 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83501 + update_stmt(assign_intptr);
83502 +
83503 + // apply logical or to temporary unsigned long and bitmask
83504 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83505 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83506 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83507 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83508 + update_stmt(assign_intptr);
83509 +
83510 + // cast temporary unsigned long back to a temporary fptr variable
83511 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83512 + add_referenced_var(new_fptr);
83513 + mark_sym_for_renaming(new_fptr);
83514 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83515 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83516 + update_stmt(assign_new_fptr);
83517 +
83518 + // replace call stmt fn with the new fptr
83519 + gimple_call_set_fn(call_stmt, new_fptr);
83520 + update_stmt(call_stmt);
83521 +}
83522 +
83523 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83524 +{
83525 + gimple asm_or_stmt, call_stmt;
83526 + tree old_fptr, new_fptr, input, output;
83527 + VEC(tree, gc) *inputs = NULL;
83528 + VEC(tree, gc) *outputs = NULL;
83529 +
83530 + call_stmt = gsi_stmt(*gsi);
83531 + old_fptr = gimple_call_fn(call_stmt);
83532 +
83533 + // create temporary fptr variable
83534 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83535 + add_referenced_var(new_fptr);
83536 + mark_sym_for_renaming(new_fptr);
83537 +
83538 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83539 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83540 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83541 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83542 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83543 + VEC_safe_push(tree, gc, inputs, input);
83544 + VEC_safe_push(tree, gc, outputs, output);
83545 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83546 + gimple_asm_set_volatile(asm_or_stmt, true);
83547 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83548 + update_stmt(asm_or_stmt);
83549 +
83550 + // replace call stmt fn with the new fptr
83551 + gimple_call_set_fn(call_stmt, new_fptr);
83552 + update_stmt(call_stmt);
83553 +}
83554 +
83555 +/*
83556 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83557 + */
83558 +static unsigned int execute_kernexec_fptr(void)
83559 +{
83560 + basic_block bb;
83561 +
83562 + // 1. loop through BBs and GIMPLE statements
83563 + FOR_EACH_BB(bb) {
83564 + gimple_stmt_iterator gsi;
83565 +
83566 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83567 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83568 + tree fn;
83569 + gimple call_stmt;
83570 +
83571 + // is it a call ...
83572 + call_stmt = gsi_stmt(gsi);
83573 + if (!is_gimple_call(call_stmt))
83574 + continue;
83575 + fn = gimple_call_fn(call_stmt);
83576 + if (TREE_CODE(fn) == ADDR_EXPR)
83577 + continue;
83578 + if (TREE_CODE(fn) != SSA_NAME)
83579 + gcc_unreachable();
83580 +
83581 + // ... through a function pointer
83582 + fn = SSA_NAME_VAR(fn);
83583 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83584 + continue;
83585 + fn = TREE_TYPE(fn);
83586 + if (TREE_CODE(fn) != POINTER_TYPE)
83587 + continue;
83588 + fn = TREE_TYPE(fn);
83589 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83590 + continue;
83591 +
83592 + kernexec_instrument_fptr(&gsi);
83593 +
83594 +//debug_tree(gimple_call_fn(call_stmt));
83595 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83596 + }
83597 + }
83598 +
83599 + return 0;
83600 +}
83601 +
83602 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83603 +static void kernexec_instrument_retaddr_bts(rtx insn)
83604 +{
83605 + rtx btsq;
83606 + rtvec argvec, constraintvec, labelvec;
83607 + int line;
83608 +
83609 + // create asm volatile("btsq $63,(%%rsp)":::)
83610 + argvec = rtvec_alloc(0);
83611 + constraintvec = rtvec_alloc(0);
83612 + labelvec = rtvec_alloc(0);
83613 + line = expand_location(RTL_LOCATION(insn)).line;
83614 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83615 + MEM_VOLATILE_P(btsq) = 1;
83616 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83617 + emit_insn_before(btsq, insn);
83618 +}
83619 +
83620 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83621 +static void kernexec_instrument_retaddr_or(rtx insn)
83622 +{
83623 + rtx orq;
83624 + rtvec argvec, constraintvec, labelvec;
83625 + int line;
83626 +
83627 + // create asm volatile("orq %%r10,(%%rsp)":::)
83628 + argvec = rtvec_alloc(0);
83629 + constraintvec = rtvec_alloc(0);
83630 + labelvec = rtvec_alloc(0);
83631 + line = expand_location(RTL_LOCATION(insn)).line;
83632 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83633 + MEM_VOLATILE_P(orq) = 1;
83634 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83635 + emit_insn_before(orq, insn);
83636 +}
83637 +
83638 +/*
83639 + * find all asm level function returns and forcibly set the highest bit of the return address
83640 + */
83641 +static unsigned int execute_kernexec_retaddr(void)
83642 +{
83643 + rtx insn;
83644 +
83645 + // 1. find function returns
83646 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83647 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83648 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83649 + rtx body;
83650 +
83651 + // is it a retn
83652 + if (!JUMP_P(insn))
83653 + continue;
83654 + body = PATTERN(insn);
83655 + if (GET_CODE(body) == PARALLEL)
83656 + body = XVECEXP(body, 0, 0);
83657 + if (GET_CODE(body) != RETURN)
83658 + continue;
83659 + kernexec_instrument_retaddr(insn);
83660 + }
83661 +
83662 +// print_simple_rtl(stderr, get_insns());
83663 +// print_rtl(stderr, get_insns());
83664 +
83665 + return 0;
83666 +}
83667 +
83668 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83669 +{
83670 + const char * const plugin_name = plugin_info->base_name;
83671 + const int argc = plugin_info->argc;
83672 + const struct plugin_argument * const argv = plugin_info->argv;
83673 + int i;
83674 + struct register_pass_info kernexec_reload_pass_info = {
83675 + .pass = &kernexec_reload_pass.pass,
83676 + .reference_pass_name = "ssa",
83677 + .ref_pass_instance_number = 1,
83678 + .pos_op = PASS_POS_INSERT_AFTER
83679 + };
83680 + struct register_pass_info kernexec_fptr_pass_info = {
83681 + .pass = &kernexec_fptr_pass.pass,
83682 + .reference_pass_name = "ssa",
83683 + .ref_pass_instance_number = 1,
83684 + .pos_op = PASS_POS_INSERT_AFTER
83685 + };
83686 + struct register_pass_info kernexec_retaddr_pass_info = {
83687 + .pass = &kernexec_retaddr_pass.pass,
83688 + .reference_pass_name = "pro_and_epilogue",
83689 + .ref_pass_instance_number = 1,
83690 + .pos_op = PASS_POS_INSERT_AFTER
83691 + };
83692 +
83693 + if (!plugin_default_version_check(version, &gcc_version)) {
83694 + error(G_("incompatible gcc/plugin versions"));
83695 + return 1;
83696 + }
83697 +
83698 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83699 +
83700 + if (TARGET_64BIT == 0)
83701 + return 0;
83702 +
83703 + for (i = 0; i < argc; ++i) {
83704 + if (!strcmp(argv[i].key, "method")) {
83705 + if (!argv[i].value) {
83706 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83707 + continue;
83708 + }
83709 + if (!strcmp(argv[i].value, "bts")) {
83710 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83711 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83712 + } else if (!strcmp(argv[i].value, "or")) {
83713 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83714 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83715 + fix_register("r10", 1, 1);
83716 + } else
83717 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83718 + continue;
83719 + }
83720 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83721 + }
83722 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83723 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83724 +
83725 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83726 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83727 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83728 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83729 +
83730 + return 0;
83731 +}
83732 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83733 new file mode 100644
83734 index 0000000..b8008f7
83735 --- /dev/null
83736 +++ b/tools/gcc/latent_entropy_plugin.c
83737 @@ -0,0 +1,295 @@
83738 +/*
83739 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83740 + * Licensed under the GPL v2
83741 + *
83742 + * Note: the choice of the license means that the compilation process is
83743 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83744 + * but for the kernel it doesn't matter since it doesn't link against
83745 + * any of the gcc libraries
83746 + *
83747 + * gcc plugin to help generate a little bit of entropy from program state,
83748 + * used during boot in the kernel
83749 + *
83750 + * TODO:
83751 + * - add ipa pass to identify not explicitly marked candidate functions
83752 + * - mix in more program state (function arguments/return values, loop variables, etc)
83753 + * - more instrumentation control via attribute parameters
83754 + *
83755 + * BUGS:
83756 + * - LTO needs -flto-partition=none for now
83757 + */
83758 +#include "gcc-plugin.h"
83759 +#include "config.h"
83760 +#include "system.h"
83761 +#include "coretypes.h"
83762 +#include "tree.h"
83763 +#include "tree-pass.h"
83764 +#include "flags.h"
83765 +#include "intl.h"
83766 +#include "toplev.h"
83767 +#include "plugin.h"
83768 +//#include "expr.h" where are you...
83769 +#include "diagnostic.h"
83770 +#include "plugin-version.h"
83771 +#include "tm.h"
83772 +#include "function.h"
83773 +#include "basic-block.h"
83774 +#include "gimple.h"
83775 +#include "rtl.h"
83776 +#include "emit-rtl.h"
83777 +#include "tree-flow.h"
83778 +
83779 +int plugin_is_GPL_compatible;
83780 +
83781 +static tree latent_entropy_decl;
83782 +
83783 +static struct plugin_info latent_entropy_plugin_info = {
83784 + .version = "201207271820",
83785 + .help = NULL
83786 +};
83787 +
83788 +static unsigned int execute_latent_entropy(void);
83789 +static bool gate_latent_entropy(void);
83790 +
83791 +static struct gimple_opt_pass latent_entropy_pass = {
83792 + .pass = {
83793 + .type = GIMPLE_PASS,
83794 + .name = "latent_entropy",
83795 + .gate = gate_latent_entropy,
83796 + .execute = execute_latent_entropy,
83797 + .sub = NULL,
83798 + .next = NULL,
83799 + .static_pass_number = 0,
83800 + .tv_id = TV_NONE,
83801 + .properties_required = PROP_gimple_leh | PROP_cfg,
83802 + .properties_provided = 0,
83803 + .properties_destroyed = 0,
83804 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83805 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83806 + }
83807 +};
83808 +
83809 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83810 +{
83811 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83812 + *no_add_attrs = true;
83813 + error("%qE attribute only applies to functions", name);
83814 + }
83815 + return NULL_TREE;
83816 +}
83817 +
83818 +static struct attribute_spec latent_entropy_attr = {
83819 + .name = "latent_entropy",
83820 + .min_length = 0,
83821 + .max_length = 0,
83822 + .decl_required = true,
83823 + .type_required = false,
83824 + .function_type_required = false,
83825 + .handler = handle_latent_entropy_attribute,
83826 +#if BUILDING_GCC_VERSION >= 4007
83827 + .affects_type_identity = false
83828 +#endif
83829 +};
83830 +
83831 +static void register_attributes(void *event_data, void *data)
83832 +{
83833 + register_attribute(&latent_entropy_attr);
83834 +}
83835 +
83836 +static bool gate_latent_entropy(void)
83837 +{
83838 + tree latent_entropy_attr;
83839 +
83840 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83841 + return latent_entropy_attr != NULL_TREE;
83842 +}
83843 +
83844 +static unsigned HOST_WIDE_INT seed;
83845 +static unsigned HOST_WIDE_INT get_random_const(void)
83846 +{
83847 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83848 + return seed;
83849 +}
83850 +
83851 +static enum tree_code get_op(tree *rhs)
83852 +{
83853 + static enum tree_code op;
83854 + unsigned HOST_WIDE_INT random_const;
83855 +
83856 + random_const = get_random_const();
83857 +
83858 + switch (op) {
83859 + case BIT_XOR_EXPR:
83860 + op = PLUS_EXPR;
83861 + break;
83862 +
83863 + case PLUS_EXPR:
83864 + if (rhs) {
83865 + op = LROTATE_EXPR;
83866 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83867 + break;
83868 + }
83869 +
83870 + case LROTATE_EXPR:
83871 + default:
83872 + op = BIT_XOR_EXPR;
83873 + break;
83874 + }
83875 + if (rhs)
83876 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83877 + return op;
83878 +}
83879 +
83880 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83881 +{
83882 + gimple_stmt_iterator gsi;
83883 + gimple assign;
83884 + tree addxorrol, rhs;
83885 + enum tree_code op;
83886 +
83887 + op = get_op(&rhs);
83888 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83889 + assign = gimple_build_assign(local_entropy, addxorrol);
83890 + find_referenced_vars_in(assign);
83891 +//debug_bb(bb);
83892 + gsi = gsi_after_labels(bb);
83893 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83894 + update_stmt(assign);
83895 +}
83896 +
83897 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83898 +{
83899 + gimple_stmt_iterator gsi;
83900 + gimple assign;
83901 + tree addxorrol, temp;
83902 +
83903 + // 1. create temporary copy of latent_entropy
83904 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83905 + add_referenced_var(temp);
83906 + mark_sym_for_renaming(temp);
83907 +
83908 + // 2. read...
83909 + assign = gimple_build_assign(temp, latent_entropy_decl);
83910 + find_referenced_vars_in(assign);
83911 + gsi = gsi_after_labels(bb);
83912 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83913 + update_stmt(assign);
83914 +
83915 + // 3. ...modify...
83916 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83917 + assign = gimple_build_assign(temp, addxorrol);
83918 + find_referenced_vars_in(assign);
83919 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83920 + update_stmt(assign);
83921 +
83922 + // 4. ...write latent_entropy
83923 + assign = gimple_build_assign(latent_entropy_decl, temp);
83924 + find_referenced_vars_in(assign);
83925 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83926 + update_stmt(assign);
83927 +}
83928 +
83929 +static unsigned int execute_latent_entropy(void)
83930 +{
83931 + basic_block bb;
83932 + gimple assign;
83933 + gimple_stmt_iterator gsi;
83934 + tree local_entropy;
83935 +
83936 + if (!latent_entropy_decl) {
83937 + struct varpool_node *node;
83938 +
83939 + for (node = varpool_nodes; node; node = node->next) {
83940 + tree var = node->decl;
83941 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83942 + continue;
83943 + latent_entropy_decl = var;
83944 +// debug_tree(var);
83945 + break;
83946 + }
83947 + if (!latent_entropy_decl) {
83948 +// debug_tree(current_function_decl);
83949 + return 0;
83950 + }
83951 + }
83952 +
83953 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83954 +
83955 + // 1. create local entropy variable
83956 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83957 + add_referenced_var(local_entropy);
83958 + mark_sym_for_renaming(local_entropy);
83959 +
83960 + // 2. initialize local entropy variable
83961 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83962 + if (dom_info_available_p(CDI_DOMINATORS))
83963 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83964 + gsi = gsi_start_bb(bb);
83965 +
83966 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83967 +// gimple_set_location(assign, loc);
83968 + find_referenced_vars_in(assign);
83969 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83970 + update_stmt(assign);
83971 + bb = bb->next_bb;
83972 +
83973 + // 3. instrument each BB with an operation on the local entropy variable
83974 + while (bb != EXIT_BLOCK_PTR) {
83975 + perturb_local_entropy(bb, local_entropy);
83976 + bb = bb->next_bb;
83977 + };
83978 +
83979 + // 4. mix local entropy into the global entropy variable
83980 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83981 + return 0;
83982 +}
83983 +
83984 +static void start_unit_callback(void *gcc_data, void *user_data)
83985 +{
83986 +#if BUILDING_GCC_VERSION >= 4007
83987 + seed = get_random_seed(false);
83988 +#else
83989 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83990 + seed *= seed;
83991 +#endif
83992 +
83993 + if (in_lto_p)
83994 + return;
83995 +
83996 + // extern u64 latent_entropy
83997 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83998 +
83999 + TREE_STATIC(latent_entropy_decl) = 1;
84000 + TREE_PUBLIC(latent_entropy_decl) = 1;
84001 + TREE_USED(latent_entropy_decl) = 1;
84002 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84003 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84004 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84005 + DECL_INITIAL(latent_entropy_decl) = NULL;
84006 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84007 +// varpool_finalize_decl(latent_entropy_decl);
84008 +// varpool_mark_needed_node(latent_entropy_decl);
84009 +}
84010 +
84011 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84012 +{
84013 + const char * const plugin_name = plugin_info->base_name;
84014 + struct register_pass_info latent_entropy_pass_info = {
84015 + .pass = &latent_entropy_pass.pass,
84016 + .reference_pass_name = "optimized",
84017 + .ref_pass_instance_number = 1,
84018 + .pos_op = PASS_POS_INSERT_BEFORE
84019 + };
84020 +
84021 + if (!plugin_default_version_check(version, &gcc_version)) {
84022 + error(G_("incompatible gcc/plugin versions"));
84023 + return 1;
84024 + }
84025 +
84026 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84027 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84028 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84029 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84030 +
84031 + return 0;
84032 +}
84033 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84034 new file mode 100644
84035 index 0000000..9332f17
84036 --- /dev/null
84037 +++ b/tools/gcc/size_overflow_hash.data
84038 @@ -0,0 +1,3597 @@
84039 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84040 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84041 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84042 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84043 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84044 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84045 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84046 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84047 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
84048 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84049 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
84050 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
84051 +_000014_hash kmemdup 2 64015 _000014_hash NULL
84052 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
84053 +_000016_hash memdup_user 2 59590 _000016_hash NULL
84054 +_000017_hash module_alloc 1 63630 _000017_hash NULL
84055 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
84056 +_000019_hash read_kcore 3 63488 _000019_hash NULL
84057 +_000020_hash read_ldt 2 47570 _000020_hash NULL
84058 +_000021_hash read_zero 3 19366 _000021_hash NULL
84059 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
84060 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
84061 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
84062 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
84063 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
84064 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
84065 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
84066 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
84067 +_000031_hash adu_write 3 30487 _000031_hash NULL
84068 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
84069 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
84070 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
84071 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
84072 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
84073 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
84074 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
84075 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
84076 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
84077 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
84078 +_000044_hash alloc_context 1 3194 _000044_hash NULL
84079 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
84080 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
84081 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
84082 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
84083 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
84084 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
84085 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
84086 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
84087 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
84088 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
84089 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
84090 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
84091 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
84092 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
84093 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
84094 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
84095 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
84096 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
84097 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
84098 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
84099 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
84100 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
84101 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
84102 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
84103 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
84104 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
84105 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
84106 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
84107 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
84108 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
84109 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
84110 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
84111 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
84112 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
84113 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
84114 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
84115 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
84116 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
84117 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
84118 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
84119 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
84120 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
84121 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
84122 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
84123 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
84124 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
84125 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
84126 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
84127 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
84128 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
84129 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
84130 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
84131 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
84132 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
84133 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
84134 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
84135 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
84136 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
84137 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
84138 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
84139 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
84140 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
84141 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
84142 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
84143 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
84144 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
84145 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
84146 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
84147 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
84148 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
84149 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
84150 +_000122_hash change_xattr 5 61390 _000122_hash NULL
84151 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
84152 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
84153 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
84154 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
84155 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
84156 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
84157 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
84158 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
84159 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
84160 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
84161 +_000133_hash cmm_write 3 2896 _000133_hash NULL
84162 +_000134_hash cm_write 3 36858 _000134_hash NULL
84163 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
84164 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
84165 +_000137_hash command_file_write 3 31318 _000137_hash NULL
84166 +_000138_hash command_write 3 58841 _000138_hash NULL
84167 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
84168 +_000140_hash concat_writev 3 21451 _000140_hash NULL
84169 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
84170 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
84171 +_000143_hash copy_items 6 50140 _000143_hash NULL
84172 +_000144_hash copy_macs 4 45534 _000144_hash NULL
84173 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
84174 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
84175 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
84176 +_000148_hash cosa_write 3 1774 _000148_hash NULL
84177 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
84178 +_000150_hash create_entry 2 33479 _000150_hash NULL
84179 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
84180 +_000153_hash create_xattr 5 54106 _000153_hash NULL
84181 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
84182 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
84183 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
84184 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
84185 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
84186 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
84187 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
84188 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
84189 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
84190 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
84191 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
84192 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
84193 +_000168_hash dev_config 3 8506 _000168_hash NULL
84194 +_000169_hash device_write 3 45156 _000169_hash NULL
84195 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
84196 +_000171_hash devres_alloc 2 551 _000171_hash NULL
84197 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
84198 +_000173_hash direct_entry 3 38836 _000173_hash NULL
84199 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
84200 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
84201 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
84202 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
84203 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
84204 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
84205 +_000180_hash dm_read 3 15674 _000180_hash NULL
84206 +_000181_hash dm_write 3 2513 _000181_hash NULL
84207 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
84208 +_000183_hash dns_query 3 9676 _000183_hash NULL
84209 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
84210 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
84211 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
84212 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
84213 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
84214 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
84215 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
84216 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
84217 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
84218 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
84219 +_000194_hash dsp_write 2 46218 _000194_hash NULL
84220 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
84221 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
84222 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
84223 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
84224 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
84225 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
84226 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
84227 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
84228 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
84229 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
84230 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
84231 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
84232 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
84233 +_000208_hash ep_read 3 58813 _000208_hash NULL
84234 +_000209_hash ep_write 3 59008 _000209_hash NULL
84235 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
84236 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
84237 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
84238 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
84239 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
84240 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
84241 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
84242 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
84243 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
84244 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
84245 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
84246 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
84247 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
84248 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
84249 +_000225_hash fl_create 5 56435 _000225_hash NULL
84250 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
84251 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
84252 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
84253 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
84254 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
84255 +_000231_hash get_arg 3 5694 _000231_hash NULL
84256 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
84257 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
84258 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
84259 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
84260 +_000236_hash get_registers 3 26187 _000236_hash NULL
84261 +_000237_hash get_scq 2 10897 _000237_hash NULL
84262 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
84263 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
84264 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
84265 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
84266 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
84267 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
84268 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
84269 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
84270 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
84271 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
84272 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
84273 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
84274 +_000250_hash handle_request 9 10024 _000250_hash NULL
84275 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
84276 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
84277 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
84278 +_000254_hash heap_init 2 49617 _000254_hash NULL
84279 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
84280 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
84281 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
84282 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
84283 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
84284 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
84285 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
84286 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
84287 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
84288 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
84289 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
84290 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
84291 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
84292 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
84293 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
84294 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
84295 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
84296 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
84297 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
84298 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
84299 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
84300 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
84301 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
84302 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
84303 +_000279_hash if_write 3 51756 _000279_hash NULL
84304 +_000280_hash ilo_write 3 64378 _000280_hash NULL
84305 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
84306 +_000282_hash init_data_container 1 60709 _000282_hash NULL
84307 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
84308 +_000284_hash insert_dent 7 65034 _000284_hash NULL
84309 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
84310 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
84311 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
84312 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
84313 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
84314 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
84315 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
84316 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
84317 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
84318 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
84319 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
84320 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
84321 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
84322 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
84323 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
84324 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
84325 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
84326 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
84327 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
84328 +_000304_hash isdn_read 3 50021 _000304_hash NULL
84329 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
84330 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
84331 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
84332 +_000308_hash iso_callback 3 43208 _000308_hash NULL
84333 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
84334 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
84335 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
84336 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
84337 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
84338 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
84339 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
84340 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
84341 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
84342 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
84343 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
84344 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
84345 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
84346 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
84347 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
84348 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
84349 +_000328_hash kone_receive 4 4690 _000328_hash NULL
84350 +_000329_hash kone_send 4 63435 _000329_hash NULL
84351 +_000330_hash krealloc 2 14908 _000330_hash NULL
84352 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
84353 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
84354 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
84355 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
84356 +_000335_hash kzalloc 1 54740 _000335_hash NULL
84357 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
84358 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
84359 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
84360 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
84361 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
84362 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
84363 +_000342_hash __lgread 4 31668 _000342_hash NULL
84364 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
84365 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
84366 +_000345_hash listxattr 3 12769 _000345_hash NULL
84367 +_000346_hash load_msg 2 95 _000346_hash NULL
84368 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
84369 +_000348_hash lp_write 3 9511 _000348_hash NULL
84370 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
84371 +_000350_hash mce_write 3 26201 _000350_hash NULL
84372 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
84373 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
84374 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
84375 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
84376 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
84377 +_000357_hash mem_rw 3 22085 _000357_hash NULL
84378 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
84379 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
84380 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
84381 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
84382 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
84383 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
84384 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
84385 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
84386 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
84387 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
84388 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
84389 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
84390 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
84391 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
84392 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84393 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84394 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84395 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84396 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84397 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84398 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84399 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84400 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84401 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84402 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84403 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84404 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84405 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84406 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84407 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84408 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84409 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84410 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84411 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84412 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84413 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84414 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84415 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84416 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84417 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84418 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84419 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84420 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84421 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84422 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84423 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84424 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84425 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84426 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84427 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84428 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84429 +_000415_hash parse_command 2 37079 _000415_hash NULL
84430 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84431 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84432 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84433 +_000419_hash pg_write 3 40766 _000419_hash NULL
84434 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84435 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84436 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84437 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84438 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84439 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84440 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84441 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84442 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84443 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84444 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84445 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84446 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84447 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84448 +_000434_hash pp_read 3 33210 _000434_hash NULL
84449 +_000435_hash pp_write 3 39554 _000435_hash NULL
84450 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84451 +_000437_hash printer_write 3 60276 _000437_hash NULL
84452 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84453 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84454 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84455 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84456 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84457 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84458 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84459 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84460 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84461 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84462 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84463 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84464 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84465 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84466 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84467 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84468 +_000456_hash pt_write 3 40159 _000456_hash NULL
84469 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84470 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84471 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84472 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84473 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84474 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84475 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84476 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84477 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84478 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84479 +_000467_hash read 3 9397 _000467_hash NULL
84480 +_000468_hash read_buf 2 20469 _000468_hash NULL
84481 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84482 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84483 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84484 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84485 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84486 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84487 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84488 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84489 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84490 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84491 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84492 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84493 +_000481_hash revalidate 2 19043 _000481_hash NULL
84494 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84495 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84496 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84497 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84498 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84499 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84500 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84501 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84502 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84503 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84504 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84505 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84506 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84507 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84508 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84509 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84510 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84511 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84512 +_000500_hash savemem 3 58129 _000500_hash NULL
84513 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84514 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84515 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84516 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84517 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84518 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84519 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84520 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84521 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84522 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84523 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84524 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84525 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84526 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84527 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84528 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84529 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84530 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84531 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84532 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84533 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84534 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84535 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84536 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84537 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84538 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84539 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84540 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84541 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84542 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84543 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84544 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84545 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84546 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84547 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84548 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84549 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84550 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84551 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84552 +_000542_hash set_registers 3 53582 _000542_hash NULL
84553 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84554 +_000544_hash setup_req 3 5848 _000544_hash NULL
84555 +_000545_hash setxattr 4 37006 _000545_hash NULL
84556 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84557 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84558 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84559 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84560 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84561 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84562 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84563 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84564 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84565 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84566 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84567 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84568 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84569 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84570 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84571 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84572 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84573 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84574 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84575 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84576 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84577 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84578 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84579 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84580 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84581 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84582 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84583 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84584 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84585 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84586 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84587 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84588 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84589 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84590 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84591 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84592 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84593 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84594 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84595 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84596 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84597 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84598 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84599 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84600 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84601 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84602 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84603 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84604 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84605 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84606 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84607 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84608 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84609 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84610 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84611 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84612 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84613 +_000606_hash tower_write 3 8580 _000606_hash NULL
84614 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84615 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84616 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84617 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84618 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84619 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84620 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84621 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84622 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84623 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84624 +_000617_hash uea_request 4 47613 _000617_hash NULL
84625 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84626 +_000619_hash uio_write 3 43202 _000619_hash NULL
84627 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84628 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84629 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84630 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84631 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84632 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84633 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84634 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84635 +_000629_hash user_update 3 41332 _000629_hash NULL
84636 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84637 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84638 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84639 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84640 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84641 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84642 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84643 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84644 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84645 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84646 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84647 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84648 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84649 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84650 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84651 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84652 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84653 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84654 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84655 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84656 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84657 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84658 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84659 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84660 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84661 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84662 +_000659_hash write 3 62671 _000659_hash NULL
84663 +_000660_hash write_flush 3 50803 _000660_hash NULL
84664 +_000661_hash write_rio 3 54837 _000661_hash NULL
84665 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84666 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84667 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84668 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84669 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84670 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84671 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84672 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84673 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84674 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84675 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84676 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84677 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84678 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84679 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84680 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84681 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84682 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84683 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84684 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84685 +_000684_hash addtgt 3 54703 _000684_hash NULL
84686 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84687 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84688 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84689 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84690 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84691 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84692 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84693 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84694 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84695 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84696 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84697 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84698 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84699 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84700 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84701 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84702 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84703 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84704 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84705 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84706 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84707 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84708 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84709 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84710 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84711 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84712 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84713 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84714 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84715 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84716 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84717 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84718 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84719 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84720 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84721 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84722 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84723 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84724 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84725 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84726 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84727 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84728 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84729 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84730 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84731 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84732 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84733 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84734 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84735 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84736 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84737 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84738 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84739 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84740 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84741 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84742 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84743 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84744 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84745 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84746 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84747 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84748 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84749 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84750 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84751 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84752 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84753 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84754 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84755 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84756 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84757 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84758 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84759 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84760 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84761 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84762 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84763 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84764 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84765 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84766 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84767 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84768 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84769 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84770 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84771 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84772 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84773 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84774 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84775 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84776 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84777 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84778 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84779 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84780 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84781 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84782 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84783 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84784 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84785 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84786 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84787 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84788 +_000799_hash construct_key 3 11329 _000799_hash NULL
84789 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84790 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84791 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84792 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84793 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84794 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84795 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84796 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84797 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84798 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84799 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84800 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84801 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84802 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84803 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84804 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84805 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84806 +_000819_hash depth_write 3 3021 _000819_hash NULL
84807 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84808 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84809 +_000822_hash dev_write 3 7708 _000822_hash NULL
84810 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84811 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84812 +_000825_hash disconnect 4 32521 _000825_hash NULL
84813 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84814 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84815 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84816 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84817 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84818 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84819 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84820 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84821 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84822 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84823 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84824 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84825 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84826 +_000840_hash do_sync 1 9604 _000840_hash NULL
84827 +_000841_hash dup_array 3 33551 _000841_hash NULL
84828 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84829 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84830 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84831 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84832 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84833 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84834 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84835 +_000849_hash enable_write 3 30456 _000849_hash NULL
84836 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84837 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84838 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84839 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84840 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84841 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84842 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84843 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84844 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84845 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84846 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84847 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84848 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84849 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84850 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84851 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84852 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84853 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84854 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84855 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84856 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84857 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84858 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84859 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84860 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84861 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84862 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84863 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84864 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84865 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84866 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84867 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84868 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84869 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84870 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84871 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84872 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84873 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84874 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84875 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84876 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84877 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84878 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84879 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84880 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84881 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84882 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84883 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84884 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84885 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84886 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84887 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84888 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84889 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84890 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84891 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84892 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84893 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84894 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84895 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84896 +_000915_hash init_q 4 132 _000915_hash NULL
84897 +_000916_hash init_state 2 60165 _000916_hash NULL
84898 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84899 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84900 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84901 +_000920_hash interfaces 2 38859 _000920_hash NULL
84902 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84903 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84904 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84905 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84906 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84907 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84908 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84909 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84910 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84911 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84912 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84913 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84914 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84915 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84916 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84917 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84918 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84919 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84920 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84921 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84922 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84923 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84924 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84925 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84926 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84927 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84928 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84929 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84930 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84931 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84932 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84933 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84934 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84935 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84936 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84937 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84938 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84939 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84940 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84941 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84942 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84943 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84944 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84945 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84946 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84947 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84948 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84949 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84950 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84951 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84952 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84953 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84954 +_000977_hash lc_create 3 48662 _000977_hash NULL
84955 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84956 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84957 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84958 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84959 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84960 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84961 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84962 +_000985_hash mem_read 3 57631 _000985_hash NULL
84963 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84964 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84965 +_000988_hash mem_write 3 22232 _000988_hash NULL
84966 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84967 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84968 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84969 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84970 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84971 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84972 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84973 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84974 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84975 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84976 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84977 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84978 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84979 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84980 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84981 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84982 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84983 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84984 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84985 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84986 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84987 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84988 +_001014_hash new_dir 3 31919 _001014_hash NULL
84989 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84990 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84991 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84992 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84993 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84994 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
84995 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
84996 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
84997 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
84998 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
84999 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
85000 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
85001 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
85002 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
85003 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
85004 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
85005 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
85006 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
85007 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
85008 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
85009 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
85010 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
85011 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
85012 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
85013 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
85014 +_001046_hash osst_write 3 31581 _001046_hash NULL
85015 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
85016 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
85017 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
85018 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
85019 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
85020 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
85021 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
85022 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
85023 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
85024 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
85025 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
85026 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
85027 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
85028 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
85029 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
85030 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
85031 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
85032 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
85033 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
85034 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
85035 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
85036 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
85037 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
85038 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
85039 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
85040 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
85041 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
85042 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
85043 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
85044 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
85045 +_001083_hash proc_write 3 51003 _001083_hash NULL
85046 +_001084_hash profile_load 3 58267 _001084_hash NULL
85047 +_001085_hash profile_remove 3 8556 _001085_hash NULL
85048 +_001086_hash profile_replace 3 14652 _001086_hash NULL
85049 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
85050 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
85051 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
85052 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
85053 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
85054 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
85055 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
85056 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
85057 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
85058 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
85059 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
85060 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
85061 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
85062 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
85063 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
85064 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
85065 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
85066 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
85067 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
85068 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
85069 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
85070 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
85071 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
85072 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
85073 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
85074 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
85075 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
85076 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
85077 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
85078 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
85079 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
85080 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
85081 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
85082 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
85083 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
85084 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
85085 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
85086 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
85087 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
85088 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
85089 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
85090 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
85091 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
85092 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
85093 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
85094 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
85095 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
85096 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
85097 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
85098 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
85099 +_001139_hash self_check_write 5 50856 _001139_hash NULL
85100 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
85101 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
85102 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
85103 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
85104 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
85105 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
85106 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
85107 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
85108 +_001148_hash set_connectable 4 56458 _001148_hash NULL
85109 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
85110 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
85111 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
85112 +_001152_hash setkey 3 14987 _001152_hash NULL
85113 +_001153_hash set_le 4 30581 _001153_hash NULL
85114 +_001154_hash set_link_security 4 4502 _001154_hash NULL
85115 +_001155_hash set_local_name 4 55757 _001155_hash NULL
85116 +_001156_hash set_powered 4 12129 _001156_hash NULL
85117 +_001157_hash set_ssp 4 62411 _001157_hash NULL
85118 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
85119 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
85120 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
85121 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
85122 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
85123 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
85124 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
85125 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
85126 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
85127 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
85128 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
85129 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
85130 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
85131 +_001174_hash skb_pad 2 17302 _001174_hash NULL
85132 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
85133 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
85134 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
85135 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
85136 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
85137 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
85138 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
85139 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
85140 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
85141 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
85142 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
85143 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
85144 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
85145 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
85146 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
85147 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
85148 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
85149 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
85150 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
85151 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
85152 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
85153 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
85154 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
85155 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
85156 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
85157 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
85158 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
85159 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
85160 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
85161 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
85162 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
85163 +_001208_hash sound_write 3 5102 _001208_hash NULL
85164 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
85165 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
85166 +_001213_hash spidev_message 3 5518 _001213_hash NULL
85167 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
85168 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
85169 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
85170 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
85171 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
85172 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
85173 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
85174 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
85175 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
85176 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
85177 +_001227_hash st_write 3 16874 _001227_hash NULL
85178 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
85179 +_001229_hash symtab_init 2 61050 _001229_hash NULL
85180 +_001230_hash sys_bind 3 10799 _001230_hash NULL
85181 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
85182 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
85183 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
85184 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
85185 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
85186 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
85187 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
85188 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
85189 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
85190 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
85191 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
85192 +_001242_hash sys_select 1 38827 _001242_hash NULL
85193 +_001243_hash sys_semop 3 39457 _001243_hash NULL
85194 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
85195 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
85196 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
85197 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
85198 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
85199 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
85200 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
85201 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
85202 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
85203 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
85204 +_001254_hash timeout_write 3 50991 _001254_hash NULL
85205 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
85206 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
85207 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
85208 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
85209 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
85210 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
85211 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
85212 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
85213 +_001264_hash tty_write 3 5494 _001264_hash NULL
85214 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
85215 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
85216 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
85217 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
85218 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
85219 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
85220 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
85221 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
85222 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
85223 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
85224 +_001277_hash vhci_write 3 2224 _001277_hash NULL
85225 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
85226 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
85227 +_001281_hash vmalloc 1 15464 _001281_hash NULL
85228 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
85229 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
85230 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
85231 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
85232 +_001286_hash vzalloc 1 47421 _001286_hash NULL
85233 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
85234 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
85235 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
85236 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
85237 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
85238 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
85239 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
85240 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
85241 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
85242 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
85243 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
85244 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
85245 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
85246 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
85247 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
85248 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
85249 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
85250 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
85251 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
85252 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
85253 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
85254 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
85255 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
85256 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
85257 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
85258 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
85259 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
85260 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
85261 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
85262 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
85263 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
85264 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
85265 +_001319_hash add_child 4 45201 _001319_hash NULL
85266 +_001320_hash add_port 2 54941 _001320_hash NULL
85267 +_001321_hash adu_read 3 24177 _001321_hash NULL
85268 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
85269 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
85270 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
85271 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
85272 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
85273 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
85274 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
85275 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
85276 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
85277 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
85278 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
85279 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
85280 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
85281 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
85282 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
85283 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
85284 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
85285 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
85286 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
85287 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
85288 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
85289 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
85290 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
85291 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
85292 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
85293 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
85294 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
85295 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
85296 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
85297 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
85298 +_001356_hash async_setkey 3 35521 _001356_hash NULL
85299 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
85300 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
85301 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
85302 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
85303 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
85304 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
85305 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
85306 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
85307 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
85308 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
85309 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
85310 +_001370_hash ax25_output 2 22736 _001370_hash NULL
85311 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
85312 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
85313 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
85314 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
85315 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
85316 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
85317 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
85318 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
85319 +_001380_hash bm_init 2 13529 _001380_hash NULL
85320 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
85321 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
85322 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
85323 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
85324 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
85325 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
85326 +_001387_hash cache_read 3 24790 _001387_hash NULL
85327 +_001388_hash cache_write 3 13589 _001388_hash NULL
85328 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
85329 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
85330 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
85331 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
85332 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
85333 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
85334 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
85335 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
85336 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
85337 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
85338 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
85339 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
85340 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
85341 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
85342 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
85343 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
85344 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
85345 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
85346 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
85347 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
85348 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
85349 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
85350 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
85351 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
85352 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
85353 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
85354 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
85355 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
85356 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
85357 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
85358 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
85359 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
85360 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
85361 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
85362 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
85363 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
85364 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
85365 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
85366 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
85367 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
85368 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
85369 +_001435_hash do_readlink 2 43518 _001435_hash NULL
85370 +_001436_hash __do_replace 5 37227 _001436_hash NULL
85371 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
85372 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
85373 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
85374 +_001440_hash dump_midi 3 51040 _001440_hash NULL
85375 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
85376 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
85377 +_001443_hash ep0_read 3 38095 _001443_hash NULL
85378 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
85379 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
85380 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
85381 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
85382 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
85383 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
85384 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
85385 +_001451_hash filldir 3 55137 _001451_hash NULL
85386 +_001452_hash filldir64 3 46469 _001452_hash NULL
85387 +_001453_hash find_skb 2 20431 _001453_hash NULL
85388 +_001454_hash from_buffer 3 18625 _001454_hash NULL
85389 +_001455_hash fsm_init 2 16134 _001455_hash NULL
85390 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
85391 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
85392 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85393 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85394 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85395 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85396 +_001462_hash get_packet 3 41914 _001462_hash NULL
85397 +_001463_hash get_packet 3 5747 _001463_hash NULL
85398 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85399 +_001465_hash get_skb 2 63008 _001465_hash NULL
85400 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85401 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85402 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85403 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85404 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85405 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85406 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85407 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85408 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85409 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85410 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85411 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85412 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85413 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85414 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85415 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85416 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85417 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85418 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85419 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85420 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85421 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85422 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85423 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85424 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85425 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85426 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85427 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85428 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85429 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85430 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85431 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85432 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85433 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85434 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85435 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85436 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85437 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85438 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85439 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85440 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85441 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85442 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85443 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85444 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85445 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85446 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85447 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85448 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85449 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85450 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85451 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85452 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85453 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85454 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85455 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85456 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85457 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85458 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85459 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85460 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85461 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85462 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85463 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85464 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85465 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85466 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85467 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85468 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85469 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85470 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85471 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85472 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85473 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85474 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85475 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85476 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85477 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85478 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85479 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85480 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85481 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85482 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85483 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85484 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85485 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85486 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85487 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85488 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85489 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85490 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85491 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85492 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85493 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85494 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85495 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85496 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85497 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85498 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85499 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85500 +_001575_hash new_skb 1 21148 _001575_hash NULL
85501 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85502 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85503 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85504 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85505 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85506 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85507 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85508 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85509 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85510 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85511 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85512 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85513 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85514 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85515 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85516 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85517 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85518 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85519 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85520 +_001599_hash override_release 2 52032 _001599_hash NULL
85521 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85522 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85523 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85524 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85525 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85526 +_001605_hash pg_read 3 17276 _001605_hash NULL
85527 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85528 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85529 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85530 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85531 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85532 +_001611_hash printer_read 3 54851 _001611_hash NULL
85533 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85534 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85535 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85536 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85537 +_001616_hash pt_read 3 49136 _001616_hash NULL
85538 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85539 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85540 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85541 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85542 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85543 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85544 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85545 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85546 +_001625_hash read_flush 3 43851 _001625_hash NULL
85547 +_001626_hash read_profile 3 27859 _001626_hash NULL
85548 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85549 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85550 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85551 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85552 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85553 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85554 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85555 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85556 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85557 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85558 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85559 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85560 +_001640_hash rx 4 57944 _001640_hash NULL
85561 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85562 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85563 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85564 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85565 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85566 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85567 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85568 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85569 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85570 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85571 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85572 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85573 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85574 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85575 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85576 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85577 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85578 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85579 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85580 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85581 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85582 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85583 +_001663_hash send_command 4 10832 _001663_hash NULL
85584 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85585 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85586 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85587 +_001667_hash set_arg 3 42824 _001667_hash NULL
85588 +_001668_hash sg_read 3 25799 _001668_hash NULL
85589 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85590 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85591 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85592 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85593 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85594 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85595 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85596 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85597 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85598 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85599 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85600 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85601 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85602 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85603 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85604 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85605 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85606 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85607 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85608 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85609 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85610 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85611 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85612 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85613 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85614 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85615 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85616 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85617 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85618 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85619 +_001704_hash store_msg 3 56417 _001704_hash NULL
85620 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85621 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85622 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85623 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85624 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85625 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85626 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85627 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85628 +_001713_hash syslog_print 2 307 _001713_hash NULL
85629 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85630 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85631 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85632 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85633 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85634 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85635 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85636 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85637 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85638 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85639 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85640 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85641 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85642 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85643 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85644 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85645 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85646 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85647 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85648 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85649 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85650 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85651 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85652 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85653 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85654 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85655 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85656 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85657 +_001746_hash uio_read 3 49300 _001746_hash NULL
85658 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85659 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85660 +_001749_hash unlink1 3 63059 _001749_hash NULL
85661 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85662 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85663 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85664 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85665 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85666 +_001756_hash user_read 3 51881 _001756_hash NULL
85667 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85668 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85669 +_001759_hash venus_create 4 20555 _001759_hash NULL
85670 +_001760_hash venus_link 5 32165 _001760_hash NULL
85671 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85672 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85673 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85674 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85675 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85676 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85677 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85678 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85679 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85680 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85681 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85682 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85683 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85684 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85685 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85686 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85687 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85688 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85689 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85690 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85691 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85692 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85693 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85694 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85695 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85696 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85697 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85698 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85699 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85700 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85701 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85702 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85703 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85704 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85705 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85706 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85707 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85708 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85709 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85710 +_001803_hash add_partition 2 55588 _001803_hash NULL
85711 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85712 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85713 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85714 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85715 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85716 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85717 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85718 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85719 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85720 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85721 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85722 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85723 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85724 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85725 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85726 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85727 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85728 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85729 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85730 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85731 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85732 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85733 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85734 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85735 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85736 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85737 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85738 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85739 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85740 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85741 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85742 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85743 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85744 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85745 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85746 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85747 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85748 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85749 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85750 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85751 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85752 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85753 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85754 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85755 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85756 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85757 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85758 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85759 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85760 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85761 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85762 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85763 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85764 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85765 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85766 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85767 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85768 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85769 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85770 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85771 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85772 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85773 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85774 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85775 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85776 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85777 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85778 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85779 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85780 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85781 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85782 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85783 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85784 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85785 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85786 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85787 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85788 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85789 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85790 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85791 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85792 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85793 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85794 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85795 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85796 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85797 +_001892_hash check_header 2 56930 _001892_hash NULL
85798 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85799 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85800 +_001895_hash console_store 4 36007 _001895_hash NULL
85801 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85802 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85803 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85804 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85805 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85806 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85807 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85808 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85809 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85810 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85811 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85812 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85813 +_001912_hash debug_output 3 18575 _001912_hash NULL
85814 +_001913_hash debug_read 3 19322 _001913_hash NULL
85815 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85816 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85817 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85818 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85819 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85820 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85821 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85822 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85823 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85824 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85825 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85826 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85827 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85828 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85829 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85830 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85831 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85832 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85833 +_001933_hash filter_read 3 61692 _001933_hash NULL
85834 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85835 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85836 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85837 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85838 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85839 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85840 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85841 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85842 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85843 +_001943_hash handle_response 5 55951 _001943_hash NULL
85844 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85845 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85846 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85847 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85848 +_001948_hash help 4 14971 _001948_hash NULL
85849 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85850 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85851 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85852 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85853 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85854 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85855 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85856 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85857 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85858 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85859 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85860 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85861 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85862 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85863 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85864 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85865 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85866 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85867 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85868 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85869 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85870 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85871 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85872 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85873 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85874 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85875 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85876 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85877 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85878 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85879 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85880 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85881 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85882 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85883 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85884 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85885 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85886 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85887 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85888 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85889 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85890 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85891 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85892 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85893 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85894 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85895 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85896 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85897 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85898 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85899 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85900 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85901 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85902 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85903 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85904 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85905 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85906 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85907 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85908 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85909 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85910 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85911 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85912 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85913 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85914 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85915 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85916 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85917 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85918 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85919 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85920 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85921 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85922 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85923 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85924 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85925 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85926 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85927 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85928 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85929 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85930 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85931 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85932 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85933 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85934 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85935 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85936 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85937 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85938 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85939 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85940 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85941 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85942 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85943 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85944 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85945 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85946 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85947 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85948 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85949 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85950 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85951 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85952 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85953 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85954 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85955 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85956 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85957 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85958 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85959 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85960 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85961 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85962 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85963 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85964 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85965 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85966 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85967 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85968 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85969 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85970 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85971 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85972 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85973 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85974 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85975 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85976 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85977 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85978 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85979 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85980 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85981 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85982 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85983 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85984 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85985 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85986 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85987 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85988 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85989 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85990 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85991 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85992 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85993 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85994 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
85995 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
85996 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
85997 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
85998 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
85999 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
86000 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
86001 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
86002 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
86003 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
86004 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
86005 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
86006 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
86007 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
86008 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
86009 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
86010 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
86011 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
86012 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
86013 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
86014 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
86015 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
86016 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
86017 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
86018 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
86019 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
86020 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
86021 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
86022 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
86023 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
86024 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
86025 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
86026 +_002136_hash osst_read 3 40237 _002136_hash NULL
86027 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
86028 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
86029 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
86030 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
86031 +_002143_hash page_readlink 3 23346 _002143_hash NULL
86032 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
86033 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
86034 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
86035 +_002148_hash pep_reply 5 50582 _002148_hash NULL
86036 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
86037 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
86038 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
86039 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
86040 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
86041 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
86042 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
86043 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
86044 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
86045 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
86046 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
86047 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
86048 +_002161_hash proc_read 3 43614 _002161_hash NULL
86049 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
86050 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
86051 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
86052 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
86053 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
86054 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
86055 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
86056 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
86057 +_002170_hash queues_read 3 24877 _002170_hash NULL
86058 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
86059 +_002172_hash rcname_read 3 25919 _002172_hash NULL
86060 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
86061 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
86062 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
86063 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
86064 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
86065 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
86066 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
86067 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
86068 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
86069 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
86070 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
86071 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
86072 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
86073 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
86074 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
86075 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
86076 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
86077 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
86078 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
86079 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
86080 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
86081 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
86082 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
86083 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
86084 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
86085 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
86086 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
86087 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
86088 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
86089 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
86090 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
86091 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
86092 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
86093 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
86094 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
86095 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
86096 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
86097 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
86098 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
86099 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
86100 +_002213_hash receive_packet 2 12367 _002213_hash NULL
86101 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
86102 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
86103 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
86104 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
86105 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
86106 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
86107 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
86108 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
86109 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
86110 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
86111 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
86112 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
86113 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
86114 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
86115 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
86116 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
86117 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
86118 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
86119 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
86120 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
86121 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
86122 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
86123 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
86124 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
86125 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
86126 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
86127 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
86128 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
86129 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
86130 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
86131 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
86132 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
86133 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
86134 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
86135 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
86136 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
86137 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
86138 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
86139 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
86140 +_002254_hash send_msg 4 37323 _002254_hash NULL
86141 +_002255_hash send_packet 4 52960 _002255_hash NULL
86142 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
86143 +_002257_hash sge_rx 3 50594 _002257_hash NULL
86144 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
86145 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
86146 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
86147 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
86148 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
86149 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
86150 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
86151 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
86152 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
86153 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
86154 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
86155 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
86156 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
86157 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
86158 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
86159 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
86160 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
86161 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
86162 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
86163 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
86164 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
86165 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
86166 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
86167 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
86168 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
86169 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
86170 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
86171 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
86172 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
86173 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
86174 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
86175 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
86176 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
86177 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
86178 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
86179 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
86180 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
86181 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
86182 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
86183 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
86184 +_002306_hash st_read 3 51251 _002306_hash NULL
86185 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
86186 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
86187 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
86188 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
86189 +_002311_hash sys_readv 3 50664 _002311_hash NULL
86190 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
86191 +_002313_hash sys_writev 3 28384 _002313_hash NULL
86192 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
86193 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
86194 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
86195 +_002317_hash teiup_create 3 43201 _002317_hash NULL
86196 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
86197 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
86198 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
86199 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
86200 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
86201 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
86202 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
86203 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
86204 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
86205 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
86206 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
86207 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
86208 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
86209 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
86210 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
86211 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
86212 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
86213 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
86214 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
86215 +_002341_hash um_idi_read 3 850 _002341_hash NULL
86216 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
86217 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
86218 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
86219 +_002345_hash use_pool 2 64607 _002345_hash NULL
86220 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
86221 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
86222 +_002348_hash vhci_read 3 47878 _002348_hash NULL
86223 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
86224 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
86225 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
86226 +_002353_hash waiters_read 3 40902 _002353_hash NULL
86227 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
86228 +_002355_hash write_pbl 4 59583 _002355_hash NULL
86229 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
86230 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
86231 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
86232 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
86233 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
86234 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
86235 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
86236 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
86237 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
86238 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
86239 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
86240 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
86241 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
86242 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
86243 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
86244 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
86245 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
86246 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
86247 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
86248 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
86249 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
86250 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
86251 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
86252 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
86253 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
86254 +_002382_hash bioset_create 1 5580 _002382_hash NULL
86255 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
86256 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
86257 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
86258 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
86259 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
86260 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
86261 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
86262 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
86263 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
86264 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
86265 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
86266 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
86267 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
86268 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
86269 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
86270 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
86271 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
86272 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
86273 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
86274 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
86275 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
86276 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
86277 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
86278 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
86279 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
86280 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
86281 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
86282 +_002411_hash depth_read 3 31112 _002411_hash NULL
86283 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
86284 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
86285 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
86286 +_002415_hash divas_write 3 63901 _002415_hash NULL
86287 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
86288 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
86289 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
86290 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
86291 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
86292 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
86293 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
86294 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
86295 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
86296 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
86297 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
86298 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
86299 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
86300 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
86301 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
86302 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
86303 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
86304 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
86305 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
86306 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
86307 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
86308 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
86309 +_002439_hash got_frame 2 16028 _002439_hash NULL
86310 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
86311 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
86312 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
86313 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
86314 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
86315 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
86316 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
86317 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
86318 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
86319 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
86320 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
86321 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
86322 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
86323 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
86324 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
86325 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
86326 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
86327 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
86328 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
86329 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
86330 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
86331 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
86332 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
86333 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
86334 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
86335 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
86336 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
86337 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
86338 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
86339 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
86340 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
86341 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
86342 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
86343 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
86344 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
86345 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
86346 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
86347 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
86348 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
86349 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
86350 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
86351 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
86352 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
86353 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
86354 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
86355 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
86356 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
86357 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
86358 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
86359 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
86360 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
86361 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
86362 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
86363 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
86364 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
86365 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
86366 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
86367 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
86368 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
86369 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
86370 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
86371 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
86372 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
86373 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
86374 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
86375 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
86376 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
86377 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
86378 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
86379 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
86380 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
86381 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
86382 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
86383 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
86384 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
86385 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
86386 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
86387 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
86388 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
86389 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
86390 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
86391 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
86392 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86393 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86394 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86395 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86396 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86397 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86398 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86399 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86400 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86401 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86402 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86403 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86404 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86405 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86406 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86407 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86408 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86409 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86410 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86411 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86412 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86413 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86414 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86415 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86416 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86417 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86418 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86419 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86420 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86421 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86422 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86423 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86424 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86425 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86426 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86427 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86428 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86429 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86430 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86431 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86432 +_002570_hash map_addr 6 4666 _002570_hash NULL
86433 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86434 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86435 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86436 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86437 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86438 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86439 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86440 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86441 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86442 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86443 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86444 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86445 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86446 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86447 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86448 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86449 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86450 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86451 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86452 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86453 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86454 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86455 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86456 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86457 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86458 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86459 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86460 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86461 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86462 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86463 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86464 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86465 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86466 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86467 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86468 +_002612_hash power_read 3 15939 _002612_hash NULL
86469 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86470 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86471 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86472 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86473 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86474 +_002618_hash prison_create 1 43623 _002618_hash NULL
86475 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86476 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86477 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86478 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86479 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86480 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86481 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86482 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86483 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86484 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86485 +_002629_hash read_dma 3 55086 _002629_hash NULL
86486 +_002630_hash read_fifo 3 826 _002630_hash NULL
86487 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86488 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86489 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86490 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86491 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86492 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86493 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86494 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86495 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86496 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86497 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86498 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86499 +_002644_hash rx_data 4 60442 _002644_hash NULL
86500 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86501 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86502 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86503 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86504 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86505 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86506 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86507 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86508 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86509 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86510 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86511 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86512 +_002658_hash send_stream 4 3397 _002658_hash NULL
86513 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86514 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86515 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86516 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86517 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86518 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86519 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86520 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86521 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86522 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86523 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86524 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86525 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86526 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86527 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86528 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86529 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86530 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86531 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86532 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86533 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86534 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86535 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86536 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86537 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86538 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86539 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86540 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86541 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86542 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86543 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86544 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86545 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86546 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86547 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86548 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86549 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86550 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86551 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86552 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86553 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86554 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86555 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86556 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86557 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86558 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86559 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86560 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86561 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86562 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86563 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86564 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86565 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86566 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86567 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86568 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86569 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86570 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86571 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86572 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86573 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86574 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86575 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86576 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86577 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86578 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86579 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86580 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86581 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86582 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86583 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86584 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86585 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86586 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86587 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86588 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86589 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86590 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86591 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86592 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86593 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86594 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86595 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86596 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86597 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86598 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86599 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86600 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86601 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86602 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86603 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86604 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86605 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86606 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86607 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86608 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86609 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86610 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86611 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86612 +_002770_hash push_rx 3 28939 _002770_hash NULL
86613 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86614 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86615 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86616 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86617 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86618 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86619 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86620 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86621 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86622 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86623 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86624 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86625 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86626 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86627 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86628 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86629 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86630 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86631 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86632 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86633 +_002794_hash write_leb 5 36957 _002794_hash NULL
86634 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86635 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86636 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86637 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86638 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86639 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86640 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86641 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86642 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86643 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86644 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86645 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86646 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86647 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86648 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86649 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86650 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86651 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86652 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86653 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86654 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86655 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86656 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86657 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86658 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86659 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86660 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86661 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86662 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86663 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86664 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86665 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86666 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86667 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86668 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86669 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86670 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86671 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86672 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86673 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86674 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86675 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86676 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86677 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86678 +_002846_hash recover_head 3 17904 _002846_hash NULL
86679 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86680 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86681 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86682 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86683 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86684 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86685 +_002853_hash write_head 4 30481 _002853_hash NULL
86686 +_002854_hash write_node 4 33121 _002854_hash NULL
86687 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86688 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86689 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86690 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86691 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86692 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86693 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86694 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86695 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86696 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86697 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86698 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86699 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86700 +_002869_hash create_log 2 8225 _002869_hash NULL
86701 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86702 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86703 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86704 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86705 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86706 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86707 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86708 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86709 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86710 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86711 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86712 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86713 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86714 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86715 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86716 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86717 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86718 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86719 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86720 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86721 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86722 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86723 +_002893_hash _malloc 1 54077 _002893_hash NULL
86724 +_002894_hash mei_read 3 6507 _002894_hash NULL
86725 +_002895_hash mei_write 3 4005 _002895_hash NULL
86726 +_002896_hash msg_set 3 51725 _002896_hash NULL
86727 +_002897_hash newpart 6 47485 _002897_hash NULL
86728 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86729 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86730 +_002900_hash packet_came 3 18072 _002900_hash NULL
86731 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86732 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86733 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86734 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86735 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86736 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86737 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86738 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86739 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86740 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86741 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86742 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86743 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86744 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86745 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86746 +_002923_hash sep_read 3 17161 _002923_hash NULL
86747 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86748 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86749 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86750 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86751 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86752 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86753 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86754 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86755 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86756 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86757 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86758 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86759 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86760 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86761 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86762 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86763 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86764 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86765 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86766 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86767 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86768 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86769 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86770 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86771 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86772 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86773 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86774 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86775 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86776 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86777 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86778 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86779 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86780 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86781 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86782 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86783 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86784 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86785 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86786 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86787 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86788 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86789 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86790 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86791 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86792 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86793 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86794 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86795 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86796 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86797 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86798 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86799 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86800 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86801 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86802 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86803 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86804 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86805 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86806 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86807 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86808 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86809 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86810 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86811 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86812 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86813 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86814 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86815 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86816 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86817 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86818 +_003003_hash flash_read 3 57843 _003003_hash NULL
86819 +_003004_hash flash_write 3 62354 _003004_hash NULL
86820 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86821 +_003006_hash gather_array 3 56641 _003006_hash NULL
86822 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86823 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86824 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86825 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86826 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86827 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86828 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86829 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86830 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86831 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86832 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86833 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86834 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86835 +_003021_hash options_write 3 47243 _003021_hash NULL
86836 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86837 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86838 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86839 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86840 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86841 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86842 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86843 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86844 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86845 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86846 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86847 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86848 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86849 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86850 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86851 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86852 +_003038_hash split 2 11691 _003038_hash NULL
86853 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86854 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86855 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86856 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86857 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86858 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86859 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86860 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86861 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86862 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86863 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86864 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86865 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86866 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86867 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86868 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86869 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86870 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86871 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86872 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86873 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86874 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86875 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86876 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86877 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86878 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86879 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86880 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86881 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86882 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86883 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86884 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86885 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86886 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86887 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86888 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86889 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86890 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86891 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86892 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86893 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86894 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86895 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86896 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86897 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86898 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86899 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86900 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86901 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86902 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86903 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86904 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86905 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86906 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86907 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86908 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86909 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86910 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86911 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86912 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86913 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86914 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86915 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86916 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86917 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86918 +_003108_hash conf_read 3 55786 _003108_hash NULL
86919 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86920 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86921 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86922 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86923 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86924 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86925 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86926 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86927 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86928 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86929 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86930 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86931 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86932 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86933 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86934 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86935 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86936 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86937 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86938 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86939 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86940 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86941 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86942 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86943 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86944 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86945 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86946 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86947 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86948 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86949 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86950 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86951 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86952 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86953 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86954 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86955 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86956 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86957 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86958 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86959 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86960 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86961 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86962 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86963 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86964 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86965 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86966 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86967 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86968 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86969 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86970 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86971 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86972 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86973 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86974 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86975 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86976 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86977 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86978 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86979 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86980 +_003175_hash get_info 3 55681 _003175_hash NULL
86981 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86982 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86983 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86984 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86985 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86986 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86987 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86988 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86989 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86990 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86991 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86992 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86993 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86994 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
86995 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
86996 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
86997 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
86998 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
86999 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
87000 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
87001 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
87002 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
87003 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
87004 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
87005 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
87006 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
87007 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
87008 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
87009 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
87010 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
87011 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
87012 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
87013 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
87014 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
87015 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
87016 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
87017 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
87018 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
87019 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
87020 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
87021 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
87022 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
87023 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
87024 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
87025 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
87026 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
87027 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
87028 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
87029 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
87030 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
87031 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
87032 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
87033 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
87034 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
87035 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
87036 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
87037 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
87038 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
87039 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
87040 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
87041 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
87042 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
87043 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
87044 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
87045 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
87046 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
87047 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
87048 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
87049 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
87050 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
87051 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
87052 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
87053 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
87054 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
87055 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
87056 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
87057 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
87058 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
87059 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
87060 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
87061 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
87062 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
87063 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
87064 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
87065 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
87066 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
87067 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
87068 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
87069 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
87070 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
87071 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
87072 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
87073 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
87074 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
87075 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
87076 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
87077 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
87078 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
87079 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
87080 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
87081 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
87082 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
87083 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
87084 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
87085 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
87086 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
87087 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
87088 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
87089 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
87090 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
87091 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
87092 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
87093 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
87094 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
87095 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
87096 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
87097 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
87098 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
87099 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
87100 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
87101 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
87102 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
87103 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
87104 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
87105 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
87106 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
87107 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
87108 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
87109 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
87110 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
87111 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
87112 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
87113 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
87114 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
87115 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
87116 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
87117 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
87118 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
87119 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
87120 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
87121 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
87122 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
87123 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
87124 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
87125 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
87126 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
87127 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
87128 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
87129 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
87130 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
87131 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
87132 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
87133 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
87134 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
87135 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
87136 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
87137 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
87138 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
87139 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
87140 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
87141 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
87142 +_003340_hash alloc_private 2 22399 _003340_hash NULL
87143 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
87144 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
87145 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
87146 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
87147 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
87148 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
87149 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
87150 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
87151 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
87152 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
87153 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
87154 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
87155 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
87156 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
87157 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
87158 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
87159 +_003359_hash comedi_read 3 13199 _003359_hash NULL
87160 +_003360_hash comedi_write 3 47926 _003360_hash NULL
87161 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
87162 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
87163 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
87164 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
87165 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
87166 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
87167 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
87168 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
87169 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
87170 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
87171 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
87172 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
87173 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
87174 +_003377_hash dev_read 3 56369 _003377_hash NULL
87175 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
87176 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
87177 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
87178 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
87179 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
87180 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
87181 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
87182 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
87183 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
87184 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
87185 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
87186 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
87187 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
87188 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
87189 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
87190 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
87191 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
87192 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
87193 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
87194 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
87195 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
87196 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
87197 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
87198 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
87199 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
87200 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
87201 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
87202 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
87203 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
87204 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
87205 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
87206 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
87207 +_003412_hash fb_read 3 33506 _003412_hash NULL
87208 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
87209 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
87210 +_003415_hash fb_write 3 46924 _003415_hash NULL
87211 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
87212 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
87213 +_003418_hash fops_read 3 40672 _003418_hash NULL
87214 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
87215 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
87216 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
87217 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
87218 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
87219 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
87220 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
87221 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
87222 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
87223 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
87224 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
87225 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
87226 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
87227 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
87228 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
87229 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
87230 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
87231 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
87232 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
87233 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
87234 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
87235 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
87236 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
87237 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
87238 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
87239 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
87240 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
87241 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
87242 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
87243 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
87244 +_003451_hash lirc_write 3 20604 _003451_hash NULL
87245 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
87246 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
87247 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
87248 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
87249 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
87250 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
87251 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
87252 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
87253 +_003461_hash mmio_read 4 40348 _003461_hash NULL
87254 +_003462_hash netlink_send 5 38434 _003462_hash NULL
87255 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
87256 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
87257 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
87258 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
87259 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
87260 +_003468_hash odev_update 2 50169 _003468_hash NULL
87261 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
87262 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
87263 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
87264 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
87265 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
87266 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
87267 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
87268 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
87269 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
87270 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
87271 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
87272 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
87273 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
87274 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
87275 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
87276 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
87277 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
87278 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
87279 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
87280 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
87281 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
87282 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
87283 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
87284 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
87285 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
87286 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
87287 +_003497_hash play_iframe 3 8219 _003497_hash NULL
87288 +_003498_hash probes_write 3 29711 _003498_hash NULL
87289 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
87290 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
87291 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
87292 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
87293 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
87294 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
87295 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
87296 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
87297 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
87298 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
87299 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
87300 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
87301 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
87302 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
87303 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
87304 +_003514_hash qc_capture 3 19298 _003514_hash NULL
87305 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
87306 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
87307 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
87308 +_003518_hash Realloc 2 34961 _003518_hash NULL
87309 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
87310 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
87311 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
87312 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
87313 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
87314 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
87315 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
87316 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
87317 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
87318 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
87319 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
87320 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
87321 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
87322 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
87323 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
87324 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
87325 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
87326 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
87327 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
87328 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
87329 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
87330 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
87331 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
87332 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
87333 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
87334 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
87335 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
87336 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
87337 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
87338 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
87339 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
87340 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
87341 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
87342 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
87343 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
87344 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
87345 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
87346 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
87347 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
87348 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
87349 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
87350 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
87351 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
87352 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
87353 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
87354 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
87355 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
87356 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
87357 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
87358 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
87359 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
87360 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
87361 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
87362 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
87363 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
87364 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
87365 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
87366 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
87367 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
87368 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
87369 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
87370 +_003584_hash ts_read 3 44687 _003584_hash NULL
87371 +_003585_hash ts_write 3 64336 _003585_hash NULL
87372 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
87373 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
87374 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
87375 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
87376 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
87377 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
87378 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
87379 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
87380 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
87381 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
87382 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
87383 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
87384 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
87385 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
87386 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
87387 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
87388 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
87389 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
87390 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
87391 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
87392 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87393 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87394 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87395 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87396 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87397 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87398 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87399 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87400 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87401 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87402 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87403 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87404 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87405 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87406 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87407 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87408 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87409 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87410 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87411 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87412 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87413 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87414 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87415 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87416 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87417 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87418 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87419 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87420 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87421 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87422 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87423 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87424 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87425 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87426 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87427 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87428 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87429 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87430 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87431 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87432 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87433 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87434 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87435 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87436 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87437 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87438 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87439 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87440 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87441 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87442 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87443 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87444 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87445 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87446 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87447 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87448 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87449 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87450 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87451 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87452 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87453 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87454 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87455 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87456 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87457 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87458 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87459 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87460 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87461 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87462 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87463 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87464 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87465 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87466 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87467 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87468 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87469 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87470 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87471 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87472 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87473 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87474 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87475 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87476 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87477 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87478 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87479 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87480 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87481 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87482 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87483 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87484 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87485 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87486 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87487 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87488 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87489 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87490 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87491 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87492 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87493 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87494 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87495 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87496 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87497 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87498 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87499 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87500 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87501 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87502 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87503 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87504 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87505 +_003729_hash vmap 2 15025 _003729_hash NULL
87506 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87507 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87508 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87509 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87510 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87511 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87512 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87513 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87514 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87515 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87516 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87517 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87518 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87519 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87520 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87521 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87522 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87523 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87524 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87525 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87526 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87527 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87528 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87529 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87530 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87531 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87532 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87533 +_003766_hash video_read 3 28148 _003766_hash NULL
87534 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87535 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87536 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87537 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87538 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87539 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87540 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87541 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87542 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87543 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87544 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87545 +_003783_hash do_test 1 15766 _003783_hash NULL
87546 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87547 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87548 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87549 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87550 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87551 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87552 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87553 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87554 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87555 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87556 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87557 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87558 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87559 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87560 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87561 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87562 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87563 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87564 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87565 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87566 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87567 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87568 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87569 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87570 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87571 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87572 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87573 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87574 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87575 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87576 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87577 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87578 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87579 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87580 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87581 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87582 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87583 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87584 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87585 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87586 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87587 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87588 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87589 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87590 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87591 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87592 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87593 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87594 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87595 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87596 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87597 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87598 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87599 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87600 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87601 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87602 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87603 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87604 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87605 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87606 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87607 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87608 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87609 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87610 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87611 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87612 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87613 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87614 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87615 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87616 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87617 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87618 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87619 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87620 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87621 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87622 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87623 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87624 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87625 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87626 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87627 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87628 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87629 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87630 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87631 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87632 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87633 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87634 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87635 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87636 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87637 new file mode 100644
87638 index 0000000..244559e
87639 --- /dev/null
87640 +++ b/tools/gcc/size_overflow_plugin.c
87641 @@ -0,0 +1,1879 @@
87642 +/*
87643 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87644 + * Licensed under the GPL v2, or (at your option) v3
87645 + *
87646 + * Homepage:
87647 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87648 + *
87649 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87650 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87651 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87652 + *
87653 + * Usage:
87654 + * $ 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
87655 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87656 + */
87657 +
87658 +#include "gcc-plugin.h"
87659 +#include "config.h"
87660 +#include "system.h"
87661 +#include "coretypes.h"
87662 +#include "tree.h"
87663 +#include "tree-pass.h"
87664 +#include "intl.h"
87665 +#include "plugin-version.h"
87666 +#include "tm.h"
87667 +#include "toplev.h"
87668 +#include "function.h"
87669 +#include "tree-flow.h"
87670 +#include "plugin.h"
87671 +#include "gimple.h"
87672 +#include "c-common.h"
87673 +#include "diagnostic.h"
87674 +#include "cfgloop.h"
87675 +
87676 +#if BUILDING_GCC_VERSION >= 4007
87677 +#include "c-tree.h"
87678 +#else
87679 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87680 +#endif
87681 +
87682 +struct size_overflow_hash {
87683 + const struct size_overflow_hash * const next;
87684 + const char * const name;
87685 + const unsigned int param;
87686 +};
87687 +
87688 +#include "size_overflow_hash.h"
87689 +
87690 +enum marked {
87691 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87692 +};
87693 +
87694 +#define __unused __attribute__((__unused__))
87695 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87696 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87697 +#define BEFORE_STMT true
87698 +#define AFTER_STMT false
87699 +#define CREATE_NEW_VAR NULL_TREE
87700 +#define CODES_LIMIT 32
87701 +#define MAX_PARAM 32
87702 +#define MY_STMT GF_PLF_1
87703 +#define NO_CAST_CHECK GF_PLF_2
87704 +
87705 +#if BUILDING_GCC_VERSION == 4005
87706 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87707 +#endif
87708 +
87709 +int plugin_is_GPL_compatible;
87710 +void debug_gimple_stmt(gimple gs);
87711 +
87712 +static tree expand(struct pointer_set_t *visited, tree lhs);
87713 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87714 +static tree report_size_overflow_decl;
87715 +static const_tree const_char_ptr_type_node;
87716 +static unsigned int handle_function(void);
87717 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87718 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87719 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87720 +
87721 +static struct plugin_info size_overflow_plugin_info = {
87722 + .version = "20120930beta",
87723 + .help = "no-size-overflow\tturn off size overflow checking\n",
87724 +};
87725 +
87726 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87727 +{
87728 + unsigned int arg_count;
87729 + enum tree_code code = TREE_CODE(*node);
87730 +
87731 + switch (code) {
87732 + case FUNCTION_DECL:
87733 + arg_count = type_num_arguments(TREE_TYPE(*node));
87734 + break;
87735 + case FUNCTION_TYPE:
87736 + case METHOD_TYPE:
87737 + arg_count = type_num_arguments(*node);
87738 + break;
87739 + default:
87740 + *no_add_attrs = true;
87741 + error("%s: %qE attribute only applies to functions", __func__, name);
87742 + return NULL_TREE;
87743 + }
87744 +
87745 + for (; args; args = TREE_CHAIN(args)) {
87746 + tree position = TREE_VALUE(args);
87747 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87748 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87749 + *no_add_attrs = true;
87750 + }
87751 + }
87752 + return NULL_TREE;
87753 +}
87754 +
87755 +static const char* get_asm_name(tree node)
87756 +{
87757 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87758 +}
87759 +
87760 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87761 +{
87762 + unsigned int arg_count, arg_num;
87763 + enum tree_code code = TREE_CODE(*node);
87764 +
87765 + switch (code) {
87766 + case FUNCTION_DECL:
87767 + arg_count = type_num_arguments(TREE_TYPE(*node));
87768 + break;
87769 + case FUNCTION_TYPE:
87770 + case METHOD_TYPE:
87771 + arg_count = type_num_arguments(*node);
87772 + break;
87773 + case FIELD_DECL:
87774 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87775 + if (arg_num != 0) {
87776 + *no_add_attrs = true;
87777 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87778 + }
87779 + return NULL_TREE;
87780 + default:
87781 + *no_add_attrs = true;
87782 + error("%qE attribute only applies to functions", name);
87783 + return NULL_TREE;
87784 + }
87785 +
87786 + for (; args; args = TREE_CHAIN(args)) {
87787 + tree position = TREE_VALUE(args);
87788 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87789 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87790 + *no_add_attrs = true;
87791 + }
87792 + }
87793 + return NULL_TREE;
87794 +}
87795 +
87796 +static struct attribute_spec size_overflow_attr = {
87797 + .name = "size_overflow",
87798 + .min_length = 1,
87799 + .max_length = -1,
87800 + .decl_required = true,
87801 + .type_required = false,
87802 + .function_type_required = false,
87803 + .handler = handle_size_overflow_attribute,
87804 +#if BUILDING_GCC_VERSION >= 4007
87805 + .affects_type_identity = false
87806 +#endif
87807 +};
87808 +
87809 +static struct attribute_spec intentional_overflow_attr = {
87810 + .name = "intentional_overflow",
87811 + .min_length = 1,
87812 + .max_length = -1,
87813 + .decl_required = true,
87814 + .type_required = false,
87815 + .function_type_required = false,
87816 + .handler = handle_intentional_overflow_attribute,
87817 +#if BUILDING_GCC_VERSION >= 4007
87818 + .affects_type_identity = false
87819 +#endif
87820 +};
87821 +
87822 +static void register_attributes(void __unused *event_data, void __unused *data)
87823 +{
87824 + register_attribute(&size_overflow_attr);
87825 + register_attribute(&intentional_overflow_attr);
87826 +}
87827 +
87828 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87829 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87830 +{
87831 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87832 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87833 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87834 +
87835 + unsigned int m = 0x57559429;
87836 + unsigned int n = 0x5052acdb;
87837 + const unsigned int *key4 = (const unsigned int *)key;
87838 + unsigned int h = len;
87839 + unsigned int k = len + seed + n;
87840 + unsigned long long p;
87841 +
87842 + while (len >= 8) {
87843 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87844 + len -= 8;
87845 + }
87846 + if (len >= 4) {
87847 + cwmixb(key4[0]) key4 += 1;
87848 + len -= 4;
87849 + }
87850 + if (len)
87851 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87852 + cwmixb(h ^ (k + n));
87853 + return k ^ h;
87854 +
87855 +#undef cwfold
87856 +#undef cwmixa
87857 +#undef cwmixb
87858 +}
87859 +
87860 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87861 +{
87862 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87863 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87864 + return fn ^ codes;
87865 +}
87866 +
87867 +static inline tree get_original_function_decl(tree fndecl)
87868 +{
87869 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87870 + return DECL_ABSTRACT_ORIGIN(fndecl);
87871 + return fndecl;
87872 +}
87873 +
87874 +static inline gimple get_def_stmt(const_tree node)
87875 +{
87876 + gcc_assert(node != NULL_TREE);
87877 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87878 + return SSA_NAME_DEF_STMT(node);
87879 +}
87880 +
87881 +static unsigned char get_tree_code(const_tree type)
87882 +{
87883 + switch (TREE_CODE(type)) {
87884 + case ARRAY_TYPE:
87885 + return 0;
87886 + case BOOLEAN_TYPE:
87887 + return 1;
87888 + case ENUMERAL_TYPE:
87889 + return 2;
87890 + case FUNCTION_TYPE:
87891 + return 3;
87892 + case INTEGER_TYPE:
87893 + return 4;
87894 + case POINTER_TYPE:
87895 + return 5;
87896 + case RECORD_TYPE:
87897 + return 6;
87898 + case UNION_TYPE:
87899 + return 7;
87900 + case VOID_TYPE:
87901 + return 8;
87902 + case REAL_TYPE:
87903 + return 9;
87904 + case VECTOR_TYPE:
87905 + return 10;
87906 + case REFERENCE_TYPE:
87907 + return 11;
87908 + case OFFSET_TYPE:
87909 + return 12;
87910 + case COMPLEX_TYPE:
87911 + return 13;
87912 + default:
87913 + debug_tree((tree)type);
87914 + gcc_unreachable();
87915 + }
87916 +}
87917 +
87918 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87919 +{
87920 + gcc_assert(type != NULL_TREE);
87921 +
87922 + while (type && len < CODES_LIMIT) {
87923 + tree_codes[len] = get_tree_code(type);
87924 + len++;
87925 + type = TREE_TYPE(type);
87926 + }
87927 + return len;
87928 +}
87929 +
87930 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87931 +{
87932 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87933 + enum tree_code code = TREE_CODE(type);
87934 + size_t len = 0;
87935 +
87936 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87937 +
87938 + arg = TYPE_ARG_TYPES(type);
87939 + // skip builtins __builtin_constant_p
87940 + if (!arg && DECL_BUILT_IN(fndecl))
87941 + return 0;
87942 +
87943 + if (TREE_CODE_CLASS(code) == tcc_type)
87944 + result = type;
87945 + else
87946 + result = DECL_RESULT(fndecl);
87947 +
87948 + gcc_assert(result != NULL_TREE);
87949 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87950 +
87951 + if (arg == NULL_TREE) {
87952 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87953 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87954 + if (arg_field == NULL_TREE)
87955 + return 0;
87956 + arg = TREE_TYPE(arg_field);
87957 + len = add_type_codes(arg, tree_codes, len);
87958 + gcc_assert(len != 0);
87959 + return len;
87960 + }
87961 +
87962 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87963 + while (arg && len < CODES_LIMIT) {
87964 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87965 + arg = TREE_CHAIN(arg);
87966 + }
87967 +
87968 + gcc_assert(len != 0);
87969 + return len;
87970 +}
87971 +
87972 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87973 +{
87974 + unsigned int hash;
87975 + const struct size_overflow_hash *entry;
87976 + unsigned char tree_codes[CODES_LIMIT];
87977 + size_t len;
87978 + const char *func_name = get_asm_name(fndecl);
87979 +
87980 + len = get_function_decl(fndecl, tree_codes);
87981 + if (len == 0)
87982 + return NULL;
87983 +
87984 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87985 +
87986 + entry = size_overflow_hash[hash];
87987 + while (entry) {
87988 + if (!strcmp(entry->name, func_name))
87989 + return entry;
87990 + entry = entry->next;
87991 + }
87992 +
87993 + return NULL;
87994 +}
87995 +
87996 +static void check_arg_type(const_tree arg)
87997 +{
87998 + const_tree type = TREE_TYPE(arg);
87999 + enum tree_code code = TREE_CODE(type);
88000 +
88001 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88002 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88003 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88004 +}
88005 +
88006 +static int find_arg_number(const_tree arg, tree func)
88007 +{
88008 + tree var;
88009 + unsigned int argnum = 1;
88010 +
88011 + if (TREE_CODE(arg) == SSA_NAME)
88012 + arg = SSA_NAME_VAR(arg);
88013 +
88014 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88015 + if (strcmp(NAME(arg), NAME(var))) {
88016 + argnum++;
88017 + continue;
88018 + }
88019 + check_arg_type(var);
88020 + return argnum;
88021 + }
88022 + gcc_unreachable();
88023 +}
88024 +
88025 +static tree create_new_var(tree type)
88026 +{
88027 + tree new_var = create_tmp_var(type, "cicus");
88028 +
88029 + add_referenced_var(new_var);
88030 + mark_sym_for_renaming(new_var);
88031 + return new_var;
88032 +}
88033 +
88034 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88035 +{
88036 + gimple assign;
88037 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88038 + tree type = TREE_TYPE(rhs1);
88039 + tree lhs = create_new_var(type);
88040 +
88041 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88042 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88043 +
88044 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88045 + update_stmt(assign);
88046 + gimple_set_plf(assign, MY_STMT, true);
88047 + return assign;
88048 +}
88049 +
88050 +static bool is_bool(const_tree node)
88051 +{
88052 + const_tree type;
88053 +
88054 + if (node == NULL_TREE)
88055 + return false;
88056 +
88057 + type = TREE_TYPE(node);
88058 + if (!INTEGRAL_TYPE_P(type))
88059 + return false;
88060 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88061 + return true;
88062 + if (TYPE_PRECISION(type) == 1)
88063 + return true;
88064 + return false;
88065 +}
88066 +
88067 +static tree cast_a_tree(tree type, tree var)
88068 +{
88069 + gcc_assert(type != NULL_TREE);
88070 + gcc_assert(var != NULL_TREE);
88071 + gcc_assert(fold_convertible_p(type, var));
88072 +
88073 + return fold_convert(type, var);
88074 +}
88075 +
88076 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88077 +{
88078 + gimple assign;
88079 +
88080 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88081 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88082 + gcc_unreachable();
88083 +
88084 + if (lhs == CREATE_NEW_VAR)
88085 + lhs = create_new_var(dst_type);
88086 +
88087 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88088 +
88089 + if (!gsi_end_p(*gsi)) {
88090 + location_t loc = gimple_location(gsi_stmt(*gsi));
88091 + gimple_set_location(assign, loc);
88092 + }
88093 +
88094 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88095 +
88096 + if (before)
88097 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88098 + else
88099 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88100 + update_stmt(assign);
88101 + gimple_set_plf(assign, MY_STMT, true);
88102 +
88103 + return assign;
88104 +}
88105 +
88106 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
88107 +{
88108 + const_gimple assign;
88109 + gimple_stmt_iterator gsi;
88110 +
88111 + if (new_rhs1 == NULL_TREE)
88112 + return NULL_TREE;
88113 +
88114 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
88115 + gsi = gsi_for_stmt(stmt);
88116 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
88117 + return gimple_get_lhs(assign);
88118 + }
88119 + return new_rhs1;
88120 +}
88121 +
88122 +static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, gimple stmt, const_tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
88123 +{
88124 + tree size_overflow_type = get_size_overflow_type(stmt, node);
88125 +
88126 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88127 +
88128 + if (new_rhs2 != NULL_TREE)
88129 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
88130 +
88131 + if (new_rhs3 != NULL_TREE)
88132 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
88133 +
88134 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
88135 +}
88136 +
88137 +
88138 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88139 +{
88140 + tree size_overflow_type, lhs;
88141 + gimple stmt;
88142 + gimple_stmt_iterator gsi;
88143 +
88144 + if (rhs1 == NULL_TREE) {
88145 + debug_gimple_stmt(oldstmt);
88146 + error("%s: rhs1 is NULL_TREE", __func__);
88147 + gcc_unreachable();
88148 + }
88149 +
88150 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88151 + lhs = rhs1;
88152 + else
88153 + lhs = gimple_get_lhs(oldstmt);
88154 +
88155 + gsi = gsi_for_stmt(oldstmt);
88156 + pointer_set_insert(visited, oldstmt);
88157 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88158 + basic_block next_bb, cur_bb;
88159 + const_edge e;
88160 +
88161 + gcc_assert(before == false);
88162 + gcc_assert(stmt_can_throw_internal(oldstmt));
88163 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88164 + gcc_assert(!gsi_end_p(gsi));
88165 +
88166 + cur_bb = gimple_bb(oldstmt);
88167 + next_bb = cur_bb->next_bb;
88168 + e = find_edge(cur_bb, next_bb);
88169 + gcc_assert(e != NULL);
88170 + gcc_assert(e->flags & EDGE_FALLTHRU);
88171 +
88172 + gsi = gsi_after_labels(next_bb);
88173 + gcc_assert(!gsi_end_p(gsi));
88174 +
88175 + before = true;
88176 + oldstmt = gsi_stmt(gsi);
88177 + }
88178 +
88179 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
88180 +
88181 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
88182 + gimple_set_plf(stmt, MY_STMT, true);
88183 + return gimple_get_lhs(stmt);
88184 +}
88185 +
88186 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
88187 +{
88188 + gimple stmt;
88189 + gimple_stmt_iterator gsi;
88190 + tree new_var, lhs = gimple_get_lhs(oldstmt);
88191 +
88192 + if (gimple_plf(oldstmt, MY_STMT))
88193 + return lhs;
88194 +
88195 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88196 + rhs1 = gimple_assign_rhs1(oldstmt);
88197 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88198 + }
88199 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88200 + rhs2 = gimple_assign_rhs2(oldstmt);
88201 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88202 + }
88203 +
88204 + stmt = gimple_copy(oldstmt);
88205 + gimple_set_location(stmt, gimple_location(oldstmt));
88206 + gimple_set_plf(stmt, MY_STMT, true);
88207 +
88208 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88209 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88210 +
88211 + if (is_bool(lhs))
88212 + new_var = SSA_NAME_VAR(lhs);
88213 + else
88214 + new_var = create_new_var(size_overflow_type);
88215 + new_var = make_ssa_name(new_var, stmt);
88216 + gimple_set_lhs(stmt, new_var);
88217 +
88218 + if (rhs1 != NULL_TREE) {
88219 + if (!gimple_assign_cast_p(oldstmt))
88220 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88221 + gimple_assign_set_rhs1(stmt, rhs1);
88222 + }
88223 +
88224 + if (rhs2 != NULL_TREE)
88225 + gimple_assign_set_rhs2(stmt, rhs2);
88226 +#if BUILDING_GCC_VERSION >= 4007
88227 + if (rhs3 != NULL_TREE)
88228 + gimple_assign_set_rhs3(stmt, rhs3);
88229 +#endif
88230 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88231 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88232 +
88233 + gsi = gsi_for_stmt(oldstmt);
88234 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88235 + update_stmt(stmt);
88236 + pointer_set_insert(visited, oldstmt);
88237 + return gimple_get_lhs(stmt);
88238 +}
88239 +
88240 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88241 +{
88242 + basic_block bb;
88243 + gimple phi;
88244 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88245 +
88246 + bb = gsi_bb(gsi);
88247 +
88248 + phi = create_phi_node(result, bb);
88249 + gsi = gsi_last(phi_nodes(bb));
88250 + gsi_remove(&gsi, false);
88251 +
88252 + gsi = gsi_for_stmt(oldstmt);
88253 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88254 + gimple_set_bb(phi, bb);
88255 + gimple_set_plf(phi, MY_STMT, true);
88256 + return phi;
88257 +}
88258 +
88259 +static basic_block create_a_first_bb(void)
88260 +{
88261 + basic_block first_bb;
88262 +
88263 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88264 + if (dom_info_available_p(CDI_DOMINATORS))
88265 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88266 + return first_bb;
88267 +}
88268 +
88269 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88270 +{
88271 + basic_block bb;
88272 + const_gimple newstmt;
88273 + gimple_stmt_iterator gsi;
88274 + bool before = BEFORE_STMT;
88275 +
88276 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88277 + gsi = gsi_for_stmt(get_def_stmt(arg));
88278 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88279 + return gimple_get_lhs(newstmt);
88280 + }
88281 +
88282 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88283 + gsi = gsi_after_labels(bb);
88284 + if (bb->index == 0) {
88285 + bb = create_a_first_bb();
88286 + gsi = gsi_start_bb(bb);
88287 + }
88288 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88289 + return gimple_get_lhs(newstmt);
88290 +}
88291 +
88292 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88293 +{
88294 + gimple newstmt;
88295 + gimple_stmt_iterator gsi;
88296 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88297 + gimple def_newstmt = get_def_stmt(new_rhs);
88298 +
88299 + gsi_insert = gsi_insert_after;
88300 + gsi = gsi_for_stmt(def_newstmt);
88301 +
88302 + switch (gimple_code(get_def_stmt(arg))) {
88303 + case GIMPLE_PHI:
88304 + newstmt = gimple_build_assign(new_var, new_rhs);
88305 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88306 + gsi_insert = gsi_insert_before;
88307 + break;
88308 + case GIMPLE_ASM:
88309 + case GIMPLE_CALL:
88310 + newstmt = gimple_build_assign(new_var, new_rhs);
88311 + break;
88312 + case GIMPLE_ASSIGN:
88313 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88314 + break;
88315 + default:
88316 + /* unknown gimple_code (handle_build_new_phi_arg) */
88317 + gcc_unreachable();
88318 + }
88319 +
88320 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88321 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88322 + gimple_set_plf(newstmt, MY_STMT, true);
88323 + update_stmt(newstmt);
88324 + return newstmt;
88325 +}
88326 +
88327 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88328 +{
88329 + const_gimple newstmt;
88330 + gimple def_stmt;
88331 + tree new_rhs;
88332 +
88333 + new_rhs = expand(visited, arg);
88334 + if (new_rhs == NULL_TREE)
88335 + return NULL_TREE;
88336 +
88337 + def_stmt = get_def_stmt(new_rhs);
88338 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88339 + return NULL_TREE;
88340 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88341 +
88342 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88343 + return gimple_get_lhs(newstmt);
88344 +}
88345 +
88346 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88347 +{
88348 + gimple phi, oldstmt = get_def_stmt(orig_result);
88349 + tree new_result, size_overflow_type;
88350 + unsigned int i;
88351 + unsigned int n = gimple_phi_num_args(oldstmt);
88352 +
88353 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88354 +
88355 + new_result = create_new_var(size_overflow_type);
88356 +
88357 + pointer_set_insert(visited, oldstmt);
88358 + phi = overflow_create_phi_node(oldstmt, new_result);
88359 + for (i = 0; i < n; i++) {
88360 + tree arg, lhs;
88361 +
88362 + arg = gimple_phi_arg_def(oldstmt, i);
88363 + if (is_gimple_constant(arg))
88364 + arg = cast_a_tree(size_overflow_type, arg);
88365 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88366 + if (lhs == NULL_TREE)
88367 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88368 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88369 + }
88370 +
88371 + update_stmt(phi);
88372 + return gimple_phi_result(phi);
88373 +}
88374 +
88375 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88376 +{
88377 + const_gimple assign;
88378 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88379 + tree origtype = TREE_TYPE(orig_rhs);
88380 +
88381 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88382 +
88383 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88384 + return gimple_get_lhs(assign);
88385 +}
88386 +
88387 +static void change_rhs1(gimple stmt, tree new_rhs1)
88388 +{
88389 + tree assign_rhs;
88390 + const_tree rhs = gimple_assign_rhs1(stmt);
88391 +
88392 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88393 + gimple_assign_set_rhs1(stmt, assign_rhs);
88394 + update_stmt(stmt);
88395 +}
88396 +
88397 +static bool check_mode_type(const_gimple stmt)
88398 +{
88399 + const_tree lhs = gimple_get_lhs(stmt);
88400 + const_tree lhs_type = TREE_TYPE(lhs);
88401 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88402 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88403 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88404 +
88405 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88406 + return false;
88407 +
88408 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88409 + return false;
88410 +
88411 + return true;
88412 +}
88413 +
88414 +static bool check_undefined_integer_operation(const_gimple stmt)
88415 +{
88416 + const_gimple def_stmt;
88417 + const_tree lhs = gimple_get_lhs(stmt);
88418 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88419 + const_tree rhs1_type = TREE_TYPE(rhs1);
88420 + const_tree lhs_type = TREE_TYPE(lhs);
88421 +
88422 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88423 + return false;
88424 +
88425 + def_stmt = get_def_stmt(rhs1);
88426 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88427 + return false;
88428 +
88429 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88430 + return false;
88431 + return true;
88432 +}
88433 +
88434 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88435 +{
88436 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88437 + enum machine_mode lhs_mode, rhs_mode;
88438 + gimple def_stmt = get_def_stmt(no_const_rhs);
88439 +
88440 + if (!gimple_assign_cast_p(def_stmt))
88441 + return false;
88442 +
88443 + rhs1 = gimple_assign_rhs1(def_stmt);
88444 + lhs = gimple_get_lhs(def_stmt);
88445 + rhs1_type = TREE_TYPE(rhs1);
88446 + lhs_type = TREE_TYPE(lhs);
88447 + rhs_mode = TYPE_MODE(rhs1_type);
88448 + lhs_mode = TYPE_MODE(lhs_type);
88449 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88450 + return false;
88451 +
88452 + return true;
88453 +}
88454 +
88455 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88456 +{
88457 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88458 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88459 + const_tree rhs1_type = TREE_TYPE(rhs1);
88460 + const_tree lhs_type = TREE_TYPE(lhs);
88461 +
88462 + new_rhs1 = expand(visited, rhs1);
88463 +
88464 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88465 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88466 +
88467 + if (gimple_plf(stmt, MY_STMT))
88468 + return lhs;
88469 +
88470 + if (gimple_plf(stmt, NO_CAST_CHECK))
88471 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88472 +
88473 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88474 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88475 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88476 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88477 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88478 + }
88479 +
88480 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88481 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88482 +
88483 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88484 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88485 +
88486 + change_rhs1(stmt, new_rhs1);
88487 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88488 +
88489 + rhs1 = gimple_assign_rhs1(stmt);
88490 + rhs1_type = TREE_TYPE(rhs1);
88491 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88492 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88493 +
88494 + if (!check_mode_type(stmt))
88495 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88496 +
88497 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88498 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88499 +
88500 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88501 +
88502 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88503 +}
88504 +
88505 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88506 +{
88507 + gimple def_stmt = get_def_stmt(lhs);
88508 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88509 +
88510 + if (is_gimple_constant(rhs1))
88511 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88512 +
88513 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88514 + switch (TREE_CODE(rhs1)) {
88515 + case SSA_NAME:
88516 + return handle_unary_rhs(visited, def_stmt);
88517 + case ARRAY_REF:
88518 + case BIT_FIELD_REF:
88519 + case ADDR_EXPR:
88520 + case COMPONENT_REF:
88521 + case INDIRECT_REF:
88522 +#if BUILDING_GCC_VERSION >= 4006
88523 + case MEM_REF:
88524 +#endif
88525 + case PARM_DECL:
88526 + case TARGET_MEM_REF:
88527 + case VAR_DECL:
88528 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88529 +
88530 + default:
88531 + debug_gimple_stmt(def_stmt);
88532 + debug_tree(rhs1);
88533 + gcc_unreachable();
88534 + }
88535 +}
88536 +
88537 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88538 +{
88539 + gimple cond_stmt;
88540 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88541 +
88542 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88543 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88544 + update_stmt(cond_stmt);
88545 +}
88546 +
88547 +static tree create_string_param(tree string)
88548 +{
88549 + tree i_type, a_type;
88550 + const int length = TREE_STRING_LENGTH(string);
88551 +
88552 + gcc_assert(length > 0);
88553 +
88554 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88555 + a_type = build_array_type(char_type_node, i_type);
88556 +
88557 + TREE_TYPE(string) = a_type;
88558 + TREE_CONSTANT(string) = 1;
88559 + TREE_READONLY(string) = 1;
88560 +
88561 + return build1(ADDR_EXPR, ptr_type_node, string);
88562 +}
88563 +
88564 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88565 +{
88566 + gimple func_stmt;
88567 + const_gimple def_stmt;
88568 + const_tree loc_line;
88569 + tree loc_file, ssa_name, current_func;
88570 + expanded_location xloc;
88571 + char ssa_name_buf[256];
88572 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88573 +
88574 + def_stmt = get_def_stmt(arg);
88575 + xloc = expand_location(gimple_location(def_stmt));
88576 +
88577 + if (!gimple_has_location(def_stmt)) {
88578 + xloc = expand_location(gimple_location(stmt));
88579 + if (!gimple_has_location(stmt))
88580 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88581 + }
88582 +
88583 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88584 +
88585 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88586 + loc_file = create_string_param(loc_file);
88587 +
88588 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88589 + current_func = create_string_param(current_func);
88590 +
88591 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88592 + ssa_name = build_string(256, ssa_name_buf);
88593 + ssa_name = create_string_param(ssa_name);
88594 +
88595 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88596 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88597 +
88598 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88599 +}
88600 +
88601 +static void __unused print_the_code_insertions(const_gimple stmt)
88602 +{
88603 + location_t loc = gimple_location(stmt);
88604 +
88605 + inform(loc, "Integer size_overflow check applied here.");
88606 +}
88607 +
88608 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88609 +{
88610 + basic_block cond_bb, join_bb, bb_true;
88611 + edge e;
88612 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88613 +
88614 + cond_bb = gimple_bb(stmt);
88615 + if (before)
88616 + gsi_prev(&gsi);
88617 + if (gsi_end_p(gsi))
88618 + e = split_block_after_labels(cond_bb);
88619 + else
88620 + e = split_block(cond_bb, gsi_stmt(gsi));
88621 + cond_bb = e->src;
88622 + join_bb = e->dest;
88623 + e->flags = EDGE_FALSE_VALUE;
88624 + e->probability = REG_BR_PROB_BASE;
88625 +
88626 + bb_true = create_empty_bb(cond_bb);
88627 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88628 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88629 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88630 +
88631 + if (dom_info_available_p(CDI_DOMINATORS)) {
88632 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88633 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88634 + }
88635 +
88636 + if (current_loops != NULL) {
88637 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88638 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88639 + }
88640 +
88641 + insert_cond(cond_bb, arg, cond_code, type_value);
88642 + insert_cond_result(bb_true, stmt, arg, min);
88643 +
88644 +// print_the_code_insertions(stmt);
88645 +}
88646 +
88647 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88648 +{
88649 + const_tree rhs_type = TREE_TYPE(rhs);
88650 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88651 +
88652 + gcc_assert(rhs_type != NULL_TREE);
88653 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88654 + return;
88655 +
88656 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88657 +
88658 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88659 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88660 +
88661 + gcc_assert(!TREE_OVERFLOW(type_max));
88662 +
88663 + cast_rhs_type = TREE_TYPE(cast_rhs);
88664 + type_max_type = TREE_TYPE(type_max);
88665 + type_min_type = TREE_TYPE(type_min);
88666 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88667 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88668 +
88669 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88670 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88671 +}
88672 +
88673 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88674 +{
88675 + gimple change_rhs_def_stmt;
88676 + tree lhs = gimple_get_lhs(def_stmt);
88677 + tree lhs_type = TREE_TYPE(lhs);
88678 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88679 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88680 +
88681 + if (change_rhs == NULL_TREE)
88682 + return get_size_overflow_type(def_stmt, lhs);
88683 +
88684 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88685 +
88686 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88687 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88688 +
88689 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88690 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88691 +
88692 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88693 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88694 +
88695 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88696 + debug_gimple_stmt(def_stmt);
88697 + gcc_unreachable();
88698 + }
88699 +
88700 + return get_size_overflow_type(def_stmt, lhs);
88701 +}
88702 +
88703 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88704 +{
88705 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88706 + return false;
88707 + if (!is_gimple_constant(rhs))
88708 + return false;
88709 + return true;
88710 +}
88711 +
88712 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88713 +{
88714 + gimple def_stmt;
88715 +
88716 + def_stmt = get_def_stmt(new_rhs);
88717 + // get_size_overflow_type
88718 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88719 + gcc_assert(gimple_assign_cast_p(def_stmt));
88720 + return gimple_assign_rhs1(def_stmt);
88721 +}
88722 +
88723 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88724 +{
88725 + gimple_stmt_iterator gsi;
88726 + const_gimple cast_stmt;
88727 + gimple def_stmt;
88728 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88729 +
88730 + if (mode != TImode && mode != DImode) {
88731 + def_stmt = get_def_stmt(new_rhs);
88732 + gcc_assert(gimple_assign_cast_p(def_stmt));
88733 + new_rhs = gimple_assign_rhs1(def_stmt);
88734 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88735 + }
88736 +
88737 + gcc_assert(mode == TImode || mode == DImode);
88738 +
88739 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88740 + return new_rhs;
88741 +
88742 + gsi = gsi_for_stmt(stmt);
88743 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88744 + new_rhs = gimple_get_lhs(cast_stmt);
88745 +
88746 + if (mode == DImode)
88747 + return new_rhs;
88748 +
88749 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88750 +
88751 + return new_rhs;
88752 +}
88753 +
88754 +static bool is_an_integer_trunction(const_gimple stmt)
88755 +{
88756 + gimple rhs1_def_stmt, rhs2_def_stmt;
88757 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88758 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88759 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88760 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88761 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88762 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88763 +
88764 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88765 + return false;
88766 +
88767 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88768 +
88769 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88770 + return false;
88771 +
88772 + rhs1_def_stmt = get_def_stmt(rhs1);
88773 + rhs2_def_stmt = get_def_stmt(rhs2);
88774 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88775 + return false;
88776 +
88777 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88778 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88779 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88780 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88781 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88782 + return false;
88783 +
88784 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88785 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88786 + return true;
88787 +}
88788 +
88789 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88790 +{
88791 + tree new_rhs1, new_rhs2;
88792 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88793 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88794 + gimple assign, stmt = get_def_stmt(lhs);
88795 + tree rhs1 = gimple_assign_rhs1(stmt);
88796 + tree rhs2 = gimple_assign_rhs2(stmt);
88797 +
88798 + if (!is_an_integer_trunction(stmt))
88799 + return NULL_TREE;
88800 +
88801 + new_rhs1 = expand(visited, rhs1);
88802 + new_rhs2 = expand(visited, rhs2);
88803 +
88804 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88805 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88806 +
88807 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88808 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88809 +
88810 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88811 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88812 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88813 + }
88814 +
88815 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88816 + new_lhs = gimple_get_lhs(assign);
88817 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88818 +
88819 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88820 +}
88821 +
88822 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88823 +{
88824 + const_gimple def_stmt;
88825 +
88826 + if (TREE_CODE(rhs) != SSA_NAME)
88827 + return false;
88828 +
88829 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88830 + return false;
88831 +
88832 + def_stmt = get_def_stmt(rhs);
88833 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88834 + return false;
88835 +
88836 + return true;
88837 +}
88838 +
88839 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88840 +{
88841 + tree new_rhs, size_overflow_type, orig_rhs;
88842 + void (*gimple_assign_set_rhs)(gimple, tree);
88843 + tree rhs1 = gimple_assign_rhs1(stmt);
88844 + tree rhs2 = gimple_assign_rhs2(stmt);
88845 + tree lhs = gimple_get_lhs(stmt);
88846 +
88847 + if (change_rhs == NULL_TREE)
88848 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88849 +
88850 + if (new_rhs2 == NULL_TREE) {
88851 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88852 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88853 + orig_rhs = rhs1;
88854 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88855 + } else {
88856 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88857 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88858 + orig_rhs = rhs2;
88859 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88860 + }
88861 +
88862 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88863 +
88864 + if (check_overflow)
88865 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88866 +
88867 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88868 + gimple_assign_set_rhs(stmt, new_rhs);
88869 + update_stmt(stmt);
88870 +
88871 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88872 +}
88873 +
88874 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88875 +{
88876 + tree rhs1, rhs2, new_lhs;
88877 + gimple def_stmt = get_def_stmt(lhs);
88878 + tree new_rhs1 = NULL_TREE;
88879 + tree new_rhs2 = NULL_TREE;
88880 +
88881 + rhs1 = gimple_assign_rhs1(def_stmt);
88882 + rhs2 = gimple_assign_rhs2(def_stmt);
88883 +
88884 + /* no DImode/TImode division in the 32/64 bit kernel */
88885 + switch (gimple_assign_rhs_code(def_stmt)) {
88886 + case RDIV_EXPR:
88887 + case TRUNC_DIV_EXPR:
88888 + case CEIL_DIV_EXPR:
88889 + case FLOOR_DIV_EXPR:
88890 + case ROUND_DIV_EXPR:
88891 + case TRUNC_MOD_EXPR:
88892 + case CEIL_MOD_EXPR:
88893 + case FLOOR_MOD_EXPR:
88894 + case ROUND_MOD_EXPR:
88895 + case EXACT_DIV_EXPR:
88896 + case POINTER_PLUS_EXPR:
88897 + case BIT_AND_EXPR:
88898 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88899 + default:
88900 + break;
88901 + }
88902 +
88903 + new_lhs = handle_integer_truncation(visited, lhs);
88904 + if (new_lhs != NULL_TREE)
88905 + return new_lhs;
88906 +
88907 + if (TREE_CODE(rhs1) == SSA_NAME)
88908 + new_rhs1 = expand(visited, rhs1);
88909 + if (TREE_CODE(rhs2) == SSA_NAME)
88910 + new_rhs2 = expand(visited, rhs2);
88911 +
88912 + if (is_a_neg_overflow(def_stmt, rhs2))
88913 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88914 + if (is_a_neg_overflow(def_stmt, rhs1))
88915 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88916 +
88917 + if (is_a_constant_overflow(def_stmt, rhs2))
88918 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88919 + if (is_a_constant_overflow(def_stmt, rhs1))
88920 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88921 +
88922 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88923 +}
88924 +
88925 +#if BUILDING_GCC_VERSION >= 4007
88926 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88927 +{
88928 + if (is_gimple_constant(rhs))
88929 + return cast_a_tree(size_overflow_type, rhs);
88930 + if (TREE_CODE(rhs) != SSA_NAME)
88931 + return NULL_TREE;
88932 + return expand(visited, rhs);
88933 +}
88934 +
88935 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88936 +{
88937 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88938 + gimple def_stmt = get_def_stmt(lhs);
88939 +
88940 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88941 +
88942 + rhs1 = gimple_assign_rhs1(def_stmt);
88943 + rhs2 = gimple_assign_rhs2(def_stmt);
88944 + rhs3 = gimple_assign_rhs3(def_stmt);
88945 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88946 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88947 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88948 +
88949 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88950 +}
88951 +#endif
88952 +
88953 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88954 +{
88955 + const_tree type;
88956 +
88957 + gcc_assert(node != NULL_TREE);
88958 +
88959 + type = TREE_TYPE(node);
88960 +
88961 + if (gimple_plf(stmt, MY_STMT))
88962 + return TREE_TYPE(node);
88963 +
88964 + switch (TYPE_MODE(type)) {
88965 + case QImode:
88966 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88967 + case HImode:
88968 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88969 + case SImode:
88970 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88971 + case DImode:
88972 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88973 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88974 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88975 + default:
88976 + debug_tree((tree)node);
88977 + error("%s: unsupported gcc configuration.", __func__);
88978 + gcc_unreachable();
88979 + }
88980 +}
88981 +
88982 +static tree expand_visited(gimple def_stmt)
88983 +{
88984 + const_gimple next_stmt;
88985 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88986 +
88987 + gsi_next(&gsi);
88988 + next_stmt = gsi_stmt(gsi);
88989 +
88990 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88991 +
88992 + switch (gimple_code(next_stmt)) {
88993 + case GIMPLE_ASSIGN:
88994 + return gimple_get_lhs(next_stmt);
88995 + case GIMPLE_PHI:
88996 + return gimple_phi_result(next_stmt);
88997 + case GIMPLE_CALL:
88998 + return gimple_call_lhs(next_stmt);
88999 + default:
89000 + return NULL_TREE;
89001 + }
89002 +}
89003 +
89004 +static tree expand(struct pointer_set_t *visited, tree lhs)
89005 +{
89006 + gimple def_stmt;
89007 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89008 +
89009 + if (is_gimple_constant(lhs))
89010 + return NULL_TREE;
89011 +
89012 + if (TREE_CODE(lhs) == ADDR_EXPR)
89013 + return NULL_TREE;
89014 +
89015 + if (code == REAL_TYPE)
89016 + return NULL_TREE;
89017 +
89018 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89019 +
89020 +
89021 + def_stmt = get_def_stmt(lhs);
89022 +
89023 + if (!def_stmt)
89024 + return NULL_TREE;
89025 +
89026 + if (gimple_plf(def_stmt, MY_STMT))
89027 + return lhs;
89028 +
89029 + if (pointer_set_contains(visited, def_stmt))
89030 + return expand_visited(def_stmt);
89031 +
89032 + switch (gimple_code(def_stmt)) {
89033 + case GIMPLE_NOP:
89034 + return NULL_TREE;
89035 + case GIMPLE_PHI:
89036 + return build_new_phi(visited, lhs);
89037 + case GIMPLE_CALL:
89038 + case GIMPLE_ASM:
89039 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89040 + case GIMPLE_ASSIGN:
89041 + switch (gimple_num_ops(def_stmt)) {
89042 + case 2:
89043 + return handle_unary_ops(visited, lhs);
89044 + case 3:
89045 + return handle_binary_ops(visited, lhs);
89046 +#if BUILDING_GCC_VERSION >= 4007
89047 + case 4:
89048 + return handle_ternary_ops(visited, lhs);
89049 +#endif
89050 + }
89051 + default:
89052 + debug_gimple_stmt(def_stmt);
89053 + error("%s: unknown gimple code", __func__);
89054 + gcc_unreachable();
89055 + }
89056 +}
89057 +
89058 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89059 +{
89060 + const_gimple assign;
89061 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89062 + tree origtype = TREE_TYPE(origarg);
89063 +
89064 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89065 +
89066 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89067 +
89068 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89069 + update_stmt(stmt);
89070 +}
89071 +
89072 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89073 +{
89074 + const char *origid;
89075 + tree arg;
89076 + const_tree origarg;
89077 +
89078 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89079 + return true;
89080 +
89081 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89082 + while (origarg && *argnum) {
89083 + (*argnum)--;
89084 + origarg = TREE_CHAIN(origarg);
89085 + }
89086 +
89087 + gcc_assert(*argnum == 0);
89088 +
89089 + gcc_assert(origarg != NULL_TREE);
89090 + origid = NAME(origarg);
89091 + *argnum = 0;
89092 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89093 + if (!strcmp(origid, NAME(arg)))
89094 + return true;
89095 + (*argnum)++;
89096 + }
89097 + return false;
89098 +}
89099 +
89100 +static bool skip_types(const_tree var)
89101 +{
89102 + switch (TREE_CODE(var)) {
89103 + case ADDR_EXPR:
89104 +#if BUILDING_GCC_VERSION >= 4006
89105 + case MEM_REF:
89106 +#endif
89107 + case ARRAY_REF:
89108 + case BIT_FIELD_REF:
89109 + case INDIRECT_REF:
89110 + case TARGET_MEM_REF:
89111 + case VAR_DECL:
89112 + return true;
89113 + default:
89114 + break;
89115 + }
89116 + return false;
89117 +}
89118 +
89119 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89120 +{
89121 + gimple phi = get_def_stmt(result);
89122 + unsigned int i, n = gimple_phi_num_args(phi);
89123 +
89124 + if (!phi)
89125 + return false;
89126 +
89127 + pointer_set_insert(visited, phi);
89128 + for (i = 0; i < n; i++) {
89129 + const_tree arg = gimple_phi_arg_def(phi, i);
89130 + if (pre_expand(visited, arg))
89131 + return true;
89132 + }
89133 + return false;
89134 +}
89135 +
89136 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89137 +{
89138 + gimple def_stmt = get_def_stmt(lhs);
89139 + const_tree rhs;
89140 +
89141 + if (!def_stmt)
89142 + return false;
89143 +
89144 + rhs = gimple_assign_rhs1(def_stmt);
89145 + if (pre_expand(visited, rhs))
89146 + return true;
89147 + return false;
89148 +}
89149 +
89150 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89151 +{
89152 + bool rhs1_found, rhs2_found;
89153 + gimple def_stmt = get_def_stmt(lhs);
89154 + const_tree rhs1, rhs2;
89155 +
89156 + if (!def_stmt)
89157 + return false;
89158 +
89159 + rhs1 = gimple_assign_rhs1(def_stmt);
89160 + rhs2 = gimple_assign_rhs2(def_stmt);
89161 + rhs1_found = pre_expand(visited, rhs1);
89162 + rhs2_found = pre_expand(visited, rhs2);
89163 +
89164 + return rhs1_found || rhs2_found;
89165 +}
89166 +
89167 +static const_tree search_field_decl(const_tree comp_ref)
89168 +{
89169 + const_tree field = NULL_TREE;
89170 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89171 +
89172 + for (i = 0; i < len; i++) {
89173 + field = TREE_OPERAND(comp_ref, i);
89174 + if (TREE_CODE(field) == FIELD_DECL)
89175 + break;
89176 + }
89177 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89178 + return field;
89179 +}
89180 +
89181 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89182 +{
89183 + const_tree attr, p;
89184 +
89185 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89186 + if (!attr || !TREE_VALUE(attr))
89187 + return MARKED_NO;
89188 +
89189 + p = TREE_VALUE(attr);
89190 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89191 + return MARKED_NOT_INTENTIONAL;
89192 +
89193 + do {
89194 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89195 + return MARKED_YES;
89196 + p = TREE_CHAIN(p);
89197 + } while (p);
89198 +
89199 + return MARKED_NO;
89200 +}
89201 +
89202 +static void print_missing_msg(tree func, unsigned int argnum)
89203 +{
89204 + unsigned int new_hash;
89205 + size_t len;
89206 + unsigned char tree_codes[CODES_LIMIT];
89207 + location_t loc = DECL_SOURCE_LOCATION(func);
89208 + const char *curfunc = get_asm_name(func);
89209 +
89210 + len = get_function_decl(func, tree_codes);
89211 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89212 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89213 +}
89214 +
89215 +static unsigned int search_missing_attribute(const_tree arg)
89216 +{
89217 + const_tree type = TREE_TYPE(arg);
89218 + tree func = get_original_function_decl(current_function_decl);
89219 + unsigned int argnum;
89220 + const struct size_overflow_hash *hash;
89221 +
89222 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89223 +
89224 + if (TREE_CODE(type) == POINTER_TYPE)
89225 + return 0;
89226 +
89227 + argnum = find_arg_number(arg, func);
89228 + if (argnum == 0)
89229 + return 0;
89230 +
89231 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89232 + return argnum;
89233 +
89234 + hash = get_function_hash(func);
89235 + if (!hash || !(hash->param & (1U << argnum))) {
89236 + print_missing_msg(func, argnum);
89237 + return 0;
89238 + }
89239 + return argnum;
89240 +}
89241 +
89242 +static bool is_already_marked(const_tree lhs)
89243 +{
89244 + unsigned int argnum;
89245 + const_tree fndecl;
89246 +
89247 + argnum = search_missing_attribute(lhs);
89248 + fndecl = get_original_function_decl(current_function_decl);
89249 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89250 + return true;
89251 + return false;
89252 +}
89253 +
89254 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89255 +{
89256 + const_gimple def_stmt;
89257 +
89258 + if (is_gimple_constant(lhs))
89259 + return false;
89260 +
89261 + if (skip_types(lhs))
89262 + return false;
89263 +
89264 + if (TREE_CODE(lhs) == PARM_DECL)
89265 + return is_already_marked(lhs);
89266 +
89267 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89268 + const_tree field, attr;
89269 +
89270 + field = search_field_decl(lhs);
89271 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89272 + if (!attr || !TREE_VALUE(attr))
89273 + return false;
89274 + return true;
89275 + }
89276 +
89277 + def_stmt = get_def_stmt(lhs);
89278 +
89279 + if (!def_stmt)
89280 + return false;
89281 +
89282 + if (pointer_set_contains(visited, def_stmt))
89283 + return false;
89284 +
89285 + switch (gimple_code(def_stmt)) {
89286 + case GIMPLE_NOP:
89287 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89288 + return is_already_marked(lhs);
89289 + return false;
89290 + case GIMPLE_PHI:
89291 + return walk_phi(visited, lhs);
89292 + case GIMPLE_CALL:
89293 + case GIMPLE_ASM:
89294 + return false;
89295 + case GIMPLE_ASSIGN:
89296 + switch (gimple_num_ops(def_stmt)) {
89297 + case 2:
89298 + return walk_unary_ops(visited, lhs);
89299 + case 3:
89300 + return walk_binary_ops(visited, lhs);
89301 + }
89302 + default:
89303 + debug_gimple_stmt((gimple)def_stmt);
89304 + error("%s: unknown gimple code", __func__);
89305 + gcc_unreachable();
89306 + }
89307 +}
89308 +
89309 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89310 +{
89311 + struct pointer_set_t *visited;
89312 + bool is_found;
89313 + enum marked is_marked;
89314 + location_t loc;
89315 +
89316 + visited = pointer_set_create();
89317 + is_found = pre_expand(visited, arg);
89318 + pointer_set_destroy(visited);
89319 +
89320 + is_marked = mark_status(fndecl, argnum + 1);
89321 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89322 + return true;
89323 +
89324 + if (is_found) {
89325 + loc = DECL_SOURCE_LOCATION(fndecl);
89326 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89327 + return true;
89328 + }
89329 + return false;
89330 +}
89331 +
89332 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89333 +{
89334 + struct pointer_set_t *visited;
89335 + tree arg, newarg;
89336 + bool match;
89337 +
89338 + match = get_function_arg(&argnum, fndecl);
89339 + if (!match)
89340 + return;
89341 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89342 + arg = gimple_call_arg(stmt, argnum);
89343 + if (arg == NULL_TREE)
89344 + return;
89345 +
89346 + if (is_gimple_constant(arg))
89347 + return;
89348 +
89349 + if (search_attributes(fndecl, arg, argnum))
89350 + return;
89351 +
89352 + if (TREE_CODE(arg) != SSA_NAME)
89353 + return;
89354 +
89355 + check_arg_type(arg);
89356 +
89357 + visited = pointer_set_create();
89358 + newarg = expand(visited, arg);
89359 + pointer_set_destroy(visited);
89360 +
89361 + if (newarg == NULL_TREE)
89362 + return;
89363 +
89364 + change_function_arg(stmt, arg, argnum, newarg);
89365 +
89366 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89367 +}
89368 +
89369 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89370 +{
89371 + tree p = TREE_VALUE(attr);
89372 + do {
89373 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89374 + p = TREE_CHAIN(p);
89375 + } while (p);
89376 +}
89377 +
89378 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89379 +{
89380 + tree orig_fndecl;
89381 + unsigned int num;
89382 + const struct size_overflow_hash *hash;
89383 +
89384 + orig_fndecl = get_original_function_decl(fndecl);
89385 + if (C_DECL_IMPLICIT(orig_fndecl))
89386 + return;
89387 + hash = get_function_hash(orig_fndecl);
89388 + if (!hash)
89389 + return;
89390 +
89391 + for (num = 1; num <= MAX_PARAM; num++)
89392 + if (hash->param & (1U << num))
89393 + handle_function_arg(stmt, fndecl, num - 1);
89394 +}
89395 +
89396 +static void set_plf_false(void)
89397 +{
89398 + basic_block bb;
89399 +
89400 + FOR_ALL_BB(bb) {
89401 + gimple_stmt_iterator si;
89402 +
89403 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89404 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89405 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89406 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89407 + }
89408 +}
89409 +
89410 +static unsigned int handle_function(void)
89411 +{
89412 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89413 +
89414 + set_plf_false();
89415 +
89416 + do {
89417 + gimple_stmt_iterator gsi;
89418 + next = bb->next_bb;
89419 +
89420 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89421 + tree fndecl, attr;
89422 + gimple stmt = gsi_stmt(gsi);
89423 +
89424 + if (!(is_gimple_call(stmt)))
89425 + continue;
89426 + fndecl = gimple_call_fndecl(stmt);
89427 + if (fndecl == NULL_TREE)
89428 + continue;
89429 + if (gimple_call_num_args(stmt) == 0)
89430 + continue;
89431 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89432 + if (!attr || !TREE_VALUE(attr))
89433 + handle_function_by_hash(stmt, fndecl);
89434 + else
89435 + handle_function_by_attribute(stmt, attr, fndecl);
89436 + gsi = gsi_for_stmt(stmt);
89437 + next = gimple_bb(stmt)->next_bb;
89438 + }
89439 + bb = next;
89440 + } while (bb);
89441 + return 0;
89442 +}
89443 +
89444 +static struct gimple_opt_pass size_overflow_pass = {
89445 + .pass = {
89446 + .type = GIMPLE_PASS,
89447 + .name = "size_overflow",
89448 + .gate = NULL,
89449 + .execute = handle_function,
89450 + .sub = NULL,
89451 + .next = NULL,
89452 + .static_pass_number = 0,
89453 + .tv_id = TV_NONE,
89454 + .properties_required = PROP_cfg | PROP_referenced_vars,
89455 + .properties_provided = 0,
89456 + .properties_destroyed = 0,
89457 + .todo_flags_start = 0,
89458 + .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
89459 + }
89460 +};
89461 +
89462 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89463 +{
89464 + tree fntype;
89465 +
89466 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89467 +
89468 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89469 + fntype = build_function_type_list(void_type_node,
89470 + const_char_ptr_type_node,
89471 + unsigned_type_node,
89472 + const_char_ptr_type_node,
89473 + const_char_ptr_type_node,
89474 + NULL_TREE);
89475 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89476 +
89477 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89478 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89479 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89480 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89481 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89482 +}
89483 +
89484 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89485 +{
89486 + int i;
89487 + const char * const plugin_name = plugin_info->base_name;
89488 + const int argc = plugin_info->argc;
89489 + const struct plugin_argument * const argv = plugin_info->argv;
89490 + bool enable = true;
89491 +
89492 + struct register_pass_info size_overflow_pass_info = {
89493 + .pass = &size_overflow_pass.pass,
89494 + .reference_pass_name = "ssa",
89495 + .ref_pass_instance_number = 1,
89496 + .pos_op = PASS_POS_INSERT_AFTER
89497 + };
89498 +
89499 + if (!plugin_default_version_check(version, &gcc_version)) {
89500 + error(G_("incompatible gcc/plugin versions"));
89501 + return 1;
89502 + }
89503 +
89504 + for (i = 0; i < argc; ++i) {
89505 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89506 + enable = false;
89507 + continue;
89508 + }
89509 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89510 + }
89511 +
89512 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89513 + if (enable) {
89514 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89515 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89516 + }
89517 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89518 +
89519 + return 0;
89520 +}
89521 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89522 new file mode 100644
89523 index 0000000..38d2014
89524 --- /dev/null
89525 +++ b/tools/gcc/stackleak_plugin.c
89526 @@ -0,0 +1,313 @@
89527 +/*
89528 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89529 + * Licensed under the GPL v2
89530 + *
89531 + * Note: the choice of the license means that the compilation process is
89532 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89533 + * but for the kernel it doesn't matter since it doesn't link against
89534 + * any of the gcc libraries
89535 + *
89536 + * gcc plugin to help implement various PaX features
89537 + *
89538 + * - track lowest stack pointer
89539 + *
89540 + * TODO:
89541 + * - initialize all local variables
89542 + *
89543 + * BUGS:
89544 + * - none known
89545 + */
89546 +#include "gcc-plugin.h"
89547 +#include "config.h"
89548 +#include "system.h"
89549 +#include "coretypes.h"
89550 +#include "tree.h"
89551 +#include "tree-pass.h"
89552 +#include "flags.h"
89553 +#include "intl.h"
89554 +#include "toplev.h"
89555 +#include "plugin.h"
89556 +//#include "expr.h" where are you...
89557 +#include "diagnostic.h"
89558 +#include "plugin-version.h"
89559 +#include "tm.h"
89560 +#include "function.h"
89561 +#include "basic-block.h"
89562 +#include "gimple.h"
89563 +#include "rtl.h"
89564 +#include "emit-rtl.h"
89565 +
89566 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89567 +
89568 +int plugin_is_GPL_compatible;
89569 +
89570 +static int track_frame_size = -1;
89571 +static const char track_function[] = "pax_track_stack";
89572 +static const char check_function[] = "pax_check_alloca";
89573 +static bool init_locals;
89574 +
89575 +static struct plugin_info stackleak_plugin_info = {
89576 + .version = "201203140940",
89577 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89578 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89579 +};
89580 +
89581 +static bool gate_stackleak_track_stack(void);
89582 +static unsigned int execute_stackleak_tree_instrument(void);
89583 +static unsigned int execute_stackleak_final(void);
89584 +
89585 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89586 + .pass = {
89587 + .type = GIMPLE_PASS,
89588 + .name = "stackleak_tree_instrument",
89589 + .gate = gate_stackleak_track_stack,
89590 + .execute = execute_stackleak_tree_instrument,
89591 + .sub = NULL,
89592 + .next = NULL,
89593 + .static_pass_number = 0,
89594 + .tv_id = TV_NONE,
89595 + .properties_required = PROP_gimple_leh | PROP_cfg,
89596 + .properties_provided = 0,
89597 + .properties_destroyed = 0,
89598 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89599 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89600 + }
89601 +};
89602 +
89603 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89604 + .pass = {
89605 + .type = RTL_PASS,
89606 + .name = "stackleak_final",
89607 + .gate = gate_stackleak_track_stack,
89608 + .execute = execute_stackleak_final,
89609 + .sub = NULL,
89610 + .next = NULL,
89611 + .static_pass_number = 0,
89612 + .tv_id = TV_NONE,
89613 + .properties_required = 0,
89614 + .properties_provided = 0,
89615 + .properties_destroyed = 0,
89616 + .todo_flags_start = 0,
89617 + .todo_flags_finish = TODO_dump_func
89618 + }
89619 +};
89620 +
89621 +static bool gate_stackleak_track_stack(void)
89622 +{
89623 + return track_frame_size >= 0;
89624 +}
89625 +
89626 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89627 +{
89628 + gimple check_alloca;
89629 + tree fntype, fndecl, alloca_size;
89630 +
89631 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89632 + fndecl = build_fn_decl(check_function, fntype);
89633 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89634 +
89635 + // insert call to void pax_check_alloca(unsigned long size)
89636 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89637 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89638 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89639 +}
89640 +
89641 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89642 +{
89643 + gimple track_stack;
89644 + tree fntype, fndecl;
89645 +
89646 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89647 + fndecl = build_fn_decl(track_function, fntype);
89648 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89649 +
89650 + // insert call to void pax_track_stack(void)
89651 + track_stack = gimple_build_call(fndecl, 0);
89652 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89653 +}
89654 +
89655 +#if BUILDING_GCC_VERSION == 4005
89656 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89657 +{
89658 + tree fndecl;
89659 +
89660 + if (!is_gimple_call(stmt))
89661 + return false;
89662 + fndecl = gimple_call_fndecl(stmt);
89663 + if (!fndecl)
89664 + return false;
89665 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89666 + return false;
89667 +// print_node(stderr, "pax", fndecl, 4);
89668 + return DECL_FUNCTION_CODE(fndecl) == code;
89669 +}
89670 +#endif
89671 +
89672 +static bool is_alloca(gimple stmt)
89673 +{
89674 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89675 + return true;
89676 +
89677 +#if BUILDING_GCC_VERSION >= 4007
89678 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89679 + return true;
89680 +#endif
89681 +
89682 + return false;
89683 +}
89684 +
89685 +static unsigned int execute_stackleak_tree_instrument(void)
89686 +{
89687 + basic_block bb, entry_bb;
89688 + bool prologue_instrumented = false, is_leaf = true;
89689 +
89690 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89691 +
89692 + // 1. loop through BBs and GIMPLE statements
89693 + FOR_EACH_BB(bb) {
89694 + gimple_stmt_iterator gsi;
89695 +
89696 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89697 + gimple stmt;
89698 +
89699 + stmt = gsi_stmt(gsi);
89700 +
89701 + if (is_gimple_call(stmt))
89702 + is_leaf = false;
89703 +
89704 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89705 + if (!is_alloca(stmt))
89706 + continue;
89707 +
89708 + // 2. insert stack overflow check before each __builtin_alloca call
89709 + stackleak_check_alloca(&gsi);
89710 +
89711 + // 3. insert track call after each __builtin_alloca call
89712 + stackleak_add_instrumentation(&gsi);
89713 + if (bb == entry_bb)
89714 + prologue_instrumented = true;
89715 + }
89716 + }
89717 +
89718 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89719 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89720 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89721 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89722 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89723 + return 0;
89724 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89725 + return 0;
89726 +
89727 + // 4. insert track call at the beginning
89728 + if (!prologue_instrumented) {
89729 + gimple_stmt_iterator gsi;
89730 +
89731 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89732 + if (dom_info_available_p(CDI_DOMINATORS))
89733 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89734 + gsi = gsi_start_bb(bb);
89735 + stackleak_add_instrumentation(&gsi);
89736 + }
89737 +
89738 + return 0;
89739 +}
89740 +
89741 +static unsigned int execute_stackleak_final(void)
89742 +{
89743 + rtx insn;
89744 +
89745 + if (cfun->calls_alloca)
89746 + return 0;
89747 +
89748 + // keep calls only if function frame is big enough
89749 + if (get_frame_size() >= track_frame_size)
89750 + return 0;
89751 +
89752 + // 1. find pax_track_stack calls
89753 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89754 + // 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))
89755 + rtx body;
89756 +
89757 + if (!CALL_P(insn))
89758 + continue;
89759 + body = PATTERN(insn);
89760 + if (GET_CODE(body) != CALL)
89761 + continue;
89762 + body = XEXP(body, 0);
89763 + if (GET_CODE(body) != MEM)
89764 + continue;
89765 + body = XEXP(body, 0);
89766 + if (GET_CODE(body) != SYMBOL_REF)
89767 + continue;
89768 + if (strcmp(XSTR(body, 0), track_function))
89769 + continue;
89770 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89771 + // 2. delete call
89772 + insn = delete_insn_and_edges(insn);
89773 +#if BUILDING_GCC_VERSION >= 4007
89774 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89775 + insn = delete_insn_and_edges(insn);
89776 +#endif
89777 + }
89778 +
89779 +// print_simple_rtl(stderr, get_insns());
89780 +// print_rtl(stderr, get_insns());
89781 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89782 +
89783 + return 0;
89784 +}
89785 +
89786 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89787 +{
89788 + const char * const plugin_name = plugin_info->base_name;
89789 + const int argc = plugin_info->argc;
89790 + const struct plugin_argument * const argv = plugin_info->argv;
89791 + int i;
89792 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89793 + .pass = &stackleak_tree_instrument_pass.pass,
89794 +// .reference_pass_name = "tree_profile",
89795 + .reference_pass_name = "optimized",
89796 + .ref_pass_instance_number = 1,
89797 + .pos_op = PASS_POS_INSERT_BEFORE
89798 + };
89799 + struct register_pass_info stackleak_final_pass_info = {
89800 + .pass = &stackleak_final_rtl_opt_pass.pass,
89801 + .reference_pass_name = "final",
89802 + .ref_pass_instance_number = 1,
89803 + .pos_op = PASS_POS_INSERT_BEFORE
89804 + };
89805 +
89806 + if (!plugin_default_version_check(version, &gcc_version)) {
89807 + error(G_("incompatible gcc/plugin versions"));
89808 + return 1;
89809 + }
89810 +
89811 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89812 +
89813 + for (i = 0; i < argc; ++i) {
89814 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89815 + if (!argv[i].value) {
89816 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89817 + continue;
89818 + }
89819 + track_frame_size = atoi(argv[i].value);
89820 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89821 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89822 + continue;
89823 + }
89824 + if (!strcmp(argv[i].key, "initialize-locals")) {
89825 + if (argv[i].value) {
89826 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89827 + continue;
89828 + }
89829 + init_locals = true;
89830 + continue;
89831 + }
89832 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89833 + }
89834 +
89835 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89836 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89837 +
89838 + return 0;
89839 +}
89840 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89841 index 6789d78..4afd019e 100644
89842 --- a/tools/perf/util/include/asm/alternative-asm.h
89843 +++ b/tools/perf/util/include/asm/alternative-asm.h
89844 @@ -5,4 +5,7 @@
89845
89846 #define altinstruction_entry #
89847
89848 + .macro pax_force_retaddr rip=0, reload=0
89849 + .endm
89850 +
89851 #endif
89852 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89853 index d617f69..6b445d2 100644
89854 --- a/virt/kvm/kvm_main.c
89855 +++ b/virt/kvm/kvm_main.c
89856 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89857
89858 static cpumask_var_t cpus_hardware_enabled;
89859 static int kvm_usage_count = 0;
89860 -static atomic_t hardware_enable_failed;
89861 +static atomic_unchecked_t hardware_enable_failed;
89862
89863 struct kmem_cache *kvm_vcpu_cache;
89864 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89865 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89866 /* We can read the guest memory with __xxx_user() later on. */
89867 if (user_alloc &&
89868 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89869 - !access_ok(VERIFY_WRITE,
89870 + !__access_ok(VERIFY_WRITE,
89871 (void __user *)(unsigned long)mem->userspace_addr,
89872 mem->memory_size)))
89873 goto out;
89874 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89875
89876 if (r) {
89877 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89878 - atomic_inc(&hardware_enable_failed);
89879 + atomic_inc_unchecked(&hardware_enable_failed);
89880 printk(KERN_INFO "kvm: enabling virtualization on "
89881 "CPU%d failed\n", cpu);
89882 }
89883 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89884
89885 kvm_usage_count++;
89886 if (kvm_usage_count == 1) {
89887 - atomic_set(&hardware_enable_failed, 0);
89888 + atomic_set_unchecked(&hardware_enable_failed, 0);
89889 on_each_cpu(hardware_enable_nolock, NULL, 1);
89890
89891 - if (atomic_read(&hardware_enable_failed)) {
89892 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89893 hardware_disable_all_nolock();
89894 r = -EBUSY;
89895 }
89896 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89897 kvm_arch_vcpu_put(vcpu);
89898 }
89899
89900 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89901 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89902 struct module *module)
89903 {
89904 int r;
89905 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89906 if (!vcpu_align)
89907 vcpu_align = __alignof__(struct kvm_vcpu);
89908 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89909 - 0, NULL);
89910 + SLAB_USERCOPY, NULL);
89911 if (!kvm_vcpu_cache) {
89912 r = -ENOMEM;
89913 goto out_free_3;
89914 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89915 if (r)
89916 goto out_free;
89917
89918 - kvm_chardev_ops.owner = module;
89919 - kvm_vm_fops.owner = module;
89920 - kvm_vcpu_fops.owner = module;
89921 + pax_open_kernel();
89922 + *(void **)&kvm_chardev_ops.owner = module;
89923 + *(void **)&kvm_vm_fops.owner = module;
89924 + *(void **)&kvm_vcpu_fops.owner = module;
89925 + pax_close_kernel();
89926
89927 r = misc_register(&kvm_dev);
89928 if (r) {