]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.5-201210312121.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.5-201210312121.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/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34787 index 57d64b8..623dd86 100644
34788 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34789 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34790 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34791 */
34792
34793 #define ATL2_PARAM(X, desc) \
34794 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34795 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34796 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34797 MODULE_PARM_DESC(X, desc);
34798 #else
34799 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34800 index f83e033..8b4f43a 100644
34801 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34802 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34803 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34804
34805 int (*wait_comp)(struct bnx2x *bp,
34806 struct bnx2x_rx_mode_ramrod_params *p);
34807 -};
34808 +} __no_const;
34809
34810 /********************** Set multicast group ***********************************/
34811
34812 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34813 index 6d52cb2..bc95640 100644
34814 --- a/drivers/net/ethernet/broadcom/tg3.h
34815 +++ b/drivers/net/ethernet/broadcom/tg3.h
34816 @@ -140,6 +140,7 @@
34817 #define CHIPREV_ID_5750_A0 0x4000
34818 #define CHIPREV_ID_5750_A1 0x4001
34819 #define CHIPREV_ID_5750_A3 0x4003
34820 +#define CHIPREV_ID_5750_C1 0x4201
34821 #define CHIPREV_ID_5750_C2 0x4202
34822 #define CHIPREV_ID_5752_A0_HW 0x5000
34823 #define CHIPREV_ID_5752_A0 0x6000
34824 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34825 index 8cffcdf..aadf043 100644
34826 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34827 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34828 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34829 */
34830 struct l2t_skb_cb {
34831 arp_failure_handler_func arp_failure_handler;
34832 -};
34833 +} __no_const;
34834
34835 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34836
34837 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34838 index f879e92..726f20f 100644
34839 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34840 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34841 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34842 for (i=0; i<ETH_ALEN; i++) {
34843 tmp.addr[i] = dev->dev_addr[i];
34844 }
34845 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34846 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34847 break;
34848
34849 case DE4X5_SET_HWADDR: /* Set the hardware address */
34850 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34851 spin_lock_irqsave(&lp->lock, flags);
34852 memcpy(&statbuf, &lp->pktStats, ioc->len);
34853 spin_unlock_irqrestore(&lp->lock, flags);
34854 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34855 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34856 return -EFAULT;
34857 break;
34858 }
34859 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34860 index ed7d1dc..d426748 100644
34861 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34862 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34863 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34864 {NULL}};
34865
34866
34867 -static const char *block_name[] __devinitdata = {
34868 +static const char *block_name[] __devinitconst = {
34869 "21140 non-MII",
34870 "21140 MII PHY",
34871 "21142 Serial PHY",
34872 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34873 index 75d45f8..3d9c55b 100644
34874 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34875 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34876 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34877 struct uli_phy_ops {
34878 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34879 u16 (*read)(struct uli526x_board_info *, u8, u8);
34880 - } phy;
34881 + } __no_const phy;
34882 struct net_device *next_dev; /* next device */
34883 struct pci_dev *pdev; /* PCI device */
34884 spinlock_t lock;
34885 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34886 index 4d1ffca..7c1ec4d 100644
34887 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34888 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34889 @@ -236,7 +236,7 @@ struct pci_id_info {
34890 int drv_flags; /* Driver use, intended as capability flags. */
34891 };
34892
34893 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34894 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34895 { /* Sometime a Level-One switch card. */
34896 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34897 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34898 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34899 index d7bb52a..3b83588 100644
34900 --- a/drivers/net/ethernet/dlink/sundance.c
34901 +++ b/drivers/net/ethernet/dlink/sundance.c
34902 @@ -218,7 +218,7 @@ enum {
34903 struct pci_id_info {
34904 const char *name;
34905 };
34906 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34907 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34908 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34909 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34910 {"D-Link DFE-580TX 4 port Server Adapter"},
34911 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34912 index 78b8aa8..dd6323a 100644
34913 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34914 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34915 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34916
34917 if (wrapped)
34918 newacc += 65536;
34919 - ACCESS_ONCE(*acc) = newacc;
34920 + ACCESS_ONCE_RW(*acc) = newacc;
34921 }
34922
34923 void be_parse_stats(struct be_adapter *adapter)
34924 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34925 index 74d749e..eefb1bd 100644
34926 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34927 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34928 @@ -31,6 +31,8 @@
34929 #include <linux/netdevice.h>
34930 #include <linux/phy.h>
34931 #include <linux/platform_device.h>
34932 +#include <linux/interrupt.h>
34933 +#include <linux/irqreturn.h>
34934 #include <net/ip.h>
34935
34936 #include "ftgmac100.h"
34937 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34938 index b901a01..1ff32ee 100644
34939 --- a/drivers/net/ethernet/faraday/ftmac100.c
34940 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34941 @@ -31,6 +31,8 @@
34942 #include <linux/module.h>
34943 #include <linux/netdevice.h>
34944 #include <linux/platform_device.h>
34945 +#include <linux/interrupt.h>
34946 +#include <linux/irqreturn.h>
34947
34948 #include "ftmac100.h"
34949
34950 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34951 index 9d71c9c..0e4a0ac 100644
34952 --- a/drivers/net/ethernet/fealnx.c
34953 +++ b/drivers/net/ethernet/fealnx.c
34954 @@ -150,7 +150,7 @@ struct chip_info {
34955 int flags;
34956 };
34957
34958 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34959 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34960 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34961 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34962 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34963 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34964 index ed5b409..ec37828 100644
34965 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34966 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34967 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34968 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34969 s32 (*read_mac_addr)(struct e1000_hw *);
34970 };
34971 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34972
34973 /*
34974 * When to use various PHY register access functions:
34975 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34976 void (*power_up)(struct e1000_hw *);
34977 void (*power_down)(struct e1000_hw *);
34978 };
34979 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34980
34981 /* Function pointers for the NVM. */
34982 struct e1000_nvm_operations {
34983 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
34984 s32 (*validate)(struct e1000_hw *);
34985 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
34986 };
34987 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
34988
34989 struct e1000_mac_info {
34990 - struct e1000_mac_operations ops;
34991 + e1000_mac_operations_no_const ops;
34992 u8 addr[ETH_ALEN];
34993 u8 perm_addr[ETH_ALEN];
34994
34995 @@ -892,7 +895,7 @@ struct e1000_mac_info {
34996 };
34997
34998 struct e1000_phy_info {
34999 - struct e1000_phy_operations ops;
35000 + e1000_phy_operations_no_const ops;
35001
35002 enum e1000_phy_type type;
35003
35004 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35005 };
35006
35007 struct e1000_nvm_info {
35008 - struct e1000_nvm_operations ops;
35009 + e1000_nvm_operations_no_const ops;
35010
35011 enum e1000_nvm_type type;
35012 enum e1000_nvm_override override;
35013 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35014 index c2a51dc..c2bd262 100644
35015 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35016 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35017 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35018 void (*release_swfw_sync)(struct e1000_hw *, u16);
35019
35020 };
35021 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35022
35023 struct e1000_phy_operations {
35024 s32 (*acquire)(struct e1000_hw *);
35025 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35026 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35027 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35028 };
35029 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35030
35031 struct e1000_nvm_operations {
35032 s32 (*acquire)(struct e1000_hw *);
35033 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35034 s32 (*validate)(struct e1000_hw *);
35035 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35036 };
35037 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35038
35039 struct e1000_info {
35040 s32 (*get_invariants)(struct e1000_hw *);
35041 @@ -364,7 +367,7 @@ struct e1000_info {
35042 extern const struct e1000_info e1000_82575_info;
35043
35044 struct e1000_mac_info {
35045 - struct e1000_mac_operations ops;
35046 + e1000_mac_operations_no_const ops;
35047
35048 u8 addr[6];
35049 u8 perm_addr[6];
35050 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35051 };
35052
35053 struct e1000_phy_info {
35054 - struct e1000_phy_operations ops;
35055 + e1000_phy_operations_no_const ops;
35056
35057 enum e1000_phy_type type;
35058
35059 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35060 };
35061
35062 struct e1000_nvm_info {
35063 - struct e1000_nvm_operations ops;
35064 + e1000_nvm_operations_no_const ops;
35065 enum e1000_nvm_type type;
35066 enum e1000_nvm_override override;
35067
35068 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35069 s32 (*check_for_ack)(struct e1000_hw *, u16);
35070 s32 (*check_for_rst)(struct e1000_hw *, u16);
35071 };
35072 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35073
35074 struct e1000_mbx_stats {
35075 u32 msgs_tx;
35076 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35077 };
35078
35079 struct e1000_mbx_info {
35080 - struct e1000_mbx_operations ops;
35081 + e1000_mbx_operations_no_const ops;
35082 struct e1000_mbx_stats stats;
35083 u32 timeout;
35084 u32 usec_delay;
35085 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35086 index 57db3c6..aa825fc 100644
35087 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35088 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35089 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35090 s32 (*read_mac_addr)(struct e1000_hw *);
35091 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35092 };
35093 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35094
35095 struct e1000_mac_info {
35096 - struct e1000_mac_operations ops;
35097 + e1000_mac_operations_no_const ops;
35098 u8 addr[6];
35099 u8 perm_addr[6];
35100
35101 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35102 s32 (*check_for_ack)(struct e1000_hw *);
35103 s32 (*check_for_rst)(struct e1000_hw *);
35104 };
35105 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35106
35107 struct e1000_mbx_stats {
35108 u32 msgs_tx;
35109 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35110 };
35111
35112 struct e1000_mbx_info {
35113 - struct e1000_mbx_operations ops;
35114 + e1000_mbx_operations_no_const ops;
35115 struct e1000_mbx_stats stats;
35116 u32 timeout;
35117 u32 usec_delay;
35118 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35119 index 3456d56..b688d81 100644
35120 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35121 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35122 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35123 /* store the new cycle speed */
35124 adapter->cycle_speed = cycle_speed;
35125
35126 - ACCESS_ONCE(adapter->base_incval) = incval;
35127 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35128 smp_mb();
35129
35130 /* grab the ptp lock */
35131 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35132 index 400f86a..7f2e062 100644
35133 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35134 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35135 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35136 s32 (*update_checksum)(struct ixgbe_hw *);
35137 u16 (*calc_checksum)(struct ixgbe_hw *);
35138 };
35139 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35140
35141 struct ixgbe_mac_operations {
35142 s32 (*init_hw)(struct ixgbe_hw *);
35143 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35144 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35145 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35146 };
35147 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35148
35149 struct ixgbe_phy_operations {
35150 s32 (*identify)(struct ixgbe_hw *);
35151 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35152 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35153 s32 (*check_overtemp)(struct ixgbe_hw *);
35154 };
35155 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35156
35157 struct ixgbe_eeprom_info {
35158 - struct ixgbe_eeprom_operations ops;
35159 + ixgbe_eeprom_operations_no_const ops;
35160 enum ixgbe_eeprom_type type;
35161 u32 semaphore_delay;
35162 u16 word_size;
35163 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35164
35165 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35166 struct ixgbe_mac_info {
35167 - struct ixgbe_mac_operations ops;
35168 + ixgbe_mac_operations_no_const ops;
35169 enum ixgbe_mac_type type;
35170 u8 addr[ETH_ALEN];
35171 u8 perm_addr[ETH_ALEN];
35172 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35173 };
35174
35175 struct ixgbe_phy_info {
35176 - struct ixgbe_phy_operations ops;
35177 + ixgbe_phy_operations_no_const ops;
35178 struct mdio_if_info mdio;
35179 enum ixgbe_phy_type type;
35180 u32 id;
35181 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35182 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35183 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35184 };
35185 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35186
35187 struct ixgbe_mbx_stats {
35188 u32 msgs_tx;
35189 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35190 };
35191
35192 struct ixgbe_mbx_info {
35193 - struct ixgbe_mbx_operations ops;
35194 + ixgbe_mbx_operations_no_const ops;
35195 struct ixgbe_mbx_stats stats;
35196 u32 timeout;
35197 u32 usec_delay;
35198 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35199 index 25c951d..cc7cf33 100644
35200 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35201 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35202 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35203 s32 (*clear_vfta)(struct ixgbe_hw *);
35204 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35205 };
35206 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35207
35208 enum ixgbe_mac_type {
35209 ixgbe_mac_unknown = 0,
35210 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35211 };
35212
35213 struct ixgbe_mac_info {
35214 - struct ixgbe_mac_operations ops;
35215 + ixgbe_mac_operations_no_const ops;
35216 u8 addr[6];
35217 u8 perm_addr[6];
35218
35219 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35220 s32 (*check_for_ack)(struct ixgbe_hw *);
35221 s32 (*check_for_rst)(struct ixgbe_hw *);
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 @@ -114,7 +116,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 udelay;
35236 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35237 index 9e0c1ee..8471f77 100644
35238 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35239 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35240 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35241 void (*link_down)(struct __vxge_hw_device *devh);
35242 void (*crit_err)(struct __vxge_hw_device *devh,
35243 enum vxge_hw_event type, u64 ext_data);
35244 -};
35245 +} __no_const;
35246
35247 /*
35248 * struct __vxge_hw_blockpool_entry - Block private data structure
35249 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35250 index 4a518a3..936b334 100644
35251 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35252 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35253 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35254 struct vxge_hw_mempool_dma *dma_object,
35255 u32 index,
35256 u32 is_last);
35257 -};
35258 +} __no_const;
35259
35260 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35261 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35262 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35263 index b47d5b3..273a516 100644
35264 --- a/drivers/net/ethernet/realtek/r8169.c
35265 +++ b/drivers/net/ethernet/realtek/r8169.c
35266 @@ -745,22 +745,22 @@ struct rtl8169_private {
35267 struct mdio_ops {
35268 void (*write)(struct rtl8169_private *, int, int);
35269 int (*read)(struct rtl8169_private *, int);
35270 - } mdio_ops;
35271 + } __no_const mdio_ops;
35272
35273 struct pll_power_ops {
35274 void (*down)(struct rtl8169_private *);
35275 void (*up)(struct rtl8169_private *);
35276 - } pll_power_ops;
35277 + } __no_const pll_power_ops;
35278
35279 struct jumbo_ops {
35280 void (*enable)(struct rtl8169_private *);
35281 void (*disable)(struct rtl8169_private *);
35282 - } jumbo_ops;
35283 + } __no_const jumbo_ops;
35284
35285 struct csi_ops {
35286 void (*write)(struct rtl8169_private *, int, int);
35287 u32 (*read)(struct rtl8169_private *, int);
35288 - } csi_ops;
35289 + } __no_const csi_ops;
35290
35291 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35292 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35293 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35294 index 4613591..d816601 100644
35295 --- a/drivers/net/ethernet/sis/sis190.c
35296 +++ b/drivers/net/ethernet/sis/sis190.c
35297 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35298 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35299 struct net_device *dev)
35300 {
35301 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35302 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35303 struct sis190_private *tp = netdev_priv(dev);
35304 struct pci_dev *isa_bridge;
35305 u8 reg, tmp8;
35306 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35307 index 0c74a70..3bc6f68 100644
35308 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35309 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35310 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35311
35312 writel(value, ioaddr + MMC_CNTRL);
35313
35314 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35315 - MMC_CNTRL, value);
35316 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35317 +// MMC_CNTRL, value);
35318 }
35319
35320 /* To mask all all interrupts.*/
35321 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35322 index 95ceb35..318fc12 100644
35323 --- a/drivers/net/hyperv/hyperv_net.h
35324 +++ b/drivers/net/hyperv/hyperv_net.h
35325 @@ -99,7 +99,7 @@ struct rndis_device {
35326
35327 enum rndis_device_state state;
35328 bool link_state;
35329 - atomic_t new_req_id;
35330 + atomic_unchecked_t new_req_id;
35331
35332 spinlock_t request_lock;
35333 struct list_head req_list;
35334 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35335 index 1e88a10..1b01736 100644
35336 --- a/drivers/net/hyperv/rndis_filter.c
35337 +++ b/drivers/net/hyperv/rndis_filter.c
35338 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35339 * template
35340 */
35341 set = &rndis_msg->msg.set_req;
35342 - set->req_id = atomic_inc_return(&dev->new_req_id);
35343 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35344
35345 /* Add to the request list */
35346 spin_lock_irqsave(&dev->request_lock, flags);
35347 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35348
35349 /* Setup the rndis set */
35350 halt = &request->request_msg.msg.halt_req;
35351 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35352 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35353
35354 /* Ignore return since this msg is optional. */
35355 rndis_filter_send_request(dev, request);
35356 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35357 index 5c05572..389610b 100644
35358 --- a/drivers/net/ppp/ppp_generic.c
35359 +++ b/drivers/net/ppp/ppp_generic.c
35360 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35361 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35362 struct ppp_stats stats;
35363 struct ppp_comp_stats cstats;
35364 - char *vers;
35365
35366 switch (cmd) {
35367 case SIOCGPPPSTATS:
35368 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35369 break;
35370
35371 case SIOCGPPPVER:
35372 - vers = PPP_VERSION;
35373 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35374 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35375 break;
35376 err = 0;
35377 break;
35378 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35379 index 3a16d4f..a311cec 100644
35380 --- a/drivers/net/tun.c
35381 +++ b/drivers/net/tun.c
35382 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35383 }
35384
35385 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35386 - unsigned long arg, int ifreq_len)
35387 + unsigned long arg, size_t ifreq_len)
35388 {
35389 struct tun_file *tfile = file->private_data;
35390 struct tun_struct *tun;
35391 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35392 int vnet_hdr_sz;
35393 int ret;
35394
35395 + if (ifreq_len > sizeof ifr)
35396 + return -EFAULT;
35397 +
35398 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35399 if (copy_from_user(&ifr, argp, ifreq_len))
35400 return -EFAULT;
35401 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35402 index 62f30b4..ff99dfd 100644
35403 --- a/drivers/net/usb/hso.c
35404 +++ b/drivers/net/usb/hso.c
35405 @@ -71,7 +71,7 @@
35406 #include <asm/byteorder.h>
35407 #include <linux/serial_core.h>
35408 #include <linux/serial.h>
35409 -
35410 +#include <asm/local.h>
35411
35412 #define MOD_AUTHOR "Option Wireless"
35413 #define MOD_DESCRIPTION "USB High Speed Option driver"
35414 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35415 struct urb *urb;
35416
35417 urb = serial->rx_urb[0];
35418 - if (serial->port.count > 0) {
35419 + if (atomic_read(&serial->port.count) > 0) {
35420 count = put_rxbuf_data(urb, serial);
35421 if (count == -1)
35422 return;
35423 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35424 DUMP1(urb->transfer_buffer, urb->actual_length);
35425
35426 /* Anyone listening? */
35427 - if (serial->port.count == 0)
35428 + if (atomic_read(&serial->port.count) == 0)
35429 return;
35430
35431 if (status == 0) {
35432 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35433 tty_port_tty_set(&serial->port, tty);
35434
35435 /* check for port already opened, if not set the termios */
35436 - serial->port.count++;
35437 - if (serial->port.count == 1) {
35438 + if (atomic_inc_return(&serial->port.count) == 1) {
35439 serial->rx_state = RX_IDLE;
35440 /* Force default termio settings */
35441 _hso_serial_set_termios(tty, NULL);
35442 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35443 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35444 if (result) {
35445 hso_stop_serial_device(serial->parent);
35446 - serial->port.count--;
35447 + atomic_dec(&serial->port.count);
35448 kref_put(&serial->parent->ref, hso_serial_ref_free);
35449 }
35450 } else {
35451 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35452
35453 /* reset the rts and dtr */
35454 /* do the actual close */
35455 - serial->port.count--;
35456 + atomic_dec(&serial->port.count);
35457
35458 - if (serial->port.count <= 0) {
35459 - serial->port.count = 0;
35460 + if (atomic_read(&serial->port.count) <= 0) {
35461 + atomic_set(&serial->port.count, 0);
35462 tty_port_tty_set(&serial->port, NULL);
35463 if (!usb_gone)
35464 hso_stop_serial_device(serial->parent);
35465 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35466
35467 /* the actual setup */
35468 spin_lock_irqsave(&serial->serial_lock, flags);
35469 - if (serial->port.count)
35470 + if (atomic_read(&serial->port.count))
35471 _hso_serial_set_termios(tty, old);
35472 else
35473 tty->termios = old;
35474 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35475 D1("Pending read interrupt on port %d\n", i);
35476 spin_lock(&serial->serial_lock);
35477 if (serial->rx_state == RX_IDLE &&
35478 - serial->port.count > 0) {
35479 + atomic_read(&serial->port.count) > 0) {
35480 /* Setup and send a ctrl req read on
35481 * port i */
35482 if (!serial->rx_urb_filled[0]) {
35483 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35484 /* Start all serial ports */
35485 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35486 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35487 - if (dev2ser(serial_table[i])->port.count) {
35488 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35489 result =
35490 hso_start_serial_device(serial_table[i], GFP_NOIO);
35491 hso_kick_transmit(dev2ser(serial_table[i]));
35492 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35493 index 6169fbd..40e8422 100644
35494 --- a/drivers/net/wireless/ath/ath.h
35495 +++ b/drivers/net/wireless/ath/ath.h
35496 @@ -119,6 +119,7 @@ struct ath_ops {
35497 void (*write_flush) (void *);
35498 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35499 };
35500 +typedef struct ath_ops __no_const ath_ops_no_const;
35501
35502 struct ath_common;
35503 struct ath_bus_ops;
35504 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35505 index 8d78253..bebbb68 100644
35506 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35507 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35508 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35509 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35510 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35511
35512 - ACCESS_ONCE(ads->ds_link) = i->link;
35513 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35514 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35515 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35516
35517 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35518 ctl6 = SM(i->keytype, AR_EncrType);
35519 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35520
35521 if ((i->is_first || i->is_last) &&
35522 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35523 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35524 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35525 | set11nTries(i->rates, 1)
35526 | set11nTries(i->rates, 2)
35527 | set11nTries(i->rates, 3)
35528 | (i->dur_update ? AR_DurUpdateEna : 0)
35529 | SM(0, AR_BurstDur);
35530
35531 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35532 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35533 | set11nRate(i->rates, 1)
35534 | set11nRate(i->rates, 2)
35535 | set11nRate(i->rates, 3);
35536 } else {
35537 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35538 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35539 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35540 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35541 }
35542
35543 if (!i->is_first) {
35544 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35545 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35546 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35547 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35548 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35549 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35550 return;
35551 }
35552
35553 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35554 break;
35555 }
35556
35557 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35558 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35559 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35560 | SM(i->txpower, AR_XmitPower)
35561 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35562 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35563 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35564 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35565
35566 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35567 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35568 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35569 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35570
35571 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35572 return;
35573
35574 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35575 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35576 | set11nPktDurRTSCTS(i->rates, 1);
35577
35578 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35579 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35580 | set11nPktDurRTSCTS(i->rates, 3);
35581
35582 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35583 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35584 | set11nRateFlags(i->rates, 1)
35585 | set11nRateFlags(i->rates, 2)
35586 | set11nRateFlags(i->rates, 3)
35587 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35588 index 78816b8..1fcdfae 100644
35589 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35590 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35591 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35592 (i->qcu << AR_TxQcuNum_S) | desc_len;
35593
35594 checksum += val;
35595 - ACCESS_ONCE(ads->info) = val;
35596 + ACCESS_ONCE_RW(ads->info) = val;
35597
35598 checksum += i->link;
35599 - ACCESS_ONCE(ads->link) = i->link;
35600 + ACCESS_ONCE_RW(ads->link) = i->link;
35601
35602 checksum += i->buf_addr[0];
35603 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35604 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35605 checksum += i->buf_addr[1];
35606 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35607 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35608 checksum += i->buf_addr[2];
35609 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35610 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35611 checksum += i->buf_addr[3];
35612 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35613 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35614
35615 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35616 - ACCESS_ONCE(ads->ctl3) = val;
35617 + ACCESS_ONCE_RW(ads->ctl3) = val;
35618 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35619 - ACCESS_ONCE(ads->ctl5) = val;
35620 + ACCESS_ONCE_RW(ads->ctl5) = val;
35621 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35622 - ACCESS_ONCE(ads->ctl7) = val;
35623 + ACCESS_ONCE_RW(ads->ctl7) = val;
35624 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35625 - ACCESS_ONCE(ads->ctl9) = val;
35626 + ACCESS_ONCE_RW(ads->ctl9) = val;
35627
35628 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35629 - ACCESS_ONCE(ads->ctl10) = checksum;
35630 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35631
35632 if (i->is_first || i->is_last) {
35633 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35634 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35635 | set11nTries(i->rates, 1)
35636 | set11nTries(i->rates, 2)
35637 | set11nTries(i->rates, 3)
35638 | (i->dur_update ? AR_DurUpdateEna : 0)
35639 | SM(0, AR_BurstDur);
35640
35641 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35642 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35643 | set11nRate(i->rates, 1)
35644 | set11nRate(i->rates, 2)
35645 | set11nRate(i->rates, 3);
35646 } else {
35647 - ACCESS_ONCE(ads->ctl13) = 0;
35648 - ACCESS_ONCE(ads->ctl14) = 0;
35649 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35650 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35651 }
35652
35653 ads->ctl20 = 0;
35654 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35655
35656 ctl17 = SM(i->keytype, AR_EncrType);
35657 if (!i->is_first) {
35658 - ACCESS_ONCE(ads->ctl11) = 0;
35659 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35660 - ACCESS_ONCE(ads->ctl15) = 0;
35661 - ACCESS_ONCE(ads->ctl16) = 0;
35662 - ACCESS_ONCE(ads->ctl17) = ctl17;
35663 - ACCESS_ONCE(ads->ctl18) = 0;
35664 - ACCESS_ONCE(ads->ctl19) = 0;
35665 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35666 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35667 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35668 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35669 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35670 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35671 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35672 return;
35673 }
35674
35675 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35676 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35677 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35678 | SM(i->txpower, AR_XmitPower)
35679 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35680 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35681 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35682 ctl12 |= SM(val, AR_PAPRDChainMask);
35683
35684 - ACCESS_ONCE(ads->ctl12) = ctl12;
35685 - ACCESS_ONCE(ads->ctl17) = ctl17;
35686 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35687 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35688
35689 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35690 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35691 | set11nPktDurRTSCTS(i->rates, 1);
35692
35693 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35694 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35695 | set11nPktDurRTSCTS(i->rates, 3);
35696
35697 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35698 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35699 | set11nRateFlags(i->rates, 1)
35700 | set11nRateFlags(i->rates, 2)
35701 | set11nRateFlags(i->rates, 3)
35702 | SM(i->rtscts_rate, AR_RTSCTSRate);
35703
35704 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35705 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35706 }
35707
35708 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35709 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35710 index de6968f..29ac4c1 100644
35711 --- a/drivers/net/wireless/ath/ath9k/hw.h
35712 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35713 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35714
35715 /* ANI */
35716 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35717 -};
35718 +} __no_const;
35719
35720 /**
35721 * struct ath_hw_ops - callbacks used by hardware code and driver code
35722 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35723 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35724 struct ath_hw_antcomb_conf *antconf);
35725
35726 -};
35727 +} __no_const;
35728
35729 struct ath_nf_limits {
35730 s16 max;
35731 @@ -706,7 +706,7 @@ enum ath_cal_list {
35732 #define AH_FASTCC 0x4
35733
35734 struct ath_hw {
35735 - struct ath_ops reg_ops;
35736 + ath_ops_no_const reg_ops;
35737
35738 struct ieee80211_hw *hw;
35739 struct ath_common common;
35740 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35741 index af00e2c..ab04d34 100644
35742 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35743 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35744 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35745 void (*carrsuppr)(struct brcms_phy *);
35746 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35747 void (*detach)(struct brcms_phy *);
35748 -};
35749 +} __no_const;
35750
35751 struct brcms_phy {
35752 struct brcms_phy_pub pubpi_ro;
35753 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35754 index faec404..a5277f1 100644
35755 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35756 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35757 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35758 */
35759 if (il3945_mod_params.disable_hw_scan) {
35760 D_INFO("Disabling hw_scan\n");
35761 - il3945_mac_ops.hw_scan = NULL;
35762 + pax_open_kernel();
35763 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35764 + pax_close_kernel();
35765 }
35766
35767 D_INFO("*** LOAD DRIVER ***\n");
35768 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35769 index a47b306..297daf2 100644
35770 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35771 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35772 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35773 {
35774 struct iwl_priv *priv = file->private_data;
35775 char buf[64];
35776 - int buf_size;
35777 + size_t buf_size;
35778 u32 offset, len;
35779
35780 memset(buf, 0, sizeof(buf));
35781 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35782 struct iwl_priv *priv = file->private_data;
35783
35784 char buf[8];
35785 - int buf_size;
35786 + size_t buf_size;
35787 u32 reset_flag;
35788
35789 memset(buf, 0, sizeof(buf));
35790 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35791 {
35792 struct iwl_priv *priv = file->private_data;
35793 char buf[8];
35794 - int buf_size;
35795 + size_t buf_size;
35796 int ht40;
35797
35798 memset(buf, 0, sizeof(buf));
35799 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35800 {
35801 struct iwl_priv *priv = file->private_data;
35802 char buf[8];
35803 - int buf_size;
35804 + size_t buf_size;
35805 int value;
35806
35807 memset(buf, 0, sizeof(buf));
35808 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35809 {
35810 struct iwl_priv *priv = file->private_data;
35811 char buf[8];
35812 - int buf_size;
35813 + size_t buf_size;
35814 int clear;
35815
35816 memset(buf, 0, sizeof(buf));
35817 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35818 {
35819 struct iwl_priv *priv = file->private_data;
35820 char buf[8];
35821 - int buf_size;
35822 + size_t buf_size;
35823 int trace;
35824
35825 memset(buf, 0, sizeof(buf));
35826 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35827 {
35828 struct iwl_priv *priv = file->private_data;
35829 char buf[8];
35830 - int buf_size;
35831 + size_t buf_size;
35832 int missed;
35833
35834 memset(buf, 0, sizeof(buf));
35835 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35836
35837 struct iwl_priv *priv = file->private_data;
35838 char buf[8];
35839 - int buf_size;
35840 + size_t buf_size;
35841 int plcp;
35842
35843 memset(buf, 0, sizeof(buf));
35844 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35845
35846 struct iwl_priv *priv = file->private_data;
35847 char buf[8];
35848 - int buf_size;
35849 + size_t buf_size;
35850 int flush;
35851
35852 memset(buf, 0, sizeof(buf));
35853 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35854
35855 struct iwl_priv *priv = file->private_data;
35856 char buf[8];
35857 - int buf_size;
35858 + size_t buf_size;
35859 int rts;
35860
35861 if (!priv->cfg->ht_params)
35862 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35863 {
35864 struct iwl_priv *priv = file->private_data;
35865 char buf[8];
35866 - int buf_size;
35867 + size_t buf_size;
35868
35869 memset(buf, 0, sizeof(buf));
35870 buf_size = min(count, sizeof(buf) - 1);
35871 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35872 struct iwl_priv *priv = file->private_data;
35873 u32 event_log_flag;
35874 char buf[8];
35875 - int buf_size;
35876 + size_t buf_size;
35877
35878 /* check that the interface is up */
35879 if (!iwl_is_ready(priv))
35880 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35881 struct iwl_priv *priv = file->private_data;
35882 char buf[8];
35883 u32 calib_disabled;
35884 - int buf_size;
35885 + size_t buf_size;
35886
35887 memset(buf, 0, sizeof(buf));
35888 buf_size = min(count, sizeof(buf) - 1);
35889 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35890 index dbeebef..b45a152 100644
35891 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35892 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35893 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35894 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35895
35896 char buf[8];
35897 - int buf_size;
35898 + size_t buf_size;
35899 u32 reset_flag;
35900
35901 memset(buf, 0, sizeof(buf));
35902 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35903 {
35904 struct iwl_trans *trans = file->private_data;
35905 char buf[8];
35906 - int buf_size;
35907 + size_t buf_size;
35908 int csr;
35909
35910 memset(buf, 0, sizeof(buf));
35911 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35912 index 0083839..fcb7225 100644
35913 --- a/drivers/net/wireless/mac80211_hwsim.c
35914 +++ b/drivers/net/wireless/mac80211_hwsim.c
35915 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35916 return -EINVAL;
35917
35918 if (fake_hw_scan) {
35919 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35920 - mac80211_hwsim_ops.sw_scan_start = NULL;
35921 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35922 + pax_open_kernel();
35923 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35924 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35925 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35926 + pax_close_kernel();
35927 }
35928
35929 spin_lock_init(&hwsim_radio_lock);
35930 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35931 index e7c2a82..582e228 100644
35932 --- a/drivers/net/wireless/mwifiex/main.h
35933 +++ b/drivers/net/wireless/mwifiex/main.h
35934 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
35935 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35936 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35937 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35938 -};
35939 +} __no_const;
35940
35941 struct mwifiex_adapter {
35942 u8 iface_type;
35943 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35944 index 7a4ae9e..56e00bd 100644
35945 --- a/drivers/net/wireless/rndis_wlan.c
35946 +++ b/drivers/net/wireless/rndis_wlan.c
35947 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35948
35949 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35950
35951 - if (rts_threshold < 0 || rts_threshold > 2347)
35952 + if (rts_threshold > 2347)
35953 rts_threshold = 2347;
35954
35955 tmp = cpu_to_le32(rts_threshold);
35956 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35957 index 8afb546..0c0dc5c 100644
35958 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35959 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35960 @@ -397,7 +397,7 @@ struct rt2x00_intf {
35961 * for hardware which doesn't support hardware
35962 * sequence counting.
35963 */
35964 - atomic_t seqno;
35965 + atomic_unchecked_t seqno;
35966 };
35967
35968 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35969 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35970 index f7e74a0..da71431 100644
35971 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35972 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35973 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35974 * sequence counter given by mac80211.
35975 */
35976 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35977 - seqno = atomic_add_return(0x10, &intf->seqno);
35978 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35979 else
35980 - seqno = atomic_read(&intf->seqno);
35981 + seqno = atomic_read_unchecked(&intf->seqno);
35982
35983 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
35984 hdr->seq_ctrl |= cpu_to_le16(seqno);
35985 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
35986 index fd02060..74ee481 100644
35987 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
35988 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
35989 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
35990 void (*reset)(struct wl1251 *wl);
35991 void (*enable_irq)(struct wl1251 *wl);
35992 void (*disable_irq)(struct wl1251 *wl);
35993 -};
35994 +} __no_const;
35995
35996 struct wl1251 {
35997 struct ieee80211_hw *hw;
35998 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
35999 index 0ce7a8e..56a0ccf 100644
36000 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36001 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36002 @@ -81,7 +81,7 @@ struct wlcore_ops {
36003 struct ieee80211_sta *sta,
36004 struct ieee80211_key_conf *key_conf);
36005 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36006 -};
36007 +} __no_const;
36008
36009 enum wlcore_partitions {
36010 PART_DOWN,
36011 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36012 index f34b5b2..b5abb9f 100644
36013 --- a/drivers/oprofile/buffer_sync.c
36014 +++ b/drivers/oprofile/buffer_sync.c
36015 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36016 if (cookie == NO_COOKIE)
36017 offset = pc;
36018 if (cookie == INVALID_COOKIE) {
36019 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36020 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36021 offset = pc;
36022 }
36023 if (cookie != last_cookie) {
36024 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36025 /* add userspace sample */
36026
36027 if (!mm) {
36028 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36029 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36030 return 0;
36031 }
36032
36033 cookie = lookup_dcookie(mm, s->eip, &offset);
36034
36035 if (cookie == INVALID_COOKIE) {
36036 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36037 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36038 return 0;
36039 }
36040
36041 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36042 /* ignore backtraces if failed to add a sample */
36043 if (state == sb_bt_start) {
36044 state = sb_bt_ignore;
36045 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36046 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36047 }
36048 }
36049 release_mm(mm);
36050 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36051 index c0cc4e7..44d4e54 100644
36052 --- a/drivers/oprofile/event_buffer.c
36053 +++ b/drivers/oprofile/event_buffer.c
36054 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36055 }
36056
36057 if (buffer_pos == buffer_size) {
36058 - atomic_inc(&oprofile_stats.event_lost_overflow);
36059 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36060 return;
36061 }
36062
36063 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36064 index ed2c3ec..deda85a 100644
36065 --- a/drivers/oprofile/oprof.c
36066 +++ b/drivers/oprofile/oprof.c
36067 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36068 if (oprofile_ops.switch_events())
36069 return;
36070
36071 - atomic_inc(&oprofile_stats.multiplex_counter);
36072 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36073 start_switch_worker();
36074 }
36075
36076 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36077 index 917d28e..d62d981 100644
36078 --- a/drivers/oprofile/oprofile_stats.c
36079 +++ b/drivers/oprofile/oprofile_stats.c
36080 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36081 cpu_buf->sample_invalid_eip = 0;
36082 }
36083
36084 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36085 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36086 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36087 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36088 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36089 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36090 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36091 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36092 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36093 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36094 }
36095
36096
36097 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36098 index 38b6fc0..b5cbfce 100644
36099 --- a/drivers/oprofile/oprofile_stats.h
36100 +++ b/drivers/oprofile/oprofile_stats.h
36101 @@ -13,11 +13,11 @@
36102 #include <linux/atomic.h>
36103
36104 struct oprofile_stat_struct {
36105 - atomic_t sample_lost_no_mm;
36106 - atomic_t sample_lost_no_mapping;
36107 - atomic_t bt_lost_no_mapping;
36108 - atomic_t event_lost_overflow;
36109 - atomic_t multiplex_counter;
36110 + atomic_unchecked_t sample_lost_no_mm;
36111 + atomic_unchecked_t sample_lost_no_mapping;
36112 + atomic_unchecked_t bt_lost_no_mapping;
36113 + atomic_unchecked_t event_lost_overflow;
36114 + atomic_unchecked_t multiplex_counter;
36115 };
36116
36117 extern struct oprofile_stat_struct oprofile_stats;
36118 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36119 index 849357c..b83c1e0 100644
36120 --- a/drivers/oprofile/oprofilefs.c
36121 +++ b/drivers/oprofile/oprofilefs.c
36122 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36123
36124
36125 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36126 - char const *name, atomic_t *val)
36127 + char const *name, atomic_unchecked_t *val)
36128 {
36129 return __oprofilefs_create_file(sb, root, name,
36130 &atomic_ro_fops, 0444, val);
36131 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36132 index 3f56bc0..707d642 100644
36133 --- a/drivers/parport/procfs.c
36134 +++ b/drivers/parport/procfs.c
36135 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36136
36137 *ppos += len;
36138
36139 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36140 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36141 }
36142
36143 #ifdef CONFIG_PARPORT_1284
36144 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36145
36146 *ppos += len;
36147
36148 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36149 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36150 }
36151 #endif /* IEEE1284.3 support. */
36152
36153 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36154 index 9fff878..ad0ad53 100644
36155 --- a/drivers/pci/hotplug/cpci_hotplug.h
36156 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36157 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36158 int (*hardware_test) (struct slot* slot, u32 value);
36159 u8 (*get_power) (struct slot* slot);
36160 int (*set_power) (struct slot* slot, int value);
36161 -};
36162 +} __no_const;
36163
36164 struct cpci_hp_controller {
36165 unsigned int irq;
36166 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36167 index 76ba8a1..20ca857 100644
36168 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36169 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36170 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36171
36172 void compaq_nvram_init (void __iomem *rom_start)
36173 {
36174 +
36175 +#ifndef CONFIG_PAX_KERNEXEC
36176 if (rom_start) {
36177 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36178 }
36179 +#endif
36180 +
36181 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36182
36183 /* initialize our int15 lock */
36184 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36185 index b500840..d7159d3 100644
36186 --- a/drivers/pci/pcie/aspm.c
36187 +++ b/drivers/pci/pcie/aspm.c
36188 @@ -27,9 +27,9 @@
36189 #define MODULE_PARAM_PREFIX "pcie_aspm."
36190
36191 /* Note: those are not register definitions */
36192 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36193 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36194 -#define ASPM_STATE_L1 (4) /* L1 state */
36195 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36196 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36197 +#define ASPM_STATE_L1 (4U) /* L1 state */
36198 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36199 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36200
36201 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36202 index 61859d0..124539e 100644
36203 --- a/drivers/pci/probe.c
36204 +++ b/drivers/pci/probe.c
36205 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36206 struct pci_bus_region region;
36207 bool bar_too_big = false, bar_disabled = false;
36208
36209 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36210 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36211
36212 /* No printks while decoding is disabled! */
36213 if (!dev->mmio_always_on) {
36214 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36215 index 27911b5..5b6db88 100644
36216 --- a/drivers/pci/proc.c
36217 +++ b/drivers/pci/proc.c
36218 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36219 static int __init pci_proc_init(void)
36220 {
36221 struct pci_dev *dev = NULL;
36222 +
36223 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36224 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36225 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36226 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36227 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36228 +#endif
36229 +#else
36230 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36231 +#endif
36232 proc_create("devices", 0, proc_bus_pci_dir,
36233 &proc_bus_pci_dev_operations);
36234 proc_initialized = 1;
36235 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36236 index 52daaa8..d6b81eb 100644
36237 --- a/drivers/platform/x86/thinkpad_acpi.c
36238 +++ b/drivers/platform/x86/thinkpad_acpi.c
36239 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36240 return 0;
36241 }
36242
36243 -void static hotkey_mask_warn_incomplete_mask(void)
36244 +static void hotkey_mask_warn_incomplete_mask(void)
36245 {
36246 /* log only what the user can fix... */
36247 const u32 wantedmask = hotkey_driver_mask &
36248 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36249 }
36250 }
36251
36252 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36253 - struct tp_nvram_state *newn,
36254 - const u32 event_mask)
36255 -{
36256 -
36257 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36258 do { \
36259 if ((event_mask & (1 << __scancode)) && \
36260 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36261 tpacpi_hotkey_send_key(__scancode); \
36262 } while (0)
36263
36264 - void issue_volchange(const unsigned int oldvol,
36265 - const unsigned int newvol)
36266 - {
36267 - unsigned int i = oldvol;
36268 +static void issue_volchange(const unsigned int oldvol,
36269 + const unsigned int newvol,
36270 + const u32 event_mask)
36271 +{
36272 + unsigned int i = oldvol;
36273
36274 - while (i > newvol) {
36275 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36276 - i--;
36277 - }
36278 - while (i < newvol) {
36279 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36280 - i++;
36281 - }
36282 + while (i > newvol) {
36283 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36284 + i--;
36285 }
36286 + while (i < newvol) {
36287 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36288 + i++;
36289 + }
36290 +}
36291
36292 - void issue_brightnesschange(const unsigned int oldbrt,
36293 - const unsigned int newbrt)
36294 - {
36295 - unsigned int i = oldbrt;
36296 +static void issue_brightnesschange(const unsigned int oldbrt,
36297 + const unsigned int newbrt,
36298 + const u32 event_mask)
36299 +{
36300 + unsigned int i = oldbrt;
36301
36302 - while (i > newbrt) {
36303 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36304 - i--;
36305 - }
36306 - while (i < newbrt) {
36307 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36308 - i++;
36309 - }
36310 + while (i > newbrt) {
36311 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36312 + i--;
36313 + }
36314 + while (i < newbrt) {
36315 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36316 + i++;
36317 }
36318 +}
36319
36320 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36321 + struct tp_nvram_state *newn,
36322 + const u32 event_mask)
36323 +{
36324 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36325 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36326 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36327 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36328 oldn->volume_level != newn->volume_level) {
36329 /* recently muted, or repeated mute keypress, or
36330 * multiple presses ending in mute */
36331 - issue_volchange(oldn->volume_level, newn->volume_level);
36332 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36333 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36334 }
36335 } else {
36336 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36337 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36338 }
36339 if (oldn->volume_level != newn->volume_level) {
36340 - issue_volchange(oldn->volume_level, newn->volume_level);
36341 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36342 } else if (oldn->volume_toggle != newn->volume_toggle) {
36343 /* repeated vol up/down keypress at end of scale ? */
36344 if (newn->volume_level == 0)
36345 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36346 /* handle brightness */
36347 if (oldn->brightness_level != newn->brightness_level) {
36348 issue_brightnesschange(oldn->brightness_level,
36349 - newn->brightness_level);
36350 + newn->brightness_level,
36351 + event_mask);
36352 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36353 /* repeated key presses that didn't change state */
36354 if (newn->brightness_level == 0)
36355 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36356 && !tp_features.bright_unkfw)
36357 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36358 }
36359 +}
36360
36361 #undef TPACPI_COMPARE_KEY
36362 #undef TPACPI_MAY_SEND_KEY
36363 -}
36364
36365 /*
36366 * Polling driver
36367 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36368 index 769d265..a3a05ca 100644
36369 --- a/drivers/pnp/pnpbios/bioscalls.c
36370 +++ b/drivers/pnp/pnpbios/bioscalls.c
36371 @@ -58,7 +58,7 @@ do { \
36372 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36373 } while(0)
36374
36375 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36376 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36377 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36378
36379 /*
36380 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36381
36382 cpu = get_cpu();
36383 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36384 +
36385 + pax_open_kernel();
36386 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36387 + pax_close_kernel();
36388
36389 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36390 spin_lock_irqsave(&pnp_bios_lock, flags);
36391 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36392 :"memory");
36393 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36394
36395 + pax_open_kernel();
36396 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36397 + pax_close_kernel();
36398 +
36399 put_cpu();
36400
36401 /* If we get here and this is set then the PnP BIOS faulted on us. */
36402 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36403 return status;
36404 }
36405
36406 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36407 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36408 {
36409 int i;
36410
36411 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36412 pnp_bios_callpoint.offset = header->fields.pm16offset;
36413 pnp_bios_callpoint.segment = PNP_CS16;
36414
36415 + pax_open_kernel();
36416 +
36417 for_each_possible_cpu(i) {
36418 struct desc_struct *gdt = get_cpu_gdt_table(i);
36419 if (!gdt)
36420 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36421 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36422 (unsigned long)__va(header->fields.pm16dseg));
36423 }
36424 +
36425 + pax_close_kernel();
36426 }
36427 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36428 index b0ecacb..7c9da2e 100644
36429 --- a/drivers/pnp/resource.c
36430 +++ b/drivers/pnp/resource.c
36431 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36432 return 1;
36433
36434 /* check if the resource is valid */
36435 - if (*irq < 0 || *irq > 15)
36436 + if (*irq > 15)
36437 return 0;
36438
36439 /* check if the resource is reserved */
36440 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36441 return 1;
36442
36443 /* check if the resource is valid */
36444 - if (*dma < 0 || *dma == 4 || *dma > 7)
36445 + if (*dma == 4 || *dma > 7)
36446 return 0;
36447
36448 /* check if the resource is reserved */
36449 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36450 index 181ddec..774b6da 100644
36451 --- a/drivers/power/bq27x00_battery.c
36452 +++ b/drivers/power/bq27x00_battery.c
36453 @@ -80,7 +80,7 @@
36454 struct bq27x00_device_info;
36455 struct bq27x00_access_methods {
36456 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36457 -};
36458 +} __no_const;
36459
36460 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36461
36462 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36463 index 8d53174..04c65de 100644
36464 --- a/drivers/regulator/max8660.c
36465 +++ b/drivers/regulator/max8660.c
36466 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36467 max8660->shadow_regs[MAX8660_OVER1] = 5;
36468 } else {
36469 /* Otherwise devices can be toggled via software */
36470 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36471 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36472 + pax_open_kernel();
36473 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36474 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36475 + pax_close_kernel();
36476 }
36477
36478 /*
36479 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36480 index b388b74..ed82573 100644
36481 --- a/drivers/regulator/mc13892-regulator.c
36482 +++ b/drivers/regulator/mc13892-regulator.c
36483 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36484 }
36485 mc13xxx_unlock(mc13892);
36486
36487 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36488 + pax_open_kernel();
36489 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36490 = mc13892_vcam_set_mode;
36491 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36492 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36493 = mc13892_vcam_get_mode;
36494 + pax_close_kernel();
36495
36496 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36497 ARRAY_SIZE(mc13892_regulators));
36498 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36499 index cace6d3..f623fda 100644
36500 --- a/drivers/rtc/rtc-dev.c
36501 +++ b/drivers/rtc/rtc-dev.c
36502 @@ -14,6 +14,7 @@
36503 #include <linux/module.h>
36504 #include <linux/rtc.h>
36505 #include <linux/sched.h>
36506 +#include <linux/grsecurity.h>
36507 #include "rtc-core.h"
36508
36509 static dev_t rtc_devt;
36510 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36511 if (copy_from_user(&tm, uarg, sizeof(tm)))
36512 return -EFAULT;
36513
36514 + gr_log_timechange();
36515 +
36516 return rtc_set_time(rtc, &tm);
36517
36518 case RTC_PIE_ON:
36519 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36520 index 9e933a8..4f969f7 100644
36521 --- a/drivers/scsi/aacraid/aacraid.h
36522 +++ b/drivers/scsi/aacraid/aacraid.h
36523 @@ -503,7 +503,7 @@ struct adapter_ops
36524 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36525 /* Administrative operations */
36526 int (*adapter_comm)(struct aac_dev * dev, int comm);
36527 -};
36528 +} __no_const;
36529
36530 /*
36531 * Define which interrupt handler needs to be installed
36532 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36533 index 7199534..cb7f158 100644
36534 --- a/drivers/scsi/aacraid/linit.c
36535 +++ b/drivers/scsi/aacraid/linit.c
36536 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36537 #elif defined(__devinitconst)
36538 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36539 #else
36540 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36541 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36542 #endif
36543 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36544 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36545 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36546 index ff80552..1c4120c 100644
36547 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36548 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36549 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36550 .lldd_ata_set_dmamode = asd_set_dmamode,
36551 };
36552
36553 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36554 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36555 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36556 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36557 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36558 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36559 index 4ad7e36..d004679 100644
36560 --- a/drivers/scsi/bfa/bfa.h
36561 +++ b/drivers/scsi/bfa/bfa.h
36562 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36563 u32 *end);
36564 int cpe_vec_q0;
36565 int rme_vec_q0;
36566 -};
36567 +} __no_const;
36568 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36569
36570 struct bfa_faa_cbfn_s {
36571 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36572 index f0f80e2..8ec946b 100644
36573 --- a/drivers/scsi/bfa/bfa_fcpim.c
36574 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36575 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36576
36577 bfa_iotag_attach(fcp);
36578
36579 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36580 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36581 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36582 (fcp->num_itns * sizeof(struct bfa_itn_s));
36583 memset(fcp->itn_arr, 0,
36584 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36585 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36586 {
36587 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36588 - struct bfa_itn_s *itn;
36589 + bfa_itn_s_no_const *itn;
36590
36591 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36592 itn->isr = isr;
36593 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36594 index 36f26da..38a34a8 100644
36595 --- a/drivers/scsi/bfa/bfa_fcpim.h
36596 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36597 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36598 struct bfa_itn_s {
36599 bfa_isr_func_t isr;
36600 };
36601 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36602
36603 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36604 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36605 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36606 struct list_head iotag_tio_free_q; /* free IO resources */
36607 struct list_head iotag_unused_q; /* unused IO resources*/
36608 struct bfa_iotag_s *iotag_arr;
36609 - struct bfa_itn_s *itn_arr;
36610 + bfa_itn_s_no_const *itn_arr;
36611 int num_ioim_reqs;
36612 int num_fwtio_reqs;
36613 int num_itns;
36614 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36615 index 1a99d4b..e85d64b 100644
36616 --- a/drivers/scsi/bfa/bfa_ioc.h
36617 +++ b/drivers/scsi/bfa/bfa_ioc.h
36618 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36619 bfa_ioc_disable_cbfn_t disable_cbfn;
36620 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36621 bfa_ioc_reset_cbfn_t reset_cbfn;
36622 -};
36623 +} __no_const;
36624
36625 /*
36626 * IOC event notification mechanism.
36627 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36628 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36629 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36630 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36631 -};
36632 +} __no_const;
36633
36634 /*
36635 * Queue element to wait for room in request queue. FIFO order is
36636 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36637 index 593085a..47aa999 100644
36638 --- a/drivers/scsi/hosts.c
36639 +++ b/drivers/scsi/hosts.c
36640 @@ -42,7 +42,7 @@
36641 #include "scsi_logging.h"
36642
36643
36644 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36645 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36646
36647
36648 static void scsi_host_cls_release(struct device *dev)
36649 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36650 * subtract one because we increment first then return, but we need to
36651 * know what the next host number was before increment
36652 */
36653 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36654 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36655 shost->dma_channel = 0xff;
36656
36657 /* These three are default values which can be overridden */
36658 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36659 index f9823f2..7bc3e81 100644
36660 --- a/drivers/scsi/hpsa.c
36661 +++ b/drivers/scsi/hpsa.c
36662 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36663 unsigned long flags;
36664
36665 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36666 - return h->access.command_completed(h, q);
36667 + return h->access->command_completed(h, q);
36668
36669 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36670 a = rq->head[rq->current_entry];
36671 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36672 while (!list_empty(&h->reqQ)) {
36673 c = list_entry(h->reqQ.next, struct CommandList, list);
36674 /* can't do anything if fifo is full */
36675 - if ((h->access.fifo_full(h))) {
36676 + if ((h->access->fifo_full(h))) {
36677 dev_warn(&h->pdev->dev, "fifo full\n");
36678 break;
36679 }
36680 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36681
36682 /* Tell the controller execute command */
36683 spin_unlock_irqrestore(&h->lock, flags);
36684 - h->access.submit_command(h, c);
36685 + h->access->submit_command(h, c);
36686 spin_lock_irqsave(&h->lock, flags);
36687 }
36688 spin_unlock_irqrestore(&h->lock, flags);
36689 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36690
36691 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36692 {
36693 - return h->access.command_completed(h, q);
36694 + return h->access->command_completed(h, q);
36695 }
36696
36697 static inline bool interrupt_pending(struct ctlr_info *h)
36698 {
36699 - return h->access.intr_pending(h);
36700 + return h->access->intr_pending(h);
36701 }
36702
36703 static inline long interrupt_not_for_us(struct ctlr_info *h)
36704 {
36705 - return (h->access.intr_pending(h) == 0) ||
36706 + return (h->access->intr_pending(h) == 0) ||
36707 (h->interrupts_enabled == 0);
36708 }
36709
36710 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36711 if (prod_index < 0)
36712 return -ENODEV;
36713 h->product_name = products[prod_index].product_name;
36714 - h->access = *(products[prod_index].access);
36715 + h->access = products[prod_index].access;
36716
36717 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36718 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36719 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36720
36721 assert_spin_locked(&lockup_detector_lock);
36722 remove_ctlr_from_lockup_detector_list(h);
36723 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36724 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36725 spin_lock_irqsave(&h->lock, flags);
36726 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36727 spin_unlock_irqrestore(&h->lock, flags);
36728 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36729 }
36730
36731 /* make sure the board interrupts are off */
36732 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36733 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36734
36735 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36736 goto clean2;
36737 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36738 * fake ones to scoop up any residual completions.
36739 */
36740 spin_lock_irqsave(&h->lock, flags);
36741 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36742 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36743 spin_unlock_irqrestore(&h->lock, flags);
36744 free_irqs(h);
36745 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36746 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36747 dev_info(&h->pdev->dev, "Board READY.\n");
36748 dev_info(&h->pdev->dev,
36749 "Waiting for stale completions to drain.\n");
36750 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36751 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36752 msleep(10000);
36753 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36754 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36755
36756 rc = controller_reset_failed(h->cfgtable);
36757 if (rc)
36758 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36759 }
36760
36761 /* Turn the interrupts on so we can service requests */
36762 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36763 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36764
36765 hpsa_hba_inquiry(h);
36766 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36767 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36768 * To write all data in the battery backed cache to disks
36769 */
36770 hpsa_flush_cache(h);
36771 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36772 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36773 hpsa_free_irqs_and_disable_msix(h);
36774 }
36775
36776 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36777 return;
36778 }
36779 /* Change the access methods to the performant access methods */
36780 - h->access = SA5_performant_access;
36781 + h->access = &SA5_performant_access;
36782 h->transMethod = CFGTBL_Trans_Performant;
36783 }
36784
36785 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36786 index 9816479..c5d4e97 100644
36787 --- a/drivers/scsi/hpsa.h
36788 +++ b/drivers/scsi/hpsa.h
36789 @@ -79,7 +79,7 @@ struct ctlr_info {
36790 unsigned int msix_vector;
36791 unsigned int msi_vector;
36792 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36793 - struct access_method access;
36794 + struct access_method *access;
36795
36796 /* queue and queue Info */
36797 struct list_head reqQ;
36798 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36799 index f2df059..a3a9930 100644
36800 --- a/drivers/scsi/ips.h
36801 +++ b/drivers/scsi/ips.h
36802 @@ -1027,7 +1027,7 @@ typedef struct {
36803 int (*intr)(struct ips_ha *);
36804 void (*enableint)(struct ips_ha *);
36805 uint32_t (*statupd)(struct ips_ha *);
36806 -} ips_hw_func_t;
36807 +} __no_const ips_hw_func_t;
36808
36809 typedef struct ips_ha {
36810 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36811 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36812 index c772d8d..35c362c 100644
36813 --- a/drivers/scsi/libfc/fc_exch.c
36814 +++ b/drivers/scsi/libfc/fc_exch.c
36815 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36816 u16 pool_max_index;
36817
36818 struct {
36819 - atomic_t no_free_exch;
36820 - atomic_t no_free_exch_xid;
36821 - atomic_t xid_not_found;
36822 - atomic_t xid_busy;
36823 - atomic_t seq_not_found;
36824 - atomic_t non_bls_resp;
36825 + atomic_unchecked_t no_free_exch;
36826 + atomic_unchecked_t no_free_exch_xid;
36827 + atomic_unchecked_t xid_not_found;
36828 + atomic_unchecked_t xid_busy;
36829 + atomic_unchecked_t seq_not_found;
36830 + atomic_unchecked_t non_bls_resp;
36831 } stats;
36832 };
36833
36834 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36835 /* allocate memory for exchange */
36836 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36837 if (!ep) {
36838 - atomic_inc(&mp->stats.no_free_exch);
36839 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36840 goto out;
36841 }
36842 memset(ep, 0, sizeof(*ep));
36843 @@ -786,7 +786,7 @@ out:
36844 return ep;
36845 err:
36846 spin_unlock_bh(&pool->lock);
36847 - atomic_inc(&mp->stats.no_free_exch_xid);
36848 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36849 mempool_free(ep, mp->ep_pool);
36850 return NULL;
36851 }
36852 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36853 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36854 ep = fc_exch_find(mp, xid);
36855 if (!ep) {
36856 - atomic_inc(&mp->stats.xid_not_found);
36857 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36858 reject = FC_RJT_OX_ID;
36859 goto out;
36860 }
36861 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36862 ep = fc_exch_find(mp, xid);
36863 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36864 if (ep) {
36865 - atomic_inc(&mp->stats.xid_busy);
36866 + atomic_inc_unchecked(&mp->stats.xid_busy);
36867 reject = FC_RJT_RX_ID;
36868 goto rel;
36869 }
36870 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36871 }
36872 xid = ep->xid; /* get our XID */
36873 } else if (!ep) {
36874 - atomic_inc(&mp->stats.xid_not_found);
36875 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36876 reject = FC_RJT_RX_ID; /* XID not found */
36877 goto out;
36878 }
36879 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36880 } else {
36881 sp = &ep->seq;
36882 if (sp->id != fh->fh_seq_id) {
36883 - atomic_inc(&mp->stats.seq_not_found);
36884 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36885 if (f_ctl & FC_FC_END_SEQ) {
36886 /*
36887 * Update sequence_id based on incoming last
36888 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36889
36890 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36891 if (!ep) {
36892 - atomic_inc(&mp->stats.xid_not_found);
36893 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36894 goto out;
36895 }
36896 if (ep->esb_stat & ESB_ST_COMPLETE) {
36897 - atomic_inc(&mp->stats.xid_not_found);
36898 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36899 goto rel;
36900 }
36901 if (ep->rxid == FC_XID_UNKNOWN)
36902 ep->rxid = ntohs(fh->fh_rx_id);
36903 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36904 - atomic_inc(&mp->stats.xid_not_found);
36905 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36906 goto rel;
36907 }
36908 if (ep->did != ntoh24(fh->fh_s_id) &&
36909 ep->did != FC_FID_FLOGI) {
36910 - atomic_inc(&mp->stats.xid_not_found);
36911 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36912 goto rel;
36913 }
36914 sof = fr_sof(fp);
36915 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36916 sp->ssb_stat |= SSB_ST_RESP;
36917 sp->id = fh->fh_seq_id;
36918 } else if (sp->id != fh->fh_seq_id) {
36919 - atomic_inc(&mp->stats.seq_not_found);
36920 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36921 goto rel;
36922 }
36923
36924 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36925 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36926
36927 if (!sp)
36928 - atomic_inc(&mp->stats.xid_not_found);
36929 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36930 else
36931 - atomic_inc(&mp->stats.non_bls_resp);
36932 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36933
36934 fc_frame_free(fp);
36935 }
36936 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36937
36938 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36939 mp = ema->mp;
36940 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36941 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36942 st->fc_no_free_exch_xid +=
36943 - atomic_read(&mp->stats.no_free_exch_xid);
36944 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36945 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36946 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36947 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36948 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36949 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36950 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36951 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36952 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36953 }
36954 }
36955 EXPORT_SYMBOL(fc_exch_update_stats);
36956 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36957 index a59fcdc..abe55f3 100644
36958 --- a/drivers/scsi/libsas/sas_ata.c
36959 +++ b/drivers/scsi/libsas/sas_ata.c
36960 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36961 .postreset = ata_std_postreset,
36962 .error_handler = ata_std_error_handler,
36963 .post_internal_cmd = sas_ata_post_internal,
36964 - .qc_defer = ata_std_qc_defer,
36965 + .qc_defer = ata_std_qc_defer,
36966 .qc_prep = ata_noop_qc_prep,
36967 .qc_issue = sas_ata_qc_issue,
36968 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36969 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36970 index a65c05a..a39e402 100644
36971 --- a/drivers/scsi/lpfc/lpfc.h
36972 +++ b/drivers/scsi/lpfc/lpfc.h
36973 @@ -420,7 +420,7 @@ struct lpfc_vport {
36974 struct dentry *debug_nodelist;
36975 struct dentry *vport_debugfs_root;
36976 struct lpfc_debugfs_trc *disc_trc;
36977 - atomic_t disc_trc_cnt;
36978 + atomic_unchecked_t disc_trc_cnt;
36979 #endif
36980 uint8_t stat_data_enabled;
36981 uint8_t stat_data_blocked;
36982 @@ -834,8 +834,8 @@ struct lpfc_hba {
36983 struct timer_list fabric_block_timer;
36984 unsigned long bit_flags;
36985 #define FABRIC_COMANDS_BLOCKED 0
36986 - atomic_t num_rsrc_err;
36987 - atomic_t num_cmd_success;
36988 + atomic_unchecked_t num_rsrc_err;
36989 + atomic_unchecked_t num_cmd_success;
36990 unsigned long last_rsrc_error_time;
36991 unsigned long last_ramp_down_time;
36992 unsigned long last_ramp_up_time;
36993 @@ -871,7 +871,7 @@ struct lpfc_hba {
36994
36995 struct dentry *debug_slow_ring_trc;
36996 struct lpfc_debugfs_trc *slow_ring_trc;
36997 - atomic_t slow_ring_trc_cnt;
36998 + atomic_unchecked_t slow_ring_trc_cnt;
36999 /* iDiag debugfs sub-directory */
37000 struct dentry *idiag_root;
37001 struct dentry *idiag_pci_cfg;
37002 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37003 index 3217d63..c417981 100644
37004 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37005 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37006 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37007
37008 #include <linux/debugfs.h>
37009
37010 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37011 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37012 static unsigned long lpfc_debugfs_start_time = 0L;
37013
37014 /* iDiag */
37015 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37016 lpfc_debugfs_enable = 0;
37017
37018 len = 0;
37019 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37020 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37021 (lpfc_debugfs_max_disc_trc - 1);
37022 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37023 dtp = vport->disc_trc + i;
37024 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37025 lpfc_debugfs_enable = 0;
37026
37027 len = 0;
37028 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37029 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37030 (lpfc_debugfs_max_slow_ring_trc - 1);
37031 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37032 dtp = phba->slow_ring_trc + i;
37033 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37034 !vport || !vport->disc_trc)
37035 return;
37036
37037 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37038 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37039 (lpfc_debugfs_max_disc_trc - 1);
37040 dtp = vport->disc_trc + index;
37041 dtp->fmt = fmt;
37042 dtp->data1 = data1;
37043 dtp->data2 = data2;
37044 dtp->data3 = data3;
37045 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37046 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37047 dtp->jif = jiffies;
37048 #endif
37049 return;
37050 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37051 !phba || !phba->slow_ring_trc)
37052 return;
37053
37054 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37055 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37056 (lpfc_debugfs_max_slow_ring_trc - 1);
37057 dtp = phba->slow_ring_trc + index;
37058 dtp->fmt = fmt;
37059 dtp->data1 = data1;
37060 dtp->data2 = data2;
37061 dtp->data3 = data3;
37062 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37063 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37064 dtp->jif = jiffies;
37065 #endif
37066 return;
37067 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37068 "slow_ring buffer\n");
37069 goto debug_failed;
37070 }
37071 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37072 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37073 memset(phba->slow_ring_trc, 0,
37074 (sizeof(struct lpfc_debugfs_trc) *
37075 lpfc_debugfs_max_slow_ring_trc));
37076 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37077 "buffer\n");
37078 goto debug_failed;
37079 }
37080 - atomic_set(&vport->disc_trc_cnt, 0);
37081 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37082
37083 snprintf(name, sizeof(name), "discovery_trace");
37084 vport->debug_disc_trc =
37085 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37086 index 45c1520..35ba744 100644
37087 --- a/drivers/scsi/lpfc/lpfc_init.c
37088 +++ b/drivers/scsi/lpfc/lpfc_init.c
37089 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37090 "misc_register returned with status %d", error);
37091
37092 if (lpfc_enable_npiv) {
37093 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37094 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37095 + pax_open_kernel();
37096 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37097 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37098 + pax_close_kernel();
37099 }
37100 lpfc_transport_template =
37101 fc_attach_transport(&lpfc_transport_functions);
37102 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37103 index 925975d..0f1fc07 100644
37104 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37105 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37106 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37107 uint32_t evt_posted;
37108
37109 spin_lock_irqsave(&phba->hbalock, flags);
37110 - atomic_inc(&phba->num_rsrc_err);
37111 + atomic_inc_unchecked(&phba->num_rsrc_err);
37112 phba->last_rsrc_error_time = jiffies;
37113
37114 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37115 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37116 unsigned long flags;
37117 struct lpfc_hba *phba = vport->phba;
37118 uint32_t evt_posted;
37119 - atomic_inc(&phba->num_cmd_success);
37120 + atomic_inc_unchecked(&phba->num_cmd_success);
37121
37122 if (vport->cfg_lun_queue_depth <= queue_depth)
37123 return;
37124 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37125 unsigned long num_rsrc_err, num_cmd_success;
37126 int i;
37127
37128 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37129 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37130 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37131 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37132
37133 /*
37134 * The error and success command counters are global per
37135 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37136 }
37137 }
37138 lpfc_destroy_vport_work_array(phba, vports);
37139 - atomic_set(&phba->num_rsrc_err, 0);
37140 - atomic_set(&phba->num_cmd_success, 0);
37141 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37142 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37143 }
37144
37145 /**
37146 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37147 }
37148 }
37149 lpfc_destroy_vport_work_array(phba, vports);
37150 - atomic_set(&phba->num_rsrc_err, 0);
37151 - atomic_set(&phba->num_cmd_success, 0);
37152 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37153 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37154 }
37155
37156 /**
37157 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37158 index ea8a0b4..812a124 100644
37159 --- a/drivers/scsi/pmcraid.c
37160 +++ b/drivers/scsi/pmcraid.c
37161 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37162 res->scsi_dev = scsi_dev;
37163 scsi_dev->hostdata = res;
37164 res->change_detected = 0;
37165 - atomic_set(&res->read_failures, 0);
37166 - atomic_set(&res->write_failures, 0);
37167 + atomic_set_unchecked(&res->read_failures, 0);
37168 + atomic_set_unchecked(&res->write_failures, 0);
37169 rc = 0;
37170 }
37171 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37172 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37173
37174 /* If this was a SCSI read/write command keep count of errors */
37175 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37176 - atomic_inc(&res->read_failures);
37177 + atomic_inc_unchecked(&res->read_failures);
37178 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37179 - atomic_inc(&res->write_failures);
37180 + atomic_inc_unchecked(&res->write_failures);
37181
37182 if (!RES_IS_GSCSI(res->cfg_entry) &&
37183 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37184 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37185 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37186 * hrrq_id assigned here in queuecommand
37187 */
37188 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37189 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37190 pinstance->num_hrrq;
37191 cmd->cmd_done = pmcraid_io_done;
37192
37193 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37194 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37195 * hrrq_id assigned here in queuecommand
37196 */
37197 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37198 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37199 pinstance->num_hrrq;
37200
37201 if (request_size) {
37202 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37203
37204 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37205 /* add resources only after host is added into system */
37206 - if (!atomic_read(&pinstance->expose_resources))
37207 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37208 return;
37209
37210 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37211 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37212 init_waitqueue_head(&pinstance->reset_wait_q);
37213
37214 atomic_set(&pinstance->outstanding_cmds, 0);
37215 - atomic_set(&pinstance->last_message_id, 0);
37216 - atomic_set(&pinstance->expose_resources, 0);
37217 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37218 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37219
37220 INIT_LIST_HEAD(&pinstance->free_res_q);
37221 INIT_LIST_HEAD(&pinstance->used_res_q);
37222 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37223 /* Schedule worker thread to handle CCN and take care of adding and
37224 * removing devices to OS
37225 */
37226 - atomic_set(&pinstance->expose_resources, 1);
37227 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37228 schedule_work(&pinstance->worker_q);
37229 return rc;
37230
37231 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37232 index e1d150f..6c6df44 100644
37233 --- a/drivers/scsi/pmcraid.h
37234 +++ b/drivers/scsi/pmcraid.h
37235 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37236 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37237
37238 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37239 - atomic_t last_message_id;
37240 + atomic_unchecked_t last_message_id;
37241
37242 /* configuration table */
37243 struct pmcraid_config_table *cfg_table;
37244 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37245 atomic_t outstanding_cmds;
37246
37247 /* should add/delete resources to mid-layer now ?*/
37248 - atomic_t expose_resources;
37249 + atomic_unchecked_t expose_resources;
37250
37251
37252
37253 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37254 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37255 };
37256 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37257 - atomic_t read_failures; /* count of failed READ commands */
37258 - atomic_t write_failures; /* count of failed WRITE commands */
37259 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37260 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37261
37262 /* To indicate add/delete/modify during CCN */
37263 u8 change_detected;
37264 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37265 index 5ab9530..2dd80f7 100644
37266 --- a/drivers/scsi/qla2xxx/qla_attr.c
37267 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37268 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37269 return 0;
37270 }
37271
37272 -struct fc_function_template qla2xxx_transport_functions = {
37273 +fc_function_template_no_const qla2xxx_transport_functions = {
37274
37275 .show_host_node_name = 1,
37276 .show_host_port_name = 1,
37277 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37278 .bsg_timeout = qla24xx_bsg_timeout,
37279 };
37280
37281 -struct fc_function_template qla2xxx_transport_vport_functions = {
37282 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37283
37284 .show_host_node_name = 1,
37285 .show_host_port_name = 1,
37286 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37287 index 39007f5..7fafc64 100644
37288 --- a/drivers/scsi/qla2xxx/qla_def.h
37289 +++ b/drivers/scsi/qla2xxx/qla_def.h
37290 @@ -2284,7 +2284,7 @@ struct isp_operations {
37291 int (*start_scsi) (srb_t *);
37292 int (*abort_isp) (struct scsi_qla_host *);
37293 int (*iospace_config)(struct qla_hw_data*);
37294 -};
37295 +} __no_const;
37296
37297 /* MSI-X Support *************************************************************/
37298
37299 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37300 index 9eacd2d..d79629c 100644
37301 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37302 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37303 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37304 struct device_attribute;
37305 extern struct device_attribute *qla2x00_host_attrs[];
37306 struct fc_function_template;
37307 -extern struct fc_function_template qla2xxx_transport_functions;
37308 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37309 +extern fc_function_template_no_const qla2xxx_transport_functions;
37310 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37311 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37312 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37313 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37314 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37315 index 7fdba7f..1b4b2c2 100644
37316 --- a/drivers/scsi/qla4xxx/ql4_def.h
37317 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37318 @@ -268,7 +268,7 @@ struct ddb_entry {
37319 * (4000 only) */
37320 atomic_t relogin_timer; /* Max Time to wait for
37321 * relogin to complete */
37322 - atomic_t relogin_retry_count; /* Num of times relogin has been
37323 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37324 * retried */
37325 uint32_t default_time2wait; /* Default Min time between
37326 * relogins (+aens) */
37327 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37328 index 9da4266..377b3b6 100644
37329 --- a/drivers/scsi/qla4xxx/ql4_os.c
37330 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37331 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37332 */
37333 if (!iscsi_is_session_online(cls_sess)) {
37334 /* Reset retry relogin timer */
37335 - atomic_inc(&ddb_entry->relogin_retry_count);
37336 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37337 DEBUG2(ql4_printk(KERN_INFO, ha,
37338 "%s: index[%d] relogin timed out-retrying"
37339 " relogin (%d), retry (%d)\n", __func__,
37340 ddb_entry->fw_ddb_index,
37341 - atomic_read(&ddb_entry->relogin_retry_count),
37342 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37343 ddb_entry->default_time2wait + 4));
37344 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37345 atomic_set(&ddb_entry->retry_relogin_timer,
37346 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37347
37348 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37349 atomic_set(&ddb_entry->relogin_timer, 0);
37350 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37351 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37352 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37353 ddb_entry->default_relogin_timeout =
37354 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37355 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37356 index 2936b44..546ecdb 100644
37357 --- a/drivers/scsi/scsi.c
37358 +++ b/drivers/scsi/scsi.c
37359 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37360 unsigned long timeout;
37361 int rtn = 0;
37362
37363 - atomic_inc(&cmd->device->iorequest_cnt);
37364 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37365
37366 /* check if the device is still usable */
37367 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37368 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37369 index faa790f..7e351ddd 100644
37370 --- a/drivers/scsi/scsi_lib.c
37371 +++ b/drivers/scsi/scsi_lib.c
37372 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37373 shost = sdev->host;
37374 scsi_init_cmd_errh(cmd);
37375 cmd->result = DID_NO_CONNECT << 16;
37376 - atomic_inc(&cmd->device->iorequest_cnt);
37377 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37378
37379 /*
37380 * SCSI request completion path will do scsi_device_unbusy(),
37381 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37382
37383 INIT_LIST_HEAD(&cmd->eh_entry);
37384
37385 - atomic_inc(&cmd->device->iodone_cnt);
37386 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37387 if (cmd->result)
37388 - atomic_inc(&cmd->device->ioerr_cnt);
37389 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37390
37391 disposition = scsi_decide_disposition(cmd);
37392 if (disposition != SUCCESS &&
37393 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37394 index ce5224c..8c6d071 100644
37395 --- a/drivers/scsi/scsi_sysfs.c
37396 +++ b/drivers/scsi/scsi_sysfs.c
37397 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37398 char *buf) \
37399 { \
37400 struct scsi_device *sdev = to_scsi_device(dev); \
37401 - unsigned long long count = atomic_read(&sdev->field); \
37402 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37403 return snprintf(buf, 20, "0x%llx\n", count); \
37404 } \
37405 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37406 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37407 index 84a1fdf..693b0d6 100644
37408 --- a/drivers/scsi/scsi_tgt_lib.c
37409 +++ b/drivers/scsi/scsi_tgt_lib.c
37410 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37411 int err;
37412
37413 dprintk("%lx %u\n", uaddr, len);
37414 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37415 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37416 if (err) {
37417 /*
37418 * TODO: need to fixup sg_tablesize, max_segment_size,
37419 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37420 index e894ca7..de9d7660 100644
37421 --- a/drivers/scsi/scsi_transport_fc.c
37422 +++ b/drivers/scsi/scsi_transport_fc.c
37423 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37424 * Netlink Infrastructure
37425 */
37426
37427 -static atomic_t fc_event_seq;
37428 +static atomic_unchecked_t fc_event_seq;
37429
37430 /**
37431 * fc_get_event_number - Obtain the next sequential FC event number
37432 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37433 u32
37434 fc_get_event_number(void)
37435 {
37436 - return atomic_add_return(1, &fc_event_seq);
37437 + return atomic_add_return_unchecked(1, &fc_event_seq);
37438 }
37439 EXPORT_SYMBOL(fc_get_event_number);
37440
37441 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37442 {
37443 int error;
37444
37445 - atomic_set(&fc_event_seq, 0);
37446 + atomic_set_unchecked(&fc_event_seq, 0);
37447
37448 error = transport_class_register(&fc_host_class);
37449 if (error)
37450 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37451 char *cp;
37452
37453 *val = simple_strtoul(buf, &cp, 0);
37454 - if ((*cp && (*cp != '\n')) || (*val < 0))
37455 + if (*cp && (*cp != '\n'))
37456 return -EINVAL;
37457 /*
37458 * Check for overflow; dev_loss_tmo is u32
37459 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37460 index fa1dfaa..4bb620c 100644
37461 --- a/drivers/scsi/scsi_transport_iscsi.c
37462 +++ b/drivers/scsi/scsi_transport_iscsi.c
37463 @@ -79,7 +79,7 @@ struct iscsi_internal {
37464 struct transport_container session_cont;
37465 };
37466
37467 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37468 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37469 static struct workqueue_struct *iscsi_eh_timer_workq;
37470
37471 static DEFINE_IDA(iscsi_sess_ida);
37472 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37473 int err;
37474
37475 ihost = shost->shost_data;
37476 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37477 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37478
37479 if (target_id == ISCSI_MAX_TARGET) {
37480 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37481 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37482 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37483 ISCSI_TRANSPORT_VERSION);
37484
37485 - atomic_set(&iscsi_session_nr, 0);
37486 + atomic_set_unchecked(&iscsi_session_nr, 0);
37487
37488 err = class_register(&iscsi_transport_class);
37489 if (err)
37490 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37491 index 21a045e..ec89e03 100644
37492 --- a/drivers/scsi/scsi_transport_srp.c
37493 +++ b/drivers/scsi/scsi_transport_srp.c
37494 @@ -33,7 +33,7 @@
37495 #include "scsi_transport_srp_internal.h"
37496
37497 struct srp_host_attrs {
37498 - atomic_t next_port_id;
37499 + atomic_unchecked_t next_port_id;
37500 };
37501 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37502
37503 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37504 struct Scsi_Host *shost = dev_to_shost(dev);
37505 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37506
37507 - atomic_set(&srp_host->next_port_id, 0);
37508 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37509 return 0;
37510 }
37511
37512 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37513 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37514 rport->roles = ids->roles;
37515
37516 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37517 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37518 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37519
37520 transport_setup_device(&rport->dev);
37521 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37522 index 4df73e5..b691c58 100644
37523 --- a/drivers/scsi/sd.c
37524 +++ b/drivers/scsi/sd.c
37525 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37526 sdkp->disk = gd;
37527 sdkp->index = index;
37528 atomic_set(&sdkp->openers, 0);
37529 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37530 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37531
37532 if (!sdp->request_queue->rq_timeout) {
37533 if (sdp->type != TYPE_MOD)
37534 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37535 index 9c5c5f2..8414557 100644
37536 --- a/drivers/scsi/sg.c
37537 +++ b/drivers/scsi/sg.c
37538 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37539 sdp->disk->disk_name,
37540 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37541 NULL,
37542 - (char *)arg);
37543 + (char __user *)arg);
37544 case BLKTRACESTART:
37545 return blk_trace_startstop(sdp->device->request_queue, 1);
37546 case BLKTRACESTOP:
37547 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37548 index 84c2861..ece0a31 100644
37549 --- a/drivers/spi/spi.c
37550 +++ b/drivers/spi/spi.c
37551 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37552 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37553
37554 /* portable code must never pass more than 32 bytes */
37555 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37556 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37557
37558 static u8 *buf;
37559
37560 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37561 index 34afc16..ffe44dd 100644
37562 --- a/drivers/staging/octeon/ethernet-rx.c
37563 +++ b/drivers/staging/octeon/ethernet-rx.c
37564 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37565 /* Increment RX stats for virtual ports */
37566 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37567 #ifdef CONFIG_64BIT
37568 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37569 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37570 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37571 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37572 #else
37573 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37574 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37575 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37576 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37577 #endif
37578 }
37579 netif_receive_skb(skb);
37580 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37581 dev->name);
37582 */
37583 #ifdef CONFIG_64BIT
37584 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37585 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37586 #else
37587 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37588 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37589 #endif
37590 dev_kfree_skb_irq(skb);
37591 }
37592 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37593 index 683bedc..86dba9a 100644
37594 --- a/drivers/staging/octeon/ethernet.c
37595 +++ b/drivers/staging/octeon/ethernet.c
37596 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37597 * since the RX tasklet also increments it.
37598 */
37599 #ifdef CONFIG_64BIT
37600 - atomic64_add(rx_status.dropped_packets,
37601 - (atomic64_t *)&priv->stats.rx_dropped);
37602 + atomic64_add_unchecked(rx_status.dropped_packets,
37603 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37604 #else
37605 - atomic_add(rx_status.dropped_packets,
37606 - (atomic_t *)&priv->stats.rx_dropped);
37607 + atomic_add_unchecked(rx_status.dropped_packets,
37608 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37609 #endif
37610 }
37611
37612 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37613 index dc23395..cf7e9b1 100644
37614 --- a/drivers/staging/rtl8712/rtl871x_io.h
37615 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37616 @@ -108,7 +108,7 @@ struct _io_ops {
37617 u8 *pmem);
37618 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37619 u8 *pmem);
37620 -};
37621 +} __no_const;
37622
37623 struct io_req {
37624 struct list_head list;
37625 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37626 index c7b5e8b..783d6cb 100644
37627 --- a/drivers/staging/sbe-2t3e3/netdev.c
37628 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37629 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37630 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37631
37632 if (rlen)
37633 - if (copy_to_user(data, &resp, rlen))
37634 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37635 return -EFAULT;
37636
37637 return 0;
37638 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37639 index 5d89c0f..9261317 100644
37640 --- a/drivers/staging/usbip/usbip_common.h
37641 +++ b/drivers/staging/usbip/usbip_common.h
37642 @@ -289,7 +289,7 @@ struct usbip_device {
37643 void (*shutdown)(struct usbip_device *);
37644 void (*reset)(struct usbip_device *);
37645 void (*unusable)(struct usbip_device *);
37646 - } eh_ops;
37647 + } __no_const eh_ops;
37648 };
37649
37650 #define kthread_get_run(threadfn, data, namefmt, ...) \
37651 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37652 index c66b8b3..a4a035b 100644
37653 --- a/drivers/staging/usbip/vhci.h
37654 +++ b/drivers/staging/usbip/vhci.h
37655 @@ -83,7 +83,7 @@ struct vhci_hcd {
37656 unsigned resuming:1;
37657 unsigned long re_timeout;
37658
37659 - atomic_t seqnum;
37660 + atomic_unchecked_t seqnum;
37661
37662 /*
37663 * NOTE:
37664 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37665 index 12a9a5f..afd8295 100644
37666 --- a/drivers/staging/usbip/vhci_hcd.c
37667 +++ b/drivers/staging/usbip/vhci_hcd.c
37668 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37669 return;
37670 }
37671
37672 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37673 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37674 if (priv->seqnum == 0xffff)
37675 dev_info(&urb->dev->dev, "seqnum max\n");
37676
37677 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37678 return -ENOMEM;
37679 }
37680
37681 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37682 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37683 if (unlink->seqnum == 0xffff)
37684 pr_info("seqnum max\n");
37685
37686 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37687 vdev->rhport = rhport;
37688 }
37689
37690 - atomic_set(&vhci->seqnum, 0);
37691 + atomic_set_unchecked(&vhci->seqnum, 0);
37692 spin_lock_init(&vhci->lock);
37693
37694 hcd->power_budget = 0; /* no limit */
37695 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37696 index f0eaf04..5a82e06 100644
37697 --- a/drivers/staging/usbip/vhci_rx.c
37698 +++ b/drivers/staging/usbip/vhci_rx.c
37699 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37700 if (!urb) {
37701 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37702 pr_info("max seqnum %d\n",
37703 - atomic_read(&the_controller->seqnum));
37704 + atomic_read_unchecked(&the_controller->seqnum));
37705 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37706 return;
37707 }
37708 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37709 index 6ac6f45..1b208ba 100644
37710 --- a/drivers/staging/vt6655/hostap.c
37711 +++ b/drivers/staging/vt6655/hostap.c
37712 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37713 *
37714 */
37715
37716 +static net_device_ops_no_const apdev_netdev_ops;
37717 +
37718 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37719 {
37720 PSDevice apdev_priv;
37721 struct net_device *dev = pDevice->dev;
37722 int ret;
37723 - const struct net_device_ops apdev_netdev_ops = {
37724 - .ndo_start_xmit = pDevice->tx_80211,
37725 - };
37726
37727 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37728
37729 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37730 *apdev_priv = *pDevice;
37731 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37732
37733 + /* only half broken now */
37734 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37735 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37736
37737 pDevice->apdev->type = ARPHRD_IEEE80211;
37738 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37739 index 682002a..35ed5cf 100644
37740 --- a/drivers/staging/vt6656/hostap.c
37741 +++ b/drivers/staging/vt6656/hostap.c
37742 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37743 *
37744 */
37745
37746 +static net_device_ops_no_const apdev_netdev_ops;
37747 +
37748 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37749 {
37750 PSDevice apdev_priv;
37751 struct net_device *dev = pDevice->dev;
37752 int ret;
37753 - const struct net_device_ops apdev_netdev_ops = {
37754 - .ndo_start_xmit = pDevice->tx_80211,
37755 - };
37756
37757 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37758
37759 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37760 *apdev_priv = *pDevice;
37761 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37762
37763 + /* only half broken now */
37764 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37765 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37766
37767 pDevice->apdev->type = ARPHRD_IEEE80211;
37768 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37769 index 7843dfd..3db105f 100644
37770 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37771 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37772 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37773
37774 struct usbctlx_completor {
37775 int (*complete) (struct usbctlx_completor *);
37776 -};
37777 +} __no_const;
37778
37779 static int
37780 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37781 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37782 index eaa9021..43f023b 100644
37783 --- a/drivers/staging/zcache/tmem.c
37784 +++ b/drivers/staging/zcache/tmem.c
37785 @@ -39,7 +39,7 @@
37786 * A tmem host implementation must use this function to register callbacks
37787 * for memory allocation.
37788 */
37789 -static struct tmem_hostops tmem_hostops;
37790 +static tmem_hostops_no_const tmem_hostops;
37791
37792 static void tmem_objnode_tree_init(void);
37793
37794 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37795 * A tmem host implementation must use this function to register
37796 * callbacks for a page-accessible memory (PAM) implementation
37797 */
37798 -static struct tmem_pamops tmem_pamops;
37799 +static tmem_pamops_no_const tmem_pamops;
37800
37801 void tmem_register_pamops(struct tmem_pamops *m)
37802 {
37803 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37804 index 0d4aa82..f7832d4 100644
37805 --- a/drivers/staging/zcache/tmem.h
37806 +++ b/drivers/staging/zcache/tmem.h
37807 @@ -180,6 +180,7 @@ struct tmem_pamops {
37808 void (*new_obj)(struct tmem_obj *);
37809 int (*replace_in_obj)(void *, struct tmem_obj *);
37810 };
37811 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37812 extern void tmem_register_pamops(struct tmem_pamops *m);
37813
37814 /* memory allocation methods provided by the host implementation */
37815 @@ -189,6 +190,7 @@ struct tmem_hostops {
37816 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37817 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37818 };
37819 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37820 extern void tmem_register_hostops(struct tmem_hostops *m);
37821
37822 /* core tmem accessor functions */
37823 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37824 index 269f544..32def0d 100644
37825 --- a/drivers/target/target_core_transport.c
37826 +++ b/drivers/target/target_core_transport.c
37827 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37828 spin_lock_init(&dev->se_port_lock);
37829 spin_lock_init(&dev->se_tmr_lock);
37830 spin_lock_init(&dev->qf_cmd_lock);
37831 - atomic_set(&dev->dev_ordered_id, 0);
37832 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37833
37834 se_dev_set_default_attribs(dev, dev_limits);
37835
37836 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37837 * Used to determine when ORDERED commands should go from
37838 * Dormant to Active status.
37839 */
37840 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37841 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37842 smp_mb__after_atomic_inc();
37843 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37844 cmd->se_ordered_id, cmd->sam_task_attr,
37845 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37846 index e61cabd..7617d26 100644
37847 --- a/drivers/tty/cyclades.c
37848 +++ b/drivers/tty/cyclades.c
37849 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37850 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37851 info->port.count);
37852 #endif
37853 - info->port.count++;
37854 + atomic_inc(&info->port.count);
37855 #ifdef CY_DEBUG_COUNT
37856 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37857 - current->pid, info->port.count);
37858 + current->pid, atomic_read(&info->port.count));
37859 #endif
37860
37861 /*
37862 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37863 for (j = 0; j < cy_card[i].nports; j++) {
37864 info = &cy_card[i].ports[j];
37865
37866 - if (info->port.count) {
37867 + if (atomic_read(&info->port.count)) {
37868 /* XXX is the ldisc num worth this? */
37869 struct tty_struct *tty;
37870 struct tty_ldisc *ld;
37871 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37872 index 2d691eb..be02ebd 100644
37873 --- a/drivers/tty/hvc/hvc_console.c
37874 +++ b/drivers/tty/hvc/hvc_console.c
37875 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37876
37877 spin_lock_irqsave(&hp->port.lock, flags);
37878 /* Check and then increment for fast path open. */
37879 - if (hp->port.count++ > 0) {
37880 + if (atomic_inc_return(&hp->port.count) > 1) {
37881 spin_unlock_irqrestore(&hp->port.lock, flags);
37882 hvc_kick();
37883 return 0;
37884 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37885
37886 spin_lock_irqsave(&hp->port.lock, flags);
37887
37888 - if (--hp->port.count == 0) {
37889 + if (atomic_dec_return(&hp->port.count) == 0) {
37890 spin_unlock_irqrestore(&hp->port.lock, flags);
37891 /* We are done with the tty pointer now. */
37892 tty_port_tty_set(&hp->port, NULL);
37893 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37894 */
37895 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37896 } else {
37897 - if (hp->port.count < 0)
37898 + if (atomic_read(&hp->port.count) < 0)
37899 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37900 - hp->vtermno, hp->port.count);
37901 + hp->vtermno, atomic_read(&hp->port.count));
37902 spin_unlock_irqrestore(&hp->port.lock, flags);
37903 }
37904
37905 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37906 * open->hangup case this can be called after the final close so prevent
37907 * that from happening for now.
37908 */
37909 - if (hp->port.count <= 0) {
37910 + if (atomic_read(&hp->port.count) <= 0) {
37911 spin_unlock_irqrestore(&hp->port.lock, flags);
37912 return;
37913 }
37914
37915 - temp_open_count = hp->port.count;
37916 - hp->port.count = 0;
37917 + temp_open_count = atomic_read(&hp->port.count);
37918 + atomic_set(&hp->port.count, 0);
37919 spin_unlock_irqrestore(&hp->port.lock, flags);
37920 tty_port_tty_set(&hp->port, NULL);
37921
37922 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37923 return -EPIPE;
37924
37925 /* FIXME what's this (unprotected) check for? */
37926 - if (hp->port.count <= 0)
37927 + if (atomic_read(&hp->port.count) <= 0)
37928 return -EIO;
37929
37930 spin_lock_irqsave(&hp->lock, flags);
37931 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37932 index d56788c..12d8f85 100644
37933 --- a/drivers/tty/hvc/hvcs.c
37934 +++ b/drivers/tty/hvc/hvcs.c
37935 @@ -83,6 +83,7 @@
37936 #include <asm/hvcserver.h>
37937 #include <asm/uaccess.h>
37938 #include <asm/vio.h>
37939 +#include <asm/local.h>
37940
37941 /*
37942 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37943 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37944
37945 spin_lock_irqsave(&hvcsd->lock, flags);
37946
37947 - if (hvcsd->port.count > 0) {
37948 + if (atomic_read(&hvcsd->port.count) > 0) {
37949 spin_unlock_irqrestore(&hvcsd->lock, flags);
37950 printk(KERN_INFO "HVCS: vterm state unchanged. "
37951 "The hvcs device node is still in use.\n");
37952 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37953 if ((retval = hvcs_partner_connect(hvcsd)))
37954 goto error_release;
37955
37956 - hvcsd->port.count = 1;
37957 + atomic_set(&hvcsd->port.count, 1);
37958 hvcsd->port.tty = tty;
37959 tty->driver_data = hvcsd;
37960
37961 @@ -1168,7 +1169,7 @@ fast_open:
37962
37963 spin_lock_irqsave(&hvcsd->lock, flags);
37964 tty_port_get(&hvcsd->port);
37965 - hvcsd->port.count++;
37966 + atomic_inc(&hvcsd->port.count);
37967 hvcsd->todo_mask |= HVCS_SCHED_READ;
37968 spin_unlock_irqrestore(&hvcsd->lock, flags);
37969
37970 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37971 hvcsd = tty->driver_data;
37972
37973 spin_lock_irqsave(&hvcsd->lock, flags);
37974 - if (--hvcsd->port.count == 0) {
37975 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37976
37977 vio_disable_interrupts(hvcsd->vdev);
37978
37979 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37980 free_irq(irq, hvcsd);
37981 tty_port_put(&hvcsd->port);
37982 return;
37983 - } else if (hvcsd->port.count < 0) {
37984 + } else if (atomic_read(&hvcsd->port.count) < 0) {
37985 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
37986 " is missmanaged.\n",
37987 - hvcsd->vdev->unit_address, hvcsd->port.count);
37988 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
37989 }
37990
37991 spin_unlock_irqrestore(&hvcsd->lock, flags);
37992 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
37993
37994 spin_lock_irqsave(&hvcsd->lock, flags);
37995 /* Preserve this so that we know how many kref refs to put */
37996 - temp_open_count = hvcsd->port.count;
37997 + temp_open_count = atomic_read(&hvcsd->port.count);
37998
37999 /*
38000 * Don't kref put inside the spinlock because the destruction
38001 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38002 tty->driver_data = NULL;
38003 hvcsd->port.tty = NULL;
38004
38005 - hvcsd->port.count = 0;
38006 + atomic_set(&hvcsd->port.count, 0);
38007
38008 /* This will drop any buffered data on the floor which is OK in a hangup
38009 * scenario. */
38010 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38011 * the middle of a write operation? This is a crummy place to do this
38012 * but we want to keep it all in the spinlock.
38013 */
38014 - if (hvcsd->port.count <= 0) {
38015 + if (atomic_read(&hvcsd->port.count) <= 0) {
38016 spin_unlock_irqrestore(&hvcsd->lock, flags);
38017 return -ENODEV;
38018 }
38019 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38020 {
38021 struct hvcs_struct *hvcsd = tty->driver_data;
38022
38023 - if (!hvcsd || hvcsd->port.count <= 0)
38024 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38025 return 0;
38026
38027 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38028 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38029 index f8b5fa0..4ba9f89 100644
38030 --- a/drivers/tty/ipwireless/tty.c
38031 +++ b/drivers/tty/ipwireless/tty.c
38032 @@ -29,6 +29,7 @@
38033 #include <linux/tty_driver.h>
38034 #include <linux/tty_flip.h>
38035 #include <linux/uaccess.h>
38036 +#include <asm/local.h>
38037
38038 #include "tty.h"
38039 #include "network.h"
38040 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38041 mutex_unlock(&tty->ipw_tty_mutex);
38042 return -ENODEV;
38043 }
38044 - if (tty->port.count == 0)
38045 + if (atomic_read(&tty->port.count) == 0)
38046 tty->tx_bytes_queued = 0;
38047
38048 - tty->port.count++;
38049 + atomic_inc(&tty->port.count);
38050
38051 tty->port.tty = linux_tty;
38052 linux_tty->driver_data = tty;
38053 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38054
38055 static void do_ipw_close(struct ipw_tty *tty)
38056 {
38057 - tty->port.count--;
38058 -
38059 - if (tty->port.count == 0) {
38060 + if (atomic_dec_return(&tty->port.count) == 0) {
38061 struct tty_struct *linux_tty = tty->port.tty;
38062
38063 if (linux_tty != NULL) {
38064 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38065 return;
38066
38067 mutex_lock(&tty->ipw_tty_mutex);
38068 - if (tty->port.count == 0) {
38069 + if (atomic_read(&tty->port.count) == 0) {
38070 mutex_unlock(&tty->ipw_tty_mutex);
38071 return;
38072 }
38073 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38074 return;
38075 }
38076
38077 - if (!tty->port.count) {
38078 + if (!atomic_read(&tty->port.count)) {
38079 mutex_unlock(&tty->ipw_tty_mutex);
38080 return;
38081 }
38082 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38083 return -ENODEV;
38084
38085 mutex_lock(&tty->ipw_tty_mutex);
38086 - if (!tty->port.count) {
38087 + if (!atomic_read(&tty->port.count)) {
38088 mutex_unlock(&tty->ipw_tty_mutex);
38089 return -EINVAL;
38090 }
38091 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38092 if (!tty)
38093 return -ENODEV;
38094
38095 - if (!tty->port.count)
38096 + if (!atomic_read(&tty->port.count))
38097 return -EINVAL;
38098
38099 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38100 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38101 if (!tty)
38102 return 0;
38103
38104 - if (!tty->port.count)
38105 + if (!atomic_read(&tty->port.count))
38106 return 0;
38107
38108 return tty->tx_bytes_queued;
38109 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38110 if (!tty)
38111 return -ENODEV;
38112
38113 - if (!tty->port.count)
38114 + if (!atomic_read(&tty->port.count))
38115 return -EINVAL;
38116
38117 return get_control_lines(tty);
38118 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38119 if (!tty)
38120 return -ENODEV;
38121
38122 - if (!tty->port.count)
38123 + if (!atomic_read(&tty->port.count))
38124 return -EINVAL;
38125
38126 return set_control_lines(tty, set, clear);
38127 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38128 if (!tty)
38129 return -ENODEV;
38130
38131 - if (!tty->port.count)
38132 + if (!atomic_read(&tty->port.count))
38133 return -EINVAL;
38134
38135 /* FIXME: Exactly how is the tty object locked here .. */
38136 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38137 * are gone */
38138 mutex_lock(&ttyj->ipw_tty_mutex);
38139 }
38140 - while (ttyj->port.count)
38141 + while (atomic_read(&ttyj->port.count))
38142 do_ipw_close(ttyj);
38143 ipwireless_disassociate_network_ttys(network,
38144 ttyj->channel_idx);
38145 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38146 index 324467d..504cc25 100644
38147 --- a/drivers/tty/moxa.c
38148 +++ b/drivers/tty/moxa.c
38149 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38150 }
38151
38152 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38153 - ch->port.count++;
38154 + atomic_inc(&ch->port.count);
38155 tty->driver_data = ch;
38156 tty_port_tty_set(&ch->port, tty);
38157 mutex_lock(&ch->port.mutex);
38158 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38159 index 90dff82..08119c3 100644
38160 --- a/drivers/tty/n_gsm.c
38161 +++ b/drivers/tty/n_gsm.c
38162 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38163 kref_init(&dlci->ref);
38164 mutex_init(&dlci->mutex);
38165 dlci->fifo = &dlci->_fifo;
38166 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38167 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38168 kfree(dlci);
38169 return NULL;
38170 }
38171 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38172 if (dlci == NULL)
38173 return -ENOMEM;
38174 port = &dlci->port;
38175 - port->count++;
38176 + atomic_inc(&port->count);
38177 tty->driver_data = dlci;
38178 dlci_get(dlci);
38179 dlci_get(dlci->gsm->dlci[0]);
38180 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38181 index 26f0d0e..b7c4273 100644
38182 --- a/drivers/tty/n_tty.c
38183 +++ b/drivers/tty/n_tty.c
38184 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38185 {
38186 *ops = tty_ldisc_N_TTY;
38187 ops->owner = NULL;
38188 - ops->refcount = ops->flags = 0;
38189 + atomic_set(&ops->refcount, 0);
38190 + ops->flags = 0;
38191 }
38192 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38193 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38194 index 5505ffc..7affff9 100644
38195 --- a/drivers/tty/pty.c
38196 +++ b/drivers/tty/pty.c
38197 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38198 panic("Couldn't register Unix98 pts driver");
38199
38200 /* Now create the /dev/ptmx special device */
38201 + pax_open_kernel();
38202 tty_default_fops(&ptmx_fops);
38203 - ptmx_fops.open = ptmx_open;
38204 + *(void **)&ptmx_fops.open = ptmx_open;
38205 + pax_close_kernel();
38206
38207 cdev_init(&ptmx_cdev, &ptmx_fops);
38208 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38209 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38210 index 777d5f9..56d67ca 100644
38211 --- a/drivers/tty/rocket.c
38212 +++ b/drivers/tty/rocket.c
38213 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38214 tty->driver_data = info;
38215 tty_port_tty_set(port, tty);
38216
38217 - if (port->count++ == 0) {
38218 + if (atomic_inc_return(&port->count) == 1) {
38219 atomic_inc(&rp_num_ports_open);
38220
38221 #ifdef ROCKET_DEBUG_OPEN
38222 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38223 #endif
38224 }
38225 #ifdef ROCKET_DEBUG_OPEN
38226 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38227 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38228 #endif
38229
38230 /*
38231 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38232 spin_unlock_irqrestore(&info->port.lock, flags);
38233 return;
38234 }
38235 - if (info->port.count)
38236 + if (atomic_read(&info->port.count))
38237 atomic_dec(&rp_num_ports_open);
38238 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38239 spin_unlock_irqrestore(&info->port.lock, flags);
38240 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38241 index 2b42a01..32a2ed3 100644
38242 --- a/drivers/tty/serial/kgdboc.c
38243 +++ b/drivers/tty/serial/kgdboc.c
38244 @@ -24,8 +24,9 @@
38245 #define MAX_CONFIG_LEN 40
38246
38247 static struct kgdb_io kgdboc_io_ops;
38248 +static struct kgdb_io kgdboc_io_ops_console;
38249
38250 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38251 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38252 static int configured = -1;
38253
38254 static char config[MAX_CONFIG_LEN];
38255 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38256 kgdboc_unregister_kbd();
38257 if (configured == 1)
38258 kgdb_unregister_io_module(&kgdboc_io_ops);
38259 + else if (configured == 2)
38260 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38261 }
38262
38263 static int configure_kgdboc(void)
38264 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38265 int err;
38266 char *cptr = config;
38267 struct console *cons;
38268 + int is_console = 0;
38269
38270 err = kgdboc_option_setup(config);
38271 if (err || !strlen(config) || isspace(config[0]))
38272 goto noconfig;
38273
38274 err = -ENODEV;
38275 - kgdboc_io_ops.is_console = 0;
38276 kgdb_tty_driver = NULL;
38277
38278 kgdboc_use_kms = 0;
38279 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38280 int idx;
38281 if (cons->device && cons->device(cons, &idx) == p &&
38282 idx == tty_line) {
38283 - kgdboc_io_ops.is_console = 1;
38284 + is_console = 1;
38285 break;
38286 }
38287 cons = cons->next;
38288 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38289 kgdb_tty_line = tty_line;
38290
38291 do_register:
38292 - err = kgdb_register_io_module(&kgdboc_io_ops);
38293 + if (is_console) {
38294 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38295 + configured = 2;
38296 + } else {
38297 + err = kgdb_register_io_module(&kgdboc_io_ops);
38298 + configured = 1;
38299 + }
38300 if (err)
38301 goto noconfig;
38302
38303 - configured = 1;
38304 -
38305 return 0;
38306
38307 noconfig:
38308 @@ -213,7 +220,7 @@ noconfig:
38309 static int __init init_kgdboc(void)
38310 {
38311 /* Already configured? */
38312 - if (configured == 1)
38313 + if (configured >= 1)
38314 return 0;
38315
38316 return configure_kgdboc();
38317 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38318 if (config[len - 1] == '\n')
38319 config[len - 1] = '\0';
38320
38321 - if (configured == 1)
38322 + if (configured >= 1)
38323 cleanup_kgdboc();
38324
38325 /* Go and configure with the new params. */
38326 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38327 .post_exception = kgdboc_post_exp_handler,
38328 };
38329
38330 +static struct kgdb_io kgdboc_io_ops_console = {
38331 + .name = "kgdboc",
38332 + .read_char = kgdboc_get_char,
38333 + .write_char = kgdboc_put_char,
38334 + .pre_exception = kgdboc_pre_exp_handler,
38335 + .post_exception = kgdboc_post_exp_handler,
38336 + .is_console = 1
38337 +};
38338 +
38339 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38340 /* This is only available if kgdboc is a built in for early debugging */
38341 static int __init kgdboc_early_init(char *opt)
38342 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38343 index a21dc8e..fe43e9e 100644
38344 --- a/drivers/tty/serial/serial_core.c
38345 +++ b/drivers/tty/serial/serial_core.c
38346 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38347 uart_flush_buffer(tty);
38348 uart_shutdown(tty, state);
38349 spin_lock_irqsave(&port->lock, flags);
38350 - port->count = 0;
38351 + atomic_set(&port->count, 0);
38352 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38353 spin_unlock_irqrestore(&port->lock, flags);
38354 tty_port_tty_set(port, NULL);
38355 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38356 goto end;
38357 }
38358
38359 - port->count++;
38360 + atomic_inc(&port->count);
38361 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38362 retval = -ENXIO;
38363 goto err_dec_count;
38364 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38365 /*
38366 * Make sure the device is in D0 state.
38367 */
38368 - if (port->count == 1)
38369 + if (atomic_read(&port->count) == 1)
38370 uart_change_pm(state, 0);
38371
38372 /*
38373 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38374 end:
38375 return retval;
38376 err_dec_count:
38377 - port->count--;
38378 + atomic_inc(&port->count);
38379 mutex_unlock(&port->mutex);
38380 goto end;
38381 }
38382 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38383 index 593d40a..bdc61f3 100644
38384 --- a/drivers/tty/synclink.c
38385 +++ b/drivers/tty/synclink.c
38386 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38387
38388 if (debug_level >= DEBUG_LEVEL_INFO)
38389 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38390 - __FILE__,__LINE__, info->device_name, info->port.count);
38391 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38392
38393 if (tty_port_close_start(&info->port, tty, filp) == 0)
38394 goto cleanup;
38395 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38396 cleanup:
38397 if (debug_level >= DEBUG_LEVEL_INFO)
38398 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38399 - tty->driver->name, info->port.count);
38400 + tty->driver->name, atomic_read(&info->port.count));
38401
38402 } /* end of mgsl_close() */
38403
38404 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38405
38406 mgsl_flush_buffer(tty);
38407 shutdown(info);
38408 -
38409 - info->port.count = 0;
38410 +
38411 + atomic_set(&info->port.count, 0);
38412 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38413 info->port.tty = NULL;
38414
38415 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38416
38417 if (debug_level >= DEBUG_LEVEL_INFO)
38418 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38419 - __FILE__,__LINE__, tty->driver->name, port->count );
38420 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38421
38422 spin_lock_irqsave(&info->irq_spinlock, flags);
38423 if (!tty_hung_up_p(filp)) {
38424 extra_count = true;
38425 - port->count--;
38426 + atomic_dec(&port->count);
38427 }
38428 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38429 port->blocked_open++;
38430 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38431
38432 if (debug_level >= DEBUG_LEVEL_INFO)
38433 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38434 - __FILE__,__LINE__, tty->driver->name, port->count );
38435 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38436
38437 tty_unlock();
38438 schedule();
38439 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38440
38441 /* FIXME: Racy on hangup during close wait */
38442 if (extra_count)
38443 - port->count++;
38444 + atomic_inc(&port->count);
38445 port->blocked_open--;
38446
38447 if (debug_level >= DEBUG_LEVEL_INFO)
38448 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38449 - __FILE__,__LINE__, tty->driver->name, port->count );
38450 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38451
38452 if (!retval)
38453 port->flags |= ASYNC_NORMAL_ACTIVE;
38454 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38455
38456 if (debug_level >= DEBUG_LEVEL_INFO)
38457 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38458 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38459 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38460
38461 /* If port is closing, signal caller to try again */
38462 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38463 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38464 spin_unlock_irqrestore(&info->netlock, flags);
38465 goto cleanup;
38466 }
38467 - info->port.count++;
38468 + atomic_inc(&info->port.count);
38469 spin_unlock_irqrestore(&info->netlock, flags);
38470
38471 - if (info->port.count == 1) {
38472 + if (atomic_read(&info->port.count) == 1) {
38473 /* 1st open on this device, init hardware */
38474 retval = startup(info);
38475 if (retval < 0)
38476 @@ -3444,8 +3444,8 @@ cleanup:
38477 if (retval) {
38478 if (tty->count == 1)
38479 info->port.tty = NULL; /* tty layer will release tty struct */
38480 - if(info->port.count)
38481 - info->port.count--;
38482 + if (atomic_read(&info->port.count))
38483 + atomic_dec(&info->port.count);
38484 }
38485
38486 return retval;
38487 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38488 unsigned short new_crctype;
38489
38490 /* return error if TTY interface open */
38491 - if (info->port.count)
38492 + if (atomic_read(&info->port.count))
38493 return -EBUSY;
38494
38495 switch (encoding)
38496 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38497
38498 /* arbitrate between network and tty opens */
38499 spin_lock_irqsave(&info->netlock, flags);
38500 - if (info->port.count != 0 || info->netcount != 0) {
38501 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38502 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38503 spin_unlock_irqrestore(&info->netlock, flags);
38504 return -EBUSY;
38505 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38506 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38507
38508 /* return error if TTY interface open */
38509 - if (info->port.count)
38510 + if (atomic_read(&info->port.count))
38511 return -EBUSY;
38512
38513 if (cmd != SIOCWANDEV)
38514 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38515 index aa1debf..9297a16 100644
38516 --- a/drivers/tty/synclink_gt.c
38517 +++ b/drivers/tty/synclink_gt.c
38518 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38519 tty->driver_data = info;
38520 info->port.tty = tty;
38521
38522 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38523 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38524
38525 /* If port is closing, signal caller to try again */
38526 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38527 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38528 mutex_unlock(&info->port.mutex);
38529 goto cleanup;
38530 }
38531 - info->port.count++;
38532 + atomic_inc(&info->port.count);
38533 spin_unlock_irqrestore(&info->netlock, flags);
38534
38535 - if (info->port.count == 1) {
38536 + if (atomic_read(&info->port.count) == 1) {
38537 /* 1st open on this device, init hardware */
38538 retval = startup(info);
38539 if (retval < 0) {
38540 @@ -716,8 +716,8 @@ cleanup:
38541 if (retval) {
38542 if (tty->count == 1)
38543 info->port.tty = NULL; /* tty layer will release tty struct */
38544 - if(info->port.count)
38545 - info->port.count--;
38546 + if(atomic_read(&info->port.count))
38547 + atomic_dec(&info->port.count);
38548 }
38549
38550 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38551 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38552
38553 if (sanity_check(info, tty->name, "close"))
38554 return;
38555 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38556 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38557
38558 if (tty_port_close_start(&info->port, tty, filp) == 0)
38559 goto cleanup;
38560 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38561 tty_port_close_end(&info->port, tty);
38562 info->port.tty = NULL;
38563 cleanup:
38564 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38565 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38566 }
38567
38568 static void hangup(struct tty_struct *tty)
38569 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38570 shutdown(info);
38571
38572 spin_lock_irqsave(&info->port.lock, flags);
38573 - info->port.count = 0;
38574 + atomic_set(&info->port.count, 0);
38575 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38576 info->port.tty = NULL;
38577 spin_unlock_irqrestore(&info->port.lock, flags);
38578 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38579 unsigned short new_crctype;
38580
38581 /* return error if TTY interface open */
38582 - if (info->port.count)
38583 + if (atomic_read(&info->port.count))
38584 return -EBUSY;
38585
38586 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38587 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38588
38589 /* arbitrate between network and tty opens */
38590 spin_lock_irqsave(&info->netlock, flags);
38591 - if (info->port.count != 0 || info->netcount != 0) {
38592 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38593 DBGINFO(("%s hdlc_open busy\n", dev->name));
38594 spin_unlock_irqrestore(&info->netlock, flags);
38595 return -EBUSY;
38596 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38597 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38598
38599 /* return error if TTY interface open */
38600 - if (info->port.count)
38601 + if (atomic_read(&info->port.count))
38602 return -EBUSY;
38603
38604 if (cmd != SIOCWANDEV)
38605 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38606 if (port == NULL)
38607 continue;
38608 spin_lock(&port->lock);
38609 - if ((port->port.count || port->netcount) &&
38610 + if ((atomic_read(&port->port.count) || port->netcount) &&
38611 port->pending_bh && !port->bh_running &&
38612 !port->bh_requested) {
38613 DBGISR(("%s bh queued\n", port->device_name));
38614 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38615 spin_lock_irqsave(&info->lock, flags);
38616 if (!tty_hung_up_p(filp)) {
38617 extra_count = true;
38618 - port->count--;
38619 + atomic_dec(&port->count);
38620 }
38621 spin_unlock_irqrestore(&info->lock, flags);
38622 port->blocked_open++;
38623 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38624 remove_wait_queue(&port->open_wait, &wait);
38625
38626 if (extra_count)
38627 - port->count++;
38628 + atomic_inc(&port->count);
38629 port->blocked_open--;
38630
38631 if (!retval)
38632 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38633 index a3dddc1..8905ab2 100644
38634 --- a/drivers/tty/synclinkmp.c
38635 +++ b/drivers/tty/synclinkmp.c
38636 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38637
38638 if (debug_level >= DEBUG_LEVEL_INFO)
38639 printk("%s(%d):%s open(), old ref count = %d\n",
38640 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38641 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38642
38643 /* If port is closing, signal caller to try again */
38644 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38645 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38646 spin_unlock_irqrestore(&info->netlock, flags);
38647 goto cleanup;
38648 }
38649 - info->port.count++;
38650 + atomic_inc(&info->port.count);
38651 spin_unlock_irqrestore(&info->netlock, flags);
38652
38653 - if (info->port.count == 1) {
38654 + if (atomic_read(&info->port.count) == 1) {
38655 /* 1st open on this device, init hardware */
38656 retval = startup(info);
38657 if (retval < 0)
38658 @@ -788,8 +788,8 @@ cleanup:
38659 if (retval) {
38660 if (tty->count == 1)
38661 info->port.tty = NULL; /* tty layer will release tty struct */
38662 - if(info->port.count)
38663 - info->port.count--;
38664 + if(atomic_read(&info->port.count))
38665 + atomic_dec(&info->port.count);
38666 }
38667
38668 return retval;
38669 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38670
38671 if (debug_level >= DEBUG_LEVEL_INFO)
38672 printk("%s(%d):%s close() entry, count=%d\n",
38673 - __FILE__,__LINE__, info->device_name, info->port.count);
38674 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38675
38676 if (tty_port_close_start(&info->port, tty, filp) == 0)
38677 goto cleanup;
38678 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38679 cleanup:
38680 if (debug_level >= DEBUG_LEVEL_INFO)
38681 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38682 - tty->driver->name, info->port.count);
38683 + tty->driver->name, atomic_read(&info->port.count));
38684 }
38685
38686 /* Called by tty_hangup() when a hangup is signaled.
38687 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38688 shutdown(info);
38689
38690 spin_lock_irqsave(&info->port.lock, flags);
38691 - info->port.count = 0;
38692 + atomic_set(&info->port.count, 0);
38693 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38694 info->port.tty = NULL;
38695 spin_unlock_irqrestore(&info->port.lock, flags);
38696 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38697 unsigned short new_crctype;
38698
38699 /* return error if TTY interface open */
38700 - if (info->port.count)
38701 + if (atomic_read(&info->port.count))
38702 return -EBUSY;
38703
38704 switch (encoding)
38705 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38706
38707 /* arbitrate between network and tty opens */
38708 spin_lock_irqsave(&info->netlock, flags);
38709 - if (info->port.count != 0 || info->netcount != 0) {
38710 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38711 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38712 spin_unlock_irqrestore(&info->netlock, flags);
38713 return -EBUSY;
38714 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38715 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38716
38717 /* return error if TTY interface open */
38718 - if (info->port.count)
38719 + if (atomic_read(&info->port.count))
38720 return -EBUSY;
38721
38722 if (cmd != SIOCWANDEV)
38723 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38724 * do not request bottom half processing if the
38725 * device is not open in a normal mode.
38726 */
38727 - if ( port && (port->port.count || port->netcount) &&
38728 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38729 port->pending_bh && !port->bh_running &&
38730 !port->bh_requested ) {
38731 if ( debug_level >= DEBUG_LEVEL_ISR )
38732 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38733
38734 if (debug_level >= DEBUG_LEVEL_INFO)
38735 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38736 - __FILE__,__LINE__, tty->driver->name, port->count );
38737 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38738
38739 spin_lock_irqsave(&info->lock, flags);
38740 if (!tty_hung_up_p(filp)) {
38741 extra_count = true;
38742 - port->count--;
38743 + atomic_dec(&port->count);
38744 }
38745 spin_unlock_irqrestore(&info->lock, flags);
38746 port->blocked_open++;
38747 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38748
38749 if (debug_level >= DEBUG_LEVEL_INFO)
38750 printk("%s(%d):%s block_til_ready() count=%d\n",
38751 - __FILE__,__LINE__, tty->driver->name, port->count );
38752 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38753
38754 tty_unlock();
38755 schedule();
38756 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38757 remove_wait_queue(&port->open_wait, &wait);
38758
38759 if (extra_count)
38760 - port->count++;
38761 + atomic_inc(&port->count);
38762 port->blocked_open--;
38763
38764 if (debug_level >= DEBUG_LEVEL_INFO)
38765 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38766 - __FILE__,__LINE__, tty->driver->name, port->count );
38767 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38768
38769 if (!retval)
38770 port->flags |= ASYNC_NORMAL_ACTIVE;
38771 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38772 index 05728894..b9d44c6 100644
38773 --- a/drivers/tty/sysrq.c
38774 +++ b/drivers/tty/sysrq.c
38775 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38776 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38777 size_t count, loff_t *ppos)
38778 {
38779 - if (count) {
38780 + if (count && capable(CAP_SYS_ADMIN)) {
38781 char c;
38782
38783 if (get_user(c, buf))
38784 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38785 index b425c79..08a3f06 100644
38786 --- a/drivers/tty/tty_io.c
38787 +++ b/drivers/tty/tty_io.c
38788 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38789
38790 void tty_default_fops(struct file_operations *fops)
38791 {
38792 - *fops = tty_fops;
38793 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38794 }
38795
38796 /*
38797 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38798 index 6f99c99..8947bc4 100644
38799 --- a/drivers/tty/tty_ldisc.c
38800 +++ b/drivers/tty/tty_ldisc.c
38801 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38802 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38803 struct tty_ldisc_ops *ldo = ld->ops;
38804
38805 - ldo->refcount--;
38806 + atomic_dec(&ldo->refcount);
38807 module_put(ldo->owner);
38808 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38809
38810 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38811 spin_lock_irqsave(&tty_ldisc_lock, flags);
38812 tty_ldiscs[disc] = new_ldisc;
38813 new_ldisc->num = disc;
38814 - new_ldisc->refcount = 0;
38815 + atomic_set(&new_ldisc->refcount, 0);
38816 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38817
38818 return ret;
38819 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38820 return -EINVAL;
38821
38822 spin_lock_irqsave(&tty_ldisc_lock, flags);
38823 - if (tty_ldiscs[disc]->refcount)
38824 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38825 ret = -EBUSY;
38826 else
38827 tty_ldiscs[disc] = NULL;
38828 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38829 if (ldops) {
38830 ret = ERR_PTR(-EAGAIN);
38831 if (try_module_get(ldops->owner)) {
38832 - ldops->refcount++;
38833 + atomic_inc(&ldops->refcount);
38834 ret = ldops;
38835 }
38836 }
38837 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38838 unsigned long flags;
38839
38840 spin_lock_irqsave(&tty_ldisc_lock, flags);
38841 - ldops->refcount--;
38842 + atomic_dec(&ldops->refcount);
38843 module_put(ldops->owner);
38844 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38845 }
38846 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38847 index bf6e238..d401c04 100644
38848 --- a/drivers/tty/tty_port.c
38849 +++ b/drivers/tty/tty_port.c
38850 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38851 unsigned long flags;
38852
38853 spin_lock_irqsave(&port->lock, flags);
38854 - port->count = 0;
38855 + atomic_set(&port->count, 0);
38856 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38857 if (port->tty) {
38858 set_bit(TTY_IO_ERROR, &port->tty->flags);
38859 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38860 /* The port lock protects the port counts */
38861 spin_lock_irqsave(&port->lock, flags);
38862 if (!tty_hung_up_p(filp))
38863 - port->count--;
38864 + atomic_dec(&port->count);
38865 port->blocked_open++;
38866 spin_unlock_irqrestore(&port->lock, flags);
38867
38868 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38869 we must not mess that up further */
38870 spin_lock_irqsave(&port->lock, flags);
38871 if (!tty_hung_up_p(filp))
38872 - port->count++;
38873 + atomic_inc(&port->count);
38874 port->blocked_open--;
38875 if (retval == 0)
38876 port->flags |= ASYNC_NORMAL_ACTIVE;
38877 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38878 return 0;
38879 }
38880
38881 - if (tty->count == 1 && port->count != 1) {
38882 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38883 printk(KERN_WARNING
38884 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38885 - port->count);
38886 - port->count = 1;
38887 + atomic_read(&port->count));
38888 + atomic_set(&port->count, 1);
38889 }
38890 - if (--port->count < 0) {
38891 + if (atomic_dec_return(&port->count) < 0) {
38892 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38893 - port->count);
38894 - port->count = 0;
38895 + atomic_read(&port->count));
38896 + atomic_set(&port->count, 0);
38897 }
38898
38899 - if (port->count) {
38900 + if (atomic_read(&port->count)) {
38901 spin_unlock_irqrestore(&port->lock, flags);
38902 if (port->ops->drop)
38903 port->ops->drop(port);
38904 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38905 {
38906 spin_lock_irq(&port->lock);
38907 if (!tty_hung_up_p(filp))
38908 - ++port->count;
38909 + atomic_inc(&port->count);
38910 spin_unlock_irq(&port->lock);
38911 tty_port_tty_set(port, tty);
38912
38913 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38914 index 770a854..e5d3db3 100644
38915 --- a/drivers/tty/vt/keyboard.c
38916 +++ b/drivers/tty/vt/keyboard.c
38917 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38918 kbd->kbdmode == VC_OFF) &&
38919 value != KVAL(K_SAK))
38920 return; /* SAK is allowed even in raw mode */
38921 +
38922 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38923 + {
38924 + void *func = fn_handler[value];
38925 + if (func == fn_show_state || func == fn_show_ptregs ||
38926 + func == fn_show_mem)
38927 + return;
38928 + }
38929 +#endif
38930 +
38931 fn_handler[value](vc);
38932 }
38933
38934 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38935 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38936 return -EFAULT;
38937
38938 - if (!capable(CAP_SYS_TTY_CONFIG))
38939 - perm = 0;
38940 -
38941 switch (cmd) {
38942 case KDGKBENT:
38943 /* Ensure another thread doesn't free it under us */
38944 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38945 spin_unlock_irqrestore(&kbd_event_lock, flags);
38946 return put_user(val, &user_kbe->kb_value);
38947 case KDSKBENT:
38948 + if (!capable(CAP_SYS_TTY_CONFIG))
38949 + perm = 0;
38950 +
38951 if (!perm)
38952 return -EPERM;
38953 if (!i && v == K_NOSUCHMAP) {
38954 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38955 int i, j, k;
38956 int ret;
38957
38958 - if (!capable(CAP_SYS_TTY_CONFIG))
38959 - perm = 0;
38960 -
38961 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38962 if (!kbs) {
38963 ret = -ENOMEM;
38964 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38965 kfree(kbs);
38966 return ((p && *p) ? -EOVERFLOW : 0);
38967 case KDSKBSENT:
38968 + if (!capable(CAP_SYS_TTY_CONFIG))
38969 + perm = 0;
38970 +
38971 if (!perm) {
38972 ret = -EPERM;
38973 goto reterr;
38974 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38975 index a783d53..cb30d94 100644
38976 --- a/drivers/uio/uio.c
38977 +++ b/drivers/uio/uio.c
38978 @@ -25,6 +25,7 @@
38979 #include <linux/kobject.h>
38980 #include <linux/cdev.h>
38981 #include <linux/uio_driver.h>
38982 +#include <asm/local.h>
38983
38984 #define UIO_MAX_DEVICES (1U << MINORBITS)
38985
38986 @@ -32,10 +33,10 @@ struct uio_device {
38987 struct module *owner;
38988 struct device *dev;
38989 int minor;
38990 - atomic_t event;
38991 + atomic_unchecked_t event;
38992 struct fasync_struct *async_queue;
38993 wait_queue_head_t wait;
38994 - int vma_count;
38995 + local_t vma_count;
38996 struct uio_info *info;
38997 struct kobject *map_dir;
38998 struct kobject *portio_dir;
38999 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39000 struct device_attribute *attr, char *buf)
39001 {
39002 struct uio_device *idev = dev_get_drvdata(dev);
39003 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39004 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39005 }
39006
39007 static struct device_attribute uio_class_attributes[] = {
39008 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39009 {
39010 struct uio_device *idev = info->uio_dev;
39011
39012 - atomic_inc(&idev->event);
39013 + atomic_inc_unchecked(&idev->event);
39014 wake_up_interruptible(&idev->wait);
39015 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39016 }
39017 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39018 }
39019
39020 listener->dev = idev;
39021 - listener->event_count = atomic_read(&idev->event);
39022 + listener->event_count = atomic_read_unchecked(&idev->event);
39023 filep->private_data = listener;
39024
39025 if (idev->info->open) {
39026 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39027 return -EIO;
39028
39029 poll_wait(filep, &idev->wait, wait);
39030 - if (listener->event_count != atomic_read(&idev->event))
39031 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39032 return POLLIN | POLLRDNORM;
39033 return 0;
39034 }
39035 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39036 do {
39037 set_current_state(TASK_INTERRUPTIBLE);
39038
39039 - event_count = atomic_read(&idev->event);
39040 + event_count = atomic_read_unchecked(&idev->event);
39041 if (event_count != listener->event_count) {
39042 if (copy_to_user(buf, &event_count, count))
39043 retval = -EFAULT;
39044 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39045 static void uio_vma_open(struct vm_area_struct *vma)
39046 {
39047 struct uio_device *idev = vma->vm_private_data;
39048 - idev->vma_count++;
39049 + local_inc(&idev->vma_count);
39050 }
39051
39052 static void uio_vma_close(struct vm_area_struct *vma)
39053 {
39054 struct uio_device *idev = vma->vm_private_data;
39055 - idev->vma_count--;
39056 + local_dec(&idev->vma_count);
39057 }
39058
39059 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39060 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39061 idev->owner = owner;
39062 idev->info = info;
39063 init_waitqueue_head(&idev->wait);
39064 - atomic_set(&idev->event, 0);
39065 + atomic_set_unchecked(&idev->event, 0);
39066
39067 ret = uio_get_minor(idev);
39068 if (ret)
39069 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39070 index b7eb86a..36d28af 100644
39071 --- a/drivers/usb/atm/cxacru.c
39072 +++ b/drivers/usb/atm/cxacru.c
39073 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39074 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39075 if (ret < 2)
39076 return -EINVAL;
39077 - if (index < 0 || index > 0x7f)
39078 + if (index > 0x7f)
39079 return -EINVAL;
39080 pos += tmp;
39081
39082 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39083 index ee62b35..b663594 100644
39084 --- a/drivers/usb/atm/usbatm.c
39085 +++ b/drivers/usb/atm/usbatm.c
39086 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39087 if (printk_ratelimit())
39088 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39089 __func__, vpi, vci);
39090 - atomic_inc(&vcc->stats->rx_err);
39091 + atomic_inc_unchecked(&vcc->stats->rx_err);
39092 return;
39093 }
39094
39095 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39096 if (length > ATM_MAX_AAL5_PDU) {
39097 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39098 __func__, length, vcc);
39099 - atomic_inc(&vcc->stats->rx_err);
39100 + atomic_inc_unchecked(&vcc->stats->rx_err);
39101 goto out;
39102 }
39103
39104 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39105 if (sarb->len < pdu_length) {
39106 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39107 __func__, pdu_length, sarb->len, vcc);
39108 - atomic_inc(&vcc->stats->rx_err);
39109 + atomic_inc_unchecked(&vcc->stats->rx_err);
39110 goto out;
39111 }
39112
39113 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39114 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39115 __func__, vcc);
39116 - atomic_inc(&vcc->stats->rx_err);
39117 + atomic_inc_unchecked(&vcc->stats->rx_err);
39118 goto out;
39119 }
39120
39121 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39122 if (printk_ratelimit())
39123 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39124 __func__, length);
39125 - atomic_inc(&vcc->stats->rx_drop);
39126 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39127 goto out;
39128 }
39129
39130 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39131
39132 vcc->push(vcc, skb);
39133
39134 - atomic_inc(&vcc->stats->rx);
39135 + atomic_inc_unchecked(&vcc->stats->rx);
39136 out:
39137 skb_trim(sarb, 0);
39138 }
39139 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39140 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39141
39142 usbatm_pop(vcc, skb);
39143 - atomic_inc(&vcc->stats->tx);
39144 + atomic_inc_unchecked(&vcc->stats->tx);
39145
39146 skb = skb_dequeue(&instance->sndqueue);
39147 }
39148 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39149 if (!left--)
39150 return sprintf(page,
39151 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39152 - atomic_read(&atm_dev->stats.aal5.tx),
39153 - atomic_read(&atm_dev->stats.aal5.tx_err),
39154 - atomic_read(&atm_dev->stats.aal5.rx),
39155 - atomic_read(&atm_dev->stats.aal5.rx_err),
39156 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39157 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39158 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39159 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39160 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39161 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39162
39163 if (!left--) {
39164 if (instance->disconnected)
39165 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39166 index 3440812..2a4ef1f 100644
39167 --- a/drivers/usb/core/devices.c
39168 +++ b/drivers/usb/core/devices.c
39169 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39170 * time it gets called.
39171 */
39172 static struct device_connect_event {
39173 - atomic_t count;
39174 + atomic_unchecked_t count;
39175 wait_queue_head_t wait;
39176 } device_event = {
39177 .count = ATOMIC_INIT(1),
39178 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39179
39180 void usbfs_conn_disc_event(void)
39181 {
39182 - atomic_add(2, &device_event.count);
39183 + atomic_add_unchecked(2, &device_event.count);
39184 wake_up(&device_event.wait);
39185 }
39186
39187 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39188
39189 poll_wait(file, &device_event.wait, wait);
39190
39191 - event_count = atomic_read(&device_event.count);
39192 + event_count = atomic_read_unchecked(&device_event.count);
39193 if (file->f_version != event_count) {
39194 file->f_version = event_count;
39195 return POLLIN | POLLRDNORM;
39196 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39197 index 89dcf15..481800b 100644
39198 --- a/drivers/usb/early/ehci-dbgp.c
39199 +++ b/drivers/usb/early/ehci-dbgp.c
39200 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39201
39202 #ifdef CONFIG_KGDB
39203 static struct kgdb_io kgdbdbgp_io_ops;
39204 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39205 +static struct kgdb_io kgdbdbgp_io_ops_console;
39206 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39207 #else
39208 #define dbgp_kgdb_mode (0)
39209 #endif
39210 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39211 .write_char = kgdbdbgp_write_char,
39212 };
39213
39214 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39215 + .name = "kgdbdbgp",
39216 + .read_char = kgdbdbgp_read_char,
39217 + .write_char = kgdbdbgp_write_char,
39218 + .is_console = 1
39219 +};
39220 +
39221 static int kgdbdbgp_wait_time;
39222
39223 static int __init kgdbdbgp_parse_config(char *str)
39224 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39225 ptr++;
39226 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39227 }
39228 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39229 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39230 + if (early_dbgp_console.index != -1)
39231 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39232 + else
39233 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39234
39235 return 0;
39236 }
39237 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39238 index da6d479..80ed10b 100644
39239 --- a/drivers/usb/gadget/u_serial.c
39240 +++ b/drivers/usb/gadget/u_serial.c
39241 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39242 spin_lock_irq(&port->port_lock);
39243
39244 /* already open? Great. */
39245 - if (port->port.count) {
39246 + if (atomic_read(&port->port.count)) {
39247 status = 0;
39248 - port->port.count++;
39249 + atomic_inc(&port->port.count);
39250
39251 /* currently opening/closing? wait ... */
39252 } else if (port->openclose) {
39253 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39254 tty->driver_data = port;
39255 port->port.tty = tty;
39256
39257 - port->port.count = 1;
39258 + atomic_set(&port->port.count, 1);
39259 port->openclose = false;
39260
39261 /* if connected, start the I/O stream */
39262 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39263
39264 spin_lock_irq(&port->port_lock);
39265
39266 - if (port->port.count != 1) {
39267 - if (port->port.count == 0)
39268 + if (atomic_read(&port->port.count) != 1) {
39269 + if (atomic_read(&port->port.count) == 0)
39270 WARN_ON(1);
39271 else
39272 - --port->port.count;
39273 + atomic_dec(&port->port.count);
39274 goto exit;
39275 }
39276
39277 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39278 * and sleep if necessary
39279 */
39280 port->openclose = true;
39281 - port->port.count = 0;
39282 + atomic_set(&port->port.count, 0);
39283
39284 gser = port->port_usb;
39285 if (gser && gser->disconnect)
39286 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39287 int cond;
39288
39289 spin_lock_irq(&port->port_lock);
39290 - cond = (port->port.count == 0) && !port->openclose;
39291 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39292 spin_unlock_irq(&port->port_lock);
39293 return cond;
39294 }
39295 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39296 /* if it's already open, start I/O ... and notify the serial
39297 * protocol about open/close status (connect/disconnect).
39298 */
39299 - if (port->port.count) {
39300 + if (atomic_read(&port->port.count)) {
39301 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39302 gs_start_io(port);
39303 if (gser->connect)
39304 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39305
39306 port->port_usb = NULL;
39307 gser->ioport = NULL;
39308 - if (port->port.count > 0 || port->openclose) {
39309 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39310 wake_up_interruptible(&port->drain_wait);
39311 if (port->port.tty)
39312 tty_hangup(port->port.tty);
39313 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39314
39315 /* finally, free any unused/unusable I/O buffers */
39316 spin_lock_irqsave(&port->port_lock, flags);
39317 - if (port->port.count == 0 && !port->openclose)
39318 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39319 gs_buf_free(&port->port_write_buf);
39320 gs_free_requests(gser->out, &port->read_pool, NULL);
39321 gs_free_requests(gser->out, &port->read_queue, NULL);
39322 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39323 index b9cca6d..75c75df 100644
39324 --- a/drivers/usb/serial/console.c
39325 +++ b/drivers/usb/serial/console.c
39326 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39327
39328 info->port = port;
39329
39330 - ++port->port.count;
39331 + atomic_inc(&port->port.count);
39332 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39333 if (serial->type->set_termios) {
39334 /*
39335 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39336 }
39337 /* Now that any required fake tty operations are completed restore
39338 * the tty port count */
39339 - --port->port.count;
39340 + atomic_dec(&port->port.count);
39341 /* The console is special in terms of closing the device so
39342 * indicate this port is now acting as a system console. */
39343 port->port.console = 1;
39344 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39345 free_tty:
39346 kfree(tty);
39347 reset_open_count:
39348 - port->port.count = 0;
39349 + atomic_set(&port->port.count, 0);
39350 usb_autopm_put_interface(serial->interface);
39351 error_get_interface:
39352 usb_serial_put(serial);
39353 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39354 index d6bea3e..60b250e 100644
39355 --- a/drivers/usb/wusbcore/wa-hc.h
39356 +++ b/drivers/usb/wusbcore/wa-hc.h
39357 @@ -192,7 +192,7 @@ struct wahc {
39358 struct list_head xfer_delayed_list;
39359 spinlock_t xfer_list_lock;
39360 struct work_struct xfer_work;
39361 - atomic_t xfer_id_count;
39362 + atomic_unchecked_t xfer_id_count;
39363 };
39364
39365
39366 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39367 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39368 spin_lock_init(&wa->xfer_list_lock);
39369 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39370 - atomic_set(&wa->xfer_id_count, 1);
39371 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39372 }
39373
39374 /**
39375 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39376 index 57c01ab..8a05959 100644
39377 --- a/drivers/usb/wusbcore/wa-xfer.c
39378 +++ b/drivers/usb/wusbcore/wa-xfer.c
39379 @@ -296,7 +296,7 @@ out:
39380 */
39381 static void wa_xfer_id_init(struct wa_xfer *xfer)
39382 {
39383 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39384 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39385 }
39386
39387 /*
39388 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39389 index ef82a0d..da8a0b3 100644
39390 --- a/drivers/vhost/vhost.c
39391 +++ b/drivers/vhost/vhost.c
39392 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39393 return 0;
39394 }
39395
39396 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39397 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39398 {
39399 struct file *eventfp, *filep = NULL,
39400 *pollstart = NULL, *pollstop = NULL;
39401 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39402 index 747442d..7c0c434 100644
39403 --- a/drivers/video/aty/aty128fb.c
39404 +++ b/drivers/video/aty/aty128fb.c
39405 @@ -149,7 +149,7 @@ enum {
39406 };
39407
39408 /* Must match above enum */
39409 -static const char *r128_family[] __devinitdata = {
39410 +static const char *r128_family[] __devinitconst = {
39411 "AGP",
39412 "PCI",
39413 "PRO AGP",
39414 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39415 index 5c3960d..15cf8fc 100644
39416 --- a/drivers/video/fbcmap.c
39417 +++ b/drivers/video/fbcmap.c
39418 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39419 rc = -ENODEV;
39420 goto out;
39421 }
39422 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39423 - !info->fbops->fb_setcmap)) {
39424 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39425 rc = -EINVAL;
39426 goto out1;
39427 }
39428 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39429 index 0dff12a..2ef47b3 100644
39430 --- a/drivers/video/fbmem.c
39431 +++ b/drivers/video/fbmem.c
39432 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39433 image->dx += image->width + 8;
39434 }
39435 } else if (rotate == FB_ROTATE_UD) {
39436 - for (x = 0; x < num && image->dx >= 0; x++) {
39437 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39438 info->fbops->fb_imageblit(info, image);
39439 image->dx -= image->width + 8;
39440 }
39441 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39442 image->dy += image->height + 8;
39443 }
39444 } else if (rotate == FB_ROTATE_CCW) {
39445 - for (x = 0; x < num && image->dy >= 0; x++) {
39446 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39447 info->fbops->fb_imageblit(info, image);
39448 image->dy -= image->height + 8;
39449 }
39450 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39451 return -EFAULT;
39452 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39453 return -EINVAL;
39454 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39455 + if (con2fb.framebuffer >= FB_MAX)
39456 return -EINVAL;
39457 if (!registered_fb[con2fb.framebuffer])
39458 request_module("fb%d", con2fb.framebuffer);
39459 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39460 index 5a5d092..265c5ed 100644
39461 --- a/drivers/video/geode/gx1fb_core.c
39462 +++ b/drivers/video/geode/gx1fb_core.c
39463 @@ -29,7 +29,7 @@ static int crt_option = 1;
39464 static char panel_option[32] = "";
39465
39466 /* Modes relevant to the GX1 (taken from modedb.c) */
39467 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39468 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39469 /* 640x480-60 VESA */
39470 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39471 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39472 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39473 index 0fad23f..0e9afa4 100644
39474 --- a/drivers/video/gxt4500.c
39475 +++ b/drivers/video/gxt4500.c
39476 @@ -156,7 +156,7 @@ struct gxt4500_par {
39477 static char *mode_option;
39478
39479 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39480 -static const struct fb_videomode defaultmode __devinitdata = {
39481 +static const struct fb_videomode defaultmode __devinitconst = {
39482 .refresh = 60,
39483 .xres = 1280,
39484 .yres = 1024,
39485 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39486 return 0;
39487 }
39488
39489 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39490 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39491 .id = "IBM GXT4500P",
39492 .type = FB_TYPE_PACKED_PIXELS,
39493 .visual = FB_VISUAL_PSEUDOCOLOR,
39494 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39495 index 7672d2e..b56437f 100644
39496 --- a/drivers/video/i810/i810_accel.c
39497 +++ b/drivers/video/i810/i810_accel.c
39498 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39499 }
39500 }
39501 printk("ringbuffer lockup!!!\n");
39502 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39503 i810_report_error(mmio);
39504 par->dev_flags |= LOCKUP;
39505 info->pixmap.scan_align = 1;
39506 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39507 index b83f361..2b05a91 100644
39508 --- a/drivers/video/i810/i810_main.c
39509 +++ b/drivers/video/i810/i810_main.c
39510 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39511 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39512
39513 /* PCI */
39514 -static const char *i810_pci_list[] __devinitdata = {
39515 +static const char *i810_pci_list[] __devinitconst = {
39516 "Intel(R) 810 Framebuffer Device" ,
39517 "Intel(R) 810-DC100 Framebuffer Device" ,
39518 "Intel(R) 810E Framebuffer Device" ,
39519 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39520 index de36693..3c63fc2 100644
39521 --- a/drivers/video/jz4740_fb.c
39522 +++ b/drivers/video/jz4740_fb.c
39523 @@ -136,7 +136,7 @@ struct jzfb {
39524 uint32_t pseudo_palette[16];
39525 };
39526
39527 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39528 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39529 .id = "JZ4740 FB",
39530 .type = FB_TYPE_PACKED_PIXELS,
39531 .visual = FB_VISUAL_TRUECOLOR,
39532 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39533 index 3c14e43..eafa544 100644
39534 --- a/drivers/video/logo/logo_linux_clut224.ppm
39535 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39536 @@ -1,1604 +1,1123 @@
39537 P3
39538 -# Standard 224-color Linux logo
39539 80 80
39540 255
39541 - 0 0 0 0 0 0 0 0 0 0 0 0
39542 - 0 0 0 0 0 0 0 0 0 0 0 0
39543 - 0 0 0 0 0 0 0 0 0 0 0 0
39544 - 0 0 0 0 0 0 0 0 0 0 0 0
39545 - 0 0 0 0 0 0 0 0 0 0 0 0
39546 - 0 0 0 0 0 0 0 0 0 0 0 0
39547 - 0 0 0 0 0 0 0 0 0 0 0 0
39548 - 0 0 0 0 0 0 0 0 0 0 0 0
39549 - 0 0 0 0 0 0 0 0 0 0 0 0
39550 - 6 6 6 6 6 6 10 10 10 10 10 10
39551 - 10 10 10 6 6 6 6 6 6 6 6 6
39552 - 0 0 0 0 0 0 0 0 0 0 0 0
39553 - 0 0 0 0 0 0 0 0 0 0 0 0
39554 - 0 0 0 0 0 0 0 0 0 0 0 0
39555 - 0 0 0 0 0 0 0 0 0 0 0 0
39556 - 0 0 0 0 0 0 0 0 0 0 0 0
39557 - 0 0 0 0 0 0 0 0 0 0 0 0
39558 - 0 0 0 0 0 0 0 0 0 0 0 0
39559 - 0 0 0 0 0 0 0 0 0 0 0 0
39560 - 0 0 0 0 0 0 0 0 0 0 0 0
39561 - 0 0 0 0 0 0 0 0 0 0 0 0
39562 - 0 0 0 0 0 0 0 0 0 0 0 0
39563 - 0 0 0 0 0 0 0 0 0 0 0 0
39564 - 0 0 0 0 0 0 0 0 0 0 0 0
39565 - 0 0 0 0 0 0 0 0 0 0 0 0
39566 - 0 0 0 0 0 0 0 0 0 0 0 0
39567 - 0 0 0 0 0 0 0 0 0 0 0 0
39568 - 0 0 0 0 0 0 0 0 0 0 0 0
39569 - 0 0 0 6 6 6 10 10 10 14 14 14
39570 - 22 22 22 26 26 26 30 30 30 34 34 34
39571 - 30 30 30 30 30 30 26 26 26 18 18 18
39572 - 14 14 14 10 10 10 6 6 6 0 0 0
39573 - 0 0 0 0 0 0 0 0 0 0 0 0
39574 - 0 0 0 0 0 0 0 0 0 0 0 0
39575 - 0 0 0 0 0 0 0 0 0 0 0 0
39576 - 0 0 0 0 0 0 0 0 0 0 0 0
39577 - 0 0 0 0 0 0 0 0 0 0 0 0
39578 - 0 0 0 0 0 0 0 0 0 0 0 0
39579 - 0 0 0 0 0 0 0 0 0 0 0 0
39580 - 0 0 0 0 0 0 0 0 0 0 0 0
39581 - 0 0 0 0 0 0 0 0 0 0 0 0
39582 - 0 0 0 0 0 1 0 0 1 0 0 0
39583 - 0 0 0 0 0 0 0 0 0 0 0 0
39584 - 0 0 0 0 0 0 0 0 0 0 0 0
39585 - 0 0 0 0 0 0 0 0 0 0 0 0
39586 - 0 0 0 0 0 0 0 0 0 0 0 0
39587 - 0 0 0 0 0 0 0 0 0 0 0 0
39588 - 0 0 0 0 0 0 0 0 0 0 0 0
39589 - 6 6 6 14 14 14 26 26 26 42 42 42
39590 - 54 54 54 66 66 66 78 78 78 78 78 78
39591 - 78 78 78 74 74 74 66 66 66 54 54 54
39592 - 42 42 42 26 26 26 18 18 18 10 10 10
39593 - 6 6 6 0 0 0 0 0 0 0 0 0
39594 - 0 0 0 0 0 0 0 0 0 0 0 0
39595 - 0 0 0 0 0 0 0 0 0 0 0 0
39596 - 0 0 0 0 0 0 0 0 0 0 0 0
39597 - 0 0 0 0 0 0 0 0 0 0 0 0
39598 - 0 0 0 0 0 0 0 0 0 0 0 0
39599 - 0 0 0 0 0 0 0 0 0 0 0 0
39600 - 0 0 0 0 0 0 0 0 0 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 1 0 0 0 0 0 0 0 0 0
39603 - 0 0 0 0 0 0 0 0 0 0 0 0
39604 - 0 0 0 0 0 0 0 0 0 0 0 0
39605 - 0 0 0 0 0 0 0 0 0 0 0 0
39606 - 0 0 0 0 0 0 0 0 0 0 0 0
39607 - 0 0 0 0 0 0 0 0 0 0 0 0
39608 - 0 0 0 0 0 0 0 0 0 10 10 10
39609 - 22 22 22 42 42 42 66 66 66 86 86 86
39610 - 66 66 66 38 38 38 38 38 38 22 22 22
39611 - 26 26 26 34 34 34 54 54 54 66 66 66
39612 - 86 86 86 70 70 70 46 46 46 26 26 26
39613 - 14 14 14 6 6 6 0 0 0 0 0 0
39614 - 0 0 0 0 0 0 0 0 0 0 0 0
39615 - 0 0 0 0 0 0 0 0 0 0 0 0
39616 - 0 0 0 0 0 0 0 0 0 0 0 0
39617 - 0 0 0 0 0 0 0 0 0 0 0 0
39618 - 0 0 0 0 0 0 0 0 0 0 0 0
39619 - 0 0 0 0 0 0 0 0 0 0 0 0
39620 - 0 0 0 0 0 0 0 0 0 0 0 0
39621 - 0 0 0 0 0 0 0 0 0 0 0 0
39622 - 0 0 1 0 0 1 0 0 1 0 0 0
39623 - 0 0 0 0 0 0 0 0 0 0 0 0
39624 - 0 0 0 0 0 0 0 0 0 0 0 0
39625 - 0 0 0 0 0 0 0 0 0 0 0 0
39626 - 0 0 0 0 0 0 0 0 0 0 0 0
39627 - 0 0 0 0 0 0 0 0 0 0 0 0
39628 - 0 0 0 0 0 0 10 10 10 26 26 26
39629 - 50 50 50 82 82 82 58 58 58 6 6 6
39630 - 2 2 6 2 2 6 2 2 6 2 2 6
39631 - 2 2 6 2 2 6 2 2 6 2 2 6
39632 - 6 6 6 54 54 54 86 86 86 66 66 66
39633 - 38 38 38 18 18 18 6 6 6 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 0 0 0 0 0 0 0 0 0 0
39641 - 0 0 0 0 0 0 0 0 0 0 0 0
39642 - 0 0 0 0 0 0 0 0 0 0 0 0
39643 - 0 0 0 0 0 0 0 0 0 0 0 0
39644 - 0 0 0 0 0 0 0 0 0 0 0 0
39645 - 0 0 0 0 0 0 0 0 0 0 0 0
39646 - 0 0 0 0 0 0 0 0 0 0 0 0
39647 - 0 0 0 0 0 0 0 0 0 0 0 0
39648 - 0 0 0 6 6 6 22 22 22 50 50 50
39649 - 78 78 78 34 34 34 2 2 6 2 2 6
39650 - 2 2 6 2 2 6 2 2 6 2 2 6
39651 - 2 2 6 2 2 6 2 2 6 2 2 6
39652 - 2 2 6 2 2 6 6 6 6 70 70 70
39653 - 78 78 78 46 46 46 22 22 22 6 6 6
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39668 - 6 6 6 18 18 18 42 42 42 82 82 82
39669 - 26 26 26 2 2 6 2 2 6 2 2 6
39670 - 2 2 6 2 2 6 2 2 6 2 2 6
39671 - 2 2 6 2 2 6 2 2 6 14 14 14
39672 - 46 46 46 34 34 34 6 6 6 2 2 6
39673 - 42 42 42 78 78 78 42 42 42 18 18 18
39674 - 6 6 6 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 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 10 10 10 30 30 30 66 66 66 58 58 58
39689 - 2 2 6 2 2 6 2 2 6 2 2 6
39690 - 2 2 6 2 2 6 2 2 6 2 2 6
39691 - 2 2 6 2 2 6 2 2 6 26 26 26
39692 - 86 86 86 101 101 101 46 46 46 10 10 10
39693 - 2 2 6 58 58 58 70 70 70 34 34 34
39694 - 10 10 10 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 14 14 14 42 42 42 86 86 86 10 10 10
39709 - 2 2 6 2 2 6 2 2 6 2 2 6
39710 - 2 2 6 2 2 6 2 2 6 2 2 6
39711 - 2 2 6 2 2 6 2 2 6 30 30 30
39712 - 94 94 94 94 94 94 58 58 58 26 26 26
39713 - 2 2 6 6 6 6 78 78 78 54 54 54
39714 - 22 22 22 6 6 6 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 0 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 0 0 0
39726 - 0 0 0 0 0 0 0 0 0 0 0 0
39727 - 0 0 0 0 0 0 0 0 0 6 6 6
39728 - 22 22 22 62 62 62 62 62 62 2 2 6
39729 - 2 2 6 2 2 6 2 2 6 2 2 6
39730 - 2 2 6 2 2 6 2 2 6 2 2 6
39731 - 2 2 6 2 2 6 2 2 6 26 26 26
39732 - 54 54 54 38 38 38 18 18 18 10 10 10
39733 - 2 2 6 2 2 6 34 34 34 82 82 82
39734 - 38 38 38 14 14 14 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 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 1 0 0 1 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 0 0 0 0 0 0
39746 - 0 0 0 0 0 0 0 0 0 0 0 0
39747 - 0 0 0 0 0 0 0 0 0 6 6 6
39748 - 30 30 30 78 78 78 30 30 30 2 2 6
39749 - 2 2 6 2 2 6 2 2 6 2 2 6
39750 - 2 2 6 2 2 6 2 2 6 2 2 6
39751 - 2 2 6 2 2 6 2 2 6 10 10 10
39752 - 10 10 10 2 2 6 2 2 6 2 2 6
39753 - 2 2 6 2 2 6 2 2 6 78 78 78
39754 - 50 50 50 18 18 18 6 6 6 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 1 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 0 0 0 0 0 0 0 0 0
39766 - 0 0 0 0 0 0 0 0 0 0 0 0
39767 - 0 0 0 0 0 0 0 0 0 10 10 10
39768 - 38 38 38 86 86 86 14 14 14 2 2 6
39769 - 2 2 6 2 2 6 2 2 6 2 2 6
39770 - 2 2 6 2 2 6 2 2 6 2 2 6
39771 - 2 2 6 2 2 6 2 2 6 2 2 6
39772 - 2 2 6 2 2 6 2 2 6 2 2 6
39773 - 2 2 6 2 2 6 2 2 6 54 54 54
39774 - 66 66 66 26 26 26 6 6 6 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 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 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39786 - 0 0 0 0 0 0 0 0 0 0 0 0
39787 - 0 0 0 0 0 0 0 0 0 14 14 14
39788 - 42 42 42 82 82 82 2 2 6 2 2 6
39789 - 2 2 6 6 6 6 10 10 10 2 2 6
39790 - 2 2 6 2 2 6 2 2 6 2 2 6
39791 - 2 2 6 2 2 6 2 2 6 6 6 6
39792 - 14 14 14 10 10 10 2 2 6 2 2 6
39793 - 2 2 6 2 2 6 2 2 6 18 18 18
39794 - 82 82 82 34 34 34 10 10 10 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 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 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39806 - 0 0 0 0 0 0 0 0 0 0 0 0
39807 - 0 0 0 0 0 0 0 0 0 14 14 14
39808 - 46 46 46 86 86 86 2 2 6 2 2 6
39809 - 6 6 6 6 6 6 22 22 22 34 34 34
39810 - 6 6 6 2 2 6 2 2 6 2 2 6
39811 - 2 2 6 2 2 6 18 18 18 34 34 34
39812 - 10 10 10 50 50 50 22 22 22 2 2 6
39813 - 2 2 6 2 2 6 2 2 6 10 10 10
39814 - 86 86 86 42 42 42 14 14 14 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1 0 0 1 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 - 0 0 0 0 0 0 0 0 0 0 0 0
39826 - 0 0 0 0 0 0 0 0 0 0 0 0
39827 - 0 0 0 0 0 0 0 0 0 14 14 14
39828 - 46 46 46 86 86 86 2 2 6 2 2 6
39829 - 38 38 38 116 116 116 94 94 94 22 22 22
39830 - 22 22 22 2 2 6 2 2 6 2 2 6
39831 - 14 14 14 86 86 86 138 138 138 162 162 162
39832 -154 154 154 38 38 38 26 26 26 6 6 6
39833 - 2 2 6 2 2 6 2 2 6 2 2 6
39834 - 86 86 86 46 46 46 14 14 14 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 0 0 0
39845 - 0 0 0 0 0 0 0 0 0 0 0 0
39846 - 0 0 0 0 0 0 0 0 0 0 0 0
39847 - 0 0 0 0 0 0 0 0 0 14 14 14
39848 - 46 46 46 86 86 86 2 2 6 14 14 14
39849 -134 134 134 198 198 198 195 195 195 116 116 116
39850 - 10 10 10 2 2 6 2 2 6 6 6 6
39851 -101 98 89 187 187 187 210 210 210 218 218 218
39852 -214 214 214 134 134 134 14 14 14 6 6 6
39853 - 2 2 6 2 2 6 2 2 6 2 2 6
39854 - 86 86 86 50 50 50 18 18 18 6 6 6
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
39862 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 0 0 0
39866 - 0 0 0 0 0 0 0 0 0 0 0 0
39867 - 0 0 0 0 0 0 0 0 0 14 14 14
39868 - 46 46 46 86 86 86 2 2 6 54 54 54
39869 -218 218 218 195 195 195 226 226 226 246 246 246
39870 - 58 58 58 2 2 6 2 2 6 30 30 30
39871 -210 210 210 253 253 253 174 174 174 123 123 123
39872 -221 221 221 234 234 234 74 74 74 2 2 6
39873 - 2 2 6 2 2 6 2 2 6 2 2 6
39874 - 70 70 70 58 58 58 22 22 22 6 6 6
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39885 - 0 0 0 0 0 0 0 0 0 0 0 0
39886 - 0 0 0 0 0 0 0 0 0 0 0 0
39887 - 0 0 0 0 0 0 0 0 0 14 14 14
39888 - 46 46 46 82 82 82 2 2 6 106 106 106
39889 -170 170 170 26 26 26 86 86 86 226 226 226
39890 -123 123 123 10 10 10 14 14 14 46 46 46
39891 -231 231 231 190 190 190 6 6 6 70 70 70
39892 - 90 90 90 238 238 238 158 158 158 2 2 6
39893 - 2 2 6 2 2 6 2 2 6 2 2 6
39894 - 70 70 70 58 58 58 22 22 22 6 6 6
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
39902 - 0 0 1 0 0 1 0 0 1 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 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 0 0 0
39906 - 0 0 0 0 0 0 0 0 0 0 0 0
39907 - 0 0 0 0 0 0 0 0 0 14 14 14
39908 - 42 42 42 86 86 86 6 6 6 116 116 116
39909 -106 106 106 6 6 6 70 70 70 149 149 149
39910 -128 128 128 18 18 18 38 38 38 54 54 54
39911 -221 221 221 106 106 106 2 2 6 14 14 14
39912 - 46 46 46 190 190 190 198 198 198 2 2 6
39913 - 2 2 6 2 2 6 2 2 6 2 2 6
39914 - 74 74 74 62 62 62 22 22 22 6 6 6
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 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 1 0 0 0
39922 - 0 0 1 0 0 0 0 0 1 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 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 0 0 0
39926 - 0 0 0 0 0 0 0 0 0 0 0 0
39927 - 0 0 0 0 0 0 0 0 0 14 14 14
39928 - 42 42 42 94 94 94 14 14 14 101 101 101
39929 -128 128 128 2 2 6 18 18 18 116 116 116
39930 -118 98 46 121 92 8 121 92 8 98 78 10
39931 -162 162 162 106 106 106 2 2 6 2 2 6
39932 - 2 2 6 195 195 195 195 195 195 6 6 6
39933 - 2 2 6 2 2 6 2 2 6 2 2 6
39934 - 74 74 74 62 62 62 22 22 22 6 6 6
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 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 1 0 0 1
39942 - 0 0 1 0 0 0 0 0 1 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 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 0 0 0
39946 - 0 0 0 0 0 0 0 0 0 0 0 0
39947 - 0 0 0 0 0 0 0 0 0 10 10 10
39948 - 38 38 38 90 90 90 14 14 14 58 58 58
39949 -210 210 210 26 26 26 54 38 6 154 114 10
39950 -226 170 11 236 186 11 225 175 15 184 144 12
39951 -215 174 15 175 146 61 37 26 9 2 2 6
39952 - 70 70 70 246 246 246 138 138 138 2 2 6
39953 - 2 2 6 2 2 6 2 2 6 2 2 6
39954 - 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
39965 - 0 0 0 0 0 0 0 0 0 0 0 0
39966 - 0 0 0 0 0 0 0 0 0 0 0 0
39967 - 0 0 0 0 0 0 0 0 0 10 10 10
39968 - 38 38 38 86 86 86 14 14 14 10 10 10
39969 -195 195 195 188 164 115 192 133 9 225 175 15
39970 -239 182 13 234 190 10 232 195 16 232 200 30
39971 -245 207 45 241 208 19 232 195 16 184 144 12
39972 -218 194 134 211 206 186 42 42 42 2 2 6
39973 - 2 2 6 2 2 6 2 2 6 2 2 6
39974 - 50 50 50 74 74 74 30 30 30 6 6 6
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 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 0 0 0
39985 - 0 0 0 0 0 0 0 0 0 0 0 0
39986 - 0 0 0 0 0 0 0 0 0 0 0 0
39987 - 0 0 0 0 0 0 0 0 0 10 10 10
39988 - 34 34 34 86 86 86 14 14 14 2 2 6
39989 -121 87 25 192 133 9 219 162 10 239 182 13
39990 -236 186 11 232 195 16 241 208 19 244 214 54
39991 -246 218 60 246 218 38 246 215 20 241 208 19
39992 -241 208 19 226 184 13 121 87 25 2 2 6
39993 - 2 2 6 2 2 6 2 2 6 2 2 6
39994 - 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 0 0 0
40006 - 0 0 0 0 0 0 0 0 0 0 0 0
40007 - 0 0 0 0 0 0 0 0 0 10 10 10
40008 - 34 34 34 82 82 82 30 30 30 61 42 6
40009 -180 123 7 206 145 10 230 174 11 239 182 13
40010 -234 190 10 238 202 15 241 208 19 246 218 74
40011 -246 218 38 246 215 20 246 215 20 246 215 20
40012 -226 184 13 215 174 15 184 144 12 6 6 6
40013 - 2 2 6 2 2 6 2 2 6 2 2 6
40014 - 26 26 26 94 94 94 42 42 42 14 14 14
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40025 - 0 0 0 0 0 0 0 0 0 0 0 0
40026 - 0 0 0 0 0 0 0 0 0 0 0 0
40027 - 0 0 0 0 0 0 0 0 0 10 10 10
40028 - 30 30 30 78 78 78 50 50 50 104 69 6
40029 -192 133 9 216 158 10 236 178 12 236 186 11
40030 -232 195 16 241 208 19 244 214 54 245 215 43
40031 -246 215 20 246 215 20 241 208 19 198 155 10
40032 -200 144 11 216 158 10 156 118 10 2 2 6
40033 - 2 2 6 2 2 6 2 2 6 2 2 6
40034 - 6 6 6 90 90 90 54 54 54 18 18 18
40035 - 6 6 6 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40045 - 0 0 0 0 0 0 0 0 0 0 0 0
40046 - 0 0 0 0 0 0 0 0 0 0 0 0
40047 - 0 0 0 0 0 0 0 0 0 10 10 10
40048 - 30 30 30 78 78 78 46 46 46 22 22 22
40049 -137 92 6 210 162 10 239 182 13 238 190 10
40050 -238 202 15 241 208 19 246 215 20 246 215 20
40051 -241 208 19 203 166 17 185 133 11 210 150 10
40052 -216 158 10 210 150 10 102 78 10 2 2 6
40053 - 6 6 6 54 54 54 14 14 14 2 2 6
40054 - 2 2 6 62 62 62 74 74 74 30 30 30
40055 - 10 10 10 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 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 0 0 0
40065 - 0 0 0 0 0 0 0 0 0 0 0 0
40066 - 0 0 0 0 0 0 0 0 0 0 0 0
40067 - 0 0 0 0 0 0 0 0 0 10 10 10
40068 - 34 34 34 78 78 78 50 50 50 6 6 6
40069 - 94 70 30 139 102 15 190 146 13 226 184 13
40070 -232 200 30 232 195 16 215 174 15 190 146 13
40071 -168 122 10 192 133 9 210 150 10 213 154 11
40072 -202 150 34 182 157 106 101 98 89 2 2 6
40073 - 2 2 6 78 78 78 116 116 116 58 58 58
40074 - 2 2 6 22 22 22 90 90 90 46 46 46
40075 - 18 18 18 6 6 6 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 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 0 0 0
40086 - 0 0 0 0 0 0 0 0 0 0 0 0
40087 - 0 0 0 0 0 0 0 0 0 10 10 10
40088 - 38 38 38 86 86 86 50 50 50 6 6 6
40089 -128 128 128 174 154 114 156 107 11 168 122 10
40090 -198 155 10 184 144 12 197 138 11 200 144 11
40091 -206 145 10 206 145 10 197 138 11 188 164 115
40092 -195 195 195 198 198 198 174 174 174 14 14 14
40093 - 2 2 6 22 22 22 116 116 116 116 116 116
40094 - 22 22 22 2 2 6 74 74 74 70 70 70
40095 - 30 30 30 10 10 10 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 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 0 0 0
40106 - 0 0 0 0 0 0 0 0 0 0 0 0
40107 - 0 0 0 0 0 0 6 6 6 18 18 18
40108 - 50 50 50 101 101 101 26 26 26 10 10 10
40109 -138 138 138 190 190 190 174 154 114 156 107 11
40110 -197 138 11 200 144 11 197 138 11 192 133 9
40111 -180 123 7 190 142 34 190 178 144 187 187 187
40112 -202 202 202 221 221 221 214 214 214 66 66 66
40113 - 2 2 6 2 2 6 50 50 50 62 62 62
40114 - 6 6 6 2 2 6 10 10 10 90 90 90
40115 - 50 50 50 18 18 18 6 6 6 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 0 0 0
40125 - 0 0 0 0 0 0 0 0 0 0 0 0
40126 - 0 0 0 0 0 0 0 0 0 0 0 0
40127 - 0 0 0 0 0 0 10 10 10 34 34 34
40128 - 74 74 74 74 74 74 2 2 6 6 6 6
40129 -144 144 144 198 198 198 190 190 190 178 166 146
40130 -154 121 60 156 107 11 156 107 11 168 124 44
40131 -174 154 114 187 187 187 190 190 190 210 210 210
40132 -246 246 246 253 253 253 253 253 253 182 182 182
40133 - 6 6 6 2 2 6 2 2 6 2 2 6
40134 - 2 2 6 2 2 6 2 2 6 62 62 62
40135 - 74 74 74 34 34 34 14 14 14 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 0 0 0
40145 - 0 0 0 0 0 0 0 0 0 0 0 0
40146 - 0 0 0 0 0 0 0 0 0 0 0 0
40147 - 0 0 0 10 10 10 22 22 22 54 54 54
40148 - 94 94 94 18 18 18 2 2 6 46 46 46
40149 -234 234 234 221 221 221 190 190 190 190 190 190
40150 -190 190 190 187 187 187 187 187 187 190 190 190
40151 -190 190 190 195 195 195 214 214 214 242 242 242
40152 -253 253 253 253 253 253 253 253 253 253 253 253
40153 - 82 82 82 2 2 6 2 2 6 2 2 6
40154 - 2 2 6 2 2 6 2 2 6 14 14 14
40155 - 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
40165 - 0 0 0 0 0 0 0 0 0 0 0 0
40166 - 0 0 0 0 0 0 0 0 0 0 0 0
40167 - 6 6 6 18 18 18 46 46 46 90 90 90
40168 - 46 46 46 18 18 18 6 6 6 182 182 182
40169 -253 253 253 246 246 246 206 206 206 190 190 190
40170 -190 190 190 190 190 190 190 190 190 190 190 190
40171 -206 206 206 231 231 231 250 250 250 253 253 253
40172 -253 253 253 253 253 253 253 253 253 253 253 253
40173 -202 202 202 14 14 14 2 2 6 2 2 6
40174 - 2 2 6 2 2 6 2 2 6 2 2 6
40175 - 42 42 42 86 86 86 42 42 42 18 18 18
40176 - 6 6 6 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 0 0 0
40185 - 0 0 0 0 0 0 0 0 0 0 0 0
40186 - 0 0 0 0 0 0 0 0 0 6 6 6
40187 - 14 14 14 38 38 38 74 74 74 66 66 66
40188 - 2 2 6 6 6 6 90 90 90 250 250 250
40189 -253 253 253 253 253 253 238 238 238 198 198 198
40190 -190 190 190 190 190 190 195 195 195 221 221 221
40191 -246 246 246 253 253 253 253 253 253 253 253 253
40192 -253 253 253 253 253 253 253 253 253 253 253 253
40193 -253 253 253 82 82 82 2 2 6 2 2 6
40194 - 2 2 6 2 2 6 2 2 6 2 2 6
40195 - 2 2 6 78 78 78 70 70 70 34 34 34
40196 - 14 14 14 6 6 6 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 0 0 0
40205 - 0 0 0 0 0 0 0 0 0 0 0 0
40206 - 0 0 0 0 0 0 0 0 0 14 14 14
40207 - 34 34 34 66 66 66 78 78 78 6 6 6
40208 - 2 2 6 18 18 18 218 218 218 253 253 253
40209 -253 253 253 253 253 253 253 253 253 246 246 246
40210 -226 226 226 231 231 231 246 246 246 253 253 253
40211 -253 253 253 253 253 253 253 253 253 253 253 253
40212 -253 253 253 253 253 253 253 253 253 253 253 253
40213 -253 253 253 178 178 178 2 2 6 2 2 6
40214 - 2 2 6 2 2 6 2 2 6 2 2 6
40215 - 2 2 6 18 18 18 90 90 90 62 62 62
40216 - 30 30 30 10 10 10 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 0 0 0 0 0 0
40225 - 0 0 0 0 0 0 0 0 0 0 0 0
40226 - 0 0 0 0 0 0 10 10 10 26 26 26
40227 - 58 58 58 90 90 90 18 18 18 2 2 6
40228 - 2 2 6 110 110 110 253 253 253 253 253 253
40229 -253 253 253 253 253 253 253 253 253 253 253 253
40230 -250 250 250 253 253 253 253 253 253 253 253 253
40231 -253 253 253 253 253 253 253 253 253 253 253 253
40232 -253 253 253 253 253 253 253 253 253 253 253 253
40233 -253 253 253 231 231 231 18 18 18 2 2 6
40234 - 2 2 6 2 2 6 2 2 6 2 2 6
40235 - 2 2 6 2 2 6 18 18 18 94 94 94
40236 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0
40245 - 0 0 0 0 0 0 0 0 0 0 0 0
40246 - 0 0 0 6 6 6 22 22 22 50 50 50
40247 - 90 90 90 26 26 26 2 2 6 2 2 6
40248 - 14 14 14 195 195 195 250 250 250 253 253 253
40249 -253 253 253 253 253 253 253 253 253 253 253 253
40250 -253 253 253 253 253 253 253 253 253 253 253 253
40251 -253 253 253 253 253 253 253 253 253 253 253 253
40252 -253 253 253 253 253 253 253 253 253 253 253 253
40253 -250 250 250 242 242 242 54 54 54 2 2 6
40254 - 2 2 6 2 2 6 2 2 6 2 2 6
40255 - 2 2 6 2 2 6 2 2 6 38 38 38
40256 - 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
40265 - 0 0 0 0 0 0 0 0 0 0 0 0
40266 - 6 6 6 14 14 14 38 38 38 82 82 82
40267 - 34 34 34 2 2 6 2 2 6 2 2 6
40268 - 42 42 42 195 195 195 246 246 246 253 253 253
40269 -253 253 253 253 253 253 253 253 253 250 250 250
40270 -242 242 242 242 242 242 250 250 250 253 253 253
40271 -253 253 253 253 253 253 253 253 253 253 253 253
40272 -253 253 253 250 250 250 246 246 246 238 238 238
40273 -226 226 226 231 231 231 101 101 101 6 6 6
40274 - 2 2 6 2 2 6 2 2 6 2 2 6
40275 - 2 2 6 2 2 6 2 2 6 2 2 6
40276 - 38 38 38 82 82 82 42 42 42 14 14 14
40277 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40285 - 0 0 0 0 0 0 0 0 0 0 0 0
40286 - 10 10 10 26 26 26 62 62 62 66 66 66
40287 - 2 2 6 2 2 6 2 2 6 6 6 6
40288 - 70 70 70 170 170 170 206 206 206 234 234 234
40289 -246 246 246 250 250 250 250 250 250 238 238 238
40290 -226 226 226 231 231 231 238 238 238 250 250 250
40291 -250 250 250 250 250 250 246 246 246 231 231 231
40292 -214 214 214 206 206 206 202 202 202 202 202 202
40293 -198 198 198 202 202 202 182 182 182 18 18 18
40294 - 2 2 6 2 2 6 2 2 6 2 2 6
40295 - 2 2 6 2 2 6 2 2 6 2 2 6
40296 - 2 2 6 62 62 62 66 66 66 30 30 30
40297 - 10 10 10 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 0 0 0
40304 - 0 0 0 0 0 0 0 0 0 0 0 0
40305 - 0 0 0 0 0 0 0 0 0 0 0 0
40306 - 14 14 14 42 42 42 82 82 82 18 18 18
40307 - 2 2 6 2 2 6 2 2 6 10 10 10
40308 - 94 94 94 182 182 182 218 218 218 242 242 242
40309 -250 250 250 253 253 253 253 253 253 250 250 250
40310 -234 234 234 253 253 253 253 253 253 253 253 253
40311 -253 253 253 253 253 253 253 253 253 246 246 246
40312 -238 238 238 226 226 226 210 210 210 202 202 202
40313 -195 195 195 195 195 195 210 210 210 158 158 158
40314 - 6 6 6 14 14 14 50 50 50 14 14 14
40315 - 2 2 6 2 2 6 2 2 6 2 2 6
40316 - 2 2 6 6 6 6 86 86 86 46 46 46
40317 - 18 18 18 6 6 6 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 0 0 0
40324 - 0 0 0 0 0 0 0 0 0 0 0 0
40325 - 0 0 0 0 0 0 0 0 0 6 6 6
40326 - 22 22 22 54 54 54 70 70 70 2 2 6
40327 - 2 2 6 10 10 10 2 2 6 22 22 22
40328 -166 166 166 231 231 231 250 250 250 253 253 253
40329 -253 253 253 253 253 253 253 253 253 250 250 250
40330 -242 242 242 253 253 253 253 253 253 253 253 253
40331 -253 253 253 253 253 253 253 253 253 253 253 253
40332 -253 253 253 253 253 253 253 253 253 246 246 246
40333 -231 231 231 206 206 206 198 198 198 226 226 226
40334 - 94 94 94 2 2 6 6 6 6 38 38 38
40335 - 30 30 30 2 2 6 2 2 6 2 2 6
40336 - 2 2 6 2 2 6 62 62 62 66 66 66
40337 - 26 26 26 10 10 10 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 0 0 0 0 0 0
40344 - 0 0 0 0 0 0 0 0 0 0 0 0
40345 - 0 0 0 0 0 0 0 0 0 10 10 10
40346 - 30 30 30 74 74 74 50 50 50 2 2 6
40347 - 26 26 26 26 26 26 2 2 6 106 106 106
40348 -238 238 238 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 253 253 253 253 253 253 253 253 253
40351 -253 253 253 253 253 253 253 253 253 253 253 253
40352 -253 253 253 253 253 253 253 253 253 253 253 253
40353 -253 253 253 246 246 246 218 218 218 202 202 202
40354 -210 210 210 14 14 14 2 2 6 2 2 6
40355 - 30 30 30 22 22 22 2 2 6 2 2 6
40356 - 2 2 6 2 2 6 18 18 18 86 86 86
40357 - 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0
40364 - 0 0 0 0 0 0 0 0 0 0 0 0
40365 - 0 0 0 0 0 0 0 0 0 14 14 14
40366 - 42 42 42 90 90 90 22 22 22 2 2 6
40367 - 42 42 42 2 2 6 18 18 18 218 218 218
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 -253 253 253 253 253 253 253 253 253 253 253 253
40371 -253 253 253 253 253 253 253 253 253 253 253 253
40372 -253 253 253 253 253 253 253 253 253 253 253 253
40373 -253 253 253 253 253 253 250 250 250 221 221 221
40374 -218 218 218 101 101 101 2 2 6 14 14 14
40375 - 18 18 18 38 38 38 10 10 10 2 2 6
40376 - 2 2 6 2 2 6 2 2 6 78 78 78
40377 - 58 58 58 22 22 22 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40384 - 0 0 0 0 0 0 0 0 0 0 0 0
40385 - 0 0 0 0 0 0 6 6 6 18 18 18
40386 - 54 54 54 82 82 82 2 2 6 26 26 26
40387 - 22 22 22 2 2 6 123 123 123 253 253 253
40388 -253 253 253 253 253 253 253 253 253 253 253 253
40389 -253 253 253 253 253 253 253 253 253 253 253 253
40390 -253 253 253 253 253 253 253 253 253 253 253 253
40391 -253 253 253 253 253 253 253 253 253 253 253 253
40392 -253 253 253 253 253 253 253 253 253 253 253 253
40393 -253 253 253 253 253 253 253 253 253 250 250 250
40394 -238 238 238 198 198 198 6 6 6 38 38 38
40395 - 58 58 58 26 26 26 38 38 38 2 2 6
40396 - 2 2 6 2 2 6 2 2 6 46 46 46
40397 - 78 78 78 30 30 30 10 10 10 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40404 - 0 0 0 0 0 0 0 0 0 0 0 0
40405 - 0 0 0 0 0 0 10 10 10 30 30 30
40406 - 74 74 74 58 58 58 2 2 6 42 42 42
40407 - 2 2 6 22 22 22 231 231 231 253 253 253
40408 -253 253 253 253 253 253 253 253 253 253 253 253
40409 -253 253 253 253 253 253 253 253 253 250 250 250
40410 -253 253 253 253 253 253 253 253 253 253 253 253
40411 -253 253 253 253 253 253 253 253 253 253 253 253
40412 -253 253 253 253 253 253 253 253 253 253 253 253
40413 -253 253 253 253 253 253 253 253 253 253 253 253
40414 -253 253 253 246 246 246 46 46 46 38 38 38
40415 - 42 42 42 14 14 14 38 38 38 14 14 14
40416 - 2 2 6 2 2 6 2 2 6 6 6 6
40417 - 86 86 86 46 46 46 14 14 14 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40424 - 0 0 0 0 0 0 0 0 0 0 0 0
40425 - 0 0 0 6 6 6 14 14 14 42 42 42
40426 - 90 90 90 18 18 18 18 18 18 26 26 26
40427 - 2 2 6 116 116 116 253 253 253 253 253 253
40428 -253 253 253 253 253 253 253 253 253 253 253 253
40429 -253 253 253 253 253 253 250 250 250 238 238 238
40430 -253 253 253 253 253 253 253 253 253 253 253 253
40431 -253 253 253 253 253 253 253 253 253 253 253 253
40432 -253 253 253 253 253 253 253 253 253 253 253 253
40433 -253 253 253 253 253 253 253 253 253 253 253 253
40434 -253 253 253 253 253 253 94 94 94 6 6 6
40435 - 2 2 6 2 2 6 10 10 10 34 34 34
40436 - 2 2 6 2 2 6 2 2 6 2 2 6
40437 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
40443 - 0 0 0 0 0 0 0 0 0 0 0 0
40444 - 0 0 0 0 0 0 0 0 0 0 0 0
40445 - 0 0 0 10 10 10 26 26 26 66 66 66
40446 - 82 82 82 2 2 6 38 38 38 6 6 6
40447 - 14 14 14 210 210 210 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 246 246 246 242 242 242
40450 -253 253 253 253 253 253 253 253 253 253 253 253
40451 -253 253 253 253 253 253 253 253 253 253 253 253
40452 -253 253 253 253 253 253 253 253 253 253 253 253
40453 -253 253 253 253 253 253 253 253 253 253 253 253
40454 -253 253 253 253 253 253 144 144 144 2 2 6
40455 - 2 2 6 2 2 6 2 2 6 46 46 46
40456 - 2 2 6 2 2 6 2 2 6 2 2 6
40457 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
40463 - 0 0 0 0 0 0 0 0 0 0 0 0
40464 - 0 0 0 0 0 0 0 0 0 0 0 0
40465 - 6 6 6 14 14 14 42 42 42 90 90 90
40466 - 26 26 26 6 6 6 42 42 42 2 2 6
40467 - 74 74 74 250 250 250 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 242 242 242 242 242 242
40470 -253 253 253 253 253 253 253 253 253 253 253 253
40471 -253 253 253 253 253 253 253 253 253 253 253 253
40472 -253 253 253 253 253 253 253 253 253 253 253 253
40473 -253 253 253 253 253 253 253 253 253 253 253 253
40474 -253 253 253 253 253 253 182 182 182 2 2 6
40475 - 2 2 6 2 2 6 2 2 6 46 46 46
40476 - 2 2 6 2 2 6 2 2 6 2 2 6
40477 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
40483 - 0 0 0 0 0 0 0 0 0 0 0 0
40484 - 0 0 0 0 0 0 0 0 0 0 0 0
40485 - 10 10 10 26 26 26 66 66 66 82 82 82
40486 - 2 2 6 22 22 22 18 18 18 2 2 6
40487 -149 149 149 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 234 234 234 242 242 242
40490 -253 253 253 253 253 253 253 253 253 253 253 253
40491 -253 253 253 253 253 253 253 253 253 253 253 253
40492 -253 253 253 253 253 253 253 253 253 253 253 253
40493 -253 253 253 253 253 253 253 253 253 253 253 253
40494 -253 253 253 253 253 253 206 206 206 2 2 6
40495 - 2 2 6 2 2 6 2 2 6 38 38 38
40496 - 2 2 6 2 2 6 2 2 6 2 2 6
40497 - 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0
40503 - 0 0 0 0 0 0 0 0 0 0 0 0
40504 - 0 0 0 0 0 0 0 0 0 6 6 6
40505 - 18 18 18 46 46 46 86 86 86 18 18 18
40506 - 2 2 6 34 34 34 10 10 10 6 6 6
40507 -210 210 210 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 234 234 234 242 242 242
40510 -253 253 253 253 253 253 253 253 253 253 253 253
40511 -253 253 253 253 253 253 253 253 253 253 253 253
40512 -253 253 253 253 253 253 253 253 253 253 253 253
40513 -253 253 253 253 253 253 253 253 253 253 253 253
40514 -253 253 253 253 253 253 221 221 221 6 6 6
40515 - 2 2 6 2 2 6 6 6 6 30 30 30
40516 - 2 2 6 2 2 6 2 2 6 2 2 6
40517 - 2 2 6 82 82 82 54 54 54 18 18 18
40518 - 6 6 6 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 0 0 0 0 0 0
40523 - 0 0 0 0 0 0 0 0 0 0 0 0
40524 - 0 0 0 0 0 0 0 0 0 10 10 10
40525 - 26 26 26 66 66 66 62 62 62 2 2 6
40526 - 2 2 6 38 38 38 10 10 10 26 26 26
40527 -238 238 238 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 231 231 231 238 238 238
40530 -253 253 253 253 253 253 253 253 253 253 253 253
40531 -253 253 253 253 253 253 253 253 253 253 253 253
40532 -253 253 253 253 253 253 253 253 253 253 253 253
40533 -253 253 253 253 253 253 253 253 253 253 253 253
40534 -253 253 253 253 253 253 231 231 231 6 6 6
40535 - 2 2 6 2 2 6 10 10 10 30 30 30
40536 - 2 2 6 2 2 6 2 2 6 2 2 6
40537 - 2 2 6 66 66 66 58 58 58 22 22 22
40538 - 6 6 6 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 0 0 0 0 0 0 0 0 0
40543 - 0 0 0 0 0 0 0 0 0 0 0 0
40544 - 0 0 0 0 0 0 0 0 0 10 10 10
40545 - 38 38 38 78 78 78 6 6 6 2 2 6
40546 - 2 2 6 46 46 46 14 14 14 42 42 42
40547 -246 246 246 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 231 231 231 242 242 242
40550 -253 253 253 253 253 253 253 253 253 253 253 253
40551 -253 253 253 253 253 253 253 253 253 253 253 253
40552 -253 253 253 253 253 253 253 253 253 253 253 253
40553 -253 253 253 253 253 253 253 253 253 253 253 253
40554 -253 253 253 253 253 253 234 234 234 10 10 10
40555 - 2 2 6 2 2 6 22 22 22 14 14 14
40556 - 2 2 6 2 2 6 2 2 6 2 2 6
40557 - 2 2 6 66 66 66 62 62 62 22 22 22
40558 - 6 6 6 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 0 0 0 0 0 0 0 0 0
40563 - 0 0 0 0 0 0 0 0 0 0 0 0
40564 - 0 0 0 0 0 0 6 6 6 18 18 18
40565 - 50 50 50 74 74 74 2 2 6 2 2 6
40566 - 14 14 14 70 70 70 34 34 34 62 62 62
40567 -250 250 250 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 231 231 231 246 246 246
40570 -253 253 253 253 253 253 253 253 253 253 253 253
40571 -253 253 253 253 253 253 253 253 253 253 253 253
40572 -253 253 253 253 253 253 253 253 253 253 253 253
40573 -253 253 253 253 253 253 253 253 253 253 253 253
40574 -253 253 253 253 253 253 234 234 234 14 14 14
40575 - 2 2 6 2 2 6 30 30 30 2 2 6
40576 - 2 2 6 2 2 6 2 2 6 2 2 6
40577 - 2 2 6 66 66 66 62 62 62 22 22 22
40578 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40583 - 0 0 0 0 0 0 0 0 0 0 0 0
40584 - 0 0 0 0 0 0 6 6 6 18 18 18
40585 - 54 54 54 62 62 62 2 2 6 2 2 6
40586 - 2 2 6 30 30 30 46 46 46 70 70 70
40587 -250 250 250 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 231 231 231 246 246 246
40590 -253 253 253 253 253 253 253 253 253 253 253 253
40591 -253 253 253 253 253 253 253 253 253 253 253 253
40592 -253 253 253 253 253 253 253 253 253 253 253 253
40593 -253 253 253 253 253 253 253 253 253 253 253 253
40594 -253 253 253 253 253 253 226 226 226 10 10 10
40595 - 2 2 6 6 6 6 30 30 30 2 2 6
40596 - 2 2 6 2 2 6 2 2 6 2 2 6
40597 - 2 2 6 66 66 66 58 58 58 22 22 22
40598 - 6 6 6 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 - 0 0 0 0 0 0 0 0 0 0 0 0
40603 - 0 0 0 0 0 0 0 0 0 0 0 0
40604 - 0 0 0 0 0 0 6 6 6 22 22 22
40605 - 58 58 58 62 62 62 2 2 6 2 2 6
40606 - 2 2 6 2 2 6 30 30 30 78 78 78
40607 -250 250 250 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 231 231 231 246 246 246
40610 -253 253 253 253 253 253 253 253 253 253 253 253
40611 -253 253 253 253 253 253 253 253 253 253 253 253
40612 -253 253 253 253 253 253 253 253 253 253 253 253
40613 -253 253 253 253 253 253 253 253 253 253 253 253
40614 -253 253 253 253 253 253 206 206 206 2 2 6
40615 - 22 22 22 34 34 34 18 14 6 22 22 22
40616 - 26 26 26 18 18 18 6 6 6 2 2 6
40617 - 2 2 6 82 82 82 54 54 54 18 18 18
40618 - 6 6 6 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 0 0 0
40622 - 0 0 0 0 0 0 0 0 0 0 0 0
40623 - 0 0 0 0 0 0 0 0 0 0 0 0
40624 - 0 0 0 0 0 0 6 6 6 26 26 26
40625 - 62 62 62 106 106 106 74 54 14 185 133 11
40626 -210 162 10 121 92 8 6 6 6 62 62 62
40627 -238 238 238 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 231 231 231 246 246 246
40630 -253 253 253 253 253 253 253 253 253 253 253 253
40631 -253 253 253 253 253 253 253 253 253 253 253 253
40632 -253 253 253 253 253 253 253 253 253 253 253 253
40633 -253 253 253 253 253 253 253 253 253 253 253 253
40634 -253 253 253 253 253 253 158 158 158 18 18 18
40635 - 14 14 14 2 2 6 2 2 6 2 2 6
40636 - 6 6 6 18 18 18 66 66 66 38 38 38
40637 - 6 6 6 94 94 94 50 50 50 18 18 18
40638 - 6 6 6 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 0 0 0
40642 - 0 0 0 0 0 0 0 0 0 0 0 0
40643 - 0 0 0 0 0 0 0 0 0 6 6 6
40644 - 10 10 10 10 10 10 18 18 18 38 38 38
40645 - 78 78 78 142 134 106 216 158 10 242 186 14
40646 -246 190 14 246 190 14 156 118 10 10 10 10
40647 - 90 90 90 238 238 238 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 231 231 231 250 250 250
40650 -253 253 253 253 253 253 253 253 253 253 253 253
40651 -253 253 253 253 253 253 253 253 253 253 253 253
40652 -253 253 253 253 253 253 253 253 253 253 253 253
40653 -253 253 253 253 253 253 253 253 253 246 230 190
40654 -238 204 91 238 204 91 181 142 44 37 26 9
40655 - 2 2 6 2 2 6 2 2 6 2 2 6
40656 - 2 2 6 2 2 6 38 38 38 46 46 46
40657 - 26 26 26 106 106 106 54 54 54 18 18 18
40658 - 6 6 6 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 0 0 0
40662 - 0 0 0 0 0 0 0 0 0 0 0 0
40663 - 0 0 0 6 6 6 14 14 14 22 22 22
40664 - 30 30 30 38 38 38 50 50 50 70 70 70
40665 -106 106 106 190 142 34 226 170 11 242 186 14
40666 -246 190 14 246 190 14 246 190 14 154 114 10
40667 - 6 6 6 74 74 74 226 226 226 253 253 253
40668 -253 253 253 253 253 253 253 253 253 253 253 253
40669 -253 253 253 253 253 253 231 231 231 250 250 250
40670 -253 253 253 253 253 253 253 253 253 253 253 253
40671 -253 253 253 253 253 253 253 253 253 253 253 253
40672 -253 253 253 253 253 253 253 253 253 253 253 253
40673 -253 253 253 253 253 253 253 253 253 228 184 62
40674 -241 196 14 241 208 19 232 195 16 38 30 10
40675 - 2 2 6 2 2 6 2 2 6 2 2 6
40676 - 2 2 6 6 6 6 30 30 30 26 26 26
40677 -203 166 17 154 142 90 66 66 66 26 26 26
40678 - 6 6 6 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 0 0 0 0 0 0
40682 - 0 0 0 0 0 0 0 0 0 0 0 0
40683 - 6 6 6 18 18 18 38 38 38 58 58 58
40684 - 78 78 78 86 86 86 101 101 101 123 123 123
40685 -175 146 61 210 150 10 234 174 13 246 186 14
40686 -246 190 14 246 190 14 246 190 14 238 190 10
40687 -102 78 10 2 2 6 46 46 46 198 198 198
40688 -253 253 253 253 253 253 253 253 253 253 253 253
40689 -253 253 253 253 253 253 234 234 234 242 242 242
40690 -253 253 253 253 253 253 253 253 253 253 253 253
40691 -253 253 253 253 253 253 253 253 253 253 253 253
40692 -253 253 253 253 253 253 253 253 253 253 253 253
40693 -253 253 253 253 253 253 253 253 253 224 178 62
40694 -242 186 14 241 196 14 210 166 10 22 18 6
40695 - 2 2 6 2 2 6 2 2 6 2 2 6
40696 - 2 2 6 2 2 6 6 6 6 121 92 8
40697 -238 202 15 232 195 16 82 82 82 34 34 34
40698 - 10 10 10 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 0 0 0 0 0 0
40702 - 0 0 0 0 0 0 0 0 0 0 0 0
40703 - 14 14 14 38 38 38 70 70 70 154 122 46
40704 -190 142 34 200 144 11 197 138 11 197 138 11
40705 -213 154 11 226 170 11 242 186 14 246 190 14
40706 -246 190 14 246 190 14 246 190 14 246 190 14
40707 -225 175 15 46 32 6 2 2 6 22 22 22
40708 -158 158 158 250 250 250 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 253 253 253 253 253 253
40712 -253 253 253 253 253 253 253 253 253 253 253 253
40713 -253 253 253 250 250 250 242 242 242 224 178 62
40714 -239 182 13 236 186 11 213 154 11 46 32 6
40715 - 2 2 6 2 2 6 2 2 6 2 2 6
40716 - 2 2 6 2 2 6 61 42 6 225 175 15
40717 -238 190 10 236 186 11 112 100 78 42 42 42
40718 - 14 14 14 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 0 0 0 0 0 0
40722 - 0 0 0 0 0 0 0 0 0 6 6 6
40723 - 22 22 22 54 54 54 154 122 46 213 154 11
40724 -226 170 11 230 174 11 226 170 11 226 170 11
40725 -236 178 12 242 186 14 246 190 14 246 190 14
40726 -246 190 14 246 190 14 246 190 14 246 190 14
40727 -241 196 14 184 144 12 10 10 10 2 2 6
40728 - 6 6 6 116 116 116 242 242 242 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 253 253 253 253 253 253
40732 -253 253 253 253 253 253 253 253 253 253 253 253
40733 -253 253 253 231 231 231 198 198 198 214 170 54
40734 -236 178 12 236 178 12 210 150 10 137 92 6
40735 - 18 14 6 2 2 6 2 2 6 2 2 6
40736 - 6 6 6 70 47 6 200 144 11 236 178 12
40737 -239 182 13 239 182 13 124 112 88 58 58 58
40738 - 22 22 22 6 6 6 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 0 0 0 0 0 0
40742 - 0 0 0 0 0 0 0 0 0 10 10 10
40743 - 30 30 30 70 70 70 180 133 36 226 170 11
40744 -239 182 13 242 186 14 242 186 14 246 186 14
40745 -246 190 14 246 190 14 246 190 14 246 190 14
40746 -246 190 14 246 190 14 246 190 14 246 190 14
40747 -246 190 14 232 195 16 98 70 6 2 2 6
40748 - 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253 253 253 253
40752 -253 253 253 253 253 253 253 253 253 253 253 253
40753 -253 253 253 206 206 206 198 198 198 214 166 58
40754 -230 174 11 230 174 11 216 158 10 192 133 9
40755 -163 110 8 116 81 8 102 78 10 116 81 8
40756 -167 114 7 197 138 11 226 170 11 239 182 13
40757 -242 186 14 242 186 14 162 146 94 78 78 78
40758 - 34 34 34 14 14 14 6 6 6 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 0 0 0
40761 - 0 0 0 0 0 0 0 0 0 0 0 0
40762 - 0 0 0 0 0 0 0 0 0 6 6 6
40763 - 30 30 30 78 78 78 190 142 34 226 170 11
40764 -239 182 13 246 190 14 246 190 14 246 190 14
40765 -246 190 14 246 190 14 246 190 14 246 190 14
40766 -246 190 14 246 190 14 246 190 14 246 190 14
40767 -246 190 14 241 196 14 203 166 17 22 18 6
40768 - 2 2 6 2 2 6 2 2 6 38 38 38
40769 -218 218 218 253 253 253 253 253 253 253 253 253
40770 -253 253 253 253 253 253 253 253 253 253 253 253
40771 -253 253 253 253 253 253 253 253 253 253 253 253
40772 -253 253 253 253 253 253 253 253 253 253 253 253
40773 -250 250 250 206 206 206 198 198 198 202 162 69
40774 -226 170 11 236 178 12 224 166 10 210 150 10
40775 -200 144 11 197 138 11 192 133 9 197 138 11
40776 -210 150 10 226 170 11 242 186 14 246 190 14
40777 -246 190 14 246 186 14 225 175 15 124 112 88
40778 - 62 62 62 30 30 30 14 14 14 6 6 6
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 0 0 0
40781 - 0 0 0 0 0 0 0 0 0 0 0 0
40782 - 0 0 0 0 0 0 0 0 0 10 10 10
40783 - 30 30 30 78 78 78 174 135 50 224 166 10
40784 -239 182 13 246 190 14 246 190 14 246 190 14
40785 -246 190 14 246 190 14 246 190 14 246 190 14
40786 -246 190 14 246 190 14 246 190 14 246 190 14
40787 -246 190 14 246 190 14 241 196 14 139 102 15
40788 - 2 2 6 2 2 6 2 2 6 2 2 6
40789 - 78 78 78 250 250 250 253 253 253 253 253 253
40790 -253 253 253 253 253 253 253 253 253 253 253 253
40791 -253 253 253 253 253 253 253 253 253 253 253 253
40792 -253 253 253 253 253 253 253 253 253 253 253 253
40793 -250 250 250 214 214 214 198 198 198 190 150 46
40794 -219 162 10 236 178 12 234 174 13 224 166 10
40795 -216 158 10 213 154 11 213 154 11 216 158 10
40796 -226 170 11 239 182 13 246 190 14 246 190 14
40797 -246 190 14 246 190 14 242 186 14 206 162 42
40798 -101 101 101 58 58 58 30 30 30 14 14 14
40799 - 6 6 6 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 0 0 0
40801 - 0 0 0 0 0 0 0 0 0 0 0 0
40802 - 0 0 0 0 0 0 0 0 0 10 10 10
40803 - 30 30 30 74 74 74 174 135 50 216 158 10
40804 -236 178 12 246 190 14 246 190 14 246 190 14
40805 -246 190 14 246 190 14 246 190 14 246 190 14
40806 -246 190 14 246 190 14 246 190 14 246 190 14
40807 -246 190 14 246 190 14 241 196 14 226 184 13
40808 - 61 42 6 2 2 6 2 2 6 2 2 6
40809 - 22 22 22 238 238 238 253 253 253 253 253 253
40810 -253 253 253 253 253 253 253 253 253 253 253 253
40811 -253 253 253 253 253 253 253 253 253 253 253 253
40812 -253 253 253 253 253 253 253 253 253 253 253 253
40813 -253 253 253 226 226 226 187 187 187 180 133 36
40814 -216 158 10 236 178 12 239 182 13 236 178 12
40815 -230 174 11 226 170 11 226 170 11 230 174 11
40816 -236 178 12 242 186 14 246 190 14 246 190 14
40817 -246 190 14 246 190 14 246 186 14 239 182 13
40818 -206 162 42 106 106 106 66 66 66 34 34 34
40819 - 14 14 14 6 6 6 0 0 0 0 0 0
40820 - 0 0 0 0 0 0 0 0 0 0 0 0
40821 - 0 0 0 0 0 0 0 0 0 0 0 0
40822 - 0 0 0 0 0 0 0 0 0 6 6 6
40823 - 26 26 26 70 70 70 163 133 67 213 154 11
40824 -236 178 12 246 190 14 246 190 14 246 190 14
40825 -246 190 14 246 190 14 246 190 14 246 190 14
40826 -246 190 14 246 190 14 246 190 14 246 190 14
40827 -246 190 14 246 190 14 246 190 14 241 196 14
40828 -190 146 13 18 14 6 2 2 6 2 2 6
40829 - 46 46 46 246 246 246 253 253 253 253 253 253
40830 -253 253 253 253 253 253 253 253 253 253 253 253
40831 -253 253 253 253 253 253 253 253 253 253 253 253
40832 -253 253 253 253 253 253 253 253 253 253 253 253
40833 -253 253 253 221 221 221 86 86 86 156 107 11
40834 -216 158 10 236 178 12 242 186 14 246 186 14
40835 -242 186 14 239 182 13 239 182 13 242 186 14
40836 -242 186 14 246 186 14 246 190 14 246 190 14
40837 -246 190 14 246 190 14 246 190 14 246 190 14
40838 -242 186 14 225 175 15 142 122 72 66 66 66
40839 - 30 30 30 10 10 10 0 0 0 0 0 0
40840 - 0 0 0 0 0 0 0 0 0 0 0 0
40841 - 0 0 0 0 0 0 0 0 0 0 0 0
40842 - 0 0 0 0 0 0 0 0 0 6 6 6
40843 - 26 26 26 70 70 70 163 133 67 210 150 10
40844 -236 178 12 246 190 14 246 190 14 246 190 14
40845 -246 190 14 246 190 14 246 190 14 246 190 14
40846 -246 190 14 246 190 14 246 190 14 246 190 14
40847 -246 190 14 246 190 14 246 190 14 246 190 14
40848 -232 195 16 121 92 8 34 34 34 106 106 106
40849 -221 221 221 253 253 253 253 253 253 253 253 253
40850 -253 253 253 253 253 253 253 253 253 253 253 253
40851 -253 253 253 253 253 253 253 253 253 253 253 253
40852 -253 253 253 253 253 253 253 253 253 253 253 253
40853 -242 242 242 82 82 82 18 14 6 163 110 8
40854 -216 158 10 236 178 12 242 186 14 246 190 14
40855 -246 190 14 246 190 14 246 190 14 246 190 14
40856 -246 190 14 246 190 14 246 190 14 246 190 14
40857 -246 190 14 246 190 14 246 190 14 246 190 14
40858 -246 190 14 246 190 14 242 186 14 163 133 67
40859 - 46 46 46 18 18 18 6 6 6 0 0 0
40860 - 0 0 0 0 0 0 0 0 0 0 0 0
40861 - 0 0 0 0 0 0 0 0 0 0 0 0
40862 - 0 0 0 0 0 0 0 0 0 10 10 10
40863 - 30 30 30 78 78 78 163 133 67 210 150 10
40864 -236 178 12 246 186 14 246 190 14 246 190 14
40865 -246 190 14 246 190 14 246 190 14 246 190 14
40866 -246 190 14 246 190 14 246 190 14 246 190 14
40867 -246 190 14 246 190 14 246 190 14 246 190 14
40868 -241 196 14 215 174 15 190 178 144 253 253 253
40869 -253 253 253 253 253 253 253 253 253 253 253 253
40870 -253 253 253 253 253 253 253 253 253 253 253 253
40871 -253 253 253 253 253 253 253 253 253 253 253 253
40872 -253 253 253 253 253 253 253 253 253 218 218 218
40873 - 58 58 58 2 2 6 22 18 6 167 114 7
40874 -216 158 10 236 178 12 246 186 14 246 190 14
40875 -246 190 14 246 190 14 246 190 14 246 190 14
40876 -246 190 14 246 190 14 246 190 14 246 190 14
40877 -246 190 14 246 190 14 246 190 14 246 190 14
40878 -246 190 14 246 186 14 242 186 14 190 150 46
40879 - 54 54 54 22 22 22 6 6 6 0 0 0
40880 - 0 0 0 0 0 0 0 0 0 0 0 0
40881 - 0 0 0 0 0 0 0 0 0 0 0 0
40882 - 0 0 0 0 0 0 0 0 0 14 14 14
40883 - 38 38 38 86 86 86 180 133 36 213 154 11
40884 -236 178 12 246 186 14 246 190 14 246 190 14
40885 -246 190 14 246 190 14 246 190 14 246 190 14
40886 -246 190 14 246 190 14 246 190 14 246 190 14
40887 -246 190 14 246 190 14 246 190 14 246 190 14
40888 -246 190 14 232 195 16 190 146 13 214 214 214
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -253 253 253 253 253 253 253 253 253 253 253 253
40891 -253 253 253 253 253 253 253 253 253 253 253 253
40892 -253 253 253 250 250 250 170 170 170 26 26 26
40893 - 2 2 6 2 2 6 37 26 9 163 110 8
40894 -219 162 10 239 182 13 246 186 14 246 190 14
40895 -246 190 14 246 190 14 246 190 14 246 190 14
40896 -246 190 14 246 190 14 246 190 14 246 190 14
40897 -246 190 14 246 190 14 246 190 14 246 190 14
40898 -246 186 14 236 178 12 224 166 10 142 122 72
40899 - 46 46 46 18 18 18 6 6 6 0 0 0
40900 - 0 0 0 0 0 0 0 0 0 0 0 0
40901 - 0 0 0 0 0 0 0 0 0 0 0 0
40902 - 0 0 0 0 0 0 6 6 6 18 18 18
40903 - 50 50 50 109 106 95 192 133 9 224 166 10
40904 -242 186 14 246 190 14 246 190 14 246 190 14
40905 -246 190 14 246 190 14 246 190 14 246 190 14
40906 -246 190 14 246 190 14 246 190 14 246 190 14
40907 -246 190 14 246 190 14 246 190 14 246 190 14
40908 -242 186 14 226 184 13 210 162 10 142 110 46
40909 -226 226 226 253 253 253 253 253 253 253 253 253
40910 -253 253 253 253 253 253 253 253 253 253 253 253
40911 -253 253 253 253 253 253 253 253 253 253 253 253
40912 -198 198 198 66 66 66 2 2 6 2 2 6
40913 - 2 2 6 2 2 6 50 34 6 156 107 11
40914 -219 162 10 239 182 13 246 186 14 246 190 14
40915 -246 190 14 246 190 14 246 190 14 246 190 14
40916 -246 190 14 246 190 14 246 190 14 246 190 14
40917 -246 190 14 246 190 14 246 190 14 242 186 14
40918 -234 174 13 213 154 11 154 122 46 66 66 66
40919 - 30 30 30 10 10 10 0 0 0 0 0 0
40920 - 0 0 0 0 0 0 0 0 0 0 0 0
40921 - 0 0 0 0 0 0 0 0 0 0 0 0
40922 - 0 0 0 0 0 0 6 6 6 22 22 22
40923 - 58 58 58 154 121 60 206 145 10 234 174 13
40924 -242 186 14 246 186 14 246 190 14 246 190 14
40925 -246 190 14 246 190 14 246 190 14 246 190 14
40926 -246 190 14 246 190 14 246 190 14 246 190 14
40927 -246 190 14 246 190 14 246 190 14 246 190 14
40928 -246 186 14 236 178 12 210 162 10 163 110 8
40929 - 61 42 6 138 138 138 218 218 218 250 250 250
40930 -253 253 253 253 253 253 253 253 253 250 250 250
40931 -242 242 242 210 210 210 144 144 144 66 66 66
40932 - 6 6 6 2 2 6 2 2 6 2 2 6
40933 - 2 2 6 2 2 6 61 42 6 163 110 8
40934 -216 158 10 236 178 12 246 190 14 246 190 14
40935 -246 190 14 246 190 14 246 190 14 246 190 14
40936 -246 190 14 246 190 14 246 190 14 246 190 14
40937 -246 190 14 239 182 13 230 174 11 216 158 10
40938 -190 142 34 124 112 88 70 70 70 38 38 38
40939 - 18 18 18 6 6 6 0 0 0 0 0 0
40940 - 0 0 0 0 0 0 0 0 0 0 0 0
40941 - 0 0 0 0 0 0 0 0 0 0 0 0
40942 - 0 0 0 0 0 0 6 6 6 22 22 22
40943 - 62 62 62 168 124 44 206 145 10 224 166 10
40944 -236 178 12 239 182 13 242 186 14 242 186 14
40945 -246 186 14 246 190 14 246 190 14 246 190 14
40946 -246 190 14 246 190 14 246 190 14 246 190 14
40947 -246 190 14 246 190 14 246 190 14 246 190 14
40948 -246 190 14 236 178 12 216 158 10 175 118 6
40949 - 80 54 7 2 2 6 6 6 6 30 30 30
40950 - 54 54 54 62 62 62 50 50 50 38 38 38
40951 - 14 14 14 2 2 6 2 2 6 2 2 6
40952 - 2 2 6 2 2 6 2 2 6 2 2 6
40953 - 2 2 6 6 6 6 80 54 7 167 114 7
40954 -213 154 11 236 178 12 246 190 14 246 190 14
40955 -246 190 14 246 190 14 246 190 14 246 190 14
40956 -246 190 14 242 186 14 239 182 13 239 182 13
40957 -230 174 11 210 150 10 174 135 50 124 112 88
40958 - 82 82 82 54 54 54 34 34 34 18 18 18
40959 - 6 6 6 0 0 0 0 0 0 0 0 0
40960 - 0 0 0 0 0 0 0 0 0 0 0 0
40961 - 0 0 0 0 0 0 0 0 0 0 0 0
40962 - 0 0 0 0 0 0 6 6 6 18 18 18
40963 - 50 50 50 158 118 36 192 133 9 200 144 11
40964 -216 158 10 219 162 10 224 166 10 226 170 11
40965 -230 174 11 236 178 12 239 182 13 239 182 13
40966 -242 186 14 246 186 14 246 190 14 246 190 14
40967 -246 190 14 246 190 14 246 190 14 246 190 14
40968 -246 186 14 230 174 11 210 150 10 163 110 8
40969 -104 69 6 10 10 10 2 2 6 2 2 6
40970 - 2 2 6 2 2 6 2 2 6 2 2 6
40971 - 2 2 6 2 2 6 2 2 6 2 2 6
40972 - 2 2 6 2 2 6 2 2 6 2 2 6
40973 - 2 2 6 6 6 6 91 60 6 167 114 7
40974 -206 145 10 230 174 11 242 186 14 246 190 14
40975 -246 190 14 246 190 14 246 186 14 242 186 14
40976 -239 182 13 230 174 11 224 166 10 213 154 11
40977 -180 133 36 124 112 88 86 86 86 58 58 58
40978 - 38 38 38 22 22 22 10 10 10 6 6 6
40979 - 0 0 0 0 0 0 0 0 0 0 0 0
40980 - 0 0 0 0 0 0 0 0 0 0 0 0
40981 - 0 0 0 0 0 0 0 0 0 0 0 0
40982 - 0 0 0 0 0 0 0 0 0 14 14 14
40983 - 34 34 34 70 70 70 138 110 50 158 118 36
40984 -167 114 7 180 123 7 192 133 9 197 138 11
40985 -200 144 11 206 145 10 213 154 11 219 162 10
40986 -224 166 10 230 174 11 239 182 13 242 186 14
40987 -246 186 14 246 186 14 246 186 14 246 186 14
40988 -239 182 13 216 158 10 185 133 11 152 99 6
40989 -104 69 6 18 14 6 2 2 6 2 2 6
40990 - 2 2 6 2 2 6 2 2 6 2 2 6
40991 - 2 2 6 2 2 6 2 2 6 2 2 6
40992 - 2 2 6 2 2 6 2 2 6 2 2 6
40993 - 2 2 6 6 6 6 80 54 7 152 99 6
40994 -192 133 9 219 162 10 236 178 12 239 182 13
40995 -246 186 14 242 186 14 239 182 13 236 178 12
40996 -224 166 10 206 145 10 192 133 9 154 121 60
40997 - 94 94 94 62 62 62 42 42 42 22 22 22
40998 - 14 14 14 6 6 6 0 0 0 0 0 0
40999 - 0 0 0 0 0 0 0 0 0 0 0 0
41000 - 0 0 0 0 0 0 0 0 0 0 0 0
41001 - 0 0 0 0 0 0 0 0 0 0 0 0
41002 - 0 0 0 0 0 0 0 0 0 6 6 6
41003 - 18 18 18 34 34 34 58 58 58 78 78 78
41004 -101 98 89 124 112 88 142 110 46 156 107 11
41005 -163 110 8 167 114 7 175 118 6 180 123 7
41006 -185 133 11 197 138 11 210 150 10 219 162 10
41007 -226 170 11 236 178 12 236 178 12 234 174 13
41008 -219 162 10 197 138 11 163 110 8 130 83 6
41009 - 91 60 6 10 10 10 2 2 6 2 2 6
41010 - 18 18 18 38 38 38 38 38 38 38 38 38
41011 - 38 38 38 38 38 38 38 38 38 38 38 38
41012 - 38 38 38 38 38 38 26 26 26 2 2 6
41013 - 2 2 6 6 6 6 70 47 6 137 92 6
41014 -175 118 6 200 144 11 219 162 10 230 174 11
41015 -234 174 13 230 174 11 219 162 10 210 150 10
41016 -192 133 9 163 110 8 124 112 88 82 82 82
41017 - 50 50 50 30 30 30 14 14 14 6 6 6
41018 - 0 0 0 0 0 0 0 0 0 0 0 0
41019 - 0 0 0 0 0 0 0 0 0 0 0 0
41020 - 0 0 0 0 0 0 0 0 0 0 0 0
41021 - 0 0 0 0 0 0 0 0 0 0 0 0
41022 - 0 0 0 0 0 0 0 0 0 0 0 0
41023 - 6 6 6 14 14 14 22 22 22 34 34 34
41024 - 42 42 42 58 58 58 74 74 74 86 86 86
41025 -101 98 89 122 102 70 130 98 46 121 87 25
41026 -137 92 6 152 99 6 163 110 8 180 123 7
41027 -185 133 11 197 138 11 206 145 10 200 144 11
41028 -180 123 7 156 107 11 130 83 6 104 69 6
41029 - 50 34 6 54 54 54 110 110 110 101 98 89
41030 - 86 86 86 82 82 82 78 78 78 78 78 78
41031 - 78 78 78 78 78 78 78 78 78 78 78 78
41032 - 78 78 78 82 82 82 86 86 86 94 94 94
41033 -106 106 106 101 101 101 86 66 34 124 80 6
41034 -156 107 11 180 123 7 192 133 9 200 144 11
41035 -206 145 10 200 144 11 192 133 9 175 118 6
41036 -139 102 15 109 106 95 70 70 70 42 42 42
41037 - 22 22 22 10 10 10 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 0 0 0 0 0 0
41040 - 0 0 0 0 0 0 0 0 0 0 0 0
41041 - 0 0 0 0 0 0 0 0 0 0 0 0
41042 - 0 0 0 0 0 0 0 0 0 0 0 0
41043 - 0 0 0 0 0 0 6 6 6 10 10 10
41044 - 14 14 14 22 22 22 30 30 30 38 38 38
41045 - 50 50 50 62 62 62 74 74 74 90 90 90
41046 -101 98 89 112 100 78 121 87 25 124 80 6
41047 -137 92 6 152 99 6 152 99 6 152 99 6
41048 -138 86 6 124 80 6 98 70 6 86 66 30
41049 -101 98 89 82 82 82 58 58 58 46 46 46
41050 - 38 38 38 34 34 34 34 34 34 34 34 34
41051 - 34 34 34 34 34 34 34 34 34 34 34 34
41052 - 34 34 34 34 34 34 38 38 38 42 42 42
41053 - 54 54 54 82 82 82 94 86 76 91 60 6
41054 -134 86 6 156 107 11 167 114 7 175 118 6
41055 -175 118 6 167 114 7 152 99 6 121 87 25
41056 -101 98 89 62 62 62 34 34 34 18 18 18
41057 - 6 6 6 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 0 0 0 0 0 0
41060 - 0 0 0 0 0 0 0 0 0 0 0 0
41061 - 0 0 0 0 0 0 0 0 0 0 0 0
41062 - 0 0 0 0 0 0 0 0 0 0 0 0
41063 - 0 0 0 0 0 0 0 0 0 0 0 0
41064 - 0 0 0 6 6 6 6 6 6 10 10 10
41065 - 18 18 18 22 22 22 30 30 30 42 42 42
41066 - 50 50 50 66 66 66 86 86 86 101 98 89
41067 -106 86 58 98 70 6 104 69 6 104 69 6
41068 -104 69 6 91 60 6 82 62 34 90 90 90
41069 - 62 62 62 38 38 38 22 22 22 14 14 14
41070 - 10 10 10 10 10 10 10 10 10 10 10 10
41071 - 10 10 10 10 10 10 6 6 6 10 10 10
41072 - 10 10 10 10 10 10 10 10 10 14 14 14
41073 - 22 22 22 42 42 42 70 70 70 89 81 66
41074 - 80 54 7 104 69 6 124 80 6 137 92 6
41075 -134 86 6 116 81 8 100 82 52 86 86 86
41076 - 58 58 58 30 30 30 14 14 14 6 6 6
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 0 0 0 0 0 0
41080 - 0 0 0 0 0 0 0 0 0 0 0 0
41081 - 0 0 0 0 0 0 0 0 0 0 0 0
41082 - 0 0 0 0 0 0 0 0 0 0 0 0
41083 - 0 0 0 0 0 0 0 0 0 0 0 0
41084 - 0 0 0 0 0 0 0 0 0 0 0 0
41085 - 0 0 0 6 6 6 10 10 10 14 14 14
41086 - 18 18 18 26 26 26 38 38 38 54 54 54
41087 - 70 70 70 86 86 86 94 86 76 89 81 66
41088 - 89 81 66 86 86 86 74 74 74 50 50 50
41089 - 30 30 30 14 14 14 6 6 6 0 0 0
41090 - 0 0 0 0 0 0 0 0 0 0 0 0
41091 - 0 0 0 0 0 0 0 0 0 0 0 0
41092 - 0 0 0 0 0 0 0 0 0 0 0 0
41093 - 6 6 6 18 18 18 34 34 34 58 58 58
41094 - 82 82 82 89 81 66 89 81 66 89 81 66
41095 - 94 86 66 94 86 76 74 74 74 50 50 50
41096 - 26 26 26 14 14 14 6 6 6 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 0 0 0
41100 - 0 0 0 0 0 0 0 0 0 0 0 0
41101 - 0 0 0 0 0 0 0 0 0 0 0 0
41102 - 0 0 0 0 0 0 0 0 0 0 0 0
41103 - 0 0 0 0 0 0 0 0 0 0 0 0
41104 - 0 0 0 0 0 0 0 0 0 0 0 0
41105 - 0 0 0 0 0 0 0 0 0 0 0 0
41106 - 6 6 6 6 6 6 14 14 14 18 18 18
41107 - 30 30 30 38 38 38 46 46 46 54 54 54
41108 - 50 50 50 42 42 42 30 30 30 18 18 18
41109 - 10 10 10 0 0 0 0 0 0 0 0 0
41110 - 0 0 0 0 0 0 0 0 0 0 0 0
41111 - 0 0 0 0 0 0 0 0 0 0 0 0
41112 - 0 0 0 0 0 0 0 0 0 0 0 0
41113 - 0 0 0 6 6 6 14 14 14 26 26 26
41114 - 38 38 38 50 50 50 58 58 58 58 58 58
41115 - 54 54 54 42 42 42 30 30 30 18 18 18
41116 - 10 10 10 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 0 0 0
41120 - 0 0 0 0 0 0 0 0 0 0 0 0
41121 - 0 0 0 0 0 0 0 0 0 0 0 0
41122 - 0 0 0 0 0 0 0 0 0 0 0 0
41123 - 0 0 0 0 0 0 0 0 0 0 0 0
41124 - 0 0 0 0 0 0 0 0 0 0 0 0
41125 - 0 0 0 0 0 0 0 0 0 0 0 0
41126 - 0 0 0 0 0 0 0 0 0 6 6 6
41127 - 6 6 6 10 10 10 14 14 14 18 18 18
41128 - 18 18 18 14 14 14 10 10 10 6 6 6
41129 - 0 0 0 0 0 0 0 0 0 0 0 0
41130 - 0 0 0 0 0 0 0 0 0 0 0 0
41131 - 0 0 0 0 0 0 0 0 0 0 0 0
41132 - 0 0 0 0 0 0 0 0 0 0 0 0
41133 - 0 0 0 0 0 0 0 0 0 6 6 6
41134 - 14 14 14 18 18 18 22 22 22 22 22 22
41135 - 18 18 18 14 14 14 10 10 10 6 6 6
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 - 0 0 0 0 0 0 0 0 0 0 0 0
41141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41154 +4 4 4 4 4 4
41155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41168 +4 4 4 4 4 4
41169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41182 +4 4 4 4 4 4
41183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41196 +4 4 4 4 4 4
41197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41210 +4 4 4 4 4 4
41211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41224 +4 4 4 4 4 4
41225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41229 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41230 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41234 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41235 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4
41239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41243 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41244 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41245 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41248 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41249 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41250 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41251 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4
41253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41257 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41258 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41259 +0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
41263 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41264 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41265 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41266 +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 5 5 5 5 5 5 2 2 2 0 0 0
41271 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41272 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41273 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
41276 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41277 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41278 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41279 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41280 +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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41285 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41286 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41287 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41288 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41289 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41290 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41291 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41292 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41293 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41294 +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 5 5 5
41298 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41299 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41300 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41301 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41302 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41303 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41304 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41305 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41306 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41307 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41308 +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 5 5 5 3 3 3
41312 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41313 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41314 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41315 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41316 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41317 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41318 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41319 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41320 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41321 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41322 +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 2 2 2 0 0 0 4 0 0
41326 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41327 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41328 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41329 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41330 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41331 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41332 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41333 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41334 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41335 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41336 +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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41340 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41341 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41342 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41343 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41344 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41345 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41346 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41347 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41348 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41349 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41354 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41355 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41356 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41357 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41358 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41359 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41360 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41361 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41362 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41363 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41364 +4 4 4 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41367 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41368 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41369 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41370 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41371 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41372 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41373 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41374 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41375 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41376 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41377 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41378 +4 4 4 4 4 4
41379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41381 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41382 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41383 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41384 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41385 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41386 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41387 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41388 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41389 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41390 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41391 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41392 +0 0 0 4 4 4
41393 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41394 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41395 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41396 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41397 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41398 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41399 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41400 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41401 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41402 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41403 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41404 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41405 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41406 +2 0 0 0 0 0
41407 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41408 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41409 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41410 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41411 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41412 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41413 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41414 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41415 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41416 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41417 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41418 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41419 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41420 +37 38 37 0 0 0
41421 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41422 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41423 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41424 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41425 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41426 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41427 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41428 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41429 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41430 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41431 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41432 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41433 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41434 +85 115 134 4 0 0
41435 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41436 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41437 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41438 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41439 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41440 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41441 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41442 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41443 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41444 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41445 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41446 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41447 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41448 +60 73 81 4 0 0
41449 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41450 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41451 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41452 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41453 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41454 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41455 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41456 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41457 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41458 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41459 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41460 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41461 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41462 +16 19 21 4 0 0
41463 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41464 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41465 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41466 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41467 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41468 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41469 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41470 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41471 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41472 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41473 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41474 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41475 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41476 +4 0 0 4 3 3
41477 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41478 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41479 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41481 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41482 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41483 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41484 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41485 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41486 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41487 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41488 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41489 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41490 +3 2 2 4 4 4
41491 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41492 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41493 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41494 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41495 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41496 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41497 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41498 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41499 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41500 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41501 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41502 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41503 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41504 +4 4 4 4 4 4
41505 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41506 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41507 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41508 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41509 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41510 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41511 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41512 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41513 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41514 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41515 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41516 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41517 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41518 +4 4 4 4 4 4
41519 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41520 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41521 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41522 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41523 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41524 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41525 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41526 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41527 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41528 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41529 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41530 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41531 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41532 +5 5 5 5 5 5
41533 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41534 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41535 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41536 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41537 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41538 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41539 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41540 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41541 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41542 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41543 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41544 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41545 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41546 +5 5 5 4 4 4
41547 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41548 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41549 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41550 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41551 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41552 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41553 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41554 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41555 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41556 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41557 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41558 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41559 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41560 +4 4 4 4 4 4
41561 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41562 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41563 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41564 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41565 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41566 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41567 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41568 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41569 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41570 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41571 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41572 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41573 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41574 +4 4 4 4 4 4
41575 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41576 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41577 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41578 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41579 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41580 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41581 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41582 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41583 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41584 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41585 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41587 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41588 +4 4 4 4 4 4
41589 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41590 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41591 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41592 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41593 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41594 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41595 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41596 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41597 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41598 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41599 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41601 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41602 +4 4 4 4 4 4
41603 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41604 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41605 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41606 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41607 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41608 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41609 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41610 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41611 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41612 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41613 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41615 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41616 +4 4 4 4 4 4
41617 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41618 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41619 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41620 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41621 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41622 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41623 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41624 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41625 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41626 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41627 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41629 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41630 +4 4 4 4 4 4
41631 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41632 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41633 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41634 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41635 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41636 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41637 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41638 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41639 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41640 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41641 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41643 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41644 +4 4 4 4 4 4
41645 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41646 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41647 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41648 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41649 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41650 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41651 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41652 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41653 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41654 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41655 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41657 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41658 +4 4 4 4 4 4
41659 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41660 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41661 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41662 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41663 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41664 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41665 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41666 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41667 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41668 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41669 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41671 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41672 +4 4 4 4 4 4
41673 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41674 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41675 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41676 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41677 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41678 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41679 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41680 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41681 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41682 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41683 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41686 +4 4 4 4 4 4
41687 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41688 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41689 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41690 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41691 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41692 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41693 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41694 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41695 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41696 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41697 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41700 +4 4 4 4 4 4
41701 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41702 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41703 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41704 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41705 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41706 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41707 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41708 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41709 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41710 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41711 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41714 +4 4 4 4 4 4
41715 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41716 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41717 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41718 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41719 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41720 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41721 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41722 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41723 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41724 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41725 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41728 +4 4 4 4 4 4
41729 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41730 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41731 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41732 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41733 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41734 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41735 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41736 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41737 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41738 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41739 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41742 +4 4 4 4 4 4
41743 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41744 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41745 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41746 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41747 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41748 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41749 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41750 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41751 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41752 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41753 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41756 +4 4 4 4 4 4
41757 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41758 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41759 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41760 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41761 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41762 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41763 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41764 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41765 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41766 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41767 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41770 +4 4 4 4 4 4
41771 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41772 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41773 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41774 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41775 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41776 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41777 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41778 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41779 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41780 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41781 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41784 +4 4 4 4 4 4
41785 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41786 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41787 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41788 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41789 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41790 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41791 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41792 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41793 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41794 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41795 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41798 +4 4 4 4 4 4
41799 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41800 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41801 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41802 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41803 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41804 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41805 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41806 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41807 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41808 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41809 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41810 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41812 +4 4 4 4 4 4
41813 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41814 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41815 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41816 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41817 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41818 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41819 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41820 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41821 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41822 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41823 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41824 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41825 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41826 +4 4 4 4 4 4
41827 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41828 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41829 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41830 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41831 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41832 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41833 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41834 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41835 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41836 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41837 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41838 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41839 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41840 +4 4 4 4 4 4
41841 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41842 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41843 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41844 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41845 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41846 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41847 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41848 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41849 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41850 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41851 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41852 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41853 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41854 +4 4 4 4 4 4
41855 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41856 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41857 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41858 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41859 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41860 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41861 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41862 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41863 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41864 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41865 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41866 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41867 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41868 +4 4 4 4 4 4
41869 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41870 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41871 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41872 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41873 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41874 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41875 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41876 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41877 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41878 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41879 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41880 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41881 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41882 +4 4 4 4 4 4
41883 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41884 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41885 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41887 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41888 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41889 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41890 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41891 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41892 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41893 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41894 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41895 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41896 +4 4 4 4 4 4
41897 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41898 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41899 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41900 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41901 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41902 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41903 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41904 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41905 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41906 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41907 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41909 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41910 +4 4 4 4 4 4
41911 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41912 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41913 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41914 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41915 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41916 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41917 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41918 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41919 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41920 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41921 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41924 +4 4 4 4 4 4
41925 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41926 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41927 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41928 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41929 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41930 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41931 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41932 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41933 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41934 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41935 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41938 +4 4 4 4 4 4
41939 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41940 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41941 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41942 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41943 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41944 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41945 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41946 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41947 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41948 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41949 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41952 +4 4 4 4 4 4
41953 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41954 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41955 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41956 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41957 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41958 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41959 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41960 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41961 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41962 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41966 +4 4 4 4 4 4
41967 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41968 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41969 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41970 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41971 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41972 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41973 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41974 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41975 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41976 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41980 +4 4 4 4 4 4
41981 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
41982 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
41983 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
41984 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
41985 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
41986 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
41987 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
41988 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
41989 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
41990 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41994 +4 4 4 4 4 4
41995 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
41996 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
41997 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
41998 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
41999 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42000 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42001 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42002 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42003 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42004 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42008 +4 4 4 4 4 4
42009 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42010 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42011 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42012 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42013 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42014 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42015 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42016 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42017 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42022 +4 4 4 4 4 4
42023 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42024 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42025 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42026 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42027 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42028 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42029 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42030 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42031 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42033 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42034 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42035 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42036 +4 4 4 4 4 4
42037 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42038 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42039 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42040 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42041 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42042 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42043 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42044 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42045 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42046 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42047 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42048 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42049 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42050 +4 4 4 4 4 4
42051 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42052 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42053 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42054 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42055 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42056 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42057 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42058 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42059 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42060 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42061 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42062 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42063 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42064 +4 4 4 4 4 4
42065 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42066 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42067 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42068 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42069 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42070 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42071 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42072 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42073 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42074 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42075 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42076 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42077 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42078 +4 4 4 4 4 4
42079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42080 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42081 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42082 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42083 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42084 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42085 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42086 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42087 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42088 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42089 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42090 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42091 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42092 +4 4 4 4 4 4
42093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42094 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42095 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42096 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42097 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42098 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42099 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42100 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42101 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42102 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42103 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42104 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42105 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42106 +4 4 4 4 4 4
42107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42108 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42109 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42110 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42111 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42112 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42113 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42114 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42115 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42116 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42117 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42118 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42119 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42120 +4 4 4 4 4 4
42121 +4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42124 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42125 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42126 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42127 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42128 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42129 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42130 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42131 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42132 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42133 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42134 +4 4 4 4 4 4
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 5 5 5
42138 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42139 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42140 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42141 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42142 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42143 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42144 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42145 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42146 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42147 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42148 +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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42153 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42154 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42155 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42156 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42157 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42158 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42159 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42160 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42162 +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 5 5 5 4 3 3 5 5 5 6 6 6
42167 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42168 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42169 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42170 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42171 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42172 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42173 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42174 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42176 +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 5 5 5 4 3 3 5 5 5
42181 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42182 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42183 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42184 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42185 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42186 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42187 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42188 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42190 +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 5 5 5
42195 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42196 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42197 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42199 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42200 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42201 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42204 +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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42210 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42211 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42214 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42215 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42218 +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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42224 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42225 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42232 +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 4 4 4 5 5 5 4 3 3 6 6 6
42238 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42246 +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 4 4 4 4 4 4 5 5 5 4 3 3
42252 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
42261 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42262 index 38fcfff..0072dcd 100644
42263 --- a/drivers/video/udlfb.c
42264 +++ b/drivers/video/udlfb.c
42265 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42266 dlfb_urb_completion(urb);
42267
42268 error:
42269 - atomic_add(bytes_sent, &dev->bytes_sent);
42270 - atomic_add(bytes_identical, &dev->bytes_identical);
42271 - atomic_add(width*height*2, &dev->bytes_rendered);
42272 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42273 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42274 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42275 end_cycles = get_cycles();
42276 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42277 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42278 >> 10)), /* Kcycles */
42279 &dev->cpu_kcycles_used);
42280
42281 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42282 dlfb_urb_completion(urb);
42283
42284 error:
42285 - atomic_add(bytes_sent, &dev->bytes_sent);
42286 - atomic_add(bytes_identical, &dev->bytes_identical);
42287 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42288 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42289 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42290 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42291 end_cycles = get_cycles();
42292 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42293 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42294 >> 10)), /* Kcycles */
42295 &dev->cpu_kcycles_used);
42296 }
42297 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42298 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42299 struct dlfb_data *dev = fb_info->par;
42300 return snprintf(buf, PAGE_SIZE, "%u\n",
42301 - atomic_read(&dev->bytes_rendered));
42302 + atomic_read_unchecked(&dev->bytes_rendered));
42303 }
42304
42305 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42306 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42307 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42308 struct dlfb_data *dev = fb_info->par;
42309 return snprintf(buf, PAGE_SIZE, "%u\n",
42310 - atomic_read(&dev->bytes_identical));
42311 + atomic_read_unchecked(&dev->bytes_identical));
42312 }
42313
42314 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42315 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42316 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42317 struct dlfb_data *dev = fb_info->par;
42318 return snprintf(buf, PAGE_SIZE, "%u\n",
42319 - atomic_read(&dev->bytes_sent));
42320 + atomic_read_unchecked(&dev->bytes_sent));
42321 }
42322
42323 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42324 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42325 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42326 struct dlfb_data *dev = fb_info->par;
42327 return snprintf(buf, PAGE_SIZE, "%u\n",
42328 - atomic_read(&dev->cpu_kcycles_used));
42329 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42330 }
42331
42332 static ssize_t edid_show(
42333 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42334 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42335 struct dlfb_data *dev = fb_info->par;
42336
42337 - atomic_set(&dev->bytes_rendered, 0);
42338 - atomic_set(&dev->bytes_identical, 0);
42339 - atomic_set(&dev->bytes_sent, 0);
42340 - atomic_set(&dev->cpu_kcycles_used, 0);
42341 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42342 + atomic_set_unchecked(&dev->bytes_identical, 0);
42343 + atomic_set_unchecked(&dev->bytes_sent, 0);
42344 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42345
42346 return count;
42347 }
42348 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42349 index b0e2a42..e2df3ad 100644
42350 --- a/drivers/video/uvesafb.c
42351 +++ b/drivers/video/uvesafb.c
42352 @@ -19,6 +19,7 @@
42353 #include <linux/io.h>
42354 #include <linux/mutex.h>
42355 #include <linux/slab.h>
42356 +#include <linux/moduleloader.h>
42357 #include <video/edid.h>
42358 #include <video/uvesafb.h>
42359 #ifdef CONFIG_X86
42360 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42361 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42362 par->pmi_setpal = par->ypan = 0;
42363 } else {
42364 +
42365 +#ifdef CONFIG_PAX_KERNEXEC
42366 +#ifdef CONFIG_MODULES
42367 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42368 +#endif
42369 + if (!par->pmi_code) {
42370 + par->pmi_setpal = par->ypan = 0;
42371 + return 0;
42372 + }
42373 +#endif
42374 +
42375 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42376 + task->t.regs.edi);
42377 +
42378 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42379 + pax_open_kernel();
42380 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42381 + pax_close_kernel();
42382 +
42383 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42384 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42385 +#else
42386 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42387 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42388 +#endif
42389 +
42390 printk(KERN_INFO "uvesafb: protected mode interface info at "
42391 "%04x:%04x\n",
42392 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42393 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42394 par->ypan = ypan;
42395
42396 if (par->pmi_setpal || par->ypan) {
42397 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42398 if (__supported_pte_mask & _PAGE_NX) {
42399 par->pmi_setpal = par->ypan = 0;
42400 printk(KERN_WARNING "uvesafb: NX protection is actively."
42401 "We have better not to use the PMI.\n");
42402 - } else {
42403 + } else
42404 +#endif
42405 uvesafb_vbe_getpmi(task, par);
42406 - }
42407 }
42408 #else
42409 /* The protected mode interface is not available on non-x86. */
42410 @@ -1836,6 +1860,11 @@ out:
42411 if (par->vbe_modes)
42412 kfree(par->vbe_modes);
42413
42414 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42415 + if (par->pmi_code)
42416 + module_free_exec(NULL, par->pmi_code);
42417 +#endif
42418 +
42419 framebuffer_release(info);
42420 return err;
42421 }
42422 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42423 kfree(par->vbe_state_orig);
42424 if (par->vbe_state_saved)
42425 kfree(par->vbe_state_saved);
42426 +
42427 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42428 + if (par->pmi_code)
42429 + module_free_exec(NULL, par->pmi_code);
42430 +#endif
42431 +
42432 }
42433
42434 framebuffer_release(info);
42435 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42436 index 501b340..86bd4cf 100644
42437 --- a/drivers/video/vesafb.c
42438 +++ b/drivers/video/vesafb.c
42439 @@ -9,6 +9,7 @@
42440 */
42441
42442 #include <linux/module.h>
42443 +#include <linux/moduleloader.h>
42444 #include <linux/kernel.h>
42445 #include <linux/errno.h>
42446 #include <linux/string.h>
42447 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42448 static int vram_total __initdata; /* Set total amount of memory */
42449 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42450 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42451 -static void (*pmi_start)(void) __read_mostly;
42452 -static void (*pmi_pal) (void) __read_mostly;
42453 +static void (*pmi_start)(void) __read_only;
42454 +static void (*pmi_pal) (void) __read_only;
42455 static int depth __read_mostly;
42456 static int vga_compat __read_mostly;
42457 /* --------------------------------------------------------------------- */
42458 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42459 unsigned int size_vmode;
42460 unsigned int size_remap;
42461 unsigned int size_total;
42462 + void *pmi_code = NULL;
42463
42464 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42465 return -ENODEV;
42466 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42467 size_remap = size_total;
42468 vesafb_fix.smem_len = size_remap;
42469
42470 -#ifndef __i386__
42471 - screen_info.vesapm_seg = 0;
42472 -#endif
42473 -
42474 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42475 printk(KERN_WARNING
42476 "vesafb: cannot reserve video memory at 0x%lx\n",
42477 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42478 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42479 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42480
42481 +#ifdef __i386__
42482 +
42483 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42484 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42485 + if (!pmi_code)
42486 +#elif !defined(CONFIG_PAX_KERNEXEC)
42487 + if (0)
42488 +#endif
42489 +
42490 +#endif
42491 + screen_info.vesapm_seg = 0;
42492 +
42493 if (screen_info.vesapm_seg) {
42494 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42495 - screen_info.vesapm_seg,screen_info.vesapm_off);
42496 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42497 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42498 }
42499
42500 if (screen_info.vesapm_seg < 0xc000)
42501 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42502
42503 if (ypan || pmi_setpal) {
42504 unsigned short *pmi_base;
42505 +
42506 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42507 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42508 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42509 +
42510 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42511 + pax_open_kernel();
42512 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42513 +#else
42514 + pmi_code = pmi_base;
42515 +#endif
42516 +
42517 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42518 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42519 +
42520 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42521 + pmi_start = ktva_ktla(pmi_start);
42522 + pmi_pal = ktva_ktla(pmi_pal);
42523 + pax_close_kernel();
42524 +#endif
42525 +
42526 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42527 if (pmi_base[3]) {
42528 printk(KERN_INFO "vesafb: pmi: ports = ");
42529 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42530 info->node, info->fix.id);
42531 return 0;
42532 err:
42533 +
42534 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42535 + module_free_exec(NULL, pmi_code);
42536 +#endif
42537 +
42538 if (info->screen_base)
42539 iounmap(info->screen_base);
42540 framebuffer_release(info);
42541 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42542 index 88714ae..16c2e11 100644
42543 --- a/drivers/video/via/via_clock.h
42544 +++ b/drivers/video/via/via_clock.h
42545 @@ -56,7 +56,7 @@ struct via_clock {
42546
42547 void (*set_engine_pll_state)(u8 state);
42548 void (*set_engine_pll)(struct via_pll_config config);
42549 -};
42550 +} __no_const;
42551
42552
42553 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42554 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42555 index 453db0c..604973e 100644
42556 --- a/drivers/virtio/virtio_mmio.c
42557 +++ b/drivers/virtio/virtio_mmio.c
42558 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42559
42560 resources[0].end = memparse(device, &str) - 1;
42561
42562 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42563 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42564 &base, &resources[1].start, &consumed,
42565 &vm_cmdline_id, &consumed);
42566
42567 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42568 index e56c934..fc22f4b 100644
42569 --- a/drivers/xen/xen-pciback/conf_space.h
42570 +++ b/drivers/xen/xen-pciback/conf_space.h
42571 @@ -44,15 +44,15 @@ struct config_field {
42572 struct {
42573 conf_dword_write write;
42574 conf_dword_read read;
42575 - } dw;
42576 + } __no_const dw;
42577 struct {
42578 conf_word_write write;
42579 conf_word_read read;
42580 - } w;
42581 + } __no_const w;
42582 struct {
42583 conf_byte_write write;
42584 conf_byte_read read;
42585 - } b;
42586 + } __no_const b;
42587 } u;
42588 struct list_head list;
42589 };
42590 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42591 index cbf9dbb..35c3af7 100644
42592 --- a/fs/9p/vfs_inode.c
42593 +++ b/fs/9p/vfs_inode.c
42594 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42595 void
42596 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42597 {
42598 - char *s = nd_get_link(nd);
42599 + const char *s = nd_get_link(nd);
42600
42601 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42602 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42603 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42604 index 0225742..1cd4732 100644
42605 --- a/fs/Kconfig.binfmt
42606 +++ b/fs/Kconfig.binfmt
42607 @@ -89,7 +89,7 @@ config HAVE_AOUT
42608
42609 config BINFMT_AOUT
42610 tristate "Kernel support for a.out and ECOFF binaries"
42611 - depends on HAVE_AOUT
42612 + depends on HAVE_AOUT && BROKEN
42613 ---help---
42614 A.out (Assembler.OUTput) is a set of formats for libraries and
42615 executables used in the earliest versions of UNIX. Linux used
42616 diff --git a/fs/aio.c b/fs/aio.c
42617 index 71f613c..9d01f1f 100644
42618 --- a/fs/aio.c
42619 +++ b/fs/aio.c
42620 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42621 size += sizeof(struct io_event) * nr_events;
42622 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42623
42624 - if (nr_pages < 0)
42625 + if (nr_pages <= 0)
42626 return -EINVAL;
42627
42628 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42629 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42630 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42631 {
42632 ssize_t ret;
42633 + struct iovec iovstack;
42634
42635 #ifdef CONFIG_COMPAT
42636 if (compat)
42637 ret = compat_rw_copy_check_uvector(type,
42638 (struct compat_iovec __user *)kiocb->ki_buf,
42639 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42640 + kiocb->ki_nbytes, 1, &iovstack,
42641 &kiocb->ki_iovec);
42642 else
42643 #endif
42644 ret = rw_copy_check_uvector(type,
42645 (struct iovec __user *)kiocb->ki_buf,
42646 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42647 + kiocb->ki_nbytes, 1, &iovstack,
42648 &kiocb->ki_iovec);
42649 if (ret < 0)
42650 goto out;
42651 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42652 if (ret < 0)
42653 goto out;
42654
42655 + if (kiocb->ki_iovec == &iovstack) {
42656 + kiocb->ki_inline_vec = iovstack;
42657 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42658 + }
42659 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42660 kiocb->ki_cur_seg = 0;
42661 /* ki_nbytes/left now reflect bytes instead of segs */
42662 diff --git a/fs/attr.c b/fs/attr.c
42663 index 29e38a1..2bc037b 100644
42664 --- a/fs/attr.c
42665 +++ b/fs/attr.c
42666 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42667 unsigned long limit;
42668
42669 limit = rlimit(RLIMIT_FSIZE);
42670 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42671 if (limit != RLIM_INFINITY && offset > limit)
42672 goto out_sig;
42673 if (offset > inode->i_sb->s_maxbytes)
42674 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42675 index da8876d..4456166 100644
42676 --- a/fs/autofs4/waitq.c
42677 +++ b/fs/autofs4/waitq.c
42678 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42679 {
42680 unsigned long sigpipe, flags;
42681 mm_segment_t fs;
42682 - const char *data = (const char *)addr;
42683 + const char __user *data = (const char __force_user *)addr;
42684 ssize_t wr = 0;
42685
42686 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42687 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42688 return 1;
42689 }
42690
42691 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42692 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42693 +#endif
42694 +
42695 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42696 enum autofs_notify notify)
42697 {
42698 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42699
42700 /* If this is a direct mount request create a dummy name */
42701 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42702 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42703 + /* this name does get written to userland via autofs4_write() */
42704 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42705 +#else
42706 qstr.len = sprintf(name, "%p", dentry);
42707 +#endif
42708 else {
42709 qstr.len = autofs4_getpath(sbi, dentry, &name);
42710 if (!qstr.len) {
42711 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42712 index cf7f3c6..f61080d 100644
42713 --- a/fs/befs/linuxvfs.c
42714 +++ b/fs/befs/linuxvfs.c
42715 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42716 {
42717 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42718 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42719 - char *link = nd_get_link(nd);
42720 + const char *link = nd_get_link(nd);
42721 if (!IS_ERR(link))
42722 kfree(link);
42723 }
42724 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42725 index d146e18..12d1bd1 100644
42726 --- a/fs/binfmt_aout.c
42727 +++ b/fs/binfmt_aout.c
42728 @@ -16,6 +16,7 @@
42729 #include <linux/string.h>
42730 #include <linux/fs.h>
42731 #include <linux/file.h>
42732 +#include <linux/security.h>
42733 #include <linux/stat.h>
42734 #include <linux/fcntl.h>
42735 #include <linux/ptrace.h>
42736 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42737 #endif
42738 # define START_STACK(u) ((void __user *)u.start_stack)
42739
42740 + memset(&dump, 0, sizeof(dump));
42741 +
42742 fs = get_fs();
42743 set_fs(KERNEL_DS);
42744 has_dumped = 1;
42745 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42746
42747 /* If the size of the dump file exceeds the rlimit, then see what would happen
42748 if we wrote the stack, but not the data area. */
42749 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42750 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42751 dump.u_dsize = 0;
42752
42753 /* Make sure we have enough room to write the stack and data areas. */
42754 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42755 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42756 dump.u_ssize = 0;
42757
42758 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42759 rlim = rlimit(RLIMIT_DATA);
42760 if (rlim >= RLIM_INFINITY)
42761 rlim = ~0;
42762 +
42763 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42764 if (ex.a_data + ex.a_bss > rlim)
42765 return -ENOMEM;
42766
42767 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42768
42769 install_exec_creds(bprm);
42770
42771 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42772 + current->mm->pax_flags = 0UL;
42773 +#endif
42774 +
42775 +#ifdef CONFIG_PAX_PAGEEXEC
42776 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42777 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42778 +
42779 +#ifdef CONFIG_PAX_EMUTRAMP
42780 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42781 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42782 +#endif
42783 +
42784 +#ifdef CONFIG_PAX_MPROTECT
42785 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42786 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42787 +#endif
42788 +
42789 + }
42790 +#endif
42791 +
42792 if (N_MAGIC(ex) == OMAGIC) {
42793 unsigned long text_addr, map_size;
42794 loff_t pos;
42795 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42796 }
42797
42798 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42799 - PROT_READ | PROT_WRITE | PROT_EXEC,
42800 + PROT_READ | PROT_WRITE,
42801 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42802 fd_offset + ex.a_text);
42803 if (error != N_DATADDR(ex)) {
42804 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42805 index 0225fdd..08bda99 100644
42806 --- a/fs/binfmt_elf.c
42807 +++ b/fs/binfmt_elf.c
42808 @@ -32,6 +32,7 @@
42809 #include <linux/elf.h>
42810 #include <linux/utsname.h>
42811 #include <linux/coredump.h>
42812 +#include <linux/xattr.h>
42813 #include <asm/uaccess.h>
42814 #include <asm/param.h>
42815 #include <asm/page.h>
42816 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42817 #define elf_core_dump NULL
42818 #endif
42819
42820 +#ifdef CONFIG_PAX_MPROTECT
42821 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42822 +#endif
42823 +
42824 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42825 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42826 #else
42827 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42828 .load_binary = load_elf_binary,
42829 .load_shlib = load_elf_library,
42830 .core_dump = elf_core_dump,
42831 +
42832 +#ifdef CONFIG_PAX_MPROTECT
42833 + .handle_mprotect= elf_handle_mprotect,
42834 +#endif
42835 +
42836 .min_coredump = ELF_EXEC_PAGESIZE,
42837 };
42838
42839 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42840
42841 static int set_brk(unsigned long start, unsigned long end)
42842 {
42843 + unsigned long e = end;
42844 +
42845 start = ELF_PAGEALIGN(start);
42846 end = ELF_PAGEALIGN(end);
42847 if (end > start) {
42848 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42849 if (BAD_ADDR(addr))
42850 return addr;
42851 }
42852 - current->mm->start_brk = current->mm->brk = end;
42853 + current->mm->start_brk = current->mm->brk = e;
42854 return 0;
42855 }
42856
42857 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42858 elf_addr_t __user *u_rand_bytes;
42859 const char *k_platform = ELF_PLATFORM;
42860 const char *k_base_platform = ELF_BASE_PLATFORM;
42861 - unsigned char k_rand_bytes[16];
42862 + u32 k_rand_bytes[4];
42863 int items;
42864 elf_addr_t *elf_info;
42865 int ei_index = 0;
42866 const struct cred *cred = current_cred();
42867 struct vm_area_struct *vma;
42868 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42869
42870 /*
42871 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42872 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42873 * Generate 16 random bytes for userspace PRNG seeding.
42874 */
42875 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42876 - u_rand_bytes = (elf_addr_t __user *)
42877 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42878 + srandom32(k_rand_bytes[0] ^ random32());
42879 + srandom32(k_rand_bytes[1] ^ random32());
42880 + srandom32(k_rand_bytes[2] ^ random32());
42881 + srandom32(k_rand_bytes[3] ^ random32());
42882 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42883 + u_rand_bytes = (elf_addr_t __user *) p;
42884 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42885 return -EFAULT;
42886
42887 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42888 return -EFAULT;
42889 current->mm->env_end = p;
42890
42891 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42892 +
42893 /* Put the elf_info on the stack in the right place. */
42894 sp = (elf_addr_t __user *)envp + 1;
42895 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42896 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42897 return -EFAULT;
42898 return 0;
42899 }
42900 @@ -373,15 +392,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
42901 an ELF header */
42902
42903 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42904 - struct file *interpreter, unsigned long *interp_map_addr,
42905 - unsigned long no_base)
42906 + struct file *interpreter, unsigned long no_base)
42907 {
42908 struct elf_phdr *elf_phdata;
42909 struct elf_phdr *eppnt;
42910 - unsigned long load_addr = 0;
42911 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42912 int load_addr_set = 0;
42913 unsigned long last_bss = 0, elf_bss = 0;
42914 - unsigned long error = ~0UL;
42915 + unsigned long error = -EINVAL;
42916 unsigned long total_size;
42917 int retval, i, size;
42918
42919 @@ -427,6 +445,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42920 goto out_close;
42921 }
42922
42923 +#ifdef CONFIG_PAX_SEGMEXEC
42924 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42925 + pax_task_size = SEGMEXEC_TASK_SIZE;
42926 +#endif
42927 +
42928 eppnt = elf_phdata;
42929 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42930 if (eppnt->p_type == PT_LOAD) {
42931 @@ -450,8 +473,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42932 map_addr = elf_map(interpreter, load_addr + vaddr,
42933 eppnt, elf_prot, elf_type, total_size);
42934 total_size = 0;
42935 - if (!*interp_map_addr)
42936 - *interp_map_addr = map_addr;
42937 error = map_addr;
42938 if (BAD_ADDR(map_addr))
42939 goto out_close;
42940 @@ -470,8 +491,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42941 k = load_addr + eppnt->p_vaddr;
42942 if (BAD_ADDR(k) ||
42943 eppnt->p_filesz > eppnt->p_memsz ||
42944 - eppnt->p_memsz > TASK_SIZE ||
42945 - TASK_SIZE - eppnt->p_memsz < k) {
42946 + eppnt->p_memsz > pax_task_size ||
42947 + pax_task_size - eppnt->p_memsz < k) {
42948 error = -ENOMEM;
42949 goto out_close;
42950 }
42951 @@ -523,6 +544,311 @@ out:
42952 return error;
42953 }
42954
42955 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42956 +#ifdef CONFIG_PAX_SOFTMODE
42957 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42958 +{
42959 + unsigned long pax_flags = 0UL;
42960 +
42961 +#ifdef CONFIG_PAX_PAGEEXEC
42962 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42963 + pax_flags |= MF_PAX_PAGEEXEC;
42964 +#endif
42965 +
42966 +#ifdef CONFIG_PAX_SEGMEXEC
42967 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42968 + pax_flags |= MF_PAX_SEGMEXEC;
42969 +#endif
42970 +
42971 +#ifdef CONFIG_PAX_EMUTRAMP
42972 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42973 + pax_flags |= MF_PAX_EMUTRAMP;
42974 +#endif
42975 +
42976 +#ifdef CONFIG_PAX_MPROTECT
42977 + if (elf_phdata->p_flags & PF_MPROTECT)
42978 + pax_flags |= MF_PAX_MPROTECT;
42979 +#endif
42980 +
42981 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42982 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42983 + pax_flags |= MF_PAX_RANDMMAP;
42984 +#endif
42985 +
42986 + return pax_flags;
42987 +}
42988 +#endif
42989 +
42990 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42991 +{
42992 + unsigned long pax_flags = 0UL;
42993 +
42994 +#ifdef CONFIG_PAX_PAGEEXEC
42995 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42996 + pax_flags |= MF_PAX_PAGEEXEC;
42997 +#endif
42998 +
42999 +#ifdef CONFIG_PAX_SEGMEXEC
43000 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43001 + pax_flags |= MF_PAX_SEGMEXEC;
43002 +#endif
43003 +
43004 +#ifdef CONFIG_PAX_EMUTRAMP
43005 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43006 + pax_flags |= MF_PAX_EMUTRAMP;
43007 +#endif
43008 +
43009 +#ifdef CONFIG_PAX_MPROTECT
43010 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43011 + pax_flags |= MF_PAX_MPROTECT;
43012 +#endif
43013 +
43014 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43015 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43016 + pax_flags |= MF_PAX_RANDMMAP;
43017 +#endif
43018 +
43019 + return pax_flags;
43020 +}
43021 +#endif
43022 +
43023 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43024 +#ifdef CONFIG_PAX_SOFTMODE
43025 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43026 +{
43027 + unsigned long pax_flags = 0UL;
43028 +
43029 +#ifdef CONFIG_PAX_PAGEEXEC
43030 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43031 + pax_flags |= MF_PAX_PAGEEXEC;
43032 +#endif
43033 +
43034 +#ifdef CONFIG_PAX_SEGMEXEC
43035 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43036 + pax_flags |= MF_PAX_SEGMEXEC;
43037 +#endif
43038 +
43039 +#ifdef CONFIG_PAX_EMUTRAMP
43040 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43041 + pax_flags |= MF_PAX_EMUTRAMP;
43042 +#endif
43043 +
43044 +#ifdef CONFIG_PAX_MPROTECT
43045 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43046 + pax_flags |= MF_PAX_MPROTECT;
43047 +#endif
43048 +
43049 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43050 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43051 + pax_flags |= MF_PAX_RANDMMAP;
43052 +#endif
43053 +
43054 + return pax_flags;
43055 +}
43056 +#endif
43057 +
43058 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43059 +{
43060 + unsigned long pax_flags = 0UL;
43061 +
43062 +#ifdef CONFIG_PAX_PAGEEXEC
43063 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43064 + pax_flags |= MF_PAX_PAGEEXEC;
43065 +#endif
43066 +
43067 +#ifdef CONFIG_PAX_SEGMEXEC
43068 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43069 + pax_flags |= MF_PAX_SEGMEXEC;
43070 +#endif
43071 +
43072 +#ifdef CONFIG_PAX_EMUTRAMP
43073 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43074 + pax_flags |= MF_PAX_EMUTRAMP;
43075 +#endif
43076 +
43077 +#ifdef CONFIG_PAX_MPROTECT
43078 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43079 + pax_flags |= MF_PAX_MPROTECT;
43080 +#endif
43081 +
43082 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43083 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43084 + pax_flags |= MF_PAX_RANDMMAP;
43085 +#endif
43086 +
43087 + return pax_flags;
43088 +}
43089 +#endif
43090 +
43091 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43092 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43093 +{
43094 + unsigned long pax_flags = 0UL;
43095 +
43096 +#ifdef CONFIG_PAX_EI_PAX
43097 +
43098 +#ifdef CONFIG_PAX_PAGEEXEC
43099 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43100 + pax_flags |= MF_PAX_PAGEEXEC;
43101 +#endif
43102 +
43103 +#ifdef CONFIG_PAX_SEGMEXEC
43104 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43105 + pax_flags |= MF_PAX_SEGMEXEC;
43106 +#endif
43107 +
43108 +#ifdef CONFIG_PAX_EMUTRAMP
43109 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43110 + pax_flags |= MF_PAX_EMUTRAMP;
43111 +#endif
43112 +
43113 +#ifdef CONFIG_PAX_MPROTECT
43114 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43115 + pax_flags |= MF_PAX_MPROTECT;
43116 +#endif
43117 +
43118 +#ifdef CONFIG_PAX_ASLR
43119 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43120 + pax_flags |= MF_PAX_RANDMMAP;
43121 +#endif
43122 +
43123 +#else
43124 +
43125 +#ifdef CONFIG_PAX_PAGEEXEC
43126 + pax_flags |= MF_PAX_PAGEEXEC;
43127 +#endif
43128 +
43129 +#ifdef CONFIG_PAX_SEGMEXEC
43130 + pax_flags |= MF_PAX_SEGMEXEC;
43131 +#endif
43132 +
43133 +#ifdef CONFIG_PAX_MPROTECT
43134 + pax_flags |= MF_PAX_MPROTECT;
43135 +#endif
43136 +
43137 +#ifdef CONFIG_PAX_RANDMMAP
43138 + if (randomize_va_space)
43139 + pax_flags |= MF_PAX_RANDMMAP;
43140 +#endif
43141 +
43142 +#endif
43143 +
43144 + return pax_flags;
43145 +}
43146 +
43147 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43148 +{
43149 +
43150 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43151 + unsigned long i;
43152 +
43153 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43154 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43155 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43156 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43157 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43158 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43159 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43160 + return ~0UL;
43161 +
43162 +#ifdef CONFIG_PAX_SOFTMODE
43163 + if (pax_softmode)
43164 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43165 + else
43166 +#endif
43167 +
43168 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43169 + break;
43170 + }
43171 +#endif
43172 +
43173 + return ~0UL;
43174 +}
43175 +
43176 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43177 +{
43178 +
43179 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43180 + ssize_t xattr_size, i;
43181 + unsigned char xattr_value[5];
43182 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43183 +
43184 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43185 + if (xattr_size <= 0)
43186 + return ~0UL;
43187 +
43188 + for (i = 0; i < xattr_size; i++)
43189 + switch (xattr_value[i]) {
43190 + default:
43191 + return ~0UL;
43192 +
43193 +#define parse_flag(option1, option2, flag) \
43194 + case option1: \
43195 + pax_flags_hardmode |= MF_PAX_##flag; \
43196 + break; \
43197 + case option2: \
43198 + pax_flags_softmode |= MF_PAX_##flag; \
43199 + break;
43200 +
43201 + parse_flag('p', 'P', PAGEEXEC);
43202 + parse_flag('e', 'E', EMUTRAMP);
43203 + parse_flag('m', 'M', MPROTECT);
43204 + parse_flag('r', 'R', RANDMMAP);
43205 + parse_flag('s', 'S', SEGMEXEC);
43206 +
43207 +#undef parse_flag
43208 + }
43209 +
43210 + if (pax_flags_hardmode & pax_flags_softmode)
43211 + return ~0UL;
43212 +
43213 +#ifdef CONFIG_PAX_SOFTMODE
43214 + if (pax_softmode)
43215 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43216 + else
43217 +#endif
43218 +
43219 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43220 +#else
43221 + return ~0UL;
43222 +#endif
43223 +
43224 +}
43225 +
43226 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43227 +{
43228 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43229 +
43230 + pax_flags = pax_parse_ei_pax(elf_ex);
43231 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43232 + xattr_pax_flags = pax_parse_xattr_pax(file);
43233 +
43234 + if (pt_pax_flags == ~0UL)
43235 + pt_pax_flags = xattr_pax_flags;
43236 + else if (xattr_pax_flags == ~0UL)
43237 + xattr_pax_flags = pt_pax_flags;
43238 + if (pt_pax_flags != xattr_pax_flags)
43239 + return -EINVAL;
43240 + if (pt_pax_flags != ~0UL)
43241 + pax_flags = pt_pax_flags;
43242 +
43243 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43244 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43245 + if ((__supported_pte_mask & _PAGE_NX))
43246 + pax_flags &= ~MF_PAX_SEGMEXEC;
43247 + else
43248 + pax_flags &= ~MF_PAX_PAGEEXEC;
43249 + }
43250 +#endif
43251 +
43252 + if (0 > pax_check_flags(&pax_flags))
43253 + return -EINVAL;
43254 +
43255 + current->mm->pax_flags = pax_flags;
43256 + return 0;
43257 +}
43258 +#endif
43259 +
43260 /*
43261 * These are the functions used to load ELF style executables and shared
43262 * libraries. There is no binary dependent code anywhere else.
43263 @@ -539,6 +865,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43264 {
43265 unsigned int random_variable = 0;
43266
43267 +#ifdef CONFIG_PAX_RANDUSTACK
43268 + if (randomize_va_space)
43269 + return stack_top - current->mm->delta_stack;
43270 +#endif
43271 +
43272 if ((current->flags & PF_RANDOMIZE) &&
43273 !(current->personality & ADDR_NO_RANDOMIZE)) {
43274 random_variable = get_random_int() & STACK_RND_MASK;
43275 @@ -557,7 +888,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43276 unsigned long load_addr = 0, load_bias = 0;
43277 int load_addr_set = 0;
43278 char * elf_interpreter = NULL;
43279 - unsigned long error;
43280 + unsigned long error = 0;
43281 struct elf_phdr *elf_ppnt, *elf_phdata;
43282 unsigned long elf_bss, elf_brk;
43283 int retval, i;
43284 @@ -567,11 +898,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43285 unsigned long start_code, end_code, start_data, end_data;
43286 unsigned long reloc_func_desc __maybe_unused = 0;
43287 int executable_stack = EXSTACK_DEFAULT;
43288 - unsigned long def_flags = 0;
43289 struct {
43290 struct elfhdr elf_ex;
43291 struct elfhdr interp_elf_ex;
43292 } *loc;
43293 + unsigned long pax_task_size = TASK_SIZE;
43294
43295 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43296 if (!loc) {
43297 @@ -707,11 +1038,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43298 goto out_free_dentry;
43299
43300 /* OK, This is the point of no return */
43301 - current->mm->def_flags = def_flags;
43302 +
43303 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43304 + current->mm->pax_flags = 0UL;
43305 +#endif
43306 +
43307 +#ifdef CONFIG_PAX_DLRESOLVE
43308 + current->mm->call_dl_resolve = 0UL;
43309 +#endif
43310 +
43311 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43312 + current->mm->call_syscall = 0UL;
43313 +#endif
43314 +
43315 +#ifdef CONFIG_PAX_ASLR
43316 + current->mm->delta_mmap = 0UL;
43317 + current->mm->delta_stack = 0UL;
43318 +#endif
43319 +
43320 + current->mm->def_flags = 0;
43321 +
43322 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43323 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43324 + send_sig(SIGKILL, current, 0);
43325 + goto out_free_dentry;
43326 + }
43327 +#endif
43328 +
43329 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43330 + pax_set_initial_flags(bprm);
43331 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43332 + if (pax_set_initial_flags_func)
43333 + (pax_set_initial_flags_func)(bprm);
43334 +#endif
43335 +
43336 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43337 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43338 + current->mm->context.user_cs_limit = PAGE_SIZE;
43339 + current->mm->def_flags |= VM_PAGEEXEC;
43340 + }
43341 +#endif
43342 +
43343 +#ifdef CONFIG_PAX_SEGMEXEC
43344 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43345 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43346 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43347 + pax_task_size = SEGMEXEC_TASK_SIZE;
43348 + current->mm->def_flags |= VM_NOHUGEPAGE;
43349 + }
43350 +#endif
43351 +
43352 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43353 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43354 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43355 + put_cpu();
43356 + }
43357 +#endif
43358
43359 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43360 may depend on the personality. */
43361 SET_PERSONALITY(loc->elf_ex);
43362 +
43363 +#ifdef CONFIG_PAX_ASLR
43364 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43365 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43366 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43367 + }
43368 +#endif
43369 +
43370 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43371 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43372 + executable_stack = EXSTACK_DISABLE_X;
43373 + current->personality &= ~READ_IMPLIES_EXEC;
43374 + } else
43375 +#endif
43376 +
43377 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43378 current->personality |= READ_IMPLIES_EXEC;
43379
43380 @@ -802,6 +1203,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43381 #else
43382 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43383 #endif
43384 +
43385 +#ifdef CONFIG_PAX_RANDMMAP
43386 + /* PaX: randomize base address at the default exe base if requested */
43387 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43388 +#ifdef CONFIG_SPARC64
43389 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43390 +#else
43391 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43392 +#endif
43393 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43394 + elf_flags |= MAP_FIXED;
43395 + }
43396 +#endif
43397 +
43398 }
43399
43400 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43401 @@ -834,9 +1249,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43402 * allowed task size. Note that p_filesz must always be
43403 * <= p_memsz so it is only necessary to check p_memsz.
43404 */
43405 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43406 - elf_ppnt->p_memsz > TASK_SIZE ||
43407 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43408 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43409 + elf_ppnt->p_memsz > pax_task_size ||
43410 + pax_task_size - elf_ppnt->p_memsz < k) {
43411 /* set_brk can never work. Avoid overflows. */
43412 send_sig(SIGKILL, current, 0);
43413 retval = -EINVAL;
43414 @@ -875,17 +1290,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43415 goto out_free_dentry;
43416 }
43417 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43418 - send_sig(SIGSEGV, current, 0);
43419 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43420 - goto out_free_dentry;
43421 + /*
43422 + * This bss-zeroing can fail if the ELF
43423 + * file specifies odd protections. So
43424 + * we don't check the return value
43425 + */
43426 }
43427
43428 +#ifdef CONFIG_PAX_RANDMMAP
43429 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43430 + unsigned long start, size;
43431 +
43432 + start = ELF_PAGEALIGN(elf_brk);
43433 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43434 + down_read(&current->mm->mmap_sem);
43435 + retval = -ENOMEM;
43436 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43437 + unsigned long prot = PROT_NONE;
43438 +
43439 + up_read(&current->mm->mmap_sem);
43440 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43441 +// if (current->personality & ADDR_NO_RANDOMIZE)
43442 +// prot = PROT_READ;
43443 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43444 + retval = IS_ERR_VALUE(start) ? start : 0;
43445 + } else
43446 + up_read(&current->mm->mmap_sem);
43447 + if (retval == 0)
43448 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43449 + if (retval < 0) {
43450 + send_sig(SIGKILL, current, 0);
43451 + goto out_free_dentry;
43452 + }
43453 + }
43454 +#endif
43455 +
43456 if (elf_interpreter) {
43457 - unsigned long uninitialized_var(interp_map_addr);
43458 -
43459 elf_entry = load_elf_interp(&loc->interp_elf_ex,
43460 interpreter,
43461 - &interp_map_addr,
43462 load_bias);
43463 if (!IS_ERR((void *)elf_entry)) {
43464 /*
43465 @@ -1107,7 +1549,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43466 * Decide what to dump of a segment, part, all or none.
43467 */
43468 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43469 - unsigned long mm_flags)
43470 + unsigned long mm_flags, long signr)
43471 {
43472 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43473
43474 @@ -1144,7 +1586,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43475 if (vma->vm_file == NULL)
43476 return 0;
43477
43478 - if (FILTER(MAPPED_PRIVATE))
43479 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43480 goto whole;
43481
43482 /*
43483 @@ -1366,9 +1808,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43484 {
43485 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43486 int i = 0;
43487 - do
43488 + do {
43489 i += 2;
43490 - while (auxv[i - 2] != AT_NULL);
43491 + } while (auxv[i - 2] != AT_NULL);
43492 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43493 }
43494
43495 @@ -1879,14 +2321,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43496 }
43497
43498 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43499 - unsigned long mm_flags)
43500 + struct coredump_params *cprm)
43501 {
43502 struct vm_area_struct *vma;
43503 size_t size = 0;
43504
43505 for (vma = first_vma(current, gate_vma); vma != NULL;
43506 vma = next_vma(vma, gate_vma))
43507 - size += vma_dump_size(vma, mm_flags);
43508 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43509 return size;
43510 }
43511
43512 @@ -1980,7 +2422,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43513
43514 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43515
43516 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43517 + offset += elf_core_vma_data_size(gate_vma, cprm);
43518 offset += elf_core_extra_data_size();
43519 e_shoff = offset;
43520
43521 @@ -1994,10 +2436,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43522 offset = dataoff;
43523
43524 size += sizeof(*elf);
43525 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43526 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43527 goto end_coredump;
43528
43529 size += sizeof(*phdr4note);
43530 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43531 if (size > cprm->limit
43532 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43533 goto end_coredump;
43534 @@ -2011,7 +2455,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43535 phdr.p_offset = offset;
43536 phdr.p_vaddr = vma->vm_start;
43537 phdr.p_paddr = 0;
43538 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43539 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43540 phdr.p_memsz = vma->vm_end - vma->vm_start;
43541 offset += phdr.p_filesz;
43542 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43543 @@ -2022,6 +2466,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43544 phdr.p_align = ELF_EXEC_PAGESIZE;
43545
43546 size += sizeof(phdr);
43547 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43548 if (size > cprm->limit
43549 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43550 goto end_coredump;
43551 @@ -2046,7 +2491,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43552 unsigned long addr;
43553 unsigned long end;
43554
43555 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43556 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43557
43558 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43559 struct page *page;
43560 @@ -2055,6 +2500,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43561 page = get_dump_page(addr);
43562 if (page) {
43563 void *kaddr = kmap(page);
43564 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43565 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43566 !dump_write(cprm->file, kaddr,
43567 PAGE_SIZE);
43568 @@ -2072,6 +2518,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43569
43570 if (e_phnum == PN_XNUM) {
43571 size += sizeof(*shdr4extnum);
43572 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43573 if (size > cprm->limit
43574 || !dump_write(cprm->file, shdr4extnum,
43575 sizeof(*shdr4extnum)))
43576 @@ -2092,6 +2539,97 @@ out:
43577
43578 #endif /* CONFIG_ELF_CORE */
43579
43580 +#ifdef CONFIG_PAX_MPROTECT
43581 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43582 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43583 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43584 + *
43585 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43586 + * basis because we want to allow the common case and not the special ones.
43587 + */
43588 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43589 +{
43590 + struct elfhdr elf_h;
43591 + struct elf_phdr elf_p;
43592 + unsigned long i;
43593 + unsigned long oldflags;
43594 + bool is_textrel_rw, is_textrel_rx, is_relro;
43595 +
43596 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43597 + return;
43598 +
43599 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43600 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43601 +
43602 +#ifdef CONFIG_PAX_ELFRELOCS
43603 + /* possible TEXTREL */
43604 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43605 + 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);
43606 +#else
43607 + is_textrel_rw = false;
43608 + is_textrel_rx = false;
43609 +#endif
43610 +
43611 + /* possible RELRO */
43612 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43613 +
43614 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43615 + return;
43616 +
43617 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43618 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43619 +
43620 +#ifdef CONFIG_PAX_ETEXECRELOCS
43621 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43622 +#else
43623 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43624 +#endif
43625 +
43626 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43627 + !elf_check_arch(&elf_h) ||
43628 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43629 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43630 + return;
43631 +
43632 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43633 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43634 + return;
43635 + switch (elf_p.p_type) {
43636 + case PT_DYNAMIC:
43637 + if (!is_textrel_rw && !is_textrel_rx)
43638 + continue;
43639 + i = 0UL;
43640 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43641 + elf_dyn dyn;
43642 +
43643 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43644 + return;
43645 + if (dyn.d_tag == DT_NULL)
43646 + return;
43647 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43648 + gr_log_textrel(vma);
43649 + if (is_textrel_rw)
43650 + vma->vm_flags |= VM_MAYWRITE;
43651 + else
43652 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43653 + vma->vm_flags &= ~VM_MAYWRITE;
43654 + return;
43655 + }
43656 + i++;
43657 + }
43658 + return;
43659 +
43660 + case PT_GNU_RELRO:
43661 + if (!is_relro)
43662 + continue;
43663 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43664 + vma->vm_flags &= ~VM_MAYWRITE;
43665 + return;
43666 + }
43667 + }
43668 +}
43669 +#endif
43670 +
43671 static int __init init_elf_binfmt(void)
43672 {
43673 register_binfmt(&elf_format);
43674 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43675 index 178cb70..8972997 100644
43676 --- a/fs/binfmt_flat.c
43677 +++ b/fs/binfmt_flat.c
43678 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43679 realdatastart = (unsigned long) -ENOMEM;
43680 printk("Unable to allocate RAM for process data, errno %d\n",
43681 (int)-realdatastart);
43682 + down_write(&current->mm->mmap_sem);
43683 vm_munmap(textpos, text_len);
43684 + up_write(&current->mm->mmap_sem);
43685 ret = realdatastart;
43686 goto err;
43687 }
43688 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43689 }
43690 if (IS_ERR_VALUE(result)) {
43691 printk("Unable to read data+bss, errno %d\n", (int)-result);
43692 + down_write(&current->mm->mmap_sem);
43693 vm_munmap(textpos, text_len);
43694 vm_munmap(realdatastart, len);
43695 + up_write(&current->mm->mmap_sem);
43696 ret = result;
43697 goto err;
43698 }
43699 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43700 }
43701 if (IS_ERR_VALUE(result)) {
43702 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43703 + down_write(&current->mm->mmap_sem);
43704 vm_munmap(textpos, text_len + data_len + extra +
43705 MAX_SHARED_LIBS * sizeof(unsigned long));
43706 + up_write(&current->mm->mmap_sem);
43707 ret = result;
43708 goto err;
43709 }
43710 diff --git a/fs/bio.c b/fs/bio.c
43711 index 71072ab..439851b 100644
43712 --- a/fs/bio.c
43713 +++ b/fs/bio.c
43714 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43715 /*
43716 * Overflow, abort
43717 */
43718 - if (end < start)
43719 + if (end < start || end - start > INT_MAX - nr_pages)
43720 return ERR_PTR(-EINVAL);
43721
43722 nr_pages += end - start;
43723 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43724 /*
43725 * Overflow, abort
43726 */
43727 - if (end < start)
43728 + if (end < start || end - start > INT_MAX - nr_pages)
43729 return ERR_PTR(-EINVAL);
43730
43731 nr_pages += end - start;
43732 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43733 const int read = bio_data_dir(bio) == READ;
43734 struct bio_map_data *bmd = bio->bi_private;
43735 int i;
43736 - char *p = bmd->sgvecs[0].iov_base;
43737 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43738
43739 __bio_for_each_segment(bvec, bio, i, 0) {
43740 char *addr = page_address(bvec->bv_page);
43741 diff --git a/fs/block_dev.c b/fs/block_dev.c
43742 index 38e721b..7a9c5bc 100644
43743 --- a/fs/block_dev.c
43744 +++ b/fs/block_dev.c
43745 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43746 else if (bdev->bd_contains == bdev)
43747 return true; /* is a whole device which isn't held */
43748
43749 - else if (whole->bd_holder == bd_may_claim)
43750 + else if (whole->bd_holder == (void *)bd_may_claim)
43751 return true; /* is a partition of a device that is being partitioned */
43752 else if (whole->bd_holder != NULL)
43753 return false; /* is a partition of a held device */
43754 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43755 index 9197e2e..7f731f8 100644
43756 --- a/fs/btrfs/check-integrity.c
43757 +++ b/fs/btrfs/check-integrity.c
43758 @@ -155,7 +155,7 @@ struct btrfsic_block {
43759 union {
43760 bio_end_io_t *bio;
43761 bh_end_io_t *bh;
43762 - } orig_bio_bh_end_io;
43763 + } __no_const orig_bio_bh_end_io;
43764 int submit_bio_bh_rw;
43765 u64 flush_gen; /* only valid if !never_written */
43766 };
43767 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43768 index 6d183f6..f47cc7a 100644
43769 --- a/fs/btrfs/ctree.c
43770 +++ b/fs/btrfs/ctree.c
43771 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43772 free_extent_buffer(buf);
43773 add_root_to_dirty_list(root);
43774 } else {
43775 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43776 - parent_start = parent->start;
43777 - else
43778 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43779 + if (parent)
43780 + parent_start = parent->start;
43781 + else
43782 + parent_start = 0;
43783 + } else
43784 parent_start = 0;
43785
43786 WARN_ON(trans->transid != btrfs_header_generation(parent));
43787 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43788 index ec154f9..bf617a7 100644
43789 --- a/fs/btrfs/inode.c
43790 +++ b/fs/btrfs/inode.c
43791 @@ -7126,7 +7126,7 @@ fail:
43792 return -ENOMEM;
43793 }
43794
43795 -static int btrfs_getattr(struct vfsmount *mnt,
43796 +int btrfs_getattr(struct vfsmount *mnt,
43797 struct dentry *dentry, struct kstat *stat)
43798 {
43799 struct inode *inode = dentry->d_inode;
43800 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43801 return 0;
43802 }
43803
43804 +EXPORT_SYMBOL(btrfs_getattr);
43805 +
43806 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43807 +{
43808 + return BTRFS_I(inode)->root->anon_dev;
43809 +}
43810 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43811 +
43812 /*
43813 * If a file is moved, it will inherit the cow and compression flags of the new
43814 * directory.
43815 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43816 index 9df50fa..6cd20d0 100644
43817 --- a/fs/btrfs/ioctl.c
43818 +++ b/fs/btrfs/ioctl.c
43819 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43820 for (i = 0; i < num_types; i++) {
43821 struct btrfs_space_info *tmp;
43822
43823 + /* Don't copy in more than we allocated */
43824 if (!slot_count)
43825 break;
43826
43827 + slot_count--;
43828 +
43829 info = NULL;
43830 rcu_read_lock();
43831 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43832 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43833 memcpy(dest, &space, sizeof(space));
43834 dest++;
43835 space_args.total_spaces++;
43836 - slot_count--;
43837 }
43838 - if (!slot_count)
43839 - break;
43840 }
43841 up_read(&info->groups_sem);
43842 }
43843 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43844 index 4da0865..01c4778 100644
43845 --- a/fs/btrfs/relocation.c
43846 +++ b/fs/btrfs/relocation.c
43847 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43848 }
43849 spin_unlock(&rc->reloc_root_tree.lock);
43850
43851 - BUG_ON((struct btrfs_root *)node->data != root);
43852 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43853
43854 if (!del) {
43855 spin_lock(&rc->reloc_root_tree.lock);
43856 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43857 index 622f469..e8d2d55 100644
43858 --- a/fs/cachefiles/bind.c
43859 +++ b/fs/cachefiles/bind.c
43860 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43861 args);
43862
43863 /* start by checking things over */
43864 - ASSERT(cache->fstop_percent >= 0 &&
43865 - cache->fstop_percent < cache->fcull_percent &&
43866 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43867 cache->fcull_percent < cache->frun_percent &&
43868 cache->frun_percent < 100);
43869
43870 - ASSERT(cache->bstop_percent >= 0 &&
43871 - cache->bstop_percent < cache->bcull_percent &&
43872 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43873 cache->bcull_percent < cache->brun_percent &&
43874 cache->brun_percent < 100);
43875
43876 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43877 index 0a1467b..6a53245 100644
43878 --- a/fs/cachefiles/daemon.c
43879 +++ b/fs/cachefiles/daemon.c
43880 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43881 if (n > buflen)
43882 return -EMSGSIZE;
43883
43884 - if (copy_to_user(_buffer, buffer, n) != 0)
43885 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43886 return -EFAULT;
43887
43888 return n;
43889 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43890 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43891 return -EIO;
43892
43893 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43894 + if (datalen > PAGE_SIZE - 1)
43895 return -EOPNOTSUPP;
43896
43897 /* drag the command string into the kernel so we can parse it */
43898 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43899 if (args[0] != '%' || args[1] != '\0')
43900 return -EINVAL;
43901
43902 - if (fstop < 0 || fstop >= cache->fcull_percent)
43903 + if (fstop >= cache->fcull_percent)
43904 return cachefiles_daemon_range_error(cache, args);
43905
43906 cache->fstop_percent = fstop;
43907 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43908 if (args[0] != '%' || args[1] != '\0')
43909 return -EINVAL;
43910
43911 - if (bstop < 0 || bstop >= cache->bcull_percent)
43912 + if (bstop >= cache->bcull_percent)
43913 return cachefiles_daemon_range_error(cache, args);
43914
43915 cache->bstop_percent = bstop;
43916 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43917 index bd6bc1b..b627b53 100644
43918 --- a/fs/cachefiles/internal.h
43919 +++ b/fs/cachefiles/internal.h
43920 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43921 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43922 struct rb_root active_nodes; /* active nodes (can't be culled) */
43923 rwlock_t active_lock; /* lock for active_nodes */
43924 - atomic_t gravecounter; /* graveyard uniquifier */
43925 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43926 unsigned frun_percent; /* when to stop culling (% files) */
43927 unsigned fcull_percent; /* when to start culling (% files) */
43928 unsigned fstop_percent; /* when to stop allocating (% files) */
43929 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43930 * proc.c
43931 */
43932 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43933 -extern atomic_t cachefiles_lookup_histogram[HZ];
43934 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43935 -extern atomic_t cachefiles_create_histogram[HZ];
43936 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43937 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43938 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43939
43940 extern int __init cachefiles_proc_init(void);
43941 extern void cachefiles_proc_cleanup(void);
43942 static inline
43943 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43944 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43945 {
43946 unsigned long jif = jiffies - start_jif;
43947 if (jif >= HZ)
43948 jif = HZ - 1;
43949 - atomic_inc(&histogram[jif]);
43950 + atomic_inc_unchecked(&histogram[jif]);
43951 }
43952
43953 #else
43954 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43955 index b0b5f7c..039bb26 100644
43956 --- a/fs/cachefiles/namei.c
43957 +++ b/fs/cachefiles/namei.c
43958 @@ -318,7 +318,7 @@ try_again:
43959 /* first step is to make up a grave dentry in the graveyard */
43960 sprintf(nbuffer, "%08x%08x",
43961 (uint32_t) get_seconds(),
43962 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43963 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43964
43965 /* do the multiway lock magic */
43966 trap = lock_rename(cache->graveyard, dir);
43967 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43968 index eccd339..4c1d995 100644
43969 --- a/fs/cachefiles/proc.c
43970 +++ b/fs/cachefiles/proc.c
43971 @@ -14,9 +14,9 @@
43972 #include <linux/seq_file.h>
43973 #include "internal.h"
43974
43975 -atomic_t cachefiles_lookup_histogram[HZ];
43976 -atomic_t cachefiles_mkdir_histogram[HZ];
43977 -atomic_t cachefiles_create_histogram[HZ];
43978 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43979 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43980 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43981
43982 /*
43983 * display the latency histogram
43984 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43985 return 0;
43986 default:
43987 index = (unsigned long) v - 3;
43988 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43989 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43990 - z = atomic_read(&cachefiles_create_histogram[index]);
43991 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43992 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43993 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43994 if (x == 0 && y == 0 && z == 0)
43995 return 0;
43996
43997 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43998 index c994691..2a1537f 100644
43999 --- a/fs/cachefiles/rdwr.c
44000 +++ b/fs/cachefiles/rdwr.c
44001 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44002 old_fs = get_fs();
44003 set_fs(KERNEL_DS);
44004 ret = file->f_op->write(
44005 - file, (const void __user *) data, len, &pos);
44006 + file, (const void __force_user *) data, len, &pos);
44007 set_fs(old_fs);
44008 kunmap(page);
44009 if (ret != len)
44010 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44011 index e5b7731..b9c59fb 100644
44012 --- a/fs/ceph/dir.c
44013 +++ b/fs/ceph/dir.c
44014 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44015 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44016 struct ceph_mds_client *mdsc = fsc->mdsc;
44017 unsigned frag = fpos_frag(filp->f_pos);
44018 - int off = fpos_off(filp->f_pos);
44019 + unsigned int off = fpos_off(filp->f_pos);
44020 int err;
44021 u32 ftype;
44022 struct ceph_mds_reply_info_parsed *rinfo;
44023 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44024 index d9ea6ed..1e6c8ac 100644
44025 --- a/fs/cifs/cifs_debug.c
44026 +++ b/fs/cifs/cifs_debug.c
44027 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44028
44029 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44030 #ifdef CONFIG_CIFS_STATS2
44031 - atomic_set(&totBufAllocCount, 0);
44032 - atomic_set(&totSmBufAllocCount, 0);
44033 + atomic_set_unchecked(&totBufAllocCount, 0);
44034 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44035 #endif /* CONFIG_CIFS_STATS2 */
44036 spin_lock(&cifs_tcp_ses_lock);
44037 list_for_each(tmp1, &cifs_tcp_ses_list) {
44038 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44039 tcon = list_entry(tmp3,
44040 struct cifs_tcon,
44041 tcon_list);
44042 - atomic_set(&tcon->num_smbs_sent, 0);
44043 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44044 if (server->ops->clear_stats)
44045 server->ops->clear_stats(tcon);
44046 }
44047 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44048 smBufAllocCount.counter, cifs_min_small);
44049 #ifdef CONFIG_CIFS_STATS2
44050 seq_printf(m, "Total Large %d Small %d Allocations\n",
44051 - atomic_read(&totBufAllocCount),
44052 - atomic_read(&totSmBufAllocCount));
44053 + atomic_read_unchecked(&totBufAllocCount),
44054 + atomic_read_unchecked(&totSmBufAllocCount));
44055 #endif /* CONFIG_CIFS_STATS2 */
44056
44057 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44058 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44059 if (tcon->need_reconnect)
44060 seq_puts(m, "\tDISCONNECTED ");
44061 seq_printf(m, "\nSMBs: %d",
44062 - atomic_read(&tcon->num_smbs_sent));
44063 + atomic_read_unchecked(&tcon->num_smbs_sent));
44064 if (server->ops->print_stats)
44065 server->ops->print_stats(m, tcon);
44066 }
44067 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44068 index db8a404..c712e2e 100644
44069 --- a/fs/cifs/cifsfs.c
44070 +++ b/fs/cifs/cifsfs.c
44071 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44072 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44073 cifs_req_cachep = kmem_cache_create("cifs_request",
44074 CIFSMaxBufSize + max_hdr_size, 0,
44075 - SLAB_HWCACHE_ALIGN, NULL);
44076 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44077 if (cifs_req_cachep == NULL)
44078 return -ENOMEM;
44079
44080 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44081 efficient to alloc 1 per page off the slab compared to 17K (5page)
44082 alloc of large cifs buffers even when page debugging is on */
44083 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44084 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44085 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44086 NULL);
44087 if (cifs_sm_req_cachep == NULL) {
44088 mempool_destroy(cifs_req_poolp);
44089 @@ -1115,8 +1115,8 @@ init_cifs(void)
44090 atomic_set(&bufAllocCount, 0);
44091 atomic_set(&smBufAllocCount, 0);
44092 #ifdef CONFIG_CIFS_STATS2
44093 - atomic_set(&totBufAllocCount, 0);
44094 - atomic_set(&totSmBufAllocCount, 0);
44095 + atomic_set_unchecked(&totBufAllocCount, 0);
44096 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44097 #endif /* CONFIG_CIFS_STATS2 */
44098
44099 atomic_set(&midCount, 0);
44100 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44101 index 977dc0e..ba48ab9 100644
44102 --- a/fs/cifs/cifsglob.h
44103 +++ b/fs/cifs/cifsglob.h
44104 @@ -590,35 +590,35 @@ struct cifs_tcon {
44105 __u16 Flags; /* optional support bits */
44106 enum statusEnum tidStatus;
44107 #ifdef CONFIG_CIFS_STATS
44108 - atomic_t num_smbs_sent;
44109 + atomic_unchecked_t num_smbs_sent;
44110 union {
44111 struct {
44112 - atomic_t num_writes;
44113 - atomic_t num_reads;
44114 - atomic_t num_flushes;
44115 - atomic_t num_oplock_brks;
44116 - atomic_t num_opens;
44117 - atomic_t num_closes;
44118 - atomic_t num_deletes;
44119 - atomic_t num_mkdirs;
44120 - atomic_t num_posixopens;
44121 - atomic_t num_posixmkdirs;
44122 - atomic_t num_rmdirs;
44123 - atomic_t num_renames;
44124 - atomic_t num_t2renames;
44125 - atomic_t num_ffirst;
44126 - atomic_t num_fnext;
44127 - atomic_t num_fclose;
44128 - atomic_t num_hardlinks;
44129 - atomic_t num_symlinks;
44130 - atomic_t num_locks;
44131 - atomic_t num_acl_get;
44132 - atomic_t num_acl_set;
44133 + atomic_unchecked_t num_writes;
44134 + atomic_unchecked_t num_reads;
44135 + atomic_unchecked_t num_flushes;
44136 + atomic_unchecked_t num_oplock_brks;
44137 + atomic_unchecked_t num_opens;
44138 + atomic_unchecked_t num_closes;
44139 + atomic_unchecked_t num_deletes;
44140 + atomic_unchecked_t num_mkdirs;
44141 + atomic_unchecked_t num_posixopens;
44142 + atomic_unchecked_t num_posixmkdirs;
44143 + atomic_unchecked_t num_rmdirs;
44144 + atomic_unchecked_t num_renames;
44145 + atomic_unchecked_t num_t2renames;
44146 + atomic_unchecked_t num_ffirst;
44147 + atomic_unchecked_t num_fnext;
44148 + atomic_unchecked_t num_fclose;
44149 + atomic_unchecked_t num_hardlinks;
44150 + atomic_unchecked_t num_symlinks;
44151 + atomic_unchecked_t num_locks;
44152 + atomic_unchecked_t num_acl_get;
44153 + atomic_unchecked_t num_acl_set;
44154 } cifs_stats;
44155 #ifdef CONFIG_CIFS_SMB2
44156 struct {
44157 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44158 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44159 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44160 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44161 } smb2_stats;
44162 #endif /* CONFIG_CIFS_SMB2 */
44163 } stats;
44164 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44165 }
44166
44167 #ifdef CONFIG_CIFS_STATS
44168 -#define cifs_stats_inc atomic_inc
44169 +#define cifs_stats_inc atomic_inc_unchecked
44170
44171 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44172 unsigned int bytes)
44173 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44174 /* Various Debug counters */
44175 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44176 #ifdef CONFIG_CIFS_STATS2
44177 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44178 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44179 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44180 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44181 #endif
44182 GLOBAL_EXTERN atomic_t smBufAllocCount;
44183 GLOBAL_EXTERN atomic_t midCount;
44184 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44185 index e6ce3b1..adc21fd 100644
44186 --- a/fs/cifs/link.c
44187 +++ b/fs/cifs/link.c
44188 @@ -602,7 +602,7 @@ symlink_exit:
44189
44190 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44191 {
44192 - char *p = nd_get_link(nd);
44193 + const char *p = nd_get_link(nd);
44194 if (!IS_ERR(p))
44195 kfree(p);
44196 }
44197 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44198 index ce41fee..ac0d27a 100644
44199 --- a/fs/cifs/misc.c
44200 +++ b/fs/cifs/misc.c
44201 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44202 memset(ret_buf, 0, buf_size + 3);
44203 atomic_inc(&bufAllocCount);
44204 #ifdef CONFIG_CIFS_STATS2
44205 - atomic_inc(&totBufAllocCount);
44206 + atomic_inc_unchecked(&totBufAllocCount);
44207 #endif /* CONFIG_CIFS_STATS2 */
44208 }
44209
44210 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44211 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44212 atomic_inc(&smBufAllocCount);
44213 #ifdef CONFIG_CIFS_STATS2
44214 - atomic_inc(&totSmBufAllocCount);
44215 + atomic_inc_unchecked(&totSmBufAllocCount);
44216 #endif /* CONFIG_CIFS_STATS2 */
44217
44218 }
44219 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44220 index 3129ac7..cc4a948 100644
44221 --- a/fs/cifs/smb1ops.c
44222 +++ b/fs/cifs/smb1ops.c
44223 @@ -524,27 +524,27 @@ static void
44224 cifs_clear_stats(struct cifs_tcon *tcon)
44225 {
44226 #ifdef CONFIG_CIFS_STATS
44227 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44228 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44229 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44230 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44231 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44232 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44233 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44234 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44235 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44236 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44237 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44238 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44239 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44240 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44241 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44242 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44243 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44244 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44245 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44246 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44247 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44248 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44249 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44250 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44251 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44252 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44253 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44254 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44255 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44256 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44257 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44258 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44259 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44260 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44261 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44262 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44263 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44264 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44265 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44266 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44267 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44268 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44269 #endif
44270 }
44271
44272 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44273 {
44274 #ifdef CONFIG_CIFS_STATS
44275 seq_printf(m, " Oplocks breaks: %d",
44276 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44277 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44278 seq_printf(m, "\nReads: %d Bytes: %llu",
44279 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44280 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44281 (long long)(tcon->bytes_read));
44282 seq_printf(m, "\nWrites: %d Bytes: %llu",
44283 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44284 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44285 (long long)(tcon->bytes_written));
44286 seq_printf(m, "\nFlushes: %d",
44287 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44288 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44289 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44290 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44291 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44292 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44293 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44294 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44295 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44296 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44297 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44298 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44299 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44300 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44301 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44302 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44303 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44304 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44305 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44306 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44307 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44308 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44309 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44310 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44311 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44312 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44313 seq_printf(m, "\nRenames: %d T2 Renames %d",
44314 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44315 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44316 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44317 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44318 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44319 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44320 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44321 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44322 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44323 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44324 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44325 #endif
44326 }
44327
44328 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44329 index 826209b..fa460f4 100644
44330 --- a/fs/cifs/smb2ops.c
44331 +++ b/fs/cifs/smb2ops.c
44332 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44333 #ifdef CONFIG_CIFS_STATS
44334 int i;
44335 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44336 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44337 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44338 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44339 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44340 }
44341 #endif
44342 }
44343 @@ -229,66 +229,66 @@ static void
44344 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44345 {
44346 #ifdef CONFIG_CIFS_STATS
44347 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44348 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44349 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44350 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44351 seq_printf(m, "\nNegotiates: %d sent %d failed",
44352 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44353 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44354 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44355 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44356 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44357 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44358 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44359 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44360 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44361 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44362 seq_printf(m, "\nLogoffs: %d sent %d failed",
44363 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44364 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44365 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44366 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44367 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44368 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44369 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44370 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44371 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44372 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44373 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44374 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44375 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44376 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44377 seq_printf(m, "\nCreates: %d sent %d failed",
44378 - atomic_read(&sent[SMB2_CREATE_HE]),
44379 - atomic_read(&failed[SMB2_CREATE_HE]));
44380 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44381 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44382 seq_printf(m, "\nCloses: %d sent %d failed",
44383 - atomic_read(&sent[SMB2_CLOSE_HE]),
44384 - atomic_read(&failed[SMB2_CLOSE_HE]));
44385 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44386 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44387 seq_printf(m, "\nFlushes: %d sent %d failed",
44388 - atomic_read(&sent[SMB2_FLUSH_HE]),
44389 - atomic_read(&failed[SMB2_FLUSH_HE]));
44390 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44391 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44392 seq_printf(m, "\nReads: %d sent %d failed",
44393 - atomic_read(&sent[SMB2_READ_HE]),
44394 - atomic_read(&failed[SMB2_READ_HE]));
44395 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44396 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44397 seq_printf(m, "\nWrites: %d sent %d failed",
44398 - atomic_read(&sent[SMB2_WRITE_HE]),
44399 - atomic_read(&failed[SMB2_WRITE_HE]));
44400 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44401 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44402 seq_printf(m, "\nLocks: %d sent %d failed",
44403 - atomic_read(&sent[SMB2_LOCK_HE]),
44404 - atomic_read(&failed[SMB2_LOCK_HE]));
44405 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44406 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44407 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44408 - atomic_read(&sent[SMB2_IOCTL_HE]),
44409 - atomic_read(&failed[SMB2_IOCTL_HE]));
44410 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44411 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44412 seq_printf(m, "\nCancels: %d sent %d failed",
44413 - atomic_read(&sent[SMB2_CANCEL_HE]),
44414 - atomic_read(&failed[SMB2_CANCEL_HE]));
44415 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44416 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44417 seq_printf(m, "\nEchos: %d sent %d failed",
44418 - atomic_read(&sent[SMB2_ECHO_HE]),
44419 - atomic_read(&failed[SMB2_ECHO_HE]));
44420 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44421 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44422 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44423 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44424 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44425 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44426 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44427 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44428 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44429 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44430 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44431 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44432 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44433 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44434 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44435 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44436 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44437 seq_printf(m, "\nSetInfos: %d sent %d failed",
44438 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44439 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44440 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44441 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44442 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44443 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44444 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44445 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44446 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44447 #endif
44448 }
44449
44450 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44451 index 958ae0e..505c9d0 100644
44452 --- a/fs/coda/cache.c
44453 +++ b/fs/coda/cache.c
44454 @@ -24,7 +24,7 @@
44455 #include "coda_linux.h"
44456 #include "coda_cache.h"
44457
44458 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44459 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44460
44461 /* replace or extend an acl cache hit */
44462 void coda_cache_enter(struct inode *inode, int mask)
44463 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44464 struct coda_inode_info *cii = ITOC(inode);
44465
44466 spin_lock(&cii->c_lock);
44467 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44468 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44469 if (cii->c_uid != current_fsuid()) {
44470 cii->c_uid = current_fsuid();
44471 cii->c_cached_perm = mask;
44472 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44473 {
44474 struct coda_inode_info *cii = ITOC(inode);
44475 spin_lock(&cii->c_lock);
44476 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44477 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44478 spin_unlock(&cii->c_lock);
44479 }
44480
44481 /* remove all acl caches */
44482 void coda_cache_clear_all(struct super_block *sb)
44483 {
44484 - atomic_inc(&permission_epoch);
44485 + atomic_inc_unchecked(&permission_epoch);
44486 }
44487
44488
44489 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44490 spin_lock(&cii->c_lock);
44491 hit = (mask & cii->c_cached_perm) == mask &&
44492 cii->c_uid == current_fsuid() &&
44493 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44494 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44495 spin_unlock(&cii->c_lock);
44496
44497 return hit;
44498 diff --git a/fs/compat.c b/fs/compat.c
44499 index 1bdb350..9f28287 100644
44500 --- a/fs/compat.c
44501 +++ b/fs/compat.c
44502 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44503
44504 set_fs(KERNEL_DS);
44505 /* The __user pointer cast is valid because of the set_fs() */
44506 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44507 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44508 set_fs(oldfs);
44509 /* truncating is ok because it's a user address */
44510 if (!ret)
44511 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44512 goto out;
44513
44514 ret = -EINVAL;
44515 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44516 + if (nr_segs > UIO_MAXIOV)
44517 goto out;
44518 if (nr_segs > fast_segs) {
44519 ret = -ENOMEM;
44520 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44521
44522 struct compat_readdir_callback {
44523 struct compat_old_linux_dirent __user *dirent;
44524 + struct file * file;
44525 int result;
44526 };
44527
44528 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44529 buf->result = -EOVERFLOW;
44530 return -EOVERFLOW;
44531 }
44532 +
44533 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44534 + return 0;
44535 +
44536 buf->result++;
44537 dirent = buf->dirent;
44538 if (!access_ok(VERIFY_WRITE, dirent,
44539 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44540
44541 buf.result = 0;
44542 buf.dirent = dirent;
44543 + buf.file = file;
44544
44545 error = vfs_readdir(file, compat_fillonedir, &buf);
44546 if (buf.result)
44547 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44548 struct compat_getdents_callback {
44549 struct compat_linux_dirent __user *current_dir;
44550 struct compat_linux_dirent __user *previous;
44551 + struct file * file;
44552 int count;
44553 int error;
44554 };
44555 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44556 buf->error = -EOVERFLOW;
44557 return -EOVERFLOW;
44558 }
44559 +
44560 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44561 + return 0;
44562 +
44563 dirent = buf->previous;
44564 if (dirent) {
44565 if (__put_user(offset, &dirent->d_off))
44566 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44567 buf.previous = NULL;
44568 buf.count = count;
44569 buf.error = 0;
44570 + buf.file = file;
44571
44572 error = vfs_readdir(file, compat_filldir, &buf);
44573 if (error >= 0)
44574 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44575 struct compat_getdents_callback64 {
44576 struct linux_dirent64 __user *current_dir;
44577 struct linux_dirent64 __user *previous;
44578 + struct file * file;
44579 int count;
44580 int error;
44581 };
44582 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44583 buf->error = -EINVAL; /* only used if we fail.. */
44584 if (reclen > buf->count)
44585 return -EINVAL;
44586 +
44587 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44588 + return 0;
44589 +
44590 dirent = buf->previous;
44591
44592 if (dirent) {
44593 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44594 buf.previous = NULL;
44595 buf.count = count;
44596 buf.error = 0;
44597 + buf.file = file;
44598
44599 error = vfs_readdir(file, compat_filldir64, &buf);
44600 if (error >= 0)
44601 error = buf.error;
44602 lastdirent = buf.previous;
44603 if (lastdirent) {
44604 - typeof(lastdirent->d_off) d_off = file->f_pos;
44605 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44606 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44607 error = -EFAULT;
44608 else
44609 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44610 index 112e45a..b59845b 100644
44611 --- a/fs/compat_binfmt_elf.c
44612 +++ b/fs/compat_binfmt_elf.c
44613 @@ -30,11 +30,13 @@
44614 #undef elf_phdr
44615 #undef elf_shdr
44616 #undef elf_note
44617 +#undef elf_dyn
44618 #undef elf_addr_t
44619 #define elfhdr elf32_hdr
44620 #define elf_phdr elf32_phdr
44621 #define elf_shdr elf32_shdr
44622 #define elf_note elf32_note
44623 +#define elf_dyn Elf32_Dyn
44624 #define elf_addr_t Elf32_Addr
44625
44626 /*
44627 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44628 index 5d2069f..75d31d4 100644
44629 --- a/fs/compat_ioctl.c
44630 +++ b/fs/compat_ioctl.c
44631 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44632 return -EFAULT;
44633 if (__get_user(udata, &ss32->iomem_base))
44634 return -EFAULT;
44635 - ss.iomem_base = compat_ptr(udata);
44636 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44637 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44638 __get_user(ss.port_high, &ss32->port_high))
44639 return -EFAULT;
44640 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44641 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44642 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44643 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44644 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44645 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44646 return -EFAULT;
44647
44648 return ioctl_preallocate(file, p);
44649 @@ -1612,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44650 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44651 {
44652 unsigned int a, b;
44653 - a = *(unsigned int *)p;
44654 - b = *(unsigned int *)q;
44655 + a = *(const unsigned int *)p;
44656 + b = *(const unsigned int *)q;
44657 if (a > b)
44658 return 1;
44659 if (a < b)
44660 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44661 index 7414ae2..d98ad6d 100644
44662 --- a/fs/configfs/dir.c
44663 +++ b/fs/configfs/dir.c
44664 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44665 }
44666 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44667 struct configfs_dirent *next;
44668 - const char * name;
44669 + const unsigned char * name;
44670 + char d_name[sizeof(next->s_dentry->d_iname)];
44671 int len;
44672 struct inode *inode = NULL;
44673
44674 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44675 continue;
44676
44677 name = configfs_get_name(next);
44678 - len = strlen(name);
44679 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44680 + len = next->s_dentry->d_name.len;
44681 + memcpy(d_name, name, len);
44682 + name = d_name;
44683 + } else
44684 + len = strlen(name);
44685
44686 /*
44687 * We'll have a dentry and an inode for
44688 diff --git a/fs/dcache.c b/fs/dcache.c
44689 index 693f95b..95f1223 100644
44690 --- a/fs/dcache.c
44691 +++ b/fs/dcache.c
44692 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44693 mempages -= reserve;
44694
44695 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44696 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44697 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44698
44699 dcache_init();
44700 inode_init();
44701 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44702 index 4733eab..71ef6fa 100644
44703 --- a/fs/debugfs/inode.c
44704 +++ b/fs/debugfs/inode.c
44705 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44706 */
44707 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44708 {
44709 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44710 + return __create_file(name, S_IFDIR | S_IRWXU,
44711 +#else
44712 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44713 +#endif
44714 parent, NULL, NULL);
44715 }
44716 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44717 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44718 index cc7709e..7e7211f 100644
44719 --- a/fs/ecryptfs/inode.c
44720 +++ b/fs/ecryptfs/inode.c
44721 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44722 old_fs = get_fs();
44723 set_fs(get_ds());
44724 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44725 - (char __user *)lower_buf,
44726 + (char __force_user *)lower_buf,
44727 PATH_MAX);
44728 set_fs(old_fs);
44729 if (rc < 0)
44730 @@ -706,7 +706,7 @@ out:
44731 static void
44732 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44733 {
44734 - char *buf = nd_get_link(nd);
44735 + const char *buf = nd_get_link(nd);
44736 if (!IS_ERR(buf)) {
44737 /* Free the char* */
44738 kfree(buf);
44739 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44740 index 412e6ed..4292d22 100644
44741 --- a/fs/ecryptfs/miscdev.c
44742 +++ b/fs/ecryptfs/miscdev.c
44743 @@ -315,7 +315,7 @@ check_list:
44744 goto out_unlock_msg_ctx;
44745 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44746 if (msg_ctx->msg) {
44747 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44748 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44749 goto out_unlock_msg_ctx;
44750 i += packet_length_size;
44751 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44752 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44753 index b2a34a1..162fa69 100644
44754 --- a/fs/ecryptfs/read_write.c
44755 +++ b/fs/ecryptfs/read_write.c
44756 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44757 return -EIO;
44758 fs_save = get_fs();
44759 set_fs(get_ds());
44760 - rc = vfs_write(lower_file, data, size, &offset);
44761 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44762 set_fs(fs_save);
44763 mark_inode_dirty_sync(ecryptfs_inode);
44764 return rc;
44765 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44766 return -EIO;
44767 fs_save = get_fs();
44768 set_fs(get_ds());
44769 - rc = vfs_read(lower_file, data, size, &offset);
44770 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44771 set_fs(fs_save);
44772 return rc;
44773 }
44774 diff --git a/fs/exec.c b/fs/exec.c
44775 index fab2c6d..4fa20c0 100644
44776 --- a/fs/exec.c
44777 +++ b/fs/exec.c
44778 @@ -55,6 +55,15 @@
44779 #include <linux/pipe_fs_i.h>
44780 #include <linux/oom.h>
44781 #include <linux/compat.h>
44782 +#include <linux/random.h>
44783 +#include <linux/seq_file.h>
44784 +
44785 +#ifdef CONFIG_PAX_REFCOUNT
44786 +#include <linux/kallsyms.h>
44787 +#include <linux/kdebug.h>
44788 +#endif
44789 +
44790 +#include <trace/events/fs.h>
44791
44792 #include <asm/uaccess.h>
44793 #include <asm/mmu_context.h>
44794 @@ -66,6 +75,18 @@
44795
44796 #include <trace/events/sched.h>
44797
44798 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44799 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44800 +{
44801 + 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");
44802 +}
44803 +#endif
44804 +
44805 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44806 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44807 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44808 +#endif
44809 +
44810 int core_uses_pid;
44811 char core_pattern[CORENAME_MAX_SIZE] = "core";
44812 unsigned int core_pipe_limit;
44813 @@ -75,7 +96,7 @@ struct core_name {
44814 char *corename;
44815 int used, size;
44816 };
44817 -static atomic_t call_count = ATOMIC_INIT(1);
44818 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44819
44820 /* The maximal length of core_pattern is also specified in sysctl.c */
44821
44822 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44823 int write)
44824 {
44825 struct page *page;
44826 - int ret;
44827
44828 -#ifdef CONFIG_STACK_GROWSUP
44829 - if (write) {
44830 - ret = expand_downwards(bprm->vma, pos);
44831 - if (ret < 0)
44832 - return NULL;
44833 - }
44834 -#endif
44835 - ret = get_user_pages(current, bprm->mm, pos,
44836 - 1, write, 1, &page, NULL);
44837 - if (ret <= 0)
44838 + if (0 > expand_downwards(bprm->vma, pos))
44839 + return NULL;
44840 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44841 return NULL;
44842
44843 if (write) {
44844 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44845 if (size <= ARG_MAX)
44846 return page;
44847
44848 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44849 + // only allow 512KB for argv+env on suid/sgid binaries
44850 + // to prevent easy ASLR exhaustion
44851 + if (((bprm->cred->euid != current_euid()) ||
44852 + (bprm->cred->egid != current_egid())) &&
44853 + (size > (512 * 1024))) {
44854 + put_page(page);
44855 + return NULL;
44856 + }
44857 +#endif
44858 +
44859 /*
44860 * Limit to 1/4-th the stack size for the argv+env strings.
44861 * This ensures that:
44862 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44863 vma->vm_end = STACK_TOP_MAX;
44864 vma->vm_start = vma->vm_end - PAGE_SIZE;
44865 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44866 +
44867 +#ifdef CONFIG_PAX_SEGMEXEC
44868 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44869 +#endif
44870 +
44871 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44872 INIT_LIST_HEAD(&vma->anon_vma_chain);
44873
44874 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44875 mm->stack_vm = mm->total_vm = 1;
44876 up_write(&mm->mmap_sem);
44877 bprm->p = vma->vm_end - sizeof(void *);
44878 +
44879 +#ifdef CONFIG_PAX_RANDUSTACK
44880 + if (randomize_va_space)
44881 + bprm->p ^= random32() & ~PAGE_MASK;
44882 +#endif
44883 +
44884 return 0;
44885 err:
44886 up_write(&mm->mmap_sem);
44887 @@ -395,19 +430,7 @@ err:
44888 return err;
44889 }
44890
44891 -struct user_arg_ptr {
44892 -#ifdef CONFIG_COMPAT
44893 - bool is_compat;
44894 -#endif
44895 - union {
44896 - const char __user *const __user *native;
44897 -#ifdef CONFIG_COMPAT
44898 - compat_uptr_t __user *compat;
44899 -#endif
44900 - } ptr;
44901 -};
44902 -
44903 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44904 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44905 {
44906 const char __user *native;
44907
44908 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44909 compat_uptr_t compat;
44910
44911 if (get_user(compat, argv.ptr.compat + nr))
44912 - return ERR_PTR(-EFAULT);
44913 + return (const char __force_user *)ERR_PTR(-EFAULT);
44914
44915 return compat_ptr(compat);
44916 }
44917 #endif
44918
44919 if (get_user(native, argv.ptr.native + nr))
44920 - return ERR_PTR(-EFAULT);
44921 + return (const char __force_user *)ERR_PTR(-EFAULT);
44922
44923 return native;
44924 }
44925 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44926 if (!p)
44927 break;
44928
44929 - if (IS_ERR(p))
44930 + if (IS_ERR((const char __force_kernel *)p))
44931 return -EFAULT;
44932
44933 if (i++ >= max)
44934 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44935
44936 ret = -EFAULT;
44937 str = get_user_arg_ptr(argv, argc);
44938 - if (IS_ERR(str))
44939 + if (IS_ERR((const char __force_kernel *)str))
44940 goto out;
44941
44942 len = strnlen_user(str, MAX_ARG_STRLEN);
44943 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44944 int r;
44945 mm_segment_t oldfs = get_fs();
44946 struct user_arg_ptr argv = {
44947 - .ptr.native = (const char __user *const __user *)__argv,
44948 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44949 };
44950
44951 set_fs(KERNEL_DS);
44952 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44953 unsigned long new_end = old_end - shift;
44954 struct mmu_gather tlb;
44955
44956 - BUG_ON(new_start > new_end);
44957 + if (new_start >= new_end || new_start < mmap_min_addr)
44958 + return -ENOMEM;
44959
44960 /*
44961 * ensure there are no vmas between where we want to go
44962 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44963 if (vma != find_vma(mm, new_start))
44964 return -EFAULT;
44965
44966 +#ifdef CONFIG_PAX_SEGMEXEC
44967 + BUG_ON(pax_find_mirror_vma(vma));
44968 +#endif
44969 +
44970 /*
44971 * cover the whole range: [new_start, old_end)
44972 */
44973 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44974 stack_top = arch_align_stack(stack_top);
44975 stack_top = PAGE_ALIGN(stack_top);
44976
44977 - if (unlikely(stack_top < mmap_min_addr) ||
44978 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44979 - return -ENOMEM;
44980 -
44981 stack_shift = vma->vm_end - stack_top;
44982
44983 bprm->p -= stack_shift;
44984 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44985 bprm->exec -= stack_shift;
44986
44987 down_write(&mm->mmap_sem);
44988 +
44989 + /* Move stack pages down in memory. */
44990 + if (stack_shift) {
44991 + ret = shift_arg_pages(vma, stack_shift);
44992 + if (ret)
44993 + goto out_unlock;
44994 + }
44995 +
44996 vm_flags = VM_STACK_FLAGS;
44997
44998 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44999 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45000 + vm_flags &= ~VM_EXEC;
45001 +
45002 +#ifdef CONFIG_PAX_MPROTECT
45003 + if (mm->pax_flags & MF_PAX_MPROTECT)
45004 + vm_flags &= ~VM_MAYEXEC;
45005 +#endif
45006 +
45007 + }
45008 +#endif
45009 +
45010 /*
45011 * Adjust stack execute permissions; explicitly enable for
45012 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45013 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45014 goto out_unlock;
45015 BUG_ON(prev != vma);
45016
45017 - /* Move stack pages down in memory. */
45018 - if (stack_shift) {
45019 - ret = shift_arg_pages(vma, stack_shift);
45020 - if (ret)
45021 - goto out_unlock;
45022 - }
45023 -
45024 /* mprotect_fixup is overkill to remove the temporary stack flags */
45025 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45026
45027 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45028
45029 fsnotify_open(file);
45030
45031 + trace_open_exec(name);
45032 +
45033 err = deny_write_access(file);
45034 if (err)
45035 goto exit;
45036 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45037 old_fs = get_fs();
45038 set_fs(get_ds());
45039 /* The cast to a user pointer is valid due to the set_fs() */
45040 - result = vfs_read(file, (void __user *)addr, count, &pos);
45041 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45042 set_fs(old_fs);
45043 return result;
45044 }
45045 @@ -1258,7 +1297,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45046 }
45047 rcu_read_unlock();
45048
45049 - if (p->fs->users > n_fs) {
45050 + if (atomic_read(&p->fs->users) > n_fs) {
45051 bprm->unsafe |= LSM_UNSAFE_SHARE;
45052 } else {
45053 res = -EAGAIN;
45054 @@ -1461,6 +1500,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45055
45056 EXPORT_SYMBOL(search_binary_handler);
45057
45058 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45059 +static DEFINE_PER_CPU(u64, exec_counter);
45060 +static int __init init_exec_counters(void)
45061 +{
45062 + unsigned int cpu;
45063 +
45064 + for_each_possible_cpu(cpu) {
45065 + per_cpu(exec_counter, cpu) = (u64)cpu;
45066 + }
45067 +
45068 + return 0;
45069 +}
45070 +early_initcall(init_exec_counters);
45071 +static inline void increment_exec_counter(void)
45072 +{
45073 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45074 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45075 +}
45076 +#else
45077 +static inline void increment_exec_counter(void) {}
45078 +#endif
45079 +
45080 /*
45081 * sys_execve() executes a new program.
45082 */
45083 @@ -1469,6 +1530,11 @@ static int do_execve_common(const char *filename,
45084 struct user_arg_ptr envp,
45085 struct pt_regs *regs)
45086 {
45087 +#ifdef CONFIG_GRKERNSEC
45088 + struct file *old_exec_file;
45089 + struct acl_subject_label *old_acl;
45090 + struct rlimit old_rlim[RLIM_NLIMITS];
45091 +#endif
45092 struct linux_binprm *bprm;
45093 struct file *file;
45094 struct files_struct *displaced;
45095 @@ -1476,6 +1542,8 @@ static int do_execve_common(const char *filename,
45096 int retval;
45097 const struct cred *cred = current_cred();
45098
45099 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45100 +
45101 /*
45102 * We move the actual failure in case of RLIMIT_NPROC excess from
45103 * set*uid() to execve() because too many poorly written programs
45104 @@ -1516,12 +1584,27 @@ static int do_execve_common(const char *filename,
45105 if (IS_ERR(file))
45106 goto out_unmark;
45107
45108 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45109 + retval = -EPERM;
45110 + goto out_file;
45111 + }
45112 +
45113 sched_exec();
45114
45115 bprm->file = file;
45116 bprm->filename = filename;
45117 bprm->interp = filename;
45118
45119 + if (gr_process_user_ban()) {
45120 + retval = -EPERM;
45121 + goto out_file;
45122 + }
45123 +
45124 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45125 + retval = -EACCES;
45126 + goto out_file;
45127 + }
45128 +
45129 retval = bprm_mm_init(bprm);
45130 if (retval)
45131 goto out_file;
45132 @@ -1538,24 +1621,65 @@ static int do_execve_common(const char *filename,
45133 if (retval < 0)
45134 goto out;
45135
45136 +#ifdef CONFIG_GRKERNSEC
45137 + old_acl = current->acl;
45138 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45139 + old_exec_file = current->exec_file;
45140 + get_file(file);
45141 + current->exec_file = file;
45142 +#endif
45143 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45144 + /* limit suid stack to 8MB
45145 + we saved the old limits above and will restore them if this exec fails
45146 + */
45147 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45148 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45149 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45150 +#endif
45151 +
45152 + if (!gr_tpe_allow(file)) {
45153 + retval = -EACCES;
45154 + goto out_fail;
45155 + }
45156 +
45157 + if (gr_check_crash_exec(file)) {
45158 + retval = -EACCES;
45159 + goto out_fail;
45160 + }
45161 +
45162 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45163 + bprm->unsafe);
45164 + if (retval < 0)
45165 + goto out_fail;
45166 +
45167 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45168 if (retval < 0)
45169 - goto out;
45170 + goto out_fail;
45171
45172 bprm->exec = bprm->p;
45173 retval = copy_strings(bprm->envc, envp, bprm);
45174 if (retval < 0)
45175 - goto out;
45176 + goto out_fail;
45177
45178 retval = copy_strings(bprm->argc, argv, bprm);
45179 if (retval < 0)
45180 - goto out;
45181 + goto out_fail;
45182 +
45183 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45184 +
45185 + gr_handle_exec_args(bprm, argv);
45186
45187 retval = search_binary_handler(bprm,regs);
45188 if (retval < 0)
45189 - goto out;
45190 + goto out_fail;
45191 +#ifdef CONFIG_GRKERNSEC
45192 + if (old_exec_file)
45193 + fput(old_exec_file);
45194 +#endif
45195
45196 /* execve succeeded */
45197 +
45198 + increment_exec_counter();
45199 current->fs->in_exec = 0;
45200 current->in_execve = 0;
45201 acct_update_integrals(current);
45202 @@ -1564,6 +1688,14 @@ static int do_execve_common(const char *filename,
45203 put_files_struct(displaced);
45204 return retval;
45205
45206 +out_fail:
45207 +#ifdef CONFIG_GRKERNSEC
45208 + current->acl = old_acl;
45209 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45210 + fput(current->exec_file);
45211 + current->exec_file = old_exec_file;
45212 +#endif
45213 +
45214 out:
45215 if (bprm->mm) {
45216 acct_arg_size(bprm, 0);
45217 @@ -1637,7 +1769,7 @@ static int expand_corename(struct core_name *cn)
45218 {
45219 char *old_corename = cn->corename;
45220
45221 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45222 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45223 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45224
45225 if (!cn->corename) {
45226 @@ -1734,7 +1866,7 @@ static int format_corename(struct core_name *cn, long signr)
45227 int pid_in_pattern = 0;
45228 int err = 0;
45229
45230 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45231 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45232 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45233 cn->used = 0;
45234
45235 @@ -1831,6 +1963,250 @@ out:
45236 return ispipe;
45237 }
45238
45239 +int pax_check_flags(unsigned long *flags)
45240 +{
45241 + int retval = 0;
45242 +
45243 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45244 + if (*flags & MF_PAX_SEGMEXEC)
45245 + {
45246 + *flags &= ~MF_PAX_SEGMEXEC;
45247 + retval = -EINVAL;
45248 + }
45249 +#endif
45250 +
45251 + if ((*flags & MF_PAX_PAGEEXEC)
45252 +
45253 +#ifdef CONFIG_PAX_PAGEEXEC
45254 + && (*flags & MF_PAX_SEGMEXEC)
45255 +#endif
45256 +
45257 + )
45258 + {
45259 + *flags &= ~MF_PAX_PAGEEXEC;
45260 + retval = -EINVAL;
45261 + }
45262 +
45263 + if ((*flags & MF_PAX_MPROTECT)
45264 +
45265 +#ifdef CONFIG_PAX_MPROTECT
45266 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45267 +#endif
45268 +
45269 + )
45270 + {
45271 + *flags &= ~MF_PAX_MPROTECT;
45272 + retval = -EINVAL;
45273 + }
45274 +
45275 + if ((*flags & MF_PAX_EMUTRAMP)
45276 +
45277 +#ifdef CONFIG_PAX_EMUTRAMP
45278 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45279 +#endif
45280 +
45281 + )
45282 + {
45283 + *flags &= ~MF_PAX_EMUTRAMP;
45284 + retval = -EINVAL;
45285 + }
45286 +
45287 + return retval;
45288 +}
45289 +
45290 +EXPORT_SYMBOL(pax_check_flags);
45291 +
45292 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45293 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45294 +{
45295 + struct task_struct *tsk = current;
45296 + struct mm_struct *mm = current->mm;
45297 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45298 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45299 + char *path_exec = NULL;
45300 + char *path_fault = NULL;
45301 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45302 +
45303 + if (buffer_exec && buffer_fault) {
45304 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45305 +
45306 + down_read(&mm->mmap_sem);
45307 + vma = mm->mmap;
45308 + while (vma && (!vma_exec || !vma_fault)) {
45309 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45310 + vma_exec = vma;
45311 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45312 + vma_fault = vma;
45313 + vma = vma->vm_next;
45314 + }
45315 + if (vma_exec) {
45316 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45317 + if (IS_ERR(path_exec))
45318 + path_exec = "<path too long>";
45319 + else {
45320 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45321 + if (path_exec) {
45322 + *path_exec = 0;
45323 + path_exec = buffer_exec;
45324 + } else
45325 + path_exec = "<path too long>";
45326 + }
45327 + }
45328 + if (vma_fault) {
45329 + start = vma_fault->vm_start;
45330 + end = vma_fault->vm_end;
45331 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45332 + if (vma_fault->vm_file) {
45333 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45334 + if (IS_ERR(path_fault))
45335 + path_fault = "<path too long>";
45336 + else {
45337 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45338 + if (path_fault) {
45339 + *path_fault = 0;
45340 + path_fault = buffer_fault;
45341 + } else
45342 + path_fault = "<path too long>";
45343 + }
45344 + } else
45345 + path_fault = "<anonymous mapping>";
45346 + }
45347 + up_read(&mm->mmap_sem);
45348 + }
45349 + if (tsk->signal->curr_ip)
45350 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45351 + else
45352 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45353 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45354 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45355 + task_uid(tsk), task_euid(tsk), pc, sp);
45356 + free_page((unsigned long)buffer_exec);
45357 + free_page((unsigned long)buffer_fault);
45358 + pax_report_insns(regs, pc, sp);
45359 + do_coredump(SIGKILL, SIGKILL, regs);
45360 +}
45361 +#endif
45362 +
45363 +#ifdef CONFIG_PAX_REFCOUNT
45364 +void pax_report_refcount_overflow(struct pt_regs *regs)
45365 +{
45366 + if (current->signal->curr_ip)
45367 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45368 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45369 + else
45370 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45371 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45372 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45373 + show_regs(regs);
45374 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45375 +}
45376 +#endif
45377 +
45378 +#ifdef CONFIG_PAX_USERCOPY
45379 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45380 +static noinline int check_stack_object(const void *obj, unsigned long len)
45381 +{
45382 + const void * const stack = task_stack_page(current);
45383 + const void * const stackend = stack + THREAD_SIZE;
45384 +
45385 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45386 + const void *frame = NULL;
45387 + const void *oldframe;
45388 +#endif
45389 +
45390 + if (obj + len < obj)
45391 + return -1;
45392 +
45393 + if (obj + len <= stack || stackend <= obj)
45394 + return 0;
45395 +
45396 + if (obj < stack || stackend < obj + len)
45397 + return -1;
45398 +
45399 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45400 + oldframe = __builtin_frame_address(1);
45401 + if (oldframe)
45402 + frame = __builtin_frame_address(2);
45403 + /*
45404 + low ----------------------------------------------> high
45405 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45406 + ^----------------^
45407 + allow copies only within here
45408 + */
45409 + while (stack <= frame && frame < stackend) {
45410 + /* if obj + len extends past the last frame, this
45411 + check won't pass and the next frame will be 0,
45412 + causing us to bail out and correctly report
45413 + the copy as invalid
45414 + */
45415 + if (obj + len <= frame)
45416 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45417 + oldframe = frame;
45418 + frame = *(const void * const *)frame;
45419 + }
45420 + return -1;
45421 +#else
45422 + return 1;
45423 +#endif
45424 +}
45425 +
45426 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45427 +{
45428 + if (current->signal->curr_ip)
45429 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45430 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45431 + else
45432 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45433 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45434 + dump_stack();
45435 + gr_handle_kernel_exploit();
45436 + do_group_exit(SIGKILL);
45437 +}
45438 +#endif
45439 +
45440 +void check_object_size(const void *ptr, unsigned long n, bool to)
45441 +{
45442 +
45443 +#ifdef CONFIG_PAX_USERCOPY
45444 + const char *type;
45445 +
45446 + if (!n)
45447 + return;
45448 +
45449 + type = check_heap_object(ptr, n, to);
45450 + if (!type) {
45451 + if (check_stack_object(ptr, n) != -1)
45452 + return;
45453 + type = "<process stack>";
45454 + }
45455 +
45456 + pax_report_usercopy(ptr, n, to, type);
45457 +#endif
45458 +
45459 +}
45460 +EXPORT_SYMBOL(check_object_size);
45461 +
45462 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45463 +void pax_track_stack(void)
45464 +{
45465 + unsigned long sp = (unsigned long)&sp;
45466 + if (sp < current_thread_info()->lowest_stack &&
45467 + sp > (unsigned long)task_stack_page(current))
45468 + current_thread_info()->lowest_stack = sp;
45469 +}
45470 +EXPORT_SYMBOL(pax_track_stack);
45471 +#endif
45472 +
45473 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45474 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45475 +{
45476 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45477 + dump_stack();
45478 + do_group_exit(SIGKILL);
45479 +}
45480 +EXPORT_SYMBOL(report_size_overflow);
45481 +#endif
45482 +
45483 static int zap_process(struct task_struct *start, int exit_code)
45484 {
45485 struct task_struct *t;
45486 @@ -2041,17 +2417,17 @@ static void wait_for_dump_helpers(struct file *file)
45487 pipe = file->f_path.dentry->d_inode->i_pipe;
45488
45489 pipe_lock(pipe);
45490 - pipe->readers++;
45491 - pipe->writers--;
45492 + atomic_inc(&pipe->readers);
45493 + atomic_dec(&pipe->writers);
45494
45495 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45496 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45497 wake_up_interruptible_sync(&pipe->wait);
45498 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45499 pipe_wait(pipe);
45500 }
45501
45502 - pipe->readers--;
45503 - pipe->writers++;
45504 + atomic_dec(&pipe->readers);
45505 + atomic_inc(&pipe->writers);
45506 pipe_unlock(pipe);
45507
45508 }
45509 @@ -2106,7 +2482,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45510 int flag = 0;
45511 int ispipe;
45512 bool need_nonrelative = false;
45513 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45514 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45515 struct coredump_params cprm = {
45516 .signr = signr,
45517 .regs = regs,
45518 @@ -2121,6 +2497,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45519
45520 audit_core_dumps(signr);
45521
45522 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45523 + gr_handle_brute_attach(current, cprm.mm_flags);
45524 +
45525 binfmt = mm->binfmt;
45526 if (!binfmt || !binfmt->core_dump)
45527 goto fail;
45528 @@ -2191,7 +2570,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45529 }
45530 cprm.limit = RLIM_INFINITY;
45531
45532 - dump_count = atomic_inc_return(&core_dump_count);
45533 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45534 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45535 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45536 task_tgid_vnr(current), current->comm);
45537 @@ -2218,6 +2597,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45538 } else {
45539 struct inode *inode;
45540
45541 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45542 +
45543 if (cprm.limit < binfmt->min_coredump)
45544 goto fail_unlock;
45545
45546 @@ -2269,7 +2650,7 @@ close_fail:
45547 filp_close(cprm.file, NULL);
45548 fail_dropcount:
45549 if (ispipe)
45550 - atomic_dec(&core_dump_count);
45551 + atomic_dec_unchecked(&core_dump_count);
45552 fail_unlock:
45553 kfree(cn.corename);
45554 fail_corename:
45555 @@ -2288,7 +2669,7 @@ fail:
45556 */
45557 int dump_write(struct file *file, const void *addr, int nr)
45558 {
45559 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45560 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45561 }
45562 EXPORT_SYMBOL(dump_write);
45563
45564 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45565 index 376aa77..59a129c 100644
45566 --- a/fs/ext2/balloc.c
45567 +++ b/fs/ext2/balloc.c
45568 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45569
45570 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45571 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45572 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45573 + if (free_blocks < root_blocks + 1 &&
45574 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45575 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45576 - !in_group_p (sbi->s_resgid))) {
45577 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45578 return 0;
45579 }
45580 return 1;
45581 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45582 index 90d901f..159975f 100644
45583 --- a/fs/ext3/balloc.c
45584 +++ b/fs/ext3/balloc.c
45585 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45586
45587 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45588 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45589 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45590 + if (free_blocks < root_blocks + 1 &&
45591 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45592 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45593 - !in_group_p (sbi->s_resgid))) {
45594 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45595 return 0;
45596 }
45597 return 1;
45598 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45599 index cf18217..8f6b9c3 100644
45600 --- a/fs/ext4/balloc.c
45601 +++ b/fs/ext4/balloc.c
45602 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45603 /* Hm, nope. Are (enough) root reserved clusters available? */
45604 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45605 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45606 - capable(CAP_SYS_RESOURCE) ||
45607 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45608 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45609 + capable_nolog(CAP_SYS_RESOURCE)) {
45610
45611 if (free_clusters >= (nclusters + dirty_clusters))
45612 return 1;
45613 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45614 index 5c69f2b..05dec7f 100644
45615 --- a/fs/ext4/ext4.h
45616 +++ b/fs/ext4/ext4.h
45617 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45618 unsigned long s_mb_last_start;
45619
45620 /* stats for buddy allocator */
45621 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45622 - atomic_t s_bal_success; /* we found long enough chunks */
45623 - atomic_t s_bal_allocated; /* in blocks */
45624 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45625 - atomic_t s_bal_goals; /* goal hits */
45626 - atomic_t s_bal_breaks; /* too long searches */
45627 - atomic_t s_bal_2orders; /* 2^order hits */
45628 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45629 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45630 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45631 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45632 + atomic_unchecked_t s_bal_goals; /* goal hits */
45633 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45634 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45635 spinlock_t s_bal_lock;
45636 unsigned long s_mb_buddies_generated;
45637 unsigned long long s_mb_generation_time;
45638 - atomic_t s_mb_lost_chunks;
45639 - atomic_t s_mb_preallocated;
45640 - atomic_t s_mb_discarded;
45641 + atomic_unchecked_t s_mb_lost_chunks;
45642 + atomic_unchecked_t s_mb_preallocated;
45643 + atomic_unchecked_t s_mb_discarded;
45644 atomic_t s_lock_busy;
45645
45646 /* locality groups */
45647 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45648 index b26410c..7383d90 100644
45649 --- a/fs/ext4/mballoc.c
45650 +++ b/fs/ext4/mballoc.c
45651 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45652 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45653
45654 if (EXT4_SB(sb)->s_mb_stats)
45655 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45656 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45657
45658 break;
45659 }
45660 @@ -2040,7 +2040,7 @@ repeat:
45661 ac->ac_status = AC_STATUS_CONTINUE;
45662 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45663 cr = 3;
45664 - atomic_inc(&sbi->s_mb_lost_chunks);
45665 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45666 goto repeat;
45667 }
45668 }
45669 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45670 if (sbi->s_mb_stats) {
45671 ext4_msg(sb, KERN_INFO,
45672 "mballoc: %u blocks %u reqs (%u success)",
45673 - atomic_read(&sbi->s_bal_allocated),
45674 - atomic_read(&sbi->s_bal_reqs),
45675 - atomic_read(&sbi->s_bal_success));
45676 + atomic_read_unchecked(&sbi->s_bal_allocated),
45677 + atomic_read_unchecked(&sbi->s_bal_reqs),
45678 + atomic_read_unchecked(&sbi->s_bal_success));
45679 ext4_msg(sb, KERN_INFO,
45680 "mballoc: %u extents scanned, %u goal hits, "
45681 "%u 2^N hits, %u breaks, %u lost",
45682 - atomic_read(&sbi->s_bal_ex_scanned),
45683 - atomic_read(&sbi->s_bal_goals),
45684 - atomic_read(&sbi->s_bal_2orders),
45685 - atomic_read(&sbi->s_bal_breaks),
45686 - atomic_read(&sbi->s_mb_lost_chunks));
45687 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45688 + atomic_read_unchecked(&sbi->s_bal_goals),
45689 + atomic_read_unchecked(&sbi->s_bal_2orders),
45690 + atomic_read_unchecked(&sbi->s_bal_breaks),
45691 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45692 ext4_msg(sb, KERN_INFO,
45693 "mballoc: %lu generated and it took %Lu",
45694 sbi->s_mb_buddies_generated,
45695 sbi->s_mb_generation_time);
45696 ext4_msg(sb, KERN_INFO,
45697 "mballoc: %u preallocated, %u discarded",
45698 - atomic_read(&sbi->s_mb_preallocated),
45699 - atomic_read(&sbi->s_mb_discarded));
45700 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45701 + atomic_read_unchecked(&sbi->s_mb_discarded));
45702 }
45703
45704 free_percpu(sbi->s_locality_groups);
45705 @@ -3051,16 +3051,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45706 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45707
45708 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45709 - atomic_inc(&sbi->s_bal_reqs);
45710 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45711 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45712 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45713 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45714 - atomic_inc(&sbi->s_bal_success);
45715 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45716 + atomic_inc_unchecked(&sbi->s_bal_success);
45717 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45718 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45719 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45720 - atomic_inc(&sbi->s_bal_goals);
45721 + atomic_inc_unchecked(&sbi->s_bal_goals);
45722 if (ac->ac_found > sbi->s_mb_max_to_scan)
45723 - atomic_inc(&sbi->s_bal_breaks);
45724 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45725 }
45726
45727 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45728 @@ -3460,7 +3460,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45729 trace_ext4_mb_new_inode_pa(ac, pa);
45730
45731 ext4_mb_use_inode_pa(ac, pa);
45732 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45733 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45734
45735 ei = EXT4_I(ac->ac_inode);
45736 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45737 @@ -3520,7 +3520,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45738 trace_ext4_mb_new_group_pa(ac, pa);
45739
45740 ext4_mb_use_group_pa(ac, pa);
45741 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45742 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45743
45744 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45745 lg = ac->ac_lg;
45746 @@ -3609,7 +3609,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45747 * from the bitmap and continue.
45748 */
45749 }
45750 - atomic_add(free, &sbi->s_mb_discarded);
45751 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45752
45753 return err;
45754 }
45755 @@ -3627,7 +3627,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45756 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45757 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45758 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45759 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45760 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45761 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45762
45763 return 0;
45764 diff --git a/fs/fcntl.c b/fs/fcntl.c
45765 index 887b5ba..0e3f2c3 100644
45766 --- a/fs/fcntl.c
45767 +++ b/fs/fcntl.c
45768 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45769 if (err)
45770 return err;
45771
45772 + if (gr_handle_chroot_fowner(pid, type))
45773 + return -ENOENT;
45774 + if (gr_check_protected_task_fowner(pid, type))
45775 + return -EACCES;
45776 +
45777 f_modown(filp, pid, type, force);
45778 return 0;
45779 }
45780 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45781
45782 static int f_setown_ex(struct file *filp, unsigned long arg)
45783 {
45784 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45785 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45786 struct f_owner_ex owner;
45787 struct pid *pid;
45788 int type;
45789 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45790
45791 static int f_getown_ex(struct file *filp, unsigned long arg)
45792 {
45793 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45794 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45795 struct f_owner_ex owner;
45796 int ret = 0;
45797
45798 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45799 switch (cmd) {
45800 case F_DUPFD:
45801 case F_DUPFD_CLOEXEC:
45802 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45803 if (arg >= rlimit(RLIMIT_NOFILE))
45804 break;
45805 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45806 diff --git a/fs/fifo.c b/fs/fifo.c
45807 index cf6f434..3d7942c 100644
45808 --- a/fs/fifo.c
45809 +++ b/fs/fifo.c
45810 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45811 */
45812 filp->f_op = &read_pipefifo_fops;
45813 pipe->r_counter++;
45814 - if (pipe->readers++ == 0)
45815 + if (atomic_inc_return(&pipe->readers) == 1)
45816 wake_up_partner(inode);
45817
45818 - if (!pipe->writers) {
45819 + if (!atomic_read(&pipe->writers)) {
45820 if ((filp->f_flags & O_NONBLOCK)) {
45821 /* suppress POLLHUP until we have
45822 * seen a writer */
45823 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45824 * errno=ENXIO when there is no process reading the FIFO.
45825 */
45826 ret = -ENXIO;
45827 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45828 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45829 goto err;
45830
45831 filp->f_op = &write_pipefifo_fops;
45832 pipe->w_counter++;
45833 - if (!pipe->writers++)
45834 + if (atomic_inc_return(&pipe->writers) == 1)
45835 wake_up_partner(inode);
45836
45837 - if (!pipe->readers) {
45838 + if (!atomic_read(&pipe->readers)) {
45839 if (wait_for_partner(inode, &pipe->r_counter))
45840 goto err_wr;
45841 }
45842 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45843 */
45844 filp->f_op = &rdwr_pipefifo_fops;
45845
45846 - pipe->readers++;
45847 - pipe->writers++;
45848 + atomic_inc(&pipe->readers);
45849 + atomic_inc(&pipe->writers);
45850 pipe->r_counter++;
45851 pipe->w_counter++;
45852 - if (pipe->readers == 1 || pipe->writers == 1)
45853 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45854 wake_up_partner(inode);
45855 break;
45856
45857 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45858 return 0;
45859
45860 err_rd:
45861 - if (!--pipe->readers)
45862 + if (atomic_dec_and_test(&pipe->readers))
45863 wake_up_interruptible(&pipe->wait);
45864 ret = -ERESTARTSYS;
45865 goto err;
45866
45867 err_wr:
45868 - if (!--pipe->writers)
45869 + if (atomic_dec_and_test(&pipe->writers))
45870 wake_up_interruptible(&pipe->wait);
45871 ret = -ERESTARTSYS;
45872 goto err;
45873
45874 err:
45875 - if (!pipe->readers && !pipe->writers)
45876 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45877 free_pipe_info(inode);
45878
45879 err_nocleanup:
45880 diff --git a/fs/file.c b/fs/file.c
45881 index ba3f605..fade102 100644
45882 --- a/fs/file.c
45883 +++ b/fs/file.c
45884 @@ -15,6 +15,7 @@
45885 #include <linux/slab.h>
45886 #include <linux/vmalloc.h>
45887 #include <linux/file.h>
45888 +#include <linux/security.h>
45889 #include <linux/fdtable.h>
45890 #include <linux/bitops.h>
45891 #include <linux/interrupt.h>
45892 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45893 * N.B. For clone tasks sharing a files structure, this test
45894 * will limit the total number of files that can be opened.
45895 */
45896 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45897 if (nr >= rlimit(RLIMIT_NOFILE))
45898 return -EMFILE;
45899
45900 diff --git a/fs/filesystems.c b/fs/filesystems.c
45901 index 96f2428..f5eeb8e 100644
45902 --- a/fs/filesystems.c
45903 +++ b/fs/filesystems.c
45904 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45905 int len = dot ? dot - name : strlen(name);
45906
45907 fs = __get_fs_type(name, len);
45908 +
45909 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45910 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45911 +#else
45912 if (!fs && (request_module("%.*s", len, name) == 0))
45913 +#endif
45914 fs = __get_fs_type(name, len);
45915
45916 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45917 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45918 index 5df4775..9d9336f 100644
45919 --- a/fs/fs_struct.c
45920 +++ b/fs/fs_struct.c
45921 @@ -4,6 +4,7 @@
45922 #include <linux/path.h>
45923 #include <linux/slab.h>
45924 #include <linux/fs_struct.h>
45925 +#include <linux/grsecurity.h>
45926 #include "internal.h"
45927
45928 /*
45929 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45930 write_seqcount_begin(&fs->seq);
45931 old_root = fs->root;
45932 fs->root = *path;
45933 + gr_set_chroot_entries(current, path);
45934 write_seqcount_end(&fs->seq);
45935 spin_unlock(&fs->lock);
45936 if (old_root.dentry)
45937 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45938 return 1;
45939 }
45940
45941 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45942 +{
45943 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45944 + return 0;
45945 + *p = *new;
45946 +
45947 + /* This function is only called from pivot_root(). Leave our
45948 + gr_chroot_dentry and is_chrooted flags as-is, so that a
45949 + pivoted root isn't treated as a chroot
45950 + */
45951 + //gr_set_chroot_entries(task, new);
45952 +
45953 + return 1;
45954 +}
45955 +
45956 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45957 {
45958 struct task_struct *g, *p;
45959 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45960 int hits = 0;
45961 spin_lock(&fs->lock);
45962 write_seqcount_begin(&fs->seq);
45963 - hits += replace_path(&fs->root, old_root, new_root);
45964 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45965 hits += replace_path(&fs->pwd, old_root, new_root);
45966 write_seqcount_end(&fs->seq);
45967 while (hits--) {
45968 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
45969 task_lock(tsk);
45970 spin_lock(&fs->lock);
45971 tsk->fs = NULL;
45972 - kill = !--fs->users;
45973 + gr_clear_chroot_entries(tsk);
45974 + kill = !atomic_dec_return(&fs->users);
45975 spin_unlock(&fs->lock);
45976 task_unlock(tsk);
45977 if (kill)
45978 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45979 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45980 /* We don't need to lock fs - think why ;-) */
45981 if (fs) {
45982 - fs->users = 1;
45983 + atomic_set(&fs->users, 1);
45984 fs->in_exec = 0;
45985 spin_lock_init(&fs->lock);
45986 seqcount_init(&fs->seq);
45987 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45988 spin_lock(&old->lock);
45989 fs->root = old->root;
45990 path_get(&fs->root);
45991 + /* instead of calling gr_set_chroot_entries here,
45992 + we call it from every caller of this function
45993 + */
45994 fs->pwd = old->pwd;
45995 path_get(&fs->pwd);
45996 spin_unlock(&old->lock);
45997 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
45998
45999 task_lock(current);
46000 spin_lock(&fs->lock);
46001 - kill = !--fs->users;
46002 + kill = !atomic_dec_return(&fs->users);
46003 current->fs = new_fs;
46004 + gr_set_chroot_entries(current, &new_fs->root);
46005 spin_unlock(&fs->lock);
46006 task_unlock(current);
46007
46008 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46009
46010 int current_umask(void)
46011 {
46012 - return current->fs->umask;
46013 + return current->fs->umask | gr_acl_umask();
46014 }
46015 EXPORT_SYMBOL(current_umask);
46016
46017 /* to be mentioned only in INIT_TASK */
46018 struct fs_struct init_fs = {
46019 - .users = 1,
46020 + .users = ATOMIC_INIT(1),
46021 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46022 .seq = SEQCNT_ZERO,
46023 .umask = 0022,
46024 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46025 task_lock(current);
46026
46027 spin_lock(&init_fs.lock);
46028 - init_fs.users++;
46029 + atomic_inc(&init_fs.users);
46030 spin_unlock(&init_fs.lock);
46031
46032 spin_lock(&fs->lock);
46033 current->fs = &init_fs;
46034 - kill = !--fs->users;
46035 + gr_set_chroot_entries(current, &current->fs->root);
46036 + kill = !atomic_dec_return(&fs->users);
46037 spin_unlock(&fs->lock);
46038
46039 task_unlock(current);
46040 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46041 index 9905350..02eaec4 100644
46042 --- a/fs/fscache/cookie.c
46043 +++ b/fs/fscache/cookie.c
46044 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46045 parent ? (char *) parent->def->name : "<no-parent>",
46046 def->name, netfs_data);
46047
46048 - fscache_stat(&fscache_n_acquires);
46049 + fscache_stat_unchecked(&fscache_n_acquires);
46050
46051 /* if there's no parent cookie, then we don't create one here either */
46052 if (!parent) {
46053 - fscache_stat(&fscache_n_acquires_null);
46054 + fscache_stat_unchecked(&fscache_n_acquires_null);
46055 _leave(" [no parent]");
46056 return NULL;
46057 }
46058 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46059 /* allocate and initialise a cookie */
46060 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46061 if (!cookie) {
46062 - fscache_stat(&fscache_n_acquires_oom);
46063 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46064 _leave(" [ENOMEM]");
46065 return NULL;
46066 }
46067 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46068
46069 switch (cookie->def->type) {
46070 case FSCACHE_COOKIE_TYPE_INDEX:
46071 - fscache_stat(&fscache_n_cookie_index);
46072 + fscache_stat_unchecked(&fscache_n_cookie_index);
46073 break;
46074 case FSCACHE_COOKIE_TYPE_DATAFILE:
46075 - fscache_stat(&fscache_n_cookie_data);
46076 + fscache_stat_unchecked(&fscache_n_cookie_data);
46077 break;
46078 default:
46079 - fscache_stat(&fscache_n_cookie_special);
46080 + fscache_stat_unchecked(&fscache_n_cookie_special);
46081 break;
46082 }
46083
46084 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46085 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46086 atomic_dec(&parent->n_children);
46087 __fscache_cookie_put(cookie);
46088 - fscache_stat(&fscache_n_acquires_nobufs);
46089 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46090 _leave(" = NULL");
46091 return NULL;
46092 }
46093 }
46094
46095 - fscache_stat(&fscache_n_acquires_ok);
46096 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46097 _leave(" = %p", cookie);
46098 return cookie;
46099 }
46100 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46101 cache = fscache_select_cache_for_object(cookie->parent);
46102 if (!cache) {
46103 up_read(&fscache_addremove_sem);
46104 - fscache_stat(&fscache_n_acquires_no_cache);
46105 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46106 _leave(" = -ENOMEDIUM [no cache]");
46107 return -ENOMEDIUM;
46108 }
46109 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46110 object = cache->ops->alloc_object(cache, cookie);
46111 fscache_stat_d(&fscache_n_cop_alloc_object);
46112 if (IS_ERR(object)) {
46113 - fscache_stat(&fscache_n_object_no_alloc);
46114 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46115 ret = PTR_ERR(object);
46116 goto error;
46117 }
46118
46119 - fscache_stat(&fscache_n_object_alloc);
46120 + fscache_stat_unchecked(&fscache_n_object_alloc);
46121
46122 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46123
46124 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46125 struct fscache_object *object;
46126 struct hlist_node *_p;
46127
46128 - fscache_stat(&fscache_n_updates);
46129 + fscache_stat_unchecked(&fscache_n_updates);
46130
46131 if (!cookie) {
46132 - fscache_stat(&fscache_n_updates_null);
46133 + fscache_stat_unchecked(&fscache_n_updates_null);
46134 _leave(" [no cookie]");
46135 return;
46136 }
46137 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46138 struct fscache_object *object;
46139 unsigned long event;
46140
46141 - fscache_stat(&fscache_n_relinquishes);
46142 + fscache_stat_unchecked(&fscache_n_relinquishes);
46143 if (retire)
46144 - fscache_stat(&fscache_n_relinquishes_retire);
46145 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46146
46147 if (!cookie) {
46148 - fscache_stat(&fscache_n_relinquishes_null);
46149 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46150 _leave(" [no cookie]");
46151 return;
46152 }
46153 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46154
46155 /* wait for the cookie to finish being instantiated (or to fail) */
46156 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46157 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46158 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46159 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46160 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46161 }
46162 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46163 index f6aad48..88dcf26 100644
46164 --- a/fs/fscache/internal.h
46165 +++ b/fs/fscache/internal.h
46166 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46167 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46168 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46169
46170 -extern atomic_t fscache_n_op_pend;
46171 -extern atomic_t fscache_n_op_run;
46172 -extern atomic_t fscache_n_op_enqueue;
46173 -extern atomic_t fscache_n_op_deferred_release;
46174 -extern atomic_t fscache_n_op_release;
46175 -extern atomic_t fscache_n_op_gc;
46176 -extern atomic_t fscache_n_op_cancelled;
46177 -extern atomic_t fscache_n_op_rejected;
46178 +extern atomic_unchecked_t fscache_n_op_pend;
46179 +extern atomic_unchecked_t fscache_n_op_run;
46180 +extern atomic_unchecked_t fscache_n_op_enqueue;
46181 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46182 +extern atomic_unchecked_t fscache_n_op_release;
46183 +extern atomic_unchecked_t fscache_n_op_gc;
46184 +extern atomic_unchecked_t fscache_n_op_cancelled;
46185 +extern atomic_unchecked_t fscache_n_op_rejected;
46186
46187 -extern atomic_t fscache_n_attr_changed;
46188 -extern atomic_t fscache_n_attr_changed_ok;
46189 -extern atomic_t fscache_n_attr_changed_nobufs;
46190 -extern atomic_t fscache_n_attr_changed_nomem;
46191 -extern atomic_t fscache_n_attr_changed_calls;
46192 +extern atomic_unchecked_t fscache_n_attr_changed;
46193 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46194 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46195 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46196 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46197
46198 -extern atomic_t fscache_n_allocs;
46199 -extern atomic_t fscache_n_allocs_ok;
46200 -extern atomic_t fscache_n_allocs_wait;
46201 -extern atomic_t fscache_n_allocs_nobufs;
46202 -extern atomic_t fscache_n_allocs_intr;
46203 -extern atomic_t fscache_n_allocs_object_dead;
46204 -extern atomic_t fscache_n_alloc_ops;
46205 -extern atomic_t fscache_n_alloc_op_waits;
46206 +extern atomic_unchecked_t fscache_n_allocs;
46207 +extern atomic_unchecked_t fscache_n_allocs_ok;
46208 +extern atomic_unchecked_t fscache_n_allocs_wait;
46209 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46210 +extern atomic_unchecked_t fscache_n_allocs_intr;
46211 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46212 +extern atomic_unchecked_t fscache_n_alloc_ops;
46213 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46214
46215 -extern atomic_t fscache_n_retrievals;
46216 -extern atomic_t fscache_n_retrievals_ok;
46217 -extern atomic_t fscache_n_retrievals_wait;
46218 -extern atomic_t fscache_n_retrievals_nodata;
46219 -extern atomic_t fscache_n_retrievals_nobufs;
46220 -extern atomic_t fscache_n_retrievals_intr;
46221 -extern atomic_t fscache_n_retrievals_nomem;
46222 -extern atomic_t fscache_n_retrievals_object_dead;
46223 -extern atomic_t fscache_n_retrieval_ops;
46224 -extern atomic_t fscache_n_retrieval_op_waits;
46225 +extern atomic_unchecked_t fscache_n_retrievals;
46226 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46227 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46228 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46229 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46230 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46231 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46232 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46233 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46234 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46235
46236 -extern atomic_t fscache_n_stores;
46237 -extern atomic_t fscache_n_stores_ok;
46238 -extern atomic_t fscache_n_stores_again;
46239 -extern atomic_t fscache_n_stores_nobufs;
46240 -extern atomic_t fscache_n_stores_oom;
46241 -extern atomic_t fscache_n_store_ops;
46242 -extern atomic_t fscache_n_store_calls;
46243 -extern atomic_t fscache_n_store_pages;
46244 -extern atomic_t fscache_n_store_radix_deletes;
46245 -extern atomic_t fscache_n_store_pages_over_limit;
46246 +extern atomic_unchecked_t fscache_n_stores;
46247 +extern atomic_unchecked_t fscache_n_stores_ok;
46248 +extern atomic_unchecked_t fscache_n_stores_again;
46249 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46250 +extern atomic_unchecked_t fscache_n_stores_oom;
46251 +extern atomic_unchecked_t fscache_n_store_ops;
46252 +extern atomic_unchecked_t fscache_n_store_calls;
46253 +extern atomic_unchecked_t fscache_n_store_pages;
46254 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46255 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46256
46257 -extern atomic_t fscache_n_store_vmscan_not_storing;
46258 -extern atomic_t fscache_n_store_vmscan_gone;
46259 -extern atomic_t fscache_n_store_vmscan_busy;
46260 -extern atomic_t fscache_n_store_vmscan_cancelled;
46261 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46262 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46263 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46264 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46265
46266 -extern atomic_t fscache_n_marks;
46267 -extern atomic_t fscache_n_uncaches;
46268 +extern atomic_unchecked_t fscache_n_marks;
46269 +extern atomic_unchecked_t fscache_n_uncaches;
46270
46271 -extern atomic_t fscache_n_acquires;
46272 -extern atomic_t fscache_n_acquires_null;
46273 -extern atomic_t fscache_n_acquires_no_cache;
46274 -extern atomic_t fscache_n_acquires_ok;
46275 -extern atomic_t fscache_n_acquires_nobufs;
46276 -extern atomic_t fscache_n_acquires_oom;
46277 +extern atomic_unchecked_t fscache_n_acquires;
46278 +extern atomic_unchecked_t fscache_n_acquires_null;
46279 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46280 +extern atomic_unchecked_t fscache_n_acquires_ok;
46281 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46282 +extern atomic_unchecked_t fscache_n_acquires_oom;
46283
46284 -extern atomic_t fscache_n_updates;
46285 -extern atomic_t fscache_n_updates_null;
46286 -extern atomic_t fscache_n_updates_run;
46287 +extern atomic_unchecked_t fscache_n_updates;
46288 +extern atomic_unchecked_t fscache_n_updates_null;
46289 +extern atomic_unchecked_t fscache_n_updates_run;
46290
46291 -extern atomic_t fscache_n_relinquishes;
46292 -extern atomic_t fscache_n_relinquishes_null;
46293 -extern atomic_t fscache_n_relinquishes_waitcrt;
46294 -extern atomic_t fscache_n_relinquishes_retire;
46295 +extern atomic_unchecked_t fscache_n_relinquishes;
46296 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46297 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46298 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46299
46300 -extern atomic_t fscache_n_cookie_index;
46301 -extern atomic_t fscache_n_cookie_data;
46302 -extern atomic_t fscache_n_cookie_special;
46303 +extern atomic_unchecked_t fscache_n_cookie_index;
46304 +extern atomic_unchecked_t fscache_n_cookie_data;
46305 +extern atomic_unchecked_t fscache_n_cookie_special;
46306
46307 -extern atomic_t fscache_n_object_alloc;
46308 -extern atomic_t fscache_n_object_no_alloc;
46309 -extern atomic_t fscache_n_object_lookups;
46310 -extern atomic_t fscache_n_object_lookups_negative;
46311 -extern atomic_t fscache_n_object_lookups_positive;
46312 -extern atomic_t fscache_n_object_lookups_timed_out;
46313 -extern atomic_t fscache_n_object_created;
46314 -extern atomic_t fscache_n_object_avail;
46315 -extern atomic_t fscache_n_object_dead;
46316 +extern atomic_unchecked_t fscache_n_object_alloc;
46317 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46318 +extern atomic_unchecked_t fscache_n_object_lookups;
46319 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46320 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46321 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46322 +extern atomic_unchecked_t fscache_n_object_created;
46323 +extern atomic_unchecked_t fscache_n_object_avail;
46324 +extern atomic_unchecked_t fscache_n_object_dead;
46325
46326 -extern atomic_t fscache_n_checkaux_none;
46327 -extern atomic_t fscache_n_checkaux_okay;
46328 -extern atomic_t fscache_n_checkaux_update;
46329 -extern atomic_t fscache_n_checkaux_obsolete;
46330 +extern atomic_unchecked_t fscache_n_checkaux_none;
46331 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46332 +extern atomic_unchecked_t fscache_n_checkaux_update;
46333 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46334
46335 extern atomic_t fscache_n_cop_alloc_object;
46336 extern atomic_t fscache_n_cop_lookup_object;
46337 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46338 atomic_inc(stat);
46339 }
46340
46341 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46342 +{
46343 + atomic_inc_unchecked(stat);
46344 +}
46345 +
46346 static inline void fscache_stat_d(atomic_t *stat)
46347 {
46348 atomic_dec(stat);
46349 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46350
46351 #define __fscache_stat(stat) (NULL)
46352 #define fscache_stat(stat) do {} while (0)
46353 +#define fscache_stat_unchecked(stat) do {} while (0)
46354 #define fscache_stat_d(stat) do {} while (0)
46355 #endif
46356
46357 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46358 index b6b897c..0ffff9c 100644
46359 --- a/fs/fscache/object.c
46360 +++ b/fs/fscache/object.c
46361 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46362 /* update the object metadata on disk */
46363 case FSCACHE_OBJECT_UPDATING:
46364 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46365 - fscache_stat(&fscache_n_updates_run);
46366 + fscache_stat_unchecked(&fscache_n_updates_run);
46367 fscache_stat(&fscache_n_cop_update_object);
46368 object->cache->ops->update_object(object);
46369 fscache_stat_d(&fscache_n_cop_update_object);
46370 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46371 spin_lock(&object->lock);
46372 object->state = FSCACHE_OBJECT_DEAD;
46373 spin_unlock(&object->lock);
46374 - fscache_stat(&fscache_n_object_dead);
46375 + fscache_stat_unchecked(&fscache_n_object_dead);
46376 goto terminal_transit;
46377
46378 /* handle the parent cache of this object being withdrawn from
46379 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46380 spin_lock(&object->lock);
46381 object->state = FSCACHE_OBJECT_DEAD;
46382 spin_unlock(&object->lock);
46383 - fscache_stat(&fscache_n_object_dead);
46384 + fscache_stat_unchecked(&fscache_n_object_dead);
46385 goto terminal_transit;
46386
46387 /* complain about the object being woken up once it is
46388 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46389 parent->cookie->def->name, cookie->def->name,
46390 object->cache->tag->name);
46391
46392 - fscache_stat(&fscache_n_object_lookups);
46393 + fscache_stat_unchecked(&fscache_n_object_lookups);
46394 fscache_stat(&fscache_n_cop_lookup_object);
46395 ret = object->cache->ops->lookup_object(object);
46396 fscache_stat_d(&fscache_n_cop_lookup_object);
46397 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46398 if (ret == -ETIMEDOUT) {
46399 /* probably stuck behind another object, so move this one to
46400 * the back of the queue */
46401 - fscache_stat(&fscache_n_object_lookups_timed_out);
46402 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46403 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46404 }
46405
46406 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46407
46408 spin_lock(&object->lock);
46409 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46410 - fscache_stat(&fscache_n_object_lookups_negative);
46411 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46412
46413 /* transit here to allow write requests to begin stacking up
46414 * and read requests to begin returning ENODATA */
46415 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46416 * result, in which case there may be data available */
46417 spin_lock(&object->lock);
46418 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46419 - fscache_stat(&fscache_n_object_lookups_positive);
46420 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46421
46422 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46423
46424 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46425 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46426 } else {
46427 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46428 - fscache_stat(&fscache_n_object_created);
46429 + fscache_stat_unchecked(&fscache_n_object_created);
46430
46431 object->state = FSCACHE_OBJECT_AVAILABLE;
46432 spin_unlock(&object->lock);
46433 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46434 fscache_enqueue_dependents(object);
46435
46436 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46437 - fscache_stat(&fscache_n_object_avail);
46438 + fscache_stat_unchecked(&fscache_n_object_avail);
46439
46440 _leave("");
46441 }
46442 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46443 enum fscache_checkaux result;
46444
46445 if (!object->cookie->def->check_aux) {
46446 - fscache_stat(&fscache_n_checkaux_none);
46447 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46448 return FSCACHE_CHECKAUX_OKAY;
46449 }
46450
46451 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46452 switch (result) {
46453 /* entry okay as is */
46454 case FSCACHE_CHECKAUX_OKAY:
46455 - fscache_stat(&fscache_n_checkaux_okay);
46456 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46457 break;
46458
46459 /* entry requires update */
46460 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46461 - fscache_stat(&fscache_n_checkaux_update);
46462 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46463 break;
46464
46465 /* entry requires deletion */
46466 case FSCACHE_CHECKAUX_OBSOLETE:
46467 - fscache_stat(&fscache_n_checkaux_obsolete);
46468 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46469 break;
46470
46471 default:
46472 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46473 index 30afdfa..2256596 100644
46474 --- a/fs/fscache/operation.c
46475 +++ b/fs/fscache/operation.c
46476 @@ -17,7 +17,7 @@
46477 #include <linux/slab.h>
46478 #include "internal.h"
46479
46480 -atomic_t fscache_op_debug_id;
46481 +atomic_unchecked_t fscache_op_debug_id;
46482 EXPORT_SYMBOL(fscache_op_debug_id);
46483
46484 /**
46485 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46486 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46487 ASSERTCMP(atomic_read(&op->usage), >, 0);
46488
46489 - fscache_stat(&fscache_n_op_enqueue);
46490 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46491 switch (op->flags & FSCACHE_OP_TYPE) {
46492 case FSCACHE_OP_ASYNC:
46493 _debug("queue async");
46494 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46495 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46496 if (op->processor)
46497 fscache_enqueue_operation(op);
46498 - fscache_stat(&fscache_n_op_run);
46499 + fscache_stat_unchecked(&fscache_n_op_run);
46500 }
46501
46502 /*
46503 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46504 if (object->n_ops > 1) {
46505 atomic_inc(&op->usage);
46506 list_add_tail(&op->pend_link, &object->pending_ops);
46507 - fscache_stat(&fscache_n_op_pend);
46508 + fscache_stat_unchecked(&fscache_n_op_pend);
46509 } else if (!list_empty(&object->pending_ops)) {
46510 atomic_inc(&op->usage);
46511 list_add_tail(&op->pend_link, &object->pending_ops);
46512 - fscache_stat(&fscache_n_op_pend);
46513 + fscache_stat_unchecked(&fscache_n_op_pend);
46514 fscache_start_operations(object);
46515 } else {
46516 ASSERTCMP(object->n_in_progress, ==, 0);
46517 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46518 object->n_exclusive++; /* reads and writes must wait */
46519 atomic_inc(&op->usage);
46520 list_add_tail(&op->pend_link, &object->pending_ops);
46521 - fscache_stat(&fscache_n_op_pend);
46522 + fscache_stat_unchecked(&fscache_n_op_pend);
46523 ret = 0;
46524 } else {
46525 /* not allowed to submit ops in any other state */
46526 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46527 if (object->n_exclusive > 0) {
46528 atomic_inc(&op->usage);
46529 list_add_tail(&op->pend_link, &object->pending_ops);
46530 - fscache_stat(&fscache_n_op_pend);
46531 + fscache_stat_unchecked(&fscache_n_op_pend);
46532 } else if (!list_empty(&object->pending_ops)) {
46533 atomic_inc(&op->usage);
46534 list_add_tail(&op->pend_link, &object->pending_ops);
46535 - fscache_stat(&fscache_n_op_pend);
46536 + fscache_stat_unchecked(&fscache_n_op_pend);
46537 fscache_start_operations(object);
46538 } else {
46539 ASSERTCMP(object->n_exclusive, ==, 0);
46540 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46541 object->n_ops++;
46542 atomic_inc(&op->usage);
46543 list_add_tail(&op->pend_link, &object->pending_ops);
46544 - fscache_stat(&fscache_n_op_pend);
46545 + fscache_stat_unchecked(&fscache_n_op_pend);
46546 ret = 0;
46547 } else if (object->state == FSCACHE_OBJECT_DYING ||
46548 object->state == FSCACHE_OBJECT_LC_DYING ||
46549 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46550 - fscache_stat(&fscache_n_op_rejected);
46551 + fscache_stat_unchecked(&fscache_n_op_rejected);
46552 ret = -ENOBUFS;
46553 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46554 fscache_report_unexpected_submission(object, op, ostate);
46555 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46556
46557 ret = -EBUSY;
46558 if (!list_empty(&op->pend_link)) {
46559 - fscache_stat(&fscache_n_op_cancelled);
46560 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46561 list_del_init(&op->pend_link);
46562 object->n_ops--;
46563 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46564 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46565 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46566 BUG();
46567
46568 - fscache_stat(&fscache_n_op_release);
46569 + fscache_stat_unchecked(&fscache_n_op_release);
46570
46571 if (op->release) {
46572 op->release(op);
46573 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46574 * lock, and defer it otherwise */
46575 if (!spin_trylock(&object->lock)) {
46576 _debug("defer put");
46577 - fscache_stat(&fscache_n_op_deferred_release);
46578 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46579
46580 cache = object->cache;
46581 spin_lock(&cache->op_gc_list_lock);
46582 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46583
46584 _debug("GC DEFERRED REL OBJ%x OP%x",
46585 object->debug_id, op->debug_id);
46586 - fscache_stat(&fscache_n_op_gc);
46587 + fscache_stat_unchecked(&fscache_n_op_gc);
46588
46589 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46590
46591 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46592 index 3f7a59b..cf196cc 100644
46593 --- a/fs/fscache/page.c
46594 +++ b/fs/fscache/page.c
46595 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46596 val = radix_tree_lookup(&cookie->stores, page->index);
46597 if (!val) {
46598 rcu_read_unlock();
46599 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46600 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46601 __fscache_uncache_page(cookie, page);
46602 return true;
46603 }
46604 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46605 spin_unlock(&cookie->stores_lock);
46606
46607 if (xpage) {
46608 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46609 - fscache_stat(&fscache_n_store_radix_deletes);
46610 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46611 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46612 ASSERTCMP(xpage, ==, page);
46613 } else {
46614 - fscache_stat(&fscache_n_store_vmscan_gone);
46615 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46616 }
46617
46618 wake_up_bit(&cookie->flags, 0);
46619 @@ -107,7 +107,7 @@ page_busy:
46620 /* we might want to wait here, but that could deadlock the allocator as
46621 * the work threads writing to the cache may all end up sleeping
46622 * on memory allocation */
46623 - fscache_stat(&fscache_n_store_vmscan_busy);
46624 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46625 return false;
46626 }
46627 EXPORT_SYMBOL(__fscache_maybe_release_page);
46628 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46629 FSCACHE_COOKIE_STORING_TAG);
46630 if (!radix_tree_tag_get(&cookie->stores, page->index,
46631 FSCACHE_COOKIE_PENDING_TAG)) {
46632 - fscache_stat(&fscache_n_store_radix_deletes);
46633 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46634 xpage = radix_tree_delete(&cookie->stores, page->index);
46635 }
46636 spin_unlock(&cookie->stores_lock);
46637 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46638
46639 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46640
46641 - fscache_stat(&fscache_n_attr_changed_calls);
46642 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46643
46644 if (fscache_object_is_active(object)) {
46645 fscache_stat(&fscache_n_cop_attr_changed);
46646 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46647
46648 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46649
46650 - fscache_stat(&fscache_n_attr_changed);
46651 + fscache_stat_unchecked(&fscache_n_attr_changed);
46652
46653 op = kzalloc(sizeof(*op), GFP_KERNEL);
46654 if (!op) {
46655 - fscache_stat(&fscache_n_attr_changed_nomem);
46656 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46657 _leave(" = -ENOMEM");
46658 return -ENOMEM;
46659 }
46660 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46661 if (fscache_submit_exclusive_op(object, op) < 0)
46662 goto nobufs;
46663 spin_unlock(&cookie->lock);
46664 - fscache_stat(&fscache_n_attr_changed_ok);
46665 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46666 fscache_put_operation(op);
46667 _leave(" = 0");
46668 return 0;
46669 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46670 nobufs:
46671 spin_unlock(&cookie->lock);
46672 kfree(op);
46673 - fscache_stat(&fscache_n_attr_changed_nobufs);
46674 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46675 _leave(" = %d", -ENOBUFS);
46676 return -ENOBUFS;
46677 }
46678 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46679 /* allocate a retrieval operation and attempt to submit it */
46680 op = kzalloc(sizeof(*op), GFP_NOIO);
46681 if (!op) {
46682 - fscache_stat(&fscache_n_retrievals_nomem);
46683 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46684 return NULL;
46685 }
46686
46687 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46688 return 0;
46689 }
46690
46691 - fscache_stat(&fscache_n_retrievals_wait);
46692 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46693
46694 jif = jiffies;
46695 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46696 fscache_wait_bit_interruptible,
46697 TASK_INTERRUPTIBLE) != 0) {
46698 - fscache_stat(&fscache_n_retrievals_intr);
46699 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46700 _leave(" = -ERESTARTSYS");
46701 return -ERESTARTSYS;
46702 }
46703 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46704 */
46705 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46706 struct fscache_retrieval *op,
46707 - atomic_t *stat_op_waits,
46708 - atomic_t *stat_object_dead)
46709 + atomic_unchecked_t *stat_op_waits,
46710 + atomic_unchecked_t *stat_object_dead)
46711 {
46712 int ret;
46713
46714 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46715 goto check_if_dead;
46716
46717 _debug(">>> WT");
46718 - fscache_stat(stat_op_waits);
46719 + fscache_stat_unchecked(stat_op_waits);
46720 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46721 fscache_wait_bit_interruptible,
46722 TASK_INTERRUPTIBLE) < 0) {
46723 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46724
46725 check_if_dead:
46726 if (unlikely(fscache_object_is_dead(object))) {
46727 - fscache_stat(stat_object_dead);
46728 + fscache_stat_unchecked(stat_object_dead);
46729 return -ENOBUFS;
46730 }
46731 return 0;
46732 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46733
46734 _enter("%p,%p,,,", cookie, page);
46735
46736 - fscache_stat(&fscache_n_retrievals);
46737 + fscache_stat_unchecked(&fscache_n_retrievals);
46738
46739 if (hlist_empty(&cookie->backing_objects))
46740 goto nobufs;
46741 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46742 goto nobufs_unlock;
46743 spin_unlock(&cookie->lock);
46744
46745 - fscache_stat(&fscache_n_retrieval_ops);
46746 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46747
46748 /* pin the netfs read context in case we need to do the actual netfs
46749 * read because we've encountered a cache read failure */
46750 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46751
46752 error:
46753 if (ret == -ENOMEM)
46754 - fscache_stat(&fscache_n_retrievals_nomem);
46755 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46756 else if (ret == -ERESTARTSYS)
46757 - fscache_stat(&fscache_n_retrievals_intr);
46758 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46759 else if (ret == -ENODATA)
46760 - fscache_stat(&fscache_n_retrievals_nodata);
46761 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46762 else if (ret < 0)
46763 - fscache_stat(&fscache_n_retrievals_nobufs);
46764 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46765 else
46766 - fscache_stat(&fscache_n_retrievals_ok);
46767 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46768
46769 fscache_put_retrieval(op);
46770 _leave(" = %d", ret);
46771 @@ -429,7 +429,7 @@ nobufs_unlock:
46772 spin_unlock(&cookie->lock);
46773 kfree(op);
46774 nobufs:
46775 - fscache_stat(&fscache_n_retrievals_nobufs);
46776 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46777 _leave(" = -ENOBUFS");
46778 return -ENOBUFS;
46779 }
46780 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46781
46782 _enter("%p,,%d,,,", cookie, *nr_pages);
46783
46784 - fscache_stat(&fscache_n_retrievals);
46785 + fscache_stat_unchecked(&fscache_n_retrievals);
46786
46787 if (hlist_empty(&cookie->backing_objects))
46788 goto nobufs;
46789 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46790 goto nobufs_unlock;
46791 spin_unlock(&cookie->lock);
46792
46793 - fscache_stat(&fscache_n_retrieval_ops);
46794 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46795
46796 /* pin the netfs read context in case we need to do the actual netfs
46797 * read because we've encountered a cache read failure */
46798 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46799
46800 error:
46801 if (ret == -ENOMEM)
46802 - fscache_stat(&fscache_n_retrievals_nomem);
46803 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46804 else if (ret == -ERESTARTSYS)
46805 - fscache_stat(&fscache_n_retrievals_intr);
46806 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46807 else if (ret == -ENODATA)
46808 - fscache_stat(&fscache_n_retrievals_nodata);
46809 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46810 else if (ret < 0)
46811 - fscache_stat(&fscache_n_retrievals_nobufs);
46812 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46813 else
46814 - fscache_stat(&fscache_n_retrievals_ok);
46815 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46816
46817 fscache_put_retrieval(op);
46818 _leave(" = %d", ret);
46819 @@ -545,7 +545,7 @@ nobufs_unlock:
46820 spin_unlock(&cookie->lock);
46821 kfree(op);
46822 nobufs:
46823 - fscache_stat(&fscache_n_retrievals_nobufs);
46824 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46825 _leave(" = -ENOBUFS");
46826 return -ENOBUFS;
46827 }
46828 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46829
46830 _enter("%p,%p,,,", cookie, page);
46831
46832 - fscache_stat(&fscache_n_allocs);
46833 + fscache_stat_unchecked(&fscache_n_allocs);
46834
46835 if (hlist_empty(&cookie->backing_objects))
46836 goto nobufs;
46837 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46838 goto nobufs_unlock;
46839 spin_unlock(&cookie->lock);
46840
46841 - fscache_stat(&fscache_n_alloc_ops);
46842 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46843
46844 ret = fscache_wait_for_retrieval_activation(
46845 object, op,
46846 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46847
46848 error:
46849 if (ret == -ERESTARTSYS)
46850 - fscache_stat(&fscache_n_allocs_intr);
46851 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46852 else if (ret < 0)
46853 - fscache_stat(&fscache_n_allocs_nobufs);
46854 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46855 else
46856 - fscache_stat(&fscache_n_allocs_ok);
46857 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46858
46859 fscache_put_retrieval(op);
46860 _leave(" = %d", ret);
46861 @@ -625,7 +625,7 @@ nobufs_unlock:
46862 spin_unlock(&cookie->lock);
46863 kfree(op);
46864 nobufs:
46865 - fscache_stat(&fscache_n_allocs_nobufs);
46866 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46867 _leave(" = -ENOBUFS");
46868 return -ENOBUFS;
46869 }
46870 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46871
46872 spin_lock(&cookie->stores_lock);
46873
46874 - fscache_stat(&fscache_n_store_calls);
46875 + fscache_stat_unchecked(&fscache_n_store_calls);
46876
46877 /* find a page to store */
46878 page = NULL;
46879 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46880 page = results[0];
46881 _debug("gang %d [%lx]", n, page->index);
46882 if (page->index > op->store_limit) {
46883 - fscache_stat(&fscache_n_store_pages_over_limit);
46884 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46885 goto superseded;
46886 }
46887
46888 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46889 spin_unlock(&cookie->stores_lock);
46890 spin_unlock(&object->lock);
46891
46892 - fscache_stat(&fscache_n_store_pages);
46893 + fscache_stat_unchecked(&fscache_n_store_pages);
46894 fscache_stat(&fscache_n_cop_write_page);
46895 ret = object->cache->ops->write_page(op, page);
46896 fscache_stat_d(&fscache_n_cop_write_page);
46897 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46898 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46899 ASSERT(PageFsCache(page));
46900
46901 - fscache_stat(&fscache_n_stores);
46902 + fscache_stat_unchecked(&fscache_n_stores);
46903
46904 op = kzalloc(sizeof(*op), GFP_NOIO);
46905 if (!op)
46906 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46907 spin_unlock(&cookie->stores_lock);
46908 spin_unlock(&object->lock);
46909
46910 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46911 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46912 op->store_limit = object->store_limit;
46913
46914 if (fscache_submit_op(object, &op->op) < 0)
46915 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46916
46917 spin_unlock(&cookie->lock);
46918 radix_tree_preload_end();
46919 - fscache_stat(&fscache_n_store_ops);
46920 - fscache_stat(&fscache_n_stores_ok);
46921 + fscache_stat_unchecked(&fscache_n_store_ops);
46922 + fscache_stat_unchecked(&fscache_n_stores_ok);
46923
46924 /* the work queue now carries its own ref on the object */
46925 fscache_put_operation(&op->op);
46926 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46927 return 0;
46928
46929 already_queued:
46930 - fscache_stat(&fscache_n_stores_again);
46931 + fscache_stat_unchecked(&fscache_n_stores_again);
46932 already_pending:
46933 spin_unlock(&cookie->stores_lock);
46934 spin_unlock(&object->lock);
46935 spin_unlock(&cookie->lock);
46936 radix_tree_preload_end();
46937 kfree(op);
46938 - fscache_stat(&fscache_n_stores_ok);
46939 + fscache_stat_unchecked(&fscache_n_stores_ok);
46940 _leave(" = 0");
46941 return 0;
46942
46943 @@ -851,14 +851,14 @@ nobufs:
46944 spin_unlock(&cookie->lock);
46945 radix_tree_preload_end();
46946 kfree(op);
46947 - fscache_stat(&fscache_n_stores_nobufs);
46948 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46949 _leave(" = -ENOBUFS");
46950 return -ENOBUFS;
46951
46952 nomem_free:
46953 kfree(op);
46954 nomem:
46955 - fscache_stat(&fscache_n_stores_oom);
46956 + fscache_stat_unchecked(&fscache_n_stores_oom);
46957 _leave(" = -ENOMEM");
46958 return -ENOMEM;
46959 }
46960 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46961 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46962 ASSERTCMP(page, !=, NULL);
46963
46964 - fscache_stat(&fscache_n_uncaches);
46965 + fscache_stat_unchecked(&fscache_n_uncaches);
46966
46967 /* cache withdrawal may beat us to it */
46968 if (!PageFsCache(page))
46969 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46970 unsigned long loop;
46971
46972 #ifdef CONFIG_FSCACHE_STATS
46973 - atomic_add(pagevec->nr, &fscache_n_marks);
46974 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46975 #endif
46976
46977 for (loop = 0; loop < pagevec->nr; loop++) {
46978 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46979 index 4765190..2a067f2 100644
46980 --- a/fs/fscache/stats.c
46981 +++ b/fs/fscache/stats.c
46982 @@ -18,95 +18,95 @@
46983 /*
46984 * operation counters
46985 */
46986 -atomic_t fscache_n_op_pend;
46987 -atomic_t fscache_n_op_run;
46988 -atomic_t fscache_n_op_enqueue;
46989 -atomic_t fscache_n_op_requeue;
46990 -atomic_t fscache_n_op_deferred_release;
46991 -atomic_t fscache_n_op_release;
46992 -atomic_t fscache_n_op_gc;
46993 -atomic_t fscache_n_op_cancelled;
46994 -atomic_t fscache_n_op_rejected;
46995 +atomic_unchecked_t fscache_n_op_pend;
46996 +atomic_unchecked_t fscache_n_op_run;
46997 +atomic_unchecked_t fscache_n_op_enqueue;
46998 +atomic_unchecked_t fscache_n_op_requeue;
46999 +atomic_unchecked_t fscache_n_op_deferred_release;
47000 +atomic_unchecked_t fscache_n_op_release;
47001 +atomic_unchecked_t fscache_n_op_gc;
47002 +atomic_unchecked_t fscache_n_op_cancelled;
47003 +atomic_unchecked_t fscache_n_op_rejected;
47004
47005 -atomic_t fscache_n_attr_changed;
47006 -atomic_t fscache_n_attr_changed_ok;
47007 -atomic_t fscache_n_attr_changed_nobufs;
47008 -atomic_t fscache_n_attr_changed_nomem;
47009 -atomic_t fscache_n_attr_changed_calls;
47010 +atomic_unchecked_t fscache_n_attr_changed;
47011 +atomic_unchecked_t fscache_n_attr_changed_ok;
47012 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47013 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47014 +atomic_unchecked_t fscache_n_attr_changed_calls;
47015
47016 -atomic_t fscache_n_allocs;
47017 -atomic_t fscache_n_allocs_ok;
47018 -atomic_t fscache_n_allocs_wait;
47019 -atomic_t fscache_n_allocs_nobufs;
47020 -atomic_t fscache_n_allocs_intr;
47021 -atomic_t fscache_n_allocs_object_dead;
47022 -atomic_t fscache_n_alloc_ops;
47023 -atomic_t fscache_n_alloc_op_waits;
47024 +atomic_unchecked_t fscache_n_allocs;
47025 +atomic_unchecked_t fscache_n_allocs_ok;
47026 +atomic_unchecked_t fscache_n_allocs_wait;
47027 +atomic_unchecked_t fscache_n_allocs_nobufs;
47028 +atomic_unchecked_t fscache_n_allocs_intr;
47029 +atomic_unchecked_t fscache_n_allocs_object_dead;
47030 +atomic_unchecked_t fscache_n_alloc_ops;
47031 +atomic_unchecked_t fscache_n_alloc_op_waits;
47032
47033 -atomic_t fscache_n_retrievals;
47034 -atomic_t fscache_n_retrievals_ok;
47035 -atomic_t fscache_n_retrievals_wait;
47036 -atomic_t fscache_n_retrievals_nodata;
47037 -atomic_t fscache_n_retrievals_nobufs;
47038 -atomic_t fscache_n_retrievals_intr;
47039 -atomic_t fscache_n_retrievals_nomem;
47040 -atomic_t fscache_n_retrievals_object_dead;
47041 -atomic_t fscache_n_retrieval_ops;
47042 -atomic_t fscache_n_retrieval_op_waits;
47043 +atomic_unchecked_t fscache_n_retrievals;
47044 +atomic_unchecked_t fscache_n_retrievals_ok;
47045 +atomic_unchecked_t fscache_n_retrievals_wait;
47046 +atomic_unchecked_t fscache_n_retrievals_nodata;
47047 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47048 +atomic_unchecked_t fscache_n_retrievals_intr;
47049 +atomic_unchecked_t fscache_n_retrievals_nomem;
47050 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47051 +atomic_unchecked_t fscache_n_retrieval_ops;
47052 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47053
47054 -atomic_t fscache_n_stores;
47055 -atomic_t fscache_n_stores_ok;
47056 -atomic_t fscache_n_stores_again;
47057 -atomic_t fscache_n_stores_nobufs;
47058 -atomic_t fscache_n_stores_oom;
47059 -atomic_t fscache_n_store_ops;
47060 -atomic_t fscache_n_store_calls;
47061 -atomic_t fscache_n_store_pages;
47062 -atomic_t fscache_n_store_radix_deletes;
47063 -atomic_t fscache_n_store_pages_over_limit;
47064 +atomic_unchecked_t fscache_n_stores;
47065 +atomic_unchecked_t fscache_n_stores_ok;
47066 +atomic_unchecked_t fscache_n_stores_again;
47067 +atomic_unchecked_t fscache_n_stores_nobufs;
47068 +atomic_unchecked_t fscache_n_stores_oom;
47069 +atomic_unchecked_t fscache_n_store_ops;
47070 +atomic_unchecked_t fscache_n_store_calls;
47071 +atomic_unchecked_t fscache_n_store_pages;
47072 +atomic_unchecked_t fscache_n_store_radix_deletes;
47073 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47074
47075 -atomic_t fscache_n_store_vmscan_not_storing;
47076 -atomic_t fscache_n_store_vmscan_gone;
47077 -atomic_t fscache_n_store_vmscan_busy;
47078 -atomic_t fscache_n_store_vmscan_cancelled;
47079 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47080 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47081 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47082 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47083
47084 -atomic_t fscache_n_marks;
47085 -atomic_t fscache_n_uncaches;
47086 +atomic_unchecked_t fscache_n_marks;
47087 +atomic_unchecked_t fscache_n_uncaches;
47088
47089 -atomic_t fscache_n_acquires;
47090 -atomic_t fscache_n_acquires_null;
47091 -atomic_t fscache_n_acquires_no_cache;
47092 -atomic_t fscache_n_acquires_ok;
47093 -atomic_t fscache_n_acquires_nobufs;
47094 -atomic_t fscache_n_acquires_oom;
47095 +atomic_unchecked_t fscache_n_acquires;
47096 +atomic_unchecked_t fscache_n_acquires_null;
47097 +atomic_unchecked_t fscache_n_acquires_no_cache;
47098 +atomic_unchecked_t fscache_n_acquires_ok;
47099 +atomic_unchecked_t fscache_n_acquires_nobufs;
47100 +atomic_unchecked_t fscache_n_acquires_oom;
47101
47102 -atomic_t fscache_n_updates;
47103 -atomic_t fscache_n_updates_null;
47104 -atomic_t fscache_n_updates_run;
47105 +atomic_unchecked_t fscache_n_updates;
47106 +atomic_unchecked_t fscache_n_updates_null;
47107 +atomic_unchecked_t fscache_n_updates_run;
47108
47109 -atomic_t fscache_n_relinquishes;
47110 -atomic_t fscache_n_relinquishes_null;
47111 -atomic_t fscache_n_relinquishes_waitcrt;
47112 -atomic_t fscache_n_relinquishes_retire;
47113 +atomic_unchecked_t fscache_n_relinquishes;
47114 +atomic_unchecked_t fscache_n_relinquishes_null;
47115 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47116 +atomic_unchecked_t fscache_n_relinquishes_retire;
47117
47118 -atomic_t fscache_n_cookie_index;
47119 -atomic_t fscache_n_cookie_data;
47120 -atomic_t fscache_n_cookie_special;
47121 +atomic_unchecked_t fscache_n_cookie_index;
47122 +atomic_unchecked_t fscache_n_cookie_data;
47123 +atomic_unchecked_t fscache_n_cookie_special;
47124
47125 -atomic_t fscache_n_object_alloc;
47126 -atomic_t fscache_n_object_no_alloc;
47127 -atomic_t fscache_n_object_lookups;
47128 -atomic_t fscache_n_object_lookups_negative;
47129 -atomic_t fscache_n_object_lookups_positive;
47130 -atomic_t fscache_n_object_lookups_timed_out;
47131 -atomic_t fscache_n_object_created;
47132 -atomic_t fscache_n_object_avail;
47133 -atomic_t fscache_n_object_dead;
47134 +atomic_unchecked_t fscache_n_object_alloc;
47135 +atomic_unchecked_t fscache_n_object_no_alloc;
47136 +atomic_unchecked_t fscache_n_object_lookups;
47137 +atomic_unchecked_t fscache_n_object_lookups_negative;
47138 +atomic_unchecked_t fscache_n_object_lookups_positive;
47139 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47140 +atomic_unchecked_t fscache_n_object_created;
47141 +atomic_unchecked_t fscache_n_object_avail;
47142 +atomic_unchecked_t fscache_n_object_dead;
47143
47144 -atomic_t fscache_n_checkaux_none;
47145 -atomic_t fscache_n_checkaux_okay;
47146 -atomic_t fscache_n_checkaux_update;
47147 -atomic_t fscache_n_checkaux_obsolete;
47148 +atomic_unchecked_t fscache_n_checkaux_none;
47149 +atomic_unchecked_t fscache_n_checkaux_okay;
47150 +atomic_unchecked_t fscache_n_checkaux_update;
47151 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47152
47153 atomic_t fscache_n_cop_alloc_object;
47154 atomic_t fscache_n_cop_lookup_object;
47155 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47156 seq_puts(m, "FS-Cache statistics\n");
47157
47158 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47159 - atomic_read(&fscache_n_cookie_index),
47160 - atomic_read(&fscache_n_cookie_data),
47161 - atomic_read(&fscache_n_cookie_special));
47162 + atomic_read_unchecked(&fscache_n_cookie_index),
47163 + atomic_read_unchecked(&fscache_n_cookie_data),
47164 + atomic_read_unchecked(&fscache_n_cookie_special));
47165
47166 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47167 - atomic_read(&fscache_n_object_alloc),
47168 - atomic_read(&fscache_n_object_no_alloc),
47169 - atomic_read(&fscache_n_object_avail),
47170 - atomic_read(&fscache_n_object_dead));
47171 + atomic_read_unchecked(&fscache_n_object_alloc),
47172 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47173 + atomic_read_unchecked(&fscache_n_object_avail),
47174 + atomic_read_unchecked(&fscache_n_object_dead));
47175 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47176 - atomic_read(&fscache_n_checkaux_none),
47177 - atomic_read(&fscache_n_checkaux_okay),
47178 - atomic_read(&fscache_n_checkaux_update),
47179 - atomic_read(&fscache_n_checkaux_obsolete));
47180 + atomic_read_unchecked(&fscache_n_checkaux_none),
47181 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47182 + atomic_read_unchecked(&fscache_n_checkaux_update),
47183 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47184
47185 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47186 - atomic_read(&fscache_n_marks),
47187 - atomic_read(&fscache_n_uncaches));
47188 + atomic_read_unchecked(&fscache_n_marks),
47189 + atomic_read_unchecked(&fscache_n_uncaches));
47190
47191 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47192 " oom=%u\n",
47193 - atomic_read(&fscache_n_acquires),
47194 - atomic_read(&fscache_n_acquires_null),
47195 - atomic_read(&fscache_n_acquires_no_cache),
47196 - atomic_read(&fscache_n_acquires_ok),
47197 - atomic_read(&fscache_n_acquires_nobufs),
47198 - atomic_read(&fscache_n_acquires_oom));
47199 + atomic_read_unchecked(&fscache_n_acquires),
47200 + atomic_read_unchecked(&fscache_n_acquires_null),
47201 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47202 + atomic_read_unchecked(&fscache_n_acquires_ok),
47203 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47204 + atomic_read_unchecked(&fscache_n_acquires_oom));
47205
47206 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47207 - atomic_read(&fscache_n_object_lookups),
47208 - atomic_read(&fscache_n_object_lookups_negative),
47209 - atomic_read(&fscache_n_object_lookups_positive),
47210 - atomic_read(&fscache_n_object_created),
47211 - atomic_read(&fscache_n_object_lookups_timed_out));
47212 + atomic_read_unchecked(&fscache_n_object_lookups),
47213 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47214 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47215 + atomic_read_unchecked(&fscache_n_object_created),
47216 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47217
47218 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47219 - atomic_read(&fscache_n_updates),
47220 - atomic_read(&fscache_n_updates_null),
47221 - atomic_read(&fscache_n_updates_run));
47222 + atomic_read_unchecked(&fscache_n_updates),
47223 + atomic_read_unchecked(&fscache_n_updates_null),
47224 + atomic_read_unchecked(&fscache_n_updates_run));
47225
47226 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47227 - atomic_read(&fscache_n_relinquishes),
47228 - atomic_read(&fscache_n_relinquishes_null),
47229 - atomic_read(&fscache_n_relinquishes_waitcrt),
47230 - atomic_read(&fscache_n_relinquishes_retire));
47231 + atomic_read_unchecked(&fscache_n_relinquishes),
47232 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47233 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47234 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47235
47236 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47237 - atomic_read(&fscache_n_attr_changed),
47238 - atomic_read(&fscache_n_attr_changed_ok),
47239 - atomic_read(&fscache_n_attr_changed_nobufs),
47240 - atomic_read(&fscache_n_attr_changed_nomem),
47241 - atomic_read(&fscache_n_attr_changed_calls));
47242 + atomic_read_unchecked(&fscache_n_attr_changed),
47243 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47244 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47245 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47246 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47247
47248 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47249 - atomic_read(&fscache_n_allocs),
47250 - atomic_read(&fscache_n_allocs_ok),
47251 - atomic_read(&fscache_n_allocs_wait),
47252 - atomic_read(&fscache_n_allocs_nobufs),
47253 - atomic_read(&fscache_n_allocs_intr));
47254 + atomic_read_unchecked(&fscache_n_allocs),
47255 + atomic_read_unchecked(&fscache_n_allocs_ok),
47256 + atomic_read_unchecked(&fscache_n_allocs_wait),
47257 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47258 + atomic_read_unchecked(&fscache_n_allocs_intr));
47259 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47260 - atomic_read(&fscache_n_alloc_ops),
47261 - atomic_read(&fscache_n_alloc_op_waits),
47262 - atomic_read(&fscache_n_allocs_object_dead));
47263 + atomic_read_unchecked(&fscache_n_alloc_ops),
47264 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47265 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47266
47267 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47268 " int=%u oom=%u\n",
47269 - atomic_read(&fscache_n_retrievals),
47270 - atomic_read(&fscache_n_retrievals_ok),
47271 - atomic_read(&fscache_n_retrievals_wait),
47272 - atomic_read(&fscache_n_retrievals_nodata),
47273 - atomic_read(&fscache_n_retrievals_nobufs),
47274 - atomic_read(&fscache_n_retrievals_intr),
47275 - atomic_read(&fscache_n_retrievals_nomem));
47276 + atomic_read_unchecked(&fscache_n_retrievals),
47277 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47278 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47279 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47280 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47281 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47282 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47283 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47284 - atomic_read(&fscache_n_retrieval_ops),
47285 - atomic_read(&fscache_n_retrieval_op_waits),
47286 - atomic_read(&fscache_n_retrievals_object_dead));
47287 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47288 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47289 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47290
47291 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47292 - atomic_read(&fscache_n_stores),
47293 - atomic_read(&fscache_n_stores_ok),
47294 - atomic_read(&fscache_n_stores_again),
47295 - atomic_read(&fscache_n_stores_nobufs),
47296 - atomic_read(&fscache_n_stores_oom));
47297 + atomic_read_unchecked(&fscache_n_stores),
47298 + atomic_read_unchecked(&fscache_n_stores_ok),
47299 + atomic_read_unchecked(&fscache_n_stores_again),
47300 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47301 + atomic_read_unchecked(&fscache_n_stores_oom));
47302 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47303 - atomic_read(&fscache_n_store_ops),
47304 - atomic_read(&fscache_n_store_calls),
47305 - atomic_read(&fscache_n_store_pages),
47306 - atomic_read(&fscache_n_store_radix_deletes),
47307 - atomic_read(&fscache_n_store_pages_over_limit));
47308 + atomic_read_unchecked(&fscache_n_store_ops),
47309 + atomic_read_unchecked(&fscache_n_store_calls),
47310 + atomic_read_unchecked(&fscache_n_store_pages),
47311 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47312 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47313
47314 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47315 - atomic_read(&fscache_n_store_vmscan_not_storing),
47316 - atomic_read(&fscache_n_store_vmscan_gone),
47317 - atomic_read(&fscache_n_store_vmscan_busy),
47318 - atomic_read(&fscache_n_store_vmscan_cancelled));
47319 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47320 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47321 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47322 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47323
47324 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47325 - atomic_read(&fscache_n_op_pend),
47326 - atomic_read(&fscache_n_op_run),
47327 - atomic_read(&fscache_n_op_enqueue),
47328 - atomic_read(&fscache_n_op_cancelled),
47329 - atomic_read(&fscache_n_op_rejected));
47330 + atomic_read_unchecked(&fscache_n_op_pend),
47331 + atomic_read_unchecked(&fscache_n_op_run),
47332 + atomic_read_unchecked(&fscache_n_op_enqueue),
47333 + atomic_read_unchecked(&fscache_n_op_cancelled),
47334 + atomic_read_unchecked(&fscache_n_op_rejected));
47335 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47336 - atomic_read(&fscache_n_op_deferred_release),
47337 - atomic_read(&fscache_n_op_release),
47338 - atomic_read(&fscache_n_op_gc));
47339 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47340 + atomic_read_unchecked(&fscache_n_op_release),
47341 + atomic_read_unchecked(&fscache_n_op_gc));
47342
47343 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47344 atomic_read(&fscache_n_cop_alloc_object),
47345 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47346 index ee8d550..7189d8c 100644
47347 --- a/fs/fuse/cuse.c
47348 +++ b/fs/fuse/cuse.c
47349 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47350 INIT_LIST_HEAD(&cuse_conntbl[i]);
47351
47352 /* inherit and extend fuse_dev_operations */
47353 - cuse_channel_fops = fuse_dev_operations;
47354 - cuse_channel_fops.owner = THIS_MODULE;
47355 - cuse_channel_fops.open = cuse_channel_open;
47356 - cuse_channel_fops.release = cuse_channel_release;
47357 + pax_open_kernel();
47358 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47359 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47360 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47361 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47362 + pax_close_kernel();
47363
47364 cuse_class = class_create(THIS_MODULE, "cuse");
47365 if (IS_ERR(cuse_class))
47366 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47367 index f4246cf..b4aed1d 100644
47368 --- a/fs/fuse/dev.c
47369 +++ b/fs/fuse/dev.c
47370 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47371 ret = 0;
47372 pipe_lock(pipe);
47373
47374 - if (!pipe->readers) {
47375 + if (!atomic_read(&pipe->readers)) {
47376 send_sig(SIGPIPE, current, 0);
47377 if (!ret)
47378 ret = -EPIPE;
47379 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47380 index 324bc08..4fdd56e 100644
47381 --- a/fs/fuse/dir.c
47382 +++ b/fs/fuse/dir.c
47383 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47384 return link;
47385 }
47386
47387 -static void free_link(char *link)
47388 +static void free_link(const char *link)
47389 {
47390 if (!IS_ERR(link))
47391 free_page((unsigned long) link);
47392 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47393 index 753af3d..f7b021a 100644
47394 --- a/fs/gfs2/inode.c
47395 +++ b/fs/gfs2/inode.c
47396 @@ -1498,7 +1498,7 @@ out:
47397
47398 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47399 {
47400 - char *s = nd_get_link(nd);
47401 + const char *s = nd_get_link(nd);
47402 if (!IS_ERR(s))
47403 kfree(s);
47404 }
47405 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47406 index 8349a89..51a0254 100644
47407 --- a/fs/hugetlbfs/inode.c
47408 +++ b/fs/hugetlbfs/inode.c
47409 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47410 .kill_sb = kill_litter_super,
47411 };
47412
47413 -static struct vfsmount *hugetlbfs_vfsmount;
47414 +struct vfsmount *hugetlbfs_vfsmount;
47415
47416 static int can_do_hugetlb_shm(void)
47417 {
47418 diff --git a/fs/inode.c b/fs/inode.c
47419 index ac8d904..9f45d40 100644
47420 --- a/fs/inode.c
47421 +++ b/fs/inode.c
47422 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47423
47424 #ifdef CONFIG_SMP
47425 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47426 - static atomic_t shared_last_ino;
47427 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47428 + static atomic_unchecked_t shared_last_ino;
47429 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47430
47431 res = next - LAST_INO_BATCH;
47432 }
47433 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47434 index 4a6cf28..d3a29d3 100644
47435 --- a/fs/jffs2/erase.c
47436 +++ b/fs/jffs2/erase.c
47437 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47438 struct jffs2_unknown_node marker = {
47439 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47440 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47441 - .totlen = cpu_to_je32(c->cleanmarker_size)
47442 + .totlen = cpu_to_je32(c->cleanmarker_size),
47443 + .hdr_crc = cpu_to_je32(0)
47444 };
47445
47446 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47447 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47448 index a6597d6..41b30ec 100644
47449 --- a/fs/jffs2/wbuf.c
47450 +++ b/fs/jffs2/wbuf.c
47451 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47452 {
47453 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47454 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47455 - .totlen = constant_cpu_to_je32(8)
47456 + .totlen = constant_cpu_to_je32(8),
47457 + .hdr_crc = constant_cpu_to_je32(0)
47458 };
47459
47460 /*
47461 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47462 index c55c745..f67ee56 100644
47463 --- a/fs/jfs/super.c
47464 +++ b/fs/jfs/super.c
47465 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47466
47467 jfs_inode_cachep =
47468 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47469 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47470 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47471 init_once);
47472 if (jfs_inode_cachep == NULL)
47473 return -ENOMEM;
47474 diff --git a/fs/libfs.c b/fs/libfs.c
47475 index a74cb17..37fcbe4 100644
47476 --- a/fs/libfs.c
47477 +++ b/fs/libfs.c
47478 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47479
47480 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47481 struct dentry *next;
47482 + char d_name[sizeof(next->d_iname)];
47483 + const unsigned char *name;
47484 +
47485 next = list_entry(p, struct dentry, d_u.d_child);
47486 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47487 if (!simple_positive(next)) {
47488 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47489
47490 spin_unlock(&next->d_lock);
47491 spin_unlock(&dentry->d_lock);
47492 - if (filldir(dirent, next->d_name.name,
47493 + name = next->d_name.name;
47494 + if (name == next->d_iname) {
47495 + memcpy(d_name, name, next->d_name.len);
47496 + name = d_name;
47497 + }
47498 + if (filldir(dirent, name,
47499 next->d_name.len, filp->f_pos,
47500 next->d_inode->i_ino,
47501 dt_type(next->d_inode)) < 0)
47502 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47503 index 05d2912..760abfa 100644
47504 --- a/fs/lockd/clntproc.c
47505 +++ b/fs/lockd/clntproc.c
47506 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47507 /*
47508 * Cookie counter for NLM requests
47509 */
47510 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47511 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47512
47513 void nlmclnt_next_cookie(struct nlm_cookie *c)
47514 {
47515 - u32 cookie = atomic_inc_return(&nlm_cookie);
47516 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47517
47518 memcpy(c->data, &cookie, 4);
47519 c->len=4;
47520 diff --git a/fs/locks.c b/fs/locks.c
47521 index 7e81bfc..c3649aa 100644
47522 --- a/fs/locks.c
47523 +++ b/fs/locks.c
47524 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47525 return;
47526
47527 if (filp->f_op && filp->f_op->flock) {
47528 - struct file_lock fl = {
47529 + struct file_lock flock = {
47530 .fl_pid = current->tgid,
47531 .fl_file = filp,
47532 .fl_flags = FL_FLOCK,
47533 .fl_type = F_UNLCK,
47534 .fl_end = OFFSET_MAX,
47535 };
47536 - filp->f_op->flock(filp, F_SETLKW, &fl);
47537 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47538 - fl.fl_ops->fl_release_private(&fl);
47539 + filp->f_op->flock(filp, F_SETLKW, &flock);
47540 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47541 + flock.fl_ops->fl_release_private(&flock);
47542 }
47543
47544 lock_flocks();
47545 diff --git a/fs/namei.c b/fs/namei.c
47546 index 091c4b7..c6d7e26 100644
47547 --- a/fs/namei.c
47548 +++ b/fs/namei.c
47549 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47550 if (ret != -EACCES)
47551 return ret;
47552
47553 +#ifdef CONFIG_GRKERNSEC
47554 + /* we'll block if we have to log due to a denied capability use */
47555 + if (mask & MAY_NOT_BLOCK)
47556 + return -ECHILD;
47557 +#endif
47558 +
47559 if (S_ISDIR(inode->i_mode)) {
47560 /* DACs are overridable for directories */
47561 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47562 - return 0;
47563 if (!(mask & MAY_WRITE))
47564 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47565 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47566 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47567 return 0;
47568 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47569 + return 0;
47570 return -EACCES;
47571 }
47572 /*
47573 + * Searching includes executable on directories, else just read.
47574 + */
47575 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47576 + if (mask == MAY_READ)
47577 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47578 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47579 + return 0;
47580 +
47581 + /*
47582 * Read/write DACs are always overridable.
47583 * Executable DACs are overridable when there is
47584 * at least one exec bit set.
47585 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47586 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47587 return 0;
47588
47589 - /*
47590 - * Searching includes executable on directories, else just read.
47591 - */
47592 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47593 - if (mask == MAY_READ)
47594 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47595 - return 0;
47596 -
47597 return -EACCES;
47598 }
47599
47600 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47601 {
47602 struct dentry *dentry = link->dentry;
47603 int error;
47604 - char *s;
47605 + const char *s;
47606
47607 BUG_ON(nd->flags & LOOKUP_RCU);
47608
47609 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47610 if (error)
47611 goto out_put_nd_path;
47612
47613 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47614 + dentry->d_inode, dentry, nd->path.mnt)) {
47615 + error = -EACCES;
47616 + goto out_put_nd_path;
47617 + }
47618 +
47619 nd->last_type = LAST_BIND;
47620 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47621 error = PTR_ERR(*p);
47622 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47623 break;
47624 res = walk_component(nd, path, &nd->last,
47625 nd->last_type, LOOKUP_FOLLOW);
47626 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47627 + res = -EACCES;
47628 put_link(nd, &link, cookie);
47629 } while (res > 0);
47630
47631 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47632 if (err)
47633 break;
47634 err = lookup_last(nd, &path);
47635 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47636 + err = -EACCES;
47637 put_link(nd, &link, cookie);
47638 }
47639 }
47640 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47641 if (!err)
47642 err = complete_walk(nd);
47643
47644 + if (!(nd->flags & LOOKUP_PARENT)) {
47645 +#ifdef CONFIG_GRKERNSEC
47646 + if (flags & LOOKUP_RCU) {
47647 + if (!err)
47648 + path_put(&nd->path);
47649 + err = -ECHILD;
47650 + } else
47651 +#endif
47652 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47653 + if (!err)
47654 + path_put(&nd->path);
47655 + err = -ENOENT;
47656 + }
47657 + }
47658 +
47659 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47660 if (!nd->inode->i_op->lookup) {
47661 path_put(&nd->path);
47662 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47663 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47664
47665 if (likely(!retval)) {
47666 + if (*name != '/' && nd->path.dentry && nd->inode) {
47667 +#ifdef CONFIG_GRKERNSEC
47668 + if (flags & LOOKUP_RCU)
47669 + return -ECHILD;
47670 +#endif
47671 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47672 + return -ENOENT;
47673 + }
47674 +
47675 if (unlikely(!audit_dummy_context())) {
47676 if (nd->path.dentry && nd->inode)
47677 audit_inode(name, nd->path.dentry);
47678 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47679 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47680 return -EPERM;
47681
47682 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47683 + return -EPERM;
47684 + if (gr_handle_rawio(inode))
47685 + return -EPERM;
47686 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47687 + return -EACCES;
47688 +
47689 return 0;
47690 }
47691
47692 @@ -2557,7 +2606,7 @@ looked_up:
47693 * cleared otherwise prior to returning.
47694 */
47695 static int lookup_open(struct nameidata *nd, struct path *path,
47696 - struct file *file,
47697 + struct path *link, struct file *file,
47698 const struct open_flags *op,
47699 bool got_write, int *opened)
47700 {
47701 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47702 /* Negative dentry, just create the file */
47703 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47704 umode_t mode = op->mode;
47705 +
47706 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47707 + error = -EACCES;
47708 + goto out_dput;
47709 + }
47710 +
47711 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47712 + error = -EACCES;
47713 + goto out_dput;
47714 + }
47715 +
47716 if (!IS_POSIXACL(dir->d_inode))
47717 mode &= ~current_umask();
47718 /*
47719 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47720 nd->flags & LOOKUP_EXCL);
47721 if (error)
47722 goto out_dput;
47723 + else
47724 + gr_handle_create(dentry, nd->path.mnt);
47725 }
47726 out_no_open:
47727 path->dentry = dentry;
47728 @@ -2627,7 +2689,7 @@ out_dput:
47729 /*
47730 * Handle the last step of open()
47731 */
47732 -static int do_last(struct nameidata *nd, struct path *path,
47733 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47734 struct file *file, const struct open_flags *op,
47735 int *opened, const char *pathname)
47736 {
47737 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47738 error = complete_walk(nd);
47739 if (error)
47740 return error;
47741 +#ifdef CONFIG_GRKERNSEC
47742 + if (nd->flags & LOOKUP_RCU) {
47743 + error = -ECHILD;
47744 + goto out;
47745 + }
47746 +#endif
47747 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47748 + error = -ENOENT;
47749 + goto out;
47750 + }
47751 audit_inode(pathname, nd->path.dentry);
47752 if (open_flag & O_CREAT) {
47753 error = -EISDIR;
47754 goto out;
47755 }
47756 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47757 + error = -EACCES;
47758 + goto out;
47759 + }
47760 goto finish_open;
47761 case LAST_BIND:
47762 error = complete_walk(nd);
47763 if (error)
47764 return error;
47765 +#ifdef CONFIG_GRKERNSEC
47766 + if (nd->flags & LOOKUP_RCU) {
47767 + error = -ECHILD;
47768 + goto out;
47769 + }
47770 +#endif
47771 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47772 + error = -ENOENT;
47773 + goto out;
47774 + }
47775 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47776 + error = -EACCES;
47777 + goto out;
47778 + }
47779 audit_inode(pathname, dir);
47780 goto finish_open;
47781 }
47782 @@ -2714,7 +2804,7 @@ retry_lookup:
47783 */
47784 }
47785 mutex_lock(&dir->d_inode->i_mutex);
47786 - error = lookup_open(nd, path, file, op, got_write, opened);
47787 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47788 mutex_unlock(&dir->d_inode->i_mutex);
47789
47790 if (error <= 0) {
47791 @@ -2738,11 +2828,28 @@ retry_lookup:
47792 goto finish_open_created;
47793 }
47794
47795 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47796 + error = -ENOENT;
47797 + goto exit_dput;
47798 + }
47799 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47800 + error = -EACCES;
47801 + goto exit_dput;
47802 + }
47803 +
47804 /*
47805 * create/update audit record if it already exists.
47806 */
47807 - if (path->dentry->d_inode)
47808 + if (path->dentry->d_inode) {
47809 + /* only check if O_CREAT is specified, all other checks need to go
47810 + into may_open */
47811 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47812 + error = -EACCES;
47813 + goto exit_dput;
47814 + }
47815 +
47816 audit_inode(pathname, path->dentry);
47817 + }
47818
47819 /*
47820 * If atomic_open() acquired write access it is dropped now due to
47821 @@ -2783,6 +2890,11 @@ finish_lookup:
47822 }
47823 }
47824 BUG_ON(inode != path->dentry->d_inode);
47825 + /* if we're resolving a symlink to another symlink */
47826 + if (link && gr_handle_symlink_owner(link, inode)) {
47827 + error = -EACCES;
47828 + goto out;
47829 + }
47830 return 1;
47831 }
47832
47833 @@ -2792,7 +2904,6 @@ finish_lookup:
47834 save_parent.dentry = nd->path.dentry;
47835 save_parent.mnt = mntget(path->mnt);
47836 nd->path.dentry = path->dentry;
47837 -
47838 }
47839 nd->inode = inode;
47840 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47841 @@ -2801,6 +2912,22 @@ finish_lookup:
47842 path_put(&save_parent);
47843 return error;
47844 }
47845 +
47846 +#ifdef CONFIG_GRKERNSEC
47847 + if (nd->flags & LOOKUP_RCU) {
47848 + error = -ECHILD;
47849 + goto out;
47850 + }
47851 +#endif
47852 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47853 + error = -ENOENT;
47854 + goto out;
47855 + }
47856 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47857 + error = -EACCES;
47858 + goto out;
47859 + }
47860 +
47861 error = -EISDIR;
47862 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47863 goto out;
47864 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47865 if (unlikely(error))
47866 goto out;
47867
47868 - error = do_last(nd, &path, file, op, &opened, pathname);
47869 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47870 while (unlikely(error > 0)) { /* trailing symlink */
47871 struct path link = path;
47872 void *cookie;
47873 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47874 error = follow_link(&link, nd, &cookie);
47875 if (unlikely(error))
47876 break;
47877 - error = do_last(nd, &path, file, op, &opened, pathname);
47878 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
47879 put_link(nd, &link, cookie);
47880 }
47881 out:
47882 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47883 goto unlock;
47884
47885 error = -EEXIST;
47886 - if (dentry->d_inode)
47887 + if (dentry->d_inode) {
47888 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47889 + error = -ENOENT;
47890 + }
47891 goto fail;
47892 + }
47893 /*
47894 * Special case - lookup gave negative, but... we had foo/bar/
47895 * From the vfs_mknod() POV we just have a negative dentry -
47896 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47897 }
47898 EXPORT_SYMBOL(user_path_create);
47899
47900 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47901 +{
47902 + char *tmp = getname(pathname);
47903 + struct dentry *res;
47904 + if (IS_ERR(tmp))
47905 + return ERR_CAST(tmp);
47906 + res = kern_path_create(dfd, tmp, path, is_dir);
47907 + if (IS_ERR(res))
47908 + putname(tmp);
47909 + else
47910 + *to = tmp;
47911 + return res;
47912 +}
47913 +
47914 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47915 {
47916 int error = may_create(dir, dentry);
47917 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47918
47919 if (!IS_POSIXACL(path.dentry->d_inode))
47920 mode &= ~current_umask();
47921 +
47922 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47923 + error = -EPERM;
47924 + goto out;
47925 + }
47926 +
47927 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47928 + error = -EACCES;
47929 + goto out;
47930 + }
47931 +
47932 error = security_path_mknod(&path, dentry, mode, dev);
47933 if (error)
47934 goto out;
47935 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47936 break;
47937 }
47938 out:
47939 + if (!error)
47940 + gr_handle_create(dentry, path.mnt);
47941 done_path_create(&path, dentry);
47942 return error;
47943 }
47944 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47945
47946 if (!IS_POSIXACL(path.dentry->d_inode))
47947 mode &= ~current_umask();
47948 +
47949 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47950 + error = -EACCES;
47951 + goto out;
47952 + }
47953 +
47954 error = security_path_mkdir(&path, dentry, mode);
47955 if (!error)
47956 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47957 + if (!error)
47958 + gr_handle_create(dentry, path.mnt);
47959 +out:
47960 done_path_create(&path, dentry);
47961 return error;
47962 }
47963 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47964 char * name;
47965 struct dentry *dentry;
47966 struct nameidata nd;
47967 + ino_t saved_ino = 0;
47968 + dev_t saved_dev = 0;
47969
47970 error = user_path_parent(dfd, pathname, &nd, &name);
47971 if (error)
47972 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
47973 error = -ENOENT;
47974 goto exit3;
47975 }
47976 +
47977 + saved_ino = dentry->d_inode->i_ino;
47978 + saved_dev = gr_get_dev_from_dentry(dentry);
47979 +
47980 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47981 + error = -EACCES;
47982 + goto exit3;
47983 + }
47984 +
47985 error = security_path_rmdir(&nd.path, dentry);
47986 if (error)
47987 goto exit3;
47988 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47989 + if (!error && (saved_dev || saved_ino))
47990 + gr_handle_delete(saved_ino, saved_dev);
47991 exit3:
47992 dput(dentry);
47993 exit2:
47994 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
47995 struct dentry *dentry;
47996 struct nameidata nd;
47997 struct inode *inode = NULL;
47998 + ino_t saved_ino = 0;
47999 + dev_t saved_dev = 0;
48000
48001 error = user_path_parent(dfd, pathname, &nd, &name);
48002 if (error)
48003 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48004 if (!inode)
48005 goto slashes;
48006 ihold(inode);
48007 +
48008 + if (inode->i_nlink <= 1) {
48009 + saved_ino = inode->i_ino;
48010 + saved_dev = gr_get_dev_from_dentry(dentry);
48011 + }
48012 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48013 + error = -EACCES;
48014 + goto exit2;
48015 + }
48016 +
48017 error = security_path_unlink(&nd.path, dentry);
48018 if (error)
48019 goto exit2;
48020 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48021 + if (!error && (saved_ino || saved_dev))
48022 + gr_handle_delete(saved_ino, saved_dev);
48023 exit2:
48024 dput(dentry);
48025 }
48026 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48027 if (IS_ERR(dentry))
48028 goto out_putname;
48029
48030 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48031 + error = -EACCES;
48032 + goto out;
48033 + }
48034 +
48035 error = security_path_symlink(&path, dentry, from);
48036 if (!error)
48037 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48038 + if (!error)
48039 + gr_handle_create(dentry, path.mnt);
48040 +out:
48041 done_path_create(&path, dentry);
48042 out_putname:
48043 putname(from);
48044 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48045 {
48046 struct dentry *new_dentry;
48047 struct path old_path, new_path;
48048 + char *to = NULL;
48049 int how = 0;
48050 int error;
48051
48052 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48053 if (error)
48054 return error;
48055
48056 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48057 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48058 error = PTR_ERR(new_dentry);
48059 if (IS_ERR(new_dentry))
48060 goto out;
48061 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48062 error = may_linkat(&old_path);
48063 if (unlikely(error))
48064 goto out_dput;
48065 +
48066 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48067 + old_path.dentry->d_inode,
48068 + old_path.dentry->d_inode->i_mode, to)) {
48069 + error = -EACCES;
48070 + goto out_dput;
48071 + }
48072 +
48073 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48074 + old_path.dentry, old_path.mnt, to)) {
48075 + error = -EACCES;
48076 + goto out_dput;
48077 + }
48078 +
48079 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48080 if (error)
48081 goto out_dput;
48082 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48083 + if (!error)
48084 + gr_handle_create(new_dentry, new_path.mnt);
48085 out_dput:
48086 + putname(to);
48087 done_path_create(&new_path, new_dentry);
48088 out:
48089 path_put(&old_path);
48090 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48091 if (new_dentry == trap)
48092 goto exit5;
48093
48094 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48095 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48096 + to);
48097 + if (error)
48098 + goto exit5;
48099 +
48100 error = security_path_rename(&oldnd.path, old_dentry,
48101 &newnd.path, new_dentry);
48102 if (error)
48103 goto exit5;
48104 error = vfs_rename(old_dir->d_inode, old_dentry,
48105 new_dir->d_inode, new_dentry);
48106 + if (!error)
48107 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48108 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48109 exit5:
48110 dput(new_dentry);
48111 exit4:
48112 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48113
48114 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48115 {
48116 + char tmpbuf[64];
48117 + const char *newlink;
48118 int len;
48119
48120 len = PTR_ERR(link);
48121 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48122 len = strlen(link);
48123 if (len > (unsigned) buflen)
48124 len = buflen;
48125 - if (copy_to_user(buffer, link, len))
48126 +
48127 + if (len < sizeof(tmpbuf)) {
48128 + memcpy(tmpbuf, link, len);
48129 + newlink = tmpbuf;
48130 + } else
48131 + newlink = link;
48132 +
48133 + if (copy_to_user(buffer, newlink, len))
48134 len = -EFAULT;
48135 out:
48136 return len;
48137 diff --git a/fs/namespace.c b/fs/namespace.c
48138 index 7bdf790..eb79c4b 100644
48139 --- a/fs/namespace.c
48140 +++ b/fs/namespace.c
48141 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48142 if (!(sb->s_flags & MS_RDONLY))
48143 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48144 up_write(&sb->s_umount);
48145 +
48146 + gr_log_remount(mnt->mnt_devname, retval);
48147 +
48148 return retval;
48149 }
48150
48151 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48152 br_write_unlock(&vfsmount_lock);
48153 up_write(&namespace_sem);
48154 release_mounts(&umount_list);
48155 +
48156 + gr_log_unmount(mnt->mnt_devname, retval);
48157 +
48158 return retval;
48159 }
48160
48161 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48162 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48163 MS_STRICTATIME);
48164
48165 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48166 + retval = -EPERM;
48167 + goto dput_out;
48168 + }
48169 +
48170 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48171 + retval = -EPERM;
48172 + goto dput_out;
48173 + }
48174 +
48175 if (flags & MS_REMOUNT)
48176 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48177 data_page);
48178 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48179 dev_name, data_page);
48180 dput_out:
48181 path_put(&path);
48182 +
48183 + gr_log_mount(dev_name, dir_name, retval);
48184 +
48185 return retval;
48186 }
48187
48188 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48189 if (error)
48190 goto out2;
48191
48192 + if (gr_handle_chroot_pivot()) {
48193 + error = -EPERM;
48194 + goto out2;
48195 + }
48196 +
48197 get_fs_root(current->fs, &root);
48198 error = lock_mount(&old);
48199 if (error)
48200 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48201 index 9b47610..066975e 100644
48202 --- a/fs/nfs/inode.c
48203 +++ b/fs/nfs/inode.c
48204 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48205 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48206 }
48207
48208 -static atomic_long_t nfs_attr_generation_counter;
48209 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48210
48211 static unsigned long nfs_read_attr_generation_counter(void)
48212 {
48213 - return atomic_long_read(&nfs_attr_generation_counter);
48214 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48215 }
48216
48217 unsigned long nfs_inc_attr_generation_counter(void)
48218 {
48219 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48220 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48221 }
48222
48223 void nfs_fattr_init(struct nfs_fattr *fattr)
48224 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48225 index a9269f1..5490437 100644
48226 --- a/fs/nfsd/vfs.c
48227 +++ b/fs/nfsd/vfs.c
48228 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48229 } else {
48230 oldfs = get_fs();
48231 set_fs(KERNEL_DS);
48232 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48233 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48234 set_fs(oldfs);
48235 }
48236
48237 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48238
48239 /* Write the data. */
48240 oldfs = get_fs(); set_fs(KERNEL_DS);
48241 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48242 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48243 set_fs(oldfs);
48244 if (host_err < 0)
48245 goto out_nfserr;
48246 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48247 */
48248
48249 oldfs = get_fs(); set_fs(KERNEL_DS);
48250 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48251 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48252 set_fs(oldfs);
48253
48254 if (host_err < 0)
48255 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48256 index d438036..0ecadde 100644
48257 --- a/fs/notify/fanotify/fanotify_user.c
48258 +++ b/fs/notify/fanotify/fanotify_user.c
48259 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48260 goto out_close_fd;
48261
48262 ret = -EFAULT;
48263 - if (copy_to_user(buf, &fanotify_event_metadata,
48264 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48265 + copy_to_user(buf, &fanotify_event_metadata,
48266 fanotify_event_metadata.event_len))
48267 goto out_kill_access_response;
48268
48269 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48270 index c887b13..0fdf472 100644
48271 --- a/fs/notify/notification.c
48272 +++ b/fs/notify/notification.c
48273 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48274 * get set to 0 so it will never get 'freed'
48275 */
48276 static struct fsnotify_event *q_overflow_event;
48277 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48278 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48279
48280 /**
48281 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48282 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48283 */
48284 u32 fsnotify_get_cookie(void)
48285 {
48286 - return atomic_inc_return(&fsnotify_sync_cookie);
48287 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48288 }
48289 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48290
48291 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48292 index 99e3610..02c1068 100644
48293 --- a/fs/ntfs/dir.c
48294 +++ b/fs/ntfs/dir.c
48295 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48296 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48297 ~(s64)(ndir->itype.index.block_size - 1)));
48298 /* Bounds checks. */
48299 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48300 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48301 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48302 "inode 0x%lx or driver bug.", vdir->i_ino);
48303 goto err_out;
48304 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48305 index 1ecf464..e1ff8bf 100644
48306 --- a/fs/ntfs/file.c
48307 +++ b/fs/ntfs/file.c
48308 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48309 #endif /* NTFS_RW */
48310 };
48311
48312 -const struct file_operations ntfs_empty_file_ops = {};
48313 +const struct file_operations ntfs_empty_file_ops __read_only;
48314
48315 -const struct inode_operations ntfs_empty_inode_ops = {};
48316 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48317 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48318 index a9f78c7..ed8a381 100644
48319 --- a/fs/ocfs2/localalloc.c
48320 +++ b/fs/ocfs2/localalloc.c
48321 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48322 goto bail;
48323 }
48324
48325 - atomic_inc(&osb->alloc_stats.moves);
48326 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48327
48328 bail:
48329 if (handle)
48330 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48331 index d355e6e..578d905 100644
48332 --- a/fs/ocfs2/ocfs2.h
48333 +++ b/fs/ocfs2/ocfs2.h
48334 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48335
48336 struct ocfs2_alloc_stats
48337 {
48338 - atomic_t moves;
48339 - atomic_t local_data;
48340 - atomic_t bitmap_data;
48341 - atomic_t bg_allocs;
48342 - atomic_t bg_extends;
48343 + atomic_unchecked_t moves;
48344 + atomic_unchecked_t local_data;
48345 + atomic_unchecked_t bitmap_data;
48346 + atomic_unchecked_t bg_allocs;
48347 + atomic_unchecked_t bg_extends;
48348 };
48349
48350 enum ocfs2_local_alloc_state
48351 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48352 index f169da4..9112253 100644
48353 --- a/fs/ocfs2/suballoc.c
48354 +++ b/fs/ocfs2/suballoc.c
48355 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48356 mlog_errno(status);
48357 goto bail;
48358 }
48359 - atomic_inc(&osb->alloc_stats.bg_extends);
48360 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48361
48362 /* You should never ask for this much metadata */
48363 BUG_ON(bits_wanted >
48364 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48365 mlog_errno(status);
48366 goto bail;
48367 }
48368 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48369 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48370
48371 *suballoc_loc = res.sr_bg_blkno;
48372 *suballoc_bit_start = res.sr_bit_offset;
48373 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48374 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48375 res->sr_bits);
48376
48377 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48378 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48379
48380 BUG_ON(res->sr_bits != 1);
48381
48382 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48383 mlog_errno(status);
48384 goto bail;
48385 }
48386 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48387 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48388
48389 BUG_ON(res.sr_bits != 1);
48390
48391 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48392 cluster_start,
48393 num_clusters);
48394 if (!status)
48395 - atomic_inc(&osb->alloc_stats.local_data);
48396 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48397 } else {
48398 if (min_clusters > (osb->bitmap_cpg - 1)) {
48399 /* The only paths asking for contiguousness
48400 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48401 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48402 res.sr_bg_blkno,
48403 res.sr_bit_offset);
48404 - atomic_inc(&osb->alloc_stats.bitmap_data);
48405 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48406 *num_clusters = res.sr_bits;
48407 }
48408 }
48409 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48410 index 68f4541..89cfe6a 100644
48411 --- a/fs/ocfs2/super.c
48412 +++ b/fs/ocfs2/super.c
48413 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48414 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48415 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48416 "Stats",
48417 - atomic_read(&osb->alloc_stats.bitmap_data),
48418 - atomic_read(&osb->alloc_stats.local_data),
48419 - atomic_read(&osb->alloc_stats.bg_allocs),
48420 - atomic_read(&osb->alloc_stats.moves),
48421 - atomic_read(&osb->alloc_stats.bg_extends));
48422 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48423 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48424 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48425 + atomic_read_unchecked(&osb->alloc_stats.moves),
48426 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48427
48428 out += snprintf(buf + out, len - out,
48429 "%10s => State: %u Descriptor: %llu Size: %u bits "
48430 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48431 spin_lock_init(&osb->osb_xattr_lock);
48432 ocfs2_init_steal_slots(osb);
48433
48434 - atomic_set(&osb->alloc_stats.moves, 0);
48435 - atomic_set(&osb->alloc_stats.local_data, 0);
48436 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48437 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48438 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48439 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48440 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48441 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48442 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48443 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48444
48445 /* Copy the blockcheck stats from the superblock probe */
48446 osb->osb_ecc_stats = *stats;
48447 diff --git a/fs/open.c b/fs/open.c
48448 index e1f2cdb..3bd5f39 100644
48449 --- a/fs/open.c
48450 +++ b/fs/open.c
48451 @@ -31,6 +31,8 @@
48452 #include <linux/ima.h>
48453 #include <linux/dnotify.h>
48454
48455 +#define CREATE_TRACE_POINTS
48456 +#include <trace/events/fs.h>
48457 #include "internal.h"
48458
48459 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48460 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48461 error = locks_verify_truncate(inode, NULL, length);
48462 if (!error)
48463 error = security_path_truncate(&path);
48464 +
48465 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48466 + error = -EACCES;
48467 +
48468 if (!error)
48469 error = do_truncate(path.dentry, length, 0, NULL);
48470
48471 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48472 if (__mnt_is_readonly(path.mnt))
48473 res = -EROFS;
48474
48475 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48476 + res = -EACCES;
48477 +
48478 out_path_release:
48479 path_put(&path);
48480 out:
48481 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48482 if (error)
48483 goto dput_and_out;
48484
48485 + gr_log_chdir(path.dentry, path.mnt);
48486 +
48487 set_fs_pwd(current->fs, &path);
48488
48489 dput_and_out:
48490 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48491 goto out_putf;
48492
48493 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48494 +
48495 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48496 + error = -EPERM;
48497 +
48498 + if (!error)
48499 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48500 +
48501 if (!error)
48502 set_fs_pwd(current->fs, &file->f_path);
48503 out_putf:
48504 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48505 if (error)
48506 goto dput_and_out;
48507
48508 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48509 + goto dput_and_out;
48510 +
48511 set_fs_root(current->fs, &path);
48512 +
48513 + gr_handle_chroot_chdir(&path);
48514 +
48515 error = 0;
48516 dput_and_out:
48517 path_put(&path);
48518 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48519 if (error)
48520 return error;
48521 mutex_lock(&inode->i_mutex);
48522 +
48523 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48524 + error = -EACCES;
48525 + goto out_unlock;
48526 + }
48527 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48528 + error = -EACCES;
48529 + goto out_unlock;
48530 + }
48531 +
48532 error = security_path_chmod(path, mode);
48533 if (error)
48534 goto out_unlock;
48535 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48536 uid = make_kuid(current_user_ns(), user);
48537 gid = make_kgid(current_user_ns(), group);
48538
48539 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48540 + return -EACCES;
48541 +
48542 newattrs.ia_valid = ATTR_CTIME;
48543 if (user != (uid_t) -1) {
48544 if (!uid_valid(uid))
48545 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48546 } else {
48547 fsnotify_open(f);
48548 fd_install(fd, f);
48549 + trace_do_sys_open(tmp, flags, mode);
48550 }
48551 }
48552 putname(tmp);
48553 diff --git a/fs/pipe.c b/fs/pipe.c
48554 index 8d85d70..581036b 100644
48555 --- a/fs/pipe.c
48556 +++ b/fs/pipe.c
48557 @@ -438,9 +438,9 @@ redo:
48558 }
48559 if (bufs) /* More to do? */
48560 continue;
48561 - if (!pipe->writers)
48562 + if (!atomic_read(&pipe->writers))
48563 break;
48564 - if (!pipe->waiting_writers) {
48565 + if (!atomic_read(&pipe->waiting_writers)) {
48566 /* syscall merging: Usually we must not sleep
48567 * if O_NONBLOCK is set, or if we got some data.
48568 * But if a writer sleeps in kernel space, then
48569 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48570 mutex_lock(&inode->i_mutex);
48571 pipe = inode->i_pipe;
48572
48573 - if (!pipe->readers) {
48574 + if (!atomic_read(&pipe->readers)) {
48575 send_sig(SIGPIPE, current, 0);
48576 ret = -EPIPE;
48577 goto out;
48578 @@ -553,7 +553,7 @@ redo1:
48579 for (;;) {
48580 int bufs;
48581
48582 - if (!pipe->readers) {
48583 + if (!atomic_read(&pipe->readers)) {
48584 send_sig(SIGPIPE, current, 0);
48585 if (!ret)
48586 ret = -EPIPE;
48587 @@ -644,9 +644,9 @@ redo2:
48588 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48589 do_wakeup = 0;
48590 }
48591 - pipe->waiting_writers++;
48592 + atomic_inc(&pipe->waiting_writers);
48593 pipe_wait(pipe);
48594 - pipe->waiting_writers--;
48595 + atomic_dec(&pipe->waiting_writers);
48596 }
48597 out:
48598 mutex_unlock(&inode->i_mutex);
48599 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48600 mask = 0;
48601 if (filp->f_mode & FMODE_READ) {
48602 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48603 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48604 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48605 mask |= POLLHUP;
48606 }
48607
48608 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48609 * Most Unices do not set POLLERR for FIFOs but on Linux they
48610 * behave exactly like pipes for poll().
48611 */
48612 - if (!pipe->readers)
48613 + if (!atomic_read(&pipe->readers))
48614 mask |= POLLERR;
48615 }
48616
48617 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48618
48619 mutex_lock(&inode->i_mutex);
48620 pipe = inode->i_pipe;
48621 - pipe->readers -= decr;
48622 - pipe->writers -= decw;
48623 + atomic_sub(decr, &pipe->readers);
48624 + atomic_sub(decw, &pipe->writers);
48625
48626 - if (!pipe->readers && !pipe->writers) {
48627 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48628 free_pipe_info(inode);
48629 } else {
48630 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48631 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48632
48633 if (inode->i_pipe) {
48634 ret = 0;
48635 - inode->i_pipe->readers++;
48636 + atomic_inc(&inode->i_pipe->readers);
48637 }
48638
48639 mutex_unlock(&inode->i_mutex);
48640 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48641
48642 if (inode->i_pipe) {
48643 ret = 0;
48644 - inode->i_pipe->writers++;
48645 + atomic_inc(&inode->i_pipe->writers);
48646 }
48647
48648 mutex_unlock(&inode->i_mutex);
48649 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48650 if (inode->i_pipe) {
48651 ret = 0;
48652 if (filp->f_mode & FMODE_READ)
48653 - inode->i_pipe->readers++;
48654 + atomic_inc(&inode->i_pipe->readers);
48655 if (filp->f_mode & FMODE_WRITE)
48656 - inode->i_pipe->writers++;
48657 + atomic_inc(&inode->i_pipe->writers);
48658 }
48659
48660 mutex_unlock(&inode->i_mutex);
48661 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48662 inode->i_pipe = NULL;
48663 }
48664
48665 -static struct vfsmount *pipe_mnt __read_mostly;
48666 +struct vfsmount *pipe_mnt __read_mostly;
48667
48668 /*
48669 * pipefs_dname() is called from d_path().
48670 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48671 goto fail_iput;
48672 inode->i_pipe = pipe;
48673
48674 - pipe->readers = pipe->writers = 1;
48675 + atomic_set(&pipe->readers, 1);
48676 + atomic_set(&pipe->writers, 1);
48677 inode->i_fop = &rdwr_pipefifo_fops;
48678
48679 /*
48680 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48681 index 15af622..0e9f4467 100644
48682 --- a/fs/proc/Kconfig
48683 +++ b/fs/proc/Kconfig
48684 @@ -30,12 +30,12 @@ config PROC_FS
48685
48686 config PROC_KCORE
48687 bool "/proc/kcore support" if !ARM
48688 - depends on PROC_FS && MMU
48689 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48690
48691 config PROC_VMCORE
48692 bool "/proc/vmcore support"
48693 - depends on PROC_FS && CRASH_DUMP
48694 - default y
48695 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48696 + default n
48697 help
48698 Exports the dump image of crashed kernel in ELF format.
48699
48700 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48701 limited in memory.
48702
48703 config PROC_PAGE_MONITOR
48704 - default y
48705 - depends on PROC_FS && MMU
48706 + default n
48707 + depends on PROC_FS && MMU && !GRKERNSEC
48708 bool "Enable /proc page monitoring" if EXPERT
48709 help
48710 Various /proc files exist to monitor process memory utilization:
48711 diff --git a/fs/proc/array.c b/fs/proc/array.c
48712 index c1c207c..01ce725 100644
48713 --- a/fs/proc/array.c
48714 +++ b/fs/proc/array.c
48715 @@ -60,6 +60,7 @@
48716 #include <linux/tty.h>
48717 #include <linux/string.h>
48718 #include <linux/mman.h>
48719 +#include <linux/grsecurity.h>
48720 #include <linux/proc_fs.h>
48721 #include <linux/ioport.h>
48722 #include <linux/uaccess.h>
48723 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48724 seq_putc(m, '\n');
48725 }
48726
48727 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48728 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48729 +{
48730 + if (p->mm)
48731 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48732 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48733 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48734 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48735 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48736 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48737 + else
48738 + seq_printf(m, "PaX:\t-----\n");
48739 +}
48740 +#endif
48741 +
48742 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48743 struct pid *pid, struct task_struct *task)
48744 {
48745 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48746 task_cpus_allowed(m, task);
48747 cpuset_task_status_allowed(m, task);
48748 task_context_switch_counts(m, task);
48749 +
48750 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48751 + task_pax(m, task);
48752 +#endif
48753 +
48754 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48755 + task_grsec_rbac(m, task);
48756 +#endif
48757 +
48758 return 0;
48759 }
48760
48761 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48762 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48763 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48764 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48765 +#endif
48766 +
48767 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48768 struct pid *pid, struct task_struct *task, int whole)
48769 {
48770 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48771 char tcomm[sizeof(task->comm)];
48772 unsigned long flags;
48773
48774 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48775 + if (current->exec_id != m->exec_id) {
48776 + gr_log_badprocpid("stat");
48777 + return 0;
48778 + }
48779 +#endif
48780 +
48781 state = *get_task_state(task);
48782 vsize = eip = esp = 0;
48783 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48784 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48785 gtime = task->gtime;
48786 }
48787
48788 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48789 + if (PAX_RAND_FLAGS(mm)) {
48790 + eip = 0;
48791 + esp = 0;
48792 + wchan = 0;
48793 + }
48794 +#endif
48795 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48796 + wchan = 0;
48797 + eip =0;
48798 + esp =0;
48799 +#endif
48800 +
48801 /* scale priority and nice values from timeslices to -20..20 */
48802 /* to make it look like a "normal" Unix priority/nice value */
48803 priority = task_prio(task);
48804 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48805 seq_put_decimal_ull(m, ' ', vsize);
48806 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48807 seq_put_decimal_ull(m, ' ', rsslim);
48808 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48809 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48810 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48811 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48812 +#else
48813 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48814 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48815 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48816 +#endif
48817 seq_put_decimal_ull(m, ' ', esp);
48818 seq_put_decimal_ull(m, ' ', eip);
48819 /* The signal information here is obsolete.
48820 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48821 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48822 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48823
48824 - if (mm && permitted) {
48825 + if (mm && permitted
48826 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48827 + && !PAX_RAND_FLAGS(mm)
48828 +#endif
48829 + ) {
48830 seq_put_decimal_ull(m, ' ', mm->start_data);
48831 seq_put_decimal_ull(m, ' ', mm->end_data);
48832 seq_put_decimal_ull(m, ' ', mm->start_brk);
48833 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48834 struct pid *pid, struct task_struct *task)
48835 {
48836 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48837 - struct mm_struct *mm = get_task_mm(task);
48838 + struct mm_struct *mm;
48839
48840 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48841 + if (current->exec_id != m->exec_id) {
48842 + gr_log_badprocpid("statm");
48843 + return 0;
48844 + }
48845 +#endif
48846 + mm = get_task_mm(task);
48847 if (mm) {
48848 size = task_statm(mm, &shared, &text, &data, &resident);
48849 mmput(mm);
48850 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48851 return 0;
48852 }
48853
48854 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48855 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48856 +{
48857 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48858 +}
48859 +#endif
48860 +
48861 #ifdef CONFIG_CHECKPOINT_RESTORE
48862 static struct pid *
48863 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48864 diff --git a/fs/proc/base.c b/fs/proc/base.c
48865 index 1b6c84c..66b738b 100644
48866 --- a/fs/proc/base.c
48867 +++ b/fs/proc/base.c
48868 @@ -110,6 +110,14 @@ struct pid_entry {
48869 union proc_op op;
48870 };
48871
48872 +struct getdents_callback {
48873 + struct linux_dirent __user * current_dir;
48874 + struct linux_dirent __user * previous;
48875 + struct file * file;
48876 + int count;
48877 + int error;
48878 +};
48879 +
48880 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48881 .name = (NAME), \
48882 .len = sizeof(NAME) - 1, \
48883 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48884 if (!mm->arg_end)
48885 goto out_mm; /* Shh! No looking before we're done */
48886
48887 + if (gr_acl_handle_procpidmem(task))
48888 + goto out_mm;
48889 +
48890 len = mm->arg_end - mm->arg_start;
48891
48892 if (len > PAGE_SIZE)
48893 @@ -236,12 +247,28 @@ out:
48894 return res;
48895 }
48896
48897 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48898 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48899 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48900 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48901 +#endif
48902 +
48903 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48904 {
48905 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48906 int res = PTR_ERR(mm);
48907 if (mm && !IS_ERR(mm)) {
48908 unsigned int nwords = 0;
48909 +
48910 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48911 + /* allow if we're currently ptracing this task */
48912 + if (PAX_RAND_FLAGS(mm) &&
48913 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48914 + mmput(mm);
48915 + return 0;
48916 + }
48917 +#endif
48918 +
48919 do {
48920 nwords += 2;
48921 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48922 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48923 }
48924
48925
48926 -#ifdef CONFIG_KALLSYMS
48927 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48928 /*
48929 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48930 * Returns the resolved symbol. If that fails, simply return the address.
48931 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48932 mutex_unlock(&task->signal->cred_guard_mutex);
48933 }
48934
48935 -#ifdef CONFIG_STACKTRACE
48936 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48937
48938 #define MAX_STACK_TRACE_DEPTH 64
48939
48940 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48941 return count;
48942 }
48943
48944 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48945 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48946 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48947 {
48948 long nr;
48949 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48950 /************************************************************************/
48951
48952 /* permission checks */
48953 -static int proc_fd_access_allowed(struct inode *inode)
48954 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48955 {
48956 struct task_struct *task;
48957 int allowed = 0;
48958 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48959 */
48960 task = get_proc_task(inode);
48961 if (task) {
48962 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48963 + if (log)
48964 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48965 + else
48966 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48967 put_task_struct(task);
48968 }
48969 return allowed;
48970 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48971 struct task_struct *task,
48972 int hide_pid_min)
48973 {
48974 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48975 + return false;
48976 +
48977 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48978 + rcu_read_lock();
48979 + {
48980 + const struct cred *tmpcred = current_cred();
48981 + const struct cred *cred = __task_cred(task);
48982 +
48983 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48984 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48985 + || in_group_p(grsec_proc_gid)
48986 +#endif
48987 + ) {
48988 + rcu_read_unlock();
48989 + return true;
48990 + }
48991 + }
48992 + rcu_read_unlock();
48993 +
48994 + if (!pid->hide_pid)
48995 + return false;
48996 +#endif
48997 +
48998 if (pid->hide_pid < hide_pid_min)
48999 return true;
49000 if (in_group_p(pid->pid_gid))
49001 return true;
49002 +
49003 return ptrace_may_access(task, PTRACE_MODE_READ);
49004 }
49005
49006 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49007 put_task_struct(task);
49008
49009 if (!has_perms) {
49010 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49011 + {
49012 +#else
49013 if (pid->hide_pid == 2) {
49014 +#endif
49015 /*
49016 * Let's make getdents(), stat(), and open()
49017 * consistent with each other. If a process
49018 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49019 if (!task)
49020 return -ESRCH;
49021
49022 + if (gr_acl_handle_procpidmem(task)) {
49023 + put_task_struct(task);
49024 + return -EPERM;
49025 + }
49026 +
49027 mm = mm_access(task, mode);
49028 put_task_struct(task);
49029
49030 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49031
49032 file->private_data = mm;
49033
49034 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49035 + file->f_version = current->exec_id;
49036 +#endif
49037 +
49038 return 0;
49039 }
49040
49041 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49042 ssize_t copied;
49043 char *page;
49044
49045 +#ifdef CONFIG_GRKERNSEC
49046 + if (write)
49047 + return -EPERM;
49048 +#endif
49049 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49050 + if (file->f_version != current->exec_id) {
49051 + gr_log_badprocpid("mem");
49052 + return 0;
49053 + }
49054 +#endif
49055 +
49056 if (!mm)
49057 return 0;
49058
49059 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49060 if (!mm)
49061 return 0;
49062
49063 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49064 + if (file->f_version != current->exec_id) {
49065 + gr_log_badprocpid("environ");
49066 + return 0;
49067 + }
49068 +#endif
49069 +
49070 page = (char *)__get_free_page(GFP_TEMPORARY);
49071 if (!page)
49072 return -ENOMEM;
49073 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49074 int error = -EACCES;
49075
49076 /* Are we allowed to snoop on the tasks file descriptors? */
49077 - if (!proc_fd_access_allowed(inode))
49078 + if (!proc_fd_access_allowed(inode, 0))
49079 goto out;
49080
49081 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49082 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49083 struct path path;
49084
49085 /* Are we allowed to snoop on the tasks file descriptors? */
49086 - if (!proc_fd_access_allowed(inode))
49087 - goto out;
49088 + /* logging this is needed for learning on chromium to work properly,
49089 + but we don't want to flood the logs from 'ps' which does a readlink
49090 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49091 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49092 + */
49093 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49094 + if (!proc_fd_access_allowed(inode,0))
49095 + goto out;
49096 + } else {
49097 + if (!proc_fd_access_allowed(inode,1))
49098 + goto out;
49099 + }
49100
49101 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49102 if (error)
49103 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49104 rcu_read_lock();
49105 cred = __task_cred(task);
49106 inode->i_uid = cred->euid;
49107 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49108 + inode->i_gid = grsec_proc_gid;
49109 +#else
49110 inode->i_gid = cred->egid;
49111 +#endif
49112 rcu_read_unlock();
49113 }
49114 security_task_to_inode(task, inode);
49115 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49116 return -ENOENT;
49117 }
49118 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49119 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49120 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49121 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49122 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49123 +#endif
49124 task_dumpable(task)) {
49125 cred = __task_cred(task);
49126 stat->uid = cred->euid;
49127 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49128 + stat->gid = grsec_proc_gid;
49129 +#else
49130 stat->gid = cred->egid;
49131 +#endif
49132 }
49133 }
49134 rcu_read_unlock();
49135 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49136
49137 if (task) {
49138 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49139 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49140 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49141 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49142 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49143 +#endif
49144 task_dumpable(task)) {
49145 rcu_read_lock();
49146 cred = __task_cred(task);
49147 inode->i_uid = cred->euid;
49148 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49149 + inode->i_gid = grsec_proc_gid;
49150 +#else
49151 inode->i_gid = cred->egid;
49152 +#endif
49153 rcu_read_unlock();
49154 } else {
49155 inode->i_uid = GLOBAL_ROOT_UID;
49156 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49157 int fd = proc_fd(inode);
49158
49159 if (task) {
49160 - files = get_files_struct(task);
49161 + if (!gr_acl_handle_procpidmem(task))
49162 + files = get_files_struct(task);
49163 put_task_struct(task);
49164 }
49165 if (files) {
49166 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49167 */
49168 static int proc_fd_permission(struct inode *inode, int mask)
49169 {
49170 + struct task_struct *task;
49171 int rv = generic_permission(inode, mask);
49172 - if (rv == 0)
49173 - return 0;
49174 +
49175 if (task_pid(current) == proc_pid(inode))
49176 rv = 0;
49177 +
49178 + task = get_proc_task(inode);
49179 + if (task == NULL)
49180 + return rv;
49181 +
49182 + if (gr_acl_handle_procpidmem(task))
49183 + rv = -EACCES;
49184 +
49185 + put_task_struct(task);
49186 +
49187 return rv;
49188 }
49189
49190 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49191 if (!task)
49192 goto out_no_task;
49193
49194 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49195 + goto out;
49196 +
49197 /*
49198 * Yes, it does not scale. And it should not. Don't add
49199 * new entries into /proc/<tgid>/ without very good reasons.
49200 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49201 if (!task)
49202 goto out_no_task;
49203
49204 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49205 + goto out;
49206 +
49207 ret = 0;
49208 i = filp->f_pos;
49209 switch (i) {
49210 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49211 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49212 void *cookie)
49213 {
49214 - char *s = nd_get_link(nd);
49215 + const char *s = nd_get_link(nd);
49216 if (!IS_ERR(s))
49217 __putname(s);
49218 }
49219 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49220 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49221 #endif
49222 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49223 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49224 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49225 INF("syscall", S_IRUGO, proc_pid_syscall),
49226 #endif
49227 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49228 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49229 #ifdef CONFIG_SECURITY
49230 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49231 #endif
49232 -#ifdef CONFIG_KALLSYMS
49233 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49234 INF("wchan", S_IRUGO, proc_pid_wchan),
49235 #endif
49236 -#ifdef CONFIG_STACKTRACE
49237 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49238 ONE("stack", S_IRUGO, proc_pid_stack),
49239 #endif
49240 #ifdef CONFIG_SCHEDSTATS
49241 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49242 #ifdef CONFIG_HARDWALL
49243 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49244 #endif
49245 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49246 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49247 +#endif
49248 #ifdef CONFIG_USER_NS
49249 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49250 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49251 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49252 if (!inode)
49253 goto out;
49254
49255 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49256 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49257 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49258 + inode->i_gid = grsec_proc_gid;
49259 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49260 +#else
49261 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49262 +#endif
49263 inode->i_op = &proc_tgid_base_inode_operations;
49264 inode->i_fop = &proc_tgid_base_operations;
49265 inode->i_flags|=S_IMMUTABLE;
49266 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49267 if (!task)
49268 goto out;
49269
49270 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49271 + goto out_put_task;
49272 +
49273 result = proc_pid_instantiate(dir, dentry, task, NULL);
49274 +out_put_task:
49275 put_task_struct(task);
49276 out:
49277 return result;
49278 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49279 static int fake_filldir(void *buf, const char *name, int namelen,
49280 loff_t offset, u64 ino, unsigned d_type)
49281 {
49282 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49283 + __buf->error = -EINVAL;
49284 return 0;
49285 }
49286
49287 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49288 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49289 #endif
49290 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49291 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49292 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49293 INF("syscall", S_IRUGO, proc_pid_syscall),
49294 #endif
49295 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49296 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49297 #ifdef CONFIG_SECURITY
49298 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49299 #endif
49300 -#ifdef CONFIG_KALLSYMS
49301 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49302 INF("wchan", S_IRUGO, proc_pid_wchan),
49303 #endif
49304 -#ifdef CONFIG_STACKTRACE
49305 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49306 ONE("stack", S_IRUGO, proc_pid_stack),
49307 #endif
49308 #ifdef CONFIG_SCHEDSTATS
49309 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49310 index 82676e3..5f8518a 100644
49311 --- a/fs/proc/cmdline.c
49312 +++ b/fs/proc/cmdline.c
49313 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49314
49315 static int __init proc_cmdline_init(void)
49316 {
49317 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49318 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49319 +#else
49320 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49321 +#endif
49322 return 0;
49323 }
49324 module_init(proc_cmdline_init);
49325 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49326 index b143471..bb105e5 100644
49327 --- a/fs/proc/devices.c
49328 +++ b/fs/proc/devices.c
49329 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49330
49331 static int __init proc_devices_init(void)
49332 {
49333 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49334 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49335 +#else
49336 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49337 +#endif
49338 return 0;
49339 }
49340 module_init(proc_devices_init);
49341 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49342 index 7ac817b..c5c9eb0 100644
49343 --- a/fs/proc/inode.c
49344 +++ b/fs/proc/inode.c
49345 @@ -21,11 +21,17 @@
49346 #include <linux/seq_file.h>
49347 #include <linux/slab.h>
49348 #include <linux/mount.h>
49349 +#include <linux/grsecurity.h>
49350
49351 #include <asm/uaccess.h>
49352
49353 #include "internal.h"
49354
49355 +#ifdef CONFIG_PROC_SYSCTL
49356 +extern const struct inode_operations proc_sys_inode_operations;
49357 +extern const struct inode_operations proc_sys_dir_operations;
49358 +#endif
49359 +
49360 static void proc_evict_inode(struct inode *inode)
49361 {
49362 struct proc_dir_entry *de;
49363 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49364 ns_ops = PROC_I(inode)->ns_ops;
49365 if (ns_ops && ns_ops->put)
49366 ns_ops->put(PROC_I(inode)->ns);
49367 +
49368 +#ifdef CONFIG_PROC_SYSCTL
49369 + if (inode->i_op == &proc_sys_inode_operations ||
49370 + inode->i_op == &proc_sys_dir_operations)
49371 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49372 +#endif
49373 +
49374 }
49375
49376 static struct kmem_cache * proc_inode_cachep;
49377 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49378 if (de->mode) {
49379 inode->i_mode = de->mode;
49380 inode->i_uid = de->uid;
49381 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49382 + inode->i_gid = grsec_proc_gid;
49383 +#else
49384 inode->i_gid = de->gid;
49385 +#endif
49386 }
49387 if (de->size)
49388 inode->i_size = de->size;
49389 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49390 index e1167a1..bd24f20 100644
49391 --- a/fs/proc/internal.h
49392 +++ b/fs/proc/internal.h
49393 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49394 struct pid *pid, struct task_struct *task);
49395 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49396 struct pid *pid, struct task_struct *task);
49397 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49398 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49399 +#endif
49400 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49401
49402 extern const struct file_operations proc_tid_children_operations;
49403 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49404 index 86c67ee..cdca321 100644
49405 --- a/fs/proc/kcore.c
49406 +++ b/fs/proc/kcore.c
49407 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49408 * the addresses in the elf_phdr on our list.
49409 */
49410 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49411 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49412 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49413 + if (tsz > buflen)
49414 tsz = buflen;
49415 -
49416 +
49417 while (buflen) {
49418 struct kcore_list *m;
49419
49420 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49421 kfree(elf_buf);
49422 } else {
49423 if (kern_addr_valid(start)) {
49424 - unsigned long n;
49425 + char *elf_buf;
49426 + mm_segment_t oldfs;
49427
49428 - n = copy_to_user(buffer, (char *)start, tsz);
49429 - /*
49430 - * We cannot distinguish between fault on source
49431 - * and fault on destination. When this happens
49432 - * we clear too and hope it will trigger the
49433 - * EFAULT again.
49434 - */
49435 - if (n) {
49436 - if (clear_user(buffer + tsz - n,
49437 - n))
49438 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49439 + if (!elf_buf)
49440 + return -ENOMEM;
49441 + oldfs = get_fs();
49442 + set_fs(KERNEL_DS);
49443 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49444 + set_fs(oldfs);
49445 + if (copy_to_user(buffer, elf_buf, tsz)) {
49446 + kfree(elf_buf);
49447 return -EFAULT;
49448 + }
49449 }
49450 + set_fs(oldfs);
49451 + kfree(elf_buf);
49452 } else {
49453 if (clear_user(buffer, tsz))
49454 return -EFAULT;
49455 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49456
49457 static int open_kcore(struct inode *inode, struct file *filp)
49458 {
49459 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49460 + return -EPERM;
49461 +#endif
49462 if (!capable(CAP_SYS_RAWIO))
49463 return -EPERM;
49464 if (kcore_need_update)
49465 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49466 index 80e4645..53e5fcf 100644
49467 --- a/fs/proc/meminfo.c
49468 +++ b/fs/proc/meminfo.c
49469 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49470 vmi.used >> 10,
49471 vmi.largest_chunk >> 10
49472 #ifdef CONFIG_MEMORY_FAILURE
49473 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49474 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49475 #endif
49476 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49477 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49478 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49479 index b1822dd..df622cb 100644
49480 --- a/fs/proc/nommu.c
49481 +++ b/fs/proc/nommu.c
49482 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49483 if (len < 1)
49484 len = 1;
49485 seq_printf(m, "%*c", len, ' ');
49486 - seq_path(m, &file->f_path, "");
49487 + seq_path(m, &file->f_path, "\n\\");
49488 }
49489
49490 seq_putc(m, '\n');
49491 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49492 index fe72cd0..cb9b67d 100644
49493 --- a/fs/proc/proc_net.c
49494 +++ b/fs/proc/proc_net.c
49495 @@ -23,6 +23,7 @@
49496 #include <linux/nsproxy.h>
49497 #include <net/net_namespace.h>
49498 #include <linux/seq_file.h>
49499 +#include <linux/grsecurity.h>
49500
49501 #include "internal.h"
49502
49503 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49504 struct task_struct *task;
49505 struct nsproxy *ns;
49506 struct net *net = NULL;
49507 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49508 + const struct cred *cred = current_cred();
49509 +#endif
49510 +
49511 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49512 + if (cred->fsuid)
49513 + return net;
49514 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49515 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49516 + return net;
49517 +#endif
49518
49519 rcu_read_lock();
49520 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49521 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49522 index eb7cc91..7327a46 100644
49523 --- a/fs/proc/proc_sysctl.c
49524 +++ b/fs/proc/proc_sysctl.c
49525 @@ -12,11 +12,15 @@
49526 #include <linux/module.h>
49527 #include "internal.h"
49528
49529 +extern int gr_handle_chroot_sysctl(const int op);
49530 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49531 + const int op);
49532 +
49533 static const struct dentry_operations proc_sys_dentry_operations;
49534 static const struct file_operations proc_sys_file_operations;
49535 -static const struct inode_operations proc_sys_inode_operations;
49536 +const struct inode_operations proc_sys_inode_operations;
49537 static const struct file_operations proc_sys_dir_file_operations;
49538 -static const struct inode_operations proc_sys_dir_operations;
49539 +const struct inode_operations proc_sys_dir_operations;
49540
49541 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49542 {
49543 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49544
49545 err = NULL;
49546 d_set_d_op(dentry, &proc_sys_dentry_operations);
49547 +
49548 + gr_handle_proc_create(dentry, inode);
49549 +
49550 d_add(dentry, inode);
49551
49552 out:
49553 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49554 struct inode *inode = filp->f_path.dentry->d_inode;
49555 struct ctl_table_header *head = grab_header(inode);
49556 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49557 + int op = write ? MAY_WRITE : MAY_READ;
49558 ssize_t error;
49559 size_t res;
49560
49561 if (IS_ERR(head))
49562 return PTR_ERR(head);
49563
49564 +
49565 /*
49566 * At this point we know that the sysctl was not unregistered
49567 * and won't be until we finish.
49568 */
49569 error = -EPERM;
49570 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49571 + if (sysctl_perm(head->root, table, op))
49572 goto out;
49573
49574 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49575 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49576 if (!table->proc_handler)
49577 goto out;
49578
49579 +#ifdef CONFIG_GRKERNSEC
49580 + error = -EPERM;
49581 + if (gr_handle_chroot_sysctl(op))
49582 + goto out;
49583 + dget(filp->f_path.dentry);
49584 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49585 + dput(filp->f_path.dentry);
49586 + goto out;
49587 + }
49588 + dput(filp->f_path.dentry);
49589 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49590 + goto out;
49591 + if (write && !capable(CAP_SYS_ADMIN))
49592 + goto out;
49593 +#endif
49594 +
49595 /* careful: calling conventions are nasty here */
49596 res = count;
49597 error = table->proc_handler(table, write, buf, &res, ppos);
49598 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49599 return -ENOMEM;
49600 } else {
49601 d_set_d_op(child, &proc_sys_dentry_operations);
49602 +
49603 + gr_handle_proc_create(child, inode);
49604 +
49605 d_add(child, inode);
49606 }
49607 } else {
49608 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49609 if ((*pos)++ < file->f_pos)
49610 return 0;
49611
49612 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49613 + return 0;
49614 +
49615 if (unlikely(S_ISLNK(table->mode)))
49616 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49617 else
49618 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49619 if (IS_ERR(head))
49620 return PTR_ERR(head);
49621
49622 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49623 + return -ENOENT;
49624 +
49625 generic_fillattr(inode, stat);
49626 if (table)
49627 stat->mode = (stat->mode & S_IFMT) | table->mode;
49628 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49629 .llseek = generic_file_llseek,
49630 };
49631
49632 -static const struct inode_operations proc_sys_inode_operations = {
49633 +const struct inode_operations proc_sys_inode_operations = {
49634 .permission = proc_sys_permission,
49635 .setattr = proc_sys_setattr,
49636 .getattr = proc_sys_getattr,
49637 };
49638
49639 -static const struct inode_operations proc_sys_dir_operations = {
49640 +const struct inode_operations proc_sys_dir_operations = {
49641 .lookup = proc_sys_lookup,
49642 .permission = proc_sys_permission,
49643 .setattr = proc_sys_setattr,
49644 diff --git a/fs/proc/root.c b/fs/proc/root.c
49645 index 9a2d9fd..ddfc92a 100644
49646 --- a/fs/proc/root.c
49647 +++ b/fs/proc/root.c
49648 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49649 #ifdef CONFIG_PROC_DEVICETREE
49650 proc_device_tree_init();
49651 #endif
49652 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49653 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49654 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49655 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49656 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49657 +#endif
49658 +#else
49659 proc_mkdir("bus", NULL);
49660 +#endif
49661 proc_sys_init();
49662 }
49663
49664 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49665 index 4540b8f..1b9772f 100644
49666 --- a/fs/proc/task_mmu.c
49667 +++ b/fs/proc/task_mmu.c
49668 @@ -11,12 +11,19 @@
49669 #include <linux/rmap.h>
49670 #include <linux/swap.h>
49671 #include <linux/swapops.h>
49672 +#include <linux/grsecurity.h>
49673
49674 #include <asm/elf.h>
49675 #include <asm/uaccess.h>
49676 #include <asm/tlbflush.h>
49677 #include "internal.h"
49678
49679 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49680 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49681 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49682 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49683 +#endif
49684 +
49685 void task_mem(struct seq_file *m, struct mm_struct *mm)
49686 {
49687 unsigned long data, text, lib, swap;
49688 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49689 "VmExe:\t%8lu kB\n"
49690 "VmLib:\t%8lu kB\n"
49691 "VmPTE:\t%8lu kB\n"
49692 - "VmSwap:\t%8lu kB\n",
49693 - hiwater_vm << (PAGE_SHIFT-10),
49694 + "VmSwap:\t%8lu kB\n"
49695 +
49696 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49697 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49698 +#endif
49699 +
49700 + ,hiwater_vm << (PAGE_SHIFT-10),
49701 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49702 mm->locked_vm << (PAGE_SHIFT-10),
49703 mm->pinned_vm << (PAGE_SHIFT-10),
49704 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49705 data << (PAGE_SHIFT-10),
49706 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49707 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49708 - swap << (PAGE_SHIFT-10));
49709 + swap << (PAGE_SHIFT-10)
49710 +
49711 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49712 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49713 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49714 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49715 +#else
49716 + , mm->context.user_cs_base
49717 + , mm->context.user_cs_limit
49718 +#endif
49719 +#endif
49720 +
49721 + );
49722 }
49723
49724 unsigned long task_vsize(struct mm_struct *mm)
49725 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49726 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49727 }
49728
49729 - /* We don't show the stack guard page in /proc/maps */
49730 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49731 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49732 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49733 +#else
49734 start = vma->vm_start;
49735 - if (stack_guard_page_start(vma, start))
49736 - start += PAGE_SIZE;
49737 end = vma->vm_end;
49738 - if (stack_guard_page_end(vma, end))
49739 - end -= PAGE_SIZE;
49740 +#endif
49741
49742 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49743 start,
49744 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49745 flags & VM_WRITE ? 'w' : '-',
49746 flags & VM_EXEC ? 'x' : '-',
49747 flags & VM_MAYSHARE ? 's' : 'p',
49748 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49749 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49750 +#else
49751 pgoff,
49752 +#endif
49753 MAJOR(dev), MINOR(dev), ino, &len);
49754
49755 /*
49756 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49757 */
49758 if (file) {
49759 pad_len_spaces(m, len);
49760 - seq_path(m, &file->f_path, "\n");
49761 + seq_path(m, &file->f_path, "\n\\");
49762 goto done;
49763 }
49764
49765 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49766 * Thread stack in /proc/PID/task/TID/maps or
49767 * the main process stack.
49768 */
49769 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49770 - vma->vm_end >= mm->start_stack)) {
49771 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49772 + (vma->vm_start <= mm->start_stack &&
49773 + vma->vm_end >= mm->start_stack)) {
49774 name = "[stack]";
49775 } else {
49776 /* Thread stack in /proc/PID/maps */
49777 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49778 struct proc_maps_private *priv = m->private;
49779 struct task_struct *task = priv->task;
49780
49781 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49782 + if (current->exec_id != m->exec_id) {
49783 + gr_log_badprocpid("maps");
49784 + return 0;
49785 + }
49786 +#endif
49787 +
49788 show_map_vma(m, vma, is_pid);
49789
49790 if (m->count < m->size) /* vma is copied successfully */
49791 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49792 .private = &mss,
49793 };
49794
49795 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49796 + if (current->exec_id != m->exec_id) {
49797 + gr_log_badprocpid("smaps");
49798 + return 0;
49799 + }
49800 +#endif
49801 memset(&mss, 0, sizeof mss);
49802 - mss.vma = vma;
49803 - /* mmap_sem is held in m_start */
49804 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49805 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49806 -
49807 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49808 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49809 +#endif
49810 + mss.vma = vma;
49811 + /* mmap_sem is held in m_start */
49812 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49813 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49815 + }
49816 +#endif
49817 show_map_vma(m, vma, is_pid);
49818
49819 seq_printf(m,
49820 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49821 "KernelPageSize: %8lu kB\n"
49822 "MMUPageSize: %8lu kB\n"
49823 "Locked: %8lu kB\n",
49824 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49825 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49826 +#else
49827 (vma->vm_end - vma->vm_start) >> 10,
49828 +#endif
49829 mss.resident >> 10,
49830 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49831 mss.shared_clean >> 10,
49832 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49833 int n;
49834 char buffer[50];
49835
49836 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49837 + if (current->exec_id != m->exec_id) {
49838 + gr_log_badprocpid("numa_maps");
49839 + return 0;
49840 + }
49841 +#endif
49842 +
49843 if (!mm)
49844 return 0;
49845
49846 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49847 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49848 mpol_cond_put(pol);
49849
49850 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49851 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49852 +#else
49853 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49854 +#endif
49855
49856 if (file) {
49857 seq_printf(m, " file=");
49858 - seq_path(m, &file->f_path, "\n\t= ");
49859 + seq_path(m, &file->f_path, "\n\t\\= ");
49860 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49861 seq_printf(m, " heap");
49862 } else {
49863 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49864 index 1ccfa53..0848f95 100644
49865 --- a/fs/proc/task_nommu.c
49866 +++ b/fs/proc/task_nommu.c
49867 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49868 else
49869 bytes += kobjsize(mm);
49870
49871 - if (current->fs && current->fs->users > 1)
49872 + if (current->fs && atomic_read(&current->fs->users) > 1)
49873 sbytes += kobjsize(current->fs);
49874 else
49875 bytes += kobjsize(current->fs);
49876 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49877
49878 if (file) {
49879 pad_len_spaces(m, len);
49880 - seq_path(m, &file->f_path, "");
49881 + seq_path(m, &file->f_path, "\n\\");
49882 } else if (mm) {
49883 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49884
49885 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49886 index d67908b..d13f6a6 100644
49887 --- a/fs/quota/netlink.c
49888 +++ b/fs/quota/netlink.c
49889 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49890 void quota_send_warning(short type, unsigned int id, dev_t dev,
49891 const char warntype)
49892 {
49893 - static atomic_t seq;
49894 + static atomic_unchecked_t seq;
49895 struct sk_buff *skb;
49896 void *msg_head;
49897 int ret;
49898 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49899 "VFS: Not enough memory to send quota warning.\n");
49900 return;
49901 }
49902 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49903 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49904 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49905 if (!msg_head) {
49906 printk(KERN_ERR
49907 diff --git a/fs/readdir.c b/fs/readdir.c
49908 index 39e3370..20d446d 100644
49909 --- a/fs/readdir.c
49910 +++ b/fs/readdir.c
49911 @@ -17,6 +17,7 @@
49912 #include <linux/security.h>
49913 #include <linux/syscalls.h>
49914 #include <linux/unistd.h>
49915 +#include <linux/namei.h>
49916
49917 #include <asm/uaccess.h>
49918
49919 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49920
49921 struct readdir_callback {
49922 struct old_linux_dirent __user * dirent;
49923 + struct file * file;
49924 int result;
49925 };
49926
49927 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49928 buf->result = -EOVERFLOW;
49929 return -EOVERFLOW;
49930 }
49931 +
49932 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49933 + return 0;
49934 +
49935 buf->result++;
49936 dirent = buf->dirent;
49937 if (!access_ok(VERIFY_WRITE, dirent,
49938 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49939
49940 buf.result = 0;
49941 buf.dirent = dirent;
49942 + buf.file = file;
49943
49944 error = vfs_readdir(file, fillonedir, &buf);
49945 if (buf.result)
49946 @@ -141,6 +148,7 @@ struct linux_dirent {
49947 struct getdents_callback {
49948 struct linux_dirent __user * current_dir;
49949 struct linux_dirent __user * previous;
49950 + struct file * file;
49951 int count;
49952 int error;
49953 };
49954 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49955 buf->error = -EOVERFLOW;
49956 return -EOVERFLOW;
49957 }
49958 +
49959 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49960 + return 0;
49961 +
49962 dirent = buf->previous;
49963 if (dirent) {
49964 if (__put_user(offset, &dirent->d_off))
49965 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49966 buf.previous = NULL;
49967 buf.count = count;
49968 buf.error = 0;
49969 + buf.file = file;
49970
49971 error = vfs_readdir(file, filldir, &buf);
49972 if (error >= 0)
49973 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49974 struct getdents_callback64 {
49975 struct linux_dirent64 __user * current_dir;
49976 struct linux_dirent64 __user * previous;
49977 + struct file *file;
49978 int count;
49979 int error;
49980 };
49981 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49982 buf->error = -EINVAL; /* only used if we fail.. */
49983 if (reclen > buf->count)
49984 return -EINVAL;
49985 +
49986 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49987 + return 0;
49988 +
49989 dirent = buf->previous;
49990 if (dirent) {
49991 if (__put_user(offset, &dirent->d_off))
49992 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49993
49994 buf.current_dir = dirent;
49995 buf.previous = NULL;
49996 + buf.file = file;
49997 buf.count = count;
49998 buf.error = 0;
49999
50000 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50001 error = buf.error;
50002 lastdirent = buf.previous;
50003 if (lastdirent) {
50004 - typeof(lastdirent->d_off) d_off = file->f_pos;
50005 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50006 if (__put_user(d_off, &lastdirent->d_off))
50007 error = -EFAULT;
50008 else
50009 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50010 index 2b7882b..1c5ef48 100644
50011 --- a/fs/reiserfs/do_balan.c
50012 +++ b/fs/reiserfs/do_balan.c
50013 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50014 return;
50015 }
50016
50017 - atomic_inc(&(fs_generation(tb->tb_sb)));
50018 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50019 do_balance_starts(tb);
50020
50021 /* balance leaf returns 0 except if combining L R and S into
50022 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50023 index e60e870..f40ac16 100644
50024 --- a/fs/reiserfs/procfs.c
50025 +++ b/fs/reiserfs/procfs.c
50026 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50027 "SMALL_TAILS " : "NO_TAILS ",
50028 replay_only(sb) ? "REPLAY_ONLY " : "",
50029 convert_reiserfs(sb) ? "CONV " : "",
50030 - atomic_read(&r->s_generation_counter),
50031 + atomic_read_unchecked(&r->s_generation_counter),
50032 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50033 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50034 SF(s_good_search_by_key_reada), SF(s_bmaps),
50035 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50036 index 33215f5..c5d427a 100644
50037 --- a/fs/reiserfs/reiserfs.h
50038 +++ b/fs/reiserfs/reiserfs.h
50039 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50040 /* Comment? -Hans */
50041 wait_queue_head_t s_wait;
50042 /* To be obsoleted soon by per buffer seals.. -Hans */
50043 - atomic_t s_generation_counter; // increased by one every time the
50044 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50045 // tree gets re-balanced
50046 unsigned long s_properties; /* File system properties. Currently holds
50047 on-disk FS format */
50048 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50049 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50050
50051 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50052 -#define get_generation(s) atomic_read (&fs_generation(s))
50053 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50054 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50055 #define __fs_changed(gen,s) (gen != get_generation (s))
50056 #define fs_changed(gen,s) \
50057 diff --git a/fs/select.c b/fs/select.c
50058 index db14c78..3aae1bd 100644
50059 --- a/fs/select.c
50060 +++ b/fs/select.c
50061 @@ -20,6 +20,7 @@
50062 #include <linux/export.h>
50063 #include <linux/slab.h>
50064 #include <linux/poll.h>
50065 +#include <linux/security.h>
50066 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50067 #include <linux/file.h>
50068 #include <linux/fdtable.h>
50069 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50070 struct poll_list *walk = head;
50071 unsigned long todo = nfds;
50072
50073 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50074 if (nfds > rlimit(RLIMIT_NOFILE))
50075 return -EINVAL;
50076
50077 diff --git a/fs/seq_file.c b/fs/seq_file.c
50078 index 14cf9de..adc4d5b 100644
50079 --- a/fs/seq_file.c
50080 +++ b/fs/seq_file.c
50081 @@ -9,6 +9,7 @@
50082 #include <linux/export.h>
50083 #include <linux/seq_file.h>
50084 #include <linux/slab.h>
50085 +#include <linux/sched.h>
50086
50087 #include <asm/uaccess.h>
50088 #include <asm/page.h>
50089 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50090 memset(p, 0, sizeof(*p));
50091 mutex_init(&p->lock);
50092 p->op = op;
50093 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50094 + p->exec_id = current->exec_id;
50095 +#endif
50096
50097 /*
50098 * Wrappers around seq_open(e.g. swaps_open) need to be
50099 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50100 return 0;
50101 }
50102 if (!m->buf) {
50103 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50104 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50105 if (!m->buf)
50106 return -ENOMEM;
50107 }
50108 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50109 Eoverflow:
50110 m->op->stop(m, p);
50111 kfree(m->buf);
50112 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50113 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50114 return !m->buf ? -ENOMEM : -EAGAIN;
50115 }
50116
50117 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50118
50119 /* grab buffer if we didn't have one */
50120 if (!m->buf) {
50121 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50122 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50123 if (!m->buf)
50124 goto Enomem;
50125 }
50126 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50127 goto Fill;
50128 m->op->stop(m, p);
50129 kfree(m->buf);
50130 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50131 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50132 if (!m->buf)
50133 goto Enomem;
50134 m->count = 0;
50135 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50136 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50137 void *data)
50138 {
50139 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50140 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50141 int res = -ENOMEM;
50142
50143 if (op) {
50144 diff --git a/fs/splice.c b/fs/splice.c
50145 index 41514dd..6564a93 100644
50146 --- a/fs/splice.c
50147 +++ b/fs/splice.c
50148 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50149 pipe_lock(pipe);
50150
50151 for (;;) {
50152 - if (!pipe->readers) {
50153 + if (!atomic_read(&pipe->readers)) {
50154 send_sig(SIGPIPE, current, 0);
50155 if (!ret)
50156 ret = -EPIPE;
50157 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50158 do_wakeup = 0;
50159 }
50160
50161 - pipe->waiting_writers++;
50162 + atomic_inc(&pipe->waiting_writers);
50163 pipe_wait(pipe);
50164 - pipe->waiting_writers--;
50165 + atomic_dec(&pipe->waiting_writers);
50166 }
50167
50168 pipe_unlock(pipe);
50169 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50170 old_fs = get_fs();
50171 set_fs(get_ds());
50172 /* The cast to a user pointer is valid due to the set_fs() */
50173 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50174 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50175 set_fs(old_fs);
50176
50177 return res;
50178 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50179 old_fs = get_fs();
50180 set_fs(get_ds());
50181 /* The cast to a user pointer is valid due to the set_fs() */
50182 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50183 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50184 set_fs(old_fs);
50185
50186 return res;
50187 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50188 goto err;
50189
50190 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50191 - vec[i].iov_base = (void __user *) page_address(page);
50192 + vec[i].iov_base = (void __force_user *) page_address(page);
50193 vec[i].iov_len = this_len;
50194 spd.pages[i] = page;
50195 spd.nr_pages++;
50196 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50197 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50198 {
50199 while (!pipe->nrbufs) {
50200 - if (!pipe->writers)
50201 + if (!atomic_read(&pipe->writers))
50202 return 0;
50203
50204 - if (!pipe->waiting_writers && sd->num_spliced)
50205 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50206 return 0;
50207
50208 if (sd->flags & SPLICE_F_NONBLOCK)
50209 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50210 * out of the pipe right after the splice_to_pipe(). So set
50211 * PIPE_READERS appropriately.
50212 */
50213 - pipe->readers = 1;
50214 + atomic_set(&pipe->readers, 1);
50215
50216 current->splice_pipe = pipe;
50217 }
50218 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50219 ret = -ERESTARTSYS;
50220 break;
50221 }
50222 - if (!pipe->writers)
50223 + if (!atomic_read(&pipe->writers))
50224 break;
50225 - if (!pipe->waiting_writers) {
50226 + if (!atomic_read(&pipe->waiting_writers)) {
50227 if (flags & SPLICE_F_NONBLOCK) {
50228 ret = -EAGAIN;
50229 break;
50230 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50231 pipe_lock(pipe);
50232
50233 while (pipe->nrbufs >= pipe->buffers) {
50234 - if (!pipe->readers) {
50235 + if (!atomic_read(&pipe->readers)) {
50236 send_sig(SIGPIPE, current, 0);
50237 ret = -EPIPE;
50238 break;
50239 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50240 ret = -ERESTARTSYS;
50241 break;
50242 }
50243 - pipe->waiting_writers++;
50244 + atomic_inc(&pipe->waiting_writers);
50245 pipe_wait(pipe);
50246 - pipe->waiting_writers--;
50247 + atomic_dec(&pipe->waiting_writers);
50248 }
50249
50250 pipe_unlock(pipe);
50251 @@ -1828,14 +1828,14 @@ retry:
50252 pipe_double_lock(ipipe, opipe);
50253
50254 do {
50255 - if (!opipe->readers) {
50256 + if (!atomic_read(&opipe->readers)) {
50257 send_sig(SIGPIPE, current, 0);
50258 if (!ret)
50259 ret = -EPIPE;
50260 break;
50261 }
50262
50263 - if (!ipipe->nrbufs && !ipipe->writers)
50264 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50265 break;
50266
50267 /*
50268 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50269 pipe_double_lock(ipipe, opipe);
50270
50271 do {
50272 - if (!opipe->readers) {
50273 + if (!atomic_read(&opipe->readers)) {
50274 send_sig(SIGPIPE, current, 0);
50275 if (!ret)
50276 ret = -EPIPE;
50277 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50278 * return EAGAIN if we have the potential of some data in the
50279 * future, otherwise just return 0
50280 */
50281 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50282 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50283 ret = -EAGAIN;
50284
50285 pipe_unlock(ipipe);
50286 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50287 index 2fbdff6..5530a61 100644
50288 --- a/fs/sysfs/dir.c
50289 +++ b/fs/sysfs/dir.c
50290 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50291 struct sysfs_dirent *sd;
50292 int rc;
50293
50294 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50295 + const char *parent_name = parent_sd->s_name;
50296 +
50297 + mode = S_IFDIR | S_IRWXU;
50298 +
50299 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50300 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50301 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50302 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50303 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50304 +#endif
50305 +
50306 /* allocate */
50307 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50308 if (!sd)
50309 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50310 index 00012e3..8392349 100644
50311 --- a/fs/sysfs/file.c
50312 +++ b/fs/sysfs/file.c
50313 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50314
50315 struct sysfs_open_dirent {
50316 atomic_t refcnt;
50317 - atomic_t event;
50318 + atomic_unchecked_t event;
50319 wait_queue_head_t poll;
50320 struct list_head buffers; /* goes through sysfs_buffer.list */
50321 };
50322 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50323 if (!sysfs_get_active(attr_sd))
50324 return -ENODEV;
50325
50326 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50327 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50328 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50329
50330 sysfs_put_active(attr_sd);
50331 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50332 return -ENOMEM;
50333
50334 atomic_set(&new_od->refcnt, 0);
50335 - atomic_set(&new_od->event, 1);
50336 + atomic_set_unchecked(&new_od->event, 1);
50337 init_waitqueue_head(&new_od->poll);
50338 INIT_LIST_HEAD(&new_od->buffers);
50339 goto retry;
50340 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50341
50342 sysfs_put_active(attr_sd);
50343
50344 - if (buffer->event != atomic_read(&od->event))
50345 + if (buffer->event != atomic_read_unchecked(&od->event))
50346 goto trigger;
50347
50348 return DEFAULT_POLLMASK;
50349 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50350
50351 od = sd->s_attr.open;
50352 if (od) {
50353 - atomic_inc(&od->event);
50354 + atomic_inc_unchecked(&od->event);
50355 wake_up_interruptible(&od->poll);
50356 }
50357
50358 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50359 index a7ac78f..02158e1 100644
50360 --- a/fs/sysfs/symlink.c
50361 +++ b/fs/sysfs/symlink.c
50362 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50363
50364 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50365 {
50366 - char *page = nd_get_link(nd);
50367 + const char *page = nd_get_link(nd);
50368 if (!IS_ERR(page))
50369 free_page((unsigned long)page);
50370 }
50371 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50372 index c175b4d..8f36a16 100644
50373 --- a/fs/udf/misc.c
50374 +++ b/fs/udf/misc.c
50375 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50376
50377 u8 udf_tag_checksum(const struct tag *t)
50378 {
50379 - u8 *data = (u8 *)t;
50380 + const u8 *data = (const u8 *)t;
50381 u8 checksum = 0;
50382 int i;
50383 for (i = 0; i < sizeof(struct tag); ++i)
50384 diff --git a/fs/utimes.c b/fs/utimes.c
50385 index fa4dbe4..e12d1b9 100644
50386 --- a/fs/utimes.c
50387 +++ b/fs/utimes.c
50388 @@ -1,6 +1,7 @@
50389 #include <linux/compiler.h>
50390 #include <linux/file.h>
50391 #include <linux/fs.h>
50392 +#include <linux/security.h>
50393 #include <linux/linkage.h>
50394 #include <linux/mount.h>
50395 #include <linux/namei.h>
50396 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50397 goto mnt_drop_write_and_out;
50398 }
50399 }
50400 +
50401 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50402 + error = -EACCES;
50403 + goto mnt_drop_write_and_out;
50404 + }
50405 +
50406 mutex_lock(&inode->i_mutex);
50407 error = notify_change(path->dentry, &newattrs);
50408 mutex_unlock(&inode->i_mutex);
50409 diff --git a/fs/xattr.c b/fs/xattr.c
50410 index 4d45b71..2ec08e10 100644
50411 --- a/fs/xattr.c
50412 +++ b/fs/xattr.c
50413 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50414 * Extended attribute SET operations
50415 */
50416 static long
50417 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50418 +setxattr(struct path *path, const char __user *name, const void __user *value,
50419 size_t size, int flags)
50420 {
50421 int error;
50422 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50423 }
50424 }
50425
50426 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50427 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50428 + error = -EACCES;
50429 + goto out;
50430 + }
50431 +
50432 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50433 out:
50434 if (vvalue)
50435 vfree(vvalue);
50436 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50437 return error;
50438 error = mnt_want_write(path.mnt);
50439 if (!error) {
50440 - error = setxattr(path.dentry, name, value, size, flags);
50441 + error = setxattr(&path, name, value, size, flags);
50442 mnt_drop_write(path.mnt);
50443 }
50444 path_put(&path);
50445 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50446 return error;
50447 error = mnt_want_write(path.mnt);
50448 if (!error) {
50449 - error = setxattr(path.dentry, name, value, size, flags);
50450 + error = setxattr(&path, name, value, size, flags);
50451 mnt_drop_write(path.mnt);
50452 }
50453 path_put(&path);
50454 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50455 {
50456 int fput_needed;
50457 struct file *f;
50458 - struct dentry *dentry;
50459 int error = -EBADF;
50460
50461 f = fget_light(fd, &fput_needed);
50462 if (!f)
50463 return error;
50464 - dentry = f->f_path.dentry;
50465 - audit_inode(NULL, dentry);
50466 + audit_inode(NULL, f->f_path.dentry);
50467 error = mnt_want_write_file(f);
50468 if (!error) {
50469 - error = setxattr(dentry, name, value, size, flags);
50470 + error = setxattr(&f->f_path, name, value, size, flags);
50471 mnt_drop_write_file(f);
50472 }
50473 fput_light(f, fput_needed);
50474 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50475 index 69d06b0..c0996e5 100644
50476 --- a/fs/xattr_acl.c
50477 +++ b/fs/xattr_acl.c
50478 @@ -17,8 +17,8 @@
50479 struct posix_acl *
50480 posix_acl_from_xattr(const void *value, size_t size)
50481 {
50482 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50483 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50484 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50485 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50486 int count;
50487 struct posix_acl *acl;
50488 struct posix_acl_entry *acl_e;
50489 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50490 index 848ffa7..1f249bf 100644
50491 --- a/fs/xfs/xfs_bmap.c
50492 +++ b/fs/xfs/xfs_bmap.c
50493 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50494 int nmap,
50495 int ret_nmap);
50496 #else
50497 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50498 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50499 #endif /* DEBUG */
50500
50501 STATIC int
50502 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50503 index 1b9fc3e..e1bdde0 100644
50504 --- a/fs/xfs/xfs_dir2_sf.c
50505 +++ b/fs/xfs/xfs_dir2_sf.c
50506 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50507 }
50508
50509 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50510 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50511 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50512 + char name[sfep->namelen];
50513 + memcpy(name, sfep->name, sfep->namelen);
50514 + if (filldir(dirent, name, sfep->namelen,
50515 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50516 + *offset = off & 0x7fffffff;
50517 + return 0;
50518 + }
50519 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50520 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50521 *offset = off & 0x7fffffff;
50522 return 0;
50523 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50524 index 0e0232c..fa5c3fe 100644
50525 --- a/fs/xfs/xfs_ioctl.c
50526 +++ b/fs/xfs/xfs_ioctl.c
50527 @@ -126,7 +126,7 @@ xfs_find_handle(
50528 }
50529
50530 error = -EFAULT;
50531 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50532 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50533 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50534 goto out_put;
50535
50536 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50537 index 4e00cf0..3374374 100644
50538 --- a/fs/xfs/xfs_iops.c
50539 +++ b/fs/xfs/xfs_iops.c
50540 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50541 struct nameidata *nd,
50542 void *p)
50543 {
50544 - char *s = nd_get_link(nd);
50545 + const char *s = nd_get_link(nd);
50546
50547 if (!IS_ERR(s))
50548 kfree(s);
50549 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50550 new file mode 100644
50551 index 0000000..d38b430
50552 --- /dev/null
50553 +++ b/grsecurity/Kconfig
50554 @@ -0,0 +1,947 @@
50555 +#
50556 +# grecurity configuration
50557 +#
50558 +menu "Memory Protections"
50559 +depends on GRKERNSEC
50560 +
50561 +config GRKERNSEC_KMEM
50562 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50563 + default y if GRKERNSEC_CONFIG_AUTO
50564 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50565 + help
50566 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50567 + be written to or read from to modify or leak the contents of the running
50568 + kernel. /dev/port will also not be allowed to be opened. If you have module
50569 + support disabled, enabling this will close up four ways that are
50570 + currently used to insert malicious code into the running kernel.
50571 + Even with all these features enabled, we still highly recommend that
50572 + you use the RBAC system, as it is still possible for an attacker to
50573 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50574 + If you are not using XFree86, you may be able to stop this additional
50575 + case by enabling the 'Disable privileged I/O' option. Though nothing
50576 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50577 + but only to video memory, which is the only writing we allow in this
50578 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50579 + not be allowed to mprotect it with PROT_WRITE later.
50580 + It is highly recommended that you say Y here if you meet all the
50581 + conditions above.
50582 +
50583 +config GRKERNSEC_VM86
50584 + bool "Restrict VM86 mode"
50585 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50586 + depends on X86_32
50587 +
50588 + help
50589 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50590 + make use of a special execution mode on 32bit x86 processors called
50591 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50592 + video cards and will still work with this option enabled. The purpose
50593 + of the option is to prevent exploitation of emulation errors in
50594 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50595 + Nearly all users should be able to enable this option.
50596 +
50597 +config GRKERNSEC_IO
50598 + bool "Disable privileged I/O"
50599 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50600 + depends on X86
50601 + select RTC_CLASS
50602 + select RTC_INTF_DEV
50603 + select RTC_DRV_CMOS
50604 +
50605 + help
50606 + If you say Y here, all ioperm and iopl calls will return an error.
50607 + Ioperm and iopl can be used to modify the running kernel.
50608 + Unfortunately, some programs need this access to operate properly,
50609 + the most notable of which are XFree86 and hwclock. hwclock can be
50610 + remedied by having RTC support in the kernel, so real-time
50611 + clock support is enabled if this option is enabled, to ensure
50612 + that hwclock operates correctly. XFree86 still will not
50613 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50614 + IF YOU USE XFree86. If you use XFree86 and you still want to
50615 + protect your kernel against modification, use the RBAC system.
50616 +
50617 +config GRKERNSEC_PROC_MEMMAP
50618 + bool "Harden ASLR against information leaks and entropy reduction"
50619 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50620 + depends on PAX_NOEXEC || PAX_ASLR
50621 + help
50622 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50623 + give no information about the addresses of its mappings if
50624 + PaX features that rely on random addresses are enabled on the task.
50625 + In addition to sanitizing this information and disabling other
50626 + dangerous sources of information, this option causes reads of sensitive
50627 + /proc/<pid> entries where the file descriptor was opened in a different
50628 + task than the one performing the read. Such attempts are logged.
50629 + This option also limits argv/env strings for suid/sgid binaries
50630 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50631 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50632 + binaries to prevent alternative mmap layouts from being abused.
50633 +
50634 + If you use PaX it is essential that you say Y here as it closes up
50635 + several holes that make full ASLR useless locally.
50636 +
50637 +config GRKERNSEC_BRUTE
50638 + bool "Deter exploit bruteforcing"
50639 + default y if GRKERNSEC_CONFIG_AUTO
50640 + help
50641 + If you say Y here, attempts to bruteforce exploits against forking
50642 + daemons such as apache or sshd, as well as against suid/sgid binaries
50643 + will be deterred. When a child of a forking daemon is killed by PaX
50644 + or crashes due to an illegal instruction or other suspicious signal,
50645 + the parent process will be delayed 30 seconds upon every subsequent
50646 + fork until the administrator is able to assess the situation and
50647 + restart the daemon.
50648 + In the suid/sgid case, the attempt is logged, the user has all their
50649 + processes terminated, and they are prevented from executing any further
50650 + processes for 15 minutes.
50651 + It is recommended that you also enable signal logging in the auditing
50652 + section so that logs are generated when a process triggers a suspicious
50653 + signal.
50654 + If the sysctl option is enabled, a sysctl option with name
50655 + "deter_bruteforce" is created.
50656 +
50657 +
50658 +config GRKERNSEC_MODHARDEN
50659 + bool "Harden module auto-loading"
50660 + default y if GRKERNSEC_CONFIG_AUTO
50661 + depends on MODULES
50662 + help
50663 + If you say Y here, module auto-loading in response to use of some
50664 + feature implemented by an unloaded module will be restricted to
50665 + root users. Enabling this option helps defend against attacks
50666 + by unprivileged users who abuse the auto-loading behavior to
50667 + cause a vulnerable module to load that is then exploited.
50668 +
50669 + If this option prevents a legitimate use of auto-loading for a
50670 + non-root user, the administrator can execute modprobe manually
50671 + with the exact name of the module mentioned in the alert log.
50672 + Alternatively, the administrator can add the module to the list
50673 + of modules loaded at boot by modifying init scripts.
50674 +
50675 + Modification of init scripts will most likely be needed on
50676 + Ubuntu servers with encrypted home directory support enabled,
50677 + as the first non-root user logging in will cause the ecb(aes),
50678 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50679 +
50680 +config GRKERNSEC_HIDESYM
50681 + bool "Hide kernel symbols"
50682 + default y if GRKERNSEC_CONFIG_AUTO
50683 + select PAX_USERCOPY_SLABS
50684 + help
50685 + If you say Y here, getting information on loaded modules, and
50686 + displaying all kernel symbols through a syscall will be restricted
50687 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50688 + /proc/kallsyms will be restricted to the root user. The RBAC
50689 + system can hide that entry even from root.
50690 +
50691 + This option also prevents leaking of kernel addresses through
50692 + several /proc entries.
50693 +
50694 + Note that this option is only effective provided the following
50695 + conditions are met:
50696 + 1) The kernel using grsecurity is not precompiled by some distribution
50697 + 2) You have also enabled GRKERNSEC_DMESG
50698 + 3) You are using the RBAC system and hiding other files such as your
50699 + kernel image and System.map. Alternatively, enabling this option
50700 + causes the permissions on /boot, /lib/modules, and the kernel
50701 + source directory to change at compile time to prevent
50702 + reading by non-root users.
50703 + If the above conditions are met, this option will aid in providing a
50704 + useful protection against local kernel exploitation of overflows
50705 + and arbitrary read/write vulnerabilities.
50706 +
50707 +config GRKERNSEC_KERN_LOCKOUT
50708 + bool "Active kernel exploit response"
50709 + default y if GRKERNSEC_CONFIG_AUTO
50710 + depends on X86 || ARM || PPC || SPARC
50711 + help
50712 + If you say Y here, when a PaX alert is triggered due to suspicious
50713 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50714 + or an OOPS occurs due to bad memory accesses, instead of just
50715 + terminating the offending process (and potentially allowing
50716 + a subsequent exploit from the same user), we will take one of two
50717 + actions:
50718 + If the user was root, we will panic the system
50719 + If the user was non-root, we will log the attempt, terminate
50720 + all processes owned by the user, then prevent them from creating
50721 + any new processes until the system is restarted
50722 + This deters repeated kernel exploitation/bruteforcing attempts
50723 + and is useful for later forensics.
50724 +
50725 +endmenu
50726 +menu "Role Based Access Control Options"
50727 +depends on GRKERNSEC
50728 +
50729 +config GRKERNSEC_RBAC_DEBUG
50730 + bool
50731 +
50732 +config GRKERNSEC_NO_RBAC
50733 + bool "Disable RBAC system"
50734 + help
50735 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50736 + preventing the RBAC system from being enabled. You should only say Y
50737 + here if you have no intention of using the RBAC system, so as to prevent
50738 + an attacker with root access from misusing the RBAC system to hide files
50739 + and processes when loadable module support and /dev/[k]mem have been
50740 + locked down.
50741 +
50742 +config GRKERNSEC_ACL_HIDEKERN
50743 + bool "Hide kernel processes"
50744 + help
50745 + If you say Y here, all kernel threads will be hidden to all
50746 + processes but those whose subject has the "view hidden processes"
50747 + flag.
50748 +
50749 +config GRKERNSEC_ACL_MAXTRIES
50750 + int "Maximum tries before password lockout"
50751 + default 3
50752 + help
50753 + This option enforces the maximum number of times a user can attempt
50754 + to authorize themselves with the grsecurity RBAC system before being
50755 + denied the ability to attempt authorization again for a specified time.
50756 + The lower the number, the harder it will be to brute-force a password.
50757 +
50758 +config GRKERNSEC_ACL_TIMEOUT
50759 + int "Time to wait after max password tries, in seconds"
50760 + default 30
50761 + help
50762 + This option specifies the time the user must wait after attempting to
50763 + authorize to the RBAC system with the maximum number of invalid
50764 + passwords. The higher the number, the harder it will be to brute-force
50765 + a password.
50766 +
50767 +endmenu
50768 +menu "Filesystem Protections"
50769 +depends on GRKERNSEC
50770 +
50771 +config GRKERNSEC_PROC
50772 + bool "Proc restrictions"
50773 + default y if GRKERNSEC_CONFIG_AUTO
50774 + help
50775 + If you say Y here, the permissions of the /proc filesystem
50776 + will be altered to enhance system security and privacy. You MUST
50777 + choose either a user only restriction or a user and group restriction.
50778 + Depending upon the option you choose, you can either restrict users to
50779 + see only the processes they themselves run, or choose a group that can
50780 + view all processes and files normally restricted to root if you choose
50781 + the "restrict to user only" option. NOTE: If you're running identd or
50782 + ntpd as a non-root user, you will have to run it as the group you
50783 + specify here.
50784 +
50785 +config GRKERNSEC_PROC_USER
50786 + bool "Restrict /proc to user only"
50787 + depends on GRKERNSEC_PROC
50788 + help
50789 + If you say Y here, non-root users will only be able to view their own
50790 + processes, and restricts them from viewing network-related information,
50791 + and viewing kernel symbol and module information.
50792 +
50793 +config GRKERNSEC_PROC_USERGROUP
50794 + bool "Allow special group"
50795 + default y if GRKERNSEC_CONFIG_AUTO
50796 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50797 + help
50798 + If you say Y here, you will be able to select a group that will be
50799 + able to view all processes and network-related information. If you've
50800 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50801 + remain hidden. This option is useful if you want to run identd as
50802 + a non-root user. The group you select may also be chosen at boot time
50803 + via "grsec_proc_gid=" on the kernel commandline.
50804 +
50805 +config GRKERNSEC_PROC_GID
50806 + int "GID for special group"
50807 + depends on GRKERNSEC_PROC_USERGROUP
50808 + default 1001
50809 +
50810 +config GRKERNSEC_PROC_ADD
50811 + bool "Additional restrictions"
50812 + default y if GRKERNSEC_CONFIG_AUTO
50813 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50814 + help
50815 + If you say Y here, additional restrictions will be placed on
50816 + /proc that keep normal users from viewing device information and
50817 + slabinfo information that could be useful for exploits.
50818 +
50819 +config GRKERNSEC_LINK
50820 + bool "Linking restrictions"
50821 + default y if GRKERNSEC_CONFIG_AUTO
50822 + help
50823 + If you say Y here, /tmp race exploits will be prevented, since users
50824 + will no longer be able to follow symlinks owned by other users in
50825 + world-writable +t directories (e.g. /tmp), unless the owner of the
50826 + symlink is the owner of the directory. users will also not be
50827 + able to hardlink to files they do not own. If the sysctl option is
50828 + enabled, a sysctl option with name "linking_restrictions" is created.
50829 +
50830 +config GRKERNSEC_SYMLINKOWN
50831 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50832 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50833 + help
50834 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50835 + that prevents it from being used as a security feature. As Apache
50836 + verifies the symlink by performing a stat() against the target of
50837 + the symlink before it is followed, an attacker can setup a symlink
50838 + to point to a same-owned file, then replace the symlink with one
50839 + that targets another user's file just after Apache "validates" the
50840 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50841 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50842 + will be in place for the group you specify. If the sysctl option
50843 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50844 + created.
50845 +
50846 +config GRKERNSEC_SYMLINKOWN_GID
50847 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50848 + depends on GRKERNSEC_SYMLINKOWN
50849 + default 1006
50850 + help
50851 + Setting this GID determines what group kernel-enforced
50852 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50853 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50854 +
50855 +config GRKERNSEC_FIFO
50856 + bool "FIFO restrictions"
50857 + default y if GRKERNSEC_CONFIG_AUTO
50858 + help
50859 + If you say Y here, users will not be able to write to FIFOs they don't
50860 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50861 + the FIFO is the same owner of the directory it's held in. If the sysctl
50862 + option is enabled, a sysctl option with name "fifo_restrictions" is
50863 + created.
50864 +
50865 +config GRKERNSEC_SYSFS_RESTRICT
50866 + bool "Sysfs/debugfs restriction"
50867 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50868 + depends on SYSFS
50869 + help
50870 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50871 + any filesystem normally mounted under it (e.g. debugfs) will be
50872 + mostly accessible only by root. These filesystems generally provide access
50873 + to hardware and debug information that isn't appropriate for unprivileged
50874 + users of the system. Sysfs and debugfs have also become a large source
50875 + of new vulnerabilities, ranging from infoleaks to local compromise.
50876 + There has been very little oversight with an eye toward security involved
50877 + in adding new exporters of information to these filesystems, so their
50878 + use is discouraged.
50879 + For reasons of compatibility, a few directories have been whitelisted
50880 + for access by non-root users:
50881 + /sys/fs/selinux
50882 + /sys/fs/fuse
50883 + /sys/devices/system/cpu
50884 +
50885 +config GRKERNSEC_ROFS
50886 + bool "Runtime read-only mount protection"
50887 + help
50888 + If you say Y here, a sysctl option with name "romount_protect" will
50889 + be created. By setting this option to 1 at runtime, filesystems
50890 + will be protected in the following ways:
50891 + * No new writable mounts will be allowed
50892 + * Existing read-only mounts won't be able to be remounted read/write
50893 + * Write operations will be denied on all block devices
50894 + This option acts independently of grsec_lock: once it is set to 1,
50895 + it cannot be turned off. Therefore, please be mindful of the resulting
50896 + behavior if this option is enabled in an init script on a read-only
50897 + filesystem. This feature is mainly intended for secure embedded systems.
50898 +
50899 +config GRKERNSEC_CHROOT
50900 + bool "Chroot jail restrictions"
50901 + default y if GRKERNSEC_CONFIG_AUTO
50902 + help
50903 + If you say Y here, you will be able to choose several options that will
50904 + make breaking out of a chrooted jail much more difficult. If you
50905 + encounter no software incompatibilities with the following options, it
50906 + is recommended that you enable each one.
50907 +
50908 +config GRKERNSEC_CHROOT_MOUNT
50909 + bool "Deny mounts"
50910 + default y if GRKERNSEC_CONFIG_AUTO
50911 + depends on GRKERNSEC_CHROOT
50912 + help
50913 + If you say Y here, processes inside a chroot will not be able to
50914 + mount or remount filesystems. If the sysctl option is enabled, a
50915 + sysctl option with name "chroot_deny_mount" is created.
50916 +
50917 +config GRKERNSEC_CHROOT_DOUBLE
50918 + bool "Deny double-chroots"
50919 + default y if GRKERNSEC_CONFIG_AUTO
50920 + depends on GRKERNSEC_CHROOT
50921 + help
50922 + If you say Y here, processes inside a chroot will not be able to chroot
50923 + again outside the chroot. This is a widely used method of breaking
50924 + out of a chroot jail and should not be allowed. If the sysctl
50925 + option is enabled, a sysctl option with name
50926 + "chroot_deny_chroot" is created.
50927 +
50928 +config GRKERNSEC_CHROOT_PIVOT
50929 + bool "Deny pivot_root in chroot"
50930 + default y if GRKERNSEC_CONFIG_AUTO
50931 + depends on GRKERNSEC_CHROOT
50932 + help
50933 + If you say Y here, processes inside a chroot will not be able to use
50934 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50935 + works similar to chroot in that it changes the root filesystem. This
50936 + function could be misused in a chrooted process to attempt to break out
50937 + of the chroot, and therefore should not be allowed. If the sysctl
50938 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50939 + created.
50940 +
50941 +config GRKERNSEC_CHROOT_CHDIR
50942 + bool "Enforce chdir(\"/\") on all chroots"
50943 + default y if GRKERNSEC_CONFIG_AUTO
50944 + depends on GRKERNSEC_CHROOT
50945 + help
50946 + If you say Y here, the current working directory of all newly-chrooted
50947 + applications will be set to the the root directory of the chroot.
50948 + The man page on chroot(2) states:
50949 + Note that this call does not change the current working
50950 + directory, so that `.' can be outside the tree rooted at
50951 + `/'. In particular, the super-user can escape from a
50952 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50953 +
50954 + It is recommended that you say Y here, since it's not known to break
50955 + any software. If the sysctl option is enabled, a sysctl option with
50956 + name "chroot_enforce_chdir" is created.
50957 +
50958 +config GRKERNSEC_CHROOT_CHMOD
50959 + bool "Deny (f)chmod +s"
50960 + default y if GRKERNSEC_CONFIG_AUTO
50961 + depends on GRKERNSEC_CHROOT
50962 + help
50963 + If you say Y here, processes inside a chroot will not be able to chmod
50964 + or fchmod files to make them have suid or sgid bits. This protects
50965 + against another published method of breaking a chroot. If the sysctl
50966 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50967 + created.
50968 +
50969 +config GRKERNSEC_CHROOT_FCHDIR
50970 + bool "Deny fchdir out of chroot"
50971 + default y if GRKERNSEC_CONFIG_AUTO
50972 + depends on GRKERNSEC_CHROOT
50973 + help
50974 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50975 + to a file descriptor of the chrooting process that points to a directory
50976 + outside the filesystem will be stopped. If the sysctl option
50977 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50978 +
50979 +config GRKERNSEC_CHROOT_MKNOD
50980 + bool "Deny mknod"
50981 + default y if GRKERNSEC_CONFIG_AUTO
50982 + depends on GRKERNSEC_CHROOT
50983 + help
50984 + If you say Y here, processes inside a chroot will not be allowed to
50985 + mknod. The problem with using mknod inside a chroot is that it
50986 + would allow an attacker to create a device entry that is the same
50987 + as one on the physical root of your system, which could range from
50988 + anything from the console device to a device for your harddrive (which
50989 + they could then use to wipe the drive or steal data). It is recommended
50990 + that you say Y here, unless you run into software incompatibilities.
50991 + If the sysctl option is enabled, a sysctl option with name
50992 + "chroot_deny_mknod" is created.
50993 +
50994 +config GRKERNSEC_CHROOT_SHMAT
50995 + bool "Deny shmat() out of chroot"
50996 + default y if GRKERNSEC_CONFIG_AUTO
50997 + depends on GRKERNSEC_CHROOT
50998 + help
50999 + If you say Y here, processes inside a chroot will not be able to attach
51000 + to shared memory segments that were created outside of the chroot jail.
51001 + It is recommended that you say Y here. If the sysctl option is enabled,
51002 + a sysctl option with name "chroot_deny_shmat" is created.
51003 +
51004 +config GRKERNSEC_CHROOT_UNIX
51005 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51006 + default y if GRKERNSEC_CONFIG_AUTO
51007 + depends on GRKERNSEC_CHROOT
51008 + help
51009 + If you say Y here, processes inside a chroot will not be able to
51010 + connect to abstract (meaning not belonging to a filesystem) Unix
51011 + domain sockets that were bound outside of a chroot. It is recommended
51012 + that you say Y here. If the sysctl option is enabled, a sysctl option
51013 + with name "chroot_deny_unix" is created.
51014 +
51015 +config GRKERNSEC_CHROOT_FINDTASK
51016 + bool "Protect outside processes"
51017 + default y if GRKERNSEC_CONFIG_AUTO
51018 + depends on GRKERNSEC_CHROOT
51019 + help
51020 + If you say Y here, processes inside a chroot will not be able to
51021 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51022 + getsid, or view any process outside of the chroot. If the sysctl
51023 + option is enabled, a sysctl option with name "chroot_findtask" is
51024 + created.
51025 +
51026 +config GRKERNSEC_CHROOT_NICE
51027 + bool "Restrict priority changes"
51028 + default y if GRKERNSEC_CONFIG_AUTO
51029 + depends on GRKERNSEC_CHROOT
51030 + help
51031 + If you say Y here, processes inside a chroot will not be able to raise
51032 + the priority of processes in the chroot, or alter the priority of
51033 + processes outside the chroot. This provides more security than simply
51034 + removing CAP_SYS_NICE from the process' capability set. If the
51035 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51036 + is created.
51037 +
51038 +config GRKERNSEC_CHROOT_SYSCTL
51039 + bool "Deny sysctl writes"
51040 + default y if GRKERNSEC_CONFIG_AUTO
51041 + depends on GRKERNSEC_CHROOT
51042 + help
51043 + If you say Y here, an attacker in a chroot will not be able to
51044 + write to sysctl entries, either by sysctl(2) or through a /proc
51045 + interface. It is strongly recommended that you say Y here. If the
51046 + sysctl option is enabled, a sysctl option with name
51047 + "chroot_deny_sysctl" is created.
51048 +
51049 +config GRKERNSEC_CHROOT_CAPS
51050 + bool "Capability restrictions"
51051 + default y if GRKERNSEC_CONFIG_AUTO
51052 + depends on GRKERNSEC_CHROOT
51053 + help
51054 + If you say Y here, the capabilities on all processes within a
51055 + chroot jail will be lowered to stop module insertion, raw i/o,
51056 + system and net admin tasks, rebooting the system, modifying immutable
51057 + files, modifying IPC owned by another, and changing the system time.
51058 + This is left an option because it can break some apps. Disable this
51059 + if your chrooted apps are having problems performing those kinds of
51060 + tasks. If the sysctl option is enabled, a sysctl option with
51061 + name "chroot_caps" is created.
51062 +
51063 +endmenu
51064 +menu "Kernel Auditing"
51065 +depends on GRKERNSEC
51066 +
51067 +config GRKERNSEC_AUDIT_GROUP
51068 + bool "Single group for auditing"
51069 + help
51070 + If you say Y here, the exec, chdir, and (un)mount logging features
51071 + will only operate on a group you specify. This option is recommended
51072 + if you only want to watch certain users instead of having a large
51073 + amount of logs from the entire system. If the sysctl option is enabled,
51074 + a sysctl option with name "audit_group" is created.
51075 +
51076 +config GRKERNSEC_AUDIT_GID
51077 + int "GID for auditing"
51078 + depends on GRKERNSEC_AUDIT_GROUP
51079 + default 1007
51080 +
51081 +config GRKERNSEC_EXECLOG
51082 + bool "Exec logging"
51083 + help
51084 + If you say Y here, all execve() calls will be logged (since the
51085 + other exec*() calls are frontends to execve(), all execution
51086 + will be logged). Useful for shell-servers that like to keep track
51087 + of their users. If the sysctl option is enabled, a sysctl option with
51088 + name "exec_logging" is created.
51089 + WARNING: This option when enabled will produce a LOT of logs, especially
51090 + on an active system.
51091 +
51092 +config GRKERNSEC_RESLOG
51093 + bool "Resource logging"
51094 + default y if GRKERNSEC_CONFIG_AUTO
51095 + help
51096 + If you say Y here, all attempts to overstep resource limits will
51097 + be logged with the resource name, the requested size, and the current
51098 + limit. It is highly recommended that you say Y here. If the sysctl
51099 + option is enabled, a sysctl option with name "resource_logging" is
51100 + created. If the RBAC system is enabled, the sysctl value is ignored.
51101 +
51102 +config GRKERNSEC_CHROOT_EXECLOG
51103 + bool "Log execs within chroot"
51104 + help
51105 + If you say Y here, all executions inside a chroot jail will be logged
51106 + to syslog. This can cause a large amount of logs if certain
51107 + applications (eg. djb's daemontools) are installed on the system, and
51108 + is therefore left as an option. If the sysctl option is enabled, a
51109 + sysctl option with name "chroot_execlog" is created.
51110 +
51111 +config GRKERNSEC_AUDIT_PTRACE
51112 + bool "Ptrace logging"
51113 + help
51114 + If you say Y here, all attempts to attach to a process via ptrace
51115 + will be logged. If the sysctl option is enabled, a sysctl option
51116 + with name "audit_ptrace" is created.
51117 +
51118 +config GRKERNSEC_AUDIT_CHDIR
51119 + bool "Chdir logging"
51120 + help
51121 + If you say Y here, all chdir() calls will be logged. If the sysctl
51122 + option is enabled, a sysctl option with name "audit_chdir" is created.
51123 +
51124 +config GRKERNSEC_AUDIT_MOUNT
51125 + bool "(Un)Mount logging"
51126 + help
51127 + If you say Y here, all mounts and unmounts will be logged. If the
51128 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51129 + created.
51130 +
51131 +config GRKERNSEC_SIGNAL
51132 + bool "Signal logging"
51133 + default y if GRKERNSEC_CONFIG_AUTO
51134 + help
51135 + If you say Y here, certain important signals will be logged, such as
51136 + SIGSEGV, which will as a result inform you of when a error in a program
51137 + occurred, which in some cases could mean a possible exploit attempt.
51138 + If the sysctl option is enabled, a sysctl option with name
51139 + "signal_logging" is created.
51140 +
51141 +config GRKERNSEC_FORKFAIL
51142 + bool "Fork failure logging"
51143 + help
51144 + If you say Y here, all failed fork() attempts will be logged.
51145 + This could suggest a fork bomb, or someone attempting to overstep
51146 + their process limit. If the sysctl option is enabled, a sysctl option
51147 + with name "forkfail_logging" is created.
51148 +
51149 +config GRKERNSEC_TIME
51150 + bool "Time change logging"
51151 + default y if GRKERNSEC_CONFIG_AUTO
51152 + help
51153 + If you say Y here, any changes of the system clock will be logged.
51154 + If the sysctl option is enabled, a sysctl option with name
51155 + "timechange_logging" is created.
51156 +
51157 +config GRKERNSEC_PROC_IPADDR
51158 + bool "/proc/<pid>/ipaddr support"
51159 + default y if GRKERNSEC_CONFIG_AUTO
51160 + help
51161 + If you say Y here, a new entry will be added to each /proc/<pid>
51162 + directory that contains the IP address of the person using the task.
51163 + The IP is carried across local TCP and AF_UNIX stream sockets.
51164 + This information can be useful for IDS/IPSes to perform remote response
51165 + to a local attack. The entry is readable by only the owner of the
51166 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51167 + the RBAC system), and thus does not create privacy concerns.
51168 +
51169 +config GRKERNSEC_RWXMAP_LOG
51170 + bool 'Denied RWX mmap/mprotect logging'
51171 + default y if GRKERNSEC_CONFIG_AUTO
51172 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51173 + help
51174 + If you say Y here, calls to mmap() and mprotect() with explicit
51175 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51176 + denied by the PAX_MPROTECT feature. If the sysctl option is
51177 + enabled, a sysctl option with name "rwxmap_logging" is created.
51178 +
51179 +config GRKERNSEC_AUDIT_TEXTREL
51180 + bool 'ELF text relocations logging (READ HELP)'
51181 + depends on PAX_MPROTECT
51182 + help
51183 + If you say Y here, text relocations will be logged with the filename
51184 + of the offending library or binary. The purpose of the feature is
51185 + to help Linux distribution developers get rid of libraries and
51186 + binaries that need text relocations which hinder the future progress
51187 + of PaX. Only Linux distribution developers should say Y here, and
51188 + never on a production machine, as this option creates an information
51189 + leak that could aid an attacker in defeating the randomization of
51190 + a single memory region. If the sysctl option is enabled, a sysctl
51191 + option with name "audit_textrel" is created.
51192 +
51193 +endmenu
51194 +
51195 +menu "Executable Protections"
51196 +depends on GRKERNSEC
51197 +
51198 +config GRKERNSEC_DMESG
51199 + bool "Dmesg(8) restriction"
51200 + default y if GRKERNSEC_CONFIG_AUTO
51201 + help
51202 + If you say Y here, non-root users will not be able to use dmesg(8)
51203 + to view up to the last 4kb of messages in the kernel's log buffer.
51204 + The kernel's log buffer often contains kernel addresses and other
51205 + identifying information useful to an attacker in fingerprinting a
51206 + system for a targeted exploit.
51207 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51208 + created.
51209 +
51210 +config GRKERNSEC_HARDEN_PTRACE
51211 + bool "Deter ptrace-based process snooping"
51212 + default y if GRKERNSEC_CONFIG_AUTO
51213 + help
51214 + If you say Y here, TTY sniffers and other malicious monitoring
51215 + programs implemented through ptrace will be defeated. If you
51216 + have been using the RBAC system, this option has already been
51217 + enabled for several years for all users, with the ability to make
51218 + fine-grained exceptions.
51219 +
51220 + This option only affects the ability of non-root users to ptrace
51221 + processes that are not a descendent of the ptracing process.
51222 + This means that strace ./binary and gdb ./binary will still work,
51223 + but attaching to arbitrary processes will not. If the sysctl
51224 + option is enabled, a sysctl option with name "harden_ptrace" is
51225 + created.
51226 +
51227 +config GRKERNSEC_PTRACE_READEXEC
51228 + bool "Require read access to ptrace sensitive binaries"
51229 + default y if GRKERNSEC_CONFIG_AUTO
51230 + help
51231 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51232 + binaries. This option is useful in environments that
51233 + remove the read bits (e.g. file mode 4711) from suid binaries to
51234 + prevent infoleaking of their contents. This option adds
51235 + consistency to the use of that file mode, as the binary could normally
51236 + be read out when run without privileges while ptracing.
51237 +
51238 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51239 + is created.
51240 +
51241 +config GRKERNSEC_SETXID
51242 + bool "Enforce consistent multithreaded privileges"
51243 + default y if GRKERNSEC_CONFIG_AUTO
51244 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51245 + help
51246 + If you say Y here, a change from a root uid to a non-root uid
51247 + in a multithreaded application will cause the resulting uids,
51248 + gids, supplementary groups, and capabilities in that thread
51249 + to be propagated to the other threads of the process. In most
51250 + cases this is unnecessary, as glibc will emulate this behavior
51251 + on behalf of the application. Other libcs do not act in the
51252 + same way, allowing the other threads of the process to continue
51253 + running with root privileges. If the sysctl option is enabled,
51254 + a sysctl option with name "consistent_setxid" is created.
51255 +
51256 +config GRKERNSEC_TPE
51257 + bool "Trusted Path Execution (TPE)"
51258 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51259 + help
51260 + If you say Y here, you will be able to choose a gid to add to the
51261 + supplementary groups of users you want to mark as "untrusted."
51262 + These users will not be able to execute any files that are not in
51263 + root-owned directories writable only by root. If the sysctl option
51264 + is enabled, a sysctl option with name "tpe" is created.
51265 +
51266 +config GRKERNSEC_TPE_ALL
51267 + bool "Partially restrict all non-root users"
51268 + depends on GRKERNSEC_TPE
51269 + help
51270 + If you say Y here, all non-root users will be covered under
51271 + a weaker TPE restriction. This is separate from, and in addition to,
51272 + the main TPE options that you have selected elsewhere. Thus, if a
51273 + "trusted" GID is chosen, this restriction applies to even that GID.
51274 + Under this restriction, all non-root users will only be allowed to
51275 + execute files in directories they own that are not group or
51276 + world-writable, or in directories owned by root and writable only by
51277 + root. If the sysctl option is enabled, a sysctl option with name
51278 + "tpe_restrict_all" is created.
51279 +
51280 +config GRKERNSEC_TPE_INVERT
51281 + bool "Invert GID option"
51282 + depends on GRKERNSEC_TPE
51283 + help
51284 + If you say Y here, the group you specify in the TPE configuration will
51285 + decide what group TPE restrictions will be *disabled* for. This
51286 + option is useful if you want TPE restrictions to be applied to most
51287 + users on the system. If the sysctl option is enabled, a sysctl option
51288 + with name "tpe_invert" is created. Unlike other sysctl options, this
51289 + entry will default to on for backward-compatibility.
51290 +
51291 +config GRKERNSEC_TPE_GID
51292 + int
51293 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51294 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51295 +
51296 +config GRKERNSEC_TPE_UNTRUSTED_GID
51297 + int "GID for TPE-untrusted users"
51298 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51299 + default 1005
51300 + help
51301 + Setting this GID determines what group TPE restrictions will be
51302 + *enabled* for. If the sysctl option is enabled, a sysctl option
51303 + with name "tpe_gid" is created.
51304 +
51305 +config GRKERNSEC_TPE_TRUSTED_GID
51306 + int "GID for TPE-trusted users"
51307 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51308 + default 1005
51309 + help
51310 + Setting this GID determines what group TPE restrictions will be
51311 + *disabled* for. If the sysctl option is enabled, a sysctl option
51312 + with name "tpe_gid" is created.
51313 +
51314 +endmenu
51315 +menu "Network Protections"
51316 +depends on GRKERNSEC
51317 +
51318 +config GRKERNSEC_RANDNET
51319 + bool "Larger entropy pools"
51320 + default y if GRKERNSEC_CONFIG_AUTO
51321 + help
51322 + If you say Y here, the entropy pools used for many features of Linux
51323 + and grsecurity will be doubled in size. Since several grsecurity
51324 + features use additional randomness, it is recommended that you say Y
51325 + here. Saying Y here has a similar effect as modifying
51326 + /proc/sys/kernel/random/poolsize.
51327 +
51328 +config GRKERNSEC_BLACKHOLE
51329 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51330 + default y if GRKERNSEC_CONFIG_AUTO
51331 + depends on NET
51332 + help
51333 + If you say Y here, neither TCP resets nor ICMP
51334 + destination-unreachable packets will be sent in response to packets
51335 + sent to ports for which no associated listening process exists.
51336 + This feature supports both IPV4 and IPV6 and exempts the
51337 + loopback interface from blackholing. Enabling this feature
51338 + makes a host more resilient to DoS attacks and reduces network
51339 + visibility against scanners.
51340 +
51341 + The blackhole feature as-implemented is equivalent to the FreeBSD
51342 + blackhole feature, as it prevents RST responses to all packets, not
51343 + just SYNs. Under most application behavior this causes no
51344 + problems, but applications (like haproxy) may not close certain
51345 + connections in a way that cleanly terminates them on the remote
51346 + end, leaving the remote host in LAST_ACK state. Because of this
51347 + side-effect and to prevent intentional LAST_ACK DoSes, this
51348 + feature also adds automatic mitigation against such attacks.
51349 + The mitigation drastically reduces the amount of time a socket
51350 + can spend in LAST_ACK state. If you're using haproxy and not
51351 + all servers it connects to have this option enabled, consider
51352 + disabling this feature on the haproxy host.
51353 +
51354 + If the sysctl option is enabled, two sysctl options with names
51355 + "ip_blackhole" and "lastack_retries" will be created.
51356 + While "ip_blackhole" takes the standard zero/non-zero on/off
51357 + toggle, "lastack_retries" uses the same kinds of values as
51358 + "tcp_retries1" and "tcp_retries2". The default value of 4
51359 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51360 + state.
51361 +
51362 +config GRKERNSEC_SOCKET
51363 + bool "Socket restrictions"
51364 + depends on NET
51365 + help
51366 + If you say Y here, you will be able to choose from several options.
51367 + If you assign a GID on your system and add it to the supplementary
51368 + groups of users you want to restrict socket access to, this patch
51369 + will perform up to three things, based on the option(s) you choose.
51370 +
51371 +config GRKERNSEC_SOCKET_ALL
51372 + bool "Deny any sockets to group"
51373 + depends on GRKERNSEC_SOCKET
51374 + help
51375 + If you say Y here, you will be able to choose a GID of whose users will
51376 + be unable to connect to other hosts from your machine or run server
51377 + applications from your machine. If the sysctl option is enabled, a
51378 + sysctl option with name "socket_all" is created.
51379 +
51380 +config GRKERNSEC_SOCKET_ALL_GID
51381 + int "GID to deny all sockets for"
51382 + depends on GRKERNSEC_SOCKET_ALL
51383 + default 1004
51384 + help
51385 + Here you can choose the GID to disable socket access for. Remember to
51386 + add the users you want socket access disabled for to the GID
51387 + specified here. If the sysctl option is enabled, a sysctl option
51388 + with name "socket_all_gid" is created.
51389 +
51390 +config GRKERNSEC_SOCKET_CLIENT
51391 + bool "Deny client sockets to group"
51392 + depends on GRKERNSEC_SOCKET
51393 + help
51394 + If you say Y here, you will be able to choose a GID of whose users will
51395 + be unable to connect to other hosts from your machine, but will be
51396 + able to run servers. If this option is enabled, all users in the group
51397 + you specify will have to use passive mode when initiating ftp transfers
51398 + from the shell on your machine. If the sysctl option is enabled, a
51399 + sysctl option with name "socket_client" is created.
51400 +
51401 +config GRKERNSEC_SOCKET_CLIENT_GID
51402 + int "GID to deny client sockets for"
51403 + depends on GRKERNSEC_SOCKET_CLIENT
51404 + default 1003
51405 + help
51406 + Here you can choose the GID to disable client socket access for.
51407 + Remember to add the users you want client socket access disabled for to
51408 + the GID specified here. If the sysctl option is enabled, a sysctl
51409 + option with name "socket_client_gid" is created.
51410 +
51411 +config GRKERNSEC_SOCKET_SERVER
51412 + bool "Deny server sockets to group"
51413 + depends on GRKERNSEC_SOCKET
51414 + help
51415 + If you say Y here, you will be able to choose a GID of whose users will
51416 + be unable to run server applications from your machine. If the sysctl
51417 + option is enabled, a sysctl option with name "socket_server" is created.
51418 +
51419 +config GRKERNSEC_SOCKET_SERVER_GID
51420 + int "GID to deny server sockets for"
51421 + depends on GRKERNSEC_SOCKET_SERVER
51422 + default 1002
51423 + help
51424 + Here you can choose the GID to disable server socket access for.
51425 + Remember to add the users you want server socket access disabled for to
51426 + the GID specified here. If the sysctl option is enabled, a sysctl
51427 + option with name "socket_server_gid" is created.
51428 +
51429 +endmenu
51430 +menu "Sysctl Support"
51431 +depends on GRKERNSEC && SYSCTL
51432 +
51433 +config GRKERNSEC_SYSCTL
51434 + bool "Sysctl support"
51435 + default y if GRKERNSEC_CONFIG_AUTO
51436 + help
51437 + If you say Y here, you will be able to change the options that
51438 + grsecurity runs with at bootup, without having to recompile your
51439 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51440 + to enable (1) or disable (0) various features. All the sysctl entries
51441 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51442 + All features enabled in the kernel configuration are disabled at boot
51443 + if you do not say Y to the "Turn on features by default" option.
51444 + All options should be set at startup, and the grsec_lock entry should
51445 + be set to a non-zero value after all the options are set.
51446 + *THIS IS EXTREMELY IMPORTANT*
51447 +
51448 +config GRKERNSEC_SYSCTL_DISTRO
51449 + bool "Extra sysctl support for distro makers (READ HELP)"
51450 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51451 + help
51452 + If you say Y here, additional sysctl options will be created
51453 + for features that affect processes running as root. Therefore,
51454 + it is critical when using this option that the grsec_lock entry be
51455 + enabled after boot. Only distros with prebuilt kernel packages
51456 + with this option enabled that can ensure grsec_lock is enabled
51457 + after boot should use this option.
51458 + *Failure to set grsec_lock after boot makes all grsec features
51459 + this option covers useless*
51460 +
51461 + Currently this option creates the following sysctl entries:
51462 + "Disable Privileged I/O": "disable_priv_io"
51463 +
51464 +config GRKERNSEC_SYSCTL_ON
51465 + bool "Turn on features by default"
51466 + default y if GRKERNSEC_CONFIG_AUTO
51467 + depends on GRKERNSEC_SYSCTL
51468 + help
51469 + If you say Y here, instead of having all features enabled in the
51470 + kernel configuration disabled at boot time, the features will be
51471 + enabled at boot time. It is recommended you say Y here unless
51472 + there is some reason you would want all sysctl-tunable features to
51473 + be disabled by default. As mentioned elsewhere, it is important
51474 + to enable the grsec_lock entry once you have finished modifying
51475 + the sysctl entries.
51476 +
51477 +endmenu
51478 +menu "Logging Options"
51479 +depends on GRKERNSEC
51480 +
51481 +config GRKERNSEC_FLOODTIME
51482 + int "Seconds in between log messages (minimum)"
51483 + default 10
51484 + help
51485 + This option allows you to enforce the number of seconds between
51486 + grsecurity log messages. The default should be suitable for most
51487 + people, however, if you choose to change it, choose a value small enough
51488 + to allow informative logs to be produced, but large enough to
51489 + prevent flooding.
51490 +
51491 +config GRKERNSEC_FLOODBURST
51492 + int "Number of messages in a burst (maximum)"
51493 + default 6
51494 + help
51495 + This option allows you to choose the maximum number of messages allowed
51496 + within the flood time interval you chose in a separate option. The
51497 + default should be suitable for most people, however if you find that
51498 + many of your logs are being interpreted as flooding, you may want to
51499 + raise this value.
51500 +
51501 +endmenu
51502 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51503 new file mode 100644
51504 index 0000000..1b9afa9
51505 --- /dev/null
51506 +++ b/grsecurity/Makefile
51507 @@ -0,0 +1,38 @@
51508 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51509 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51510 +# into an RBAC system
51511 +#
51512 +# All code in this directory and various hooks inserted throughout the kernel
51513 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51514 +# under the GPL v2 or higher
51515 +
51516 +KBUILD_CFLAGS += -Werror
51517 +
51518 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51519 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51520 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51521 +
51522 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51523 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51524 + gracl_learn.o grsec_log.o
51525 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51526 +
51527 +ifdef CONFIG_NET
51528 +obj-y += grsec_sock.o
51529 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51530 +endif
51531 +
51532 +ifndef CONFIG_GRKERNSEC
51533 +obj-y += grsec_disabled.o
51534 +endif
51535 +
51536 +ifdef CONFIG_GRKERNSEC_HIDESYM
51537 +extra-y := grsec_hidesym.o
51538 +$(obj)/grsec_hidesym.o:
51539 + @-chmod -f 500 /boot
51540 + @-chmod -f 500 /lib/modules
51541 + @-chmod -f 500 /lib64/modules
51542 + @-chmod -f 500 /lib32/modules
51543 + @-chmod -f 700 .
51544 + @echo ' grsec: protected kernel image paths'
51545 +endif
51546 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51547 new file mode 100644
51548 index 0000000..3d58260
51549 --- /dev/null
51550 +++ b/grsecurity/gracl.c
51551 @@ -0,0 +1,4029 @@
51552 +#include <linux/kernel.h>
51553 +#include <linux/module.h>
51554 +#include <linux/sched.h>
51555 +#include <linux/mm.h>
51556 +#include <linux/file.h>
51557 +#include <linux/fs.h>
51558 +#include <linux/namei.h>
51559 +#include <linux/mount.h>
51560 +#include <linux/tty.h>
51561 +#include <linux/proc_fs.h>
51562 +#include <linux/lglock.h>
51563 +#include <linux/slab.h>
51564 +#include <linux/vmalloc.h>
51565 +#include <linux/types.h>
51566 +#include <linux/sysctl.h>
51567 +#include <linux/netdevice.h>
51568 +#include <linux/ptrace.h>
51569 +#include <linux/gracl.h>
51570 +#include <linux/gralloc.h>
51571 +#include <linux/security.h>
51572 +#include <linux/grinternal.h>
51573 +#include <linux/pid_namespace.h>
51574 +#include <linux/stop_machine.h>
51575 +#include <linux/fdtable.h>
51576 +#include <linux/percpu.h>
51577 +#include <linux/lglock.h>
51578 +#include "../fs/mount.h"
51579 +
51580 +#include <asm/uaccess.h>
51581 +#include <asm/errno.h>
51582 +#include <asm/mman.h>
51583 +
51584 +extern struct lglock vfsmount_lock;
51585 +
51586 +static struct acl_role_db acl_role_set;
51587 +static struct name_db name_set;
51588 +static struct inodev_db inodev_set;
51589 +
51590 +/* for keeping track of userspace pointers used for subjects, so we
51591 + can share references in the kernel as well
51592 +*/
51593 +
51594 +static struct path real_root;
51595 +
51596 +static struct acl_subj_map_db subj_map_set;
51597 +
51598 +static struct acl_role_label *default_role;
51599 +
51600 +static struct acl_role_label *role_list;
51601 +
51602 +static u16 acl_sp_role_value;
51603 +
51604 +extern char *gr_shared_page[4];
51605 +static DEFINE_MUTEX(gr_dev_mutex);
51606 +DEFINE_RWLOCK(gr_inode_lock);
51607 +
51608 +struct gr_arg *gr_usermode;
51609 +
51610 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51611 +
51612 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51613 +extern void gr_clear_learn_entries(void);
51614 +
51615 +#ifdef CONFIG_GRKERNSEC_RESLOG
51616 +extern void gr_log_resource(const struct task_struct *task,
51617 + const int res, const unsigned long wanted, const int gt);
51618 +#endif
51619 +
51620 +unsigned char *gr_system_salt;
51621 +unsigned char *gr_system_sum;
51622 +
51623 +static struct sprole_pw **acl_special_roles = NULL;
51624 +static __u16 num_sprole_pws = 0;
51625 +
51626 +static struct acl_role_label *kernel_role = NULL;
51627 +
51628 +static unsigned int gr_auth_attempts = 0;
51629 +static unsigned long gr_auth_expires = 0UL;
51630 +
51631 +#ifdef CONFIG_NET
51632 +extern struct vfsmount *sock_mnt;
51633 +#endif
51634 +
51635 +extern struct vfsmount *pipe_mnt;
51636 +extern struct vfsmount *shm_mnt;
51637 +#ifdef CONFIG_HUGETLBFS
51638 +extern struct vfsmount *hugetlbfs_vfsmount;
51639 +#endif
51640 +
51641 +static struct acl_object_label *fakefs_obj_rw;
51642 +static struct acl_object_label *fakefs_obj_rwx;
51643 +
51644 +extern int gr_init_uidset(void);
51645 +extern void gr_free_uidset(void);
51646 +extern void gr_remove_uid(uid_t uid);
51647 +extern int gr_find_uid(uid_t uid);
51648 +
51649 +__inline__ int
51650 +gr_acl_is_enabled(void)
51651 +{
51652 + return (gr_status & GR_READY);
51653 +}
51654 +
51655 +#ifdef CONFIG_BTRFS_FS
51656 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51657 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51658 +#endif
51659 +
51660 +static inline dev_t __get_dev(const struct dentry *dentry)
51661 +{
51662 +#ifdef CONFIG_BTRFS_FS
51663 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51664 + return get_btrfs_dev_from_inode(dentry->d_inode);
51665 + else
51666 +#endif
51667 + return dentry->d_inode->i_sb->s_dev;
51668 +}
51669 +
51670 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51671 +{
51672 + return __get_dev(dentry);
51673 +}
51674 +
51675 +static char gr_task_roletype_to_char(struct task_struct *task)
51676 +{
51677 + switch (task->role->roletype &
51678 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51679 + GR_ROLE_SPECIAL)) {
51680 + case GR_ROLE_DEFAULT:
51681 + return 'D';
51682 + case GR_ROLE_USER:
51683 + return 'U';
51684 + case GR_ROLE_GROUP:
51685 + return 'G';
51686 + case GR_ROLE_SPECIAL:
51687 + return 'S';
51688 + }
51689 +
51690 + return 'X';
51691 +}
51692 +
51693 +char gr_roletype_to_char(void)
51694 +{
51695 + return gr_task_roletype_to_char(current);
51696 +}
51697 +
51698 +__inline__ int
51699 +gr_acl_tpe_check(void)
51700 +{
51701 + if (unlikely(!(gr_status & GR_READY)))
51702 + return 0;
51703 + if (current->role->roletype & GR_ROLE_TPE)
51704 + return 1;
51705 + else
51706 + return 0;
51707 +}
51708 +
51709 +int
51710 +gr_handle_rawio(const struct inode *inode)
51711 +{
51712 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51713 + if (inode && S_ISBLK(inode->i_mode) &&
51714 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51715 + !capable(CAP_SYS_RAWIO))
51716 + return 1;
51717 +#endif
51718 + return 0;
51719 +}
51720 +
51721 +static int
51722 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51723 +{
51724 + if (likely(lena != lenb))
51725 + return 0;
51726 +
51727 + return !memcmp(a, b, lena);
51728 +}
51729 +
51730 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51731 +{
51732 + *buflen -= namelen;
51733 + if (*buflen < 0)
51734 + return -ENAMETOOLONG;
51735 + *buffer -= namelen;
51736 + memcpy(*buffer, str, namelen);
51737 + return 0;
51738 +}
51739 +
51740 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51741 +{
51742 + return prepend(buffer, buflen, name->name, name->len);
51743 +}
51744 +
51745 +static int prepend_path(const struct path *path, struct path *root,
51746 + char **buffer, int *buflen)
51747 +{
51748 + struct dentry *dentry = path->dentry;
51749 + struct vfsmount *vfsmnt = path->mnt;
51750 + struct mount *mnt = real_mount(vfsmnt);
51751 + bool slash = false;
51752 + int error = 0;
51753 +
51754 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51755 + struct dentry * parent;
51756 +
51757 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51758 + /* Global root? */
51759 + if (!mnt_has_parent(mnt)) {
51760 + goto out;
51761 + }
51762 + dentry = mnt->mnt_mountpoint;
51763 + mnt = mnt->mnt_parent;
51764 + vfsmnt = &mnt->mnt;
51765 + continue;
51766 + }
51767 + parent = dentry->d_parent;
51768 + prefetch(parent);
51769 + spin_lock(&dentry->d_lock);
51770 + error = prepend_name(buffer, buflen, &dentry->d_name);
51771 + spin_unlock(&dentry->d_lock);
51772 + if (!error)
51773 + error = prepend(buffer, buflen, "/", 1);
51774 + if (error)
51775 + break;
51776 +
51777 + slash = true;
51778 + dentry = parent;
51779 + }
51780 +
51781 +out:
51782 + if (!error && !slash)
51783 + error = prepend(buffer, buflen, "/", 1);
51784 +
51785 + return error;
51786 +}
51787 +
51788 +/* this must be called with vfsmount_lock and rename_lock held */
51789 +
51790 +static char *__our_d_path(const struct path *path, struct path *root,
51791 + char *buf, int buflen)
51792 +{
51793 + char *res = buf + buflen;
51794 + int error;
51795 +
51796 + prepend(&res, &buflen, "\0", 1);
51797 + error = prepend_path(path, root, &res, &buflen);
51798 + if (error)
51799 + return ERR_PTR(error);
51800 +
51801 + return res;
51802 +}
51803 +
51804 +static char *
51805 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51806 +{
51807 + char *retval;
51808 +
51809 + retval = __our_d_path(path, root, buf, buflen);
51810 + if (unlikely(IS_ERR(retval)))
51811 + retval = strcpy(buf, "<path too long>");
51812 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51813 + retval[1] = '\0';
51814 +
51815 + return retval;
51816 +}
51817 +
51818 +static char *
51819 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51820 + char *buf, int buflen)
51821 +{
51822 + struct path path;
51823 + char *res;
51824 +
51825 + path.dentry = (struct dentry *)dentry;
51826 + path.mnt = (struct vfsmount *)vfsmnt;
51827 +
51828 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51829 + by the RBAC system */
51830 + res = gen_full_path(&path, &real_root, buf, buflen);
51831 +
51832 + return res;
51833 +}
51834 +
51835 +static char *
51836 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51837 + char *buf, int buflen)
51838 +{
51839 + char *res;
51840 + struct path path;
51841 + struct path root;
51842 + struct task_struct *reaper = init_pid_ns.child_reaper;
51843 +
51844 + path.dentry = (struct dentry *)dentry;
51845 + path.mnt = (struct vfsmount *)vfsmnt;
51846 +
51847 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51848 + get_fs_root(reaper->fs, &root);
51849 +
51850 + write_seqlock(&rename_lock);
51851 + br_read_lock(&vfsmount_lock);
51852 + res = gen_full_path(&path, &root, buf, buflen);
51853 + br_read_unlock(&vfsmount_lock);
51854 + write_sequnlock(&rename_lock);
51855 +
51856 + path_put(&root);
51857 + return res;
51858 +}
51859 +
51860 +static char *
51861 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51862 +{
51863 + char *ret;
51864 + write_seqlock(&rename_lock);
51865 + br_read_lock(&vfsmount_lock);
51866 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51867 + PAGE_SIZE);
51868 + br_read_unlock(&vfsmount_lock);
51869 + write_sequnlock(&rename_lock);
51870 + return ret;
51871 +}
51872 +
51873 +static char *
51874 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51875 +{
51876 + char *ret;
51877 + char *buf;
51878 + int buflen;
51879 +
51880 + write_seqlock(&rename_lock);
51881 + br_read_lock(&vfsmount_lock);
51882 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51883 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51884 + buflen = (int)(ret - buf);
51885 + if (buflen >= 5)
51886 + prepend(&ret, &buflen, "/proc", 5);
51887 + else
51888 + ret = strcpy(buf, "<path too long>");
51889 + br_read_unlock(&vfsmount_lock);
51890 + write_sequnlock(&rename_lock);
51891 + return ret;
51892 +}
51893 +
51894 +char *
51895 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51896 +{
51897 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51898 + PAGE_SIZE);
51899 +}
51900 +
51901 +char *
51902 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51903 +{
51904 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51905 + PAGE_SIZE);
51906 +}
51907 +
51908 +char *
51909 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51910 +{
51911 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51912 + PAGE_SIZE);
51913 +}
51914 +
51915 +char *
51916 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51917 +{
51918 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51919 + PAGE_SIZE);
51920 +}
51921 +
51922 +char *
51923 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51924 +{
51925 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51926 + PAGE_SIZE);
51927 +}
51928 +
51929 +__inline__ __u32
51930 +to_gr_audit(const __u32 reqmode)
51931 +{
51932 + /* masks off auditable permission flags, then shifts them to create
51933 + auditing flags, and adds the special case of append auditing if
51934 + we're requesting write */
51935 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51936 +}
51937 +
51938 +struct acl_subject_label *
51939 +lookup_subject_map(const struct acl_subject_label *userp)
51940 +{
51941 + unsigned int index = shash(userp, subj_map_set.s_size);
51942 + struct subject_map *match;
51943 +
51944 + match = subj_map_set.s_hash[index];
51945 +
51946 + while (match && match->user != userp)
51947 + match = match->next;
51948 +
51949 + if (match != NULL)
51950 + return match->kernel;
51951 + else
51952 + return NULL;
51953 +}
51954 +
51955 +static void
51956 +insert_subj_map_entry(struct subject_map *subjmap)
51957 +{
51958 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51959 + struct subject_map **curr;
51960 +
51961 + subjmap->prev = NULL;
51962 +
51963 + curr = &subj_map_set.s_hash[index];
51964 + if (*curr != NULL)
51965 + (*curr)->prev = subjmap;
51966 +
51967 + subjmap->next = *curr;
51968 + *curr = subjmap;
51969 +
51970 + return;
51971 +}
51972 +
51973 +static struct acl_role_label *
51974 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51975 + const gid_t gid)
51976 +{
51977 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51978 + struct acl_role_label *match;
51979 + struct role_allowed_ip *ipp;
51980 + unsigned int x;
51981 + u32 curr_ip = task->signal->curr_ip;
51982 +
51983 + task->signal->saved_ip = curr_ip;
51984 +
51985 + match = acl_role_set.r_hash[index];
51986 +
51987 + while (match) {
51988 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51989 + for (x = 0; x < match->domain_child_num; x++) {
51990 + if (match->domain_children[x] == uid)
51991 + goto found;
51992 + }
51993 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
51994 + break;
51995 + match = match->next;
51996 + }
51997 +found:
51998 + if (match == NULL) {
51999 + try_group:
52000 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52001 + match = acl_role_set.r_hash[index];
52002 +
52003 + while (match) {
52004 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52005 + for (x = 0; x < match->domain_child_num; x++) {
52006 + if (match->domain_children[x] == gid)
52007 + goto found2;
52008 + }
52009 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52010 + break;
52011 + match = match->next;
52012 + }
52013 +found2:
52014 + if (match == NULL)
52015 + match = default_role;
52016 + if (match->allowed_ips == NULL)
52017 + return match;
52018 + else {
52019 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52020 + if (likely
52021 + ((ntohl(curr_ip) & ipp->netmask) ==
52022 + (ntohl(ipp->addr) & ipp->netmask)))
52023 + return match;
52024 + }
52025 + match = default_role;
52026 + }
52027 + } else if (match->allowed_ips == NULL) {
52028 + return match;
52029 + } else {
52030 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52031 + if (likely
52032 + ((ntohl(curr_ip) & ipp->netmask) ==
52033 + (ntohl(ipp->addr) & ipp->netmask)))
52034 + return match;
52035 + }
52036 + goto try_group;
52037 + }
52038 +
52039 + return match;
52040 +}
52041 +
52042 +struct acl_subject_label *
52043 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52044 + const struct acl_role_label *role)
52045 +{
52046 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52047 + struct acl_subject_label *match;
52048 +
52049 + match = role->subj_hash[index];
52050 +
52051 + while (match && (match->inode != ino || match->device != dev ||
52052 + (match->mode & GR_DELETED))) {
52053 + match = match->next;
52054 + }
52055 +
52056 + if (match && !(match->mode & GR_DELETED))
52057 + return match;
52058 + else
52059 + return NULL;
52060 +}
52061 +
52062 +struct acl_subject_label *
52063 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52064 + const struct acl_role_label *role)
52065 +{
52066 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52067 + struct acl_subject_label *match;
52068 +
52069 + match = role->subj_hash[index];
52070 +
52071 + while (match && (match->inode != ino || match->device != dev ||
52072 + !(match->mode & GR_DELETED))) {
52073 + match = match->next;
52074 + }
52075 +
52076 + if (match && (match->mode & GR_DELETED))
52077 + return match;
52078 + else
52079 + return NULL;
52080 +}
52081 +
52082 +static struct acl_object_label *
52083 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52084 + const struct acl_subject_label *subj)
52085 +{
52086 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52087 + struct acl_object_label *match;
52088 +
52089 + match = subj->obj_hash[index];
52090 +
52091 + while (match && (match->inode != ino || match->device != dev ||
52092 + (match->mode & GR_DELETED))) {
52093 + match = match->next;
52094 + }
52095 +
52096 + if (match && !(match->mode & GR_DELETED))
52097 + return match;
52098 + else
52099 + return NULL;
52100 +}
52101 +
52102 +static struct acl_object_label *
52103 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52104 + const struct acl_subject_label *subj)
52105 +{
52106 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52107 + struct acl_object_label *match;
52108 +
52109 + match = subj->obj_hash[index];
52110 +
52111 + while (match && (match->inode != ino || match->device != dev ||
52112 + !(match->mode & GR_DELETED))) {
52113 + match = match->next;
52114 + }
52115 +
52116 + if (match && (match->mode & GR_DELETED))
52117 + return match;
52118 +
52119 + match = subj->obj_hash[index];
52120 +
52121 + while (match && (match->inode != ino || match->device != dev ||
52122 + (match->mode & GR_DELETED))) {
52123 + match = match->next;
52124 + }
52125 +
52126 + if (match && !(match->mode & GR_DELETED))
52127 + return match;
52128 + else
52129 + return NULL;
52130 +}
52131 +
52132 +static struct name_entry *
52133 +lookup_name_entry(const char *name)
52134 +{
52135 + unsigned int len = strlen(name);
52136 + unsigned int key = full_name_hash(name, len);
52137 + unsigned int index = key % name_set.n_size;
52138 + struct name_entry *match;
52139 +
52140 + match = name_set.n_hash[index];
52141 +
52142 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52143 + match = match->next;
52144 +
52145 + return match;
52146 +}
52147 +
52148 +static struct name_entry *
52149 +lookup_name_entry_create(const char *name)
52150 +{
52151 + unsigned int len = strlen(name);
52152 + unsigned int key = full_name_hash(name, len);
52153 + unsigned int index = key % name_set.n_size;
52154 + struct name_entry *match;
52155 +
52156 + match = name_set.n_hash[index];
52157 +
52158 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52159 + !match->deleted))
52160 + match = match->next;
52161 +
52162 + if (match && match->deleted)
52163 + return match;
52164 +
52165 + match = name_set.n_hash[index];
52166 +
52167 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52168 + match->deleted))
52169 + match = match->next;
52170 +
52171 + if (match && !match->deleted)
52172 + return match;
52173 + else
52174 + return NULL;
52175 +}
52176 +
52177 +static struct inodev_entry *
52178 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52179 +{
52180 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52181 + struct inodev_entry *match;
52182 +
52183 + match = inodev_set.i_hash[index];
52184 +
52185 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52186 + match = match->next;
52187 +
52188 + return match;
52189 +}
52190 +
52191 +static void
52192 +insert_inodev_entry(struct inodev_entry *entry)
52193 +{
52194 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52195 + inodev_set.i_size);
52196 + struct inodev_entry **curr;
52197 +
52198 + entry->prev = NULL;
52199 +
52200 + curr = &inodev_set.i_hash[index];
52201 + if (*curr != NULL)
52202 + (*curr)->prev = entry;
52203 +
52204 + entry->next = *curr;
52205 + *curr = entry;
52206 +
52207 + return;
52208 +}
52209 +
52210 +static void
52211 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52212 +{
52213 + unsigned int index =
52214 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52215 + struct acl_role_label **curr;
52216 + struct acl_role_label *tmp, *tmp2;
52217 +
52218 + curr = &acl_role_set.r_hash[index];
52219 +
52220 + /* simple case, slot is empty, just set it to our role */
52221 + if (*curr == NULL) {
52222 + *curr = role;
52223 + } else {
52224 + /* example:
52225 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52226 + 2 -> 3
52227 + */
52228 + /* first check to see if we can already be reached via this slot */
52229 + tmp = *curr;
52230 + while (tmp && tmp != role)
52231 + tmp = tmp->next;
52232 + if (tmp == role) {
52233 + /* we don't need to add ourselves to this slot's chain */
52234 + return;
52235 + }
52236 + /* we need to add ourselves to this chain, two cases */
52237 + if (role->next == NULL) {
52238 + /* simple case, append the current chain to our role */
52239 + role->next = *curr;
52240 + *curr = role;
52241 + } else {
52242 + /* 1 -> 2 -> 3 -> 4
52243 + 2 -> 3 -> 4
52244 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52245 + */
52246 + /* trickier case: walk our role's chain until we find
52247 + the role for the start of the current slot's chain */
52248 + tmp = role;
52249 + tmp2 = *curr;
52250 + while (tmp->next && tmp->next != tmp2)
52251 + tmp = tmp->next;
52252 + if (tmp->next == tmp2) {
52253 + /* from example above, we found 3, so just
52254 + replace this slot's chain with ours */
52255 + *curr = role;
52256 + } else {
52257 + /* we didn't find a subset of our role's chain
52258 + in the current slot's chain, so append their
52259 + chain to ours, and set us as the first role in
52260 + the slot's chain
52261 +
52262 + we could fold this case with the case above,
52263 + but making it explicit for clarity
52264 + */
52265 + tmp->next = tmp2;
52266 + *curr = role;
52267 + }
52268 + }
52269 + }
52270 +
52271 + return;
52272 +}
52273 +
52274 +static void
52275 +insert_acl_role_label(struct acl_role_label *role)
52276 +{
52277 + int i;
52278 +
52279 + if (role_list == NULL) {
52280 + role_list = role;
52281 + role->prev = NULL;
52282 + } else {
52283 + role->prev = role_list;
52284 + role_list = role;
52285 + }
52286 +
52287 + /* used for hash chains */
52288 + role->next = NULL;
52289 +
52290 + if (role->roletype & GR_ROLE_DOMAIN) {
52291 + for (i = 0; i < role->domain_child_num; i++)
52292 + __insert_acl_role_label(role, role->domain_children[i]);
52293 + } else
52294 + __insert_acl_role_label(role, role->uidgid);
52295 +}
52296 +
52297 +static int
52298 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52299 +{
52300 + struct name_entry **curr, *nentry;
52301 + struct inodev_entry *ientry;
52302 + unsigned int len = strlen(name);
52303 + unsigned int key = full_name_hash(name, len);
52304 + unsigned int index = key % name_set.n_size;
52305 +
52306 + curr = &name_set.n_hash[index];
52307 +
52308 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52309 + curr = &((*curr)->next);
52310 +
52311 + if (*curr != NULL)
52312 + return 1;
52313 +
52314 + nentry = acl_alloc(sizeof (struct name_entry));
52315 + if (nentry == NULL)
52316 + return 0;
52317 + ientry = acl_alloc(sizeof (struct inodev_entry));
52318 + if (ientry == NULL)
52319 + return 0;
52320 + ientry->nentry = nentry;
52321 +
52322 + nentry->key = key;
52323 + nentry->name = name;
52324 + nentry->inode = inode;
52325 + nentry->device = device;
52326 + nentry->len = len;
52327 + nentry->deleted = deleted;
52328 +
52329 + nentry->prev = NULL;
52330 + curr = &name_set.n_hash[index];
52331 + if (*curr != NULL)
52332 + (*curr)->prev = nentry;
52333 + nentry->next = *curr;
52334 + *curr = nentry;
52335 +
52336 + /* insert us into the table searchable by inode/dev */
52337 + insert_inodev_entry(ientry);
52338 +
52339 + return 1;
52340 +}
52341 +
52342 +static void
52343 +insert_acl_obj_label(struct acl_object_label *obj,
52344 + struct acl_subject_label *subj)
52345 +{
52346 + unsigned int index =
52347 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52348 + struct acl_object_label **curr;
52349 +
52350 +
52351 + obj->prev = NULL;
52352 +
52353 + curr = &subj->obj_hash[index];
52354 + if (*curr != NULL)
52355 + (*curr)->prev = obj;
52356 +
52357 + obj->next = *curr;
52358 + *curr = obj;
52359 +
52360 + return;
52361 +}
52362 +
52363 +static void
52364 +insert_acl_subj_label(struct acl_subject_label *obj,
52365 + struct acl_role_label *role)
52366 +{
52367 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52368 + struct acl_subject_label **curr;
52369 +
52370 + obj->prev = NULL;
52371 +
52372 + curr = &role->subj_hash[index];
52373 + if (*curr != NULL)
52374 + (*curr)->prev = obj;
52375 +
52376 + obj->next = *curr;
52377 + *curr = obj;
52378 +
52379 + return;
52380 +}
52381 +
52382 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52383 +
52384 +static void *
52385 +create_table(__u32 * len, int elementsize)
52386 +{
52387 + unsigned int table_sizes[] = {
52388 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52389 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52390 + 4194301, 8388593, 16777213, 33554393, 67108859
52391 + };
52392 + void *newtable = NULL;
52393 + unsigned int pwr = 0;
52394 +
52395 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52396 + table_sizes[pwr] <= *len)
52397 + pwr++;
52398 +
52399 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52400 + return newtable;
52401 +
52402 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52403 + newtable =
52404 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52405 + else
52406 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52407 +
52408 + *len = table_sizes[pwr];
52409 +
52410 + return newtable;
52411 +}
52412 +
52413 +static int
52414 +init_variables(const struct gr_arg *arg)
52415 +{
52416 + struct task_struct *reaper = init_pid_ns.child_reaper;
52417 + unsigned int stacksize;
52418 +
52419 + subj_map_set.s_size = arg->role_db.num_subjects;
52420 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52421 + name_set.n_size = arg->role_db.num_objects;
52422 + inodev_set.i_size = arg->role_db.num_objects;
52423 +
52424 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52425 + !name_set.n_size || !inodev_set.i_size)
52426 + return 1;
52427 +
52428 + if (!gr_init_uidset())
52429 + return 1;
52430 +
52431 + /* set up the stack that holds allocation info */
52432 +
52433 + stacksize = arg->role_db.num_pointers + 5;
52434 +
52435 + if (!acl_alloc_stack_init(stacksize))
52436 + return 1;
52437 +
52438 + /* grab reference for the real root dentry and vfsmount */
52439 + get_fs_root(reaper->fs, &real_root);
52440 +
52441 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52442 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52443 +#endif
52444 +
52445 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52446 + if (fakefs_obj_rw == NULL)
52447 + return 1;
52448 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52449 +
52450 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52451 + if (fakefs_obj_rwx == NULL)
52452 + return 1;
52453 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52454 +
52455 + subj_map_set.s_hash =
52456 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52457 + acl_role_set.r_hash =
52458 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52459 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52460 + inodev_set.i_hash =
52461 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52462 +
52463 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52464 + !name_set.n_hash || !inodev_set.i_hash)
52465 + return 1;
52466 +
52467 + memset(subj_map_set.s_hash, 0,
52468 + sizeof(struct subject_map *) * subj_map_set.s_size);
52469 + memset(acl_role_set.r_hash, 0,
52470 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52471 + memset(name_set.n_hash, 0,
52472 + sizeof (struct name_entry *) * name_set.n_size);
52473 + memset(inodev_set.i_hash, 0,
52474 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52475 +
52476 + return 0;
52477 +}
52478 +
52479 +/* free information not needed after startup
52480 + currently contains user->kernel pointer mappings for subjects
52481 +*/
52482 +
52483 +static void
52484 +free_init_variables(void)
52485 +{
52486 + __u32 i;
52487 +
52488 + if (subj_map_set.s_hash) {
52489 + for (i = 0; i < subj_map_set.s_size; i++) {
52490 + if (subj_map_set.s_hash[i]) {
52491 + kfree(subj_map_set.s_hash[i]);
52492 + subj_map_set.s_hash[i] = NULL;
52493 + }
52494 + }
52495 +
52496 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52497 + PAGE_SIZE)
52498 + kfree(subj_map_set.s_hash);
52499 + else
52500 + vfree(subj_map_set.s_hash);
52501 + }
52502 +
52503 + return;
52504 +}
52505 +
52506 +static void
52507 +free_variables(void)
52508 +{
52509 + struct acl_subject_label *s;
52510 + struct acl_role_label *r;
52511 + struct task_struct *task, *task2;
52512 + unsigned int x;
52513 +
52514 + gr_clear_learn_entries();
52515 +
52516 + read_lock(&tasklist_lock);
52517 + do_each_thread(task2, task) {
52518 + task->acl_sp_role = 0;
52519 + task->acl_role_id = 0;
52520 + task->acl = NULL;
52521 + task->role = NULL;
52522 + } while_each_thread(task2, task);
52523 + read_unlock(&tasklist_lock);
52524 +
52525 + /* release the reference to the real root dentry and vfsmount */
52526 + path_put(&real_root);
52527 + memset(&real_root, 0, sizeof(real_root));
52528 +
52529 + /* free all object hash tables */
52530 +
52531 + FOR_EACH_ROLE_START(r)
52532 + if (r->subj_hash == NULL)
52533 + goto next_role;
52534 + FOR_EACH_SUBJECT_START(r, s, x)
52535 + if (s->obj_hash == NULL)
52536 + break;
52537 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52538 + kfree(s->obj_hash);
52539 + else
52540 + vfree(s->obj_hash);
52541 + FOR_EACH_SUBJECT_END(s, x)
52542 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52543 + if (s->obj_hash == NULL)
52544 + break;
52545 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52546 + kfree(s->obj_hash);
52547 + else
52548 + vfree(s->obj_hash);
52549 + FOR_EACH_NESTED_SUBJECT_END(s)
52550 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52551 + kfree(r->subj_hash);
52552 + else
52553 + vfree(r->subj_hash);
52554 + r->subj_hash = NULL;
52555 +next_role:
52556 + FOR_EACH_ROLE_END(r)
52557 +
52558 + acl_free_all();
52559 +
52560 + if (acl_role_set.r_hash) {
52561 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52562 + PAGE_SIZE)
52563 + kfree(acl_role_set.r_hash);
52564 + else
52565 + vfree(acl_role_set.r_hash);
52566 + }
52567 + if (name_set.n_hash) {
52568 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52569 + PAGE_SIZE)
52570 + kfree(name_set.n_hash);
52571 + else
52572 + vfree(name_set.n_hash);
52573 + }
52574 +
52575 + if (inodev_set.i_hash) {
52576 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52577 + PAGE_SIZE)
52578 + kfree(inodev_set.i_hash);
52579 + else
52580 + vfree(inodev_set.i_hash);
52581 + }
52582 +
52583 + gr_free_uidset();
52584 +
52585 + memset(&name_set, 0, sizeof (struct name_db));
52586 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52587 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52588 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52589 +
52590 + default_role = NULL;
52591 + kernel_role = NULL;
52592 + role_list = NULL;
52593 +
52594 + return;
52595 +}
52596 +
52597 +static __u32
52598 +count_user_objs(struct acl_object_label *userp)
52599 +{
52600 + struct acl_object_label o_tmp;
52601 + __u32 num = 0;
52602 +
52603 + while (userp) {
52604 + if (copy_from_user(&o_tmp, userp,
52605 + sizeof (struct acl_object_label)))
52606 + break;
52607 +
52608 + userp = o_tmp.prev;
52609 + num++;
52610 + }
52611 +
52612 + return num;
52613 +}
52614 +
52615 +static struct acl_subject_label *
52616 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52617 +
52618 +static int
52619 +copy_user_glob(struct acl_object_label *obj)
52620 +{
52621 + struct acl_object_label *g_tmp, **guser;
52622 + unsigned int len;
52623 + char *tmp;
52624 +
52625 + if (obj->globbed == NULL)
52626 + return 0;
52627 +
52628 + guser = &obj->globbed;
52629 + while (*guser) {
52630 + g_tmp = (struct acl_object_label *)
52631 + acl_alloc(sizeof (struct acl_object_label));
52632 + if (g_tmp == NULL)
52633 + return -ENOMEM;
52634 +
52635 + if (copy_from_user(g_tmp, *guser,
52636 + sizeof (struct acl_object_label)))
52637 + return -EFAULT;
52638 +
52639 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52640 +
52641 + if (!len || len >= PATH_MAX)
52642 + return -EINVAL;
52643 +
52644 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52645 + return -ENOMEM;
52646 +
52647 + if (copy_from_user(tmp, g_tmp->filename, len))
52648 + return -EFAULT;
52649 + tmp[len-1] = '\0';
52650 + g_tmp->filename = tmp;
52651 +
52652 + *guser = g_tmp;
52653 + guser = &(g_tmp->next);
52654 + }
52655 +
52656 + return 0;
52657 +}
52658 +
52659 +static int
52660 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52661 + struct acl_role_label *role)
52662 +{
52663 + struct acl_object_label *o_tmp;
52664 + unsigned int len;
52665 + int ret;
52666 + char *tmp;
52667 +
52668 + while (userp) {
52669 + if ((o_tmp = (struct acl_object_label *)
52670 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52671 + return -ENOMEM;
52672 +
52673 + if (copy_from_user(o_tmp, userp,
52674 + sizeof (struct acl_object_label)))
52675 + return -EFAULT;
52676 +
52677 + userp = o_tmp->prev;
52678 +
52679 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52680 +
52681 + if (!len || len >= PATH_MAX)
52682 + return -EINVAL;
52683 +
52684 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52685 + return -ENOMEM;
52686 +
52687 + if (copy_from_user(tmp, o_tmp->filename, len))
52688 + return -EFAULT;
52689 + tmp[len-1] = '\0';
52690 + o_tmp->filename = tmp;
52691 +
52692 + insert_acl_obj_label(o_tmp, subj);
52693 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52694 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52695 + return -ENOMEM;
52696 +
52697 + ret = copy_user_glob(o_tmp);
52698 + if (ret)
52699 + return ret;
52700 +
52701 + if (o_tmp->nested) {
52702 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52703 + if (IS_ERR(o_tmp->nested))
52704 + return PTR_ERR(o_tmp->nested);
52705 +
52706 + /* insert into nested subject list */
52707 + o_tmp->nested->next = role->hash->first;
52708 + role->hash->first = o_tmp->nested;
52709 + }
52710 + }
52711 +
52712 + return 0;
52713 +}
52714 +
52715 +static __u32
52716 +count_user_subjs(struct acl_subject_label *userp)
52717 +{
52718 + struct acl_subject_label s_tmp;
52719 + __u32 num = 0;
52720 +
52721 + while (userp) {
52722 + if (copy_from_user(&s_tmp, userp,
52723 + sizeof (struct acl_subject_label)))
52724 + break;
52725 +
52726 + userp = s_tmp.prev;
52727 + /* do not count nested subjects against this count, since
52728 + they are not included in the hash table, but are
52729 + attached to objects. We have already counted
52730 + the subjects in userspace for the allocation
52731 + stack
52732 + */
52733 + if (!(s_tmp.mode & GR_NESTED))
52734 + num++;
52735 + }
52736 +
52737 + return num;
52738 +}
52739 +
52740 +static int
52741 +copy_user_allowedips(struct acl_role_label *rolep)
52742 +{
52743 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52744 +
52745 + ruserip = rolep->allowed_ips;
52746 +
52747 + while (ruserip) {
52748 + rlast = rtmp;
52749 +
52750 + if ((rtmp = (struct role_allowed_ip *)
52751 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52752 + return -ENOMEM;
52753 +
52754 + if (copy_from_user(rtmp, ruserip,
52755 + sizeof (struct role_allowed_ip)))
52756 + return -EFAULT;
52757 +
52758 + ruserip = rtmp->prev;
52759 +
52760 + if (!rlast) {
52761 + rtmp->prev = NULL;
52762 + rolep->allowed_ips = rtmp;
52763 + } else {
52764 + rlast->next = rtmp;
52765 + rtmp->prev = rlast;
52766 + }
52767 +
52768 + if (!ruserip)
52769 + rtmp->next = NULL;
52770 + }
52771 +
52772 + return 0;
52773 +}
52774 +
52775 +static int
52776 +copy_user_transitions(struct acl_role_label *rolep)
52777 +{
52778 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52779 +
52780 + unsigned int len;
52781 + char *tmp;
52782 +
52783 + rusertp = rolep->transitions;
52784 +
52785 + while (rusertp) {
52786 + rlast = rtmp;
52787 +
52788 + if ((rtmp = (struct role_transition *)
52789 + acl_alloc(sizeof (struct role_transition))) == NULL)
52790 + return -ENOMEM;
52791 +
52792 + if (copy_from_user(rtmp, rusertp,
52793 + sizeof (struct role_transition)))
52794 + return -EFAULT;
52795 +
52796 + rusertp = rtmp->prev;
52797 +
52798 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52799 +
52800 + if (!len || len >= GR_SPROLE_LEN)
52801 + return -EINVAL;
52802 +
52803 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52804 + return -ENOMEM;
52805 +
52806 + if (copy_from_user(tmp, rtmp->rolename, len))
52807 + return -EFAULT;
52808 + tmp[len-1] = '\0';
52809 + rtmp->rolename = tmp;
52810 +
52811 + if (!rlast) {
52812 + rtmp->prev = NULL;
52813 + rolep->transitions = rtmp;
52814 + } else {
52815 + rlast->next = rtmp;
52816 + rtmp->prev = rlast;
52817 + }
52818 +
52819 + if (!rusertp)
52820 + rtmp->next = NULL;
52821 + }
52822 +
52823 + return 0;
52824 +}
52825 +
52826 +static struct acl_subject_label *
52827 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52828 +{
52829 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52830 + unsigned int len;
52831 + char *tmp;
52832 + __u32 num_objs;
52833 + struct acl_ip_label **i_tmp, *i_utmp2;
52834 + struct gr_hash_struct ghash;
52835 + struct subject_map *subjmap;
52836 + unsigned int i_num;
52837 + int err;
52838 +
52839 + s_tmp = lookup_subject_map(userp);
52840 +
52841 + /* we've already copied this subject into the kernel, just return
52842 + the reference to it, and don't copy it over again
52843 + */
52844 + if (s_tmp)
52845 + return(s_tmp);
52846 +
52847 + if ((s_tmp = (struct acl_subject_label *)
52848 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52849 + return ERR_PTR(-ENOMEM);
52850 +
52851 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52852 + if (subjmap == NULL)
52853 + return ERR_PTR(-ENOMEM);
52854 +
52855 + subjmap->user = userp;
52856 + subjmap->kernel = s_tmp;
52857 + insert_subj_map_entry(subjmap);
52858 +
52859 + if (copy_from_user(s_tmp, userp,
52860 + sizeof (struct acl_subject_label)))
52861 + return ERR_PTR(-EFAULT);
52862 +
52863 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52864 +
52865 + if (!len || len >= PATH_MAX)
52866 + return ERR_PTR(-EINVAL);
52867 +
52868 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52869 + return ERR_PTR(-ENOMEM);
52870 +
52871 + if (copy_from_user(tmp, s_tmp->filename, len))
52872 + return ERR_PTR(-EFAULT);
52873 + tmp[len-1] = '\0';
52874 + s_tmp->filename = tmp;
52875 +
52876 + if (!strcmp(s_tmp->filename, "/"))
52877 + role->root_label = s_tmp;
52878 +
52879 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52880 + return ERR_PTR(-EFAULT);
52881 +
52882 + /* copy user and group transition tables */
52883 +
52884 + if (s_tmp->user_trans_num) {
52885 + uid_t *uidlist;
52886 +
52887 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52888 + if (uidlist == NULL)
52889 + return ERR_PTR(-ENOMEM);
52890 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52891 + return ERR_PTR(-EFAULT);
52892 +
52893 + s_tmp->user_transitions = uidlist;
52894 + }
52895 +
52896 + if (s_tmp->group_trans_num) {
52897 + gid_t *gidlist;
52898 +
52899 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52900 + if (gidlist == NULL)
52901 + return ERR_PTR(-ENOMEM);
52902 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52903 + return ERR_PTR(-EFAULT);
52904 +
52905 + s_tmp->group_transitions = gidlist;
52906 + }
52907 +
52908 + /* set up object hash table */
52909 + num_objs = count_user_objs(ghash.first);
52910 +
52911 + s_tmp->obj_hash_size = num_objs;
52912 + s_tmp->obj_hash =
52913 + (struct acl_object_label **)
52914 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52915 +
52916 + if (!s_tmp->obj_hash)
52917 + return ERR_PTR(-ENOMEM);
52918 +
52919 + memset(s_tmp->obj_hash, 0,
52920 + s_tmp->obj_hash_size *
52921 + sizeof (struct acl_object_label *));
52922 +
52923 + /* add in objects */
52924 + err = copy_user_objs(ghash.first, s_tmp, role);
52925 +
52926 + if (err)
52927 + return ERR_PTR(err);
52928 +
52929 + /* set pointer for parent subject */
52930 + if (s_tmp->parent_subject) {
52931 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52932 +
52933 + if (IS_ERR(s_tmp2))
52934 + return s_tmp2;
52935 +
52936 + s_tmp->parent_subject = s_tmp2;
52937 + }
52938 +
52939 + /* add in ip acls */
52940 +
52941 + if (!s_tmp->ip_num) {
52942 + s_tmp->ips = NULL;
52943 + goto insert;
52944 + }
52945 +
52946 + i_tmp =
52947 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52948 + sizeof (struct acl_ip_label *));
52949 +
52950 + if (!i_tmp)
52951 + return ERR_PTR(-ENOMEM);
52952 +
52953 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52954 + *(i_tmp + i_num) =
52955 + (struct acl_ip_label *)
52956 + acl_alloc(sizeof (struct acl_ip_label));
52957 + if (!*(i_tmp + i_num))
52958 + return ERR_PTR(-ENOMEM);
52959 +
52960 + if (copy_from_user
52961 + (&i_utmp2, s_tmp->ips + i_num,
52962 + sizeof (struct acl_ip_label *)))
52963 + return ERR_PTR(-EFAULT);
52964 +
52965 + if (copy_from_user
52966 + (*(i_tmp + i_num), i_utmp2,
52967 + sizeof (struct acl_ip_label)))
52968 + return ERR_PTR(-EFAULT);
52969 +
52970 + if ((*(i_tmp + i_num))->iface == NULL)
52971 + continue;
52972 +
52973 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52974 + if (!len || len >= IFNAMSIZ)
52975 + return ERR_PTR(-EINVAL);
52976 + tmp = acl_alloc(len);
52977 + if (tmp == NULL)
52978 + return ERR_PTR(-ENOMEM);
52979 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52980 + return ERR_PTR(-EFAULT);
52981 + (*(i_tmp + i_num))->iface = tmp;
52982 + }
52983 +
52984 + s_tmp->ips = i_tmp;
52985 +
52986 +insert:
52987 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52988 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52989 + return ERR_PTR(-ENOMEM);
52990 +
52991 + return s_tmp;
52992 +}
52993 +
52994 +static int
52995 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
52996 +{
52997 + struct acl_subject_label s_pre;
52998 + struct acl_subject_label * ret;
52999 + int err;
53000 +
53001 + while (userp) {
53002 + if (copy_from_user(&s_pre, userp,
53003 + sizeof (struct acl_subject_label)))
53004 + return -EFAULT;
53005 +
53006 + /* do not add nested subjects here, add
53007 + while parsing objects
53008 + */
53009 +
53010 + if (s_pre.mode & GR_NESTED) {
53011 + userp = s_pre.prev;
53012 + continue;
53013 + }
53014 +
53015 + ret = do_copy_user_subj(userp, role);
53016 +
53017 + err = PTR_ERR(ret);
53018 + if (IS_ERR(ret))
53019 + return err;
53020 +
53021 + insert_acl_subj_label(ret, role);
53022 +
53023 + userp = s_pre.prev;
53024 + }
53025 +
53026 + return 0;
53027 +}
53028 +
53029 +static int
53030 +copy_user_acl(struct gr_arg *arg)
53031 +{
53032 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53033 + struct acl_subject_label *subj_list;
53034 + struct sprole_pw *sptmp;
53035 + struct gr_hash_struct *ghash;
53036 + uid_t *domainlist;
53037 + unsigned int r_num;
53038 + unsigned int len;
53039 + char *tmp;
53040 + int err = 0;
53041 + __u16 i;
53042 + __u32 num_subjs;
53043 +
53044 + /* we need a default and kernel role */
53045 + if (arg->role_db.num_roles < 2)
53046 + return -EINVAL;
53047 +
53048 + /* copy special role authentication info from userspace */
53049 +
53050 + num_sprole_pws = arg->num_sprole_pws;
53051 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53052 +
53053 + if (!acl_special_roles && num_sprole_pws)
53054 + return -ENOMEM;
53055 +
53056 + for (i = 0; i < num_sprole_pws; i++) {
53057 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53058 + if (!sptmp)
53059 + return -ENOMEM;
53060 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53061 + sizeof (struct sprole_pw)))
53062 + return -EFAULT;
53063 +
53064 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53065 +
53066 + if (!len || len >= GR_SPROLE_LEN)
53067 + return -EINVAL;
53068 +
53069 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53070 + return -ENOMEM;
53071 +
53072 + if (copy_from_user(tmp, sptmp->rolename, len))
53073 + return -EFAULT;
53074 +
53075 + tmp[len-1] = '\0';
53076 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53077 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53078 +#endif
53079 + sptmp->rolename = tmp;
53080 + acl_special_roles[i] = sptmp;
53081 + }
53082 +
53083 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53084 +
53085 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53086 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53087 +
53088 + if (!r_tmp)
53089 + return -ENOMEM;
53090 +
53091 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53092 + sizeof (struct acl_role_label *)))
53093 + return -EFAULT;
53094 +
53095 + if (copy_from_user(r_tmp, r_utmp2,
53096 + sizeof (struct acl_role_label)))
53097 + return -EFAULT;
53098 +
53099 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53100 +
53101 + if (!len || len >= PATH_MAX)
53102 + return -EINVAL;
53103 +
53104 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53105 + return -ENOMEM;
53106 +
53107 + if (copy_from_user(tmp, r_tmp->rolename, len))
53108 + return -EFAULT;
53109 +
53110 + tmp[len-1] = '\0';
53111 + r_tmp->rolename = tmp;
53112 +
53113 + if (!strcmp(r_tmp->rolename, "default")
53114 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53115 + default_role = r_tmp;
53116 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53117 + kernel_role = r_tmp;
53118 + }
53119 +
53120 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53121 + return -ENOMEM;
53122 +
53123 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53124 + return -EFAULT;
53125 +
53126 + r_tmp->hash = ghash;
53127 +
53128 + num_subjs = count_user_subjs(r_tmp->hash->first);
53129 +
53130 + r_tmp->subj_hash_size = num_subjs;
53131 + r_tmp->subj_hash =
53132 + (struct acl_subject_label **)
53133 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53134 +
53135 + if (!r_tmp->subj_hash)
53136 + return -ENOMEM;
53137 +
53138 + err = copy_user_allowedips(r_tmp);
53139 + if (err)
53140 + return err;
53141 +
53142 + /* copy domain info */
53143 + if (r_tmp->domain_children != NULL) {
53144 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53145 + if (domainlist == NULL)
53146 + return -ENOMEM;
53147 +
53148 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53149 + return -EFAULT;
53150 +
53151 + r_tmp->domain_children = domainlist;
53152 + }
53153 +
53154 + err = copy_user_transitions(r_tmp);
53155 + if (err)
53156 + return err;
53157 +
53158 + memset(r_tmp->subj_hash, 0,
53159 + r_tmp->subj_hash_size *
53160 + sizeof (struct acl_subject_label *));
53161 +
53162 + /* acquire the list of subjects, then NULL out
53163 + the list prior to parsing the subjects for this role,
53164 + as during this parsing the list is replaced with a list
53165 + of *nested* subjects for the role
53166 + */
53167 + subj_list = r_tmp->hash->first;
53168 +
53169 + /* set nested subject list to null */
53170 + r_tmp->hash->first = NULL;
53171 +
53172 + err = copy_user_subjs(subj_list, r_tmp);
53173 +
53174 + if (err)
53175 + return err;
53176 +
53177 + insert_acl_role_label(r_tmp);
53178 + }
53179 +
53180 + if (default_role == NULL || kernel_role == NULL)
53181 + return -EINVAL;
53182 +
53183 + return err;
53184 +}
53185 +
53186 +static int
53187 +gracl_init(struct gr_arg *args)
53188 +{
53189 + int error = 0;
53190 +
53191 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53192 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53193 +
53194 + if (init_variables(args)) {
53195 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53196 + error = -ENOMEM;
53197 + free_variables();
53198 + goto out;
53199 + }
53200 +
53201 + error = copy_user_acl(args);
53202 + free_init_variables();
53203 + if (error) {
53204 + free_variables();
53205 + goto out;
53206 + }
53207 +
53208 + if ((error = gr_set_acls(0))) {
53209 + free_variables();
53210 + goto out;
53211 + }
53212 +
53213 + pax_open_kernel();
53214 + gr_status |= GR_READY;
53215 + pax_close_kernel();
53216 +
53217 + out:
53218 + return error;
53219 +}
53220 +
53221 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53222 +
53223 +static int
53224 +glob_match(const char *p, const char *n)
53225 +{
53226 + char c;
53227 +
53228 + while ((c = *p++) != '\0') {
53229 + switch (c) {
53230 + case '?':
53231 + if (*n == '\0')
53232 + return 1;
53233 + else if (*n == '/')
53234 + return 1;
53235 + break;
53236 + case '\\':
53237 + if (*n != c)
53238 + return 1;
53239 + break;
53240 + case '*':
53241 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53242 + if (*n == '/')
53243 + return 1;
53244 + else if (c == '?') {
53245 + if (*n == '\0')
53246 + return 1;
53247 + else
53248 + ++n;
53249 + }
53250 + }
53251 + if (c == '\0') {
53252 + return 0;
53253 + } else {
53254 + const char *endp;
53255 +
53256 + if ((endp = strchr(n, '/')) == NULL)
53257 + endp = n + strlen(n);
53258 +
53259 + if (c == '[') {
53260 + for (--p; n < endp; ++n)
53261 + if (!glob_match(p, n))
53262 + return 0;
53263 + } else if (c == '/') {
53264 + while (*n != '\0' && *n != '/')
53265 + ++n;
53266 + if (*n == '/' && !glob_match(p, n + 1))
53267 + return 0;
53268 + } else {
53269 + for (--p; n < endp; ++n)
53270 + if (*n == c && !glob_match(p, n))
53271 + return 0;
53272 + }
53273 +
53274 + return 1;
53275 + }
53276 + case '[':
53277 + {
53278 + int not;
53279 + char cold;
53280 +
53281 + if (*n == '\0' || *n == '/')
53282 + return 1;
53283 +
53284 + not = (*p == '!' || *p == '^');
53285 + if (not)
53286 + ++p;
53287 +
53288 + c = *p++;
53289 + for (;;) {
53290 + unsigned char fn = (unsigned char)*n;
53291 +
53292 + if (c == '\0')
53293 + return 1;
53294 + else {
53295 + if (c == fn)
53296 + goto matched;
53297 + cold = c;
53298 + c = *p++;
53299 +
53300 + if (c == '-' && *p != ']') {
53301 + unsigned char cend = *p++;
53302 +
53303 + if (cend == '\0')
53304 + return 1;
53305 +
53306 + if (cold <= fn && fn <= cend)
53307 + goto matched;
53308 +
53309 + c = *p++;
53310 + }
53311 + }
53312 +
53313 + if (c == ']')
53314 + break;
53315 + }
53316 + if (!not)
53317 + return 1;
53318 + break;
53319 + matched:
53320 + while (c != ']') {
53321 + if (c == '\0')
53322 + return 1;
53323 +
53324 + c = *p++;
53325 + }
53326 + if (not)
53327 + return 1;
53328 + }
53329 + break;
53330 + default:
53331 + if (c != *n)
53332 + return 1;
53333 + }
53334 +
53335 + ++n;
53336 + }
53337 +
53338 + if (*n == '\0')
53339 + return 0;
53340 +
53341 + if (*n == '/')
53342 + return 0;
53343 +
53344 + return 1;
53345 +}
53346 +
53347 +static struct acl_object_label *
53348 +chk_glob_label(struct acl_object_label *globbed,
53349 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53350 +{
53351 + struct acl_object_label *tmp;
53352 +
53353 + if (*path == NULL)
53354 + *path = gr_to_filename_nolock(dentry, mnt);
53355 +
53356 + tmp = globbed;
53357 +
53358 + while (tmp) {
53359 + if (!glob_match(tmp->filename, *path))
53360 + return tmp;
53361 + tmp = tmp->next;
53362 + }
53363 +
53364 + return NULL;
53365 +}
53366 +
53367 +static struct acl_object_label *
53368 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53369 + const ino_t curr_ino, const dev_t curr_dev,
53370 + const struct acl_subject_label *subj, char **path, const int checkglob)
53371 +{
53372 + struct acl_subject_label *tmpsubj;
53373 + struct acl_object_label *retval;
53374 + struct acl_object_label *retval2;
53375 +
53376 + tmpsubj = (struct acl_subject_label *) subj;
53377 + read_lock(&gr_inode_lock);
53378 + do {
53379 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53380 + if (retval) {
53381 + if (checkglob && retval->globbed) {
53382 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53383 + if (retval2)
53384 + retval = retval2;
53385 + }
53386 + break;
53387 + }
53388 + } while ((tmpsubj = tmpsubj->parent_subject));
53389 + read_unlock(&gr_inode_lock);
53390 +
53391 + return retval;
53392 +}
53393 +
53394 +static __inline__ struct acl_object_label *
53395 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53396 + struct dentry *curr_dentry,
53397 + const struct acl_subject_label *subj, char **path, const int checkglob)
53398 +{
53399 + int newglob = checkglob;
53400 + ino_t inode;
53401 + dev_t device;
53402 +
53403 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53404 + as we don't want a / * rule to match instead of the / object
53405 + don't do this for create lookups that call this function though, since they're looking up
53406 + on the parent and thus need globbing checks on all paths
53407 + */
53408 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53409 + newglob = GR_NO_GLOB;
53410 +
53411 + spin_lock(&curr_dentry->d_lock);
53412 + inode = curr_dentry->d_inode->i_ino;
53413 + device = __get_dev(curr_dentry);
53414 + spin_unlock(&curr_dentry->d_lock);
53415 +
53416 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53417 +}
53418 +
53419 +static struct acl_object_label *
53420 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53421 + const struct acl_subject_label *subj, char *path, const int checkglob)
53422 +{
53423 + struct dentry *dentry = (struct dentry *) l_dentry;
53424 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53425 + struct mount *real_mnt = real_mount(mnt);
53426 + struct acl_object_label *retval;
53427 + struct dentry *parent;
53428 +
53429 + write_seqlock(&rename_lock);
53430 + br_read_lock(&vfsmount_lock);
53431 +
53432 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53433 +#ifdef CONFIG_NET
53434 + mnt == sock_mnt ||
53435 +#endif
53436 +#ifdef CONFIG_HUGETLBFS
53437 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53438 +#endif
53439 + /* ignore Eric Biederman */
53440 + IS_PRIVATE(l_dentry->d_inode))) {
53441 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53442 + goto out;
53443 + }
53444 +
53445 + for (;;) {
53446 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53447 + break;
53448 +
53449 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53450 + if (!mnt_has_parent(real_mnt))
53451 + break;
53452 +
53453 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53454 + if (retval != NULL)
53455 + goto out;
53456 +
53457 + dentry = real_mnt->mnt_mountpoint;
53458 + real_mnt = real_mnt->mnt_parent;
53459 + mnt = &real_mnt->mnt;
53460 + continue;
53461 + }
53462 +
53463 + parent = dentry->d_parent;
53464 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53465 + if (retval != NULL)
53466 + goto out;
53467 +
53468 + dentry = parent;
53469 + }
53470 +
53471 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53472 +
53473 + /* real_root is pinned so we don't have to hold a reference */
53474 + if (retval == NULL)
53475 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53476 +out:
53477 + br_read_unlock(&vfsmount_lock);
53478 + write_sequnlock(&rename_lock);
53479 +
53480 + BUG_ON(retval == NULL);
53481 +
53482 + return retval;
53483 +}
53484 +
53485 +static __inline__ struct acl_object_label *
53486 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53487 + const struct acl_subject_label *subj)
53488 +{
53489 + char *path = NULL;
53490 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53491 +}
53492 +
53493 +static __inline__ struct acl_object_label *
53494 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53495 + const struct acl_subject_label *subj)
53496 +{
53497 + char *path = NULL;
53498 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53499 +}
53500 +
53501 +static __inline__ struct acl_object_label *
53502 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53503 + const struct acl_subject_label *subj, char *path)
53504 +{
53505 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53506 +}
53507 +
53508 +static struct acl_subject_label *
53509 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53510 + const struct acl_role_label *role)
53511 +{
53512 + struct dentry *dentry = (struct dentry *) l_dentry;
53513 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53514 + struct mount *real_mnt = real_mount(mnt);
53515 + struct acl_subject_label *retval;
53516 + struct dentry *parent;
53517 +
53518 + write_seqlock(&rename_lock);
53519 + br_read_lock(&vfsmount_lock);
53520 +
53521 + for (;;) {
53522 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53523 + break;
53524 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53525 + if (!mnt_has_parent(real_mnt))
53526 + break;
53527 +
53528 + spin_lock(&dentry->d_lock);
53529 + read_lock(&gr_inode_lock);
53530 + retval =
53531 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53532 + __get_dev(dentry), role);
53533 + read_unlock(&gr_inode_lock);
53534 + spin_unlock(&dentry->d_lock);
53535 + if (retval != NULL)
53536 + goto out;
53537 +
53538 + dentry = real_mnt->mnt_mountpoint;
53539 + real_mnt = real_mnt->mnt_parent;
53540 + mnt = &real_mnt->mnt;
53541 + continue;
53542 + }
53543 +
53544 + spin_lock(&dentry->d_lock);
53545 + read_lock(&gr_inode_lock);
53546 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53547 + __get_dev(dentry), role);
53548 + read_unlock(&gr_inode_lock);
53549 + parent = dentry->d_parent;
53550 + spin_unlock(&dentry->d_lock);
53551 +
53552 + if (retval != NULL)
53553 + goto out;
53554 +
53555 + dentry = parent;
53556 + }
53557 +
53558 + spin_lock(&dentry->d_lock);
53559 + read_lock(&gr_inode_lock);
53560 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53561 + __get_dev(dentry), role);
53562 + read_unlock(&gr_inode_lock);
53563 + spin_unlock(&dentry->d_lock);
53564 +
53565 + if (unlikely(retval == NULL)) {
53566 + /* real_root is pinned, we don't need to hold a reference */
53567 + read_lock(&gr_inode_lock);
53568 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53569 + __get_dev(real_root.dentry), role);
53570 + read_unlock(&gr_inode_lock);
53571 + }
53572 +out:
53573 + br_read_unlock(&vfsmount_lock);
53574 + write_sequnlock(&rename_lock);
53575 +
53576 + BUG_ON(retval == NULL);
53577 +
53578 + return retval;
53579 +}
53580 +
53581 +static void
53582 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53583 +{
53584 + struct task_struct *task = current;
53585 + const struct cred *cred = current_cred();
53586 +
53587 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53588 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53589 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53590 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53591 +
53592 + return;
53593 +}
53594 +
53595 +static void
53596 +gr_log_learn_id_change(const char type, const unsigned int real,
53597 + const unsigned int effective, const unsigned int fs)
53598 +{
53599 + struct task_struct *task = current;
53600 + const struct cred *cred = current_cred();
53601 +
53602 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53603 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53604 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53605 + type, real, effective, fs, &task->signal->saved_ip);
53606 +
53607 + return;
53608 +}
53609 +
53610 +__u32
53611 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53612 + const struct vfsmount * mnt)
53613 +{
53614 + __u32 retval = mode;
53615 + struct acl_subject_label *curracl;
53616 + struct acl_object_label *currobj;
53617 +
53618 + if (unlikely(!(gr_status & GR_READY)))
53619 + return (mode & ~GR_AUDITS);
53620 +
53621 + curracl = current->acl;
53622 +
53623 + currobj = chk_obj_label(dentry, mnt, curracl);
53624 + retval = currobj->mode & mode;
53625 +
53626 + /* if we're opening a specified transfer file for writing
53627 + (e.g. /dev/initctl), then transfer our role to init
53628 + */
53629 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53630 + current->role->roletype & GR_ROLE_PERSIST)) {
53631 + struct task_struct *task = init_pid_ns.child_reaper;
53632 +
53633 + if (task->role != current->role) {
53634 + task->acl_sp_role = 0;
53635 + task->acl_role_id = current->acl_role_id;
53636 + task->role = current->role;
53637 + rcu_read_lock();
53638 + read_lock(&grsec_exec_file_lock);
53639 + gr_apply_subject_to_task(task);
53640 + read_unlock(&grsec_exec_file_lock);
53641 + rcu_read_unlock();
53642 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53643 + }
53644 + }
53645 +
53646 + if (unlikely
53647 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53648 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53649 + __u32 new_mode = mode;
53650 +
53651 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53652 +
53653 + retval = new_mode;
53654 +
53655 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53656 + new_mode |= GR_INHERIT;
53657 +
53658 + if (!(mode & GR_NOLEARN))
53659 + gr_log_learn(dentry, mnt, new_mode);
53660 + }
53661 +
53662 + return retval;
53663 +}
53664 +
53665 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53666 + const struct dentry *parent,
53667 + const struct vfsmount *mnt)
53668 +{
53669 + struct name_entry *match;
53670 + struct acl_object_label *matchpo;
53671 + struct acl_subject_label *curracl;
53672 + char *path;
53673 +
53674 + if (unlikely(!(gr_status & GR_READY)))
53675 + return NULL;
53676 +
53677 + preempt_disable();
53678 + path = gr_to_filename_rbac(new_dentry, mnt);
53679 + match = lookup_name_entry_create(path);
53680 +
53681 + curracl = current->acl;
53682 +
53683 + if (match) {
53684 + read_lock(&gr_inode_lock);
53685 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53686 + read_unlock(&gr_inode_lock);
53687 +
53688 + if (matchpo) {
53689 + preempt_enable();
53690 + return matchpo;
53691 + }
53692 + }
53693 +
53694 + // lookup parent
53695 +
53696 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53697 +
53698 + preempt_enable();
53699 + return matchpo;
53700 +}
53701 +
53702 +__u32
53703 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53704 + const struct vfsmount * mnt, const __u32 mode)
53705 +{
53706 + struct acl_object_label *matchpo;
53707 + __u32 retval;
53708 +
53709 + if (unlikely(!(gr_status & GR_READY)))
53710 + return (mode & ~GR_AUDITS);
53711 +
53712 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53713 +
53714 + retval = matchpo->mode & mode;
53715 +
53716 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53717 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53718 + __u32 new_mode = mode;
53719 +
53720 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53721 +
53722 + gr_log_learn(new_dentry, mnt, new_mode);
53723 + return new_mode;
53724 + }
53725 +
53726 + return retval;
53727 +}
53728 +
53729 +__u32
53730 +gr_check_link(const struct dentry * new_dentry,
53731 + const struct dentry * parent_dentry,
53732 + const struct vfsmount * parent_mnt,
53733 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53734 +{
53735 + struct acl_object_label *obj;
53736 + __u32 oldmode, newmode;
53737 + __u32 needmode;
53738 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53739 + GR_DELETE | GR_INHERIT;
53740 +
53741 + if (unlikely(!(gr_status & GR_READY)))
53742 + return (GR_CREATE | GR_LINK);
53743 +
53744 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53745 + oldmode = obj->mode;
53746 +
53747 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53748 + newmode = obj->mode;
53749 +
53750 + needmode = newmode & checkmodes;
53751 +
53752 + // old name for hardlink must have at least the permissions of the new name
53753 + if ((oldmode & needmode) != needmode)
53754 + goto bad;
53755 +
53756 + // if old name had restrictions/auditing, make sure the new name does as well
53757 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53758 +
53759 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53760 + if (is_privileged_binary(old_dentry))
53761 + needmode |= GR_SETID;
53762 +
53763 + if ((newmode & needmode) != needmode)
53764 + goto bad;
53765 +
53766 + // enforce minimum permissions
53767 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53768 + return newmode;
53769 +bad:
53770 + needmode = oldmode;
53771 + if (is_privileged_binary(old_dentry))
53772 + needmode |= GR_SETID;
53773 +
53774 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53775 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53776 + return (GR_CREATE | GR_LINK);
53777 + } else if (newmode & GR_SUPPRESS)
53778 + return GR_SUPPRESS;
53779 + else
53780 + return 0;
53781 +}
53782 +
53783 +int
53784 +gr_check_hidden_task(const struct task_struct *task)
53785 +{
53786 + if (unlikely(!(gr_status & GR_READY)))
53787 + return 0;
53788 +
53789 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53790 + return 1;
53791 +
53792 + return 0;
53793 +}
53794 +
53795 +int
53796 +gr_check_protected_task(const struct task_struct *task)
53797 +{
53798 + if (unlikely(!(gr_status & GR_READY) || !task))
53799 + return 0;
53800 +
53801 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53802 + task->acl != current->acl)
53803 + return 1;
53804 +
53805 + return 0;
53806 +}
53807 +
53808 +int
53809 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53810 +{
53811 + struct task_struct *p;
53812 + int ret = 0;
53813 +
53814 + if (unlikely(!(gr_status & GR_READY) || !pid))
53815 + return ret;
53816 +
53817 + read_lock(&tasklist_lock);
53818 + do_each_pid_task(pid, type, p) {
53819 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53820 + p->acl != current->acl) {
53821 + ret = 1;
53822 + goto out;
53823 + }
53824 + } while_each_pid_task(pid, type, p);
53825 +out:
53826 + read_unlock(&tasklist_lock);
53827 +
53828 + return ret;
53829 +}
53830 +
53831 +void
53832 +gr_copy_label(struct task_struct *tsk)
53833 +{
53834 + tsk->signal->used_accept = 0;
53835 + tsk->acl_sp_role = 0;
53836 + tsk->acl_role_id = current->acl_role_id;
53837 + tsk->acl = current->acl;
53838 + tsk->role = current->role;
53839 + tsk->signal->curr_ip = current->signal->curr_ip;
53840 + tsk->signal->saved_ip = current->signal->saved_ip;
53841 + if (current->exec_file)
53842 + get_file(current->exec_file);
53843 + tsk->exec_file = current->exec_file;
53844 + tsk->is_writable = current->is_writable;
53845 + if (unlikely(current->signal->used_accept)) {
53846 + current->signal->curr_ip = 0;
53847 + current->signal->saved_ip = 0;
53848 + }
53849 +
53850 + return;
53851 +}
53852 +
53853 +static void
53854 +gr_set_proc_res(struct task_struct *task)
53855 +{
53856 + struct acl_subject_label *proc;
53857 + unsigned short i;
53858 +
53859 + proc = task->acl;
53860 +
53861 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53862 + return;
53863 +
53864 + for (i = 0; i < RLIM_NLIMITS; i++) {
53865 + if (!(proc->resmask & (1 << i)))
53866 + continue;
53867 +
53868 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53869 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53870 + }
53871 +
53872 + return;
53873 +}
53874 +
53875 +extern int __gr_process_user_ban(struct user_struct *user);
53876 +
53877 +int
53878 +gr_check_user_change(int real, int effective, int fs)
53879 +{
53880 + unsigned int i;
53881 + __u16 num;
53882 + uid_t *uidlist;
53883 + int curuid;
53884 + int realok = 0;
53885 + int effectiveok = 0;
53886 + int fsok = 0;
53887 +
53888 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53889 + struct user_struct *user;
53890 +
53891 + if (real == -1)
53892 + goto skipit;
53893 +
53894 + user = find_user(real);
53895 + if (user == NULL)
53896 + goto skipit;
53897 +
53898 + if (__gr_process_user_ban(user)) {
53899 + /* for find_user */
53900 + free_uid(user);
53901 + return 1;
53902 + }
53903 +
53904 + /* for find_user */
53905 + free_uid(user);
53906 +
53907 +skipit:
53908 +#endif
53909 +
53910 + if (unlikely(!(gr_status & GR_READY)))
53911 + return 0;
53912 +
53913 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53914 + gr_log_learn_id_change('u', real, effective, fs);
53915 +
53916 + num = current->acl->user_trans_num;
53917 + uidlist = current->acl->user_transitions;
53918 +
53919 + if (uidlist == NULL)
53920 + return 0;
53921 +
53922 + if (real == -1)
53923 + realok = 1;
53924 + if (effective == -1)
53925 + effectiveok = 1;
53926 + if (fs == -1)
53927 + fsok = 1;
53928 +
53929 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53930 + for (i = 0; i < num; i++) {
53931 + curuid = (int)uidlist[i];
53932 + if (real == curuid)
53933 + realok = 1;
53934 + if (effective == curuid)
53935 + effectiveok = 1;
53936 + if (fs == curuid)
53937 + fsok = 1;
53938 + }
53939 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53940 + for (i = 0; i < num; i++) {
53941 + curuid = (int)uidlist[i];
53942 + if (real == curuid)
53943 + break;
53944 + if (effective == curuid)
53945 + break;
53946 + if (fs == curuid)
53947 + break;
53948 + }
53949 + /* not in deny list */
53950 + if (i == num) {
53951 + realok = 1;
53952 + effectiveok = 1;
53953 + fsok = 1;
53954 + }
53955 + }
53956 +
53957 + if (realok && effectiveok && fsok)
53958 + return 0;
53959 + else {
53960 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53961 + return 1;
53962 + }
53963 +}
53964 +
53965 +int
53966 +gr_check_group_change(int real, int effective, int fs)
53967 +{
53968 + unsigned int i;
53969 + __u16 num;
53970 + gid_t *gidlist;
53971 + int curgid;
53972 + int realok = 0;
53973 + int effectiveok = 0;
53974 + int fsok = 0;
53975 +
53976 + if (unlikely(!(gr_status & GR_READY)))
53977 + return 0;
53978 +
53979 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53980 + gr_log_learn_id_change('g', real, effective, fs);
53981 +
53982 + num = current->acl->group_trans_num;
53983 + gidlist = current->acl->group_transitions;
53984 +
53985 + if (gidlist == NULL)
53986 + return 0;
53987 +
53988 + if (real == -1)
53989 + realok = 1;
53990 + if (effective == -1)
53991 + effectiveok = 1;
53992 + if (fs == -1)
53993 + fsok = 1;
53994 +
53995 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53996 + for (i = 0; i < num; i++) {
53997 + curgid = (int)gidlist[i];
53998 + if (real == curgid)
53999 + realok = 1;
54000 + if (effective == curgid)
54001 + effectiveok = 1;
54002 + if (fs == curgid)
54003 + fsok = 1;
54004 + }
54005 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54006 + for (i = 0; i < num; i++) {
54007 + curgid = (int)gidlist[i];
54008 + if (real == curgid)
54009 + break;
54010 + if (effective == curgid)
54011 + break;
54012 + if (fs == curgid)
54013 + break;
54014 + }
54015 + /* not in deny list */
54016 + if (i == num) {
54017 + realok = 1;
54018 + effectiveok = 1;
54019 + fsok = 1;
54020 + }
54021 + }
54022 +
54023 + if (realok && effectiveok && fsok)
54024 + return 0;
54025 + else {
54026 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54027 + return 1;
54028 + }
54029 +}
54030 +
54031 +extern int gr_acl_is_capable(const int cap);
54032 +
54033 +void
54034 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54035 +{
54036 + struct acl_role_label *role = task->role;
54037 + struct acl_subject_label *subj = NULL;
54038 + struct acl_object_label *obj;
54039 + struct file *filp;
54040 +
54041 + if (unlikely(!(gr_status & GR_READY)))
54042 + return;
54043 +
54044 + filp = task->exec_file;
54045 +
54046 + /* kernel process, we'll give them the kernel role */
54047 + if (unlikely(!filp)) {
54048 + task->role = kernel_role;
54049 + task->acl = kernel_role->root_label;
54050 + return;
54051 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54052 + role = lookup_acl_role_label(task, uid, gid);
54053 +
54054 + /* don't change the role if we're not a privileged process */
54055 + if (role && task->role != role &&
54056 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54057 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54058 + return;
54059 +
54060 + /* perform subject lookup in possibly new role
54061 + we can use this result below in the case where role == task->role
54062 + */
54063 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54064 +
54065 + /* if we changed uid/gid, but result in the same role
54066 + and are using inheritance, don't lose the inherited subject
54067 + if current subject is other than what normal lookup
54068 + would result in, we arrived via inheritance, don't
54069 + lose subject
54070 + */
54071 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54072 + (subj == task->acl)))
54073 + task->acl = subj;
54074 +
54075 + task->role = role;
54076 +
54077 + task->is_writable = 0;
54078 +
54079 + /* ignore additional mmap checks for processes that are writable
54080 + by the default ACL */
54081 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54082 + if (unlikely(obj->mode & GR_WRITE))
54083 + task->is_writable = 1;
54084 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54085 + if (unlikely(obj->mode & GR_WRITE))
54086 + task->is_writable = 1;
54087 +
54088 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54089 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54090 +#endif
54091 +
54092 + gr_set_proc_res(task);
54093 +
54094 + return;
54095 +}
54096 +
54097 +int
54098 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54099 + const int unsafe_flags)
54100 +{
54101 + struct task_struct *task = current;
54102 + struct acl_subject_label *newacl;
54103 + struct acl_object_label *obj;
54104 + __u32 retmode;
54105 +
54106 + if (unlikely(!(gr_status & GR_READY)))
54107 + return 0;
54108 +
54109 + newacl = chk_subj_label(dentry, mnt, task->role);
54110 +
54111 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54112 + did an exec
54113 + */
54114 + rcu_read_lock();
54115 + read_lock(&tasklist_lock);
54116 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54117 + (task->parent->acl->mode & GR_POVERRIDE))) {
54118 + read_unlock(&tasklist_lock);
54119 + rcu_read_unlock();
54120 + goto skip_check;
54121 + }
54122 + read_unlock(&tasklist_lock);
54123 + rcu_read_unlock();
54124 +
54125 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54126 + !(task->role->roletype & GR_ROLE_GOD) &&
54127 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54128 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54129 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54130 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54131 + else
54132 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54133 + return -EACCES;
54134 + }
54135 +
54136 +skip_check:
54137 +
54138 + obj = chk_obj_label(dentry, mnt, task->acl);
54139 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54140 +
54141 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54142 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54143 + if (obj->nested)
54144 + task->acl = obj->nested;
54145 + else
54146 + task->acl = newacl;
54147 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54148 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54149 +
54150 + task->is_writable = 0;
54151 +
54152 + /* ignore additional mmap checks for processes that are writable
54153 + by the default ACL */
54154 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54155 + if (unlikely(obj->mode & GR_WRITE))
54156 + task->is_writable = 1;
54157 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54158 + if (unlikely(obj->mode & GR_WRITE))
54159 + task->is_writable = 1;
54160 +
54161 + gr_set_proc_res(task);
54162 +
54163 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54164 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54165 +#endif
54166 + return 0;
54167 +}
54168 +
54169 +/* always called with valid inodev ptr */
54170 +static void
54171 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54172 +{
54173 + struct acl_object_label *matchpo;
54174 + struct acl_subject_label *matchps;
54175 + struct acl_subject_label *subj;
54176 + struct acl_role_label *role;
54177 + unsigned int x;
54178 +
54179 + FOR_EACH_ROLE_START(role)
54180 + FOR_EACH_SUBJECT_START(role, subj, x)
54181 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54182 + matchpo->mode |= GR_DELETED;
54183 + FOR_EACH_SUBJECT_END(subj,x)
54184 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54185 + /* nested subjects aren't in the role's subj_hash table */
54186 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54187 + matchpo->mode |= GR_DELETED;
54188 + FOR_EACH_NESTED_SUBJECT_END(subj)
54189 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54190 + matchps->mode |= GR_DELETED;
54191 + FOR_EACH_ROLE_END(role)
54192 +
54193 + inodev->nentry->deleted = 1;
54194 +
54195 + return;
54196 +}
54197 +
54198 +void
54199 +gr_handle_delete(const ino_t ino, const dev_t dev)
54200 +{
54201 + struct inodev_entry *inodev;
54202 +
54203 + if (unlikely(!(gr_status & GR_READY)))
54204 + return;
54205 +
54206 + write_lock(&gr_inode_lock);
54207 + inodev = lookup_inodev_entry(ino, dev);
54208 + if (inodev != NULL)
54209 + do_handle_delete(inodev, ino, dev);
54210 + write_unlock(&gr_inode_lock);
54211 +
54212 + return;
54213 +}
54214 +
54215 +static void
54216 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54217 + const ino_t newinode, const dev_t newdevice,
54218 + struct acl_subject_label *subj)
54219 +{
54220 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54221 + struct acl_object_label *match;
54222 +
54223 + match = subj->obj_hash[index];
54224 +
54225 + while (match && (match->inode != oldinode ||
54226 + match->device != olddevice ||
54227 + !(match->mode & GR_DELETED)))
54228 + match = match->next;
54229 +
54230 + if (match && (match->inode == oldinode)
54231 + && (match->device == olddevice)
54232 + && (match->mode & GR_DELETED)) {
54233 + if (match->prev == NULL) {
54234 + subj->obj_hash[index] = match->next;
54235 + if (match->next != NULL)
54236 + match->next->prev = NULL;
54237 + } else {
54238 + match->prev->next = match->next;
54239 + if (match->next != NULL)
54240 + match->next->prev = match->prev;
54241 + }
54242 + match->prev = NULL;
54243 + match->next = NULL;
54244 + match->inode = newinode;
54245 + match->device = newdevice;
54246 + match->mode &= ~GR_DELETED;
54247 +
54248 + insert_acl_obj_label(match, subj);
54249 + }
54250 +
54251 + return;
54252 +}
54253 +
54254 +static void
54255 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54256 + const ino_t newinode, const dev_t newdevice,
54257 + struct acl_role_label *role)
54258 +{
54259 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54260 + struct acl_subject_label *match;
54261 +
54262 + match = role->subj_hash[index];
54263 +
54264 + while (match && (match->inode != oldinode ||
54265 + match->device != olddevice ||
54266 + !(match->mode & GR_DELETED)))
54267 + match = match->next;
54268 +
54269 + if (match && (match->inode == oldinode)
54270 + && (match->device == olddevice)
54271 + && (match->mode & GR_DELETED)) {
54272 + if (match->prev == NULL) {
54273 + role->subj_hash[index] = match->next;
54274 + if (match->next != NULL)
54275 + match->next->prev = NULL;
54276 + } else {
54277 + match->prev->next = match->next;
54278 + if (match->next != NULL)
54279 + match->next->prev = match->prev;
54280 + }
54281 + match->prev = NULL;
54282 + match->next = NULL;
54283 + match->inode = newinode;
54284 + match->device = newdevice;
54285 + match->mode &= ~GR_DELETED;
54286 +
54287 + insert_acl_subj_label(match, role);
54288 + }
54289 +
54290 + return;
54291 +}
54292 +
54293 +static void
54294 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54295 + const ino_t newinode, const dev_t newdevice)
54296 +{
54297 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54298 + struct inodev_entry *match;
54299 +
54300 + match = inodev_set.i_hash[index];
54301 +
54302 + while (match && (match->nentry->inode != oldinode ||
54303 + match->nentry->device != olddevice || !match->nentry->deleted))
54304 + match = match->next;
54305 +
54306 + if (match && (match->nentry->inode == oldinode)
54307 + && (match->nentry->device == olddevice) &&
54308 + match->nentry->deleted) {
54309 + if (match->prev == NULL) {
54310 + inodev_set.i_hash[index] = match->next;
54311 + if (match->next != NULL)
54312 + match->next->prev = NULL;
54313 + } else {
54314 + match->prev->next = match->next;
54315 + if (match->next != NULL)
54316 + match->next->prev = match->prev;
54317 + }
54318 + match->prev = NULL;
54319 + match->next = NULL;
54320 + match->nentry->inode = newinode;
54321 + match->nentry->device = newdevice;
54322 + match->nentry->deleted = 0;
54323 +
54324 + insert_inodev_entry(match);
54325 + }
54326 +
54327 + return;
54328 +}
54329 +
54330 +static void
54331 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54332 +{
54333 + struct acl_subject_label *subj;
54334 + struct acl_role_label *role;
54335 + unsigned int x;
54336 +
54337 + FOR_EACH_ROLE_START(role)
54338 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54339 +
54340 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54341 + if ((subj->inode == ino) && (subj->device == dev)) {
54342 + subj->inode = ino;
54343 + subj->device = dev;
54344 + }
54345 + /* nested subjects aren't in the role's subj_hash table */
54346 + update_acl_obj_label(matchn->inode, matchn->device,
54347 + ino, dev, subj);
54348 + FOR_EACH_NESTED_SUBJECT_END(subj)
54349 + FOR_EACH_SUBJECT_START(role, subj, x)
54350 + update_acl_obj_label(matchn->inode, matchn->device,
54351 + ino, dev, subj);
54352 + FOR_EACH_SUBJECT_END(subj,x)
54353 + FOR_EACH_ROLE_END(role)
54354 +
54355 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54356 +
54357 + return;
54358 +}
54359 +
54360 +static void
54361 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54362 + const struct vfsmount *mnt)
54363 +{
54364 + ino_t ino = dentry->d_inode->i_ino;
54365 + dev_t dev = __get_dev(dentry);
54366 +
54367 + __do_handle_create(matchn, ino, dev);
54368 +
54369 + return;
54370 +}
54371 +
54372 +void
54373 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54374 +{
54375 + struct name_entry *matchn;
54376 +
54377 + if (unlikely(!(gr_status & GR_READY)))
54378 + return;
54379 +
54380 + preempt_disable();
54381 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54382 +
54383 + if (unlikely((unsigned long)matchn)) {
54384 + write_lock(&gr_inode_lock);
54385 + do_handle_create(matchn, dentry, mnt);
54386 + write_unlock(&gr_inode_lock);
54387 + }
54388 + preempt_enable();
54389 +
54390 + return;
54391 +}
54392 +
54393 +void
54394 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54395 +{
54396 + struct name_entry *matchn;
54397 +
54398 + if (unlikely(!(gr_status & GR_READY)))
54399 + return;
54400 +
54401 + preempt_disable();
54402 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54403 +
54404 + if (unlikely((unsigned long)matchn)) {
54405 + write_lock(&gr_inode_lock);
54406 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54407 + write_unlock(&gr_inode_lock);
54408 + }
54409 + preempt_enable();
54410 +
54411 + return;
54412 +}
54413 +
54414 +void
54415 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54416 + struct dentry *old_dentry,
54417 + struct dentry *new_dentry,
54418 + struct vfsmount *mnt, const __u8 replace)
54419 +{
54420 + struct name_entry *matchn;
54421 + struct inodev_entry *inodev;
54422 + struct inode *inode = new_dentry->d_inode;
54423 + ino_t old_ino = old_dentry->d_inode->i_ino;
54424 + dev_t old_dev = __get_dev(old_dentry);
54425 +
54426 + /* vfs_rename swaps the name and parent link for old_dentry and
54427 + new_dentry
54428 + at this point, old_dentry has the new name, parent link, and inode
54429 + for the renamed file
54430 + if a file is being replaced by a rename, new_dentry has the inode
54431 + and name for the replaced file
54432 + */
54433 +
54434 + if (unlikely(!(gr_status & GR_READY)))
54435 + return;
54436 +
54437 + preempt_disable();
54438 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54439 +
54440 + /* we wouldn't have to check d_inode if it weren't for
54441 + NFS silly-renaming
54442 + */
54443 +
54444 + write_lock(&gr_inode_lock);
54445 + if (unlikely(replace && inode)) {
54446 + ino_t new_ino = inode->i_ino;
54447 + dev_t new_dev = __get_dev(new_dentry);
54448 +
54449 + inodev = lookup_inodev_entry(new_ino, new_dev);
54450 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54451 + do_handle_delete(inodev, new_ino, new_dev);
54452 + }
54453 +
54454 + inodev = lookup_inodev_entry(old_ino, old_dev);
54455 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54456 + do_handle_delete(inodev, old_ino, old_dev);
54457 +
54458 + if (unlikely((unsigned long)matchn))
54459 + do_handle_create(matchn, old_dentry, mnt);
54460 +
54461 + write_unlock(&gr_inode_lock);
54462 + preempt_enable();
54463 +
54464 + return;
54465 +}
54466 +
54467 +static int
54468 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54469 + unsigned char **sum)
54470 +{
54471 + struct acl_role_label *r;
54472 + struct role_allowed_ip *ipp;
54473 + struct role_transition *trans;
54474 + unsigned int i;
54475 + int found = 0;
54476 + u32 curr_ip = current->signal->curr_ip;
54477 +
54478 + current->signal->saved_ip = curr_ip;
54479 +
54480 + /* check transition table */
54481 +
54482 + for (trans = current->role->transitions; trans; trans = trans->next) {
54483 + if (!strcmp(rolename, trans->rolename)) {
54484 + found = 1;
54485 + break;
54486 + }
54487 + }
54488 +
54489 + if (!found)
54490 + return 0;
54491 +
54492 + /* handle special roles that do not require authentication
54493 + and check ip */
54494 +
54495 + FOR_EACH_ROLE_START(r)
54496 + if (!strcmp(rolename, r->rolename) &&
54497 + (r->roletype & GR_ROLE_SPECIAL)) {
54498 + found = 0;
54499 + if (r->allowed_ips != NULL) {
54500 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54501 + if ((ntohl(curr_ip) & ipp->netmask) ==
54502 + (ntohl(ipp->addr) & ipp->netmask))
54503 + found = 1;
54504 + }
54505 + } else
54506 + found = 2;
54507 + if (!found)
54508 + return 0;
54509 +
54510 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54511 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54512 + *salt = NULL;
54513 + *sum = NULL;
54514 + return 1;
54515 + }
54516 + }
54517 + FOR_EACH_ROLE_END(r)
54518 +
54519 + for (i = 0; i < num_sprole_pws; i++) {
54520 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54521 + *salt = acl_special_roles[i]->salt;
54522 + *sum = acl_special_roles[i]->sum;
54523 + return 1;
54524 + }
54525 + }
54526 +
54527 + return 0;
54528 +}
54529 +
54530 +static void
54531 +assign_special_role(char *rolename)
54532 +{
54533 + struct acl_object_label *obj;
54534 + struct acl_role_label *r;
54535 + struct acl_role_label *assigned = NULL;
54536 + struct task_struct *tsk;
54537 + struct file *filp;
54538 +
54539 + FOR_EACH_ROLE_START(r)
54540 + if (!strcmp(rolename, r->rolename) &&
54541 + (r->roletype & GR_ROLE_SPECIAL)) {
54542 + assigned = r;
54543 + break;
54544 + }
54545 + FOR_EACH_ROLE_END(r)
54546 +
54547 + if (!assigned)
54548 + return;
54549 +
54550 + read_lock(&tasklist_lock);
54551 + read_lock(&grsec_exec_file_lock);
54552 +
54553 + tsk = current->real_parent;
54554 + if (tsk == NULL)
54555 + goto out_unlock;
54556 +
54557 + filp = tsk->exec_file;
54558 + if (filp == NULL)
54559 + goto out_unlock;
54560 +
54561 + tsk->is_writable = 0;
54562 +
54563 + tsk->acl_sp_role = 1;
54564 + tsk->acl_role_id = ++acl_sp_role_value;
54565 + tsk->role = assigned;
54566 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54567 +
54568 + /* ignore additional mmap checks for processes that are writable
54569 + by the default ACL */
54570 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54571 + if (unlikely(obj->mode & GR_WRITE))
54572 + tsk->is_writable = 1;
54573 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54574 + if (unlikely(obj->mode & GR_WRITE))
54575 + tsk->is_writable = 1;
54576 +
54577 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54578 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54579 +#endif
54580 +
54581 +out_unlock:
54582 + read_unlock(&grsec_exec_file_lock);
54583 + read_unlock(&tasklist_lock);
54584 + return;
54585 +}
54586 +
54587 +int gr_check_secure_terminal(struct task_struct *task)
54588 +{
54589 + struct task_struct *p, *p2, *p3;
54590 + struct files_struct *files;
54591 + struct fdtable *fdt;
54592 + struct file *our_file = NULL, *file;
54593 + int i;
54594 +
54595 + if (task->signal->tty == NULL)
54596 + return 1;
54597 +
54598 + files = get_files_struct(task);
54599 + if (files != NULL) {
54600 + rcu_read_lock();
54601 + fdt = files_fdtable(files);
54602 + for (i=0; i < fdt->max_fds; i++) {
54603 + file = fcheck_files(files, i);
54604 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54605 + get_file(file);
54606 + our_file = file;
54607 + }
54608 + }
54609 + rcu_read_unlock();
54610 + put_files_struct(files);
54611 + }
54612 +
54613 + if (our_file == NULL)
54614 + return 1;
54615 +
54616 + read_lock(&tasklist_lock);
54617 + do_each_thread(p2, p) {
54618 + files = get_files_struct(p);
54619 + if (files == NULL ||
54620 + (p->signal && p->signal->tty == task->signal->tty)) {
54621 + if (files != NULL)
54622 + put_files_struct(files);
54623 + continue;
54624 + }
54625 + rcu_read_lock();
54626 + fdt = files_fdtable(files);
54627 + for (i=0; i < fdt->max_fds; i++) {
54628 + file = fcheck_files(files, i);
54629 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54630 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54631 + p3 = task;
54632 + while (p3->pid > 0) {
54633 + if (p3 == p)
54634 + break;
54635 + p3 = p3->real_parent;
54636 + }
54637 + if (p3 == p)
54638 + break;
54639 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54640 + gr_handle_alertkill(p);
54641 + rcu_read_unlock();
54642 + put_files_struct(files);
54643 + read_unlock(&tasklist_lock);
54644 + fput(our_file);
54645 + return 0;
54646 + }
54647 + }
54648 + rcu_read_unlock();
54649 + put_files_struct(files);
54650 + } while_each_thread(p2, p);
54651 + read_unlock(&tasklist_lock);
54652 +
54653 + fput(our_file);
54654 + return 1;
54655 +}
54656 +
54657 +static int gr_rbac_disable(void *unused)
54658 +{
54659 + pax_open_kernel();
54660 + gr_status &= ~GR_READY;
54661 + pax_close_kernel();
54662 +
54663 + return 0;
54664 +}
54665 +
54666 +ssize_t
54667 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54668 +{
54669 + struct gr_arg_wrapper uwrap;
54670 + unsigned char *sprole_salt = NULL;
54671 + unsigned char *sprole_sum = NULL;
54672 + int error = sizeof (struct gr_arg_wrapper);
54673 + int error2 = 0;
54674 +
54675 + mutex_lock(&gr_dev_mutex);
54676 +
54677 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54678 + error = -EPERM;
54679 + goto out;
54680 + }
54681 +
54682 + if (count != sizeof (struct gr_arg_wrapper)) {
54683 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54684 + error = -EINVAL;
54685 + goto out;
54686 + }
54687 +
54688 +
54689 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54690 + gr_auth_expires = 0;
54691 + gr_auth_attempts = 0;
54692 + }
54693 +
54694 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54695 + error = -EFAULT;
54696 + goto out;
54697 + }
54698 +
54699 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54700 + error = -EINVAL;
54701 + goto out;
54702 + }
54703 +
54704 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54705 + error = -EFAULT;
54706 + goto out;
54707 + }
54708 +
54709 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54710 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54711 + time_after(gr_auth_expires, get_seconds())) {
54712 + error = -EBUSY;
54713 + goto out;
54714 + }
54715 +
54716 + /* if non-root trying to do anything other than use a special role,
54717 + do not attempt authentication, do not count towards authentication
54718 + locking
54719 + */
54720 +
54721 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54722 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54723 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54724 + error = -EPERM;
54725 + goto out;
54726 + }
54727 +
54728 + /* ensure pw and special role name are null terminated */
54729 +
54730 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54731 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54732 +
54733 + /* Okay.
54734 + * We have our enough of the argument structure..(we have yet
54735 + * to copy_from_user the tables themselves) . Copy the tables
54736 + * only if we need them, i.e. for loading operations. */
54737 +
54738 + switch (gr_usermode->mode) {
54739 + case GR_STATUS:
54740 + if (gr_status & GR_READY) {
54741 + error = 1;
54742 + if (!gr_check_secure_terminal(current))
54743 + error = 3;
54744 + } else
54745 + error = 2;
54746 + goto out;
54747 + case GR_SHUTDOWN:
54748 + if ((gr_status & GR_READY)
54749 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54750 + stop_machine(gr_rbac_disable, NULL, NULL);
54751 + free_variables();
54752 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54753 + memset(gr_system_salt, 0, GR_SALT_LEN);
54754 + memset(gr_system_sum, 0, GR_SHA_LEN);
54755 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54756 + } else if (gr_status & GR_READY) {
54757 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54758 + error = -EPERM;
54759 + } else {
54760 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54761 + error = -EAGAIN;
54762 + }
54763 + break;
54764 + case GR_ENABLE:
54765 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54766 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54767 + else {
54768 + if (gr_status & GR_READY)
54769 + error = -EAGAIN;
54770 + else
54771 + error = error2;
54772 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54773 + }
54774 + break;
54775 + case GR_RELOAD:
54776 + if (!(gr_status & GR_READY)) {
54777 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54778 + error = -EAGAIN;
54779 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54780 + stop_machine(gr_rbac_disable, NULL, NULL);
54781 + free_variables();
54782 + error2 = gracl_init(gr_usermode);
54783 + if (!error2)
54784 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54785 + else {
54786 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54787 + error = error2;
54788 + }
54789 + } else {
54790 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54791 + error = -EPERM;
54792 + }
54793 + break;
54794 + case GR_SEGVMOD:
54795 + if (unlikely(!(gr_status & GR_READY))) {
54796 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54797 + error = -EAGAIN;
54798 + break;
54799 + }
54800 +
54801 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54802 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54803 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54804 + struct acl_subject_label *segvacl;
54805 + segvacl =
54806 + lookup_acl_subj_label(gr_usermode->segv_inode,
54807 + gr_usermode->segv_device,
54808 + current->role);
54809 + if (segvacl) {
54810 + segvacl->crashes = 0;
54811 + segvacl->expires = 0;
54812 + }
54813 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54814 + gr_remove_uid(gr_usermode->segv_uid);
54815 + }
54816 + } else {
54817 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54818 + error = -EPERM;
54819 + }
54820 + break;
54821 + case GR_SPROLE:
54822 + case GR_SPROLEPAM:
54823 + if (unlikely(!(gr_status & GR_READY))) {
54824 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54825 + error = -EAGAIN;
54826 + break;
54827 + }
54828 +
54829 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54830 + current->role->expires = 0;
54831 + current->role->auth_attempts = 0;
54832 + }
54833 +
54834 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54835 + time_after(current->role->expires, get_seconds())) {
54836 + error = -EBUSY;
54837 + goto out;
54838 + }
54839 +
54840 + if (lookup_special_role_auth
54841 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54842 + && ((!sprole_salt && !sprole_sum)
54843 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54844 + char *p = "";
54845 + assign_special_role(gr_usermode->sp_role);
54846 + read_lock(&tasklist_lock);
54847 + if (current->real_parent)
54848 + p = current->real_parent->role->rolename;
54849 + read_unlock(&tasklist_lock);
54850 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54851 + p, acl_sp_role_value);
54852 + } else {
54853 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54854 + error = -EPERM;
54855 + if(!(current->role->auth_attempts++))
54856 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54857 +
54858 + goto out;
54859 + }
54860 + break;
54861 + case GR_UNSPROLE:
54862 + if (unlikely(!(gr_status & GR_READY))) {
54863 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54864 + error = -EAGAIN;
54865 + break;
54866 + }
54867 +
54868 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54869 + char *p = "";
54870 + int i = 0;
54871 +
54872 + read_lock(&tasklist_lock);
54873 + if (current->real_parent) {
54874 + p = current->real_parent->role->rolename;
54875 + i = current->real_parent->acl_role_id;
54876 + }
54877 + read_unlock(&tasklist_lock);
54878 +
54879 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54880 + gr_set_acls(1);
54881 + } else {
54882 + error = -EPERM;
54883 + goto out;
54884 + }
54885 + break;
54886 + default:
54887 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54888 + error = -EINVAL;
54889 + break;
54890 + }
54891 +
54892 + if (error != -EPERM)
54893 + goto out;
54894 +
54895 + if(!(gr_auth_attempts++))
54896 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54897 +
54898 + out:
54899 + mutex_unlock(&gr_dev_mutex);
54900 + return error;
54901 +}
54902 +
54903 +/* must be called with
54904 + rcu_read_lock();
54905 + read_lock(&tasklist_lock);
54906 + read_lock(&grsec_exec_file_lock);
54907 +*/
54908 +int gr_apply_subject_to_task(struct task_struct *task)
54909 +{
54910 + struct acl_object_label *obj;
54911 + char *tmpname;
54912 + struct acl_subject_label *tmpsubj;
54913 + struct file *filp;
54914 + struct name_entry *nmatch;
54915 +
54916 + filp = task->exec_file;
54917 + if (filp == NULL)
54918 + return 0;
54919 +
54920 + /* the following is to apply the correct subject
54921 + on binaries running when the RBAC system
54922 + is enabled, when the binaries have been
54923 + replaced or deleted since their execution
54924 + -----
54925 + when the RBAC system starts, the inode/dev
54926 + from exec_file will be one the RBAC system
54927 + is unaware of. It only knows the inode/dev
54928 + of the present file on disk, or the absence
54929 + of it.
54930 + */
54931 + preempt_disable();
54932 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54933 +
54934 + nmatch = lookup_name_entry(tmpname);
54935 + preempt_enable();
54936 + tmpsubj = NULL;
54937 + if (nmatch) {
54938 + if (nmatch->deleted)
54939 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54940 + else
54941 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54942 + if (tmpsubj != NULL)
54943 + task->acl = tmpsubj;
54944 + }
54945 + if (tmpsubj == NULL)
54946 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54947 + task->role);
54948 + if (task->acl) {
54949 + task->is_writable = 0;
54950 + /* ignore additional mmap checks for processes that are writable
54951 + by the default ACL */
54952 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54953 + if (unlikely(obj->mode & GR_WRITE))
54954 + task->is_writable = 1;
54955 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54956 + if (unlikely(obj->mode & GR_WRITE))
54957 + task->is_writable = 1;
54958 +
54959 + gr_set_proc_res(task);
54960 +
54961 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54962 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54963 +#endif
54964 + } else {
54965 + return 1;
54966 + }
54967 +
54968 + return 0;
54969 +}
54970 +
54971 +int
54972 +gr_set_acls(const int type)
54973 +{
54974 + struct task_struct *task, *task2;
54975 + struct acl_role_label *role = current->role;
54976 + __u16 acl_role_id = current->acl_role_id;
54977 + const struct cred *cred;
54978 + int ret;
54979 +
54980 + rcu_read_lock();
54981 + read_lock(&tasklist_lock);
54982 + read_lock(&grsec_exec_file_lock);
54983 + do_each_thread(task2, task) {
54984 + /* check to see if we're called from the exit handler,
54985 + if so, only replace ACLs that have inherited the admin
54986 + ACL */
54987 +
54988 + if (type && (task->role != role ||
54989 + task->acl_role_id != acl_role_id))
54990 + continue;
54991 +
54992 + task->acl_role_id = 0;
54993 + task->acl_sp_role = 0;
54994 +
54995 + if (task->exec_file) {
54996 + cred = __task_cred(task);
54997 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54998 + ret = gr_apply_subject_to_task(task);
54999 + if (ret) {
55000 + read_unlock(&grsec_exec_file_lock);
55001 + read_unlock(&tasklist_lock);
55002 + rcu_read_unlock();
55003 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55004 + return ret;
55005 + }
55006 + } else {
55007 + // it's a kernel process
55008 + task->role = kernel_role;
55009 + task->acl = kernel_role->root_label;
55010 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55011 + task->acl->mode &= ~GR_PROCFIND;
55012 +#endif
55013 + }
55014 + } while_each_thread(task2, task);
55015 + read_unlock(&grsec_exec_file_lock);
55016 + read_unlock(&tasklist_lock);
55017 + rcu_read_unlock();
55018 +
55019 + return 0;
55020 +}
55021 +
55022 +void
55023 +gr_learn_resource(const struct task_struct *task,
55024 + const int res, const unsigned long wanted, const int gt)
55025 +{
55026 + struct acl_subject_label *acl;
55027 + const struct cred *cred;
55028 +
55029 + if (unlikely((gr_status & GR_READY) &&
55030 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55031 + goto skip_reslog;
55032 +
55033 +#ifdef CONFIG_GRKERNSEC_RESLOG
55034 + gr_log_resource(task, res, wanted, gt);
55035 +#endif
55036 + skip_reslog:
55037 +
55038 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55039 + return;
55040 +
55041 + acl = task->acl;
55042 +
55043 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55044 + !(acl->resmask & (1 << (unsigned short) res))))
55045 + return;
55046 +
55047 + if (wanted >= acl->res[res].rlim_cur) {
55048 + unsigned long res_add;
55049 +
55050 + res_add = wanted;
55051 + switch (res) {
55052 + case RLIMIT_CPU:
55053 + res_add += GR_RLIM_CPU_BUMP;
55054 + break;
55055 + case RLIMIT_FSIZE:
55056 + res_add += GR_RLIM_FSIZE_BUMP;
55057 + break;
55058 + case RLIMIT_DATA:
55059 + res_add += GR_RLIM_DATA_BUMP;
55060 + break;
55061 + case RLIMIT_STACK:
55062 + res_add += GR_RLIM_STACK_BUMP;
55063 + break;
55064 + case RLIMIT_CORE:
55065 + res_add += GR_RLIM_CORE_BUMP;
55066 + break;
55067 + case RLIMIT_RSS:
55068 + res_add += GR_RLIM_RSS_BUMP;
55069 + break;
55070 + case RLIMIT_NPROC:
55071 + res_add += GR_RLIM_NPROC_BUMP;
55072 + break;
55073 + case RLIMIT_NOFILE:
55074 + res_add += GR_RLIM_NOFILE_BUMP;
55075 + break;
55076 + case RLIMIT_MEMLOCK:
55077 + res_add += GR_RLIM_MEMLOCK_BUMP;
55078 + break;
55079 + case RLIMIT_AS:
55080 + res_add += GR_RLIM_AS_BUMP;
55081 + break;
55082 + case RLIMIT_LOCKS:
55083 + res_add += GR_RLIM_LOCKS_BUMP;
55084 + break;
55085 + case RLIMIT_SIGPENDING:
55086 + res_add += GR_RLIM_SIGPENDING_BUMP;
55087 + break;
55088 + case RLIMIT_MSGQUEUE:
55089 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55090 + break;
55091 + case RLIMIT_NICE:
55092 + res_add += GR_RLIM_NICE_BUMP;
55093 + break;
55094 + case RLIMIT_RTPRIO:
55095 + res_add += GR_RLIM_RTPRIO_BUMP;
55096 + break;
55097 + case RLIMIT_RTTIME:
55098 + res_add += GR_RLIM_RTTIME_BUMP;
55099 + break;
55100 + }
55101 +
55102 + acl->res[res].rlim_cur = res_add;
55103 +
55104 + if (wanted > acl->res[res].rlim_max)
55105 + acl->res[res].rlim_max = res_add;
55106 +
55107 + /* only log the subject filename, since resource logging is supported for
55108 + single-subject learning only */
55109 + rcu_read_lock();
55110 + cred = __task_cred(task);
55111 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55112 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55113 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55114 + "", (unsigned long) res, &task->signal->saved_ip);
55115 + rcu_read_unlock();
55116 + }
55117 +
55118 + return;
55119 +}
55120 +
55121 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55122 +void
55123 +pax_set_initial_flags(struct linux_binprm *bprm)
55124 +{
55125 + struct task_struct *task = current;
55126 + struct acl_subject_label *proc;
55127 + unsigned long flags;
55128 +
55129 + if (unlikely(!(gr_status & GR_READY)))
55130 + return;
55131 +
55132 + flags = pax_get_flags(task);
55133 +
55134 + proc = task->acl;
55135 +
55136 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55137 + flags &= ~MF_PAX_PAGEEXEC;
55138 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55139 + flags &= ~MF_PAX_SEGMEXEC;
55140 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55141 + flags &= ~MF_PAX_RANDMMAP;
55142 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55143 + flags &= ~MF_PAX_EMUTRAMP;
55144 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55145 + flags &= ~MF_PAX_MPROTECT;
55146 +
55147 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55148 + flags |= MF_PAX_PAGEEXEC;
55149 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55150 + flags |= MF_PAX_SEGMEXEC;
55151 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55152 + flags |= MF_PAX_RANDMMAP;
55153 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55154 + flags |= MF_PAX_EMUTRAMP;
55155 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55156 + flags |= MF_PAX_MPROTECT;
55157 +
55158 + pax_set_flags(task, flags);
55159 +
55160 + return;
55161 +}
55162 +#endif
55163 +
55164 +int
55165 +gr_handle_proc_ptrace(struct task_struct *task)
55166 +{
55167 + struct file *filp;
55168 + struct task_struct *tmp = task;
55169 + struct task_struct *curtemp = current;
55170 + __u32 retmode;
55171 +
55172 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55173 + if (unlikely(!(gr_status & GR_READY)))
55174 + return 0;
55175 +#endif
55176 +
55177 + read_lock(&tasklist_lock);
55178 + read_lock(&grsec_exec_file_lock);
55179 + filp = task->exec_file;
55180 +
55181 + while (tmp->pid > 0) {
55182 + if (tmp == curtemp)
55183 + break;
55184 + tmp = tmp->real_parent;
55185 + }
55186 +
55187 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55188 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55189 + read_unlock(&grsec_exec_file_lock);
55190 + read_unlock(&tasklist_lock);
55191 + return 1;
55192 + }
55193 +
55194 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55195 + if (!(gr_status & GR_READY)) {
55196 + read_unlock(&grsec_exec_file_lock);
55197 + read_unlock(&tasklist_lock);
55198 + return 0;
55199 + }
55200 +#endif
55201 +
55202 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55203 + read_unlock(&grsec_exec_file_lock);
55204 + read_unlock(&tasklist_lock);
55205 +
55206 + if (retmode & GR_NOPTRACE)
55207 + return 1;
55208 +
55209 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55210 + && (current->acl != task->acl || (current->acl != current->role->root_label
55211 + && current->pid != task->pid)))
55212 + return 1;
55213 +
55214 + return 0;
55215 +}
55216 +
55217 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55218 +{
55219 + if (unlikely(!(gr_status & GR_READY)))
55220 + return;
55221 +
55222 + if (!(current->role->roletype & GR_ROLE_GOD))
55223 + return;
55224 +
55225 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55226 + p->role->rolename, gr_task_roletype_to_char(p),
55227 + p->acl->filename);
55228 +}
55229 +
55230 +int
55231 +gr_handle_ptrace(struct task_struct *task, const long request)
55232 +{
55233 + struct task_struct *tmp = task;
55234 + struct task_struct *curtemp = current;
55235 + __u32 retmode;
55236 +
55237 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55238 + if (unlikely(!(gr_status & GR_READY)))
55239 + return 0;
55240 +#endif
55241 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55242 + read_lock(&tasklist_lock);
55243 + while (tmp->pid > 0) {
55244 + if (tmp == curtemp)
55245 + break;
55246 + tmp = tmp->real_parent;
55247 + }
55248 +
55249 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55250 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55251 + read_unlock(&tasklist_lock);
55252 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55253 + return 1;
55254 + }
55255 + read_unlock(&tasklist_lock);
55256 + }
55257 +
55258 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55259 + if (!(gr_status & GR_READY))
55260 + return 0;
55261 +#endif
55262 +
55263 + read_lock(&grsec_exec_file_lock);
55264 + if (unlikely(!task->exec_file)) {
55265 + read_unlock(&grsec_exec_file_lock);
55266 + return 0;
55267 + }
55268 +
55269 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55270 + read_unlock(&grsec_exec_file_lock);
55271 +
55272 + if (retmode & GR_NOPTRACE) {
55273 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55274 + return 1;
55275 + }
55276 +
55277 + if (retmode & GR_PTRACERD) {
55278 + switch (request) {
55279 + case PTRACE_SEIZE:
55280 + case PTRACE_POKETEXT:
55281 + case PTRACE_POKEDATA:
55282 + case PTRACE_POKEUSR:
55283 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55284 + case PTRACE_SETREGS:
55285 + case PTRACE_SETFPREGS:
55286 +#endif
55287 +#ifdef CONFIG_X86
55288 + case PTRACE_SETFPXREGS:
55289 +#endif
55290 +#ifdef CONFIG_ALTIVEC
55291 + case PTRACE_SETVRREGS:
55292 +#endif
55293 + return 1;
55294 + default:
55295 + return 0;
55296 + }
55297 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55298 + !(current->role->roletype & GR_ROLE_GOD) &&
55299 + (current->acl != task->acl)) {
55300 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55301 + return 1;
55302 + }
55303 +
55304 + return 0;
55305 +}
55306 +
55307 +static int is_writable_mmap(const struct file *filp)
55308 +{
55309 + struct task_struct *task = current;
55310 + struct acl_object_label *obj, *obj2;
55311 +
55312 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55313 + !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))) {
55314 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55315 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55316 + task->role->root_label);
55317 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55318 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55319 + return 1;
55320 + }
55321 + }
55322 + return 0;
55323 +}
55324 +
55325 +int
55326 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55327 +{
55328 + __u32 mode;
55329 +
55330 + if (unlikely(!file || !(prot & PROT_EXEC)))
55331 + return 1;
55332 +
55333 + if (is_writable_mmap(file))
55334 + return 0;
55335 +
55336 + mode =
55337 + gr_search_file(file->f_path.dentry,
55338 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55339 + file->f_path.mnt);
55340 +
55341 + if (!gr_tpe_allow(file))
55342 + return 0;
55343 +
55344 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55345 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55346 + return 0;
55347 + } else if (unlikely(!(mode & GR_EXEC))) {
55348 + return 0;
55349 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55350 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55351 + return 1;
55352 + }
55353 +
55354 + return 1;
55355 +}
55356 +
55357 +int
55358 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55359 +{
55360 + __u32 mode;
55361 +
55362 + if (unlikely(!file || !(prot & PROT_EXEC)))
55363 + return 1;
55364 +
55365 + if (is_writable_mmap(file))
55366 + return 0;
55367 +
55368 + mode =
55369 + gr_search_file(file->f_path.dentry,
55370 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55371 + file->f_path.mnt);
55372 +
55373 + if (!gr_tpe_allow(file))
55374 + return 0;
55375 +
55376 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55377 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55378 + return 0;
55379 + } else if (unlikely(!(mode & GR_EXEC))) {
55380 + return 0;
55381 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55382 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55383 + return 1;
55384 + }
55385 +
55386 + return 1;
55387 +}
55388 +
55389 +void
55390 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55391 +{
55392 + unsigned long runtime;
55393 + unsigned long cputime;
55394 + unsigned int wday, cday;
55395 + __u8 whr, chr;
55396 + __u8 wmin, cmin;
55397 + __u8 wsec, csec;
55398 + struct timespec timeval;
55399 +
55400 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55401 + !(task->acl->mode & GR_PROCACCT)))
55402 + return;
55403 +
55404 + do_posix_clock_monotonic_gettime(&timeval);
55405 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55406 + wday = runtime / (3600 * 24);
55407 + runtime -= wday * (3600 * 24);
55408 + whr = runtime / 3600;
55409 + runtime -= whr * 3600;
55410 + wmin = runtime / 60;
55411 + runtime -= wmin * 60;
55412 + wsec = runtime;
55413 +
55414 + cputime = (task->utime + task->stime) / HZ;
55415 + cday = cputime / (3600 * 24);
55416 + cputime -= cday * (3600 * 24);
55417 + chr = cputime / 3600;
55418 + cputime -= chr * 3600;
55419 + cmin = cputime / 60;
55420 + cputime -= cmin * 60;
55421 + csec = cputime;
55422 +
55423 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55424 +
55425 + return;
55426 +}
55427 +
55428 +void gr_set_kernel_label(struct task_struct *task)
55429 +{
55430 + if (gr_status & GR_READY) {
55431 + task->role = kernel_role;
55432 + task->acl = kernel_role->root_label;
55433 + }
55434 + return;
55435 +}
55436 +
55437 +#ifdef CONFIG_TASKSTATS
55438 +int gr_is_taskstats_denied(int pid)
55439 +{
55440 + struct task_struct *task;
55441 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55442 + const struct cred *cred;
55443 +#endif
55444 + int ret = 0;
55445 +
55446 + /* restrict taskstats viewing to un-chrooted root users
55447 + who have the 'view' subject flag if the RBAC system is enabled
55448 + */
55449 +
55450 + rcu_read_lock();
55451 + read_lock(&tasklist_lock);
55452 + task = find_task_by_vpid(pid);
55453 + if (task) {
55454 +#ifdef CONFIG_GRKERNSEC_CHROOT
55455 + if (proc_is_chrooted(task))
55456 + ret = -EACCES;
55457 +#endif
55458 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55459 + cred = __task_cred(task);
55460 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55461 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55462 + ret = -EACCES;
55463 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55464 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55465 + ret = -EACCES;
55466 +#endif
55467 +#endif
55468 + if (gr_status & GR_READY) {
55469 + if (!(task->acl->mode & GR_VIEW))
55470 + ret = -EACCES;
55471 + }
55472 + } else
55473 + ret = -ENOENT;
55474 +
55475 + read_unlock(&tasklist_lock);
55476 + rcu_read_unlock();
55477 +
55478 + return ret;
55479 +}
55480 +#endif
55481 +
55482 +/* AUXV entries are filled via a descendant of search_binary_handler
55483 + after we've already applied the subject for the target
55484 +*/
55485 +int gr_acl_enable_at_secure(void)
55486 +{
55487 + if (unlikely(!(gr_status & GR_READY)))
55488 + return 0;
55489 +
55490 + if (current->acl->mode & GR_ATSECURE)
55491 + return 1;
55492 +
55493 + return 0;
55494 +}
55495 +
55496 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55497 +{
55498 + struct task_struct *task = current;
55499 + struct dentry *dentry = file->f_path.dentry;
55500 + struct vfsmount *mnt = file->f_path.mnt;
55501 + struct acl_object_label *obj, *tmp;
55502 + struct acl_subject_label *subj;
55503 + unsigned int bufsize;
55504 + int is_not_root;
55505 + char *path;
55506 + dev_t dev = __get_dev(dentry);
55507 +
55508 + if (unlikely(!(gr_status & GR_READY)))
55509 + return 1;
55510 +
55511 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55512 + return 1;
55513 +
55514 + /* ignore Eric Biederman */
55515 + if (IS_PRIVATE(dentry->d_inode))
55516 + return 1;
55517 +
55518 + subj = task->acl;
55519 + read_lock(&gr_inode_lock);
55520 + do {
55521 + obj = lookup_acl_obj_label(ino, dev, subj);
55522 + if (obj != NULL) {
55523 + read_unlock(&gr_inode_lock);
55524 + return (obj->mode & GR_FIND) ? 1 : 0;
55525 + }
55526 + } while ((subj = subj->parent_subject));
55527 + read_unlock(&gr_inode_lock);
55528 +
55529 + /* this is purely an optimization since we're looking for an object
55530 + for the directory we're doing a readdir on
55531 + if it's possible for any globbed object to match the entry we're
55532 + filling into the directory, then the object we find here will be
55533 + an anchor point with attached globbed objects
55534 + */
55535 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55536 + if (obj->globbed == NULL)
55537 + return (obj->mode & GR_FIND) ? 1 : 0;
55538 +
55539 + is_not_root = ((obj->filename[0] == '/') &&
55540 + (obj->filename[1] == '\0')) ? 0 : 1;
55541 + bufsize = PAGE_SIZE - namelen - is_not_root;
55542 +
55543 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55544 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55545 + return 1;
55546 +
55547 + preempt_disable();
55548 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55549 + bufsize);
55550 +
55551 + bufsize = strlen(path);
55552 +
55553 + /* if base is "/", don't append an additional slash */
55554 + if (is_not_root)
55555 + *(path + bufsize) = '/';
55556 + memcpy(path + bufsize + is_not_root, name, namelen);
55557 + *(path + bufsize + namelen + is_not_root) = '\0';
55558 +
55559 + tmp = obj->globbed;
55560 + while (tmp) {
55561 + if (!glob_match(tmp->filename, path)) {
55562 + preempt_enable();
55563 + return (tmp->mode & GR_FIND) ? 1 : 0;
55564 + }
55565 + tmp = tmp->next;
55566 + }
55567 + preempt_enable();
55568 + return (obj->mode & GR_FIND) ? 1 : 0;
55569 +}
55570 +
55571 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55572 +EXPORT_SYMBOL(gr_acl_is_enabled);
55573 +#endif
55574 +EXPORT_SYMBOL(gr_learn_resource);
55575 +EXPORT_SYMBOL(gr_set_kernel_label);
55576 +#ifdef CONFIG_SECURITY
55577 +EXPORT_SYMBOL(gr_check_user_change);
55578 +EXPORT_SYMBOL(gr_check_group_change);
55579 +#endif
55580 +
55581 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55582 new file mode 100644
55583 index 0000000..34fefda
55584 --- /dev/null
55585 +++ b/grsecurity/gracl_alloc.c
55586 @@ -0,0 +1,105 @@
55587 +#include <linux/kernel.h>
55588 +#include <linux/mm.h>
55589 +#include <linux/slab.h>
55590 +#include <linux/vmalloc.h>
55591 +#include <linux/gracl.h>
55592 +#include <linux/grsecurity.h>
55593 +
55594 +static unsigned long alloc_stack_next = 1;
55595 +static unsigned long alloc_stack_size = 1;
55596 +static void **alloc_stack;
55597 +
55598 +static __inline__ int
55599 +alloc_pop(void)
55600 +{
55601 + if (alloc_stack_next == 1)
55602 + return 0;
55603 +
55604 + kfree(alloc_stack[alloc_stack_next - 2]);
55605 +
55606 + alloc_stack_next--;
55607 +
55608 + return 1;
55609 +}
55610 +
55611 +static __inline__ int
55612 +alloc_push(void *buf)
55613 +{
55614 + if (alloc_stack_next >= alloc_stack_size)
55615 + return 1;
55616 +
55617 + alloc_stack[alloc_stack_next - 1] = buf;
55618 +
55619 + alloc_stack_next++;
55620 +
55621 + return 0;
55622 +}
55623 +
55624 +void *
55625 +acl_alloc(unsigned long len)
55626 +{
55627 + void *ret = NULL;
55628 +
55629 + if (!len || len > PAGE_SIZE)
55630 + goto out;
55631 +
55632 + ret = kmalloc(len, GFP_KERNEL);
55633 +
55634 + if (ret) {
55635 + if (alloc_push(ret)) {
55636 + kfree(ret);
55637 + ret = NULL;
55638 + }
55639 + }
55640 +
55641 +out:
55642 + return ret;
55643 +}
55644 +
55645 +void *
55646 +acl_alloc_num(unsigned long num, unsigned long len)
55647 +{
55648 + if (!len || (num > (PAGE_SIZE / len)))
55649 + return NULL;
55650 +
55651 + return acl_alloc(num * len);
55652 +}
55653 +
55654 +void
55655 +acl_free_all(void)
55656 +{
55657 + if (gr_acl_is_enabled() || !alloc_stack)
55658 + return;
55659 +
55660 + while (alloc_pop()) ;
55661 +
55662 + if (alloc_stack) {
55663 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55664 + kfree(alloc_stack);
55665 + else
55666 + vfree(alloc_stack);
55667 + }
55668 +
55669 + alloc_stack = NULL;
55670 + alloc_stack_size = 1;
55671 + alloc_stack_next = 1;
55672 +
55673 + return;
55674 +}
55675 +
55676 +int
55677 +acl_alloc_stack_init(unsigned long size)
55678 +{
55679 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55680 + alloc_stack =
55681 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55682 + else
55683 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55684 +
55685 + alloc_stack_size = size;
55686 +
55687 + if (!alloc_stack)
55688 + return 0;
55689 + else
55690 + return 1;
55691 +}
55692 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55693 new file mode 100644
55694 index 0000000..6d21049
55695 --- /dev/null
55696 +++ b/grsecurity/gracl_cap.c
55697 @@ -0,0 +1,110 @@
55698 +#include <linux/kernel.h>
55699 +#include <linux/module.h>
55700 +#include <linux/sched.h>
55701 +#include <linux/gracl.h>
55702 +#include <linux/grsecurity.h>
55703 +#include <linux/grinternal.h>
55704 +
55705 +extern const char *captab_log[];
55706 +extern int captab_log_entries;
55707 +
55708 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55709 +{
55710 + struct acl_subject_label *curracl;
55711 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55712 + kernel_cap_t cap_audit = __cap_empty_set;
55713 +
55714 + if (!gr_acl_is_enabled())
55715 + return 1;
55716 +
55717 + curracl = task->acl;
55718 +
55719 + cap_drop = curracl->cap_lower;
55720 + cap_mask = curracl->cap_mask;
55721 + cap_audit = curracl->cap_invert_audit;
55722 +
55723 + while ((curracl = curracl->parent_subject)) {
55724 + /* if the cap isn't specified in the current computed mask but is specified in the
55725 + current level subject, and is lowered in the current level subject, then add
55726 + it to the set of dropped capabilities
55727 + otherwise, add the current level subject's mask to the current computed mask
55728 + */
55729 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55730 + cap_raise(cap_mask, cap);
55731 + if (cap_raised(curracl->cap_lower, cap))
55732 + cap_raise(cap_drop, cap);
55733 + if (cap_raised(curracl->cap_invert_audit, cap))
55734 + cap_raise(cap_audit, cap);
55735 + }
55736 + }
55737 +
55738 + if (!cap_raised(cap_drop, cap)) {
55739 + if (cap_raised(cap_audit, cap))
55740 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55741 + return 1;
55742 + }
55743 +
55744 + curracl = task->acl;
55745 +
55746 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55747 + && cap_raised(cred->cap_effective, cap)) {
55748 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55749 + task->role->roletype, cred->uid,
55750 + cred->gid, task->exec_file ?
55751 + gr_to_filename(task->exec_file->f_path.dentry,
55752 + task->exec_file->f_path.mnt) : curracl->filename,
55753 + curracl->filename, 0UL,
55754 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55755 + return 1;
55756 + }
55757 +
55758 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55759 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55760 +
55761 + return 0;
55762 +}
55763 +
55764 +int
55765 +gr_acl_is_capable(const int cap)
55766 +{
55767 + return gr_task_acl_is_capable(current, current_cred(), cap);
55768 +}
55769 +
55770 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55771 +{
55772 + struct acl_subject_label *curracl;
55773 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55774 +
55775 + if (!gr_acl_is_enabled())
55776 + return 1;
55777 +
55778 + curracl = task->acl;
55779 +
55780 + cap_drop = curracl->cap_lower;
55781 + cap_mask = curracl->cap_mask;
55782 +
55783 + while ((curracl = curracl->parent_subject)) {
55784 + /* if the cap isn't specified in the current computed mask but is specified in the
55785 + current level subject, and is lowered in the current level subject, then add
55786 + it to the set of dropped capabilities
55787 + otherwise, add the current level subject's mask to the current computed mask
55788 + */
55789 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55790 + cap_raise(cap_mask, cap);
55791 + if (cap_raised(curracl->cap_lower, cap))
55792 + cap_raise(cap_drop, cap);
55793 + }
55794 + }
55795 +
55796 + if (!cap_raised(cap_drop, cap))
55797 + return 1;
55798 +
55799 + return 0;
55800 +}
55801 +
55802 +int
55803 +gr_acl_is_capable_nolog(const int cap)
55804 +{
55805 + return gr_task_acl_is_capable_nolog(current, cap);
55806 +}
55807 +
55808 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55809 new file mode 100644
55810 index 0000000..d28e241
55811 --- /dev/null
55812 +++ b/grsecurity/gracl_fs.c
55813 @@ -0,0 +1,437 @@
55814 +#include <linux/kernel.h>
55815 +#include <linux/sched.h>
55816 +#include <linux/types.h>
55817 +#include <linux/fs.h>
55818 +#include <linux/file.h>
55819 +#include <linux/stat.h>
55820 +#include <linux/grsecurity.h>
55821 +#include <linux/grinternal.h>
55822 +#include <linux/gracl.h>
55823 +
55824 +umode_t
55825 +gr_acl_umask(void)
55826 +{
55827 + if (unlikely(!gr_acl_is_enabled()))
55828 + return 0;
55829 +
55830 + return current->role->umask;
55831 +}
55832 +
55833 +__u32
55834 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55835 + const struct vfsmount * mnt)
55836 +{
55837 + __u32 mode;
55838 +
55839 + if (unlikely(!dentry->d_inode))
55840 + return GR_FIND;
55841 +
55842 + mode =
55843 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55844 +
55845 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55846 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55847 + return mode;
55848 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55849 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55850 + return 0;
55851 + } else if (unlikely(!(mode & GR_FIND)))
55852 + return 0;
55853 +
55854 + return GR_FIND;
55855 +}
55856 +
55857 +__u32
55858 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55859 + int acc_mode)
55860 +{
55861 + __u32 reqmode = GR_FIND;
55862 + __u32 mode;
55863 +
55864 + if (unlikely(!dentry->d_inode))
55865 + return reqmode;
55866 +
55867 + if (acc_mode & MAY_APPEND)
55868 + reqmode |= GR_APPEND;
55869 + else if (acc_mode & MAY_WRITE)
55870 + reqmode |= GR_WRITE;
55871 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55872 + reqmode |= GR_READ;
55873 +
55874 + mode =
55875 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55876 + mnt);
55877 +
55878 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55879 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55880 + reqmode & GR_READ ? " reading" : "",
55881 + reqmode & GR_WRITE ? " writing" : reqmode &
55882 + GR_APPEND ? " appending" : "");
55883 + return reqmode;
55884 + } else
55885 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55886 + {
55887 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55888 + reqmode & GR_READ ? " reading" : "",
55889 + reqmode & GR_WRITE ? " writing" : reqmode &
55890 + GR_APPEND ? " appending" : "");
55891 + return 0;
55892 + } else if (unlikely((mode & reqmode) != reqmode))
55893 + return 0;
55894 +
55895 + return reqmode;
55896 +}
55897 +
55898 +__u32
55899 +gr_acl_handle_creat(const struct dentry * dentry,
55900 + const struct dentry * p_dentry,
55901 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55902 + const int imode)
55903 +{
55904 + __u32 reqmode = GR_WRITE | GR_CREATE;
55905 + __u32 mode;
55906 +
55907 + if (acc_mode & MAY_APPEND)
55908 + reqmode |= GR_APPEND;
55909 + // if a directory was required or the directory already exists, then
55910 + // don't count this open as a read
55911 + if ((acc_mode & MAY_READ) &&
55912 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55913 + reqmode |= GR_READ;
55914 + if ((open_flags & O_CREAT) &&
55915 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55916 + reqmode |= GR_SETID;
55917 +
55918 + mode =
55919 + gr_check_create(dentry, p_dentry, p_mnt,
55920 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55921 +
55922 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55923 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55924 + reqmode & GR_READ ? " reading" : "",
55925 + reqmode & GR_WRITE ? " writing" : reqmode &
55926 + GR_APPEND ? " appending" : "");
55927 + return reqmode;
55928 + } else
55929 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55930 + {
55931 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55932 + reqmode & GR_READ ? " reading" : "",
55933 + reqmode & GR_WRITE ? " writing" : reqmode &
55934 + GR_APPEND ? " appending" : "");
55935 + return 0;
55936 + } else if (unlikely((mode & reqmode) != reqmode))
55937 + return 0;
55938 +
55939 + return reqmode;
55940 +}
55941 +
55942 +__u32
55943 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55944 + const int fmode)
55945 +{
55946 + __u32 mode, reqmode = GR_FIND;
55947 +
55948 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55949 + reqmode |= GR_EXEC;
55950 + if (fmode & S_IWOTH)
55951 + reqmode |= GR_WRITE;
55952 + if (fmode & S_IROTH)
55953 + reqmode |= GR_READ;
55954 +
55955 + mode =
55956 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55957 + mnt);
55958 +
55959 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55960 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55961 + reqmode & GR_READ ? " reading" : "",
55962 + reqmode & GR_WRITE ? " writing" : "",
55963 + reqmode & GR_EXEC ? " executing" : "");
55964 + return reqmode;
55965 + } else
55966 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55967 + {
55968 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55969 + reqmode & GR_READ ? " reading" : "",
55970 + reqmode & GR_WRITE ? " writing" : "",
55971 + reqmode & GR_EXEC ? " executing" : "");
55972 + return 0;
55973 + } else if (unlikely((mode & reqmode) != reqmode))
55974 + return 0;
55975 +
55976 + return reqmode;
55977 +}
55978 +
55979 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55980 +{
55981 + __u32 mode;
55982 +
55983 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55984 +
55985 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55986 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55987 + return mode;
55988 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55989 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55990 + return 0;
55991 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55992 + return 0;
55993 +
55994 + return (reqmode);
55995 +}
55996 +
55997 +__u32
55998 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55999 +{
56000 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56001 +}
56002 +
56003 +__u32
56004 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56005 +{
56006 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56007 +}
56008 +
56009 +__u32
56010 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56011 +{
56012 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56013 +}
56014 +
56015 +__u32
56016 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56017 +{
56018 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56019 +}
56020 +
56021 +__u32
56022 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56023 + umode_t *modeptr)
56024 +{
56025 + umode_t mode;
56026 +
56027 + *modeptr &= ~gr_acl_umask();
56028 + mode = *modeptr;
56029 +
56030 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56031 + return 1;
56032 +
56033 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56034 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56035 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56036 + GR_CHMOD_ACL_MSG);
56037 + } else {
56038 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56039 + }
56040 +}
56041 +
56042 +__u32
56043 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56044 +{
56045 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56046 +}
56047 +
56048 +__u32
56049 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56050 +{
56051 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56052 +}
56053 +
56054 +__u32
56055 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56056 +{
56057 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56058 +}
56059 +
56060 +__u32
56061 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56062 +{
56063 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56064 + GR_UNIXCONNECT_ACL_MSG);
56065 +}
56066 +
56067 +/* hardlinks require at minimum create and link permission,
56068 + any additional privilege required is based on the
56069 + privilege of the file being linked to
56070 +*/
56071 +__u32
56072 +gr_acl_handle_link(const struct dentry * new_dentry,
56073 + const struct dentry * parent_dentry,
56074 + const struct vfsmount * parent_mnt,
56075 + const struct dentry * old_dentry,
56076 + const struct vfsmount * old_mnt, const char *to)
56077 +{
56078 + __u32 mode;
56079 + __u32 needmode = GR_CREATE | GR_LINK;
56080 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56081 +
56082 + mode =
56083 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56084 + old_mnt);
56085 +
56086 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56087 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56088 + return mode;
56089 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56090 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56091 + return 0;
56092 + } else if (unlikely((mode & needmode) != needmode))
56093 + return 0;
56094 +
56095 + return 1;
56096 +}
56097 +
56098 +__u32
56099 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56100 + const struct dentry * parent_dentry,
56101 + const struct vfsmount * parent_mnt, const char *from)
56102 +{
56103 + __u32 needmode = GR_WRITE | GR_CREATE;
56104 + __u32 mode;
56105 +
56106 + mode =
56107 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56108 + GR_CREATE | GR_AUDIT_CREATE |
56109 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56110 +
56111 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56112 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56113 + return mode;
56114 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56115 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56116 + return 0;
56117 + } else if (unlikely((mode & needmode) != needmode))
56118 + return 0;
56119 +
56120 + return (GR_WRITE | GR_CREATE);
56121 +}
56122 +
56123 +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)
56124 +{
56125 + __u32 mode;
56126 +
56127 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56128 +
56129 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56130 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56131 + return mode;
56132 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56133 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56134 + return 0;
56135 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56136 + return 0;
56137 +
56138 + return (reqmode);
56139 +}
56140 +
56141 +__u32
56142 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56143 + const struct dentry * parent_dentry,
56144 + const struct vfsmount * parent_mnt,
56145 + const int mode)
56146 +{
56147 + __u32 reqmode = GR_WRITE | GR_CREATE;
56148 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56149 + reqmode |= GR_SETID;
56150 +
56151 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56152 + reqmode, GR_MKNOD_ACL_MSG);
56153 +}
56154 +
56155 +__u32
56156 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56157 + const struct dentry *parent_dentry,
56158 + const struct vfsmount *parent_mnt)
56159 +{
56160 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56161 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56162 +}
56163 +
56164 +#define RENAME_CHECK_SUCCESS(old, new) \
56165 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56166 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56167 +
56168 +int
56169 +gr_acl_handle_rename(struct dentry *new_dentry,
56170 + struct dentry *parent_dentry,
56171 + const struct vfsmount *parent_mnt,
56172 + struct dentry *old_dentry,
56173 + struct inode *old_parent_inode,
56174 + struct vfsmount *old_mnt, const char *newname)
56175 +{
56176 + __u32 comp1, comp2;
56177 + int error = 0;
56178 +
56179 + if (unlikely(!gr_acl_is_enabled()))
56180 + return 0;
56181 +
56182 + if (!new_dentry->d_inode) {
56183 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56184 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56185 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56186 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56187 + GR_DELETE | GR_AUDIT_DELETE |
56188 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56189 + GR_SUPPRESS, old_mnt);
56190 + } else {
56191 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56192 + GR_CREATE | GR_DELETE |
56193 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56194 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56195 + GR_SUPPRESS, parent_mnt);
56196 + comp2 =
56197 + gr_search_file(old_dentry,
56198 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56199 + GR_DELETE | GR_AUDIT_DELETE |
56200 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56201 + }
56202 +
56203 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56204 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56205 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56206 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56207 + && !(comp2 & GR_SUPPRESS)) {
56208 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56209 + error = -EACCES;
56210 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56211 + error = -EACCES;
56212 +
56213 + return error;
56214 +}
56215 +
56216 +void
56217 +gr_acl_handle_exit(void)
56218 +{
56219 + u16 id;
56220 + char *rolename;
56221 + struct file *exec_file;
56222 +
56223 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56224 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56225 + id = current->acl_role_id;
56226 + rolename = current->role->rolename;
56227 + gr_set_acls(1);
56228 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56229 + }
56230 +
56231 + write_lock(&grsec_exec_file_lock);
56232 + exec_file = current->exec_file;
56233 + current->exec_file = NULL;
56234 + write_unlock(&grsec_exec_file_lock);
56235 +
56236 + if (exec_file)
56237 + fput(exec_file);
56238 +}
56239 +
56240 +int
56241 +gr_acl_handle_procpidmem(const struct task_struct *task)
56242 +{
56243 + if (unlikely(!gr_acl_is_enabled()))
56244 + return 0;
56245 +
56246 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56247 + return -EACCES;
56248 +
56249 + return 0;
56250 +}
56251 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56252 new file mode 100644
56253 index 0000000..58800a7
56254 --- /dev/null
56255 +++ b/grsecurity/gracl_ip.c
56256 @@ -0,0 +1,384 @@
56257 +#include <linux/kernel.h>
56258 +#include <asm/uaccess.h>
56259 +#include <asm/errno.h>
56260 +#include <net/sock.h>
56261 +#include <linux/file.h>
56262 +#include <linux/fs.h>
56263 +#include <linux/net.h>
56264 +#include <linux/in.h>
56265 +#include <linux/skbuff.h>
56266 +#include <linux/ip.h>
56267 +#include <linux/udp.h>
56268 +#include <linux/types.h>
56269 +#include <linux/sched.h>
56270 +#include <linux/netdevice.h>
56271 +#include <linux/inetdevice.h>
56272 +#include <linux/gracl.h>
56273 +#include <linux/grsecurity.h>
56274 +#include <linux/grinternal.h>
56275 +
56276 +#define GR_BIND 0x01
56277 +#define GR_CONNECT 0x02
56278 +#define GR_INVERT 0x04
56279 +#define GR_BINDOVERRIDE 0x08
56280 +#define GR_CONNECTOVERRIDE 0x10
56281 +#define GR_SOCK_FAMILY 0x20
56282 +
56283 +static const char * gr_protocols[IPPROTO_MAX] = {
56284 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56285 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56286 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56287 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56288 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56289 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56290 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56291 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56292 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56293 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56294 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56295 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56296 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56297 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56298 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56299 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56300 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56301 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56302 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56303 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56304 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56305 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56306 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56307 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56308 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56309 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56310 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56311 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56312 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56313 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56314 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56315 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56316 + };
56317 +
56318 +static const char * gr_socktypes[SOCK_MAX] = {
56319 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56320 + "unknown:7", "unknown:8", "unknown:9", "packet"
56321 + };
56322 +
56323 +static const char * gr_sockfamilies[AF_MAX+1] = {
56324 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56325 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56326 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56327 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56328 + };
56329 +
56330 +const char *
56331 +gr_proto_to_name(unsigned char proto)
56332 +{
56333 + return gr_protocols[proto];
56334 +}
56335 +
56336 +const char *
56337 +gr_socktype_to_name(unsigned char type)
56338 +{
56339 + return gr_socktypes[type];
56340 +}
56341 +
56342 +const char *
56343 +gr_sockfamily_to_name(unsigned char family)
56344 +{
56345 + return gr_sockfamilies[family];
56346 +}
56347 +
56348 +int
56349 +gr_search_socket(const int domain, const int type, const int protocol)
56350 +{
56351 + struct acl_subject_label *curr;
56352 + const struct cred *cred = current_cred();
56353 +
56354 + if (unlikely(!gr_acl_is_enabled()))
56355 + goto exit;
56356 +
56357 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56358 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56359 + goto exit; // let the kernel handle it
56360 +
56361 + curr = current->acl;
56362 +
56363 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56364 + /* the family is allowed, if this is PF_INET allow it only if
56365 + the extra sock type/protocol checks pass */
56366 + if (domain == PF_INET)
56367 + goto inet_check;
56368 + goto exit;
56369 + } else {
56370 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56371 + __u32 fakeip = 0;
56372 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56373 + current->role->roletype, cred->uid,
56374 + cred->gid, current->exec_file ?
56375 + gr_to_filename(current->exec_file->f_path.dentry,
56376 + current->exec_file->f_path.mnt) :
56377 + curr->filename, curr->filename,
56378 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56379 + &current->signal->saved_ip);
56380 + goto exit;
56381 + }
56382 + goto exit_fail;
56383 + }
56384 +
56385 +inet_check:
56386 + /* the rest of this checking is for IPv4 only */
56387 + if (!curr->ips)
56388 + goto exit;
56389 +
56390 + if ((curr->ip_type & (1 << type)) &&
56391 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56392 + goto exit;
56393 +
56394 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56395 + /* we don't place acls on raw sockets , and sometimes
56396 + dgram/ip sockets are opened for ioctl and not
56397 + bind/connect, so we'll fake a bind learn log */
56398 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56399 + __u32 fakeip = 0;
56400 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56401 + current->role->roletype, cred->uid,
56402 + cred->gid, current->exec_file ?
56403 + gr_to_filename(current->exec_file->f_path.dentry,
56404 + current->exec_file->f_path.mnt) :
56405 + curr->filename, curr->filename,
56406 + &fakeip, 0, type,
56407 + protocol, GR_CONNECT, &current->signal->saved_ip);
56408 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56409 + __u32 fakeip = 0;
56410 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56411 + current->role->roletype, cred->uid,
56412 + cred->gid, current->exec_file ?
56413 + gr_to_filename(current->exec_file->f_path.dentry,
56414 + current->exec_file->f_path.mnt) :
56415 + curr->filename, curr->filename,
56416 + &fakeip, 0, type,
56417 + protocol, GR_BIND, &current->signal->saved_ip);
56418 + }
56419 + /* we'll log when they use connect or bind */
56420 + goto exit;
56421 + }
56422 +
56423 +exit_fail:
56424 + if (domain == PF_INET)
56425 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56426 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56427 + else
56428 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56429 + gr_socktype_to_name(type), protocol);
56430 +
56431 + return 0;
56432 +exit:
56433 + return 1;
56434 +}
56435 +
56436 +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)
56437 +{
56438 + if ((ip->mode & mode) &&
56439 + (ip_port >= ip->low) &&
56440 + (ip_port <= ip->high) &&
56441 + ((ntohl(ip_addr) & our_netmask) ==
56442 + (ntohl(our_addr) & our_netmask))
56443 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56444 + && (ip->type & (1 << type))) {
56445 + if (ip->mode & GR_INVERT)
56446 + return 2; // specifically denied
56447 + else
56448 + return 1; // allowed
56449 + }
56450 +
56451 + return 0; // not specifically allowed, may continue parsing
56452 +}
56453 +
56454 +static int
56455 +gr_search_connectbind(const int full_mode, struct sock *sk,
56456 + struct sockaddr_in *addr, const int type)
56457 +{
56458 + char iface[IFNAMSIZ] = {0};
56459 + struct acl_subject_label *curr;
56460 + struct acl_ip_label *ip;
56461 + struct inet_sock *isk;
56462 + struct net_device *dev;
56463 + struct in_device *idev;
56464 + unsigned long i;
56465 + int ret;
56466 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56467 + __u32 ip_addr = 0;
56468 + __u32 our_addr;
56469 + __u32 our_netmask;
56470 + char *p;
56471 + __u16 ip_port = 0;
56472 + const struct cred *cred = current_cred();
56473 +
56474 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56475 + return 0;
56476 +
56477 + curr = current->acl;
56478 + isk = inet_sk(sk);
56479 +
56480 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56481 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56482 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56483 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56484 + struct sockaddr_in saddr;
56485 + int err;
56486 +
56487 + saddr.sin_family = AF_INET;
56488 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56489 + saddr.sin_port = isk->inet_sport;
56490 +
56491 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56492 + if (err)
56493 + return err;
56494 +
56495 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56496 + if (err)
56497 + return err;
56498 + }
56499 +
56500 + if (!curr->ips)
56501 + return 0;
56502 +
56503 + ip_addr = addr->sin_addr.s_addr;
56504 + ip_port = ntohs(addr->sin_port);
56505 +
56506 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56507 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56508 + current->role->roletype, cred->uid,
56509 + cred->gid, current->exec_file ?
56510 + gr_to_filename(current->exec_file->f_path.dentry,
56511 + current->exec_file->f_path.mnt) :
56512 + curr->filename, curr->filename,
56513 + &ip_addr, ip_port, type,
56514 + sk->sk_protocol, mode, &current->signal->saved_ip);
56515 + return 0;
56516 + }
56517 +
56518 + for (i = 0; i < curr->ip_num; i++) {
56519 + ip = *(curr->ips + i);
56520 + if (ip->iface != NULL) {
56521 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56522 + p = strchr(iface, ':');
56523 + if (p != NULL)
56524 + *p = '\0';
56525 + dev = dev_get_by_name(sock_net(sk), iface);
56526 + if (dev == NULL)
56527 + continue;
56528 + idev = in_dev_get(dev);
56529 + if (idev == NULL) {
56530 + dev_put(dev);
56531 + continue;
56532 + }
56533 + rcu_read_lock();
56534 + for_ifa(idev) {
56535 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56536 + our_addr = ifa->ifa_address;
56537 + our_netmask = 0xffffffff;
56538 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56539 + if (ret == 1) {
56540 + rcu_read_unlock();
56541 + in_dev_put(idev);
56542 + dev_put(dev);
56543 + return 0;
56544 + } else if (ret == 2) {
56545 + rcu_read_unlock();
56546 + in_dev_put(idev);
56547 + dev_put(dev);
56548 + goto denied;
56549 + }
56550 + }
56551 + } endfor_ifa(idev);
56552 + rcu_read_unlock();
56553 + in_dev_put(idev);
56554 + dev_put(dev);
56555 + } else {
56556 + our_addr = ip->addr;
56557 + our_netmask = ip->netmask;
56558 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56559 + if (ret == 1)
56560 + return 0;
56561 + else if (ret == 2)
56562 + goto denied;
56563 + }
56564 + }
56565 +
56566 +denied:
56567 + if (mode == GR_BIND)
56568 + 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));
56569 + else if (mode == GR_CONNECT)
56570 + 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));
56571 +
56572 + return -EACCES;
56573 +}
56574 +
56575 +int
56576 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56577 +{
56578 + /* always allow disconnection of dgram sockets with connect */
56579 + if (addr->sin_family == AF_UNSPEC)
56580 + return 0;
56581 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56582 +}
56583 +
56584 +int
56585 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56586 +{
56587 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56588 +}
56589 +
56590 +int gr_search_listen(struct socket *sock)
56591 +{
56592 + struct sock *sk = sock->sk;
56593 + struct sockaddr_in addr;
56594 +
56595 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56596 + addr.sin_port = inet_sk(sk)->inet_sport;
56597 +
56598 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56599 +}
56600 +
56601 +int gr_search_accept(struct socket *sock)
56602 +{
56603 + struct sock *sk = sock->sk;
56604 + struct sockaddr_in addr;
56605 +
56606 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56607 + addr.sin_port = inet_sk(sk)->inet_sport;
56608 +
56609 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56610 +}
56611 +
56612 +int
56613 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56614 +{
56615 + if (addr)
56616 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56617 + else {
56618 + struct sockaddr_in sin;
56619 + const struct inet_sock *inet = inet_sk(sk);
56620 +
56621 + sin.sin_addr.s_addr = inet->inet_daddr;
56622 + sin.sin_port = inet->inet_dport;
56623 +
56624 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56625 + }
56626 +}
56627 +
56628 +int
56629 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56630 +{
56631 + struct sockaddr_in sin;
56632 +
56633 + if (unlikely(skb->len < sizeof (struct udphdr)))
56634 + return 0; // skip this packet
56635 +
56636 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56637 + sin.sin_port = udp_hdr(skb)->source;
56638 +
56639 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56640 +}
56641 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56642 new file mode 100644
56643 index 0000000..25f54ef
56644 --- /dev/null
56645 +++ b/grsecurity/gracl_learn.c
56646 @@ -0,0 +1,207 @@
56647 +#include <linux/kernel.h>
56648 +#include <linux/mm.h>
56649 +#include <linux/sched.h>
56650 +#include <linux/poll.h>
56651 +#include <linux/string.h>
56652 +#include <linux/file.h>
56653 +#include <linux/types.h>
56654 +#include <linux/vmalloc.h>
56655 +#include <linux/grinternal.h>
56656 +
56657 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56658 + size_t count, loff_t *ppos);
56659 +extern int gr_acl_is_enabled(void);
56660 +
56661 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56662 +static int gr_learn_attached;
56663 +
56664 +/* use a 512k buffer */
56665 +#define LEARN_BUFFER_SIZE (512 * 1024)
56666 +
56667 +static DEFINE_SPINLOCK(gr_learn_lock);
56668 +static DEFINE_MUTEX(gr_learn_user_mutex);
56669 +
56670 +/* we need to maintain two buffers, so that the kernel context of grlearn
56671 + uses a semaphore around the userspace copying, and the other kernel contexts
56672 + use a spinlock when copying into the buffer, since they cannot sleep
56673 +*/
56674 +static char *learn_buffer;
56675 +static char *learn_buffer_user;
56676 +static int learn_buffer_len;
56677 +static int learn_buffer_user_len;
56678 +
56679 +static ssize_t
56680 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56681 +{
56682 + DECLARE_WAITQUEUE(wait, current);
56683 + ssize_t retval = 0;
56684 +
56685 + add_wait_queue(&learn_wait, &wait);
56686 + set_current_state(TASK_INTERRUPTIBLE);
56687 + do {
56688 + mutex_lock(&gr_learn_user_mutex);
56689 + spin_lock(&gr_learn_lock);
56690 + if (learn_buffer_len)
56691 + break;
56692 + spin_unlock(&gr_learn_lock);
56693 + mutex_unlock(&gr_learn_user_mutex);
56694 + if (file->f_flags & O_NONBLOCK) {
56695 + retval = -EAGAIN;
56696 + goto out;
56697 + }
56698 + if (signal_pending(current)) {
56699 + retval = -ERESTARTSYS;
56700 + goto out;
56701 + }
56702 +
56703 + schedule();
56704 + } while (1);
56705 +
56706 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56707 + learn_buffer_user_len = learn_buffer_len;
56708 + retval = learn_buffer_len;
56709 + learn_buffer_len = 0;
56710 +
56711 + spin_unlock(&gr_learn_lock);
56712 +
56713 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56714 + retval = -EFAULT;
56715 +
56716 + mutex_unlock(&gr_learn_user_mutex);
56717 +out:
56718 + set_current_state(TASK_RUNNING);
56719 + remove_wait_queue(&learn_wait, &wait);
56720 + return retval;
56721 +}
56722 +
56723 +static unsigned int
56724 +poll_learn(struct file * file, poll_table * wait)
56725 +{
56726 + poll_wait(file, &learn_wait, wait);
56727 +
56728 + if (learn_buffer_len)
56729 + return (POLLIN | POLLRDNORM);
56730 +
56731 + return 0;
56732 +}
56733 +
56734 +void
56735 +gr_clear_learn_entries(void)
56736 +{
56737 + char *tmp;
56738 +
56739 + mutex_lock(&gr_learn_user_mutex);
56740 + spin_lock(&gr_learn_lock);
56741 + tmp = learn_buffer;
56742 + learn_buffer = NULL;
56743 + spin_unlock(&gr_learn_lock);
56744 + if (tmp)
56745 + vfree(tmp);
56746 + if (learn_buffer_user != NULL) {
56747 + vfree(learn_buffer_user);
56748 + learn_buffer_user = NULL;
56749 + }
56750 + learn_buffer_len = 0;
56751 + mutex_unlock(&gr_learn_user_mutex);
56752 +
56753 + return;
56754 +}
56755 +
56756 +void
56757 +gr_add_learn_entry(const char *fmt, ...)
56758 +{
56759 + va_list args;
56760 + unsigned int len;
56761 +
56762 + if (!gr_learn_attached)
56763 + return;
56764 +
56765 + spin_lock(&gr_learn_lock);
56766 +
56767 + /* leave a gap at the end so we know when it's "full" but don't have to
56768 + compute the exact length of the string we're trying to append
56769 + */
56770 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56771 + spin_unlock(&gr_learn_lock);
56772 + wake_up_interruptible(&learn_wait);
56773 + return;
56774 + }
56775 + if (learn_buffer == NULL) {
56776 + spin_unlock(&gr_learn_lock);
56777 + return;
56778 + }
56779 +
56780 + va_start(args, fmt);
56781 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56782 + va_end(args);
56783 +
56784 + learn_buffer_len += len + 1;
56785 +
56786 + spin_unlock(&gr_learn_lock);
56787 + wake_up_interruptible(&learn_wait);
56788 +
56789 + return;
56790 +}
56791 +
56792 +static int
56793 +open_learn(struct inode *inode, struct file *file)
56794 +{
56795 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56796 + return -EBUSY;
56797 + if (file->f_mode & FMODE_READ) {
56798 + int retval = 0;
56799 + mutex_lock(&gr_learn_user_mutex);
56800 + if (learn_buffer == NULL)
56801 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56802 + if (learn_buffer_user == NULL)
56803 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56804 + if (learn_buffer == NULL) {
56805 + retval = -ENOMEM;
56806 + goto out_error;
56807 + }
56808 + if (learn_buffer_user == NULL) {
56809 + retval = -ENOMEM;
56810 + goto out_error;
56811 + }
56812 + learn_buffer_len = 0;
56813 + learn_buffer_user_len = 0;
56814 + gr_learn_attached = 1;
56815 +out_error:
56816 + mutex_unlock(&gr_learn_user_mutex);
56817 + return retval;
56818 + }
56819 + return 0;
56820 +}
56821 +
56822 +static int
56823 +close_learn(struct inode *inode, struct file *file)
56824 +{
56825 + if (file->f_mode & FMODE_READ) {
56826 + char *tmp = NULL;
56827 + mutex_lock(&gr_learn_user_mutex);
56828 + spin_lock(&gr_learn_lock);
56829 + tmp = learn_buffer;
56830 + learn_buffer = NULL;
56831 + spin_unlock(&gr_learn_lock);
56832 + if (tmp)
56833 + vfree(tmp);
56834 + if (learn_buffer_user != NULL) {
56835 + vfree(learn_buffer_user);
56836 + learn_buffer_user = NULL;
56837 + }
56838 + learn_buffer_len = 0;
56839 + learn_buffer_user_len = 0;
56840 + gr_learn_attached = 0;
56841 + mutex_unlock(&gr_learn_user_mutex);
56842 + }
56843 +
56844 + return 0;
56845 +}
56846 +
56847 +const struct file_operations grsec_fops = {
56848 + .read = read_learn,
56849 + .write = write_grsec_handler,
56850 + .open = open_learn,
56851 + .release = close_learn,
56852 + .poll = poll_learn,
56853 +};
56854 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56855 new file mode 100644
56856 index 0000000..39645c9
56857 --- /dev/null
56858 +++ b/grsecurity/gracl_res.c
56859 @@ -0,0 +1,68 @@
56860 +#include <linux/kernel.h>
56861 +#include <linux/sched.h>
56862 +#include <linux/gracl.h>
56863 +#include <linux/grinternal.h>
56864 +
56865 +static const char *restab_log[] = {
56866 + [RLIMIT_CPU] = "RLIMIT_CPU",
56867 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56868 + [RLIMIT_DATA] = "RLIMIT_DATA",
56869 + [RLIMIT_STACK] = "RLIMIT_STACK",
56870 + [RLIMIT_CORE] = "RLIMIT_CORE",
56871 + [RLIMIT_RSS] = "RLIMIT_RSS",
56872 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56873 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56874 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56875 + [RLIMIT_AS] = "RLIMIT_AS",
56876 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56877 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56878 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56879 + [RLIMIT_NICE] = "RLIMIT_NICE",
56880 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56881 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56882 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56883 +};
56884 +
56885 +void
56886 +gr_log_resource(const struct task_struct *task,
56887 + const int res, const unsigned long wanted, const int gt)
56888 +{
56889 + const struct cred *cred;
56890 + unsigned long rlim;
56891 +
56892 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56893 + return;
56894 +
56895 + // not yet supported resource
56896 + if (unlikely(!restab_log[res]))
56897 + return;
56898 +
56899 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56900 + rlim = task_rlimit_max(task, res);
56901 + else
56902 + rlim = task_rlimit(task, res);
56903 +
56904 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56905 + return;
56906 +
56907 + rcu_read_lock();
56908 + cred = __task_cred(task);
56909 +
56910 + if (res == RLIMIT_NPROC &&
56911 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56912 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56913 + goto out_rcu_unlock;
56914 + else if (res == RLIMIT_MEMLOCK &&
56915 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56916 + goto out_rcu_unlock;
56917 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56918 + goto out_rcu_unlock;
56919 + rcu_read_unlock();
56920 +
56921 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56922 +
56923 + return;
56924 +out_rcu_unlock:
56925 + rcu_read_unlock();
56926 + return;
56927 +}
56928 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56929 new file mode 100644
56930 index 0000000..25197e9
56931 --- /dev/null
56932 +++ b/grsecurity/gracl_segv.c
56933 @@ -0,0 +1,299 @@
56934 +#include <linux/kernel.h>
56935 +#include <linux/mm.h>
56936 +#include <asm/uaccess.h>
56937 +#include <asm/errno.h>
56938 +#include <asm/mman.h>
56939 +#include <net/sock.h>
56940 +#include <linux/file.h>
56941 +#include <linux/fs.h>
56942 +#include <linux/net.h>
56943 +#include <linux/in.h>
56944 +#include <linux/slab.h>
56945 +#include <linux/types.h>
56946 +#include <linux/sched.h>
56947 +#include <linux/timer.h>
56948 +#include <linux/gracl.h>
56949 +#include <linux/grsecurity.h>
56950 +#include <linux/grinternal.h>
56951 +
56952 +static struct crash_uid *uid_set;
56953 +static unsigned short uid_used;
56954 +static DEFINE_SPINLOCK(gr_uid_lock);
56955 +extern rwlock_t gr_inode_lock;
56956 +extern struct acl_subject_label *
56957 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56958 + struct acl_role_label *role);
56959 +
56960 +#ifdef CONFIG_BTRFS_FS
56961 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56962 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56963 +#endif
56964 +
56965 +static inline dev_t __get_dev(const struct dentry *dentry)
56966 +{
56967 +#ifdef CONFIG_BTRFS_FS
56968 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56969 + return get_btrfs_dev_from_inode(dentry->d_inode);
56970 + else
56971 +#endif
56972 + return dentry->d_inode->i_sb->s_dev;
56973 +}
56974 +
56975 +int
56976 +gr_init_uidset(void)
56977 +{
56978 + uid_set =
56979 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56980 + uid_used = 0;
56981 +
56982 + return uid_set ? 1 : 0;
56983 +}
56984 +
56985 +void
56986 +gr_free_uidset(void)
56987 +{
56988 + if (uid_set)
56989 + kfree(uid_set);
56990 +
56991 + return;
56992 +}
56993 +
56994 +int
56995 +gr_find_uid(const uid_t uid)
56996 +{
56997 + struct crash_uid *tmp = uid_set;
56998 + uid_t buid;
56999 + int low = 0, high = uid_used - 1, mid;
57000 +
57001 + while (high >= low) {
57002 + mid = (low + high) >> 1;
57003 + buid = tmp[mid].uid;
57004 + if (buid == uid)
57005 + return mid;
57006 + if (buid > uid)
57007 + high = mid - 1;
57008 + if (buid < uid)
57009 + low = mid + 1;
57010 + }
57011 +
57012 + return -1;
57013 +}
57014 +
57015 +static __inline__ void
57016 +gr_insertsort(void)
57017 +{
57018 + unsigned short i, j;
57019 + struct crash_uid index;
57020 +
57021 + for (i = 1; i < uid_used; i++) {
57022 + index = uid_set[i];
57023 + j = i;
57024 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57025 + uid_set[j] = uid_set[j - 1];
57026 + j--;
57027 + }
57028 + uid_set[j] = index;
57029 + }
57030 +
57031 + return;
57032 +}
57033 +
57034 +static __inline__ void
57035 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57036 +{
57037 + int loc;
57038 +
57039 + if (uid_used == GR_UIDTABLE_MAX)
57040 + return;
57041 +
57042 + loc = gr_find_uid(uid);
57043 +
57044 + if (loc >= 0) {
57045 + uid_set[loc].expires = expires;
57046 + return;
57047 + }
57048 +
57049 + uid_set[uid_used].uid = uid;
57050 + uid_set[uid_used].expires = expires;
57051 + uid_used++;
57052 +
57053 + gr_insertsort();
57054 +
57055 + return;
57056 +}
57057 +
57058 +void
57059 +gr_remove_uid(const unsigned short loc)
57060 +{
57061 + unsigned short i;
57062 +
57063 + for (i = loc + 1; i < uid_used; i++)
57064 + uid_set[i - 1] = uid_set[i];
57065 +
57066 + uid_used--;
57067 +
57068 + return;
57069 +}
57070 +
57071 +int
57072 +gr_check_crash_uid(const uid_t uid)
57073 +{
57074 + int loc;
57075 + int ret = 0;
57076 +
57077 + if (unlikely(!gr_acl_is_enabled()))
57078 + return 0;
57079 +
57080 + spin_lock(&gr_uid_lock);
57081 + loc = gr_find_uid(uid);
57082 +
57083 + if (loc < 0)
57084 + goto out_unlock;
57085 +
57086 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57087 + gr_remove_uid(loc);
57088 + else
57089 + ret = 1;
57090 +
57091 +out_unlock:
57092 + spin_unlock(&gr_uid_lock);
57093 + return ret;
57094 +}
57095 +
57096 +static __inline__ int
57097 +proc_is_setxid(const struct cred *cred)
57098 +{
57099 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57100 + !uid_eq(cred->uid, cred->fsuid))
57101 + return 1;
57102 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57103 + !uid_eq(cred->gid, cred->fsgid))
57104 + return 1;
57105 +
57106 + return 0;
57107 +}
57108 +
57109 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57110 +
57111 +void
57112 +gr_handle_crash(struct task_struct *task, const int sig)
57113 +{
57114 + struct acl_subject_label *curr;
57115 + struct task_struct *tsk, *tsk2;
57116 + const struct cred *cred;
57117 + const struct cred *cred2;
57118 +
57119 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57120 + return;
57121 +
57122 + if (unlikely(!gr_acl_is_enabled()))
57123 + return;
57124 +
57125 + curr = task->acl;
57126 +
57127 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57128 + return;
57129 +
57130 + if (time_before_eq(curr->expires, get_seconds())) {
57131 + curr->expires = 0;
57132 + curr->crashes = 0;
57133 + }
57134 +
57135 + curr->crashes++;
57136 +
57137 + if (!curr->expires)
57138 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57139 +
57140 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57141 + time_after(curr->expires, get_seconds())) {
57142 + rcu_read_lock();
57143 + cred = __task_cred(task);
57144 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57145 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57146 + spin_lock(&gr_uid_lock);
57147 + gr_insert_uid(cred->uid, curr->expires);
57148 + spin_unlock(&gr_uid_lock);
57149 + curr->expires = 0;
57150 + curr->crashes = 0;
57151 + read_lock(&tasklist_lock);
57152 + do_each_thread(tsk2, tsk) {
57153 + cred2 = __task_cred(tsk);
57154 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57155 + gr_fake_force_sig(SIGKILL, tsk);
57156 + } while_each_thread(tsk2, tsk);
57157 + read_unlock(&tasklist_lock);
57158 + } else {
57159 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57160 + read_lock(&tasklist_lock);
57161 + read_lock(&grsec_exec_file_lock);
57162 + do_each_thread(tsk2, tsk) {
57163 + if (likely(tsk != task)) {
57164 + // if this thread has the same subject as the one that triggered
57165 + // RES_CRASH and it's the same binary, kill it
57166 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57167 + gr_fake_force_sig(SIGKILL, tsk);
57168 + }
57169 + } while_each_thread(tsk2, tsk);
57170 + read_unlock(&grsec_exec_file_lock);
57171 + read_unlock(&tasklist_lock);
57172 + }
57173 + rcu_read_unlock();
57174 + }
57175 +
57176 + return;
57177 +}
57178 +
57179 +int
57180 +gr_check_crash_exec(const struct file *filp)
57181 +{
57182 + struct acl_subject_label *curr;
57183 +
57184 + if (unlikely(!gr_acl_is_enabled()))
57185 + return 0;
57186 +
57187 + read_lock(&gr_inode_lock);
57188 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57189 + __get_dev(filp->f_path.dentry),
57190 + current->role);
57191 + read_unlock(&gr_inode_lock);
57192 +
57193 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57194 + (!curr->crashes && !curr->expires))
57195 + return 0;
57196 +
57197 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57198 + time_after(curr->expires, get_seconds()))
57199 + return 1;
57200 + else if (time_before_eq(curr->expires, get_seconds())) {
57201 + curr->crashes = 0;
57202 + curr->expires = 0;
57203 + }
57204 +
57205 + return 0;
57206 +}
57207 +
57208 +void
57209 +gr_handle_alertkill(struct task_struct *task)
57210 +{
57211 + struct acl_subject_label *curracl;
57212 + __u32 curr_ip;
57213 + struct task_struct *p, *p2;
57214 +
57215 + if (unlikely(!gr_acl_is_enabled()))
57216 + return;
57217 +
57218 + curracl = task->acl;
57219 + curr_ip = task->signal->curr_ip;
57220 +
57221 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57222 + read_lock(&tasklist_lock);
57223 + do_each_thread(p2, p) {
57224 + if (p->signal->curr_ip == curr_ip)
57225 + gr_fake_force_sig(SIGKILL, p);
57226 + } while_each_thread(p2, p);
57227 + read_unlock(&tasklist_lock);
57228 + } else if (curracl->mode & GR_KILLPROC)
57229 + gr_fake_force_sig(SIGKILL, task);
57230 +
57231 + return;
57232 +}
57233 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57234 new file mode 100644
57235 index 0000000..9d83a69
57236 --- /dev/null
57237 +++ b/grsecurity/gracl_shm.c
57238 @@ -0,0 +1,40 @@
57239 +#include <linux/kernel.h>
57240 +#include <linux/mm.h>
57241 +#include <linux/sched.h>
57242 +#include <linux/file.h>
57243 +#include <linux/ipc.h>
57244 +#include <linux/gracl.h>
57245 +#include <linux/grsecurity.h>
57246 +#include <linux/grinternal.h>
57247 +
57248 +int
57249 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57250 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57251 +{
57252 + struct task_struct *task;
57253 +
57254 + if (!gr_acl_is_enabled())
57255 + return 1;
57256 +
57257 + rcu_read_lock();
57258 + read_lock(&tasklist_lock);
57259 +
57260 + task = find_task_by_vpid(shm_cprid);
57261 +
57262 + if (unlikely(!task))
57263 + task = find_task_by_vpid(shm_lapid);
57264 +
57265 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57266 + (task->pid == shm_lapid)) &&
57267 + (task->acl->mode & GR_PROTSHM) &&
57268 + (task->acl != current->acl))) {
57269 + read_unlock(&tasklist_lock);
57270 + rcu_read_unlock();
57271 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57272 + return 0;
57273 + }
57274 + read_unlock(&tasklist_lock);
57275 + rcu_read_unlock();
57276 +
57277 + return 1;
57278 +}
57279 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57280 new file mode 100644
57281 index 0000000..bc0be01
57282 --- /dev/null
57283 +++ b/grsecurity/grsec_chdir.c
57284 @@ -0,0 +1,19 @@
57285 +#include <linux/kernel.h>
57286 +#include <linux/sched.h>
57287 +#include <linux/fs.h>
57288 +#include <linux/file.h>
57289 +#include <linux/grsecurity.h>
57290 +#include <linux/grinternal.h>
57291 +
57292 +void
57293 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57294 +{
57295 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57296 + if ((grsec_enable_chdir && grsec_enable_group &&
57297 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57298 + !grsec_enable_group)) {
57299 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57300 + }
57301 +#endif
57302 + return;
57303 +}
57304 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57305 new file mode 100644
57306 index 0000000..9807ee2
57307 --- /dev/null
57308 +++ b/grsecurity/grsec_chroot.c
57309 @@ -0,0 +1,368 @@
57310 +#include <linux/kernel.h>
57311 +#include <linux/module.h>
57312 +#include <linux/sched.h>
57313 +#include <linux/file.h>
57314 +#include <linux/fs.h>
57315 +#include <linux/mount.h>
57316 +#include <linux/types.h>
57317 +#include "../fs/mount.h"
57318 +#include <linux/grsecurity.h>
57319 +#include <linux/grinternal.h>
57320 +
57321 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57322 +{
57323 +#ifdef CONFIG_GRKERNSEC
57324 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57325 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57326 + task->gr_is_chrooted = 1;
57327 + else
57328 + task->gr_is_chrooted = 0;
57329 +
57330 + task->gr_chroot_dentry = path->dentry;
57331 +#endif
57332 + return;
57333 +}
57334 +
57335 +void gr_clear_chroot_entries(struct task_struct *task)
57336 +{
57337 +#ifdef CONFIG_GRKERNSEC
57338 + task->gr_is_chrooted = 0;
57339 + task->gr_chroot_dentry = NULL;
57340 +#endif
57341 + return;
57342 +}
57343 +
57344 +int
57345 +gr_handle_chroot_unix(const pid_t pid)
57346 +{
57347 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57348 + struct task_struct *p;
57349 +
57350 + if (unlikely(!grsec_enable_chroot_unix))
57351 + return 1;
57352 +
57353 + if (likely(!proc_is_chrooted(current)))
57354 + return 1;
57355 +
57356 + rcu_read_lock();
57357 + read_lock(&tasklist_lock);
57358 + p = find_task_by_vpid_unrestricted(pid);
57359 + if (unlikely(p && !have_same_root(current, p))) {
57360 + read_unlock(&tasklist_lock);
57361 + rcu_read_unlock();
57362 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57363 + return 0;
57364 + }
57365 + read_unlock(&tasklist_lock);
57366 + rcu_read_unlock();
57367 +#endif
57368 + return 1;
57369 +}
57370 +
57371 +int
57372 +gr_handle_chroot_nice(void)
57373 +{
57374 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57375 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57376 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57377 + return -EPERM;
57378 + }
57379 +#endif
57380 + return 0;
57381 +}
57382 +
57383 +int
57384 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57385 +{
57386 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57387 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57388 + && proc_is_chrooted(current)) {
57389 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57390 + return -EACCES;
57391 + }
57392 +#endif
57393 + return 0;
57394 +}
57395 +
57396 +int
57397 +gr_handle_chroot_rawio(const struct inode *inode)
57398 +{
57399 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57400 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57401 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57402 + return 1;
57403 +#endif
57404 + return 0;
57405 +}
57406 +
57407 +int
57408 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57409 +{
57410 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57411 + struct task_struct *p;
57412 + int ret = 0;
57413 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57414 + return ret;
57415 +
57416 + read_lock(&tasklist_lock);
57417 + do_each_pid_task(pid, type, p) {
57418 + if (!have_same_root(current, p)) {
57419 + ret = 1;
57420 + goto out;
57421 + }
57422 + } while_each_pid_task(pid, type, p);
57423 +out:
57424 + read_unlock(&tasklist_lock);
57425 + return ret;
57426 +#endif
57427 + return 0;
57428 +}
57429 +
57430 +int
57431 +gr_pid_is_chrooted(struct task_struct *p)
57432 +{
57433 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57434 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57435 + return 0;
57436 +
57437 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57438 + !have_same_root(current, p)) {
57439 + return 1;
57440 + }
57441 +#endif
57442 + return 0;
57443 +}
57444 +
57445 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57446 +
57447 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57448 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57449 +{
57450 + struct path path, currentroot;
57451 + int ret = 0;
57452 +
57453 + path.dentry = (struct dentry *)u_dentry;
57454 + path.mnt = (struct vfsmount *)u_mnt;
57455 + get_fs_root(current->fs, &currentroot);
57456 + if (path_is_under(&path, &currentroot))
57457 + ret = 1;
57458 + path_put(&currentroot);
57459 +
57460 + return ret;
57461 +}
57462 +#endif
57463 +
57464 +int
57465 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57466 +{
57467 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57468 + if (!grsec_enable_chroot_fchdir)
57469 + return 1;
57470 +
57471 + if (!proc_is_chrooted(current))
57472 + return 1;
57473 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57474 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57475 + return 0;
57476 + }
57477 +#endif
57478 + return 1;
57479 +}
57480 +
57481 +int
57482 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57483 + const time_t shm_createtime)
57484 +{
57485 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57486 + struct task_struct *p;
57487 + time_t starttime;
57488 +
57489 + if (unlikely(!grsec_enable_chroot_shmat))
57490 + return 1;
57491 +
57492 + if (likely(!proc_is_chrooted(current)))
57493 + return 1;
57494 +
57495 + rcu_read_lock();
57496 + read_lock(&tasklist_lock);
57497 +
57498 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57499 + starttime = p->start_time.tv_sec;
57500 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57501 + if (have_same_root(current, p)) {
57502 + goto allow;
57503 + } else {
57504 + read_unlock(&tasklist_lock);
57505 + rcu_read_unlock();
57506 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57507 + return 0;
57508 + }
57509 + }
57510 + /* creator exited, pid reuse, fall through to next check */
57511 + }
57512 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57513 + if (unlikely(!have_same_root(current, p))) {
57514 + read_unlock(&tasklist_lock);
57515 + rcu_read_unlock();
57516 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57517 + return 0;
57518 + }
57519 + }
57520 +
57521 +allow:
57522 + read_unlock(&tasklist_lock);
57523 + rcu_read_unlock();
57524 +#endif
57525 + return 1;
57526 +}
57527 +
57528 +void
57529 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57530 +{
57531 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57532 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57533 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57534 +#endif
57535 + return;
57536 +}
57537 +
57538 +int
57539 +gr_handle_chroot_mknod(const struct dentry *dentry,
57540 + const struct vfsmount *mnt, const int mode)
57541 +{
57542 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57543 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57544 + proc_is_chrooted(current)) {
57545 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57546 + return -EPERM;
57547 + }
57548 +#endif
57549 + return 0;
57550 +}
57551 +
57552 +int
57553 +gr_handle_chroot_mount(const struct dentry *dentry,
57554 + const struct vfsmount *mnt, const char *dev_name)
57555 +{
57556 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57557 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57558 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57559 + return -EPERM;
57560 + }
57561 +#endif
57562 + return 0;
57563 +}
57564 +
57565 +int
57566 +gr_handle_chroot_pivot(void)
57567 +{
57568 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57569 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57570 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57571 + return -EPERM;
57572 + }
57573 +#endif
57574 + return 0;
57575 +}
57576 +
57577 +int
57578 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57579 +{
57580 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57581 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57582 + !gr_is_outside_chroot(dentry, mnt)) {
57583 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57584 + return -EPERM;
57585 + }
57586 +#endif
57587 + return 0;
57588 +}
57589 +
57590 +extern const char *captab_log[];
57591 +extern int captab_log_entries;
57592 +
57593 +int
57594 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57595 +{
57596 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57597 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57598 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57599 + if (cap_raised(chroot_caps, cap)) {
57600 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57601 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57602 + }
57603 + return 0;
57604 + }
57605 + }
57606 +#endif
57607 + return 1;
57608 +}
57609 +
57610 +int
57611 +gr_chroot_is_capable(const int cap)
57612 +{
57613 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57614 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57615 +#endif
57616 + return 1;
57617 +}
57618 +
57619 +int
57620 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57621 +{
57622 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57623 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57624 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57625 + if (cap_raised(chroot_caps, cap)) {
57626 + return 0;
57627 + }
57628 + }
57629 +#endif
57630 + return 1;
57631 +}
57632 +
57633 +int
57634 +gr_chroot_is_capable_nolog(const int cap)
57635 +{
57636 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57637 + return gr_task_chroot_is_capable_nolog(current, cap);
57638 +#endif
57639 + return 1;
57640 +}
57641 +
57642 +int
57643 +gr_handle_chroot_sysctl(const int op)
57644 +{
57645 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57646 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57647 + proc_is_chrooted(current))
57648 + return -EACCES;
57649 +#endif
57650 + return 0;
57651 +}
57652 +
57653 +void
57654 +gr_handle_chroot_chdir(struct path *path)
57655 +{
57656 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57657 + if (grsec_enable_chroot_chdir)
57658 + set_fs_pwd(current->fs, path);
57659 +#endif
57660 + return;
57661 +}
57662 +
57663 +int
57664 +gr_handle_chroot_chmod(const struct dentry *dentry,
57665 + const struct vfsmount *mnt, const int mode)
57666 +{
57667 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57668 + /* allow chmod +s on directories, but not files */
57669 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57670 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57671 + proc_is_chrooted(current)) {
57672 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57673 + return -EPERM;
57674 + }
57675 +#endif
57676 + return 0;
57677 +}
57678 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57679 new file mode 100644
57680 index 0000000..213ad8b
57681 --- /dev/null
57682 +++ b/grsecurity/grsec_disabled.c
57683 @@ -0,0 +1,437 @@
57684 +#include <linux/kernel.h>
57685 +#include <linux/module.h>
57686 +#include <linux/sched.h>
57687 +#include <linux/file.h>
57688 +#include <linux/fs.h>
57689 +#include <linux/kdev_t.h>
57690 +#include <linux/net.h>
57691 +#include <linux/in.h>
57692 +#include <linux/ip.h>
57693 +#include <linux/skbuff.h>
57694 +#include <linux/sysctl.h>
57695 +
57696 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57697 +void
57698 +pax_set_initial_flags(struct linux_binprm *bprm)
57699 +{
57700 + return;
57701 +}
57702 +#endif
57703 +
57704 +#ifdef CONFIG_SYSCTL
57705 +__u32
57706 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57707 +{
57708 + return 0;
57709 +}
57710 +#endif
57711 +
57712 +#ifdef CONFIG_TASKSTATS
57713 +int gr_is_taskstats_denied(int pid)
57714 +{
57715 + return 0;
57716 +}
57717 +#endif
57718 +
57719 +int
57720 +gr_acl_is_enabled(void)
57721 +{
57722 + return 0;
57723 +}
57724 +
57725 +void
57726 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57727 +{
57728 + return;
57729 +}
57730 +
57731 +int
57732 +gr_handle_rawio(const struct inode *inode)
57733 +{
57734 + return 0;
57735 +}
57736 +
57737 +void
57738 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57739 +{
57740 + return;
57741 +}
57742 +
57743 +int
57744 +gr_handle_ptrace(struct task_struct *task, const long request)
57745 +{
57746 + return 0;
57747 +}
57748 +
57749 +int
57750 +gr_handle_proc_ptrace(struct task_struct *task)
57751 +{
57752 + return 0;
57753 +}
57754 +
57755 +void
57756 +gr_learn_resource(const struct task_struct *task,
57757 + const int res, const unsigned long wanted, const int gt)
57758 +{
57759 + return;
57760 +}
57761 +
57762 +int
57763 +gr_set_acls(const int type)
57764 +{
57765 + return 0;
57766 +}
57767 +
57768 +int
57769 +gr_check_hidden_task(const struct task_struct *tsk)
57770 +{
57771 + return 0;
57772 +}
57773 +
57774 +int
57775 +gr_check_protected_task(const struct task_struct *task)
57776 +{
57777 + return 0;
57778 +}
57779 +
57780 +int
57781 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57782 +{
57783 + return 0;
57784 +}
57785 +
57786 +void
57787 +gr_copy_label(struct task_struct *tsk)
57788 +{
57789 + return;
57790 +}
57791 +
57792 +void
57793 +gr_set_pax_flags(struct task_struct *task)
57794 +{
57795 + return;
57796 +}
57797 +
57798 +int
57799 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57800 + const int unsafe_share)
57801 +{
57802 + return 0;
57803 +}
57804 +
57805 +void
57806 +gr_handle_delete(const ino_t ino, const dev_t dev)
57807 +{
57808 + return;
57809 +}
57810 +
57811 +void
57812 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57813 +{
57814 + return;
57815 +}
57816 +
57817 +void
57818 +gr_handle_crash(struct task_struct *task, const int sig)
57819 +{
57820 + return;
57821 +}
57822 +
57823 +int
57824 +gr_check_crash_exec(const struct file *filp)
57825 +{
57826 + return 0;
57827 +}
57828 +
57829 +int
57830 +gr_check_crash_uid(const uid_t uid)
57831 +{
57832 + return 0;
57833 +}
57834 +
57835 +void
57836 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57837 + struct dentry *old_dentry,
57838 + struct dentry *new_dentry,
57839 + struct vfsmount *mnt, const __u8 replace)
57840 +{
57841 + return;
57842 +}
57843 +
57844 +int
57845 +gr_search_socket(const int family, const int type, const int protocol)
57846 +{
57847 + return 1;
57848 +}
57849 +
57850 +int
57851 +gr_search_connectbind(const int mode, const struct socket *sock,
57852 + const struct sockaddr_in *addr)
57853 +{
57854 + return 0;
57855 +}
57856 +
57857 +void
57858 +gr_handle_alertkill(struct task_struct *task)
57859 +{
57860 + return;
57861 +}
57862 +
57863 +__u32
57864 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57865 +{
57866 + return 1;
57867 +}
57868 +
57869 +__u32
57870 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57871 + const struct vfsmount * mnt)
57872 +{
57873 + return 1;
57874 +}
57875 +
57876 +__u32
57877 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57878 + int acc_mode)
57879 +{
57880 + return 1;
57881 +}
57882 +
57883 +__u32
57884 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57885 +{
57886 + return 1;
57887 +}
57888 +
57889 +__u32
57890 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57891 +{
57892 + return 1;
57893 +}
57894 +
57895 +int
57896 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57897 + unsigned int *vm_flags)
57898 +{
57899 + return 1;
57900 +}
57901 +
57902 +__u32
57903 +gr_acl_handle_truncate(const struct dentry * dentry,
57904 + const struct vfsmount * mnt)
57905 +{
57906 + return 1;
57907 +}
57908 +
57909 +__u32
57910 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57911 +{
57912 + return 1;
57913 +}
57914 +
57915 +__u32
57916 +gr_acl_handle_access(const struct dentry * dentry,
57917 + const struct vfsmount * mnt, const int fmode)
57918 +{
57919 + return 1;
57920 +}
57921 +
57922 +__u32
57923 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57924 + umode_t *mode)
57925 +{
57926 + return 1;
57927 +}
57928 +
57929 +__u32
57930 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57931 +{
57932 + return 1;
57933 +}
57934 +
57935 +__u32
57936 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57937 +{
57938 + return 1;
57939 +}
57940 +
57941 +void
57942 +grsecurity_init(void)
57943 +{
57944 + return;
57945 +}
57946 +
57947 +umode_t gr_acl_umask(void)
57948 +{
57949 + return 0;
57950 +}
57951 +
57952 +__u32
57953 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57954 + const struct dentry * parent_dentry,
57955 + const struct vfsmount * parent_mnt,
57956 + const int mode)
57957 +{
57958 + return 1;
57959 +}
57960 +
57961 +__u32
57962 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57963 + const struct dentry * parent_dentry,
57964 + const struct vfsmount * parent_mnt)
57965 +{
57966 + return 1;
57967 +}
57968 +
57969 +__u32
57970 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57971 + const struct dentry * parent_dentry,
57972 + const struct vfsmount * parent_mnt, const char *from)
57973 +{
57974 + return 1;
57975 +}
57976 +
57977 +__u32
57978 +gr_acl_handle_link(const struct dentry * new_dentry,
57979 + const struct dentry * parent_dentry,
57980 + const struct vfsmount * parent_mnt,
57981 + const struct dentry * old_dentry,
57982 + const struct vfsmount * old_mnt, const char *to)
57983 +{
57984 + return 1;
57985 +}
57986 +
57987 +int
57988 +gr_acl_handle_rename(const struct dentry *new_dentry,
57989 + const struct dentry *parent_dentry,
57990 + const struct vfsmount *parent_mnt,
57991 + const struct dentry *old_dentry,
57992 + const struct inode *old_parent_inode,
57993 + const struct vfsmount *old_mnt, const char *newname)
57994 +{
57995 + return 0;
57996 +}
57997 +
57998 +int
57999 +gr_acl_handle_filldir(const struct file *file, const char *name,
58000 + const int namelen, const ino_t ino)
58001 +{
58002 + return 1;
58003 +}
58004 +
58005 +int
58006 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58007 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58008 +{
58009 + return 1;
58010 +}
58011 +
58012 +int
58013 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58014 +{
58015 + return 0;
58016 +}
58017 +
58018 +int
58019 +gr_search_accept(const struct socket *sock)
58020 +{
58021 + return 0;
58022 +}
58023 +
58024 +int
58025 +gr_search_listen(const struct socket *sock)
58026 +{
58027 + return 0;
58028 +}
58029 +
58030 +int
58031 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58032 +{
58033 + return 0;
58034 +}
58035 +
58036 +__u32
58037 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58038 +{
58039 + return 1;
58040 +}
58041 +
58042 +__u32
58043 +gr_acl_handle_creat(const struct dentry * dentry,
58044 + const struct dentry * p_dentry,
58045 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58046 + const int imode)
58047 +{
58048 + return 1;
58049 +}
58050 +
58051 +void
58052 +gr_acl_handle_exit(void)
58053 +{
58054 + return;
58055 +}
58056 +
58057 +int
58058 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58059 +{
58060 + return 1;
58061 +}
58062 +
58063 +void
58064 +gr_set_role_label(const uid_t uid, const gid_t gid)
58065 +{
58066 + return;
58067 +}
58068 +
58069 +int
58070 +gr_acl_handle_procpidmem(const struct task_struct *task)
58071 +{
58072 + return 0;
58073 +}
58074 +
58075 +int
58076 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58077 +{
58078 + return 0;
58079 +}
58080 +
58081 +int
58082 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58083 +{
58084 + return 0;
58085 +}
58086 +
58087 +void
58088 +gr_set_kernel_label(struct task_struct *task)
58089 +{
58090 + return;
58091 +}
58092 +
58093 +int
58094 +gr_check_user_change(int real, int effective, int fs)
58095 +{
58096 + return 0;
58097 +}
58098 +
58099 +int
58100 +gr_check_group_change(int real, int effective, int fs)
58101 +{
58102 + return 0;
58103 +}
58104 +
58105 +int gr_acl_enable_at_secure(void)
58106 +{
58107 + return 0;
58108 +}
58109 +
58110 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58111 +{
58112 + return dentry->d_inode->i_sb->s_dev;
58113 +}
58114 +
58115 +EXPORT_SYMBOL(gr_learn_resource);
58116 +EXPORT_SYMBOL(gr_set_kernel_label);
58117 +#ifdef CONFIG_SECURITY
58118 +EXPORT_SYMBOL(gr_check_user_change);
58119 +EXPORT_SYMBOL(gr_check_group_change);
58120 +#endif
58121 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58122 new file mode 100644
58123 index 0000000..abfa971
58124 --- /dev/null
58125 +++ b/grsecurity/grsec_exec.c
58126 @@ -0,0 +1,174 @@
58127 +#include <linux/kernel.h>
58128 +#include <linux/sched.h>
58129 +#include <linux/file.h>
58130 +#include <linux/binfmts.h>
58131 +#include <linux/fs.h>
58132 +#include <linux/types.h>
58133 +#include <linux/grdefs.h>
58134 +#include <linux/grsecurity.h>
58135 +#include <linux/grinternal.h>
58136 +#include <linux/capability.h>
58137 +#include <linux/module.h>
58138 +
58139 +#include <asm/uaccess.h>
58140 +
58141 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58142 +static char gr_exec_arg_buf[132];
58143 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58144 +#endif
58145 +
58146 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58147 +
58148 +void
58149 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58150 +{
58151 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58152 + char *grarg = gr_exec_arg_buf;
58153 + unsigned int i, x, execlen = 0;
58154 + char c;
58155 +
58156 + if (!((grsec_enable_execlog && grsec_enable_group &&
58157 + in_group_p(grsec_audit_gid))
58158 + || (grsec_enable_execlog && !grsec_enable_group)))
58159 + return;
58160 +
58161 + mutex_lock(&gr_exec_arg_mutex);
58162 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58163 +
58164 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58165 + const char __user *p;
58166 + unsigned int len;
58167 +
58168 + p = get_user_arg_ptr(argv, i);
58169 + if (IS_ERR(p))
58170 + goto log;
58171 +
58172 + len = strnlen_user(p, 128 - execlen);
58173 + if (len > 128 - execlen)
58174 + len = 128 - execlen;
58175 + else if (len > 0)
58176 + len--;
58177 + if (copy_from_user(grarg + execlen, p, len))
58178 + goto log;
58179 +
58180 + /* rewrite unprintable characters */
58181 + for (x = 0; x < len; x++) {
58182 + c = *(grarg + execlen + x);
58183 + if (c < 32 || c > 126)
58184 + *(grarg + execlen + x) = ' ';
58185 + }
58186 +
58187 + execlen += len;
58188 + *(grarg + execlen) = ' ';
58189 + *(grarg + execlen + 1) = '\0';
58190 + execlen++;
58191 + }
58192 +
58193 + log:
58194 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58195 + bprm->file->f_path.mnt, grarg);
58196 + mutex_unlock(&gr_exec_arg_mutex);
58197 +#endif
58198 + return;
58199 +}
58200 +
58201 +#ifdef CONFIG_GRKERNSEC
58202 +extern int gr_acl_is_capable(const int cap);
58203 +extern int gr_acl_is_capable_nolog(const int cap);
58204 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58205 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58206 +extern int gr_chroot_is_capable(const int cap);
58207 +extern int gr_chroot_is_capable_nolog(const int cap);
58208 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58209 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58210 +#endif
58211 +
58212 +const char *captab_log[] = {
58213 + "CAP_CHOWN",
58214 + "CAP_DAC_OVERRIDE",
58215 + "CAP_DAC_READ_SEARCH",
58216 + "CAP_FOWNER",
58217 + "CAP_FSETID",
58218 + "CAP_KILL",
58219 + "CAP_SETGID",
58220 + "CAP_SETUID",
58221 + "CAP_SETPCAP",
58222 + "CAP_LINUX_IMMUTABLE",
58223 + "CAP_NET_BIND_SERVICE",
58224 + "CAP_NET_BROADCAST",
58225 + "CAP_NET_ADMIN",
58226 + "CAP_NET_RAW",
58227 + "CAP_IPC_LOCK",
58228 + "CAP_IPC_OWNER",
58229 + "CAP_SYS_MODULE",
58230 + "CAP_SYS_RAWIO",
58231 + "CAP_SYS_CHROOT",
58232 + "CAP_SYS_PTRACE",
58233 + "CAP_SYS_PACCT",
58234 + "CAP_SYS_ADMIN",
58235 + "CAP_SYS_BOOT",
58236 + "CAP_SYS_NICE",
58237 + "CAP_SYS_RESOURCE",
58238 + "CAP_SYS_TIME",
58239 + "CAP_SYS_TTY_CONFIG",
58240 + "CAP_MKNOD",
58241 + "CAP_LEASE",
58242 + "CAP_AUDIT_WRITE",
58243 + "CAP_AUDIT_CONTROL",
58244 + "CAP_SETFCAP",
58245 + "CAP_MAC_OVERRIDE",
58246 + "CAP_MAC_ADMIN",
58247 + "CAP_SYSLOG",
58248 + "CAP_WAKE_ALARM"
58249 +};
58250 +
58251 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58252 +
58253 +int gr_is_capable(const int cap)
58254 +{
58255 +#ifdef CONFIG_GRKERNSEC
58256 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58257 + return 1;
58258 + return 0;
58259 +#else
58260 + return 1;
58261 +#endif
58262 +}
58263 +
58264 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58265 +{
58266 +#ifdef CONFIG_GRKERNSEC
58267 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58268 + return 1;
58269 + return 0;
58270 +#else
58271 + return 1;
58272 +#endif
58273 +}
58274 +
58275 +int gr_is_capable_nolog(const int cap)
58276 +{
58277 +#ifdef CONFIG_GRKERNSEC
58278 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58279 + return 1;
58280 + return 0;
58281 +#else
58282 + return 1;
58283 +#endif
58284 +}
58285 +
58286 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58287 +{
58288 +#ifdef CONFIG_GRKERNSEC
58289 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58290 + return 1;
58291 + return 0;
58292 +#else
58293 + return 1;
58294 +#endif
58295 +}
58296 +
58297 +EXPORT_SYMBOL(gr_is_capable);
58298 +EXPORT_SYMBOL(gr_is_capable_nolog);
58299 +EXPORT_SYMBOL(gr_task_is_capable);
58300 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58301 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58302 new file mode 100644
58303 index 0000000..d3ee748
58304 --- /dev/null
58305 +++ b/grsecurity/grsec_fifo.c
58306 @@ -0,0 +1,24 @@
58307 +#include <linux/kernel.h>
58308 +#include <linux/sched.h>
58309 +#include <linux/fs.h>
58310 +#include <linux/file.h>
58311 +#include <linux/grinternal.h>
58312 +
58313 +int
58314 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58315 + const struct dentry *dir, const int flag, const int acc_mode)
58316 +{
58317 +#ifdef CONFIG_GRKERNSEC_FIFO
58318 + const struct cred *cred = current_cred();
58319 +
58320 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58321 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58322 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58323 + (cred->fsuid != dentry->d_inode->i_uid)) {
58324 + if (!inode_permission(dentry->d_inode, acc_mode))
58325 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58326 + return -EACCES;
58327 + }
58328 +#endif
58329 + return 0;
58330 +}
58331 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58332 new file mode 100644
58333 index 0000000..8ca18bf
58334 --- /dev/null
58335 +++ b/grsecurity/grsec_fork.c
58336 @@ -0,0 +1,23 @@
58337 +#include <linux/kernel.h>
58338 +#include <linux/sched.h>
58339 +#include <linux/grsecurity.h>
58340 +#include <linux/grinternal.h>
58341 +#include <linux/errno.h>
58342 +
58343 +void
58344 +gr_log_forkfail(const int retval)
58345 +{
58346 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58347 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58348 + switch (retval) {
58349 + case -EAGAIN:
58350 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58351 + break;
58352 + case -ENOMEM:
58353 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58354 + break;
58355 + }
58356 + }
58357 +#endif
58358 + return;
58359 +}
58360 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58361 new file mode 100644
58362 index 0000000..05a6015
58363 --- /dev/null
58364 +++ b/grsecurity/grsec_init.c
58365 @@ -0,0 +1,283 @@
58366 +#include <linux/kernel.h>
58367 +#include <linux/sched.h>
58368 +#include <linux/mm.h>
58369 +#include <linux/gracl.h>
58370 +#include <linux/slab.h>
58371 +#include <linux/vmalloc.h>
58372 +#include <linux/percpu.h>
58373 +#include <linux/module.h>
58374 +
58375 +int grsec_enable_ptrace_readexec;
58376 +int grsec_enable_setxid;
58377 +int grsec_enable_symlinkown;
58378 +int grsec_symlinkown_gid;
58379 +int grsec_enable_brute;
58380 +int grsec_enable_link;
58381 +int grsec_enable_dmesg;
58382 +int grsec_enable_harden_ptrace;
58383 +int grsec_enable_fifo;
58384 +int grsec_enable_execlog;
58385 +int grsec_enable_signal;
58386 +int grsec_enable_forkfail;
58387 +int grsec_enable_audit_ptrace;
58388 +int grsec_enable_time;
58389 +int grsec_enable_audit_textrel;
58390 +int grsec_enable_group;
58391 +int grsec_audit_gid;
58392 +int grsec_enable_chdir;
58393 +int grsec_enable_mount;
58394 +int grsec_enable_rofs;
58395 +int grsec_enable_chroot_findtask;
58396 +int grsec_enable_chroot_mount;
58397 +int grsec_enable_chroot_shmat;
58398 +int grsec_enable_chroot_fchdir;
58399 +int grsec_enable_chroot_double;
58400 +int grsec_enable_chroot_pivot;
58401 +int grsec_enable_chroot_chdir;
58402 +int grsec_enable_chroot_chmod;
58403 +int grsec_enable_chroot_mknod;
58404 +int grsec_enable_chroot_nice;
58405 +int grsec_enable_chroot_execlog;
58406 +int grsec_enable_chroot_caps;
58407 +int grsec_enable_chroot_sysctl;
58408 +int grsec_enable_chroot_unix;
58409 +int grsec_enable_tpe;
58410 +int grsec_tpe_gid;
58411 +int grsec_enable_blackhole;
58412 +#ifdef CONFIG_IPV6_MODULE
58413 +EXPORT_SYMBOL(grsec_enable_blackhole);
58414 +#endif
58415 +int grsec_lastack_retries;
58416 +int grsec_enable_tpe_all;
58417 +int grsec_enable_tpe_invert;
58418 +int grsec_enable_socket_all;
58419 +int grsec_socket_all_gid;
58420 +int grsec_enable_socket_client;
58421 +int grsec_socket_client_gid;
58422 +int grsec_enable_socket_server;
58423 +int grsec_socket_server_gid;
58424 +int grsec_resource_logging;
58425 +int grsec_disable_privio;
58426 +int grsec_enable_log_rwxmaps;
58427 +int grsec_lock;
58428 +
58429 +DEFINE_SPINLOCK(grsec_alert_lock);
58430 +unsigned long grsec_alert_wtime = 0;
58431 +unsigned long grsec_alert_fyet = 0;
58432 +
58433 +DEFINE_SPINLOCK(grsec_audit_lock);
58434 +
58435 +DEFINE_RWLOCK(grsec_exec_file_lock);
58436 +
58437 +char *gr_shared_page[4];
58438 +
58439 +char *gr_alert_log_fmt;
58440 +char *gr_audit_log_fmt;
58441 +char *gr_alert_log_buf;
58442 +char *gr_audit_log_buf;
58443 +
58444 +extern struct gr_arg *gr_usermode;
58445 +extern unsigned char *gr_system_salt;
58446 +extern unsigned char *gr_system_sum;
58447 +
58448 +void __init
58449 +grsecurity_init(void)
58450 +{
58451 + int j;
58452 + /* create the per-cpu shared pages */
58453 +
58454 +#ifdef CONFIG_X86
58455 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58456 +#endif
58457 +
58458 + for (j = 0; j < 4; j++) {
58459 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58460 + if (gr_shared_page[j] == NULL) {
58461 + panic("Unable to allocate grsecurity shared page");
58462 + return;
58463 + }
58464 + }
58465 +
58466 + /* allocate log buffers */
58467 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58468 + if (!gr_alert_log_fmt) {
58469 + panic("Unable to allocate grsecurity alert log format buffer");
58470 + return;
58471 + }
58472 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58473 + if (!gr_audit_log_fmt) {
58474 + panic("Unable to allocate grsecurity audit log format buffer");
58475 + return;
58476 + }
58477 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58478 + if (!gr_alert_log_buf) {
58479 + panic("Unable to allocate grsecurity alert log buffer");
58480 + return;
58481 + }
58482 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58483 + if (!gr_audit_log_buf) {
58484 + panic("Unable to allocate grsecurity audit log buffer");
58485 + return;
58486 + }
58487 +
58488 + /* allocate memory for authentication structure */
58489 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58490 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58491 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58492 +
58493 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58494 + panic("Unable to allocate grsecurity authentication structure");
58495 + return;
58496 + }
58497 +
58498 +
58499 +#ifdef CONFIG_GRKERNSEC_IO
58500 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58501 + grsec_disable_privio = 1;
58502 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58503 + grsec_disable_privio = 1;
58504 +#else
58505 + grsec_disable_privio = 0;
58506 +#endif
58507 +#endif
58508 +
58509 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58510 + /* for backward compatibility, tpe_invert always defaults to on if
58511 + enabled in the kernel
58512 + */
58513 + grsec_enable_tpe_invert = 1;
58514 +#endif
58515 +
58516 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58517 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58518 + grsec_lock = 1;
58519 +#endif
58520 +
58521 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58522 + grsec_enable_audit_textrel = 1;
58523 +#endif
58524 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58525 + grsec_enable_log_rwxmaps = 1;
58526 +#endif
58527 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58528 + grsec_enable_group = 1;
58529 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58530 +#endif
58531 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58532 + grsec_enable_ptrace_readexec = 1;
58533 +#endif
58534 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58535 + grsec_enable_chdir = 1;
58536 +#endif
58537 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58538 + grsec_enable_harden_ptrace = 1;
58539 +#endif
58540 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58541 + grsec_enable_mount = 1;
58542 +#endif
58543 +#ifdef CONFIG_GRKERNSEC_LINK
58544 + grsec_enable_link = 1;
58545 +#endif
58546 +#ifdef CONFIG_GRKERNSEC_BRUTE
58547 + grsec_enable_brute = 1;
58548 +#endif
58549 +#ifdef CONFIG_GRKERNSEC_DMESG
58550 + grsec_enable_dmesg = 1;
58551 +#endif
58552 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58553 + grsec_enable_blackhole = 1;
58554 + grsec_lastack_retries = 4;
58555 +#endif
58556 +#ifdef CONFIG_GRKERNSEC_FIFO
58557 + grsec_enable_fifo = 1;
58558 +#endif
58559 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58560 + grsec_enable_execlog = 1;
58561 +#endif
58562 +#ifdef CONFIG_GRKERNSEC_SETXID
58563 + grsec_enable_setxid = 1;
58564 +#endif
58565 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58566 + grsec_enable_signal = 1;
58567 +#endif
58568 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58569 + grsec_enable_forkfail = 1;
58570 +#endif
58571 +#ifdef CONFIG_GRKERNSEC_TIME
58572 + grsec_enable_time = 1;
58573 +#endif
58574 +#ifdef CONFIG_GRKERNSEC_RESLOG
58575 + grsec_resource_logging = 1;
58576 +#endif
58577 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58578 + grsec_enable_chroot_findtask = 1;
58579 +#endif
58580 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58581 + grsec_enable_chroot_unix = 1;
58582 +#endif
58583 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58584 + grsec_enable_chroot_mount = 1;
58585 +#endif
58586 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58587 + grsec_enable_chroot_fchdir = 1;
58588 +#endif
58589 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58590 + grsec_enable_chroot_shmat = 1;
58591 +#endif
58592 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58593 + grsec_enable_audit_ptrace = 1;
58594 +#endif
58595 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58596 + grsec_enable_chroot_double = 1;
58597 +#endif
58598 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58599 + grsec_enable_chroot_pivot = 1;
58600 +#endif
58601 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58602 + grsec_enable_chroot_chdir = 1;
58603 +#endif
58604 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58605 + grsec_enable_chroot_chmod = 1;
58606 +#endif
58607 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58608 + grsec_enable_chroot_mknod = 1;
58609 +#endif
58610 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58611 + grsec_enable_chroot_nice = 1;
58612 +#endif
58613 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58614 + grsec_enable_chroot_execlog = 1;
58615 +#endif
58616 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58617 + grsec_enable_chroot_caps = 1;
58618 +#endif
58619 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58620 + grsec_enable_chroot_sysctl = 1;
58621 +#endif
58622 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58623 + grsec_enable_symlinkown = 1;
58624 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58625 +#endif
58626 +#ifdef CONFIG_GRKERNSEC_TPE
58627 + grsec_enable_tpe = 1;
58628 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58629 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58630 + grsec_enable_tpe_all = 1;
58631 +#endif
58632 +#endif
58633 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58634 + grsec_enable_socket_all = 1;
58635 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58636 +#endif
58637 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58638 + grsec_enable_socket_client = 1;
58639 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58640 +#endif
58641 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58642 + grsec_enable_socket_server = 1;
58643 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58644 +#endif
58645 +#endif
58646 +
58647 + return;
58648 +}
58649 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58650 new file mode 100644
58651 index 0000000..589481f
58652 --- /dev/null
58653 +++ b/grsecurity/grsec_link.c
58654 @@ -0,0 +1,58 @@
58655 +#include <linux/kernel.h>
58656 +#include <linux/sched.h>
58657 +#include <linux/fs.h>
58658 +#include <linux/file.h>
58659 +#include <linux/grinternal.h>
58660 +
58661 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58662 +{
58663 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58664 + const struct inode *link_inode = link->dentry->d_inode;
58665 +
58666 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58667 + /* ignore root-owned links, e.g. /proc/self */
58668 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58669 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58670 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58671 + return 1;
58672 + }
58673 +#endif
58674 + return 0;
58675 +}
58676 +
58677 +int
58678 +gr_handle_follow_link(const struct inode *parent,
58679 + const struct inode *inode,
58680 + const struct dentry *dentry, const struct vfsmount *mnt)
58681 +{
58682 +#ifdef CONFIG_GRKERNSEC_LINK
58683 + const struct cred *cred = current_cred();
58684 +
58685 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58686 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58687 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58688 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58689 + return -EACCES;
58690 + }
58691 +#endif
58692 + return 0;
58693 +}
58694 +
58695 +int
58696 +gr_handle_hardlink(const struct dentry *dentry,
58697 + const struct vfsmount *mnt,
58698 + struct inode *inode, const int mode, const char *to)
58699 +{
58700 +#ifdef CONFIG_GRKERNSEC_LINK
58701 + const struct cred *cred = current_cred();
58702 +
58703 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58704 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58705 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58706 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58707 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58708 + return -EPERM;
58709 + }
58710 +#endif
58711 + return 0;
58712 +}
58713 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58714 new file mode 100644
58715 index 0000000..a45d2e9
58716 --- /dev/null
58717 +++ b/grsecurity/grsec_log.c
58718 @@ -0,0 +1,322 @@
58719 +#include <linux/kernel.h>
58720 +#include <linux/sched.h>
58721 +#include <linux/file.h>
58722 +#include <linux/tty.h>
58723 +#include <linux/fs.h>
58724 +#include <linux/grinternal.h>
58725 +
58726 +#ifdef CONFIG_TREE_PREEMPT_RCU
58727 +#define DISABLE_PREEMPT() preempt_disable()
58728 +#define ENABLE_PREEMPT() preempt_enable()
58729 +#else
58730 +#define DISABLE_PREEMPT()
58731 +#define ENABLE_PREEMPT()
58732 +#endif
58733 +
58734 +#define BEGIN_LOCKS(x) \
58735 + DISABLE_PREEMPT(); \
58736 + rcu_read_lock(); \
58737 + read_lock(&tasklist_lock); \
58738 + read_lock(&grsec_exec_file_lock); \
58739 + if (x != GR_DO_AUDIT) \
58740 + spin_lock(&grsec_alert_lock); \
58741 + else \
58742 + spin_lock(&grsec_audit_lock)
58743 +
58744 +#define END_LOCKS(x) \
58745 + if (x != GR_DO_AUDIT) \
58746 + spin_unlock(&grsec_alert_lock); \
58747 + else \
58748 + spin_unlock(&grsec_audit_lock); \
58749 + read_unlock(&grsec_exec_file_lock); \
58750 + read_unlock(&tasklist_lock); \
58751 + rcu_read_unlock(); \
58752 + ENABLE_PREEMPT(); \
58753 + if (x == GR_DONT_AUDIT) \
58754 + gr_handle_alertkill(current)
58755 +
58756 +enum {
58757 + FLOODING,
58758 + NO_FLOODING
58759 +};
58760 +
58761 +extern char *gr_alert_log_fmt;
58762 +extern char *gr_audit_log_fmt;
58763 +extern char *gr_alert_log_buf;
58764 +extern char *gr_audit_log_buf;
58765 +
58766 +static int gr_log_start(int audit)
58767 +{
58768 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58769 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58770 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58771 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58772 + unsigned long curr_secs = get_seconds();
58773 +
58774 + if (audit == GR_DO_AUDIT)
58775 + goto set_fmt;
58776 +
58777 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58778 + grsec_alert_wtime = curr_secs;
58779 + grsec_alert_fyet = 0;
58780 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58781 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58782 + grsec_alert_fyet++;
58783 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58784 + grsec_alert_wtime = curr_secs;
58785 + grsec_alert_fyet++;
58786 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58787 + return FLOODING;
58788 + }
58789 + else return FLOODING;
58790 +
58791 +set_fmt:
58792 +#endif
58793 + memset(buf, 0, PAGE_SIZE);
58794 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58795 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58796 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58797 + } else if (current->signal->curr_ip) {
58798 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58799 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58800 + } else if (gr_acl_is_enabled()) {
58801 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58802 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58803 + } else {
58804 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58805 + strcpy(buf, fmt);
58806 + }
58807 +
58808 + return NO_FLOODING;
58809 +}
58810 +
58811 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58812 + __attribute__ ((format (printf, 2, 0)));
58813 +
58814 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58815 +{
58816 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58817 + unsigned int len = strlen(buf);
58818 +
58819 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58820 +
58821 + return;
58822 +}
58823 +
58824 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58825 + __attribute__ ((format (printf, 2, 3)));
58826 +
58827 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58828 +{
58829 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58830 + unsigned int len = strlen(buf);
58831 + va_list ap;
58832 +
58833 + va_start(ap, msg);
58834 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58835 + va_end(ap);
58836 +
58837 + return;
58838 +}
58839 +
58840 +static void gr_log_end(int audit, int append_default)
58841 +{
58842 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58843 +
58844 + if (append_default) {
58845 + unsigned int len = strlen(buf);
58846 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58847 + }
58848 +
58849 + printk("%s\n", buf);
58850 +
58851 + return;
58852 +}
58853 +
58854 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58855 +{
58856 + int logtype;
58857 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58858 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58859 + void *voidptr = NULL;
58860 + int num1 = 0, num2 = 0;
58861 + unsigned long ulong1 = 0, ulong2 = 0;
58862 + struct dentry *dentry = NULL;
58863 + struct vfsmount *mnt = NULL;
58864 + struct file *file = NULL;
58865 + struct task_struct *task = NULL;
58866 + const struct cred *cred, *pcred;
58867 + va_list ap;
58868 +
58869 + BEGIN_LOCKS(audit);
58870 + logtype = gr_log_start(audit);
58871 + if (logtype == FLOODING) {
58872 + END_LOCKS(audit);
58873 + return;
58874 + }
58875 + va_start(ap, argtypes);
58876 + switch (argtypes) {
58877 + case GR_TTYSNIFF:
58878 + task = va_arg(ap, struct task_struct *);
58879 + 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);
58880 + break;
58881 + case GR_SYSCTL_HIDDEN:
58882 + str1 = va_arg(ap, char *);
58883 + gr_log_middle_varargs(audit, msg, result, str1);
58884 + break;
58885 + case GR_RBAC:
58886 + dentry = va_arg(ap, struct dentry *);
58887 + mnt = va_arg(ap, struct vfsmount *);
58888 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58889 + break;
58890 + case GR_RBAC_STR:
58891 + dentry = va_arg(ap, struct dentry *);
58892 + mnt = va_arg(ap, struct vfsmount *);
58893 + str1 = va_arg(ap, char *);
58894 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58895 + break;
58896 + case GR_STR_RBAC:
58897 + str1 = va_arg(ap, char *);
58898 + dentry = va_arg(ap, struct dentry *);
58899 + mnt = va_arg(ap, struct vfsmount *);
58900 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58901 + break;
58902 + case GR_RBAC_MODE2:
58903 + dentry = va_arg(ap, struct dentry *);
58904 + mnt = va_arg(ap, struct vfsmount *);
58905 + str1 = va_arg(ap, char *);
58906 + str2 = va_arg(ap, char *);
58907 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58908 + break;
58909 + case GR_RBAC_MODE3:
58910 + dentry = va_arg(ap, struct dentry *);
58911 + mnt = va_arg(ap, struct vfsmount *);
58912 + str1 = va_arg(ap, char *);
58913 + str2 = va_arg(ap, char *);
58914 + str3 = va_arg(ap, char *);
58915 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58916 + break;
58917 + case GR_FILENAME:
58918 + dentry = va_arg(ap, struct dentry *);
58919 + mnt = va_arg(ap, struct vfsmount *);
58920 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58921 + break;
58922 + case GR_STR_FILENAME:
58923 + str1 = va_arg(ap, char *);
58924 + dentry = va_arg(ap, struct dentry *);
58925 + mnt = va_arg(ap, struct vfsmount *);
58926 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58927 + break;
58928 + case GR_FILENAME_STR:
58929 + dentry = va_arg(ap, struct dentry *);
58930 + mnt = va_arg(ap, struct vfsmount *);
58931 + str1 = va_arg(ap, char *);
58932 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58933 + break;
58934 + case GR_FILENAME_TWO_INT:
58935 + dentry = va_arg(ap, struct dentry *);
58936 + mnt = va_arg(ap, struct vfsmount *);
58937 + num1 = va_arg(ap, int);
58938 + num2 = va_arg(ap, int);
58939 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58940 + break;
58941 + case GR_FILENAME_TWO_INT_STR:
58942 + dentry = va_arg(ap, struct dentry *);
58943 + mnt = va_arg(ap, struct vfsmount *);
58944 + num1 = va_arg(ap, int);
58945 + num2 = va_arg(ap, int);
58946 + str1 = va_arg(ap, char *);
58947 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58948 + break;
58949 + case GR_TEXTREL:
58950 + file = va_arg(ap, struct file *);
58951 + ulong1 = va_arg(ap, unsigned long);
58952 + ulong2 = va_arg(ap, unsigned long);
58953 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58954 + break;
58955 + case GR_PTRACE:
58956 + task = va_arg(ap, struct task_struct *);
58957 + 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);
58958 + break;
58959 + case GR_RESOURCE:
58960 + task = va_arg(ap, struct task_struct *);
58961 + cred = __task_cred(task);
58962 + pcred = __task_cred(task->real_parent);
58963 + ulong1 = va_arg(ap, unsigned long);
58964 + str1 = va_arg(ap, char *);
58965 + ulong2 = va_arg(ap, unsigned long);
58966 + 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);
58967 + break;
58968 + case GR_CAP:
58969 + task = va_arg(ap, struct task_struct *);
58970 + cred = __task_cred(task);
58971 + pcred = __task_cred(task->real_parent);
58972 + str1 = va_arg(ap, char *);
58973 + 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);
58974 + break;
58975 + case GR_SIG:
58976 + str1 = va_arg(ap, char *);
58977 + voidptr = va_arg(ap, void *);
58978 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58979 + break;
58980 + case GR_SIG2:
58981 + task = va_arg(ap, struct task_struct *);
58982 + cred = __task_cred(task);
58983 + pcred = __task_cred(task->real_parent);
58984 + num1 = va_arg(ap, int);
58985 + 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);
58986 + break;
58987 + case GR_CRASH1:
58988 + task = va_arg(ap, struct task_struct *);
58989 + cred = __task_cred(task);
58990 + pcred = __task_cred(task->real_parent);
58991 + ulong1 = va_arg(ap, unsigned long);
58992 + 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);
58993 + break;
58994 + case GR_CRASH2:
58995 + task = va_arg(ap, struct task_struct *);
58996 + cred = __task_cred(task);
58997 + pcred = __task_cred(task->real_parent);
58998 + ulong1 = va_arg(ap, unsigned long);
58999 + 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);
59000 + break;
59001 + case GR_RWXMAP:
59002 + file = va_arg(ap, struct file *);
59003 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59004 + break;
59005 + case GR_PSACCT:
59006 + {
59007 + unsigned int wday, cday;
59008 + __u8 whr, chr;
59009 + __u8 wmin, cmin;
59010 + __u8 wsec, csec;
59011 + char cur_tty[64] = { 0 };
59012 + char parent_tty[64] = { 0 };
59013 +
59014 + task = va_arg(ap, struct task_struct *);
59015 + wday = va_arg(ap, unsigned int);
59016 + cday = va_arg(ap, unsigned int);
59017 + whr = va_arg(ap, int);
59018 + chr = va_arg(ap, int);
59019 + wmin = va_arg(ap, int);
59020 + cmin = va_arg(ap, int);
59021 + wsec = va_arg(ap, int);
59022 + csec = va_arg(ap, int);
59023 + ulong1 = va_arg(ap, unsigned long);
59024 + cred = __task_cred(task);
59025 + pcred = __task_cred(task->real_parent);
59026 +
59027 + 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);
59028 + }
59029 + break;
59030 + default:
59031 + gr_log_middle(audit, msg, ap);
59032 + }
59033 + va_end(ap);
59034 + // these don't need DEFAULTSECARGS printed on the end
59035 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59036 + gr_log_end(audit, 0);
59037 + else
59038 + gr_log_end(audit, 1);
59039 + END_LOCKS(audit);
59040 +}
59041 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59042 new file mode 100644
59043 index 0000000..f536303
59044 --- /dev/null
59045 +++ b/grsecurity/grsec_mem.c
59046 @@ -0,0 +1,40 @@
59047 +#include <linux/kernel.h>
59048 +#include <linux/sched.h>
59049 +#include <linux/mm.h>
59050 +#include <linux/mman.h>
59051 +#include <linux/grinternal.h>
59052 +
59053 +void
59054 +gr_handle_ioperm(void)
59055 +{
59056 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59057 + return;
59058 +}
59059 +
59060 +void
59061 +gr_handle_iopl(void)
59062 +{
59063 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59064 + return;
59065 +}
59066 +
59067 +void
59068 +gr_handle_mem_readwrite(u64 from, u64 to)
59069 +{
59070 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59071 + return;
59072 +}
59073 +
59074 +void
59075 +gr_handle_vm86(void)
59076 +{
59077 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59078 + return;
59079 +}
59080 +
59081 +void
59082 +gr_log_badprocpid(const char *entry)
59083 +{
59084 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59085 + return;
59086 +}
59087 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59088 new file mode 100644
59089 index 0000000..2131422
59090 --- /dev/null
59091 +++ b/grsecurity/grsec_mount.c
59092 @@ -0,0 +1,62 @@
59093 +#include <linux/kernel.h>
59094 +#include <linux/sched.h>
59095 +#include <linux/mount.h>
59096 +#include <linux/grsecurity.h>
59097 +#include <linux/grinternal.h>
59098 +
59099 +void
59100 +gr_log_remount(const char *devname, const int retval)
59101 +{
59102 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59103 + if (grsec_enable_mount && (retval >= 0))
59104 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59105 +#endif
59106 + return;
59107 +}
59108 +
59109 +void
59110 +gr_log_unmount(const char *devname, const int retval)
59111 +{
59112 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59113 + if (grsec_enable_mount && (retval >= 0))
59114 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59115 +#endif
59116 + return;
59117 +}
59118 +
59119 +void
59120 +gr_log_mount(const char *from, const char *to, const int retval)
59121 +{
59122 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59123 + if (grsec_enable_mount && (retval >= 0))
59124 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59125 +#endif
59126 + return;
59127 +}
59128 +
59129 +int
59130 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59131 +{
59132 +#ifdef CONFIG_GRKERNSEC_ROFS
59133 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59134 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59135 + return -EPERM;
59136 + } else
59137 + return 0;
59138 +#endif
59139 + return 0;
59140 +}
59141 +
59142 +int
59143 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59144 +{
59145 +#ifdef CONFIG_GRKERNSEC_ROFS
59146 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59147 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59148 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59149 + return -EPERM;
59150 + } else
59151 + return 0;
59152 +#endif
59153 + return 0;
59154 +}
59155 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59156 new file mode 100644
59157 index 0000000..a3b12a0
59158 --- /dev/null
59159 +++ b/grsecurity/grsec_pax.c
59160 @@ -0,0 +1,36 @@
59161 +#include <linux/kernel.h>
59162 +#include <linux/sched.h>
59163 +#include <linux/mm.h>
59164 +#include <linux/file.h>
59165 +#include <linux/grinternal.h>
59166 +#include <linux/grsecurity.h>
59167 +
59168 +void
59169 +gr_log_textrel(struct vm_area_struct * vma)
59170 +{
59171 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59172 + if (grsec_enable_audit_textrel)
59173 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59174 +#endif
59175 + return;
59176 +}
59177 +
59178 +void
59179 +gr_log_rwxmmap(struct file *file)
59180 +{
59181 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59182 + if (grsec_enable_log_rwxmaps)
59183 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59184 +#endif
59185 + return;
59186 +}
59187 +
59188 +void
59189 +gr_log_rwxmprotect(struct file *file)
59190 +{
59191 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59192 + if (grsec_enable_log_rwxmaps)
59193 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59194 +#endif
59195 + return;
59196 +}
59197 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59198 new file mode 100644
59199 index 0000000..f7f29aa
59200 --- /dev/null
59201 +++ b/grsecurity/grsec_ptrace.c
59202 @@ -0,0 +1,30 @@
59203 +#include <linux/kernel.h>
59204 +#include <linux/sched.h>
59205 +#include <linux/grinternal.h>
59206 +#include <linux/security.h>
59207 +
59208 +void
59209 +gr_audit_ptrace(struct task_struct *task)
59210 +{
59211 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59212 + if (grsec_enable_audit_ptrace)
59213 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59214 +#endif
59215 + return;
59216 +}
59217 +
59218 +int
59219 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59220 +{
59221 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59222 + const struct dentry *dentry = file->f_path.dentry;
59223 + const struct vfsmount *mnt = file->f_path.mnt;
59224 +
59225 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59226 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59227 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59228 + return -EACCES;
59229 + }
59230 +#endif
59231 + return 0;
59232 +}
59233 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59234 new file mode 100644
59235 index 0000000..b4ac94c
59236 --- /dev/null
59237 +++ b/grsecurity/grsec_sig.c
59238 @@ -0,0 +1,209 @@
59239 +#include <linux/kernel.h>
59240 +#include <linux/sched.h>
59241 +#include <linux/delay.h>
59242 +#include <linux/grsecurity.h>
59243 +#include <linux/grinternal.h>
59244 +#include <linux/hardirq.h>
59245 +
59246 +char *signames[] = {
59247 + [SIGSEGV] = "Segmentation fault",
59248 + [SIGILL] = "Illegal instruction",
59249 + [SIGABRT] = "Abort",
59250 + [SIGBUS] = "Invalid alignment/Bus error"
59251 +};
59252 +
59253 +void
59254 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59255 +{
59256 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59257 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59258 + (sig == SIGABRT) || (sig == SIGBUS))) {
59259 + if (t->pid == current->pid) {
59260 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59261 + } else {
59262 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59263 + }
59264 + }
59265 +#endif
59266 + return;
59267 +}
59268 +
59269 +int
59270 +gr_handle_signal(const struct task_struct *p, const int sig)
59271 +{
59272 +#ifdef CONFIG_GRKERNSEC
59273 + /* ignore the 0 signal for protected task checks */
59274 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59275 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59276 + return -EPERM;
59277 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59278 + return -EPERM;
59279 + }
59280 +#endif
59281 + return 0;
59282 +}
59283 +
59284 +#ifdef CONFIG_GRKERNSEC
59285 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59286 +
59287 +int gr_fake_force_sig(int sig, struct task_struct *t)
59288 +{
59289 + unsigned long int flags;
59290 + int ret, blocked, ignored;
59291 + struct k_sigaction *action;
59292 +
59293 + spin_lock_irqsave(&t->sighand->siglock, flags);
59294 + action = &t->sighand->action[sig-1];
59295 + ignored = action->sa.sa_handler == SIG_IGN;
59296 + blocked = sigismember(&t->blocked, sig);
59297 + if (blocked || ignored) {
59298 + action->sa.sa_handler = SIG_DFL;
59299 + if (blocked) {
59300 + sigdelset(&t->blocked, sig);
59301 + recalc_sigpending_and_wake(t);
59302 + }
59303 + }
59304 + if (action->sa.sa_handler == SIG_DFL)
59305 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59306 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59307 +
59308 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59309 +
59310 + return ret;
59311 +}
59312 +#endif
59313 +
59314 +#ifdef CONFIG_GRKERNSEC_BRUTE
59315 +#define GR_USER_BAN_TIME (15 * 60)
59316 +
59317 +static int __get_dumpable(unsigned long mm_flags)
59318 +{
59319 + int ret;
59320 +
59321 + ret = mm_flags & MMF_DUMPABLE_MASK;
59322 + return (ret >= 2) ? 2 : ret;
59323 +}
59324 +#endif
59325 +
59326 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59327 +{
59328 +#ifdef CONFIG_GRKERNSEC_BRUTE
59329 + kuid_t uid = GLOBAL_ROOT_UID;
59330 +
59331 + if (!grsec_enable_brute)
59332 + return;
59333 +
59334 + rcu_read_lock();
59335 + read_lock(&tasklist_lock);
59336 + read_lock(&grsec_exec_file_lock);
59337 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59338 + p->real_parent->brute = 1;
59339 + else {
59340 + const struct cred *cred = __task_cred(p), *cred2;
59341 + struct task_struct *tsk, *tsk2;
59342 +
59343 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59344 + struct user_struct *user;
59345 +
59346 + uid = cred->uid;
59347 +
59348 + /* this is put upon execution past expiration */
59349 + user = find_user(uid);
59350 + if (user == NULL)
59351 + goto unlock;
59352 + user->banned = 1;
59353 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59354 + if (user->ban_expires == ~0UL)
59355 + user->ban_expires--;
59356 +
59357 + do_each_thread(tsk2, tsk) {
59358 + cred2 = __task_cred(tsk);
59359 + if (tsk != p && uid_eq(cred2->uid, uid))
59360 + gr_fake_force_sig(SIGKILL, tsk);
59361 + } while_each_thread(tsk2, tsk);
59362 + }
59363 + }
59364 +unlock:
59365 + read_unlock(&grsec_exec_file_lock);
59366 + read_unlock(&tasklist_lock);
59367 + rcu_read_unlock();
59368 +
59369 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59370 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59371 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59372 +
59373 +#endif
59374 + return;
59375 +}
59376 +
59377 +void gr_handle_brute_check(void)
59378 +{
59379 +#ifdef CONFIG_GRKERNSEC_BRUTE
59380 + if (current->brute)
59381 + msleep(30 * 1000);
59382 +#endif
59383 + return;
59384 +}
59385 +
59386 +void gr_handle_kernel_exploit(void)
59387 +{
59388 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59389 + const struct cred *cred;
59390 + struct task_struct *tsk, *tsk2;
59391 + struct user_struct *user;
59392 + kuid_t uid;
59393 +
59394 + if (in_irq() || in_serving_softirq() || in_nmi())
59395 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59396 +
59397 + uid = current_uid();
59398 +
59399 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59400 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59401 + else {
59402 + /* kill all the processes of this user, hold a reference
59403 + to their creds struct, and prevent them from creating
59404 + another process until system reset
59405 + */
59406 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59407 + from_kuid_munged(&init_user_ns, uid));
59408 + /* we intentionally leak this ref */
59409 + user = get_uid(current->cred->user);
59410 + if (user) {
59411 + user->banned = 1;
59412 + user->ban_expires = ~0UL;
59413 + }
59414 +
59415 + read_lock(&tasklist_lock);
59416 + do_each_thread(tsk2, tsk) {
59417 + cred = __task_cred(tsk);
59418 + if (uid_eq(cred->uid, uid))
59419 + gr_fake_force_sig(SIGKILL, tsk);
59420 + } while_each_thread(tsk2, tsk);
59421 + read_unlock(&tasklist_lock);
59422 + }
59423 +#endif
59424 +}
59425 +
59426 +int __gr_process_user_ban(struct user_struct *user)
59427 +{
59428 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59429 + if (unlikely(user->banned)) {
59430 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59431 + user->banned = 0;
59432 + user->ban_expires = 0;
59433 + free_uid(user);
59434 + } else
59435 + return -EPERM;
59436 + }
59437 +#endif
59438 + return 0;
59439 +}
59440 +
59441 +int gr_process_user_ban(void)
59442 +{
59443 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59444 + return __gr_process_user_ban(current->cred->user);
59445 +#endif
59446 + return 0;
59447 +}
59448 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59449 new file mode 100644
59450 index 0000000..4030d57
59451 --- /dev/null
59452 +++ b/grsecurity/grsec_sock.c
59453 @@ -0,0 +1,244 @@
59454 +#include <linux/kernel.h>
59455 +#include <linux/module.h>
59456 +#include <linux/sched.h>
59457 +#include <linux/file.h>
59458 +#include <linux/net.h>
59459 +#include <linux/in.h>
59460 +#include <linux/ip.h>
59461 +#include <net/sock.h>
59462 +#include <net/inet_sock.h>
59463 +#include <linux/grsecurity.h>
59464 +#include <linux/grinternal.h>
59465 +#include <linux/gracl.h>
59466 +
59467 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59468 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59469 +
59470 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59471 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59472 +
59473 +#ifdef CONFIG_UNIX_MODULE
59474 +EXPORT_SYMBOL(gr_acl_handle_unix);
59475 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59476 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59477 +EXPORT_SYMBOL(gr_handle_create);
59478 +#endif
59479 +
59480 +#ifdef CONFIG_GRKERNSEC
59481 +#define gr_conn_table_size 32749
59482 +struct conn_table_entry {
59483 + struct conn_table_entry *next;
59484 + struct signal_struct *sig;
59485 +};
59486 +
59487 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59488 +DEFINE_SPINLOCK(gr_conn_table_lock);
59489 +
59490 +extern const char * gr_socktype_to_name(unsigned char type);
59491 +extern const char * gr_proto_to_name(unsigned char proto);
59492 +extern const char * gr_sockfamily_to_name(unsigned char family);
59493 +
59494 +static __inline__ int
59495 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59496 +{
59497 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59498 +}
59499 +
59500 +static __inline__ int
59501 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59502 + __u16 sport, __u16 dport)
59503 +{
59504 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59505 + sig->gr_sport == sport && sig->gr_dport == dport))
59506 + return 1;
59507 + else
59508 + return 0;
59509 +}
59510 +
59511 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59512 +{
59513 + struct conn_table_entry **match;
59514 + unsigned int index;
59515 +
59516 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59517 + sig->gr_sport, sig->gr_dport,
59518 + gr_conn_table_size);
59519 +
59520 + newent->sig = sig;
59521 +
59522 + match = &gr_conn_table[index];
59523 + newent->next = *match;
59524 + *match = newent;
59525 +
59526 + return;
59527 +}
59528 +
59529 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59530 +{
59531 + struct conn_table_entry *match, *last = NULL;
59532 + unsigned int index;
59533 +
59534 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59535 + sig->gr_sport, sig->gr_dport,
59536 + gr_conn_table_size);
59537 +
59538 + match = gr_conn_table[index];
59539 + while (match && !conn_match(match->sig,
59540 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59541 + sig->gr_dport)) {
59542 + last = match;
59543 + match = match->next;
59544 + }
59545 +
59546 + if (match) {
59547 + if (last)
59548 + last->next = match->next;
59549 + else
59550 + gr_conn_table[index] = NULL;
59551 + kfree(match);
59552 + }
59553 +
59554 + return;
59555 +}
59556 +
59557 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59558 + __u16 sport, __u16 dport)
59559 +{
59560 + struct conn_table_entry *match;
59561 + unsigned int index;
59562 +
59563 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59564 +
59565 + match = gr_conn_table[index];
59566 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59567 + match = match->next;
59568 +
59569 + if (match)
59570 + return match->sig;
59571 + else
59572 + return NULL;
59573 +}
59574 +
59575 +#endif
59576 +
59577 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59578 +{
59579 +#ifdef CONFIG_GRKERNSEC
59580 + struct signal_struct *sig = task->signal;
59581 + struct conn_table_entry *newent;
59582 +
59583 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59584 + if (newent == NULL)
59585 + return;
59586 + /* no bh lock needed since we are called with bh disabled */
59587 + spin_lock(&gr_conn_table_lock);
59588 + gr_del_task_from_ip_table_nolock(sig);
59589 + sig->gr_saddr = inet->inet_rcv_saddr;
59590 + sig->gr_daddr = inet->inet_daddr;
59591 + sig->gr_sport = inet->inet_sport;
59592 + sig->gr_dport = inet->inet_dport;
59593 + gr_add_to_task_ip_table_nolock(sig, newent);
59594 + spin_unlock(&gr_conn_table_lock);
59595 +#endif
59596 + return;
59597 +}
59598 +
59599 +void gr_del_task_from_ip_table(struct task_struct *task)
59600 +{
59601 +#ifdef CONFIG_GRKERNSEC
59602 + spin_lock_bh(&gr_conn_table_lock);
59603 + gr_del_task_from_ip_table_nolock(task->signal);
59604 + spin_unlock_bh(&gr_conn_table_lock);
59605 +#endif
59606 + return;
59607 +}
59608 +
59609 +void
59610 +gr_attach_curr_ip(const struct sock *sk)
59611 +{
59612 +#ifdef CONFIG_GRKERNSEC
59613 + struct signal_struct *p, *set;
59614 + const struct inet_sock *inet = inet_sk(sk);
59615 +
59616 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59617 + return;
59618 +
59619 + set = current->signal;
59620 +
59621 + spin_lock_bh(&gr_conn_table_lock);
59622 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59623 + inet->inet_dport, inet->inet_sport);
59624 + if (unlikely(p != NULL)) {
59625 + set->curr_ip = p->curr_ip;
59626 + set->used_accept = 1;
59627 + gr_del_task_from_ip_table_nolock(p);
59628 + spin_unlock_bh(&gr_conn_table_lock);
59629 + return;
59630 + }
59631 + spin_unlock_bh(&gr_conn_table_lock);
59632 +
59633 + set->curr_ip = inet->inet_daddr;
59634 + set->used_accept = 1;
59635 +#endif
59636 + return;
59637 +}
59638 +
59639 +int
59640 +gr_handle_sock_all(const int family, const int type, const int protocol)
59641 +{
59642 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59643 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59644 + (family != AF_UNIX)) {
59645 + if (family == AF_INET)
59646 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59647 + else
59648 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59649 + return -EACCES;
59650 + }
59651 +#endif
59652 + return 0;
59653 +}
59654 +
59655 +int
59656 +gr_handle_sock_server(const struct sockaddr *sck)
59657 +{
59658 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59659 + if (grsec_enable_socket_server &&
59660 + in_group_p(grsec_socket_server_gid) &&
59661 + sck && (sck->sa_family != AF_UNIX) &&
59662 + (sck->sa_family != AF_LOCAL)) {
59663 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59664 + return -EACCES;
59665 + }
59666 +#endif
59667 + return 0;
59668 +}
59669 +
59670 +int
59671 +gr_handle_sock_server_other(const struct sock *sck)
59672 +{
59673 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59674 + if (grsec_enable_socket_server &&
59675 + in_group_p(grsec_socket_server_gid) &&
59676 + sck && (sck->sk_family != AF_UNIX) &&
59677 + (sck->sk_family != AF_LOCAL)) {
59678 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59679 + return -EACCES;
59680 + }
59681 +#endif
59682 + return 0;
59683 +}
59684 +
59685 +int
59686 +gr_handle_sock_client(const struct sockaddr *sck)
59687 +{
59688 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59689 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59690 + sck && (sck->sa_family != AF_UNIX) &&
59691 + (sck->sa_family != AF_LOCAL)) {
59692 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59693 + return -EACCES;
59694 + }
59695 +#endif
59696 + return 0;
59697 +}
59698 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59699 new file mode 100644
59700 index 0000000..f55ef0f
59701 --- /dev/null
59702 +++ b/grsecurity/grsec_sysctl.c
59703 @@ -0,0 +1,469 @@
59704 +#include <linux/kernel.h>
59705 +#include <linux/sched.h>
59706 +#include <linux/sysctl.h>
59707 +#include <linux/grsecurity.h>
59708 +#include <linux/grinternal.h>
59709 +
59710 +int
59711 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59712 +{
59713 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59714 + if (dirname == NULL || name == NULL)
59715 + return 0;
59716 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59717 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59718 + return -EACCES;
59719 + }
59720 +#endif
59721 + return 0;
59722 +}
59723 +
59724 +#ifdef CONFIG_GRKERNSEC_ROFS
59725 +static int __maybe_unused one = 1;
59726 +#endif
59727 +
59728 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59729 +struct ctl_table grsecurity_table[] = {
59730 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59731 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59732 +#ifdef CONFIG_GRKERNSEC_IO
59733 + {
59734 + .procname = "disable_priv_io",
59735 + .data = &grsec_disable_privio,
59736 + .maxlen = sizeof(int),
59737 + .mode = 0600,
59738 + .proc_handler = &proc_dointvec,
59739 + },
59740 +#endif
59741 +#endif
59742 +#ifdef CONFIG_GRKERNSEC_LINK
59743 + {
59744 + .procname = "linking_restrictions",
59745 + .data = &grsec_enable_link,
59746 + .maxlen = sizeof(int),
59747 + .mode = 0600,
59748 + .proc_handler = &proc_dointvec,
59749 + },
59750 +#endif
59751 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59752 + {
59753 + .procname = "enforce_symlinksifowner",
59754 + .data = &grsec_enable_symlinkown,
59755 + .maxlen = sizeof(int),
59756 + .mode = 0600,
59757 + .proc_handler = &proc_dointvec,
59758 + },
59759 + {
59760 + .procname = "symlinkown_gid",
59761 + .data = &grsec_symlinkown_gid,
59762 + .maxlen = sizeof(int),
59763 + .mode = 0600,
59764 + .proc_handler = &proc_dointvec,
59765 + },
59766 +#endif
59767 +#ifdef CONFIG_GRKERNSEC_BRUTE
59768 + {
59769 + .procname = "deter_bruteforce",
59770 + .data = &grsec_enable_brute,
59771 + .maxlen = sizeof(int),
59772 + .mode = 0600,
59773 + .proc_handler = &proc_dointvec,
59774 + },
59775 +#endif
59776 +#ifdef CONFIG_GRKERNSEC_FIFO
59777 + {
59778 + .procname = "fifo_restrictions",
59779 + .data = &grsec_enable_fifo,
59780 + .maxlen = sizeof(int),
59781 + .mode = 0600,
59782 + .proc_handler = &proc_dointvec,
59783 + },
59784 +#endif
59785 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59786 + {
59787 + .procname = "ptrace_readexec",
59788 + .data = &grsec_enable_ptrace_readexec,
59789 + .maxlen = sizeof(int),
59790 + .mode = 0600,
59791 + .proc_handler = &proc_dointvec,
59792 + },
59793 +#endif
59794 +#ifdef CONFIG_GRKERNSEC_SETXID
59795 + {
59796 + .procname = "consistent_setxid",
59797 + .data = &grsec_enable_setxid,
59798 + .maxlen = sizeof(int),
59799 + .mode = 0600,
59800 + .proc_handler = &proc_dointvec,
59801 + },
59802 +#endif
59803 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59804 + {
59805 + .procname = "ip_blackhole",
59806 + .data = &grsec_enable_blackhole,
59807 + .maxlen = sizeof(int),
59808 + .mode = 0600,
59809 + .proc_handler = &proc_dointvec,
59810 + },
59811 + {
59812 + .procname = "lastack_retries",
59813 + .data = &grsec_lastack_retries,
59814 + .maxlen = sizeof(int),
59815 + .mode = 0600,
59816 + .proc_handler = &proc_dointvec,
59817 + },
59818 +#endif
59819 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59820 + {
59821 + .procname = "exec_logging",
59822 + .data = &grsec_enable_execlog,
59823 + .maxlen = sizeof(int),
59824 + .mode = 0600,
59825 + .proc_handler = &proc_dointvec,
59826 + },
59827 +#endif
59828 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59829 + {
59830 + .procname = "rwxmap_logging",
59831 + .data = &grsec_enable_log_rwxmaps,
59832 + .maxlen = sizeof(int),
59833 + .mode = 0600,
59834 + .proc_handler = &proc_dointvec,
59835 + },
59836 +#endif
59837 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59838 + {
59839 + .procname = "signal_logging",
59840 + .data = &grsec_enable_signal,
59841 + .maxlen = sizeof(int),
59842 + .mode = 0600,
59843 + .proc_handler = &proc_dointvec,
59844 + },
59845 +#endif
59846 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59847 + {
59848 + .procname = "forkfail_logging",
59849 + .data = &grsec_enable_forkfail,
59850 + .maxlen = sizeof(int),
59851 + .mode = 0600,
59852 + .proc_handler = &proc_dointvec,
59853 + },
59854 +#endif
59855 +#ifdef CONFIG_GRKERNSEC_TIME
59856 + {
59857 + .procname = "timechange_logging",
59858 + .data = &grsec_enable_time,
59859 + .maxlen = sizeof(int),
59860 + .mode = 0600,
59861 + .proc_handler = &proc_dointvec,
59862 + },
59863 +#endif
59864 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59865 + {
59866 + .procname = "chroot_deny_shmat",
59867 + .data = &grsec_enable_chroot_shmat,
59868 + .maxlen = sizeof(int),
59869 + .mode = 0600,
59870 + .proc_handler = &proc_dointvec,
59871 + },
59872 +#endif
59873 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59874 + {
59875 + .procname = "chroot_deny_unix",
59876 + .data = &grsec_enable_chroot_unix,
59877 + .maxlen = sizeof(int),
59878 + .mode = 0600,
59879 + .proc_handler = &proc_dointvec,
59880 + },
59881 +#endif
59882 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59883 + {
59884 + .procname = "chroot_deny_mount",
59885 + .data = &grsec_enable_chroot_mount,
59886 + .maxlen = sizeof(int),
59887 + .mode = 0600,
59888 + .proc_handler = &proc_dointvec,
59889 + },
59890 +#endif
59891 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59892 + {
59893 + .procname = "chroot_deny_fchdir",
59894 + .data = &grsec_enable_chroot_fchdir,
59895 + .maxlen = sizeof(int),
59896 + .mode = 0600,
59897 + .proc_handler = &proc_dointvec,
59898 + },
59899 +#endif
59900 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59901 + {
59902 + .procname = "chroot_deny_chroot",
59903 + .data = &grsec_enable_chroot_double,
59904 + .maxlen = sizeof(int),
59905 + .mode = 0600,
59906 + .proc_handler = &proc_dointvec,
59907 + },
59908 +#endif
59909 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59910 + {
59911 + .procname = "chroot_deny_pivot",
59912 + .data = &grsec_enable_chroot_pivot,
59913 + .maxlen = sizeof(int),
59914 + .mode = 0600,
59915 + .proc_handler = &proc_dointvec,
59916 + },
59917 +#endif
59918 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59919 + {
59920 + .procname = "chroot_enforce_chdir",
59921 + .data = &grsec_enable_chroot_chdir,
59922 + .maxlen = sizeof(int),
59923 + .mode = 0600,
59924 + .proc_handler = &proc_dointvec,
59925 + },
59926 +#endif
59927 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59928 + {
59929 + .procname = "chroot_deny_chmod",
59930 + .data = &grsec_enable_chroot_chmod,
59931 + .maxlen = sizeof(int),
59932 + .mode = 0600,
59933 + .proc_handler = &proc_dointvec,
59934 + },
59935 +#endif
59936 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59937 + {
59938 + .procname = "chroot_deny_mknod",
59939 + .data = &grsec_enable_chroot_mknod,
59940 + .maxlen = sizeof(int),
59941 + .mode = 0600,
59942 + .proc_handler = &proc_dointvec,
59943 + },
59944 +#endif
59945 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59946 + {
59947 + .procname = "chroot_restrict_nice",
59948 + .data = &grsec_enable_chroot_nice,
59949 + .maxlen = sizeof(int),
59950 + .mode = 0600,
59951 + .proc_handler = &proc_dointvec,
59952 + },
59953 +#endif
59954 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59955 + {
59956 + .procname = "chroot_execlog",
59957 + .data = &grsec_enable_chroot_execlog,
59958 + .maxlen = sizeof(int),
59959 + .mode = 0600,
59960 + .proc_handler = &proc_dointvec,
59961 + },
59962 +#endif
59963 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59964 + {
59965 + .procname = "chroot_caps",
59966 + .data = &grsec_enable_chroot_caps,
59967 + .maxlen = sizeof(int),
59968 + .mode = 0600,
59969 + .proc_handler = &proc_dointvec,
59970 + },
59971 +#endif
59972 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59973 + {
59974 + .procname = "chroot_deny_sysctl",
59975 + .data = &grsec_enable_chroot_sysctl,
59976 + .maxlen = sizeof(int),
59977 + .mode = 0600,
59978 + .proc_handler = &proc_dointvec,
59979 + },
59980 +#endif
59981 +#ifdef CONFIG_GRKERNSEC_TPE
59982 + {
59983 + .procname = "tpe",
59984 + .data = &grsec_enable_tpe,
59985 + .maxlen = sizeof(int),
59986 + .mode = 0600,
59987 + .proc_handler = &proc_dointvec,
59988 + },
59989 + {
59990 + .procname = "tpe_gid",
59991 + .data = &grsec_tpe_gid,
59992 + .maxlen = sizeof(int),
59993 + .mode = 0600,
59994 + .proc_handler = &proc_dointvec,
59995 + },
59996 +#endif
59997 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59998 + {
59999 + .procname = "tpe_invert",
60000 + .data = &grsec_enable_tpe_invert,
60001 + .maxlen = sizeof(int),
60002 + .mode = 0600,
60003 + .proc_handler = &proc_dointvec,
60004 + },
60005 +#endif
60006 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60007 + {
60008 + .procname = "tpe_restrict_all",
60009 + .data = &grsec_enable_tpe_all,
60010 + .maxlen = sizeof(int),
60011 + .mode = 0600,
60012 + .proc_handler = &proc_dointvec,
60013 + },
60014 +#endif
60015 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60016 + {
60017 + .procname = "socket_all",
60018 + .data = &grsec_enable_socket_all,
60019 + .maxlen = sizeof(int),
60020 + .mode = 0600,
60021 + .proc_handler = &proc_dointvec,
60022 + },
60023 + {
60024 + .procname = "socket_all_gid",
60025 + .data = &grsec_socket_all_gid,
60026 + .maxlen = sizeof(int),
60027 + .mode = 0600,
60028 + .proc_handler = &proc_dointvec,
60029 + },
60030 +#endif
60031 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60032 + {
60033 + .procname = "socket_client",
60034 + .data = &grsec_enable_socket_client,
60035 + .maxlen = sizeof(int),
60036 + .mode = 0600,
60037 + .proc_handler = &proc_dointvec,
60038 + },
60039 + {
60040 + .procname = "socket_client_gid",
60041 + .data = &grsec_socket_client_gid,
60042 + .maxlen = sizeof(int),
60043 + .mode = 0600,
60044 + .proc_handler = &proc_dointvec,
60045 + },
60046 +#endif
60047 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60048 + {
60049 + .procname = "socket_server",
60050 + .data = &grsec_enable_socket_server,
60051 + .maxlen = sizeof(int),
60052 + .mode = 0600,
60053 + .proc_handler = &proc_dointvec,
60054 + },
60055 + {
60056 + .procname = "socket_server_gid",
60057 + .data = &grsec_socket_server_gid,
60058 + .maxlen = sizeof(int),
60059 + .mode = 0600,
60060 + .proc_handler = &proc_dointvec,
60061 + },
60062 +#endif
60063 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60064 + {
60065 + .procname = "audit_group",
60066 + .data = &grsec_enable_group,
60067 + .maxlen = sizeof(int),
60068 + .mode = 0600,
60069 + .proc_handler = &proc_dointvec,
60070 + },
60071 + {
60072 + .procname = "audit_gid",
60073 + .data = &grsec_audit_gid,
60074 + .maxlen = sizeof(int),
60075 + .mode = 0600,
60076 + .proc_handler = &proc_dointvec,
60077 + },
60078 +#endif
60079 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60080 + {
60081 + .procname = "audit_chdir",
60082 + .data = &grsec_enable_chdir,
60083 + .maxlen = sizeof(int),
60084 + .mode = 0600,
60085 + .proc_handler = &proc_dointvec,
60086 + },
60087 +#endif
60088 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60089 + {
60090 + .procname = "audit_mount",
60091 + .data = &grsec_enable_mount,
60092 + .maxlen = sizeof(int),
60093 + .mode = 0600,
60094 + .proc_handler = &proc_dointvec,
60095 + },
60096 +#endif
60097 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60098 + {
60099 + .procname = "audit_textrel",
60100 + .data = &grsec_enable_audit_textrel,
60101 + .maxlen = sizeof(int),
60102 + .mode = 0600,
60103 + .proc_handler = &proc_dointvec,
60104 + },
60105 +#endif
60106 +#ifdef CONFIG_GRKERNSEC_DMESG
60107 + {
60108 + .procname = "dmesg",
60109 + .data = &grsec_enable_dmesg,
60110 + .maxlen = sizeof(int),
60111 + .mode = 0600,
60112 + .proc_handler = &proc_dointvec,
60113 + },
60114 +#endif
60115 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60116 + {
60117 + .procname = "chroot_findtask",
60118 + .data = &grsec_enable_chroot_findtask,
60119 + .maxlen = sizeof(int),
60120 + .mode = 0600,
60121 + .proc_handler = &proc_dointvec,
60122 + },
60123 +#endif
60124 +#ifdef CONFIG_GRKERNSEC_RESLOG
60125 + {
60126 + .procname = "resource_logging",
60127 + .data = &grsec_resource_logging,
60128 + .maxlen = sizeof(int),
60129 + .mode = 0600,
60130 + .proc_handler = &proc_dointvec,
60131 + },
60132 +#endif
60133 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60134 + {
60135 + .procname = "audit_ptrace",
60136 + .data = &grsec_enable_audit_ptrace,
60137 + .maxlen = sizeof(int),
60138 + .mode = 0600,
60139 + .proc_handler = &proc_dointvec,
60140 + },
60141 +#endif
60142 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60143 + {
60144 + .procname = "harden_ptrace",
60145 + .data = &grsec_enable_harden_ptrace,
60146 + .maxlen = sizeof(int),
60147 + .mode = 0600,
60148 + .proc_handler = &proc_dointvec,
60149 + },
60150 +#endif
60151 + {
60152 + .procname = "grsec_lock",
60153 + .data = &grsec_lock,
60154 + .maxlen = sizeof(int),
60155 + .mode = 0600,
60156 + .proc_handler = &proc_dointvec,
60157 + },
60158 +#endif
60159 +#ifdef CONFIG_GRKERNSEC_ROFS
60160 + {
60161 + .procname = "romount_protect",
60162 + .data = &grsec_enable_rofs,
60163 + .maxlen = sizeof(int),
60164 + .mode = 0600,
60165 + .proc_handler = &proc_dointvec_minmax,
60166 + .extra1 = &one,
60167 + .extra2 = &one,
60168 + },
60169 +#endif
60170 + { }
60171 +};
60172 +#endif
60173 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60174 new file mode 100644
60175 index 0000000..0dc13c3
60176 --- /dev/null
60177 +++ b/grsecurity/grsec_time.c
60178 @@ -0,0 +1,16 @@
60179 +#include <linux/kernel.h>
60180 +#include <linux/sched.h>
60181 +#include <linux/grinternal.h>
60182 +#include <linux/module.h>
60183 +
60184 +void
60185 +gr_log_timechange(void)
60186 +{
60187 +#ifdef CONFIG_GRKERNSEC_TIME
60188 + if (grsec_enable_time)
60189 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60190 +#endif
60191 + return;
60192 +}
60193 +
60194 +EXPORT_SYMBOL(gr_log_timechange);
60195 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60196 new file mode 100644
60197 index 0000000..07e0dc0
60198 --- /dev/null
60199 +++ b/grsecurity/grsec_tpe.c
60200 @@ -0,0 +1,73 @@
60201 +#include <linux/kernel.h>
60202 +#include <linux/sched.h>
60203 +#include <linux/file.h>
60204 +#include <linux/fs.h>
60205 +#include <linux/grinternal.h>
60206 +
60207 +extern int gr_acl_tpe_check(void);
60208 +
60209 +int
60210 +gr_tpe_allow(const struct file *file)
60211 +{
60212 +#ifdef CONFIG_GRKERNSEC
60213 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60214 + const struct cred *cred = current_cred();
60215 + char *msg = NULL;
60216 + char *msg2 = NULL;
60217 +
60218 + // never restrict root
60219 + if (!cred->uid)
60220 + return 1;
60221 +
60222 + if (grsec_enable_tpe) {
60223 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60224 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60225 + msg = "not being in trusted group";
60226 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60227 + msg = "being in untrusted group";
60228 +#else
60229 + if (in_group_p(grsec_tpe_gid))
60230 + msg = "being in untrusted group";
60231 +#endif
60232 + }
60233 + if (!msg && gr_acl_tpe_check())
60234 + msg = "being in untrusted role";
60235 +
60236 + // not in any affected group/role
60237 + if (!msg)
60238 + goto next_check;
60239 +
60240 + if (inode->i_uid)
60241 + msg2 = "file in non-root-owned directory";
60242 + else if (inode->i_mode & S_IWOTH)
60243 + msg2 = "file in world-writable directory";
60244 + else if (inode->i_mode & S_IWGRP)
60245 + msg2 = "file in group-writable directory";
60246 +
60247 + if (msg && msg2) {
60248 + char fullmsg[70] = {0};
60249 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60250 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60251 + return 0;
60252 + }
60253 + msg = NULL;
60254 +next_check:
60255 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60256 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60257 + return 1;
60258 +
60259 + if (inode->i_uid && (inode->i_uid != cred->uid))
60260 + msg = "directory not owned by user";
60261 + else if (inode->i_mode & S_IWOTH)
60262 + msg = "file in world-writable directory";
60263 + else if (inode->i_mode & S_IWGRP)
60264 + msg = "file in group-writable directory";
60265 +
60266 + if (msg) {
60267 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60268 + return 0;
60269 + }
60270 +#endif
60271 +#endif
60272 + return 1;
60273 +}
60274 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60275 new file mode 100644
60276 index 0000000..9f7b1ac
60277 --- /dev/null
60278 +++ b/grsecurity/grsum.c
60279 @@ -0,0 +1,61 @@
60280 +#include <linux/err.h>
60281 +#include <linux/kernel.h>
60282 +#include <linux/sched.h>
60283 +#include <linux/mm.h>
60284 +#include <linux/scatterlist.h>
60285 +#include <linux/crypto.h>
60286 +#include <linux/gracl.h>
60287 +
60288 +
60289 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60290 +#error "crypto and sha256 must be built into the kernel"
60291 +#endif
60292 +
60293 +int
60294 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60295 +{
60296 + char *p;
60297 + struct crypto_hash *tfm;
60298 + struct hash_desc desc;
60299 + struct scatterlist sg;
60300 + unsigned char temp_sum[GR_SHA_LEN];
60301 + volatile int retval = 0;
60302 + volatile int dummy = 0;
60303 + unsigned int i;
60304 +
60305 + sg_init_table(&sg, 1);
60306 +
60307 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60308 + if (IS_ERR(tfm)) {
60309 + /* should never happen, since sha256 should be built in */
60310 + return 1;
60311 + }
60312 +
60313 + desc.tfm = tfm;
60314 + desc.flags = 0;
60315 +
60316 + crypto_hash_init(&desc);
60317 +
60318 + p = salt;
60319 + sg_set_buf(&sg, p, GR_SALT_LEN);
60320 + crypto_hash_update(&desc, &sg, sg.length);
60321 +
60322 + p = entry->pw;
60323 + sg_set_buf(&sg, p, strlen(p));
60324 +
60325 + crypto_hash_update(&desc, &sg, sg.length);
60326 +
60327 + crypto_hash_final(&desc, temp_sum);
60328 +
60329 + memset(entry->pw, 0, GR_PW_LEN);
60330 +
60331 + for (i = 0; i < GR_SHA_LEN; i++)
60332 + if (sum[i] != temp_sum[i])
60333 + retval = 1;
60334 + else
60335 + dummy = 1; // waste a cycle
60336 +
60337 + crypto_free_hash(tfm);
60338 +
60339 + return retval;
60340 +}
60341 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60342 index bde976e..a1cc32a 100644
60343 --- a/include/acpi/acpi_bus.h
60344 +++ b/include/acpi/acpi_bus.h
60345 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60346 acpi_op_bind bind;
60347 acpi_op_unbind unbind;
60348 acpi_op_notify notify;
60349 -};
60350 +} __no_const;
60351
60352 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60353
60354 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60355 index 77ff547..181834f 100644
60356 --- a/include/asm-generic/4level-fixup.h
60357 +++ b/include/asm-generic/4level-fixup.h
60358 @@ -13,8 +13,10 @@
60359 #define pmd_alloc(mm, pud, address) \
60360 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60361 NULL: pmd_offset(pud, address))
60362 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60363
60364 #define pud_alloc(mm, pgd, address) (pgd)
60365 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60366 #define pud_offset(pgd, start) (pgd)
60367 #define pud_none(pud) 0
60368 #define pud_bad(pud) 0
60369 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60370 index b7babf0..3ba8aee 100644
60371 --- a/include/asm-generic/atomic-long.h
60372 +++ b/include/asm-generic/atomic-long.h
60373 @@ -22,6 +22,12 @@
60374
60375 typedef atomic64_t atomic_long_t;
60376
60377 +#ifdef CONFIG_PAX_REFCOUNT
60378 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60379 +#else
60380 +typedef atomic64_t atomic_long_unchecked_t;
60381 +#endif
60382 +
60383 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60384
60385 static inline long atomic_long_read(atomic_long_t *l)
60386 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60387 return (long)atomic64_read(v);
60388 }
60389
60390 +#ifdef CONFIG_PAX_REFCOUNT
60391 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60392 +{
60393 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60394 +
60395 + return (long)atomic64_read_unchecked(v);
60396 +}
60397 +#endif
60398 +
60399 static inline void atomic_long_set(atomic_long_t *l, long i)
60400 {
60401 atomic64_t *v = (atomic64_t *)l;
60402 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60403 atomic64_set(v, i);
60404 }
60405
60406 +#ifdef CONFIG_PAX_REFCOUNT
60407 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60408 +{
60409 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60410 +
60411 + atomic64_set_unchecked(v, i);
60412 +}
60413 +#endif
60414 +
60415 static inline void atomic_long_inc(atomic_long_t *l)
60416 {
60417 atomic64_t *v = (atomic64_t *)l;
60418 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60419 atomic64_inc(v);
60420 }
60421
60422 +#ifdef CONFIG_PAX_REFCOUNT
60423 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60424 +{
60425 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60426 +
60427 + atomic64_inc_unchecked(v);
60428 +}
60429 +#endif
60430 +
60431 static inline void atomic_long_dec(atomic_long_t *l)
60432 {
60433 atomic64_t *v = (atomic64_t *)l;
60434 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60435 atomic64_dec(v);
60436 }
60437
60438 +#ifdef CONFIG_PAX_REFCOUNT
60439 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60440 +{
60441 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60442 +
60443 + atomic64_dec_unchecked(v);
60444 +}
60445 +#endif
60446 +
60447 static inline void atomic_long_add(long i, atomic_long_t *l)
60448 {
60449 atomic64_t *v = (atomic64_t *)l;
60450 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60451 atomic64_add(i, v);
60452 }
60453
60454 +#ifdef CONFIG_PAX_REFCOUNT
60455 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60456 +{
60457 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60458 +
60459 + atomic64_add_unchecked(i, v);
60460 +}
60461 +#endif
60462 +
60463 static inline void atomic_long_sub(long i, atomic_long_t *l)
60464 {
60465 atomic64_t *v = (atomic64_t *)l;
60466 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60467 atomic64_sub(i, v);
60468 }
60469
60470 +#ifdef CONFIG_PAX_REFCOUNT
60471 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60472 +{
60473 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60474 +
60475 + atomic64_sub_unchecked(i, v);
60476 +}
60477 +#endif
60478 +
60479 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60480 {
60481 atomic64_t *v = (atomic64_t *)l;
60482 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60483 return (long)atomic64_inc_return(v);
60484 }
60485
60486 +#ifdef CONFIG_PAX_REFCOUNT
60487 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60488 +{
60489 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60490 +
60491 + return (long)atomic64_inc_return_unchecked(v);
60492 +}
60493 +#endif
60494 +
60495 static inline long atomic_long_dec_return(atomic_long_t *l)
60496 {
60497 atomic64_t *v = (atomic64_t *)l;
60498 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60499
60500 typedef atomic_t atomic_long_t;
60501
60502 +#ifdef CONFIG_PAX_REFCOUNT
60503 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60504 +#else
60505 +typedef atomic_t atomic_long_unchecked_t;
60506 +#endif
60507 +
60508 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60509 static inline long atomic_long_read(atomic_long_t *l)
60510 {
60511 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60512 return (long)atomic_read(v);
60513 }
60514
60515 +#ifdef CONFIG_PAX_REFCOUNT
60516 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60517 +{
60518 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60519 +
60520 + return (long)atomic_read_unchecked(v);
60521 +}
60522 +#endif
60523 +
60524 static inline void atomic_long_set(atomic_long_t *l, long i)
60525 {
60526 atomic_t *v = (atomic_t *)l;
60527 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60528 atomic_set(v, i);
60529 }
60530
60531 +#ifdef CONFIG_PAX_REFCOUNT
60532 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60533 +{
60534 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60535 +
60536 + atomic_set_unchecked(v, i);
60537 +}
60538 +#endif
60539 +
60540 static inline void atomic_long_inc(atomic_long_t *l)
60541 {
60542 atomic_t *v = (atomic_t *)l;
60543 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60544 atomic_inc(v);
60545 }
60546
60547 +#ifdef CONFIG_PAX_REFCOUNT
60548 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60549 +{
60550 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60551 +
60552 + atomic_inc_unchecked(v);
60553 +}
60554 +#endif
60555 +
60556 static inline void atomic_long_dec(atomic_long_t *l)
60557 {
60558 atomic_t *v = (atomic_t *)l;
60559 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60560 atomic_dec(v);
60561 }
60562
60563 +#ifdef CONFIG_PAX_REFCOUNT
60564 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60565 +{
60566 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60567 +
60568 + atomic_dec_unchecked(v);
60569 +}
60570 +#endif
60571 +
60572 static inline void atomic_long_add(long i, atomic_long_t *l)
60573 {
60574 atomic_t *v = (atomic_t *)l;
60575 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60576 atomic_add(i, v);
60577 }
60578
60579 +#ifdef CONFIG_PAX_REFCOUNT
60580 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60581 +{
60582 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60583 +
60584 + atomic_add_unchecked(i, v);
60585 +}
60586 +#endif
60587 +
60588 static inline void atomic_long_sub(long i, atomic_long_t *l)
60589 {
60590 atomic_t *v = (atomic_t *)l;
60591 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60592 atomic_sub(i, v);
60593 }
60594
60595 +#ifdef CONFIG_PAX_REFCOUNT
60596 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60597 +{
60598 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60599 +
60600 + atomic_sub_unchecked(i, v);
60601 +}
60602 +#endif
60603 +
60604 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60605 {
60606 atomic_t *v = (atomic_t *)l;
60607 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60608 return (long)atomic_inc_return(v);
60609 }
60610
60611 +#ifdef CONFIG_PAX_REFCOUNT
60612 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60613 +{
60614 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60615 +
60616 + return (long)atomic_inc_return_unchecked(v);
60617 +}
60618 +#endif
60619 +
60620 static inline long atomic_long_dec_return(atomic_long_t *l)
60621 {
60622 atomic_t *v = (atomic_t *)l;
60623 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60624
60625 #endif /* BITS_PER_LONG == 64 */
60626
60627 +#ifdef CONFIG_PAX_REFCOUNT
60628 +static inline void pax_refcount_needs_these_functions(void)
60629 +{
60630 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60631 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60632 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60633 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60634 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60635 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60636 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60637 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60638 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60639 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60640 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60641 +#ifdef CONFIG_X86
60642 + atomic_clear_mask_unchecked(0, NULL);
60643 + atomic_set_mask_unchecked(0, NULL);
60644 +#endif
60645 +
60646 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60647 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60648 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60649 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60650 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60651 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60652 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60653 +}
60654 +#else
60655 +#define atomic_read_unchecked(v) atomic_read(v)
60656 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60657 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60658 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60659 +#define atomic_inc_unchecked(v) atomic_inc(v)
60660 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60661 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60662 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60663 +#define atomic_dec_unchecked(v) atomic_dec(v)
60664 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60665 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60666 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60667 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60668 +
60669 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60670 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60671 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60672 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60673 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60674 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60675 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60676 +#endif
60677 +
60678 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60679 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60680 index 1ced641..c896ee8 100644
60681 --- a/include/asm-generic/atomic.h
60682 +++ b/include/asm-generic/atomic.h
60683 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60684 * Atomically clears the bits set in @mask from @v
60685 */
60686 #ifndef atomic_clear_mask
60687 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60688 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60689 {
60690 unsigned long flags;
60691
60692 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60693 index b18ce4f..2ee2843 100644
60694 --- a/include/asm-generic/atomic64.h
60695 +++ b/include/asm-generic/atomic64.h
60696 @@ -16,6 +16,8 @@ typedef struct {
60697 long long counter;
60698 } atomic64_t;
60699
60700 +typedef atomic64_t atomic64_unchecked_t;
60701 +
60702 #define ATOMIC64_INIT(i) { (i) }
60703
60704 extern long long atomic64_read(const atomic64_t *v);
60705 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60706 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60707 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60708
60709 +#define atomic64_read_unchecked(v) atomic64_read(v)
60710 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60711 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60712 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60713 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60714 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60715 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60716 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60717 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60718 +
60719 #endif /* _ASM_GENERIC_ATOMIC64_H */
60720 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60721 index 1bfcfe5..e04c5c9 100644
60722 --- a/include/asm-generic/cache.h
60723 +++ b/include/asm-generic/cache.h
60724 @@ -6,7 +6,7 @@
60725 * cache lines need to provide their own cache.h.
60726 */
60727
60728 -#define L1_CACHE_SHIFT 5
60729 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60730 +#define L1_CACHE_SHIFT 5UL
60731 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60732
60733 #endif /* __ASM_GENERIC_CACHE_H */
60734 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60735 index 0d68a1e..b74a761 100644
60736 --- a/include/asm-generic/emergency-restart.h
60737 +++ b/include/asm-generic/emergency-restart.h
60738 @@ -1,7 +1,7 @@
60739 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60740 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60741
60742 -static inline void machine_emergency_restart(void)
60743 +static inline __noreturn void machine_emergency_restart(void)
60744 {
60745 machine_restart(NULL);
60746 }
60747 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60748 index 90f99c7..00ce236 100644
60749 --- a/include/asm-generic/kmap_types.h
60750 +++ b/include/asm-generic/kmap_types.h
60751 @@ -2,9 +2,9 @@
60752 #define _ASM_GENERIC_KMAP_TYPES_H
60753
60754 #ifdef __WITH_KM_FENCE
60755 -# define KM_TYPE_NR 41
60756 +# define KM_TYPE_NR 42
60757 #else
60758 -# define KM_TYPE_NR 20
60759 +# define KM_TYPE_NR 21
60760 #endif
60761
60762 #endif
60763 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60764 index 9ceb03b..2efbcbd 100644
60765 --- a/include/asm-generic/local.h
60766 +++ b/include/asm-generic/local.h
60767 @@ -39,6 +39,7 @@ typedef struct
60768 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60769 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60770 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60771 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60772
60773 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60774 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60775 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60776 index 725612b..9cc513a 100644
60777 --- a/include/asm-generic/pgtable-nopmd.h
60778 +++ b/include/asm-generic/pgtable-nopmd.h
60779 @@ -1,14 +1,19 @@
60780 #ifndef _PGTABLE_NOPMD_H
60781 #define _PGTABLE_NOPMD_H
60782
60783 -#ifndef __ASSEMBLY__
60784 -
60785 #include <asm-generic/pgtable-nopud.h>
60786
60787 -struct mm_struct;
60788 -
60789 #define __PAGETABLE_PMD_FOLDED
60790
60791 +#define PMD_SHIFT PUD_SHIFT
60792 +#define PTRS_PER_PMD 1
60793 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60794 +#define PMD_MASK (~(PMD_SIZE-1))
60795 +
60796 +#ifndef __ASSEMBLY__
60797 +
60798 +struct mm_struct;
60799 +
60800 /*
60801 * Having the pmd type consist of a pud gets the size right, and allows
60802 * us to conceptually access the pud entry that this pmd is folded into
60803 @@ -16,11 +21,6 @@ struct mm_struct;
60804 */
60805 typedef struct { pud_t pud; } pmd_t;
60806
60807 -#define PMD_SHIFT PUD_SHIFT
60808 -#define PTRS_PER_PMD 1
60809 -#define PMD_SIZE (1UL << PMD_SHIFT)
60810 -#define PMD_MASK (~(PMD_SIZE-1))
60811 -
60812 /*
60813 * The "pud_xxx()" functions here are trivial for a folded two-level
60814 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60815 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60816 index 810431d..0ec4804f 100644
60817 --- a/include/asm-generic/pgtable-nopud.h
60818 +++ b/include/asm-generic/pgtable-nopud.h
60819 @@ -1,10 +1,15 @@
60820 #ifndef _PGTABLE_NOPUD_H
60821 #define _PGTABLE_NOPUD_H
60822
60823 -#ifndef __ASSEMBLY__
60824 -
60825 #define __PAGETABLE_PUD_FOLDED
60826
60827 +#define PUD_SHIFT PGDIR_SHIFT
60828 +#define PTRS_PER_PUD 1
60829 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60830 +#define PUD_MASK (~(PUD_SIZE-1))
60831 +
60832 +#ifndef __ASSEMBLY__
60833 +
60834 /*
60835 * Having the pud type consist of a pgd gets the size right, and allows
60836 * us to conceptually access the pgd entry that this pud is folded into
60837 @@ -12,11 +17,6 @@
60838 */
60839 typedef struct { pgd_t pgd; } pud_t;
60840
60841 -#define PUD_SHIFT PGDIR_SHIFT
60842 -#define PTRS_PER_PUD 1
60843 -#define PUD_SIZE (1UL << PUD_SHIFT)
60844 -#define PUD_MASK (~(PUD_SIZE-1))
60845 -
60846 /*
60847 * The "pgd_xxx()" functions here are trivial for a folded two-level
60848 * setup: the pud is never bad, and a pud always exists (as it's folded
60849 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60850 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60851
60852 #define pgd_populate(mm, pgd, pud) do { } while (0)
60853 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60854 /*
60855 * (puds are folded into pgds so this doesn't get actually called,
60856 * but the define is needed for a generic inline function.)
60857 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60858 index ff4947b..f48183f 100644
60859 --- a/include/asm-generic/pgtable.h
60860 +++ b/include/asm-generic/pgtable.h
60861 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60862 #endif
60863 }
60864
60865 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60866 +static inline unsigned long pax_open_kernel(void) { return 0; }
60867 +#endif
60868 +
60869 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60870 +static inline unsigned long pax_close_kernel(void) { return 0; }
60871 +#endif
60872 +
60873 #endif /* CONFIG_MMU */
60874
60875 #endif /* !__ASSEMBLY__ */
60876 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60877 index 4e2e1cc..12c266b 100644
60878 --- a/include/asm-generic/vmlinux.lds.h
60879 +++ b/include/asm-generic/vmlinux.lds.h
60880 @@ -218,6 +218,7 @@
60881 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60882 VMLINUX_SYMBOL(__start_rodata) = .; \
60883 *(.rodata) *(.rodata.*) \
60884 + *(.data..read_only) \
60885 *(__vermagic) /* Kernel version magic */ \
60886 . = ALIGN(8); \
60887 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60888 @@ -716,17 +717,18 @@
60889 * section in the linker script will go there too. @phdr should have
60890 * a leading colon.
60891 *
60892 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60893 + * Note that this macros defines per_cpu_load as an absolute symbol.
60894 * If there is no need to put the percpu section at a predetermined
60895 * address, use PERCPU_SECTION.
60896 */
60897 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60898 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60899 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60900 + per_cpu_load = .; \
60901 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60902 - LOAD_OFFSET) { \
60903 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60904 PERCPU_INPUT(cacheline) \
60905 } phdr \
60906 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60907 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60908
60909 /**
60910 * PERCPU_SECTION - define output section for percpu area, simple version
60911 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60912 index d6b67bb..a272c29 100644
60913 --- a/include/drm/drmP.h
60914 +++ b/include/drm/drmP.h
60915 @@ -72,6 +72,7 @@
60916 #include <linux/workqueue.h>
60917 #include <linux/poll.h>
60918 #include <asm/pgalloc.h>
60919 +#include <asm/local.h>
60920 #include "drm.h"
60921
60922 #include <linux/idr.h>
60923 @@ -1067,7 +1068,7 @@ struct drm_device {
60924
60925 /** \name Usage Counters */
60926 /*@{ */
60927 - int open_count; /**< Outstanding files open */
60928 + local_t open_count; /**< Outstanding files open */
60929 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60930 atomic_t vma_count; /**< Outstanding vma areas open */
60931 int buf_use; /**< Buffers in use -- cannot alloc */
60932 @@ -1078,7 +1079,7 @@ struct drm_device {
60933 /*@{ */
60934 unsigned long counters;
60935 enum drm_stat_type types[15];
60936 - atomic_t counts[15];
60937 + atomic_unchecked_t counts[15];
60938 /*@} */
60939
60940 struct list_head filelist;
60941 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60942 index e01cc80..319855d 100644
60943 --- a/include/drm/drm_crtc_helper.h
60944 +++ b/include/drm/drm_crtc_helper.h
60945 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60946
60947 /* disable crtc when not in use - more explicit than dpms off */
60948 void (*disable)(struct drm_crtc *crtc);
60949 -};
60950 +} __no_const;
60951
60952 /**
60953 * drm_encoder_helper_funcs - helper operations for encoders
60954 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60955 struct drm_connector *connector);
60956 /* disable encoder when not in use - more explicit than dpms off */
60957 void (*disable)(struct drm_encoder *encoder);
60958 -};
60959 +} __no_const;
60960
60961 /**
60962 * drm_connector_helper_funcs - helper operations for connectors
60963 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60964 index d6d1da4..fdd1ac5 100644
60965 --- a/include/drm/ttm/ttm_memory.h
60966 +++ b/include/drm/ttm/ttm_memory.h
60967 @@ -48,7 +48,7 @@
60968
60969 struct ttm_mem_shrink {
60970 int (*do_shrink) (struct ttm_mem_shrink *);
60971 -};
60972 +} __no_const;
60973
60974 /**
60975 * struct ttm_mem_global - Global memory accounting structure.
60976 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60977 index e86dfca..40cc55f 100644
60978 --- a/include/linux/a.out.h
60979 +++ b/include/linux/a.out.h
60980 @@ -39,6 +39,14 @@ enum machine_type {
60981 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60982 };
60983
60984 +/* Constants for the N_FLAGS field */
60985 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60986 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60987 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60988 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60989 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60990 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60991 +
60992 #if !defined (N_MAGIC)
60993 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60994 #endif
60995 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60996 index 06fd4bb..1caec0d 100644
60997 --- a/include/linux/atmdev.h
60998 +++ b/include/linux/atmdev.h
60999 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61000 #endif
61001
61002 struct k_atm_aal_stats {
61003 -#define __HANDLE_ITEM(i) atomic_t i
61004 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61005 __AAL_STAT_ITEMS
61006 #undef __HANDLE_ITEM
61007 };
61008 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61009 index 366422b..1fa7f84 100644
61010 --- a/include/linux/binfmts.h
61011 +++ b/include/linux/binfmts.h
61012 @@ -89,6 +89,7 @@ struct linux_binfmt {
61013 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61014 int (*load_shlib)(struct file *);
61015 int (*core_dump)(struct coredump_params *cprm);
61016 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61017 unsigned long min_coredump; /* minimal dump size */
61018 };
61019
61020 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61021 index 4a2ab7c..a2de7a8 100644
61022 --- a/include/linux/blkdev.h
61023 +++ b/include/linux/blkdev.h
61024 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61025 /* this callback is with swap_lock and sometimes page table lock held */
61026 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61027 struct module *owner;
61028 -};
61029 +} __do_const;
61030
61031 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61032 unsigned long);
61033 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61034 index 4d1a074..88f929a 100644
61035 --- a/include/linux/blktrace_api.h
61036 +++ b/include/linux/blktrace_api.h
61037 @@ -162,7 +162,7 @@ struct blk_trace {
61038 struct dentry *dir;
61039 struct dentry *dropped_file;
61040 struct dentry *msg_file;
61041 - atomic_t dropped;
61042 + atomic_unchecked_t dropped;
61043 };
61044
61045 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61046 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61047 index 83195fb..0b0f77d 100644
61048 --- a/include/linux/byteorder/little_endian.h
61049 +++ b/include/linux/byteorder/little_endian.h
61050 @@ -42,51 +42,51 @@
61051
61052 static inline __le64 __cpu_to_le64p(const __u64 *p)
61053 {
61054 - return (__force __le64)*p;
61055 + return (__force const __le64)*p;
61056 }
61057 static inline __u64 __le64_to_cpup(const __le64 *p)
61058 {
61059 - return (__force __u64)*p;
61060 + return (__force const __u64)*p;
61061 }
61062 static inline __le32 __cpu_to_le32p(const __u32 *p)
61063 {
61064 - return (__force __le32)*p;
61065 + return (__force const __le32)*p;
61066 }
61067 static inline __u32 __le32_to_cpup(const __le32 *p)
61068 {
61069 - return (__force __u32)*p;
61070 + return (__force const __u32)*p;
61071 }
61072 static inline __le16 __cpu_to_le16p(const __u16 *p)
61073 {
61074 - return (__force __le16)*p;
61075 + return (__force const __le16)*p;
61076 }
61077 static inline __u16 __le16_to_cpup(const __le16 *p)
61078 {
61079 - return (__force __u16)*p;
61080 + return (__force const __u16)*p;
61081 }
61082 static inline __be64 __cpu_to_be64p(const __u64 *p)
61083 {
61084 - return (__force __be64)__swab64p(p);
61085 + return (__force const __be64)__swab64p(p);
61086 }
61087 static inline __u64 __be64_to_cpup(const __be64 *p)
61088 {
61089 - return __swab64p((__u64 *)p);
61090 + return __swab64p((const __u64 *)p);
61091 }
61092 static inline __be32 __cpu_to_be32p(const __u32 *p)
61093 {
61094 - return (__force __be32)__swab32p(p);
61095 + return (__force const __be32)__swab32p(p);
61096 }
61097 static inline __u32 __be32_to_cpup(const __be32 *p)
61098 {
61099 - return __swab32p((__u32 *)p);
61100 + return __swab32p((const __u32 *)p);
61101 }
61102 static inline __be16 __cpu_to_be16p(const __u16 *p)
61103 {
61104 - return (__force __be16)__swab16p(p);
61105 + return (__force const __be16)__swab16p(p);
61106 }
61107 static inline __u16 __be16_to_cpup(const __be16 *p)
61108 {
61109 - return __swab16p((__u16 *)p);
61110 + return __swab16p((const __u16 *)p);
61111 }
61112 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61113 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61114 diff --git a/include/linux/cache.h b/include/linux/cache.h
61115 index 4c57065..4307975 100644
61116 --- a/include/linux/cache.h
61117 +++ b/include/linux/cache.h
61118 @@ -16,6 +16,10 @@
61119 #define __read_mostly
61120 #endif
61121
61122 +#ifndef __read_only
61123 +#define __read_only __read_mostly
61124 +#endif
61125 +
61126 #ifndef ____cacheline_aligned
61127 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61128 #endif
61129 diff --git a/include/linux/capability.h b/include/linux/capability.h
61130 index d10b7ed..0288b79 100644
61131 --- a/include/linux/capability.h
61132 +++ b/include/linux/capability.h
61133 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61134 extern bool ns_capable(struct user_namespace *ns, int cap);
61135 extern bool nsown_capable(int cap);
61136 extern bool inode_capable(const struct inode *inode, int cap);
61137 +extern bool capable_nolog(int cap);
61138 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61139 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61140
61141 /* audit system wants to get cap info from files as well */
61142 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61143
61144 +extern int is_privileged_binary(const struct dentry *dentry);
61145 +
61146 #endif /* __KERNEL__ */
61147
61148 #endif /* !_LINUX_CAPABILITY_H */
61149 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61150 index 42e55de..1cd0e66 100644
61151 --- a/include/linux/cleancache.h
61152 +++ b/include/linux/cleancache.h
61153 @@ -31,7 +31,7 @@ struct cleancache_ops {
61154 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61155 void (*invalidate_inode)(int, struct cleancache_filekey);
61156 void (*invalidate_fs)(int);
61157 -};
61158 +} __no_const;
61159
61160 extern struct cleancache_ops
61161 cleancache_register_ops(struct cleancache_ops *ops);
61162 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61163 index 77335fa..6cbe7dd 100644
61164 --- a/include/linux/clk-provider.h
61165 +++ b/include/linux/clk-provider.h
61166 @@ -111,6 +111,7 @@ struct clk_ops {
61167 unsigned long);
61168 void (*init)(struct clk_hw *hw);
61169 };
61170 +typedef struct clk_ops __no_const clk_ops_no_const;
61171
61172 /**
61173 * struct clk_init_data - holds init data that's common to all clocks and is
61174 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61175 index 934bc34..1b47129 100644
61176 --- a/include/linux/compiler-gcc4.h
61177 +++ b/include/linux/compiler-gcc4.h
61178 @@ -32,6 +32,21 @@
61179 #define __linktime_error(message) __attribute__((__error__(message)))
61180
61181 #if __GNUC_MINOR__ >= 5
61182 +
61183 +#ifdef CONSTIFY_PLUGIN
61184 +#define __no_const __attribute__((no_const))
61185 +#define __do_const __attribute__((do_const))
61186 +#endif
61187 +
61188 +#ifdef SIZE_OVERFLOW_PLUGIN
61189 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61190 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61191 +#endif
61192 +
61193 +#ifdef LATENT_ENTROPY_PLUGIN
61194 +#define __latent_entropy __attribute__((latent_entropy))
61195 +#endif
61196 +
61197 /*
61198 * Mark a position in code as unreachable. This can be used to
61199 * suppress control flow warnings after asm blocks that transfer
61200 @@ -47,6 +62,11 @@
61201 #define __noclone __attribute__((__noclone__))
61202
61203 #endif
61204 +
61205 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61206 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61207 +#define __bos0(ptr) __bos((ptr), 0)
61208 +#define __bos1(ptr) __bos((ptr), 1)
61209 #endif
61210
61211 #if __GNUC_MINOR__ >= 6
61212 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61213 index f430e41..38be90f 100644
61214 --- a/include/linux/compiler.h
61215 +++ b/include/linux/compiler.h
61216 @@ -5,31 +5,62 @@
61217
61218 #ifdef __CHECKER__
61219 # define __user __attribute__((noderef, address_space(1)))
61220 +# define __force_user __force __user
61221 # define __kernel __attribute__((address_space(0)))
61222 +# define __force_kernel __force __kernel
61223 # define __safe __attribute__((safe))
61224 # define __force __attribute__((force))
61225 # define __nocast __attribute__((nocast))
61226 # define __iomem __attribute__((noderef, address_space(2)))
61227 +# define __force_iomem __force __iomem
61228 # define __acquires(x) __attribute__((context(x,0,1)))
61229 # define __releases(x) __attribute__((context(x,1,0)))
61230 # define __acquire(x) __context__(x,1)
61231 # define __release(x) __context__(x,-1)
61232 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61233 # define __percpu __attribute__((noderef, address_space(3)))
61234 +# define __force_percpu __force __percpu
61235 #ifdef CONFIG_SPARSE_RCU_POINTER
61236 # define __rcu __attribute__((noderef, address_space(4)))
61237 +# define __force_rcu __force __rcu
61238 #else
61239 # define __rcu
61240 +# define __force_rcu
61241 #endif
61242 extern void __chk_user_ptr(const volatile void __user *);
61243 extern void __chk_io_ptr(const volatile void __iomem *);
61244 +#elif defined(CHECKER_PLUGIN)
61245 +//# define __user
61246 +//# define __force_user
61247 +//# define __kernel
61248 +//# define __force_kernel
61249 +# define __safe
61250 +# define __force
61251 +# define __nocast
61252 +# define __iomem
61253 +# define __force_iomem
61254 +# define __chk_user_ptr(x) (void)0
61255 +# define __chk_io_ptr(x) (void)0
61256 +# define __builtin_warning(x, y...) (1)
61257 +# define __acquires(x)
61258 +# define __releases(x)
61259 +# define __acquire(x) (void)0
61260 +# define __release(x) (void)0
61261 +# define __cond_lock(x,c) (c)
61262 +# define __percpu
61263 +# define __force_percpu
61264 +# define __rcu
61265 +# define __force_rcu
61266 #else
61267 # define __user
61268 +# define __force_user
61269 # define __kernel
61270 +# define __force_kernel
61271 # define __safe
61272 # define __force
61273 # define __nocast
61274 # define __iomem
61275 +# define __force_iomem
61276 # define __chk_user_ptr(x) (void)0
61277 # define __chk_io_ptr(x) (void)0
61278 # define __builtin_warning(x, y...) (1)
61279 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61280 # define __release(x) (void)0
61281 # define __cond_lock(x,c) (c)
61282 # define __percpu
61283 +# define __force_percpu
61284 # define __rcu
61285 +# define __force_rcu
61286 #endif
61287
61288 #ifdef __KERNEL__
61289 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61290 # define __attribute_const__ /* unimplemented */
61291 #endif
61292
61293 +#ifndef __no_const
61294 +# define __no_const
61295 +#endif
61296 +
61297 +#ifndef __do_const
61298 +# define __do_const
61299 +#endif
61300 +
61301 +#ifndef __size_overflow
61302 +# define __size_overflow(...)
61303 +#endif
61304 +
61305 +#ifndef __intentional_overflow
61306 +# define __intentional_overflow(...)
61307 +#endif
61308 +
61309 +#ifndef __latent_entropy
61310 +# define __latent_entropy
61311 +#endif
61312 +
61313 /*
61314 * Tell gcc if a function is cold. The compiler will assume any path
61315 * directly leading to the call is unlikely.
61316 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61317 #define __cold
61318 #endif
61319
61320 +#ifndef __alloc_size
61321 +#define __alloc_size(...)
61322 +#endif
61323 +
61324 +#ifndef __bos
61325 +#define __bos(ptr, arg)
61326 +#endif
61327 +
61328 +#ifndef __bos0
61329 +#define __bos0(ptr)
61330 +#endif
61331 +
61332 +#ifndef __bos1
61333 +#define __bos1(ptr)
61334 +#endif
61335 +
61336 /* Simple shorthand for a section definition */
61337 #ifndef __section
61338 # define __section(S) __attribute__ ((__section__(#S)))
61339 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61340 * use is to mediate communication between process-level code and irq/NMI
61341 * handlers, all running on the same CPU.
61342 */
61343 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61344 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61345 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61346
61347 #endif /* __LINUX_COMPILER_H */
61348 diff --git a/include/linux/cred.h b/include/linux/cred.h
61349 index ebbed2c..908cc2c 100644
61350 --- a/include/linux/cred.h
61351 +++ b/include/linux/cred.h
61352 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61353 static inline void validate_process_creds(void)
61354 {
61355 }
61356 +static inline void validate_task_creds(struct task_struct *task)
61357 +{
61358 +}
61359 #endif
61360
61361 /**
61362 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61363 index b92eadf..b4ecdc1 100644
61364 --- a/include/linux/crypto.h
61365 +++ b/include/linux/crypto.h
61366 @@ -373,7 +373,7 @@ struct cipher_tfm {
61367 const u8 *key, unsigned int keylen);
61368 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61369 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61370 -};
61371 +} __no_const;
61372
61373 struct hash_tfm {
61374 int (*init)(struct hash_desc *desc);
61375 @@ -394,13 +394,13 @@ struct compress_tfm {
61376 int (*cot_decompress)(struct crypto_tfm *tfm,
61377 const u8 *src, unsigned int slen,
61378 u8 *dst, unsigned int *dlen);
61379 -};
61380 +} __no_const;
61381
61382 struct rng_tfm {
61383 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61384 unsigned int dlen);
61385 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61386 -};
61387 +} __no_const;
61388
61389 #define crt_ablkcipher crt_u.ablkcipher
61390 #define crt_aead crt_u.aead
61391 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61392 index 7925bf0..d5143d2 100644
61393 --- a/include/linux/decompress/mm.h
61394 +++ b/include/linux/decompress/mm.h
61395 @@ -77,7 +77,7 @@ static void free(void *where)
61396 * warnings when not needed (indeed large_malloc / large_free are not
61397 * needed by inflate */
61398
61399 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61400 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61401 #define free(a) kfree(a)
61402
61403 #define large_malloc(a) vmalloc(a)
61404 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61405 index 94af418..b1ca7a2 100644
61406 --- a/include/linux/dma-mapping.h
61407 +++ b/include/linux/dma-mapping.h
61408 @@ -54,7 +54,7 @@ struct dma_map_ops {
61409 u64 (*get_required_mask)(struct device *dev);
61410 #endif
61411 int is_phys;
61412 -};
61413 +} __do_const;
61414
61415 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61416
61417 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61418 index 9c02a45..89fdd73 100644
61419 --- a/include/linux/dmaengine.h
61420 +++ b/include/linux/dmaengine.h
61421 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61422 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61423 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61424
61425 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61426 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61427 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61428 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61429 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61430 struct dma_pinned_list *pinned_list, struct page *page,
61431 unsigned int offset, size_t len);
61432
61433 diff --git a/include/linux/efi.h b/include/linux/efi.h
61434 index 5782114..e9b1ba1 100644
61435 --- a/include/linux/efi.h
61436 +++ b/include/linux/efi.h
61437 @@ -640,7 +640,7 @@ struct efivar_operations {
61438 efi_get_variable_t *get_variable;
61439 efi_get_next_variable_t *get_next_variable;
61440 efi_set_variable_t *set_variable;
61441 -};
61442 +} __no_const;
61443
61444 struct efivars {
61445 /*
61446 diff --git a/include/linux/elf.h b/include/linux/elf.h
61447 index 999b4f5..57753b4 100644
61448 --- a/include/linux/elf.h
61449 +++ b/include/linux/elf.h
61450 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61451 #define PT_GNU_EH_FRAME 0x6474e550
61452
61453 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61454 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61455 +
61456 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61457 +
61458 +/* Constants for the e_flags field */
61459 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61460 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61461 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61462 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61463 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61464 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61465
61466 /*
61467 * Extended Numbering
61468 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61469 #define DT_DEBUG 21
61470 #define DT_TEXTREL 22
61471 #define DT_JMPREL 23
61472 +#define DT_FLAGS 30
61473 + #define DF_TEXTREL 0x00000004
61474 #define DT_ENCODING 32
61475 #define OLD_DT_LOOS 0x60000000
61476 #define DT_LOOS 0x6000000d
61477 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61478 #define PF_W 0x2
61479 #define PF_X 0x1
61480
61481 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61482 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61483 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61484 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61485 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61486 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61487 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61488 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61489 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61490 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61491 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61492 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61493 +
61494 typedef struct elf32_phdr{
61495 Elf32_Word p_type;
61496 Elf32_Off p_offset;
61497 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61498 #define EI_OSABI 7
61499 #define EI_PAD 8
61500
61501 +#define EI_PAX 14
61502 +
61503 #define ELFMAG0 0x7f /* EI_MAG */
61504 #define ELFMAG1 'E'
61505 #define ELFMAG2 'L'
61506 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61507 #define elf_note elf32_note
61508 #define elf_addr_t Elf32_Off
61509 #define Elf_Half Elf32_Half
61510 +#define elf_dyn Elf32_Dyn
61511
61512 #else
61513
61514 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61515 #define elf_note elf64_note
61516 #define elf_addr_t Elf64_Off
61517 #define Elf_Half Elf64_Half
61518 +#define elf_dyn Elf64_Dyn
61519
61520 #endif
61521
61522 diff --git a/include/linux/filter.h b/include/linux/filter.h
61523 index 82b0135..917914d 100644
61524 --- a/include/linux/filter.h
61525 +++ b/include/linux/filter.h
61526 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61527
61528 struct sk_buff;
61529 struct sock;
61530 +struct bpf_jit_work;
61531
61532 struct sk_filter
61533 {
61534 @@ -153,6 +154,9 @@ struct sk_filter
61535 unsigned int len; /* Number of filter blocks */
61536 unsigned int (*bpf_func)(const struct sk_buff *skb,
61537 const struct sock_filter *filter);
61538 +#ifdef CONFIG_BPF_JIT
61539 + struct bpf_jit_work *work;
61540 +#endif
61541 struct rcu_head rcu;
61542 struct sock_filter insns[0];
61543 };
61544 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61545 index db04ec5..f6ed627 100644
61546 --- a/include/linux/firewire.h
61547 +++ b/include/linux/firewire.h
61548 @@ -430,7 +430,7 @@ struct fw_iso_context {
61549 union {
61550 fw_iso_callback_t sc;
61551 fw_iso_mc_callback_t mc;
61552 - } callback;
61553 + } __no_const callback;
61554 void *callback_data;
61555 };
61556
61557 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61558 index 0e4e2ee..4ff4312 100644
61559 --- a/include/linux/frontswap.h
61560 +++ b/include/linux/frontswap.h
61561 @@ -11,7 +11,7 @@ struct frontswap_ops {
61562 int (*load)(unsigned, pgoff_t, struct page *);
61563 void (*invalidate_page)(unsigned, pgoff_t);
61564 void (*invalidate_area)(unsigned);
61565 -};
61566 +} __no_const;
61567
61568 extern bool frontswap_enabled;
61569 extern struct frontswap_ops
61570 diff --git a/include/linux/fs.h b/include/linux/fs.h
61571 index aa11047..7d046d0 100644
61572 --- a/include/linux/fs.h
61573 +++ b/include/linux/fs.h
61574 @@ -1802,7 +1802,8 @@ struct file_operations {
61575 int (*setlease)(struct file *, long, struct file_lock **);
61576 long (*fallocate)(struct file *file, int mode, loff_t offset,
61577 loff_t len);
61578 -};
61579 +} __do_const;
61580 +typedef struct file_operations __no_const file_operations_no_const;
61581
61582 struct inode_operations {
61583 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61584 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61585 index 003dc0f..3c4ea97 100644
61586 --- a/include/linux/fs_struct.h
61587 +++ b/include/linux/fs_struct.h
61588 @@ -6,7 +6,7 @@
61589 #include <linux/seqlock.h>
61590
61591 struct fs_struct {
61592 - int users;
61593 + atomic_t users;
61594 spinlock_t lock;
61595 seqcount_t seq;
61596 int umask;
61597 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61598 index ce31408..b1ad003 100644
61599 --- a/include/linux/fscache-cache.h
61600 +++ b/include/linux/fscache-cache.h
61601 @@ -102,7 +102,7 @@ struct fscache_operation {
61602 fscache_operation_release_t release;
61603 };
61604
61605 -extern atomic_t fscache_op_debug_id;
61606 +extern atomic_unchecked_t fscache_op_debug_id;
61607 extern void fscache_op_work_func(struct work_struct *work);
61608
61609 extern void fscache_enqueue_operation(struct fscache_operation *);
61610 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61611 {
61612 INIT_WORK(&op->work, fscache_op_work_func);
61613 atomic_set(&op->usage, 1);
61614 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61615 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61616 op->processor = processor;
61617 op->release = release;
61618 INIT_LIST_HEAD(&op->pend_link);
61619 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61620 index a6dfe69..569586df 100644
61621 --- a/include/linux/fsnotify.h
61622 +++ b/include/linux/fsnotify.h
61623 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61624 */
61625 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61626 {
61627 - return kstrdup(name, GFP_KERNEL);
61628 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61629 }
61630
61631 /*
61632 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61633 index 63d966d..cdcb717 100644
61634 --- a/include/linux/fsnotify_backend.h
61635 +++ b/include/linux/fsnotify_backend.h
61636 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61637 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61638 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61639 };
61640 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61641
61642 /*
61643 * A group is a "thing" that wants to receive notification about filesystem
61644 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61645 index 642928c..e6c83a7 100644
61646 --- a/include/linux/ftrace_event.h
61647 +++ b/include/linux/ftrace_event.h
61648 @@ -97,7 +97,7 @@ struct trace_event_functions {
61649 trace_print_func raw;
61650 trace_print_func hex;
61651 trace_print_func binary;
61652 -};
61653 +} __no_const;
61654
61655 struct trace_event {
61656 struct hlist_node node;
61657 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61658 extern int trace_add_event_call(struct ftrace_event_call *call);
61659 extern void trace_remove_event_call(struct ftrace_event_call *call);
61660
61661 -#define is_signed_type(type) (((type)(-1)) < 0)
61662 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61663
61664 int trace_set_clr_event(const char *system, const char *event, int set);
61665
61666 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61667 index 4f440b3..342233a 100644
61668 --- a/include/linux/genhd.h
61669 +++ b/include/linux/genhd.h
61670 @@ -190,7 +190,7 @@ struct gendisk {
61671 struct kobject *slave_dir;
61672
61673 struct timer_rand_state *random;
61674 - atomic_t sync_io; /* RAID */
61675 + atomic_unchecked_t sync_io; /* RAID */
61676 struct disk_events *ev;
61677 #ifdef CONFIG_BLK_DEV_INTEGRITY
61678 struct blk_integrity *integrity;
61679 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61680 index 4883f39..26688a8 100644
61681 --- a/include/linux/gfp.h
61682 +++ b/include/linux/gfp.h
61683 @@ -39,6 +39,12 @@ struct vm_area_struct;
61684 #define ___GFP_OTHER_NODE 0x800000u
61685 #define ___GFP_WRITE 0x1000000u
61686
61687 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61688 +#define ___GFP_USERCOPY 0x2000000u
61689 +#else
61690 +#define ___GFP_USERCOPY 0
61691 +#endif
61692 +
61693 /*
61694 * GFP bitmasks..
61695 *
61696 @@ -93,6 +99,7 @@ struct vm_area_struct;
61697 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61698 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61699 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61700 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61701
61702 /*
61703 * This may seem redundant, but it's a way of annotating false positives vs.
61704 @@ -100,7 +107,7 @@ struct vm_area_struct;
61705 */
61706 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61707
61708 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61709 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61710 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61711
61712 /* This equals 0, but use constants in case they ever change */
61713 @@ -154,6 +161,8 @@ struct vm_area_struct;
61714 /* 4GB DMA on some platforms */
61715 #define GFP_DMA32 __GFP_DMA32
61716
61717 +#define GFP_USERCOPY __GFP_USERCOPY
61718 +
61719 /* Convert GFP flags to their corresponding migrate type */
61720 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61721 {
61722 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61723 new file mode 100644
61724 index 0000000..c938b1f
61725 --- /dev/null
61726 +++ b/include/linux/gracl.h
61727 @@ -0,0 +1,319 @@
61728 +#ifndef GR_ACL_H
61729 +#define GR_ACL_H
61730 +
61731 +#include <linux/grdefs.h>
61732 +#include <linux/resource.h>
61733 +#include <linux/capability.h>
61734 +#include <linux/dcache.h>
61735 +#include <asm/resource.h>
61736 +
61737 +/* Major status information */
61738 +
61739 +#define GR_VERSION "grsecurity 2.9.1"
61740 +#define GRSECURITY_VERSION 0x2901
61741 +
61742 +enum {
61743 + GR_SHUTDOWN = 0,
61744 + GR_ENABLE = 1,
61745 + GR_SPROLE = 2,
61746 + GR_RELOAD = 3,
61747 + GR_SEGVMOD = 4,
61748 + GR_STATUS = 5,
61749 + GR_UNSPROLE = 6,
61750 + GR_PASSSET = 7,
61751 + GR_SPROLEPAM = 8,
61752 +};
61753 +
61754 +/* Password setup definitions
61755 + * kernel/grhash.c */
61756 +enum {
61757 + GR_PW_LEN = 128,
61758 + GR_SALT_LEN = 16,
61759 + GR_SHA_LEN = 32,
61760 +};
61761 +
61762 +enum {
61763 + GR_SPROLE_LEN = 64,
61764 +};
61765 +
61766 +enum {
61767 + GR_NO_GLOB = 0,
61768 + GR_REG_GLOB,
61769 + GR_CREATE_GLOB
61770 +};
61771 +
61772 +#define GR_NLIMITS 32
61773 +
61774 +/* Begin Data Structures */
61775 +
61776 +struct sprole_pw {
61777 + unsigned char *rolename;
61778 + unsigned char salt[GR_SALT_LEN];
61779 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61780 +};
61781 +
61782 +struct name_entry {
61783 + __u32 key;
61784 + ino_t inode;
61785 + dev_t device;
61786 + char *name;
61787 + __u16 len;
61788 + __u8 deleted;
61789 + struct name_entry *prev;
61790 + struct name_entry *next;
61791 +};
61792 +
61793 +struct inodev_entry {
61794 + struct name_entry *nentry;
61795 + struct inodev_entry *prev;
61796 + struct inodev_entry *next;
61797 +};
61798 +
61799 +struct acl_role_db {
61800 + struct acl_role_label **r_hash;
61801 + __u32 r_size;
61802 +};
61803 +
61804 +struct inodev_db {
61805 + struct inodev_entry **i_hash;
61806 + __u32 i_size;
61807 +};
61808 +
61809 +struct name_db {
61810 + struct name_entry **n_hash;
61811 + __u32 n_size;
61812 +};
61813 +
61814 +struct crash_uid {
61815 + uid_t uid;
61816 + unsigned long expires;
61817 +};
61818 +
61819 +struct gr_hash_struct {
61820 + void **table;
61821 + void **nametable;
61822 + void *first;
61823 + __u32 table_size;
61824 + __u32 used_size;
61825 + int type;
61826 +};
61827 +
61828 +/* Userspace Grsecurity ACL data structures */
61829 +
61830 +struct acl_subject_label {
61831 + char *filename;
61832 + ino_t inode;
61833 + dev_t device;
61834 + __u32 mode;
61835 + kernel_cap_t cap_mask;
61836 + kernel_cap_t cap_lower;
61837 + kernel_cap_t cap_invert_audit;
61838 +
61839 + struct rlimit res[GR_NLIMITS];
61840 + __u32 resmask;
61841 +
61842 + __u8 user_trans_type;
61843 + __u8 group_trans_type;
61844 + uid_t *user_transitions;
61845 + gid_t *group_transitions;
61846 + __u16 user_trans_num;
61847 + __u16 group_trans_num;
61848 +
61849 + __u32 sock_families[2];
61850 + __u32 ip_proto[8];
61851 + __u32 ip_type;
61852 + struct acl_ip_label **ips;
61853 + __u32 ip_num;
61854 + __u32 inaddr_any_override;
61855 +
61856 + __u32 crashes;
61857 + unsigned long expires;
61858 +
61859 + struct acl_subject_label *parent_subject;
61860 + struct gr_hash_struct *hash;
61861 + struct acl_subject_label *prev;
61862 + struct acl_subject_label *next;
61863 +
61864 + struct acl_object_label **obj_hash;
61865 + __u32 obj_hash_size;
61866 + __u16 pax_flags;
61867 +};
61868 +
61869 +struct role_allowed_ip {
61870 + __u32 addr;
61871 + __u32 netmask;
61872 +
61873 + struct role_allowed_ip *prev;
61874 + struct role_allowed_ip *next;
61875 +};
61876 +
61877 +struct role_transition {
61878 + char *rolename;
61879 +
61880 + struct role_transition *prev;
61881 + struct role_transition *next;
61882 +};
61883 +
61884 +struct acl_role_label {
61885 + char *rolename;
61886 + uid_t uidgid;
61887 + __u16 roletype;
61888 +
61889 + __u16 auth_attempts;
61890 + unsigned long expires;
61891 +
61892 + struct acl_subject_label *root_label;
61893 + struct gr_hash_struct *hash;
61894 +
61895 + struct acl_role_label *prev;
61896 + struct acl_role_label *next;
61897 +
61898 + struct role_transition *transitions;
61899 + struct role_allowed_ip *allowed_ips;
61900 + uid_t *domain_children;
61901 + __u16 domain_child_num;
61902 +
61903 + umode_t umask;
61904 +
61905 + struct acl_subject_label **subj_hash;
61906 + __u32 subj_hash_size;
61907 +};
61908 +
61909 +struct user_acl_role_db {
61910 + struct acl_role_label **r_table;
61911 + __u32 num_pointers; /* Number of allocations to track */
61912 + __u32 num_roles; /* Number of roles */
61913 + __u32 num_domain_children; /* Number of domain children */
61914 + __u32 num_subjects; /* Number of subjects */
61915 + __u32 num_objects; /* Number of objects */
61916 +};
61917 +
61918 +struct acl_object_label {
61919 + char *filename;
61920 + ino_t inode;
61921 + dev_t device;
61922 + __u32 mode;
61923 +
61924 + struct acl_subject_label *nested;
61925 + struct acl_object_label *globbed;
61926 +
61927 + /* next two structures not used */
61928 +
61929 + struct acl_object_label *prev;
61930 + struct acl_object_label *next;
61931 +};
61932 +
61933 +struct acl_ip_label {
61934 + char *iface;
61935 + __u32 addr;
61936 + __u32 netmask;
61937 + __u16 low, high;
61938 + __u8 mode;
61939 + __u32 type;
61940 + __u32 proto[8];
61941 +
61942 + /* next two structures not used */
61943 +
61944 + struct acl_ip_label *prev;
61945 + struct acl_ip_label *next;
61946 +};
61947 +
61948 +struct gr_arg {
61949 + struct user_acl_role_db role_db;
61950 + unsigned char pw[GR_PW_LEN];
61951 + unsigned char salt[GR_SALT_LEN];
61952 + unsigned char sum[GR_SHA_LEN];
61953 + unsigned char sp_role[GR_SPROLE_LEN];
61954 + struct sprole_pw *sprole_pws;
61955 + dev_t segv_device;
61956 + ino_t segv_inode;
61957 + uid_t segv_uid;
61958 + __u16 num_sprole_pws;
61959 + __u16 mode;
61960 +};
61961 +
61962 +struct gr_arg_wrapper {
61963 + struct gr_arg *arg;
61964 + __u32 version;
61965 + __u32 size;
61966 +};
61967 +
61968 +struct subject_map {
61969 + struct acl_subject_label *user;
61970 + struct acl_subject_label *kernel;
61971 + struct subject_map *prev;
61972 + struct subject_map *next;
61973 +};
61974 +
61975 +struct acl_subj_map_db {
61976 + struct subject_map **s_hash;
61977 + __u32 s_size;
61978 +};
61979 +
61980 +/* End Data Structures Section */
61981 +
61982 +/* Hash functions generated by empirical testing by Brad Spengler
61983 + Makes good use of the low bits of the inode. Generally 0-1 times
61984 + in loop for successful match. 0-3 for unsuccessful match.
61985 + Shift/add algorithm with modulus of table size and an XOR*/
61986 +
61987 +static __inline__ unsigned int
61988 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61989 +{
61990 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61991 +}
61992 +
61993 + static __inline__ unsigned int
61994 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61995 +{
61996 + return ((const unsigned long)userp % sz);
61997 +}
61998 +
61999 +static __inline__ unsigned int
62000 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62001 +{
62002 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62003 +}
62004 +
62005 +static __inline__ unsigned int
62006 +nhash(const char *name, const __u16 len, const unsigned int sz)
62007 +{
62008 + return full_name_hash((const unsigned char *)name, len) % sz;
62009 +}
62010 +
62011 +#define FOR_EACH_ROLE_START(role) \
62012 + role = role_list; \
62013 + while (role) {
62014 +
62015 +#define FOR_EACH_ROLE_END(role) \
62016 + role = role->prev; \
62017 + }
62018 +
62019 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62020 + subj = NULL; \
62021 + iter = 0; \
62022 + while (iter < role->subj_hash_size) { \
62023 + if (subj == NULL) \
62024 + subj = role->subj_hash[iter]; \
62025 + if (subj == NULL) { \
62026 + iter++; \
62027 + continue; \
62028 + }
62029 +
62030 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62031 + subj = subj->next; \
62032 + if (subj == NULL) \
62033 + iter++; \
62034 + }
62035 +
62036 +
62037 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62038 + subj = role->hash->first; \
62039 + while (subj != NULL) {
62040 +
62041 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62042 + subj = subj->next; \
62043 + }
62044 +
62045 +#endif
62046 +
62047 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62048 new file mode 100644
62049 index 0000000..323ecf2
62050 --- /dev/null
62051 +++ b/include/linux/gralloc.h
62052 @@ -0,0 +1,9 @@
62053 +#ifndef __GRALLOC_H
62054 +#define __GRALLOC_H
62055 +
62056 +void acl_free_all(void);
62057 +int acl_alloc_stack_init(unsigned long size);
62058 +void *acl_alloc(unsigned long len);
62059 +void *acl_alloc_num(unsigned long num, unsigned long len);
62060 +
62061 +#endif
62062 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62063 new file mode 100644
62064 index 0000000..b30e9bc
62065 --- /dev/null
62066 +++ b/include/linux/grdefs.h
62067 @@ -0,0 +1,140 @@
62068 +#ifndef GRDEFS_H
62069 +#define GRDEFS_H
62070 +
62071 +/* Begin grsecurity status declarations */
62072 +
62073 +enum {
62074 + GR_READY = 0x01,
62075 + GR_STATUS_INIT = 0x00 // disabled state
62076 +};
62077 +
62078 +/* Begin ACL declarations */
62079 +
62080 +/* Role flags */
62081 +
62082 +enum {
62083 + GR_ROLE_USER = 0x0001,
62084 + GR_ROLE_GROUP = 0x0002,
62085 + GR_ROLE_DEFAULT = 0x0004,
62086 + GR_ROLE_SPECIAL = 0x0008,
62087 + GR_ROLE_AUTH = 0x0010,
62088 + GR_ROLE_NOPW = 0x0020,
62089 + GR_ROLE_GOD = 0x0040,
62090 + GR_ROLE_LEARN = 0x0080,
62091 + GR_ROLE_TPE = 0x0100,
62092 + GR_ROLE_DOMAIN = 0x0200,
62093 + GR_ROLE_PAM = 0x0400,
62094 + GR_ROLE_PERSIST = 0x0800
62095 +};
62096 +
62097 +/* ACL Subject and Object mode flags */
62098 +enum {
62099 + GR_DELETED = 0x80000000
62100 +};
62101 +
62102 +/* ACL Object-only mode flags */
62103 +enum {
62104 + GR_READ = 0x00000001,
62105 + GR_APPEND = 0x00000002,
62106 + GR_WRITE = 0x00000004,
62107 + GR_EXEC = 0x00000008,
62108 + GR_FIND = 0x00000010,
62109 + GR_INHERIT = 0x00000020,
62110 + GR_SETID = 0x00000040,
62111 + GR_CREATE = 0x00000080,
62112 + GR_DELETE = 0x00000100,
62113 + GR_LINK = 0x00000200,
62114 + GR_AUDIT_READ = 0x00000400,
62115 + GR_AUDIT_APPEND = 0x00000800,
62116 + GR_AUDIT_WRITE = 0x00001000,
62117 + GR_AUDIT_EXEC = 0x00002000,
62118 + GR_AUDIT_FIND = 0x00004000,
62119 + GR_AUDIT_INHERIT= 0x00008000,
62120 + GR_AUDIT_SETID = 0x00010000,
62121 + GR_AUDIT_CREATE = 0x00020000,
62122 + GR_AUDIT_DELETE = 0x00040000,
62123 + GR_AUDIT_LINK = 0x00080000,
62124 + GR_PTRACERD = 0x00100000,
62125 + GR_NOPTRACE = 0x00200000,
62126 + GR_SUPPRESS = 0x00400000,
62127 + GR_NOLEARN = 0x00800000,
62128 + GR_INIT_TRANSFER= 0x01000000
62129 +};
62130 +
62131 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62132 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62133 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62134 +
62135 +/* ACL subject-only mode flags */
62136 +enum {
62137 + GR_KILL = 0x00000001,
62138 + GR_VIEW = 0x00000002,
62139 + GR_PROTECTED = 0x00000004,
62140 + GR_LEARN = 0x00000008,
62141 + GR_OVERRIDE = 0x00000010,
62142 + /* just a placeholder, this mode is only used in userspace */
62143 + GR_DUMMY = 0x00000020,
62144 + GR_PROTSHM = 0x00000040,
62145 + GR_KILLPROC = 0x00000080,
62146 + GR_KILLIPPROC = 0x00000100,
62147 + /* just a placeholder, this mode is only used in userspace */
62148 + GR_NOTROJAN = 0x00000200,
62149 + GR_PROTPROCFD = 0x00000400,
62150 + GR_PROCACCT = 0x00000800,
62151 + GR_RELAXPTRACE = 0x00001000,
62152 + GR_NESTED = 0x00002000,
62153 + GR_INHERITLEARN = 0x00004000,
62154 + GR_PROCFIND = 0x00008000,
62155 + GR_POVERRIDE = 0x00010000,
62156 + GR_KERNELAUTH = 0x00020000,
62157 + GR_ATSECURE = 0x00040000,
62158 + GR_SHMEXEC = 0x00080000
62159 +};
62160 +
62161 +enum {
62162 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62163 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62164 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62165 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62166 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62167 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62168 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62169 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62170 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62171 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62172 +};
62173 +
62174 +enum {
62175 + GR_ID_USER = 0x01,
62176 + GR_ID_GROUP = 0x02,
62177 +};
62178 +
62179 +enum {
62180 + GR_ID_ALLOW = 0x01,
62181 + GR_ID_DENY = 0x02,
62182 +};
62183 +
62184 +#define GR_CRASH_RES 31
62185 +#define GR_UIDTABLE_MAX 500
62186 +
62187 +/* begin resource learning section */
62188 +enum {
62189 + GR_RLIM_CPU_BUMP = 60,
62190 + GR_RLIM_FSIZE_BUMP = 50000,
62191 + GR_RLIM_DATA_BUMP = 10000,
62192 + GR_RLIM_STACK_BUMP = 1000,
62193 + GR_RLIM_CORE_BUMP = 10000,
62194 + GR_RLIM_RSS_BUMP = 500000,
62195 + GR_RLIM_NPROC_BUMP = 1,
62196 + GR_RLIM_NOFILE_BUMP = 5,
62197 + GR_RLIM_MEMLOCK_BUMP = 50000,
62198 + GR_RLIM_AS_BUMP = 500000,
62199 + GR_RLIM_LOCKS_BUMP = 2,
62200 + GR_RLIM_SIGPENDING_BUMP = 5,
62201 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62202 + GR_RLIM_NICE_BUMP = 1,
62203 + GR_RLIM_RTPRIO_BUMP = 1,
62204 + GR_RLIM_RTTIME_BUMP = 1000000
62205 +};
62206 +
62207 +#endif
62208 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62209 new file mode 100644
62210 index 0000000..c9292f7
62211 --- /dev/null
62212 +++ b/include/linux/grinternal.h
62213 @@ -0,0 +1,223 @@
62214 +#ifndef __GRINTERNAL_H
62215 +#define __GRINTERNAL_H
62216 +
62217 +#ifdef CONFIG_GRKERNSEC
62218 +
62219 +#include <linux/fs.h>
62220 +#include <linux/mnt_namespace.h>
62221 +#include <linux/nsproxy.h>
62222 +#include <linux/gracl.h>
62223 +#include <linux/grdefs.h>
62224 +#include <linux/grmsg.h>
62225 +
62226 +void gr_add_learn_entry(const char *fmt, ...)
62227 + __attribute__ ((format (printf, 1, 2)));
62228 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62229 + const struct vfsmount *mnt);
62230 +__u32 gr_check_create(const struct dentry *new_dentry,
62231 + const struct dentry *parent,
62232 + const struct vfsmount *mnt, const __u32 mode);
62233 +int gr_check_protected_task(const struct task_struct *task);
62234 +__u32 to_gr_audit(const __u32 reqmode);
62235 +int gr_set_acls(const int type);
62236 +int gr_apply_subject_to_task(struct task_struct *task);
62237 +int gr_acl_is_enabled(void);
62238 +char gr_roletype_to_char(void);
62239 +
62240 +void gr_handle_alertkill(struct task_struct *task);
62241 +char *gr_to_filename(const struct dentry *dentry,
62242 + const struct vfsmount *mnt);
62243 +char *gr_to_filename1(const struct dentry *dentry,
62244 + const struct vfsmount *mnt);
62245 +char *gr_to_filename2(const struct dentry *dentry,
62246 + const struct vfsmount *mnt);
62247 +char *gr_to_filename3(const struct dentry *dentry,
62248 + const struct vfsmount *mnt);
62249 +
62250 +extern int grsec_enable_ptrace_readexec;
62251 +extern int grsec_enable_harden_ptrace;
62252 +extern int grsec_enable_link;
62253 +extern int grsec_enable_fifo;
62254 +extern int grsec_enable_execve;
62255 +extern int grsec_enable_shm;
62256 +extern int grsec_enable_execlog;
62257 +extern int grsec_enable_signal;
62258 +extern int grsec_enable_audit_ptrace;
62259 +extern int grsec_enable_forkfail;
62260 +extern int grsec_enable_time;
62261 +extern int grsec_enable_rofs;
62262 +extern int grsec_enable_chroot_shmat;
62263 +extern int grsec_enable_chroot_mount;
62264 +extern int grsec_enable_chroot_double;
62265 +extern int grsec_enable_chroot_pivot;
62266 +extern int grsec_enable_chroot_chdir;
62267 +extern int grsec_enable_chroot_chmod;
62268 +extern int grsec_enable_chroot_mknod;
62269 +extern int grsec_enable_chroot_fchdir;
62270 +extern int grsec_enable_chroot_nice;
62271 +extern int grsec_enable_chroot_execlog;
62272 +extern int grsec_enable_chroot_caps;
62273 +extern int grsec_enable_chroot_sysctl;
62274 +extern int grsec_enable_chroot_unix;
62275 +extern int grsec_enable_symlinkown;
62276 +extern int grsec_symlinkown_gid;
62277 +extern int grsec_enable_tpe;
62278 +extern int grsec_tpe_gid;
62279 +extern int grsec_enable_tpe_all;
62280 +extern int grsec_enable_tpe_invert;
62281 +extern int grsec_enable_socket_all;
62282 +extern int grsec_socket_all_gid;
62283 +extern int grsec_enable_socket_client;
62284 +extern int grsec_socket_client_gid;
62285 +extern int grsec_enable_socket_server;
62286 +extern int grsec_socket_server_gid;
62287 +extern int grsec_audit_gid;
62288 +extern int grsec_enable_group;
62289 +extern int grsec_enable_audit_textrel;
62290 +extern int grsec_enable_log_rwxmaps;
62291 +extern int grsec_enable_mount;
62292 +extern int grsec_enable_chdir;
62293 +extern int grsec_resource_logging;
62294 +extern int grsec_enable_blackhole;
62295 +extern int grsec_lastack_retries;
62296 +extern int grsec_enable_brute;
62297 +extern int grsec_lock;
62298 +
62299 +extern spinlock_t grsec_alert_lock;
62300 +extern unsigned long grsec_alert_wtime;
62301 +extern unsigned long grsec_alert_fyet;
62302 +
62303 +extern spinlock_t grsec_audit_lock;
62304 +
62305 +extern rwlock_t grsec_exec_file_lock;
62306 +
62307 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62308 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62309 + (tsk)->exec_file->f_vfsmnt) : "/")
62310 +
62311 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62312 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62313 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62314 +
62315 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62316 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62317 + (tsk)->exec_file->f_vfsmnt) : "/")
62318 +
62319 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62320 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62321 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62322 +
62323 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62324 +
62325 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62326 +
62327 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62328 + (task)->pid, (cred)->uid, \
62329 + (cred)->euid, (cred)->gid, (cred)->egid, \
62330 + gr_parent_task_fullpath(task), \
62331 + (task)->real_parent->comm, (task)->real_parent->pid, \
62332 + (pcred)->uid, (pcred)->euid, \
62333 + (pcred)->gid, (pcred)->egid
62334 +
62335 +#define GR_CHROOT_CAPS {{ \
62336 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62337 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62338 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62339 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62340 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62341 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62342 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62343 +
62344 +#define security_learn(normal_msg,args...) \
62345 +({ \
62346 + read_lock(&grsec_exec_file_lock); \
62347 + gr_add_learn_entry(normal_msg "\n", ## args); \
62348 + read_unlock(&grsec_exec_file_lock); \
62349 +})
62350 +
62351 +enum {
62352 + GR_DO_AUDIT,
62353 + GR_DONT_AUDIT,
62354 + /* used for non-audit messages that we shouldn't kill the task on */
62355 + GR_DONT_AUDIT_GOOD
62356 +};
62357 +
62358 +enum {
62359 + GR_TTYSNIFF,
62360 + GR_RBAC,
62361 + GR_RBAC_STR,
62362 + GR_STR_RBAC,
62363 + GR_RBAC_MODE2,
62364 + GR_RBAC_MODE3,
62365 + GR_FILENAME,
62366 + GR_SYSCTL_HIDDEN,
62367 + GR_NOARGS,
62368 + GR_ONE_INT,
62369 + GR_ONE_INT_TWO_STR,
62370 + GR_ONE_STR,
62371 + GR_STR_INT,
62372 + GR_TWO_STR_INT,
62373 + GR_TWO_INT,
62374 + GR_TWO_U64,
62375 + GR_THREE_INT,
62376 + GR_FIVE_INT_TWO_STR,
62377 + GR_TWO_STR,
62378 + GR_THREE_STR,
62379 + GR_FOUR_STR,
62380 + GR_STR_FILENAME,
62381 + GR_FILENAME_STR,
62382 + GR_FILENAME_TWO_INT,
62383 + GR_FILENAME_TWO_INT_STR,
62384 + GR_TEXTREL,
62385 + GR_PTRACE,
62386 + GR_RESOURCE,
62387 + GR_CAP,
62388 + GR_SIG,
62389 + GR_SIG2,
62390 + GR_CRASH1,
62391 + GR_CRASH2,
62392 + GR_PSACCT,
62393 + GR_RWXMAP
62394 +};
62395 +
62396 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62397 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62398 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62399 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62400 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62401 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62402 +#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)
62403 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62404 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62405 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62406 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62407 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62408 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62409 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62410 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62411 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62412 +#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)
62413 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62414 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62415 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62416 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62417 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62418 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62419 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62420 +#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)
62421 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62422 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62423 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62424 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62425 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62426 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62427 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62428 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62429 +#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)
62430 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62431 +
62432 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62433 +
62434 +#endif
62435 +
62436 +#endif
62437 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62438 new file mode 100644
62439 index 0000000..54f4e85
62440 --- /dev/null
62441 +++ b/include/linux/grmsg.h
62442 @@ -0,0 +1,110 @@
62443 +#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"
62444 +#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"
62445 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62446 +#define GR_STOPMOD_MSG "denied modification of module state by "
62447 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62448 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62449 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62450 +#define GR_IOPL_MSG "denied use of iopl() by "
62451 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62452 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62453 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62454 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62455 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62456 +#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"
62457 +#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"
62458 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62459 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62460 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62461 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62462 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62463 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62464 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62465 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62466 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62467 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62468 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62469 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62470 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62471 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62472 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62473 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62474 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62475 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62476 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62477 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62478 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62479 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62480 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62481 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62482 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62483 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62484 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62485 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62486 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62487 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62488 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62489 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62490 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62491 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62492 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62493 +#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"
62494 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62495 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62496 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62497 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62498 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62499 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62500 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62501 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62502 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62503 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62504 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62505 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62506 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62507 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62508 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62509 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62510 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62511 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62512 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62513 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62514 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62515 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62516 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62517 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62518 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62519 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62520 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62521 +#define GR_TIME_MSG "time set by "
62522 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62523 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62524 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62525 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62526 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62527 +#define GR_BIND_MSG "denied bind() by "
62528 +#define GR_CONNECT_MSG "denied connect() by "
62529 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62530 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62531 +#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"
62532 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62533 +#define GR_CAP_ACL_MSG "use of %s denied for "
62534 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62535 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62536 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62537 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62538 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62539 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62540 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62541 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62542 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62543 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62544 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62545 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62546 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62547 +#define GR_VM86_MSG "denied use of vm86 by "
62548 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62549 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62550 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62551 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62552 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62553 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62554 new file mode 100644
62555 index 0000000..f9b9a21
62556 --- /dev/null
62557 +++ b/include/linux/grsecurity.h
62558 @@ -0,0 +1,238 @@
62559 +#ifndef GR_SECURITY_H
62560 +#define GR_SECURITY_H
62561 +#include <linux/fs.h>
62562 +#include <linux/fs_struct.h>
62563 +#include <linux/binfmts.h>
62564 +#include <linux/gracl.h>
62565 +
62566 +/* notify of brain-dead configs */
62567 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62568 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62569 +#endif
62570 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62571 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62572 +#endif
62573 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62574 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62575 +#endif
62576 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62577 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62578 +#endif
62579 +
62580 +#include <linux/compat.h>
62581 +
62582 +struct user_arg_ptr {
62583 +#ifdef CONFIG_COMPAT
62584 + bool is_compat;
62585 +#endif
62586 + union {
62587 + const char __user *const __user *native;
62588 +#ifdef CONFIG_COMPAT
62589 + compat_uptr_t __user *compat;
62590 +#endif
62591 + } ptr;
62592 +};
62593 +
62594 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62595 +void gr_handle_brute_check(void);
62596 +void gr_handle_kernel_exploit(void);
62597 +int gr_process_user_ban(void);
62598 +
62599 +char gr_roletype_to_char(void);
62600 +
62601 +int gr_acl_enable_at_secure(void);
62602 +
62603 +int gr_check_user_change(int real, int effective, int fs);
62604 +int gr_check_group_change(int real, int effective, int fs);
62605 +
62606 +void gr_del_task_from_ip_table(struct task_struct *p);
62607 +
62608 +int gr_pid_is_chrooted(struct task_struct *p);
62609 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62610 +int gr_handle_chroot_nice(void);
62611 +int gr_handle_chroot_sysctl(const int op);
62612 +int gr_handle_chroot_setpriority(struct task_struct *p,
62613 + const int niceval);
62614 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62615 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62616 + const struct vfsmount *mnt);
62617 +void gr_handle_chroot_chdir(struct path *path);
62618 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62619 + const struct vfsmount *mnt, const int mode);
62620 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62621 + const struct vfsmount *mnt, const int mode);
62622 +int gr_handle_chroot_mount(const struct dentry *dentry,
62623 + const struct vfsmount *mnt,
62624 + const char *dev_name);
62625 +int gr_handle_chroot_pivot(void);
62626 +int gr_handle_chroot_unix(const pid_t pid);
62627 +
62628 +int gr_handle_rawio(const struct inode *inode);
62629 +
62630 +void gr_handle_ioperm(void);
62631 +void gr_handle_iopl(void);
62632 +
62633 +umode_t gr_acl_umask(void);
62634 +
62635 +int gr_tpe_allow(const struct file *file);
62636 +
62637 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62638 +void gr_clear_chroot_entries(struct task_struct *task);
62639 +
62640 +void gr_log_forkfail(const int retval);
62641 +void gr_log_timechange(void);
62642 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62643 +void gr_log_chdir(const struct dentry *dentry,
62644 + const struct vfsmount *mnt);
62645 +void gr_log_chroot_exec(const struct dentry *dentry,
62646 + const struct vfsmount *mnt);
62647 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62648 +void gr_log_remount(const char *devname, const int retval);
62649 +void gr_log_unmount(const char *devname, const int retval);
62650 +void gr_log_mount(const char *from, const char *to, const int retval);
62651 +void gr_log_textrel(struct vm_area_struct *vma);
62652 +void gr_log_rwxmmap(struct file *file);
62653 +void gr_log_rwxmprotect(struct file *file);
62654 +
62655 +int gr_handle_follow_link(const struct inode *parent,
62656 + const struct inode *inode,
62657 + const struct dentry *dentry,
62658 + const struct vfsmount *mnt);
62659 +int gr_handle_fifo(const struct dentry *dentry,
62660 + const struct vfsmount *mnt,
62661 + const struct dentry *dir, const int flag,
62662 + const int acc_mode);
62663 +int gr_handle_hardlink(const struct dentry *dentry,
62664 + const struct vfsmount *mnt,
62665 + struct inode *inode,
62666 + const int mode, const char *to);
62667 +
62668 +int gr_is_capable(const int cap);
62669 +int gr_is_capable_nolog(const int cap);
62670 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62671 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62672 +
62673 +void gr_learn_resource(const struct task_struct *task, const int limit,
62674 + const unsigned long wanted, const int gt);
62675 +void gr_copy_label(struct task_struct *tsk);
62676 +void gr_handle_crash(struct task_struct *task, const int sig);
62677 +int gr_handle_signal(const struct task_struct *p, const int sig);
62678 +int gr_check_crash_uid(const uid_t uid);
62679 +int gr_check_protected_task(const struct task_struct *task);
62680 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62681 +int gr_acl_handle_mmap(const struct file *file,
62682 + const unsigned long prot);
62683 +int gr_acl_handle_mprotect(const struct file *file,
62684 + const unsigned long prot);
62685 +int gr_check_hidden_task(const struct task_struct *tsk);
62686 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62687 + const struct vfsmount *mnt);
62688 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62689 + const struct vfsmount *mnt);
62690 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62691 + const struct vfsmount *mnt, const int fmode);
62692 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62693 + const struct vfsmount *mnt, umode_t *mode);
62694 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62695 + const struct vfsmount *mnt);
62696 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62697 + const struct vfsmount *mnt);
62698 +int gr_handle_ptrace(struct task_struct *task, const long request);
62699 +int gr_handle_proc_ptrace(struct task_struct *task);
62700 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62701 + const struct vfsmount *mnt);
62702 +int gr_check_crash_exec(const struct file *filp);
62703 +int gr_acl_is_enabled(void);
62704 +void gr_set_kernel_label(struct task_struct *task);
62705 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62706 + const gid_t gid);
62707 +int gr_set_proc_label(const struct dentry *dentry,
62708 + const struct vfsmount *mnt,
62709 + const int unsafe_flags);
62710 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62711 + const struct vfsmount *mnt);
62712 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62713 + const struct vfsmount *mnt, int acc_mode);
62714 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62715 + const struct dentry *p_dentry,
62716 + const struct vfsmount *p_mnt,
62717 + int open_flags, int acc_mode, const int imode);
62718 +void gr_handle_create(const struct dentry *dentry,
62719 + const struct vfsmount *mnt);
62720 +void gr_handle_proc_create(const struct dentry *dentry,
62721 + const struct inode *inode);
62722 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62723 + const struct dentry *parent_dentry,
62724 + const struct vfsmount *parent_mnt,
62725 + const int mode);
62726 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62727 + const struct dentry *parent_dentry,
62728 + const struct vfsmount *parent_mnt);
62729 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62730 + const struct vfsmount *mnt);
62731 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62732 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62733 + const struct vfsmount *mnt);
62734 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62735 + const struct dentry *parent_dentry,
62736 + const struct vfsmount *parent_mnt,
62737 + const char *from);
62738 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62739 + const struct dentry *parent_dentry,
62740 + const struct vfsmount *parent_mnt,
62741 + const struct dentry *old_dentry,
62742 + const struct vfsmount *old_mnt, const char *to);
62743 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62744 +int gr_acl_handle_rename(struct dentry *new_dentry,
62745 + struct dentry *parent_dentry,
62746 + const struct vfsmount *parent_mnt,
62747 + struct dentry *old_dentry,
62748 + struct inode *old_parent_inode,
62749 + struct vfsmount *old_mnt, const char *newname);
62750 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62751 + struct dentry *old_dentry,
62752 + struct dentry *new_dentry,
62753 + struct vfsmount *mnt, const __u8 replace);
62754 +__u32 gr_check_link(const struct dentry *new_dentry,
62755 + const struct dentry *parent_dentry,
62756 + const struct vfsmount *parent_mnt,
62757 + const struct dentry *old_dentry,
62758 + const struct vfsmount *old_mnt);
62759 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62760 + const unsigned int namelen, const ino_t ino);
62761 +
62762 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62763 + const struct vfsmount *mnt);
62764 +void gr_acl_handle_exit(void);
62765 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62766 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62767 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62768 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62769 +void gr_audit_ptrace(struct task_struct *task);
62770 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62771 +
62772 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62773 +
62774 +#ifdef CONFIG_GRKERNSEC
62775 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62776 +void gr_handle_vm86(void);
62777 +void gr_handle_mem_readwrite(u64 from, u64 to);
62778 +
62779 +void gr_log_badprocpid(const char *entry);
62780 +
62781 +extern int grsec_enable_dmesg;
62782 +extern int grsec_disable_privio;
62783 +
62784 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62785 +extern int grsec_proc_gid;
62786 +#endif
62787 +
62788 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62789 +extern int grsec_enable_chroot_findtask;
62790 +#endif
62791 +#ifdef CONFIG_GRKERNSEC_SETXID
62792 +extern int grsec_enable_setxid;
62793 +#endif
62794 +#endif
62795 +
62796 +#endif
62797 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62798 new file mode 100644
62799 index 0000000..e7ffaaf
62800 --- /dev/null
62801 +++ b/include/linux/grsock.h
62802 @@ -0,0 +1,19 @@
62803 +#ifndef __GRSOCK_H
62804 +#define __GRSOCK_H
62805 +
62806 +extern void gr_attach_curr_ip(const struct sock *sk);
62807 +extern int gr_handle_sock_all(const int family, const int type,
62808 + const int protocol);
62809 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62810 +extern int gr_handle_sock_server_other(const struct sock *sck);
62811 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62812 +extern int gr_search_connect(struct socket * sock,
62813 + struct sockaddr_in * addr);
62814 +extern int gr_search_bind(struct socket * sock,
62815 + struct sockaddr_in * addr);
62816 +extern int gr_search_listen(struct socket * sock);
62817 +extern int gr_search_accept(struct socket * sock);
62818 +extern int gr_search_socket(const int domain, const int type,
62819 + const int protocol);
62820 +
62821 +#endif
62822 diff --git a/include/linux/hid.h b/include/linux/hid.h
62823 index 42970de..5db3c92 100644
62824 --- a/include/linux/hid.h
62825 +++ b/include/linux/hid.h
62826 @@ -705,7 +705,7 @@ struct hid_ll_driver {
62827 unsigned int code, int value);
62828
62829 int (*parse)(struct hid_device *hdev);
62830 -};
62831 +} __no_const;
62832
62833 #define PM_HINT_FULLON 1<<5
62834 #define PM_HINT_NORMAL 1<<1
62835 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62836 index ef788b5..ac41b7b 100644
62837 --- a/include/linux/highmem.h
62838 +++ b/include/linux/highmem.h
62839 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62840 kunmap_atomic(kaddr);
62841 }
62842
62843 +static inline void sanitize_highpage(struct page *page)
62844 +{
62845 + void *kaddr;
62846 + unsigned long flags;
62847 +
62848 + local_irq_save(flags);
62849 + kaddr = kmap_atomic(page);
62850 + clear_page(kaddr);
62851 + kunmap_atomic(kaddr);
62852 + local_irq_restore(flags);
62853 +}
62854 +
62855 static inline void zero_user_segments(struct page *page,
62856 unsigned start1, unsigned end1,
62857 unsigned start2, unsigned end2)
62858 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62859 index 5970266..1c48c3b 100644
62860 --- a/include/linux/i2c.h
62861 +++ b/include/linux/i2c.h
62862 @@ -369,6 +369,7 @@ struct i2c_algorithm {
62863 /* To determine what the adapter supports */
62864 u32 (*functionality) (struct i2c_adapter *);
62865 };
62866 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62867
62868 /*
62869 * i2c_adapter is the structure used to identify a physical i2c bus along
62870 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62871 index d23c3c2..eb63c81 100644
62872 --- a/include/linux/i2o.h
62873 +++ b/include/linux/i2o.h
62874 @@ -565,7 +565,7 @@ struct i2o_controller {
62875 struct i2o_device *exec; /* Executive */
62876 #if BITS_PER_LONG == 64
62877 spinlock_t context_list_lock; /* lock for context_list */
62878 - atomic_t context_list_counter; /* needed for unique contexts */
62879 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62880 struct list_head context_list; /* list of context id's
62881 and pointers */
62882 #endif
62883 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62884 index aa2e167..84024ce 100644
62885 --- a/include/linux/if_team.h
62886 +++ b/include/linux/if_team.h
62887 @@ -109,6 +109,7 @@ struct team_mode_ops {
62888 void (*port_enabled)(struct team *team, struct team_port *port);
62889 void (*port_disabled)(struct team *team, struct team_port *port);
62890 };
62891 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62892
62893 enum team_option_type {
62894 TEAM_OPTION_TYPE_U32,
62895 @@ -181,7 +182,7 @@ struct team {
62896 struct list_head option_inst_list; /* list of option instances */
62897
62898 const struct team_mode *mode;
62899 - struct team_mode_ops ops;
62900 + team_mode_ops_no_const ops;
62901 long mode_priv[TEAM_MODE_PRIV_LONGS];
62902 };
62903
62904 diff --git a/include/linux/init.h b/include/linux/init.h
62905 index 5e664f6..0a1225c 100644
62906 --- a/include/linux/init.h
62907 +++ b/include/linux/init.h
62908 @@ -39,9 +39,15 @@
62909 * Also note, that this data cannot be "const".
62910 */
62911
62912 +#ifdef MODULE
62913 +#define add_latent_entropy
62914 +#else
62915 +#define add_latent_entropy __latent_entropy
62916 +#endif
62917 +
62918 /* These are for everybody (although not all archs will actually
62919 discard it in modules) */
62920 -#define __init __section(.init.text) __cold notrace
62921 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62922 #define __initdata __section(.init.data)
62923 #define __initconst __section(.init.rodata)
62924 #define __exitdata __section(.exit.data)
62925 @@ -83,7 +89,7 @@
62926 #define __exit __section(.exit.text) __exitused __cold notrace
62927
62928 /* Used for HOTPLUG */
62929 -#define __devinit __section(.devinit.text) __cold notrace
62930 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62931 #define __devinitdata __section(.devinit.data)
62932 #define __devinitconst __section(.devinit.rodata)
62933 #define __devexit __section(.devexit.text) __exitused __cold notrace
62934 @@ -91,7 +97,7 @@
62935 #define __devexitconst __section(.devexit.rodata)
62936
62937 /* Used for HOTPLUG_CPU */
62938 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62939 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62940 #define __cpuinitdata __section(.cpuinit.data)
62941 #define __cpuinitconst __section(.cpuinit.rodata)
62942 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62943 @@ -99,7 +105,7 @@
62944 #define __cpuexitconst __section(.cpuexit.rodata)
62945
62946 /* Used for MEMORY_HOTPLUG */
62947 -#define __meminit __section(.meminit.text) __cold notrace
62948 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62949 #define __meminitdata __section(.meminit.data)
62950 #define __meminitconst __section(.meminit.rodata)
62951 #define __memexit __section(.memexit.text) __exitused __cold notrace
62952 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62953 index 89f1cb1..7986c0f 100644
62954 --- a/include/linux/init_task.h
62955 +++ b/include/linux/init_task.h
62956 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
62957
62958 #define INIT_TASK_COMM "swapper"
62959
62960 +#ifdef CONFIG_X86
62961 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62962 +#else
62963 +#define INIT_TASK_THREAD_INFO
62964 +#endif
62965 +
62966 /*
62967 * INIT_TASK is used to set up the first task table, touch at
62968 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62969 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
62970 RCU_POINTER_INITIALIZER(cred, &init_cred), \
62971 .comm = INIT_TASK_COMM, \
62972 .thread = INIT_THREAD, \
62973 + INIT_TASK_THREAD_INFO \
62974 .fs = &init_fs, \
62975 .files = &init_files, \
62976 .signal = &init_signals, \
62977 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62978 index 78e2ada..745564d 100644
62979 --- a/include/linux/intel-iommu.h
62980 +++ b/include/linux/intel-iommu.h
62981 @@ -296,7 +296,7 @@ struct iommu_flush {
62982 u8 fm, u64 type);
62983 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62984 unsigned int size_order, u64 type);
62985 -};
62986 +} __no_const;
62987
62988 enum {
62989 SR_DMAR_FECTL_REG,
62990 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62991 index c5f856a..d29c117 100644
62992 --- a/include/linux/interrupt.h
62993 +++ b/include/linux/interrupt.h
62994 @@ -433,7 +433,7 @@ enum
62995 /* map softirq index to softirq name. update 'softirq_to_name' in
62996 * kernel/softirq.c when adding a new softirq.
62997 */
62998 -extern char *softirq_to_name[NR_SOFTIRQS];
62999 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63000
63001 /* softirq mask and active fields moved to irq_cpustat_t in
63002 * asm/hardirq.h to get better cache usage. KAO
63003 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63004
63005 struct softirq_action
63006 {
63007 - void (*action)(struct softirq_action *);
63008 + void (*action)(void);
63009 };
63010
63011 asmlinkage void do_softirq(void);
63012 asmlinkage void __do_softirq(void);
63013 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63014 +extern void open_softirq(int nr, void (*action)(void));
63015 extern void softirq_init(void);
63016 extern void __raise_softirq_irqoff(unsigned int nr);
63017
63018 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63019 index 6883e19..06992b1 100644
63020 --- a/include/linux/kallsyms.h
63021 +++ b/include/linux/kallsyms.h
63022 @@ -15,7 +15,8 @@
63023
63024 struct module;
63025
63026 -#ifdef CONFIG_KALLSYMS
63027 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63028 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63029 /* Lookup the address for a symbol. Returns 0 if not found. */
63030 unsigned long kallsyms_lookup_name(const char *name);
63031
63032 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63033 /* Stupid that this does nothing, but I didn't create this mess. */
63034 #define __print_symbol(fmt, addr)
63035 #endif /*CONFIG_KALLSYMS*/
63036 +#else /* when included by kallsyms.c, vsnprintf.c, or
63037 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63038 +extern void __print_symbol(const char *fmt, unsigned long address);
63039 +extern int sprint_backtrace(char *buffer, unsigned long address);
63040 +extern int sprint_symbol(char *buffer, unsigned long address);
63041 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63042 +const char *kallsyms_lookup(unsigned long addr,
63043 + unsigned long *symbolsize,
63044 + unsigned long *offset,
63045 + char **modname, char *namebuf);
63046 +#endif
63047
63048 /* This macro allows us to keep printk typechecking */
63049 static __printf(1, 2)
63050 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63051 index c4d2fc1..5df9c19 100644
63052 --- a/include/linux/kgdb.h
63053 +++ b/include/linux/kgdb.h
63054 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63055 extern int kgdb_io_module_registered;
63056
63057 extern atomic_t kgdb_setting_breakpoint;
63058 -extern atomic_t kgdb_cpu_doing_single_step;
63059 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63060
63061 extern struct task_struct *kgdb_usethread;
63062 extern struct task_struct *kgdb_contthread;
63063 @@ -252,7 +252,7 @@ struct kgdb_arch {
63064 void (*disable_hw_break)(struct pt_regs *regs);
63065 void (*remove_all_hw_break)(void);
63066 void (*correct_hw_break)(void);
63067 -};
63068 +} __do_const;
63069
63070 /**
63071 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63072 @@ -277,7 +277,7 @@ struct kgdb_io {
63073 void (*pre_exception) (void);
63074 void (*post_exception) (void);
63075 int is_console;
63076 -};
63077 +} __do_const;
63078
63079 extern struct kgdb_arch arch_kgdb_ops;
63080
63081 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63082 index 5398d58..5883a34 100644
63083 --- a/include/linux/kmod.h
63084 +++ b/include/linux/kmod.h
63085 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63086 * usually useless though. */
63087 extern __printf(2, 3)
63088 int __request_module(bool wait, const char *name, ...);
63089 +extern __printf(3, 4)
63090 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63091 #define request_module(mod...) __request_module(true, mod)
63092 #define request_module_nowait(mod...) __request_module(false, mod)
63093 #define try_then_request_module(x, mod...) \
63094 diff --git a/include/linux/kref.h b/include/linux/kref.h
63095 index 65af688..0592677 100644
63096 --- a/include/linux/kref.h
63097 +++ b/include/linux/kref.h
63098 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63099 static inline int kref_sub(struct kref *kref, unsigned int count,
63100 void (*release)(struct kref *kref))
63101 {
63102 - WARN_ON(release == NULL);
63103 + BUG_ON(release == NULL);
63104
63105 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63106 release(kref);
63107 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63108 index b70b48b..0d7153b 100644
63109 --- a/include/linux/kvm_host.h
63110 +++ b/include/linux/kvm_host.h
63111 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63112 void vcpu_load(struct kvm_vcpu *vcpu);
63113 void vcpu_put(struct kvm_vcpu *vcpu);
63114
63115 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63116 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63117 struct module *module);
63118 void kvm_exit(void);
63119
63120 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63121 struct kvm_guest_debug *dbg);
63122 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63123
63124 -int kvm_arch_init(void *opaque);
63125 +int kvm_arch_init(const void *opaque);
63126 void kvm_arch_exit(void);
63127
63128 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63129 diff --git a/include/linux/libata.h b/include/linux/libata.h
63130 index 64f90e1..32b945b 100644
63131 --- a/include/linux/libata.h
63132 +++ b/include/linux/libata.h
63133 @@ -909,7 +909,7 @@ struct ata_port_operations {
63134 * fields must be pointers.
63135 */
63136 const struct ata_port_operations *inherits;
63137 -};
63138 +} __do_const;
63139
63140 struct ata_port_info {
63141 unsigned long flags;
63142 diff --git a/include/linux/memory.h b/include/linux/memory.h
63143 index ff9a9f8..c715deb 100644
63144 --- a/include/linux/memory.h
63145 +++ b/include/linux/memory.h
63146 @@ -143,7 +143,7 @@ struct memory_accessor {
63147 size_t count);
63148 ssize_t (*write)(struct memory_accessor *, const char *buf,
63149 off_t offset, size_t count);
63150 -};
63151 +} __no_const;
63152
63153 /*
63154 * Kernel text modification mutex, used for code patching. Users of this lock
63155 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63156 index 1318ca6..7521340 100644
63157 --- a/include/linux/mfd/abx500.h
63158 +++ b/include/linux/mfd/abx500.h
63159 @@ -452,6 +452,7 @@ struct abx500_ops {
63160 int (*event_registers_startup_state_get) (struct device *, u8 *);
63161 int (*startup_irq_enabled) (struct device *, unsigned int);
63162 };
63163 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63164
63165 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63166 void abx500_remove_ops(struct device *dev);
63167 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63168 index 9b07725..3d55001 100644
63169 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63170 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63171 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63172 int (*enable) (struct ux500_charger *, int, int, int);
63173 int (*kick_wd) (struct ux500_charger *);
63174 int (*update_curr) (struct ux500_charger *, int);
63175 -};
63176 +} __no_const;
63177
63178 /**
63179 * struct ux500_charger - power supply ux500 charger sub class
63180 diff --git a/include/linux/mm.h b/include/linux/mm.h
63181 index 311be90..5f1638c 100644
63182 --- a/include/linux/mm.h
63183 +++ b/include/linux/mm.h
63184 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63185
63186 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63187 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63188 +
63189 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63190 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63191 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63192 +#else
63193 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63194 +#endif
63195 +
63196 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63197 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63198
63199 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63200 int set_page_dirty_lock(struct page *page);
63201 int clear_page_dirty_for_io(struct page *page);
63202
63203 -/* Is the vma a continuation of the stack vma above it? */
63204 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63205 -{
63206 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63207 -}
63208 -
63209 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63210 - unsigned long addr)
63211 -{
63212 - return (vma->vm_flags & VM_GROWSDOWN) &&
63213 - (vma->vm_start == addr) &&
63214 - !vma_growsdown(vma->vm_prev, addr);
63215 -}
63216 -
63217 -/* Is the vma a continuation of the stack vma below it? */
63218 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63219 -{
63220 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63221 -}
63222 -
63223 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63224 - unsigned long addr)
63225 -{
63226 - return (vma->vm_flags & VM_GROWSUP) &&
63227 - (vma->vm_end == addr) &&
63228 - !vma_growsup(vma->vm_next, addr);
63229 -}
63230 -
63231 extern pid_t
63232 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63233
63234 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63235 }
63236 #endif
63237
63238 +#ifdef CONFIG_MMU
63239 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63240 +#else
63241 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63242 +{
63243 + return __pgprot(0);
63244 +}
63245 +#endif
63246 +
63247 int vma_wants_writenotify(struct vm_area_struct *vma);
63248
63249 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63250 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63251 {
63252 return 0;
63253 }
63254 +
63255 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63256 + unsigned long address)
63257 +{
63258 + return 0;
63259 +}
63260 #else
63261 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63262 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63263 #endif
63264
63265 #ifdef __PAGETABLE_PMD_FOLDED
63266 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63267 {
63268 return 0;
63269 }
63270 +
63271 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63272 + unsigned long address)
63273 +{
63274 + return 0;
63275 +}
63276 #else
63277 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63278 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63279 #endif
63280
63281 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63282 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63283 NULL: pud_offset(pgd, address);
63284 }
63285
63286 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63287 +{
63288 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63289 + NULL: pud_offset(pgd, address);
63290 +}
63291 +
63292 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63293 {
63294 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63295 NULL: pmd_offset(pud, address);
63296 }
63297 +
63298 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63299 +{
63300 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63301 + NULL: pmd_offset(pud, address);
63302 +}
63303 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63304
63305 #if USE_SPLIT_PTLOCKS
63306 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63307 unsigned long, unsigned long,
63308 unsigned long, unsigned long);
63309 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63310 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63311
63312 /* These take the mm semaphore themselves */
63313 extern unsigned long vm_brk(unsigned long, unsigned long);
63314 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63315 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63316 struct vm_area_struct **pprev);
63317
63318 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63319 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63320 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63321 +
63322 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63323 NULL if none. Assume start_addr < end_addr. */
63324 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63325 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63326 return vma;
63327 }
63328
63329 -#ifdef CONFIG_MMU
63330 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63331 -#else
63332 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63333 -{
63334 - return __pgprot(0);
63335 -}
63336 -#endif
63337 -
63338 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63339 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63340 unsigned long pfn, unsigned long size, pgprot_t);
63341 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63342 extern int sysctl_memory_failure_early_kill;
63343 extern int sysctl_memory_failure_recovery;
63344 extern void shake_page(struct page *p, int access);
63345 -extern atomic_long_t mce_bad_pages;
63346 +extern atomic_long_unchecked_t mce_bad_pages;
63347 extern int soft_offline_page(struct page *page, int flags);
63348
63349 extern void dump_page(struct page *page);
63350 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63351 static inline bool page_is_guard(struct page *page) { return false; }
63352 #endif /* CONFIG_DEBUG_PAGEALLOC */
63353
63354 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63355 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63356 +#else
63357 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63358 +#endif
63359 +
63360 #endif /* __KERNEL__ */
63361 #endif /* _LINUX_MM_H */
63362 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63363 index bf78672..debc693 100644
63364 --- a/include/linux/mm_types.h
63365 +++ b/include/linux/mm_types.h
63366 @@ -279,6 +279,8 @@ struct vm_area_struct {
63367 #ifdef CONFIG_NUMA
63368 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63369 #endif
63370 +
63371 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63372 };
63373
63374 struct core_thread {
63375 @@ -353,7 +355,7 @@ struct mm_struct {
63376 unsigned long def_flags;
63377 unsigned long nr_ptes; /* Page table pages */
63378 unsigned long start_code, end_code, start_data, end_data;
63379 - unsigned long start_brk, brk, start_stack;
63380 + unsigned long brk_gap, start_brk, brk, start_stack;
63381 unsigned long arg_start, arg_end, env_start, env_end;
63382
63383 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63384 @@ -405,6 +407,24 @@ struct mm_struct {
63385 struct cpumask cpumask_allocation;
63386 #endif
63387 struct uprobes_state uprobes_state;
63388 +
63389 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63390 + unsigned long pax_flags;
63391 +#endif
63392 +
63393 +#ifdef CONFIG_PAX_DLRESOLVE
63394 + unsigned long call_dl_resolve;
63395 +#endif
63396 +
63397 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63398 + unsigned long call_syscall;
63399 +#endif
63400 +
63401 +#ifdef CONFIG_PAX_ASLR
63402 + unsigned long delta_mmap; /* randomized offset */
63403 + unsigned long delta_stack; /* randomized offset */
63404 +#endif
63405 +
63406 };
63407
63408 static inline void mm_init_cpumask(struct mm_struct *mm)
63409 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63410 index 1d1b1e1..2a13c78 100644
63411 --- a/include/linux/mmu_notifier.h
63412 +++ b/include/linux/mmu_notifier.h
63413 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63414 */
63415 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63416 ({ \
63417 - pte_t __pte; \
63418 + pte_t ___pte; \
63419 struct vm_area_struct *___vma = __vma; \
63420 unsigned long ___address = __address; \
63421 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63422 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63423 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63424 - __pte; \
63425 + ___pte; \
63426 })
63427
63428 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63429 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63430 index 2daa54f..bfdf2f5 100644
63431 --- a/include/linux/mmzone.h
63432 +++ b/include/linux/mmzone.h
63433 @@ -414,7 +414,7 @@ struct zone {
63434 unsigned long flags; /* zone flags, see below */
63435
63436 /* Zone statistics */
63437 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63438 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63439
63440 /*
63441 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63442 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63443 index 6955045..ebdb7cd 100644
63444 --- a/include/linux/mod_devicetable.h
63445 +++ b/include/linux/mod_devicetable.h
63446 @@ -12,7 +12,7 @@
63447 typedef unsigned long kernel_ulong_t;
63448 #endif
63449
63450 -#define PCI_ANY_ID (~0)
63451 +#define PCI_ANY_ID ((__u16)~0)
63452
63453 struct pci_device_id {
63454 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63455 @@ -139,7 +139,7 @@ struct usb_device_id {
63456 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63457 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63458
63459 -#define HID_ANY_ID (~0)
63460 +#define HID_ANY_ID (~0U)
63461 #define HID_BUS_ANY 0xffff
63462 #define HID_GROUP_ANY 0x0000
63463
63464 diff --git a/include/linux/module.h b/include/linux/module.h
63465 index fbcafe2..e5d9587 100644
63466 --- a/include/linux/module.h
63467 +++ b/include/linux/module.h
63468 @@ -17,6 +17,7 @@
63469 #include <linux/moduleparam.h>
63470 #include <linux/tracepoint.h>
63471 #include <linux/export.h>
63472 +#include <linux/fs.h>
63473
63474 #include <linux/percpu.h>
63475 #include <asm/module.h>
63476 @@ -273,19 +274,16 @@ struct module
63477 int (*init)(void);
63478
63479 /* If this is non-NULL, vfree after init() returns */
63480 - void *module_init;
63481 + void *module_init_rx, *module_init_rw;
63482
63483 /* Here is the actual code + data, vfree'd on unload. */
63484 - void *module_core;
63485 + void *module_core_rx, *module_core_rw;
63486
63487 /* Here are the sizes of the init and core sections */
63488 - unsigned int init_size, core_size;
63489 + unsigned int init_size_rw, core_size_rw;
63490
63491 /* The size of the executable code in each section. */
63492 - unsigned int init_text_size, core_text_size;
63493 -
63494 - /* Size of RO sections of the module (text+rodata) */
63495 - unsigned int init_ro_size, core_ro_size;
63496 + unsigned int init_size_rx, core_size_rx;
63497
63498 /* Arch-specific module values */
63499 struct mod_arch_specific arch;
63500 @@ -341,6 +339,10 @@ struct module
63501 #ifdef CONFIG_EVENT_TRACING
63502 struct ftrace_event_call **trace_events;
63503 unsigned int num_trace_events;
63504 + struct file_operations trace_id;
63505 + struct file_operations trace_enable;
63506 + struct file_operations trace_format;
63507 + struct file_operations trace_filter;
63508 #endif
63509 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63510 unsigned int num_ftrace_callsites;
63511 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63512 bool is_module_percpu_address(unsigned long addr);
63513 bool is_module_text_address(unsigned long addr);
63514
63515 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63516 +{
63517 +
63518 +#ifdef CONFIG_PAX_KERNEXEC
63519 + if (ktla_ktva(addr) >= (unsigned long)start &&
63520 + ktla_ktva(addr) < (unsigned long)start + size)
63521 + return 1;
63522 +#endif
63523 +
63524 + return ((void *)addr >= start && (void *)addr < start + size);
63525 +}
63526 +
63527 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63528 +{
63529 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63530 +}
63531 +
63532 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63533 +{
63534 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63535 +}
63536 +
63537 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63538 +{
63539 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63540 +}
63541 +
63542 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63543 +{
63544 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63545 +}
63546 +
63547 static inline int within_module_core(unsigned long addr, struct module *mod)
63548 {
63549 - return (unsigned long)mod->module_core <= addr &&
63550 - addr < (unsigned long)mod->module_core + mod->core_size;
63551 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63552 }
63553
63554 static inline int within_module_init(unsigned long addr, struct module *mod)
63555 {
63556 - return (unsigned long)mod->module_init <= addr &&
63557 - addr < (unsigned long)mod->module_init + mod->init_size;
63558 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63559 }
63560
63561 /* Search for module by name: must hold module_mutex. */
63562 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63563 index b2be02e..72d2f78 100644
63564 --- a/include/linux/moduleloader.h
63565 +++ b/include/linux/moduleloader.h
63566 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63567
63568 /* Allocator used for allocating struct module, core sections and init
63569 sections. Returns NULL on failure. */
63570 -void *module_alloc(unsigned long size);
63571 +void *module_alloc(unsigned long size) __size_overflow(1);
63572 +
63573 +#ifdef CONFIG_PAX_KERNEXEC
63574 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63575 +#else
63576 +#define module_alloc_exec(x) module_alloc(x)
63577 +#endif
63578
63579 /* Free memory returned from module_alloc. */
63580 void module_free(struct module *mod, void *module_region);
63581
63582 +#ifdef CONFIG_PAX_KERNEXEC
63583 +void module_free_exec(struct module *mod, void *module_region);
63584 +#else
63585 +#define module_free_exec(x, y) module_free((x), (y))
63586 +#endif
63587 +
63588 /* Apply the given relocation to the (simplified) ELF. Return -error
63589 or 0. */
63590 int apply_relocate(Elf_Shdr *sechdrs,
63591 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63592 index d6a5806..7c13347 100644
63593 --- a/include/linux/moduleparam.h
63594 +++ b/include/linux/moduleparam.h
63595 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63596 * @len is usually just sizeof(string).
63597 */
63598 #define module_param_string(name, string, len, perm) \
63599 - static const struct kparam_string __param_string_##name \
63600 + static const struct kparam_string __param_string_##name __used \
63601 = { len, string }; \
63602 __module_param_call(MODULE_PARAM_PREFIX, name, \
63603 &param_ops_string, \
63604 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63605 */
63606 #define module_param_array_named(name, array, type, nump, perm) \
63607 param_check_##type(name, &(array)[0]); \
63608 - static const struct kparam_array __param_arr_##name \
63609 + static const struct kparam_array __param_arr_##name __used \
63610 = { .max = ARRAY_SIZE(array), .num = nump, \
63611 .ops = &param_ops_##type, \
63612 .elemsize = sizeof(array[0]), .elem = array }; \
63613 diff --git a/include/linux/namei.h b/include/linux/namei.h
63614 index 4bf19d8..5268cea 100644
63615 --- a/include/linux/namei.h
63616 +++ b/include/linux/namei.h
63617 @@ -18,7 +18,7 @@ struct nameidata {
63618 unsigned seq;
63619 int last_type;
63620 unsigned depth;
63621 - char *saved_names[MAX_NESTED_LINKS + 1];
63622 + const char *saved_names[MAX_NESTED_LINKS + 1];
63623 };
63624
63625 /*
63626 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63627
63628 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63629
63630 -static inline void nd_set_link(struct nameidata *nd, char *path)
63631 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63632 {
63633 nd->saved_names[nd->depth] = path;
63634 }
63635
63636 -static inline char *nd_get_link(struct nameidata *nd)
63637 +static inline const char *nd_get_link(const struct nameidata *nd)
63638 {
63639 return nd->saved_names[nd->depth];
63640 }
63641 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63642 index 59dc05f3..c905a34 100644
63643 --- a/include/linux/netdevice.h
63644 +++ b/include/linux/netdevice.h
63645 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63646 struct net_device *dev,
63647 int idx);
63648 };
63649 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63650
63651 /*
63652 * The DEVICE structure.
63653 @@ -1087,7 +1088,7 @@ struct net_device {
63654 int iflink;
63655
63656 struct net_device_stats stats;
63657 - atomic_long_t rx_dropped; /* dropped packets by core network
63658 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63659 * Do not use this in drivers.
63660 */
63661
63662 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63663 new file mode 100644
63664 index 0000000..33f4af8
63665 --- /dev/null
63666 +++ b/include/linux/netfilter/xt_gradm.h
63667 @@ -0,0 +1,9 @@
63668 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63669 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63670 +
63671 +struct xt_gradm_mtinfo {
63672 + __u16 flags;
63673 + __u16 invflags;
63674 +};
63675 +
63676 +#endif
63677 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63678 index c65a18a..0c05f3a 100644
63679 --- a/include/linux/of_pdt.h
63680 +++ b/include/linux/of_pdt.h
63681 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63682
63683 /* return 0 on success; fill in 'len' with number of bytes in path */
63684 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63685 -};
63686 +} __no_const;
63687
63688 extern void *prom_early_alloc(unsigned long size);
63689
63690 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63691 index a4c5624..79d6d88 100644
63692 --- a/include/linux/oprofile.h
63693 +++ b/include/linux/oprofile.h
63694 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63695 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63696 char const * name, ulong * val);
63697
63698 -/** Create a file for read-only access to an atomic_t. */
63699 +/** Create a file for read-only access to an atomic_unchecked_t. */
63700 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63701 - char const * name, atomic_t * val);
63702 + char const * name, atomic_unchecked_t * val);
63703
63704 /** create a directory */
63705 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63706 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63707 index bdb4161..f373d41 100644
63708 --- a/include/linux/perf_event.h
63709 +++ b/include/linux/perf_event.h
63710 @@ -882,8 +882,8 @@ struct perf_event {
63711
63712 enum perf_event_active_state state;
63713 unsigned int attach_state;
63714 - local64_t count;
63715 - atomic64_t child_count;
63716 + local64_t count; /* PaX: fix it one day */
63717 + atomic64_unchecked_t child_count;
63718
63719 /*
63720 * These are the total time in nanoseconds that the event
63721 @@ -934,8 +934,8 @@ struct perf_event {
63722 * These accumulate total time (in nanoseconds) that children
63723 * events have been enabled and running, respectively.
63724 */
63725 - atomic64_t child_total_time_enabled;
63726 - atomic64_t child_total_time_running;
63727 + atomic64_unchecked_t child_total_time_enabled;
63728 + atomic64_unchecked_t child_total_time_running;
63729
63730 /*
63731 * Protect attach/detach and child_list:
63732 diff --git a/include/linux/personality.h b/include/linux/personality.h
63733 index 8fc7dd1a..c19d89e 100644
63734 --- a/include/linux/personality.h
63735 +++ b/include/linux/personality.h
63736 @@ -44,6 +44,7 @@ enum {
63737 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63738 ADDR_NO_RANDOMIZE | \
63739 ADDR_COMPAT_LAYOUT | \
63740 + ADDR_LIMIT_3GB | \
63741 MMAP_PAGE_ZERO)
63742
63743 /*
63744 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63745 index ad1a427..6419649 100644
63746 --- a/include/linux/pipe_fs_i.h
63747 +++ b/include/linux/pipe_fs_i.h
63748 @@ -45,9 +45,9 @@ struct pipe_buffer {
63749 struct pipe_inode_info {
63750 wait_queue_head_t wait;
63751 unsigned int nrbufs, curbuf, buffers;
63752 - unsigned int readers;
63753 - unsigned int writers;
63754 - unsigned int waiting_writers;
63755 + atomic_t readers;
63756 + atomic_t writers;
63757 + atomic_t waiting_writers;
63758 unsigned int r_counter;
63759 unsigned int w_counter;
63760 struct page *tmp_page;
63761 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63762 index f271860..6b3bec5 100644
63763 --- a/include/linux/pm_runtime.h
63764 +++ b/include/linux/pm_runtime.h
63765 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63766
63767 static inline void pm_runtime_mark_last_busy(struct device *dev)
63768 {
63769 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63770 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63771 }
63772
63773 #else /* !CONFIG_PM_RUNTIME */
63774 diff --git a/include/linux/poison.h b/include/linux/poison.h
63775 index 2110a81..13a11bb 100644
63776 --- a/include/linux/poison.h
63777 +++ b/include/linux/poison.h
63778 @@ -19,8 +19,8 @@
63779 * under normal circumstances, used to verify that nobody uses
63780 * non-initialized list entries.
63781 */
63782 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63783 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63784 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63785 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63786
63787 /********** include/linux/timer.h **********/
63788 /*
63789 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63790 index 5a710b9..0b0dab9 100644
63791 --- a/include/linux/preempt.h
63792 +++ b/include/linux/preempt.h
63793 @@ -126,7 +126,7 @@ struct preempt_ops {
63794 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63795 void (*sched_out)(struct preempt_notifier *notifier,
63796 struct task_struct *next);
63797 -};
63798 +} __no_const;
63799
63800 /**
63801 * preempt_notifier - key for installing preemption notifiers
63802 diff --git a/include/linux/printk.h b/include/linux/printk.h
63803 index 9afc01e..92c32e8 100644
63804 --- a/include/linux/printk.h
63805 +++ b/include/linux/printk.h
63806 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63807 extern int printk_needs_cpu(int cpu);
63808 extern void printk_tick(void);
63809
63810 +extern int kptr_restrict;
63811 +
63812 #ifdef CONFIG_PRINTK
63813 asmlinkage __printf(5, 0)
63814 int vprintk_emit(int facility, int level,
63815 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63816
63817 extern int printk_delay_msec;
63818 extern int dmesg_restrict;
63819 -extern int kptr_restrict;
63820
63821 void log_buf_kexec_setup(void);
63822 void __init setup_log_buf(int early);
63823 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63824 index 3fd2e87..d93a721 100644
63825 --- a/include/linux/proc_fs.h
63826 +++ b/include/linux/proc_fs.h
63827 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63828 return proc_create_data(name, mode, parent, proc_fops, NULL);
63829 }
63830
63831 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63832 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63833 +{
63834 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63835 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63836 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63837 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63838 +#else
63839 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63840 +#endif
63841 +}
63842 +
63843 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63844 umode_t mode, struct proc_dir_entry *base,
63845 read_proc_t *read_proc, void * data)
63846 @@ -258,7 +270,7 @@ union proc_op {
63847 int (*proc_show)(struct seq_file *m,
63848 struct pid_namespace *ns, struct pid *pid,
63849 struct task_struct *task);
63850 -};
63851 +} __no_const;
63852
63853 struct ctl_table_header;
63854 struct ctl_table;
63855 diff --git a/include/linux/random.h b/include/linux/random.h
63856 index ac621ce..c1215f3 100644
63857 --- a/include/linux/random.h
63858 +++ b/include/linux/random.h
63859 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63860 unsigned int value);
63861 extern void add_interrupt_randomness(int irq, int irq_flags);
63862
63863 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63864 +extern void transfer_latent_entropy(void);
63865 +#endif
63866 +
63867 extern void get_random_bytes(void *buf, int nbytes);
63868 extern void get_random_bytes_arch(void *buf, int nbytes);
63869 void generate_random_uuid(unsigned char uuid_out[16]);
63870 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63871
63872 u32 prandom32(struct rnd_state *);
63873
63874 +static inline unsigned long pax_get_random_long(void)
63875 +{
63876 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63877 +}
63878 +
63879 /*
63880 * Handle minimum values for seeds
63881 */
63882 static inline u32 __seed(u32 x, u32 m)
63883 {
63884 - return (x < m) ? x + m : x;
63885 + return (x <= m) ? x + m + 1 : x;
63886 }
63887
63888 /**
63889 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63890 index e0879a7..a12f962 100644
63891 --- a/include/linux/reboot.h
63892 +++ b/include/linux/reboot.h
63893 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63894 * Architecture-specific implementations of sys_reboot commands.
63895 */
63896
63897 -extern void machine_restart(char *cmd);
63898 -extern void machine_halt(void);
63899 -extern void machine_power_off(void);
63900 +extern void machine_restart(char *cmd) __noreturn;
63901 +extern void machine_halt(void) __noreturn;
63902 +extern void machine_power_off(void) __noreturn;
63903
63904 extern void machine_shutdown(void);
63905 struct pt_regs;
63906 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63907 */
63908
63909 extern void kernel_restart_prepare(char *cmd);
63910 -extern void kernel_restart(char *cmd);
63911 -extern void kernel_halt(void);
63912 -extern void kernel_power_off(void);
63913 +extern void kernel_restart(char *cmd) __noreturn;
63914 +extern void kernel_halt(void) __noreturn;
63915 +extern void kernel_power_off(void) __noreturn;
63916
63917 extern int C_A_D; /* for sysctl */
63918 void ctrl_alt_del(void);
63919 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63920 * Emergency restart, callable from an interrupt handler.
63921 */
63922
63923 -extern void emergency_restart(void);
63924 +extern void emergency_restart(void) __noreturn;
63925 #include <asm/emergency-restart.h>
63926
63927 #endif
63928 diff --git a/include/linux/relay.h b/include/linux/relay.h
63929 index 91cacc3..b55ff74 100644
63930 --- a/include/linux/relay.h
63931 +++ b/include/linux/relay.h
63932 @@ -160,7 +160,7 @@ struct rchan_callbacks
63933 * The callback should return 0 if successful, negative if not.
63934 */
63935 int (*remove_buf_file)(struct dentry *dentry);
63936 -};
63937 +} __no_const;
63938
63939 /*
63940 * CONFIG_RELAY kernel API, kernel/relay.c
63941 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63942 index 6fdf027..ff72610 100644
63943 --- a/include/linux/rfkill.h
63944 +++ b/include/linux/rfkill.h
63945 @@ -147,6 +147,7 @@ struct rfkill_ops {
63946 void (*query)(struct rfkill *rfkill, void *data);
63947 int (*set_block)(void *data, bool blocked);
63948 };
63949 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63950
63951 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63952 /**
63953 diff --git a/include/linux/rio.h b/include/linux/rio.h
63954 index a90ebad..fd87b5d 100644
63955 --- a/include/linux/rio.h
63956 +++ b/include/linux/rio.h
63957 @@ -321,7 +321,7 @@ struct rio_ops {
63958 int mbox, void *buffer, size_t len);
63959 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63960 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63961 -};
63962 +} __no_const;
63963
63964 #define RIO_RESOURCE_MEM 0x00000100
63965 #define RIO_RESOURCE_DOORBELL 0x00000200
63966 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63967 index 3fce545..b4fed6e 100644
63968 --- a/include/linux/rmap.h
63969 +++ b/include/linux/rmap.h
63970 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63971 void anon_vma_init(void); /* create anon_vma_cachep */
63972 int anon_vma_prepare(struct vm_area_struct *);
63973 void unlink_anon_vmas(struct vm_area_struct *);
63974 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63975 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63976 void anon_vma_moveto_tail(struct vm_area_struct *);
63977 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63978 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63979
63980 static inline void anon_vma_merge(struct vm_area_struct *vma,
63981 struct vm_area_struct *next)
63982 diff --git a/include/linux/sched.h b/include/linux/sched.h
63983 index 23bddac..5976055 100644
63984 --- a/include/linux/sched.h
63985 +++ b/include/linux/sched.h
63986 @@ -101,6 +101,7 @@ struct bio_list;
63987 struct fs_struct;
63988 struct perf_event_context;
63989 struct blk_plug;
63990 +struct linux_binprm;
63991
63992 /*
63993 * List of flags we want to share for kernel threads,
63994 @@ -384,10 +385,13 @@ struct user_namespace;
63995 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63996
63997 extern int sysctl_max_map_count;
63998 +extern unsigned long sysctl_heap_stack_gap;
63999
64000 #include <linux/aio.h>
64001
64002 #ifdef CONFIG_MMU
64003 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64004 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64005 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64006 extern unsigned long
64007 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64008 @@ -651,6 +655,17 @@ struct signal_struct {
64009 #ifdef CONFIG_TASKSTATS
64010 struct taskstats *stats;
64011 #endif
64012 +
64013 +#ifdef CONFIG_GRKERNSEC
64014 + u32 curr_ip;
64015 + u32 saved_ip;
64016 + u32 gr_saddr;
64017 + u32 gr_daddr;
64018 + u16 gr_sport;
64019 + u16 gr_dport;
64020 + u8 used_accept:1;
64021 +#endif
64022 +
64023 #ifdef CONFIG_AUDIT
64024 unsigned audit_tty;
64025 struct tty_audit_buf *tty_audit_buf;
64026 @@ -734,6 +749,11 @@ struct user_struct {
64027 struct key *session_keyring; /* UID's default session keyring */
64028 #endif
64029
64030 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64031 + unsigned int banned;
64032 + unsigned long ban_expires;
64033 +#endif
64034 +
64035 /* Hash table maintenance information */
64036 struct hlist_node uidhash_node;
64037 kuid_t uid;
64038 @@ -1356,8 +1376,8 @@ struct task_struct {
64039 struct list_head thread_group;
64040
64041 struct completion *vfork_done; /* for vfork() */
64042 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64043 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64044 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64045 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64046
64047 cputime_t utime, stime, utimescaled, stimescaled;
64048 cputime_t gtime;
64049 @@ -1373,11 +1393,6 @@ struct task_struct {
64050 struct task_cputime cputime_expires;
64051 struct list_head cpu_timers[3];
64052
64053 -/* process credentials */
64054 - const struct cred __rcu *real_cred; /* objective and real subjective task
64055 - * credentials (COW) */
64056 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64057 - * credentials (COW) */
64058 char comm[TASK_COMM_LEN]; /* executable name excluding path
64059 - access with [gs]et_task_comm (which lock
64060 it with task_lock())
64061 @@ -1394,6 +1409,10 @@ struct task_struct {
64062 #endif
64063 /* CPU-specific state of this task */
64064 struct thread_struct thread;
64065 +/* thread_info moved to task_struct */
64066 +#ifdef CONFIG_X86
64067 + struct thread_info tinfo;
64068 +#endif
64069 /* filesystem information */
64070 struct fs_struct *fs;
64071 /* open file information */
64072 @@ -1467,6 +1486,10 @@ struct task_struct {
64073 gfp_t lockdep_reclaim_gfp;
64074 #endif
64075
64076 +/* process credentials */
64077 + const struct cred __rcu *real_cred; /* objective and real subjective task
64078 + * credentials (COW) */
64079 +
64080 /* journalling filesystem info */
64081 void *journal_info;
64082
64083 @@ -1505,6 +1528,10 @@ struct task_struct {
64084 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64085 struct list_head cg_list;
64086 #endif
64087 +
64088 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64089 + * credentials (COW) */
64090 +
64091 #ifdef CONFIG_FUTEX
64092 struct robust_list_head __user *robust_list;
64093 #ifdef CONFIG_COMPAT
64094 @@ -1589,8 +1616,74 @@ struct task_struct {
64095 #ifdef CONFIG_UPROBES
64096 struct uprobe_task *utask;
64097 #endif
64098 +
64099 +#ifdef CONFIG_GRKERNSEC
64100 + /* grsecurity */
64101 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64102 + u64 exec_id;
64103 +#endif
64104 +#ifdef CONFIG_GRKERNSEC_SETXID
64105 + const struct cred *delayed_cred;
64106 +#endif
64107 + struct dentry *gr_chroot_dentry;
64108 + struct acl_subject_label *acl;
64109 + struct acl_role_label *role;
64110 + struct file *exec_file;
64111 + u16 acl_role_id;
64112 + /* is this the task that authenticated to the special role */
64113 + u8 acl_sp_role;
64114 + u8 is_writable;
64115 + u8 brute;
64116 + u8 gr_is_chrooted;
64117 +#endif
64118 +
64119 };
64120
64121 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64122 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64123 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64124 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64125 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64126 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64127 +
64128 +#ifdef CONFIG_PAX_SOFTMODE
64129 +extern int pax_softmode;
64130 +#endif
64131 +
64132 +extern int pax_check_flags(unsigned long *);
64133 +
64134 +/* if tsk != current then task_lock must be held on it */
64135 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64136 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64137 +{
64138 + if (likely(tsk->mm))
64139 + return tsk->mm->pax_flags;
64140 + else
64141 + return 0UL;
64142 +}
64143 +
64144 +/* if tsk != current then task_lock must be held on it */
64145 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64146 +{
64147 + if (likely(tsk->mm)) {
64148 + tsk->mm->pax_flags = flags;
64149 + return 0;
64150 + }
64151 + return -EINVAL;
64152 +}
64153 +#endif
64154 +
64155 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64156 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64157 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64158 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64159 +#endif
64160 +
64161 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64162 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64163 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64164 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64165 +
64166 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64167 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64168
64169 @@ -2125,7 +2218,9 @@ void yield(void);
64170 extern struct exec_domain default_exec_domain;
64171
64172 union thread_union {
64173 +#ifndef CONFIG_X86
64174 struct thread_info thread_info;
64175 +#endif
64176 unsigned long stack[THREAD_SIZE/sizeof(long)];
64177 };
64178
64179 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64180 */
64181
64182 extern struct task_struct *find_task_by_vpid(pid_t nr);
64183 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64184 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64185 struct pid_namespace *ns);
64186
64187 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64188 extern void exit_itimers(struct signal_struct *);
64189 extern void flush_itimer_signals(void);
64190
64191 -extern void do_group_exit(int);
64192 +extern __noreturn void do_group_exit(int);
64193
64194 extern void daemonize(const char *, ...);
64195 extern int allow_signal(int);
64196 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64197
64198 #endif
64199
64200 -static inline int object_is_on_stack(void *obj)
64201 +static inline int object_starts_on_stack(void *obj)
64202 {
64203 - void *stack = task_stack_page(current);
64204 + const void *stack = task_stack_page(current);
64205
64206 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64207 }
64208 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64209 index 899fbb4..1cb4138 100644
64210 --- a/include/linux/screen_info.h
64211 +++ b/include/linux/screen_info.h
64212 @@ -43,7 +43,8 @@ struct screen_info {
64213 __u16 pages; /* 0x32 */
64214 __u16 vesa_attributes; /* 0x34 */
64215 __u32 capabilities; /* 0x36 */
64216 - __u8 _reserved[6]; /* 0x3a */
64217 + __u16 vesapm_size; /* 0x3a */
64218 + __u8 _reserved[4]; /* 0x3c */
64219 } __attribute__((packed));
64220
64221 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64222 diff --git a/include/linux/security.h b/include/linux/security.h
64223 index d143b8e..9f27b95 100644
64224 --- a/include/linux/security.h
64225 +++ b/include/linux/security.h
64226 @@ -26,6 +26,7 @@
64227 #include <linux/capability.h>
64228 #include <linux/slab.h>
64229 #include <linux/err.h>
64230 +#include <linux/grsecurity.h>
64231
64232 struct linux_binprm;
64233 struct cred;
64234 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64235 index 83c44ee..e8a9eba 100644
64236 --- a/include/linux/seq_file.h
64237 +++ b/include/linux/seq_file.h
64238 @@ -25,6 +25,9 @@ struct seq_file {
64239 struct mutex lock;
64240 const struct seq_operations *op;
64241 int poll_event;
64242 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64243 + u64 exec_id;
64244 +#endif
64245 void *private;
64246 };
64247
64248 @@ -34,6 +37,7 @@ struct seq_operations {
64249 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64250 int (*show) (struct seq_file *m, void *v);
64251 };
64252 +typedef struct seq_operations __no_const seq_operations_no_const;
64253
64254 #define SEQ_SKIP 1
64255
64256 diff --git a/include/linux/shm.h b/include/linux/shm.h
64257 index edd0868..f98feee 100644
64258 --- a/include/linux/shm.h
64259 +++ b/include/linux/shm.h
64260 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64261
64262 /* The task created the shm object. NULL if the task is dead. */
64263 struct task_struct *shm_creator;
64264 +#ifdef CONFIG_GRKERNSEC
64265 + time_t shm_createtime;
64266 + pid_t shm_lapid;
64267 +#endif
64268 };
64269
64270 /* shm_mode upper byte flags */
64271 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64272 index f3165d2..2cb3cb7 100644
64273 --- a/include/linux/skbuff.h
64274 +++ b/include/linux/skbuff.h
64275 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64276 extern struct sk_buff *__alloc_skb(unsigned int size,
64277 gfp_t priority, int flags, int node);
64278 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64279 -static inline struct sk_buff *alloc_skb(unsigned int size,
64280 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64281 gfp_t priority)
64282 {
64283 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64284 @@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64285 */
64286 static inline int skb_queue_empty(const struct sk_buff_head *list)
64287 {
64288 - return list->next == (struct sk_buff *)list;
64289 + return list->next == (const struct sk_buff *)list;
64290 }
64291
64292 /**
64293 @@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64294 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64295 const struct sk_buff *skb)
64296 {
64297 - return skb->next == (struct sk_buff *)list;
64298 + return skb->next == (const struct sk_buff *)list;
64299 }
64300
64301 /**
64302 @@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64303 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64304 const struct sk_buff *skb)
64305 {
64306 - return skb->prev == (struct sk_buff *)list;
64307 + return skb->prev == (const struct sk_buff *)list;
64308 }
64309
64310 /**
64311 @@ -1623,7 +1623,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64312 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64313 */
64314 #ifndef NET_SKB_PAD
64315 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64316 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64317 #endif
64318
64319 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64320 @@ -2201,7 +2201,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64321 int noblock, int *err);
64322 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64323 struct poll_table_struct *wait);
64324 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64325 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64326 int offset, struct iovec *to,
64327 int size);
64328 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64329 diff --git a/include/linux/slab.h b/include/linux/slab.h
64330 index 0dd2dfa..2b8677c 100644
64331 --- a/include/linux/slab.h
64332 +++ b/include/linux/slab.h
64333 @@ -11,12 +11,20 @@
64334
64335 #include <linux/gfp.h>
64336 #include <linux/types.h>
64337 +#include <linux/err.h>
64338
64339 /*
64340 * Flags to pass to kmem_cache_create().
64341 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64342 */
64343 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64344 +
64345 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64346 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64347 +#else
64348 +#define SLAB_USERCOPY 0x00000000UL
64349 +#endif
64350 +
64351 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64352 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64353 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64354 @@ -87,10 +95,13 @@
64355 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64356 * Both make kfree a no-op.
64357 */
64358 -#define ZERO_SIZE_PTR ((void *)16)
64359 +#define ZERO_SIZE_PTR \
64360 +({ \
64361 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64362 + (void *)(-MAX_ERRNO-1L); \
64363 +})
64364
64365 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64366 - (unsigned long)ZERO_SIZE_PTR)
64367 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64368
64369 /*
64370 * Common fields provided in kmem_cache by all slab allocators
64371 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64372 void kfree(const void *);
64373 void kzfree(const void *);
64374 size_t ksize(const void *);
64375 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64376 +bool is_usercopy_object(const void *ptr);
64377
64378 /*
64379 * Allocator specific definitions. These are mainly used to establish optimized
64380 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64381 */
64382 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64383 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64384 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64385 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64386 #define kmalloc_track_caller(size, flags) \
64387 __kmalloc_track_caller(size, flags, _RET_IP_)
64388 #else
64389 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64390 */
64391 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64392 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64393 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64394 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64395 #define kmalloc_node_track_caller(size, flags, node) \
64396 __kmalloc_node_track_caller(size, flags, node, \
64397 _RET_IP_)
64398 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64399 index 0c634fa..8616300 100644
64400 --- a/include/linux/slab_def.h
64401 +++ b/include/linux/slab_def.h
64402 @@ -69,10 +69,10 @@ struct kmem_cache {
64403 unsigned long node_allocs;
64404 unsigned long node_frees;
64405 unsigned long node_overflow;
64406 - atomic_t allochit;
64407 - atomic_t allocmiss;
64408 - atomic_t freehit;
64409 - atomic_t freemiss;
64410 + atomic_unchecked_t allochit;
64411 + atomic_unchecked_t allocmiss;
64412 + atomic_unchecked_t freehit;
64413 + atomic_unchecked_t freemiss;
64414
64415 /*
64416 * If debugging is enabled, then the allocator can add additional
64417 @@ -105,11 +105,16 @@ struct cache_sizes {
64418 #ifdef CONFIG_ZONE_DMA
64419 struct kmem_cache *cs_dmacachep;
64420 #endif
64421 +
64422 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64423 + struct kmem_cache *cs_usercopycachep;
64424 +#endif
64425 +
64426 };
64427 extern struct cache_sizes malloc_sizes[];
64428
64429 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64430 -void *__kmalloc(size_t size, gfp_t flags);
64431 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64432
64433 #ifdef CONFIG_TRACING
64434 extern void *kmem_cache_alloc_trace(size_t size,
64435 @@ -152,6 +157,13 @@ found:
64436 cachep = malloc_sizes[i].cs_dmacachep;
64437 else
64438 #endif
64439 +
64440 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64441 + if (flags & GFP_USERCOPY)
64442 + cachep = malloc_sizes[i].cs_usercopycachep;
64443 + else
64444 +#endif
64445 +
64446 cachep = malloc_sizes[i].cs_cachep;
64447
64448 ret = kmem_cache_alloc_trace(size, cachep, flags);
64449 @@ -162,7 +174,7 @@ found:
64450 }
64451
64452 #ifdef CONFIG_NUMA
64453 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64454 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64455 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64456
64457 #ifdef CONFIG_TRACING
64458 @@ -205,6 +217,13 @@ found:
64459 cachep = malloc_sizes[i].cs_dmacachep;
64460 else
64461 #endif
64462 +
64463 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64464 + if (flags & GFP_USERCOPY)
64465 + cachep = malloc_sizes[i].cs_usercopycachep;
64466 + else
64467 +#endif
64468 +
64469 cachep = malloc_sizes[i].cs_cachep;
64470
64471 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64472 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64473 index 0ec00b3..22b4715 100644
64474 --- a/include/linux/slob_def.h
64475 +++ b/include/linux/slob_def.h
64476 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64477 return kmem_cache_alloc_node(cachep, flags, -1);
64478 }
64479
64480 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64481 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64482
64483 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64484 {
64485 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64486 return __kmalloc_node(size, flags, -1);
64487 }
64488
64489 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64490 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64491 {
64492 return kmalloc(size, flags);
64493 }
64494 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64495 index df448ad..b99e7f6 100644
64496 --- a/include/linux/slub_def.h
64497 +++ b/include/linux/slub_def.h
64498 @@ -91,7 +91,7 @@ struct kmem_cache {
64499 struct kmem_cache_order_objects max;
64500 struct kmem_cache_order_objects min;
64501 gfp_t allocflags; /* gfp flags to use on each alloc */
64502 - int refcount; /* Refcount for slab cache destroy */
64503 + atomic_t refcount; /* Refcount for slab cache destroy */
64504 void (*ctor)(void *);
64505 int inuse; /* Offset to metadata */
64506 int align; /* Alignment */
64507 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64508 * Sorry that the following has to be that ugly but some versions of GCC
64509 * have trouble with constant propagation and loops.
64510 */
64511 -static __always_inline int kmalloc_index(size_t size)
64512 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64513 {
64514 if (!size)
64515 return 0;
64516 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64517 }
64518
64519 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64520 -void *__kmalloc(size_t size, gfp_t flags);
64521 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64522
64523 static __always_inline void *
64524 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64525 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64526 }
64527 #endif
64528
64529 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64530 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64531 {
64532 unsigned int order = get_order(size);
64533 return kmalloc_order_trace(size, flags, order);
64534 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64535 }
64536
64537 #ifdef CONFIG_NUMA
64538 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64539 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64540 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64541
64542 #ifdef CONFIG_TRACING
64543 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64544 index de8832d..0147b46 100644
64545 --- a/include/linux/sonet.h
64546 +++ b/include/linux/sonet.h
64547 @@ -61,7 +61,7 @@ struct sonet_stats {
64548 #include <linux/atomic.h>
64549
64550 struct k_sonet_stats {
64551 -#define __HANDLE_ITEM(i) atomic_t i
64552 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64553 __SONET_ITEMS
64554 #undef __HANDLE_ITEM
64555 };
64556 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64557 index 523547e..2cb7140 100644
64558 --- a/include/linux/sunrpc/clnt.h
64559 +++ b/include/linux/sunrpc/clnt.h
64560 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64561 {
64562 switch (sap->sa_family) {
64563 case AF_INET:
64564 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64565 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64566 case AF_INET6:
64567 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64568 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64569 }
64570 return 0;
64571 }
64572 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64573 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64574 const struct sockaddr *src)
64575 {
64576 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64577 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64578 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64579
64580 dsin->sin_family = ssin->sin_family;
64581 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64582 if (sa->sa_family != AF_INET6)
64583 return 0;
64584
64585 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64586 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64587 }
64588
64589 #endif /* __KERNEL__ */
64590 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64591 index dc0c3cc..8503fb6 100644
64592 --- a/include/linux/sunrpc/sched.h
64593 +++ b/include/linux/sunrpc/sched.h
64594 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64595 void (*rpc_count_stats)(struct rpc_task *, void *);
64596 void (*rpc_release)(void *);
64597 };
64598 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64599
64600 struct rpc_task_setup {
64601 struct rpc_task *task;
64602 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64603 index 0b8e3e6..33e0a01 100644
64604 --- a/include/linux/sunrpc/svc_rdma.h
64605 +++ b/include/linux/sunrpc/svc_rdma.h
64606 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64607 extern unsigned int svcrdma_max_requests;
64608 extern unsigned int svcrdma_max_req_size;
64609
64610 -extern atomic_t rdma_stat_recv;
64611 -extern atomic_t rdma_stat_read;
64612 -extern atomic_t rdma_stat_write;
64613 -extern atomic_t rdma_stat_sq_starve;
64614 -extern atomic_t rdma_stat_rq_starve;
64615 -extern atomic_t rdma_stat_rq_poll;
64616 -extern atomic_t rdma_stat_rq_prod;
64617 -extern atomic_t rdma_stat_sq_poll;
64618 -extern atomic_t rdma_stat_sq_prod;
64619 +extern atomic_unchecked_t rdma_stat_recv;
64620 +extern atomic_unchecked_t rdma_stat_read;
64621 +extern atomic_unchecked_t rdma_stat_write;
64622 +extern atomic_unchecked_t rdma_stat_sq_starve;
64623 +extern atomic_unchecked_t rdma_stat_rq_starve;
64624 +extern atomic_unchecked_t rdma_stat_rq_poll;
64625 +extern atomic_unchecked_t rdma_stat_rq_prod;
64626 +extern atomic_unchecked_t rdma_stat_sq_poll;
64627 +extern atomic_unchecked_t rdma_stat_sq_prod;
64628
64629 #define RPCRDMA_VERSION 1
64630
64631 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64632 index c34b4c8..a65b67d 100644
64633 --- a/include/linux/sysctl.h
64634 +++ b/include/linux/sysctl.h
64635 @@ -155,7 +155,11 @@ enum
64636 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64637 };
64638
64639 -
64640 +#ifdef CONFIG_PAX_SOFTMODE
64641 +enum {
64642 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64643 +};
64644 +#endif
64645
64646 /* CTL_VM names: */
64647 enum
64648 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64649
64650 extern int proc_dostring(struct ctl_table *, int,
64651 void __user *, size_t *, loff_t *);
64652 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64653 + void __user *, size_t *, loff_t *);
64654 extern int proc_dointvec(struct ctl_table *, int,
64655 void __user *, size_t *, loff_t *);
64656 extern int proc_dointvec_minmax(struct ctl_table *, int,
64657 diff --git a/include/linux/tty.h b/include/linux/tty.h
64658 index 9f47ab5..73da944 100644
64659 --- a/include/linux/tty.h
64660 +++ b/include/linux/tty.h
64661 @@ -225,7 +225,7 @@ struct tty_port {
64662 const struct tty_port_operations *ops; /* Port operations */
64663 spinlock_t lock; /* Lock protecting tty field */
64664 int blocked_open; /* Waiting to open */
64665 - int count; /* Usage count */
64666 + atomic_t count; /* Usage count */
64667 wait_queue_head_t open_wait; /* Open waiters */
64668 wait_queue_head_t close_wait; /* Close waiters */
64669 wait_queue_head_t delta_msr_wait; /* Modem status change */
64670 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64671 struct tty_struct *tty, struct file *filp);
64672 static inline int tty_port_users(struct tty_port *port)
64673 {
64674 - return port->count + port->blocked_open;
64675 + return atomic_read(&port->count) + port->blocked_open;
64676 }
64677
64678 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64679 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64680 index fb79dd8d..07d4773 100644
64681 --- a/include/linux/tty_ldisc.h
64682 +++ b/include/linux/tty_ldisc.h
64683 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64684
64685 struct module *owner;
64686
64687 - int refcount;
64688 + atomic_t refcount;
64689 };
64690
64691 struct tty_ldisc {
64692 diff --git a/include/linux/types.h b/include/linux/types.h
64693 index bf0dd75..a1f23aaa 100644
64694 --- a/include/linux/types.h
64695 +++ b/include/linux/types.h
64696 @@ -220,10 +220,26 @@ typedef struct {
64697 int counter;
64698 } atomic_t;
64699
64700 +#ifdef CONFIG_PAX_REFCOUNT
64701 +typedef struct {
64702 + int counter;
64703 +} atomic_unchecked_t;
64704 +#else
64705 +typedef atomic_t atomic_unchecked_t;
64706 +#endif
64707 +
64708 #ifdef CONFIG_64BIT
64709 typedef struct {
64710 long counter;
64711 } atomic64_t;
64712 +
64713 +#ifdef CONFIG_PAX_REFCOUNT
64714 +typedef struct {
64715 + long counter;
64716 +} atomic64_unchecked_t;
64717 +#else
64718 +typedef atomic64_t atomic64_unchecked_t;
64719 +#endif
64720 #endif
64721
64722 struct list_head {
64723 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64724 index 5ca0951..ab496a5 100644
64725 --- a/include/linux/uaccess.h
64726 +++ b/include/linux/uaccess.h
64727 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64728 long ret; \
64729 mm_segment_t old_fs = get_fs(); \
64730 \
64731 - set_fs(KERNEL_DS); \
64732 pagefault_disable(); \
64733 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64734 - pagefault_enable(); \
64735 + set_fs(KERNEL_DS); \
64736 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64737 set_fs(old_fs); \
64738 + pagefault_enable(); \
64739 ret; \
64740 })
64741
64742 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64743 index 99c1b4d..bb94261 100644
64744 --- a/include/linux/unaligned/access_ok.h
64745 +++ b/include/linux/unaligned/access_ok.h
64746 @@ -6,32 +6,32 @@
64747
64748 static inline u16 get_unaligned_le16(const void *p)
64749 {
64750 - return le16_to_cpup((__le16 *)p);
64751 + return le16_to_cpup((const __le16 *)p);
64752 }
64753
64754 static inline u32 get_unaligned_le32(const void *p)
64755 {
64756 - return le32_to_cpup((__le32 *)p);
64757 + return le32_to_cpup((const __le32 *)p);
64758 }
64759
64760 static inline u64 get_unaligned_le64(const void *p)
64761 {
64762 - return le64_to_cpup((__le64 *)p);
64763 + return le64_to_cpup((const __le64 *)p);
64764 }
64765
64766 static inline u16 get_unaligned_be16(const void *p)
64767 {
64768 - return be16_to_cpup((__be16 *)p);
64769 + return be16_to_cpup((const __be16 *)p);
64770 }
64771
64772 static inline u32 get_unaligned_be32(const void *p)
64773 {
64774 - return be32_to_cpup((__be32 *)p);
64775 + return be32_to_cpup((const __be32 *)p);
64776 }
64777
64778 static inline u64 get_unaligned_be64(const void *p)
64779 {
64780 - return be64_to_cpup((__be64 *)p);
64781 + return be64_to_cpup((const __be64 *)p);
64782 }
64783
64784 static inline void put_unaligned_le16(u16 val, void *p)
64785 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64786 index c5d36c6..8478c90 100644
64787 --- a/include/linux/usb/renesas_usbhs.h
64788 +++ b/include/linux/usb/renesas_usbhs.h
64789 @@ -39,7 +39,7 @@ enum {
64790 */
64791 struct renesas_usbhs_driver_callback {
64792 int (*notify_hotplug)(struct platform_device *pdev);
64793 -};
64794 +} __no_const;
64795
64796 /*
64797 * callback functions for platform
64798 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64799 * VBUS control is needed for Host
64800 */
64801 int (*set_vbus)(struct platform_device *pdev, int enable);
64802 -};
64803 +} __no_const;
64804
64805 /*
64806 * parameters for renesas usbhs
64807 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64808 index 6f8fbcf..8259001 100644
64809 --- a/include/linux/vermagic.h
64810 +++ b/include/linux/vermagic.h
64811 @@ -25,9 +25,35 @@
64812 #define MODULE_ARCH_VERMAGIC ""
64813 #endif
64814
64815 +#ifdef CONFIG_PAX_REFCOUNT
64816 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64817 +#else
64818 +#define MODULE_PAX_REFCOUNT ""
64819 +#endif
64820 +
64821 +#ifdef CONSTIFY_PLUGIN
64822 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64823 +#else
64824 +#define MODULE_CONSTIFY_PLUGIN ""
64825 +#endif
64826 +
64827 +#ifdef STACKLEAK_PLUGIN
64828 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64829 +#else
64830 +#define MODULE_STACKLEAK_PLUGIN ""
64831 +#endif
64832 +
64833 +#ifdef CONFIG_GRKERNSEC
64834 +#define MODULE_GRSEC "GRSEC "
64835 +#else
64836 +#define MODULE_GRSEC ""
64837 +#endif
64838 +
64839 #define VERMAGIC_STRING \
64840 UTS_RELEASE " " \
64841 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64842 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64843 - MODULE_ARCH_VERMAGIC
64844 + MODULE_ARCH_VERMAGIC \
64845 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64846 + MODULE_GRSEC
64847
64848 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64849 index 6071e91..ca6a489 100644
64850 --- a/include/linux/vmalloc.h
64851 +++ b/include/linux/vmalloc.h
64852 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64853 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64854 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64855 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64856 +
64857 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64858 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64859 +#endif
64860 +
64861 /* bits [20..32] reserved for arch specific ioremap internals */
64862
64863 /*
64864 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64865 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64866 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64867 unsigned long start, unsigned long end, gfp_t gfp_mask,
64868 - pgprot_t prot, int node, const void *caller);
64869 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
64870 extern void vfree(const void *addr);
64871
64872 extern void *vmap(struct page **pages, unsigned int count,
64873 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64874 extern void free_vm_area(struct vm_struct *area);
64875
64876 /* for /dev/kmem */
64877 -extern long vread(char *buf, char *addr, unsigned long count);
64878 -extern long vwrite(char *buf, char *addr, unsigned long count);
64879 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64880 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64881
64882 /*
64883 * Internals. Dont't use..
64884 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64885 index ad2cfd5..74c94ad 100644
64886 --- a/include/linux/vmstat.h
64887 +++ b/include/linux/vmstat.h
64888 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64889 /*
64890 * Zone based page accounting with per cpu differentials.
64891 */
64892 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64893 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64894
64895 static inline void zone_page_state_add(long x, struct zone *zone,
64896 enum zone_stat_item item)
64897 {
64898 - atomic_long_add(x, &zone->vm_stat[item]);
64899 - atomic_long_add(x, &vm_stat[item]);
64900 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64901 + atomic_long_add_unchecked(x, &vm_stat[item]);
64902 }
64903
64904 static inline unsigned long global_page_state(enum zone_stat_item item)
64905 {
64906 - long x = atomic_long_read(&vm_stat[item]);
64907 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64908 #ifdef CONFIG_SMP
64909 if (x < 0)
64910 x = 0;
64911 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64912 static inline unsigned long zone_page_state(struct zone *zone,
64913 enum zone_stat_item item)
64914 {
64915 - long x = atomic_long_read(&zone->vm_stat[item]);
64916 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64917 #ifdef CONFIG_SMP
64918 if (x < 0)
64919 x = 0;
64920 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64921 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64922 enum zone_stat_item item)
64923 {
64924 - long x = atomic_long_read(&zone->vm_stat[item]);
64925 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64926
64927 #ifdef CONFIG_SMP
64928 int cpu;
64929 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64930
64931 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64932 {
64933 - atomic_long_inc(&zone->vm_stat[item]);
64934 - atomic_long_inc(&vm_stat[item]);
64935 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64936 + atomic_long_inc_unchecked(&vm_stat[item]);
64937 }
64938
64939 static inline void __inc_zone_page_state(struct page *page,
64940 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
64941
64942 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64943 {
64944 - atomic_long_dec(&zone->vm_stat[item]);
64945 - atomic_long_dec(&vm_stat[item]);
64946 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64947 + atomic_long_dec_unchecked(&vm_stat[item]);
64948 }
64949
64950 static inline void __dec_zone_page_state(struct page *page,
64951 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64952 index e5d1220..ef6e406 100644
64953 --- a/include/linux/xattr.h
64954 +++ b/include/linux/xattr.h
64955 @@ -57,6 +57,11 @@
64956 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64957 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64958
64959 +/* User namespace */
64960 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64961 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64962 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64963 +
64964 #ifdef __KERNEL__
64965
64966 #include <linux/types.h>
64967 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64968 index 944ecdf..a3994fc 100644
64969 --- a/include/media/saa7146_vv.h
64970 +++ b/include/media/saa7146_vv.h
64971 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64972 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64973
64974 /* the extension can override this */
64975 - struct v4l2_ioctl_ops vid_ops;
64976 - struct v4l2_ioctl_ops vbi_ops;
64977 + v4l2_ioctl_ops_no_const vid_ops;
64978 + v4l2_ioctl_ops_no_const vbi_ops;
64979 /* pointer to the saa7146 core ops */
64980 const struct v4l2_ioctl_ops *core_ops;
64981
64982 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64983 index 5c416cd..20021aa 100644
64984 --- a/include/media/v4l2-dev.h
64985 +++ b/include/media/v4l2-dev.h
64986 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64987 int (*mmap) (struct file *, struct vm_area_struct *);
64988 int (*open) (struct file *);
64989 int (*release) (struct file *);
64990 -};
64991 +} __do_const;
64992 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64993
64994 /*
64995 * Newer version of video_device, handled by videodev2.c
64996 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64997 index e614c9c..20602b7 100644
64998 --- a/include/media/v4l2-ioctl.h
64999 +++ b/include/media/v4l2-ioctl.h
65000 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
65001 long (*vidioc_default) (struct file *file, void *fh,
65002 bool valid_prio, int cmd, void *arg);
65003 };
65004 -
65005 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65006
65007 /* v4l debugging and diagnostics */
65008
65009 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65010 index bcb9cc3..f4ec722e 100644
65011 --- a/include/net/caif/caif_hsi.h
65012 +++ b/include/net/caif/caif_hsi.h
65013 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65014 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65015 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65016 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65017 -};
65018 +} __no_const;
65019
65020 /* Structure implemented by HSI device. */
65021 struct cfhsi_ops {
65022 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65023 index 9e5425b..8136ffc 100644
65024 --- a/include/net/caif/cfctrl.h
65025 +++ b/include/net/caif/cfctrl.h
65026 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65027 void (*radioset_rsp)(void);
65028 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65029 struct cflayer *client_layer);
65030 -};
65031 +} __no_const;
65032
65033 /* Link Setup Parameters for CAIF-Links. */
65034 struct cfctrl_link_param {
65035 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65036 struct cfctrl {
65037 struct cfsrvl serv;
65038 struct cfctrl_rsp res;
65039 - atomic_t req_seq_no;
65040 - atomic_t rsp_seq_no;
65041 + atomic_unchecked_t req_seq_no;
65042 + atomic_unchecked_t rsp_seq_no;
65043 struct list_head list;
65044 /* Protects from simultaneous access to first_req list */
65045 spinlock_t info_list_lock;
65046 diff --git a/include/net/flow.h b/include/net/flow.h
65047 index 628e11b..4c475df 100644
65048 --- a/include/net/flow.h
65049 +++ b/include/net/flow.h
65050 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65051
65052 extern void flow_cache_flush(void);
65053 extern void flow_cache_flush_deferred(void);
65054 -extern atomic_t flow_cache_genid;
65055 +extern atomic_unchecked_t flow_cache_genid;
65056
65057 #endif
65058 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65059 index 53f464d..ba76aaa 100644
65060 --- a/include/net/inetpeer.h
65061 +++ b/include/net/inetpeer.h
65062 @@ -47,8 +47,8 @@ struct inet_peer {
65063 */
65064 union {
65065 struct {
65066 - atomic_t rid; /* Frag reception counter */
65067 - atomic_t ip_id_count; /* IP ID for the next packet */
65068 + atomic_unchecked_t rid; /* Frag reception counter */
65069 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65070 };
65071 struct rcu_head rcu;
65072 struct inet_peer *gc_next;
65073 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65074 more++;
65075 inet_peer_refcheck(p);
65076 do {
65077 - old = atomic_read(&p->ip_id_count);
65078 + old = atomic_read_unchecked(&p->ip_id_count);
65079 new = old + more;
65080 if (!new)
65081 new = 1;
65082 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65083 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65084 return new;
65085 }
65086
65087 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65088 index 9497be1..5a4fafe 100644
65089 --- a/include/net/ip_fib.h
65090 +++ b/include/net/ip_fib.h
65091 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65092
65093 #define FIB_RES_SADDR(net, res) \
65094 ((FIB_RES_NH(res).nh_saddr_genid == \
65095 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65096 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65097 FIB_RES_NH(res).nh_saddr : \
65098 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65099 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65100 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65101 index 95374d1..2300e36 100644
65102 --- a/include/net/ip_vs.h
65103 +++ b/include/net/ip_vs.h
65104 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65105 struct ip_vs_conn *control; /* Master control connection */
65106 atomic_t n_control; /* Number of controlled ones */
65107 struct ip_vs_dest *dest; /* real server */
65108 - atomic_t in_pkts; /* incoming packet counter */
65109 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65110
65111 /* packet transmitter for different forwarding methods. If it
65112 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65113 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65114 __be16 port; /* port number of the server */
65115 union nf_inet_addr addr; /* IP address of the server */
65116 volatile unsigned int flags; /* dest status flags */
65117 - atomic_t conn_flags; /* flags to copy to conn */
65118 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65119 atomic_t weight; /* server weight */
65120
65121 atomic_t refcnt; /* reference counter */
65122 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65123 index 69b610a..fe3962c 100644
65124 --- a/include/net/irda/ircomm_core.h
65125 +++ b/include/net/irda/ircomm_core.h
65126 @@ -51,7 +51,7 @@ typedef struct {
65127 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65128 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65129 struct ircomm_info *);
65130 -} call_t;
65131 +} __no_const call_t;
65132
65133 struct ircomm_cb {
65134 irda_queue_t queue;
65135 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65136 index 59ba38bc..d515662 100644
65137 --- a/include/net/irda/ircomm_tty.h
65138 +++ b/include/net/irda/ircomm_tty.h
65139 @@ -35,6 +35,7 @@
65140 #include <linux/termios.h>
65141 #include <linux/timer.h>
65142 #include <linux/tty.h> /* struct tty_struct */
65143 +#include <asm/local.h>
65144
65145 #include <net/irda/irias_object.h>
65146 #include <net/irda/ircomm_core.h>
65147 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65148 unsigned short close_delay;
65149 unsigned short closing_wait; /* time to wait before closing */
65150
65151 - int open_count;
65152 - int blocked_open; /* # of blocked opens */
65153 + local_t open_count;
65154 + local_t blocked_open; /* # of blocked opens */
65155
65156 /* Protect concurent access to :
65157 * o self->open_count
65158 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65159 index cc7c197..9f2da2a 100644
65160 --- a/include/net/iucv/af_iucv.h
65161 +++ b/include/net/iucv/af_iucv.h
65162 @@ -141,7 +141,7 @@ struct iucv_sock {
65163 struct iucv_sock_list {
65164 struct hlist_head head;
65165 rwlock_t lock;
65166 - atomic_t autobind_name;
65167 + atomic_unchecked_t autobind_name;
65168 };
65169
65170 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65171 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65172 index 344d898..2ae1302 100644
65173 --- a/include/net/neighbour.h
65174 +++ b/include/net/neighbour.h
65175 @@ -123,7 +123,7 @@ struct neigh_ops {
65176 void (*error_report)(struct neighbour *, struct sk_buff *);
65177 int (*output)(struct neighbour *, struct sk_buff *);
65178 int (*connected_output)(struct neighbour *, struct sk_buff *);
65179 -};
65180 +} __do_const;
65181
65182 struct pneigh_entry {
65183 struct pneigh_entry *next;
65184 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65185 index fd87963..312a11f 100644
65186 --- a/include/net/net_namespace.h
65187 +++ b/include/net/net_namespace.h
65188 @@ -102,7 +102,7 @@ struct net {
65189 #endif
65190 struct netns_ipvs *ipvs;
65191 struct sock *diag_nlsk;
65192 - atomic_t rt_genid;
65193 + atomic_unchecked_t rt_genid;
65194 };
65195
65196
65197 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65198
65199 static inline int rt_genid(struct net *net)
65200 {
65201 - return atomic_read(&net->rt_genid);
65202 + return atomic_read_unchecked(&net->rt_genid);
65203 }
65204
65205 static inline void rt_genid_bump(struct net *net)
65206 {
65207 - atomic_inc(&net->rt_genid);
65208 + atomic_inc_unchecked(&net->rt_genid);
65209 }
65210
65211 #endif /* __NET_NET_NAMESPACE_H */
65212 diff --git a/include/net/netdma.h b/include/net/netdma.h
65213 index 8ba8ce2..99b7fff 100644
65214 --- a/include/net/netdma.h
65215 +++ b/include/net/netdma.h
65216 @@ -24,7 +24,7 @@
65217 #include <linux/dmaengine.h>
65218 #include <linux/skbuff.h>
65219
65220 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65221 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65222 struct sk_buff *skb, int offset, struct iovec *to,
65223 size_t len, struct dma_pinned_list *pinned_list);
65224
65225 diff --git a/include/net/netlink.h b/include/net/netlink.h
65226 index 785f37a..c81dc0c 100644
65227 --- a/include/net/netlink.h
65228 +++ b/include/net/netlink.h
65229 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65230 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65231 {
65232 if (mark)
65233 - skb_trim(skb, (unsigned char *) mark - skb->data);
65234 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65235 }
65236
65237 /**
65238 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65239 index eb24dbc..567d6ed 100644
65240 --- a/include/net/netns/ipv4.h
65241 +++ b/include/net/netns/ipv4.h
65242 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65243 unsigned int sysctl_ping_group_range[2];
65244 long sysctl_tcp_mem[3];
65245
65246 - atomic_t dev_addr_genid;
65247 + atomic_unchecked_t dev_addr_genid;
65248
65249 #ifdef CONFIG_IP_MROUTE
65250 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65251 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65252 index ff49964..1411fee 100644
65253 --- a/include/net/sctp/sctp.h
65254 +++ b/include/net/sctp/sctp.h
65255 @@ -320,9 +320,9 @@ do { \
65256
65257 #else /* SCTP_DEBUG */
65258
65259 -#define SCTP_DEBUG_PRINTK(whatever...)
65260 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65261 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65262 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65263 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65264 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65265 #define SCTP_ENABLE_DEBUG
65266 #define SCTP_DISABLE_DEBUG
65267 #define SCTP_ASSERT(expr, str, func)
65268 diff --git a/include/net/sock.h b/include/net/sock.h
65269 index adb7da2..1100002 100644
65270 --- a/include/net/sock.h
65271 +++ b/include/net/sock.h
65272 @@ -305,7 +305,7 @@ struct sock {
65273 #ifdef CONFIG_RPS
65274 __u32 sk_rxhash;
65275 #endif
65276 - atomic_t sk_drops;
65277 + atomic_unchecked_t sk_drops;
65278 int sk_rcvbuf;
65279
65280 struct sk_filter __rcu *sk_filter;
65281 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65282 }
65283
65284 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65285 - char __user *from, char *to,
65286 + char __user *from, unsigned char *to,
65287 int copy, int offset)
65288 {
65289 if (skb->ip_summed == CHECKSUM_NONE) {
65290 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65291 }
65292 }
65293
65294 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65295 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65296
65297 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65298 {
65299 diff --git a/include/net/tcp.h b/include/net/tcp.h
65300 index 1f000ff..e5a8dfb 100644
65301 --- a/include/net/tcp.h
65302 +++ b/include/net/tcp.h
65303 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65304 extern void tcp_xmit_retransmit_queue(struct sock *);
65305 extern void tcp_simple_retransmit(struct sock *);
65306 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65307 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65308 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65309
65310 extern void tcp_send_probe0(struct sock *);
65311 extern void tcp_send_partial(struct sock *);
65312 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65313 struct inet6_skb_parm h6;
65314 #endif
65315 } header; /* For incoming frames */
65316 - __u32 seq; /* Starting sequence number */
65317 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65318 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65319 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65320 __u32 when; /* used to compute rtt's */
65321 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65322
65323 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65324
65325 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65326 /* 1 byte hole */
65327 - __u32 ack_seq; /* Sequence number ACK'd */
65328 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65329 };
65330
65331 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65332 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65333 char *name;
65334 sa_family_t family;
65335 const struct file_operations *seq_fops;
65336 - struct seq_operations seq_ops;
65337 + seq_operations_no_const seq_ops;
65338 };
65339
65340 struct tcp_iter_state {
65341 diff --git a/include/net/udp.h b/include/net/udp.h
65342 index 065f379..b661b40 100644
65343 --- a/include/net/udp.h
65344 +++ b/include/net/udp.h
65345 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65346 sa_family_t family;
65347 struct udp_table *udp_table;
65348 const struct file_operations *seq_fops;
65349 - struct seq_operations seq_ops;
65350 + seq_operations_no_const seq_ops;
65351 };
65352
65353 struct udp_iter_state {
65354 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65355 index 639dd13..15b206c 100644
65356 --- a/include/net/xfrm.h
65357 +++ b/include/net/xfrm.h
65358 @@ -514,7 +514,7 @@ struct xfrm_policy {
65359 struct timer_list timer;
65360
65361 struct flow_cache_object flo;
65362 - atomic_t genid;
65363 + atomic_unchecked_t genid;
65364 u32 priority;
65365 u32 index;
65366 struct xfrm_mark mark;
65367 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65368 index 1a046b1..ee0bef0 100644
65369 --- a/include/rdma/iw_cm.h
65370 +++ b/include/rdma/iw_cm.h
65371 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65372 int backlog);
65373
65374 int (*destroy_listen)(struct iw_cm_id *cm_id);
65375 -};
65376 +} __no_const;
65377
65378 /**
65379 * iw_create_cm_id - Create an IW CM identifier.
65380 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65381 index 399162b..b337f1a 100644
65382 --- a/include/scsi/libfc.h
65383 +++ b/include/scsi/libfc.h
65384 @@ -762,6 +762,7 @@ struct libfc_function_template {
65385 */
65386 void (*disc_stop_final) (struct fc_lport *);
65387 };
65388 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65389
65390 /**
65391 * struct fc_disc - Discovery context
65392 @@ -866,7 +867,7 @@ struct fc_lport {
65393 struct fc_vport *vport;
65394
65395 /* Operational Information */
65396 - struct libfc_function_template tt;
65397 + libfc_function_template_no_const tt;
65398 u8 link_up;
65399 u8 qfull;
65400 enum fc_lport_state state;
65401 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65402 index 9895f69..f1418f0 100644
65403 --- a/include/scsi/scsi_device.h
65404 +++ b/include/scsi/scsi_device.h
65405 @@ -166,9 +166,9 @@ struct scsi_device {
65406 unsigned int max_device_blocked; /* what device_blocked counts down from */
65407 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65408
65409 - atomic_t iorequest_cnt;
65410 - atomic_t iodone_cnt;
65411 - atomic_t ioerr_cnt;
65412 + atomic_unchecked_t iorequest_cnt;
65413 + atomic_unchecked_t iodone_cnt;
65414 + atomic_unchecked_t ioerr_cnt;
65415
65416 struct device sdev_gendev,
65417 sdev_dev;
65418 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65419 index b797e8f..8e2c3aa 100644
65420 --- a/include/scsi/scsi_transport_fc.h
65421 +++ b/include/scsi/scsi_transport_fc.h
65422 @@ -751,7 +751,8 @@ struct fc_function_template {
65423 unsigned long show_host_system_hostname:1;
65424
65425 unsigned long disable_target_scan:1;
65426 -};
65427 +} __do_const;
65428 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65429
65430
65431 /**
65432 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65433 index 030b87c..98a6954 100644
65434 --- a/include/sound/ak4xxx-adda.h
65435 +++ b/include/sound/ak4xxx-adda.h
65436 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65437 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65438 unsigned char val);
65439 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65440 -};
65441 +} __no_const;
65442
65443 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65444
65445 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65446 index 8c05e47..2b5df97 100644
65447 --- a/include/sound/hwdep.h
65448 +++ b/include/sound/hwdep.h
65449 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65450 struct snd_hwdep_dsp_status *status);
65451 int (*dsp_load)(struct snd_hwdep *hw,
65452 struct snd_hwdep_dsp_image *image);
65453 -};
65454 +} __no_const;
65455
65456 struct snd_hwdep {
65457 struct snd_card *card;
65458 diff --git a/include/sound/info.h b/include/sound/info.h
65459 index 9ca1a49..aba1728 100644
65460 --- a/include/sound/info.h
65461 +++ b/include/sound/info.h
65462 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65463 struct snd_info_buffer *buffer);
65464 void (*write)(struct snd_info_entry *entry,
65465 struct snd_info_buffer *buffer);
65466 -};
65467 +} __no_const;
65468
65469 struct snd_info_entry_ops {
65470 int (*open)(struct snd_info_entry *entry,
65471 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65472 index cdca2ab..10bbe05 100644
65473 --- a/include/sound/pcm.h
65474 +++ b/include/sound/pcm.h
65475 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65476 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65477 int (*ack)(struct snd_pcm_substream *substream);
65478 };
65479 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65480
65481 /*
65482 *
65483 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65484 index af1b49e..a5d55a5 100644
65485 --- a/include/sound/sb16_csp.h
65486 +++ b/include/sound/sb16_csp.h
65487 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65488 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65489 int (*csp_stop) (struct snd_sb_csp * p);
65490 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65491 -};
65492 +} __no_const;
65493
65494 /*
65495 * CSP private data
65496 diff --git a/include/sound/soc.h b/include/sound/soc.h
65497 index e063380..e8077d5 100644
65498 --- a/include/sound/soc.h
65499 +++ b/include/sound/soc.h
65500 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65501 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65502 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65503 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65504 -};
65505 +} __do_const;
65506
65507 struct snd_soc_platform {
65508 const char *name;
65509 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65510 struct snd_soc_dai_link *dai_link;
65511 struct mutex pcm_mutex;
65512 enum snd_soc_pcm_subclass pcm_subclass;
65513 - struct snd_pcm_ops ops;
65514 + snd_pcm_ops_no_const ops;
65515
65516 unsigned int dev_registered:1;
65517
65518 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65519 index fe8590c..aaed363 100644
65520 --- a/include/sound/tea575x-tuner.h
65521 +++ b/include/sound/tea575x-tuner.h
65522 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65523
65524 struct snd_tea575x {
65525 struct v4l2_device *v4l2_dev;
65526 - struct v4l2_file_operations fops;
65527 + v4l2_file_operations_no_const fops;
65528 struct video_device vd; /* video device */
65529 int radio_nr; /* radio_nr */
65530 bool tea5759; /* 5759 chip is present */
65531 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65532 index 5be8937..a8e46e9 100644
65533 --- a/include/target/target_core_base.h
65534 +++ b/include/target/target_core_base.h
65535 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65536 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65537 int (*t10_pr_register)(struct se_cmd *);
65538 int (*t10_pr_clear)(struct se_cmd *);
65539 -};
65540 +} __no_const;
65541
65542 struct t10_reservation {
65543 /* Reservation effects all target ports */
65544 @@ -758,7 +758,7 @@ struct se_device {
65545 spinlock_t stats_lock;
65546 /* Active commands on this virtual SE device */
65547 atomic_t simple_cmds;
65548 - atomic_t dev_ordered_id;
65549 + atomic_unchecked_t dev_ordered_id;
65550 atomic_t dev_ordered_sync;
65551 atomic_t dev_qf_count;
65552 struct se_obj dev_obj;
65553 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65554 new file mode 100644
65555 index 0000000..2efe49d
65556 --- /dev/null
65557 +++ b/include/trace/events/fs.h
65558 @@ -0,0 +1,53 @@
65559 +#undef TRACE_SYSTEM
65560 +#define TRACE_SYSTEM fs
65561 +
65562 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65563 +#define _TRACE_FS_H
65564 +
65565 +#include <linux/fs.h>
65566 +#include <linux/tracepoint.h>
65567 +
65568 +TRACE_EVENT(do_sys_open,
65569 +
65570 + TP_PROTO(char *filename, int flags, int mode),
65571 +
65572 + TP_ARGS(filename, flags, mode),
65573 +
65574 + TP_STRUCT__entry(
65575 + __string( filename, filename )
65576 + __field( int, flags )
65577 + __field( int, mode )
65578 + ),
65579 +
65580 + TP_fast_assign(
65581 + __assign_str(filename, filename);
65582 + __entry->flags = flags;
65583 + __entry->mode = mode;
65584 + ),
65585 +
65586 + TP_printk("\"%s\" %x %o",
65587 + __get_str(filename), __entry->flags, __entry->mode)
65588 +);
65589 +
65590 +TRACE_EVENT(open_exec,
65591 +
65592 + TP_PROTO(const char *filename),
65593 +
65594 + TP_ARGS(filename),
65595 +
65596 + TP_STRUCT__entry(
65597 + __string( filename, filename )
65598 + ),
65599 +
65600 + TP_fast_assign(
65601 + __assign_str(filename, filename);
65602 + ),
65603 +
65604 + TP_printk("\"%s\"",
65605 + __get_str(filename))
65606 +);
65607 +
65608 +#endif /* _TRACE_FS_H */
65609 +
65610 +/* This part must be outside protection */
65611 +#include <trace/define_trace.h>
65612 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65613 index 1c09820..7f5ec79 100644
65614 --- a/include/trace/events/irq.h
65615 +++ b/include/trace/events/irq.h
65616 @@ -36,7 +36,7 @@ struct softirq_action;
65617 */
65618 TRACE_EVENT(irq_handler_entry,
65619
65620 - TP_PROTO(int irq, struct irqaction *action),
65621 + TP_PROTO(int irq, const struct irqaction *action),
65622
65623 TP_ARGS(irq, action),
65624
65625 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65626 */
65627 TRACE_EVENT(irq_handler_exit,
65628
65629 - TP_PROTO(int irq, struct irqaction *action, int ret),
65630 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65631
65632 TP_ARGS(irq, action, ret),
65633
65634 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65635 index f9466fa..f4e2b81 100644
65636 --- a/include/video/udlfb.h
65637 +++ b/include/video/udlfb.h
65638 @@ -53,10 +53,10 @@ struct dlfb_data {
65639 u32 pseudo_palette[256];
65640 int blank_mode; /*one of FB_BLANK_ */
65641 /* blit-only rendering path metrics, exposed through sysfs */
65642 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65643 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65644 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65645 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65646 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65647 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65648 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65649 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65650 };
65651
65652 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65653 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65654 index 0993a22..32ba2fe 100644
65655 --- a/include/video/uvesafb.h
65656 +++ b/include/video/uvesafb.h
65657 @@ -177,6 +177,7 @@ struct uvesafb_par {
65658 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65659 u8 pmi_setpal; /* PMI for palette changes */
65660 u16 *pmi_base; /* protected mode interface location */
65661 + u8 *pmi_code; /* protected mode code location */
65662 void *pmi_start;
65663 void *pmi_pal;
65664 u8 *vbe_state_orig; /*
65665 diff --git a/init/Kconfig b/init/Kconfig
65666 index af6c7f8..5c188f8 100644
65667 --- a/init/Kconfig
65668 +++ b/init/Kconfig
65669 @@ -850,6 +850,7 @@ endif # CGROUPS
65670
65671 config CHECKPOINT_RESTORE
65672 bool "Checkpoint/restore support" if EXPERT
65673 + depends on !GRKERNSEC
65674 default n
65675 help
65676 Enables additional kernel features in a sake of checkpoint/restore.
65677 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65678 # Security modules
65679 depends on SECURITY_TOMOYO = n
65680 depends on SECURITY_APPARMOR = n
65681 + depends on GRKERNSEC = n
65682
65683 config UIDGID_STRICT_TYPE_CHECKS
65684 bool "Require conversions between uid/gids and their internal representation"
65685 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65686
65687 config COMPAT_BRK
65688 bool "Disable heap randomization"
65689 - default y
65690 + default n
65691 help
65692 Randomizing heap placement makes heap exploits harder, but it
65693 also breaks ancient binaries (including anything libc5 based).
65694 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65695 config STOP_MACHINE
65696 bool
65697 default y
65698 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65699 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65700 help
65701 Need stop_machine() primitive.
65702
65703 diff --git a/init/Makefile b/init/Makefile
65704 index 7bc47ee..6da2dc7 100644
65705 --- a/init/Makefile
65706 +++ b/init/Makefile
65707 @@ -2,6 +2,9 @@
65708 # Makefile for the linux kernel.
65709 #
65710
65711 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65712 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65713 +
65714 obj-y := main.o version.o mounts.o
65715 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65716 obj-y += noinitramfs.o
65717 diff --git a/init/do_mounts.c b/init/do_mounts.c
65718 index d3f0aee..c9322f5 100644
65719 --- a/init/do_mounts.c
65720 +++ b/init/do_mounts.c
65721 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65722 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65723 {
65724 struct super_block *s;
65725 - int err = sys_mount(name, "/root", fs, flags, data);
65726 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65727 if (err)
65728 return err;
65729
65730 - sys_chdir("/root");
65731 + sys_chdir((const char __force_user *)"/root");
65732 s = current->fs->pwd.dentry->d_sb;
65733 ROOT_DEV = s->s_dev;
65734 printk(KERN_INFO
65735 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65736 va_start(args, fmt);
65737 vsprintf(buf, fmt, args);
65738 va_end(args);
65739 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65740 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65741 if (fd >= 0) {
65742 sys_ioctl(fd, FDEJECT, 0);
65743 sys_close(fd);
65744 }
65745 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65746 - fd = sys_open("/dev/console", O_RDWR, 0);
65747 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65748 if (fd >= 0) {
65749 sys_ioctl(fd, TCGETS, (long)&termios);
65750 termios.c_lflag &= ~ICANON;
65751 sys_ioctl(fd, TCSETSF, (long)&termios);
65752 - sys_read(fd, &c, 1);
65753 + sys_read(fd, (char __user *)&c, 1);
65754 termios.c_lflag |= ICANON;
65755 sys_ioctl(fd, TCSETSF, (long)&termios);
65756 sys_close(fd);
65757 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65758 mount_root();
65759 out:
65760 devtmpfs_mount("dev");
65761 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65762 - sys_chroot(".");
65763 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65764 + sys_chroot((const char __force_user *)".");
65765 }
65766 diff --git a/init/do_mounts.h b/init/do_mounts.h
65767 index f5b978a..69dbfe8 100644
65768 --- a/init/do_mounts.h
65769 +++ b/init/do_mounts.h
65770 @@ -15,15 +15,15 @@ extern int root_mountflags;
65771
65772 static inline int create_dev(char *name, dev_t dev)
65773 {
65774 - sys_unlink(name);
65775 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65776 + sys_unlink((char __force_user *)name);
65777 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65778 }
65779
65780 #if BITS_PER_LONG == 32
65781 static inline u32 bstat(char *name)
65782 {
65783 struct stat64 stat;
65784 - if (sys_stat64(name, &stat) != 0)
65785 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65786 return 0;
65787 if (!S_ISBLK(stat.st_mode))
65788 return 0;
65789 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65790 static inline u32 bstat(char *name)
65791 {
65792 struct stat stat;
65793 - if (sys_newstat(name, &stat) != 0)
65794 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65795 return 0;
65796 if (!S_ISBLK(stat.st_mode))
65797 return 0;
65798 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65799 index 135959a2..28a3f43 100644
65800 --- a/init/do_mounts_initrd.c
65801 +++ b/init/do_mounts_initrd.c
65802 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65803 create_dev("/dev/root.old", Root_RAM0);
65804 /* mount initrd on rootfs' /root */
65805 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65806 - sys_mkdir("/old", 0700);
65807 - root_fd = sys_open("/", 0, 0);
65808 - old_fd = sys_open("/old", 0, 0);
65809 + sys_mkdir((const char __force_user *)"/old", 0700);
65810 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65811 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65812 /* move initrd over / and chdir/chroot in initrd root */
65813 - sys_chdir("/root");
65814 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65815 - sys_chroot(".");
65816 + sys_chdir((const char __force_user *)"/root");
65817 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65818 + sys_chroot((const char __force_user *)".");
65819
65820 /*
65821 * In case that a resume from disk is carried out by linuxrc or one of
65822 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65823
65824 /* move initrd to rootfs' /old */
65825 sys_fchdir(old_fd);
65826 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65827 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65828 /* switch root and cwd back to / of rootfs */
65829 sys_fchdir(root_fd);
65830 - sys_chroot(".");
65831 + sys_chroot((const char __force_user *)".");
65832 sys_close(old_fd);
65833 sys_close(root_fd);
65834
65835 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65836 - sys_chdir("/old");
65837 + sys_chdir((const char __force_user *)"/old");
65838 return;
65839 }
65840
65841 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65842 mount_root();
65843
65844 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65845 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65846 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65847 if (!error)
65848 printk("okay\n");
65849 else {
65850 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65851 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65852 if (error == -ENOENT)
65853 printk("/initrd does not exist. Ignored.\n");
65854 else
65855 printk("failed\n");
65856 printk(KERN_NOTICE "Unmounting old root\n");
65857 - sys_umount("/old", MNT_DETACH);
65858 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65859 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65860 if (fd < 0) {
65861 error = fd;
65862 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65863 * mounted in the normal path.
65864 */
65865 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65866 - sys_unlink("/initrd.image");
65867 + sys_unlink((const char __force_user *)"/initrd.image");
65868 handle_initrd();
65869 return 1;
65870 }
65871 }
65872 - sys_unlink("/initrd.image");
65873 + sys_unlink((const char __force_user *)"/initrd.image");
65874 return 0;
65875 }
65876 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65877 index 8cb6db5..d729f50 100644
65878 --- a/init/do_mounts_md.c
65879 +++ b/init/do_mounts_md.c
65880 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65881 partitioned ? "_d" : "", minor,
65882 md_setup_args[ent].device_names);
65883
65884 - fd = sys_open(name, 0, 0);
65885 + fd = sys_open((char __force_user *)name, 0, 0);
65886 if (fd < 0) {
65887 printk(KERN_ERR "md: open failed - cannot start "
65888 "array %s\n", name);
65889 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65890 * array without it
65891 */
65892 sys_close(fd);
65893 - fd = sys_open(name, 0, 0);
65894 + fd = sys_open((char __force_user *)name, 0, 0);
65895 sys_ioctl(fd, BLKRRPART, 0);
65896 }
65897 sys_close(fd);
65898 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65899
65900 wait_for_device_probe();
65901
65902 - fd = sys_open("/dev/md0", 0, 0);
65903 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65904 if (fd >= 0) {
65905 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65906 sys_close(fd);
65907 diff --git a/init/init_task.c b/init/init_task.c
65908 index 8b2f399..f0797c9 100644
65909 --- a/init/init_task.c
65910 +++ b/init/init_task.c
65911 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65912 * Initial thread structure. Alignment of this is handled by a special
65913 * linker map entry.
65914 */
65915 +#ifdef CONFIG_X86
65916 +union thread_union init_thread_union __init_task_data;
65917 +#else
65918 union thread_union init_thread_union __init_task_data =
65919 { INIT_THREAD_INFO(init_task) };
65920 +#endif
65921 diff --git a/init/initramfs.c b/init/initramfs.c
65922 index 84c6bf1..8899338 100644
65923 --- a/init/initramfs.c
65924 +++ b/init/initramfs.c
65925 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65926 }
65927 }
65928
65929 -static long __init do_utime(char *filename, time_t mtime)
65930 +static long __init do_utime(char __force_user *filename, time_t mtime)
65931 {
65932 struct timespec t[2];
65933
65934 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65935 struct dir_entry *de, *tmp;
65936 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65937 list_del(&de->list);
65938 - do_utime(de->name, de->mtime);
65939 + do_utime((char __force_user *)de->name, de->mtime);
65940 kfree(de->name);
65941 kfree(de);
65942 }
65943 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65944 if (nlink >= 2) {
65945 char *old = find_link(major, minor, ino, mode, collected);
65946 if (old)
65947 - return (sys_link(old, collected) < 0) ? -1 : 1;
65948 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65949 }
65950 return 0;
65951 }
65952 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65953 {
65954 struct stat st;
65955
65956 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65957 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65958 if (S_ISDIR(st.st_mode))
65959 - sys_rmdir(path);
65960 + sys_rmdir((char __force_user *)path);
65961 else
65962 - sys_unlink(path);
65963 + sys_unlink((char __force_user *)path);
65964 }
65965 }
65966
65967 @@ -315,7 +315,7 @@ static int __init do_name(void)
65968 int openflags = O_WRONLY|O_CREAT;
65969 if (ml != 1)
65970 openflags |= O_TRUNC;
65971 - wfd = sys_open(collected, openflags, mode);
65972 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65973
65974 if (wfd >= 0) {
65975 sys_fchown(wfd, uid, gid);
65976 @@ -327,17 +327,17 @@ static int __init do_name(void)
65977 }
65978 }
65979 } else if (S_ISDIR(mode)) {
65980 - sys_mkdir(collected, mode);
65981 - sys_chown(collected, uid, gid);
65982 - sys_chmod(collected, mode);
65983 + sys_mkdir((char __force_user *)collected, mode);
65984 + sys_chown((char __force_user *)collected, uid, gid);
65985 + sys_chmod((char __force_user *)collected, mode);
65986 dir_add(collected, mtime);
65987 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65988 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65989 if (maybe_link() == 0) {
65990 - sys_mknod(collected, mode, rdev);
65991 - sys_chown(collected, uid, gid);
65992 - sys_chmod(collected, mode);
65993 - do_utime(collected, mtime);
65994 + sys_mknod((char __force_user *)collected, mode, rdev);
65995 + sys_chown((char __force_user *)collected, uid, gid);
65996 + sys_chmod((char __force_user *)collected, mode);
65997 + do_utime((char __force_user *)collected, mtime);
65998 }
65999 }
66000 return 0;
66001 @@ -346,15 +346,15 @@ static int __init do_name(void)
66002 static int __init do_copy(void)
66003 {
66004 if (count >= body_len) {
66005 - sys_write(wfd, victim, body_len);
66006 + sys_write(wfd, (char __force_user *)victim, body_len);
66007 sys_close(wfd);
66008 - do_utime(vcollected, mtime);
66009 + do_utime((char __force_user *)vcollected, mtime);
66010 kfree(vcollected);
66011 eat(body_len);
66012 state = SkipIt;
66013 return 0;
66014 } else {
66015 - sys_write(wfd, victim, count);
66016 + sys_write(wfd, (char __force_user *)victim, count);
66017 body_len -= count;
66018 eat(count);
66019 return 1;
66020 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66021 {
66022 collected[N_ALIGN(name_len) + body_len] = '\0';
66023 clean_path(collected, 0);
66024 - sys_symlink(collected + N_ALIGN(name_len), collected);
66025 - sys_lchown(collected, uid, gid);
66026 - do_utime(collected, mtime);
66027 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66028 + sys_lchown((char __force_user *)collected, uid, gid);
66029 + do_utime((char __force_user *)collected, mtime);
66030 state = SkipIt;
66031 next_state = Reset;
66032 return 0;
66033 diff --git a/init/main.c b/init/main.c
66034 index d61ec54..bd3144f 100644
66035 --- a/init/main.c
66036 +++ b/init/main.c
66037 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66038 extern void tc_init(void);
66039 #endif
66040
66041 +extern void grsecurity_init(void);
66042 +
66043 /*
66044 * Debug helper: via this flag we know that we are in 'early bootup code'
66045 * where only the boot processor is running with IRQ disabled. This means
66046 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66047
66048 __setup("reset_devices", set_reset_devices);
66049
66050 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66051 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66052 +static int __init setup_grsec_proc_gid(char *str)
66053 +{
66054 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66055 + return 1;
66056 +}
66057 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66058 +#endif
66059 +
66060 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66061 +extern char pax_enter_kernel_user[];
66062 +extern char pax_exit_kernel_user[];
66063 +extern pgdval_t clone_pgd_mask;
66064 +#endif
66065 +
66066 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66067 +static int __init setup_pax_nouderef(char *str)
66068 +{
66069 +#ifdef CONFIG_X86_32
66070 + unsigned int cpu;
66071 + struct desc_struct *gdt;
66072 +
66073 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66074 + gdt = get_cpu_gdt_table(cpu);
66075 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66076 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66077 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66078 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66079 + }
66080 + loadsegment(ds, __KERNEL_DS);
66081 + loadsegment(es, __KERNEL_DS);
66082 + loadsegment(ss, __KERNEL_DS);
66083 +#else
66084 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66085 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66086 + clone_pgd_mask = ~(pgdval_t)0UL;
66087 +#endif
66088 +
66089 + return 0;
66090 +}
66091 +early_param("pax_nouderef", setup_pax_nouderef);
66092 +#endif
66093 +
66094 +#ifdef CONFIG_PAX_SOFTMODE
66095 +int pax_softmode;
66096 +
66097 +static int __init setup_pax_softmode(char *str)
66098 +{
66099 + get_option(&str, &pax_softmode);
66100 + return 1;
66101 +}
66102 +__setup("pax_softmode=", setup_pax_softmode);
66103 +#endif
66104 +
66105 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66106 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66107 static const char *panic_later, *panic_param;
66108 @@ -678,6 +735,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66109 {
66110 int count = preempt_count();
66111 int ret;
66112 + const char *msg1 = "", *msg2 = "";
66113
66114 if (initcall_debug)
66115 ret = do_one_initcall_debug(fn);
66116 @@ -690,15 +748,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66117 sprintf(msgbuf, "error code %d ", ret);
66118
66119 if (preempt_count() != count) {
66120 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66121 + msg1 = " preemption imbalance";
66122 preempt_count() = count;
66123 }
66124 if (irqs_disabled()) {
66125 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66126 + msg2 = " disabled interrupts";
66127 local_irq_enable();
66128 }
66129 - if (msgbuf[0]) {
66130 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66131 + if (msgbuf[0] || *msg1 || *msg2) {
66132 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66133 }
66134
66135 return ret;
66136 @@ -752,8 +810,14 @@ static void __init do_initcall_level(int level)
66137 level, level,
66138 &repair_env_string);
66139
66140 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66141 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66142 do_one_initcall(*fn);
66143 +
66144 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66145 + transfer_latent_entropy();
66146 +#endif
66147 +
66148 + }
66149 }
66150
66151 static void __init do_initcalls(void)
66152 @@ -787,8 +851,14 @@ static void __init do_pre_smp_initcalls(void)
66153 {
66154 initcall_t *fn;
66155
66156 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66157 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66158 do_one_initcall(*fn);
66159 +
66160 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66161 + transfer_latent_entropy();
66162 +#endif
66163 +
66164 + }
66165 }
66166
66167 static void run_init_process(const char *init_filename)
66168 @@ -870,7 +940,7 @@ static int __init kernel_init(void * unused)
66169 do_basic_setup();
66170
66171 /* Open the /dev/console on the rootfs, this should never fail */
66172 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66173 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66174 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66175
66176 (void) sys_dup(0);
66177 @@ -883,11 +953,13 @@ static int __init kernel_init(void * unused)
66178 if (!ramdisk_execute_command)
66179 ramdisk_execute_command = "/init";
66180
66181 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66182 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66183 ramdisk_execute_command = NULL;
66184 prepare_namespace();
66185 }
66186
66187 + grsecurity_init();
66188 +
66189 /*
66190 * Ok, we have completed the initial bootup, and
66191 * we're essentially up and running. Get rid of the
66192 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66193 index 9a08acc..e65ebe7 100644
66194 --- a/ipc/mqueue.c
66195 +++ b/ipc/mqueue.c
66196 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66197 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66198 info->attr.mq_msgsize);
66199
66200 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66201 spin_lock(&mq_lock);
66202 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66203 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66204 diff --git a/ipc/msg.c b/ipc/msg.c
66205 index 7385de2..a8180e08 100644
66206 --- a/ipc/msg.c
66207 +++ b/ipc/msg.c
66208 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66209 return security_msg_queue_associate(msq, msgflg);
66210 }
66211
66212 +static struct ipc_ops msg_ops = {
66213 + .getnew = newque,
66214 + .associate = msg_security,
66215 + .more_checks = NULL
66216 +};
66217 +
66218 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66219 {
66220 struct ipc_namespace *ns;
66221 - struct ipc_ops msg_ops;
66222 struct ipc_params msg_params;
66223
66224 ns = current->nsproxy->ipc_ns;
66225
66226 - msg_ops.getnew = newque;
66227 - msg_ops.associate = msg_security;
66228 - msg_ops.more_checks = NULL;
66229 -
66230 msg_params.key = key;
66231 msg_params.flg = msgflg;
66232
66233 diff --git a/ipc/sem.c b/ipc/sem.c
66234 index 5215a81..cfc0cac 100644
66235 --- a/ipc/sem.c
66236 +++ b/ipc/sem.c
66237 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66238 return 0;
66239 }
66240
66241 +static struct ipc_ops sem_ops = {
66242 + .getnew = newary,
66243 + .associate = sem_security,
66244 + .more_checks = sem_more_checks
66245 +};
66246 +
66247 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66248 {
66249 struct ipc_namespace *ns;
66250 - struct ipc_ops sem_ops;
66251 struct ipc_params sem_params;
66252
66253 ns = current->nsproxy->ipc_ns;
66254 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66255 if (nsems < 0 || nsems > ns->sc_semmsl)
66256 return -EINVAL;
66257
66258 - sem_ops.getnew = newary;
66259 - sem_ops.associate = sem_security;
66260 - sem_ops.more_checks = sem_more_checks;
66261 -
66262 sem_params.key = key;
66263 sem_params.flg = semflg;
66264 sem_params.u.nsems = nsems;
66265 diff --git a/ipc/shm.c b/ipc/shm.c
66266 index 00faa05..7040960 100644
66267 --- a/ipc/shm.c
66268 +++ b/ipc/shm.c
66269 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66270 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66271 #endif
66272
66273 +#ifdef CONFIG_GRKERNSEC
66274 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66275 + const time_t shm_createtime, const uid_t cuid,
66276 + const int shmid);
66277 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66278 + const time_t shm_createtime);
66279 +#endif
66280 +
66281 void shm_init_ns(struct ipc_namespace *ns)
66282 {
66283 ns->shm_ctlmax = SHMMAX;
66284 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66285 shp->shm_lprid = 0;
66286 shp->shm_atim = shp->shm_dtim = 0;
66287 shp->shm_ctim = get_seconds();
66288 +#ifdef CONFIG_GRKERNSEC
66289 + {
66290 + struct timespec timeval;
66291 + do_posix_clock_monotonic_gettime(&timeval);
66292 +
66293 + shp->shm_createtime = timeval.tv_sec;
66294 + }
66295 +#endif
66296 shp->shm_segsz = size;
66297 shp->shm_nattch = 0;
66298 shp->shm_file = file;
66299 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66300 return 0;
66301 }
66302
66303 +static struct ipc_ops shm_ops = {
66304 + .getnew = newseg,
66305 + .associate = shm_security,
66306 + .more_checks = shm_more_checks
66307 +};
66308 +
66309 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66310 {
66311 struct ipc_namespace *ns;
66312 - struct ipc_ops shm_ops;
66313 struct ipc_params shm_params;
66314
66315 ns = current->nsproxy->ipc_ns;
66316
66317 - shm_ops.getnew = newseg;
66318 - shm_ops.associate = shm_security;
66319 - shm_ops.more_checks = shm_more_checks;
66320 -
66321 shm_params.key = key;
66322 shm_params.flg = shmflg;
66323 shm_params.u.size = size;
66324 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66325 f_mode = FMODE_READ | FMODE_WRITE;
66326 }
66327 if (shmflg & SHM_EXEC) {
66328 +
66329 +#ifdef CONFIG_PAX_MPROTECT
66330 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66331 + goto out;
66332 +#endif
66333 +
66334 prot |= PROT_EXEC;
66335 acc_mode |= S_IXUGO;
66336 }
66337 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66338 if (err)
66339 goto out_unlock;
66340
66341 +#ifdef CONFIG_GRKERNSEC
66342 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66343 + shp->shm_perm.cuid, shmid) ||
66344 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66345 + err = -EACCES;
66346 + goto out_unlock;
66347 + }
66348 +#endif
66349 +
66350 path = shp->shm_file->f_path;
66351 path_get(&path);
66352 shp->shm_nattch++;
66353 +#ifdef CONFIG_GRKERNSEC
66354 + shp->shm_lapid = current->pid;
66355 +#endif
66356 size = i_size_read(path.dentry->d_inode);
66357 shm_unlock(shp);
66358
66359 diff --git a/kernel/acct.c b/kernel/acct.c
66360 index 02e6167..54824f7 100644
66361 --- a/kernel/acct.c
66362 +++ b/kernel/acct.c
66363 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66364 */
66365 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66366 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66367 - file->f_op->write(file, (char *)&ac,
66368 + file->f_op->write(file, (char __force_user *)&ac,
66369 sizeof(acct_t), &file->f_pos);
66370 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66371 set_fs(fs);
66372 diff --git a/kernel/audit.c b/kernel/audit.c
66373 index a8c84be..8bd034c 100644
66374 --- a/kernel/audit.c
66375 +++ b/kernel/audit.c
66376 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66377 3) suppressed due to audit_rate_limit
66378 4) suppressed due to audit_backlog_limit
66379 */
66380 -static atomic_t audit_lost = ATOMIC_INIT(0);
66381 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66382
66383 /* The netlink socket. */
66384 static struct sock *audit_sock;
66385 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66386 unsigned long now;
66387 int print;
66388
66389 - atomic_inc(&audit_lost);
66390 + atomic_inc_unchecked(&audit_lost);
66391
66392 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66393
66394 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66395 printk(KERN_WARNING
66396 "audit: audit_lost=%d audit_rate_limit=%d "
66397 "audit_backlog_limit=%d\n",
66398 - atomic_read(&audit_lost),
66399 + atomic_read_unchecked(&audit_lost),
66400 audit_rate_limit,
66401 audit_backlog_limit);
66402 audit_panic(message);
66403 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66404 status_set.pid = audit_pid;
66405 status_set.rate_limit = audit_rate_limit;
66406 status_set.backlog_limit = audit_backlog_limit;
66407 - status_set.lost = atomic_read(&audit_lost);
66408 + status_set.lost = atomic_read_unchecked(&audit_lost);
66409 status_set.backlog = skb_queue_len(&audit_skb_queue);
66410 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66411 &status_set, sizeof(status_set));
66412 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66413 index 4b96415..d8c16ee 100644
66414 --- a/kernel/auditsc.c
66415 +++ b/kernel/auditsc.c
66416 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66417 }
66418
66419 /* global counter which is incremented every time something logs in */
66420 -static atomic_t session_id = ATOMIC_INIT(0);
66421 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66422
66423 /**
66424 * audit_set_loginuid - set current task's audit_context loginuid
66425 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66426 return -EPERM;
66427 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66428
66429 - sessionid = atomic_inc_return(&session_id);
66430 + sessionid = atomic_inc_return_unchecked(&session_id);
66431 if (context && context->in_syscall) {
66432 struct audit_buffer *ab;
66433
66434 diff --git a/kernel/capability.c b/kernel/capability.c
66435 index 493d972..ea17248 100644
66436 --- a/kernel/capability.c
66437 +++ b/kernel/capability.c
66438 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66439 * before modification is attempted and the application
66440 * fails.
66441 */
66442 + if (tocopy > ARRAY_SIZE(kdata))
66443 + return -EFAULT;
66444 +
66445 if (copy_to_user(dataptr, kdata, tocopy
66446 * sizeof(struct __user_cap_data_struct))) {
66447 return -EFAULT;
66448 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66449 int ret;
66450
66451 rcu_read_lock();
66452 - ret = security_capable(__task_cred(t), ns, cap);
66453 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66454 + gr_task_is_capable(t, __task_cred(t), cap);
66455 rcu_read_unlock();
66456
66457 - return (ret == 0);
66458 + return ret;
66459 }
66460
66461 /**
66462 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66463 int ret;
66464
66465 rcu_read_lock();
66466 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66467 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66468 rcu_read_unlock();
66469
66470 - return (ret == 0);
66471 + return ret;
66472 }
66473
66474 /**
66475 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66476 BUG();
66477 }
66478
66479 - if (security_capable(current_cred(), ns, cap) == 0) {
66480 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66481 current->flags |= PF_SUPERPRIV;
66482 return true;
66483 }
66484 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66485 }
66486 EXPORT_SYMBOL(ns_capable);
66487
66488 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66489 +{
66490 + if (unlikely(!cap_valid(cap))) {
66491 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66492 + BUG();
66493 + }
66494 +
66495 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66496 + current->flags |= PF_SUPERPRIV;
66497 + return true;
66498 + }
66499 + return false;
66500 +}
66501 +EXPORT_SYMBOL(ns_capable_nolog);
66502 +
66503 /**
66504 * capable - Determine if the current task has a superior capability in effect
66505 * @cap: The capability to be tested for
66506 @@ -408,6 +427,12 @@ bool capable(int cap)
66507 }
66508 EXPORT_SYMBOL(capable);
66509
66510 +bool capable_nolog(int cap)
66511 +{
66512 + return ns_capable_nolog(&init_user_ns, cap);
66513 +}
66514 +EXPORT_SYMBOL(capable_nolog);
66515 +
66516 /**
66517 * nsown_capable - Check superior capability to one's own user_ns
66518 * @cap: The capability in question
66519 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66520
66521 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66522 }
66523 +
66524 +bool inode_capable_nolog(const struct inode *inode, int cap)
66525 +{
66526 + struct user_namespace *ns = current_user_ns();
66527 +
66528 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66529 +}
66530 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66531 index ff2bce5..a41e8f9 100644
66532 --- a/kernel/cgroup.c
66533 +++ b/kernel/cgroup.c
66534 @@ -5390,7 +5390,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66535 struct css_set *cg = link->cg;
66536 struct task_struct *task;
66537 int count = 0;
66538 - seq_printf(seq, "css_set %p\n", cg);
66539 + seq_printf(seq, "css_set %pK\n", cg);
66540 list_for_each_entry(task, &cg->tasks, cg_list) {
66541 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66542 seq_puts(seq, " ...\n");
66543 diff --git a/kernel/compat.c b/kernel/compat.c
66544 index c28a306..b4d0cf3 100644
66545 --- a/kernel/compat.c
66546 +++ b/kernel/compat.c
66547 @@ -13,6 +13,7 @@
66548
66549 #include <linux/linkage.h>
66550 #include <linux/compat.h>
66551 +#include <linux/module.h>
66552 #include <linux/errno.h>
66553 #include <linux/time.h>
66554 #include <linux/signal.h>
66555 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66556 mm_segment_t oldfs;
66557 long ret;
66558
66559 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66560 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66561 oldfs = get_fs();
66562 set_fs(KERNEL_DS);
66563 ret = hrtimer_nanosleep_restart(restart);
66564 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66565 oldfs = get_fs();
66566 set_fs(KERNEL_DS);
66567 ret = hrtimer_nanosleep(&tu,
66568 - rmtp ? (struct timespec __user *)&rmt : NULL,
66569 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66570 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66571 set_fs(oldfs);
66572
66573 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66574 mm_segment_t old_fs = get_fs();
66575
66576 set_fs(KERNEL_DS);
66577 - ret = sys_sigpending((old_sigset_t __user *) &s);
66578 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66579 set_fs(old_fs);
66580 if (ret == 0)
66581 ret = put_user(s, set);
66582 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66583 mm_segment_t old_fs = get_fs();
66584
66585 set_fs(KERNEL_DS);
66586 - ret = sys_old_getrlimit(resource, &r);
66587 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66588 set_fs(old_fs);
66589
66590 if (!ret) {
66591 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66592 mm_segment_t old_fs = get_fs();
66593
66594 set_fs(KERNEL_DS);
66595 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66596 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66597 set_fs(old_fs);
66598
66599 if (ret)
66600 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66601 set_fs (KERNEL_DS);
66602 ret = sys_wait4(pid,
66603 (stat_addr ?
66604 - (unsigned int __user *) &status : NULL),
66605 - options, (struct rusage __user *) &r);
66606 + (unsigned int __force_user *) &status : NULL),
66607 + options, (struct rusage __force_user *) &r);
66608 set_fs (old_fs);
66609
66610 if (ret > 0) {
66611 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66612 memset(&info, 0, sizeof(info));
66613
66614 set_fs(KERNEL_DS);
66615 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66616 - uru ? (struct rusage __user *)&ru : NULL);
66617 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66618 + uru ? (struct rusage __force_user *)&ru : NULL);
66619 set_fs(old_fs);
66620
66621 if ((ret < 0) || (info.si_signo == 0))
66622 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66623 oldfs = get_fs();
66624 set_fs(KERNEL_DS);
66625 err = sys_timer_settime(timer_id, flags,
66626 - (struct itimerspec __user *) &newts,
66627 - (struct itimerspec __user *) &oldts);
66628 + (struct itimerspec __force_user *) &newts,
66629 + (struct itimerspec __force_user *) &oldts);
66630 set_fs(oldfs);
66631 if (!err && old && put_compat_itimerspec(old, &oldts))
66632 return -EFAULT;
66633 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66634 oldfs = get_fs();
66635 set_fs(KERNEL_DS);
66636 err = sys_timer_gettime(timer_id,
66637 - (struct itimerspec __user *) &ts);
66638 + (struct itimerspec __force_user *) &ts);
66639 set_fs(oldfs);
66640 if (!err && put_compat_itimerspec(setting, &ts))
66641 return -EFAULT;
66642 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66643 oldfs = get_fs();
66644 set_fs(KERNEL_DS);
66645 err = sys_clock_settime(which_clock,
66646 - (struct timespec __user *) &ts);
66647 + (struct timespec __force_user *) &ts);
66648 set_fs(oldfs);
66649 return err;
66650 }
66651 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66652 oldfs = get_fs();
66653 set_fs(KERNEL_DS);
66654 err = sys_clock_gettime(which_clock,
66655 - (struct timespec __user *) &ts);
66656 + (struct timespec __force_user *) &ts);
66657 set_fs(oldfs);
66658 if (!err && put_compat_timespec(&ts, tp))
66659 return -EFAULT;
66660 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66661
66662 oldfs = get_fs();
66663 set_fs(KERNEL_DS);
66664 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66665 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66666 set_fs(oldfs);
66667
66668 err = compat_put_timex(utp, &txc);
66669 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66670 oldfs = get_fs();
66671 set_fs(KERNEL_DS);
66672 err = sys_clock_getres(which_clock,
66673 - (struct timespec __user *) &ts);
66674 + (struct timespec __force_user *) &ts);
66675 set_fs(oldfs);
66676 if (!err && tp && put_compat_timespec(&ts, tp))
66677 return -EFAULT;
66678 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66679 long err;
66680 mm_segment_t oldfs;
66681 struct timespec tu;
66682 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66683 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66684
66685 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66686 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66687 oldfs = get_fs();
66688 set_fs(KERNEL_DS);
66689 err = clock_nanosleep_restart(restart);
66690 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66691 oldfs = get_fs();
66692 set_fs(KERNEL_DS);
66693 err = sys_clock_nanosleep(which_clock, flags,
66694 - (struct timespec __user *) &in,
66695 - (struct timespec __user *) &out);
66696 + (struct timespec __force_user *) &in,
66697 + (struct timespec __force_user *) &out);
66698 set_fs(oldfs);
66699
66700 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66701 diff --git a/kernel/configs.c b/kernel/configs.c
66702 index 42e8fa0..9e7406b 100644
66703 --- a/kernel/configs.c
66704 +++ b/kernel/configs.c
66705 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66706 struct proc_dir_entry *entry;
66707
66708 /* create the current config file */
66709 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66710 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66711 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66712 + &ikconfig_file_ops);
66713 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66714 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66715 + &ikconfig_file_ops);
66716 +#endif
66717 +#else
66718 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66719 &ikconfig_file_ops);
66720 +#endif
66721 +
66722 if (!entry)
66723 return -ENOMEM;
66724
66725 diff --git a/kernel/cred.c b/kernel/cred.c
66726 index de728ac..e3c267c 100644
66727 --- a/kernel/cred.c
66728 +++ b/kernel/cred.c
66729 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66730 validate_creds(cred);
66731 alter_cred_subscribers(cred, -1);
66732 put_cred(cred);
66733 +
66734 +#ifdef CONFIG_GRKERNSEC_SETXID
66735 + cred = (struct cred *) tsk->delayed_cred;
66736 + if (cred != NULL) {
66737 + tsk->delayed_cred = NULL;
66738 + validate_creds(cred);
66739 + alter_cred_subscribers(cred, -1);
66740 + put_cred(cred);
66741 + }
66742 +#endif
66743 }
66744
66745 /**
66746 @@ -469,7 +479,7 @@ error_put:
66747 * Always returns 0 thus allowing this function to be tail-called at the end
66748 * of, say, sys_setgid().
66749 */
66750 -int commit_creds(struct cred *new)
66751 +static int __commit_creds(struct cred *new)
66752 {
66753 struct task_struct *task = current;
66754 const struct cred *old = task->real_cred;
66755 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66756
66757 get_cred(new); /* we will require a ref for the subj creds too */
66758
66759 + gr_set_role_label(task, new->uid, new->gid);
66760 +
66761 /* dumpability changes */
66762 if (!uid_eq(old->euid, new->euid) ||
66763 !gid_eq(old->egid, new->egid) ||
66764 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66765 put_cred(old);
66766 return 0;
66767 }
66768 +#ifdef CONFIG_GRKERNSEC_SETXID
66769 +extern int set_user(struct cred *new);
66770 +
66771 +void gr_delayed_cred_worker(void)
66772 +{
66773 + const struct cred *new = current->delayed_cred;
66774 + struct cred *ncred;
66775 +
66776 + current->delayed_cred = NULL;
66777 +
66778 + if (current_uid() && new != NULL) {
66779 + // from doing get_cred on it when queueing this
66780 + put_cred(new);
66781 + return;
66782 + } else if (new == NULL)
66783 + return;
66784 +
66785 + ncred = prepare_creds();
66786 + if (!ncred)
66787 + goto die;
66788 + // uids
66789 + ncred->uid = new->uid;
66790 + ncred->euid = new->euid;
66791 + ncred->suid = new->suid;
66792 + ncred->fsuid = new->fsuid;
66793 + // gids
66794 + ncred->gid = new->gid;
66795 + ncred->egid = new->egid;
66796 + ncred->sgid = new->sgid;
66797 + ncred->fsgid = new->fsgid;
66798 + // groups
66799 + if (set_groups(ncred, new->group_info) < 0) {
66800 + abort_creds(ncred);
66801 + goto die;
66802 + }
66803 + // caps
66804 + ncred->securebits = new->securebits;
66805 + ncred->cap_inheritable = new->cap_inheritable;
66806 + ncred->cap_permitted = new->cap_permitted;
66807 + ncred->cap_effective = new->cap_effective;
66808 + ncred->cap_bset = new->cap_bset;
66809 +
66810 + if (set_user(ncred)) {
66811 + abort_creds(ncred);
66812 + goto die;
66813 + }
66814 +
66815 + // from doing get_cred on it when queueing this
66816 + put_cred(new);
66817 +
66818 + __commit_creds(ncred);
66819 + return;
66820 +die:
66821 + // from doing get_cred on it when queueing this
66822 + put_cred(new);
66823 + do_group_exit(SIGKILL);
66824 +}
66825 +#endif
66826 +
66827 +int commit_creds(struct cred *new)
66828 +{
66829 +#ifdef CONFIG_GRKERNSEC_SETXID
66830 + int ret;
66831 + int schedule_it = 0;
66832 + struct task_struct *t;
66833 +
66834 + /* we won't get called with tasklist_lock held for writing
66835 + and interrupts disabled as the cred struct in that case is
66836 + init_cred
66837 + */
66838 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66839 + !current_uid() && new->uid) {
66840 + schedule_it = 1;
66841 + }
66842 + ret = __commit_creds(new);
66843 + if (schedule_it) {
66844 + rcu_read_lock();
66845 + read_lock(&tasklist_lock);
66846 + for (t = next_thread(current); t != current;
66847 + t = next_thread(t)) {
66848 + if (t->delayed_cred == NULL) {
66849 + t->delayed_cred = get_cred(new);
66850 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66851 + set_tsk_need_resched(t);
66852 + }
66853 + }
66854 + read_unlock(&tasklist_lock);
66855 + rcu_read_unlock();
66856 + }
66857 + return ret;
66858 +#else
66859 + return __commit_creds(new);
66860 +#endif
66861 +}
66862 +
66863 EXPORT_SYMBOL(commit_creds);
66864
66865 /**
66866 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66867 index 0557f24..1a00d9a 100644
66868 --- a/kernel/debug/debug_core.c
66869 +++ b/kernel/debug/debug_core.c
66870 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66871 */
66872 static atomic_t masters_in_kgdb;
66873 static atomic_t slaves_in_kgdb;
66874 -static atomic_t kgdb_break_tasklet_var;
66875 +static atomic_unchecked_t kgdb_break_tasklet_var;
66876 atomic_t kgdb_setting_breakpoint;
66877
66878 struct task_struct *kgdb_usethread;
66879 @@ -132,7 +132,7 @@ int kgdb_single_step;
66880 static pid_t kgdb_sstep_pid;
66881
66882 /* to keep track of the CPU which is doing the single stepping*/
66883 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66884 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66885
66886 /*
66887 * If you are debugging a problem where roundup (the collection of
66888 @@ -540,7 +540,7 @@ return_normal:
66889 * kernel will only try for the value of sstep_tries before
66890 * giving up and continuing on.
66891 */
66892 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66893 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66894 (kgdb_info[cpu].task &&
66895 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66896 atomic_set(&kgdb_active, -1);
66897 @@ -634,8 +634,8 @@ cpu_master_loop:
66898 }
66899
66900 kgdb_restore:
66901 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66902 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66903 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66904 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66905 if (kgdb_info[sstep_cpu].task)
66906 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66907 else
66908 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66909 static void kgdb_tasklet_bpt(unsigned long ing)
66910 {
66911 kgdb_breakpoint();
66912 - atomic_set(&kgdb_break_tasklet_var, 0);
66913 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66914 }
66915
66916 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66917
66918 void kgdb_schedule_breakpoint(void)
66919 {
66920 - if (atomic_read(&kgdb_break_tasklet_var) ||
66921 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66922 atomic_read(&kgdb_active) != -1 ||
66923 atomic_read(&kgdb_setting_breakpoint))
66924 return;
66925 - atomic_inc(&kgdb_break_tasklet_var);
66926 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66927 tasklet_schedule(&kgdb_tasklet_breakpoint);
66928 }
66929 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66930 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66931 index 31df170..bc98840 100644
66932 --- a/kernel/debug/kdb/kdb_main.c
66933 +++ b/kernel/debug/kdb/kdb_main.c
66934 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
66935 list_for_each_entry(mod, kdb_modules, list) {
66936
66937 kdb_printf("%-20s%8u 0x%p ", mod->name,
66938 - mod->core_size, (void *)mod);
66939 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66940 #ifdef CONFIG_MODULE_UNLOAD
66941 kdb_printf("%4ld ", module_refcount(mod));
66942 #endif
66943 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
66944 kdb_printf(" (Loading)");
66945 else
66946 kdb_printf(" (Live)");
66947 - kdb_printf(" 0x%p", mod->module_core);
66948 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66949
66950 #ifdef CONFIG_MODULE_UNLOAD
66951 {
66952 diff --git a/kernel/events/core.c b/kernel/events/core.c
66953 index 7fee567..8affa2c 100644
66954 --- a/kernel/events/core.c
66955 +++ b/kernel/events/core.c
66956 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66957 return 0;
66958 }
66959
66960 -static atomic64_t perf_event_id;
66961 +static atomic64_unchecked_t perf_event_id;
66962
66963 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66964 enum event_type_t event_type);
66965 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
66966
66967 static inline u64 perf_event_count(struct perf_event *event)
66968 {
66969 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66970 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66971 }
66972
66973 static u64 perf_event_read(struct perf_event *event)
66974 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66975 mutex_lock(&event->child_mutex);
66976 total += perf_event_read(event);
66977 *enabled += event->total_time_enabled +
66978 - atomic64_read(&event->child_total_time_enabled);
66979 + atomic64_read_unchecked(&event->child_total_time_enabled);
66980 *running += event->total_time_running +
66981 - atomic64_read(&event->child_total_time_running);
66982 + atomic64_read_unchecked(&event->child_total_time_running);
66983
66984 list_for_each_entry(child, &event->child_list, child_list) {
66985 total += perf_event_read(child);
66986 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
66987 userpg->offset -= local64_read(&event->hw.prev_count);
66988
66989 userpg->time_enabled = enabled +
66990 - atomic64_read(&event->child_total_time_enabled);
66991 + atomic64_read_unchecked(&event->child_total_time_enabled);
66992
66993 userpg->time_running = running +
66994 - atomic64_read(&event->child_total_time_running);
66995 + atomic64_read_unchecked(&event->child_total_time_running);
66996
66997 arch_perf_update_userpage(userpg, now);
66998
66999 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67000 values[n++] = perf_event_count(event);
67001 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67002 values[n++] = enabled +
67003 - atomic64_read(&event->child_total_time_enabled);
67004 + atomic64_read_unchecked(&event->child_total_time_enabled);
67005 }
67006 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67007 values[n++] = running +
67008 - atomic64_read(&event->child_total_time_running);
67009 + atomic64_read_unchecked(&event->child_total_time_running);
67010 }
67011 if (read_format & PERF_FORMAT_ID)
67012 values[n++] = primary_event_id(event);
67013 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67014 * need to add enough zero bytes after the string to handle
67015 * the 64bit alignment we do later.
67016 */
67017 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67018 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67019 if (!buf) {
67020 name = strncpy(tmp, "//enomem", sizeof(tmp));
67021 goto got_name;
67022 }
67023 - name = d_path(&file->f_path, buf, PATH_MAX);
67024 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67025 if (IS_ERR(name)) {
67026 name = strncpy(tmp, "//toolong", sizeof(tmp));
67027 goto got_name;
67028 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67029 event->parent = parent_event;
67030
67031 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67032 - event->id = atomic64_inc_return(&perf_event_id);
67033 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67034
67035 event->state = PERF_EVENT_STATE_INACTIVE;
67036
67037 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67038 /*
67039 * Add back the child's count to the parent's count:
67040 */
67041 - atomic64_add(child_val, &parent_event->child_count);
67042 - atomic64_add(child_event->total_time_enabled,
67043 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67044 + atomic64_add_unchecked(child_event->total_time_enabled,
67045 &parent_event->child_total_time_enabled);
67046 - atomic64_add(child_event->total_time_running,
67047 + atomic64_add_unchecked(child_event->total_time_running,
67048 &parent_event->child_total_time_running);
67049
67050 /*
67051 diff --git a/kernel/exit.c b/kernel/exit.c
67052 index f65345f9..9c28dab 100644
67053 --- a/kernel/exit.c
67054 +++ b/kernel/exit.c
67055 @@ -59,6 +59,10 @@
67056 #include <asm/pgtable.h>
67057 #include <asm/mmu_context.h>
67058
67059 +#ifdef CONFIG_GRKERNSEC
67060 +extern rwlock_t grsec_exec_file_lock;
67061 +#endif
67062 +
67063 static void exit_mm(struct task_struct * tsk);
67064
67065 static void __unhash_process(struct task_struct *p, bool group_dead)
67066 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67067 struct task_struct *leader;
67068 int zap_leader;
67069 repeat:
67070 +#ifdef CONFIG_NET
67071 + gr_del_task_from_ip_table(p);
67072 +#endif
67073 +
67074 /* don't need to get the RCU readlock here - the process is dead and
67075 * can't be modifying its own credentials. But shut RCU-lockdep up */
67076 rcu_read_lock();
67077 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67078 * know it'll be handled, so that they don't get converted to
67079 * SIGKILL or just silently dropped.
67080 */
67081 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67082 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67083 recalc_sigpending();
67084 spin_unlock_irq(&current->sighand->siglock);
67085 return 0;
67086 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67087 vsnprintf(current->comm, sizeof(current->comm), name, args);
67088 va_end(args);
67089
67090 +#ifdef CONFIG_GRKERNSEC
67091 + write_lock(&grsec_exec_file_lock);
67092 + if (current->exec_file) {
67093 + fput(current->exec_file);
67094 + current->exec_file = NULL;
67095 + }
67096 + write_unlock(&grsec_exec_file_lock);
67097 +#endif
67098 +
67099 + gr_set_kernel_label(current);
67100 +
67101 /*
67102 * If we were started as result of loading a module, close all of the
67103 * user space pages. We don't need them, and if we didn't close them
67104 @@ -907,6 +926,8 @@ void do_exit(long code)
67105 struct task_struct *tsk = current;
67106 int group_dead;
67107
67108 + set_fs(USER_DS);
67109 +
67110 profile_task_exit(tsk);
67111
67112 WARN_ON(blk_needs_flush_plug(tsk));
67113 @@ -923,7 +944,6 @@ void do_exit(long code)
67114 * mm_release()->clear_child_tid() from writing to a user-controlled
67115 * kernel address.
67116 */
67117 - set_fs(USER_DS);
67118
67119 ptrace_event(PTRACE_EVENT_EXIT, code);
67120
67121 @@ -982,6 +1002,9 @@ void do_exit(long code)
67122 tsk->exit_code = code;
67123 taskstats_exit(tsk, group_dead);
67124
67125 + gr_acl_handle_psacct(tsk, code);
67126 + gr_acl_handle_exit();
67127 +
67128 exit_mm(tsk);
67129
67130 if (group_dead)
67131 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67132 * Take down every thread in the group. This is called by fatal signals
67133 * as well as by sys_exit_group (below).
67134 */
67135 -void
67136 +__noreturn void
67137 do_group_exit(int exit_code)
67138 {
67139 struct signal_struct *sig = current->signal;
67140 diff --git a/kernel/fork.c b/kernel/fork.c
67141 index 2c8857e..288c9c7 100644
67142 --- a/kernel/fork.c
67143 +++ b/kernel/fork.c
67144 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67145 *stackend = STACK_END_MAGIC; /* for overflow detection */
67146
67147 #ifdef CONFIG_CC_STACKPROTECTOR
67148 - tsk->stack_canary = get_random_int();
67149 + tsk->stack_canary = pax_get_random_long();
67150 #endif
67151
67152 /*
67153 @@ -343,13 +343,78 @@ free_tsk:
67154 }
67155
67156 #ifdef CONFIG_MMU
67157 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67158 +{
67159 + struct vm_area_struct *tmp;
67160 + unsigned long charge;
67161 + struct mempolicy *pol;
67162 + struct file *file;
67163 +
67164 + charge = 0;
67165 + if (mpnt->vm_flags & VM_ACCOUNT) {
67166 + unsigned long len = vma_pages(mpnt);
67167 +
67168 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67169 + goto fail_nomem;
67170 + charge = len;
67171 + }
67172 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67173 + if (!tmp)
67174 + goto fail_nomem;
67175 + *tmp = *mpnt;
67176 + tmp->vm_mm = mm;
67177 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67178 + pol = mpol_dup(vma_policy(mpnt));
67179 + if (IS_ERR(pol))
67180 + goto fail_nomem_policy;
67181 + vma_set_policy(tmp, pol);
67182 + if (anon_vma_fork(tmp, mpnt))
67183 + goto fail_nomem_anon_vma_fork;
67184 + tmp->vm_flags &= ~VM_LOCKED;
67185 + tmp->vm_next = tmp->vm_prev = NULL;
67186 + tmp->vm_mirror = NULL;
67187 + file = tmp->vm_file;
67188 + if (file) {
67189 + struct inode *inode = file->f_path.dentry->d_inode;
67190 + struct address_space *mapping = file->f_mapping;
67191 +
67192 + get_file(file);
67193 + if (tmp->vm_flags & VM_DENYWRITE)
67194 + atomic_dec(&inode->i_writecount);
67195 + mutex_lock(&mapping->i_mmap_mutex);
67196 + if (tmp->vm_flags & VM_SHARED)
67197 + mapping->i_mmap_writable++;
67198 + flush_dcache_mmap_lock(mapping);
67199 + /* insert tmp into the share list, just after mpnt */
67200 + vma_prio_tree_add(tmp, mpnt);
67201 + flush_dcache_mmap_unlock(mapping);
67202 + mutex_unlock(&mapping->i_mmap_mutex);
67203 + }
67204 +
67205 + /*
67206 + * Clear hugetlb-related page reserves for children. This only
67207 + * affects MAP_PRIVATE mappings. Faults generated by the child
67208 + * are not guaranteed to succeed, even if read-only
67209 + */
67210 + if (is_vm_hugetlb_page(tmp))
67211 + reset_vma_resv_huge_pages(tmp);
67212 +
67213 + return tmp;
67214 +
67215 +fail_nomem_anon_vma_fork:
67216 + mpol_put(pol);
67217 +fail_nomem_policy:
67218 + kmem_cache_free(vm_area_cachep, tmp);
67219 +fail_nomem:
67220 + vm_unacct_memory(charge);
67221 + return NULL;
67222 +}
67223 +
67224 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67225 {
67226 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67227 struct rb_node **rb_link, *rb_parent;
67228 int retval;
67229 - unsigned long charge;
67230 - struct mempolicy *pol;
67231
67232 down_write(&oldmm->mmap_sem);
67233 flush_cache_dup_mm(oldmm);
67234 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67235 mm->locked_vm = 0;
67236 mm->mmap = NULL;
67237 mm->mmap_cache = NULL;
67238 - mm->free_area_cache = oldmm->mmap_base;
67239 - mm->cached_hole_size = ~0UL;
67240 + mm->free_area_cache = oldmm->free_area_cache;
67241 + mm->cached_hole_size = oldmm->cached_hole_size;
67242 mm->map_count = 0;
67243 cpumask_clear(mm_cpumask(mm));
67244 mm->mm_rb = RB_ROOT;
67245 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67246
67247 prev = NULL;
67248 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67249 - struct file *file;
67250 -
67251 if (mpnt->vm_flags & VM_DONTCOPY) {
67252 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67253 -vma_pages(mpnt));
67254 continue;
67255 }
67256 - charge = 0;
67257 - if (mpnt->vm_flags & VM_ACCOUNT) {
67258 - unsigned long len = vma_pages(mpnt);
67259 -
67260 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67261 - goto fail_nomem;
67262 - charge = len;
67263 - }
67264 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67265 - if (!tmp)
67266 - goto fail_nomem;
67267 - *tmp = *mpnt;
67268 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67269 - pol = mpol_dup(vma_policy(mpnt));
67270 - retval = PTR_ERR(pol);
67271 - if (IS_ERR(pol))
67272 - goto fail_nomem_policy;
67273 - vma_set_policy(tmp, pol);
67274 - tmp->vm_mm = mm;
67275 - if (anon_vma_fork(tmp, mpnt))
67276 - goto fail_nomem_anon_vma_fork;
67277 - tmp->vm_flags &= ~VM_LOCKED;
67278 - tmp->vm_next = tmp->vm_prev = NULL;
67279 - file = tmp->vm_file;
67280 - if (file) {
67281 - struct inode *inode = file->f_path.dentry->d_inode;
67282 - struct address_space *mapping = file->f_mapping;
67283 -
67284 - get_file(file);
67285 - if (tmp->vm_flags & VM_DENYWRITE)
67286 - atomic_dec(&inode->i_writecount);
67287 - mutex_lock(&mapping->i_mmap_mutex);
67288 - if (tmp->vm_flags & VM_SHARED)
67289 - mapping->i_mmap_writable++;
67290 - flush_dcache_mmap_lock(mapping);
67291 - /* insert tmp into the share list, just after mpnt */
67292 - vma_prio_tree_add(tmp, mpnt);
67293 - flush_dcache_mmap_unlock(mapping);
67294 - mutex_unlock(&mapping->i_mmap_mutex);
67295 + tmp = dup_vma(mm, oldmm, mpnt);
67296 + if (!tmp) {
67297 + retval = -ENOMEM;
67298 + goto out;
67299 }
67300
67301 /*
67302 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67303 if (retval)
67304 goto out;
67305
67306 - if (file)
67307 + if (tmp->vm_file)
67308 uprobe_mmap(tmp);
67309 }
67310 +
67311 +#ifdef CONFIG_PAX_SEGMEXEC
67312 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67313 + struct vm_area_struct *mpnt_m;
67314 +
67315 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67316 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67317 +
67318 + if (!mpnt->vm_mirror)
67319 + continue;
67320 +
67321 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67322 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67323 + mpnt->vm_mirror = mpnt_m;
67324 + } else {
67325 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67326 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67327 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67328 + mpnt->vm_mirror->vm_mirror = mpnt;
67329 + }
67330 + }
67331 + BUG_ON(mpnt_m);
67332 + }
67333 +#endif
67334 +
67335 /* a new mm has just been created */
67336 arch_dup_mmap(oldmm, mm);
67337 retval = 0;
67338 @@ -466,14 +519,6 @@ out:
67339 flush_tlb_mm(oldmm);
67340 up_write(&oldmm->mmap_sem);
67341 return retval;
67342 -fail_nomem_anon_vma_fork:
67343 - mpol_put(pol);
67344 -fail_nomem_policy:
67345 - kmem_cache_free(vm_area_cachep, tmp);
67346 -fail_nomem:
67347 - retval = -ENOMEM;
67348 - vm_unacct_memory(charge);
67349 - goto out;
67350 }
67351
67352 static inline int mm_alloc_pgd(struct mm_struct *mm)
67353 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67354 return ERR_PTR(err);
67355
67356 mm = get_task_mm(task);
67357 - if (mm && mm != current->mm &&
67358 - !ptrace_may_access(task, mode)) {
67359 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67360 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67361 mmput(mm);
67362 mm = ERR_PTR(-EACCES);
67363 }
67364 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67365 spin_unlock(&fs->lock);
67366 return -EAGAIN;
67367 }
67368 - fs->users++;
67369 + atomic_inc(&fs->users);
67370 spin_unlock(&fs->lock);
67371 return 0;
67372 }
67373 tsk->fs = copy_fs_struct(fs);
67374 if (!tsk->fs)
67375 return -ENOMEM;
67376 + /* Carry through gr_chroot_dentry and is_chrooted instead
67377 + of recomputing it here. Already copied when the task struct
67378 + is duplicated. This allows pivot_root to not be treated as
67379 + a chroot
67380 + */
67381 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67382 +
67383 return 0;
67384 }
67385
67386 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67387 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67388 #endif
67389 retval = -EAGAIN;
67390 +
67391 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67392 +
67393 if (atomic_read(&p->real_cred->user->processes) >=
67394 task_rlimit(p, RLIMIT_NPROC)) {
67395 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67396 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67397 /* Need tasklist lock for parent etc handling! */
67398 write_lock_irq(&tasklist_lock);
67399
67400 + /* synchronizes with gr_set_acls() */
67401 + gr_copy_label(p);
67402 +
67403 /* CLONE_PARENT re-uses the old parent */
67404 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67405 p->real_parent = current->real_parent;
67406 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67407 bad_fork_free:
67408 free_task(p);
67409 fork_out:
67410 + gr_log_forkfail(retval);
67411 +
67412 return ERR_PTR(retval);
67413 }
67414
67415 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67416 if (clone_flags & CLONE_PARENT_SETTID)
67417 put_user(nr, parent_tidptr);
67418
67419 + gr_handle_brute_check();
67420 +
67421 if (clone_flags & CLONE_VFORK) {
67422 p->vfork_done = &vfork;
67423 init_completion(&vfork);
67424 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67425 return 0;
67426
67427 /* don't need lock here; in the worst case we'll do useless copy */
67428 - if (fs->users == 1)
67429 + if (atomic_read(&fs->users) == 1)
67430 return 0;
67431
67432 *new_fsp = copy_fs_struct(fs);
67433 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67434 fs = current->fs;
67435 spin_lock(&fs->lock);
67436 current->fs = new_fs;
67437 - if (--fs->users)
67438 + gr_set_chroot_entries(current, &current->fs->root);
67439 + if (atomic_dec_return(&fs->users))
67440 new_fs = NULL;
67441 else
67442 new_fs = fs;
67443 diff --git a/kernel/futex.c b/kernel/futex.c
67444 index 3717e7b..473c750 100644
67445 --- a/kernel/futex.c
67446 +++ b/kernel/futex.c
67447 @@ -54,6 +54,7 @@
67448 #include <linux/mount.h>
67449 #include <linux/pagemap.h>
67450 #include <linux/syscalls.h>
67451 +#include <linux/ptrace.h>
67452 #include <linux/signal.h>
67453 #include <linux/export.h>
67454 #include <linux/magic.h>
67455 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67456 struct page *page, *page_head;
67457 int err, ro = 0;
67458
67459 +#ifdef CONFIG_PAX_SEGMEXEC
67460 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67461 + return -EFAULT;
67462 +#endif
67463 +
67464 /*
67465 * The futex address must be "naturally" aligned.
67466 */
67467 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67468 {
67469 u32 curval;
67470 int i;
67471 + mm_segment_t oldfs;
67472
67473 /*
67474 * This will fail and we want it. Some arch implementations do
67475 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67476 * implementation, the non-functional ones will return
67477 * -ENOSYS.
67478 */
67479 + oldfs = get_fs();
67480 + set_fs(USER_DS);
67481 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67482 futex_cmpxchg_enabled = 1;
67483 + set_fs(oldfs);
67484
67485 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67486 plist_head_init(&futex_queues[i].chain);
67487 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67488 index 9b22d03..6295b62 100644
67489 --- a/kernel/gcov/base.c
67490 +++ b/kernel/gcov/base.c
67491 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67492 }
67493
67494 #ifdef CONFIG_MODULES
67495 -static inline int within(void *addr, void *start, unsigned long size)
67496 -{
67497 - return ((addr >= start) && (addr < start + size));
67498 -}
67499 -
67500 /* Update list and generate events when modules are unloaded. */
67501 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67502 void *data)
67503 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67504 prev = NULL;
67505 /* Remove entries located in module from linked list. */
67506 for (info = gcov_info_head; info; info = info->next) {
67507 - if (within(info, mod->module_core, mod->core_size)) {
67508 + if (within_module_core_rw((unsigned long)info, mod)) {
67509 if (prev)
67510 prev->next = info->next;
67511 else
67512 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67513 index 6db7a5e..25b6648 100644
67514 --- a/kernel/hrtimer.c
67515 +++ b/kernel/hrtimer.c
67516 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67517 local_irq_restore(flags);
67518 }
67519
67520 -static void run_hrtimer_softirq(struct softirq_action *h)
67521 +static void run_hrtimer_softirq(void)
67522 {
67523 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67524
67525 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67526 index 4304919..408c4c0 100644
67527 --- a/kernel/jump_label.c
67528 +++ b/kernel/jump_label.c
67529 @@ -13,6 +13,7 @@
67530 #include <linux/sort.h>
67531 #include <linux/err.h>
67532 #include <linux/static_key.h>
67533 +#include <linux/mm.h>
67534
67535 #ifdef HAVE_JUMP_LABEL
67536
67537 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67538
67539 size = (((unsigned long)stop - (unsigned long)start)
67540 / sizeof(struct jump_entry));
67541 + pax_open_kernel();
67542 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67543 + pax_close_kernel();
67544 }
67545
67546 static void jump_label_update(struct static_key *key, int enable);
67547 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67548 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67549 struct jump_entry *iter;
67550
67551 + pax_open_kernel();
67552 for (iter = iter_start; iter < iter_stop; iter++) {
67553 if (within_module_init(iter->code, mod))
67554 iter->code = 0;
67555 }
67556 + pax_close_kernel();
67557 }
67558
67559 static int
67560 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67561 index 2169fee..45c017a 100644
67562 --- a/kernel/kallsyms.c
67563 +++ b/kernel/kallsyms.c
67564 @@ -11,6 +11,9 @@
67565 * Changed the compression method from stem compression to "table lookup"
67566 * compression (see scripts/kallsyms.c for a more complete description)
67567 */
67568 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67569 +#define __INCLUDED_BY_HIDESYM 1
67570 +#endif
67571 #include <linux/kallsyms.h>
67572 #include <linux/module.h>
67573 #include <linux/init.h>
67574 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67575
67576 static inline int is_kernel_inittext(unsigned long addr)
67577 {
67578 + if (system_state != SYSTEM_BOOTING)
67579 + return 0;
67580 +
67581 if (addr >= (unsigned long)_sinittext
67582 && addr <= (unsigned long)_einittext)
67583 return 1;
67584 return 0;
67585 }
67586
67587 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67588 +#ifdef CONFIG_MODULES
67589 +static inline int is_module_text(unsigned long addr)
67590 +{
67591 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67592 + return 1;
67593 +
67594 + addr = ktla_ktva(addr);
67595 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67596 +}
67597 +#else
67598 +static inline int is_module_text(unsigned long addr)
67599 +{
67600 + return 0;
67601 +}
67602 +#endif
67603 +#endif
67604 +
67605 static inline int is_kernel_text(unsigned long addr)
67606 {
67607 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67608 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67609
67610 static inline int is_kernel(unsigned long addr)
67611 {
67612 +
67613 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67614 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67615 + return 1;
67616 +
67617 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67618 +#else
67619 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67620 +#endif
67621 +
67622 return 1;
67623 return in_gate_area_no_mm(addr);
67624 }
67625
67626 static int is_ksym_addr(unsigned long addr)
67627 {
67628 +
67629 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67630 + if (is_module_text(addr))
67631 + return 0;
67632 +#endif
67633 +
67634 if (all_var)
67635 return is_kernel(addr);
67636
67637 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67638
67639 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67640 {
67641 - iter->name[0] = '\0';
67642 iter->nameoff = get_symbol_offset(new_pos);
67643 iter->pos = new_pos;
67644 }
67645 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67646 {
67647 struct kallsym_iter *iter = m->private;
67648
67649 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67650 + if (current_uid())
67651 + return 0;
67652 +#endif
67653 +
67654 /* Some debugging symbols have no name. Ignore them. */
67655 if (!iter->name[0])
67656 return 0;
67657 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67658 */
67659 type = iter->exported ? toupper(iter->type) :
67660 tolower(iter->type);
67661 +
67662 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67663 type, iter->name, iter->module_name);
67664 } else
67665 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67666 struct kallsym_iter *iter;
67667 int ret;
67668
67669 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67670 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67671 if (!iter)
67672 return -ENOMEM;
67673 reset_iter(iter, 0);
67674 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67675 index 30b7b22..c726387 100644
67676 --- a/kernel/kcmp.c
67677 +++ b/kernel/kcmp.c
67678 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67679 struct task_struct *task1, *task2;
67680 int ret;
67681
67682 +#ifdef CONFIG_GRKERNSEC
67683 + return -ENOSYS;
67684 +#endif
67685 +
67686 rcu_read_lock();
67687
67688 /*
67689 diff --git a/kernel/kexec.c b/kernel/kexec.c
67690 index 0668d58..591b6fc 100644
67691 --- a/kernel/kexec.c
67692 +++ b/kernel/kexec.c
67693 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67694 unsigned long flags)
67695 {
67696 struct compat_kexec_segment in;
67697 - struct kexec_segment out, __user *ksegments;
67698 + struct kexec_segment out;
67699 + struct kexec_segment __user *ksegments;
67700 unsigned long i, result;
67701
67702 /* Don't allow clients that don't understand the native
67703 diff --git a/kernel/kmod.c b/kernel/kmod.c
67704 index 6f99aea..eb6e3a0 100644
67705 --- a/kernel/kmod.c
67706 +++ b/kernel/kmod.c
67707 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67708 kfree(info->argv);
67709 }
67710
67711 -static int call_modprobe(char *module_name, int wait)
67712 +static int call_modprobe(char *module_name, char *module_param, int wait)
67713 {
67714 static char *envp[] = {
67715 "HOME=/",
67716 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67717 NULL
67718 };
67719
67720 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67721 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67722 if (!argv)
67723 goto out;
67724
67725 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67726 argv[1] = "-q";
67727 argv[2] = "--";
67728 argv[3] = module_name; /* check free_modprobe_argv() */
67729 - argv[4] = NULL;
67730 + argv[4] = module_param;
67731 + argv[5] = NULL;
67732
67733 return call_usermodehelper_fns(modprobe_path, argv, envp,
67734 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67735 @@ -119,9 +120,8 @@ out:
67736 * If module auto-loading support is disabled then this function
67737 * becomes a no-operation.
67738 */
67739 -int __request_module(bool wait, const char *fmt, ...)
67740 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67741 {
67742 - va_list args;
67743 char module_name[MODULE_NAME_LEN];
67744 unsigned int max_modprobes;
67745 int ret;
67746 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67747 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67748 static int kmod_loop_msg;
67749
67750 - va_start(args, fmt);
67751 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67752 - va_end(args);
67753 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67754 if (ret >= MODULE_NAME_LEN)
67755 return -ENAMETOOLONG;
67756
67757 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67758 if (ret)
67759 return ret;
67760
67761 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67762 + if (!current_uid()) {
67763 + /* hack to workaround consolekit/udisks stupidity */
67764 + read_lock(&tasklist_lock);
67765 + if (!strcmp(current->comm, "mount") &&
67766 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67767 + read_unlock(&tasklist_lock);
67768 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67769 + return -EPERM;
67770 + }
67771 + read_unlock(&tasklist_lock);
67772 + }
67773 +#endif
67774 +
67775 /* If modprobe needs a service that is in a module, we get a recursive
67776 * loop. Limit the number of running kmod threads to max_threads/2 or
67777 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67778 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67779
67780 trace_module_request(module_name, wait, _RET_IP_);
67781
67782 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67783 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67784
67785 atomic_dec(&kmod_concurrent);
67786 return ret;
67787 }
67788 +
67789 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67790 +{
67791 + va_list args;
67792 + int ret;
67793 +
67794 + va_start(args, fmt);
67795 + ret = ____request_module(wait, module_param, fmt, args);
67796 + va_end(args);
67797 +
67798 + return ret;
67799 +}
67800 +
67801 +int __request_module(bool wait, const char *fmt, ...)
67802 +{
67803 + va_list args;
67804 + int ret;
67805 +
67806 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67807 + if (current_uid()) {
67808 + char module_param[MODULE_NAME_LEN];
67809 +
67810 + memset(module_param, 0, sizeof(module_param));
67811 +
67812 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67813 +
67814 + va_start(args, fmt);
67815 + ret = ____request_module(wait, module_param, fmt, args);
67816 + va_end(args);
67817 +
67818 + return ret;
67819 + }
67820 +#endif
67821 +
67822 + va_start(args, fmt);
67823 + ret = ____request_module(wait, NULL, fmt, args);
67824 + va_end(args);
67825 +
67826 + return ret;
67827 +}
67828 +
67829 EXPORT_SYMBOL(__request_module);
67830 #endif /* CONFIG_MODULES */
67831
67832 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
67833 *
67834 * Thus the __user pointer cast is valid here.
67835 */
67836 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67837 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67838
67839 /*
67840 * If ret is 0, either ____call_usermodehelper failed and the
67841 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67842 index c62b854..6fc810d 100644
67843 --- a/kernel/kprobes.c
67844 +++ b/kernel/kprobes.c
67845 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67846 * kernel image and loaded module images reside. This is required
67847 * so x86_64 can correctly handle the %rip-relative fixups.
67848 */
67849 - kip->insns = module_alloc(PAGE_SIZE);
67850 + kip->insns = module_alloc_exec(PAGE_SIZE);
67851 if (!kip->insns) {
67852 kfree(kip);
67853 return NULL;
67854 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67855 */
67856 if (!list_is_singular(&kip->list)) {
67857 list_del(&kip->list);
67858 - module_free(NULL, kip->insns);
67859 + module_free_exec(NULL, kip->insns);
67860 kfree(kip);
67861 }
67862 return 1;
67863 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67864 {
67865 int i, err = 0;
67866 unsigned long offset = 0, size = 0;
67867 - char *modname, namebuf[128];
67868 + char *modname, namebuf[KSYM_NAME_LEN];
67869 const char *symbol_name;
67870 void *addr;
67871 struct kprobe_blackpoint *kb;
67872 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
67873 kprobe_type = "k";
67874
67875 if (sym)
67876 - seq_printf(pi, "%p %s %s+0x%x %s ",
67877 + seq_printf(pi, "%pK %s %s+0x%x %s ",
67878 p->addr, kprobe_type, sym, offset,
67879 (modname ? modname : " "));
67880 else
67881 - seq_printf(pi, "%p %s %p ",
67882 + seq_printf(pi, "%pK %s %pK ",
67883 p->addr, kprobe_type, p->addr);
67884
67885 if (!pp)
67886 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67887 const char *sym = NULL;
67888 unsigned int i = *(loff_t *) v;
67889 unsigned long offset = 0;
67890 - char *modname, namebuf[128];
67891 + char *modname, namebuf[KSYM_NAME_LEN];
67892
67893 head = &kprobe_table[i];
67894 preempt_disable();
67895 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67896 index 4e316e1..5501eef 100644
67897 --- a/kernel/ksysfs.c
67898 +++ b/kernel/ksysfs.c
67899 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67900 {
67901 if (count+1 > UEVENT_HELPER_PATH_LEN)
67902 return -ENOENT;
67903 + if (!capable(CAP_SYS_ADMIN))
67904 + return -EPERM;
67905 memcpy(uevent_helper, buf, count);
67906 uevent_helper[count] = '\0';
67907 if (count && uevent_helper[count-1] == '\n')
67908 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67909 index ea9ee45..67ebc8f 100644
67910 --- a/kernel/lockdep.c
67911 +++ b/kernel/lockdep.c
67912 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67913 end = (unsigned long) &_end,
67914 addr = (unsigned long) obj;
67915
67916 +#ifdef CONFIG_PAX_KERNEXEC
67917 + start = ktla_ktva(start);
67918 +#endif
67919 +
67920 /*
67921 * static variable?
67922 */
67923 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67924 if (!static_obj(lock->key)) {
67925 debug_locks_off();
67926 printk("INFO: trying to register non-static key.\n");
67927 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67928 printk("the code is fine but needs lockdep annotation.\n");
67929 printk("turning off the locking correctness validator.\n");
67930 dump_stack();
67931 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67932 if (!class)
67933 return 0;
67934 }
67935 - atomic_inc((atomic_t *)&class->ops);
67936 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67937 if (very_verbose(class)) {
67938 printk("\nacquire class [%p] %s", class->key, class->name);
67939 if (class->name_version > 1)
67940 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67941 index 91c32a0..7b88d63 100644
67942 --- a/kernel/lockdep_proc.c
67943 +++ b/kernel/lockdep_proc.c
67944 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67945
67946 static void print_name(struct seq_file *m, struct lock_class *class)
67947 {
67948 - char str[128];
67949 + char str[KSYM_NAME_LEN];
67950 const char *name = class->name;
67951
67952 if (!name) {
67953 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
67954 return 0;
67955 }
67956
67957 - seq_printf(m, "%p", class->key);
67958 + seq_printf(m, "%pK", class->key);
67959 #ifdef CONFIG_DEBUG_LOCKDEP
67960 seq_printf(m, " OPS:%8ld", class->ops);
67961 #endif
67962 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
67963
67964 list_for_each_entry(entry, &class->locks_after, entry) {
67965 if (entry->distance == 1) {
67966 - seq_printf(m, " -> [%p] ", entry->class->key);
67967 + seq_printf(m, " -> [%pK] ", entry->class->key);
67968 print_name(m, entry->class);
67969 seq_puts(m, "\n");
67970 }
67971 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
67972 if (!class->key)
67973 continue;
67974
67975 - seq_printf(m, "[%p] ", class->key);
67976 + seq_printf(m, "[%pK] ", class->key);
67977 print_name(m, class);
67978 seq_puts(m, "\n");
67979 }
67980 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67981 if (!i)
67982 seq_line(m, '-', 40-namelen, namelen);
67983
67984 - snprintf(ip, sizeof(ip), "[<%p>]",
67985 + snprintf(ip, sizeof(ip), "[<%pK>]",
67986 (void *)class->contention_point[i]);
67987 seq_printf(m, "%40s %14lu %29s %pS\n",
67988 name, stats->contention_point[i],
67989 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67990 if (!i)
67991 seq_line(m, '-', 40-namelen, namelen);
67992
67993 - snprintf(ip, sizeof(ip), "[<%p>]",
67994 + snprintf(ip, sizeof(ip), "[<%pK>]",
67995 (void *)class->contending_point[i]);
67996 seq_printf(m, "%40s %14lu %29s %pS\n",
67997 name, stats->contending_point[i],
67998 diff --git a/kernel/module.c b/kernel/module.c
67999 index 9ad9ee9..de7a157 100644
68000 --- a/kernel/module.c
68001 +++ b/kernel/module.c
68002 @@ -58,6 +58,7 @@
68003 #include <linux/jump_label.h>
68004 #include <linux/pfn.h>
68005 #include <linux/bsearch.h>
68006 +#include <linux/grsecurity.h>
68007
68008 #define CREATE_TRACE_POINTS
68009 #include <trace/events/module.h>
68010 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68011
68012 /* Bounds of module allocation, for speeding __module_address.
68013 * Protected by module_mutex. */
68014 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68015 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68016 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68017
68018 int register_module_notifier(struct notifier_block * nb)
68019 {
68020 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68021 return true;
68022
68023 list_for_each_entry_rcu(mod, &modules, list) {
68024 - struct symsearch arr[] = {
68025 + struct symsearch modarr[] = {
68026 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68027 NOT_GPL_ONLY, false },
68028 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68029 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68030 #endif
68031 };
68032
68033 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68034 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68035 return true;
68036 }
68037 return false;
68038 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68039 static int percpu_modalloc(struct module *mod,
68040 unsigned long size, unsigned long align)
68041 {
68042 - if (align > PAGE_SIZE) {
68043 + if (align-1 >= PAGE_SIZE) {
68044 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68045 mod->name, align, PAGE_SIZE);
68046 align = PAGE_SIZE;
68047 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68048 static ssize_t show_coresize(struct module_attribute *mattr,
68049 struct module_kobject *mk, char *buffer)
68050 {
68051 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68052 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68053 }
68054
68055 static struct module_attribute modinfo_coresize =
68056 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68057 static ssize_t show_initsize(struct module_attribute *mattr,
68058 struct module_kobject *mk, char *buffer)
68059 {
68060 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68061 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68062 }
68063
68064 static struct module_attribute modinfo_initsize =
68065 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68066 */
68067 #ifdef CONFIG_SYSFS
68068
68069 -#ifdef CONFIG_KALLSYMS
68070 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68071 static inline bool sect_empty(const Elf_Shdr *sect)
68072 {
68073 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68074 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68075
68076 static void unset_module_core_ro_nx(struct module *mod)
68077 {
68078 - set_page_attributes(mod->module_core + mod->core_text_size,
68079 - mod->module_core + mod->core_size,
68080 + set_page_attributes(mod->module_core_rw,
68081 + mod->module_core_rw + mod->core_size_rw,
68082 set_memory_x);
68083 - set_page_attributes(mod->module_core,
68084 - mod->module_core + mod->core_ro_size,
68085 + set_page_attributes(mod->module_core_rx,
68086 + mod->module_core_rx + mod->core_size_rx,
68087 set_memory_rw);
68088 }
68089
68090 static void unset_module_init_ro_nx(struct module *mod)
68091 {
68092 - set_page_attributes(mod->module_init + mod->init_text_size,
68093 - mod->module_init + mod->init_size,
68094 + set_page_attributes(mod->module_init_rw,
68095 + mod->module_init_rw + mod->init_size_rw,
68096 set_memory_x);
68097 - set_page_attributes(mod->module_init,
68098 - mod->module_init + mod->init_ro_size,
68099 + set_page_attributes(mod->module_init_rx,
68100 + mod->module_init_rx + mod->init_size_rx,
68101 set_memory_rw);
68102 }
68103
68104 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68105
68106 mutex_lock(&module_mutex);
68107 list_for_each_entry_rcu(mod, &modules, list) {
68108 - if ((mod->module_core) && (mod->core_text_size)) {
68109 - set_page_attributes(mod->module_core,
68110 - mod->module_core + mod->core_text_size,
68111 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68112 + set_page_attributes(mod->module_core_rx,
68113 + mod->module_core_rx + mod->core_size_rx,
68114 set_memory_rw);
68115 }
68116 - if ((mod->module_init) && (mod->init_text_size)) {
68117 - set_page_attributes(mod->module_init,
68118 - mod->module_init + mod->init_text_size,
68119 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68120 + set_page_attributes(mod->module_init_rx,
68121 + mod->module_init_rx + mod->init_size_rx,
68122 set_memory_rw);
68123 }
68124 }
68125 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68126
68127 mutex_lock(&module_mutex);
68128 list_for_each_entry_rcu(mod, &modules, list) {
68129 - if ((mod->module_core) && (mod->core_text_size)) {
68130 - set_page_attributes(mod->module_core,
68131 - mod->module_core + mod->core_text_size,
68132 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68133 + set_page_attributes(mod->module_core_rx,
68134 + mod->module_core_rx + mod->core_size_rx,
68135 set_memory_ro);
68136 }
68137 - if ((mod->module_init) && (mod->init_text_size)) {
68138 - set_page_attributes(mod->module_init,
68139 - mod->module_init + mod->init_text_size,
68140 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68141 + set_page_attributes(mod->module_init_rx,
68142 + mod->module_init_rx + mod->init_size_rx,
68143 set_memory_ro);
68144 }
68145 }
68146 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68147
68148 /* This may be NULL, but that's OK */
68149 unset_module_init_ro_nx(mod);
68150 - module_free(mod, mod->module_init);
68151 + module_free(mod, mod->module_init_rw);
68152 + module_free_exec(mod, mod->module_init_rx);
68153 kfree(mod->args);
68154 percpu_modfree(mod);
68155
68156 /* Free lock-classes: */
68157 - lockdep_free_key_range(mod->module_core, mod->core_size);
68158 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68159 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68160
68161 /* Finally, free the core (containing the module structure) */
68162 unset_module_core_ro_nx(mod);
68163 - module_free(mod, mod->module_core);
68164 + module_free_exec(mod, mod->module_core_rx);
68165 + module_free(mod, mod->module_core_rw);
68166
68167 #ifdef CONFIG_MPU
68168 update_protections(current->mm);
68169 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68170 int ret = 0;
68171 const struct kernel_symbol *ksym;
68172
68173 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68174 + int is_fs_load = 0;
68175 + int register_filesystem_found = 0;
68176 + char *p;
68177 +
68178 + p = strstr(mod->args, "grsec_modharden_fs");
68179 + if (p) {
68180 + char *endptr = p + strlen("grsec_modharden_fs");
68181 + /* copy \0 as well */
68182 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68183 + is_fs_load = 1;
68184 + }
68185 +#endif
68186 +
68187 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68188 const char *name = info->strtab + sym[i].st_name;
68189
68190 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68191 + /* it's a real shame this will never get ripped and copied
68192 + upstream! ;(
68193 + */
68194 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68195 + register_filesystem_found = 1;
68196 +#endif
68197 +
68198 switch (sym[i].st_shndx) {
68199 case SHN_COMMON:
68200 /* We compiled with -fno-common. These are not
68201 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68202 ksym = resolve_symbol_wait(mod, info, name);
68203 /* Ok if resolved. */
68204 if (ksym && !IS_ERR(ksym)) {
68205 + pax_open_kernel();
68206 sym[i].st_value = ksym->value;
68207 + pax_close_kernel();
68208 break;
68209 }
68210
68211 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68212 secbase = (unsigned long)mod_percpu(mod);
68213 else
68214 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68215 + pax_open_kernel();
68216 sym[i].st_value += secbase;
68217 + pax_close_kernel();
68218 break;
68219 }
68220 }
68221
68222 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68223 + if (is_fs_load && !register_filesystem_found) {
68224 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68225 + ret = -EPERM;
68226 + }
68227 +#endif
68228 +
68229 return ret;
68230 }
68231
68232 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68233 || s->sh_entsize != ~0UL
68234 || strstarts(sname, ".init"))
68235 continue;
68236 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68237 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68238 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68239 + else
68240 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68241 pr_debug("\t%s\n", sname);
68242 }
68243 - switch (m) {
68244 - case 0: /* executable */
68245 - mod->core_size = debug_align(mod->core_size);
68246 - mod->core_text_size = mod->core_size;
68247 - break;
68248 - case 1: /* RO: text and ro-data */
68249 - mod->core_size = debug_align(mod->core_size);
68250 - mod->core_ro_size = mod->core_size;
68251 - break;
68252 - case 3: /* whole core */
68253 - mod->core_size = debug_align(mod->core_size);
68254 - break;
68255 - }
68256 }
68257
68258 pr_debug("Init section allocation order:\n");
68259 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68260 || s->sh_entsize != ~0UL
68261 || !strstarts(sname, ".init"))
68262 continue;
68263 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68264 - | INIT_OFFSET_MASK);
68265 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68266 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68267 + else
68268 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68269 + s->sh_entsize |= INIT_OFFSET_MASK;
68270 pr_debug("\t%s\n", sname);
68271 }
68272 - switch (m) {
68273 - case 0: /* executable */
68274 - mod->init_size = debug_align(mod->init_size);
68275 - mod->init_text_size = mod->init_size;
68276 - break;
68277 - case 1: /* RO: text and ro-data */
68278 - mod->init_size = debug_align(mod->init_size);
68279 - mod->init_ro_size = mod->init_size;
68280 - break;
68281 - case 3: /* whole init */
68282 - mod->init_size = debug_align(mod->init_size);
68283 - break;
68284 - }
68285 }
68286 }
68287
68288 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68289
68290 /* Put symbol section at end of init part of module. */
68291 symsect->sh_flags |= SHF_ALLOC;
68292 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68293 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68294 info->index.sym) | INIT_OFFSET_MASK;
68295 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68296
68297 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68298 }
68299
68300 /* Append room for core symbols at end of core part. */
68301 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68302 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68303 - mod->core_size += strtab_size;
68304 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68305 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68306 + mod->core_size_rx += strtab_size;
68307
68308 /* Put string table section at end of init part of module. */
68309 strsect->sh_flags |= SHF_ALLOC;
68310 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68311 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68312 info->index.str) | INIT_OFFSET_MASK;
68313 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68314 }
68315 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68316 /* Make sure we get permanent strtab: don't use info->strtab. */
68317 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68318
68319 + pax_open_kernel();
68320 +
68321 /* Set types up while we still have access to sections. */
68322 for (i = 0; i < mod->num_symtab; i++)
68323 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68324
68325 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68326 - mod->core_strtab = s = mod->module_core + info->stroffs;
68327 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68328 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68329 src = mod->symtab;
68330 *dst = *src;
68331 *s++ = 0;
68332 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68333 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68334 }
68335 mod->core_num_syms = ndst;
68336 +
68337 + pax_close_kernel();
68338 }
68339 #else
68340 static inline void layout_symtab(struct module *mod, struct load_info *info)
68341 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68342 return size == 0 ? NULL : vmalloc_exec(size);
68343 }
68344
68345 -static void *module_alloc_update_bounds(unsigned long size)
68346 +static void *module_alloc_update_bounds_rw(unsigned long size)
68347 {
68348 void *ret = module_alloc(size);
68349
68350 if (ret) {
68351 mutex_lock(&module_mutex);
68352 /* Update module bounds. */
68353 - if ((unsigned long)ret < module_addr_min)
68354 - module_addr_min = (unsigned long)ret;
68355 - if ((unsigned long)ret + size > module_addr_max)
68356 - module_addr_max = (unsigned long)ret + size;
68357 + if ((unsigned long)ret < module_addr_min_rw)
68358 + module_addr_min_rw = (unsigned long)ret;
68359 + if ((unsigned long)ret + size > module_addr_max_rw)
68360 + module_addr_max_rw = (unsigned long)ret + size;
68361 + mutex_unlock(&module_mutex);
68362 + }
68363 + return ret;
68364 +}
68365 +
68366 +static void *module_alloc_update_bounds_rx(unsigned long size)
68367 +{
68368 + void *ret = module_alloc_exec(size);
68369 +
68370 + if (ret) {
68371 + mutex_lock(&module_mutex);
68372 + /* Update module bounds. */
68373 + if ((unsigned long)ret < module_addr_min_rx)
68374 + module_addr_min_rx = (unsigned long)ret;
68375 + if ((unsigned long)ret + size > module_addr_max_rx)
68376 + module_addr_max_rx = (unsigned long)ret + size;
68377 mutex_unlock(&module_mutex);
68378 }
68379 return ret;
68380 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68381 static int check_modinfo(struct module *mod, struct load_info *info)
68382 {
68383 const char *modmagic = get_modinfo(info, "vermagic");
68384 + const char *license = get_modinfo(info, "license");
68385 int err;
68386
68387 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68388 + if (!license || !license_is_gpl_compatible(license))
68389 + return -ENOEXEC;
68390 +#endif
68391 +
68392 /* This is allowed: modprobe --force will invalidate it. */
68393 if (!modmagic) {
68394 err = try_to_force_load(mod, "bad vermagic");
68395 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68396 }
68397
68398 /* Set up license info based on the info section */
68399 - set_license(mod, get_modinfo(info, "license"));
68400 + set_license(mod, license);
68401
68402 return 0;
68403 }
68404 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68405 void *ptr;
68406
68407 /* Do the allocs. */
68408 - ptr = module_alloc_update_bounds(mod->core_size);
68409 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68410 /*
68411 * The pointer to this block is stored in the module structure
68412 * which is inside the block. Just mark it as not being a
68413 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68414 if (!ptr)
68415 return -ENOMEM;
68416
68417 - memset(ptr, 0, mod->core_size);
68418 - mod->module_core = ptr;
68419 + memset(ptr, 0, mod->core_size_rw);
68420 + mod->module_core_rw = ptr;
68421
68422 - ptr = module_alloc_update_bounds(mod->init_size);
68423 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68424 /*
68425 * The pointer to this block is stored in the module structure
68426 * which is inside the block. This block doesn't need to be
68427 * scanned as it contains data and code that will be freed
68428 * after the module is initialized.
68429 */
68430 - kmemleak_ignore(ptr);
68431 - if (!ptr && mod->init_size) {
68432 - module_free(mod, mod->module_core);
68433 + kmemleak_not_leak(ptr);
68434 + if (!ptr && mod->init_size_rw) {
68435 + module_free(mod, mod->module_core_rw);
68436 return -ENOMEM;
68437 }
68438 - memset(ptr, 0, mod->init_size);
68439 - mod->module_init = ptr;
68440 + memset(ptr, 0, mod->init_size_rw);
68441 + mod->module_init_rw = ptr;
68442 +
68443 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68444 + kmemleak_not_leak(ptr);
68445 + if (!ptr) {
68446 + module_free(mod, mod->module_init_rw);
68447 + module_free(mod, mod->module_core_rw);
68448 + return -ENOMEM;
68449 + }
68450 +
68451 + pax_open_kernel();
68452 + memset(ptr, 0, mod->core_size_rx);
68453 + pax_close_kernel();
68454 + mod->module_core_rx = ptr;
68455 +
68456 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68457 + kmemleak_not_leak(ptr);
68458 + if (!ptr && mod->init_size_rx) {
68459 + module_free_exec(mod, mod->module_core_rx);
68460 + module_free(mod, mod->module_init_rw);
68461 + module_free(mod, mod->module_core_rw);
68462 + return -ENOMEM;
68463 + }
68464 +
68465 + pax_open_kernel();
68466 + memset(ptr, 0, mod->init_size_rx);
68467 + pax_close_kernel();
68468 + mod->module_init_rx = ptr;
68469
68470 /* Transfer each section which specifies SHF_ALLOC */
68471 pr_debug("final section addresses:\n");
68472 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68473 if (!(shdr->sh_flags & SHF_ALLOC))
68474 continue;
68475
68476 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68477 - dest = mod->module_init
68478 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68479 - else
68480 - dest = mod->module_core + shdr->sh_entsize;
68481 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68482 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68483 + dest = mod->module_init_rw
68484 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68485 + else
68486 + dest = mod->module_init_rx
68487 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68488 + } else {
68489 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68490 + dest = mod->module_core_rw + shdr->sh_entsize;
68491 + else
68492 + dest = mod->module_core_rx + shdr->sh_entsize;
68493 + }
68494 +
68495 + if (shdr->sh_type != SHT_NOBITS) {
68496 +
68497 +#ifdef CONFIG_PAX_KERNEXEC
68498 +#ifdef CONFIG_X86_64
68499 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68500 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68501 +#endif
68502 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68503 + pax_open_kernel();
68504 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68505 + pax_close_kernel();
68506 + } else
68507 +#endif
68508
68509 - if (shdr->sh_type != SHT_NOBITS)
68510 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68511 + }
68512 /* Update sh_addr to point to copy in image. */
68513 - shdr->sh_addr = (unsigned long)dest;
68514 +
68515 +#ifdef CONFIG_PAX_KERNEXEC
68516 + if (shdr->sh_flags & SHF_EXECINSTR)
68517 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68518 + else
68519 +#endif
68520 +
68521 + shdr->sh_addr = (unsigned long)dest;
68522 pr_debug("\t0x%lx %s\n",
68523 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68524 }
68525 @@ -2763,12 +2863,12 @@ static void flush_module_icache(const struct module *mod)
68526 * Do it before processing of module parameters, so the module
68527 * can provide parameter accessor functions of its own.
68528 */
68529 - if (mod->module_init)
68530 - flush_icache_range((unsigned long)mod->module_init,
68531 - (unsigned long)mod->module_init
68532 - + mod->init_size);
68533 - flush_icache_range((unsigned long)mod->module_core,
68534 - (unsigned long)mod->module_core + mod->core_size);
68535 + if (mod->module_init_rx)
68536 + flush_icache_range((unsigned long)mod->module_init_rx,
68537 + (unsigned long)mod->module_init_rx
68538 + + mod->init_size_rx);
68539 + flush_icache_range((unsigned long)mod->module_core_rx,
68540 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68541
68542 set_fs(old_fs);
68543 }
68544 @@ -2838,8 +2938,10 @@ out:
68545 static void module_deallocate(struct module *mod, struct load_info *info)
68546 {
68547 percpu_modfree(mod);
68548 - module_free(mod, mod->module_init);
68549 - module_free(mod, mod->module_core);
68550 + module_free_exec(mod, mod->module_init_rx);
68551 + module_free_exec(mod, mod->module_core_rx);
68552 + module_free(mod, mod->module_init_rw);
68553 + module_free(mod, mod->module_core_rw);
68554 }
68555
68556 int __weak module_finalize(const Elf_Ehdr *hdr,
68557 @@ -2852,7 +2954,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68558 static int post_relocation(struct module *mod, const struct load_info *info)
68559 {
68560 /* Sort exception table now relocations are done. */
68561 + pax_open_kernel();
68562 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68563 + pax_close_kernel();
68564
68565 /* Copy relocated percpu area over. */
68566 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68567 @@ -2903,9 +3007,38 @@ static struct module *load_module(void __user *umod,
68568 if (err)
68569 goto free_unload;
68570
68571 + /* Now copy in args */
68572 + mod->args = strndup_user(uargs, ~0UL >> 1);
68573 + if (IS_ERR(mod->args)) {
68574 + err = PTR_ERR(mod->args);
68575 + goto free_unload;
68576 + }
68577 +
68578 /* Set up MODINFO_ATTR fields */
68579 setup_modinfo(mod, &info);
68580
68581 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68582 + {
68583 + char *p, *p2;
68584 +
68585 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68586 + 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);
68587 + err = -EPERM;
68588 + goto free_modinfo;
68589 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68590 + p += strlen("grsec_modharden_normal");
68591 + p2 = strstr(p, "_");
68592 + if (p2) {
68593 + *p2 = '\0';
68594 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68595 + *p2 = '_';
68596 + }
68597 + err = -EPERM;
68598 + goto free_modinfo;
68599 + }
68600 + }
68601 +#endif
68602 +
68603 /* Fix up syms, so that st_value is a pointer to location. */
68604 err = simplify_symbols(mod, &info);
68605 if (err < 0)
68606 @@ -2921,13 +3054,6 @@ static struct module *load_module(void __user *umod,
68607
68608 flush_module_icache(mod);
68609
68610 - /* Now copy in args */
68611 - mod->args = strndup_user(uargs, ~0UL >> 1);
68612 - if (IS_ERR(mod->args)) {
68613 - err = PTR_ERR(mod->args);
68614 - goto free_arch_cleanup;
68615 - }
68616 -
68617 /* Mark state as coming so strong_try_module_get() ignores us. */
68618 mod->state = MODULE_STATE_COMING;
68619
68620 @@ -2985,11 +3111,10 @@ static struct module *load_module(void __user *umod,
68621 unlock:
68622 mutex_unlock(&module_mutex);
68623 synchronize_sched();
68624 - kfree(mod->args);
68625 - free_arch_cleanup:
68626 module_arch_cleanup(mod);
68627 free_modinfo:
68628 free_modinfo(mod);
68629 + kfree(mod->args);
68630 free_unload:
68631 module_unload_free(mod);
68632 free_module:
68633 @@ -3030,16 +3155,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68634 MODULE_STATE_COMING, mod);
68635
68636 /* Set RO and NX regions for core */
68637 - set_section_ro_nx(mod->module_core,
68638 - mod->core_text_size,
68639 - mod->core_ro_size,
68640 - mod->core_size);
68641 + set_section_ro_nx(mod->module_core_rx,
68642 + mod->core_size_rx,
68643 + mod->core_size_rx,
68644 + mod->core_size_rx);
68645
68646 /* Set RO and NX regions for init */
68647 - set_section_ro_nx(mod->module_init,
68648 - mod->init_text_size,
68649 - mod->init_ro_size,
68650 - mod->init_size);
68651 + set_section_ro_nx(mod->module_init_rx,
68652 + mod->init_size_rx,
68653 + mod->init_size_rx,
68654 + mod->init_size_rx);
68655
68656 do_mod_ctors(mod);
68657 /* Start the module */
68658 @@ -3085,11 +3210,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68659 mod->strtab = mod->core_strtab;
68660 #endif
68661 unset_module_init_ro_nx(mod);
68662 - module_free(mod, mod->module_init);
68663 - mod->module_init = NULL;
68664 - mod->init_size = 0;
68665 - mod->init_ro_size = 0;
68666 - mod->init_text_size = 0;
68667 + module_free(mod, mod->module_init_rw);
68668 + module_free_exec(mod, mod->module_init_rx);
68669 + mod->module_init_rw = NULL;
68670 + mod->module_init_rx = NULL;
68671 + mod->init_size_rw = 0;
68672 + mod->init_size_rx = 0;
68673 mutex_unlock(&module_mutex);
68674
68675 return 0;
68676 @@ -3120,10 +3246,16 @@ static const char *get_ksymbol(struct module *mod,
68677 unsigned long nextval;
68678
68679 /* At worse, next value is at end of module */
68680 - if (within_module_init(addr, mod))
68681 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68682 + if (within_module_init_rx(addr, mod))
68683 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68684 + else if (within_module_init_rw(addr, mod))
68685 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68686 + else if (within_module_core_rx(addr, mod))
68687 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68688 + else if (within_module_core_rw(addr, mod))
68689 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68690 else
68691 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68692 + return NULL;
68693
68694 /* Scan for closest preceding symbol, and next symbol. (ELF
68695 starts real symbols at 1). */
68696 @@ -3358,7 +3490,7 @@ static int m_show(struct seq_file *m, void *p)
68697 char buf[8];
68698
68699 seq_printf(m, "%s %u",
68700 - mod->name, mod->init_size + mod->core_size);
68701 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68702 print_unload_info(m, mod);
68703
68704 /* Informative for users. */
68705 @@ -3367,7 +3499,7 @@ static int m_show(struct seq_file *m, void *p)
68706 mod->state == MODULE_STATE_COMING ? "Loading":
68707 "Live");
68708 /* Used by oprofile and other similar tools. */
68709 - seq_printf(m, " 0x%pK", mod->module_core);
68710 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68711
68712 /* Taints info */
68713 if (mod->taints)
68714 @@ -3403,7 +3535,17 @@ static const struct file_operations proc_modules_operations = {
68715
68716 static int __init proc_modules_init(void)
68717 {
68718 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68719 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68720 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68721 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68722 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68723 +#else
68724 proc_create("modules", 0, NULL, &proc_modules_operations);
68725 +#endif
68726 +#else
68727 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68728 +#endif
68729 return 0;
68730 }
68731 module_init(proc_modules_init);
68732 @@ -3462,12 +3604,12 @@ struct module *__module_address(unsigned long addr)
68733 {
68734 struct module *mod;
68735
68736 - if (addr < module_addr_min || addr > module_addr_max)
68737 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68738 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68739 return NULL;
68740
68741 list_for_each_entry_rcu(mod, &modules, list)
68742 - if (within_module_core(addr, mod)
68743 - || within_module_init(addr, mod))
68744 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68745 return mod;
68746 return NULL;
68747 }
68748 @@ -3501,11 +3643,20 @@ bool is_module_text_address(unsigned long addr)
68749 */
68750 struct module *__module_text_address(unsigned long addr)
68751 {
68752 - struct module *mod = __module_address(addr);
68753 + struct module *mod;
68754 +
68755 +#ifdef CONFIG_X86_32
68756 + addr = ktla_ktva(addr);
68757 +#endif
68758 +
68759 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68760 + return NULL;
68761 +
68762 + mod = __module_address(addr);
68763 +
68764 if (mod) {
68765 /* Make sure it's within the text section. */
68766 - if (!within(addr, mod->module_init, mod->init_text_size)
68767 - && !within(addr, mod->module_core, mod->core_text_size))
68768 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68769 mod = NULL;
68770 }
68771 return mod;
68772 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68773 index 7e3443f..b2a1e6b 100644
68774 --- a/kernel/mutex-debug.c
68775 +++ b/kernel/mutex-debug.c
68776 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68777 }
68778
68779 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68780 - struct thread_info *ti)
68781 + struct task_struct *task)
68782 {
68783 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68784
68785 /* Mark the current thread as blocked on the lock: */
68786 - ti->task->blocked_on = waiter;
68787 + task->blocked_on = waiter;
68788 }
68789
68790 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68791 - struct thread_info *ti)
68792 + struct task_struct *task)
68793 {
68794 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68795 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68796 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68797 - ti->task->blocked_on = NULL;
68798 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68799 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68800 + task->blocked_on = NULL;
68801
68802 list_del_init(&waiter->list);
68803 waiter->task = NULL;
68804 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68805 index 0799fd3..d06ae3b 100644
68806 --- a/kernel/mutex-debug.h
68807 +++ b/kernel/mutex-debug.h
68808 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68809 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68810 extern void debug_mutex_add_waiter(struct mutex *lock,
68811 struct mutex_waiter *waiter,
68812 - struct thread_info *ti);
68813 + struct task_struct *task);
68814 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68815 - struct thread_info *ti);
68816 + struct task_struct *task);
68817 extern void debug_mutex_unlock(struct mutex *lock);
68818 extern void debug_mutex_init(struct mutex *lock, const char *name,
68819 struct lock_class_key *key);
68820 diff --git a/kernel/mutex.c b/kernel/mutex.c
68821 index a307cc9..27fd2e9 100644
68822 --- a/kernel/mutex.c
68823 +++ b/kernel/mutex.c
68824 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68825 spin_lock_mutex(&lock->wait_lock, flags);
68826
68827 debug_mutex_lock_common(lock, &waiter);
68828 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68829 + debug_mutex_add_waiter(lock, &waiter, task);
68830
68831 /* add waiting tasks to the end of the waitqueue (FIFO): */
68832 list_add_tail(&waiter.list, &lock->wait_list);
68833 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68834 * TASK_UNINTERRUPTIBLE case.)
68835 */
68836 if (unlikely(signal_pending_state(state, task))) {
68837 - mutex_remove_waiter(lock, &waiter,
68838 - task_thread_info(task));
68839 + mutex_remove_waiter(lock, &waiter, task);
68840 mutex_release(&lock->dep_map, 1, ip);
68841 spin_unlock_mutex(&lock->wait_lock, flags);
68842
68843 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68844 done:
68845 lock_acquired(&lock->dep_map, ip);
68846 /* got the lock - rejoice! */
68847 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68848 + mutex_remove_waiter(lock, &waiter, task);
68849 mutex_set_owner(lock);
68850
68851 /* set it to 0 if there are no waiters left: */
68852 diff --git a/kernel/panic.c b/kernel/panic.c
68853 index e1b2822..5edc1d9 100644
68854 --- a/kernel/panic.c
68855 +++ b/kernel/panic.c
68856 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68857 const char *board;
68858
68859 printk(KERN_WARNING "------------[ cut here ]------------\n");
68860 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68861 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68862 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68863 if (board)
68864 printk(KERN_WARNING "Hardware name: %s\n", board);
68865 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68866 */
68867 void __stack_chk_fail(void)
68868 {
68869 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68870 + dump_stack();
68871 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68872 __builtin_return_address(0));
68873 }
68874 EXPORT_SYMBOL(__stack_chk_fail);
68875 diff --git a/kernel/pid.c b/kernel/pid.c
68876 index e86b291a..e8b0fb5 100644
68877 --- a/kernel/pid.c
68878 +++ b/kernel/pid.c
68879 @@ -33,6 +33,7 @@
68880 #include <linux/rculist.h>
68881 #include <linux/bootmem.h>
68882 #include <linux/hash.h>
68883 +#include <linux/security.h>
68884 #include <linux/pid_namespace.h>
68885 #include <linux/init_task.h>
68886 #include <linux/syscalls.h>
68887 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68888
68889 int pid_max = PID_MAX_DEFAULT;
68890
68891 -#define RESERVED_PIDS 300
68892 +#define RESERVED_PIDS 500
68893
68894 int pid_max_min = RESERVED_PIDS + 1;
68895 int pid_max_max = PID_MAX_LIMIT;
68896 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68897 */
68898 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68899 {
68900 + struct task_struct *task;
68901 +
68902 rcu_lockdep_assert(rcu_read_lock_held(),
68903 "find_task_by_pid_ns() needs rcu_read_lock()"
68904 " protection");
68905 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68906 +
68907 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68908 +
68909 + if (gr_pid_is_chrooted(task))
68910 + return NULL;
68911 +
68912 + return task;
68913 }
68914
68915 struct task_struct *find_task_by_vpid(pid_t vnr)
68916 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68917 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68918 }
68919
68920 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68921 +{
68922 + rcu_lockdep_assert(rcu_read_lock_held(),
68923 + "find_task_by_pid_ns() needs rcu_read_lock()"
68924 + " protection");
68925 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68926 +}
68927 +
68928 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68929 {
68930 struct pid *pid;
68931 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68932 index 125cb67..a4d1c30 100644
68933 --- a/kernel/posix-cpu-timers.c
68934 +++ b/kernel/posix-cpu-timers.c
68935 @@ -6,6 +6,7 @@
68936 #include <linux/posix-timers.h>
68937 #include <linux/errno.h>
68938 #include <linux/math64.h>
68939 +#include <linux/security.h>
68940 #include <asm/uaccess.h>
68941 #include <linux/kernel_stat.h>
68942 #include <trace/events/timer.h>
68943 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68944
68945 static __init int init_posix_cpu_timers(void)
68946 {
68947 - struct k_clock process = {
68948 + static struct k_clock process = {
68949 .clock_getres = process_cpu_clock_getres,
68950 .clock_get = process_cpu_clock_get,
68951 .timer_create = process_cpu_timer_create,
68952 .nsleep = process_cpu_nsleep,
68953 .nsleep_restart = process_cpu_nsleep_restart,
68954 };
68955 - struct k_clock thread = {
68956 + static struct k_clock thread = {
68957 .clock_getres = thread_cpu_clock_getres,
68958 .clock_get = thread_cpu_clock_get,
68959 .timer_create = thread_cpu_timer_create,
68960 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68961 index 69185ae..cc2847a 100644
68962 --- a/kernel/posix-timers.c
68963 +++ b/kernel/posix-timers.c
68964 @@ -43,6 +43,7 @@
68965 #include <linux/idr.h>
68966 #include <linux/posix-clock.h>
68967 #include <linux/posix-timers.h>
68968 +#include <linux/grsecurity.h>
68969 #include <linux/syscalls.h>
68970 #include <linux/wait.h>
68971 #include <linux/workqueue.h>
68972 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68973 * which we beg off on and pass to do_sys_settimeofday().
68974 */
68975
68976 -static struct k_clock posix_clocks[MAX_CLOCKS];
68977 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68978
68979 /*
68980 * These ones are defined below.
68981 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68982 */
68983 static __init int init_posix_timers(void)
68984 {
68985 - struct k_clock clock_realtime = {
68986 + static struct k_clock clock_realtime = {
68987 .clock_getres = hrtimer_get_res,
68988 .clock_get = posix_clock_realtime_get,
68989 .clock_set = posix_clock_realtime_set,
68990 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68991 .timer_get = common_timer_get,
68992 .timer_del = common_timer_del,
68993 };
68994 - struct k_clock clock_monotonic = {
68995 + static struct k_clock clock_monotonic = {
68996 .clock_getres = hrtimer_get_res,
68997 .clock_get = posix_ktime_get_ts,
68998 .nsleep = common_nsleep,
68999 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69000 .timer_get = common_timer_get,
69001 .timer_del = common_timer_del,
69002 };
69003 - struct k_clock clock_monotonic_raw = {
69004 + static struct k_clock clock_monotonic_raw = {
69005 .clock_getres = hrtimer_get_res,
69006 .clock_get = posix_get_monotonic_raw,
69007 };
69008 - struct k_clock clock_realtime_coarse = {
69009 + static struct k_clock clock_realtime_coarse = {
69010 .clock_getres = posix_get_coarse_res,
69011 .clock_get = posix_get_realtime_coarse,
69012 };
69013 - struct k_clock clock_monotonic_coarse = {
69014 + static struct k_clock clock_monotonic_coarse = {
69015 .clock_getres = posix_get_coarse_res,
69016 .clock_get = posix_get_monotonic_coarse,
69017 };
69018 - struct k_clock clock_boottime = {
69019 + static struct k_clock clock_boottime = {
69020 .clock_getres = hrtimer_get_res,
69021 .clock_get = posix_get_boottime,
69022 .nsleep = common_nsleep,
69023 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69024 return;
69025 }
69026
69027 - posix_clocks[clock_id] = *new_clock;
69028 + posix_clocks[clock_id] = new_clock;
69029 }
69030 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69031
69032 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69033 return (id & CLOCKFD_MASK) == CLOCKFD ?
69034 &clock_posix_dynamic : &clock_posix_cpu;
69035
69036 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69037 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69038 return NULL;
69039 - return &posix_clocks[id];
69040 + return posix_clocks[id];
69041 }
69042
69043 static int common_timer_create(struct k_itimer *new_timer)
69044 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69045 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69046 return -EFAULT;
69047
69048 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69049 + have their clock_set fptr set to a nosettime dummy function
69050 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69051 + call common_clock_set, which calls do_sys_settimeofday, which
69052 + we hook
69053 + */
69054 +
69055 return kc->clock_set(which_clock, &new_tp);
69056 }
69057
69058 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69059 index d523593..68197a4 100644
69060 --- a/kernel/power/poweroff.c
69061 +++ b/kernel/power/poweroff.c
69062 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69063 .enable_mask = SYSRQ_ENABLE_BOOT,
69064 };
69065
69066 -static int pm_sysrq_init(void)
69067 +static int __init pm_sysrq_init(void)
69068 {
69069 register_sysrq_key('o', &sysrq_poweroff_op);
69070 return 0;
69071 diff --git a/kernel/power/process.c b/kernel/power/process.c
69072 index 19db29f..33b52b6 100644
69073 --- a/kernel/power/process.c
69074 +++ b/kernel/power/process.c
69075 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69076 u64 elapsed_csecs64;
69077 unsigned int elapsed_csecs;
69078 bool wakeup = false;
69079 + bool timedout = false;
69080
69081 do_gettimeofday(&start);
69082
69083 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69084
69085 while (true) {
69086 todo = 0;
69087 + if (time_after(jiffies, end_time))
69088 + timedout = true;
69089 read_lock(&tasklist_lock);
69090 do_each_thread(g, p) {
69091 if (p == current || !freeze_task(p))
69092 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69093 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69094 * transition can't race with task state testing here.
69095 */
69096 - if (!task_is_stopped_or_traced(p) &&
69097 - !freezer_should_skip(p))
69098 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69099 todo++;
69100 + if (timedout) {
69101 + printk(KERN_ERR "Task refusing to freeze:\n");
69102 + sched_show_task(p);
69103 + }
69104 + }
69105 } while_each_thread(g, p);
69106 read_unlock(&tasklist_lock);
69107
69108 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69109 todo += wq_busy;
69110 }
69111
69112 - if (!todo || time_after(jiffies, end_time))
69113 + if (!todo || timedout)
69114 break;
69115
69116 if (pm_wakeup_pending()) {
69117 diff --git a/kernel/printk.c b/kernel/printk.c
69118 index 66a2ea3..10f3a01 100644
69119 --- a/kernel/printk.c
69120 +++ b/kernel/printk.c
69121 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69122 if (from_file && type != SYSLOG_ACTION_OPEN)
69123 return 0;
69124
69125 +#ifdef CONFIG_GRKERNSEC_DMESG
69126 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69127 + return -EPERM;
69128 +#endif
69129 +
69130 if (syslog_action_restricted(type)) {
69131 if (capable(CAP_SYSLOG))
69132 return 0;
69133 diff --git a/kernel/profile.c b/kernel/profile.c
69134 index 76b8e77..a2930e8 100644
69135 --- a/kernel/profile.c
69136 +++ b/kernel/profile.c
69137 @@ -39,7 +39,7 @@ struct profile_hit {
69138 /* Oprofile timer tick hook */
69139 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69140
69141 -static atomic_t *prof_buffer;
69142 +static atomic_unchecked_t *prof_buffer;
69143 static unsigned long prof_len, prof_shift;
69144
69145 int prof_on __read_mostly;
69146 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69147 hits[i].pc = 0;
69148 continue;
69149 }
69150 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69151 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69152 hits[i].hits = hits[i].pc = 0;
69153 }
69154 }
69155 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69156 * Add the current hit(s) and flush the write-queue out
69157 * to the global buffer:
69158 */
69159 - atomic_add(nr_hits, &prof_buffer[pc]);
69160 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69161 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69162 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69163 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69164 hits[i].pc = hits[i].hits = 0;
69165 }
69166 out:
69167 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69168 {
69169 unsigned long pc;
69170 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69171 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69172 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69173 }
69174 #endif /* !CONFIG_SMP */
69175
69176 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69177 return -EFAULT;
69178 buf++; p++; count--; read++;
69179 }
69180 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69181 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69182 if (copy_to_user(buf, (void *)pnt, count))
69183 return -EFAULT;
69184 read += count;
69185 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69186 }
69187 #endif
69188 profile_discard_flip_buffers();
69189 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69190 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69191 return count;
69192 }
69193
69194 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69195 index a232bb5..2a65ef9 100644
69196 --- a/kernel/ptrace.c
69197 +++ b/kernel/ptrace.c
69198 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69199
69200 if (seize)
69201 flags |= PT_SEIZED;
69202 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69203 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69204 flags |= PT_PTRACE_CAP;
69205 task->ptrace = flags;
69206
69207 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69208 break;
69209 return -EIO;
69210 }
69211 - if (copy_to_user(dst, buf, retval))
69212 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69213 return -EFAULT;
69214 copied += retval;
69215 src += retval;
69216 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69217 bool seized = child->ptrace & PT_SEIZED;
69218 int ret = -EIO;
69219 siginfo_t siginfo, *si;
69220 - void __user *datavp = (void __user *) data;
69221 + void __user *datavp = (__force void __user *) data;
69222 unsigned long __user *datalp = datavp;
69223 unsigned long flags;
69224
69225 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69226 goto out;
69227 }
69228
69229 + if (gr_handle_ptrace(child, request)) {
69230 + ret = -EPERM;
69231 + goto out_put_task_struct;
69232 + }
69233 +
69234 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69235 ret = ptrace_attach(child, request, addr, data);
69236 /*
69237 * Some architectures need to do book-keeping after
69238 * a ptrace attach.
69239 */
69240 - if (!ret)
69241 + if (!ret) {
69242 arch_ptrace_attach(child);
69243 + gr_audit_ptrace(child);
69244 + }
69245 goto out_put_task_struct;
69246 }
69247
69248 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69249 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69250 if (copied != sizeof(tmp))
69251 return -EIO;
69252 - return put_user(tmp, (unsigned long __user *)data);
69253 + return put_user(tmp, (__force unsigned long __user *)data);
69254 }
69255
69256 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69257 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69258 goto out;
69259 }
69260
69261 + if (gr_handle_ptrace(child, request)) {
69262 + ret = -EPERM;
69263 + goto out_put_task_struct;
69264 + }
69265 +
69266 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69267 ret = ptrace_attach(child, request, addr, data);
69268 /*
69269 * Some architectures need to do book-keeping after
69270 * a ptrace attach.
69271 */
69272 - if (!ret)
69273 + if (!ret) {
69274 arch_ptrace_attach(child);
69275 + gr_audit_ptrace(child);
69276 + }
69277 goto out_put_task_struct;
69278 }
69279
69280 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69281 index 547b1fe..65e874e 100644
69282 --- a/kernel/rcutiny.c
69283 +++ b/kernel/rcutiny.c
69284 @@ -46,7 +46,7 @@
69285 struct rcu_ctrlblk;
69286 static void invoke_rcu_callbacks(void);
69287 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69288 -static void rcu_process_callbacks(struct softirq_action *unused);
69289 +static void rcu_process_callbacks(void);
69290 static void __call_rcu(struct rcu_head *head,
69291 void (*func)(struct rcu_head *rcu),
69292 struct rcu_ctrlblk *rcp);
69293 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69294 rcu_is_callbacks_kthread()));
69295 }
69296
69297 -static void rcu_process_callbacks(struct softirq_action *unused)
69298 +static void rcu_process_callbacks(void)
69299 {
69300 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69301 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69302 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69303 index 918fd1e..85089bb 100644
69304 --- a/kernel/rcutiny_plugin.h
69305 +++ b/kernel/rcutiny_plugin.h
69306 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69307 have_rcu_kthread_work = morework;
69308 local_irq_restore(flags);
69309 if (work)
69310 - rcu_process_callbacks(NULL);
69311 + rcu_process_callbacks();
69312 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69313 }
69314
69315 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69316 index 25b1503..1988a74 100644
69317 --- a/kernel/rcutorture.c
69318 +++ b/kernel/rcutorture.c
69319 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69320 { 0 };
69321 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69322 { 0 };
69323 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69324 -static atomic_t n_rcu_torture_alloc;
69325 -static atomic_t n_rcu_torture_alloc_fail;
69326 -static atomic_t n_rcu_torture_free;
69327 -static atomic_t n_rcu_torture_mberror;
69328 -static atomic_t n_rcu_torture_error;
69329 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69330 +static atomic_unchecked_t n_rcu_torture_alloc;
69331 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69332 +static atomic_unchecked_t n_rcu_torture_free;
69333 +static atomic_unchecked_t n_rcu_torture_mberror;
69334 +static atomic_unchecked_t n_rcu_torture_error;
69335 static long n_rcu_torture_barrier_error;
69336 static long n_rcu_torture_boost_ktrerror;
69337 static long n_rcu_torture_boost_rterror;
69338 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69339
69340 spin_lock_bh(&rcu_torture_lock);
69341 if (list_empty(&rcu_torture_freelist)) {
69342 - atomic_inc(&n_rcu_torture_alloc_fail);
69343 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69344 spin_unlock_bh(&rcu_torture_lock);
69345 return NULL;
69346 }
69347 - atomic_inc(&n_rcu_torture_alloc);
69348 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69349 p = rcu_torture_freelist.next;
69350 list_del_init(p);
69351 spin_unlock_bh(&rcu_torture_lock);
69352 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69353 static void
69354 rcu_torture_free(struct rcu_torture *p)
69355 {
69356 - atomic_inc(&n_rcu_torture_free);
69357 + atomic_inc_unchecked(&n_rcu_torture_free);
69358 spin_lock_bh(&rcu_torture_lock);
69359 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69360 spin_unlock_bh(&rcu_torture_lock);
69361 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69362 i = rp->rtort_pipe_count;
69363 if (i > RCU_TORTURE_PIPE_LEN)
69364 i = RCU_TORTURE_PIPE_LEN;
69365 - atomic_inc(&rcu_torture_wcount[i]);
69366 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69367 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69368 rp->rtort_mbtest = 0;
69369 rcu_torture_free(rp);
69370 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69371 i = rp->rtort_pipe_count;
69372 if (i > RCU_TORTURE_PIPE_LEN)
69373 i = RCU_TORTURE_PIPE_LEN;
69374 - atomic_inc(&rcu_torture_wcount[i]);
69375 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69376 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69377 rp->rtort_mbtest = 0;
69378 list_del(&rp->rtort_free);
69379 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69380 i = old_rp->rtort_pipe_count;
69381 if (i > RCU_TORTURE_PIPE_LEN)
69382 i = RCU_TORTURE_PIPE_LEN;
69383 - atomic_inc(&rcu_torture_wcount[i]);
69384 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69385 old_rp->rtort_pipe_count++;
69386 cur_ops->deferred_free(old_rp);
69387 }
69388 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69389 }
69390 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69391 if (p->rtort_mbtest == 0)
69392 - atomic_inc(&n_rcu_torture_mberror);
69393 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69394 spin_lock(&rand_lock);
69395 cur_ops->read_delay(&rand);
69396 n_rcu_torture_timers++;
69397 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69398 }
69399 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69400 if (p->rtort_mbtest == 0)
69401 - atomic_inc(&n_rcu_torture_mberror);
69402 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69403 cur_ops->read_delay(&rand);
69404 preempt_disable();
69405 pipe_count = p->rtort_pipe_count;
69406 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69407 rcu_torture_current,
69408 rcu_torture_current_version,
69409 list_empty(&rcu_torture_freelist),
69410 - atomic_read(&n_rcu_torture_alloc),
69411 - atomic_read(&n_rcu_torture_alloc_fail),
69412 - atomic_read(&n_rcu_torture_free));
69413 + atomic_read_unchecked(&n_rcu_torture_alloc),
69414 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69415 + atomic_read_unchecked(&n_rcu_torture_free));
69416 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69417 - atomic_read(&n_rcu_torture_mberror),
69418 + atomic_read_unchecked(&n_rcu_torture_mberror),
69419 n_rcu_torture_boost_ktrerror,
69420 n_rcu_torture_boost_rterror);
69421 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69422 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69423 n_barrier_attempts,
69424 n_rcu_torture_barrier_error);
69425 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69426 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69427 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69428 n_rcu_torture_barrier_error != 0 ||
69429 n_rcu_torture_boost_ktrerror != 0 ||
69430 n_rcu_torture_boost_rterror != 0 ||
69431 n_rcu_torture_boost_failure != 0 ||
69432 i > 1) {
69433 cnt += sprintf(&page[cnt], "!!! ");
69434 - atomic_inc(&n_rcu_torture_error);
69435 + atomic_inc_unchecked(&n_rcu_torture_error);
69436 WARN_ON_ONCE(1);
69437 }
69438 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69439 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69440 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69441 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69442 cnt += sprintf(&page[cnt], " %d",
69443 - atomic_read(&rcu_torture_wcount[i]));
69444 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69445 }
69446 cnt += sprintf(&page[cnt], "\n");
69447 if (cur_ops->stats)
69448 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69449
69450 if (cur_ops->cleanup)
69451 cur_ops->cleanup();
69452 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69453 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69454 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69455 else if (n_online_successes != n_online_attempts ||
69456 n_offline_successes != n_offline_attempts)
69457 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69458
69459 rcu_torture_current = NULL;
69460 rcu_torture_current_version = 0;
69461 - atomic_set(&n_rcu_torture_alloc, 0);
69462 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69463 - atomic_set(&n_rcu_torture_free, 0);
69464 - atomic_set(&n_rcu_torture_mberror, 0);
69465 - atomic_set(&n_rcu_torture_error, 0);
69466 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69467 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69468 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69469 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69470 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69471 n_rcu_torture_barrier_error = 0;
69472 n_rcu_torture_boost_ktrerror = 0;
69473 n_rcu_torture_boost_rterror = 0;
69474 n_rcu_torture_boost_failure = 0;
69475 n_rcu_torture_boosts = 0;
69476 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69477 - atomic_set(&rcu_torture_wcount[i], 0);
69478 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69479 for_each_possible_cpu(cpu) {
69480 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69481 per_cpu(rcu_torture_count, cpu)[i] = 0;
69482 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69483 index f7bcd9e..8973e14 100644
69484 --- a/kernel/rcutree.c
69485 +++ b/kernel/rcutree.c
69486 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69487 rcu_prepare_for_idle(smp_processor_id());
69488 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69489 smp_mb__before_atomic_inc(); /* See above. */
69490 - atomic_inc(&rdtp->dynticks);
69491 + atomic_inc_unchecked(&rdtp->dynticks);
69492 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69493 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69494 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69495
69496 /*
69497 * The idle task is not permitted to enter the idle loop while
69498 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69499 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69500 {
69501 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69502 - atomic_inc(&rdtp->dynticks);
69503 + atomic_inc_unchecked(&rdtp->dynticks);
69504 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69505 smp_mb__after_atomic_inc(); /* See above. */
69506 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69507 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69508 rcu_cleanup_after_idle(smp_processor_id());
69509 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69510 if (!is_idle_task(current)) {
69511 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69512 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69513
69514 if (rdtp->dynticks_nmi_nesting == 0 &&
69515 - (atomic_read(&rdtp->dynticks) & 0x1))
69516 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69517 return;
69518 rdtp->dynticks_nmi_nesting++;
69519 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69520 - atomic_inc(&rdtp->dynticks);
69521 + atomic_inc_unchecked(&rdtp->dynticks);
69522 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69523 smp_mb__after_atomic_inc(); /* See above. */
69524 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69525 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69526 }
69527
69528 /**
69529 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69530 return;
69531 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69532 smp_mb__before_atomic_inc(); /* See above. */
69533 - atomic_inc(&rdtp->dynticks);
69534 + atomic_inc_unchecked(&rdtp->dynticks);
69535 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69536 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69537 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69538 }
69539
69540 /**
69541 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69542 int ret;
69543
69544 preempt_disable();
69545 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69546 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69547 preempt_enable();
69548 return ret;
69549 }
69550 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69551 */
69552 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69553 {
69554 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69555 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69556 return (rdp->dynticks_snap & 0x1) == 0;
69557 }
69558
69559 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69560 unsigned int curr;
69561 unsigned int snap;
69562
69563 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69564 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69565 snap = (unsigned int)rdp->dynticks_snap;
69566
69567 /*
69568 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69569 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69570 */
69571 if (till_stall_check < 3) {
69572 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69573 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69574 till_stall_check = 3;
69575 } else if (till_stall_check > 300) {
69576 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69577 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69578 till_stall_check = 300;
69579 }
69580 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69581 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69582 rsp->qlen += rdp->qlen;
69583 rdp->n_cbs_orphaned += rdp->qlen;
69584 rdp->qlen_lazy = 0;
69585 - ACCESS_ONCE(rdp->qlen) = 0;
69586 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69587 }
69588
69589 /*
69590 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69591 }
69592 smp_mb(); /* List handling before counting for rcu_barrier(). */
69593 rdp->qlen_lazy -= count_lazy;
69594 - ACCESS_ONCE(rdp->qlen) -= count;
69595 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69596 rdp->n_cbs_invoked += count;
69597
69598 /* Reinstate batch limit if we have worked down the excess. */
69599 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69600 /*
69601 * Do RCU core processing for the current CPU.
69602 */
69603 -static void rcu_process_callbacks(struct softirq_action *unused)
69604 +static void rcu_process_callbacks(void)
69605 {
69606 struct rcu_state *rsp;
69607
69608 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69609 rdp = this_cpu_ptr(rsp->rda);
69610
69611 /* Add the callback to our list. */
69612 - ACCESS_ONCE(rdp->qlen)++;
69613 + ACCESS_ONCE_RW(rdp->qlen)++;
69614 if (lazy)
69615 rdp->qlen_lazy++;
69616 else
69617 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69618 }
69619 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69620
69621 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69622 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69623 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69624 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69625
69626 static int synchronize_sched_expedited_cpu_stop(void *data)
69627 {
69628 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69629 int firstsnap, s, snap, trycount = 0;
69630
69631 /* Note that atomic_inc_return() implies full memory barrier. */
69632 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69633 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69634 get_online_cpus();
69635 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69636
69637 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69638 }
69639
69640 /* Check to see if someone else did our work for us. */
69641 - s = atomic_read(&sync_sched_expedited_done);
69642 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69643 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69644 smp_mb(); /* ensure test happens before caller kfree */
69645 return;
69646 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69647 * grace period works for us.
69648 */
69649 get_online_cpus();
69650 - snap = atomic_read(&sync_sched_expedited_started);
69651 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69652 smp_mb(); /* ensure read is before try_stop_cpus(). */
69653 }
69654
69655 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69656 * than we did beat us to the punch.
69657 */
69658 do {
69659 - s = atomic_read(&sync_sched_expedited_done);
69660 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69661 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69662 smp_mb(); /* ensure test happens before caller kfree */
69663 break;
69664 }
69665 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69666 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69667
69668 put_online_cpus();
69669 }
69670 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69671 * ACCESS_ONCE() to prevent the compiler from speculating
69672 * the increment to precede the early-exit check.
69673 */
69674 - ACCESS_ONCE(rsp->n_barrier_done)++;
69675 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69676 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69677 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69678 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69679 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69680
69681 /* Increment ->n_barrier_done to prevent duplicate work. */
69682 smp_mb(); /* Keep increment after above mechanism. */
69683 - ACCESS_ONCE(rsp->n_barrier_done)++;
69684 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69685 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69686 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69687 smp_mb(); /* Keep increment before caller's subsequent code. */
69688 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69689 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69690 init_callback_list(rdp);
69691 rdp->qlen_lazy = 0;
69692 - ACCESS_ONCE(rdp->qlen) = 0;
69693 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69694 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69695 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69696 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69697 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69698 rdp->cpu = cpu;
69699 rdp->rsp = rsp;
69700 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69701 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69702 rdp->n_force_qs_snap = rsp->n_force_qs;
69703 rdp->blimit = blimit;
69704 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69705 - atomic_set(&rdp->dynticks->dynticks,
69706 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69707 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69708 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69709 rcu_prepare_for_idle_init(cpu);
69710 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69711
69712 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69713 index 4d29169..d104a3c 100644
69714 --- a/kernel/rcutree.h
69715 +++ b/kernel/rcutree.h
69716 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69717 long long dynticks_nesting; /* Track irq/process nesting level. */
69718 /* Process level is worth LLONG_MAX/2. */
69719 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69720 - atomic_t dynticks; /* Even value for idle, else odd. */
69721 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69722 #ifdef CONFIG_RCU_FAST_NO_HZ
69723 int dyntick_drain; /* Prepare-for-idle state variable. */
69724 unsigned long dyntick_holdoff;
69725 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69726 index 7f3244c..417d606 100644
69727 --- a/kernel/rcutree_plugin.h
69728 +++ b/kernel/rcutree_plugin.h
69729 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69730
69731 /* Clean up and exit. */
69732 smp_mb(); /* ensure expedited GP seen before counter increment. */
69733 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69734 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69735 unlock_mb_ret:
69736 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69737 mb_ret:
69738 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69739 index abffb48..cbfa6d3 100644
69740 --- a/kernel/rcutree_trace.c
69741 +++ b/kernel/rcutree_trace.c
69742 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69743 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69744 rdp->qs_pending);
69745 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69746 - atomic_read(&rdp->dynticks->dynticks),
69747 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69748 rdp->dynticks->dynticks_nesting,
69749 rdp->dynticks->dynticks_nmi_nesting,
69750 rdp->dynticks_fqs);
69751 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69752 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69753 rdp->qs_pending);
69754 seq_printf(m, ",%d,%llx,%d,%lu",
69755 - atomic_read(&rdp->dynticks->dynticks),
69756 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69757 rdp->dynticks->dynticks_nesting,
69758 rdp->dynticks->dynticks_nmi_nesting,
69759 rdp->dynticks_fqs);
69760 diff --git a/kernel/resource.c b/kernel/resource.c
69761 index 34d4588..10baa6a 100644
69762 --- a/kernel/resource.c
69763 +++ b/kernel/resource.c
69764 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69765
69766 static int __init ioresources_init(void)
69767 {
69768 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69769 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69770 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69771 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69772 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69773 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69774 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69775 +#endif
69776 +#else
69777 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69778 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69779 +#endif
69780 return 0;
69781 }
69782 __initcall(ioresources_init);
69783 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69784 index 98ec494..4241d6d 100644
69785 --- a/kernel/rtmutex-tester.c
69786 +++ b/kernel/rtmutex-tester.c
69787 @@ -20,7 +20,7 @@
69788 #define MAX_RT_TEST_MUTEXES 8
69789
69790 static spinlock_t rttest_lock;
69791 -static atomic_t rttest_event;
69792 +static atomic_unchecked_t rttest_event;
69793
69794 struct test_thread_data {
69795 int opcode;
69796 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69797
69798 case RTTEST_LOCKCONT:
69799 td->mutexes[td->opdata] = 1;
69800 - td->event = atomic_add_return(1, &rttest_event);
69801 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69802 return 0;
69803
69804 case RTTEST_RESET:
69805 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69806 return 0;
69807
69808 case RTTEST_RESETEVENT:
69809 - atomic_set(&rttest_event, 0);
69810 + atomic_set_unchecked(&rttest_event, 0);
69811 return 0;
69812
69813 default:
69814 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69815 return ret;
69816
69817 td->mutexes[id] = 1;
69818 - td->event = atomic_add_return(1, &rttest_event);
69819 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69820 rt_mutex_lock(&mutexes[id]);
69821 - td->event = atomic_add_return(1, &rttest_event);
69822 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69823 td->mutexes[id] = 4;
69824 return 0;
69825
69826 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69827 return ret;
69828
69829 td->mutexes[id] = 1;
69830 - td->event = atomic_add_return(1, &rttest_event);
69831 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69832 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69833 - td->event = atomic_add_return(1, &rttest_event);
69834 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69835 td->mutexes[id] = ret ? 0 : 4;
69836 return ret ? -EINTR : 0;
69837
69838 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69839 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69840 return ret;
69841
69842 - td->event = atomic_add_return(1, &rttest_event);
69843 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69844 rt_mutex_unlock(&mutexes[id]);
69845 - td->event = atomic_add_return(1, &rttest_event);
69846 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69847 td->mutexes[id] = 0;
69848 return 0;
69849
69850 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69851 break;
69852
69853 td->mutexes[dat] = 2;
69854 - td->event = atomic_add_return(1, &rttest_event);
69855 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69856 break;
69857
69858 default:
69859 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69860 return;
69861
69862 td->mutexes[dat] = 3;
69863 - td->event = atomic_add_return(1, &rttest_event);
69864 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69865 break;
69866
69867 case RTTEST_LOCKNOWAIT:
69868 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69869 return;
69870
69871 td->mutexes[dat] = 1;
69872 - td->event = atomic_add_return(1, &rttest_event);
69873 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69874 return;
69875
69876 default:
69877 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69878 index 0984a21..939f183 100644
69879 --- a/kernel/sched/auto_group.c
69880 +++ b/kernel/sched/auto_group.c
69881 @@ -11,7 +11,7 @@
69882
69883 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69884 static struct autogroup autogroup_default;
69885 -static atomic_t autogroup_seq_nr;
69886 +static atomic_unchecked_t autogroup_seq_nr;
69887
69888 void __init autogroup_init(struct task_struct *init_task)
69889 {
69890 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69891
69892 kref_init(&ag->kref);
69893 init_rwsem(&ag->lock);
69894 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69895 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69896 ag->tg = tg;
69897 #ifdef CONFIG_RT_GROUP_SCHED
69898 /*
69899 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69900 index 1a48cdb..d3949ff 100644
69901 --- a/kernel/sched/core.c
69902 +++ b/kernel/sched/core.c
69903 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69904 /* convert nice value [19,-20] to rlimit style value [1,40] */
69905 int nice_rlim = 20 - nice;
69906
69907 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69908 +
69909 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69910 capable(CAP_SYS_NICE));
69911 }
69912 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69913 if (nice > 19)
69914 nice = 19;
69915
69916 - if (increment < 0 && !can_nice(current, nice))
69917 + if (increment < 0 && (!can_nice(current, nice) ||
69918 + gr_handle_chroot_nice()))
69919 return -EPERM;
69920
69921 retval = security_task_setnice(current, nice);
69922 @@ -4290,6 +4293,7 @@ recheck:
69923 unsigned long rlim_rtprio =
69924 task_rlimit(p, RLIMIT_RTPRIO);
69925
69926 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69927 /* can't set/change the rt policy */
69928 if (policy != p->policy && !rlim_rtprio)
69929 return -EPERM;
69930 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69931 index 96e2b18..bb31eec 100644
69932 --- a/kernel/sched/fair.c
69933 +++ b/kernel/sched/fair.c
69934 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69935 * run_rebalance_domains is triggered when needed from the scheduler tick.
69936 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69937 */
69938 -static void run_rebalance_domains(struct softirq_action *h)
69939 +static void run_rebalance_domains(void)
69940 {
69941 int this_cpu = smp_processor_id();
69942 struct rq *this_rq = cpu_rq(this_cpu);
69943 diff --git a/kernel/signal.c b/kernel/signal.c
69944 index be4f856..453401c 100644
69945 --- a/kernel/signal.c
69946 +++ b/kernel/signal.c
69947 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69948
69949 int print_fatal_signals __read_mostly;
69950
69951 -static void __user *sig_handler(struct task_struct *t, int sig)
69952 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69953 {
69954 return t->sighand->action[sig - 1].sa.sa_handler;
69955 }
69956
69957 -static int sig_handler_ignored(void __user *handler, int sig)
69958 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69959 {
69960 /* Is it explicitly or implicitly ignored? */
69961 return handler == SIG_IGN ||
69962 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69963
69964 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69965 {
69966 - void __user *handler;
69967 + __sighandler_t handler;
69968
69969 handler = sig_handler(t, sig);
69970
69971 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69972 atomic_inc(&user->sigpending);
69973 rcu_read_unlock();
69974
69975 + if (!override_rlimit)
69976 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69977 +
69978 if (override_rlimit ||
69979 atomic_read(&user->sigpending) <=
69980 task_rlimit(t, RLIMIT_SIGPENDING)) {
69981 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69982
69983 int unhandled_signal(struct task_struct *tsk, int sig)
69984 {
69985 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69986 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69987 if (is_global_init(tsk))
69988 return 1;
69989 if (handler != SIG_IGN && handler != SIG_DFL)
69990 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69991 }
69992 }
69993
69994 + /* allow glibc communication via tgkill to other threads in our
69995 + thread group */
69996 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69997 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69998 + && gr_handle_signal(t, sig))
69999 + return -EPERM;
70000 +
70001 return security_task_kill(t, info, sig, 0);
70002 }
70003
70004 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70005 return send_signal(sig, info, p, 1);
70006 }
70007
70008 -static int
70009 +int
70010 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70011 {
70012 return send_signal(sig, info, t, 0);
70013 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70014 unsigned long int flags;
70015 int ret, blocked, ignored;
70016 struct k_sigaction *action;
70017 + int is_unhandled = 0;
70018
70019 spin_lock_irqsave(&t->sighand->siglock, flags);
70020 action = &t->sighand->action[sig-1];
70021 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70022 }
70023 if (action->sa.sa_handler == SIG_DFL)
70024 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70025 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70026 + is_unhandled = 1;
70027 ret = specific_send_sig_info(sig, info, t);
70028 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70029
70030 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70031 + normal operation */
70032 + if (is_unhandled) {
70033 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70034 + gr_handle_crash(t, sig);
70035 + }
70036 +
70037 return ret;
70038 }
70039
70040 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70041 ret = check_kill_permission(sig, info, p);
70042 rcu_read_unlock();
70043
70044 - if (!ret && sig)
70045 + if (!ret && sig) {
70046 ret = do_send_sig_info(sig, info, p, true);
70047 + if (!ret)
70048 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70049 + }
70050
70051 return ret;
70052 }
70053 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70054 int error = -ESRCH;
70055
70056 rcu_read_lock();
70057 - p = find_task_by_vpid(pid);
70058 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70059 + /* allow glibc communication via tgkill to other threads in our
70060 + thread group */
70061 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70062 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70063 + p = find_task_by_vpid_unrestricted(pid);
70064 + else
70065 +#endif
70066 + p = find_task_by_vpid(pid);
70067 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70068 error = check_kill_permission(sig, info, p);
70069 /*
70070 diff --git a/kernel/softirq.c b/kernel/softirq.c
70071 index b73e681..645ab62 100644
70072 --- a/kernel/softirq.c
70073 +++ b/kernel/softirq.c
70074 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70075
70076 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70077
70078 -char *softirq_to_name[NR_SOFTIRQS] = {
70079 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70080 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70081 "TASKLET", "SCHED", "HRTIMER", "RCU"
70082 };
70083 @@ -243,7 +243,7 @@ restart:
70084 kstat_incr_softirqs_this_cpu(vec_nr);
70085
70086 trace_softirq_entry(vec_nr);
70087 - h->action(h);
70088 + h->action();
70089 trace_softirq_exit(vec_nr);
70090 if (unlikely(prev_count != preempt_count())) {
70091 printk(KERN_ERR "huh, entered softirq %u %s %p"
70092 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70093 or_softirq_pending(1UL << nr);
70094 }
70095
70096 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70097 +void open_softirq(int nr, void (*action)(void))
70098 {
70099 - softirq_vec[nr].action = action;
70100 + pax_open_kernel();
70101 + *(void **)&softirq_vec[nr].action = action;
70102 + pax_close_kernel();
70103 }
70104
70105 /*
70106 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70107
70108 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70109
70110 -static void tasklet_action(struct softirq_action *a)
70111 +static void tasklet_action(void)
70112 {
70113 struct tasklet_struct *list;
70114
70115 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70116 }
70117 }
70118
70119 -static void tasklet_hi_action(struct softirq_action *a)
70120 +static void tasklet_hi_action(void)
70121 {
70122 struct tasklet_struct *list;
70123
70124 diff --git a/kernel/srcu.c b/kernel/srcu.c
70125 index 2095be3..9a5b89d 100644
70126 --- a/kernel/srcu.c
70127 +++ b/kernel/srcu.c
70128 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70129 preempt_disable();
70130 idx = rcu_dereference_index_check(sp->completed,
70131 rcu_read_lock_sched_held()) & 0x1;
70132 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70133 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70134 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70135 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70136 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70137 preempt_enable();
70138 return idx;
70139 }
70140 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70141 {
70142 preempt_disable();
70143 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70144 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70145 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70146 preempt_enable();
70147 }
70148 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70149 diff --git a/kernel/sys.c b/kernel/sys.c
70150 index 909148a..cd51acf 100644
70151 --- a/kernel/sys.c
70152 +++ b/kernel/sys.c
70153 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70154 error = -EACCES;
70155 goto out;
70156 }
70157 +
70158 + if (gr_handle_chroot_setpriority(p, niceval)) {
70159 + error = -EACCES;
70160 + goto out;
70161 + }
70162 +
70163 no_nice = security_task_setnice(p, niceval);
70164 if (no_nice) {
70165 error = no_nice;
70166 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70167 goto error;
70168 }
70169
70170 + if (gr_check_group_change(new->gid, new->egid, -1))
70171 + goto error;
70172 +
70173 if (rgid != (gid_t) -1 ||
70174 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70175 new->sgid = new->egid;
70176 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70177 old = current_cred();
70178
70179 retval = -EPERM;
70180 +
70181 + if (gr_check_group_change(kgid, kgid, kgid))
70182 + goto error;
70183 +
70184 if (nsown_capable(CAP_SETGID))
70185 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70186 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70187 @@ -647,7 +660,7 @@ error:
70188 /*
70189 * change the user struct in a credentials set to match the new UID
70190 */
70191 -static int set_user(struct cred *new)
70192 +int set_user(struct cred *new)
70193 {
70194 struct user_struct *new_user;
70195
70196 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70197 goto error;
70198 }
70199
70200 + if (gr_check_user_change(new->uid, new->euid, -1))
70201 + goto error;
70202 +
70203 if (!uid_eq(new->uid, old->uid)) {
70204 retval = set_user(new);
70205 if (retval < 0)
70206 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70207 old = current_cred();
70208
70209 retval = -EPERM;
70210 +
70211 + if (gr_check_crash_uid(kuid))
70212 + goto error;
70213 + if (gr_check_user_change(kuid, kuid, kuid))
70214 + goto error;
70215 +
70216 if (nsown_capable(CAP_SETUID)) {
70217 new->suid = new->uid = kuid;
70218 if (!uid_eq(kuid, old->uid)) {
70219 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70220 goto error;
70221 }
70222
70223 + if (gr_check_user_change(kruid, keuid, -1))
70224 + goto error;
70225 +
70226 if (ruid != (uid_t) -1) {
70227 new->uid = kruid;
70228 if (!uid_eq(kruid, old->uid)) {
70229 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70230 goto error;
70231 }
70232
70233 + if (gr_check_group_change(krgid, kegid, -1))
70234 + goto error;
70235 +
70236 if (rgid != (gid_t) -1)
70237 new->gid = krgid;
70238 if (egid != (gid_t) -1)
70239 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70240 if (!uid_valid(kuid))
70241 return old_fsuid;
70242
70243 + if (gr_check_user_change(-1, -1, kuid))
70244 + goto error;
70245 +
70246 new = prepare_creds();
70247 if (!new)
70248 return old_fsuid;
70249 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70250 }
70251 }
70252
70253 +error:
70254 abort_creds(new);
70255 return old_fsuid;
70256
70257 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70258 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70259 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70260 nsown_capable(CAP_SETGID)) {
70261 + if (gr_check_group_change(-1, -1, kgid))
70262 + goto error;
70263 +
70264 if (!gid_eq(kgid, old->fsgid)) {
70265 new->fsgid = kgid;
70266 goto change_okay;
70267 }
70268 }
70269
70270 +error:
70271 abort_creds(new);
70272 return old_fsgid;
70273
70274 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70275 return -EFAULT;
70276
70277 down_read(&uts_sem);
70278 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70279 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70280 __OLD_UTS_LEN);
70281 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70282 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70283 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70284 __OLD_UTS_LEN);
70285 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70286 - error |= __copy_to_user(&name->release, &utsname()->release,
70287 + error |= __copy_to_user(name->release, &utsname()->release,
70288 __OLD_UTS_LEN);
70289 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70290 - error |= __copy_to_user(&name->version, &utsname()->version,
70291 + error |= __copy_to_user(name->version, &utsname()->version,
70292 __OLD_UTS_LEN);
70293 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70294 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70295 + error |= __copy_to_user(name->machine, &utsname()->machine,
70296 __OLD_UTS_LEN);
70297 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70298 up_read(&uts_sem);
70299 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70300 error = get_dumpable(me->mm);
70301 break;
70302 case PR_SET_DUMPABLE:
70303 - if (arg2 < 0 || arg2 > 1) {
70304 + if (arg2 > 1) {
70305 error = -EINVAL;
70306 break;
70307 }
70308 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70309 index 87174ef..68cbb82 100644
70310 --- a/kernel/sysctl.c
70311 +++ b/kernel/sysctl.c
70312 @@ -92,7 +92,6 @@
70313
70314
70315 #if defined(CONFIG_SYSCTL)
70316 -
70317 /* External variables not in a header file. */
70318 extern int sysctl_overcommit_memory;
70319 extern int sysctl_overcommit_ratio;
70320 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70321 void __user *buffer, size_t *lenp, loff_t *ppos);
70322 #endif
70323
70324 -#ifdef CONFIG_PRINTK
70325 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70326 void __user *buffer, size_t *lenp, loff_t *ppos);
70327 -#endif
70328
70329 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70330 void __user *buffer, size_t *lenp, loff_t *ppos);
70331 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70332
70333 #endif
70334
70335 +extern struct ctl_table grsecurity_table[];
70336 +
70337 static struct ctl_table kern_table[];
70338 static struct ctl_table vm_table[];
70339 static struct ctl_table fs_table[];
70340 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70341 int sysctl_legacy_va_layout;
70342 #endif
70343
70344 +#ifdef CONFIG_PAX_SOFTMODE
70345 +static ctl_table pax_table[] = {
70346 + {
70347 + .procname = "softmode",
70348 + .data = &pax_softmode,
70349 + .maxlen = sizeof(unsigned int),
70350 + .mode = 0600,
70351 + .proc_handler = &proc_dointvec,
70352 + },
70353 +
70354 + { }
70355 +};
70356 +#endif
70357 +
70358 /* The default sysctl tables: */
70359
70360 static struct ctl_table sysctl_base_table[] = {
70361 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70362 #endif
70363
70364 static struct ctl_table kern_table[] = {
70365 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70366 + {
70367 + .procname = "grsecurity",
70368 + .mode = 0500,
70369 + .child = grsecurity_table,
70370 + },
70371 +#endif
70372 +
70373 +#ifdef CONFIG_PAX_SOFTMODE
70374 + {
70375 + .procname = "pax",
70376 + .mode = 0500,
70377 + .child = pax_table,
70378 + },
70379 +#endif
70380 +
70381 {
70382 .procname = "sched_child_runs_first",
70383 .data = &sysctl_sched_child_runs_first,
70384 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70385 .data = &modprobe_path,
70386 .maxlen = KMOD_PATH_LEN,
70387 .mode = 0644,
70388 - .proc_handler = proc_dostring,
70389 + .proc_handler = proc_dostring_modpriv,
70390 },
70391 {
70392 .procname = "modules_disabled",
70393 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70394 .extra1 = &zero,
70395 .extra2 = &one,
70396 },
70397 +#endif
70398 {
70399 .procname = "kptr_restrict",
70400 .data = &kptr_restrict,
70401 .maxlen = sizeof(int),
70402 .mode = 0644,
70403 .proc_handler = proc_dointvec_minmax_sysadmin,
70404 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70405 + .extra1 = &two,
70406 +#else
70407 .extra1 = &zero,
70408 +#endif
70409 .extra2 = &two,
70410 },
70411 -#endif
70412 {
70413 .procname = "ngroups_max",
70414 .data = &ngroups_max,
70415 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70416 .proc_handler = proc_dointvec_minmax,
70417 .extra1 = &zero,
70418 },
70419 + {
70420 + .procname = "heap_stack_gap",
70421 + .data = &sysctl_heap_stack_gap,
70422 + .maxlen = sizeof(sysctl_heap_stack_gap),
70423 + .mode = 0644,
70424 + .proc_handler = proc_doulongvec_minmax,
70425 + },
70426 #else
70427 {
70428 .procname = "nr_trim_pages",
70429 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70430 buffer, lenp, ppos);
70431 }
70432
70433 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70434 + void __user *buffer, size_t *lenp, loff_t *ppos)
70435 +{
70436 + if (write && !capable(CAP_SYS_MODULE))
70437 + return -EPERM;
70438 +
70439 + return _proc_do_string(table->data, table->maxlen, write,
70440 + buffer, lenp, ppos);
70441 +}
70442 +
70443 static size_t proc_skip_spaces(char **buf)
70444 {
70445 size_t ret;
70446 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70447 len = strlen(tmp);
70448 if (len > *size)
70449 len = *size;
70450 + if (len > sizeof(tmp))
70451 + len = sizeof(tmp);
70452 if (copy_to_user(*buf, tmp, len))
70453 return -EFAULT;
70454 *size -= len;
70455 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70456 return err;
70457 }
70458
70459 -#ifdef CONFIG_PRINTK
70460 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70461 void __user *buffer, size_t *lenp, loff_t *ppos)
70462 {
70463 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70464
70465 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70466 }
70467 -#endif
70468
70469 struct do_proc_dointvec_minmax_conv_param {
70470 int *min;
70471 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70472 *i = val;
70473 } else {
70474 val = convdiv * (*i) / convmul;
70475 - if (!first)
70476 + if (!first) {
70477 err = proc_put_char(&buffer, &left, '\t');
70478 + if (err)
70479 + break;
70480 + }
70481 err = proc_put_long(&buffer, &left, val, false);
70482 if (err)
70483 break;
70484 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70485 return -ENOSYS;
70486 }
70487
70488 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70489 + void __user *buffer, size_t *lenp, loff_t *ppos)
70490 +{
70491 + return -ENOSYS;
70492 +}
70493 +
70494 int proc_dointvec(struct ctl_table *table, int write,
70495 void __user *buffer, size_t *lenp, loff_t *ppos)
70496 {
70497 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70498 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70499 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70500 EXPORT_SYMBOL(proc_dostring);
70501 +EXPORT_SYMBOL(proc_dostring_modpriv);
70502 EXPORT_SYMBOL(proc_doulongvec_minmax);
70503 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70504 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70505 index 65bdcf1..21eb831 100644
70506 --- a/kernel/sysctl_binary.c
70507 +++ b/kernel/sysctl_binary.c
70508 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70509 int i;
70510
70511 set_fs(KERNEL_DS);
70512 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70513 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70514 set_fs(old_fs);
70515 if (result < 0)
70516 goto out_kfree;
70517 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70518 }
70519
70520 set_fs(KERNEL_DS);
70521 - result = vfs_write(file, buffer, str - buffer, &pos);
70522 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70523 set_fs(old_fs);
70524 if (result < 0)
70525 goto out_kfree;
70526 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70527 int i;
70528
70529 set_fs(KERNEL_DS);
70530 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70531 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70532 set_fs(old_fs);
70533 if (result < 0)
70534 goto out_kfree;
70535 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70536 }
70537
70538 set_fs(KERNEL_DS);
70539 - result = vfs_write(file, buffer, str - buffer, &pos);
70540 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70541 set_fs(old_fs);
70542 if (result < 0)
70543 goto out_kfree;
70544 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70545 int i;
70546
70547 set_fs(KERNEL_DS);
70548 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70549 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70550 set_fs(old_fs);
70551 if (result < 0)
70552 goto out;
70553 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70554 __le16 dnaddr;
70555
70556 set_fs(KERNEL_DS);
70557 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70558 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70559 set_fs(old_fs);
70560 if (result < 0)
70561 goto out;
70562 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70563 le16_to_cpu(dnaddr) & 0x3ff);
70564
70565 set_fs(KERNEL_DS);
70566 - result = vfs_write(file, buf, len, &pos);
70567 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70568 set_fs(old_fs);
70569 if (result < 0)
70570 goto out;
70571 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70572 index d0a3279..db0ad99 100644
70573 --- a/kernel/taskstats.c
70574 +++ b/kernel/taskstats.c
70575 @@ -27,9 +27,12 @@
70576 #include <linux/cgroup.h>
70577 #include <linux/fs.h>
70578 #include <linux/file.h>
70579 +#include <linux/grsecurity.h>
70580 #include <net/genetlink.h>
70581 #include <linux/atomic.h>
70582
70583 +extern int gr_is_taskstats_denied(int pid);
70584 +
70585 /*
70586 * Maximum length of a cpumask that can be specified in
70587 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70588 @@ -561,6 +564,9 @@ err:
70589
70590 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70591 {
70592 + if (gr_is_taskstats_denied(current->pid))
70593 + return -EACCES;
70594 +
70595 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70596 return cmd_attr_register_cpumask(info);
70597 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70598 diff --git a/kernel/time.c b/kernel/time.c
70599 index ba744cf..267b7c5 100644
70600 --- a/kernel/time.c
70601 +++ b/kernel/time.c
70602 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70603 return error;
70604
70605 if (tz) {
70606 + /* we log in do_settimeofday called below, so don't log twice
70607 + */
70608 + if (!tv)
70609 + gr_log_timechange();
70610 +
70611 sys_tz = *tz;
70612 update_vsyscall_tz();
70613 if (firsttime) {
70614 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70615 index aa27d39..34d221c 100644
70616 --- a/kernel/time/alarmtimer.c
70617 +++ b/kernel/time/alarmtimer.c
70618 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70619 struct platform_device *pdev;
70620 int error = 0;
70621 int i;
70622 - struct k_clock alarm_clock = {
70623 + static struct k_clock alarm_clock = {
70624 .clock_getres = alarm_clock_getres,
70625 .clock_get = alarm_clock_get,
70626 .timer_create = alarm_timer_create,
70627 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70628 index f113755..ec24223 100644
70629 --- a/kernel/time/tick-broadcast.c
70630 +++ b/kernel/time/tick-broadcast.c
70631 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70632 * then clear the broadcast bit.
70633 */
70634 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70635 - int cpu = smp_processor_id();
70636 + cpu = smp_processor_id();
70637
70638 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70639 tick_broadcast_clear_oneshot(cpu);
70640 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70641 index f791637..00051de 100644
70642 --- a/kernel/time/timekeeping.c
70643 +++ b/kernel/time/timekeeping.c
70644 @@ -14,6 +14,7 @@
70645 #include <linux/init.h>
70646 #include <linux/mm.h>
70647 #include <linux/sched.h>
70648 +#include <linux/grsecurity.h>
70649 #include <linux/syscore_ops.h>
70650 #include <linux/clocksource.h>
70651 #include <linux/jiffies.h>
70652 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70653 if (!timespec_valid_strict(tv))
70654 return -EINVAL;
70655
70656 + gr_log_timechange();
70657 +
70658 write_seqlock_irqsave(&tk->lock, flags);
70659
70660 timekeeping_forward_now(tk);
70661 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70662 index af5a7e9..715611a 100644
70663 --- a/kernel/time/timer_list.c
70664 +++ b/kernel/time/timer_list.c
70665 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70666
70667 static void print_name_offset(struct seq_file *m, void *sym)
70668 {
70669 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70670 + SEQ_printf(m, "<%p>", NULL);
70671 +#else
70672 char symname[KSYM_NAME_LEN];
70673
70674 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70675 SEQ_printf(m, "<%pK>", sym);
70676 else
70677 SEQ_printf(m, "%s", symname);
70678 +#endif
70679 }
70680
70681 static void
70682 @@ -112,7 +116,11 @@ next_one:
70683 static void
70684 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70685 {
70686 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70687 + SEQ_printf(m, " .base: %p\n", NULL);
70688 +#else
70689 SEQ_printf(m, " .base: %pK\n", base);
70690 +#endif
70691 SEQ_printf(m, " .index: %d\n",
70692 base->index);
70693 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70694 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70695 {
70696 struct proc_dir_entry *pe;
70697
70698 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70699 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70700 +#else
70701 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70702 +#endif
70703 if (!pe)
70704 return -ENOMEM;
70705 return 0;
70706 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70707 index 0b537f2..40d6c20 100644
70708 --- a/kernel/time/timer_stats.c
70709 +++ b/kernel/time/timer_stats.c
70710 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70711 static unsigned long nr_entries;
70712 static struct entry entries[MAX_ENTRIES];
70713
70714 -static atomic_t overflow_count;
70715 +static atomic_unchecked_t overflow_count;
70716
70717 /*
70718 * The entries are in a hash-table, for fast lookup:
70719 @@ -140,7 +140,7 @@ static void reset_entries(void)
70720 nr_entries = 0;
70721 memset(entries, 0, sizeof(entries));
70722 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70723 - atomic_set(&overflow_count, 0);
70724 + atomic_set_unchecked(&overflow_count, 0);
70725 }
70726
70727 static struct entry *alloc_entry(void)
70728 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70729 if (likely(entry))
70730 entry->count++;
70731 else
70732 - atomic_inc(&overflow_count);
70733 + atomic_inc_unchecked(&overflow_count);
70734
70735 out_unlock:
70736 raw_spin_unlock_irqrestore(lock, flags);
70737 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70738
70739 static void print_name_offset(struct seq_file *m, unsigned long addr)
70740 {
70741 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70742 + seq_printf(m, "<%p>", NULL);
70743 +#else
70744 char symname[KSYM_NAME_LEN];
70745
70746 if (lookup_symbol_name(addr, symname) < 0)
70747 - seq_printf(m, "<%p>", (void *)addr);
70748 + seq_printf(m, "<%pK>", (void *)addr);
70749 else
70750 seq_printf(m, "%s", symname);
70751 +#endif
70752 }
70753
70754 static int tstats_show(struct seq_file *m, void *v)
70755 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70756
70757 seq_puts(m, "Timer Stats Version: v0.2\n");
70758 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70759 - if (atomic_read(&overflow_count))
70760 + if (atomic_read_unchecked(&overflow_count))
70761 seq_printf(m, "Overflow: %d entries\n",
70762 - atomic_read(&overflow_count));
70763 + atomic_read_unchecked(&overflow_count));
70764
70765 for (i = 0; i < nr_entries; i++) {
70766 entry = entries + i;
70767 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70768 {
70769 struct proc_dir_entry *pe;
70770
70771 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70772 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70773 +#else
70774 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70775 +#endif
70776 if (!pe)
70777 return -ENOMEM;
70778 return 0;
70779 diff --git a/kernel/timer.c b/kernel/timer.c
70780 index 46ef2b1..ad081f144 100644
70781 --- a/kernel/timer.c
70782 +++ b/kernel/timer.c
70783 @@ -1377,7 +1377,7 @@ void update_process_times(int user_tick)
70784 /*
70785 * This function runs timers and the timer-tq in bottom half context.
70786 */
70787 -static void run_timer_softirq(struct softirq_action *h)
70788 +static void run_timer_softirq(void)
70789 {
70790 struct tvec_base *base = __this_cpu_read(tvec_bases);
70791
70792 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70793 index c0bd030..62a1927 100644
70794 --- a/kernel/trace/blktrace.c
70795 +++ b/kernel/trace/blktrace.c
70796 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70797 struct blk_trace *bt = filp->private_data;
70798 char buf[16];
70799
70800 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70801 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70802
70803 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70804 }
70805 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70806 return 1;
70807
70808 bt = buf->chan->private_data;
70809 - atomic_inc(&bt->dropped);
70810 + atomic_inc_unchecked(&bt->dropped);
70811 return 0;
70812 }
70813
70814 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70815
70816 bt->dir = dir;
70817 bt->dev = dev;
70818 - atomic_set(&bt->dropped, 0);
70819 + atomic_set_unchecked(&bt->dropped, 0);
70820
70821 ret = -EIO;
70822 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70823 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70824 index b4f20fb..483c5fa 100644
70825 --- a/kernel/trace/ftrace.c
70826 +++ b/kernel/trace/ftrace.c
70827 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70828 if (unlikely(ftrace_disabled))
70829 return 0;
70830
70831 + ret = ftrace_arch_code_modify_prepare();
70832 + FTRACE_WARN_ON(ret);
70833 + if (ret)
70834 + return 0;
70835 +
70836 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70837 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70838 if (ret) {
70839 ftrace_bug(ret, ip);
70840 - return 0;
70841 }
70842 - return 1;
70843 + return ret ? 0 : 1;
70844 }
70845
70846 /*
70847 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70848
70849 int
70850 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70851 - void *data)
70852 + void *data)
70853 {
70854 struct ftrace_func_probe *entry;
70855 struct ftrace_page *pg;
70856 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70857 if (!count)
70858 return 0;
70859
70860 + pax_open_kernel();
70861 sort(start, count, sizeof(*start),
70862 ftrace_cmp_ips, ftrace_swap_ips);
70863 + pax_close_kernel();
70864
70865 start_pg = ftrace_allocate_pages(count);
70866 if (!start_pg)
70867 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70868 index 5c38c81..88012af 100644
70869 --- a/kernel/trace/trace.c
70870 +++ b/kernel/trace/trace.c
70871 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70872 };
70873 #endif
70874
70875 -static struct dentry *d_tracer;
70876 -
70877 struct dentry *tracing_init_dentry(void)
70878 {
70879 + static struct dentry *d_tracer;
70880 static int once;
70881
70882 if (d_tracer)
70883 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
70884 return d_tracer;
70885 }
70886
70887 -static struct dentry *d_percpu;
70888 -
70889 struct dentry *tracing_dentry_percpu(void)
70890 {
70891 + static struct dentry *d_percpu;
70892 static int once;
70893 struct dentry *d_tracer;
70894
70895 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70896 index 29111da..d190fe2 100644
70897 --- a/kernel/trace/trace_events.c
70898 +++ b/kernel/trace/trace_events.c
70899 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70900 struct ftrace_module_file_ops {
70901 struct list_head list;
70902 struct module *mod;
70903 - struct file_operations id;
70904 - struct file_operations enable;
70905 - struct file_operations format;
70906 - struct file_operations filter;
70907 };
70908
70909 static struct ftrace_module_file_ops *
70910 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70911
70912 file_ops->mod = mod;
70913
70914 - file_ops->id = ftrace_event_id_fops;
70915 - file_ops->id.owner = mod;
70916 -
70917 - file_ops->enable = ftrace_enable_fops;
70918 - file_ops->enable.owner = mod;
70919 -
70920 - file_ops->filter = ftrace_event_filter_fops;
70921 - file_ops->filter.owner = mod;
70922 -
70923 - file_ops->format = ftrace_event_format_fops;
70924 - file_ops->format.owner = mod;
70925 + pax_open_kernel();
70926 + *(void **)&mod->trace_id.owner = mod;
70927 + *(void **)&mod->trace_enable.owner = mod;
70928 + *(void **)&mod->trace_filter.owner = mod;
70929 + *(void **)&mod->trace_format.owner = mod;
70930 + pax_close_kernel();
70931
70932 list_add(&file_ops->list, &ftrace_module_file_list);
70933
70934 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70935
70936 for_each_event(call, start, end) {
70937 __trace_add_event_call(*call, mod,
70938 - &file_ops->id, &file_ops->enable,
70939 - &file_ops->filter, &file_ops->format);
70940 + &mod->trace_id, &mod->trace_enable,
70941 + &mod->trace_filter, &mod->trace_format);
70942 }
70943 }
70944
70945 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70946 index fd3c8aa..5f324a6 100644
70947 --- a/kernel/trace/trace_mmiotrace.c
70948 +++ b/kernel/trace/trace_mmiotrace.c
70949 @@ -24,7 +24,7 @@ struct header_iter {
70950 static struct trace_array *mmio_trace_array;
70951 static bool overrun_detected;
70952 static unsigned long prev_overruns;
70953 -static atomic_t dropped_count;
70954 +static atomic_unchecked_t dropped_count;
70955
70956 static void mmio_reset_data(struct trace_array *tr)
70957 {
70958 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70959
70960 static unsigned long count_overruns(struct trace_iterator *iter)
70961 {
70962 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70963 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70964 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70965
70966 if (over > prev_overruns)
70967 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70968 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70969 sizeof(*entry), 0, pc);
70970 if (!event) {
70971 - atomic_inc(&dropped_count);
70972 + atomic_inc_unchecked(&dropped_count);
70973 return;
70974 }
70975 entry = ring_buffer_event_data(event);
70976 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70977 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
70978 sizeof(*entry), 0, pc);
70979 if (!event) {
70980 - atomic_inc(&dropped_count);
70981 + atomic_inc_unchecked(&dropped_count);
70982 return;
70983 }
70984 entry = ring_buffer_event_data(event);
70985 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
70986 index 123b189..97b81f5 100644
70987 --- a/kernel/trace/trace_output.c
70988 +++ b/kernel/trace/trace_output.c
70989 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
70990
70991 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
70992 if (!IS_ERR(p)) {
70993 - p = mangle_path(s->buffer + s->len, p, "\n");
70994 + p = mangle_path(s->buffer + s->len, p, "\n\\");
70995 if (p) {
70996 s->len = p - s->buffer;
70997 return 1;
70998 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
70999 index d4545f4..a9010a1 100644
71000 --- a/kernel/trace/trace_stack.c
71001 +++ b/kernel/trace/trace_stack.c
71002 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71003 return;
71004
71005 /* we do not handle interrupt stacks yet */
71006 - if (!object_is_on_stack(&this_size))
71007 + if (!object_starts_on_stack(&this_size))
71008 return;
71009
71010 local_irq_save(flags);
71011 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71012 index 872bd6d..31601a2 100644
71013 --- a/kernel/workqueue.c
71014 +++ b/kernel/workqueue.c
71015 @@ -1422,7 +1422,7 @@ retry:
71016 /* morph UNBOUND to REBIND atomically */
71017 worker_flags &= ~WORKER_UNBOUND;
71018 worker_flags |= WORKER_REBIND;
71019 - ACCESS_ONCE(worker->flags) = worker_flags;
71020 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71021
71022 idle_rebind.cnt++;
71023 worker->idle_rebind = &idle_rebind;
71024 @@ -1448,7 +1448,7 @@ retry:
71025 /* morph UNBOUND to REBIND atomically */
71026 worker_flags &= ~WORKER_UNBOUND;
71027 worker_flags |= WORKER_REBIND;
71028 - ACCESS_ONCE(worker->flags) = worker_flags;
71029 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71030
71031 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71032 work_data_bits(rebind_work)))
71033 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71034 index 2403a63..5c4be4c 100644
71035 --- a/lib/Kconfig.debug
71036 +++ b/lib/Kconfig.debug
71037 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71038 depends on DEBUG_KERNEL
71039 depends on STACKTRACE_SUPPORT
71040 depends on PROC_FS
71041 + depends on !GRKERNSEC_HIDESYM
71042 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71043 select KALLSYMS
71044 select KALLSYMS_ALL
71045 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71046
71047 config PROVIDE_OHCI1394_DMA_INIT
71048 bool "Remote debugging over FireWire early on boot"
71049 - depends on PCI && X86
71050 + depends on PCI && X86 && !GRKERNSEC
71051 help
71052 If you want to debug problems which hang or crash the kernel early
71053 on boot and the crashing machine has a FireWire port, you can use
71054 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71055
71056 config FIREWIRE_OHCI_REMOTE_DMA
71057 bool "Remote debugging over FireWire with firewire-ohci"
71058 - depends on FIREWIRE_OHCI
71059 + depends on FIREWIRE_OHCI && !GRKERNSEC
71060 help
71061 This option lets you use the FireWire bus for remote debugging
71062 with help of the firewire-ohci driver. It enables unfiltered
71063 diff --git a/lib/bitmap.c b/lib/bitmap.c
71064 index 06fdfa1..97c5c7d 100644
71065 --- a/lib/bitmap.c
71066 +++ b/lib/bitmap.c
71067 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71068 {
71069 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71070 u32 chunk;
71071 - const char __user __force *ubuf = (const char __user __force *)buf;
71072 + const char __user *ubuf = (const char __force_user *)buf;
71073
71074 bitmap_zero(maskp, nmaskbits);
71075
71076 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71077 {
71078 if (!access_ok(VERIFY_READ, ubuf, ulen))
71079 return -EFAULT;
71080 - return __bitmap_parse((const char __force *)ubuf,
71081 + return __bitmap_parse((const char __force_kernel *)ubuf,
71082 ulen, 1, maskp, nmaskbits);
71083
71084 }
71085 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71086 {
71087 unsigned a, b;
71088 int c, old_c, totaldigits;
71089 - const char __user __force *ubuf = (const char __user __force *)buf;
71090 + const char __user *ubuf = (const char __force_user *)buf;
71091 int exp_digit, in_range;
71092
71093 totaldigits = c = 0;
71094 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71095 {
71096 if (!access_ok(VERIFY_READ, ubuf, ulen))
71097 return -EFAULT;
71098 - return __bitmap_parselist((const char __force *)ubuf,
71099 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71100 ulen, 1, maskp, nmaskbits);
71101 }
71102 EXPORT_SYMBOL(bitmap_parselist_user);
71103 diff --git a/lib/bug.c b/lib/bug.c
71104 index a28c141..2bd3d95 100644
71105 --- a/lib/bug.c
71106 +++ b/lib/bug.c
71107 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71108 return BUG_TRAP_TYPE_NONE;
71109
71110 bug = find_bug(bugaddr);
71111 + if (!bug)
71112 + return BUG_TRAP_TYPE_NONE;
71113
71114 file = NULL;
71115 line = 0;
71116 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71117 index d11808c..dc2d6f8 100644
71118 --- a/lib/debugobjects.c
71119 +++ b/lib/debugobjects.c
71120 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71121 if (limit > 4)
71122 return;
71123
71124 - is_on_stack = object_is_on_stack(addr);
71125 + is_on_stack = object_starts_on_stack(addr);
71126 if (is_on_stack == onstack)
71127 return;
71128
71129 diff --git a/lib/devres.c b/lib/devres.c
71130 index 80b9c76..9e32279 100644
71131 --- a/lib/devres.c
71132 +++ b/lib/devres.c
71133 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71134 void devm_iounmap(struct device *dev, void __iomem *addr)
71135 {
71136 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71137 - (void *)addr));
71138 + (void __force *)addr));
71139 iounmap(addr);
71140 }
71141 EXPORT_SYMBOL(devm_iounmap);
71142 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71143 {
71144 ioport_unmap(addr);
71145 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71146 - devm_ioport_map_match, (void *)addr));
71147 + devm_ioport_map_match, (void __force *)addr));
71148 }
71149 EXPORT_SYMBOL(devm_ioport_unmap);
71150
71151 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71152 index 66ce414..6f0a0dd 100644
71153 --- a/lib/dma-debug.c
71154 +++ b/lib/dma-debug.c
71155 @@ -924,7 +924,7 @@ out:
71156
71157 static void check_for_stack(struct device *dev, void *addr)
71158 {
71159 - if (object_is_on_stack(addr))
71160 + if (object_starts_on_stack(addr))
71161 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71162 "stack [addr=%p]\n", addr);
71163 }
71164 diff --git a/lib/inflate.c b/lib/inflate.c
71165 index 013a761..c28f3fc 100644
71166 --- a/lib/inflate.c
71167 +++ b/lib/inflate.c
71168 @@ -269,7 +269,7 @@ static void free(void *where)
71169 malloc_ptr = free_mem_ptr;
71170 }
71171 #else
71172 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71173 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71174 #define free(a) kfree(a)
71175 #endif
71176
71177 diff --git a/lib/ioremap.c b/lib/ioremap.c
71178 index 0c9216c..863bd89 100644
71179 --- a/lib/ioremap.c
71180 +++ b/lib/ioremap.c
71181 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71182 unsigned long next;
71183
71184 phys_addr -= addr;
71185 - pmd = pmd_alloc(&init_mm, pud, addr);
71186 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71187 if (!pmd)
71188 return -ENOMEM;
71189 do {
71190 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71191 unsigned long next;
71192
71193 phys_addr -= addr;
71194 - pud = pud_alloc(&init_mm, pgd, addr);
71195 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71196 if (!pud)
71197 return -ENOMEM;
71198 do {
71199 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71200 index bd2bea9..6b3c95e 100644
71201 --- a/lib/is_single_threaded.c
71202 +++ b/lib/is_single_threaded.c
71203 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71204 struct task_struct *p, *t;
71205 bool ret;
71206
71207 + if (!mm)
71208 + return true;
71209 +
71210 if (atomic_read(&task->signal->live) != 1)
71211 return false;
71212
71213 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71214 index e796429..6e38f9f 100644
71215 --- a/lib/radix-tree.c
71216 +++ b/lib/radix-tree.c
71217 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71218 int nr;
71219 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71220 };
71221 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71222 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71223
71224 static inline void *ptr_to_indirect(void *ptr)
71225 {
71226 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71227 index 0e33754..50a0e63 100644
71228 --- a/lib/vsprintf.c
71229 +++ b/lib/vsprintf.c
71230 @@ -16,6 +16,9 @@
71231 * - scnprintf and vscnprintf
71232 */
71233
71234 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71235 +#define __INCLUDED_BY_HIDESYM 1
71236 +#endif
71237 #include <stdarg.h>
71238 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71239 #include <linux/types.h>
71240 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71241 char sym[KSYM_SYMBOL_LEN];
71242 if (ext == 'B')
71243 sprint_backtrace(sym, value);
71244 - else if (ext != 'f' && ext != 's')
71245 + else if (ext != 'f' && ext != 's' && ext != 'a')
71246 sprint_symbol(sym, value);
71247 else
71248 sprint_symbol_no_offset(sym, value);
71249 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71250 return number(buf, end, *(const netdev_features_t *)addr, spec);
71251 }
71252
71253 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71254 +int kptr_restrict __read_mostly = 2;
71255 +#else
71256 int kptr_restrict __read_mostly;
71257 +#endif
71258
71259 /*
71260 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71261 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71262 * - 'S' For symbolic direct pointers with offset
71263 * - 's' For symbolic direct pointers without offset
71264 * - 'B' For backtraced symbolic direct pointers with offset
71265 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71266 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71267 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71268 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71269 * - 'M' For a 6-byte MAC address, it prints the address in the
71270 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71271
71272 if (!ptr && *fmt != 'K') {
71273 /*
71274 - * Print (null) with the same width as a pointer so it makes
71275 + * Print (nil) with the same width as a pointer so it makes
71276 * tabular output look nice.
71277 */
71278 if (spec.field_width == -1)
71279 spec.field_width = default_width;
71280 - return string(buf, end, "(null)", spec);
71281 + return string(buf, end, "(nil)", spec);
71282 }
71283
71284 switch (*fmt) {
71285 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71286 /* Fallthrough */
71287 case 'S':
71288 case 's':
71289 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71290 + break;
71291 +#else
71292 + return symbol_string(buf, end, ptr, spec, *fmt);
71293 +#endif
71294 + case 'A':
71295 + case 'a':
71296 case 'B':
71297 return symbol_string(buf, end, ptr, spec, *fmt);
71298 case 'R':
71299 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71300 va_end(va);
71301 return buf;
71302 }
71303 + case 'P':
71304 + break;
71305 case 'K':
71306 /*
71307 * %pK cannot be used in IRQ context because its test
71308 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71309 }
71310 break;
71311 }
71312 +
71313 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71314 + /* 'P' = approved pointers to copy to userland,
71315 + as in the /proc/kallsyms case, as we make it display nothing
71316 + for non-root users, and the real contents for root users
71317 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71318 + above
71319 + */
71320 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71321 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71322 + dump_stack();
71323 + ptr = NULL;
71324 + }
71325 +#endif
71326 +
71327 spec.flags |= SMALL;
71328 if (spec.field_width == -1) {
71329 spec.field_width = default_width;
71330 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71331 typeof(type) value; \
71332 if (sizeof(type) == 8) { \
71333 args = PTR_ALIGN(args, sizeof(u32)); \
71334 - *(u32 *)&value = *(u32 *)args; \
71335 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71336 + *(u32 *)&value = *(const u32 *)args; \
71337 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71338 } else { \
71339 args = PTR_ALIGN(args, sizeof(type)); \
71340 - value = *(typeof(type) *)args; \
71341 + value = *(const typeof(type) *)args; \
71342 } \
71343 args += sizeof(type); \
71344 value; \
71345 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71346 case FORMAT_TYPE_STR: {
71347 const char *str_arg = args;
71348 args += strlen(str_arg) + 1;
71349 - str = string(str, end, (char *)str_arg, spec);
71350 + str = string(str, end, str_arg, spec);
71351 break;
71352 }
71353
71354 diff --git a/localversion-grsec b/localversion-grsec
71355 new file mode 100644
71356 index 0000000..7cd6065
71357 --- /dev/null
71358 +++ b/localversion-grsec
71359 @@ -0,0 +1 @@
71360 +-grsec
71361 diff --git a/mm/Kconfig b/mm/Kconfig
71362 index d5c8019..f513038 100644
71363 --- a/mm/Kconfig
71364 +++ b/mm/Kconfig
71365 @@ -251,10 +251,10 @@ config KSM
71366 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71367
71368 config DEFAULT_MMAP_MIN_ADDR
71369 - int "Low address space to protect from user allocation"
71370 + int "Low address space to protect from user allocation"
71371 depends on MMU
71372 - default 4096
71373 - help
71374 + default 65536
71375 + help
71376 This is the portion of low virtual memory which should be protected
71377 from userspace allocation. Keeping a user from writing to low pages
71378 can help reduce the impact of kernel NULL pointer bugs.
71379 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71380
71381 config HWPOISON_INJECT
71382 tristate "HWPoison pages injector"
71383 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71384 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71385 select PROC_PAGE_MONITOR
71386
71387 config NOMMU_INITIAL_TRIM_EXCESS
71388 diff --git a/mm/filemap.c b/mm/filemap.c
71389 index 3843445..4fe6833 100644
71390 --- a/mm/filemap.c
71391 +++ b/mm/filemap.c
71392 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71393 struct address_space *mapping = file->f_mapping;
71394
71395 if (!mapping->a_ops->readpage)
71396 - return -ENOEXEC;
71397 + return -ENODEV;
71398 file_accessed(file);
71399 vma->vm_ops = &generic_file_vm_ops;
71400 vma->vm_flags |= VM_CAN_NONLINEAR;
71401 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71402 *pos = i_size_read(inode);
71403
71404 if (limit != RLIM_INFINITY) {
71405 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71406 if (*pos >= limit) {
71407 send_sig(SIGXFSZ, current, 0);
71408 return -EFBIG;
71409 diff --git a/mm/fremap.c b/mm/fremap.c
71410 index 9ed4fd4..c42648d 100644
71411 --- a/mm/fremap.c
71412 +++ b/mm/fremap.c
71413 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71414 retry:
71415 vma = find_vma(mm, start);
71416
71417 +#ifdef CONFIG_PAX_SEGMEXEC
71418 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71419 + goto out;
71420 +#endif
71421 +
71422 /*
71423 * Make sure the vma is shared, that it supports prefaulting,
71424 * and that the remapped range is valid and fully within
71425 diff --git a/mm/highmem.c b/mm/highmem.c
71426 index d517cd1..006a1c5 100644
71427 --- a/mm/highmem.c
71428 +++ b/mm/highmem.c
71429 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71430 * So no dangers, even with speculative execution.
71431 */
71432 page = pte_page(pkmap_page_table[i]);
71433 + pax_open_kernel();
71434 pte_clear(&init_mm, (unsigned long)page_address(page),
71435 &pkmap_page_table[i]);
71436 -
71437 + pax_close_kernel();
71438 set_page_address(page, NULL);
71439 need_flush = 1;
71440 }
71441 @@ -198,9 +199,11 @@ start:
71442 }
71443 }
71444 vaddr = PKMAP_ADDR(last_pkmap_nr);
71445 +
71446 + pax_open_kernel();
71447 set_pte_at(&init_mm, vaddr,
71448 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71449 -
71450 + pax_close_kernel();
71451 pkmap_count[last_pkmap_nr] = 1;
71452 set_page_address(page, (void *)vaddr);
71453
71454 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71455 index 141dbb6..ebff057 100644
71456 --- a/mm/huge_memory.c
71457 +++ b/mm/huge_memory.c
71458 @@ -735,7 +735,7 @@ out:
71459 * run pte_offset_map on the pmd, if an huge pmd could
71460 * materialize from under us from a different thread.
71461 */
71462 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71463 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71464 return VM_FAULT_OOM;
71465 /* if an huge pmd materialized from under us just retry later */
71466 if (unlikely(pmd_trans_huge(*pmd)))
71467 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71468 index 3adceaf..dccfea3 100644
71469 --- a/mm/hugetlb.c
71470 +++ b/mm/hugetlb.c
71471 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71472 return 1;
71473 }
71474
71475 +#ifdef CONFIG_PAX_SEGMEXEC
71476 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71477 +{
71478 + struct mm_struct *mm = vma->vm_mm;
71479 + struct vm_area_struct *vma_m;
71480 + unsigned long address_m;
71481 + pte_t *ptep_m;
71482 +
71483 + vma_m = pax_find_mirror_vma(vma);
71484 + if (!vma_m)
71485 + return;
71486 +
71487 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71488 + address_m = address + SEGMEXEC_TASK_SIZE;
71489 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71490 + get_page(page_m);
71491 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71492 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71493 +}
71494 +#endif
71495 +
71496 /*
71497 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71498 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71499 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71500 make_huge_pte(vma, new_page, 1));
71501 page_remove_rmap(old_page);
71502 hugepage_add_new_anon_rmap(new_page, vma, address);
71503 +
71504 +#ifdef CONFIG_PAX_SEGMEXEC
71505 + pax_mirror_huge_pte(vma, address, new_page);
71506 +#endif
71507 +
71508 /* Make the old page be freed below */
71509 new_page = old_page;
71510 mmu_notifier_invalidate_range_end(mm,
71511 @@ -2786,6 +2812,10 @@ retry:
71512 && (vma->vm_flags & VM_SHARED)));
71513 set_huge_pte_at(mm, address, ptep, new_pte);
71514
71515 +#ifdef CONFIG_PAX_SEGMEXEC
71516 + pax_mirror_huge_pte(vma, address, page);
71517 +#endif
71518 +
71519 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71520 /* Optimization, do the COW without a second fault */
71521 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71522 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71523 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71524 struct hstate *h = hstate_vma(vma);
71525
71526 +#ifdef CONFIG_PAX_SEGMEXEC
71527 + struct vm_area_struct *vma_m;
71528 +#endif
71529 +
71530 address &= huge_page_mask(h);
71531
71532 ptep = huge_pte_offset(mm, address);
71533 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71534 VM_FAULT_SET_HINDEX(hstate_index(h));
71535 }
71536
71537 +#ifdef CONFIG_PAX_SEGMEXEC
71538 + vma_m = pax_find_mirror_vma(vma);
71539 + if (vma_m) {
71540 + unsigned long address_m;
71541 +
71542 + if (vma->vm_start > vma_m->vm_start) {
71543 + address_m = address;
71544 + address -= SEGMEXEC_TASK_SIZE;
71545 + vma = vma_m;
71546 + h = hstate_vma(vma);
71547 + } else
71548 + address_m = address + SEGMEXEC_TASK_SIZE;
71549 +
71550 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71551 + return VM_FAULT_OOM;
71552 + address_m &= HPAGE_MASK;
71553 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71554 + }
71555 +#endif
71556 +
71557 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71558 if (!ptep)
71559 return VM_FAULT_OOM;
71560 diff --git a/mm/internal.h b/mm/internal.h
71561 index b8c91b3..93e95a3 100644
71562 --- a/mm/internal.h
71563 +++ b/mm/internal.h
71564 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71565 * in mm/page_alloc.c
71566 */
71567 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71568 +extern void free_compound_page(struct page *page);
71569 extern void prep_compound_page(struct page *page, unsigned long order);
71570 #ifdef CONFIG_MEMORY_FAILURE
71571 extern bool is_free_buddy_page(struct page *page);
71572 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71573 index 45eb621..6ccd8ea 100644
71574 --- a/mm/kmemleak.c
71575 +++ b/mm/kmemleak.c
71576 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71577
71578 for (i = 0; i < object->trace_len; i++) {
71579 void *ptr = (void *)object->trace[i];
71580 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71581 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71582 }
71583 }
71584
71585 diff --git a/mm/maccess.c b/mm/maccess.c
71586 index d53adf9..03a24bf 100644
71587 --- a/mm/maccess.c
71588 +++ b/mm/maccess.c
71589 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71590 set_fs(KERNEL_DS);
71591 pagefault_disable();
71592 ret = __copy_from_user_inatomic(dst,
71593 - (__force const void __user *)src, size);
71594 + (const void __force_user *)src, size);
71595 pagefault_enable();
71596 set_fs(old_fs);
71597
71598 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71599
71600 set_fs(KERNEL_DS);
71601 pagefault_disable();
71602 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71603 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71604 pagefault_enable();
71605 set_fs(old_fs);
71606
71607 diff --git a/mm/madvise.c b/mm/madvise.c
71608 index 14d260f..b2a80fd 100644
71609 --- a/mm/madvise.c
71610 +++ b/mm/madvise.c
71611 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71612 pgoff_t pgoff;
71613 unsigned long new_flags = vma->vm_flags;
71614
71615 +#ifdef CONFIG_PAX_SEGMEXEC
71616 + struct vm_area_struct *vma_m;
71617 +#endif
71618 +
71619 switch (behavior) {
71620 case MADV_NORMAL:
71621 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71622 @@ -119,6 +123,13 @@ success:
71623 /*
71624 * vm_flags is protected by the mmap_sem held in write mode.
71625 */
71626 +
71627 +#ifdef CONFIG_PAX_SEGMEXEC
71628 + vma_m = pax_find_mirror_vma(vma);
71629 + if (vma_m)
71630 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71631 +#endif
71632 +
71633 vma->vm_flags = new_flags;
71634
71635 out:
71636 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71637 struct vm_area_struct ** prev,
71638 unsigned long start, unsigned long end)
71639 {
71640 +
71641 +#ifdef CONFIG_PAX_SEGMEXEC
71642 + struct vm_area_struct *vma_m;
71643 +#endif
71644 +
71645 *prev = vma;
71646 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71647 return -EINVAL;
71648 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71649 zap_page_range(vma, start, end - start, &details);
71650 } else
71651 zap_page_range(vma, start, end - start, NULL);
71652 +
71653 +#ifdef CONFIG_PAX_SEGMEXEC
71654 + vma_m = pax_find_mirror_vma(vma);
71655 + if (vma_m) {
71656 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71657 + struct zap_details details = {
71658 + .nonlinear_vma = vma_m,
71659 + .last_index = ULONG_MAX,
71660 + };
71661 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71662 + } else
71663 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71664 + }
71665 +#endif
71666 +
71667 return 0;
71668 }
71669
71670 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71671 if (end < start)
71672 goto out;
71673
71674 +#ifdef CONFIG_PAX_SEGMEXEC
71675 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71676 + if (end > SEGMEXEC_TASK_SIZE)
71677 + goto out;
71678 + } else
71679 +#endif
71680 +
71681 + if (end > TASK_SIZE)
71682 + goto out;
71683 +
71684 error = 0;
71685 if (end == start)
71686 goto out;
71687 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71688 index a6e2141..eaf5aad 100644
71689 --- a/mm/memory-failure.c
71690 +++ b/mm/memory-failure.c
71691 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71692
71693 int sysctl_memory_failure_recovery __read_mostly = 1;
71694
71695 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71696 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71697
71698 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71699
71700 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71701 pfn, t->comm, t->pid);
71702 si.si_signo = SIGBUS;
71703 si.si_errno = 0;
71704 - si.si_addr = (void *)addr;
71705 + si.si_addr = (void __user *)addr;
71706 #ifdef __ARCH_SI_TRAPNO
71707 si.si_trapno = trapno;
71708 #endif
71709 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71710 }
71711
71712 nr_pages = 1 << compound_trans_order(hpage);
71713 - atomic_long_add(nr_pages, &mce_bad_pages);
71714 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71715
71716 /*
71717 * We need/can do nothing about count=0 pages.
71718 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71719 if (!PageHWPoison(hpage)
71720 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71721 || (p != hpage && TestSetPageHWPoison(hpage))) {
71722 - atomic_long_sub(nr_pages, &mce_bad_pages);
71723 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71724 return 0;
71725 }
71726 set_page_hwpoison_huge_page(hpage);
71727 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71728 }
71729 if (hwpoison_filter(p)) {
71730 if (TestClearPageHWPoison(p))
71731 - atomic_long_sub(nr_pages, &mce_bad_pages);
71732 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71733 unlock_page(hpage);
71734 put_page(hpage);
71735 return 0;
71736 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71737 return 0;
71738 }
71739 if (TestClearPageHWPoison(p))
71740 - atomic_long_sub(nr_pages, &mce_bad_pages);
71741 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71742 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71743 return 0;
71744 }
71745 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71746 */
71747 if (TestClearPageHWPoison(page)) {
71748 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71749 - atomic_long_sub(nr_pages, &mce_bad_pages);
71750 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71751 freeit = 1;
71752 if (PageHuge(page))
71753 clear_page_hwpoison_huge_page(page);
71754 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71755 }
71756 done:
71757 if (!PageHWPoison(hpage))
71758 - atomic_long_add(1 << compound_trans_order(hpage),
71759 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71760 &mce_bad_pages);
71761 set_page_hwpoison_huge_page(hpage);
71762 dequeue_hwpoisoned_huge_page(hpage);
71763 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71764 return ret;
71765
71766 done:
71767 - atomic_long_add(1, &mce_bad_pages);
71768 + atomic_long_add_unchecked(1, &mce_bad_pages);
71769 SetPageHWPoison(page);
71770 /* keep elevated page count for bad page */
71771 return ret;
71772 diff --git a/mm/memory.c b/mm/memory.c
71773 index 5736170..8e04800 100644
71774 --- a/mm/memory.c
71775 +++ b/mm/memory.c
71776 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71777 free_pte_range(tlb, pmd, addr);
71778 } while (pmd++, addr = next, addr != end);
71779
71780 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71781 start &= PUD_MASK;
71782 if (start < floor)
71783 return;
71784 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71785 pmd = pmd_offset(pud, start);
71786 pud_clear(pud);
71787 pmd_free_tlb(tlb, pmd, start);
71788 +#endif
71789 +
71790 }
71791
71792 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71793 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71794 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71795 } while (pud++, addr = next, addr != end);
71796
71797 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71798 start &= PGDIR_MASK;
71799 if (start < floor)
71800 return;
71801 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71802 pud = pud_offset(pgd, start);
71803 pgd_clear(pgd);
71804 pud_free_tlb(tlb, pud, start);
71805 +#endif
71806 +
71807 }
71808
71809 /*
71810 @@ -1614,12 +1620,6 @@ no_page_table:
71811 return page;
71812 }
71813
71814 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71815 -{
71816 - return stack_guard_page_start(vma, addr) ||
71817 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71818 -}
71819 -
71820 /**
71821 * __get_user_pages() - pin user pages in memory
71822 * @tsk: task_struct of target task
71823 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71824 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71825 i = 0;
71826
71827 - do {
71828 + while (nr_pages) {
71829 struct vm_area_struct *vma;
71830
71831 - vma = find_extend_vma(mm, start);
71832 + vma = find_vma(mm, start);
71833 if (!vma && in_gate_area(mm, start)) {
71834 unsigned long pg = start & PAGE_MASK;
71835 pgd_t *pgd;
71836 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71837 goto next_page;
71838 }
71839
71840 - if (!vma ||
71841 + if (!vma || start < vma->vm_start ||
71842 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71843 !(vm_flags & vma->vm_flags))
71844 return i ? : -EFAULT;
71845 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71846 int ret;
71847 unsigned int fault_flags = 0;
71848
71849 - /* For mlock, just skip the stack guard page. */
71850 - if (foll_flags & FOLL_MLOCK) {
71851 - if (stack_guard_page(vma, start))
71852 - goto next_page;
71853 - }
71854 if (foll_flags & FOLL_WRITE)
71855 fault_flags |= FAULT_FLAG_WRITE;
71856 if (nonblocking)
71857 @@ -1848,7 +1843,7 @@ next_page:
71858 start += PAGE_SIZE;
71859 nr_pages--;
71860 } while (nr_pages && start < vma->vm_end);
71861 - } while (nr_pages);
71862 + }
71863 return i;
71864 }
71865 EXPORT_SYMBOL(__get_user_pages);
71866 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71867 page_add_file_rmap(page);
71868 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71869
71870 +#ifdef CONFIG_PAX_SEGMEXEC
71871 + pax_mirror_file_pte(vma, addr, page, ptl);
71872 +#endif
71873 +
71874 retval = 0;
71875 pte_unmap_unlock(pte, ptl);
71876 return retval;
71877 @@ -2089,10 +2088,22 @@ out:
71878 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71879 struct page *page)
71880 {
71881 +
71882 +#ifdef CONFIG_PAX_SEGMEXEC
71883 + struct vm_area_struct *vma_m;
71884 +#endif
71885 +
71886 if (addr < vma->vm_start || addr >= vma->vm_end)
71887 return -EFAULT;
71888 if (!page_count(page))
71889 return -EINVAL;
71890 +
71891 +#ifdef CONFIG_PAX_SEGMEXEC
71892 + vma_m = pax_find_mirror_vma(vma);
71893 + if (vma_m)
71894 + vma_m->vm_flags |= VM_INSERTPAGE;
71895 +#endif
71896 +
71897 vma->vm_flags |= VM_INSERTPAGE;
71898 return insert_page(vma, addr, page, vma->vm_page_prot);
71899 }
71900 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71901 unsigned long pfn)
71902 {
71903 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71904 + BUG_ON(vma->vm_mirror);
71905
71906 if (addr < vma->vm_start || addr >= vma->vm_end)
71907 return -EFAULT;
71908 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71909
71910 BUG_ON(pud_huge(*pud));
71911
71912 - pmd = pmd_alloc(mm, pud, addr);
71913 + pmd = (mm == &init_mm) ?
71914 + pmd_alloc_kernel(mm, pud, addr) :
71915 + pmd_alloc(mm, pud, addr);
71916 if (!pmd)
71917 return -ENOMEM;
71918 do {
71919 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71920 unsigned long next;
71921 int err;
71922
71923 - pud = pud_alloc(mm, pgd, addr);
71924 + pud = (mm == &init_mm) ?
71925 + pud_alloc_kernel(mm, pgd, addr) :
71926 + pud_alloc(mm, pgd, addr);
71927 if (!pud)
71928 return -ENOMEM;
71929 do {
71930 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71931 copy_user_highpage(dst, src, va, vma);
71932 }
71933
71934 +#ifdef CONFIG_PAX_SEGMEXEC
71935 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71936 +{
71937 + struct mm_struct *mm = vma->vm_mm;
71938 + spinlock_t *ptl;
71939 + pte_t *pte, entry;
71940 +
71941 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71942 + entry = *pte;
71943 + if (!pte_present(entry)) {
71944 + if (!pte_none(entry)) {
71945 + BUG_ON(pte_file(entry));
71946 + free_swap_and_cache(pte_to_swp_entry(entry));
71947 + pte_clear_not_present_full(mm, address, pte, 0);
71948 + }
71949 + } else {
71950 + struct page *page;
71951 +
71952 + flush_cache_page(vma, address, pte_pfn(entry));
71953 + entry = ptep_clear_flush(vma, address, pte);
71954 + BUG_ON(pte_dirty(entry));
71955 + page = vm_normal_page(vma, address, entry);
71956 + if (page) {
71957 + update_hiwater_rss(mm);
71958 + if (PageAnon(page))
71959 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71960 + else
71961 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71962 + page_remove_rmap(page);
71963 + page_cache_release(page);
71964 + }
71965 + }
71966 + pte_unmap_unlock(pte, ptl);
71967 +}
71968 +
71969 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71970 + *
71971 + * the ptl of the lower mapped page is held on entry and is not released on exit
71972 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71973 + */
71974 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71975 +{
71976 + struct mm_struct *mm = vma->vm_mm;
71977 + unsigned long address_m;
71978 + spinlock_t *ptl_m;
71979 + struct vm_area_struct *vma_m;
71980 + pmd_t *pmd_m;
71981 + pte_t *pte_m, entry_m;
71982 +
71983 + BUG_ON(!page_m || !PageAnon(page_m));
71984 +
71985 + vma_m = pax_find_mirror_vma(vma);
71986 + if (!vma_m)
71987 + return;
71988 +
71989 + BUG_ON(!PageLocked(page_m));
71990 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71991 + address_m = address + SEGMEXEC_TASK_SIZE;
71992 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
71993 + pte_m = pte_offset_map(pmd_m, address_m);
71994 + ptl_m = pte_lockptr(mm, pmd_m);
71995 + if (ptl != ptl_m) {
71996 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
71997 + if (!pte_none(*pte_m))
71998 + goto out;
71999 + }
72000 +
72001 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72002 + page_cache_get(page_m);
72003 + page_add_anon_rmap(page_m, vma_m, address_m);
72004 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72005 + set_pte_at(mm, address_m, pte_m, entry_m);
72006 + update_mmu_cache(vma_m, address_m, entry_m);
72007 +out:
72008 + if (ptl != ptl_m)
72009 + spin_unlock(ptl_m);
72010 + pte_unmap(pte_m);
72011 + unlock_page(page_m);
72012 +}
72013 +
72014 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72015 +{
72016 + struct mm_struct *mm = vma->vm_mm;
72017 + unsigned long address_m;
72018 + spinlock_t *ptl_m;
72019 + struct vm_area_struct *vma_m;
72020 + pmd_t *pmd_m;
72021 + pte_t *pte_m, entry_m;
72022 +
72023 + BUG_ON(!page_m || PageAnon(page_m));
72024 +
72025 + vma_m = pax_find_mirror_vma(vma);
72026 + if (!vma_m)
72027 + return;
72028 +
72029 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72030 + address_m = address + SEGMEXEC_TASK_SIZE;
72031 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72032 + pte_m = pte_offset_map(pmd_m, address_m);
72033 + ptl_m = pte_lockptr(mm, pmd_m);
72034 + if (ptl != ptl_m) {
72035 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72036 + if (!pte_none(*pte_m))
72037 + goto out;
72038 + }
72039 +
72040 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72041 + page_cache_get(page_m);
72042 + page_add_file_rmap(page_m);
72043 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72044 + set_pte_at(mm, address_m, pte_m, entry_m);
72045 + update_mmu_cache(vma_m, address_m, entry_m);
72046 +out:
72047 + if (ptl != ptl_m)
72048 + spin_unlock(ptl_m);
72049 + pte_unmap(pte_m);
72050 +}
72051 +
72052 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72053 +{
72054 + struct mm_struct *mm = vma->vm_mm;
72055 + unsigned long address_m;
72056 + spinlock_t *ptl_m;
72057 + struct vm_area_struct *vma_m;
72058 + pmd_t *pmd_m;
72059 + pte_t *pte_m, entry_m;
72060 +
72061 + vma_m = pax_find_mirror_vma(vma);
72062 + if (!vma_m)
72063 + return;
72064 +
72065 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72066 + address_m = address + SEGMEXEC_TASK_SIZE;
72067 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72068 + pte_m = pte_offset_map(pmd_m, address_m);
72069 + ptl_m = pte_lockptr(mm, pmd_m);
72070 + if (ptl != ptl_m) {
72071 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72072 + if (!pte_none(*pte_m))
72073 + goto out;
72074 + }
72075 +
72076 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72077 + set_pte_at(mm, address_m, pte_m, entry_m);
72078 +out:
72079 + if (ptl != ptl_m)
72080 + spin_unlock(ptl_m);
72081 + pte_unmap(pte_m);
72082 +}
72083 +
72084 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72085 +{
72086 + struct page *page_m;
72087 + pte_t entry;
72088 +
72089 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72090 + goto out;
72091 +
72092 + entry = *pte;
72093 + page_m = vm_normal_page(vma, address, entry);
72094 + if (!page_m)
72095 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72096 + else if (PageAnon(page_m)) {
72097 + if (pax_find_mirror_vma(vma)) {
72098 + pte_unmap_unlock(pte, ptl);
72099 + lock_page(page_m);
72100 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72101 + if (pte_same(entry, *pte))
72102 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72103 + else
72104 + unlock_page(page_m);
72105 + }
72106 + } else
72107 + pax_mirror_file_pte(vma, address, page_m, ptl);
72108 +
72109 +out:
72110 + pte_unmap_unlock(pte, ptl);
72111 +}
72112 +#endif
72113 +
72114 /*
72115 * This routine handles present pages, when users try to write
72116 * to a shared page. It is done by copying the page to a new address
72117 @@ -2703,6 +2899,12 @@ gotten:
72118 */
72119 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72120 if (likely(pte_same(*page_table, orig_pte))) {
72121 +
72122 +#ifdef CONFIG_PAX_SEGMEXEC
72123 + if (pax_find_mirror_vma(vma))
72124 + BUG_ON(!trylock_page(new_page));
72125 +#endif
72126 +
72127 if (old_page) {
72128 if (!PageAnon(old_page)) {
72129 dec_mm_counter_fast(mm, MM_FILEPAGES);
72130 @@ -2754,6 +2956,10 @@ gotten:
72131 page_remove_rmap(old_page);
72132 }
72133
72134 +#ifdef CONFIG_PAX_SEGMEXEC
72135 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72136 +#endif
72137 +
72138 /* Free the old page.. */
72139 new_page = old_page;
72140 ret |= VM_FAULT_WRITE;
72141 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72142 swap_free(entry);
72143 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72144 try_to_free_swap(page);
72145 +
72146 +#ifdef CONFIG_PAX_SEGMEXEC
72147 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72148 +#endif
72149 +
72150 unlock_page(page);
72151 if (swapcache) {
72152 /*
72153 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72154
72155 /* No need to invalidate - it was non-present before */
72156 update_mmu_cache(vma, address, page_table);
72157 +
72158 +#ifdef CONFIG_PAX_SEGMEXEC
72159 + pax_mirror_anon_pte(vma, address, page, ptl);
72160 +#endif
72161 +
72162 unlock:
72163 pte_unmap_unlock(page_table, ptl);
72164 out:
72165 @@ -3075,40 +3291,6 @@ out_release:
72166 }
72167
72168 /*
72169 - * This is like a special single-page "expand_{down|up}wards()",
72170 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72171 - * doesn't hit another vma.
72172 - */
72173 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72174 -{
72175 - address &= PAGE_MASK;
72176 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72177 - struct vm_area_struct *prev = vma->vm_prev;
72178 -
72179 - /*
72180 - * Is there a mapping abutting this one below?
72181 - *
72182 - * That's only ok if it's the same stack mapping
72183 - * that has gotten split..
72184 - */
72185 - if (prev && prev->vm_end == address)
72186 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72187 -
72188 - expand_downwards(vma, address - PAGE_SIZE);
72189 - }
72190 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72191 - struct vm_area_struct *next = vma->vm_next;
72192 -
72193 - /* As VM_GROWSDOWN but s/below/above/ */
72194 - if (next && next->vm_start == address + PAGE_SIZE)
72195 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72196 -
72197 - expand_upwards(vma, address + PAGE_SIZE);
72198 - }
72199 - return 0;
72200 -}
72201 -
72202 -/*
72203 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72204 * but allow concurrent faults), and pte mapped but not yet locked.
72205 * We return with mmap_sem still held, but pte unmapped and unlocked.
72206 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72207 unsigned long address, pte_t *page_table, pmd_t *pmd,
72208 unsigned int flags)
72209 {
72210 - struct page *page;
72211 + struct page *page = NULL;
72212 spinlock_t *ptl;
72213 pte_t entry;
72214
72215 - pte_unmap(page_table);
72216 -
72217 - /* Check if we need to add a guard page to the stack */
72218 - if (check_stack_guard_page(vma, address) < 0)
72219 - return VM_FAULT_SIGBUS;
72220 -
72221 - /* Use the zero-page for reads */
72222 if (!(flags & FAULT_FLAG_WRITE)) {
72223 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72224 vma->vm_page_prot));
72225 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72226 + ptl = pte_lockptr(mm, pmd);
72227 + spin_lock(ptl);
72228 if (!pte_none(*page_table))
72229 goto unlock;
72230 goto setpte;
72231 }
72232
72233 /* Allocate our own private page. */
72234 + pte_unmap(page_table);
72235 +
72236 if (unlikely(anon_vma_prepare(vma)))
72237 goto oom;
72238 page = alloc_zeroed_user_highpage_movable(vma, address);
72239 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72240 if (!pte_none(*page_table))
72241 goto release;
72242
72243 +#ifdef CONFIG_PAX_SEGMEXEC
72244 + if (pax_find_mirror_vma(vma))
72245 + BUG_ON(!trylock_page(page));
72246 +#endif
72247 +
72248 inc_mm_counter_fast(mm, MM_ANONPAGES);
72249 page_add_new_anon_rmap(page, vma, address);
72250 setpte:
72251 @@ -3163,6 +3346,12 @@ setpte:
72252
72253 /* No need to invalidate - it was non-present before */
72254 update_mmu_cache(vma, address, page_table);
72255 +
72256 +#ifdef CONFIG_PAX_SEGMEXEC
72257 + if (page)
72258 + pax_mirror_anon_pte(vma, address, page, ptl);
72259 +#endif
72260 +
72261 unlock:
72262 pte_unmap_unlock(page_table, ptl);
72263 return 0;
72264 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72265 */
72266 /* Only go through if we didn't race with anybody else... */
72267 if (likely(pte_same(*page_table, orig_pte))) {
72268 +
72269 +#ifdef CONFIG_PAX_SEGMEXEC
72270 + if (anon && pax_find_mirror_vma(vma))
72271 + BUG_ON(!trylock_page(page));
72272 +#endif
72273 +
72274 flush_icache_page(vma, page);
72275 entry = mk_pte(page, vma->vm_page_prot);
72276 if (flags & FAULT_FLAG_WRITE)
72277 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72278
72279 /* no need to invalidate: a not-present page won't be cached */
72280 update_mmu_cache(vma, address, page_table);
72281 +
72282 +#ifdef CONFIG_PAX_SEGMEXEC
72283 + if (anon)
72284 + pax_mirror_anon_pte(vma, address, page, ptl);
72285 + else
72286 + pax_mirror_file_pte(vma, address, page, ptl);
72287 +#endif
72288 +
72289 } else {
72290 if (cow_page)
72291 mem_cgroup_uncharge_page(cow_page);
72292 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72293 if (flags & FAULT_FLAG_WRITE)
72294 flush_tlb_fix_spurious_fault(vma, address);
72295 }
72296 +
72297 +#ifdef CONFIG_PAX_SEGMEXEC
72298 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72299 + return 0;
72300 +#endif
72301 +
72302 unlock:
72303 pte_unmap_unlock(pte, ptl);
72304 return 0;
72305 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72306 pmd_t *pmd;
72307 pte_t *pte;
72308
72309 +#ifdef CONFIG_PAX_SEGMEXEC
72310 + struct vm_area_struct *vma_m;
72311 +#endif
72312 +
72313 __set_current_state(TASK_RUNNING);
72314
72315 count_vm_event(PGFAULT);
72316 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72317 if (unlikely(is_vm_hugetlb_page(vma)))
72318 return hugetlb_fault(mm, vma, address, flags);
72319
72320 +#ifdef CONFIG_PAX_SEGMEXEC
72321 + vma_m = pax_find_mirror_vma(vma);
72322 + if (vma_m) {
72323 + unsigned long address_m;
72324 + pgd_t *pgd_m;
72325 + pud_t *pud_m;
72326 + pmd_t *pmd_m;
72327 +
72328 + if (vma->vm_start > vma_m->vm_start) {
72329 + address_m = address;
72330 + address -= SEGMEXEC_TASK_SIZE;
72331 + vma = vma_m;
72332 + } else
72333 + address_m = address + SEGMEXEC_TASK_SIZE;
72334 +
72335 + pgd_m = pgd_offset(mm, address_m);
72336 + pud_m = pud_alloc(mm, pgd_m, address_m);
72337 + if (!pud_m)
72338 + return VM_FAULT_OOM;
72339 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72340 + if (!pmd_m)
72341 + return VM_FAULT_OOM;
72342 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72343 + return VM_FAULT_OOM;
72344 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72345 + }
72346 +#endif
72347 +
72348 retry:
72349 pgd = pgd_offset(mm, address);
72350 pud = pud_alloc(mm, pgd, address);
72351 @@ -3547,7 +3788,7 @@ retry:
72352 * run pte_offset_map on the pmd, if an huge pmd could
72353 * materialize from under us from a different thread.
72354 */
72355 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72356 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72357 return VM_FAULT_OOM;
72358 /* if an huge pmd materialized from under us just retry later */
72359 if (unlikely(pmd_trans_huge(*pmd)))
72360 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72361 spin_unlock(&mm->page_table_lock);
72362 return 0;
72363 }
72364 +
72365 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72366 +{
72367 + pud_t *new = pud_alloc_one(mm, address);
72368 + if (!new)
72369 + return -ENOMEM;
72370 +
72371 + smp_wmb(); /* See comment in __pte_alloc */
72372 +
72373 + spin_lock(&mm->page_table_lock);
72374 + if (pgd_present(*pgd)) /* Another has populated it */
72375 + pud_free(mm, new);
72376 + else
72377 + pgd_populate_kernel(mm, pgd, new);
72378 + spin_unlock(&mm->page_table_lock);
72379 + return 0;
72380 +}
72381 #endif /* __PAGETABLE_PUD_FOLDED */
72382
72383 #ifndef __PAGETABLE_PMD_FOLDED
72384 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72385 spin_unlock(&mm->page_table_lock);
72386 return 0;
72387 }
72388 +
72389 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72390 +{
72391 + pmd_t *new = pmd_alloc_one(mm, address);
72392 + if (!new)
72393 + return -ENOMEM;
72394 +
72395 + smp_wmb(); /* See comment in __pte_alloc */
72396 +
72397 + spin_lock(&mm->page_table_lock);
72398 +#ifndef __ARCH_HAS_4LEVEL_HACK
72399 + if (pud_present(*pud)) /* Another has populated it */
72400 + pmd_free(mm, new);
72401 + else
72402 + pud_populate_kernel(mm, pud, new);
72403 +#else
72404 + if (pgd_present(*pud)) /* Another has populated it */
72405 + pmd_free(mm, new);
72406 + else
72407 + pgd_populate_kernel(mm, pud, new);
72408 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72409 + spin_unlock(&mm->page_table_lock);
72410 + return 0;
72411 +}
72412 #endif /* __PAGETABLE_PMD_FOLDED */
72413
72414 int make_pages_present(unsigned long addr, unsigned long end)
72415 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72416 gate_vma.vm_start = FIXADDR_USER_START;
72417 gate_vma.vm_end = FIXADDR_USER_END;
72418 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72419 - gate_vma.vm_page_prot = __P101;
72420 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72421
72422 return 0;
72423 }
72424 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72425 index 3d64b36..c6ab69c 100644
72426 --- a/mm/mempolicy.c
72427 +++ b/mm/mempolicy.c
72428 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72429 unsigned long vmstart;
72430 unsigned long vmend;
72431
72432 +#ifdef CONFIG_PAX_SEGMEXEC
72433 + struct vm_area_struct *vma_m;
72434 +#endif
72435 +
72436 vma = find_vma(mm, start);
72437 if (!vma || vma->vm_start > start)
72438 return -EFAULT;
72439 @@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72440 if (err)
72441 goto out;
72442 }
72443 +
72444 err = vma_replace_policy(vma, new_pol);
72445 if (err)
72446 goto out;
72447 +
72448 +#ifdef CONFIG_PAX_SEGMEXEC
72449 + vma_m = pax_find_mirror_vma(vma);
72450 + if (vma_m) {
72451 + err = vma_replace_policy(vma_m, new_pol);
72452 + if (err)
72453 + goto out;
72454 + }
72455 +#endif
72456 +
72457 }
72458
72459 out:
72460 @@ -1147,6 +1162,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72461
72462 if (end < start)
72463 return -EINVAL;
72464 +
72465 +#ifdef CONFIG_PAX_SEGMEXEC
72466 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72467 + if (end > SEGMEXEC_TASK_SIZE)
72468 + return -EINVAL;
72469 + } else
72470 +#endif
72471 +
72472 + if (end > TASK_SIZE)
72473 + return -EINVAL;
72474 +
72475 if (end == start)
72476 return 0;
72477
72478 @@ -1370,8 +1396,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72479 */
72480 tcred = __task_cred(task);
72481 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72482 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72483 - !capable(CAP_SYS_NICE)) {
72484 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72485 rcu_read_unlock();
72486 err = -EPERM;
72487 goto out_put;
72488 @@ -1402,6 +1427,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72489 goto out;
72490 }
72491
72492 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72493 + if (mm != current->mm &&
72494 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72495 + mmput(mm);
72496 + err = -EPERM;
72497 + goto out;
72498 + }
72499 +#endif
72500 +
72501 err = do_migrate_pages(mm, old, new,
72502 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72503
72504 diff --git a/mm/migrate.c b/mm/migrate.c
72505 index 77ed2d7..317d528 100644
72506 --- a/mm/migrate.c
72507 +++ b/mm/migrate.c
72508 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72509 */
72510 tcred = __task_cred(task);
72511 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72512 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72513 - !capable(CAP_SYS_NICE)) {
72514 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72515 rcu_read_unlock();
72516 err = -EPERM;
72517 goto out;
72518 diff --git a/mm/mlock.c b/mm/mlock.c
72519 index ef726e8..cd7f1ec 100644
72520 --- a/mm/mlock.c
72521 +++ b/mm/mlock.c
72522 @@ -13,6 +13,7 @@
72523 #include <linux/pagemap.h>
72524 #include <linux/mempolicy.h>
72525 #include <linux/syscalls.h>
72526 +#include <linux/security.h>
72527 #include <linux/sched.h>
72528 #include <linux/export.h>
72529 #include <linux/rmap.h>
72530 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72531 {
72532 unsigned long nstart, end, tmp;
72533 struct vm_area_struct * vma, * prev;
72534 - int error;
72535 + int error = 0;
72536
72537 VM_BUG_ON(start & ~PAGE_MASK);
72538 VM_BUG_ON(len != PAGE_ALIGN(len));
72539 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72540 return -EINVAL;
72541 if (end == start)
72542 return 0;
72543 + if (end > TASK_SIZE)
72544 + return -EINVAL;
72545 +
72546 vma = find_vma(current->mm, start);
72547 if (!vma || vma->vm_start > start)
72548 return -ENOMEM;
72549 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72550 for (nstart = start ; ; ) {
72551 vm_flags_t newflags;
72552
72553 +#ifdef CONFIG_PAX_SEGMEXEC
72554 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72555 + break;
72556 +#endif
72557 +
72558 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72559
72560 newflags = vma->vm_flags | VM_LOCKED;
72561 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72562 lock_limit >>= PAGE_SHIFT;
72563
72564 /* check against resource limits */
72565 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72566 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72567 error = do_mlock(start, len, 1);
72568 up_write(&current->mm->mmap_sem);
72569 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72570 static int do_mlockall(int flags)
72571 {
72572 struct vm_area_struct * vma, * prev = NULL;
72573 - unsigned int def_flags = 0;
72574
72575 if (flags & MCL_FUTURE)
72576 - def_flags = VM_LOCKED;
72577 - current->mm->def_flags = def_flags;
72578 + current->mm->def_flags |= VM_LOCKED;
72579 + else
72580 + current->mm->def_flags &= ~VM_LOCKED;
72581 if (flags == MCL_FUTURE)
72582 goto out;
72583
72584 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72585 vm_flags_t newflags;
72586
72587 +#ifdef CONFIG_PAX_SEGMEXEC
72588 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72589 + break;
72590 +#endif
72591 +
72592 + BUG_ON(vma->vm_end > TASK_SIZE);
72593 newflags = vma->vm_flags | VM_LOCKED;
72594 if (!(flags & MCL_CURRENT))
72595 newflags &= ~VM_LOCKED;
72596 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72597 lock_limit >>= PAGE_SHIFT;
72598
72599 ret = -ENOMEM;
72600 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72601 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72602 capable(CAP_IPC_LOCK))
72603 ret = do_mlockall(flags);
72604 diff --git a/mm/mmap.c b/mm/mmap.c
72605 index ae18a48..86cf99e 100644
72606 --- a/mm/mmap.c
72607 +++ b/mm/mmap.c
72608 @@ -47,6 +47,16 @@
72609 #define arch_rebalance_pgtables(addr, len) (addr)
72610 #endif
72611
72612 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72613 +{
72614 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72615 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72616 + up_read(&mm->mmap_sem);
72617 + BUG();
72618 + }
72619 +#endif
72620 +}
72621 +
72622 static void unmap_region(struct mm_struct *mm,
72623 struct vm_area_struct *vma, struct vm_area_struct *prev,
72624 unsigned long start, unsigned long end);
72625 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72626 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72627 *
72628 */
72629 -pgprot_t protection_map[16] = {
72630 +pgprot_t protection_map[16] __read_only = {
72631 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72632 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72633 };
72634
72635 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72636 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72637 {
72638 - return __pgprot(pgprot_val(protection_map[vm_flags &
72639 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72640 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72641 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72642 +
72643 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72644 + if (!(__supported_pte_mask & _PAGE_NX) &&
72645 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72646 + (vm_flags & (VM_READ | VM_WRITE)))
72647 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72648 +#endif
72649 +
72650 + return prot;
72651 }
72652 EXPORT_SYMBOL(vm_get_page_prot);
72653
72654 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72655 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72656 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72657 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72658 /*
72659 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72660 * other variables. It can be updated by several CPUs frequently.
72661 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72662 struct vm_area_struct *next = vma->vm_next;
72663
72664 might_sleep();
72665 + BUG_ON(vma->vm_mirror);
72666 if (vma->vm_ops && vma->vm_ops->close)
72667 vma->vm_ops->close(vma);
72668 if (vma->vm_file) {
72669 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72670 * not page aligned -Ram Gupta
72671 */
72672 rlim = rlimit(RLIMIT_DATA);
72673 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72674 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72675 (mm->end_data - mm->start_data) > rlim)
72676 goto out;
72677 @@ -708,6 +730,12 @@ static int
72678 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72679 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72680 {
72681 +
72682 +#ifdef CONFIG_PAX_SEGMEXEC
72683 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72684 + return 0;
72685 +#endif
72686 +
72687 if (is_mergeable_vma(vma, file, vm_flags) &&
72688 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72689 if (vma->vm_pgoff == vm_pgoff)
72690 @@ -727,6 +755,12 @@ static int
72691 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72692 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72693 {
72694 +
72695 +#ifdef CONFIG_PAX_SEGMEXEC
72696 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72697 + return 0;
72698 +#endif
72699 +
72700 if (is_mergeable_vma(vma, file, vm_flags) &&
72701 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72702 pgoff_t vm_pglen;
72703 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72704 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72705 struct vm_area_struct *prev, unsigned long addr,
72706 unsigned long end, unsigned long vm_flags,
72707 - struct anon_vma *anon_vma, struct file *file,
72708 + struct anon_vma *anon_vma, struct file *file,
72709 pgoff_t pgoff, struct mempolicy *policy)
72710 {
72711 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72712 struct vm_area_struct *area, *next;
72713 int err;
72714
72715 +#ifdef CONFIG_PAX_SEGMEXEC
72716 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72717 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72718 +
72719 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72720 +#endif
72721 +
72722 /*
72723 * We later require that vma->vm_flags == vm_flags,
72724 * so this tests vma->vm_flags & VM_SPECIAL, too.
72725 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72726 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72727 next = next->vm_next;
72728
72729 +#ifdef CONFIG_PAX_SEGMEXEC
72730 + if (prev)
72731 + prev_m = pax_find_mirror_vma(prev);
72732 + if (area)
72733 + area_m = pax_find_mirror_vma(area);
72734 + if (next)
72735 + next_m = pax_find_mirror_vma(next);
72736 +#endif
72737 +
72738 /*
72739 * Can it merge with the predecessor?
72740 */
72741 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72742 /* cases 1, 6 */
72743 err = vma_adjust(prev, prev->vm_start,
72744 next->vm_end, prev->vm_pgoff, NULL);
72745 - } else /* cases 2, 5, 7 */
72746 +
72747 +#ifdef CONFIG_PAX_SEGMEXEC
72748 + if (!err && prev_m)
72749 + err = vma_adjust(prev_m, prev_m->vm_start,
72750 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72751 +#endif
72752 +
72753 + } else { /* cases 2, 5, 7 */
72754 err = vma_adjust(prev, prev->vm_start,
72755 end, prev->vm_pgoff, NULL);
72756 +
72757 +#ifdef CONFIG_PAX_SEGMEXEC
72758 + if (!err && prev_m)
72759 + err = vma_adjust(prev_m, prev_m->vm_start,
72760 + end_m, prev_m->vm_pgoff, NULL);
72761 +#endif
72762 +
72763 + }
72764 if (err)
72765 return NULL;
72766 khugepaged_enter_vma_merge(prev);
72767 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72768 mpol_equal(policy, vma_policy(next)) &&
72769 can_vma_merge_before(next, vm_flags,
72770 anon_vma, file, pgoff+pglen)) {
72771 - if (prev && addr < prev->vm_end) /* case 4 */
72772 + if (prev && addr < prev->vm_end) { /* case 4 */
72773 err = vma_adjust(prev, prev->vm_start,
72774 addr, prev->vm_pgoff, NULL);
72775 - else /* cases 3, 8 */
72776 +
72777 +#ifdef CONFIG_PAX_SEGMEXEC
72778 + if (!err && prev_m)
72779 + err = vma_adjust(prev_m, prev_m->vm_start,
72780 + addr_m, prev_m->vm_pgoff, NULL);
72781 +#endif
72782 +
72783 + } else { /* cases 3, 8 */
72784 err = vma_adjust(area, addr, next->vm_end,
72785 next->vm_pgoff - pglen, NULL);
72786 +
72787 +#ifdef CONFIG_PAX_SEGMEXEC
72788 + if (!err && area_m)
72789 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72790 + next_m->vm_pgoff - pglen, NULL);
72791 +#endif
72792 +
72793 + }
72794 if (err)
72795 return NULL;
72796 khugepaged_enter_vma_merge(area);
72797 @@ -940,16 +1020,13 @@ none:
72798 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72799 struct file *file, long pages)
72800 {
72801 - const unsigned long stack_flags
72802 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72803 -
72804 mm->total_vm += pages;
72805
72806 if (file) {
72807 mm->shared_vm += pages;
72808 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72809 mm->exec_vm += pages;
72810 - } else if (flags & stack_flags)
72811 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72812 mm->stack_vm += pages;
72813 if (flags & (VM_RESERVED|VM_IO))
72814 mm->reserved_vm += pages;
72815 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72816 * (the exception is when the underlying filesystem is noexec
72817 * mounted, in which case we dont add PROT_EXEC.)
72818 */
72819 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72820 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72821 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72822 prot |= PROT_EXEC;
72823
72824 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72825 /* Obtain the address to map to. we verify (or select) it and ensure
72826 * that it represents a valid section of the address space.
72827 */
72828 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72829 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72830 if (addr & ~PAGE_MASK)
72831 return addr;
72832
72833 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72834 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72835 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72836
72837 +#ifdef CONFIG_PAX_MPROTECT
72838 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72839 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72840 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72841 + gr_log_rwxmmap(file);
72842 +
72843 +#ifdef CONFIG_PAX_EMUPLT
72844 + vm_flags &= ~VM_EXEC;
72845 +#else
72846 + return -EPERM;
72847 +#endif
72848 +
72849 + }
72850 +
72851 + if (!(vm_flags & VM_EXEC))
72852 + vm_flags &= ~VM_MAYEXEC;
72853 +#else
72854 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72855 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72856 +#endif
72857 + else
72858 + vm_flags &= ~VM_MAYWRITE;
72859 + }
72860 +#endif
72861 +
72862 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72863 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72864 + vm_flags &= ~VM_PAGEEXEC;
72865 +#endif
72866 +
72867 if (flags & MAP_LOCKED)
72868 if (!can_do_mlock())
72869 return -EPERM;
72870 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72871 locked += mm->locked_vm;
72872 lock_limit = rlimit(RLIMIT_MEMLOCK);
72873 lock_limit >>= PAGE_SHIFT;
72874 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72875 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72876 return -EAGAIN;
72877 }
72878 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72879 }
72880 }
72881
72882 + if (!gr_acl_handle_mmap(file, prot))
72883 + return -EACCES;
72884 +
72885 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72886 }
72887
72888 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72889 vm_flags_t vm_flags = vma->vm_flags;
72890
72891 /* If it was private or non-writable, the write bit is already clear */
72892 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72893 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72894 return 0;
72895
72896 /* The backer wishes to know when pages are first written to? */
72897 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72898 unsigned long charged = 0;
72899 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72900
72901 +#ifdef CONFIG_PAX_SEGMEXEC
72902 + struct vm_area_struct *vma_m = NULL;
72903 +#endif
72904 +
72905 + /*
72906 + * mm->mmap_sem is required to protect against another thread
72907 + * changing the mappings in case we sleep.
72908 + */
72909 + verify_mm_writelocked(mm);
72910 +
72911 /* Clear old maps */
72912 error = -ENOMEM;
72913 -munmap_back:
72914 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72915 if (vma && vma->vm_start < addr + len) {
72916 if (do_munmap(mm, addr, len))
72917 return -ENOMEM;
72918 - goto munmap_back;
72919 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72920 + BUG_ON(vma && vma->vm_start < addr + len);
72921 }
72922
72923 /* Check against address space limit. */
72924 @@ -1282,6 +1403,16 @@ munmap_back:
72925 goto unacct_error;
72926 }
72927
72928 +#ifdef CONFIG_PAX_SEGMEXEC
72929 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72930 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72931 + if (!vma_m) {
72932 + error = -ENOMEM;
72933 + goto free_vma;
72934 + }
72935 + }
72936 +#endif
72937 +
72938 vma->vm_mm = mm;
72939 vma->vm_start = addr;
72940 vma->vm_end = addr + len;
72941 @@ -1306,6 +1437,19 @@ munmap_back:
72942 error = file->f_op->mmap(file, vma);
72943 if (error)
72944 goto unmap_and_free_vma;
72945 +
72946 +#ifdef CONFIG_PAX_SEGMEXEC
72947 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72948 + added_exe_file_vma(mm);
72949 +#endif
72950 +
72951 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72952 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72953 + vma->vm_flags |= VM_PAGEEXEC;
72954 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72955 + }
72956 +#endif
72957 +
72958 if (vm_flags & VM_EXECUTABLE)
72959 added_exe_file_vma(mm);
72960
72961 @@ -1343,6 +1487,11 @@ munmap_back:
72962 vma_link(mm, vma, prev, rb_link, rb_parent);
72963 file = vma->vm_file;
72964
72965 +#ifdef CONFIG_PAX_SEGMEXEC
72966 + if (vma_m)
72967 + BUG_ON(pax_mirror_vma(vma_m, vma));
72968 +#endif
72969 +
72970 /* Once vma denies write, undo our temporary denial count */
72971 if (correct_wcount)
72972 atomic_inc(&inode->i_writecount);
72973 @@ -1350,6 +1499,7 @@ out:
72974 perf_event_mmap(vma);
72975
72976 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72977 + track_exec_limit(mm, addr, addr + len, vm_flags);
72978 if (vm_flags & VM_LOCKED) {
72979 if (!mlock_vma_pages_range(vma, addr, addr + len))
72980 mm->locked_vm += (len >> PAGE_SHIFT);
72981 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
72982 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
72983 charged = 0;
72984 free_vma:
72985 +
72986 +#ifdef CONFIG_PAX_SEGMEXEC
72987 + if (vma_m)
72988 + kmem_cache_free(vm_area_cachep, vma_m);
72989 +#endif
72990 +
72991 kmem_cache_free(vm_area_cachep, vma);
72992 unacct_error:
72993 if (charged)
72994 @@ -1378,6 +1534,44 @@ unacct_error:
72995 return error;
72996 }
72997
72998 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
72999 +{
73000 + if (!vma) {
73001 +#ifdef CONFIG_STACK_GROWSUP
73002 + if (addr > sysctl_heap_stack_gap)
73003 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73004 + else
73005 + vma = find_vma(current->mm, 0);
73006 + if (vma && (vma->vm_flags & VM_GROWSUP))
73007 + return false;
73008 +#endif
73009 + return true;
73010 + }
73011 +
73012 + if (addr + len > vma->vm_start)
73013 + return false;
73014 +
73015 + if (vma->vm_flags & VM_GROWSDOWN)
73016 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73017 +#ifdef CONFIG_STACK_GROWSUP
73018 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73019 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73020 +#endif
73021 +
73022 + return true;
73023 +}
73024 +
73025 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73026 +{
73027 + if (vma->vm_start < len)
73028 + return -ENOMEM;
73029 + if (!(vma->vm_flags & VM_GROWSDOWN))
73030 + return vma->vm_start - len;
73031 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73032 + return vma->vm_start - len - sysctl_heap_stack_gap;
73033 + return -ENOMEM;
73034 +}
73035 +
73036 /* Get an address range which is currently unmapped.
73037 * For shmat() with addr=0.
73038 *
73039 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73040 if (flags & MAP_FIXED)
73041 return addr;
73042
73043 +#ifdef CONFIG_PAX_RANDMMAP
73044 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73045 +#endif
73046 +
73047 if (addr) {
73048 addr = PAGE_ALIGN(addr);
73049 - vma = find_vma(mm, addr);
73050 - if (TASK_SIZE - len >= addr &&
73051 - (!vma || addr + len <= vma->vm_start))
73052 - return addr;
73053 + if (TASK_SIZE - len >= addr) {
73054 + vma = find_vma(mm, addr);
73055 + if (check_heap_stack_gap(vma, addr, len))
73056 + return addr;
73057 + }
73058 }
73059 if (len > mm->cached_hole_size) {
73060 - start_addr = addr = mm->free_area_cache;
73061 + start_addr = addr = mm->free_area_cache;
73062 } else {
73063 - start_addr = addr = TASK_UNMAPPED_BASE;
73064 - mm->cached_hole_size = 0;
73065 + start_addr = addr = mm->mmap_base;
73066 + mm->cached_hole_size = 0;
73067 }
73068
73069 full_search:
73070 @@ -1426,34 +1625,40 @@ full_search:
73071 * Start a new search - just in case we missed
73072 * some holes.
73073 */
73074 - if (start_addr != TASK_UNMAPPED_BASE) {
73075 - addr = TASK_UNMAPPED_BASE;
73076 - start_addr = addr;
73077 + if (start_addr != mm->mmap_base) {
73078 + start_addr = addr = mm->mmap_base;
73079 mm->cached_hole_size = 0;
73080 goto full_search;
73081 }
73082 return -ENOMEM;
73083 }
73084 - if (!vma || addr + len <= vma->vm_start) {
73085 - /*
73086 - * Remember the place where we stopped the search:
73087 - */
73088 - mm->free_area_cache = addr + len;
73089 - return addr;
73090 - }
73091 + if (check_heap_stack_gap(vma, addr, len))
73092 + break;
73093 if (addr + mm->cached_hole_size < vma->vm_start)
73094 mm->cached_hole_size = vma->vm_start - addr;
73095 addr = vma->vm_end;
73096 }
73097 +
73098 + /*
73099 + * Remember the place where we stopped the search:
73100 + */
73101 + mm->free_area_cache = addr + len;
73102 + return addr;
73103 }
73104 #endif
73105
73106 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73107 {
73108 +
73109 +#ifdef CONFIG_PAX_SEGMEXEC
73110 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73111 + return;
73112 +#endif
73113 +
73114 /*
73115 * Is this a new hole at the lowest possible address?
73116 */
73117 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73118 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73119 mm->free_area_cache = addr;
73120 }
73121
73122 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73123 {
73124 struct vm_area_struct *vma;
73125 struct mm_struct *mm = current->mm;
73126 - unsigned long addr = addr0, start_addr;
73127 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73128
73129 /* requested length too big for entire address space */
73130 if (len > TASK_SIZE)
73131 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73132 if (flags & MAP_FIXED)
73133 return addr;
73134
73135 +#ifdef CONFIG_PAX_RANDMMAP
73136 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73137 +#endif
73138 +
73139 /* requesting a specific address */
73140 if (addr) {
73141 addr = PAGE_ALIGN(addr);
73142 - vma = find_vma(mm, addr);
73143 - if (TASK_SIZE - len >= addr &&
73144 - (!vma || addr + len <= vma->vm_start))
73145 - return addr;
73146 + if (TASK_SIZE - len >= addr) {
73147 + vma = find_vma(mm, addr);
73148 + if (check_heap_stack_gap(vma, addr, len))
73149 + return addr;
73150 + }
73151 }
73152
73153 /* check if free_area_cache is useful for us */
73154 @@ -1508,7 +1718,7 @@ try_again:
73155 * return with success:
73156 */
73157 vma = find_vma(mm, addr);
73158 - if (!vma || addr+len <= vma->vm_start)
73159 + if (check_heap_stack_gap(vma, addr, len))
73160 /* remember the address as a hint for next time */
73161 return (mm->free_area_cache = addr);
73162
73163 @@ -1517,8 +1727,8 @@ try_again:
73164 mm->cached_hole_size = vma->vm_start - addr;
73165
73166 /* try just below the current vma->vm_start */
73167 - addr = vma->vm_start-len;
73168 - } while (len < vma->vm_start);
73169 + addr = skip_heap_stack_gap(vma, len);
73170 + } while (!IS_ERR_VALUE(addr));
73171
73172 fail:
73173 /*
73174 @@ -1541,13 +1751,21 @@ fail:
73175 * can happen with large stack limits and large mmap()
73176 * allocations.
73177 */
73178 + mm->mmap_base = TASK_UNMAPPED_BASE;
73179 +
73180 +#ifdef CONFIG_PAX_RANDMMAP
73181 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73182 + mm->mmap_base += mm->delta_mmap;
73183 +#endif
73184 +
73185 + mm->free_area_cache = mm->mmap_base;
73186 mm->cached_hole_size = ~0UL;
73187 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73188 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73189 /*
73190 * Restore the topdown base:
73191 */
73192 - mm->free_area_cache = mm->mmap_base;
73193 + mm->mmap_base = base;
73194 + mm->free_area_cache = base;
73195 mm->cached_hole_size = ~0UL;
73196
73197 return addr;
73198 @@ -1556,6 +1774,12 @@ fail:
73199
73200 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73201 {
73202 +
73203 +#ifdef CONFIG_PAX_SEGMEXEC
73204 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73205 + return;
73206 +#endif
73207 +
73208 /*
73209 * Is this a new hole at the highest possible address?
73210 */
73211 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73212 mm->free_area_cache = addr;
73213
73214 /* dont allow allocations above current base */
73215 - if (mm->free_area_cache > mm->mmap_base)
73216 + if (mm->free_area_cache > mm->mmap_base) {
73217 mm->free_area_cache = mm->mmap_base;
73218 + mm->cached_hole_size = ~0UL;
73219 + }
73220 }
73221
73222 unsigned long
73223 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73224 return vma;
73225 }
73226
73227 +#ifdef CONFIG_PAX_SEGMEXEC
73228 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73229 +{
73230 + struct vm_area_struct *vma_m;
73231 +
73232 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73233 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73234 + BUG_ON(vma->vm_mirror);
73235 + return NULL;
73236 + }
73237 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73238 + vma_m = vma->vm_mirror;
73239 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73240 + BUG_ON(vma->vm_file != vma_m->vm_file);
73241 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73242 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73243 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73244 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73245 + return vma_m;
73246 +}
73247 +#endif
73248 +
73249 /*
73250 * Verify that the stack growth is acceptable and
73251 * update accounting. This is shared with both the
73252 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73253 return -ENOMEM;
73254
73255 /* Stack limit test */
73256 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73257 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73258 return -ENOMEM;
73259
73260 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73261 locked = mm->locked_vm + grow;
73262 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73263 limit >>= PAGE_SHIFT;
73264 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73265 if (locked > limit && !capable(CAP_IPC_LOCK))
73266 return -ENOMEM;
73267 }
73268 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73269 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73270 * vma is the last one with address > vma->vm_end. Have to extend vma.
73271 */
73272 +#ifndef CONFIG_IA64
73273 +static
73274 +#endif
73275 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73276 {
73277 int error;
73278 + bool locknext;
73279
73280 if (!(vma->vm_flags & VM_GROWSUP))
73281 return -EFAULT;
73282
73283 + /* Also guard against wrapping around to address 0. */
73284 + if (address < PAGE_ALIGN(address+1))
73285 + address = PAGE_ALIGN(address+1);
73286 + else
73287 + return -ENOMEM;
73288 +
73289 /*
73290 * We must make sure the anon_vma is allocated
73291 * so that the anon_vma locking is not a noop.
73292 */
73293 if (unlikely(anon_vma_prepare(vma)))
73294 return -ENOMEM;
73295 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73296 + if (locknext && anon_vma_prepare(vma->vm_next))
73297 + return -ENOMEM;
73298 vma_lock_anon_vma(vma);
73299 + if (locknext)
73300 + vma_lock_anon_vma(vma->vm_next);
73301
73302 /*
73303 * vma->vm_start/vm_end cannot change under us because the caller
73304 * is required to hold the mmap_sem in read mode. We need the
73305 - * anon_vma lock to serialize against concurrent expand_stacks.
73306 - * Also guard against wrapping around to address 0.
73307 + * anon_vma locks to serialize against concurrent expand_stacks
73308 + * and expand_upwards.
73309 */
73310 - if (address < PAGE_ALIGN(address+4))
73311 - address = PAGE_ALIGN(address+4);
73312 - else {
73313 - vma_unlock_anon_vma(vma);
73314 - return -ENOMEM;
73315 - }
73316 error = 0;
73317
73318 /* Somebody else might have raced and expanded it already */
73319 - if (address > vma->vm_end) {
73320 + 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)
73321 + error = -ENOMEM;
73322 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73323 unsigned long size, grow;
73324
73325 size = address - vma->vm_start;
73326 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73327 }
73328 }
73329 }
73330 + if (locknext)
73331 + vma_unlock_anon_vma(vma->vm_next);
73332 vma_unlock_anon_vma(vma);
73333 khugepaged_enter_vma_merge(vma);
73334 return error;
73335 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73336 unsigned long address)
73337 {
73338 int error;
73339 + bool lockprev = false;
73340 + struct vm_area_struct *prev;
73341
73342 /*
73343 * We must make sure the anon_vma is allocated
73344 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73345 if (error)
73346 return error;
73347
73348 + prev = vma->vm_prev;
73349 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73350 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73351 +#endif
73352 + if (lockprev && anon_vma_prepare(prev))
73353 + return -ENOMEM;
73354 + if (lockprev)
73355 + vma_lock_anon_vma(prev);
73356 +
73357 vma_lock_anon_vma(vma);
73358
73359 /*
73360 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73361 */
73362
73363 /* Somebody else might have raced and expanded it already */
73364 - if (address < vma->vm_start) {
73365 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73366 + error = -ENOMEM;
73367 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73368 unsigned long size, grow;
73369
73370 +#ifdef CONFIG_PAX_SEGMEXEC
73371 + struct vm_area_struct *vma_m;
73372 +
73373 + vma_m = pax_find_mirror_vma(vma);
73374 +#endif
73375 +
73376 size = vma->vm_end - address;
73377 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73378
73379 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73380 if (!error) {
73381 vma->vm_start = address;
73382 vma->vm_pgoff -= grow;
73383 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73384 +
73385 +#ifdef CONFIG_PAX_SEGMEXEC
73386 + if (vma_m) {
73387 + vma_m->vm_start -= grow << PAGE_SHIFT;
73388 + vma_m->vm_pgoff -= grow;
73389 + }
73390 +#endif
73391 +
73392 perf_event_mmap(vma);
73393 }
73394 }
73395 }
73396 vma_unlock_anon_vma(vma);
73397 + if (lockprev)
73398 + vma_unlock_anon_vma(prev);
73399 khugepaged_enter_vma_merge(vma);
73400 return error;
73401 }
73402 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73403 do {
73404 long nrpages = vma_pages(vma);
73405
73406 +#ifdef CONFIG_PAX_SEGMEXEC
73407 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73408 + vma = remove_vma(vma);
73409 + continue;
73410 + }
73411 +#endif
73412 +
73413 if (vma->vm_flags & VM_ACCOUNT)
73414 nr_accounted += nrpages;
73415 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73416 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73417 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73418 vma->vm_prev = NULL;
73419 do {
73420 +
73421 +#ifdef CONFIG_PAX_SEGMEXEC
73422 + if (vma->vm_mirror) {
73423 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73424 + vma->vm_mirror->vm_mirror = NULL;
73425 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73426 + vma->vm_mirror = NULL;
73427 + }
73428 +#endif
73429 +
73430 rb_erase(&vma->vm_rb, &mm->mm_rb);
73431 mm->map_count--;
73432 tail_vma = vma;
73433 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73434 struct vm_area_struct *new;
73435 int err = -ENOMEM;
73436
73437 +#ifdef CONFIG_PAX_SEGMEXEC
73438 + struct vm_area_struct *vma_m, *new_m = NULL;
73439 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73440 +#endif
73441 +
73442 if (is_vm_hugetlb_page(vma) && (addr &
73443 ~(huge_page_mask(hstate_vma(vma)))))
73444 return -EINVAL;
73445
73446 +#ifdef CONFIG_PAX_SEGMEXEC
73447 + vma_m = pax_find_mirror_vma(vma);
73448 +#endif
73449 +
73450 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73451 if (!new)
73452 goto out_err;
73453
73454 +#ifdef CONFIG_PAX_SEGMEXEC
73455 + if (vma_m) {
73456 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73457 + if (!new_m) {
73458 + kmem_cache_free(vm_area_cachep, new);
73459 + goto out_err;
73460 + }
73461 + }
73462 +#endif
73463 +
73464 /* most fields are the same, copy all, and then fixup */
73465 *new = *vma;
73466
73467 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73468 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73469 }
73470
73471 +#ifdef CONFIG_PAX_SEGMEXEC
73472 + if (vma_m) {
73473 + *new_m = *vma_m;
73474 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73475 + new_m->vm_mirror = new;
73476 + new->vm_mirror = new_m;
73477 +
73478 + if (new_below)
73479 + new_m->vm_end = addr_m;
73480 + else {
73481 + new_m->vm_start = addr_m;
73482 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73483 + }
73484 + }
73485 +#endif
73486 +
73487 pol = mpol_dup(vma_policy(vma));
73488 if (IS_ERR(pol)) {
73489 err = PTR_ERR(pol);
73490 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73491 else
73492 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73493
73494 +#ifdef CONFIG_PAX_SEGMEXEC
73495 + if (!err && vma_m) {
73496 + if (anon_vma_clone(new_m, vma_m))
73497 + goto out_free_mpol;
73498 +
73499 + mpol_get(pol);
73500 + vma_set_policy(new_m, pol);
73501 +
73502 + if (new_m->vm_file) {
73503 + get_file(new_m->vm_file);
73504 + if (vma_m->vm_flags & VM_EXECUTABLE)
73505 + added_exe_file_vma(mm);
73506 + }
73507 +
73508 + if (new_m->vm_ops && new_m->vm_ops->open)
73509 + new_m->vm_ops->open(new_m);
73510 +
73511 + if (new_below)
73512 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73513 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73514 + else
73515 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73516 +
73517 + if (err) {
73518 + if (new_m->vm_ops && new_m->vm_ops->close)
73519 + new_m->vm_ops->close(new_m);
73520 + if (new_m->vm_file) {
73521 + if (vma_m->vm_flags & VM_EXECUTABLE)
73522 + removed_exe_file_vma(mm);
73523 + fput(new_m->vm_file);
73524 + }
73525 + mpol_put(pol);
73526 + }
73527 + }
73528 +#endif
73529 +
73530 /* Success. */
73531 if (!err)
73532 return 0;
73533 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73534 removed_exe_file_vma(mm);
73535 fput(new->vm_file);
73536 }
73537 - unlink_anon_vmas(new);
73538 out_free_mpol:
73539 mpol_put(pol);
73540 out_free_vma:
73541 +
73542 +#ifdef CONFIG_PAX_SEGMEXEC
73543 + if (new_m) {
73544 + unlink_anon_vmas(new_m);
73545 + kmem_cache_free(vm_area_cachep, new_m);
73546 + }
73547 +#endif
73548 +
73549 + unlink_anon_vmas(new);
73550 kmem_cache_free(vm_area_cachep, new);
73551 out_err:
73552 return err;
73553 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73554 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73555 unsigned long addr, int new_below)
73556 {
73557 +
73558 +#ifdef CONFIG_PAX_SEGMEXEC
73559 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73560 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73561 + if (mm->map_count >= sysctl_max_map_count-1)
73562 + return -ENOMEM;
73563 + } else
73564 +#endif
73565 +
73566 if (mm->map_count >= sysctl_max_map_count)
73567 return -ENOMEM;
73568
73569 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73570 * work. This now handles partial unmappings.
73571 * Jeremy Fitzhardinge <jeremy@goop.org>
73572 */
73573 +#ifdef CONFIG_PAX_SEGMEXEC
73574 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73575 {
73576 + int ret = __do_munmap(mm, start, len);
73577 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73578 + return ret;
73579 +
73580 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73581 +}
73582 +
73583 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73584 +#else
73585 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73586 +#endif
73587 +{
73588 unsigned long end;
73589 struct vm_area_struct *vma, *prev, *last;
73590
73591 + /*
73592 + * mm->mmap_sem is required to protect against another thread
73593 + * changing the mappings in case we sleep.
73594 + */
73595 + verify_mm_writelocked(mm);
73596 +
73597 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73598 return -EINVAL;
73599
73600 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73601 /* Fix up all other VM information */
73602 remove_vma_list(mm, vma);
73603
73604 + track_exec_limit(mm, start, end, 0UL);
73605 +
73606 return 0;
73607 }
73608
73609 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73610 int ret;
73611 struct mm_struct *mm = current->mm;
73612
73613 +
73614 +#ifdef CONFIG_PAX_SEGMEXEC
73615 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73616 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73617 + return -EINVAL;
73618 +#endif
73619 +
73620 down_write(&mm->mmap_sem);
73621 ret = do_munmap(mm, start, len);
73622 up_write(&mm->mmap_sem);
73623 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73624 return vm_munmap(addr, len);
73625 }
73626
73627 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73628 -{
73629 -#ifdef CONFIG_DEBUG_VM
73630 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73631 - WARN_ON(1);
73632 - up_read(&mm->mmap_sem);
73633 - }
73634 -#endif
73635 -}
73636 -
73637 /*
73638 * this is really a simplified "do_mmap". it only handles
73639 * anonymous maps. eventually we may be able to do some
73640 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73641 struct rb_node ** rb_link, * rb_parent;
73642 pgoff_t pgoff = addr >> PAGE_SHIFT;
73643 int error;
73644 + unsigned long charged;
73645
73646 len = PAGE_ALIGN(len);
73647 if (!len)
73648 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73649
73650 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73651
73652 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73653 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73654 + flags &= ~VM_EXEC;
73655 +
73656 +#ifdef CONFIG_PAX_MPROTECT
73657 + if (mm->pax_flags & MF_PAX_MPROTECT)
73658 + flags &= ~VM_MAYEXEC;
73659 +#endif
73660 +
73661 + }
73662 +#endif
73663 +
73664 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73665 if (error & ~PAGE_MASK)
73666 return error;
73667
73668 + charged = len >> PAGE_SHIFT;
73669 +
73670 /*
73671 * mlock MCL_FUTURE?
73672 */
73673 if (mm->def_flags & VM_LOCKED) {
73674 unsigned long locked, lock_limit;
73675 - locked = len >> PAGE_SHIFT;
73676 + locked = charged;
73677 locked += mm->locked_vm;
73678 lock_limit = rlimit(RLIMIT_MEMLOCK);
73679 lock_limit >>= PAGE_SHIFT;
73680 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73681 /*
73682 * Clear old maps. this also does some error checking for us
73683 */
73684 - munmap_back:
73685 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73686 if (vma && vma->vm_start < addr + len) {
73687 if (do_munmap(mm, addr, len))
73688 return -ENOMEM;
73689 - goto munmap_back;
73690 - }
73691 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73692 + BUG_ON(vma && vma->vm_start < addr + len);
73693 + }
73694
73695 /* Check against address space limits *after* clearing old maps... */
73696 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73697 + if (!may_expand_vm(mm, charged))
73698 return -ENOMEM;
73699
73700 if (mm->map_count > sysctl_max_map_count)
73701 return -ENOMEM;
73702
73703 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73704 + if (security_vm_enough_memory_mm(mm, charged))
73705 return -ENOMEM;
73706
73707 /* Can we just expand an old private anonymous mapping? */
73708 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73709 */
73710 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73711 if (!vma) {
73712 - vm_unacct_memory(len >> PAGE_SHIFT);
73713 + vm_unacct_memory(charged);
73714 return -ENOMEM;
73715 }
73716
73717 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73718 vma_link(mm, vma, prev, rb_link, rb_parent);
73719 out:
73720 perf_event_mmap(vma);
73721 - mm->total_vm += len >> PAGE_SHIFT;
73722 + mm->total_vm += charged;
73723 if (flags & VM_LOCKED) {
73724 if (!mlock_vma_pages_range(vma, addr, addr + len))
73725 - mm->locked_vm += (len >> PAGE_SHIFT);
73726 + mm->locked_vm += charged;
73727 }
73728 + track_exec_limit(mm, addr, addr + len, flags);
73729 return addr;
73730 }
73731
73732 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73733 while (vma) {
73734 if (vma->vm_flags & VM_ACCOUNT)
73735 nr_accounted += vma_pages(vma);
73736 + vma->vm_mirror = NULL;
73737 vma = remove_vma(vma);
73738 }
73739 vm_unacct_memory(nr_accounted);
73740 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73741 struct vm_area_struct * __vma, * prev;
73742 struct rb_node ** rb_link, * rb_parent;
73743
73744 +#ifdef CONFIG_PAX_SEGMEXEC
73745 + struct vm_area_struct *vma_m = NULL;
73746 +#endif
73747 +
73748 + if (security_mmap_addr(vma->vm_start))
73749 + return -EPERM;
73750 +
73751 /*
73752 * The vm_pgoff of a purely anonymous vma should be irrelevant
73753 * until its first write fault, when page's anon_vma and index
73754 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73755 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73756 return -ENOMEM;
73757
73758 +#ifdef CONFIG_PAX_SEGMEXEC
73759 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73760 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73761 + if (!vma_m)
73762 + return -ENOMEM;
73763 + }
73764 +#endif
73765 +
73766 vma_link(mm, vma, prev, rb_link, rb_parent);
73767 +
73768 +#ifdef CONFIG_PAX_SEGMEXEC
73769 + if (vma_m)
73770 + BUG_ON(pax_mirror_vma(vma_m, vma));
73771 +#endif
73772 +
73773 return 0;
73774 }
73775
73776 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73777 struct mempolicy *pol;
73778 bool faulted_in_anon_vma = true;
73779
73780 + BUG_ON(vma->vm_mirror);
73781 +
73782 /*
73783 * If anonymous vma has not yet been faulted, update new pgoff
73784 * to match new location, to increase its chance of merging.
73785 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73786 return NULL;
73787 }
73788
73789 +#ifdef CONFIG_PAX_SEGMEXEC
73790 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73791 +{
73792 + struct vm_area_struct *prev_m;
73793 + struct rb_node **rb_link_m, *rb_parent_m;
73794 + struct mempolicy *pol_m;
73795 +
73796 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73797 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73798 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73799 + *vma_m = *vma;
73800 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73801 + if (anon_vma_clone(vma_m, vma))
73802 + return -ENOMEM;
73803 + pol_m = vma_policy(vma_m);
73804 + mpol_get(pol_m);
73805 + vma_set_policy(vma_m, pol_m);
73806 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73807 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73808 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73809 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73810 + if (vma_m->vm_file)
73811 + get_file(vma_m->vm_file);
73812 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73813 + vma_m->vm_ops->open(vma_m);
73814 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73815 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73816 + vma_m->vm_mirror = vma;
73817 + vma->vm_mirror = vma_m;
73818 + return 0;
73819 +}
73820 +#endif
73821 +
73822 /*
73823 * Return true if the calling process may expand its vm space by the passed
73824 * number of pages
73825 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73826
73827 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73828
73829 +#ifdef CONFIG_PAX_RANDMMAP
73830 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73831 + cur -= mm->brk_gap;
73832 +#endif
73833 +
73834 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73835 if (cur + npages > lim)
73836 return 0;
73837 return 1;
73838 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
73839 vma->vm_start = addr;
73840 vma->vm_end = addr + len;
73841
73842 +#ifdef CONFIG_PAX_MPROTECT
73843 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73844 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73845 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73846 + return -EPERM;
73847 + if (!(vm_flags & VM_EXEC))
73848 + vm_flags &= ~VM_MAYEXEC;
73849 +#else
73850 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73851 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73852 +#endif
73853 + else
73854 + vm_flags &= ~VM_MAYWRITE;
73855 + }
73856 +#endif
73857 +
73858 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73859 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73860
73861 diff --git a/mm/mprotect.c b/mm/mprotect.c
73862 index a409926..8b32e6d 100644
73863 --- a/mm/mprotect.c
73864 +++ b/mm/mprotect.c
73865 @@ -23,10 +23,17 @@
73866 #include <linux/mmu_notifier.h>
73867 #include <linux/migrate.h>
73868 #include <linux/perf_event.h>
73869 +
73870 +#ifdef CONFIG_PAX_MPROTECT
73871 +#include <linux/elf.h>
73872 +#include <linux/binfmts.h>
73873 +#endif
73874 +
73875 #include <asm/uaccess.h>
73876 #include <asm/pgtable.h>
73877 #include <asm/cacheflush.h>
73878 #include <asm/tlbflush.h>
73879 +#include <asm/mmu_context.h>
73880
73881 #ifndef pgprot_modify
73882 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73883 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73884 flush_tlb_range(vma, start, end);
73885 }
73886
73887 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73888 +/* called while holding the mmap semaphor for writing except stack expansion */
73889 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73890 +{
73891 + unsigned long oldlimit, newlimit = 0UL;
73892 +
73893 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73894 + return;
73895 +
73896 + spin_lock(&mm->page_table_lock);
73897 + oldlimit = mm->context.user_cs_limit;
73898 + if ((prot & VM_EXEC) && oldlimit < end)
73899 + /* USER_CS limit moved up */
73900 + newlimit = end;
73901 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73902 + /* USER_CS limit moved down */
73903 + newlimit = start;
73904 +
73905 + if (newlimit) {
73906 + mm->context.user_cs_limit = newlimit;
73907 +
73908 +#ifdef CONFIG_SMP
73909 + wmb();
73910 + cpus_clear(mm->context.cpu_user_cs_mask);
73911 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73912 +#endif
73913 +
73914 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73915 + }
73916 + spin_unlock(&mm->page_table_lock);
73917 + if (newlimit == end) {
73918 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73919 +
73920 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73921 + if (is_vm_hugetlb_page(vma))
73922 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73923 + else
73924 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73925 + }
73926 +}
73927 +#endif
73928 +
73929 int
73930 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73931 unsigned long start, unsigned long end, unsigned long newflags)
73932 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73933 int error;
73934 int dirty_accountable = 0;
73935
73936 +#ifdef CONFIG_PAX_SEGMEXEC
73937 + struct vm_area_struct *vma_m = NULL;
73938 + unsigned long start_m, end_m;
73939 +
73940 + start_m = start + SEGMEXEC_TASK_SIZE;
73941 + end_m = end + SEGMEXEC_TASK_SIZE;
73942 +#endif
73943 +
73944 if (newflags == oldflags) {
73945 *pprev = vma;
73946 return 0;
73947 }
73948
73949 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73950 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73951 +
73952 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73953 + return -ENOMEM;
73954 +
73955 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73956 + return -ENOMEM;
73957 + }
73958 +
73959 /*
73960 * If we make a private mapping writable we increase our commit;
73961 * but (without finer accounting) cannot reduce our commit if we
73962 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73963 }
73964 }
73965
73966 +#ifdef CONFIG_PAX_SEGMEXEC
73967 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73968 + if (start != vma->vm_start) {
73969 + error = split_vma(mm, vma, start, 1);
73970 + if (error)
73971 + goto fail;
73972 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73973 + *pprev = (*pprev)->vm_next;
73974 + }
73975 +
73976 + if (end != vma->vm_end) {
73977 + error = split_vma(mm, vma, end, 0);
73978 + if (error)
73979 + goto fail;
73980 + }
73981 +
73982 + if (pax_find_mirror_vma(vma)) {
73983 + error = __do_munmap(mm, start_m, end_m - start_m);
73984 + if (error)
73985 + goto fail;
73986 + } else {
73987 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73988 + if (!vma_m) {
73989 + error = -ENOMEM;
73990 + goto fail;
73991 + }
73992 + vma->vm_flags = newflags;
73993 + error = pax_mirror_vma(vma_m, vma);
73994 + if (error) {
73995 + vma->vm_flags = oldflags;
73996 + goto fail;
73997 + }
73998 + }
73999 + }
74000 +#endif
74001 +
74002 /*
74003 * First try to merge with previous and/or next vma.
74004 */
74005 @@ -204,9 +307,21 @@ success:
74006 * vm_flags and vm_page_prot are protected by the mmap_sem
74007 * held in write mode.
74008 */
74009 +
74010 +#ifdef CONFIG_PAX_SEGMEXEC
74011 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74012 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74013 +#endif
74014 +
74015 vma->vm_flags = newflags;
74016 +
74017 +#ifdef CONFIG_PAX_MPROTECT
74018 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74019 + mm->binfmt->handle_mprotect(vma, newflags);
74020 +#endif
74021 +
74022 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74023 - vm_get_page_prot(newflags));
74024 + vm_get_page_prot(vma->vm_flags));
74025
74026 if (vma_wants_writenotify(vma)) {
74027 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74028 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74029 end = start + len;
74030 if (end <= start)
74031 return -ENOMEM;
74032 +
74033 +#ifdef CONFIG_PAX_SEGMEXEC
74034 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74035 + if (end > SEGMEXEC_TASK_SIZE)
74036 + return -EINVAL;
74037 + } else
74038 +#endif
74039 +
74040 + if (end > TASK_SIZE)
74041 + return -EINVAL;
74042 +
74043 if (!arch_validate_prot(prot))
74044 return -EINVAL;
74045
74046 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74047 /*
74048 * Does the application expect PROT_READ to imply PROT_EXEC:
74049 */
74050 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74051 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74052 prot |= PROT_EXEC;
74053
74054 vm_flags = calc_vm_prot_bits(prot);
74055 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74056 if (start > vma->vm_start)
74057 prev = vma;
74058
74059 +#ifdef CONFIG_PAX_MPROTECT
74060 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74061 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74062 +#endif
74063 +
74064 for (nstart = start ; ; ) {
74065 unsigned long newflags;
74066
74067 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74068
74069 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74070 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74071 + if (prot & (PROT_WRITE | PROT_EXEC))
74072 + gr_log_rwxmprotect(vma->vm_file);
74073 +
74074 + error = -EACCES;
74075 + goto out;
74076 + }
74077 +
74078 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74079 error = -EACCES;
74080 goto out;
74081 }
74082 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74083 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74084 if (error)
74085 goto out;
74086 +
74087 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74088 +
74089 nstart = tmp;
74090
74091 if (nstart < prev->vm_end)
74092 diff --git a/mm/mremap.c b/mm/mremap.c
74093 index cc06d0e..40b5d18 100644
74094 --- a/mm/mremap.c
74095 +++ b/mm/mremap.c
74096 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74097 continue;
74098 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74099 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74100 +
74101 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74102 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74103 + pte = pte_exprotect(pte);
74104 +#endif
74105 +
74106 set_pte_at(mm, new_addr, new_pte, pte);
74107 }
74108
74109 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74110 if (is_vm_hugetlb_page(vma))
74111 goto Einval;
74112
74113 +#ifdef CONFIG_PAX_SEGMEXEC
74114 + if (pax_find_mirror_vma(vma))
74115 + goto Einval;
74116 +#endif
74117 +
74118 /* We can't remap across vm area boundaries */
74119 if (old_len > vma->vm_end - addr)
74120 goto Efault;
74121 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74122 unsigned long ret = -EINVAL;
74123 unsigned long charged = 0;
74124 unsigned long map_flags;
74125 + unsigned long pax_task_size = TASK_SIZE;
74126
74127 if (new_addr & ~PAGE_MASK)
74128 goto out;
74129
74130 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74131 +#ifdef CONFIG_PAX_SEGMEXEC
74132 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74133 + pax_task_size = SEGMEXEC_TASK_SIZE;
74134 +#endif
74135 +
74136 + pax_task_size -= PAGE_SIZE;
74137 +
74138 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74139 goto out;
74140
74141 /* Check if the location we're moving into overlaps the
74142 * old location at all, and fail if it does.
74143 */
74144 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74145 - goto out;
74146 -
74147 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74148 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74149 goto out;
74150
74151 ret = do_munmap(mm, new_addr, new_len);
74152 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74153 struct vm_area_struct *vma;
74154 unsigned long ret = -EINVAL;
74155 unsigned long charged = 0;
74156 + unsigned long pax_task_size = TASK_SIZE;
74157
74158 down_write(&current->mm->mmap_sem);
74159
74160 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74161 if (!new_len)
74162 goto out;
74163
74164 +#ifdef CONFIG_PAX_SEGMEXEC
74165 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74166 + pax_task_size = SEGMEXEC_TASK_SIZE;
74167 +#endif
74168 +
74169 + pax_task_size -= PAGE_SIZE;
74170 +
74171 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74172 + old_len > pax_task_size || addr > pax_task_size-old_len)
74173 + goto out;
74174 +
74175 if (flags & MREMAP_FIXED) {
74176 if (flags & MREMAP_MAYMOVE)
74177 ret = mremap_to(addr, old_len, new_addr, new_len);
74178 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74179 addr + new_len);
74180 }
74181 ret = addr;
74182 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74183 goto out;
74184 }
74185 }
74186 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74187 goto out;
74188 }
74189
74190 + map_flags = vma->vm_flags;
74191 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74192 + if (!(ret & ~PAGE_MASK)) {
74193 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74194 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74195 + }
74196 }
74197 out:
74198 if (ret & ~PAGE_MASK)
74199 diff --git a/mm/nommu.c b/mm/nommu.c
74200 index d4b0c10..ed421b5 100644
74201 --- a/mm/nommu.c
74202 +++ b/mm/nommu.c
74203 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74204 int sysctl_overcommit_ratio = 50; /* default is 50% */
74205 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74206 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74207 -int heap_stack_gap = 0;
74208
74209 atomic_long_t mmap_pages_allocated;
74210
74211 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74212 EXPORT_SYMBOL(find_vma);
74213
74214 /*
74215 - * find a VMA
74216 - * - we don't extend stack VMAs under NOMMU conditions
74217 - */
74218 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74219 -{
74220 - return find_vma(mm, addr);
74221 -}
74222 -
74223 -/*
74224 * expand a stack to a given address
74225 * - not supported under NOMMU conditions
74226 */
74227 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74228
74229 /* most fields are the same, copy all, and then fixup */
74230 *new = *vma;
74231 + INIT_LIST_HEAD(&new->anon_vma_chain);
74232 *region = *vma->vm_region;
74233 new->vm_region = region;
74234
74235 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74236 index c13ea75..081ab2c 100644
74237 --- a/mm/page_alloc.c
74238 +++ b/mm/page_alloc.c
74239 @@ -340,7 +340,7 @@ out:
74240 * This usage means that zero-order pages may not be compound.
74241 */
74242
74243 -static void free_compound_page(struct page *page)
74244 +void free_compound_page(struct page *page)
74245 {
74246 __free_pages_ok(page, compound_order(page));
74247 }
74248 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74249 int i;
74250 int bad = 0;
74251
74252 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74253 + unsigned long index = 1UL << order;
74254 +#endif
74255 +
74256 trace_mm_page_free(page, order);
74257 kmemcheck_free_shadow(page, order);
74258
74259 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74260 debug_check_no_obj_freed(page_address(page),
74261 PAGE_SIZE << order);
74262 }
74263 +
74264 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74265 + for (; index; --index)
74266 + sanitize_highpage(page + index - 1);
74267 +#endif
74268 +
74269 arch_free_page(page, order);
74270 kernel_map_pages(page, 1 << order, 0);
74271
74272 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74273 arch_alloc_page(page, order);
74274 kernel_map_pages(page, 1 << order, 1);
74275
74276 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74277 if (gfp_flags & __GFP_ZERO)
74278 prep_zero_page(page, order, gfp_flags);
74279 +#endif
74280
74281 if (order && (gfp_flags & __GFP_COMP))
74282 prep_compound_page(page, order);
74283 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74284 unsigned long pfn;
74285
74286 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74287 +#ifdef CONFIG_X86_32
74288 + /* boot failures in VMware 8 on 32bit vanilla since
74289 + this change */
74290 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74291 +#else
74292 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74293 +#endif
74294 return 1;
74295 }
74296 return 0;
74297 diff --git a/mm/percpu.c b/mm/percpu.c
74298 index bb4be74..a43ea85 100644
74299 --- a/mm/percpu.c
74300 +++ b/mm/percpu.c
74301 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74302 static unsigned int pcpu_high_unit_cpu __read_mostly;
74303
74304 /* the address of the first chunk which starts with the kernel static area */
74305 -void *pcpu_base_addr __read_mostly;
74306 +void *pcpu_base_addr __read_only;
74307 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74308
74309 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74310 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74311 index 926b466..b23df53 100644
74312 --- a/mm/process_vm_access.c
74313 +++ b/mm/process_vm_access.c
74314 @@ -13,6 +13,7 @@
74315 #include <linux/uio.h>
74316 #include <linux/sched.h>
74317 #include <linux/highmem.h>
74318 +#include <linux/security.h>
74319 #include <linux/ptrace.h>
74320 #include <linux/slab.h>
74321 #include <linux/syscalls.h>
74322 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74323 size_t iov_l_curr_offset = 0;
74324 ssize_t iov_len;
74325
74326 + return -ENOSYS; // PaX: until properly audited
74327 +
74328 /*
74329 * Work out how many pages of struct pages we're going to need
74330 * when eventually calling get_user_pages
74331 */
74332 for (i = 0; i < riovcnt; i++) {
74333 iov_len = rvec[i].iov_len;
74334 - if (iov_len > 0) {
74335 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74336 - + iov_len)
74337 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74338 - / PAGE_SIZE + 1;
74339 - nr_pages = max(nr_pages, nr_pages_iov);
74340 - }
74341 + if (iov_len <= 0)
74342 + continue;
74343 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74344 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74345 + nr_pages = max(nr_pages, nr_pages_iov);
74346 }
74347
74348 if (nr_pages == 0)
74349 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74350 goto free_proc_pages;
74351 }
74352
74353 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74354 + rc = -EPERM;
74355 + goto put_task_struct;
74356 + }
74357 +
74358 mm = mm_access(task, PTRACE_MODE_ATTACH);
74359 if (!mm || IS_ERR(mm)) {
74360 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74361 diff --git a/mm/rmap.c b/mm/rmap.c
74362 index aa95e59..b681a63 100644
74363 --- a/mm/rmap.c
74364 +++ b/mm/rmap.c
74365 @@ -168,6 +168,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74366 struct anon_vma *anon_vma = vma->anon_vma;
74367 struct anon_vma_chain *avc;
74368
74369 +#ifdef CONFIG_PAX_SEGMEXEC
74370 + struct anon_vma_chain *avc_m = NULL;
74371 +#endif
74372 +
74373 might_sleep();
74374 if (unlikely(!anon_vma)) {
74375 struct mm_struct *mm = vma->vm_mm;
74376 @@ -177,6 +181,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74377 if (!avc)
74378 goto out_enomem;
74379
74380 +#ifdef CONFIG_PAX_SEGMEXEC
74381 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74382 + if (!avc_m)
74383 + goto out_enomem_free_avc;
74384 +#endif
74385 +
74386 anon_vma = find_mergeable_anon_vma(vma);
74387 allocated = NULL;
74388 if (!anon_vma) {
74389 @@ -190,6 +200,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74390 /* page_table_lock to protect against threads */
74391 spin_lock(&mm->page_table_lock);
74392 if (likely(!vma->anon_vma)) {
74393 +
74394 +#ifdef CONFIG_PAX_SEGMEXEC
74395 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74396 +
74397 + if (vma_m) {
74398 + BUG_ON(vma_m->anon_vma);
74399 + vma_m->anon_vma = anon_vma;
74400 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74401 + avc_m = NULL;
74402 + }
74403 +#endif
74404 +
74405 vma->anon_vma = anon_vma;
74406 anon_vma_chain_link(vma, avc, anon_vma);
74407 allocated = NULL;
74408 @@ -200,12 +222,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74409
74410 if (unlikely(allocated))
74411 put_anon_vma(allocated);
74412 +
74413 +#ifdef CONFIG_PAX_SEGMEXEC
74414 + if (unlikely(avc_m))
74415 + anon_vma_chain_free(avc_m);
74416 +#endif
74417 +
74418 if (unlikely(avc))
74419 anon_vma_chain_free(avc);
74420 }
74421 return 0;
74422
74423 out_enomem_free_avc:
74424 +
74425 +#ifdef CONFIG_PAX_SEGMEXEC
74426 + if (avc_m)
74427 + anon_vma_chain_free(avc_m);
74428 +#endif
74429 +
74430 anon_vma_chain_free(avc);
74431 out_enomem:
74432 return -ENOMEM;
74433 @@ -241,7 +275,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74434 * Attach the anon_vmas from src to dst.
74435 * Returns 0 on success, -ENOMEM on failure.
74436 */
74437 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74438 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74439 {
74440 struct anon_vma_chain *avc, *pavc;
74441 struct anon_vma *root = NULL;
74442 @@ -319,7 +353,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74443 * the corresponding VMA in the parent process is attached to.
74444 * Returns 0 on success, non-zero on failure.
74445 */
74446 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74447 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74448 {
74449 struct anon_vma_chain *avc;
74450 struct anon_vma *anon_vma;
74451 diff --git a/mm/shmem.c b/mm/shmem.c
74452 index d2eeca1..3f160be 100644
74453 --- a/mm/shmem.c
74454 +++ b/mm/shmem.c
74455 @@ -31,7 +31,7 @@
74456 #include <linux/export.h>
74457 #include <linux/swap.h>
74458
74459 -static struct vfsmount *shm_mnt;
74460 +struct vfsmount *shm_mnt;
74461
74462 #ifdef CONFIG_SHMEM
74463 /*
74464 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74465 #define BOGO_DIRENT_SIZE 20
74466
74467 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74468 -#define SHORT_SYMLINK_LEN 128
74469 +#define SHORT_SYMLINK_LEN 64
74470
74471 struct shmem_xattr {
74472 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74473 @@ -2594,8 +2594,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74474 int err = -ENOMEM;
74475
74476 /* Round up to L1_CACHE_BYTES to resist false sharing */
74477 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74478 - L1_CACHE_BYTES), GFP_KERNEL);
74479 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74480 if (!sbinfo)
74481 return -ENOMEM;
74482
74483 diff --git a/mm/slab.c b/mm/slab.c
74484 index d066037..5bb78d9 100644
74485 --- a/mm/slab.c
74486 +++ b/mm/slab.c
74487 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74488
74489 /* Legal flag mask for kmem_cache_create(). */
74490 #if DEBUG
74491 -# define CREATE_MASK (SLAB_RED_ZONE | \
74492 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74493 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74494 SLAB_CACHE_DMA | \
74495 SLAB_STORE_USER | \
74496 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74497 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74498 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74499 #else
74500 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74501 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74502 SLAB_CACHE_DMA | \
74503 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74504 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74505 @@ -322,7 +322,7 @@ struct kmem_list3 {
74506 * Need this for bootstrapping a per node allocator.
74507 */
74508 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74509 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74510 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74511 #define CACHE_CACHE 0
74512 #define SIZE_AC MAX_NUMNODES
74513 #define SIZE_L3 (2 * MAX_NUMNODES)
74514 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74515 if ((x)->max_freeable < i) \
74516 (x)->max_freeable = i; \
74517 } while (0)
74518 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74519 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74520 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74521 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74522 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74523 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74524 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74525 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74526 #else
74527 #define STATS_INC_ACTIVE(x) do { } while (0)
74528 #define STATS_DEC_ACTIVE(x) do { } while (0)
74529 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74530 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74531 */
74532 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74533 - const struct slab *slab, void *obj)
74534 + const struct slab *slab, const void *obj)
74535 {
74536 u32 offset = (obj - slab->s_mem);
74537 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74538 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74539 struct cache_names {
74540 char *name;
74541 char *name_dma;
74542 + char *name_usercopy;
74543 };
74544
74545 static struct cache_names __initdata cache_names[] = {
74546 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74547 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74548 #include <linux/kmalloc_sizes.h>
74549 - {NULL,}
74550 + {NULL}
74551 #undef CACHE
74552 };
74553
74554 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74555 if (unlikely(gfpflags & GFP_DMA))
74556 return csizep->cs_dmacachep;
74557 #endif
74558 +
74559 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74560 + if (unlikely(gfpflags & GFP_USERCOPY))
74561 + return csizep->cs_usercopycachep;
74562 +#endif
74563 +
74564 return csizep->cs_cachep;
74565 }
74566
74567 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74568 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74569 sizes[INDEX_AC].cs_size,
74570 ARCH_KMALLOC_MINALIGN,
74571 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74572 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74573 NULL);
74574
74575 if (INDEX_AC != INDEX_L3) {
74576 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74577 __kmem_cache_create(names[INDEX_L3].name,
74578 sizes[INDEX_L3].cs_size,
74579 ARCH_KMALLOC_MINALIGN,
74580 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74581 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74582 NULL);
74583 }
74584
74585 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74586 sizes->cs_cachep = __kmem_cache_create(names->name,
74587 sizes->cs_size,
74588 ARCH_KMALLOC_MINALIGN,
74589 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74590 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74591 NULL);
74592 }
74593 #ifdef CONFIG_ZONE_DMA
74594 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74595 SLAB_PANIC,
74596 NULL);
74597 #endif
74598 +
74599 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74600 + sizes->cs_usercopycachep = kmem_cache_create(
74601 + names->name_usercopy,
74602 + sizes->cs_size,
74603 + ARCH_KMALLOC_MINALIGN,
74604 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74605 + NULL);
74606 +#endif
74607 +
74608 sizes++;
74609 names++;
74610 }
74611 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74612 }
74613 /* cpu stats */
74614 {
74615 - unsigned long allochit = atomic_read(&cachep->allochit);
74616 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74617 - unsigned long freehit = atomic_read(&cachep->freehit);
74618 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74619 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74620 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74621 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74622 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74623
74624 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74625 allochit, allocmiss, freehit, freemiss);
74626 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74627 {
74628 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74629 #ifdef CONFIG_DEBUG_SLAB_LEAK
74630 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74631 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74632 #endif
74633 return 0;
74634 }
74635 module_init(slab_proc_init);
74636 #endif
74637
74638 +bool is_usercopy_object(const void *ptr)
74639 +{
74640 + struct page *page;
74641 + struct kmem_cache *cachep;
74642 +
74643 + if (ZERO_OR_NULL_PTR(ptr))
74644 + return false;
74645 +
74646 + if (!slab_is_available())
74647 + return false;
74648 +
74649 + if (!virt_addr_valid(ptr))
74650 + return false;
74651 +
74652 + page = virt_to_head_page(ptr);
74653 +
74654 + if (!PageSlab(page))
74655 + return false;
74656 +
74657 + cachep = page_get_cache(page);
74658 + return cachep->flags & SLAB_USERCOPY;
74659 +}
74660 +
74661 +#ifdef CONFIG_PAX_USERCOPY
74662 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74663 +{
74664 + struct page *page;
74665 + struct kmem_cache *cachep;
74666 + struct slab *slabp;
74667 + unsigned int objnr;
74668 + unsigned long offset;
74669 +
74670 + if (ZERO_OR_NULL_PTR(ptr))
74671 + return "<null>";
74672 +
74673 + if (!virt_addr_valid(ptr))
74674 + return NULL;
74675 +
74676 + page = virt_to_head_page(ptr);
74677 +
74678 + if (!PageSlab(page))
74679 + return NULL;
74680 +
74681 + cachep = page_get_cache(page);
74682 + if (!(cachep->flags & SLAB_USERCOPY))
74683 + return cachep->name;
74684 +
74685 + slabp = page->slab_page;
74686 + objnr = obj_to_index(cachep, slabp, ptr);
74687 + BUG_ON(objnr >= cachep->num);
74688 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74689 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74690 + return NULL;
74691 +
74692 + return cachep->name;
74693 +}
74694 +#endif
74695 +
74696 /**
74697 * ksize - get the actual amount of memory allocated for a given object
74698 * @objp: Pointer to the object
74699 diff --git a/mm/slob.c b/mm/slob.c
74700 index 45d4ca7..88943c1 100644
74701 --- a/mm/slob.c
74702 +++ b/mm/slob.c
74703 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74704 /*
74705 * Return the size of a slob block.
74706 */
74707 -static slobidx_t slob_units(slob_t *s)
74708 +static slobidx_t slob_units(const slob_t *s)
74709 {
74710 if (s->units > 0)
74711 return s->units;
74712 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74713 /*
74714 * Return the next free slob block pointer after this one.
74715 */
74716 -static slob_t *slob_next(slob_t *s)
74717 +static slob_t *slob_next(const slob_t *s)
74718 {
74719 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74720 slobidx_t next;
74721 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74722 /*
74723 * Returns true if s is the last free block in its page.
74724 */
74725 -static int slob_last(slob_t *s)
74726 +static int slob_last(const slob_t *s)
74727 {
74728 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74729 }
74730
74731 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74732 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74733 {
74734 - void *page;
74735 + struct page *page;
74736
74737 #ifdef CONFIG_NUMA
74738 if (node != -1)
74739 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74740 if (!page)
74741 return NULL;
74742
74743 - return page_address(page);
74744 + __SetPageSlab(page);
74745 + return page;
74746 }
74747
74748 -static void slob_free_pages(void *b, int order)
74749 +static void slob_free_pages(struct page *sp, int order)
74750 {
74751 if (current->reclaim_state)
74752 current->reclaim_state->reclaimed_slab += 1 << order;
74753 - free_pages((unsigned long)b, order);
74754 + __ClearPageSlab(sp);
74755 + reset_page_mapcount(sp);
74756 + sp->private = 0;
74757 + __free_pages(sp, order);
74758 }
74759
74760 /*
74761 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74762
74763 /* Not enough space: must allocate a new page */
74764 if (!b) {
74765 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74766 - if (!b)
74767 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74768 + if (!sp)
74769 return NULL;
74770 - sp = virt_to_page(b);
74771 - __SetPageSlab(sp);
74772 + b = page_address(sp);
74773
74774 spin_lock_irqsave(&slob_lock, flags);
74775 sp->units = SLOB_UNITS(PAGE_SIZE);
74776 sp->freelist = b;
74777 + sp->private = 0;
74778 INIT_LIST_HEAD(&sp->list);
74779 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74780 set_slob_page_free(sp, slob_list);
74781 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74782 if (slob_page_free(sp))
74783 clear_slob_page_free(sp);
74784 spin_unlock_irqrestore(&slob_lock, flags);
74785 - __ClearPageSlab(sp);
74786 - reset_page_mapcount(sp);
74787 - slob_free_pages(b, 0);
74788 + slob_free_pages(sp, 0);
74789 return;
74790 }
74791
74792 @@ -425,11 +427,10 @@ out:
74793 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74794 */
74795
74796 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74797 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74798 {
74799 - unsigned int *m;
74800 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74801 - void *ret;
74802 + slob_t *m;
74803 + void *ret = NULL;
74804
74805 gfp &= gfp_allowed_mask;
74806
74807 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74808
74809 if (!m)
74810 return NULL;
74811 - *m = size;
74812 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74813 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74814 + m[0].units = size;
74815 + m[1].units = align;
74816 ret = (void *)m + align;
74817
74818 trace_kmalloc_node(_RET_IP_, ret,
74819 size, size + align, gfp, node);
74820 } else {
74821 unsigned int order = get_order(size);
74822 + struct page *page;
74823
74824 if (likely(order))
74825 gfp |= __GFP_COMP;
74826 - ret = slob_new_pages(gfp, order, node);
74827 - if (ret) {
74828 - struct page *page;
74829 - page = virt_to_page(ret);
74830 + page = slob_new_pages(gfp, order, node);
74831 + if (page) {
74832 + ret = page_address(page);
74833 page->private = size;
74834 }
74835
74836 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74837 size, PAGE_SIZE << order, gfp, node);
74838 }
74839
74840 - kmemleak_alloc(ret, size, 1, gfp);
74841 + return ret;
74842 +}
74843 +
74844 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74845 +{
74846 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74847 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74848 +
74849 + if (!ZERO_OR_NULL_PTR(ret))
74850 + kmemleak_alloc(ret, size, 1, gfp);
74851 return ret;
74852 }
74853 EXPORT_SYMBOL(__kmalloc_node);
74854 @@ -480,15 +493,91 @@ void kfree(const void *block)
74855 kmemleak_free(block);
74856
74857 sp = virt_to_page(block);
74858 - if (PageSlab(sp)) {
74859 + VM_BUG_ON(!PageSlab(sp));
74860 + if (!sp->private) {
74861 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74862 - unsigned int *m = (unsigned int *)(block - align);
74863 - slob_free(m, *m + align);
74864 - } else
74865 + slob_t *m = (slob_t *)(block - align);
74866 + slob_free(m, m[0].units + align);
74867 + } else {
74868 + __ClearPageSlab(sp);
74869 + reset_page_mapcount(sp);
74870 + sp->private = 0;
74871 put_page(sp);
74872 + }
74873 }
74874 EXPORT_SYMBOL(kfree);
74875
74876 +bool is_usercopy_object(const void *ptr)
74877 +{
74878 + if (!slab_is_available())
74879 + return false;
74880 +
74881 + // PAX: TODO
74882 +
74883 + return false;
74884 +}
74885 +
74886 +#ifdef CONFIG_PAX_USERCOPY
74887 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74888 +{
74889 + struct page *page;
74890 + const slob_t *free;
74891 + const void *base;
74892 + unsigned long flags;
74893 +
74894 + if (ZERO_OR_NULL_PTR(ptr))
74895 + return "<null>";
74896 +
74897 + if (!virt_addr_valid(ptr))
74898 + return NULL;
74899 +
74900 + page = virt_to_head_page(ptr);
74901 + if (!PageSlab(page))
74902 + return NULL;
74903 +
74904 + if (page->private) {
74905 + base = page;
74906 + if (base <= ptr && n <= page->private - (ptr - base))
74907 + return NULL;
74908 + return "<slob>";
74909 + }
74910 +
74911 + /* some tricky double walking to find the chunk */
74912 + spin_lock_irqsave(&slob_lock, flags);
74913 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74914 + free = page->freelist;
74915 +
74916 + while (!slob_last(free) && (void *)free <= ptr) {
74917 + base = free + slob_units(free);
74918 + free = slob_next(free);
74919 + }
74920 +
74921 + while (base < (void *)free) {
74922 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74923 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74924 + int offset;
74925 +
74926 + if (ptr < base + align)
74927 + break;
74928 +
74929 + offset = ptr - base - align;
74930 + if (offset >= m) {
74931 + base += size;
74932 + continue;
74933 + }
74934 +
74935 + if (n > m - offset)
74936 + break;
74937 +
74938 + spin_unlock_irqrestore(&slob_lock, flags);
74939 + return NULL;
74940 + }
74941 +
74942 + spin_unlock_irqrestore(&slob_lock, flags);
74943 + return "<slob>";
74944 +}
74945 +#endif
74946 +
74947 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74948 size_t ksize(const void *block)
74949 {
74950 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
74951 return 0;
74952
74953 sp = virt_to_page(block);
74954 - if (PageSlab(sp)) {
74955 + VM_BUG_ON(!PageSlab(sp));
74956 + if (!sp->private) {
74957 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74958 - unsigned int *m = (unsigned int *)(block - align);
74959 - return SLOB_UNITS(*m) * SLOB_UNIT;
74960 + slob_t *m = (slob_t *)(block - align);
74961 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74962 } else
74963 return sp->private;
74964 }
74965 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
74966 {
74967 struct kmem_cache *c;
74968
74969 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74970 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74971 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74972 +#else
74973 c = slob_alloc(sizeof(struct kmem_cache),
74974 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74975 +#endif
74976
74977 if (c) {
74978 c->name = name;
74979 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
74980
74981 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
74982 {
74983 - void *b;
74984 + void *b = NULL;
74985
74986 flags &= gfp_allowed_mask;
74987
74988 lockdep_trace_alloc(flags);
74989
74990 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74991 + b = __kmalloc_node_align(c->size, flags, node, c->align);
74992 +#else
74993 if (c->size < PAGE_SIZE) {
74994 b = slob_alloc(c->size, flags, c->align, node);
74995 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
74996 SLOB_UNITS(c->size) * SLOB_UNIT,
74997 flags, node);
74998 } else {
74999 - b = slob_new_pages(flags, get_order(c->size), node);
75000 + struct page *sp;
75001 +
75002 + sp = slob_new_pages(flags, get_order(c->size), node);
75003 + if (sp) {
75004 + b = page_address(sp);
75005 + sp->private = c->size;
75006 + }
75007 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75008 PAGE_SIZE << get_order(c->size),
75009 flags, node);
75010 }
75011 +#endif
75012
75013 if (c->ctor)
75014 c->ctor(b);
75015 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75016
75017 static void __kmem_cache_free(void *b, int size)
75018 {
75019 - if (size < PAGE_SIZE)
75020 + struct page *sp;
75021 +
75022 + sp = virt_to_page(b);
75023 + BUG_ON(!PageSlab(sp));
75024 + if (!sp->private)
75025 slob_free(b, size);
75026 else
75027 - slob_free_pages(b, get_order(size));
75028 + slob_free_pages(sp, get_order(size));
75029 }
75030
75031 static void kmem_rcu_free(struct rcu_head *head)
75032 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75033
75034 void kmem_cache_free(struct kmem_cache *c, void *b)
75035 {
75036 + int size = c->size;
75037 +
75038 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75039 + if (size + c->align < PAGE_SIZE) {
75040 + size += c->align;
75041 + b -= c->align;
75042 + }
75043 +#endif
75044 +
75045 kmemleak_free_recursive(b, c->flags);
75046 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75047 struct slob_rcu *slob_rcu;
75048 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75049 - slob_rcu->size = c->size;
75050 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75051 + slob_rcu->size = size;
75052 call_rcu(&slob_rcu->head, kmem_rcu_free);
75053 } else {
75054 - __kmem_cache_free(b, c->size);
75055 + __kmem_cache_free(b, size);
75056 }
75057
75058 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75059 + trace_kfree(_RET_IP_, b);
75060 +#else
75061 trace_kmem_cache_free(_RET_IP_, b);
75062 +#endif
75063 +
75064 }
75065 EXPORT_SYMBOL(kmem_cache_free);
75066
75067 diff --git a/mm/slub.c b/mm/slub.c
75068 index 2fdd96f..1e2f893 100644
75069 --- a/mm/slub.c
75070 +++ b/mm/slub.c
75071 @@ -201,7 +201,7 @@ struct track {
75072
75073 enum track_item { TRACK_ALLOC, TRACK_FREE };
75074
75075 -#ifdef CONFIG_SYSFS
75076 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75077 static int sysfs_slab_add(struct kmem_cache *);
75078 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75079 static void sysfs_slab_remove(struct kmem_cache *);
75080 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75081 if (!t->addr)
75082 return;
75083
75084 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75085 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75086 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75087 #ifdef CONFIG_STACKTRACE
75088 {
75089 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75090
75091 page = virt_to_head_page(x);
75092
75093 + BUG_ON(!PageSlab(page));
75094 +
75095 slab_free(s, page, x, _RET_IP_);
75096
75097 trace_kmem_cache_free(_RET_IP_, x);
75098 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75099 * Merge control. If this is set then no merging of slab caches will occur.
75100 * (Could be removed. This was introduced to pacify the merge skeptics.)
75101 */
75102 -static int slub_nomerge;
75103 +static int slub_nomerge = 1;
75104
75105 /*
75106 * Calculate the order of allocation given an slab object size.
75107 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75108 else
75109 s->cpu_partial = 30;
75110
75111 - s->refcount = 1;
75112 + atomic_set(&s->refcount, 1);
75113 #ifdef CONFIG_NUMA
75114 s->remote_node_defrag_ratio = 1000;
75115 #endif
75116 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75117 void kmem_cache_destroy(struct kmem_cache *s)
75118 {
75119 mutex_lock(&slab_mutex);
75120 - s->refcount--;
75121 - if (!s->refcount) {
75122 + if (atomic_dec_and_test(&s->refcount)) {
75123 list_del(&s->list);
75124 mutex_unlock(&slab_mutex);
75125 if (kmem_cache_close(s)) {
75126 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75127 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75128 #endif
75129
75130 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75131 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75132 +#endif
75133 +
75134 static int __init setup_slub_min_order(char *str)
75135 {
75136 get_option(&str, &slub_min_order);
75137 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75138 return kmalloc_dma_caches[index];
75139
75140 #endif
75141 +
75142 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75143 + if (flags & SLAB_USERCOPY)
75144 + return kmalloc_usercopy_caches[index];
75145 +
75146 +#endif
75147 +
75148 return kmalloc_caches[index];
75149 }
75150
75151 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75152 EXPORT_SYMBOL(__kmalloc_node);
75153 #endif
75154
75155 +bool is_usercopy_object(const void *ptr)
75156 +{
75157 + struct page *page;
75158 + struct kmem_cache *s;
75159 +
75160 + if (ZERO_OR_NULL_PTR(ptr))
75161 + return false;
75162 +
75163 + if (!slab_is_available())
75164 + return false;
75165 +
75166 + if (!virt_addr_valid(ptr))
75167 + return false;
75168 +
75169 + page = virt_to_head_page(ptr);
75170 +
75171 + if (!PageSlab(page))
75172 + return false;
75173 +
75174 + s = page->slab;
75175 + return s->flags & SLAB_USERCOPY;
75176 +}
75177 +
75178 +#ifdef CONFIG_PAX_USERCOPY
75179 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75180 +{
75181 + struct page *page;
75182 + struct kmem_cache *s;
75183 + unsigned long offset;
75184 +
75185 + if (ZERO_OR_NULL_PTR(ptr))
75186 + return "<null>";
75187 +
75188 + if (!virt_addr_valid(ptr))
75189 + return NULL;
75190 +
75191 + page = virt_to_head_page(ptr);
75192 +
75193 + if (!PageSlab(page))
75194 + return NULL;
75195 +
75196 + s = page->slab;
75197 + if (!(s->flags & SLAB_USERCOPY))
75198 + return s->name;
75199 +
75200 + offset = (ptr - page_address(page)) % s->size;
75201 + if (offset <= s->object_size && n <= s->object_size - offset)
75202 + return NULL;
75203 +
75204 + return s->name;
75205 +}
75206 +#endif
75207 +
75208 size_t ksize(const void *object)
75209 {
75210 struct page *page;
75211 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75212 int node;
75213
75214 list_add(&s->list, &slab_caches);
75215 - s->refcount = -1;
75216 + atomic_set(&s->refcount, -1);
75217
75218 for_each_node_state(node, N_NORMAL_MEMORY) {
75219 struct kmem_cache_node *n = get_node(s, node);
75220 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75221
75222 /* Caches that are not of the two-to-the-power-of size */
75223 if (KMALLOC_MIN_SIZE <= 32) {
75224 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75225 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75226 caches++;
75227 }
75228
75229 if (KMALLOC_MIN_SIZE <= 64) {
75230 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75231 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75232 caches++;
75233 }
75234
75235 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75236 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75237 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75238 caches++;
75239 }
75240
75241 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75242 }
75243 }
75244 #endif
75245 +
75246 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75247 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75248 + struct kmem_cache *s = kmalloc_caches[i];
75249 +
75250 + if (s && s->size) {
75251 + char *name = kasprintf(GFP_NOWAIT,
75252 + "usercopy-kmalloc-%d", s->object_size);
75253 +
75254 + BUG_ON(!name);
75255 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75256 + s->object_size, SLAB_USERCOPY);
75257 + }
75258 + }
75259 +#endif
75260 +
75261 printk(KERN_INFO
75262 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75263 " CPUs=%d, Nodes=%d\n",
75264 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75265 /*
75266 * We may have set a slab to be unmergeable during bootstrap.
75267 */
75268 - if (s->refcount < 0)
75269 + if (atomic_read(&s->refcount) < 0)
75270 return 1;
75271
75272 return 0;
75273 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75274
75275 s = find_mergeable(size, align, flags, name, ctor);
75276 if (s) {
75277 - s->refcount++;
75278 + atomic_inc(&s->refcount);
75279 /*
75280 * Adjust the object sizes so that we clear
75281 * the complete object on kzalloc.
75282 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75283 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75284
75285 if (sysfs_slab_alias(s, name)) {
75286 - s->refcount--;
75287 + atomic_dec(&s->refcount);
75288 return NULL;
75289 }
75290 return s;
75291 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75292 }
75293 #endif
75294
75295 -#ifdef CONFIG_SYSFS
75296 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75297 static int count_inuse(struct page *page)
75298 {
75299 return page->inuse;
75300 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75301 validate_slab_cache(kmalloc_caches[9]);
75302 }
75303 #else
75304 -#ifdef CONFIG_SYSFS
75305 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75306 static void resiliency_test(void) {};
75307 #endif
75308 #endif
75309
75310 -#ifdef CONFIG_SYSFS
75311 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75312 enum slab_stat_type {
75313 SL_ALL, /* All slabs */
75314 SL_PARTIAL, /* Only partially allocated slabs */
75315 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75316
75317 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75318 {
75319 - return sprintf(buf, "%d\n", s->refcount - 1);
75320 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75321 }
75322 SLAB_ATTR_RO(aliases);
75323
75324 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75325 return name;
75326 }
75327
75328 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75329 static int sysfs_slab_add(struct kmem_cache *s)
75330 {
75331 int err;
75332 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75333 kobject_del(&s->kobj);
75334 kobject_put(&s->kobj);
75335 }
75336 +#endif
75337
75338 /*
75339 * Need to buffer aliases during bootup until sysfs becomes
75340 @@ -5354,6 +5437,7 @@ struct saved_alias {
75341
75342 static struct saved_alias *alias_list;
75343
75344 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75345 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75346 {
75347 struct saved_alias *al;
75348 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75349 alias_list = al;
75350 return 0;
75351 }
75352 +#endif
75353
75354 static int __init slab_sysfs_init(void)
75355 {
75356 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75357 index 1b7e22a..3fcd4f3 100644
75358 --- a/mm/sparse-vmemmap.c
75359 +++ b/mm/sparse-vmemmap.c
75360 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75361 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75362 if (!p)
75363 return NULL;
75364 - pud_populate(&init_mm, pud, p);
75365 + pud_populate_kernel(&init_mm, pud, p);
75366 }
75367 return pud;
75368 }
75369 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75370 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75371 if (!p)
75372 return NULL;
75373 - pgd_populate(&init_mm, pgd, p);
75374 + pgd_populate_kernel(&init_mm, pgd, p);
75375 }
75376 return pgd;
75377 }
75378 diff --git a/mm/swap.c b/mm/swap.c
75379 index 7782588..228c784 100644
75380 --- a/mm/swap.c
75381 +++ b/mm/swap.c
75382 @@ -30,6 +30,7 @@
75383 #include <linux/backing-dev.h>
75384 #include <linux/memcontrol.h>
75385 #include <linux/gfp.h>
75386 +#include <linux/hugetlb.h>
75387
75388 #include "internal.h"
75389
75390 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75391
75392 __page_cache_release(page);
75393 dtor = get_compound_page_dtor(page);
75394 + if (!PageHuge(page))
75395 + BUG_ON(dtor != free_compound_page);
75396 (*dtor)(page);
75397 }
75398
75399 diff --git a/mm/swapfile.c b/mm/swapfile.c
75400 index 14e254c..a6af32c 100644
75401 --- a/mm/swapfile.c
75402 +++ b/mm/swapfile.c
75403 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75404
75405 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75406 /* Activity counter to indicate that a swapon or swapoff has occurred */
75407 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75408 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75409
75410 static inline unsigned char swap_count(unsigned char ent)
75411 {
75412 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75413 }
75414 filp_close(swap_file, NULL);
75415 err = 0;
75416 - atomic_inc(&proc_poll_event);
75417 + atomic_inc_unchecked(&proc_poll_event);
75418 wake_up_interruptible(&proc_poll_wait);
75419
75420 out_dput:
75421 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75422
75423 poll_wait(file, &proc_poll_wait, wait);
75424
75425 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75426 - seq->poll_event = atomic_read(&proc_poll_event);
75427 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75428 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75429 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75430 }
75431
75432 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75433 return ret;
75434
75435 seq = file->private_data;
75436 - seq->poll_event = atomic_read(&proc_poll_event);
75437 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75438 return 0;
75439 }
75440
75441 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75442 (frontswap_map) ? "FS" : "");
75443
75444 mutex_unlock(&swapon_mutex);
75445 - atomic_inc(&proc_poll_event);
75446 + atomic_inc_unchecked(&proc_poll_event);
75447 wake_up_interruptible(&proc_poll_wait);
75448
75449 if (S_ISREG(inode->i_mode))
75450 diff --git a/mm/util.c b/mm/util.c
75451 index 8c7265a..c96d884 100644
75452 --- a/mm/util.c
75453 +++ b/mm/util.c
75454 @@ -285,6 +285,12 @@ done:
75455 void arch_pick_mmap_layout(struct mm_struct *mm)
75456 {
75457 mm->mmap_base = TASK_UNMAPPED_BASE;
75458 +
75459 +#ifdef CONFIG_PAX_RANDMMAP
75460 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75461 + mm->mmap_base += mm->delta_mmap;
75462 +#endif
75463 +
75464 mm->get_unmapped_area = arch_get_unmapped_area;
75465 mm->unmap_area = arch_unmap_area;
75466 }
75467 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75468 index 2bb90b1..ed47e53 100644
75469 --- a/mm/vmalloc.c
75470 +++ b/mm/vmalloc.c
75471 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75472
75473 pte = pte_offset_kernel(pmd, addr);
75474 do {
75475 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75476 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75477 +
75478 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75479 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75480 + BUG_ON(!pte_exec(*pte));
75481 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75482 + continue;
75483 + }
75484 +#endif
75485 +
75486 + {
75487 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75488 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75489 + }
75490 } while (pte++, addr += PAGE_SIZE, addr != end);
75491 }
75492
75493 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75494 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75495 {
75496 pte_t *pte;
75497 + int ret = -ENOMEM;
75498
75499 /*
75500 * nr is a running index into the array which helps higher level
75501 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75502 pte = pte_alloc_kernel(pmd, addr);
75503 if (!pte)
75504 return -ENOMEM;
75505 +
75506 + pax_open_kernel();
75507 do {
75508 struct page *page = pages[*nr];
75509
75510 - if (WARN_ON(!pte_none(*pte)))
75511 - return -EBUSY;
75512 - if (WARN_ON(!page))
75513 - return -ENOMEM;
75514 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75515 + if (pgprot_val(prot) & _PAGE_NX)
75516 +#endif
75517 +
75518 + if (WARN_ON(!pte_none(*pte))) {
75519 + ret = -EBUSY;
75520 + goto out;
75521 + }
75522 + if (WARN_ON(!page)) {
75523 + ret = -ENOMEM;
75524 + goto out;
75525 + }
75526 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75527 (*nr)++;
75528 } while (pte++, addr += PAGE_SIZE, addr != end);
75529 - return 0;
75530 + ret = 0;
75531 +out:
75532 + pax_close_kernel();
75533 + return ret;
75534 }
75535
75536 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75537 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75538 pmd_t *pmd;
75539 unsigned long next;
75540
75541 - pmd = pmd_alloc(&init_mm, pud, addr);
75542 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75543 if (!pmd)
75544 return -ENOMEM;
75545 do {
75546 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75547 pud_t *pud;
75548 unsigned long next;
75549
75550 - pud = pud_alloc(&init_mm, pgd, addr);
75551 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75552 if (!pud)
75553 return -ENOMEM;
75554 do {
75555 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75556 * and fall back on vmalloc() if that fails. Others
75557 * just put it in the vmalloc space.
75558 */
75559 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75560 +#ifdef CONFIG_MODULES
75561 +#ifdef MODULES_VADDR
75562 unsigned long addr = (unsigned long)x;
75563 if (addr >= MODULES_VADDR && addr < MODULES_END)
75564 return 1;
75565 #endif
75566 +
75567 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75568 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75569 + return 1;
75570 +#endif
75571 +
75572 +#endif
75573 +
75574 return is_vmalloc_addr(x);
75575 }
75576
75577 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75578
75579 if (!pgd_none(*pgd)) {
75580 pud_t *pud = pud_offset(pgd, addr);
75581 +#ifdef CONFIG_X86
75582 + if (!pud_large(*pud))
75583 +#endif
75584 if (!pud_none(*pud)) {
75585 pmd_t *pmd = pmd_offset(pud, addr);
75586 +#ifdef CONFIG_X86
75587 + if (!pmd_large(*pmd))
75588 +#endif
75589 if (!pmd_none(*pmd)) {
75590 pte_t *ptep, pte;
75591
75592 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75593 * Allocate a region of KVA of the specified size and alignment, within the
75594 * vstart and vend.
75595 */
75596 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75597 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75598 unsigned long align,
75599 unsigned long vstart, unsigned long vend,
75600 int node, gfp_t gfp_mask)
75601 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75602 struct vm_struct *area;
75603
75604 BUG_ON(in_interrupt());
75605 +
75606 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75607 + if (flags & VM_KERNEXEC) {
75608 + if (start != VMALLOC_START || end != VMALLOC_END)
75609 + return NULL;
75610 + start = (unsigned long)MODULES_EXEC_VADDR;
75611 + end = (unsigned long)MODULES_EXEC_END;
75612 + }
75613 +#endif
75614 +
75615 if (flags & VM_IOREMAP) {
75616 int bit = fls(size);
75617
75618 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75619 if (count > totalram_pages)
75620 return NULL;
75621
75622 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75623 + if (!(pgprot_val(prot) & _PAGE_NX))
75624 + flags |= VM_KERNEXEC;
75625 +#endif
75626 +
75627 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75628 __builtin_return_address(0));
75629 if (!area)
75630 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75631 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75632 goto fail;
75633
75634 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75635 + if (!(pgprot_val(prot) & _PAGE_NX))
75636 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75637 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75638 + else
75639 +#endif
75640 +
75641 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75642 start, end, node, gfp_mask, caller);
75643 if (!area)
75644 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75645 * For tight control over page level allocator and protection flags
75646 * use __vmalloc() instead.
75647 */
75648 -
75649 void *vmalloc_exec(unsigned long size)
75650 {
75651 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75652 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75653 -1, __builtin_return_address(0));
75654 }
75655
75656 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75657 unsigned long uaddr = vma->vm_start;
75658 unsigned long usize = vma->vm_end - vma->vm_start;
75659
75660 + BUG_ON(vma->vm_mirror);
75661 +
75662 if ((PAGE_SIZE-1) & (unsigned long)addr)
75663 return -EINVAL;
75664
75665 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75666 {
75667 struct vm_struct *v = p;
75668
75669 - seq_printf(m, "0x%p-0x%p %7ld",
75670 + seq_printf(m, "0x%pK-0x%pK %7ld",
75671 v->addr, v->addr + v->size, v->size);
75672
75673 if (v->caller)
75674 diff --git a/mm/vmstat.c b/mm/vmstat.c
75675 index df7a674..8b4a4f3 100644
75676 --- a/mm/vmstat.c
75677 +++ b/mm/vmstat.c
75678 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75679 *
75680 * vm_stat contains the global counters
75681 */
75682 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75683 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75684 EXPORT_SYMBOL(vm_stat);
75685
75686 #ifdef CONFIG_SMP
75687 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75688 v = p->vm_stat_diff[i];
75689 p->vm_stat_diff[i] = 0;
75690 local_irq_restore(flags);
75691 - atomic_long_add(v, &zone->vm_stat[i]);
75692 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75693 global_diff[i] += v;
75694 #ifdef CONFIG_NUMA
75695 /* 3 seconds idle till flush */
75696 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75697
75698 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75699 if (global_diff[i])
75700 - atomic_long_add(global_diff[i], &vm_stat[i]);
75701 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75702 }
75703
75704 #endif
75705 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75706 start_cpu_timer(cpu);
75707 #endif
75708 #ifdef CONFIG_PROC_FS
75709 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75710 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75711 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75712 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75713 + {
75714 + mode_t gr_mode = S_IRUGO;
75715 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75716 + gr_mode = S_IRUSR;
75717 +#endif
75718 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75719 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75720 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75721 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75722 +#else
75723 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75724 +#endif
75725 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75726 + }
75727 #endif
75728 return 0;
75729 }
75730 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75731 index 9096bcb..43ed7bb 100644
75732 --- a/net/8021q/vlan.c
75733 +++ b/net/8021q/vlan.c
75734 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75735 err = -EPERM;
75736 if (!capable(CAP_NET_ADMIN))
75737 break;
75738 - if ((args.u.name_type >= 0) &&
75739 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75740 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75741 struct vlan_net *vn;
75742
75743 vn = net_generic(net, vlan_net_id);
75744 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75745 index 6449bae..8c1f454 100644
75746 --- a/net/9p/trans_fd.c
75747 +++ b/net/9p/trans_fd.c
75748 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75749 oldfs = get_fs();
75750 set_fs(get_ds());
75751 /* The cast to a user pointer is valid due to the set_fs() */
75752 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75753 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75754 set_fs(oldfs);
75755
75756 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75757 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75758 index 876fbe8..8bbea9f 100644
75759 --- a/net/atm/atm_misc.c
75760 +++ b/net/atm/atm_misc.c
75761 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75762 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75763 return 1;
75764 atm_return(vcc, truesize);
75765 - atomic_inc(&vcc->stats->rx_drop);
75766 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75767 return 0;
75768 }
75769 EXPORT_SYMBOL(atm_charge);
75770 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75771 }
75772 }
75773 atm_return(vcc, guess);
75774 - atomic_inc(&vcc->stats->rx_drop);
75775 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75776 return NULL;
75777 }
75778 EXPORT_SYMBOL(atm_alloc_charge);
75779 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75780
75781 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75782 {
75783 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75784 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75785 __SONET_ITEMS
75786 #undef __HANDLE_ITEM
75787 }
75788 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75789
75790 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75791 {
75792 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75793 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75794 __SONET_ITEMS
75795 #undef __HANDLE_ITEM
75796 }
75797 diff --git a/net/atm/lec.h b/net/atm/lec.h
75798 index a86aff9..3a0d6f6 100644
75799 --- a/net/atm/lec.h
75800 +++ b/net/atm/lec.h
75801 @@ -48,7 +48,7 @@ struct lane2_ops {
75802 const u8 *tlvs, u32 sizeoftlvs);
75803 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75804 const u8 *tlvs, u32 sizeoftlvs);
75805 -};
75806 +} __no_const;
75807
75808 /*
75809 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75810 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75811 index 0919a88..a23d54e 100644
75812 --- a/net/atm/mpc.h
75813 +++ b/net/atm/mpc.h
75814 @@ -33,7 +33,7 @@ struct mpoa_client {
75815 struct mpc_parameters parameters; /* parameters for this client */
75816
75817 const struct net_device_ops *old_ops;
75818 - struct net_device_ops new_ops;
75819 + net_device_ops_no_const new_ops;
75820 };
75821
75822
75823 diff --git a/net/atm/proc.c b/net/atm/proc.c
75824 index 0d020de..011c7bb 100644
75825 --- a/net/atm/proc.c
75826 +++ b/net/atm/proc.c
75827 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75828 const struct k_atm_aal_stats *stats)
75829 {
75830 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75831 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75832 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75833 - atomic_read(&stats->rx_drop));
75834 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75835 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75836 + atomic_read_unchecked(&stats->rx_drop));
75837 }
75838
75839 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75840 diff --git a/net/atm/resources.c b/net/atm/resources.c
75841 index 23f45ce..c748f1a 100644
75842 --- a/net/atm/resources.c
75843 +++ b/net/atm/resources.c
75844 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75845 static void copy_aal_stats(struct k_atm_aal_stats *from,
75846 struct atm_aal_stats *to)
75847 {
75848 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75849 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75850 __AAL_STAT_ITEMS
75851 #undef __HANDLE_ITEM
75852 }
75853 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75854 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75855 struct atm_aal_stats *to)
75856 {
75857 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75858 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75859 __AAL_STAT_ITEMS
75860 #undef __HANDLE_ITEM
75861 }
75862 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75863 index 469daab..9fc7f8d 100644
75864 --- a/net/batman-adv/bat_iv_ogm.c
75865 +++ b/net/batman-adv/bat_iv_ogm.c
75866 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
75867
75868 /* randomize initial seqno to avoid collision */
75869 get_random_bytes(&random_seqno, sizeof(random_seqno));
75870 - atomic_set(&hard_iface->seqno, random_seqno);
75871 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75872
75873 hard_iface->packet_len = BATADV_OGM_HLEN;
75874 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75875 @@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
75876 "Sending own" :
75877 "Forwarding"));
75878 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
75879 - "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75880 + "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75881 fwd_str, (packet_num > 0 ? "aggregated " : ""),
75882 batadv_ogm_packet->orig,
75883 ntohl(batadv_ogm_packet->seqno),
75884 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
75885
75886 /* change sequence number to network order */
75887 batadv_ogm_packet->seqno =
75888 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75889 - atomic_inc(&hard_iface->seqno);
75890 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75891 + atomic_inc_unchecked(&hard_iface->seqno);
75892
75893 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75894 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
75895 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
75896 return;
75897
75898 /* could be changed by schedule_own_packet() */
75899 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75900 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75901
75902 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
75903 has_directlink_flag = 1;
75904 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75905 index 282bf6e..4b2603d 100644
75906 --- a/net/batman-adv/hard-interface.c
75907 +++ b/net/batman-adv/hard-interface.c
75908 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
75909 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75910 dev_add_pack(&hard_iface->batman_adv_ptype);
75911
75912 - atomic_set(&hard_iface->frag_seqno, 1);
75913 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75914 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
75915 hard_iface->net_dev->name);
75916
75917 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
75918 /* This can't be called via a bat_priv callback because
75919 * we have no bat_priv yet.
75920 */
75921 - atomic_set(&hard_iface->seqno, 1);
75922 + atomic_set_unchecked(&hard_iface->seqno, 1);
75923 hard_iface->packet_buff = NULL;
75924
75925 return hard_iface;
75926 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75927 index 21c5357..768be1a 100644
75928 --- a/net/batman-adv/soft-interface.c
75929 +++ b/net/batman-adv/soft-interface.c
75930 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
75931
75932 /* set broadcast sequence number */
75933 bcast_packet->seqno =
75934 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75935 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75936
75937 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
75938
75939 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
75940 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
75941
75942 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
75943 - atomic_set(&bat_priv->bcast_seqno, 1);
75944 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75945 atomic_set(&bat_priv->ttvn, 0);
75946 atomic_set(&bat_priv->tt_local_changes, 0);
75947 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75948 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75949 index 12635fd..d99d837 100644
75950 --- a/net/batman-adv/types.h
75951 +++ b/net/batman-adv/types.h
75952 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
75953 int16_t if_num;
75954 char if_status;
75955 struct net_device *net_dev;
75956 - atomic_t seqno;
75957 - atomic_t frag_seqno;
75958 + atomic_unchecked_t seqno;
75959 + atomic_unchecked_t frag_seqno;
75960 unsigned char *packet_buff;
75961 int packet_len;
75962 struct kobject *hardif_obj;
75963 @@ -176,7 +176,7 @@ struct batadv_priv {
75964 atomic_t orig_interval; /* uint */
75965 atomic_t hop_penalty; /* uint */
75966 atomic_t log_level; /* uint */
75967 - atomic_t bcast_seqno;
75968 + atomic_unchecked_t bcast_seqno;
75969 atomic_t bcast_queue_left;
75970 atomic_t batman_queue_left;
75971 atomic_t ttvn; /* translation table version number */
75972 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75973 index 0016464..0ef3e53 100644
75974 --- a/net/batman-adv/unicast.c
75975 +++ b/net/batman-adv/unicast.c
75976 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
75977 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
75978 frag2->flags = large_tail;
75979
75980 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
75981 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
75982 frag1->seqno = htons(seqno - 1);
75983 frag2->seqno = htons(seqno);
75984
75985 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
75986 index d5ace1e..231c4bf 100644
75987 --- a/net/bluetooth/hci_sock.c
75988 +++ b/net/bluetooth/hci_sock.c
75989 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
75990 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
75991 }
75992
75993 - len = min_t(unsigned int, len, sizeof(uf));
75994 + len = min((size_t)len, sizeof(uf));
75995 if (copy_from_user(&uf, optval, len)) {
75996 err = -EFAULT;
75997 break;
75998 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
75999 index 38c00f1..e9d566e 100644
76000 --- a/net/bluetooth/l2cap_core.c
76001 +++ b/net/bluetooth/l2cap_core.c
76002 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76003 break;
76004
76005 case L2CAP_CONF_RFC:
76006 - if (olen == sizeof(rfc))
76007 - memcpy(&rfc, (void *)val, olen);
76008 + if (olen != sizeof(rfc))
76009 + break;
76010 +
76011 + memcpy(&rfc, (void *)val, olen);
76012
76013 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76014 rfc.mode != chan->mode)
76015 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76016 index 34bbe1c..451c19b 100644
76017 --- a/net/bluetooth/l2cap_sock.c
76018 +++ b/net/bluetooth/l2cap_sock.c
76019 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76020 struct sock *sk = sock->sk;
76021 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76022 struct l2cap_options opts;
76023 - int len, err = 0;
76024 + int err = 0;
76025 + size_t len = optlen;
76026 u32 opt;
76027
76028 BT_DBG("sk %p", sk);
76029 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76030 opts.max_tx = chan->max_tx;
76031 opts.txwin_size = chan->tx_win;
76032
76033 - len = min_t(unsigned int, sizeof(opts), optlen);
76034 + len = min(sizeof(opts), len);
76035 if (copy_from_user((char *) &opts, optval, len)) {
76036 err = -EFAULT;
76037 break;
76038 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76039 struct bt_security sec;
76040 struct bt_power pwr;
76041 struct l2cap_conn *conn;
76042 - int len, err = 0;
76043 + int err = 0;
76044 + size_t len = optlen;
76045 u32 opt;
76046
76047 BT_DBG("sk %p", sk);
76048 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76049
76050 sec.level = BT_SECURITY_LOW;
76051
76052 - len = min_t(unsigned int, sizeof(sec), optlen);
76053 + len = min(sizeof(sec), len);
76054 if (copy_from_user((char *) &sec, optval, len)) {
76055 err = -EFAULT;
76056 break;
76057 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76058
76059 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76060
76061 - len = min_t(unsigned int, sizeof(pwr), optlen);
76062 + len = min(sizeof(pwr), len);
76063 if (copy_from_user((char *) &pwr, optval, len)) {
76064 err = -EFAULT;
76065 break;
76066 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76067 index 1a17850..65a3129 100644
76068 --- a/net/bluetooth/rfcomm/sock.c
76069 +++ b/net/bluetooth/rfcomm/sock.c
76070 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76071 struct sock *sk = sock->sk;
76072 struct bt_security sec;
76073 int err = 0;
76074 - size_t len;
76075 + size_t len = optlen;
76076 u32 opt;
76077
76078 BT_DBG("sk %p", sk);
76079 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76080
76081 sec.level = BT_SECURITY_LOW;
76082
76083 - len = min_t(unsigned int, sizeof(sec), optlen);
76084 + len = min(sizeof(sec), len);
76085 if (copy_from_user((char *) &sec, optval, len)) {
76086 err = -EFAULT;
76087 break;
76088 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76089 index 56f1823..da44330 100644
76090 --- a/net/bluetooth/rfcomm/tty.c
76091 +++ b/net/bluetooth/rfcomm/tty.c
76092 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76093 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76094
76095 spin_lock_irqsave(&dev->port.lock, flags);
76096 - if (dev->port.count > 0) {
76097 + if (atomic_read(&dev->port.count) > 0) {
76098 spin_unlock_irqrestore(&dev->port.lock, flags);
76099 return;
76100 }
76101 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76102 return -ENODEV;
76103
76104 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76105 - dev->channel, dev->port.count);
76106 + dev->channel, atomic_read(&dev->port.count));
76107
76108 spin_lock_irqsave(&dev->port.lock, flags);
76109 - if (++dev->port.count > 1) {
76110 + if (atomic_inc_return(&dev->port.count) > 1) {
76111 spin_unlock_irqrestore(&dev->port.lock, flags);
76112 return 0;
76113 }
76114 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76115 return;
76116
76117 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76118 - dev->port.count);
76119 + atomic_read(&dev->port.count));
76120
76121 spin_lock_irqsave(&dev->port.lock, flags);
76122 - if (!--dev->port.count) {
76123 + if (!atomic_dec_return(&dev->port.count)) {
76124 spin_unlock_irqrestore(&dev->port.lock, flags);
76125 if (dev->tty_dev->parent)
76126 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76127 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76128 index 5fe2ff3..121d696 100644
76129 --- a/net/bridge/netfilter/ebtables.c
76130 +++ b/net/bridge/netfilter/ebtables.c
76131 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76132 tmp.valid_hooks = t->table->valid_hooks;
76133 }
76134 mutex_unlock(&ebt_mutex);
76135 - if (copy_to_user(user, &tmp, *len) != 0){
76136 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76137 BUGPRINT("c2u Didn't work\n");
76138 ret = -EFAULT;
76139 break;
76140 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76141 goto out;
76142 tmp.valid_hooks = t->valid_hooks;
76143
76144 - if (copy_to_user(user, &tmp, *len) != 0) {
76145 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76146 ret = -EFAULT;
76147 break;
76148 }
76149 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76150 tmp.entries_size = t->table->entries_size;
76151 tmp.valid_hooks = t->table->valid_hooks;
76152
76153 - if (copy_to_user(user, &tmp, *len) != 0) {
76154 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76155 ret = -EFAULT;
76156 break;
76157 }
76158 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76159 index 44f270f..1f5602d 100644
76160 --- a/net/caif/cfctrl.c
76161 +++ b/net/caif/cfctrl.c
76162 @@ -10,6 +10,7 @@
76163 #include <linux/spinlock.h>
76164 #include <linux/slab.h>
76165 #include <linux/pkt_sched.h>
76166 +#include <linux/sched.h>
76167 #include <net/caif/caif_layer.h>
76168 #include <net/caif/cfpkt.h>
76169 #include <net/caif/cfctrl.h>
76170 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76171 memset(&dev_info, 0, sizeof(dev_info));
76172 dev_info.id = 0xff;
76173 cfsrvl_init(&this->serv, 0, &dev_info, false);
76174 - atomic_set(&this->req_seq_no, 1);
76175 - atomic_set(&this->rsp_seq_no, 1);
76176 + atomic_set_unchecked(&this->req_seq_no, 1);
76177 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76178 this->serv.layer.receive = cfctrl_recv;
76179 sprintf(this->serv.layer.name, "ctrl");
76180 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76181 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76182 struct cfctrl_request_info *req)
76183 {
76184 spin_lock_bh(&ctrl->info_list_lock);
76185 - atomic_inc(&ctrl->req_seq_no);
76186 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76187 + atomic_inc_unchecked(&ctrl->req_seq_no);
76188 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76189 list_add_tail(&req->list, &ctrl->list);
76190 spin_unlock_bh(&ctrl->info_list_lock);
76191 }
76192 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76193 if (p != first)
76194 pr_warn("Requests are not received in order\n");
76195
76196 - atomic_set(&ctrl->rsp_seq_no,
76197 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76198 p->sequence_no);
76199 list_del(&p->list);
76200 goto out;
76201 diff --git a/net/can/gw.c b/net/can/gw.c
76202 index b54d5e6..91c3b25 100644
76203 --- a/net/can/gw.c
76204 +++ b/net/can/gw.c
76205 @@ -96,7 +96,7 @@ struct cf_mod {
76206 struct {
76207 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76208 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76209 - } csumfunc;
76210 + } __no_const csumfunc;
76211 };
76212
76213
76214 diff --git a/net/compat.c b/net/compat.c
76215 index 74ed1d7..3695bd9 100644
76216 --- a/net/compat.c
76217 +++ b/net/compat.c
76218 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76219 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76220 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76221 return -EFAULT;
76222 - kmsg->msg_name = compat_ptr(tmp1);
76223 - kmsg->msg_iov = compat_ptr(tmp2);
76224 - kmsg->msg_control = compat_ptr(tmp3);
76225 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76226 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76227 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76228 return 0;
76229 }
76230
76231 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76232
76233 if (kern_msg->msg_namelen) {
76234 if (mode == VERIFY_READ) {
76235 - int err = move_addr_to_kernel(kern_msg->msg_name,
76236 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76237 kern_msg->msg_namelen,
76238 kern_address);
76239 if (err < 0)
76240 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76241 kern_msg->msg_name = NULL;
76242
76243 tot_len = iov_from_user_compat_to_kern(kern_iov,
76244 - (struct compat_iovec __user *)kern_msg->msg_iov,
76245 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76246 kern_msg->msg_iovlen);
76247 if (tot_len >= 0)
76248 kern_msg->msg_iov = kern_iov;
76249 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76250
76251 #define CMSG_COMPAT_FIRSTHDR(msg) \
76252 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76253 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76254 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76255 (struct compat_cmsghdr __user *)NULL)
76256
76257 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76258 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76259 (ucmlen) <= (unsigned long) \
76260 ((mhdr)->msg_controllen - \
76261 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76262 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76263
76264 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76265 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76266 {
76267 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76268 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76269 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76270 msg->msg_controllen)
76271 return NULL;
76272 return (struct compat_cmsghdr __user *)ptr;
76273 @@ -219,7 +219,7 @@ Efault:
76274
76275 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76276 {
76277 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76278 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76279 struct compat_cmsghdr cmhdr;
76280 struct compat_timeval ctv;
76281 struct compat_timespec cts[3];
76282 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76283
76284 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76285 {
76286 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76287 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76288 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76289 int fdnum = scm->fp->count;
76290 struct file **fp = scm->fp->fp;
76291 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76292 return -EFAULT;
76293 old_fs = get_fs();
76294 set_fs(KERNEL_DS);
76295 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76296 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76297 set_fs(old_fs);
76298
76299 return err;
76300 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76301 len = sizeof(ktime);
76302 old_fs = get_fs();
76303 set_fs(KERNEL_DS);
76304 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76305 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76306 set_fs(old_fs);
76307
76308 if (!err) {
76309 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76310 case MCAST_JOIN_GROUP:
76311 case MCAST_LEAVE_GROUP:
76312 {
76313 - struct compat_group_req __user *gr32 = (void *)optval;
76314 + struct compat_group_req __user *gr32 = (void __user *)optval;
76315 struct group_req __user *kgr =
76316 compat_alloc_user_space(sizeof(struct group_req));
76317 u32 interface;
76318 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76319 case MCAST_BLOCK_SOURCE:
76320 case MCAST_UNBLOCK_SOURCE:
76321 {
76322 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76323 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76324 struct group_source_req __user *kgsr = compat_alloc_user_space(
76325 sizeof(struct group_source_req));
76326 u32 interface;
76327 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76328 }
76329 case MCAST_MSFILTER:
76330 {
76331 - struct compat_group_filter __user *gf32 = (void *)optval;
76332 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76333 struct group_filter __user *kgf;
76334 u32 interface, fmode, numsrc;
76335
76336 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76337 char __user *optval, int __user *optlen,
76338 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76339 {
76340 - struct compat_group_filter __user *gf32 = (void *)optval;
76341 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76342 struct group_filter __user *kgf;
76343 int __user *koptlen;
76344 u32 interface, fmode, numsrc;
76345 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76346
76347 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76348 return -EINVAL;
76349 - if (copy_from_user(a, args, nas[call]))
76350 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76351 return -EFAULT;
76352 a0 = a[0];
76353 a1 = a[1];
76354 diff --git a/net/core/datagram.c b/net/core/datagram.c
76355 index 0337e2b..47914a0 100644
76356 --- a/net/core/datagram.c
76357 +++ b/net/core/datagram.c
76358 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76359 }
76360
76361 kfree_skb(skb);
76362 - atomic_inc(&sk->sk_drops);
76363 + atomic_inc_unchecked(&sk->sk_drops);
76364 sk_mem_reclaim_partial(sk);
76365
76366 return err;
76367 diff --git a/net/core/dev.c b/net/core/dev.c
76368 index 2fb9f59..d9a07df 100644
76369 --- a/net/core/dev.c
76370 +++ b/net/core/dev.c
76371 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76372 if (no_module && capable(CAP_NET_ADMIN))
76373 no_module = request_module("netdev-%s", name);
76374 if (no_module && capable(CAP_SYS_MODULE)) {
76375 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76376 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76377 +#else
76378 if (!request_module("%s", name))
76379 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76380 name);
76381 +#endif
76382 }
76383 }
76384 EXPORT_SYMBOL(dev_load);
76385 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76386 {
76387 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76388 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76389 - atomic_long_inc(&dev->rx_dropped);
76390 + atomic_long_inc_unchecked(&dev->rx_dropped);
76391 kfree_skb(skb);
76392 return NET_RX_DROP;
76393 }
76394 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76395 nf_reset(skb);
76396
76397 if (unlikely(!is_skb_forwardable(dev, skb))) {
76398 - atomic_long_inc(&dev->rx_dropped);
76399 + atomic_long_inc_unchecked(&dev->rx_dropped);
76400 kfree_skb(skb);
76401 return NET_RX_DROP;
76402 }
76403 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76404
76405 struct dev_gso_cb {
76406 void (*destructor)(struct sk_buff *skb);
76407 -};
76408 +} __no_const;
76409
76410 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76411
76412 @@ -2928,7 +2932,7 @@ enqueue:
76413
76414 local_irq_restore(flags);
76415
76416 - atomic_long_inc(&skb->dev->rx_dropped);
76417 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76418 kfree_skb(skb);
76419 return NET_RX_DROP;
76420 }
76421 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76422 }
76423 EXPORT_SYMBOL(netif_rx_ni);
76424
76425 -static void net_tx_action(struct softirq_action *h)
76426 +static void net_tx_action(void)
76427 {
76428 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76429
76430 @@ -3331,7 +3335,7 @@ ncls:
76431 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76432 } else {
76433 drop:
76434 - atomic_long_inc(&skb->dev->rx_dropped);
76435 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76436 kfree_skb(skb);
76437 /* Jamal, now you will not able to escape explaining
76438 * me how you were going to use this. :-)
76439 @@ -3898,7 +3902,7 @@ void netif_napi_del(struct napi_struct *napi)
76440 }
76441 EXPORT_SYMBOL(netif_napi_del);
76442
76443 -static void net_rx_action(struct softirq_action *h)
76444 +static void net_rx_action(void)
76445 {
76446 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76447 unsigned long time_limit = jiffies + 2;
76448 @@ -4368,8 +4372,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76449 else
76450 seq_printf(seq, "%04x", ntohs(pt->type));
76451
76452 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76453 + seq_printf(seq, " %-8s %p\n",
76454 + pt->dev ? pt->dev->name : "", NULL);
76455 +#else
76456 seq_printf(seq, " %-8s %pF\n",
76457 pt->dev ? pt->dev->name : "", pt->func);
76458 +#endif
76459 }
76460
76461 return 0;
76462 @@ -5922,7 +5931,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76463 } else {
76464 netdev_stats_to_stats64(storage, &dev->stats);
76465 }
76466 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76467 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76468 return storage;
76469 }
76470 EXPORT_SYMBOL(dev_get_stats);
76471 diff --git a/net/core/flow.c b/net/core/flow.c
76472 index e318c7e..168b1d0 100644
76473 --- a/net/core/flow.c
76474 +++ b/net/core/flow.c
76475 @@ -61,7 +61,7 @@ struct flow_cache {
76476 struct timer_list rnd_timer;
76477 };
76478
76479 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76480 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76481 EXPORT_SYMBOL(flow_cache_genid);
76482 static struct flow_cache flow_cache_global;
76483 static struct kmem_cache *flow_cachep __read_mostly;
76484 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76485
76486 static int flow_entry_valid(struct flow_cache_entry *fle)
76487 {
76488 - if (atomic_read(&flow_cache_genid) != fle->genid)
76489 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76490 return 0;
76491 if (fle->object && !fle->object->ops->check(fle->object))
76492 return 0;
76493 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76494 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76495 fcp->hash_count++;
76496 }
76497 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76498 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76499 flo = fle->object;
76500 if (!flo)
76501 goto ret_object;
76502 @@ -280,7 +280,7 @@ nocache:
76503 }
76504 flo = resolver(net, key, family, dir, flo, ctx);
76505 if (fle) {
76506 - fle->genid = atomic_read(&flow_cache_genid);
76507 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76508 if (!IS_ERR(flo))
76509 fle->object = flo;
76510 else
76511 diff --git a/net/core/iovec.c b/net/core/iovec.c
76512 index 7e7aeb0..2a998cb 100644
76513 --- a/net/core/iovec.c
76514 +++ b/net/core/iovec.c
76515 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76516 if (m->msg_namelen) {
76517 if (mode == VERIFY_READ) {
76518 void __user *namep;
76519 - namep = (void __user __force *) m->msg_name;
76520 + namep = (void __force_user *) m->msg_name;
76521 err = move_addr_to_kernel(namep, m->msg_namelen,
76522 address);
76523 if (err < 0)
76524 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76525 }
76526
76527 size = m->msg_iovlen * sizeof(struct iovec);
76528 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76529 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76530 return -EFAULT;
76531
76532 m->msg_iov = iov;
76533 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76534 index 2c5a0a0..a45f90c 100644
76535 --- a/net/core/rtnetlink.c
76536 +++ b/net/core/rtnetlink.c
76537 @@ -58,7 +58,7 @@ struct rtnl_link {
76538 rtnl_doit_func doit;
76539 rtnl_dumpit_func dumpit;
76540 rtnl_calcit_func calcit;
76541 -};
76542 +} __no_const;
76543
76544 static DEFINE_MUTEX(rtnl_mutex);
76545
76546 diff --git a/net/core/scm.c b/net/core/scm.c
76547 index 040cebe..5b1e312 100644
76548 --- a/net/core/scm.c
76549 +++ b/net/core/scm.c
76550 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76551 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76552 {
76553 struct cmsghdr __user *cm
76554 - = (__force struct cmsghdr __user *)msg->msg_control;
76555 + = (struct cmsghdr __force_user *)msg->msg_control;
76556 struct cmsghdr cmhdr;
76557 int cmlen = CMSG_LEN(len);
76558 int err;
76559 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76560 err = -EFAULT;
76561 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76562 goto out;
76563 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76564 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76565 goto out;
76566 cmlen = CMSG_SPACE(len);
76567 if (msg->msg_controllen < cmlen)
76568 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76569 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76570 {
76571 struct cmsghdr __user *cm
76572 - = (__force struct cmsghdr __user*)msg->msg_control;
76573 + = (struct cmsghdr __force_user *)msg->msg_control;
76574
76575 int fdmax = 0;
76576 int fdnum = scm->fp->count;
76577 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76578 if (fdnum < fdmax)
76579 fdmax = fdnum;
76580
76581 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76582 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76583 i++, cmfptr++)
76584 {
76585 struct socket *sock;
76586 diff --git a/net/core/sock.c b/net/core/sock.c
76587 index a6000fb..d4aee72 100644
76588 --- a/net/core/sock.c
76589 +++ b/net/core/sock.c
76590 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76591 struct sk_buff_head *list = &sk->sk_receive_queue;
76592
76593 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76594 - atomic_inc(&sk->sk_drops);
76595 + atomic_inc_unchecked(&sk->sk_drops);
76596 trace_sock_rcvqueue_full(sk, skb);
76597 return -ENOMEM;
76598 }
76599 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76600 return err;
76601
76602 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76603 - atomic_inc(&sk->sk_drops);
76604 + atomic_inc_unchecked(&sk->sk_drops);
76605 return -ENOBUFS;
76606 }
76607
76608 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76609 skb_dst_force(skb);
76610
76611 spin_lock_irqsave(&list->lock, flags);
76612 - skb->dropcount = atomic_read(&sk->sk_drops);
76613 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76614 __skb_queue_tail(list, skb);
76615 spin_unlock_irqrestore(&list->lock, flags);
76616
76617 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76618 skb->dev = NULL;
76619
76620 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76621 - atomic_inc(&sk->sk_drops);
76622 + atomic_inc_unchecked(&sk->sk_drops);
76623 goto discard_and_relse;
76624 }
76625 if (nested)
76626 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76627 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76628 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76629 bh_unlock_sock(sk);
76630 - atomic_inc(&sk->sk_drops);
76631 + atomic_inc_unchecked(&sk->sk_drops);
76632 goto discard_and_relse;
76633 }
76634
76635 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76636 struct timeval tm;
76637 } v;
76638
76639 - int lv = sizeof(int);
76640 - int len;
76641 + unsigned int lv = sizeof(int);
76642 + unsigned int len;
76643
76644 if (get_user(len, optlen))
76645 return -EFAULT;
76646 - if (len < 0)
76647 + if (len > INT_MAX)
76648 return -EINVAL;
76649
76650 memset(&v, 0, sizeof(v));
76651 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76652
76653 case SO_PEERNAME:
76654 {
76655 - char address[128];
76656 + char address[_K_SS_MAXSIZE];
76657
76658 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76659 return -ENOTCONN;
76660 - if (lv < len)
76661 + if (lv < len || sizeof address < len)
76662 return -EINVAL;
76663 if (copy_to_user(optval, address, len))
76664 return -EFAULT;
76665 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76666
76667 if (len > lv)
76668 len = lv;
76669 - if (copy_to_user(optval, &v, len))
76670 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76671 return -EFAULT;
76672 lenout:
76673 if (put_user(len, optlen))
76674 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76675 */
76676 smp_wmb();
76677 atomic_set(&sk->sk_refcnt, 1);
76678 - atomic_set(&sk->sk_drops, 0);
76679 + atomic_set_unchecked(&sk->sk_drops, 0);
76680 }
76681 EXPORT_SYMBOL(sock_init_data);
76682
76683 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76684 index 9d8755e..26de8bc 100644
76685 --- a/net/core/sock_diag.c
76686 +++ b/net/core/sock_diag.c
76687 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76688
76689 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76690 {
76691 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76692 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76693 cookie[1] != INET_DIAG_NOCOOKIE) &&
76694 ((u32)(unsigned long)sk != cookie[0] ||
76695 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76696 return -ESTALE;
76697 else
76698 +#endif
76699 return 0;
76700 }
76701 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76702
76703 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76704 {
76705 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76706 + cookie[0] = 0;
76707 + cookie[1] = 0;
76708 +#else
76709 cookie[0] = (u32)(unsigned long)sk;
76710 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76711 +#endif
76712 }
76713 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76714
76715 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76716 index a55eecc..dd8428c 100644
76717 --- a/net/decnet/sysctl_net_decnet.c
76718 +++ b/net/decnet/sysctl_net_decnet.c
76719 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76720
76721 if (len > *lenp) len = *lenp;
76722
76723 - if (copy_to_user(buffer, addr, len))
76724 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76725 return -EFAULT;
76726
76727 *lenp = len;
76728 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76729
76730 if (len > *lenp) len = *lenp;
76731
76732 - if (copy_to_user(buffer, devname, len))
76733 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76734 return -EFAULT;
76735
76736 *lenp = len;
76737 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76738 index f444ac7..b7bdda9 100644
76739 --- a/net/ipv4/fib_frontend.c
76740 +++ b/net/ipv4/fib_frontend.c
76741 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76742 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76743 fib_sync_up(dev);
76744 #endif
76745 - atomic_inc(&net->ipv4.dev_addr_genid);
76746 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76747 rt_cache_flush(dev_net(dev));
76748 break;
76749 case NETDEV_DOWN:
76750 fib_del_ifaddr(ifa, NULL);
76751 - atomic_inc(&net->ipv4.dev_addr_genid);
76752 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76753 if (ifa->ifa_dev->ifa_list == NULL) {
76754 /* Last address was deleted from this interface.
76755 * Disable IP.
76756 @@ -1062,7 +1062,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76757 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76758 fib_sync_up(dev);
76759 #endif
76760 - atomic_inc(&net->ipv4.dev_addr_genid);
76761 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76762 rt_cache_flush(dev_net(dev));
76763 break;
76764 case NETDEV_DOWN:
76765 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76766 index 9633661..4e0bc08 100644
76767 --- a/net/ipv4/fib_semantics.c
76768 +++ b/net/ipv4/fib_semantics.c
76769 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76770 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76771 nh->nh_gw,
76772 nh->nh_parent->fib_scope);
76773 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76774 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76775
76776 return nh->nh_saddr;
76777 }
76778 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76779 index 7880af9..70f92a3 100644
76780 --- a/net/ipv4/inet_hashtables.c
76781 +++ b/net/ipv4/inet_hashtables.c
76782 @@ -18,12 +18,15 @@
76783 #include <linux/sched.h>
76784 #include <linux/slab.h>
76785 #include <linux/wait.h>
76786 +#include <linux/security.h>
76787
76788 #include <net/inet_connection_sock.h>
76789 #include <net/inet_hashtables.h>
76790 #include <net/secure_seq.h>
76791 #include <net/ip.h>
76792
76793 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76794 +
76795 /*
76796 * Allocate and initialize a new local port bind bucket.
76797 * The bindhash mutex for snum's hash chain must be held here.
76798 @@ -530,6 +533,8 @@ ok:
76799 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76800 spin_unlock(&head->lock);
76801
76802 + gr_update_task_in_ip_table(current, inet_sk(sk));
76803 +
76804 if (tw) {
76805 inet_twsk_deschedule(tw, death_row);
76806 while (twrefcnt) {
76807 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76808 index c7527f6..d8bba61 100644
76809 --- a/net/ipv4/inetpeer.c
76810 +++ b/net/ipv4/inetpeer.c
76811 @@ -503,8 +503,8 @@ relookup:
76812 if (p) {
76813 p->daddr = *daddr;
76814 atomic_set(&p->refcnt, 1);
76815 - atomic_set(&p->rid, 0);
76816 - atomic_set(&p->ip_id_count,
76817 + atomic_set_unchecked(&p->rid, 0);
76818 + atomic_set_unchecked(&p->ip_id_count,
76819 (daddr->family == AF_INET) ?
76820 secure_ip_id(daddr->addr.a4) :
76821 secure_ipv6_id(daddr->addr.a6));
76822 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76823 index 8d07c97..d0812ef 100644
76824 --- a/net/ipv4/ip_fragment.c
76825 +++ b/net/ipv4/ip_fragment.c
76826 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76827 return 0;
76828
76829 start = qp->rid;
76830 - end = atomic_inc_return(&peer->rid);
76831 + end = atomic_inc_return_unchecked(&peer->rid);
76832 qp->rid = end;
76833
76834 rc = qp->q.fragments && (end - start) > max;
76835 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76836 index 5eea4a8..49819c2 100644
76837 --- a/net/ipv4/ip_sockglue.c
76838 +++ b/net/ipv4/ip_sockglue.c
76839 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76840 len = min_t(unsigned int, len, opt->optlen);
76841 if (put_user(len, optlen))
76842 return -EFAULT;
76843 - if (copy_to_user(optval, opt->__data, len))
76844 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76845 + copy_to_user(optval, opt->__data, len))
76846 return -EFAULT;
76847 return 0;
76848 }
76849 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76850 if (sk->sk_type != SOCK_STREAM)
76851 return -ENOPROTOOPT;
76852
76853 - msg.msg_control = optval;
76854 + msg.msg_control = (void __force_kernel *)optval;
76855 msg.msg_controllen = len;
76856 msg.msg_flags = flags;
76857
76858 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76859 index 67e8a6b..386764d 100644
76860 --- a/net/ipv4/ipconfig.c
76861 +++ b/net/ipv4/ipconfig.c
76862 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76863
76864 mm_segment_t oldfs = get_fs();
76865 set_fs(get_ds());
76866 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76867 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76868 set_fs(oldfs);
76869 return res;
76870 }
76871 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76872
76873 mm_segment_t oldfs = get_fs();
76874 set_fs(get_ds());
76875 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76876 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76877 set_fs(oldfs);
76878 return res;
76879 }
76880 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76881
76882 mm_segment_t oldfs = get_fs();
76883 set_fs(get_ds());
76884 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76885 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76886 set_fs(oldfs);
76887 return res;
76888 }
76889 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76890 index 97e61ea..cac1bbb 100644
76891 --- a/net/ipv4/netfilter/arp_tables.c
76892 +++ b/net/ipv4/netfilter/arp_tables.c
76893 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
76894 #endif
76895
76896 static int get_info(struct net *net, void __user *user,
76897 - const int *len, int compat)
76898 + int len, int compat)
76899 {
76900 char name[XT_TABLE_MAXNAMELEN];
76901 struct xt_table *t;
76902 int ret;
76903
76904 - if (*len != sizeof(struct arpt_getinfo)) {
76905 - duprintf("length %u != %Zu\n", *len,
76906 + if (len != sizeof(struct arpt_getinfo)) {
76907 + duprintf("length %u != %Zu\n", len,
76908 sizeof(struct arpt_getinfo));
76909 return -EINVAL;
76910 }
76911 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
76912 info.size = private->size;
76913 strcpy(info.name, name);
76914
76915 - if (copy_to_user(user, &info, *len) != 0)
76916 + if (copy_to_user(user, &info, len) != 0)
76917 ret = -EFAULT;
76918 else
76919 ret = 0;
76920 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
76921
76922 switch (cmd) {
76923 case ARPT_SO_GET_INFO:
76924 - ret = get_info(sock_net(sk), user, len, 1);
76925 + ret = get_info(sock_net(sk), user, *len, 1);
76926 break;
76927 case ARPT_SO_GET_ENTRIES:
76928 ret = compat_get_entries(sock_net(sk), user, len);
76929 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
76930
76931 switch (cmd) {
76932 case ARPT_SO_GET_INFO:
76933 - ret = get_info(sock_net(sk), user, len, 0);
76934 + ret = get_info(sock_net(sk), user, *len, 0);
76935 break;
76936
76937 case ARPT_SO_GET_ENTRIES:
76938 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76939 index 170b1fd..6105b91 100644
76940 --- a/net/ipv4/netfilter/ip_tables.c
76941 +++ b/net/ipv4/netfilter/ip_tables.c
76942 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
76943 #endif
76944
76945 static int get_info(struct net *net, void __user *user,
76946 - const int *len, int compat)
76947 + int len, int compat)
76948 {
76949 char name[XT_TABLE_MAXNAMELEN];
76950 struct xt_table *t;
76951 int ret;
76952
76953 - if (*len != sizeof(struct ipt_getinfo)) {
76954 - duprintf("length %u != %zu\n", *len,
76955 + if (len != sizeof(struct ipt_getinfo)) {
76956 + duprintf("length %u != %zu\n", len,
76957 sizeof(struct ipt_getinfo));
76958 return -EINVAL;
76959 }
76960 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
76961 info.size = private->size;
76962 strcpy(info.name, name);
76963
76964 - if (copy_to_user(user, &info, *len) != 0)
76965 + if (copy_to_user(user, &info, len) != 0)
76966 ret = -EFAULT;
76967 else
76968 ret = 0;
76969 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76970
76971 switch (cmd) {
76972 case IPT_SO_GET_INFO:
76973 - ret = get_info(sock_net(sk), user, len, 1);
76974 + ret = get_info(sock_net(sk), user, *len, 1);
76975 break;
76976 case IPT_SO_GET_ENTRIES:
76977 ret = compat_get_entries(sock_net(sk), user, len);
76978 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76979
76980 switch (cmd) {
76981 case IPT_SO_GET_INFO:
76982 - ret = get_info(sock_net(sk), user, len, 0);
76983 + ret = get_info(sock_net(sk), user, *len, 0);
76984 break;
76985
76986 case IPT_SO_GET_ENTRIES:
76987 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
76988 index 6232d47..6b88607 100644
76989 --- a/net/ipv4/ping.c
76990 +++ b/net/ipv4/ping.c
76991 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
76992 sk_rmem_alloc_get(sp),
76993 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
76994 atomic_read(&sp->sk_refcnt), sp,
76995 - atomic_read(&sp->sk_drops), len);
76996 + atomic_read_unchecked(&sp->sk_drops), len);
76997 }
76998
76999 static int ping_seq_show(struct seq_file *seq, void *v)
77000 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77001 index d23c657..cb69cc2 100644
77002 --- a/net/ipv4/raw.c
77003 +++ b/net/ipv4/raw.c
77004 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77005 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77006 {
77007 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77008 - atomic_inc(&sk->sk_drops);
77009 + atomic_inc_unchecked(&sk->sk_drops);
77010 kfree_skb(skb);
77011 return NET_RX_DROP;
77012 }
77013 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77014
77015 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77016 {
77017 + struct icmp_filter filter;
77018 +
77019 if (optlen > sizeof(struct icmp_filter))
77020 optlen = sizeof(struct icmp_filter);
77021 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77022 + if (copy_from_user(&filter, optval, optlen))
77023 return -EFAULT;
77024 + raw_sk(sk)->filter = filter;
77025 return 0;
77026 }
77027
77028 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77029 {
77030 int len, ret = -EFAULT;
77031 + struct icmp_filter filter;
77032
77033 if (get_user(len, optlen))
77034 goto out;
77035 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77036 if (len > sizeof(struct icmp_filter))
77037 len = sizeof(struct icmp_filter);
77038 ret = -EFAULT;
77039 - if (put_user(len, optlen) ||
77040 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77041 + filter = raw_sk(sk)->filter;
77042 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77043 goto out;
77044 ret = 0;
77045 out: return ret;
77046 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77047 sk_wmem_alloc_get(sp),
77048 sk_rmem_alloc_get(sp),
77049 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77050 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77051 + atomic_read(&sp->sk_refcnt),
77052 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77053 + NULL,
77054 +#else
77055 + sp,
77056 +#endif
77057 + atomic_read_unchecked(&sp->sk_drops));
77058 }
77059
77060 static int raw_seq_show(struct seq_file *seq, void *v)
77061 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77062 index 2a1383c..ff99572 100644
77063 --- a/net/ipv4/route.c
77064 +++ b/net/ipv4/route.c
77065 @@ -2523,7 +2523,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77066
77067 static __net_init int rt_genid_init(struct net *net)
77068 {
77069 - atomic_set(&net->rt_genid, 0);
77070 + atomic_set_unchecked(&net->rt_genid, 0);
77071 get_random_bytes(&net->ipv4.dev_addr_genid,
77072 sizeof(net->ipv4.dev_addr_genid));
77073 return 0;
77074 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77075 index d377f48..c2211ed 100644
77076 --- a/net/ipv4/tcp_input.c
77077 +++ b/net/ipv4/tcp_input.c
77078 @@ -4728,7 +4728,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77079 * simplifies code)
77080 */
77081 static void
77082 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77083 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77084 struct sk_buff *head, struct sk_buff *tail,
77085 u32 start, u32 end)
77086 {
77087 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77088 index db7bfad..bfea796 100644
77089 --- a/net/ipv4/tcp_ipv4.c
77090 +++ b/net/ipv4/tcp_ipv4.c
77091 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77092 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77093
77094
77095 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77096 +extern int grsec_enable_blackhole;
77097 +#endif
77098 +
77099 #ifdef CONFIG_TCP_MD5SIG
77100 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77101 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77102 @@ -1664,6 +1668,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77103 return 0;
77104
77105 reset:
77106 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77107 + if (!grsec_enable_blackhole)
77108 +#endif
77109 tcp_v4_send_reset(rsk, skb);
77110 discard:
77111 kfree_skb(skb);
77112 @@ -1764,12 +1771,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77113 TCP_SKB_CB(skb)->sacked = 0;
77114
77115 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77116 - if (!sk)
77117 + if (!sk) {
77118 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77119 + ret = 1;
77120 +#endif
77121 goto no_tcp_socket;
77122 -
77123 + }
77124 process:
77125 - if (sk->sk_state == TCP_TIME_WAIT)
77126 + if (sk->sk_state == TCP_TIME_WAIT) {
77127 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77128 + ret = 2;
77129 +#endif
77130 goto do_time_wait;
77131 + }
77132
77133 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77134 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77135 @@ -1820,6 +1834,10 @@ no_tcp_socket:
77136 bad_packet:
77137 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77138 } else {
77139 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77140 + if (!grsec_enable_blackhole || (ret == 1 &&
77141 + (skb->dev->flags & IFF_LOOPBACK)))
77142 +#endif
77143 tcp_v4_send_reset(NULL, skb);
77144 }
77145
77146 @@ -2415,7 +2433,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77147 0, /* non standard timer */
77148 0, /* open_requests have no inode */
77149 atomic_read(&sk->sk_refcnt),
77150 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77151 + NULL,
77152 +#else
77153 req,
77154 +#endif
77155 len);
77156 }
77157
77158 @@ -2465,7 +2487,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77159 sock_i_uid(sk),
77160 icsk->icsk_probes_out,
77161 sock_i_ino(sk),
77162 - atomic_read(&sk->sk_refcnt), sk,
77163 + atomic_read(&sk->sk_refcnt),
77164 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77165 + NULL,
77166 +#else
77167 + sk,
77168 +#endif
77169 jiffies_to_clock_t(icsk->icsk_rto),
77170 jiffies_to_clock_t(icsk->icsk_ack.ato),
77171 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77172 @@ -2493,7 +2520,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77173 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77174 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77175 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77176 - atomic_read(&tw->tw_refcnt), tw, len);
77177 + atomic_read(&tw->tw_refcnt),
77178 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77179 + NULL,
77180 +#else
77181 + tw,
77182 +#endif
77183 + len);
77184 }
77185
77186 #define TMPSZ 150
77187 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77188 index 6ff7f10..38de56e 100644
77189 --- a/net/ipv4/tcp_minisocks.c
77190 +++ b/net/ipv4/tcp_minisocks.c
77191 @@ -27,6 +27,10 @@
77192 #include <net/inet_common.h>
77193 #include <net/xfrm.h>
77194
77195 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77196 +extern int grsec_enable_blackhole;
77197 +#endif
77198 +
77199 int sysctl_tcp_syncookies __read_mostly = 1;
77200 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77201
77202 @@ -707,6 +711,10 @@ listen_overflow:
77203
77204 embryonic_reset:
77205 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77206 +
77207 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77208 + if (!grsec_enable_blackhole)
77209 +#endif
77210 if (!(flg & TCP_FLAG_RST))
77211 req->rsk_ops->send_reset(sk, skb);
77212
77213 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77214 index 4526fe6..1a34e43 100644
77215 --- a/net/ipv4/tcp_probe.c
77216 +++ b/net/ipv4/tcp_probe.c
77217 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77218 if (cnt + width >= len)
77219 break;
77220
77221 - if (copy_to_user(buf + cnt, tbuf, width))
77222 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77223 return -EFAULT;
77224 cnt += width;
77225 }
77226 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77227 index b774a03..3873efe 100644
77228 --- a/net/ipv4/tcp_timer.c
77229 +++ b/net/ipv4/tcp_timer.c
77230 @@ -22,6 +22,10 @@
77231 #include <linux/gfp.h>
77232 #include <net/tcp.h>
77233
77234 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77235 +extern int grsec_lastack_retries;
77236 +#endif
77237 +
77238 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77239 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77240 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77241 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77242 }
77243 }
77244
77245 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77246 + if ((sk->sk_state == TCP_LAST_ACK) &&
77247 + (grsec_lastack_retries > 0) &&
77248 + (grsec_lastack_retries < retry_until))
77249 + retry_until = grsec_lastack_retries;
77250 +#endif
77251 +
77252 if (retransmits_timed_out(sk, retry_until,
77253 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77254 /* Has it gone just too far? */
77255 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77256 index 2814f66..fa2b223 100644
77257 --- a/net/ipv4/udp.c
77258 +++ b/net/ipv4/udp.c
77259 @@ -87,6 +87,7 @@
77260 #include <linux/types.h>
77261 #include <linux/fcntl.h>
77262 #include <linux/module.h>
77263 +#include <linux/security.h>
77264 #include <linux/socket.h>
77265 #include <linux/sockios.h>
77266 #include <linux/igmp.h>
77267 @@ -111,6 +112,10 @@
77268 #include <trace/events/skb.h>
77269 #include "udp_impl.h"
77270
77271 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77272 +extern int grsec_enable_blackhole;
77273 +#endif
77274 +
77275 struct udp_table udp_table __read_mostly;
77276 EXPORT_SYMBOL(udp_table);
77277
77278 @@ -569,6 +574,9 @@ found:
77279 return s;
77280 }
77281
77282 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77283 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77284 +
77285 /*
77286 * This routine is called by the ICMP module when it gets some
77287 * sort of error condition. If err < 0 then the socket should
77288 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77289 dport = usin->sin_port;
77290 if (dport == 0)
77291 return -EINVAL;
77292 +
77293 + err = gr_search_udp_sendmsg(sk, usin);
77294 + if (err)
77295 + return err;
77296 } else {
77297 if (sk->sk_state != TCP_ESTABLISHED)
77298 return -EDESTADDRREQ;
77299 +
77300 + err = gr_search_udp_sendmsg(sk, NULL);
77301 + if (err)
77302 + return err;
77303 +
77304 daddr = inet->inet_daddr;
77305 dport = inet->inet_dport;
77306 /* Open fast path for connected socket.
77307 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77308 udp_lib_checksum_complete(skb)) {
77309 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77310 IS_UDPLITE(sk));
77311 - atomic_inc(&sk->sk_drops);
77312 + atomic_inc_unchecked(&sk->sk_drops);
77313 __skb_unlink(skb, rcvq);
77314 __skb_queue_tail(&list_kill, skb);
77315 }
77316 @@ -1194,6 +1211,10 @@ try_again:
77317 if (!skb)
77318 goto out;
77319
77320 + err = gr_search_udp_recvmsg(sk, skb);
77321 + if (err)
77322 + goto out_free;
77323 +
77324 ulen = skb->len - sizeof(struct udphdr);
77325 copied = len;
77326 if (copied > ulen)
77327 @@ -1227,7 +1248,7 @@ try_again:
77328 if (unlikely(err)) {
77329 trace_kfree_skb(skb, udp_recvmsg);
77330 if (!peeked) {
77331 - atomic_inc(&sk->sk_drops);
77332 + atomic_inc_unchecked(&sk->sk_drops);
77333 UDP_INC_STATS_USER(sock_net(sk),
77334 UDP_MIB_INERRORS, is_udplite);
77335 }
77336 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77337
77338 drop:
77339 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77340 - atomic_inc(&sk->sk_drops);
77341 + atomic_inc_unchecked(&sk->sk_drops);
77342 kfree_skb(skb);
77343 return -1;
77344 }
77345 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77346 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77347
77348 if (!skb1) {
77349 - atomic_inc(&sk->sk_drops);
77350 + atomic_inc_unchecked(&sk->sk_drops);
77351 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77352 IS_UDPLITE(sk));
77353 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77354 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77355 goto csum_error;
77356
77357 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77358 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77359 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77360 +#endif
77361 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77362
77363 /*
77364 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77365 sk_wmem_alloc_get(sp),
77366 sk_rmem_alloc_get(sp),
77367 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77368 - atomic_read(&sp->sk_refcnt), sp,
77369 - atomic_read(&sp->sk_drops), len);
77370 + atomic_read(&sp->sk_refcnt),
77371 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77372 + NULL,
77373 +#else
77374 + sp,
77375 +#endif
77376 + atomic_read_unchecked(&sp->sk_drops), len);
77377 }
77378
77379 int udp4_seq_show(struct seq_file *seq, void *v)
77380 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77381 index b10374d..0baa1f9 100644
77382 --- a/net/ipv6/addrconf.c
77383 +++ b/net/ipv6/addrconf.c
77384 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77385 p.iph.ihl = 5;
77386 p.iph.protocol = IPPROTO_IPV6;
77387 p.iph.ttl = 64;
77388 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77389 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77390
77391 if (ops->ndo_do_ioctl) {
77392 mm_segment_t oldfs = get_fs();
77393 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77394 index ba6d13d..6899122 100644
77395 --- a/net/ipv6/ipv6_sockglue.c
77396 +++ b/net/ipv6/ipv6_sockglue.c
77397 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77398 if (sk->sk_type != SOCK_STREAM)
77399 return -ENOPROTOOPT;
77400
77401 - msg.msg_control = optval;
77402 + msg.msg_control = (void __force_kernel *)optval;
77403 msg.msg_controllen = len;
77404 msg.msg_flags = flags;
77405
77406 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77407 index d7cb045..8c0ded6 100644
77408 --- a/net/ipv6/netfilter/ip6_tables.c
77409 +++ b/net/ipv6/netfilter/ip6_tables.c
77410 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77411 #endif
77412
77413 static int get_info(struct net *net, void __user *user,
77414 - const int *len, int compat)
77415 + int len, int compat)
77416 {
77417 char name[XT_TABLE_MAXNAMELEN];
77418 struct xt_table *t;
77419 int ret;
77420
77421 - if (*len != sizeof(struct ip6t_getinfo)) {
77422 - duprintf("length %u != %zu\n", *len,
77423 + if (len != sizeof(struct ip6t_getinfo)) {
77424 + duprintf("length %u != %zu\n", len,
77425 sizeof(struct ip6t_getinfo));
77426 return -EINVAL;
77427 }
77428 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77429 info.size = private->size;
77430 strcpy(info.name, name);
77431
77432 - if (copy_to_user(user, &info, *len) != 0)
77433 + if (copy_to_user(user, &info, len) != 0)
77434 ret = -EFAULT;
77435 else
77436 ret = 0;
77437 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77438
77439 switch (cmd) {
77440 case IP6T_SO_GET_INFO:
77441 - ret = get_info(sock_net(sk), user, len, 1);
77442 + ret = get_info(sock_net(sk), user, *len, 1);
77443 break;
77444 case IP6T_SO_GET_ENTRIES:
77445 ret = compat_get_entries(sock_net(sk), user, len);
77446 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77447
77448 switch (cmd) {
77449 case IP6T_SO_GET_INFO:
77450 - ret = get_info(sock_net(sk), user, len, 0);
77451 + ret = get_info(sock_net(sk), user, *len, 0);
77452 break;
77453
77454 case IP6T_SO_GET_ENTRIES:
77455 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77456 index 4a5f78b..3f22ebe 100644
77457 --- a/net/ipv6/raw.c
77458 +++ b/net/ipv6/raw.c
77459 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77460 {
77461 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77462 skb_checksum_complete(skb)) {
77463 - atomic_inc(&sk->sk_drops);
77464 + atomic_inc_unchecked(&sk->sk_drops);
77465 kfree_skb(skb);
77466 return NET_RX_DROP;
77467 }
77468 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77469 struct raw6_sock *rp = raw6_sk(sk);
77470
77471 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77472 - atomic_inc(&sk->sk_drops);
77473 + atomic_inc_unchecked(&sk->sk_drops);
77474 kfree_skb(skb);
77475 return NET_RX_DROP;
77476 }
77477 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77478
77479 if (inet->hdrincl) {
77480 if (skb_checksum_complete(skb)) {
77481 - atomic_inc(&sk->sk_drops);
77482 + atomic_inc_unchecked(&sk->sk_drops);
77483 kfree_skb(skb);
77484 return NET_RX_DROP;
77485 }
77486 @@ -604,7 +604,7 @@ out:
77487 return err;
77488 }
77489
77490 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77491 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77492 struct flowi6 *fl6, struct dst_entry **dstp,
77493 unsigned int flags)
77494 {
77495 @@ -916,12 +916,15 @@ do_confirm:
77496 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77497 char __user *optval, int optlen)
77498 {
77499 + struct icmp6_filter filter;
77500 +
77501 switch (optname) {
77502 case ICMPV6_FILTER:
77503 if (optlen > sizeof(struct icmp6_filter))
77504 optlen = sizeof(struct icmp6_filter);
77505 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77506 + if (copy_from_user(&filter, optval, optlen))
77507 return -EFAULT;
77508 + raw6_sk(sk)->filter = filter;
77509 return 0;
77510 default:
77511 return -ENOPROTOOPT;
77512 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77513 char __user *optval, int __user *optlen)
77514 {
77515 int len;
77516 + struct icmp6_filter filter;
77517
77518 switch (optname) {
77519 case ICMPV6_FILTER:
77520 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77521 len = sizeof(struct icmp6_filter);
77522 if (put_user(len, optlen))
77523 return -EFAULT;
77524 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77525 + filter = raw6_sk(sk)->filter;
77526 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77527 return -EFAULT;
77528 return 0;
77529 default:
77530 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77531 0, 0L, 0,
77532 sock_i_uid(sp), 0,
77533 sock_i_ino(sp),
77534 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77535 + atomic_read(&sp->sk_refcnt),
77536 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77537 + NULL,
77538 +#else
77539 + sp,
77540 +#endif
77541 + atomic_read_unchecked(&sp->sk_drops));
77542 }
77543
77544 static int raw6_seq_show(struct seq_file *seq, void *v)
77545 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77546 index 7e32d42..5d975ba 100644
77547 --- a/net/ipv6/tcp_ipv6.c
77548 +++ b/net/ipv6/tcp_ipv6.c
77549 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77550 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77551 }
77552
77553 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77554 +extern int grsec_enable_blackhole;
77555 +#endif
77556 +
77557 static void tcp_v6_hash(struct sock *sk)
77558 {
77559 if (sk->sk_state != TCP_CLOSE) {
77560 @@ -1511,6 +1515,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77561 return 0;
77562
77563 reset:
77564 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77565 + if (!grsec_enable_blackhole)
77566 +#endif
77567 tcp_v6_send_reset(sk, skb);
77568 discard:
77569 if (opt_skb)
77570 @@ -1592,12 +1599,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77571 TCP_SKB_CB(skb)->sacked = 0;
77572
77573 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77574 - if (!sk)
77575 + if (!sk) {
77576 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77577 + ret = 1;
77578 +#endif
77579 goto no_tcp_socket;
77580 + }
77581
77582 process:
77583 - if (sk->sk_state == TCP_TIME_WAIT)
77584 + if (sk->sk_state == TCP_TIME_WAIT) {
77585 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77586 + ret = 2;
77587 +#endif
77588 goto do_time_wait;
77589 + }
77590
77591 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77592 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77593 @@ -1646,6 +1661,10 @@ no_tcp_socket:
77594 bad_packet:
77595 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77596 } else {
77597 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77598 + if (!grsec_enable_blackhole || (ret == 1 &&
77599 + (skb->dev->flags & IFF_LOOPBACK)))
77600 +#endif
77601 tcp_v6_send_reset(NULL, skb);
77602 }
77603
77604 @@ -1857,7 +1876,13 @@ static void get_openreq6(struct seq_file *seq,
77605 uid,
77606 0, /* non standard timer */
77607 0, /* open_requests have no inode */
77608 - 0, req);
77609 + 0,
77610 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77611 + NULL
77612 +#else
77613 + req
77614 +#endif
77615 + );
77616 }
77617
77618 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77619 @@ -1907,7 +1932,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77620 sock_i_uid(sp),
77621 icsk->icsk_probes_out,
77622 sock_i_ino(sp),
77623 - atomic_read(&sp->sk_refcnt), sp,
77624 + atomic_read(&sp->sk_refcnt),
77625 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77626 + NULL,
77627 +#else
77628 + sp,
77629 +#endif
77630 jiffies_to_clock_t(icsk->icsk_rto),
77631 jiffies_to_clock_t(icsk->icsk_ack.ato),
77632 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77633 @@ -1942,7 +1972,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77634 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77635 tw->tw_substate, 0, 0,
77636 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77637 - atomic_read(&tw->tw_refcnt), tw);
77638 + atomic_read(&tw->tw_refcnt),
77639 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77640 + NULL
77641 +#else
77642 + tw
77643 +#endif
77644 + );
77645 }
77646
77647 static int tcp6_seq_show(struct seq_file *seq, void *v)
77648 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77649 index 07e2bfe..328dae8 100644
77650 --- a/net/ipv6/udp.c
77651 +++ b/net/ipv6/udp.c
77652 @@ -51,6 +51,10 @@
77653 #include <trace/events/skb.h>
77654 #include "udp_impl.h"
77655
77656 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77657 +extern int grsec_enable_blackhole;
77658 +#endif
77659 +
77660 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77661 {
77662 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77663 @@ -395,7 +399,7 @@ try_again:
77664 if (unlikely(err)) {
77665 trace_kfree_skb(skb, udpv6_recvmsg);
77666 if (!peeked) {
77667 - atomic_inc(&sk->sk_drops);
77668 + atomic_inc_unchecked(&sk->sk_drops);
77669 if (is_udp4)
77670 UDP_INC_STATS_USER(sock_net(sk),
77671 UDP_MIB_INERRORS,
77672 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77673 return rc;
77674 drop:
77675 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77676 - atomic_inc(&sk->sk_drops);
77677 + atomic_inc_unchecked(&sk->sk_drops);
77678 kfree_skb(skb);
77679 return -1;
77680 }
77681 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77682 if (likely(skb1 == NULL))
77683 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77684 if (!skb1) {
77685 - atomic_inc(&sk->sk_drops);
77686 + atomic_inc_unchecked(&sk->sk_drops);
77687 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77688 IS_UDPLITE(sk));
77689 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77690 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77691 goto discard;
77692
77693 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77694 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77695 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77696 +#endif
77697 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77698
77699 kfree_skb(skb);
77700 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77701 0, 0L, 0,
77702 sock_i_uid(sp), 0,
77703 sock_i_ino(sp),
77704 - atomic_read(&sp->sk_refcnt), sp,
77705 - atomic_read(&sp->sk_drops));
77706 + atomic_read(&sp->sk_refcnt),
77707 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77708 + NULL,
77709 +#else
77710 + sp,
77711 +#endif
77712 + atomic_read_unchecked(&sp->sk_drops));
77713 }
77714
77715 int udp6_seq_show(struct seq_file *seq, void *v)
77716 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77717 index 6b9d5a0..4dffaf1 100644
77718 --- a/net/irda/ircomm/ircomm_tty.c
77719 +++ b/net/irda/ircomm/ircomm_tty.c
77720 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77721 add_wait_queue(&self->open_wait, &wait);
77722
77723 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77724 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77725 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77726
77727 /* As far as I can see, we protect open_count - Jean II */
77728 spin_lock_irqsave(&self->spinlock, flags);
77729 if (!tty_hung_up_p(filp)) {
77730 extra_count = 1;
77731 - self->open_count--;
77732 + local_dec(&self->open_count);
77733 }
77734 spin_unlock_irqrestore(&self->spinlock, flags);
77735 - self->blocked_open++;
77736 + local_inc(&self->blocked_open);
77737
77738 while (1) {
77739 if (tty->termios->c_cflag & CBAUD) {
77740 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77741 }
77742
77743 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77744 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77745 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77746
77747 schedule();
77748 }
77749 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77750 if (extra_count) {
77751 /* ++ is not atomic, so this should be protected - Jean II */
77752 spin_lock_irqsave(&self->spinlock, flags);
77753 - self->open_count++;
77754 + local_inc(&self->open_count);
77755 spin_unlock_irqrestore(&self->spinlock, flags);
77756 }
77757 - self->blocked_open--;
77758 + local_dec(&self->blocked_open);
77759
77760 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77761 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77762 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77763
77764 if (!retval)
77765 self->flags |= ASYNC_NORMAL_ACTIVE;
77766 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77767 }
77768 /* ++ is not atomic, so this should be protected - Jean II */
77769 spin_lock_irqsave(&self->spinlock, flags);
77770 - self->open_count++;
77771 + local_inc(&self->open_count);
77772
77773 tty->driver_data = self;
77774 self->tty = tty;
77775 spin_unlock_irqrestore(&self->spinlock, flags);
77776
77777 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77778 - self->line, self->open_count);
77779 + self->line, local_read(&self->open_count));
77780
77781 /* Not really used by us, but lets do it anyway */
77782 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77783 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77784 return;
77785 }
77786
77787 - if ((tty->count == 1) && (self->open_count != 1)) {
77788 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77789 /*
77790 * Uh, oh. tty->count is 1, which means that the tty
77791 * structure will be freed. state->count should always
77792 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77793 */
77794 IRDA_DEBUG(0, "%s(), bad serial port count; "
77795 "tty->count is 1, state->count is %d\n", __func__ ,
77796 - self->open_count);
77797 - self->open_count = 1;
77798 + local_read(&self->open_count));
77799 + local_set(&self->open_count, 1);
77800 }
77801
77802 - if (--self->open_count < 0) {
77803 + if (local_dec_return(&self->open_count) < 0) {
77804 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77805 - __func__, self->line, self->open_count);
77806 - self->open_count = 0;
77807 + __func__, self->line, local_read(&self->open_count));
77808 + local_set(&self->open_count, 0);
77809 }
77810 - if (self->open_count) {
77811 + if (local_read(&self->open_count)) {
77812 spin_unlock_irqrestore(&self->spinlock, flags);
77813
77814 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77815 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77816 tty->closing = 0;
77817 self->tty = NULL;
77818
77819 - if (self->blocked_open) {
77820 + if (local_read(&self->blocked_open)) {
77821 if (self->close_delay)
77822 schedule_timeout_interruptible(self->close_delay);
77823 wake_up_interruptible(&self->open_wait);
77824 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77825 spin_lock_irqsave(&self->spinlock, flags);
77826 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77827 self->tty = NULL;
77828 - self->open_count = 0;
77829 + local_set(&self->open_count, 0);
77830 spin_unlock_irqrestore(&self->spinlock, flags);
77831
77832 wake_up_interruptible(&self->open_wait);
77833 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77834 seq_putc(m, '\n');
77835
77836 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77837 - seq_printf(m, "Open count: %d\n", self->open_count);
77838 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77839 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77840 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77841
77842 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77843 index cd6f7a9..e63fe89 100644
77844 --- a/net/iucv/af_iucv.c
77845 +++ b/net/iucv/af_iucv.c
77846 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77847
77848 write_lock_bh(&iucv_sk_list.lock);
77849
77850 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77851 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77852 while (__iucv_get_sock_by_name(name)) {
77853 sprintf(name, "%08x",
77854 - atomic_inc_return(&iucv_sk_list.autobind_name));
77855 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77856 }
77857
77858 write_unlock_bh(&iucv_sk_list.lock);
77859 diff --git a/net/key/af_key.c b/net/key/af_key.c
77860 index 34e4185..8823368 100644
77861 --- a/net/key/af_key.c
77862 +++ b/net/key/af_key.c
77863 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77864 static u32 get_acqseq(void)
77865 {
77866 u32 res;
77867 - static atomic_t acqseq;
77868 + static atomic_unchecked_t acqseq;
77869
77870 do {
77871 - res = atomic_inc_return(&acqseq);
77872 + res = atomic_inc_return_unchecked(&acqseq);
77873 } while (!res);
77874 return res;
77875 }
77876 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77877 index bb61f77..3788d63 100644
77878 --- a/net/mac80211/ieee80211_i.h
77879 +++ b/net/mac80211/ieee80211_i.h
77880 @@ -28,6 +28,7 @@
77881 #include <net/ieee80211_radiotap.h>
77882 #include <net/cfg80211.h>
77883 #include <net/mac80211.h>
77884 +#include <asm/local.h>
77885 #include "key.h"
77886 #include "sta_info.h"
77887 #include "debug.h"
77888 @@ -840,7 +841,7 @@ struct ieee80211_local {
77889 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77890 spinlock_t queue_stop_reason_lock;
77891
77892 - int open_count;
77893 + local_t open_count;
77894 int monitors, cooked_mntrs;
77895 /* number of interfaces with corresponding FIF_ flags */
77896 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77897 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77898 index c93d395..a305570 100644
77899 --- a/net/mac80211/iface.c
77900 +++ b/net/mac80211/iface.c
77901 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77902 break;
77903 }
77904
77905 - if (local->open_count == 0) {
77906 + if (local_read(&local->open_count) == 0) {
77907 res = drv_start(local);
77908 if (res)
77909 goto err_del_bss;
77910 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77911 break;
77912 }
77913
77914 - if (local->monitors == 0 && local->open_count == 0) {
77915 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77916 res = ieee80211_add_virtual_monitor(local);
77917 if (res)
77918 goto err_stop;
77919 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77920 mutex_unlock(&local->mtx);
77921
77922 if (coming_up)
77923 - local->open_count++;
77924 + local_inc(&local->open_count);
77925
77926 if (hw_reconf_flags)
77927 ieee80211_hw_config(local, hw_reconf_flags);
77928 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77929 err_del_interface:
77930 drv_remove_interface(local, sdata);
77931 err_stop:
77932 - if (!local->open_count)
77933 + if (!local_read(&local->open_count))
77934 drv_stop(local);
77935 err_del_bss:
77936 sdata->bss = NULL;
77937 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77938 }
77939
77940 if (going_down)
77941 - local->open_count--;
77942 + local_dec(&local->open_count);
77943
77944 switch (sdata->vif.type) {
77945 case NL80211_IFTYPE_AP_VLAN:
77946 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77947
77948 ieee80211_recalc_ps(local, -1);
77949
77950 - if (local->open_count == 0) {
77951 + if (local_read(&local->open_count) == 0) {
77952 if (local->ops->napi_poll)
77953 napi_disable(&local->napi);
77954 ieee80211_clear_tx_pending(local);
77955 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77956 }
77957 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77958
77959 - if (local->monitors == local->open_count && local->monitors > 0)
77960 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77961 ieee80211_add_virtual_monitor(local);
77962 }
77963
77964 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77965 index c26e231..8916637 100644
77966 --- a/net/mac80211/main.c
77967 +++ b/net/mac80211/main.c
77968 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77969 local->hw.conf.power_level = power;
77970 }
77971
77972 - if (changed && local->open_count) {
77973 + if (changed && local_read(&local->open_count)) {
77974 ret = drv_config(local, changed);
77975 /*
77976 * Goal:
77977 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77978 index 5c572e7..ecf75ce 100644
77979 --- a/net/mac80211/pm.c
77980 +++ b/net/mac80211/pm.c
77981 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77982 struct ieee80211_sub_if_data *sdata;
77983 struct sta_info *sta;
77984
77985 - if (!local->open_count)
77986 + if (!local_read(&local->open_count))
77987 goto suspend;
77988
77989 ieee80211_scan_cancel(local);
77990 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
77991 cancel_work_sync(&local->dynamic_ps_enable_work);
77992 del_timer_sync(&local->dynamic_ps_timer);
77993
77994 - local->wowlan = wowlan && local->open_count;
77995 + local->wowlan = wowlan && local_read(&local->open_count);
77996 if (local->wowlan) {
77997 int err = drv_suspend(local, wowlan);
77998 if (err < 0) {
77999 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78000 drv_remove_interface(local, sdata);
78001
78002 /* stop hardware - this must stop RX */
78003 - if (local->open_count)
78004 + if (local_read(&local->open_count))
78005 ieee80211_stop_device(local);
78006
78007 suspend:
78008 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78009 index 3313c11..bec9f17 100644
78010 --- a/net/mac80211/rate.c
78011 +++ b/net/mac80211/rate.c
78012 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78013
78014 ASSERT_RTNL();
78015
78016 - if (local->open_count)
78017 + if (local_read(&local->open_count))
78018 return -EBUSY;
78019
78020 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78021 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78022 index c97a065..ff61928 100644
78023 --- a/net/mac80211/rc80211_pid_debugfs.c
78024 +++ b/net/mac80211/rc80211_pid_debugfs.c
78025 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78026
78027 spin_unlock_irqrestore(&events->lock, status);
78028
78029 - if (copy_to_user(buf, pb, p))
78030 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78031 return -EFAULT;
78032
78033 return p;
78034 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78035 index c9b52f7..4da1014 100644
78036 --- a/net/mac80211/util.c
78037 +++ b/net/mac80211/util.c
78038 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78039 }
78040 #endif
78041 /* everything else happens only if HW was up & running */
78042 - if (!local->open_count)
78043 + if (!local_read(&local->open_count))
78044 goto wake_up;
78045
78046 /*
78047 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78048 index c19b214..471fad1 100644
78049 --- a/net/netfilter/Kconfig
78050 +++ b/net/netfilter/Kconfig
78051 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78052
78053 To compile it as a module, choose M here. If unsure, say N.
78054
78055 +config NETFILTER_XT_MATCH_GRADM
78056 + tristate '"gradm" match support'
78057 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78058 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78059 + ---help---
78060 + The gradm match allows to match on grsecurity RBAC being enabled.
78061 + It is useful when iptables rules are applied early on bootup to
78062 + prevent connections to the machine (except from a trusted host)
78063 + while the RBAC system is disabled.
78064 +
78065 config NETFILTER_XT_MATCH_HASHLIMIT
78066 tristate '"hashlimit" match support'
78067 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78068 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78069 index 1c5160f..145ae21 100644
78070 --- a/net/netfilter/Makefile
78071 +++ b/net/netfilter/Makefile
78072 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78073 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78074 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78075 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78076 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78077 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78078 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78079 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78080 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78081 index 1548df9..98ad9b4 100644
78082 --- a/net/netfilter/ipvs/ip_vs_conn.c
78083 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78084 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78085 /* Increase the refcnt counter of the dest */
78086 atomic_inc(&dest->refcnt);
78087
78088 - conn_flags = atomic_read(&dest->conn_flags);
78089 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78090 if (cp->protocol != IPPROTO_UDP)
78091 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78092 flags = cp->flags;
78093 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78094 atomic_set(&cp->refcnt, 1);
78095
78096 atomic_set(&cp->n_control, 0);
78097 - atomic_set(&cp->in_pkts, 0);
78098 + atomic_set_unchecked(&cp->in_pkts, 0);
78099
78100 atomic_inc(&ipvs->conn_count);
78101 if (flags & IP_VS_CONN_F_NO_CPORT)
78102 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78103
78104 /* Don't drop the entry if its number of incoming packets is not
78105 located in [0, 8] */
78106 - i = atomic_read(&cp->in_pkts);
78107 + i = atomic_read_unchecked(&cp->in_pkts);
78108 if (i > 8 || i < 0) return 0;
78109
78110 if (!todrop_rate[i]) return 0;
78111 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78112 index b54ecce..fc5f6cf 100644
78113 --- a/net/netfilter/ipvs/ip_vs_core.c
78114 +++ b/net/netfilter/ipvs/ip_vs_core.c
78115 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78116 ret = cp->packet_xmit(skb, cp, pd->pp);
78117 /* do not touch skb anymore */
78118
78119 - atomic_inc(&cp->in_pkts);
78120 + atomic_inc_unchecked(&cp->in_pkts);
78121 ip_vs_conn_put(cp);
78122 return ret;
78123 }
78124 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78125 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78126 pkts = sysctl_sync_threshold(ipvs);
78127 else
78128 - pkts = atomic_add_return(1, &cp->in_pkts);
78129 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78130
78131 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78132 ip_vs_sync_conn(net, cp, pkts);
78133 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78134 index f51013c..c99ee52 100644
78135 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78136 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78137 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78138 ip_vs_rs_hash(ipvs, dest);
78139 write_unlock_bh(&ipvs->rs_lock);
78140 }
78141 - atomic_set(&dest->conn_flags, conn_flags);
78142 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78143
78144 /* bind the service */
78145 if (!dest->svc) {
78146 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78147 " %-7s %-6d %-10d %-10d\n",
78148 &dest->addr.in6,
78149 ntohs(dest->port),
78150 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78151 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78152 atomic_read(&dest->weight),
78153 atomic_read(&dest->activeconns),
78154 atomic_read(&dest->inactconns));
78155 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78156 "%-7s %-6d %-10d %-10d\n",
78157 ntohl(dest->addr.ip),
78158 ntohs(dest->port),
78159 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78160 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78161 atomic_read(&dest->weight),
78162 atomic_read(&dest->activeconns),
78163 atomic_read(&dest->inactconns));
78164 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78165
78166 entry.addr = dest->addr.ip;
78167 entry.port = dest->port;
78168 - entry.conn_flags = atomic_read(&dest->conn_flags);
78169 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78170 entry.weight = atomic_read(&dest->weight);
78171 entry.u_threshold = dest->u_threshold;
78172 entry.l_threshold = dest->l_threshold;
78173 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78174 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78175 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78176 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78177 - (atomic_read(&dest->conn_flags) &
78178 + (atomic_read_unchecked(&dest->conn_flags) &
78179 IP_VS_CONN_F_FWD_MASK)) ||
78180 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78181 atomic_read(&dest->weight)) ||
78182 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78183 index effa10c..9058928 100644
78184 --- a/net/netfilter/ipvs/ip_vs_sync.c
78185 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78186 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78187 cp = cp->control;
78188 if (cp) {
78189 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78190 - pkts = atomic_add_return(1, &cp->in_pkts);
78191 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78192 else
78193 pkts = sysctl_sync_threshold(ipvs);
78194 ip_vs_sync_conn(net, cp->control, pkts);
78195 @@ -758,7 +758,7 @@ control:
78196 if (!cp)
78197 return;
78198 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78199 - pkts = atomic_add_return(1, &cp->in_pkts);
78200 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78201 else
78202 pkts = sysctl_sync_threshold(ipvs);
78203 goto sloop;
78204 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78205
78206 if (opt)
78207 memcpy(&cp->in_seq, opt, sizeof(*opt));
78208 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78209 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78210 cp->state = state;
78211 cp->old_state = cp->state;
78212 /*
78213 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78214 index c3c6291..3376d73 100644
78215 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78216 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78217 @@ -1157,7 +1157,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78218 else
78219 rc = NF_ACCEPT;
78220 /* do not touch skb anymore */
78221 - atomic_inc(&cp->in_pkts);
78222 + atomic_inc_unchecked(&cp->in_pkts);
78223 goto out;
78224 }
78225
78226 @@ -1278,7 +1278,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78227 else
78228 rc = NF_ACCEPT;
78229 /* do not touch skb anymore */
78230 - atomic_inc(&cp->in_pkts);
78231 + atomic_inc_unchecked(&cp->in_pkts);
78232 goto out;
78233 }
78234
78235 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78236 index 2ceec64..a5b8a61 100644
78237 --- a/net/netfilter/nf_conntrack_core.c
78238 +++ b/net/netfilter/nf_conntrack_core.c
78239 @@ -1529,6 +1529,10 @@ err_extend:
78240 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78241 #define DYING_NULLS_VAL ((1<<30)+1)
78242
78243 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78244 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78245 +#endif
78246 +
78247 static int nf_conntrack_init_net(struct net *net)
78248 {
78249 int ret;
78250 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78251 goto err_stat;
78252 }
78253
78254 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78255 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78256 +#else
78257 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78258 +#endif
78259 if (!net->ct.slabname) {
78260 ret = -ENOMEM;
78261 goto err_slabname;
78262 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78263 index 5cfb5be..217c6d8 100644
78264 --- a/net/netfilter/nfnetlink_log.c
78265 +++ b/net/netfilter/nfnetlink_log.c
78266 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78267 };
78268
78269 static DEFINE_SPINLOCK(instances_lock);
78270 -static atomic_t global_seq;
78271 +static atomic_unchecked_t global_seq;
78272
78273 #define INSTANCE_BUCKETS 16
78274 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78275 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78276 /* global sequence number */
78277 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78278 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78279 - htonl(atomic_inc_return(&global_seq))))
78280 + htonl(atomic_inc_return_unchecked(&global_seq))))
78281 goto nla_put_failure;
78282
78283 if (data_len) {
78284 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78285 new file mode 100644
78286 index 0000000..6905327
78287 --- /dev/null
78288 +++ b/net/netfilter/xt_gradm.c
78289 @@ -0,0 +1,51 @@
78290 +/*
78291 + * gradm match for netfilter
78292 + * Copyright © Zbigniew Krzystolik, 2010
78293 + *
78294 + * This program is free software; you can redistribute it and/or modify
78295 + * it under the terms of the GNU General Public License; either version
78296 + * 2 or 3 as published by the Free Software Foundation.
78297 + */
78298 +#include <linux/module.h>
78299 +#include <linux/moduleparam.h>
78300 +#include <linux/skbuff.h>
78301 +#include <linux/netfilter/x_tables.h>
78302 +#include <linux/grsecurity.h>
78303 +#include <linux/netfilter/xt_gradm.h>
78304 +
78305 +static bool
78306 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78307 +{
78308 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78309 + bool retval = false;
78310 + if (gr_acl_is_enabled())
78311 + retval = true;
78312 + return retval ^ info->invflags;
78313 +}
78314 +
78315 +static struct xt_match gradm_mt_reg __read_mostly = {
78316 + .name = "gradm",
78317 + .revision = 0,
78318 + .family = NFPROTO_UNSPEC,
78319 + .match = gradm_mt,
78320 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78321 + .me = THIS_MODULE,
78322 +};
78323 +
78324 +static int __init gradm_mt_init(void)
78325 +{
78326 + return xt_register_match(&gradm_mt_reg);
78327 +}
78328 +
78329 +static void __exit gradm_mt_exit(void)
78330 +{
78331 + xt_unregister_match(&gradm_mt_reg);
78332 +}
78333 +
78334 +module_init(gradm_mt_init);
78335 +module_exit(gradm_mt_exit);
78336 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78337 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78338 +MODULE_LICENSE("GPL");
78339 +MODULE_ALIAS("ipt_gradm");
78340 +MODULE_ALIAS("ip6t_gradm");
78341 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78342 index 4fe4fb4..87a89e5 100644
78343 --- a/net/netfilter/xt_statistic.c
78344 +++ b/net/netfilter/xt_statistic.c
78345 @@ -19,7 +19,7 @@
78346 #include <linux/module.h>
78347
78348 struct xt_statistic_priv {
78349 - atomic_t count;
78350 + atomic_unchecked_t count;
78351 } ____cacheline_aligned_in_smp;
78352
78353 MODULE_LICENSE("GPL");
78354 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78355 break;
78356 case XT_STATISTIC_MODE_NTH:
78357 do {
78358 - oval = atomic_read(&info->master->count);
78359 + oval = atomic_read_unchecked(&info->master->count);
78360 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78361 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78362 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78363 if (nval == 0)
78364 ret = !ret;
78365 break;
78366 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78367 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78368 if (info->master == NULL)
78369 return -ENOMEM;
78370 - atomic_set(&info->master->count, info->u.nth.count);
78371 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78372
78373 return 0;
78374 }
78375 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78376 index 9172179..a4035c4 100644
78377 --- a/net/netlink/af_netlink.c
78378 +++ b/net/netlink/af_netlink.c
78379 @@ -769,7 +769,7 @@ static void netlink_overrun(struct sock *sk)
78380 sk->sk_error_report(sk);
78381 }
78382 }
78383 - atomic_inc(&sk->sk_drops);
78384 + atomic_inc_unchecked(&sk->sk_drops);
78385 }
78386
78387 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78388 @@ -2059,7 +2059,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78389 sk_wmem_alloc_get(s),
78390 nlk->cb,
78391 atomic_read(&s->sk_refcnt),
78392 - atomic_read(&s->sk_drops),
78393 + atomic_read_unchecked(&s->sk_drops),
78394 sock_i_ino(s)
78395 );
78396
78397 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78398 index 7261eb8..44e8ac6 100644
78399 --- a/net/netrom/af_netrom.c
78400 +++ b/net/netrom/af_netrom.c
78401 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78402 struct sock *sk = sock->sk;
78403 struct nr_sock *nr = nr_sk(sk);
78404
78405 + memset(sax, 0, sizeof(*sax));
78406 lock_sock(sk);
78407 if (peer != 0) {
78408 if (sk->sk_state != TCP_ESTABLISHED) {
78409 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78410 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78411 } else {
78412 sax->fsa_ax25.sax25_family = AF_NETROM;
78413 - sax->fsa_ax25.sax25_ndigis = 0;
78414 sax->fsa_ax25.sax25_call = nr->source_addr;
78415 *uaddr_len = sizeof(struct sockaddr_ax25);
78416 }
78417 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78418 index c5c9e2a..4814ab1 100644
78419 --- a/net/packet/af_packet.c
78420 +++ b/net/packet/af_packet.c
78421 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78422
78423 spin_lock(&sk->sk_receive_queue.lock);
78424 po->stats.tp_packets++;
78425 - skb->dropcount = atomic_read(&sk->sk_drops);
78426 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78427 __skb_queue_tail(&sk->sk_receive_queue, skb);
78428 spin_unlock(&sk->sk_receive_queue.lock);
78429 sk->sk_data_ready(sk, skb->len);
78430 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78431 drop_n_acct:
78432 spin_lock(&sk->sk_receive_queue.lock);
78433 po->stats.tp_drops++;
78434 - atomic_inc(&sk->sk_drops);
78435 + atomic_inc_unchecked(&sk->sk_drops);
78436 spin_unlock(&sk->sk_receive_queue.lock);
78437
78438 drop_n_restore:
78439 @@ -2642,6 +2642,7 @@ out:
78440
78441 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78442 {
78443 + struct sock_extended_err ee;
78444 struct sock_exterr_skb *serr;
78445 struct sk_buff *skb, *skb2;
78446 int copied, err;
78447 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78448 sock_recv_timestamp(msg, sk, skb);
78449
78450 serr = SKB_EXT_ERR(skb);
78451 + ee = serr->ee;
78452 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78453 - sizeof(serr->ee), &serr->ee);
78454 + sizeof ee, &ee);
78455
78456 msg->msg_flags |= MSG_ERRQUEUE;
78457 err = copied;
78458 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78459 case PACKET_HDRLEN:
78460 if (len > sizeof(int))
78461 len = sizeof(int);
78462 - if (copy_from_user(&val, optval, len))
78463 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78464 return -EFAULT;
78465 switch (val) {
78466 case TPACKET_V1:
78467 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78468 len = lv;
78469 if (put_user(len, optlen))
78470 return -EFAULT;
78471 - if (copy_to_user(optval, data, len))
78472 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78473 return -EFAULT;
78474 return 0;
78475 }
78476 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78477 index 5a940db..f0b9c12 100644
78478 --- a/net/phonet/af_phonet.c
78479 +++ b/net/phonet/af_phonet.c
78480 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78481 {
78482 struct phonet_protocol *pp;
78483
78484 - if (protocol >= PHONET_NPROTO)
78485 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78486 return NULL;
78487
78488 rcu_read_lock();
78489 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78490 {
78491 int err = 0;
78492
78493 - if (protocol >= PHONET_NPROTO)
78494 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78495 return -EINVAL;
78496
78497 err = proto_register(pp->prot, 1);
78498 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78499 index 576f22c..bc7a71b 100644
78500 --- a/net/phonet/pep.c
78501 +++ b/net/phonet/pep.c
78502 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78503
78504 case PNS_PEP_CTRL_REQ:
78505 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78506 - atomic_inc(&sk->sk_drops);
78507 + atomic_inc_unchecked(&sk->sk_drops);
78508 break;
78509 }
78510 __skb_pull(skb, 4);
78511 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78512 }
78513
78514 if (pn->rx_credits == 0) {
78515 - atomic_inc(&sk->sk_drops);
78516 + atomic_inc_unchecked(&sk->sk_drops);
78517 err = -ENOBUFS;
78518 break;
78519 }
78520 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78521 }
78522
78523 if (pn->rx_credits == 0) {
78524 - atomic_inc(&sk->sk_drops);
78525 + atomic_inc_unchecked(&sk->sk_drops);
78526 err = NET_RX_DROP;
78527 break;
78528 }
78529 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78530 index 0acc943..c727611 100644
78531 --- a/net/phonet/socket.c
78532 +++ b/net/phonet/socket.c
78533 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78534 pn->resource, sk->sk_state,
78535 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78536 sock_i_uid(sk), sock_i_ino(sk),
78537 - atomic_read(&sk->sk_refcnt), sk,
78538 - atomic_read(&sk->sk_drops), &len);
78539 + atomic_read(&sk->sk_refcnt),
78540 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78541 + NULL,
78542 +#else
78543 + sk,
78544 +#endif
78545 + atomic_read_unchecked(&sk->sk_drops), &len);
78546 }
78547 seq_printf(seq, "%*s\n", 127 - len, "");
78548 return 0;
78549 diff --git a/net/rds/cong.c b/net/rds/cong.c
78550 index e5b65ac..f3b6fb7 100644
78551 --- a/net/rds/cong.c
78552 +++ b/net/rds/cong.c
78553 @@ -78,7 +78,7 @@
78554 * finds that the saved generation number is smaller than the global generation
78555 * number, it wakes up the process.
78556 */
78557 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78558 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78559
78560 /*
78561 * Congestion monitoring
78562 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78563 rdsdebug("waking map %p for %pI4\n",
78564 map, &map->m_addr);
78565 rds_stats_inc(s_cong_update_received);
78566 - atomic_inc(&rds_cong_generation);
78567 + atomic_inc_unchecked(&rds_cong_generation);
78568 if (waitqueue_active(&map->m_waitq))
78569 wake_up(&map->m_waitq);
78570 if (waitqueue_active(&rds_poll_waitq))
78571 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78572
78573 int rds_cong_updated_since(unsigned long *recent)
78574 {
78575 - unsigned long gen = atomic_read(&rds_cong_generation);
78576 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78577
78578 if (likely(*recent == gen))
78579 return 0;
78580 diff --git a/net/rds/ib.h b/net/rds/ib.h
78581 index 8d2b3d5..227ec5b 100644
78582 --- a/net/rds/ib.h
78583 +++ b/net/rds/ib.h
78584 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78585 /* sending acks */
78586 unsigned long i_ack_flags;
78587 #ifdef KERNEL_HAS_ATOMIC64
78588 - atomic64_t i_ack_next; /* next ACK to send */
78589 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78590 #else
78591 spinlock_t i_ack_lock; /* protect i_ack_next */
78592 u64 i_ack_next; /* next ACK to send */
78593 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78594 index a1e1162..265e129 100644
78595 --- a/net/rds/ib_cm.c
78596 +++ b/net/rds/ib_cm.c
78597 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78598 /* Clear the ACK state */
78599 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78600 #ifdef KERNEL_HAS_ATOMIC64
78601 - atomic64_set(&ic->i_ack_next, 0);
78602 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78603 #else
78604 ic->i_ack_next = 0;
78605 #endif
78606 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78607 index 8d19491..05a3e65 100644
78608 --- a/net/rds/ib_recv.c
78609 +++ b/net/rds/ib_recv.c
78610 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78611 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78612 int ack_required)
78613 {
78614 - atomic64_set(&ic->i_ack_next, seq);
78615 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78616 if (ack_required) {
78617 smp_mb__before_clear_bit();
78618 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78619 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78620 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78621 smp_mb__after_clear_bit();
78622
78623 - return atomic64_read(&ic->i_ack_next);
78624 + return atomic64_read_unchecked(&ic->i_ack_next);
78625 }
78626 #endif
78627
78628 diff --git a/net/rds/iw.h b/net/rds/iw.h
78629 index 04ce3b1..48119a6 100644
78630 --- a/net/rds/iw.h
78631 +++ b/net/rds/iw.h
78632 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78633 /* sending acks */
78634 unsigned long i_ack_flags;
78635 #ifdef KERNEL_HAS_ATOMIC64
78636 - atomic64_t i_ack_next; /* next ACK to send */
78637 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78638 #else
78639 spinlock_t i_ack_lock; /* protect i_ack_next */
78640 u64 i_ack_next; /* next ACK to send */
78641 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78642 index a91e1db..cf3053f 100644
78643 --- a/net/rds/iw_cm.c
78644 +++ b/net/rds/iw_cm.c
78645 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78646 /* Clear the ACK state */
78647 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78648 #ifdef KERNEL_HAS_ATOMIC64
78649 - atomic64_set(&ic->i_ack_next, 0);
78650 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78651 #else
78652 ic->i_ack_next = 0;
78653 #endif
78654 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78655 index 4503335..db566b4 100644
78656 --- a/net/rds/iw_recv.c
78657 +++ b/net/rds/iw_recv.c
78658 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78659 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78660 int ack_required)
78661 {
78662 - atomic64_set(&ic->i_ack_next, seq);
78663 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78664 if (ack_required) {
78665 smp_mb__before_clear_bit();
78666 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78667 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78668 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78669 smp_mb__after_clear_bit();
78670
78671 - return atomic64_read(&ic->i_ack_next);
78672 + return atomic64_read_unchecked(&ic->i_ack_next);
78673 }
78674 #endif
78675
78676 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78677 index edac9ef..16bcb98 100644
78678 --- a/net/rds/tcp.c
78679 +++ b/net/rds/tcp.c
78680 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78681 int val = 1;
78682
78683 set_fs(KERNEL_DS);
78684 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78685 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78686 sizeof(val));
78687 set_fs(oldfs);
78688 }
78689 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78690 index 1b4fd68..2234175 100644
78691 --- a/net/rds/tcp_send.c
78692 +++ b/net/rds/tcp_send.c
78693 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78694
78695 oldfs = get_fs();
78696 set_fs(KERNEL_DS);
78697 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78698 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78699 sizeof(val));
78700 set_fs(oldfs);
78701 }
78702 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78703 index 05996d0..5a1dfe0 100644
78704 --- a/net/rxrpc/af_rxrpc.c
78705 +++ b/net/rxrpc/af_rxrpc.c
78706 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78707 __be32 rxrpc_epoch;
78708
78709 /* current debugging ID */
78710 -atomic_t rxrpc_debug_id;
78711 +atomic_unchecked_t rxrpc_debug_id;
78712
78713 /* count of skbs currently in use */
78714 atomic_t rxrpc_n_skbs;
78715 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78716 index e4d9cbc..b229649 100644
78717 --- a/net/rxrpc/ar-ack.c
78718 +++ b/net/rxrpc/ar-ack.c
78719 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78720
78721 _enter("{%d,%d,%d,%d},",
78722 call->acks_hard, call->acks_unacked,
78723 - atomic_read(&call->sequence),
78724 + atomic_read_unchecked(&call->sequence),
78725 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78726
78727 stop = 0;
78728 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78729
78730 /* each Tx packet has a new serial number */
78731 sp->hdr.serial =
78732 - htonl(atomic_inc_return(&call->conn->serial));
78733 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78734
78735 hdr = (struct rxrpc_header *) txb->head;
78736 hdr->serial = sp->hdr.serial;
78737 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78738 */
78739 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78740 {
78741 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78742 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78743 }
78744
78745 /*
78746 @@ -629,7 +629,7 @@ process_further:
78747
78748 latest = ntohl(sp->hdr.serial);
78749 hard = ntohl(ack.firstPacket);
78750 - tx = atomic_read(&call->sequence);
78751 + tx = atomic_read_unchecked(&call->sequence);
78752
78753 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78754 latest,
78755 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78756 goto maybe_reschedule;
78757
78758 send_ACK_with_skew:
78759 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78760 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78761 ntohl(ack.serial));
78762 send_ACK:
78763 mtu = call->conn->trans->peer->if_mtu;
78764 @@ -1173,7 +1173,7 @@ send_ACK:
78765 ackinfo.rxMTU = htonl(5692);
78766 ackinfo.jumbo_max = htonl(4);
78767
78768 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78769 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78770 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78771 ntohl(hdr.serial),
78772 ntohs(ack.maxSkew),
78773 @@ -1191,7 +1191,7 @@ send_ACK:
78774 send_message:
78775 _debug("send message");
78776
78777 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78778 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78779 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78780 send_message_2:
78781
78782 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78783 index a3bbb36..3341fb9 100644
78784 --- a/net/rxrpc/ar-call.c
78785 +++ b/net/rxrpc/ar-call.c
78786 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78787 spin_lock_init(&call->lock);
78788 rwlock_init(&call->state_lock);
78789 atomic_set(&call->usage, 1);
78790 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78791 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78792 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78793
78794 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78795 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78796 index 4106ca9..a338d7a 100644
78797 --- a/net/rxrpc/ar-connection.c
78798 +++ b/net/rxrpc/ar-connection.c
78799 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78800 rwlock_init(&conn->lock);
78801 spin_lock_init(&conn->state_lock);
78802 atomic_set(&conn->usage, 1);
78803 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78804 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78805 conn->avail_calls = RXRPC_MAXCALLS;
78806 conn->size_align = 4;
78807 conn->header_size = sizeof(struct rxrpc_header);
78808 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78809 index e7ed43a..6afa140 100644
78810 --- a/net/rxrpc/ar-connevent.c
78811 +++ b/net/rxrpc/ar-connevent.c
78812 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78813
78814 len = iov[0].iov_len + iov[1].iov_len;
78815
78816 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78817 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78818 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78819
78820 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78821 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78822 index 529572f..c758ca7 100644
78823 --- a/net/rxrpc/ar-input.c
78824 +++ b/net/rxrpc/ar-input.c
78825 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78826 /* track the latest serial number on this connection for ACK packet
78827 * information */
78828 serial = ntohl(sp->hdr.serial);
78829 - hi_serial = atomic_read(&call->conn->hi_serial);
78830 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78831 while (serial > hi_serial)
78832 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78833 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78834 serial);
78835
78836 /* request ACK generation for any ACK or DATA packet that requests
78837 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78838 index a693aca..81e7293 100644
78839 --- a/net/rxrpc/ar-internal.h
78840 +++ b/net/rxrpc/ar-internal.h
78841 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78842 int error; /* error code for local abort */
78843 int debug_id; /* debug ID for printks */
78844 unsigned int call_counter; /* call ID counter */
78845 - atomic_t serial; /* packet serial number counter */
78846 - atomic_t hi_serial; /* highest serial number received */
78847 + atomic_unchecked_t serial; /* packet serial number counter */
78848 + atomic_unchecked_t hi_serial; /* highest serial number received */
78849 u8 avail_calls; /* number of calls available */
78850 u8 size_align; /* data size alignment (for security) */
78851 u8 header_size; /* rxrpc + security header size */
78852 @@ -346,7 +346,7 @@ struct rxrpc_call {
78853 spinlock_t lock;
78854 rwlock_t state_lock; /* lock for state transition */
78855 atomic_t usage;
78856 - atomic_t sequence; /* Tx data packet sequence counter */
78857 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78858 u32 abort_code; /* local/remote abort code */
78859 enum { /* current state of call */
78860 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78861 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78862 */
78863 extern atomic_t rxrpc_n_skbs;
78864 extern __be32 rxrpc_epoch;
78865 -extern atomic_t rxrpc_debug_id;
78866 +extern atomic_unchecked_t rxrpc_debug_id;
78867 extern struct workqueue_struct *rxrpc_workqueue;
78868
78869 /*
78870 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78871 index 87f7135..74d3703 100644
78872 --- a/net/rxrpc/ar-local.c
78873 +++ b/net/rxrpc/ar-local.c
78874 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78875 spin_lock_init(&local->lock);
78876 rwlock_init(&local->services_lock);
78877 atomic_set(&local->usage, 1);
78878 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78879 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78880 memcpy(&local->srx, srx, sizeof(*srx));
78881 }
78882
78883 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78884 index e1ac183..b43e10e 100644
78885 --- a/net/rxrpc/ar-output.c
78886 +++ b/net/rxrpc/ar-output.c
78887 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78888 sp->hdr.cid = call->cid;
78889 sp->hdr.callNumber = call->call_id;
78890 sp->hdr.seq =
78891 - htonl(atomic_inc_return(&call->sequence));
78892 + htonl(atomic_inc_return_unchecked(&call->sequence));
78893 sp->hdr.serial =
78894 - htonl(atomic_inc_return(&conn->serial));
78895 + htonl(atomic_inc_return_unchecked(&conn->serial));
78896 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78897 sp->hdr.userStatus = 0;
78898 sp->hdr.securityIndex = conn->security_ix;
78899 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78900 index bebaa43..2644591 100644
78901 --- a/net/rxrpc/ar-peer.c
78902 +++ b/net/rxrpc/ar-peer.c
78903 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78904 INIT_LIST_HEAD(&peer->error_targets);
78905 spin_lock_init(&peer->lock);
78906 atomic_set(&peer->usage, 1);
78907 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78908 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78909 memcpy(&peer->srx, srx, sizeof(*srx));
78910
78911 rxrpc_assess_MTU_size(peer);
78912 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78913 index 38047f7..9f48511 100644
78914 --- a/net/rxrpc/ar-proc.c
78915 +++ b/net/rxrpc/ar-proc.c
78916 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78917 atomic_read(&conn->usage),
78918 rxrpc_conn_states[conn->state],
78919 key_serial(conn->key),
78920 - atomic_read(&conn->serial),
78921 - atomic_read(&conn->hi_serial));
78922 + atomic_read_unchecked(&conn->serial),
78923 + atomic_read_unchecked(&conn->hi_serial));
78924
78925 return 0;
78926 }
78927 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78928 index 92df566..87ec1bf 100644
78929 --- a/net/rxrpc/ar-transport.c
78930 +++ b/net/rxrpc/ar-transport.c
78931 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78932 spin_lock_init(&trans->client_lock);
78933 rwlock_init(&trans->conn_lock);
78934 atomic_set(&trans->usage, 1);
78935 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78936 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78937
78938 if (peer->srx.transport.family == AF_INET) {
78939 switch (peer->srx.transport_type) {
78940 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78941 index f226709..0e735a8 100644
78942 --- a/net/rxrpc/rxkad.c
78943 +++ b/net/rxrpc/rxkad.c
78944 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78945
78946 len = iov[0].iov_len + iov[1].iov_len;
78947
78948 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78949 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78950 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78951
78952 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78953 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78954
78955 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78956
78957 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78958 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78959 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78960
78961 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78962 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78963 index 1e2eee8..ce3967e 100644
78964 --- a/net/sctp/proc.c
78965 +++ b/net/sctp/proc.c
78966 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78967 seq_printf(seq,
78968 "%8pK %8pK %-3d %-3d %-2d %-4d "
78969 "%4d %8d %8d %7d %5lu %-5d %5d ",
78970 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78971 + assoc, sk,
78972 + sctp_sk(sk)->type, sk->sk_state,
78973 assoc->state, hash,
78974 assoc->assoc_id,
78975 assoc->sndbuf_used,
78976 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78977 index 5e25981..dbda919 100644
78978 --- a/net/sctp/socket.c
78979 +++ b/net/sctp/socket.c
78980 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
78981 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
78982 if (space_left < addrlen)
78983 return -ENOMEM;
78984 + if (addrlen > sizeof(temp) || addrlen < 0)
78985 + return -EFAULT;
78986 if (copy_to_user(to, &temp, addrlen))
78987 return -EFAULT;
78988 to += addrlen;
78989 diff --git a/net/socket.c b/net/socket.c
78990 index edc3c4a..4b4e4a8 100644
78991 --- a/net/socket.c
78992 +++ b/net/socket.c
78993 @@ -88,6 +88,7 @@
78994 #include <linux/nsproxy.h>
78995 #include <linux/magic.h>
78996 #include <linux/slab.h>
78997 +#include <linux/in.h>
78998
78999 #include <asm/uaccess.h>
79000 #include <asm/unistd.h>
79001 @@ -105,6 +106,8 @@
79002 #include <linux/sockios.h>
79003 #include <linux/atalk.h>
79004
79005 +#include <linux/grsock.h>
79006 +
79007 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79008 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79009 unsigned long nr_segs, loff_t pos);
79010 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79011 &sockfs_dentry_operations, SOCKFS_MAGIC);
79012 }
79013
79014 -static struct vfsmount *sock_mnt __read_mostly;
79015 +struct vfsmount *sock_mnt __read_mostly;
79016
79017 static struct file_system_type sock_fs_type = {
79018 .name = "sockfs",
79019 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79020 return -EAFNOSUPPORT;
79021 if (type < 0 || type >= SOCK_MAX)
79022 return -EINVAL;
79023 + if (protocol < 0)
79024 + return -EINVAL;
79025
79026 /* Compatibility.
79027
79028 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79029 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79030 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79031
79032 + if(!gr_search_socket(family, type, protocol)) {
79033 + retval = -EACCES;
79034 + goto out;
79035 + }
79036 +
79037 + if (gr_handle_sock_all(family, type, protocol)) {
79038 + retval = -EACCES;
79039 + goto out;
79040 + }
79041 +
79042 retval = sock_create(family, type, protocol, &sock);
79043 if (retval < 0)
79044 goto out;
79045 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79046 if (sock) {
79047 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79048 if (err >= 0) {
79049 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79050 + err = -EACCES;
79051 + goto error;
79052 + }
79053 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79054 + if (err)
79055 + goto error;
79056 +
79057 err = security_socket_bind(sock,
79058 (struct sockaddr *)&address,
79059 addrlen);
79060 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79061 (struct sockaddr *)
79062 &address, addrlen);
79063 }
79064 +error:
79065 fput_light(sock->file, fput_needed);
79066 }
79067 return err;
79068 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79069 if ((unsigned int)backlog > somaxconn)
79070 backlog = somaxconn;
79071
79072 + if (gr_handle_sock_server_other(sock->sk)) {
79073 + err = -EPERM;
79074 + goto error;
79075 + }
79076 +
79077 + err = gr_search_listen(sock);
79078 + if (err)
79079 + goto error;
79080 +
79081 err = security_socket_listen(sock, backlog);
79082 if (!err)
79083 err = sock->ops->listen(sock, backlog);
79084
79085 +error:
79086 fput_light(sock->file, fput_needed);
79087 }
79088 return err;
79089 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79090 newsock->type = sock->type;
79091 newsock->ops = sock->ops;
79092
79093 + if (gr_handle_sock_server_other(sock->sk)) {
79094 + err = -EPERM;
79095 + sock_release(newsock);
79096 + goto out_put;
79097 + }
79098 +
79099 + err = gr_search_accept(sock);
79100 + if (err) {
79101 + sock_release(newsock);
79102 + goto out_put;
79103 + }
79104 +
79105 /*
79106 * We don't need try_module_get here, as the listening socket (sock)
79107 * has the protocol module (sock->ops->owner) held.
79108 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79109 fd_install(newfd, newfile);
79110 err = newfd;
79111
79112 + gr_attach_curr_ip(newsock->sk);
79113 +
79114 out_put:
79115 fput_light(sock->file, fput_needed);
79116 out:
79117 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79118 int, addrlen)
79119 {
79120 struct socket *sock;
79121 + struct sockaddr *sck;
79122 struct sockaddr_storage address;
79123 int err, fput_needed;
79124
79125 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79126 if (err < 0)
79127 goto out_put;
79128
79129 + sck = (struct sockaddr *)&address;
79130 +
79131 + if (gr_handle_sock_client(sck)) {
79132 + err = -EACCES;
79133 + goto out_put;
79134 + }
79135 +
79136 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79137 + if (err)
79138 + goto out_put;
79139 +
79140 err =
79141 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79142 if (err)
79143 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79144 * checking falls down on this.
79145 */
79146 if (copy_from_user(ctl_buf,
79147 - (void __user __force *)msg_sys->msg_control,
79148 + (void __force_user *)msg_sys->msg_control,
79149 ctl_len))
79150 goto out_freectl;
79151 msg_sys->msg_control = ctl_buf;
79152 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79153 * kernel msghdr to use the kernel address space)
79154 */
79155
79156 - uaddr = (__force void __user *)msg_sys->msg_name;
79157 + uaddr = (void __force_user *)msg_sys->msg_name;
79158 uaddr_len = COMPAT_NAMELEN(msg);
79159 if (MSG_CMSG_COMPAT & flags) {
79160 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79161 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79162 }
79163
79164 ifr = compat_alloc_user_space(buf_size);
79165 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79166 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79167
79168 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79169 return -EFAULT;
79170 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79171 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79172
79173 if (copy_in_user(rxnfc, compat_rxnfc,
79174 - (void *)(&rxnfc->fs.m_ext + 1) -
79175 - (void *)rxnfc) ||
79176 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79177 + (void __user *)rxnfc) ||
79178 copy_in_user(&rxnfc->fs.ring_cookie,
79179 &compat_rxnfc->fs.ring_cookie,
79180 - (void *)(&rxnfc->fs.location + 1) -
79181 - (void *)&rxnfc->fs.ring_cookie) ||
79182 + (void __user *)(&rxnfc->fs.location + 1) -
79183 + (void __user *)&rxnfc->fs.ring_cookie) ||
79184 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79185 sizeof(rxnfc->rule_cnt)))
79186 return -EFAULT;
79187 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79188
79189 if (convert_out) {
79190 if (copy_in_user(compat_rxnfc, rxnfc,
79191 - (const void *)(&rxnfc->fs.m_ext + 1) -
79192 - (const void *)rxnfc) ||
79193 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79194 + (const void __user *)rxnfc) ||
79195 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79196 &rxnfc->fs.ring_cookie,
79197 - (const void *)(&rxnfc->fs.location + 1) -
79198 - (const void *)&rxnfc->fs.ring_cookie) ||
79199 + (const void __user *)(&rxnfc->fs.location + 1) -
79200 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79201 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79202 sizeof(rxnfc->rule_cnt)))
79203 return -EFAULT;
79204 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79205 old_fs = get_fs();
79206 set_fs(KERNEL_DS);
79207 err = dev_ioctl(net, cmd,
79208 - (struct ifreq __user __force *) &kifr);
79209 + (struct ifreq __force_user *) &kifr);
79210 set_fs(old_fs);
79211
79212 return err;
79213 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79214
79215 old_fs = get_fs();
79216 set_fs(KERNEL_DS);
79217 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79218 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79219 set_fs(old_fs);
79220
79221 if (cmd == SIOCGIFMAP && !err) {
79222 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79223 ret |= __get_user(rtdev, &(ur4->rt_dev));
79224 if (rtdev) {
79225 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79226 - r4.rt_dev = (char __user __force *)devname;
79227 + r4.rt_dev = (char __force_user *)devname;
79228 devname[15] = 0;
79229 } else
79230 r4.rt_dev = NULL;
79231 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79232 int __user *uoptlen;
79233 int err;
79234
79235 - uoptval = (char __user __force *) optval;
79236 - uoptlen = (int __user __force *) optlen;
79237 + uoptval = (char __force_user *) optval;
79238 + uoptlen = (int __force_user *) optlen;
79239
79240 set_fs(KERNEL_DS);
79241 if (level == SOL_SOCKET)
79242 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79243 char __user *uoptval;
79244 int err;
79245
79246 - uoptval = (char __user __force *) optval;
79247 + uoptval = (char __force_user *) optval;
79248
79249 set_fs(KERNEL_DS);
79250 if (level == SOL_SOCKET)
79251 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79252 index 128494e..775d0e0 100644
79253 --- a/net/sunrpc/sched.c
79254 +++ b/net/sunrpc/sched.c
79255 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79256 #ifdef RPC_DEBUG
79257 static void rpc_task_set_debuginfo(struct rpc_task *task)
79258 {
79259 - static atomic_t rpc_pid;
79260 + static atomic_unchecked_t rpc_pid;
79261
79262 - task->tk_pid = atomic_inc_return(&rpc_pid);
79263 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79264 }
79265 #else
79266 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79267 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79268 index 8343737..677025e 100644
79269 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79270 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79271 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79272 static unsigned int min_max_inline = 4096;
79273 static unsigned int max_max_inline = 65536;
79274
79275 -atomic_t rdma_stat_recv;
79276 -atomic_t rdma_stat_read;
79277 -atomic_t rdma_stat_write;
79278 -atomic_t rdma_stat_sq_starve;
79279 -atomic_t rdma_stat_rq_starve;
79280 -atomic_t rdma_stat_rq_poll;
79281 -atomic_t rdma_stat_rq_prod;
79282 -atomic_t rdma_stat_sq_poll;
79283 -atomic_t rdma_stat_sq_prod;
79284 +atomic_unchecked_t rdma_stat_recv;
79285 +atomic_unchecked_t rdma_stat_read;
79286 +atomic_unchecked_t rdma_stat_write;
79287 +atomic_unchecked_t rdma_stat_sq_starve;
79288 +atomic_unchecked_t rdma_stat_rq_starve;
79289 +atomic_unchecked_t rdma_stat_rq_poll;
79290 +atomic_unchecked_t rdma_stat_rq_prod;
79291 +atomic_unchecked_t rdma_stat_sq_poll;
79292 +atomic_unchecked_t rdma_stat_sq_prod;
79293
79294 /* Temporary NFS request map and context caches */
79295 struct kmem_cache *svc_rdma_map_cachep;
79296 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79297 len -= *ppos;
79298 if (len > *lenp)
79299 len = *lenp;
79300 - if (len && copy_to_user(buffer, str_buf, len))
79301 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79302 return -EFAULT;
79303 *lenp = len;
79304 *ppos += len;
79305 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79306 {
79307 .procname = "rdma_stat_read",
79308 .data = &rdma_stat_read,
79309 - .maxlen = sizeof(atomic_t),
79310 + .maxlen = sizeof(atomic_unchecked_t),
79311 .mode = 0644,
79312 .proc_handler = read_reset_stat,
79313 },
79314 {
79315 .procname = "rdma_stat_recv",
79316 .data = &rdma_stat_recv,
79317 - .maxlen = sizeof(atomic_t),
79318 + .maxlen = sizeof(atomic_unchecked_t),
79319 .mode = 0644,
79320 .proc_handler = read_reset_stat,
79321 },
79322 {
79323 .procname = "rdma_stat_write",
79324 .data = &rdma_stat_write,
79325 - .maxlen = sizeof(atomic_t),
79326 + .maxlen = sizeof(atomic_unchecked_t),
79327 .mode = 0644,
79328 .proc_handler = read_reset_stat,
79329 },
79330 {
79331 .procname = "rdma_stat_sq_starve",
79332 .data = &rdma_stat_sq_starve,
79333 - .maxlen = sizeof(atomic_t),
79334 + .maxlen = sizeof(atomic_unchecked_t),
79335 .mode = 0644,
79336 .proc_handler = read_reset_stat,
79337 },
79338 {
79339 .procname = "rdma_stat_rq_starve",
79340 .data = &rdma_stat_rq_starve,
79341 - .maxlen = sizeof(atomic_t),
79342 + .maxlen = sizeof(atomic_unchecked_t),
79343 .mode = 0644,
79344 .proc_handler = read_reset_stat,
79345 },
79346 {
79347 .procname = "rdma_stat_rq_poll",
79348 .data = &rdma_stat_rq_poll,
79349 - .maxlen = sizeof(atomic_t),
79350 + .maxlen = sizeof(atomic_unchecked_t),
79351 .mode = 0644,
79352 .proc_handler = read_reset_stat,
79353 },
79354 {
79355 .procname = "rdma_stat_rq_prod",
79356 .data = &rdma_stat_rq_prod,
79357 - .maxlen = sizeof(atomic_t),
79358 + .maxlen = sizeof(atomic_unchecked_t),
79359 .mode = 0644,
79360 .proc_handler = read_reset_stat,
79361 },
79362 {
79363 .procname = "rdma_stat_sq_poll",
79364 .data = &rdma_stat_sq_poll,
79365 - .maxlen = sizeof(atomic_t),
79366 + .maxlen = sizeof(atomic_unchecked_t),
79367 .mode = 0644,
79368 .proc_handler = read_reset_stat,
79369 },
79370 {
79371 .procname = "rdma_stat_sq_prod",
79372 .data = &rdma_stat_sq_prod,
79373 - .maxlen = sizeof(atomic_t),
79374 + .maxlen = sizeof(atomic_unchecked_t),
79375 .mode = 0644,
79376 .proc_handler = read_reset_stat,
79377 },
79378 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79379 index 41cb63b..c4a1489 100644
79380 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79381 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79382 @@ -501,7 +501,7 @@ next_sge:
79383 svc_rdma_put_context(ctxt, 0);
79384 goto out;
79385 }
79386 - atomic_inc(&rdma_stat_read);
79387 + atomic_inc_unchecked(&rdma_stat_read);
79388
79389 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79390 chl_map->ch[ch_no].count -= read_wr.num_sge;
79391 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79392 dto_q);
79393 list_del_init(&ctxt->dto_q);
79394 } else {
79395 - atomic_inc(&rdma_stat_rq_starve);
79396 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79397 clear_bit(XPT_DATA, &xprt->xpt_flags);
79398 ctxt = NULL;
79399 }
79400 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79401 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79402 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79403 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79404 - atomic_inc(&rdma_stat_recv);
79405 + atomic_inc_unchecked(&rdma_stat_recv);
79406
79407 /* Build up the XDR from the receive buffers. */
79408 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79409 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79410 index 42eb7ba..c887c45 100644
79411 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79412 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79413 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79414 write_wr.wr.rdma.remote_addr = to;
79415
79416 /* Post It */
79417 - atomic_inc(&rdma_stat_write);
79418 + atomic_inc_unchecked(&rdma_stat_write);
79419 if (svc_rdma_send(xprt, &write_wr))
79420 goto err;
79421 return 0;
79422 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79423 index 73b428b..5f3f8f3 100644
79424 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79425 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79426 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79427 return;
79428
79429 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79430 - atomic_inc(&rdma_stat_rq_poll);
79431 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79432
79433 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79434 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79435 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79436 }
79437
79438 if (ctxt)
79439 - atomic_inc(&rdma_stat_rq_prod);
79440 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79441
79442 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79443 /*
79444 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79445 return;
79446
79447 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79448 - atomic_inc(&rdma_stat_sq_poll);
79449 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79450 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79451 if (wc.status != IB_WC_SUCCESS)
79452 /* Close the transport */
79453 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79454 }
79455
79456 if (ctxt)
79457 - atomic_inc(&rdma_stat_sq_prod);
79458 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79459 }
79460
79461 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79462 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79463 spin_lock_bh(&xprt->sc_lock);
79464 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79465 spin_unlock_bh(&xprt->sc_lock);
79466 - atomic_inc(&rdma_stat_sq_starve);
79467 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79468
79469 /* See if we can opportunistically reap SQ WR to make room */
79470 sq_cq_reap(xprt);
79471 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79472 index e3a6e37..be2ea77 100644
79473 --- a/net/sysctl_net.c
79474 +++ b/net/sysctl_net.c
79475 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79476 struct ctl_table *table)
79477 {
79478 /* Allow network administrator to have same access as root. */
79479 - if (capable(CAP_NET_ADMIN)) {
79480 + if (capable_nolog(CAP_NET_ADMIN)) {
79481 int mode = (table->mode >> 6) & 7;
79482 return (mode << 6) | (mode << 3) | mode;
79483 }
79484 diff --git a/net/tipc/link.c b/net/tipc/link.c
79485 index 1c1e615..113e0ae 100644
79486 --- a/net/tipc/link.c
79487 +++ b/net/tipc/link.c
79488 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79489 struct tipc_msg fragm_hdr;
79490 struct sk_buff *buf, *buf_chain, *prev;
79491 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79492 - const unchar *sect_crs;
79493 + const unchar __user *sect_crs;
79494 int curr_sect;
79495 u32 fragm_no;
79496
79497 @@ -1212,7 +1212,7 @@ again:
79498
79499 if (!sect_rest) {
79500 sect_rest = msg_sect[++curr_sect].iov_len;
79501 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79502 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79503 }
79504
79505 if (sect_rest < fragm_rest)
79506 @@ -1231,7 +1231,7 @@ error:
79507 }
79508 } else
79509 skb_copy_to_linear_data_offset(buf, fragm_crs,
79510 - sect_crs, sz);
79511 + (const void __force_kernel *)sect_crs, sz);
79512 sect_crs += sz;
79513 sect_rest -= sz;
79514 fragm_crs += sz;
79515 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79516 index f2db8a8..9245aa4 100644
79517 --- a/net/tipc/msg.c
79518 +++ b/net/tipc/msg.c
79519 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79520 msg_sect[cnt].iov_len);
79521 else
79522 skb_copy_to_linear_data_offset(*buf, pos,
79523 - msg_sect[cnt].iov_base,
79524 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79525 msg_sect[cnt].iov_len);
79526 pos += msg_sect[cnt].iov_len;
79527 }
79528 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79529 index 5ed5965..90abe34 100644
79530 --- a/net/tipc/subscr.c
79531 +++ b/net/tipc/subscr.c
79532 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79533 {
79534 struct iovec msg_sect;
79535
79536 - msg_sect.iov_base = (void *)&sub->evt;
79537 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79538 msg_sect.iov_len = sizeof(struct tipc_event);
79539
79540 sub->evt.event = htohl(event, sub->swap);
79541 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79542 index c5ee4ff..e905948 100644
79543 --- a/net/unix/af_unix.c
79544 +++ b/net/unix/af_unix.c
79545 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79546 err = -ECONNREFUSED;
79547 if (!S_ISSOCK(inode->i_mode))
79548 goto put_fail;
79549 +
79550 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79551 + err = -EACCES;
79552 + goto put_fail;
79553 + }
79554 +
79555 u = unix_find_socket_byinode(inode);
79556 if (!u)
79557 goto put_fail;
79558 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79559 if (u) {
79560 struct dentry *dentry;
79561 dentry = unix_sk(u)->path.dentry;
79562 +
79563 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79564 + err = -EPERM;
79565 + sock_put(u);
79566 + goto fail;
79567 + }
79568 +
79569 if (dentry)
79570 touch_atime(&unix_sk(u)->path);
79571 } else
79572 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79573 */
79574 err = security_path_mknod(&path, dentry, mode, 0);
79575 if (!err) {
79576 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79577 + err = -EACCES;
79578 + goto out;
79579 + }
79580 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79581 if (!err) {
79582 res->mnt = mntget(path.mnt);
79583 res->dentry = dget(dentry);
79584 + gr_handle_create(dentry, path.mnt);
79585 }
79586 }
79587 +out:
79588 done_path_create(&path, dentry);
79589 return err;
79590 }
79591 diff --git a/net/wireless/core.h b/net/wireless/core.h
79592 index bc7430b..35349de 100644
79593 --- a/net/wireless/core.h
79594 +++ b/net/wireless/core.h
79595 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79596 struct mutex mtx;
79597
79598 /* rfkill support */
79599 - struct rfkill_ops rfkill_ops;
79600 + rfkill_ops_no_const rfkill_ops;
79601 struct rfkill *rfkill;
79602 struct work_struct rfkill_sync;
79603
79604 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79605 index b0eb7aa..7d73e82 100644
79606 --- a/net/wireless/wext-core.c
79607 +++ b/net/wireless/wext-core.c
79608 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79609 */
79610
79611 /* Support for very large requests */
79612 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79613 - (user_length > descr->max_tokens)) {
79614 + if (user_length > descr->max_tokens) {
79615 /* Allow userspace to GET more than max so
79616 * we can support any size GET requests.
79617 * There is still a limit : -ENOMEM.
79618 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79619 }
79620 }
79621
79622 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79623 - /*
79624 - * If this is a GET, but not NOMAX, it means that the extra
79625 - * data is not bounded by userspace, but by max_tokens. Thus
79626 - * set the length to max_tokens. This matches the extra data
79627 - * allocation.
79628 - * The driver should fill it with the number of tokens it
79629 - * provided, and it may check iwp->length rather than having
79630 - * knowledge of max_tokens. If the driver doesn't change the
79631 - * iwp->length, this ioctl just copies back max_token tokens
79632 - * filled with zeroes. Hopefully the driver isn't claiming
79633 - * them to be valid data.
79634 - */
79635 - iwp->length = descr->max_tokens;
79636 - }
79637 -
79638 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79639
79640 iwp->length += essid_compat;
79641 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79642 index 387848e..a6667a2 100644
79643 --- a/net/xfrm/xfrm_policy.c
79644 +++ b/net/xfrm/xfrm_policy.c
79645 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79646 {
79647 policy->walk.dead = 1;
79648
79649 - atomic_inc(&policy->genid);
79650 + atomic_inc_unchecked(&policy->genid);
79651
79652 if (del_timer(&policy->timer))
79653 xfrm_pol_put(policy);
79654 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79655 hlist_add_head(&policy->bydst, chain);
79656 xfrm_pol_hold(policy);
79657 net->xfrm.policy_count[dir]++;
79658 - atomic_inc(&flow_cache_genid);
79659 + atomic_inc_unchecked(&flow_cache_genid);
79660 rt_genid_bump(net);
79661 if (delpol)
79662 __xfrm_policy_unlink(delpol, dir);
79663 @@ -1533,7 +1533,7 @@ free_dst:
79664 goto out;
79665 }
79666
79667 -static int inline
79668 +static inline int
79669 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79670 {
79671 if (!*target) {
79672 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79673 return 0;
79674 }
79675
79676 -static int inline
79677 +static inline int
79678 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79679 {
79680 #ifdef CONFIG_XFRM_SUB_POLICY
79681 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79682 #endif
79683 }
79684
79685 -static int inline
79686 +static inline int
79687 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79688 {
79689 #ifdef CONFIG_XFRM_SUB_POLICY
79690 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79691
79692 xdst->num_pols = num_pols;
79693 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79694 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79695 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79696
79697 return xdst;
79698 }
79699 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79700 if (xdst->xfrm_genid != dst->xfrm->genid)
79701 return 0;
79702 if (xdst->num_pols > 0 &&
79703 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79704 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79705 return 0;
79706
79707 mtu = dst_mtu(dst->child);
79708 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79709 sizeof(pol->xfrm_vec[i].saddr));
79710 pol->xfrm_vec[i].encap_family = mp->new_family;
79711 /* flush bundles */
79712 - atomic_inc(&pol->genid);
79713 + atomic_inc_unchecked(&pol->genid);
79714 }
79715 }
79716
79717 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79718 index ff1720d..ed8475e 100644
79719 --- a/scripts/Makefile.build
79720 +++ b/scripts/Makefile.build
79721 @@ -111,7 +111,7 @@ endif
79722 endif
79723
79724 # Do not include host rules unless needed
79725 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79726 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
79727 include scripts/Makefile.host
79728 endif
79729
79730 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79731 index 686cb0d..9d653bf 100644
79732 --- a/scripts/Makefile.clean
79733 +++ b/scripts/Makefile.clean
79734 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79735 __clean-files := $(extra-y) $(always) \
79736 $(targets) $(clean-files) \
79737 $(host-progs) \
79738 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79739 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79740 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79741
79742 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79743
79744 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79745 index 1ac414f..38575f7 100644
79746 --- a/scripts/Makefile.host
79747 +++ b/scripts/Makefile.host
79748 @@ -31,6 +31,8 @@
79749 # Note: Shared libraries consisting of C++ files are not supported
79750
79751 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79752 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79753 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
79754
79755 # C code
79756 # Executables compiled from a single .c file
79757 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79758 # Shared libaries (only .c supported)
79759 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79760 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79761 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79762 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
79763 # Remove .so files from "xxx-objs"
79764 host-cobjs := $(filter-out %.so,$(host-cobjs))
79765 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
79766
79767 -#Object (.o) files used by the shared libaries
79768 +# Object (.o) files used by the shared libaries
79769 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
79770 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
79771
79772 # output directory for programs/.o files
79773 # hostprogs-y := tools/build may have been specified. Retrieve directory
79774 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
79775 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
79776 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
79777 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
79778 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
79779 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
79780 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
79781 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
79782
79783 obj-dirs += $(host-objdirs)
79784 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
79785 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
79786 $(call if_changed_dep,host-cshobjs)
79787
79788 +# Compile .c file, create position independent .o file
79789 +# host-cxxshobjs -> .o
79790 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
79791 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
79792 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
79793 + $(call if_changed_dep,host-cxxshobjs)
79794 +
79795 # Link a shared library, based on position independent .o files
79796 # *.o -> .so shared library (host-cshlib)
79797 quiet_cmd_host-cshlib = HOSTLLD -shared $@
79798 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
79799 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
79800 $(call if_changed,host-cshlib)
79801
79802 +# Link a shared library, based on position independent .o files
79803 +# *.o -> .so shared library (host-cxxshlib)
79804 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
79805 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
79806 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
79807 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
79808 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
79809 + $(call if_changed,host-cxxshlib)
79810 +
79811 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
79812 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
79813 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
79814
79815 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79816 index cb1f50c..cef2a7c 100644
79817 --- a/scripts/basic/fixdep.c
79818 +++ b/scripts/basic/fixdep.c
79819 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79820 /*
79821 * Lookup a value in the configuration string.
79822 */
79823 -static int is_defined_config(const char *name, int len, unsigned int hash)
79824 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79825 {
79826 struct item *aux;
79827
79828 @@ -211,10 +211,10 @@ static void clear_config(void)
79829 /*
79830 * Record the use of a CONFIG_* word.
79831 */
79832 -static void use_config(const char *m, int slen)
79833 +static void use_config(const char *m, unsigned int slen)
79834 {
79835 unsigned int hash = strhash(m, slen);
79836 - int c, i;
79837 + unsigned int c, i;
79838
79839 if (is_defined_config(m, slen, hash))
79840 return;
79841 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79842
79843 static void parse_config_file(const char *map, size_t len)
79844 {
79845 - const int *end = (const int *) (map + len);
79846 + const unsigned int *end = (const unsigned int *) (map + len);
79847 /* start at +1, so that p can never be < map */
79848 - const int *m = (const int *) map + 1;
79849 + const unsigned int *m = (const unsigned int *) map + 1;
79850 const char *p, *q;
79851
79852 for (; m < end; m++) {
79853 @@ -406,7 +406,7 @@ static void print_deps(void)
79854 static void traps(void)
79855 {
79856 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79857 - int *p = (int *)test;
79858 + unsigned int *p = (unsigned int *)test;
79859
79860 if (*p != INT_CONF) {
79861 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79862 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79863 new file mode 100644
79864 index 0000000..008ac1a
79865 --- /dev/null
79866 +++ b/scripts/gcc-plugin.sh
79867 @@ -0,0 +1,17 @@
79868 +#!/bin/bash
79869 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
79870 +#include "gcc-plugin.h"
79871 +#include "tree.h"
79872 +#include "tm.h"
79873 +#include "rtl.h"
79874 +#ifdef ENABLE_BUILD_WITH_CXX
79875 +#warning $2
79876 +#else
79877 +#warning $1
79878 +#endif
79879 +EOF`
79880 +if [ $? -eq 0 ]
79881 +then
79882 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
79883 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
79884 +fi
79885 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
79886 index b3d907e..a4782ab 100644
79887 --- a/scripts/link-vmlinux.sh
79888 +++ b/scripts/link-vmlinux.sh
79889 @@ -152,7 +152,7 @@ else
79890 fi;
79891
79892 # final build of init/
79893 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
79894 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
79895
79896 kallsymso=""
79897 kallsyms_vmlinux=""
79898 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79899 index 7ed6864..b6e90e6 100644
79900 --- a/scripts/mod/file2alias.c
79901 +++ b/scripts/mod/file2alias.c
79902 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79903 unsigned long size, unsigned long id_size,
79904 void *symval)
79905 {
79906 - int i;
79907 + unsigned int i;
79908
79909 if (size % id_size || size < id_size) {
79910 if (cross_build != 0)
79911 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79912 /* USB is special because the bcdDevice can be matched against a numeric range */
79913 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
79914 static void do_usb_entry(struct usb_device_id *id,
79915 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79916 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79917 unsigned char range_lo, unsigned char range_hi,
79918 unsigned char max, struct module *mod)
79919 {
79920 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79921 {
79922 unsigned int devlo, devhi;
79923 unsigned char chi, clo, max;
79924 - int ndigits;
79925 + unsigned int ndigits;
79926
79927 id->match_flags = TO_NATIVE(id->match_flags);
79928 id->idVendor = TO_NATIVE(id->idVendor);
79929 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79930 for (i = 0; i < count; i++) {
79931 const char *id = (char *)devs[i].id;
79932 char acpi_id[sizeof(devs[0].id)];
79933 - int j;
79934 + unsigned int j;
79935
79936 buf_printf(&mod->dev_table_buf,
79937 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79938 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79939
79940 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79941 const char *id = (char *)card->devs[j].id;
79942 - int i2, j2;
79943 + unsigned int i2, j2;
79944 int dup = 0;
79945
79946 if (!id[0])
79947 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79948 /* add an individual alias for every device entry */
79949 if (!dup) {
79950 char acpi_id[sizeof(card->devs[0].id)];
79951 - int k;
79952 + unsigned int k;
79953
79954 buf_printf(&mod->dev_table_buf,
79955 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79956 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79957 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79958 char *alias)
79959 {
79960 - int i, j;
79961 + unsigned int i, j;
79962
79963 sprintf(alias, "dmi*");
79964
79965 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79966 index 68e9f5e..ac7759b 100644
79967 --- a/scripts/mod/modpost.c
79968 +++ b/scripts/mod/modpost.c
79969 @@ -930,6 +930,7 @@ enum mismatch {
79970 ANY_INIT_TO_ANY_EXIT,
79971 ANY_EXIT_TO_ANY_INIT,
79972 EXPORT_TO_INIT_EXIT,
79973 + DATA_TO_TEXT
79974 };
79975
79976 struct sectioncheck {
79977 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
79978 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79979 .mismatch = EXPORT_TO_INIT_EXIT,
79980 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
79981 +},
79982 +/* Do not reference code from writable data */
79983 +{
79984 + .fromsec = { DATA_SECTIONS, NULL },
79985 + .tosec = { TEXT_SECTIONS, NULL },
79986 + .mismatch = DATA_TO_TEXT
79987 }
79988 };
79989
79990 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
79991 continue;
79992 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
79993 continue;
79994 - if (sym->st_value == addr)
79995 - return sym;
79996 /* Find a symbol nearby - addr are maybe negative */
79997 d = sym->st_value - addr;
79998 + if (d == 0)
79999 + return sym;
80000 if (d < 0)
80001 d = addr - sym->st_value;
80002 if (d < distance) {
80003 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80004 tosym, prl_to, prl_to, tosym);
80005 free(prl_to);
80006 break;
80007 + case DATA_TO_TEXT:
80008 +#if 0
80009 + fprintf(stderr,
80010 + "The %s %s:%s references\n"
80011 + "the %s %s:%s%s\n",
80012 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80013 +#endif
80014 + break;
80015 }
80016 fprintf(stderr, "\n");
80017 }
80018 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80019 static void check_sec_ref(struct module *mod, const char *modname,
80020 struct elf_info *elf)
80021 {
80022 - int i;
80023 + unsigned int i;
80024 Elf_Shdr *sechdrs = elf->sechdrs;
80025
80026 /* Walk through all sections */
80027 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80028 va_end(ap);
80029 }
80030
80031 -void buf_write(struct buffer *buf, const char *s, int len)
80032 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80033 {
80034 if (buf->size - buf->pos < len) {
80035 buf->size += len + SZ;
80036 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80037 if (fstat(fileno(file), &st) < 0)
80038 goto close_write;
80039
80040 - if (st.st_size != b->pos)
80041 + if (st.st_size != (off_t)b->pos)
80042 goto close_write;
80043
80044 tmp = NOFAIL(malloc(b->pos));
80045 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80046 index 51207e4..f7d603d 100644
80047 --- a/scripts/mod/modpost.h
80048 +++ b/scripts/mod/modpost.h
80049 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80050
80051 struct buffer {
80052 char *p;
80053 - int pos;
80054 - int size;
80055 + unsigned int pos;
80056 + unsigned int size;
80057 };
80058
80059 void __attribute__((format(printf, 2, 3)))
80060 buf_printf(struct buffer *buf, const char *fmt, ...);
80061
80062 void
80063 -buf_write(struct buffer *buf, const char *s, int len);
80064 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80065
80066 struct module {
80067 struct module *next;
80068 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80069 index 9dfcd6d..099068e 100644
80070 --- a/scripts/mod/sumversion.c
80071 +++ b/scripts/mod/sumversion.c
80072 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80073 goto out;
80074 }
80075
80076 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80077 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80078 warn("writing sum in %s failed: %s\n",
80079 filename, strerror(errno));
80080 goto out;
80081 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80082 index 5c11312..72742b5 100644
80083 --- a/scripts/pnmtologo.c
80084 +++ b/scripts/pnmtologo.c
80085 @@ -237,14 +237,14 @@ static void write_header(void)
80086 fprintf(out, " * Linux logo %s\n", logoname);
80087 fputs(" */\n\n", out);
80088 fputs("#include <linux/linux_logo.h>\n\n", out);
80089 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80090 + fprintf(out, "static unsigned char %s_data[] = {\n",
80091 logoname);
80092 }
80093
80094 static void write_footer(void)
80095 {
80096 fputs("\n};\n\n", out);
80097 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80098 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80099 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80100 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80101 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80102 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80103 fputs("\n};\n\n", out);
80104
80105 /* write logo clut */
80106 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80107 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80108 logoname);
80109 write_hex_cnt = 0;
80110 for (i = 0; i < logo_clutsize; i++) {
80111 diff --git a/security/Kconfig b/security/Kconfig
80112 index e9c6ac7..e7feb0d 100644
80113 --- a/security/Kconfig
80114 +++ b/security/Kconfig
80115 @@ -4,6 +4,896 @@
80116
80117 menu "Security options"
80118
80119 +menu "Grsecurity"
80120 +
80121 + config ARCH_TRACK_EXEC_LIMIT
80122 + bool
80123 +
80124 + config PAX_KERNEXEC_PLUGIN
80125 + bool
80126 +
80127 + config PAX_PER_CPU_PGD
80128 + bool
80129 +
80130 + config TASK_SIZE_MAX_SHIFT
80131 + int
80132 + depends on X86_64
80133 + default 47 if !PAX_PER_CPU_PGD
80134 + default 42 if PAX_PER_CPU_PGD
80135 +
80136 + config PAX_ENABLE_PAE
80137 + bool
80138 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80139 +
80140 + config PAX_USERCOPY_SLABS
80141 + bool
80142 +
80143 +config GRKERNSEC
80144 + bool "Grsecurity"
80145 + select CRYPTO
80146 + select CRYPTO_SHA256
80147 + select PROC_FS
80148 + select STOP_MACHINE
80149 + help
80150 + If you say Y here, you will be able to configure many features
80151 + that will enhance the security of your system. It is highly
80152 + recommended that you say Y here and read through the help
80153 + for each option so that you fully understand the features and
80154 + can evaluate their usefulness for your machine.
80155 +
80156 +choice
80157 + prompt "Configuration Method"
80158 + depends on GRKERNSEC
80159 + default GRKERNSEC_CONFIG_CUSTOM
80160 + help
80161 +
80162 +config GRKERNSEC_CONFIG_AUTO
80163 + bool "Automatic"
80164 + help
80165 + If you choose this configuration method, you'll be able to answer a small
80166 + number of simple questions about how you plan to use this kernel.
80167 + The settings of grsecurity and PaX will be automatically configured for
80168 + the highest commonly-used settings within the provided constraints.
80169 +
80170 + If you require additional configuration, custom changes can still be made
80171 + from the "custom configuration" menu.
80172 +
80173 +config GRKERNSEC_CONFIG_CUSTOM
80174 + bool "Custom"
80175 + help
80176 + If you choose this configuration method, you'll be able to configure all
80177 + grsecurity and PaX settings manually. Via this method, no options are
80178 + automatically enabled.
80179 +
80180 +endchoice
80181 +
80182 +choice
80183 + prompt "Usage Type"
80184 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80185 + default GRKERNSEC_CONFIG_SERVER
80186 + help
80187 +
80188 +config GRKERNSEC_CONFIG_SERVER
80189 + bool "Server"
80190 + help
80191 + Choose this option if you plan to use this kernel on a server.
80192 +
80193 +config GRKERNSEC_CONFIG_DESKTOP
80194 + bool "Desktop"
80195 + help
80196 + Choose this option if you plan to use this kernel on a desktop.
80197 +
80198 +endchoice
80199 +
80200 +choice
80201 + prompt "Virtualization Type"
80202 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80203 + default GRKERNSEC_CONFIG_VIRT_NONE
80204 + help
80205 +
80206 +config GRKERNSEC_CONFIG_VIRT_NONE
80207 + bool "None"
80208 + help
80209 + Choose this option if this kernel will be run on bare metal.
80210 +
80211 +config GRKERNSEC_CONFIG_VIRT_GUEST
80212 + bool "Guest"
80213 + help
80214 + Choose this option if this kernel will be run as a VM guest.
80215 +
80216 +config GRKERNSEC_CONFIG_VIRT_HOST
80217 + bool "Host"
80218 + help
80219 + Choose this option if this kernel will be run as a VM host.
80220 +
80221 +endchoice
80222 +
80223 +choice
80224 + prompt "Virtualization Hardware"
80225 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80226 + help
80227 +
80228 +config GRKERNSEC_CONFIG_VIRT_EPT
80229 + bool "EPT/RVI Processor Support"
80230 + depends on X86
80231 + help
80232 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80233 + hardware virtualization. This allows for additional kernel hardening protections
80234 + to operate without additional performance impact.
80235 +
80236 + To see if your Intel processor supports EPT, see:
80237 + http://ark.intel.com/Products/VirtualizationTechnology
80238 + (Most Core i3/5/7 support EPT)
80239 +
80240 + To see if your AMD processor supports RVI, see:
80241 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80242 +
80243 +config GRKERNSEC_CONFIG_VIRT_SOFT
80244 + bool "First-gen/No Hardware Virtualization"
80245 + help
80246 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80247 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80248 +
80249 +endchoice
80250 +
80251 +choice
80252 + prompt "Virtualization Software"
80253 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80254 + help
80255 +
80256 +config GRKERNSEC_CONFIG_VIRT_XEN
80257 + bool "Xen"
80258 + help
80259 + Choose this option if this kernel is running as a Xen guest or host.
80260 +
80261 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80262 + bool "VMWare"
80263 + help
80264 + Choose this option if this kernel is running as a VMWare guest or host.
80265 +
80266 +config GRKERNSEC_CONFIG_VIRT_KVM
80267 + bool "KVM"
80268 + help
80269 + Choose this option if this kernel is running as a KVM guest or host.
80270 +
80271 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80272 + bool "VirtualBox"
80273 + help
80274 + Choose this option if this kernel is running as a VirtualBox guest or host.
80275 +
80276 +endchoice
80277 +
80278 +choice
80279 + prompt "Required Priorities"
80280 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80281 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80282 + help
80283 +
80284 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80285 + bool "Performance"
80286 + help
80287 + Choose this option if performance is of highest priority for this deployment
80288 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80289 + and freed memory sanitizing will be disabled.
80290 +
80291 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80292 + bool "Security"
80293 + help
80294 + Choose this option if security is of highest priority for this deployment of
80295 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80296 + be enabled for this kernel. In a worst-case scenario, these features can
80297 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80298 +
80299 +endchoice
80300 +
80301 +menu "Default Special Groups"
80302 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80303 +
80304 +config GRKERNSEC_PROC_GID
80305 + int "GID exempted from /proc restrictions"
80306 + default 1001
80307 + help
80308 + Setting this GID determines which group will be exempted from
80309 + grsecurity's /proc restrictions, allowing users of the specified
80310 + group to view network statistics and the existence of other users'
80311 + processes on the system. This GID may also be chosen at boot time
80312 + via "grsec_proc_gid=" on the kernel commandline.
80313 +
80314 +config GRKERNSEC_TPE_UNTRUSTED_GID
80315 + int "GID for TPE-untrusted users"
80316 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80317 + default 1005
80318 + help
80319 + Setting this GID determines which group untrusted users should
80320 + be added to. These users will be placed under grsecurity's Trusted Path
80321 + Execution mechanism, preventing them from executing their own binaries.
80322 + The users will only be able to execute binaries in directories owned and
80323 + writable only by the root user. If the sysctl option is enabled, a sysctl
80324 + option with name "tpe_gid" is created.
80325 +
80326 +config GRKERNSEC_TPE_TRUSTED_GID
80327 + int "GID for TPE-trusted users"
80328 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80329 + default 1005
80330 + help
80331 + Setting this GID determines what group TPE restrictions will be
80332 + *disabled* for. If the sysctl option is enabled, a sysctl option
80333 + with name "tpe_gid" is created.
80334 +
80335 +config GRKERNSEC_SYMLINKOWN_GID
80336 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80337 + depends on GRKERNSEC_CONFIG_SERVER
80338 + default 1006
80339 + help
80340 + Setting this GID determines what group kernel-enforced
80341 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80342 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80343 +
80344 +
80345 +endmenu
80346 +
80347 +menu "Customize Configuration"
80348 +depends on GRKERNSEC
80349 +
80350 +menu "PaX"
80351 +
80352 +config PAX
80353 + bool "Enable various PaX features"
80354 + default y if GRKERNSEC_CONFIG_AUTO
80355 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80356 + help
80357 + This allows you to enable various PaX features. PaX adds
80358 + intrusion prevention mechanisms to the kernel that reduce
80359 + the risks posed by exploitable memory corruption bugs.
80360 +
80361 +menu "PaX Control"
80362 + depends on PAX
80363 +
80364 +config PAX_SOFTMODE
80365 + bool 'Support soft mode'
80366 + help
80367 + Enabling this option will allow you to run PaX in soft mode, that
80368 + is, PaX features will not be enforced by default, only on executables
80369 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80370 + support as they are the only way to mark executables for soft mode use.
80371 +
80372 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80373 + line option on boot. Furthermore you can control various PaX features
80374 + at runtime via the entries in /proc/sys/kernel/pax.
80375 +
80376 +config PAX_EI_PAX
80377 + bool 'Use legacy ELF header marking'
80378 + default y if GRKERNSEC_CONFIG_AUTO
80379 + help
80380 + Enabling this option will allow you to control PaX features on
80381 + a per executable basis via the 'chpax' utility available at
80382 + http://pax.grsecurity.net/. The control flags will be read from
80383 + an otherwise reserved part of the ELF header. This marking has
80384 + numerous drawbacks (no support for soft-mode, toolchain does not
80385 + know about the non-standard use of the ELF header) therefore it
80386 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80387 + support.
80388 +
80389 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80390 + support as well, they will override the legacy EI_PAX marks.
80391 +
80392 + If you enable none of the marking options then all applications
80393 + will run with PaX enabled on them by default.
80394 +
80395 +config PAX_PT_PAX_FLAGS
80396 + bool 'Use ELF program header marking'
80397 + default y if GRKERNSEC_CONFIG_AUTO
80398 + help
80399 + Enabling this option will allow you to control PaX features on
80400 + a per executable basis via the 'paxctl' utility available at
80401 + http://pax.grsecurity.net/. The control flags will be read from
80402 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80403 + has the benefits of supporting both soft mode and being fully
80404 + integrated into the toolchain (the binutils patch is available
80405 + from http://pax.grsecurity.net).
80406 +
80407 + Note that if you enable the legacy EI_PAX marking support as well,
80408 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80409 +
80410 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80411 + must make sure that the marks are the same if a binary has both marks.
80412 +
80413 + If you enable none of the marking options then all applications
80414 + will run with PaX enabled on them by default.
80415 +
80416 +config PAX_XATTR_PAX_FLAGS
80417 + bool 'Use filesystem extended attributes marking'
80418 + default y if GRKERNSEC_CONFIG_AUTO
80419 + select CIFS_XATTR if CIFS
80420 + select EXT2_FS_XATTR if EXT2_FS
80421 + select EXT3_FS_XATTR if EXT3_FS
80422 + select EXT4_FS_XATTR if EXT4_FS
80423 + select JFFS2_FS_XATTR if JFFS2_FS
80424 + select REISERFS_FS_XATTR if REISERFS_FS
80425 + select SQUASHFS_XATTR if SQUASHFS
80426 + select TMPFS_XATTR if TMPFS
80427 + select UBIFS_FS_XATTR if UBIFS_FS
80428 + help
80429 + Enabling this option will allow you to control PaX features on
80430 + a per executable basis via the 'setfattr' utility. The control
80431 + flags will be read from the user.pax.flags extended attribute of
80432 + the file. This marking has the benefit of supporting binary-only
80433 + applications that self-check themselves (e.g., skype) and would
80434 + not tolerate chpax/paxctl changes. The main drawback is that
80435 + extended attributes are not supported by some filesystems (e.g.,
80436 + isofs, udf, vfat) so copying files through such filesystems will
80437 + lose the extended attributes and these PaX markings.
80438 +
80439 + Note that if you enable the legacy EI_PAX marking support as well,
80440 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80441 +
80442 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80443 + must make sure that the marks are the same if a binary has both marks.
80444 +
80445 + If you enable none of the marking options then all applications
80446 + will run with PaX enabled on them by default.
80447 +
80448 +choice
80449 + prompt 'MAC system integration'
80450 + default PAX_HAVE_ACL_FLAGS
80451 + help
80452 + Mandatory Access Control systems have the option of controlling
80453 + PaX flags on a per executable basis, choose the method supported
80454 + by your particular system.
80455 +
80456 + - "none": if your MAC system does not interact with PaX,
80457 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80458 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80459 +
80460 + NOTE: this option is for developers/integrators only.
80461 +
80462 + config PAX_NO_ACL_FLAGS
80463 + bool 'none'
80464 +
80465 + config PAX_HAVE_ACL_FLAGS
80466 + bool 'direct'
80467 +
80468 + config PAX_HOOK_ACL_FLAGS
80469 + bool 'hook'
80470 +endchoice
80471 +
80472 +endmenu
80473 +
80474 +menu "Non-executable pages"
80475 + depends on PAX
80476 +
80477 +config PAX_NOEXEC
80478 + bool "Enforce non-executable pages"
80479 + default y if GRKERNSEC_CONFIG_AUTO
80480 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80481 + help
80482 + By design some architectures do not allow for protecting memory
80483 + pages against execution or even if they do, Linux does not make
80484 + use of this feature. In practice this means that if a page is
80485 + readable (such as the stack or heap) it is also executable.
80486 +
80487 + There is a well known exploit technique that makes use of this
80488 + fact and a common programming mistake where an attacker can
80489 + introduce code of his choice somewhere in the attacked program's
80490 + memory (typically the stack or the heap) and then execute it.
80491 +
80492 + If the attacked program was running with different (typically
80493 + higher) privileges than that of the attacker, then he can elevate
80494 + his own privilege level (e.g. get a root shell, write to files for
80495 + which he does not have write access to, etc).
80496 +
80497 + Enabling this option will let you choose from various features
80498 + that prevent the injection and execution of 'foreign' code in
80499 + a program.
80500 +
80501 + This will also break programs that rely on the old behaviour and
80502 + expect that dynamically allocated memory via the malloc() family
80503 + of functions is executable (which it is not). Notable examples
80504 + are the XFree86 4.x server, the java runtime and wine.
80505 +
80506 +config PAX_PAGEEXEC
80507 + bool "Paging based non-executable pages"
80508 + default y if GRKERNSEC_CONFIG_AUTO
80509 + 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)
80510 + select S390_SWITCH_AMODE if S390
80511 + select S390_EXEC_PROTECT if S390
80512 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80513 + help
80514 + This implementation is based on the paging feature of the CPU.
80515 + On i386 without hardware non-executable bit support there is a
80516 + variable but usually low performance impact, however on Intel's
80517 + P4 core based CPUs it is very high so you should not enable this
80518 + for kernels meant to be used on such CPUs.
80519 +
80520 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80521 + with hardware non-executable bit support there is no performance
80522 + impact, on ppc the impact is negligible.
80523 +
80524 + Note that several architectures require various emulations due to
80525 + badly designed userland ABIs, this will cause a performance impact
80526 + but will disappear as soon as userland is fixed. For example, ppc
80527 + userland MUST have been built with secure-plt by a recent toolchain.
80528 +
80529 +config PAX_SEGMEXEC
80530 + bool "Segmentation based non-executable pages"
80531 + default y if GRKERNSEC_CONFIG_AUTO
80532 + depends on PAX_NOEXEC && X86_32
80533 + help
80534 + This implementation is based on the segmentation feature of the
80535 + CPU and has a very small performance impact, however applications
80536 + will be limited to a 1.5 GB address space instead of the normal
80537 + 3 GB.
80538 +
80539 +config PAX_EMUTRAMP
80540 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80541 + default y if PARISC
80542 + help
80543 + There are some programs and libraries that for one reason or
80544 + another attempt to execute special small code snippets from
80545 + non-executable memory pages. Most notable examples are the
80546 + signal handler return code generated by the kernel itself and
80547 + the GCC trampolines.
80548 +
80549 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80550 + such programs will no longer work under your kernel.
80551 +
80552 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80553 + utilities to enable trampoline emulation for the affected programs
80554 + yet still have the protection provided by the non-executable pages.
80555 +
80556 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80557 + your system will not even boot.
80558 +
80559 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80560 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80561 + for the affected files.
80562 +
80563 + NOTE: enabling this feature *may* open up a loophole in the
80564 + protection provided by non-executable pages that an attacker
80565 + could abuse. Therefore the best solution is to not have any
80566 + files on your system that would require this option. This can
80567 + be achieved by not using libc5 (which relies on the kernel
80568 + signal handler return code) and not using or rewriting programs
80569 + that make use of the nested function implementation of GCC.
80570 + Skilled users can just fix GCC itself so that it implements
80571 + nested function calls in a way that does not interfere with PaX.
80572 +
80573 +config PAX_EMUSIGRT
80574 + bool "Automatically emulate sigreturn trampolines"
80575 + depends on PAX_EMUTRAMP && PARISC
80576 + default y
80577 + help
80578 + Enabling this option will have the kernel automatically detect
80579 + and emulate signal return trampolines executing on the stack
80580 + that would otherwise lead to task termination.
80581 +
80582 + This solution is intended as a temporary one for users with
80583 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80584 + Modula-3 runtime, etc) or executables linked to such, basically
80585 + everything that does not specify its own SA_RESTORER function in
80586 + normal executable memory like glibc 2.1+ does.
80587 +
80588 + On parisc you MUST enable this option, otherwise your system will
80589 + not even boot.
80590 +
80591 + NOTE: this feature cannot be disabled on a per executable basis
80592 + and since it *does* open up a loophole in the protection provided
80593 + by non-executable pages, the best solution is to not have any
80594 + files on your system that would require this option.
80595 +
80596 +config PAX_MPROTECT
80597 + bool "Restrict mprotect()"
80598 + default y if GRKERNSEC_CONFIG_AUTO
80599 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80600 + help
80601 + Enabling this option will prevent programs from
80602 + - changing the executable status of memory pages that were
80603 + not originally created as executable,
80604 + - making read-only executable pages writable again,
80605 + - creating executable pages from anonymous memory,
80606 + - making read-only-after-relocations (RELRO) data pages writable again.
80607 +
80608 + You should say Y here to complete the protection provided by
80609 + the enforcement of non-executable pages.
80610 +
80611 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80612 + this feature on a per file basis.
80613 +
80614 +config PAX_MPROTECT_COMPAT
80615 + bool "Use legacy/compat protection demoting (read help)"
80616 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80617 + depends on PAX_MPROTECT
80618 + help
80619 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80620 + by sending the proper error code to the application. For some broken
80621 + userland, this can cause problems with Python or other applications. The
80622 + current implementation however allows for applications like clamav to
80623 + detect if JIT compilation/execution is allowed and to fall back gracefully
80624 + to an interpreter-based mode if it does not. While we encourage everyone
80625 + to use the current implementation as-is and push upstream to fix broken
80626 + userland (note that the RWX logging option can assist with this), in some
80627 + environments this may not be possible. Having to disable MPROTECT
80628 + completely on certain binaries reduces the security benefit of PaX,
80629 + so this option is provided for those environments to revert to the old
80630 + behavior.
80631 +
80632 +config PAX_ELFRELOCS
80633 + bool "Allow ELF text relocations (read help)"
80634 + depends on PAX_MPROTECT
80635 + default n
80636 + help
80637 + Non-executable pages and mprotect() restrictions are effective
80638 + in preventing the introduction of new executable code into an
80639 + attacked task's address space. There remain only two venues
80640 + for this kind of attack: if the attacker can execute already
80641 + existing code in the attacked task then he can either have it
80642 + create and mmap() a file containing his code or have it mmap()
80643 + an already existing ELF library that does not have position
80644 + independent code in it and use mprotect() on it to make it
80645 + writable and copy his code there. While protecting against
80646 + the former approach is beyond PaX, the latter can be prevented
80647 + by having only PIC ELF libraries on one's system (which do not
80648 + need to relocate their code). If you are sure this is your case,
80649 + as is the case with all modern Linux distributions, then leave
80650 + this option disabled. You should say 'n' here.
80651 +
80652 +config PAX_ETEXECRELOCS
80653 + bool "Allow ELF ET_EXEC text relocations"
80654 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80655 + select PAX_ELFRELOCS
80656 + default y
80657 + help
80658 + On some architectures there are incorrectly created applications
80659 + that require text relocations and would not work without enabling
80660 + this option. If you are an alpha, ia64 or parisc user, you should
80661 + enable this option and disable it once you have made sure that
80662 + none of your applications need it.
80663 +
80664 +config PAX_EMUPLT
80665 + bool "Automatically emulate ELF PLT"
80666 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80667 + default y
80668 + help
80669 + Enabling this option will have the kernel automatically detect
80670 + and emulate the Procedure Linkage Table entries in ELF files.
80671 + On some architectures such entries are in writable memory, and
80672 + become non-executable leading to task termination. Therefore
80673 + it is mandatory that you enable this option on alpha, parisc,
80674 + sparc and sparc64, otherwise your system would not even boot.
80675 +
80676 + NOTE: this feature *does* open up a loophole in the protection
80677 + provided by the non-executable pages, therefore the proper
80678 + solution is to modify the toolchain to produce a PLT that does
80679 + not need to be writable.
80680 +
80681 +config PAX_DLRESOLVE
80682 + bool 'Emulate old glibc resolver stub'
80683 + depends on PAX_EMUPLT && SPARC
80684 + default n
80685 + help
80686 + This option is needed if userland has an old glibc (before 2.4)
80687 + that puts a 'save' instruction into the runtime generated resolver
80688 + stub that needs special emulation.
80689 +
80690 +config PAX_KERNEXEC
80691 + bool "Enforce non-executable kernel pages"
80692 + 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))
80693 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80694 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80695 + select PAX_KERNEXEC_PLUGIN if X86_64
80696 + help
80697 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80698 + that is, enabling this option will make it harder to inject
80699 + and execute 'foreign' code in kernel memory itself.
80700 +
80701 +choice
80702 + prompt "Return Address Instrumentation Method"
80703 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80704 + depends on PAX_KERNEXEC_PLUGIN
80705 + help
80706 + Select the method used to instrument function pointer dereferences.
80707 + Note that binary modules cannot be instrumented by this approach.
80708 +
80709 + Note that the implementation requires a gcc with plugin support,
80710 + i.e., gcc 4.5 or newer. You may need to install the supporting
80711 + headers explicitly in addition to the normal gcc package.
80712 +
80713 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80714 + bool "bts"
80715 + help
80716 + This method is compatible with binary only modules but has
80717 + a higher runtime overhead.
80718 +
80719 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80720 + bool "or"
80721 + depends on !PARAVIRT
80722 + help
80723 + This method is incompatible with binary only modules but has
80724 + a lower runtime overhead.
80725 +endchoice
80726 +
80727 +config PAX_KERNEXEC_PLUGIN_METHOD
80728 + string
80729 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80730 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80731 + default ""
80732 +
80733 +config PAX_KERNEXEC_MODULE_TEXT
80734 + int "Minimum amount of memory reserved for module code"
80735 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
80736 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80737 + depends on PAX_KERNEXEC && X86_32 && MODULES
80738 + help
80739 + Due to implementation details the kernel must reserve a fixed
80740 + amount of memory for module code at compile time that cannot be
80741 + changed at runtime. Here you can specify the minimum amount
80742 + in MB that will be reserved. Due to the same implementation
80743 + details this size will always be rounded up to the next 2/4 MB
80744 + boundary (depends on PAE) so the actually available memory for
80745 + module code will usually be more than this minimum.
80746 +
80747 + The default 4 MB should be enough for most users but if you have
80748 + an excessive number of modules (e.g., most distribution configs
80749 + compile many drivers as modules) or use huge modules such as
80750 + nvidia's kernel driver, you will need to adjust this amount.
80751 + A good rule of thumb is to look at your currently loaded kernel
80752 + modules and add up their sizes.
80753 +
80754 +endmenu
80755 +
80756 +menu "Address Space Layout Randomization"
80757 + depends on PAX
80758 +
80759 +config PAX_ASLR
80760 + bool "Address Space Layout Randomization"
80761 + default y if GRKERNSEC_CONFIG_AUTO
80762 + help
80763 + Many if not most exploit techniques rely on the knowledge of
80764 + certain addresses in the attacked program. The following options
80765 + will allow the kernel to apply a certain amount of randomization
80766 + to specific parts of the program thereby forcing an attacker to
80767 + guess them in most cases. Any failed guess will most likely crash
80768 + the attacked program which allows the kernel to detect such attempts
80769 + and react on them. PaX itself provides no reaction mechanisms,
80770 + instead it is strongly encouraged that you make use of Nergal's
80771 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80772 + (http://www.grsecurity.net/) built-in crash detection features or
80773 + develop one yourself.
80774 +
80775 + By saying Y here you can choose to randomize the following areas:
80776 + - top of the task's kernel stack
80777 + - top of the task's userland stack
80778 + - base address for mmap() requests that do not specify one
80779 + (this includes all libraries)
80780 + - base address of the main executable
80781 +
80782 + It is strongly recommended to say Y here as address space layout
80783 + randomization has negligible impact on performance yet it provides
80784 + a very effective protection.
80785 +
80786 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80787 + this feature on a per file basis.
80788 +
80789 +config PAX_RANDKSTACK
80790 + bool "Randomize kernel stack base"
80791 + default y if GRKERNSEC_CONFIG_AUTO
80792 + depends on X86_TSC && X86
80793 + help
80794 + By saying Y here the kernel will randomize every task's kernel
80795 + stack on every system call. This will not only force an attacker
80796 + to guess it but also prevent him from making use of possible
80797 + leaked information about it.
80798 +
80799 + Since the kernel stack is a rather scarce resource, randomization
80800 + may cause unexpected stack overflows, therefore you should very
80801 + carefully test your system. Note that once enabled in the kernel
80802 + configuration, this feature cannot be disabled on a per file basis.
80803 +
80804 +config PAX_RANDUSTACK
80805 + bool "Randomize user stack base"
80806 + default y if GRKERNSEC_CONFIG_AUTO
80807 + depends on PAX_ASLR
80808 + help
80809 + By saying Y here the kernel will randomize every task's userland
80810 + stack. The randomization is done in two steps where the second
80811 + one may apply a big amount of shift to the top of the stack and
80812 + cause problems for programs that want to use lots of memory (more
80813 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80814 + For this reason the second step can be controlled by 'chpax' or
80815 + 'paxctl' on a per file basis.
80816 +
80817 +config PAX_RANDMMAP
80818 + bool "Randomize mmap() base"
80819 + default y if GRKERNSEC_CONFIG_AUTO
80820 + depends on PAX_ASLR
80821 + help
80822 + By saying Y here the kernel will use a randomized base address for
80823 + mmap() requests that do not specify one themselves. As a result
80824 + all dynamically loaded libraries will appear at random addresses
80825 + and therefore be harder to exploit by a technique where an attacker
80826 + attempts to execute library code for his purposes (e.g. spawn a
80827 + shell from an exploited program that is running at an elevated
80828 + privilege level).
80829 +
80830 + Furthermore, if a program is relinked as a dynamic ELF file, its
80831 + base address will be randomized as well, completing the full
80832 + randomization of the address space layout. Attacking such programs
80833 + becomes a guess game. You can find an example of doing this at
80834 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80835 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80836 +
80837 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80838 + feature on a per file basis.
80839 +
80840 +endmenu
80841 +
80842 +menu "Miscellaneous hardening features"
80843 +
80844 +config PAX_MEMORY_SANITIZE
80845 + bool "Sanitize all freed memory"
80846 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80847 + depends on !HIBERNATION
80848 + help
80849 + By saying Y here the kernel will erase memory pages as soon as they
80850 + are freed. This in turn reduces the lifetime of data stored in the
80851 + pages, making it less likely that sensitive information such as
80852 + passwords, cryptographic secrets, etc stay in memory for too long.
80853 +
80854 + This is especially useful for programs whose runtime is short, long
80855 + lived processes and the kernel itself benefit from this as long as
80856 + they operate on whole memory pages and ensure timely freeing of pages
80857 + that may hold sensitive information.
80858 +
80859 + The tradeoff is performance impact, on a single CPU system kernel
80860 + compilation sees a 3% slowdown, other systems and workloads may vary
80861 + and you are advised to test this feature on your expected workload
80862 + before deploying it.
80863 +
80864 + Note that this feature does not protect data stored in live pages,
80865 + e.g., process memory swapped to disk may stay there for a long time.
80866 +
80867 +config PAX_MEMORY_STACKLEAK
80868 + bool "Sanitize kernel stack"
80869 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80870 + depends on X86
80871 + help
80872 + By saying Y here the kernel will erase the kernel stack before it
80873 + returns from a system call. This in turn reduces the information
80874 + that a kernel stack leak bug can reveal.
80875 +
80876 + Note that such a bug can still leak information that was put on
80877 + the stack by the current system call (the one eventually triggering
80878 + the bug) but traces of earlier system calls on the kernel stack
80879 + cannot leak anymore.
80880 +
80881 + The tradeoff is performance impact: on a single CPU system kernel
80882 + compilation sees a 1% slowdown, other systems and workloads may vary
80883 + and you are advised to test this feature on your expected workload
80884 + before deploying it.
80885 +
80886 + Note that the full feature requires a gcc with plugin support,
80887 + i.e., gcc 4.5 or newer. You may need to install the supporting
80888 + headers explicitly in addition to the normal gcc package. Using
80889 + older gcc versions means that functions with large enough stack
80890 + frames may leave uninitialized memory behind that may be exposed
80891 + to a later syscall leaking the stack.
80892 +
80893 +config PAX_MEMORY_UDEREF
80894 + bool "Prevent invalid userland pointer dereference"
80895 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
80896 + depends on X86 && !UML_X86 && !XEN
80897 + select PAX_PER_CPU_PGD if X86_64
80898 + help
80899 + By saying Y here the kernel will be prevented from dereferencing
80900 + userland pointers in contexts where the kernel expects only kernel
80901 + pointers. This is both a useful runtime debugging feature and a
80902 + security measure that prevents exploiting a class of kernel bugs.
80903 +
80904 + The tradeoff is that some virtualization solutions may experience
80905 + a huge slowdown and therefore you should not enable this feature
80906 + for kernels meant to run in such environments. Whether a given VM
80907 + solution is affected or not is best determined by simply trying it
80908 + out, the performance impact will be obvious right on boot as this
80909 + mechanism engages from very early on. A good rule of thumb is that
80910 + VMs running on CPUs without hardware virtualization support (i.e.,
80911 + the majority of IA-32 CPUs) will likely experience the slowdown.
80912 +
80913 +config PAX_REFCOUNT
80914 + bool "Prevent various kernel object reference counter overflows"
80915 + default y if GRKERNSEC_CONFIG_AUTO
80916 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80917 + help
80918 + By saying Y here the kernel will detect and prevent overflowing
80919 + various (but not all) kinds of object reference counters. Such
80920 + overflows can normally occur due to bugs only and are often, if
80921 + not always, exploitable.
80922 +
80923 + The tradeoff is that data structures protected by an overflowed
80924 + refcount will never be freed and therefore will leak memory. Note
80925 + that this leak also happens even without this protection but in
80926 + that case the overflow can eventually trigger the freeing of the
80927 + data structure while it is still being used elsewhere, resulting
80928 + in the exploitable situation that this feature prevents.
80929 +
80930 + Since this has a negligible performance impact, you should enable
80931 + this feature.
80932 +
80933 +config PAX_USERCOPY
80934 + bool "Harden heap object copies between kernel and userland"
80935 + default y if GRKERNSEC_CONFIG_AUTO
80936 + depends on X86 || PPC || SPARC || ARM
80937 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80938 + select PAX_USERCOPY_SLABS
80939 + help
80940 + By saying Y here the kernel will enforce the size of heap objects
80941 + when they are copied in either direction between the kernel and
80942 + userland, even if only a part of the heap object is copied.
80943 +
80944 + Specifically, this checking prevents information leaking from the
80945 + kernel heap during kernel to userland copies (if the kernel heap
80946 + object is otherwise fully initialized) and prevents kernel heap
80947 + overflows during userland to kernel copies.
80948 +
80949 + Note that the current implementation provides the strictest bounds
80950 + checks for the SLUB allocator.
80951 +
80952 + Enabling this option also enables per-slab cache protection against
80953 + data in a given cache being copied into/out of via userland
80954 + accessors. Though the whitelist of regions will be reduced over
80955 + time, it notably protects important data structures like task structs.
80956 +
80957 + If frame pointers are enabled on x86, this option will also restrict
80958 + copies into and out of the kernel stack to local variables within a
80959 + single frame.
80960 +
80961 + Since this has a negligible performance impact, you should enable
80962 + this feature.
80963 +
80964 +config PAX_SIZE_OVERFLOW
80965 + bool "Prevent various integer overflows in function size parameters"
80966 + default y if GRKERNSEC_CONFIG_AUTO
80967 + depends on X86
80968 + help
80969 + By saying Y here the kernel recomputes expressions of function
80970 + arguments marked by a size_overflow attribute with double integer
80971 + precision (DImode/TImode for 32/64 bit integer types).
80972 +
80973 + The recomputed argument is checked against TYPE_MAX and an event
80974 + is logged on overflow and the triggering process is killed.
80975 +
80976 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
80977 +
80978 + Note that the implementation requires a gcc with plugin support,
80979 + i.e., gcc 4.5 or newer. You may need to install the supporting
80980 + headers explicitly in addition to the normal gcc package.
80981 +
80982 +config PAX_LATENT_ENTROPY
80983 + bool "Generate some entropy during boot"
80984 + default y if GRKERNSEC_CONFIG_AUTO
80985 + help
80986 + By saying Y here the kernel will instrument early boot code to
80987 + extract some entropy from both original and artificially created
80988 + program state. This will help especially embedded systems where
80989 + there is little 'natural' source of entropy normally. The cost
80990 + is some slowdown of the boot process.
80991 +
80992 + Note that the implementation requires a gcc with plugin support,
80993 + i.e., gcc 4.5 or newer. You may need to install the supporting
80994 + headers explicitly in addition to the normal gcc package.
80995 +
80996 + Note that entropy extracted this way is not cryptographically
80997 + secure!
80998 +
80999 +endmenu
81000 +
81001 +endmenu
81002 +
81003 +source grsecurity/Kconfig
81004 +
81005 +endmenu
81006 +
81007 +endmenu
81008 +
81009 source security/keys/Kconfig
81010
81011 config SECURITY_DMESG_RESTRICT
81012 @@ -103,7 +993,7 @@ config INTEL_TXT
81013 config LSM_MMAP_MIN_ADDR
81014 int "Low address space for LSM to protect from user allocation"
81015 depends on SECURITY && SECURITY_SELINUX
81016 - default 32768 if ARM
81017 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81018 default 65536
81019 help
81020 This is the portion of low virtual memory which should be protected
81021 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81022 index 8ea39aa..8569ac5 100644
81023 --- a/security/apparmor/lsm.c
81024 +++ b/security/apparmor/lsm.c
81025 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81026 return error;
81027 }
81028
81029 -static struct security_operations apparmor_ops = {
81030 +static struct security_operations apparmor_ops __read_only = {
81031 .name = "apparmor",
81032
81033 .ptrace_access_check = apparmor_ptrace_access_check,
81034 diff --git a/security/commoncap.c b/security/commoncap.c
81035 index 6dbae46..d5611fd 100644
81036 --- a/security/commoncap.c
81037 +++ b/security/commoncap.c
81038 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81039 return 0;
81040 }
81041
81042 +/* returns:
81043 + 1 for suid privilege
81044 + 2 for sgid privilege
81045 + 3 for fscap privilege
81046 +*/
81047 +int is_privileged_binary(const struct dentry *dentry)
81048 +{
81049 + struct cpu_vfs_cap_data capdata;
81050 + struct inode *inode = dentry->d_inode;
81051 +
81052 + if (!inode || S_ISDIR(inode->i_mode))
81053 + return 0;
81054 +
81055 + if (inode->i_mode & S_ISUID)
81056 + return 1;
81057 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81058 + return 2;
81059 +
81060 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81061 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81062 + return 3;
81063 + }
81064 +
81065 + return 0;
81066 +}
81067 +
81068 /*
81069 * Attempt to get the on-exec apply capability sets for an executable file from
81070 * its xattrs and, if present, apply them to the proposed credentials being
81071 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81072 const struct cred *cred = current_cred();
81073 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81074
81075 + if (gr_acl_enable_at_secure())
81076 + return 1;
81077 +
81078 if (!uid_eq(cred->uid, root_uid)) {
81079 if (bprm->cap_effective)
81080 return 1;
81081 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81082 index e7c99fd..5b2fa24 100644
81083 --- a/security/integrity/ima/ima.h
81084 +++ b/security/integrity/ima/ima.h
81085 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81086 extern spinlock_t ima_queue_lock;
81087
81088 struct ima_h_table {
81089 - atomic_long_t len; /* number of stored measurements in the list */
81090 - atomic_long_t violations;
81091 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81092 + atomic_long_unchecked_t violations;
81093 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81094 };
81095 extern struct ima_h_table ima_htable;
81096 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81097 index 032ff03..c428a74 100644
81098 --- a/security/integrity/ima/ima_api.c
81099 +++ b/security/integrity/ima/ima_api.c
81100 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81101 int result;
81102
81103 /* can overflow, only indicator */
81104 - atomic_long_inc(&ima_htable.violations);
81105 + atomic_long_inc_unchecked(&ima_htable.violations);
81106
81107 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81108 if (!entry) {
81109 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81110 index 38477c9..87a60c7 100644
81111 --- a/security/integrity/ima/ima_fs.c
81112 +++ b/security/integrity/ima/ima_fs.c
81113 @@ -28,12 +28,12 @@
81114 static int valid_policy = 1;
81115 #define TMPBUFLEN 12
81116 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81117 - loff_t *ppos, atomic_long_t *val)
81118 + loff_t *ppos, atomic_long_unchecked_t *val)
81119 {
81120 char tmpbuf[TMPBUFLEN];
81121 ssize_t len;
81122
81123 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81124 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81125 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81126 }
81127
81128 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81129 index 55a6271..ad829c3 100644
81130 --- a/security/integrity/ima/ima_queue.c
81131 +++ b/security/integrity/ima/ima_queue.c
81132 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81133 INIT_LIST_HEAD(&qe->later);
81134 list_add_tail_rcu(&qe->later, &ima_measurements);
81135
81136 - atomic_long_inc(&ima_htable.len);
81137 + atomic_long_inc_unchecked(&ima_htable.len);
81138 key = ima_hash_key(entry->digest);
81139 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81140 return 0;
81141 diff --git a/security/keys/compat.c b/security/keys/compat.c
81142 index 1c26176..64a1ba2 100644
81143 --- a/security/keys/compat.c
81144 +++ b/security/keys/compat.c
81145 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81146 if (ret == 0)
81147 goto no_payload_free;
81148
81149 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81150 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81151
81152 if (iov != iovstack)
81153 kfree(iov);
81154 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81155 index 3364fbf..1f10f31 100644
81156 --- a/security/keys/keyctl.c
81157 +++ b/security/keys/keyctl.c
81158 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81159 /*
81160 * Copy the iovec data from userspace
81161 */
81162 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81163 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81164 unsigned ioc)
81165 {
81166 for (; ioc > 0; ioc--) {
81167 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81168 * If successful, 0 will be returned.
81169 */
81170 long keyctl_instantiate_key_common(key_serial_t id,
81171 - const struct iovec *payload_iov,
81172 + const struct iovec __user *payload_iov,
81173 unsigned ioc,
81174 size_t plen,
81175 key_serial_t ringid)
81176 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81177 [0].iov_len = plen
81178 };
81179
81180 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81181 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81182 }
81183
81184 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81185 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81186 if (ret == 0)
81187 goto no_payload_free;
81188
81189 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81190 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81191
81192 if (iov != iovstack)
81193 kfree(iov);
81194 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81195 index 81e7852..2b2ecc3 100644
81196 --- a/security/keys/keyring.c
81197 +++ b/security/keys/keyring.c
81198 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81199 ret = -EFAULT;
81200
81201 for (loop = 0; loop < klist->nkeys; loop++) {
81202 + key_serial_t serial;
81203 key = rcu_deref_link_locked(klist, loop,
81204 keyring);
81205 + serial = key->serial;
81206
81207 tmp = sizeof(key_serial_t);
81208 if (tmp > buflen)
81209 tmp = buflen;
81210
81211 - if (copy_to_user(buffer,
81212 - &key->serial,
81213 - tmp) != 0)
81214 + if (copy_to_user(buffer, &serial, tmp))
81215 goto error;
81216
81217 buflen -= tmp;
81218 diff --git a/security/min_addr.c b/security/min_addr.c
81219 index f728728..6457a0c 100644
81220 --- a/security/min_addr.c
81221 +++ b/security/min_addr.c
81222 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81223 */
81224 static void update_mmap_min_addr(void)
81225 {
81226 +#ifndef SPARC
81227 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81228 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81229 mmap_min_addr = dac_mmap_min_addr;
81230 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81231 #else
81232 mmap_min_addr = dac_mmap_min_addr;
81233 #endif
81234 +#endif
81235 }
81236
81237 /*
81238 diff --git a/security/security.c b/security/security.c
81239 index 860aeb3..45765c0 100644
81240 --- a/security/security.c
81241 +++ b/security/security.c
81242 @@ -20,6 +20,7 @@
81243 #include <linux/ima.h>
81244 #include <linux/evm.h>
81245 #include <linux/fsnotify.h>
81246 +#include <linux/mm.h>
81247 #include <linux/mman.h>
81248 #include <linux/mount.h>
81249 #include <linux/personality.h>
81250 @@ -32,8 +33,8 @@
81251 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81252 CONFIG_DEFAULT_SECURITY;
81253
81254 -static struct security_operations *security_ops;
81255 -static struct security_operations default_security_ops = {
81256 +static struct security_operations *security_ops __read_only;
81257 +static struct security_operations default_security_ops __read_only = {
81258 .name = "default",
81259 };
81260
81261 @@ -74,7 +75,9 @@ int __init security_init(void)
81262
81263 void reset_security_ops(void)
81264 {
81265 + pax_open_kernel();
81266 security_ops = &default_security_ops;
81267 + pax_close_kernel();
81268 }
81269
81270 /* Save user chosen LSM */
81271 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81272 index 6c77f63..7496c76 100644
81273 --- a/security/selinux/hooks.c
81274 +++ b/security/selinux/hooks.c
81275 @@ -95,8 +95,6 @@
81276
81277 #define NUM_SEL_MNT_OPTS 5
81278
81279 -extern struct security_operations *security_ops;
81280 -
81281 /* SECMARK reference count */
81282 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81283
81284 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81285
81286 #endif
81287
81288 -static struct security_operations selinux_ops = {
81289 +static struct security_operations selinux_ops __read_only = {
81290 .name = "selinux",
81291
81292 .ptrace_access_check = selinux_ptrace_access_check,
81293 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81294 index 65f67cb..3f141ef 100644
81295 --- a/security/selinux/include/xfrm.h
81296 +++ b/security/selinux/include/xfrm.h
81297 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81298
81299 static inline void selinux_xfrm_notify_policyload(void)
81300 {
81301 - atomic_inc(&flow_cache_genid);
81302 + atomic_inc_unchecked(&flow_cache_genid);
81303 rt_genid_bump(&init_net);
81304 }
81305 #else
81306 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81307 index 8221514..5c4775f 100644
81308 --- a/security/smack/smack_lsm.c
81309 +++ b/security/smack/smack_lsm.c
81310 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81311 return 0;
81312 }
81313
81314 -struct security_operations smack_ops = {
81315 +struct security_operations smack_ops __read_only = {
81316 .name = "smack",
81317
81318 .ptrace_access_check = smack_ptrace_access_check,
81319 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81320 index c2d04a5..e6a1aeb 100644
81321 --- a/security/tomoyo/tomoyo.c
81322 +++ b/security/tomoyo/tomoyo.c
81323 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81324 * tomoyo_security_ops is a "struct security_operations" which is used for
81325 * registering TOMOYO.
81326 */
81327 -static struct security_operations tomoyo_security_ops = {
81328 +static struct security_operations tomoyo_security_ops __read_only = {
81329 .name = "tomoyo",
81330 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81331 .cred_prepare = tomoyo_cred_prepare,
81332 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81333 index 51d6709..1f3dbe2 100644
81334 --- a/security/yama/Kconfig
81335 +++ b/security/yama/Kconfig
81336 @@ -1,6 +1,6 @@
81337 config SECURITY_YAMA
81338 bool "Yama support"
81339 - depends on SECURITY
81340 + depends on SECURITY && !GRKERNSEC
81341 select SECURITYFS
81342 select SECURITY_PATH
81343 default n
81344 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81345 index 4cedc69..e59d8a3 100644
81346 --- a/sound/aoa/codecs/onyx.c
81347 +++ b/sound/aoa/codecs/onyx.c
81348 @@ -54,7 +54,7 @@ struct onyx {
81349 spdif_locked:1,
81350 analog_locked:1,
81351 original_mute:2;
81352 - int open_count;
81353 + local_t open_count;
81354 struct codec_info *codec_info;
81355
81356 /* mutex serializes concurrent access to the device
81357 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81358 struct onyx *onyx = cii->codec_data;
81359
81360 mutex_lock(&onyx->mutex);
81361 - onyx->open_count++;
81362 + local_inc(&onyx->open_count);
81363 mutex_unlock(&onyx->mutex);
81364
81365 return 0;
81366 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81367 struct onyx *onyx = cii->codec_data;
81368
81369 mutex_lock(&onyx->mutex);
81370 - onyx->open_count--;
81371 - if (!onyx->open_count)
81372 + if (local_dec_and_test(&onyx->open_count))
81373 onyx->spdif_locked = onyx->analog_locked = 0;
81374 mutex_unlock(&onyx->mutex);
81375
81376 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81377 index ffd2025..df062c9 100644
81378 --- a/sound/aoa/codecs/onyx.h
81379 +++ b/sound/aoa/codecs/onyx.h
81380 @@ -11,6 +11,7 @@
81381 #include <linux/i2c.h>
81382 #include <asm/pmac_low_i2c.h>
81383 #include <asm/prom.h>
81384 +#include <asm/local.h>
81385
81386 /* PCM3052 register definitions */
81387
81388 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81389 index 08fde00..0bf641a 100644
81390 --- a/sound/core/oss/pcm_oss.c
81391 +++ b/sound/core/oss/pcm_oss.c
81392 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81393 if (in_kernel) {
81394 mm_segment_t fs;
81395 fs = snd_enter_user();
81396 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81397 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81398 snd_leave_user(fs);
81399 } else {
81400 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81401 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81402 }
81403 if (ret != -EPIPE && ret != -ESTRPIPE)
81404 break;
81405 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81406 if (in_kernel) {
81407 mm_segment_t fs;
81408 fs = snd_enter_user();
81409 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81410 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81411 snd_leave_user(fs);
81412 } else {
81413 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81414 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81415 }
81416 if (ret == -EPIPE) {
81417 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81418 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81419 struct snd_pcm_plugin_channel *channels;
81420 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81421 if (!in_kernel) {
81422 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81423 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81424 return -EFAULT;
81425 buf = runtime->oss.buffer;
81426 }
81427 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81428 }
81429 } else {
81430 tmp = snd_pcm_oss_write2(substream,
81431 - (const char __force *)buf,
81432 + (const char __force_kernel *)buf,
81433 runtime->oss.period_bytes, 0);
81434 if (tmp <= 0)
81435 goto err;
81436 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81437 struct snd_pcm_runtime *runtime = substream->runtime;
81438 snd_pcm_sframes_t frames, frames1;
81439 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81440 - char __user *final_dst = (char __force __user *)buf;
81441 + char __user *final_dst = (char __force_user *)buf;
81442 if (runtime->oss.plugin_first) {
81443 struct snd_pcm_plugin_channel *channels;
81444 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81445 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81446 xfer += tmp;
81447 runtime->oss.buffer_used -= tmp;
81448 } else {
81449 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81450 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81451 runtime->oss.period_bytes, 0);
81452 if (tmp <= 0)
81453 goto err;
81454 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81455 size1);
81456 size1 /= runtime->channels; /* frames */
81457 fs = snd_enter_user();
81458 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81459 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81460 snd_leave_user(fs);
81461 }
81462 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81463 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81464 index 91cdf94..4085161 100644
81465 --- a/sound/core/pcm_compat.c
81466 +++ b/sound/core/pcm_compat.c
81467 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81468 int err;
81469
81470 fs = snd_enter_user();
81471 - err = snd_pcm_delay(substream, &delay);
81472 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81473 snd_leave_user(fs);
81474 if (err < 0)
81475 return err;
81476 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81477 index 53b5ada..2db94c8 100644
81478 --- a/sound/core/pcm_native.c
81479 +++ b/sound/core/pcm_native.c
81480 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81481 switch (substream->stream) {
81482 case SNDRV_PCM_STREAM_PLAYBACK:
81483 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81484 - (void __user *)arg);
81485 + (void __force_user *)arg);
81486 break;
81487 case SNDRV_PCM_STREAM_CAPTURE:
81488 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81489 - (void __user *)arg);
81490 + (void __force_user *)arg);
81491 break;
81492 default:
81493 result = -EINVAL;
81494 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81495 index 5cf8d65..912a79c 100644
81496 --- a/sound/core/seq/seq_device.c
81497 +++ b/sound/core/seq/seq_device.c
81498 @@ -64,7 +64,7 @@ struct ops_list {
81499 int argsize; /* argument size */
81500
81501 /* operators */
81502 - struct snd_seq_dev_ops ops;
81503 + struct snd_seq_dev_ops *ops;
81504
81505 /* registred devices */
81506 struct list_head dev_list; /* list of devices */
81507 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81508
81509 mutex_lock(&ops->reg_mutex);
81510 /* copy driver operators */
81511 - ops->ops = *entry;
81512 + ops->ops = entry;
81513 ops->driver |= DRIVER_LOADED;
81514 ops->argsize = argsize;
81515
81516 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81517 dev->name, ops->id, ops->argsize, dev->argsize);
81518 return -EINVAL;
81519 }
81520 - if (ops->ops.init_device(dev) >= 0) {
81521 + if (ops->ops->init_device(dev) >= 0) {
81522 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81523 ops->num_init_devices++;
81524 } else {
81525 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81526 dev->name, ops->id, ops->argsize, dev->argsize);
81527 return -EINVAL;
81528 }
81529 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81530 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81531 dev->status = SNDRV_SEQ_DEVICE_FREE;
81532 dev->driver_data = NULL;
81533 ops->num_init_devices--;
81534 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81535 index 2d5514b..3afae9c 100644
81536 --- a/sound/drivers/mts64.c
81537 +++ b/sound/drivers/mts64.c
81538 @@ -29,6 +29,7 @@
81539 #include <sound/initval.h>
81540 #include <sound/rawmidi.h>
81541 #include <sound/control.h>
81542 +#include <asm/local.h>
81543
81544 #define CARD_NAME "Miditerminal 4140"
81545 #define DRIVER_NAME "MTS64"
81546 @@ -67,7 +68,7 @@ struct mts64 {
81547 struct pardevice *pardev;
81548 int pardev_claimed;
81549
81550 - int open_count;
81551 + local_t open_count;
81552 int current_midi_output_port;
81553 int current_midi_input_port;
81554 u8 mode[MTS64_NUM_INPUT_PORTS];
81555 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81556 {
81557 struct mts64 *mts = substream->rmidi->private_data;
81558
81559 - if (mts->open_count == 0) {
81560 + if (local_read(&mts->open_count) == 0) {
81561 /* We don't need a spinlock here, because this is just called
81562 if the device has not been opened before.
81563 So there aren't any IRQs from the device */
81564 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81565
81566 msleep(50);
81567 }
81568 - ++(mts->open_count);
81569 + local_inc(&mts->open_count);
81570
81571 return 0;
81572 }
81573 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81574 struct mts64 *mts = substream->rmidi->private_data;
81575 unsigned long flags;
81576
81577 - --(mts->open_count);
81578 - if (mts->open_count == 0) {
81579 + if (local_dec_return(&mts->open_count) == 0) {
81580 /* We need the spinlock_irqsave here because we can still
81581 have IRQs at this point */
81582 spin_lock_irqsave(&mts->lock, flags);
81583 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81584
81585 msleep(500);
81586
81587 - } else if (mts->open_count < 0)
81588 - mts->open_count = 0;
81589 + } else if (local_read(&mts->open_count) < 0)
81590 + local_set(&mts->open_count, 0);
81591
81592 return 0;
81593 }
81594 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81595 index b953fb4..1999c01 100644
81596 --- a/sound/drivers/opl4/opl4_lib.c
81597 +++ b/sound/drivers/opl4/opl4_lib.c
81598 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81599 MODULE_DESCRIPTION("OPL4 driver");
81600 MODULE_LICENSE("GPL");
81601
81602 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81603 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81604 {
81605 int timeout = 10;
81606 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81607 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81608 index 8364855..59f2e2b 100644
81609 --- a/sound/drivers/portman2x4.c
81610 +++ b/sound/drivers/portman2x4.c
81611 @@ -48,6 +48,7 @@
81612 #include <sound/initval.h>
81613 #include <sound/rawmidi.h>
81614 #include <sound/control.h>
81615 +#include <asm/local.h>
81616
81617 #define CARD_NAME "Portman 2x4"
81618 #define DRIVER_NAME "portman"
81619 @@ -85,7 +86,7 @@ struct portman {
81620 struct pardevice *pardev;
81621 int pardev_claimed;
81622
81623 - int open_count;
81624 + local_t open_count;
81625 int mode[PORTMAN_NUM_INPUT_PORTS];
81626 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81627 };
81628 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81629 index ea995af..f1bfa37 100644
81630 --- a/sound/firewire/amdtp.c
81631 +++ b/sound/firewire/amdtp.c
81632 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81633 ptr = s->pcm_buffer_pointer + data_blocks;
81634 if (ptr >= pcm->runtime->buffer_size)
81635 ptr -= pcm->runtime->buffer_size;
81636 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81637 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81638
81639 s->pcm_period_pointer += data_blocks;
81640 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81641 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
81642 */
81643 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81644 {
81645 - ACCESS_ONCE(s->source_node_id_field) =
81646 + ACCESS_ONCE_RW(s->source_node_id_field) =
81647 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81648 }
81649 EXPORT_SYMBOL(amdtp_out_stream_update);
81650 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81651 index b680c5e..061b7a0 100644
81652 --- a/sound/firewire/amdtp.h
81653 +++ b/sound/firewire/amdtp.h
81654 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
81655 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81656 struct snd_pcm_substream *pcm)
81657 {
81658 - ACCESS_ONCE(s->pcm) = pcm;
81659 + ACCESS_ONCE_RW(s->pcm) = pcm;
81660 }
81661
81662 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
81663 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81664 index d428ffe..751ef78 100644
81665 --- a/sound/firewire/isight.c
81666 +++ b/sound/firewire/isight.c
81667 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81668 ptr += count;
81669 if (ptr >= runtime->buffer_size)
81670 ptr -= runtime->buffer_size;
81671 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81672 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81673
81674 isight->period_counter += count;
81675 if (isight->period_counter >= runtime->period_size) {
81676 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81677 if (err < 0)
81678 return err;
81679
81680 - ACCESS_ONCE(isight->pcm_active) = true;
81681 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81682
81683 return 0;
81684 }
81685 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81686 {
81687 struct isight *isight = substream->private_data;
81688
81689 - ACCESS_ONCE(isight->pcm_active) = false;
81690 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81691
81692 mutex_lock(&isight->mutex);
81693 isight_stop_streaming(isight);
81694 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81695
81696 switch (cmd) {
81697 case SNDRV_PCM_TRIGGER_START:
81698 - ACCESS_ONCE(isight->pcm_running) = true;
81699 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81700 break;
81701 case SNDRV_PCM_TRIGGER_STOP:
81702 - ACCESS_ONCE(isight->pcm_running) = false;
81703 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81704 break;
81705 default:
81706 return -EINVAL;
81707 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81708 index 7bd5e33..1fcab12 100644
81709 --- a/sound/isa/cmi8330.c
81710 +++ b/sound/isa/cmi8330.c
81711 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81712
81713 struct snd_pcm *pcm;
81714 struct snd_cmi8330_stream {
81715 - struct snd_pcm_ops ops;
81716 + snd_pcm_ops_no_const ops;
81717 snd_pcm_open_callback_t open;
81718 void *private_data; /* sb or wss */
81719 } streams[2];
81720 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81721 index b2b3c01..e1c1e1f 100644
81722 --- a/sound/oss/sb_audio.c
81723 +++ b/sound/oss/sb_audio.c
81724 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
81725 buf16 = (signed short *)(localbuf + localoffs);
81726 while (c)
81727 {
81728 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81729 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81730 if (copy_from_user(lbuf8,
81731 userbuf+useroffs + p,
81732 locallen))
81733 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81734 index 7d8803a..559f8d0 100644
81735 --- a/sound/oss/swarm_cs4297a.c
81736 +++ b/sound/oss/swarm_cs4297a.c
81737 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
81738 {
81739 struct cs4297a_state *s;
81740 u32 pwr, id;
81741 - mm_segment_t fs;
81742 int rval;
81743 #ifndef CONFIG_BCM_CS4297A_CSWARM
81744 u64 cfg;
81745 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
81746 if (!rval) {
81747 char *sb1250_duart_present;
81748
81749 +#if 0
81750 + mm_segment_t fs;
81751 fs = get_fs();
81752 set_fs(KERNEL_DS);
81753 -#if 0
81754 val = SOUND_MASK_LINE;
81755 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81756 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81757 val = initvol[i].vol;
81758 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81759 }
81760 + set_fs(fs);
81761 // cs4297a_write_ac97(s, 0x18, 0x0808);
81762 #else
81763 // cs4297a_write_ac97(s, 0x5e, 0x180);
81764 cs4297a_write_ac97(s, 0x02, 0x0808);
81765 cs4297a_write_ac97(s, 0x18, 0x0808);
81766 #endif
81767 - set_fs(fs);
81768
81769 list_add(&s->list, &cs4297a_devs);
81770
81771 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81772 index e5a7e19..4049063 100644
81773 --- a/sound/pci/hda/hda_codec.h
81774 +++ b/sound/pci/hda/hda_codec.h
81775 @@ -614,7 +614,7 @@ struct hda_bus_ops {
81776 /* notify power-up/down from codec to controller */
81777 void (*pm_notify)(struct hda_bus *bus);
81778 #endif
81779 -};
81780 +} __no_const;
81781
81782 /* template to pass to the bus constructor */
81783 struct hda_bus_template {
81784 @@ -714,6 +714,7 @@ struct hda_codec_ops {
81785 #endif
81786 void (*reboot_notify)(struct hda_codec *codec);
81787 };
81788 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81789
81790 /* record for amp information cache */
81791 struct hda_cache_head {
81792 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
81793 struct snd_pcm_substream *substream);
81794 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81795 struct snd_pcm_substream *substream);
81796 -};
81797 +} __no_const;
81798
81799 /* PCM information for each substream */
81800 struct hda_pcm_stream {
81801 @@ -802,7 +803,7 @@ struct hda_codec {
81802 const char *modelname; /* model name for preset */
81803
81804 /* set by patch */
81805 - struct hda_codec_ops patch_ops;
81806 + hda_codec_ops_no_const patch_ops;
81807
81808 /* PCM to create, set by patch_ops.build_pcms callback */
81809 unsigned int num_pcms;
81810 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81811 index 0da778a..bc38b84 100644
81812 --- a/sound/pci/ice1712/ice1712.h
81813 +++ b/sound/pci/ice1712/ice1712.h
81814 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81815 unsigned int mask_flags; /* total mask bits */
81816 struct snd_akm4xxx_ops {
81817 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81818 - } ops;
81819 + } __no_const ops;
81820 };
81821
81822 struct snd_ice1712_spdif {
81823 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81824 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81825 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81826 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81827 - } ops;
81828 + } __no_const ops;
81829 };
81830
81831
81832 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
81833 index bddc405..2c0733c 100644
81834 --- a/sound/pci/ymfpci/ymfpci.h
81835 +++ b/sound/pci/ymfpci/ymfpci.h
81836 @@ -358,7 +358,7 @@ struct snd_ymfpci {
81837 spinlock_t reg_lock;
81838 spinlock_t voice_lock;
81839 wait_queue_head_t interrupt_sleep;
81840 - atomic_t interrupt_sleep_count;
81841 + atomic_unchecked_t interrupt_sleep_count;
81842 struct snd_info_entry *proc_entry;
81843 const struct firmware *dsp_microcode;
81844 const struct firmware *controller_microcode;
81845 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81846 index 62b2363..ee77972 100644
81847 --- a/sound/pci/ymfpci/ymfpci_main.c
81848 +++ b/sound/pci/ymfpci/ymfpci_main.c
81849 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81850 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81851 break;
81852 }
81853 - if (atomic_read(&chip->interrupt_sleep_count)) {
81854 - atomic_set(&chip->interrupt_sleep_count, 0);
81855 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81856 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81857 wake_up(&chip->interrupt_sleep);
81858 }
81859 __end:
81860 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81861 continue;
81862 init_waitqueue_entry(&wait, current);
81863 add_wait_queue(&chip->interrupt_sleep, &wait);
81864 - atomic_inc(&chip->interrupt_sleep_count);
81865 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81866 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81867 remove_wait_queue(&chip->interrupt_sleep, &wait);
81868 }
81869 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81870 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81871 spin_unlock(&chip->reg_lock);
81872
81873 - if (atomic_read(&chip->interrupt_sleep_count)) {
81874 - atomic_set(&chip->interrupt_sleep_count, 0);
81875 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81876 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81877 wake_up(&chip->interrupt_sleep);
81878 }
81879 }
81880 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81881 spin_lock_init(&chip->reg_lock);
81882 spin_lock_init(&chip->voice_lock);
81883 init_waitqueue_head(&chip->interrupt_sleep);
81884 - atomic_set(&chip->interrupt_sleep_count, 0);
81885 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81886 chip->card = card;
81887 chip->pci = pci;
81888 chip->irq = -1;
81889 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
81890 new file mode 100644
81891 index 0000000..50f2f2f
81892 --- /dev/null
81893 +++ b/tools/gcc/.gitignore
81894 @@ -0,0 +1 @@
81895 +size_overflow_hash.h
81896 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81897 new file mode 100644
81898 index 0000000..1d09b7e
81899 --- /dev/null
81900 +++ b/tools/gcc/Makefile
81901 @@ -0,0 +1,43 @@
81902 +#CC := gcc
81903 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81904 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81905 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81906 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81907 +
81908 +ifeq ($(PLUGINCC),$(HOSTCC))
81909 +HOSTLIBS := hostlibs
81910 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81911 +else
81912 +HOSTLIBS := hostcxxlibs
81913 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
81914 +endif
81915 +
81916 +$(HOSTLIBS)-y := constify_plugin.so
81917 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81918 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81919 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81920 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81921 +$(HOSTLIBS)-y += colorize_plugin.so
81922 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81923 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
81924 +
81925 +always := $($(HOSTLIBS)-y)
81926 +
81927 +constify_plugin-objs := constify_plugin.o
81928 +stackleak_plugin-objs := stackleak_plugin.o
81929 +kallocstat_plugin-objs := kallocstat_plugin.o
81930 +kernexec_plugin-objs := kernexec_plugin.o
81931 +checker_plugin-objs := checker_plugin.o
81932 +colorize_plugin-objs := colorize_plugin.o
81933 +size_overflow_plugin-objs := size_overflow_plugin.o
81934 +latent_entropy_plugin-objs := latent_entropy_plugin.o
81935 +
81936 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
81937 +
81938 +quiet_cmd_build_size_overflow_hash = GENHASH $@
81939 + cmd_build_size_overflow_hash = \
81940 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
81941 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
81942 + $(call if_changed,build_size_overflow_hash)
81943 +
81944 +targets += size_overflow_hash.h
81945 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81946 new file mode 100644
81947 index 0000000..d41b5af
81948 --- /dev/null
81949 +++ b/tools/gcc/checker_plugin.c
81950 @@ -0,0 +1,171 @@
81951 +/*
81952 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81953 + * Licensed under the GPL v2
81954 + *
81955 + * Note: the choice of the license means that the compilation process is
81956 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81957 + * but for the kernel it doesn't matter since it doesn't link against
81958 + * any of the gcc libraries
81959 + *
81960 + * gcc plugin to implement various sparse (source code checker) features
81961 + *
81962 + * TODO:
81963 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81964 + *
81965 + * BUGS:
81966 + * - none known
81967 + */
81968 +#include "gcc-plugin.h"
81969 +#include "config.h"
81970 +#include "system.h"
81971 +#include "coretypes.h"
81972 +#include "tree.h"
81973 +#include "tree-pass.h"
81974 +#include "flags.h"
81975 +#include "intl.h"
81976 +#include "toplev.h"
81977 +#include "plugin.h"
81978 +//#include "expr.h" where are you...
81979 +#include "diagnostic.h"
81980 +#include "plugin-version.h"
81981 +#include "tm.h"
81982 +#include "function.h"
81983 +#include "basic-block.h"
81984 +#include "gimple.h"
81985 +#include "rtl.h"
81986 +#include "emit-rtl.h"
81987 +#include "tree-flow.h"
81988 +#include "target.h"
81989 +
81990 +extern void c_register_addr_space (const char *str, addr_space_t as);
81991 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
81992 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
81993 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
81994 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
81995 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
81996 +
81997 +extern void print_gimple_stmt(FILE *, gimple, int, int);
81998 +extern rtx emit_move_insn(rtx x, rtx y);
81999 +
82000 +int plugin_is_GPL_compatible;
82001 +
82002 +static struct plugin_info checker_plugin_info = {
82003 + .version = "201111150100",
82004 +};
82005 +
82006 +#define ADDR_SPACE_KERNEL 0
82007 +#define ADDR_SPACE_FORCE_KERNEL 1
82008 +#define ADDR_SPACE_USER 2
82009 +#define ADDR_SPACE_FORCE_USER 3
82010 +#define ADDR_SPACE_IOMEM 0
82011 +#define ADDR_SPACE_FORCE_IOMEM 0
82012 +#define ADDR_SPACE_PERCPU 0
82013 +#define ADDR_SPACE_FORCE_PERCPU 0
82014 +#define ADDR_SPACE_RCU 0
82015 +#define ADDR_SPACE_FORCE_RCU 0
82016 +
82017 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82018 +{
82019 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82020 +}
82021 +
82022 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82023 +{
82024 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82025 +}
82026 +
82027 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82028 +{
82029 + return default_addr_space_valid_pointer_mode(mode, as);
82030 +}
82031 +
82032 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82033 +{
82034 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82035 +}
82036 +
82037 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82038 +{
82039 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82040 +}
82041 +
82042 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82043 +{
82044 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82045 + return true;
82046 +
82047 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82048 + return true;
82049 +
82050 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82051 + return true;
82052 +
82053 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82054 + return true;
82055 +
82056 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82057 + return true;
82058 +
82059 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82060 + return true;
82061 +
82062 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82063 + return true;
82064 +
82065 + return subset == superset;
82066 +}
82067 +
82068 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82069 +{
82070 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82071 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82072 +
82073 + return op;
82074 +}
82075 +
82076 +static void register_checker_address_spaces(void *event_data, void *data)
82077 +{
82078 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82079 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82080 + c_register_addr_space("__user", ADDR_SPACE_USER);
82081 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82082 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82083 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82084 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82085 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82086 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82087 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82088 +
82089 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82090 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82091 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82092 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82093 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82094 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82095 + targetm.addr_space.convert = checker_addr_space_convert;
82096 +}
82097 +
82098 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82099 +{
82100 + const char * const plugin_name = plugin_info->base_name;
82101 + const int argc = plugin_info->argc;
82102 + const struct plugin_argument * const argv = plugin_info->argv;
82103 + int i;
82104 +
82105 + if (!plugin_default_version_check(version, &gcc_version)) {
82106 + error(G_("incompatible gcc/plugin versions"));
82107 + return 1;
82108 + }
82109 +
82110 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82111 +
82112 + for (i = 0; i < argc; ++i)
82113 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82114 +
82115 + if (TARGET_64BIT == 0)
82116 + return 0;
82117 +
82118 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82119 +
82120 + return 0;
82121 +}
82122 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82123 new file mode 100644
82124 index 0000000..846aeb0
82125 --- /dev/null
82126 +++ b/tools/gcc/colorize_plugin.c
82127 @@ -0,0 +1,148 @@
82128 +/*
82129 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82130 + * Licensed under the GPL v2
82131 + *
82132 + * Note: the choice of the license means that the compilation process is
82133 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82134 + * but for the kernel it doesn't matter since it doesn't link against
82135 + * any of the gcc libraries
82136 + *
82137 + * gcc plugin to colorize diagnostic output
82138 + *
82139 + */
82140 +
82141 +#include "gcc-plugin.h"
82142 +#include "config.h"
82143 +#include "system.h"
82144 +#include "coretypes.h"
82145 +#include "tree.h"
82146 +#include "tree-pass.h"
82147 +#include "flags.h"
82148 +#include "intl.h"
82149 +#include "toplev.h"
82150 +#include "plugin.h"
82151 +#include "diagnostic.h"
82152 +#include "plugin-version.h"
82153 +#include "tm.h"
82154 +
82155 +int plugin_is_GPL_compatible;
82156 +
82157 +static struct plugin_info colorize_plugin_info = {
82158 + .version = "201203092200",
82159 + .help = NULL,
82160 +};
82161 +
82162 +#define GREEN "\033[32m\033[2m"
82163 +#define LIGHTGREEN "\033[32m\033[1m"
82164 +#define YELLOW "\033[33m\033[2m"
82165 +#define LIGHTYELLOW "\033[33m\033[1m"
82166 +#define RED "\033[31m\033[2m"
82167 +#define LIGHTRED "\033[31m\033[1m"
82168 +#define BLUE "\033[34m\033[2m"
82169 +#define LIGHTBLUE "\033[34m\033[1m"
82170 +#define BRIGHT "\033[m\033[1m"
82171 +#define NORMAL "\033[m"
82172 +
82173 +static diagnostic_starter_fn old_starter;
82174 +static diagnostic_finalizer_fn old_finalizer;
82175 +
82176 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82177 +{
82178 + const char *color;
82179 + char *newprefix;
82180 +
82181 + switch (diagnostic->kind) {
82182 + case DK_NOTE:
82183 + color = LIGHTBLUE;
82184 + break;
82185 +
82186 + case DK_PEDWARN:
82187 + case DK_WARNING:
82188 + color = LIGHTYELLOW;
82189 + break;
82190 +
82191 + case DK_ERROR:
82192 + case DK_FATAL:
82193 + case DK_ICE:
82194 + case DK_PERMERROR:
82195 + case DK_SORRY:
82196 + color = LIGHTRED;
82197 + break;
82198 +
82199 + default:
82200 + color = NORMAL;
82201 + }
82202 +
82203 + old_starter(context, diagnostic);
82204 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82205 + return;
82206 + pp_destroy_prefix(context->printer);
82207 + pp_set_prefix(context->printer, newprefix);
82208 +}
82209 +
82210 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82211 +{
82212 + old_finalizer(context, diagnostic);
82213 +}
82214 +
82215 +static void colorize_arm(void)
82216 +{
82217 + old_starter = diagnostic_starter(global_dc);
82218 + old_finalizer = diagnostic_finalizer(global_dc);
82219 +
82220 + diagnostic_starter(global_dc) = start_colorize;
82221 + diagnostic_finalizer(global_dc) = finalize_colorize;
82222 +}
82223 +
82224 +static unsigned int execute_colorize_rearm(void)
82225 +{
82226 + if (diagnostic_starter(global_dc) == start_colorize)
82227 + return 0;
82228 +
82229 + colorize_arm();
82230 + return 0;
82231 +}
82232 +
82233 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82234 + .pass = {
82235 + .type = SIMPLE_IPA_PASS,
82236 + .name = "colorize_rearm",
82237 + .gate = NULL,
82238 + .execute = execute_colorize_rearm,
82239 + .sub = NULL,
82240 + .next = NULL,
82241 + .static_pass_number = 0,
82242 + .tv_id = TV_NONE,
82243 + .properties_required = 0,
82244 + .properties_provided = 0,
82245 + .properties_destroyed = 0,
82246 + .todo_flags_start = 0,
82247 + .todo_flags_finish = 0
82248 + }
82249 +};
82250 +
82251 +static void colorize_start_unit(void *gcc_data, void *user_data)
82252 +{
82253 + colorize_arm();
82254 +}
82255 +
82256 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82257 +{
82258 + const char * const plugin_name = plugin_info->base_name;
82259 + struct register_pass_info colorize_rearm_pass_info = {
82260 + .pass = &pass_ipa_colorize_rearm.pass,
82261 + .reference_pass_name = "*free_lang_data",
82262 + .ref_pass_instance_number = 1,
82263 + .pos_op = PASS_POS_INSERT_AFTER
82264 + };
82265 +
82266 + if (!plugin_default_version_check(version, &gcc_version)) {
82267 + error(G_("incompatible gcc/plugin versions"));
82268 + return 1;
82269 + }
82270 +
82271 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82272 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82273 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82274 + return 0;
82275 +}
82276 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82277 new file mode 100644
82278 index 0000000..92ed719
82279 --- /dev/null
82280 +++ b/tools/gcc/constify_plugin.c
82281 @@ -0,0 +1,331 @@
82282 +/*
82283 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82284 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82285 + * Licensed under the GPL v2, or (at your option) v3
82286 + *
82287 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82288 + *
82289 + * Homepage:
82290 + * http://www.grsecurity.net/~ephox/const_plugin/
82291 + *
82292 + * Usage:
82293 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82294 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82295 + */
82296 +
82297 +#include "gcc-plugin.h"
82298 +#include "config.h"
82299 +#include "system.h"
82300 +#include "coretypes.h"
82301 +#include "tree.h"
82302 +#include "tree-pass.h"
82303 +#include "flags.h"
82304 +#include "intl.h"
82305 +#include "toplev.h"
82306 +#include "plugin.h"
82307 +#include "diagnostic.h"
82308 +#include "plugin-version.h"
82309 +#include "tm.h"
82310 +#include "function.h"
82311 +#include "basic-block.h"
82312 +#include "gimple.h"
82313 +#include "rtl.h"
82314 +#include "emit-rtl.h"
82315 +#include "tree-flow.h"
82316 +
82317 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82318 +
82319 +int plugin_is_GPL_compatible;
82320 +
82321 +static struct plugin_info const_plugin_info = {
82322 + .version = "201205300030",
82323 + .help = "no-constify\tturn off constification\n",
82324 +};
82325 +
82326 +static void deconstify_tree(tree node);
82327 +
82328 +static void deconstify_type(tree type)
82329 +{
82330 + tree field;
82331 +
82332 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82333 + tree type = TREE_TYPE(field);
82334 +
82335 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82336 + continue;
82337 + if (!TYPE_READONLY(type))
82338 + continue;
82339 +
82340 + deconstify_tree(field);
82341 + }
82342 + TYPE_READONLY(type) = 0;
82343 + C_TYPE_FIELDS_READONLY(type) = 0;
82344 +}
82345 +
82346 +static void deconstify_tree(tree node)
82347 +{
82348 + tree old_type, new_type, field;
82349 +
82350 + old_type = TREE_TYPE(node);
82351 +
82352 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82353 +
82354 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82355 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82356 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82357 + DECL_FIELD_CONTEXT(field) = new_type;
82358 +
82359 + deconstify_type(new_type);
82360 +
82361 + TREE_READONLY(node) = 0;
82362 + TREE_TYPE(node) = new_type;
82363 +}
82364 +
82365 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82366 +{
82367 + tree type;
82368 +
82369 + *no_add_attrs = true;
82370 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82371 + error("%qE attribute does not apply to functions", name);
82372 + return NULL_TREE;
82373 + }
82374 +
82375 + if (TREE_CODE(*node) == VAR_DECL) {
82376 + error("%qE attribute does not apply to variables", name);
82377 + return NULL_TREE;
82378 + }
82379 +
82380 + if (TYPE_P(*node)) {
82381 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82382 + *no_add_attrs = false;
82383 + else
82384 + error("%qE attribute applies to struct and union types only", name);
82385 + return NULL_TREE;
82386 + }
82387 +
82388 + type = TREE_TYPE(*node);
82389 +
82390 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82391 + error("%qE attribute applies to struct and union types only", name);
82392 + return NULL_TREE;
82393 + }
82394 +
82395 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82396 + error("%qE attribute is already applied to the type", name);
82397 + return NULL_TREE;
82398 + }
82399 +
82400 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82401 + error("%qE attribute used on type that is not constified", name);
82402 + return NULL_TREE;
82403 + }
82404 +
82405 + if (TREE_CODE(*node) == TYPE_DECL) {
82406 + deconstify_tree(*node);
82407 + return NULL_TREE;
82408 + }
82409 +
82410 + return NULL_TREE;
82411 +}
82412 +
82413 +static void constify_type(tree type)
82414 +{
82415 + TYPE_READONLY(type) = 1;
82416 + C_TYPE_FIELDS_READONLY(type) = 1;
82417 +}
82418 +
82419 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82420 +{
82421 + *no_add_attrs = true;
82422 + if (!TYPE_P(*node)) {
82423 + error("%qE attribute applies to types only", name);
82424 + return NULL_TREE;
82425 + }
82426 +
82427 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82428 + error("%qE attribute applies to struct and union types only", name);
82429 + return NULL_TREE;
82430 + }
82431 +
82432 + *no_add_attrs = false;
82433 + constify_type(*node);
82434 + return NULL_TREE;
82435 +}
82436 +
82437 +static struct attribute_spec no_const_attr = {
82438 + .name = "no_const",
82439 + .min_length = 0,
82440 + .max_length = 0,
82441 + .decl_required = false,
82442 + .type_required = false,
82443 + .function_type_required = false,
82444 + .handler = handle_no_const_attribute,
82445 +#if BUILDING_GCC_VERSION >= 4007
82446 + .affects_type_identity = true
82447 +#endif
82448 +};
82449 +
82450 +static struct attribute_spec do_const_attr = {
82451 + .name = "do_const",
82452 + .min_length = 0,
82453 + .max_length = 0,
82454 + .decl_required = false,
82455 + .type_required = false,
82456 + .function_type_required = false,
82457 + .handler = handle_do_const_attribute,
82458 +#if BUILDING_GCC_VERSION >= 4007
82459 + .affects_type_identity = true
82460 +#endif
82461 +};
82462 +
82463 +static void register_attributes(void *event_data, void *data)
82464 +{
82465 + register_attribute(&no_const_attr);
82466 + register_attribute(&do_const_attr);
82467 +}
82468 +
82469 +static bool is_fptr(tree field)
82470 +{
82471 + tree ptr = TREE_TYPE(field);
82472 +
82473 + if (TREE_CODE(ptr) != POINTER_TYPE)
82474 + return false;
82475 +
82476 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82477 +}
82478 +
82479 +static bool walk_struct(tree node)
82480 +{
82481 + tree field;
82482 +
82483 + if (TYPE_FIELDS(node) == NULL_TREE)
82484 + return false;
82485 +
82486 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82487 + gcc_assert(!TYPE_READONLY(node));
82488 + deconstify_type(node);
82489 + return false;
82490 + }
82491 +
82492 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82493 + tree type = TREE_TYPE(field);
82494 + enum tree_code code = TREE_CODE(type);
82495 +
82496 + if (node == type)
82497 + return false;
82498 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82499 + if (!(walk_struct(type)))
82500 + return false;
82501 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82502 + return false;
82503 + }
82504 + return true;
82505 +}
82506 +
82507 +static void finish_type(void *event_data, void *data)
82508 +{
82509 + tree type = (tree)event_data;
82510 +
82511 + if (type == NULL_TREE || type == error_mark_node)
82512 + return;
82513 +
82514 + if (TYPE_READONLY(type))
82515 + return;
82516 +
82517 + if (walk_struct(type))
82518 + constify_type(type);
82519 +}
82520 +
82521 +static unsigned int check_local_variables(void);
82522 +
82523 +struct gimple_opt_pass pass_local_variable = {
82524 + {
82525 + .type = GIMPLE_PASS,
82526 + .name = "check_local_variables",
82527 + .gate = NULL,
82528 + .execute = check_local_variables,
82529 + .sub = NULL,
82530 + .next = NULL,
82531 + .static_pass_number = 0,
82532 + .tv_id = TV_NONE,
82533 + .properties_required = 0,
82534 + .properties_provided = 0,
82535 + .properties_destroyed = 0,
82536 + .todo_flags_start = 0,
82537 + .todo_flags_finish = 0
82538 + }
82539 +};
82540 +
82541 +static unsigned int check_local_variables(void)
82542 +{
82543 + tree var;
82544 + referenced_var_iterator rvi;
82545 +
82546 +#if BUILDING_GCC_VERSION == 4005
82547 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82548 +#else
82549 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82550 +#endif
82551 + tree type = TREE_TYPE(var);
82552 +
82553 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82554 + continue;
82555 +
82556 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82557 + continue;
82558 +
82559 + if (!TYPE_READONLY(type))
82560 + continue;
82561 +
82562 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82563 +// continue;
82564 +
82565 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82566 +// continue;
82567 +
82568 + if (walk_struct(type)) {
82569 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82570 + return 1;
82571 + }
82572 + }
82573 + return 0;
82574 +}
82575 +
82576 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82577 +{
82578 + const char * const plugin_name = plugin_info->base_name;
82579 + const int argc = plugin_info->argc;
82580 + const struct plugin_argument * const argv = plugin_info->argv;
82581 + int i;
82582 + bool constify = true;
82583 +
82584 + struct register_pass_info local_variable_pass_info = {
82585 + .pass = &pass_local_variable.pass,
82586 + .reference_pass_name = "*referenced_vars",
82587 + .ref_pass_instance_number = 1,
82588 + .pos_op = PASS_POS_INSERT_AFTER
82589 + };
82590 +
82591 + if (!plugin_default_version_check(version, &gcc_version)) {
82592 + error(G_("incompatible gcc/plugin versions"));
82593 + return 1;
82594 + }
82595 +
82596 + for (i = 0; i < argc; ++i) {
82597 + if (!(strcmp(argv[i].key, "no-constify"))) {
82598 + constify = false;
82599 + continue;
82600 + }
82601 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82602 + }
82603 +
82604 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82605 + if (constify) {
82606 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82607 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82608 + }
82609 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82610 +
82611 + return 0;
82612 +}
82613 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82614 new file mode 100644
82615 index 0000000..02c6bec
82616 --- /dev/null
82617 +++ b/tools/gcc/generate_size_overflow_hash.sh
82618 @@ -0,0 +1,94 @@
82619 +#!/bin/bash
82620 +
82621 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82622 +
82623 +header1="size_overflow_hash.h"
82624 +database="size_overflow_hash.data"
82625 +n=65536
82626 +
82627 +usage() {
82628 +cat <<EOF
82629 +usage: $0 options
82630 +OPTIONS:
82631 + -h|--help help
82632 + -o header file
82633 + -d database file
82634 + -n hash array size
82635 +EOF
82636 + return 0
82637 +}
82638 +
82639 +while true
82640 +do
82641 + case "$1" in
82642 + -h|--help) usage && exit 0;;
82643 + -n) n=$2; shift 2;;
82644 + -o) header1="$2"; shift 2;;
82645 + -d) database="$2"; shift 2;;
82646 + --) shift 1; break ;;
82647 + *) break ;;
82648 + esac
82649 +done
82650 +
82651 +create_defines() {
82652 + for i in `seq 1 32`
82653 + do
82654 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
82655 + done
82656 + echo >> "$header1"
82657 +}
82658 +
82659 +create_structs () {
82660 + rm -f "$header1"
82661 +
82662 + create_defines
82663 +
82664 + cat "$database" | while read data
82665 + do
82666 + data_array=($data)
82667 + struct_hash_name="${data_array[0]}"
82668 + funcn="${data_array[1]}"
82669 + params="${data_array[2]}"
82670 + next="${data_array[5]}"
82671 +
82672 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
82673 +
82674 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
82675 + echo -en "\t.param\t= " >> "$header1"
82676 + line=
82677 + for param_num in ${params//-/ };
82678 + do
82679 + line="${line}PARAM"$param_num"|"
82680 + done
82681 +
82682 + echo -e "${line%?},\n};\n" >> "$header1"
82683 + done
82684 +}
82685 +
82686 +create_headers () {
82687 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
82688 +}
82689 +
82690 +create_array_elements () {
82691 + index=0
82692 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
82693 + do
82694 + data_array=($data)
82695 + i="${data_array[3]}"
82696 + hash="${data_array[4]}"
82697 + while [[ $index -lt $i ]]
82698 + do
82699 + echo -e "\t["$index"]\t= NULL," >> "$header1"
82700 + index=$(($index + 1))
82701 + done
82702 + index=$(($index + 1))
82703 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
82704 + done
82705 + echo '};' >> $header1
82706 +}
82707 +
82708 +create_structs
82709 +create_headers
82710 +create_array_elements
82711 +
82712 +exit 0
82713 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82714 new file mode 100644
82715 index 0000000..a86e422
82716 --- /dev/null
82717 +++ b/tools/gcc/kallocstat_plugin.c
82718 @@ -0,0 +1,167 @@
82719 +/*
82720 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82721 + * Licensed under the GPL v2
82722 + *
82723 + * Note: the choice of the license means that the compilation process is
82724 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82725 + * but for the kernel it doesn't matter since it doesn't link against
82726 + * any of the gcc libraries
82727 + *
82728 + * gcc plugin to find the distribution of k*alloc sizes
82729 + *
82730 + * TODO:
82731 + *
82732 + * BUGS:
82733 + * - none known
82734 + */
82735 +#include "gcc-plugin.h"
82736 +#include "config.h"
82737 +#include "system.h"
82738 +#include "coretypes.h"
82739 +#include "tree.h"
82740 +#include "tree-pass.h"
82741 +#include "flags.h"
82742 +#include "intl.h"
82743 +#include "toplev.h"
82744 +#include "plugin.h"
82745 +//#include "expr.h" where are you...
82746 +#include "diagnostic.h"
82747 +#include "plugin-version.h"
82748 +#include "tm.h"
82749 +#include "function.h"
82750 +#include "basic-block.h"
82751 +#include "gimple.h"
82752 +#include "rtl.h"
82753 +#include "emit-rtl.h"
82754 +
82755 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82756 +
82757 +int plugin_is_GPL_compatible;
82758 +
82759 +static const char * const kalloc_functions[] = {
82760 + "__kmalloc",
82761 + "kmalloc",
82762 + "kmalloc_large",
82763 + "kmalloc_node",
82764 + "kmalloc_order",
82765 + "kmalloc_order_trace",
82766 + "kmalloc_slab",
82767 + "kzalloc",
82768 + "kzalloc_node",
82769 +};
82770 +
82771 +static struct plugin_info kallocstat_plugin_info = {
82772 + .version = "201111150100",
82773 +};
82774 +
82775 +static unsigned int execute_kallocstat(void);
82776 +
82777 +static struct gimple_opt_pass kallocstat_pass = {
82778 + .pass = {
82779 + .type = GIMPLE_PASS,
82780 + .name = "kallocstat",
82781 + .gate = NULL,
82782 + .execute = execute_kallocstat,
82783 + .sub = NULL,
82784 + .next = NULL,
82785 + .static_pass_number = 0,
82786 + .tv_id = TV_NONE,
82787 + .properties_required = 0,
82788 + .properties_provided = 0,
82789 + .properties_destroyed = 0,
82790 + .todo_flags_start = 0,
82791 + .todo_flags_finish = 0
82792 + }
82793 +};
82794 +
82795 +static bool is_kalloc(const char *fnname)
82796 +{
82797 + size_t i;
82798 +
82799 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82800 + if (!strcmp(fnname, kalloc_functions[i]))
82801 + return true;
82802 + return false;
82803 +}
82804 +
82805 +static unsigned int execute_kallocstat(void)
82806 +{
82807 + basic_block bb;
82808 +
82809 + // 1. loop through BBs and GIMPLE statements
82810 + FOR_EACH_BB(bb) {
82811 + gimple_stmt_iterator gsi;
82812 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82813 + // gimple match:
82814 + tree fndecl, size;
82815 + gimple call_stmt;
82816 + const char *fnname;
82817 +
82818 + // is it a call
82819 + call_stmt = gsi_stmt(gsi);
82820 + if (!is_gimple_call(call_stmt))
82821 + continue;
82822 + fndecl = gimple_call_fndecl(call_stmt);
82823 + if (fndecl == NULL_TREE)
82824 + continue;
82825 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82826 + continue;
82827 +
82828 + // is it a call to k*alloc
82829 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82830 + if (!is_kalloc(fnname))
82831 + continue;
82832 +
82833 + // is the size arg the result of a simple const assignment
82834 + size = gimple_call_arg(call_stmt, 0);
82835 + while (true) {
82836 + gimple def_stmt;
82837 + expanded_location xloc;
82838 + size_t size_val;
82839 +
82840 + if (TREE_CODE(size) != SSA_NAME)
82841 + break;
82842 + def_stmt = SSA_NAME_DEF_STMT(size);
82843 + if (!def_stmt || !is_gimple_assign(def_stmt))
82844 + break;
82845 + if (gimple_num_ops(def_stmt) != 2)
82846 + break;
82847 + size = gimple_assign_rhs1(def_stmt);
82848 + if (!TREE_CONSTANT(size))
82849 + continue;
82850 + xloc = expand_location(gimple_location(def_stmt));
82851 + if (!xloc.file)
82852 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82853 + size_val = TREE_INT_CST_LOW(size);
82854 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82855 + break;
82856 + }
82857 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82858 +//debug_tree(gimple_call_fn(call_stmt));
82859 +//print_node(stderr, "pax", fndecl, 4);
82860 + }
82861 + }
82862 +
82863 + return 0;
82864 +}
82865 +
82866 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82867 +{
82868 + const char * const plugin_name = plugin_info->base_name;
82869 + struct register_pass_info kallocstat_pass_info = {
82870 + .pass = &kallocstat_pass.pass,
82871 + .reference_pass_name = "ssa",
82872 + .ref_pass_instance_number = 1,
82873 + .pos_op = PASS_POS_INSERT_AFTER
82874 + };
82875 +
82876 + if (!plugin_default_version_check(version, &gcc_version)) {
82877 + error(G_("incompatible gcc/plugin versions"));
82878 + return 1;
82879 + }
82880 +
82881 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82882 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82883 +
82884 + return 0;
82885 +}
82886 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82887 new file mode 100644
82888 index 0000000..98011fa
82889 --- /dev/null
82890 +++ b/tools/gcc/kernexec_plugin.c
82891 @@ -0,0 +1,427 @@
82892 +/*
82893 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82894 + * Licensed under the GPL v2
82895 + *
82896 + * Note: the choice of the license means that the compilation process is
82897 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82898 + * but for the kernel it doesn't matter since it doesn't link against
82899 + * any of the gcc libraries
82900 + *
82901 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82902 + *
82903 + * TODO:
82904 + *
82905 + * BUGS:
82906 + * - none known
82907 + */
82908 +#include "gcc-plugin.h"
82909 +#include "config.h"
82910 +#include "system.h"
82911 +#include "coretypes.h"
82912 +#include "tree.h"
82913 +#include "tree-pass.h"
82914 +#include "flags.h"
82915 +#include "intl.h"
82916 +#include "toplev.h"
82917 +#include "plugin.h"
82918 +//#include "expr.h" where are you...
82919 +#include "diagnostic.h"
82920 +#include "plugin-version.h"
82921 +#include "tm.h"
82922 +#include "function.h"
82923 +#include "basic-block.h"
82924 +#include "gimple.h"
82925 +#include "rtl.h"
82926 +#include "emit-rtl.h"
82927 +#include "tree-flow.h"
82928 +
82929 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82930 +extern rtx emit_move_insn(rtx x, rtx y);
82931 +
82932 +int plugin_is_GPL_compatible;
82933 +
82934 +static struct plugin_info kernexec_plugin_info = {
82935 + .version = "201111291120",
82936 + .help = "method=[bts|or]\tinstrumentation method\n"
82937 +};
82938 +
82939 +static unsigned int execute_kernexec_reload(void);
82940 +static unsigned int execute_kernexec_fptr(void);
82941 +static unsigned int execute_kernexec_retaddr(void);
82942 +static bool kernexec_cmodel_check(void);
82943 +
82944 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82945 +static void (*kernexec_instrument_retaddr)(rtx);
82946 +
82947 +static struct gimple_opt_pass kernexec_reload_pass = {
82948 + .pass = {
82949 + .type = GIMPLE_PASS,
82950 + .name = "kernexec_reload",
82951 + .gate = kernexec_cmodel_check,
82952 + .execute = execute_kernexec_reload,
82953 + .sub = NULL,
82954 + .next = NULL,
82955 + .static_pass_number = 0,
82956 + .tv_id = TV_NONE,
82957 + .properties_required = 0,
82958 + .properties_provided = 0,
82959 + .properties_destroyed = 0,
82960 + .todo_flags_start = 0,
82961 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82962 + }
82963 +};
82964 +
82965 +static struct gimple_opt_pass kernexec_fptr_pass = {
82966 + .pass = {
82967 + .type = GIMPLE_PASS,
82968 + .name = "kernexec_fptr",
82969 + .gate = kernexec_cmodel_check,
82970 + .execute = execute_kernexec_fptr,
82971 + .sub = NULL,
82972 + .next = NULL,
82973 + .static_pass_number = 0,
82974 + .tv_id = TV_NONE,
82975 + .properties_required = 0,
82976 + .properties_provided = 0,
82977 + .properties_destroyed = 0,
82978 + .todo_flags_start = 0,
82979 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82980 + }
82981 +};
82982 +
82983 +static struct rtl_opt_pass kernexec_retaddr_pass = {
82984 + .pass = {
82985 + .type = RTL_PASS,
82986 + .name = "kernexec_retaddr",
82987 + .gate = kernexec_cmodel_check,
82988 + .execute = execute_kernexec_retaddr,
82989 + .sub = NULL,
82990 + .next = NULL,
82991 + .static_pass_number = 0,
82992 + .tv_id = TV_NONE,
82993 + .properties_required = 0,
82994 + .properties_provided = 0,
82995 + .properties_destroyed = 0,
82996 + .todo_flags_start = 0,
82997 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
82998 + }
82999 +};
83000 +
83001 +static bool kernexec_cmodel_check(void)
83002 +{
83003 + tree section;
83004 +
83005 + if (ix86_cmodel != CM_KERNEL)
83006 + return false;
83007 +
83008 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83009 + if (!section || !TREE_VALUE(section))
83010 + return true;
83011 +
83012 + section = TREE_VALUE(TREE_VALUE(section));
83013 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83014 + return true;
83015 +
83016 + return false;
83017 +}
83018 +
83019 +/*
83020 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83021 + */
83022 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83023 +{
83024 + gimple asm_movabs_stmt;
83025 +
83026 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83027 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83028 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83029 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83030 + update_stmt(asm_movabs_stmt);
83031 +}
83032 +
83033 +/*
83034 + * find all asm() stmts that clobber r10 and add a reload of r10
83035 + */
83036 +static unsigned int execute_kernexec_reload(void)
83037 +{
83038 + basic_block bb;
83039 +
83040 + // 1. loop through BBs and GIMPLE statements
83041 + FOR_EACH_BB(bb) {
83042 + gimple_stmt_iterator gsi;
83043 +
83044 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83045 + // gimple match: __asm__ ("" : : : "r10");
83046 + gimple asm_stmt;
83047 + size_t nclobbers;
83048 +
83049 + // is it an asm ...
83050 + asm_stmt = gsi_stmt(gsi);
83051 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83052 + continue;
83053 +
83054 + // ... clobbering r10
83055 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83056 + while (nclobbers--) {
83057 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83058 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83059 + continue;
83060 + kernexec_reload_fptr_mask(&gsi);
83061 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83062 + break;
83063 + }
83064 + }
83065 + }
83066 +
83067 + return 0;
83068 +}
83069 +
83070 +/*
83071 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83072 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83073 + */
83074 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83075 +{
83076 + gimple assign_intptr, assign_new_fptr, call_stmt;
83077 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83078 +
83079 + call_stmt = gsi_stmt(*gsi);
83080 + old_fptr = gimple_call_fn(call_stmt);
83081 +
83082 + // create temporary unsigned long variable used for bitops and cast fptr to it
83083 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83084 + add_referenced_var(intptr);
83085 + mark_sym_for_renaming(intptr);
83086 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83087 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83088 + update_stmt(assign_intptr);
83089 +
83090 + // apply logical or to temporary unsigned long and bitmask
83091 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83092 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83093 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83094 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83095 + update_stmt(assign_intptr);
83096 +
83097 + // cast temporary unsigned long back to a temporary fptr variable
83098 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83099 + add_referenced_var(new_fptr);
83100 + mark_sym_for_renaming(new_fptr);
83101 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83102 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83103 + update_stmt(assign_new_fptr);
83104 +
83105 + // replace call stmt fn with the new fptr
83106 + gimple_call_set_fn(call_stmt, new_fptr);
83107 + update_stmt(call_stmt);
83108 +}
83109 +
83110 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83111 +{
83112 + gimple asm_or_stmt, call_stmt;
83113 + tree old_fptr, new_fptr, input, output;
83114 + VEC(tree, gc) *inputs = NULL;
83115 + VEC(tree, gc) *outputs = NULL;
83116 +
83117 + call_stmt = gsi_stmt(*gsi);
83118 + old_fptr = gimple_call_fn(call_stmt);
83119 +
83120 + // create temporary fptr variable
83121 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83122 + add_referenced_var(new_fptr);
83123 + mark_sym_for_renaming(new_fptr);
83124 +
83125 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83126 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83127 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83128 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83129 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83130 + VEC_safe_push(tree, gc, inputs, input);
83131 + VEC_safe_push(tree, gc, outputs, output);
83132 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83133 + gimple_asm_set_volatile(asm_or_stmt, true);
83134 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83135 + update_stmt(asm_or_stmt);
83136 +
83137 + // replace call stmt fn with the new fptr
83138 + gimple_call_set_fn(call_stmt, new_fptr);
83139 + update_stmt(call_stmt);
83140 +}
83141 +
83142 +/*
83143 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83144 + */
83145 +static unsigned int execute_kernexec_fptr(void)
83146 +{
83147 + basic_block bb;
83148 +
83149 + // 1. loop through BBs and GIMPLE statements
83150 + FOR_EACH_BB(bb) {
83151 + gimple_stmt_iterator gsi;
83152 +
83153 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83154 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83155 + tree fn;
83156 + gimple call_stmt;
83157 +
83158 + // is it a call ...
83159 + call_stmt = gsi_stmt(gsi);
83160 + if (!is_gimple_call(call_stmt))
83161 + continue;
83162 + fn = gimple_call_fn(call_stmt);
83163 + if (TREE_CODE(fn) == ADDR_EXPR)
83164 + continue;
83165 + if (TREE_CODE(fn) != SSA_NAME)
83166 + gcc_unreachable();
83167 +
83168 + // ... through a function pointer
83169 + fn = SSA_NAME_VAR(fn);
83170 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83171 + continue;
83172 + fn = TREE_TYPE(fn);
83173 + if (TREE_CODE(fn) != POINTER_TYPE)
83174 + continue;
83175 + fn = TREE_TYPE(fn);
83176 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83177 + continue;
83178 +
83179 + kernexec_instrument_fptr(&gsi);
83180 +
83181 +//debug_tree(gimple_call_fn(call_stmt));
83182 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83183 + }
83184 + }
83185 +
83186 + return 0;
83187 +}
83188 +
83189 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83190 +static void kernexec_instrument_retaddr_bts(rtx insn)
83191 +{
83192 + rtx btsq;
83193 + rtvec argvec, constraintvec, labelvec;
83194 + int line;
83195 +
83196 + // create asm volatile("btsq $63,(%%rsp)":::)
83197 + argvec = rtvec_alloc(0);
83198 + constraintvec = rtvec_alloc(0);
83199 + labelvec = rtvec_alloc(0);
83200 + line = expand_location(RTL_LOCATION(insn)).line;
83201 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83202 + MEM_VOLATILE_P(btsq) = 1;
83203 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83204 + emit_insn_before(btsq, insn);
83205 +}
83206 +
83207 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83208 +static void kernexec_instrument_retaddr_or(rtx insn)
83209 +{
83210 + rtx orq;
83211 + rtvec argvec, constraintvec, labelvec;
83212 + int line;
83213 +
83214 + // create asm volatile("orq %%r10,(%%rsp)":::)
83215 + argvec = rtvec_alloc(0);
83216 + constraintvec = rtvec_alloc(0);
83217 + labelvec = rtvec_alloc(0);
83218 + line = expand_location(RTL_LOCATION(insn)).line;
83219 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83220 + MEM_VOLATILE_P(orq) = 1;
83221 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83222 + emit_insn_before(orq, insn);
83223 +}
83224 +
83225 +/*
83226 + * find all asm level function returns and forcibly set the highest bit of the return address
83227 + */
83228 +static unsigned int execute_kernexec_retaddr(void)
83229 +{
83230 + rtx insn;
83231 +
83232 + // 1. find function returns
83233 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83234 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83235 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83236 + rtx body;
83237 +
83238 + // is it a retn
83239 + if (!JUMP_P(insn))
83240 + continue;
83241 + body = PATTERN(insn);
83242 + if (GET_CODE(body) == PARALLEL)
83243 + body = XVECEXP(body, 0, 0);
83244 + if (GET_CODE(body) != RETURN)
83245 + continue;
83246 + kernexec_instrument_retaddr(insn);
83247 + }
83248 +
83249 +// print_simple_rtl(stderr, get_insns());
83250 +// print_rtl(stderr, get_insns());
83251 +
83252 + return 0;
83253 +}
83254 +
83255 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83256 +{
83257 + const char * const plugin_name = plugin_info->base_name;
83258 + const int argc = plugin_info->argc;
83259 + const struct plugin_argument * const argv = plugin_info->argv;
83260 + int i;
83261 + struct register_pass_info kernexec_reload_pass_info = {
83262 + .pass = &kernexec_reload_pass.pass,
83263 + .reference_pass_name = "ssa",
83264 + .ref_pass_instance_number = 1,
83265 + .pos_op = PASS_POS_INSERT_AFTER
83266 + };
83267 + struct register_pass_info kernexec_fptr_pass_info = {
83268 + .pass = &kernexec_fptr_pass.pass,
83269 + .reference_pass_name = "ssa",
83270 + .ref_pass_instance_number = 1,
83271 + .pos_op = PASS_POS_INSERT_AFTER
83272 + };
83273 + struct register_pass_info kernexec_retaddr_pass_info = {
83274 + .pass = &kernexec_retaddr_pass.pass,
83275 + .reference_pass_name = "pro_and_epilogue",
83276 + .ref_pass_instance_number = 1,
83277 + .pos_op = PASS_POS_INSERT_AFTER
83278 + };
83279 +
83280 + if (!plugin_default_version_check(version, &gcc_version)) {
83281 + error(G_("incompatible gcc/plugin versions"));
83282 + return 1;
83283 + }
83284 +
83285 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83286 +
83287 + if (TARGET_64BIT == 0)
83288 + return 0;
83289 +
83290 + for (i = 0; i < argc; ++i) {
83291 + if (!strcmp(argv[i].key, "method")) {
83292 + if (!argv[i].value) {
83293 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83294 + continue;
83295 + }
83296 + if (!strcmp(argv[i].value, "bts")) {
83297 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83298 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83299 + } else if (!strcmp(argv[i].value, "or")) {
83300 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83301 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83302 + fix_register("r10", 1, 1);
83303 + } else
83304 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83305 + continue;
83306 + }
83307 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83308 + }
83309 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83310 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83311 +
83312 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83313 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83314 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83315 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83316 +
83317 + return 0;
83318 +}
83319 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83320 new file mode 100644
83321 index 0000000..b8008f7
83322 --- /dev/null
83323 +++ b/tools/gcc/latent_entropy_plugin.c
83324 @@ -0,0 +1,295 @@
83325 +/*
83326 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83327 + * Licensed under the GPL v2
83328 + *
83329 + * Note: the choice of the license means that the compilation process is
83330 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83331 + * but for the kernel it doesn't matter since it doesn't link against
83332 + * any of the gcc libraries
83333 + *
83334 + * gcc plugin to help generate a little bit of entropy from program state,
83335 + * used during boot in the kernel
83336 + *
83337 + * TODO:
83338 + * - add ipa pass to identify not explicitly marked candidate functions
83339 + * - mix in more program state (function arguments/return values, loop variables, etc)
83340 + * - more instrumentation control via attribute parameters
83341 + *
83342 + * BUGS:
83343 + * - LTO needs -flto-partition=none for now
83344 + */
83345 +#include "gcc-plugin.h"
83346 +#include "config.h"
83347 +#include "system.h"
83348 +#include "coretypes.h"
83349 +#include "tree.h"
83350 +#include "tree-pass.h"
83351 +#include "flags.h"
83352 +#include "intl.h"
83353 +#include "toplev.h"
83354 +#include "plugin.h"
83355 +//#include "expr.h" where are you...
83356 +#include "diagnostic.h"
83357 +#include "plugin-version.h"
83358 +#include "tm.h"
83359 +#include "function.h"
83360 +#include "basic-block.h"
83361 +#include "gimple.h"
83362 +#include "rtl.h"
83363 +#include "emit-rtl.h"
83364 +#include "tree-flow.h"
83365 +
83366 +int plugin_is_GPL_compatible;
83367 +
83368 +static tree latent_entropy_decl;
83369 +
83370 +static struct plugin_info latent_entropy_plugin_info = {
83371 + .version = "201207271820",
83372 + .help = NULL
83373 +};
83374 +
83375 +static unsigned int execute_latent_entropy(void);
83376 +static bool gate_latent_entropy(void);
83377 +
83378 +static struct gimple_opt_pass latent_entropy_pass = {
83379 + .pass = {
83380 + .type = GIMPLE_PASS,
83381 + .name = "latent_entropy",
83382 + .gate = gate_latent_entropy,
83383 + .execute = execute_latent_entropy,
83384 + .sub = NULL,
83385 + .next = NULL,
83386 + .static_pass_number = 0,
83387 + .tv_id = TV_NONE,
83388 + .properties_required = PROP_gimple_leh | PROP_cfg,
83389 + .properties_provided = 0,
83390 + .properties_destroyed = 0,
83391 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83392 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83393 + }
83394 +};
83395 +
83396 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83397 +{
83398 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83399 + *no_add_attrs = true;
83400 + error("%qE attribute only applies to functions", name);
83401 + }
83402 + return NULL_TREE;
83403 +}
83404 +
83405 +static struct attribute_spec latent_entropy_attr = {
83406 + .name = "latent_entropy",
83407 + .min_length = 0,
83408 + .max_length = 0,
83409 + .decl_required = true,
83410 + .type_required = false,
83411 + .function_type_required = false,
83412 + .handler = handle_latent_entropy_attribute,
83413 +#if BUILDING_GCC_VERSION >= 4007
83414 + .affects_type_identity = false
83415 +#endif
83416 +};
83417 +
83418 +static void register_attributes(void *event_data, void *data)
83419 +{
83420 + register_attribute(&latent_entropy_attr);
83421 +}
83422 +
83423 +static bool gate_latent_entropy(void)
83424 +{
83425 + tree latent_entropy_attr;
83426 +
83427 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83428 + return latent_entropy_attr != NULL_TREE;
83429 +}
83430 +
83431 +static unsigned HOST_WIDE_INT seed;
83432 +static unsigned HOST_WIDE_INT get_random_const(void)
83433 +{
83434 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83435 + return seed;
83436 +}
83437 +
83438 +static enum tree_code get_op(tree *rhs)
83439 +{
83440 + static enum tree_code op;
83441 + unsigned HOST_WIDE_INT random_const;
83442 +
83443 + random_const = get_random_const();
83444 +
83445 + switch (op) {
83446 + case BIT_XOR_EXPR:
83447 + op = PLUS_EXPR;
83448 + break;
83449 +
83450 + case PLUS_EXPR:
83451 + if (rhs) {
83452 + op = LROTATE_EXPR;
83453 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83454 + break;
83455 + }
83456 +
83457 + case LROTATE_EXPR:
83458 + default:
83459 + op = BIT_XOR_EXPR;
83460 + break;
83461 + }
83462 + if (rhs)
83463 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83464 + return op;
83465 +}
83466 +
83467 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83468 +{
83469 + gimple_stmt_iterator gsi;
83470 + gimple assign;
83471 + tree addxorrol, rhs;
83472 + enum tree_code op;
83473 +
83474 + op = get_op(&rhs);
83475 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83476 + assign = gimple_build_assign(local_entropy, addxorrol);
83477 + find_referenced_vars_in(assign);
83478 +//debug_bb(bb);
83479 + gsi = gsi_after_labels(bb);
83480 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83481 + update_stmt(assign);
83482 +}
83483 +
83484 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83485 +{
83486 + gimple_stmt_iterator gsi;
83487 + gimple assign;
83488 + tree addxorrol, temp;
83489 +
83490 + // 1. create temporary copy of latent_entropy
83491 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83492 + add_referenced_var(temp);
83493 + mark_sym_for_renaming(temp);
83494 +
83495 + // 2. read...
83496 + assign = gimple_build_assign(temp, latent_entropy_decl);
83497 + find_referenced_vars_in(assign);
83498 + gsi = gsi_after_labels(bb);
83499 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83500 + update_stmt(assign);
83501 +
83502 + // 3. ...modify...
83503 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83504 + assign = gimple_build_assign(temp, addxorrol);
83505 + find_referenced_vars_in(assign);
83506 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83507 + update_stmt(assign);
83508 +
83509 + // 4. ...write latent_entropy
83510 + assign = gimple_build_assign(latent_entropy_decl, temp);
83511 + find_referenced_vars_in(assign);
83512 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83513 + update_stmt(assign);
83514 +}
83515 +
83516 +static unsigned int execute_latent_entropy(void)
83517 +{
83518 + basic_block bb;
83519 + gimple assign;
83520 + gimple_stmt_iterator gsi;
83521 + tree local_entropy;
83522 +
83523 + if (!latent_entropy_decl) {
83524 + struct varpool_node *node;
83525 +
83526 + for (node = varpool_nodes; node; node = node->next) {
83527 + tree var = node->decl;
83528 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83529 + continue;
83530 + latent_entropy_decl = var;
83531 +// debug_tree(var);
83532 + break;
83533 + }
83534 + if (!latent_entropy_decl) {
83535 +// debug_tree(current_function_decl);
83536 + return 0;
83537 + }
83538 + }
83539 +
83540 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83541 +
83542 + // 1. create local entropy variable
83543 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83544 + add_referenced_var(local_entropy);
83545 + mark_sym_for_renaming(local_entropy);
83546 +
83547 + // 2. initialize local entropy variable
83548 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83549 + if (dom_info_available_p(CDI_DOMINATORS))
83550 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83551 + gsi = gsi_start_bb(bb);
83552 +
83553 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83554 +// gimple_set_location(assign, loc);
83555 + find_referenced_vars_in(assign);
83556 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83557 + update_stmt(assign);
83558 + bb = bb->next_bb;
83559 +
83560 + // 3. instrument each BB with an operation on the local entropy variable
83561 + while (bb != EXIT_BLOCK_PTR) {
83562 + perturb_local_entropy(bb, local_entropy);
83563 + bb = bb->next_bb;
83564 + };
83565 +
83566 + // 4. mix local entropy into the global entropy variable
83567 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83568 + return 0;
83569 +}
83570 +
83571 +static void start_unit_callback(void *gcc_data, void *user_data)
83572 +{
83573 +#if BUILDING_GCC_VERSION >= 4007
83574 + seed = get_random_seed(false);
83575 +#else
83576 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83577 + seed *= seed;
83578 +#endif
83579 +
83580 + if (in_lto_p)
83581 + return;
83582 +
83583 + // extern u64 latent_entropy
83584 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83585 +
83586 + TREE_STATIC(latent_entropy_decl) = 1;
83587 + TREE_PUBLIC(latent_entropy_decl) = 1;
83588 + TREE_USED(latent_entropy_decl) = 1;
83589 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83590 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83591 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83592 + DECL_INITIAL(latent_entropy_decl) = NULL;
83593 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83594 +// varpool_finalize_decl(latent_entropy_decl);
83595 +// varpool_mark_needed_node(latent_entropy_decl);
83596 +}
83597 +
83598 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83599 +{
83600 + const char * const plugin_name = plugin_info->base_name;
83601 + struct register_pass_info latent_entropy_pass_info = {
83602 + .pass = &latent_entropy_pass.pass,
83603 + .reference_pass_name = "optimized",
83604 + .ref_pass_instance_number = 1,
83605 + .pos_op = PASS_POS_INSERT_BEFORE
83606 + };
83607 +
83608 + if (!plugin_default_version_check(version, &gcc_version)) {
83609 + error(G_("incompatible gcc/plugin versions"));
83610 + return 1;
83611 + }
83612 +
83613 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83614 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83615 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83616 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83617 +
83618 + return 0;
83619 +}
83620 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83621 new file mode 100644
83622 index 0000000..9332f17
83623 --- /dev/null
83624 +++ b/tools/gcc/size_overflow_hash.data
83625 @@ -0,0 +1,3597 @@
83626 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
83627 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
83628 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
83629 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
83630 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
83631 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
83632 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
83633 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
83634 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
83635 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
83636 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
83637 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
83638 +_000014_hash kmemdup 2 64015 _000014_hash NULL
83639 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
83640 +_000016_hash memdup_user 2 59590 _000016_hash NULL
83641 +_000017_hash module_alloc 1 63630 _000017_hash NULL
83642 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
83643 +_000019_hash read_kcore 3 63488 _000019_hash NULL
83644 +_000020_hash read_ldt 2 47570 _000020_hash NULL
83645 +_000021_hash read_zero 3 19366 _000021_hash NULL
83646 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
83647 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
83648 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
83649 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
83650 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
83651 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
83652 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
83653 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
83654 +_000031_hash adu_write 3 30487 _000031_hash NULL
83655 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
83656 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
83657 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
83658 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
83659 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
83660 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
83661 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
83662 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
83663 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
83664 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
83665 +_000044_hash alloc_context 1 3194 _000044_hash NULL
83666 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
83667 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
83668 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
83669 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
83670 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
83671 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
83672 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
83673 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
83674 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
83675 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
83676 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
83677 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
83678 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
83679 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
83680 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
83681 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
83682 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
83683 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
83684 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
83685 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
83686 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
83687 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
83688 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
83689 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
83690 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
83691 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
83692 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
83693 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
83694 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
83695 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
83696 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
83697 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
83698 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
83699 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
83700 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
83701 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
83702 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
83703 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
83704 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
83705 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
83706 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
83707 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
83708 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
83709 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
83710 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
83711 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
83712 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
83713 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
83714 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
83715 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
83716 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
83717 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
83718 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
83719 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
83720 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
83721 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
83722 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
83723 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
83724 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
83725 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
83726 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
83727 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
83728 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
83729 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
83730 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
83731 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
83732 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
83733 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
83734 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
83735 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
83736 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
83737 +_000122_hash change_xattr 5 61390 _000122_hash NULL
83738 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
83739 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
83740 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
83741 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
83742 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
83743 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
83744 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
83745 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
83746 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
83747 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
83748 +_000133_hash cmm_write 3 2896 _000133_hash NULL
83749 +_000134_hash cm_write 3 36858 _000134_hash NULL
83750 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
83751 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
83752 +_000137_hash command_file_write 3 31318 _000137_hash NULL
83753 +_000138_hash command_write 3 58841 _000138_hash NULL
83754 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
83755 +_000140_hash concat_writev 3 21451 _000140_hash NULL
83756 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
83757 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
83758 +_000143_hash copy_items 6 50140 _000143_hash NULL
83759 +_000144_hash copy_macs 4 45534 _000144_hash NULL
83760 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
83761 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
83762 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
83763 +_000148_hash cosa_write 3 1774 _000148_hash NULL
83764 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
83765 +_000150_hash create_entry 2 33479 _000150_hash NULL
83766 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
83767 +_000153_hash create_xattr 5 54106 _000153_hash NULL
83768 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
83769 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
83770 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
83771 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
83772 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
83773 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
83774 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
83775 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
83776 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
83777 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
83778 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
83779 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
83780 +_000168_hash dev_config 3 8506 _000168_hash NULL
83781 +_000169_hash device_write 3 45156 _000169_hash NULL
83782 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
83783 +_000171_hash devres_alloc 2 551 _000171_hash NULL
83784 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
83785 +_000173_hash direct_entry 3 38836 _000173_hash NULL
83786 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
83787 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
83788 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
83789 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
83790 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
83791 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
83792 +_000180_hash dm_read 3 15674 _000180_hash NULL
83793 +_000181_hash dm_write 3 2513 _000181_hash NULL
83794 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
83795 +_000183_hash dns_query 3 9676 _000183_hash NULL
83796 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
83797 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
83798 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
83799 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
83800 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
83801 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
83802 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
83803 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
83804 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
83805 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
83806 +_000194_hash dsp_write 2 46218 _000194_hash NULL
83807 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
83808 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
83809 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
83810 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
83811 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
83812 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
83813 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
83814 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
83815 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
83816 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
83817 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
83818 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
83819 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
83820 +_000208_hash ep_read 3 58813 _000208_hash NULL
83821 +_000209_hash ep_write 3 59008 _000209_hash NULL
83822 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
83823 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
83824 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
83825 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
83826 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
83827 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
83828 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
83829 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
83830 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
83831 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
83832 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
83833 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
83834 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
83835 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
83836 +_000225_hash fl_create 5 56435 _000225_hash NULL
83837 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
83838 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
83839 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
83840 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
83841 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
83842 +_000231_hash get_arg 3 5694 _000231_hash NULL
83843 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
83844 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
83845 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
83846 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
83847 +_000236_hash get_registers 3 26187 _000236_hash NULL
83848 +_000237_hash get_scq 2 10897 _000237_hash NULL
83849 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
83850 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
83851 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
83852 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
83853 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
83854 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
83855 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
83856 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
83857 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
83858 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
83859 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
83860 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
83861 +_000250_hash handle_request 9 10024 _000250_hash NULL
83862 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
83863 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
83864 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
83865 +_000254_hash heap_init 2 49617 _000254_hash NULL
83866 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
83867 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
83868 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
83869 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
83870 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
83871 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
83872 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
83873 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
83874 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
83875 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
83876 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
83877 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
83878 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
83879 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
83880 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
83881 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
83882 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
83883 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
83884 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
83885 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
83886 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
83887 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
83888 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
83889 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
83890 +_000279_hash if_write 3 51756 _000279_hash NULL
83891 +_000280_hash ilo_write 3 64378 _000280_hash NULL
83892 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
83893 +_000282_hash init_data_container 1 60709 _000282_hash NULL
83894 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
83895 +_000284_hash insert_dent 7 65034 _000284_hash NULL
83896 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
83897 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
83898 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
83899 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
83900 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
83901 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
83902 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
83903 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
83904 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
83905 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
83906 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
83907 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
83908 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
83909 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
83910 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
83911 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
83912 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
83913 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
83914 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
83915 +_000304_hash isdn_read 3 50021 _000304_hash NULL
83916 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
83917 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
83918 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
83919 +_000308_hash iso_callback 3 43208 _000308_hash NULL
83920 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
83921 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
83922 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
83923 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
83924 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
83925 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
83926 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
83927 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
83928 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
83929 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
83930 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
83931 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
83932 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
83933 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
83934 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
83935 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
83936 +_000328_hash kone_receive 4 4690 _000328_hash NULL
83937 +_000329_hash kone_send 4 63435 _000329_hash NULL
83938 +_000330_hash krealloc 2 14908 _000330_hash NULL
83939 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
83940 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
83941 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
83942 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
83943 +_000335_hash kzalloc 1 54740 _000335_hash NULL
83944 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
83945 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
83946 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
83947 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
83948 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
83949 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
83950 +_000342_hash __lgread 4 31668 _000342_hash NULL
83951 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
83952 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
83953 +_000345_hash listxattr 3 12769 _000345_hash NULL
83954 +_000346_hash load_msg 2 95 _000346_hash NULL
83955 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
83956 +_000348_hash lp_write 3 9511 _000348_hash NULL
83957 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
83958 +_000350_hash mce_write 3 26201 _000350_hash NULL
83959 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
83960 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
83961 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
83962 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
83963 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
83964 +_000357_hash mem_rw 3 22085 _000357_hash NULL
83965 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
83966 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
83967 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
83968 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
83969 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
83970 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
83971 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
83972 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
83973 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
83974 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
83975 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
83976 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
83977 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
83978 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
83979 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
83980 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
83981 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
83982 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
83983 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
83984 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
83985 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
83986 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
83987 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
83988 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
83989 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
83990 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
83991 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
83992 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
83993 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
83994 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
83995 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
83996 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
83997 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
83998 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
83999 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84000 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84001 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84002 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84003 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84004 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84005 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84006 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84007 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84008 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84009 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84010 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84011 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84012 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84013 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84014 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84015 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84016 +_000415_hash parse_command 2 37079 _000415_hash NULL
84017 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84018 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84019 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84020 +_000419_hash pg_write 3 40766 _000419_hash NULL
84021 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84022 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84023 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84024 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84025 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84026 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84027 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84028 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84029 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84030 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84031 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84032 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84033 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84034 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84035 +_000434_hash pp_read 3 33210 _000434_hash NULL
84036 +_000435_hash pp_write 3 39554 _000435_hash NULL
84037 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84038 +_000437_hash printer_write 3 60276 _000437_hash NULL
84039 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84040 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84041 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84042 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84043 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84044 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84045 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84046 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84047 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84048 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84049 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84050 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84051 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84052 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84053 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84054 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84055 +_000456_hash pt_write 3 40159 _000456_hash NULL
84056 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84057 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84058 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84059 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84060 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84061 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84062 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84063 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84064 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84065 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84066 +_000467_hash read 3 9397 _000467_hash NULL
84067 +_000468_hash read_buf 2 20469 _000468_hash NULL
84068 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84069 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84070 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84071 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84072 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84073 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84074 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84075 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84076 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84077 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84078 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84079 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84080 +_000481_hash revalidate 2 19043 _000481_hash NULL
84081 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84082 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84083 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84084 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84085 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84086 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84087 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84088 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84089 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84090 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84091 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84092 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84093 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84094 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84095 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84096 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84097 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84098 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84099 +_000500_hash savemem 3 58129 _000500_hash NULL
84100 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84101 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84102 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84103 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84104 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84105 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84106 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84107 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84108 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84109 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84110 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84111 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84112 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84113 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84114 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84115 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84116 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84117 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84118 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84119 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84120 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84121 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84122 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84123 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84124 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84125 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84126 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84127 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84128 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84129 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84130 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84131 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84132 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84133 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84134 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84135 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84136 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84137 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84138 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84139 +_000542_hash set_registers 3 53582 _000542_hash NULL
84140 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84141 +_000544_hash setup_req 3 5848 _000544_hash NULL
84142 +_000545_hash setxattr 4 37006 _000545_hash NULL
84143 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84144 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84145 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84146 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84147 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84148 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84149 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84150 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84151 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84152 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84153 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84154 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84155 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84156 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84157 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84158 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84159 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84160 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84161 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84162 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84163 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84164 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84165 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84166 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84167 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84168 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84169 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84170 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84171 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84172 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84173 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84174 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84175 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84176 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84177 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84178 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84179 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84180 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84181 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84182 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84183 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84184 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84185 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84186 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84187 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84188 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84189 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84190 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84191 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84192 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84193 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84194 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84195 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84196 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84197 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84198 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84199 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84200 +_000606_hash tower_write 3 8580 _000606_hash NULL
84201 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84202 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84203 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84204 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84205 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84206 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84207 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84208 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84209 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84210 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84211 +_000617_hash uea_request 4 47613 _000617_hash NULL
84212 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84213 +_000619_hash uio_write 3 43202 _000619_hash NULL
84214 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84215 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84216 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84217 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84218 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84219 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84220 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84221 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84222 +_000629_hash user_update 3 41332 _000629_hash NULL
84223 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84224 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84225 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84226 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84227 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84228 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84229 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84230 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84231 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84232 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84233 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84234 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84235 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84236 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84237 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84238 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84239 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84240 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84241 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84242 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84243 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84244 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84245 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84246 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84247 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84248 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84249 +_000659_hash write 3 62671 _000659_hash NULL
84250 +_000660_hash write_flush 3 50803 _000660_hash NULL
84251 +_000661_hash write_rio 3 54837 _000661_hash NULL
84252 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84253 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84254 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84255 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84256 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84257 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84258 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84259 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84260 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84261 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84262 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84263 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84264 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84265 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84266 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84267 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84268 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84269 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84270 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84271 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84272 +_000684_hash addtgt 3 54703 _000684_hash NULL
84273 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84274 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84275 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84276 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84277 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84278 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84279 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84280 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84281 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84282 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84283 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84284 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84285 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84286 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84287 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84288 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84289 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84290 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84291 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84292 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84293 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84294 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84295 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84296 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84297 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84298 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84299 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84300 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84301 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84302 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84303 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84304 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84305 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84306 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84307 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84308 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84309 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84310 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84311 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84312 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84313 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84314 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84315 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84316 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84317 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84318 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84319 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84320 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84321 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84322 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84323 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84324 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84325 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84326 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84327 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84328 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84329 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84330 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84331 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84332 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84333 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84334 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84335 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84336 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84337 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84338 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84339 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84340 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84341 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84342 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84343 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84344 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84345 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84346 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84347 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84348 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84349 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84350 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84351 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84352 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84353 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84354 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84355 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84356 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84357 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84358 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84359 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84360 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84361 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84362 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84363 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84364 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84365 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84366 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84367 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84368 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84369 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84370 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84371 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84372 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84373 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84374 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84375 +_000799_hash construct_key 3 11329 _000799_hash NULL
84376 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84377 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84378 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84379 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84380 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84381 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84382 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84383 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84384 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84385 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84386 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84387 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84388 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84389 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84390 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84391 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84392 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84393 +_000819_hash depth_write 3 3021 _000819_hash NULL
84394 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84395 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84396 +_000822_hash dev_write 3 7708 _000822_hash NULL
84397 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84398 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84399 +_000825_hash disconnect 4 32521 _000825_hash NULL
84400 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84401 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84402 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84403 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84404 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84405 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84406 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84407 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84408 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84409 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84410 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84411 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84412 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84413 +_000840_hash do_sync 1 9604 _000840_hash NULL
84414 +_000841_hash dup_array 3 33551 _000841_hash NULL
84415 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84416 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84417 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84418 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84419 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84420 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84421 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84422 +_000849_hash enable_write 3 30456 _000849_hash NULL
84423 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84424 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84425 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84426 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84427 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84428 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84429 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84430 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84431 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84432 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84433 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84434 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84435 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84436 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84437 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84438 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84439 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84440 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84441 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84442 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84443 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84444 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84445 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84446 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84447 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84448 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84449 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84450 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84451 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84452 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84453 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84454 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84455 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84456 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84457 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84458 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84459 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84460 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84461 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84462 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84463 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84464 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84465 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84466 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84467 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84468 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84469 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84470 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84471 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84472 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84473 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84474 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84475 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84476 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84477 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84478 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84479 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84480 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84481 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84482 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84483 +_000915_hash init_q 4 132 _000915_hash NULL
84484 +_000916_hash init_state 2 60165 _000916_hash NULL
84485 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84486 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84487 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84488 +_000920_hash interfaces 2 38859 _000920_hash NULL
84489 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84490 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84491 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84492 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84493 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84494 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84495 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84496 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84497 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84498 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84499 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84500 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84501 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84502 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84503 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84504 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84505 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84506 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84507 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84508 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84509 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84510 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84511 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84512 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84513 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84514 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84515 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84516 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84517 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84518 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84519 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84520 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84521 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84522 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84523 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84524 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84525 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84526 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84527 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84528 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84529 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84530 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84531 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84532 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84533 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84534 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84535 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84536 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84537 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84538 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84539 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84540 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84541 +_000977_hash lc_create 3 48662 _000977_hash NULL
84542 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84543 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84544 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84545 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84546 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84547 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84548 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84549 +_000985_hash mem_read 3 57631 _000985_hash NULL
84550 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84551 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84552 +_000988_hash mem_write 3 22232 _000988_hash NULL
84553 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84554 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84555 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84556 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84557 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84558 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84559 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84560 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84561 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84562 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84563 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84564 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84565 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84566 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84567 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84568 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84569 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84570 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84571 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84572 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84573 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84574 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84575 +_001014_hash new_dir 3 31919 _001014_hash NULL
84576 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84577 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84578 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84579 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84580 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84581 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
84582 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
84583 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
84584 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
84585 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
84586 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
84587 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
84588 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
84589 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
84590 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
84591 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
84592 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
84593 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
84594 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
84595 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
84596 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
84597 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
84598 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
84599 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
84600 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
84601 +_001046_hash osst_write 3 31581 _001046_hash NULL
84602 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
84603 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
84604 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
84605 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
84606 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
84607 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
84608 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
84609 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
84610 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
84611 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
84612 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
84613 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
84614 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
84615 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
84616 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
84617 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
84618 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
84619 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
84620 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
84621 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
84622 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
84623 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
84624 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
84625 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
84626 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
84627 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
84628 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
84629 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
84630 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
84631 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
84632 +_001083_hash proc_write 3 51003 _001083_hash NULL
84633 +_001084_hash profile_load 3 58267 _001084_hash NULL
84634 +_001085_hash profile_remove 3 8556 _001085_hash NULL
84635 +_001086_hash profile_replace 3 14652 _001086_hash NULL
84636 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
84637 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
84638 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
84639 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
84640 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
84641 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
84642 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
84643 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
84644 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
84645 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
84646 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
84647 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
84648 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
84649 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
84650 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
84651 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
84652 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
84653 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
84654 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
84655 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
84656 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
84657 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
84658 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
84659 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
84660 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
84661 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
84662 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
84663 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
84664 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
84665 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
84666 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
84667 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
84668 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
84669 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
84670 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
84671 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
84672 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
84673 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
84674 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
84675 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
84676 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
84677 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
84678 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
84679 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
84680 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
84681 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
84682 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
84683 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
84684 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
84685 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
84686 +_001139_hash self_check_write 5 50856 _001139_hash NULL
84687 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
84688 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
84689 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
84690 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
84691 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
84692 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
84693 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
84694 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
84695 +_001148_hash set_connectable 4 56458 _001148_hash NULL
84696 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
84697 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
84698 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
84699 +_001152_hash setkey 3 14987 _001152_hash NULL
84700 +_001153_hash set_le 4 30581 _001153_hash NULL
84701 +_001154_hash set_link_security 4 4502 _001154_hash NULL
84702 +_001155_hash set_local_name 4 55757 _001155_hash NULL
84703 +_001156_hash set_powered 4 12129 _001156_hash NULL
84704 +_001157_hash set_ssp 4 62411 _001157_hash NULL
84705 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
84706 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
84707 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
84708 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
84709 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
84710 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
84711 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
84712 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
84713 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
84714 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
84715 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
84716 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
84717 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
84718 +_001174_hash skb_pad 2 17302 _001174_hash NULL
84719 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
84720 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
84721 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
84722 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
84723 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
84724 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
84725 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
84726 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
84727 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
84728 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
84729 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
84730 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
84731 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
84732 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
84733 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
84734 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
84735 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
84736 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
84737 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
84738 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
84739 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
84740 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
84741 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
84742 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
84743 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
84744 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
84745 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
84746 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
84747 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
84748 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
84749 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
84750 +_001208_hash sound_write 3 5102 _001208_hash NULL
84751 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
84752 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
84753 +_001213_hash spidev_message 3 5518 _001213_hash NULL
84754 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
84755 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
84756 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
84757 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
84758 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
84759 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
84760 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
84761 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
84762 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
84763 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
84764 +_001227_hash st_write 3 16874 _001227_hash NULL
84765 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
84766 +_001229_hash symtab_init 2 61050 _001229_hash NULL
84767 +_001230_hash sys_bind 3 10799 _001230_hash NULL
84768 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
84769 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
84770 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
84771 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
84772 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
84773 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
84774 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
84775 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
84776 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
84777 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
84778 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
84779 +_001242_hash sys_select 1 38827 _001242_hash NULL
84780 +_001243_hash sys_semop 3 39457 _001243_hash NULL
84781 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
84782 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
84783 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
84784 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
84785 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
84786 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
84787 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
84788 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
84789 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
84790 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
84791 +_001254_hash timeout_write 3 50991 _001254_hash NULL
84792 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
84793 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
84794 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
84795 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
84796 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
84797 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
84798 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
84799 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
84800 +_001264_hash tty_write 3 5494 _001264_hash NULL
84801 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
84802 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
84803 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
84804 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
84805 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
84806 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
84807 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
84808 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
84809 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
84810 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
84811 +_001277_hash vhci_write 3 2224 _001277_hash NULL
84812 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
84813 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
84814 +_001281_hash vmalloc 1 15464 _001281_hash NULL
84815 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
84816 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
84817 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
84818 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
84819 +_001286_hash vzalloc 1 47421 _001286_hash NULL
84820 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
84821 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
84822 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
84823 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
84824 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
84825 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
84826 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
84827 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
84828 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
84829 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
84830 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
84831 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
84832 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
84833 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
84834 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
84835 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
84836 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
84837 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
84838 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
84839 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
84840 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
84841 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
84842 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
84843 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
84844 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
84845 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
84846 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
84847 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
84848 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
84849 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
84850 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
84851 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
84852 +_001319_hash add_child 4 45201 _001319_hash NULL
84853 +_001320_hash add_port 2 54941 _001320_hash NULL
84854 +_001321_hash adu_read 3 24177 _001321_hash NULL
84855 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
84856 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
84857 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
84858 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
84859 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
84860 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
84861 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
84862 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
84863 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
84864 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
84865 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
84866 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
84867 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
84868 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
84869 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
84870 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
84871 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
84872 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
84873 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
84874 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
84875 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
84876 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
84877 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
84878 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
84879 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
84880 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
84881 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
84882 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
84883 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
84884 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
84885 +_001356_hash async_setkey 3 35521 _001356_hash NULL
84886 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
84887 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
84888 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
84889 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
84890 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
84891 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
84892 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
84893 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
84894 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
84895 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
84896 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
84897 +_001370_hash ax25_output 2 22736 _001370_hash NULL
84898 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
84899 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
84900 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
84901 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
84902 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
84903 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
84904 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
84905 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
84906 +_001380_hash bm_init 2 13529 _001380_hash NULL
84907 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
84908 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
84909 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
84910 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
84911 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
84912 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
84913 +_001387_hash cache_read 3 24790 _001387_hash NULL
84914 +_001388_hash cache_write 3 13589 _001388_hash NULL
84915 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
84916 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
84917 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
84918 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
84919 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
84920 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
84921 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
84922 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
84923 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
84924 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
84925 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
84926 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
84927 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
84928 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
84929 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
84930 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
84931 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
84932 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
84933 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
84934 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
84935 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
84936 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
84937 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
84938 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
84939 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
84940 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
84941 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
84942 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
84943 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
84944 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
84945 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
84946 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
84947 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
84948 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
84949 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
84950 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
84951 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
84952 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
84953 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
84954 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
84955 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
84956 +_001435_hash do_readlink 2 43518 _001435_hash NULL
84957 +_001436_hash __do_replace 5 37227 _001436_hash NULL
84958 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
84959 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
84960 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
84961 +_001440_hash dump_midi 3 51040 _001440_hash NULL
84962 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
84963 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
84964 +_001443_hash ep0_read 3 38095 _001443_hash NULL
84965 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
84966 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
84967 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
84968 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
84969 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
84970 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
84971 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
84972 +_001451_hash filldir 3 55137 _001451_hash NULL
84973 +_001452_hash filldir64 3 46469 _001452_hash NULL
84974 +_001453_hash find_skb 2 20431 _001453_hash NULL
84975 +_001454_hash from_buffer 3 18625 _001454_hash NULL
84976 +_001455_hash fsm_init 2 16134 _001455_hash NULL
84977 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
84978 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
84979 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
84980 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
84981 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
84982 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
84983 +_001462_hash get_packet 3 41914 _001462_hash NULL
84984 +_001463_hash get_packet 3 5747 _001463_hash NULL
84985 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
84986 +_001465_hash get_skb 2 63008 _001465_hash NULL
84987 +_001466_hash get_subdir 3 62581 _001466_hash NULL
84988 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
84989 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
84990 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
84991 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
84992 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
84993 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
84994 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
84995 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
84996 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
84997 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
84998 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
84999 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85000 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85001 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85002 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85003 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85004 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85005 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85006 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85007 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85008 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85009 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85010 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85011 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85012 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85013 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85014 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85015 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85016 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85017 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85018 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85019 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85020 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85021 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85022 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85023 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85024 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85025 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85026 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85027 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85028 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85029 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85030 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85031 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85032 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85033 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85034 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85035 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85036 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85037 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85038 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85039 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85040 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85041 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85042 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85043 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85044 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85045 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85046 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85047 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85048 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85049 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85050 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85051 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85052 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85053 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85054 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85055 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85056 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85057 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85058 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85059 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85060 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85061 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85062 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85063 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85064 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85065 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85066 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85067 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85068 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85069 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85070 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85071 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85072 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85073 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85074 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85075 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85076 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85077 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85078 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85079 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85080 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85081 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85082 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85083 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85084 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85085 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85086 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85087 +_001575_hash new_skb 1 21148 _001575_hash NULL
85088 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85089 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85090 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85091 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85092 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85093 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85094 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85095 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85096 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85097 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85098 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85099 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85100 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85101 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85102 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85103 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85104 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85105 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85106 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85107 +_001599_hash override_release 2 52032 _001599_hash NULL
85108 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85109 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85110 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85111 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85112 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85113 +_001605_hash pg_read 3 17276 _001605_hash NULL
85114 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85115 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85116 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85117 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85118 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85119 +_001611_hash printer_read 3 54851 _001611_hash NULL
85120 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85121 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85122 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85123 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85124 +_001616_hash pt_read 3 49136 _001616_hash NULL
85125 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85126 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85127 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85128 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85129 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85130 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85131 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85132 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85133 +_001625_hash read_flush 3 43851 _001625_hash NULL
85134 +_001626_hash read_profile 3 27859 _001626_hash NULL
85135 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85136 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85137 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85138 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85139 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85140 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85141 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85142 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85143 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85144 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85145 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85146 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85147 +_001640_hash rx 4 57944 _001640_hash NULL
85148 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85149 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85150 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85151 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85152 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85153 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85154 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85155 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85156 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85157 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85158 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85159 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85160 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85161 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85162 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85163 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85164 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85165 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85166 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85167 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85168 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85169 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85170 +_001663_hash send_command 4 10832 _001663_hash NULL
85171 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85172 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85173 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85174 +_001667_hash set_arg 3 42824 _001667_hash NULL
85175 +_001668_hash sg_read 3 25799 _001668_hash NULL
85176 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85177 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85178 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85179 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85180 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85181 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85182 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85183 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85184 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85185 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85186 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85187 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85188 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85189 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85190 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85191 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85192 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85193 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85194 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85195 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85196 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85197 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85198 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85199 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85200 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85201 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85202 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85203 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85204 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85205 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85206 +_001704_hash store_msg 3 56417 _001704_hash NULL
85207 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85208 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85209 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85210 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85211 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85212 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85213 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85214 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85215 +_001713_hash syslog_print 2 307 _001713_hash NULL
85216 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85217 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85218 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85219 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85220 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85221 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85222 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85223 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85224 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85225 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85226 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85227 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85228 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85229 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85230 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85231 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85232 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85233 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85234 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85235 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85236 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85237 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85238 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85239 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85240 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85241 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85242 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85243 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85244 +_001746_hash uio_read 3 49300 _001746_hash NULL
85245 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85246 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85247 +_001749_hash unlink1 3 63059 _001749_hash NULL
85248 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85249 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85250 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85251 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85252 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85253 +_001756_hash user_read 3 51881 _001756_hash NULL
85254 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85255 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85256 +_001759_hash venus_create 4 20555 _001759_hash NULL
85257 +_001760_hash venus_link 5 32165 _001760_hash NULL
85258 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85259 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85260 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85261 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85262 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85263 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85264 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85265 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85266 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85267 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85268 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85269 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85270 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85271 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85272 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85273 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85274 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85275 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85276 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85277 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85278 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85279 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85280 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85281 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85282 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85283 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85284 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85285 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85286 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85287 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85288 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85289 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85290 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85291 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85292 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85293 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85294 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85295 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85296 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85297 +_001803_hash add_partition 2 55588 _001803_hash NULL
85298 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85299 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85300 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85301 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85302 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85303 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85304 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85305 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85306 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85307 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85308 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85309 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85310 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85311 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85312 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85313 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85314 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85315 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85316 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85317 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85318 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85319 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85320 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85321 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85322 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85323 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85324 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85325 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85326 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85327 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85328 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85329 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85330 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85331 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85332 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85333 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85334 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85335 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85336 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85337 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85338 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85339 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85340 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85341 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85342 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85343 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85344 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85345 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85346 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85347 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85348 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85349 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85350 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85351 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85352 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85353 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85354 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85355 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85356 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85357 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85358 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85359 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85360 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85361 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85362 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85363 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85364 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85365 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85366 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85367 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85368 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85369 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85370 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85371 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85372 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85373 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85374 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85375 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85376 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85377 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85378 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85379 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85380 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85381 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85382 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85383 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85384 +_001892_hash check_header 2 56930 _001892_hash NULL
85385 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85386 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85387 +_001895_hash console_store 4 36007 _001895_hash NULL
85388 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85389 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85390 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85391 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85392 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85393 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85394 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85395 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85396 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85397 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85398 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85399 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85400 +_001912_hash debug_output 3 18575 _001912_hash NULL
85401 +_001913_hash debug_read 3 19322 _001913_hash NULL
85402 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85403 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85404 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85405 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85406 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85407 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85408 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85409 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85410 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85411 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85412 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85413 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85414 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85415 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85416 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85417 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85418 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85419 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85420 +_001933_hash filter_read 3 61692 _001933_hash NULL
85421 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85422 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85423 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85424 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85425 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85426 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85427 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85428 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85429 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85430 +_001943_hash handle_response 5 55951 _001943_hash NULL
85431 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85432 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85433 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85434 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85435 +_001948_hash help 4 14971 _001948_hash NULL
85436 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85437 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85438 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85439 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85440 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85441 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85442 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85443 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85444 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85445 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85446 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85447 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85448 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85449 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85450 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85451 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85452 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85453 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85454 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85455 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85456 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85457 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85458 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85459 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85460 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85461 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85462 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85463 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85464 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85465 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85466 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85467 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85468 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85469 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85470 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85471 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85472 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85473 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85474 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85475 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85476 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85477 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85478 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85479 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85480 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85481 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85482 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85483 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85484 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85485 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85486 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85487 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85488 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85489 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85490 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85491 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85492 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85493 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85494 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85495 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85496 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85497 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85498 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85499 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85500 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85501 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85502 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85503 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85504 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85505 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85506 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85507 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85508 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85509 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85510 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85511 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85512 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85513 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85514 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85515 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85516 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85517 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85518 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85519 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85520 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85521 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85522 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85523 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85524 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85525 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85526 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85527 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85528 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85529 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85530 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85531 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85532 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85533 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85534 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85535 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85536 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85537 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85538 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85539 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85540 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85541 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85542 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85543 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85544 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85545 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85546 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85547 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85548 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85549 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85550 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85551 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85552 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85553 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85554 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85555 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85556 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85557 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85558 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85559 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85560 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85561 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85562 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85563 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85564 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85565 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85566 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85567 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85568 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85569 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85570 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85571 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85572 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85573 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85574 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85575 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85576 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85577 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85578 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85579 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85580 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85581 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
85582 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
85583 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
85584 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
85585 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
85586 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
85587 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
85588 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
85589 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
85590 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
85591 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
85592 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
85593 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
85594 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
85595 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
85596 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
85597 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
85598 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
85599 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
85600 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
85601 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
85602 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
85603 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
85604 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
85605 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
85606 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
85607 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
85608 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
85609 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
85610 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
85611 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
85612 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
85613 +_002136_hash osst_read 3 40237 _002136_hash NULL
85614 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
85615 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
85616 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
85617 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
85618 +_002143_hash page_readlink 3 23346 _002143_hash NULL
85619 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
85620 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
85621 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
85622 +_002148_hash pep_reply 5 50582 _002148_hash NULL
85623 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
85624 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
85625 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
85626 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
85627 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
85628 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
85629 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
85630 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
85631 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
85632 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
85633 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
85634 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
85635 +_002161_hash proc_read 3 43614 _002161_hash NULL
85636 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
85637 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
85638 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
85639 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
85640 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
85641 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
85642 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
85643 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
85644 +_002170_hash queues_read 3 24877 _002170_hash NULL
85645 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
85646 +_002172_hash rcname_read 3 25919 _002172_hash NULL
85647 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
85648 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
85649 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
85650 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
85651 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
85652 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
85653 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
85654 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
85655 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
85656 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
85657 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
85658 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
85659 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
85660 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
85661 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
85662 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
85663 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
85664 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
85665 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
85666 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
85667 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
85668 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
85669 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
85670 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
85671 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
85672 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
85673 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
85674 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
85675 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
85676 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
85677 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
85678 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
85679 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
85680 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
85681 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
85682 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
85683 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
85684 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
85685 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
85686 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
85687 +_002213_hash receive_packet 2 12367 _002213_hash NULL
85688 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
85689 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
85690 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
85691 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
85692 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
85693 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
85694 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
85695 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
85696 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
85697 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
85698 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
85699 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
85700 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
85701 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
85702 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
85703 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
85704 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
85705 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
85706 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
85707 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
85708 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
85709 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
85710 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
85711 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
85712 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
85713 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
85714 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
85715 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
85716 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
85717 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
85718 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
85719 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
85720 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
85721 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
85722 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
85723 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
85724 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
85725 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
85726 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
85727 +_002254_hash send_msg 4 37323 _002254_hash NULL
85728 +_002255_hash send_packet 4 52960 _002255_hash NULL
85729 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
85730 +_002257_hash sge_rx 3 50594 _002257_hash NULL
85731 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
85732 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
85733 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
85734 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
85735 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
85736 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
85737 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
85738 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
85739 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
85740 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
85741 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
85742 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
85743 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
85744 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
85745 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
85746 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
85747 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
85748 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
85749 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
85750 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
85751 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
85752 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
85753 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
85754 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
85755 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
85756 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
85757 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
85758 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
85759 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
85760 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
85761 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
85762 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
85763 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
85764 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
85765 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
85766 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
85767 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
85768 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
85769 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
85770 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
85771 +_002306_hash st_read 3 51251 _002306_hash NULL
85772 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
85773 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
85774 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
85775 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
85776 +_002311_hash sys_readv 3 50664 _002311_hash NULL
85777 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
85778 +_002313_hash sys_writev 3 28384 _002313_hash NULL
85779 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
85780 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
85781 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
85782 +_002317_hash teiup_create 3 43201 _002317_hash NULL
85783 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
85784 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
85785 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
85786 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
85787 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
85788 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
85789 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
85790 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
85791 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
85792 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
85793 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
85794 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
85795 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
85796 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
85797 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
85798 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
85799 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
85800 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
85801 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
85802 +_002341_hash um_idi_read 3 850 _002341_hash NULL
85803 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
85804 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
85805 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
85806 +_002345_hash use_pool 2 64607 _002345_hash NULL
85807 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
85808 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
85809 +_002348_hash vhci_read 3 47878 _002348_hash NULL
85810 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
85811 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
85812 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
85813 +_002353_hash waiters_read 3 40902 _002353_hash NULL
85814 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
85815 +_002355_hash write_pbl 4 59583 _002355_hash NULL
85816 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
85817 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
85818 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
85819 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
85820 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
85821 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
85822 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
85823 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
85824 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
85825 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
85826 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
85827 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
85828 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
85829 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
85830 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
85831 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
85832 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
85833 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
85834 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
85835 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
85836 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
85837 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
85838 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
85839 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
85840 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
85841 +_002382_hash bioset_create 1 5580 _002382_hash NULL
85842 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
85843 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
85844 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
85845 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
85846 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
85847 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
85848 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
85849 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
85850 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
85851 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
85852 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
85853 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
85854 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
85855 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
85856 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
85857 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
85858 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
85859 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
85860 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
85861 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
85862 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
85863 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
85864 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
85865 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
85866 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
85867 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
85868 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
85869 +_002411_hash depth_read 3 31112 _002411_hash NULL
85870 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
85871 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
85872 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
85873 +_002415_hash divas_write 3 63901 _002415_hash NULL
85874 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
85875 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
85876 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
85877 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
85878 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
85879 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
85880 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
85881 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
85882 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
85883 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
85884 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
85885 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
85886 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
85887 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
85888 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
85889 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
85890 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
85891 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
85892 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
85893 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
85894 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
85895 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
85896 +_002439_hash got_frame 2 16028 _002439_hash NULL
85897 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
85898 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
85899 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
85900 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
85901 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
85902 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
85903 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
85904 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
85905 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
85906 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
85907 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
85908 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
85909 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
85910 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
85911 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
85912 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
85913 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
85914 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
85915 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
85916 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
85917 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
85918 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
85919 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
85920 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
85921 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
85922 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
85923 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
85924 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
85925 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
85926 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
85927 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
85928 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
85929 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
85930 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
85931 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
85932 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
85933 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
85934 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
85935 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
85936 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
85937 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
85938 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
85939 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
85940 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
85941 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
85942 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
85943 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
85944 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
85945 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
85946 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
85947 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
85948 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
85949 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
85950 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
85951 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
85952 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
85953 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
85954 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
85955 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
85956 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
85957 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
85958 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
85959 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
85960 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
85961 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
85962 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
85963 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
85964 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
85965 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
85966 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
85967 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
85968 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
85969 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
85970 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
85971 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
85972 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
85973 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
85974 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
85975 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
85976 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
85977 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
85978 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
85979 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
85980 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
85981 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
85982 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
85983 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
85984 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
85985 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
85986 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
85987 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
85988 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
85989 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
85990 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
85991 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
85992 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
85993 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
85994 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
85995 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
85996 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
85997 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
85998 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
85999 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86000 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86001 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86002 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86003 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86004 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86005 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86006 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86007 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86008 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86009 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86010 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86011 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86012 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86013 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86014 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86015 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86016 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86017 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86018 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86019 +_002570_hash map_addr 6 4666 _002570_hash NULL
86020 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86021 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86022 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86023 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86024 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86025 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86026 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86027 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86028 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86029 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86030 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86031 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86032 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86033 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86034 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86035 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86036 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86037 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86038 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86039 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86040 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86041 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86042 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86043 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86044 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86045 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86046 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86047 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86048 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86049 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86050 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86051 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86052 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86053 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86054 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86055 +_002612_hash power_read 3 15939 _002612_hash NULL
86056 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86057 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86058 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86059 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86060 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86061 +_002618_hash prison_create 1 43623 _002618_hash NULL
86062 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86063 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86064 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86065 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86066 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86067 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86068 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86069 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86070 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86071 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86072 +_002629_hash read_dma 3 55086 _002629_hash NULL
86073 +_002630_hash read_fifo 3 826 _002630_hash NULL
86074 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86075 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86076 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86077 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86078 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86079 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86080 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86081 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86082 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86083 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86084 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86085 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86086 +_002644_hash rx_data 4 60442 _002644_hash NULL
86087 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86088 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86089 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86090 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86091 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86092 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86093 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86094 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86095 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86096 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86097 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86098 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86099 +_002658_hash send_stream 4 3397 _002658_hash NULL
86100 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86101 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86102 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86103 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86104 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86105 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86106 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86107 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86108 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86109 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86110 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86111 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86112 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86113 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86114 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86115 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86116 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86117 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86118 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86119 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86120 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86121 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86122 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86123 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86124 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86125 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86126 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86127 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86128 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86129 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86130 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86131 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86132 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86133 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86134 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86135 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86136 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86137 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86138 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86139 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86140 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86141 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86142 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86143 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86144 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86145 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86146 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86147 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86148 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86149 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86150 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86151 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86152 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86153 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86154 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86155 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86156 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86157 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86158 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86159 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86160 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86161 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86162 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86163 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86164 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86165 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86166 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86167 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86168 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86169 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86170 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86171 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86172 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86173 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86174 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86175 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86176 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86177 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86178 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86179 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86180 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86181 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86182 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86183 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86184 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86185 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86186 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86187 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86188 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86189 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86190 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86191 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86192 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86193 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86194 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86195 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86196 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86197 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86198 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86199 +_002770_hash push_rx 3 28939 _002770_hash NULL
86200 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86201 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86202 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86203 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86204 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86205 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86206 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86207 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86208 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86209 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86210 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86211 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86212 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86213 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86214 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86215 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86216 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86217 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86218 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86219 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86220 +_002794_hash write_leb 5 36957 _002794_hash NULL
86221 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86222 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86223 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86224 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86225 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86226 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86227 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86228 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86229 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86230 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86231 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86232 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86233 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86234 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86235 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86236 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86237 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86238 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86239 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86240 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86241 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86242 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86243 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86244 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86245 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86246 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86247 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86248 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86249 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86250 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86251 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86252 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86253 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86254 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86255 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86256 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86257 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86258 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86259 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86260 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86261 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86262 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86263 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86264 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86265 +_002846_hash recover_head 3 17904 _002846_hash NULL
86266 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86267 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86268 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86269 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86270 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86271 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86272 +_002853_hash write_head 4 30481 _002853_hash NULL
86273 +_002854_hash write_node 4 33121 _002854_hash NULL
86274 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86275 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86276 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86277 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86278 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86279 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86280 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86281 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86282 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86283 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86284 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86285 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86286 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86287 +_002869_hash create_log 2 8225 _002869_hash NULL
86288 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86289 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86290 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86291 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86292 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86293 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86294 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86295 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86296 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86297 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86298 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86299 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86300 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86301 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86302 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86303 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86304 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86305 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86306 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86307 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86308 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86309 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86310 +_002893_hash _malloc 1 54077 _002893_hash NULL
86311 +_002894_hash mei_read 3 6507 _002894_hash NULL
86312 +_002895_hash mei_write 3 4005 _002895_hash NULL
86313 +_002896_hash msg_set 3 51725 _002896_hash NULL
86314 +_002897_hash newpart 6 47485 _002897_hash NULL
86315 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86316 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86317 +_002900_hash packet_came 3 18072 _002900_hash NULL
86318 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86319 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86320 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86321 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86322 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86323 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86324 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86325 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86326 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86327 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86328 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86329 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86330 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86331 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86332 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86333 +_002923_hash sep_read 3 17161 _002923_hash NULL
86334 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86335 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86336 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86337 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86338 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86339 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86340 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86341 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86342 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86343 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86344 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86345 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86346 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86347 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86348 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86349 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86350 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86351 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86352 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86353 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86354 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86355 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86356 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86357 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86358 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86359 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86360 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86361 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86362 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86363 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86364 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86365 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86366 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86367 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86368 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86369 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86370 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86371 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86372 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86373 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86374 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86375 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86376 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86377 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86378 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86379 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86380 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86381 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86382 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86383 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86384 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86385 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86386 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86387 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86388 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86389 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86390 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86391 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86392 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86393 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86394 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86395 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86396 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86397 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86398 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86399 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86400 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86401 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86402 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86403 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86404 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86405 +_003003_hash flash_read 3 57843 _003003_hash NULL
86406 +_003004_hash flash_write 3 62354 _003004_hash NULL
86407 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86408 +_003006_hash gather_array 3 56641 _003006_hash NULL
86409 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86410 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86411 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86412 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86413 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86414 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86415 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86416 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86417 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86418 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86419 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86420 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86421 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86422 +_003021_hash options_write 3 47243 _003021_hash NULL
86423 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86424 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86425 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86426 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86427 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86428 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86429 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86430 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86431 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86432 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86433 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86434 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86435 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86436 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86437 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86438 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86439 +_003038_hash split 2 11691 _003038_hash NULL
86440 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86441 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86442 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86443 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86444 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86445 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86446 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86447 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86448 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86449 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86450 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86451 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86452 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86453 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86454 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86455 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86456 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86457 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86458 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86459 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86460 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86461 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86462 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86463 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86464 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86465 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86466 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86467 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86468 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86469 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86470 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86471 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86472 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86473 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86474 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86475 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86476 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86477 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86478 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86479 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86480 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86481 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86482 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86483 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86484 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86485 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86486 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86487 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86488 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86489 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86490 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86491 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86492 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86493 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86494 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86495 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86496 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86497 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86498 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86499 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86500 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86501 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86502 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86503 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86504 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86505 +_003108_hash conf_read 3 55786 _003108_hash NULL
86506 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86507 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86508 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86509 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86510 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86511 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86512 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86513 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86514 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86515 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86516 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86517 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86518 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86519 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86520 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86521 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86522 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86523 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86524 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86525 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86526 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86527 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86528 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86529 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86530 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86531 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86532 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86533 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86534 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86535 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86536 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86537 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86538 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86539 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86540 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86541 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86542 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86543 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86544 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86545 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86546 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86547 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86548 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86549 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86550 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86551 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86552 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86553 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86554 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86555 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86556 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86557 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86558 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86559 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86560 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86561 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86562 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86563 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86564 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86565 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86566 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86567 +_003175_hash get_info 3 55681 _003175_hash NULL
86568 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86569 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86570 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86571 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86572 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86573 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86574 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86575 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86576 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86577 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86578 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86579 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86580 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86581 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
86582 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
86583 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
86584 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
86585 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
86586 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
86587 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
86588 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
86589 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
86590 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
86591 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
86592 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
86593 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
86594 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
86595 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
86596 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
86597 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
86598 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
86599 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
86600 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
86601 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
86602 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
86603 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
86604 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
86605 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
86606 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
86607 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
86608 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
86609 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
86610 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
86611 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
86612 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
86613 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
86614 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
86615 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
86616 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
86617 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
86618 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
86619 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
86620 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
86621 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
86622 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
86623 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
86624 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
86625 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
86626 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
86627 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
86628 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
86629 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
86630 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
86631 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
86632 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
86633 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
86634 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
86635 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
86636 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
86637 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
86638 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
86639 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
86640 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
86641 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
86642 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
86643 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
86644 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
86645 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
86646 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
86647 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
86648 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
86649 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
86650 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
86651 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
86652 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
86653 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
86654 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
86655 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
86656 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
86657 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
86658 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
86659 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
86660 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
86661 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
86662 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
86663 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
86664 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
86665 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
86666 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
86667 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
86668 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
86669 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
86670 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
86671 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
86672 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
86673 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
86674 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
86675 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
86676 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
86677 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
86678 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
86679 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
86680 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
86681 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
86682 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
86683 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
86684 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
86685 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
86686 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
86687 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
86688 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
86689 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
86690 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
86691 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
86692 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
86693 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
86694 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
86695 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
86696 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
86697 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
86698 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
86699 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
86700 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
86701 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
86702 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
86703 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
86704 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
86705 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
86706 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
86707 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
86708 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
86709 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
86710 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
86711 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
86712 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
86713 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
86714 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
86715 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
86716 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
86717 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
86718 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
86719 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
86720 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
86721 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
86722 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
86723 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
86724 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
86725 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
86726 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
86727 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
86728 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
86729 +_003340_hash alloc_private 2 22399 _003340_hash NULL
86730 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
86731 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
86732 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
86733 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
86734 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
86735 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
86736 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
86737 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
86738 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
86739 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
86740 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
86741 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
86742 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
86743 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
86744 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
86745 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
86746 +_003359_hash comedi_read 3 13199 _003359_hash NULL
86747 +_003360_hash comedi_write 3 47926 _003360_hash NULL
86748 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
86749 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
86750 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
86751 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
86752 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
86753 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
86754 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
86755 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
86756 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
86757 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
86758 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
86759 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
86760 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
86761 +_003377_hash dev_read 3 56369 _003377_hash NULL
86762 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
86763 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
86764 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
86765 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
86766 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
86767 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
86768 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
86769 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
86770 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
86771 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
86772 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
86773 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
86774 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
86775 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
86776 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
86777 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
86778 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
86779 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
86780 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
86781 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
86782 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
86783 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
86784 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
86785 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
86786 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
86787 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
86788 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
86789 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
86790 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
86791 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
86792 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
86793 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
86794 +_003412_hash fb_read 3 33506 _003412_hash NULL
86795 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
86796 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
86797 +_003415_hash fb_write 3 46924 _003415_hash NULL
86798 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
86799 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
86800 +_003418_hash fops_read 3 40672 _003418_hash NULL
86801 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
86802 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
86803 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
86804 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
86805 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
86806 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
86807 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
86808 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
86809 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
86810 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
86811 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
86812 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
86813 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
86814 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
86815 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
86816 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
86817 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
86818 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
86819 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
86820 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
86821 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
86822 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
86823 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
86824 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
86825 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
86826 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
86827 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
86828 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
86829 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
86830 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
86831 +_003451_hash lirc_write 3 20604 _003451_hash NULL
86832 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
86833 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
86834 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
86835 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
86836 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
86837 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
86838 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
86839 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
86840 +_003461_hash mmio_read 4 40348 _003461_hash NULL
86841 +_003462_hash netlink_send 5 38434 _003462_hash NULL
86842 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
86843 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
86844 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
86845 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
86846 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
86847 +_003468_hash odev_update 2 50169 _003468_hash NULL
86848 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
86849 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
86850 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
86851 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
86852 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
86853 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
86854 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
86855 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
86856 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
86857 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
86858 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
86859 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
86860 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
86861 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
86862 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
86863 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
86864 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
86865 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
86866 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
86867 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
86868 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
86869 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
86870 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
86871 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
86872 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
86873 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
86874 +_003497_hash play_iframe 3 8219 _003497_hash NULL
86875 +_003498_hash probes_write 3 29711 _003498_hash NULL
86876 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
86877 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
86878 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
86879 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
86880 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
86881 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
86882 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
86883 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
86884 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
86885 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
86886 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
86887 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
86888 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
86889 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
86890 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
86891 +_003514_hash qc_capture 3 19298 _003514_hash NULL
86892 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
86893 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
86894 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
86895 +_003518_hash Realloc 2 34961 _003518_hash NULL
86896 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
86897 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
86898 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
86899 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
86900 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
86901 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
86902 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
86903 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
86904 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
86905 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
86906 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
86907 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
86908 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
86909 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
86910 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
86911 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
86912 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
86913 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
86914 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
86915 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
86916 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
86917 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
86918 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
86919 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
86920 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
86921 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
86922 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
86923 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
86924 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
86925 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
86926 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
86927 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
86928 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
86929 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
86930 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
86931 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
86932 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
86933 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
86934 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
86935 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
86936 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
86937 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
86938 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
86939 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
86940 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
86941 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
86942 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
86943 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
86944 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
86945 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
86946 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
86947 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
86948 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
86949 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
86950 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
86951 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
86952 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
86953 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
86954 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
86955 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
86956 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
86957 +_003584_hash ts_read 3 44687 _003584_hash NULL
86958 +_003585_hash ts_write 3 64336 _003585_hash NULL
86959 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
86960 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
86961 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
86962 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
86963 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
86964 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
86965 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
86966 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
86967 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
86968 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
86969 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
86970 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
86971 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
86972 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
86973 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
86974 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
86975 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
86976 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
86977 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
86978 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
86979 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
86980 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
86981 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
86982 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
86983 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
86984 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
86985 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
86986 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
86987 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
86988 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
86989 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
86990 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
86991 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
86992 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
86993 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
86994 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
86995 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
86996 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
86997 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
86998 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
86999 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87000 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87001 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87002 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87003 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87004 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87005 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87006 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87007 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87008 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87009 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87010 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87011 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87012 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87013 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87014 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87015 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87016 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87017 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87018 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87019 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87020 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87021 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87022 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87023 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87024 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87025 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87026 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87027 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87028 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87029 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87030 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87031 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87032 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87033 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87034 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87035 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87036 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87037 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87038 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87039 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87040 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87041 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87042 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87043 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87044 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87045 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87046 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87047 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87048 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87049 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87050 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87051 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87052 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87053 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87054 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87055 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87056 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87057 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87058 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87059 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87060 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87061 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87062 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87063 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87064 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87065 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87066 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87067 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87068 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87069 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87070 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87071 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87072 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87073 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87074 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87075 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87076 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87077 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87078 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87079 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87080 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87081 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87082 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87083 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87084 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87085 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87086 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87087 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87088 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87089 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87090 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87091 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87092 +_003729_hash vmap 2 15025 _003729_hash NULL
87093 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87094 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87095 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87096 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87097 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87098 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87099 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87100 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87101 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87102 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87103 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87104 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87105 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87106 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87107 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87108 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87109 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87110 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87111 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87112 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87113 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87114 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87115 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87116 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87117 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87118 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87119 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87120 +_003766_hash video_read 3 28148 _003766_hash NULL
87121 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87122 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87123 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87124 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87125 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87126 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87127 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87128 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87129 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87130 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87131 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87132 +_003783_hash do_test 1 15766 _003783_hash NULL
87133 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87134 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87135 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87136 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87137 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87138 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87139 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87140 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87141 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87142 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87143 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87144 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87145 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87146 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87147 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87148 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87149 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87150 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87151 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87152 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87153 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87154 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87155 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87156 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87157 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87158 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87159 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87160 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87161 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87162 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87163 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87164 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87165 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87166 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87167 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87168 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87169 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87170 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87171 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87172 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87173 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87174 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87175 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87176 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87177 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87178 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87179 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87180 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87181 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87182 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87183 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87184 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87185 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87186 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87187 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87188 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87189 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87190 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87191 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87192 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87193 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87194 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87195 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87196 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87197 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87198 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87199 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87200 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87201 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87202 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87203 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87204 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87205 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87206 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87207 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87208 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87209 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87210 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87211 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87212 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87213 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87214 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87215 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87216 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87217 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87218 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87219 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87220 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87221 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87222 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87223 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87224 new file mode 100644
87225 index 0000000..244559e
87226 --- /dev/null
87227 +++ b/tools/gcc/size_overflow_plugin.c
87228 @@ -0,0 +1,1879 @@
87229 +/*
87230 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87231 + * Licensed under the GPL v2, or (at your option) v3
87232 + *
87233 + * Homepage:
87234 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87235 + *
87236 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87237 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87238 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87239 + *
87240 + * Usage:
87241 + * $ 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
87242 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87243 + */
87244 +
87245 +#include "gcc-plugin.h"
87246 +#include "config.h"
87247 +#include "system.h"
87248 +#include "coretypes.h"
87249 +#include "tree.h"
87250 +#include "tree-pass.h"
87251 +#include "intl.h"
87252 +#include "plugin-version.h"
87253 +#include "tm.h"
87254 +#include "toplev.h"
87255 +#include "function.h"
87256 +#include "tree-flow.h"
87257 +#include "plugin.h"
87258 +#include "gimple.h"
87259 +#include "c-common.h"
87260 +#include "diagnostic.h"
87261 +#include "cfgloop.h"
87262 +
87263 +#if BUILDING_GCC_VERSION >= 4007
87264 +#include "c-tree.h"
87265 +#else
87266 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87267 +#endif
87268 +
87269 +struct size_overflow_hash {
87270 + const struct size_overflow_hash * const next;
87271 + const char * const name;
87272 + const unsigned int param;
87273 +};
87274 +
87275 +#include "size_overflow_hash.h"
87276 +
87277 +enum marked {
87278 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87279 +};
87280 +
87281 +#define __unused __attribute__((__unused__))
87282 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87283 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87284 +#define BEFORE_STMT true
87285 +#define AFTER_STMT false
87286 +#define CREATE_NEW_VAR NULL_TREE
87287 +#define CODES_LIMIT 32
87288 +#define MAX_PARAM 32
87289 +#define MY_STMT GF_PLF_1
87290 +#define NO_CAST_CHECK GF_PLF_2
87291 +
87292 +#if BUILDING_GCC_VERSION == 4005
87293 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87294 +#endif
87295 +
87296 +int plugin_is_GPL_compatible;
87297 +void debug_gimple_stmt(gimple gs);
87298 +
87299 +static tree expand(struct pointer_set_t *visited, tree lhs);
87300 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87301 +static tree report_size_overflow_decl;
87302 +static const_tree const_char_ptr_type_node;
87303 +static unsigned int handle_function(void);
87304 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87305 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87306 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87307 +
87308 +static struct plugin_info size_overflow_plugin_info = {
87309 + .version = "20120930beta",
87310 + .help = "no-size-overflow\tturn off size overflow checking\n",
87311 +};
87312 +
87313 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87314 +{
87315 + unsigned int arg_count;
87316 + enum tree_code code = TREE_CODE(*node);
87317 +
87318 + switch (code) {
87319 + case FUNCTION_DECL:
87320 + arg_count = type_num_arguments(TREE_TYPE(*node));
87321 + break;
87322 + case FUNCTION_TYPE:
87323 + case METHOD_TYPE:
87324 + arg_count = type_num_arguments(*node);
87325 + break;
87326 + default:
87327 + *no_add_attrs = true;
87328 + error("%s: %qE attribute only applies to functions", __func__, name);
87329 + return NULL_TREE;
87330 + }
87331 +
87332 + for (; args; args = TREE_CHAIN(args)) {
87333 + tree position = TREE_VALUE(args);
87334 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87335 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87336 + *no_add_attrs = true;
87337 + }
87338 + }
87339 + return NULL_TREE;
87340 +}
87341 +
87342 +static const char* get_asm_name(tree node)
87343 +{
87344 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87345 +}
87346 +
87347 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87348 +{
87349 + unsigned int arg_count, arg_num;
87350 + enum tree_code code = TREE_CODE(*node);
87351 +
87352 + switch (code) {
87353 + case FUNCTION_DECL:
87354 + arg_count = type_num_arguments(TREE_TYPE(*node));
87355 + break;
87356 + case FUNCTION_TYPE:
87357 + case METHOD_TYPE:
87358 + arg_count = type_num_arguments(*node);
87359 + break;
87360 + case FIELD_DECL:
87361 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87362 + if (arg_num != 0) {
87363 + *no_add_attrs = true;
87364 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87365 + }
87366 + return NULL_TREE;
87367 + default:
87368 + *no_add_attrs = true;
87369 + error("%qE attribute only applies to functions", name);
87370 + return NULL_TREE;
87371 + }
87372 +
87373 + for (; args; args = TREE_CHAIN(args)) {
87374 + tree position = TREE_VALUE(args);
87375 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87376 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87377 + *no_add_attrs = true;
87378 + }
87379 + }
87380 + return NULL_TREE;
87381 +}
87382 +
87383 +static struct attribute_spec size_overflow_attr = {
87384 + .name = "size_overflow",
87385 + .min_length = 1,
87386 + .max_length = -1,
87387 + .decl_required = true,
87388 + .type_required = false,
87389 + .function_type_required = false,
87390 + .handler = handle_size_overflow_attribute,
87391 +#if BUILDING_GCC_VERSION >= 4007
87392 + .affects_type_identity = false
87393 +#endif
87394 +};
87395 +
87396 +static struct attribute_spec intentional_overflow_attr = {
87397 + .name = "intentional_overflow",
87398 + .min_length = 1,
87399 + .max_length = -1,
87400 + .decl_required = true,
87401 + .type_required = false,
87402 + .function_type_required = false,
87403 + .handler = handle_intentional_overflow_attribute,
87404 +#if BUILDING_GCC_VERSION >= 4007
87405 + .affects_type_identity = false
87406 +#endif
87407 +};
87408 +
87409 +static void register_attributes(void __unused *event_data, void __unused *data)
87410 +{
87411 + register_attribute(&size_overflow_attr);
87412 + register_attribute(&intentional_overflow_attr);
87413 +}
87414 +
87415 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87416 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87417 +{
87418 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87419 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87420 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87421 +
87422 + unsigned int m = 0x57559429;
87423 + unsigned int n = 0x5052acdb;
87424 + const unsigned int *key4 = (const unsigned int *)key;
87425 + unsigned int h = len;
87426 + unsigned int k = len + seed + n;
87427 + unsigned long long p;
87428 +
87429 + while (len >= 8) {
87430 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87431 + len -= 8;
87432 + }
87433 + if (len >= 4) {
87434 + cwmixb(key4[0]) key4 += 1;
87435 + len -= 4;
87436 + }
87437 + if (len)
87438 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87439 + cwmixb(h ^ (k + n));
87440 + return k ^ h;
87441 +
87442 +#undef cwfold
87443 +#undef cwmixa
87444 +#undef cwmixb
87445 +}
87446 +
87447 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87448 +{
87449 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87450 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87451 + return fn ^ codes;
87452 +}
87453 +
87454 +static inline tree get_original_function_decl(tree fndecl)
87455 +{
87456 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87457 + return DECL_ABSTRACT_ORIGIN(fndecl);
87458 + return fndecl;
87459 +}
87460 +
87461 +static inline gimple get_def_stmt(const_tree node)
87462 +{
87463 + gcc_assert(node != NULL_TREE);
87464 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87465 + return SSA_NAME_DEF_STMT(node);
87466 +}
87467 +
87468 +static unsigned char get_tree_code(const_tree type)
87469 +{
87470 + switch (TREE_CODE(type)) {
87471 + case ARRAY_TYPE:
87472 + return 0;
87473 + case BOOLEAN_TYPE:
87474 + return 1;
87475 + case ENUMERAL_TYPE:
87476 + return 2;
87477 + case FUNCTION_TYPE:
87478 + return 3;
87479 + case INTEGER_TYPE:
87480 + return 4;
87481 + case POINTER_TYPE:
87482 + return 5;
87483 + case RECORD_TYPE:
87484 + return 6;
87485 + case UNION_TYPE:
87486 + return 7;
87487 + case VOID_TYPE:
87488 + return 8;
87489 + case REAL_TYPE:
87490 + return 9;
87491 + case VECTOR_TYPE:
87492 + return 10;
87493 + case REFERENCE_TYPE:
87494 + return 11;
87495 + case OFFSET_TYPE:
87496 + return 12;
87497 + case COMPLEX_TYPE:
87498 + return 13;
87499 + default:
87500 + debug_tree((tree)type);
87501 + gcc_unreachable();
87502 + }
87503 +}
87504 +
87505 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87506 +{
87507 + gcc_assert(type != NULL_TREE);
87508 +
87509 + while (type && len < CODES_LIMIT) {
87510 + tree_codes[len] = get_tree_code(type);
87511 + len++;
87512 + type = TREE_TYPE(type);
87513 + }
87514 + return len;
87515 +}
87516 +
87517 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87518 +{
87519 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87520 + enum tree_code code = TREE_CODE(type);
87521 + size_t len = 0;
87522 +
87523 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87524 +
87525 + arg = TYPE_ARG_TYPES(type);
87526 + // skip builtins __builtin_constant_p
87527 + if (!arg && DECL_BUILT_IN(fndecl))
87528 + return 0;
87529 +
87530 + if (TREE_CODE_CLASS(code) == tcc_type)
87531 + result = type;
87532 + else
87533 + result = DECL_RESULT(fndecl);
87534 +
87535 + gcc_assert(result != NULL_TREE);
87536 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87537 +
87538 + if (arg == NULL_TREE) {
87539 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87540 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87541 + if (arg_field == NULL_TREE)
87542 + return 0;
87543 + arg = TREE_TYPE(arg_field);
87544 + len = add_type_codes(arg, tree_codes, len);
87545 + gcc_assert(len != 0);
87546 + return len;
87547 + }
87548 +
87549 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87550 + while (arg && len < CODES_LIMIT) {
87551 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87552 + arg = TREE_CHAIN(arg);
87553 + }
87554 +
87555 + gcc_assert(len != 0);
87556 + return len;
87557 +}
87558 +
87559 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87560 +{
87561 + unsigned int hash;
87562 + const struct size_overflow_hash *entry;
87563 + unsigned char tree_codes[CODES_LIMIT];
87564 + size_t len;
87565 + const char *func_name = get_asm_name(fndecl);
87566 +
87567 + len = get_function_decl(fndecl, tree_codes);
87568 + if (len == 0)
87569 + return NULL;
87570 +
87571 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87572 +
87573 + entry = size_overflow_hash[hash];
87574 + while (entry) {
87575 + if (!strcmp(entry->name, func_name))
87576 + return entry;
87577 + entry = entry->next;
87578 + }
87579 +
87580 + return NULL;
87581 +}
87582 +
87583 +static void check_arg_type(const_tree arg)
87584 +{
87585 + const_tree type = TREE_TYPE(arg);
87586 + enum tree_code code = TREE_CODE(type);
87587 +
87588 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
87589 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
87590 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
87591 +}
87592 +
87593 +static int find_arg_number(const_tree arg, tree func)
87594 +{
87595 + tree var;
87596 + unsigned int argnum = 1;
87597 +
87598 + if (TREE_CODE(arg) == SSA_NAME)
87599 + arg = SSA_NAME_VAR(arg);
87600 +
87601 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
87602 + if (strcmp(NAME(arg), NAME(var))) {
87603 + argnum++;
87604 + continue;
87605 + }
87606 + check_arg_type(var);
87607 + return argnum;
87608 + }
87609 + gcc_unreachable();
87610 +}
87611 +
87612 +static tree create_new_var(tree type)
87613 +{
87614 + tree new_var = create_tmp_var(type, "cicus");
87615 +
87616 + add_referenced_var(new_var);
87617 + mark_sym_for_renaming(new_var);
87618 + return new_var;
87619 +}
87620 +
87621 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
87622 +{
87623 + gimple assign;
87624 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87625 + tree type = TREE_TYPE(rhs1);
87626 + tree lhs = create_new_var(type);
87627 +
87628 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
87629 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87630 +
87631 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87632 + update_stmt(assign);
87633 + gimple_set_plf(assign, MY_STMT, true);
87634 + return assign;
87635 +}
87636 +
87637 +static bool is_bool(const_tree node)
87638 +{
87639 + const_tree type;
87640 +
87641 + if (node == NULL_TREE)
87642 + return false;
87643 +
87644 + type = TREE_TYPE(node);
87645 + if (!INTEGRAL_TYPE_P(type))
87646 + return false;
87647 + if (TREE_CODE(type) == BOOLEAN_TYPE)
87648 + return true;
87649 + if (TYPE_PRECISION(type) == 1)
87650 + return true;
87651 + return false;
87652 +}
87653 +
87654 +static tree cast_a_tree(tree type, tree var)
87655 +{
87656 + gcc_assert(type != NULL_TREE);
87657 + gcc_assert(var != NULL_TREE);
87658 + gcc_assert(fold_convertible_p(type, var));
87659 +
87660 + return fold_convert(type, var);
87661 +}
87662 +
87663 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
87664 +{
87665 + gimple assign;
87666 +
87667 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
87668 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
87669 + gcc_unreachable();
87670 +
87671 + if (lhs == CREATE_NEW_VAR)
87672 + lhs = create_new_var(dst_type);
87673 +
87674 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
87675 +
87676 + if (!gsi_end_p(*gsi)) {
87677 + location_t loc = gimple_location(gsi_stmt(*gsi));
87678 + gimple_set_location(assign, loc);
87679 + }
87680 +
87681 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87682 +
87683 + if (before)
87684 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
87685 + else
87686 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
87687 + update_stmt(assign);
87688 + gimple_set_plf(assign, MY_STMT, true);
87689 +
87690 + return assign;
87691 +}
87692 +
87693 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
87694 +{
87695 + const_gimple assign;
87696 + gimple_stmt_iterator gsi;
87697 +
87698 + if (new_rhs1 == NULL_TREE)
87699 + return NULL_TREE;
87700 +
87701 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
87702 + gsi = gsi_for_stmt(stmt);
87703 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
87704 + return gimple_get_lhs(assign);
87705 + }
87706 + return new_rhs1;
87707 +}
87708 +
87709 +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)
87710 +{
87711 + tree size_overflow_type = get_size_overflow_type(stmt, node);
87712 +
87713 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87714 +
87715 + if (new_rhs2 != NULL_TREE)
87716 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
87717 +
87718 + if (new_rhs3 != NULL_TREE)
87719 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
87720 +
87721 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
87722 +}
87723 +
87724 +
87725 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
87726 +{
87727 + tree size_overflow_type, lhs;
87728 + gimple stmt;
87729 + gimple_stmt_iterator gsi;
87730 +
87731 + if (rhs1 == NULL_TREE) {
87732 + debug_gimple_stmt(oldstmt);
87733 + error("%s: rhs1 is NULL_TREE", __func__);
87734 + gcc_unreachable();
87735 + }
87736 +
87737 + if (gimple_code(oldstmt) == GIMPLE_ASM)
87738 + lhs = rhs1;
87739 + else
87740 + lhs = gimple_get_lhs(oldstmt);
87741 +
87742 + gsi = gsi_for_stmt(oldstmt);
87743 + pointer_set_insert(visited, oldstmt);
87744 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
87745 + basic_block next_bb, cur_bb;
87746 + const_edge e;
87747 +
87748 + gcc_assert(before == false);
87749 + gcc_assert(stmt_can_throw_internal(oldstmt));
87750 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
87751 + gcc_assert(!gsi_end_p(gsi));
87752 +
87753 + cur_bb = gimple_bb(oldstmt);
87754 + next_bb = cur_bb->next_bb;
87755 + e = find_edge(cur_bb, next_bb);
87756 + gcc_assert(e != NULL);
87757 + gcc_assert(e->flags & EDGE_FALLTHRU);
87758 +
87759 + gsi = gsi_after_labels(next_bb);
87760 + gcc_assert(!gsi_end_p(gsi));
87761 +
87762 + before = true;
87763 + oldstmt = gsi_stmt(gsi);
87764 + }
87765 +
87766 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
87767 +
87768 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
87769 + gimple_set_plf(stmt, MY_STMT, true);
87770 + return gimple_get_lhs(stmt);
87771 +}
87772 +
87773 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
87774 +{
87775 + gimple stmt;
87776 + gimple_stmt_iterator gsi;
87777 + tree new_var, lhs = gimple_get_lhs(oldstmt);
87778 +
87779 + if (gimple_plf(oldstmt, MY_STMT))
87780 + return lhs;
87781 +
87782 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
87783 + rhs1 = gimple_assign_rhs1(oldstmt);
87784 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
87785 + }
87786 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
87787 + rhs2 = gimple_assign_rhs2(oldstmt);
87788 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
87789 + }
87790 +
87791 + stmt = gimple_copy(oldstmt);
87792 + gimple_set_location(stmt, gimple_location(oldstmt));
87793 + gimple_set_plf(stmt, MY_STMT, true);
87794 +
87795 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
87796 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
87797 +
87798 + if (is_bool(lhs))
87799 + new_var = SSA_NAME_VAR(lhs);
87800 + else
87801 + new_var = create_new_var(size_overflow_type);
87802 + new_var = make_ssa_name(new_var, stmt);
87803 + gimple_set_lhs(stmt, new_var);
87804 +
87805 + if (rhs1 != NULL_TREE) {
87806 + if (!gimple_assign_cast_p(oldstmt))
87807 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
87808 + gimple_assign_set_rhs1(stmt, rhs1);
87809 + }
87810 +
87811 + if (rhs2 != NULL_TREE)
87812 + gimple_assign_set_rhs2(stmt, rhs2);
87813 +#if BUILDING_GCC_VERSION >= 4007
87814 + if (rhs3 != NULL_TREE)
87815 + gimple_assign_set_rhs3(stmt, rhs3);
87816 +#endif
87817 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
87818 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
87819 +
87820 + gsi = gsi_for_stmt(oldstmt);
87821 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
87822 + update_stmt(stmt);
87823 + pointer_set_insert(visited, oldstmt);
87824 + return gimple_get_lhs(stmt);
87825 +}
87826 +
87827 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
87828 +{
87829 + basic_block bb;
87830 + gimple phi;
87831 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
87832 +
87833 + bb = gsi_bb(gsi);
87834 +
87835 + phi = create_phi_node(result, bb);
87836 + gsi = gsi_last(phi_nodes(bb));
87837 + gsi_remove(&gsi, false);
87838 +
87839 + gsi = gsi_for_stmt(oldstmt);
87840 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
87841 + gimple_set_bb(phi, bb);
87842 + gimple_set_plf(phi, MY_STMT, true);
87843 + return phi;
87844 +}
87845 +
87846 +static basic_block create_a_first_bb(void)
87847 +{
87848 + basic_block first_bb;
87849 +
87850 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87851 + if (dom_info_available_p(CDI_DOMINATORS))
87852 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
87853 + return first_bb;
87854 +}
87855 +
87856 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
87857 +{
87858 + basic_block bb;
87859 + const_gimple newstmt;
87860 + gimple_stmt_iterator gsi;
87861 + bool before = BEFORE_STMT;
87862 +
87863 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
87864 + gsi = gsi_for_stmt(get_def_stmt(arg));
87865 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
87866 + return gimple_get_lhs(newstmt);
87867 + }
87868 +
87869 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
87870 + gsi = gsi_after_labels(bb);
87871 + if (bb->index == 0) {
87872 + bb = create_a_first_bb();
87873 + gsi = gsi_start_bb(bb);
87874 + }
87875 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
87876 + return gimple_get_lhs(newstmt);
87877 +}
87878 +
87879 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
87880 +{
87881 + gimple newstmt;
87882 + gimple_stmt_iterator gsi;
87883 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
87884 + gimple def_newstmt = get_def_stmt(new_rhs);
87885 +
87886 + gsi_insert = gsi_insert_after;
87887 + gsi = gsi_for_stmt(def_newstmt);
87888 +
87889 + switch (gimple_code(get_def_stmt(arg))) {
87890 + case GIMPLE_PHI:
87891 + newstmt = gimple_build_assign(new_var, new_rhs);
87892 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
87893 + gsi_insert = gsi_insert_before;
87894 + break;
87895 + case GIMPLE_ASM:
87896 + case GIMPLE_CALL:
87897 + newstmt = gimple_build_assign(new_var, new_rhs);
87898 + break;
87899 + case GIMPLE_ASSIGN:
87900 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
87901 + break;
87902 + default:
87903 + /* unknown gimple_code (handle_build_new_phi_arg) */
87904 + gcc_unreachable();
87905 + }
87906 +
87907 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
87908 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
87909 + gimple_set_plf(newstmt, MY_STMT, true);
87910 + update_stmt(newstmt);
87911 + return newstmt;
87912 +}
87913 +
87914 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
87915 +{
87916 + const_gimple newstmt;
87917 + gimple def_stmt;
87918 + tree new_rhs;
87919 +
87920 + new_rhs = expand(visited, arg);
87921 + if (new_rhs == NULL_TREE)
87922 + return NULL_TREE;
87923 +
87924 + def_stmt = get_def_stmt(new_rhs);
87925 + if (gimple_code(def_stmt) == GIMPLE_NOP)
87926 + return NULL_TREE;
87927 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
87928 +
87929 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
87930 + return gimple_get_lhs(newstmt);
87931 +}
87932 +
87933 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
87934 +{
87935 + gimple phi, oldstmt = get_def_stmt(orig_result);
87936 + tree new_result, size_overflow_type;
87937 + unsigned int i;
87938 + unsigned int n = gimple_phi_num_args(oldstmt);
87939 +
87940 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
87941 +
87942 + new_result = create_new_var(size_overflow_type);
87943 +
87944 + pointer_set_insert(visited, oldstmt);
87945 + phi = overflow_create_phi_node(oldstmt, new_result);
87946 + for (i = 0; i < n; i++) {
87947 + tree arg, lhs;
87948 +
87949 + arg = gimple_phi_arg_def(oldstmt, i);
87950 + if (is_gimple_constant(arg))
87951 + arg = cast_a_tree(size_overflow_type, arg);
87952 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
87953 + if (lhs == NULL_TREE)
87954 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
87955 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
87956 + }
87957 +
87958 + update_stmt(phi);
87959 + return gimple_phi_result(phi);
87960 +}
87961 +
87962 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
87963 +{
87964 + const_gimple assign;
87965 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87966 + tree origtype = TREE_TYPE(orig_rhs);
87967 +
87968 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
87969 +
87970 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87971 + return gimple_get_lhs(assign);
87972 +}
87973 +
87974 +static void change_rhs1(gimple stmt, tree new_rhs1)
87975 +{
87976 + tree assign_rhs;
87977 + const_tree rhs = gimple_assign_rhs1(stmt);
87978 +
87979 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
87980 + gimple_assign_set_rhs1(stmt, assign_rhs);
87981 + update_stmt(stmt);
87982 +}
87983 +
87984 +static bool check_mode_type(const_gimple stmt)
87985 +{
87986 + const_tree lhs = gimple_get_lhs(stmt);
87987 + const_tree lhs_type = TREE_TYPE(lhs);
87988 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
87989 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
87990 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
87991 +
87992 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
87993 + return false;
87994 +
87995 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
87996 + return false;
87997 +
87998 + return true;
87999 +}
88000 +
88001 +static bool check_undefined_integer_operation(const_gimple stmt)
88002 +{
88003 + const_gimple def_stmt;
88004 + const_tree lhs = gimple_get_lhs(stmt);
88005 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88006 + const_tree rhs1_type = TREE_TYPE(rhs1);
88007 + const_tree lhs_type = TREE_TYPE(lhs);
88008 +
88009 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88010 + return false;
88011 +
88012 + def_stmt = get_def_stmt(rhs1);
88013 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88014 + return false;
88015 +
88016 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88017 + return false;
88018 + return true;
88019 +}
88020 +
88021 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88022 +{
88023 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88024 + enum machine_mode lhs_mode, rhs_mode;
88025 + gimple def_stmt = get_def_stmt(no_const_rhs);
88026 +
88027 + if (!gimple_assign_cast_p(def_stmt))
88028 + return false;
88029 +
88030 + rhs1 = gimple_assign_rhs1(def_stmt);
88031 + lhs = gimple_get_lhs(def_stmt);
88032 + rhs1_type = TREE_TYPE(rhs1);
88033 + lhs_type = TREE_TYPE(lhs);
88034 + rhs_mode = TYPE_MODE(rhs1_type);
88035 + lhs_mode = TYPE_MODE(lhs_type);
88036 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88037 + return false;
88038 +
88039 + return true;
88040 +}
88041 +
88042 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88043 +{
88044 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88045 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88046 + const_tree rhs1_type = TREE_TYPE(rhs1);
88047 + const_tree lhs_type = TREE_TYPE(lhs);
88048 +
88049 + new_rhs1 = expand(visited, rhs1);
88050 +
88051 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88052 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88053 +
88054 + if (gimple_plf(stmt, MY_STMT))
88055 + return lhs;
88056 +
88057 + if (gimple_plf(stmt, NO_CAST_CHECK))
88058 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88059 +
88060 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88061 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88062 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88063 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88064 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88065 + }
88066 +
88067 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88068 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88069 +
88070 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88071 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88072 +
88073 + change_rhs1(stmt, new_rhs1);
88074 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88075 +
88076 + rhs1 = gimple_assign_rhs1(stmt);
88077 + rhs1_type = TREE_TYPE(rhs1);
88078 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88079 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88080 +
88081 + if (!check_mode_type(stmt))
88082 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88083 +
88084 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88085 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88086 +
88087 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88088 +
88089 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88090 +}
88091 +
88092 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88093 +{
88094 + gimple def_stmt = get_def_stmt(lhs);
88095 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88096 +
88097 + if (is_gimple_constant(rhs1))
88098 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88099 +
88100 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88101 + switch (TREE_CODE(rhs1)) {
88102 + case SSA_NAME:
88103 + return handle_unary_rhs(visited, def_stmt);
88104 + case ARRAY_REF:
88105 + case BIT_FIELD_REF:
88106 + case ADDR_EXPR:
88107 + case COMPONENT_REF:
88108 + case INDIRECT_REF:
88109 +#if BUILDING_GCC_VERSION >= 4006
88110 + case MEM_REF:
88111 +#endif
88112 + case PARM_DECL:
88113 + case TARGET_MEM_REF:
88114 + case VAR_DECL:
88115 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88116 +
88117 + default:
88118 + debug_gimple_stmt(def_stmt);
88119 + debug_tree(rhs1);
88120 + gcc_unreachable();
88121 + }
88122 +}
88123 +
88124 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88125 +{
88126 + gimple cond_stmt;
88127 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88128 +
88129 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88130 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88131 + update_stmt(cond_stmt);
88132 +}
88133 +
88134 +static tree create_string_param(tree string)
88135 +{
88136 + tree i_type, a_type;
88137 + const int length = TREE_STRING_LENGTH(string);
88138 +
88139 + gcc_assert(length > 0);
88140 +
88141 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88142 + a_type = build_array_type(char_type_node, i_type);
88143 +
88144 + TREE_TYPE(string) = a_type;
88145 + TREE_CONSTANT(string) = 1;
88146 + TREE_READONLY(string) = 1;
88147 +
88148 + return build1(ADDR_EXPR, ptr_type_node, string);
88149 +}
88150 +
88151 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88152 +{
88153 + gimple func_stmt;
88154 + const_gimple def_stmt;
88155 + const_tree loc_line;
88156 + tree loc_file, ssa_name, current_func;
88157 + expanded_location xloc;
88158 + char ssa_name_buf[256];
88159 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88160 +
88161 + def_stmt = get_def_stmt(arg);
88162 + xloc = expand_location(gimple_location(def_stmt));
88163 +
88164 + if (!gimple_has_location(def_stmt)) {
88165 + xloc = expand_location(gimple_location(stmt));
88166 + if (!gimple_has_location(stmt))
88167 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88168 + }
88169 +
88170 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88171 +
88172 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88173 + loc_file = create_string_param(loc_file);
88174 +
88175 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88176 + current_func = create_string_param(current_func);
88177 +
88178 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88179 + ssa_name = build_string(256, ssa_name_buf);
88180 + ssa_name = create_string_param(ssa_name);
88181 +
88182 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88183 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88184 +
88185 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88186 +}
88187 +
88188 +static void __unused print_the_code_insertions(const_gimple stmt)
88189 +{
88190 + location_t loc = gimple_location(stmt);
88191 +
88192 + inform(loc, "Integer size_overflow check applied here.");
88193 +}
88194 +
88195 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88196 +{
88197 + basic_block cond_bb, join_bb, bb_true;
88198 + edge e;
88199 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88200 +
88201 + cond_bb = gimple_bb(stmt);
88202 + if (before)
88203 + gsi_prev(&gsi);
88204 + if (gsi_end_p(gsi))
88205 + e = split_block_after_labels(cond_bb);
88206 + else
88207 + e = split_block(cond_bb, gsi_stmt(gsi));
88208 + cond_bb = e->src;
88209 + join_bb = e->dest;
88210 + e->flags = EDGE_FALSE_VALUE;
88211 + e->probability = REG_BR_PROB_BASE;
88212 +
88213 + bb_true = create_empty_bb(cond_bb);
88214 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88215 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88216 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88217 +
88218 + if (dom_info_available_p(CDI_DOMINATORS)) {
88219 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88220 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88221 + }
88222 +
88223 + if (current_loops != NULL) {
88224 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88225 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88226 + }
88227 +
88228 + insert_cond(cond_bb, arg, cond_code, type_value);
88229 + insert_cond_result(bb_true, stmt, arg, min);
88230 +
88231 +// print_the_code_insertions(stmt);
88232 +}
88233 +
88234 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88235 +{
88236 + const_tree rhs_type = TREE_TYPE(rhs);
88237 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88238 +
88239 + gcc_assert(rhs_type != NULL_TREE);
88240 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88241 + return;
88242 +
88243 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88244 +
88245 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88246 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88247 +
88248 + gcc_assert(!TREE_OVERFLOW(type_max));
88249 +
88250 + cast_rhs_type = TREE_TYPE(cast_rhs);
88251 + type_max_type = TREE_TYPE(type_max);
88252 + type_min_type = TREE_TYPE(type_min);
88253 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88254 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88255 +
88256 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88257 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88258 +}
88259 +
88260 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88261 +{
88262 + gimple change_rhs_def_stmt;
88263 + tree lhs = gimple_get_lhs(def_stmt);
88264 + tree lhs_type = TREE_TYPE(lhs);
88265 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88266 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88267 +
88268 + if (change_rhs == NULL_TREE)
88269 + return get_size_overflow_type(def_stmt, lhs);
88270 +
88271 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88272 +
88273 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88274 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88275 +
88276 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88277 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88278 +
88279 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88280 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88281 +
88282 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88283 + debug_gimple_stmt(def_stmt);
88284 + gcc_unreachable();
88285 + }
88286 +
88287 + return get_size_overflow_type(def_stmt, lhs);
88288 +}
88289 +
88290 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88291 +{
88292 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88293 + return false;
88294 + if (!is_gimple_constant(rhs))
88295 + return false;
88296 + return true;
88297 +}
88298 +
88299 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88300 +{
88301 + gimple def_stmt;
88302 +
88303 + def_stmt = get_def_stmt(new_rhs);
88304 + // get_size_overflow_type
88305 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88306 + gcc_assert(gimple_assign_cast_p(def_stmt));
88307 + return gimple_assign_rhs1(def_stmt);
88308 +}
88309 +
88310 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88311 +{
88312 + gimple_stmt_iterator gsi;
88313 + const_gimple cast_stmt;
88314 + gimple def_stmt;
88315 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88316 +
88317 + if (mode != TImode && mode != DImode) {
88318 + def_stmt = get_def_stmt(new_rhs);
88319 + gcc_assert(gimple_assign_cast_p(def_stmt));
88320 + new_rhs = gimple_assign_rhs1(def_stmt);
88321 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88322 + }
88323 +
88324 + gcc_assert(mode == TImode || mode == DImode);
88325 +
88326 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88327 + return new_rhs;
88328 +
88329 + gsi = gsi_for_stmt(stmt);
88330 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88331 + new_rhs = gimple_get_lhs(cast_stmt);
88332 +
88333 + if (mode == DImode)
88334 + return new_rhs;
88335 +
88336 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88337 +
88338 + return new_rhs;
88339 +}
88340 +
88341 +static bool is_an_integer_trunction(const_gimple stmt)
88342 +{
88343 + gimple rhs1_def_stmt, rhs2_def_stmt;
88344 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88345 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88346 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88347 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88348 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88349 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88350 +
88351 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88352 + return false;
88353 +
88354 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88355 +
88356 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88357 + return false;
88358 +
88359 + rhs1_def_stmt = get_def_stmt(rhs1);
88360 + rhs2_def_stmt = get_def_stmt(rhs2);
88361 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88362 + return false;
88363 +
88364 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88365 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88366 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88367 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88368 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88369 + return false;
88370 +
88371 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88372 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88373 + return true;
88374 +}
88375 +
88376 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88377 +{
88378 + tree new_rhs1, new_rhs2;
88379 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88380 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88381 + gimple assign, stmt = get_def_stmt(lhs);
88382 + tree rhs1 = gimple_assign_rhs1(stmt);
88383 + tree rhs2 = gimple_assign_rhs2(stmt);
88384 +
88385 + if (!is_an_integer_trunction(stmt))
88386 + return NULL_TREE;
88387 +
88388 + new_rhs1 = expand(visited, rhs1);
88389 + new_rhs2 = expand(visited, rhs2);
88390 +
88391 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88392 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88393 +
88394 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88395 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88396 +
88397 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88398 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88399 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88400 + }
88401 +
88402 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88403 + new_lhs = gimple_get_lhs(assign);
88404 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88405 +
88406 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88407 +}
88408 +
88409 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88410 +{
88411 + const_gimple def_stmt;
88412 +
88413 + if (TREE_CODE(rhs) != SSA_NAME)
88414 + return false;
88415 +
88416 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88417 + return false;
88418 +
88419 + def_stmt = get_def_stmt(rhs);
88420 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88421 + return false;
88422 +
88423 + return true;
88424 +}
88425 +
88426 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88427 +{
88428 + tree new_rhs, size_overflow_type, orig_rhs;
88429 + void (*gimple_assign_set_rhs)(gimple, tree);
88430 + tree rhs1 = gimple_assign_rhs1(stmt);
88431 + tree rhs2 = gimple_assign_rhs2(stmt);
88432 + tree lhs = gimple_get_lhs(stmt);
88433 +
88434 + if (change_rhs == NULL_TREE)
88435 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88436 +
88437 + if (new_rhs2 == NULL_TREE) {
88438 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88439 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88440 + orig_rhs = rhs1;
88441 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88442 + } else {
88443 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88444 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88445 + orig_rhs = rhs2;
88446 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88447 + }
88448 +
88449 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88450 +
88451 + if (check_overflow)
88452 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88453 +
88454 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88455 + gimple_assign_set_rhs(stmt, new_rhs);
88456 + update_stmt(stmt);
88457 +
88458 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88459 +}
88460 +
88461 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88462 +{
88463 + tree rhs1, rhs2, new_lhs;
88464 + gimple def_stmt = get_def_stmt(lhs);
88465 + tree new_rhs1 = NULL_TREE;
88466 + tree new_rhs2 = NULL_TREE;
88467 +
88468 + rhs1 = gimple_assign_rhs1(def_stmt);
88469 + rhs2 = gimple_assign_rhs2(def_stmt);
88470 +
88471 + /* no DImode/TImode division in the 32/64 bit kernel */
88472 + switch (gimple_assign_rhs_code(def_stmt)) {
88473 + case RDIV_EXPR:
88474 + case TRUNC_DIV_EXPR:
88475 + case CEIL_DIV_EXPR:
88476 + case FLOOR_DIV_EXPR:
88477 + case ROUND_DIV_EXPR:
88478 + case TRUNC_MOD_EXPR:
88479 + case CEIL_MOD_EXPR:
88480 + case FLOOR_MOD_EXPR:
88481 + case ROUND_MOD_EXPR:
88482 + case EXACT_DIV_EXPR:
88483 + case POINTER_PLUS_EXPR:
88484 + case BIT_AND_EXPR:
88485 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88486 + default:
88487 + break;
88488 + }
88489 +
88490 + new_lhs = handle_integer_truncation(visited, lhs);
88491 + if (new_lhs != NULL_TREE)
88492 + return new_lhs;
88493 +
88494 + if (TREE_CODE(rhs1) == SSA_NAME)
88495 + new_rhs1 = expand(visited, rhs1);
88496 + if (TREE_CODE(rhs2) == SSA_NAME)
88497 + new_rhs2 = expand(visited, rhs2);
88498 +
88499 + if (is_a_neg_overflow(def_stmt, rhs2))
88500 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88501 + if (is_a_neg_overflow(def_stmt, rhs1))
88502 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88503 +
88504 + if (is_a_constant_overflow(def_stmt, rhs2))
88505 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88506 + if (is_a_constant_overflow(def_stmt, rhs1))
88507 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88508 +
88509 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88510 +}
88511 +
88512 +#if BUILDING_GCC_VERSION >= 4007
88513 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88514 +{
88515 + if (is_gimple_constant(rhs))
88516 + return cast_a_tree(size_overflow_type, rhs);
88517 + if (TREE_CODE(rhs) != SSA_NAME)
88518 + return NULL_TREE;
88519 + return expand(visited, rhs);
88520 +}
88521 +
88522 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88523 +{
88524 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88525 + gimple def_stmt = get_def_stmt(lhs);
88526 +
88527 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88528 +
88529 + rhs1 = gimple_assign_rhs1(def_stmt);
88530 + rhs2 = gimple_assign_rhs2(def_stmt);
88531 + rhs3 = gimple_assign_rhs3(def_stmt);
88532 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88533 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88534 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88535 +
88536 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88537 +}
88538 +#endif
88539 +
88540 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88541 +{
88542 + const_tree type;
88543 +
88544 + gcc_assert(node != NULL_TREE);
88545 +
88546 + type = TREE_TYPE(node);
88547 +
88548 + if (gimple_plf(stmt, MY_STMT))
88549 + return TREE_TYPE(node);
88550 +
88551 + switch (TYPE_MODE(type)) {
88552 + case QImode:
88553 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88554 + case HImode:
88555 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88556 + case SImode:
88557 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88558 + case DImode:
88559 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88560 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88561 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88562 + default:
88563 + debug_tree((tree)node);
88564 + error("%s: unsupported gcc configuration.", __func__);
88565 + gcc_unreachable();
88566 + }
88567 +}
88568 +
88569 +static tree expand_visited(gimple def_stmt)
88570 +{
88571 + const_gimple next_stmt;
88572 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88573 +
88574 + gsi_next(&gsi);
88575 + next_stmt = gsi_stmt(gsi);
88576 +
88577 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88578 +
88579 + switch (gimple_code(next_stmt)) {
88580 + case GIMPLE_ASSIGN:
88581 + return gimple_get_lhs(next_stmt);
88582 + case GIMPLE_PHI:
88583 + return gimple_phi_result(next_stmt);
88584 + case GIMPLE_CALL:
88585 + return gimple_call_lhs(next_stmt);
88586 + default:
88587 + return NULL_TREE;
88588 + }
88589 +}
88590 +
88591 +static tree expand(struct pointer_set_t *visited, tree lhs)
88592 +{
88593 + gimple def_stmt;
88594 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
88595 +
88596 + if (is_gimple_constant(lhs))
88597 + return NULL_TREE;
88598 +
88599 + if (TREE_CODE(lhs) == ADDR_EXPR)
88600 + return NULL_TREE;
88601 +
88602 + if (code == REAL_TYPE)
88603 + return NULL_TREE;
88604 +
88605 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
88606 +
88607 +
88608 + def_stmt = get_def_stmt(lhs);
88609 +
88610 + if (!def_stmt)
88611 + return NULL_TREE;
88612 +
88613 + if (gimple_plf(def_stmt, MY_STMT))
88614 + return lhs;
88615 +
88616 + if (pointer_set_contains(visited, def_stmt))
88617 + return expand_visited(def_stmt);
88618 +
88619 + switch (gimple_code(def_stmt)) {
88620 + case GIMPLE_NOP:
88621 + return NULL_TREE;
88622 + case GIMPLE_PHI:
88623 + return build_new_phi(visited, lhs);
88624 + case GIMPLE_CALL:
88625 + case GIMPLE_ASM:
88626 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88627 + case GIMPLE_ASSIGN:
88628 + switch (gimple_num_ops(def_stmt)) {
88629 + case 2:
88630 + return handle_unary_ops(visited, lhs);
88631 + case 3:
88632 + return handle_binary_ops(visited, lhs);
88633 +#if BUILDING_GCC_VERSION >= 4007
88634 + case 4:
88635 + return handle_ternary_ops(visited, lhs);
88636 +#endif
88637 + }
88638 + default:
88639 + debug_gimple_stmt(def_stmt);
88640 + error("%s: unknown gimple code", __func__);
88641 + gcc_unreachable();
88642 + }
88643 +}
88644 +
88645 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
88646 +{
88647 + const_gimple assign;
88648 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88649 + tree origtype = TREE_TYPE(origarg);
88650 +
88651 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
88652 +
88653 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88654 +
88655 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
88656 + update_stmt(stmt);
88657 +}
88658 +
88659 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
88660 +{
88661 + const char *origid;
88662 + tree arg;
88663 + const_tree origarg;
88664 +
88665 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
88666 + return true;
88667 +
88668 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
88669 + while (origarg && *argnum) {
88670 + (*argnum)--;
88671 + origarg = TREE_CHAIN(origarg);
88672 + }
88673 +
88674 + gcc_assert(*argnum == 0);
88675 +
88676 + gcc_assert(origarg != NULL_TREE);
88677 + origid = NAME(origarg);
88678 + *argnum = 0;
88679 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
88680 + if (!strcmp(origid, NAME(arg)))
88681 + return true;
88682 + (*argnum)++;
88683 + }
88684 + return false;
88685 +}
88686 +
88687 +static bool skip_types(const_tree var)
88688 +{
88689 + switch (TREE_CODE(var)) {
88690 + case ADDR_EXPR:
88691 +#if BUILDING_GCC_VERSION >= 4006
88692 + case MEM_REF:
88693 +#endif
88694 + case ARRAY_REF:
88695 + case BIT_FIELD_REF:
88696 + case INDIRECT_REF:
88697 + case TARGET_MEM_REF:
88698 + case VAR_DECL:
88699 + return true;
88700 + default:
88701 + break;
88702 + }
88703 + return false;
88704 +}
88705 +
88706 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
88707 +{
88708 + gimple phi = get_def_stmt(result);
88709 + unsigned int i, n = gimple_phi_num_args(phi);
88710 +
88711 + if (!phi)
88712 + return false;
88713 +
88714 + pointer_set_insert(visited, phi);
88715 + for (i = 0; i < n; i++) {
88716 + const_tree arg = gimple_phi_arg_def(phi, i);
88717 + if (pre_expand(visited, arg))
88718 + return true;
88719 + }
88720 + return false;
88721 +}
88722 +
88723 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
88724 +{
88725 + gimple def_stmt = get_def_stmt(lhs);
88726 + const_tree rhs;
88727 +
88728 + if (!def_stmt)
88729 + return false;
88730 +
88731 + rhs = gimple_assign_rhs1(def_stmt);
88732 + if (pre_expand(visited, rhs))
88733 + return true;
88734 + return false;
88735 +}
88736 +
88737 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
88738 +{
88739 + bool rhs1_found, rhs2_found;
88740 + gimple def_stmt = get_def_stmt(lhs);
88741 + const_tree rhs1, rhs2;
88742 +
88743 + if (!def_stmt)
88744 + return false;
88745 +
88746 + rhs1 = gimple_assign_rhs1(def_stmt);
88747 + rhs2 = gimple_assign_rhs2(def_stmt);
88748 + rhs1_found = pre_expand(visited, rhs1);
88749 + rhs2_found = pre_expand(visited, rhs2);
88750 +
88751 + return rhs1_found || rhs2_found;
88752 +}
88753 +
88754 +static const_tree search_field_decl(const_tree comp_ref)
88755 +{
88756 + const_tree field = NULL_TREE;
88757 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
88758 +
88759 + for (i = 0; i < len; i++) {
88760 + field = TREE_OPERAND(comp_ref, i);
88761 + if (TREE_CODE(field) == FIELD_DECL)
88762 + break;
88763 + }
88764 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
88765 + return field;
88766 +}
88767 +
88768 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
88769 +{
88770 + const_tree attr, p;
88771 +
88772 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
88773 + if (!attr || !TREE_VALUE(attr))
88774 + return MARKED_NO;
88775 +
88776 + p = TREE_VALUE(attr);
88777 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
88778 + return MARKED_NOT_INTENTIONAL;
88779 +
88780 + do {
88781 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
88782 + return MARKED_YES;
88783 + p = TREE_CHAIN(p);
88784 + } while (p);
88785 +
88786 + return MARKED_NO;
88787 +}
88788 +
88789 +static void print_missing_msg(tree func, unsigned int argnum)
88790 +{
88791 + unsigned int new_hash;
88792 + size_t len;
88793 + unsigned char tree_codes[CODES_LIMIT];
88794 + location_t loc = DECL_SOURCE_LOCATION(func);
88795 + const char *curfunc = get_asm_name(func);
88796 +
88797 + len = get_function_decl(func, tree_codes);
88798 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
88799 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
88800 +}
88801 +
88802 +static unsigned int search_missing_attribute(const_tree arg)
88803 +{
88804 + const_tree type = TREE_TYPE(arg);
88805 + tree func = get_original_function_decl(current_function_decl);
88806 + unsigned int argnum;
88807 + const struct size_overflow_hash *hash;
88808 +
88809 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
88810 +
88811 + if (TREE_CODE(type) == POINTER_TYPE)
88812 + return 0;
88813 +
88814 + argnum = find_arg_number(arg, func);
88815 + if (argnum == 0)
88816 + return 0;
88817 +
88818 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
88819 + return argnum;
88820 +
88821 + hash = get_function_hash(func);
88822 + if (!hash || !(hash->param & (1U << argnum))) {
88823 + print_missing_msg(func, argnum);
88824 + return 0;
88825 + }
88826 + return argnum;
88827 +}
88828 +
88829 +static bool is_already_marked(const_tree lhs)
88830 +{
88831 + unsigned int argnum;
88832 + const_tree fndecl;
88833 +
88834 + argnum = search_missing_attribute(lhs);
88835 + fndecl = get_original_function_decl(current_function_decl);
88836 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
88837 + return true;
88838 + return false;
88839 +}
88840 +
88841 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
88842 +{
88843 + const_gimple def_stmt;
88844 +
88845 + if (is_gimple_constant(lhs))
88846 + return false;
88847 +
88848 + if (skip_types(lhs))
88849 + return false;
88850 +
88851 + if (TREE_CODE(lhs) == PARM_DECL)
88852 + return is_already_marked(lhs);
88853 +
88854 + if (TREE_CODE(lhs) == COMPONENT_REF) {
88855 + const_tree field, attr;
88856 +
88857 + field = search_field_decl(lhs);
88858 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
88859 + if (!attr || !TREE_VALUE(attr))
88860 + return false;
88861 + return true;
88862 + }
88863 +
88864 + def_stmt = get_def_stmt(lhs);
88865 +
88866 + if (!def_stmt)
88867 + return false;
88868 +
88869 + if (pointer_set_contains(visited, def_stmt))
88870 + return false;
88871 +
88872 + switch (gimple_code(def_stmt)) {
88873 + case GIMPLE_NOP:
88874 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
88875 + return is_already_marked(lhs);
88876 + return false;
88877 + case GIMPLE_PHI:
88878 + return walk_phi(visited, lhs);
88879 + case GIMPLE_CALL:
88880 + case GIMPLE_ASM:
88881 + return false;
88882 + case GIMPLE_ASSIGN:
88883 + switch (gimple_num_ops(def_stmt)) {
88884 + case 2:
88885 + return walk_unary_ops(visited, lhs);
88886 + case 3:
88887 + return walk_binary_ops(visited, lhs);
88888 + }
88889 + default:
88890 + debug_gimple_stmt((gimple)def_stmt);
88891 + error("%s: unknown gimple code", __func__);
88892 + gcc_unreachable();
88893 + }
88894 +}
88895 +
88896 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
88897 +{
88898 + struct pointer_set_t *visited;
88899 + bool is_found;
88900 + enum marked is_marked;
88901 + location_t loc;
88902 +
88903 + visited = pointer_set_create();
88904 + is_found = pre_expand(visited, arg);
88905 + pointer_set_destroy(visited);
88906 +
88907 + is_marked = mark_status(fndecl, argnum + 1);
88908 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
88909 + return true;
88910 +
88911 + if (is_found) {
88912 + loc = DECL_SOURCE_LOCATION(fndecl);
88913 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
88914 + return true;
88915 + }
88916 + return false;
88917 +}
88918 +
88919 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
88920 +{
88921 + struct pointer_set_t *visited;
88922 + tree arg, newarg;
88923 + bool match;
88924 +
88925 + match = get_function_arg(&argnum, fndecl);
88926 + if (!match)
88927 + return;
88928 + gcc_assert(gimple_call_num_args(stmt) > argnum);
88929 + arg = gimple_call_arg(stmt, argnum);
88930 + if (arg == NULL_TREE)
88931 + return;
88932 +
88933 + if (is_gimple_constant(arg))
88934 + return;
88935 +
88936 + if (search_attributes(fndecl, arg, argnum))
88937 + return;
88938 +
88939 + if (TREE_CODE(arg) != SSA_NAME)
88940 + return;
88941 +
88942 + check_arg_type(arg);
88943 +
88944 + visited = pointer_set_create();
88945 + newarg = expand(visited, arg);
88946 + pointer_set_destroy(visited);
88947 +
88948 + if (newarg == NULL_TREE)
88949 + return;
88950 +
88951 + change_function_arg(stmt, arg, argnum, newarg);
88952 +
88953 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
88954 +}
88955 +
88956 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
88957 +{
88958 + tree p = TREE_VALUE(attr);
88959 + do {
88960 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
88961 + p = TREE_CHAIN(p);
88962 + } while (p);
88963 +}
88964 +
88965 +static void handle_function_by_hash(gimple stmt, tree fndecl)
88966 +{
88967 + tree orig_fndecl;
88968 + unsigned int num;
88969 + const struct size_overflow_hash *hash;
88970 +
88971 + orig_fndecl = get_original_function_decl(fndecl);
88972 + if (C_DECL_IMPLICIT(orig_fndecl))
88973 + return;
88974 + hash = get_function_hash(orig_fndecl);
88975 + if (!hash)
88976 + return;
88977 +
88978 + for (num = 1; num <= MAX_PARAM; num++)
88979 + if (hash->param & (1U << num))
88980 + handle_function_arg(stmt, fndecl, num - 1);
88981 +}
88982 +
88983 +static void set_plf_false(void)
88984 +{
88985 + basic_block bb;
88986 +
88987 + FOR_ALL_BB(bb) {
88988 + gimple_stmt_iterator si;
88989 +
88990 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
88991 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
88992 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
88993 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
88994 + }
88995 +}
88996 +
88997 +static unsigned int handle_function(void)
88998 +{
88999 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89000 +
89001 + set_plf_false();
89002 +
89003 + do {
89004 + gimple_stmt_iterator gsi;
89005 + next = bb->next_bb;
89006 +
89007 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89008 + tree fndecl, attr;
89009 + gimple stmt = gsi_stmt(gsi);
89010 +
89011 + if (!(is_gimple_call(stmt)))
89012 + continue;
89013 + fndecl = gimple_call_fndecl(stmt);
89014 + if (fndecl == NULL_TREE)
89015 + continue;
89016 + if (gimple_call_num_args(stmt) == 0)
89017 + continue;
89018 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89019 + if (!attr || !TREE_VALUE(attr))
89020 + handle_function_by_hash(stmt, fndecl);
89021 + else
89022 + handle_function_by_attribute(stmt, attr, fndecl);
89023 + gsi = gsi_for_stmt(stmt);
89024 + next = gimple_bb(stmt)->next_bb;
89025 + }
89026 + bb = next;
89027 + } while (bb);
89028 + return 0;
89029 +}
89030 +
89031 +static struct gimple_opt_pass size_overflow_pass = {
89032 + .pass = {
89033 + .type = GIMPLE_PASS,
89034 + .name = "size_overflow",
89035 + .gate = NULL,
89036 + .execute = handle_function,
89037 + .sub = NULL,
89038 + .next = NULL,
89039 + .static_pass_number = 0,
89040 + .tv_id = TV_NONE,
89041 + .properties_required = PROP_cfg | PROP_referenced_vars,
89042 + .properties_provided = 0,
89043 + .properties_destroyed = 0,
89044 + .todo_flags_start = 0,
89045 + .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
89046 + }
89047 +};
89048 +
89049 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89050 +{
89051 + tree fntype;
89052 +
89053 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89054 +
89055 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89056 + fntype = build_function_type_list(void_type_node,
89057 + const_char_ptr_type_node,
89058 + unsigned_type_node,
89059 + const_char_ptr_type_node,
89060 + const_char_ptr_type_node,
89061 + NULL_TREE);
89062 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89063 +
89064 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89065 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89066 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89067 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89068 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89069 +}
89070 +
89071 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89072 +{
89073 + int i;
89074 + const char * const plugin_name = plugin_info->base_name;
89075 + const int argc = plugin_info->argc;
89076 + const struct plugin_argument * const argv = plugin_info->argv;
89077 + bool enable = true;
89078 +
89079 + struct register_pass_info size_overflow_pass_info = {
89080 + .pass = &size_overflow_pass.pass,
89081 + .reference_pass_name = "ssa",
89082 + .ref_pass_instance_number = 1,
89083 + .pos_op = PASS_POS_INSERT_AFTER
89084 + };
89085 +
89086 + if (!plugin_default_version_check(version, &gcc_version)) {
89087 + error(G_("incompatible gcc/plugin versions"));
89088 + return 1;
89089 + }
89090 +
89091 + for (i = 0; i < argc; ++i) {
89092 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89093 + enable = false;
89094 + continue;
89095 + }
89096 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89097 + }
89098 +
89099 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89100 + if (enable) {
89101 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89102 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89103 + }
89104 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89105 +
89106 + return 0;
89107 +}
89108 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89109 new file mode 100644
89110 index 0000000..38d2014
89111 --- /dev/null
89112 +++ b/tools/gcc/stackleak_plugin.c
89113 @@ -0,0 +1,313 @@
89114 +/*
89115 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89116 + * Licensed under the GPL v2
89117 + *
89118 + * Note: the choice of the license means that the compilation process is
89119 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89120 + * but for the kernel it doesn't matter since it doesn't link against
89121 + * any of the gcc libraries
89122 + *
89123 + * gcc plugin to help implement various PaX features
89124 + *
89125 + * - track lowest stack pointer
89126 + *
89127 + * TODO:
89128 + * - initialize all local variables
89129 + *
89130 + * BUGS:
89131 + * - none known
89132 + */
89133 +#include "gcc-plugin.h"
89134 +#include "config.h"
89135 +#include "system.h"
89136 +#include "coretypes.h"
89137 +#include "tree.h"
89138 +#include "tree-pass.h"
89139 +#include "flags.h"
89140 +#include "intl.h"
89141 +#include "toplev.h"
89142 +#include "plugin.h"
89143 +//#include "expr.h" where are you...
89144 +#include "diagnostic.h"
89145 +#include "plugin-version.h"
89146 +#include "tm.h"
89147 +#include "function.h"
89148 +#include "basic-block.h"
89149 +#include "gimple.h"
89150 +#include "rtl.h"
89151 +#include "emit-rtl.h"
89152 +
89153 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89154 +
89155 +int plugin_is_GPL_compatible;
89156 +
89157 +static int track_frame_size = -1;
89158 +static const char track_function[] = "pax_track_stack";
89159 +static const char check_function[] = "pax_check_alloca";
89160 +static bool init_locals;
89161 +
89162 +static struct plugin_info stackleak_plugin_info = {
89163 + .version = "201203140940",
89164 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89165 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89166 +};
89167 +
89168 +static bool gate_stackleak_track_stack(void);
89169 +static unsigned int execute_stackleak_tree_instrument(void);
89170 +static unsigned int execute_stackleak_final(void);
89171 +
89172 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89173 + .pass = {
89174 + .type = GIMPLE_PASS,
89175 + .name = "stackleak_tree_instrument",
89176 + .gate = gate_stackleak_track_stack,
89177 + .execute = execute_stackleak_tree_instrument,
89178 + .sub = NULL,
89179 + .next = NULL,
89180 + .static_pass_number = 0,
89181 + .tv_id = TV_NONE,
89182 + .properties_required = PROP_gimple_leh | PROP_cfg,
89183 + .properties_provided = 0,
89184 + .properties_destroyed = 0,
89185 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89186 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89187 + }
89188 +};
89189 +
89190 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89191 + .pass = {
89192 + .type = RTL_PASS,
89193 + .name = "stackleak_final",
89194 + .gate = gate_stackleak_track_stack,
89195 + .execute = execute_stackleak_final,
89196 + .sub = NULL,
89197 + .next = NULL,
89198 + .static_pass_number = 0,
89199 + .tv_id = TV_NONE,
89200 + .properties_required = 0,
89201 + .properties_provided = 0,
89202 + .properties_destroyed = 0,
89203 + .todo_flags_start = 0,
89204 + .todo_flags_finish = TODO_dump_func
89205 + }
89206 +};
89207 +
89208 +static bool gate_stackleak_track_stack(void)
89209 +{
89210 + return track_frame_size >= 0;
89211 +}
89212 +
89213 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89214 +{
89215 + gimple check_alloca;
89216 + tree fntype, fndecl, alloca_size;
89217 +
89218 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89219 + fndecl = build_fn_decl(check_function, fntype);
89220 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89221 +
89222 + // insert call to void pax_check_alloca(unsigned long size)
89223 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89224 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89225 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89226 +}
89227 +
89228 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89229 +{
89230 + gimple track_stack;
89231 + tree fntype, fndecl;
89232 +
89233 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89234 + fndecl = build_fn_decl(track_function, fntype);
89235 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89236 +
89237 + // insert call to void pax_track_stack(void)
89238 + track_stack = gimple_build_call(fndecl, 0);
89239 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89240 +}
89241 +
89242 +#if BUILDING_GCC_VERSION == 4005
89243 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89244 +{
89245 + tree fndecl;
89246 +
89247 + if (!is_gimple_call(stmt))
89248 + return false;
89249 + fndecl = gimple_call_fndecl(stmt);
89250 + if (!fndecl)
89251 + return false;
89252 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89253 + return false;
89254 +// print_node(stderr, "pax", fndecl, 4);
89255 + return DECL_FUNCTION_CODE(fndecl) == code;
89256 +}
89257 +#endif
89258 +
89259 +static bool is_alloca(gimple stmt)
89260 +{
89261 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89262 + return true;
89263 +
89264 +#if BUILDING_GCC_VERSION >= 4007
89265 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89266 + return true;
89267 +#endif
89268 +
89269 + return false;
89270 +}
89271 +
89272 +static unsigned int execute_stackleak_tree_instrument(void)
89273 +{
89274 + basic_block bb, entry_bb;
89275 + bool prologue_instrumented = false, is_leaf = true;
89276 +
89277 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89278 +
89279 + // 1. loop through BBs and GIMPLE statements
89280 + FOR_EACH_BB(bb) {
89281 + gimple_stmt_iterator gsi;
89282 +
89283 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89284 + gimple stmt;
89285 +
89286 + stmt = gsi_stmt(gsi);
89287 +
89288 + if (is_gimple_call(stmt))
89289 + is_leaf = false;
89290 +
89291 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89292 + if (!is_alloca(stmt))
89293 + continue;
89294 +
89295 + // 2. insert stack overflow check before each __builtin_alloca call
89296 + stackleak_check_alloca(&gsi);
89297 +
89298 + // 3. insert track call after each __builtin_alloca call
89299 + stackleak_add_instrumentation(&gsi);
89300 + if (bb == entry_bb)
89301 + prologue_instrumented = true;
89302 + }
89303 + }
89304 +
89305 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89306 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89307 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89308 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89309 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89310 + return 0;
89311 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89312 + return 0;
89313 +
89314 + // 4. insert track call at the beginning
89315 + if (!prologue_instrumented) {
89316 + gimple_stmt_iterator gsi;
89317 +
89318 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89319 + if (dom_info_available_p(CDI_DOMINATORS))
89320 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89321 + gsi = gsi_start_bb(bb);
89322 + stackleak_add_instrumentation(&gsi);
89323 + }
89324 +
89325 + return 0;
89326 +}
89327 +
89328 +static unsigned int execute_stackleak_final(void)
89329 +{
89330 + rtx insn;
89331 +
89332 + if (cfun->calls_alloca)
89333 + return 0;
89334 +
89335 + // keep calls only if function frame is big enough
89336 + if (get_frame_size() >= track_frame_size)
89337 + return 0;
89338 +
89339 + // 1. find pax_track_stack calls
89340 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89341 + // 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))
89342 + rtx body;
89343 +
89344 + if (!CALL_P(insn))
89345 + continue;
89346 + body = PATTERN(insn);
89347 + if (GET_CODE(body) != CALL)
89348 + continue;
89349 + body = XEXP(body, 0);
89350 + if (GET_CODE(body) != MEM)
89351 + continue;
89352 + body = XEXP(body, 0);
89353 + if (GET_CODE(body) != SYMBOL_REF)
89354 + continue;
89355 + if (strcmp(XSTR(body, 0), track_function))
89356 + continue;
89357 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89358 + // 2. delete call
89359 + insn = delete_insn_and_edges(insn);
89360 +#if BUILDING_GCC_VERSION >= 4007
89361 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89362 + insn = delete_insn_and_edges(insn);
89363 +#endif
89364 + }
89365 +
89366 +// print_simple_rtl(stderr, get_insns());
89367 +// print_rtl(stderr, get_insns());
89368 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89369 +
89370 + return 0;
89371 +}
89372 +
89373 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89374 +{
89375 + const char * const plugin_name = plugin_info->base_name;
89376 + const int argc = plugin_info->argc;
89377 + const struct plugin_argument * const argv = plugin_info->argv;
89378 + int i;
89379 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89380 + .pass = &stackleak_tree_instrument_pass.pass,
89381 +// .reference_pass_name = "tree_profile",
89382 + .reference_pass_name = "optimized",
89383 + .ref_pass_instance_number = 1,
89384 + .pos_op = PASS_POS_INSERT_BEFORE
89385 + };
89386 + struct register_pass_info stackleak_final_pass_info = {
89387 + .pass = &stackleak_final_rtl_opt_pass.pass,
89388 + .reference_pass_name = "final",
89389 + .ref_pass_instance_number = 1,
89390 + .pos_op = PASS_POS_INSERT_BEFORE
89391 + };
89392 +
89393 + if (!plugin_default_version_check(version, &gcc_version)) {
89394 + error(G_("incompatible gcc/plugin versions"));
89395 + return 1;
89396 + }
89397 +
89398 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89399 +
89400 + for (i = 0; i < argc; ++i) {
89401 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89402 + if (!argv[i].value) {
89403 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89404 + continue;
89405 + }
89406 + track_frame_size = atoi(argv[i].value);
89407 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89408 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89409 + continue;
89410 + }
89411 + if (!strcmp(argv[i].key, "initialize-locals")) {
89412 + if (argv[i].value) {
89413 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89414 + continue;
89415 + }
89416 + init_locals = true;
89417 + continue;
89418 + }
89419 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89420 + }
89421 +
89422 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89423 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89424 +
89425 + return 0;
89426 +}
89427 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89428 index 6789d78..4afd019e 100644
89429 --- a/tools/perf/util/include/asm/alternative-asm.h
89430 +++ b/tools/perf/util/include/asm/alternative-asm.h
89431 @@ -5,4 +5,7 @@
89432
89433 #define altinstruction_entry #
89434
89435 + .macro pax_force_retaddr rip=0, reload=0
89436 + .endm
89437 +
89438 #endif
89439 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89440 index d617f69..6b445d2 100644
89441 --- a/virt/kvm/kvm_main.c
89442 +++ b/virt/kvm/kvm_main.c
89443 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89444
89445 static cpumask_var_t cpus_hardware_enabled;
89446 static int kvm_usage_count = 0;
89447 -static atomic_t hardware_enable_failed;
89448 +static atomic_unchecked_t hardware_enable_failed;
89449
89450 struct kmem_cache *kvm_vcpu_cache;
89451 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89452 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89453 /* We can read the guest memory with __xxx_user() later on. */
89454 if (user_alloc &&
89455 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89456 - !access_ok(VERIFY_WRITE,
89457 + !__access_ok(VERIFY_WRITE,
89458 (void __user *)(unsigned long)mem->userspace_addr,
89459 mem->memory_size)))
89460 goto out;
89461 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89462
89463 if (r) {
89464 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89465 - atomic_inc(&hardware_enable_failed);
89466 + atomic_inc_unchecked(&hardware_enable_failed);
89467 printk(KERN_INFO "kvm: enabling virtualization on "
89468 "CPU%d failed\n", cpu);
89469 }
89470 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89471
89472 kvm_usage_count++;
89473 if (kvm_usage_count == 1) {
89474 - atomic_set(&hardware_enable_failed, 0);
89475 + atomic_set_unchecked(&hardware_enable_failed, 0);
89476 on_each_cpu(hardware_enable_nolock, NULL, 1);
89477
89478 - if (atomic_read(&hardware_enable_failed)) {
89479 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89480 hardware_disable_all_nolock();
89481 r = -EBUSY;
89482 }
89483 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89484 kvm_arch_vcpu_put(vcpu);
89485 }
89486
89487 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89488 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89489 struct module *module)
89490 {
89491 int r;
89492 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89493 if (!vcpu_align)
89494 vcpu_align = __alignof__(struct kvm_vcpu);
89495 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89496 - 0, NULL);
89497 + SLAB_USERCOPY, NULL);
89498 if (!kvm_vcpu_cache) {
89499 r = -ENOMEM;
89500 goto out_free_3;
89501 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89502 if (r)
89503 goto out_free;
89504
89505 - kvm_chardev_ops.owner = module;
89506 - kvm_vm_fops.owner = module;
89507 - kvm_vcpu_fops.owner = module;
89508 + pax_open_kernel();
89509 + *(void **)&kvm_chardev_ops.owner = module;
89510 + *(void **)&kvm_vm_fops.owner = module;
89511 + *(void **)&kvm_vcpu_fops.owner = module;
89512 + pax_close_kernel();
89513
89514 r = misc_register(&kvm_dev);
89515 if (r) {