]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.6.2-201210151829.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.6.2-201210151829.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 af5d6a9..4ccd9fb 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 1d7e274..b39c527 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 @@ -226,7 +226,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), %l6
5995 + andcc %l0, _TIF_WORK_SYSCALL, %l6
5996 80:
5997 /* System call success, clear Carry condition code. */
5998 andn %g3, %g2, %g3
5999 @@ -241,7 +241,7 @@ ret_sys_call:
6000 /* System call failure, set Carry condition code.
6001 * Also, get abs(errno) to return to the process.
6002 */
6003 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6004 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6005 sub %g0, %o0, %o0
6006 or %g3, %g2, %g3
6007 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6008 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6009 index a5785ea..405c5f7 100644
6010 --- a/arch/sparc/kernel/traps_32.c
6011 +++ b/arch/sparc/kernel/traps_32.c
6012 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6013 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6014 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6015
6016 +extern void gr_handle_kernel_exploit(void);
6017 +
6018 void die_if_kernel(char *str, struct pt_regs *regs)
6019 {
6020 static int die_counter;
6021 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6022 count++ < 30 &&
6023 (((unsigned long) rw) >= PAGE_OFFSET) &&
6024 !(((unsigned long) rw) & 0x7)) {
6025 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6026 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6027 (void *) rw->ins[7]);
6028 rw = (struct reg_window32 *)rw->ins[6];
6029 }
6030 }
6031 printk("Instruction DUMP:");
6032 instruction_dump ((unsigned long *) regs->pc);
6033 - if(regs->psr & PSR_PS)
6034 + if(regs->psr & PSR_PS) {
6035 + gr_handle_kernel_exploit();
6036 do_exit(SIGKILL);
6037 + }
6038 do_exit(SIGSEGV);
6039 }
6040
6041 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6042 index 3b05e66..6ea2917 100644
6043 --- a/arch/sparc/kernel/traps_64.c
6044 +++ b/arch/sparc/kernel/traps_64.c
6045 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6046 i + 1,
6047 p->trapstack[i].tstate, p->trapstack[i].tpc,
6048 p->trapstack[i].tnpc, p->trapstack[i].tt);
6049 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6050 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6051 }
6052 }
6053
6054 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6055
6056 lvl -= 0x100;
6057 if (regs->tstate & TSTATE_PRIV) {
6058 +
6059 +#ifdef CONFIG_PAX_REFCOUNT
6060 + if (lvl == 6)
6061 + pax_report_refcount_overflow(regs);
6062 +#endif
6063 +
6064 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6065 die_if_kernel(buffer, regs);
6066 }
6067 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6068 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6069 {
6070 char buffer[32];
6071 -
6072 +
6073 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6074 0, lvl, SIGTRAP) == NOTIFY_STOP)
6075 return;
6076
6077 +#ifdef CONFIG_PAX_REFCOUNT
6078 + if (lvl == 6)
6079 + pax_report_refcount_overflow(regs);
6080 +#endif
6081 +
6082 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6083
6084 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6085 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6086 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6087 printk("%s" "ERROR(%d): ",
6088 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6089 - printk("TPC<%pS>\n", (void *) regs->tpc);
6090 + printk("TPC<%pA>\n", (void *) regs->tpc);
6091 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6092 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6093 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6094 @@ -1748,7 +1759,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_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6099 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6100 panic("Irrecoverable Cheetah+ parity error.");
6101 }
6102
6103 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6104 smp_processor_id(),
6105 (type & 0x1) ? 'I' : 'D',
6106 regs->tpc);
6107 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6108 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6109 }
6110
6111 struct sun4v_error_entry {
6112 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6113
6114 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6115 regs->tpc, tl);
6116 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6117 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6118 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6119 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6120 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6121 (void *) regs->u_regs[UREG_I7]);
6122 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6123 "pte[%lx] error[%lx]\n",
6124 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6125
6126 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6127 regs->tpc, tl);
6128 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6129 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6130 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6131 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6132 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6133 (void *) regs->u_regs[UREG_I7]);
6134 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6135 "pte[%lx] error[%lx]\n",
6136 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6137 fp = (unsigned long)sf->fp + STACK_BIAS;
6138 }
6139
6140 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6141 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6142 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6143 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6144 int index = tsk->curr_ret_stack;
6145 if (tsk->ret_stack && index >= graph) {
6146 pc = tsk->ret_stack[index - graph].ret;
6147 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6148 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6149 graph++;
6150 }
6151 }
6152 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6153 return (struct reg_window *) (fp + STACK_BIAS);
6154 }
6155
6156 +extern void gr_handle_kernel_exploit(void);
6157 +
6158 void die_if_kernel(char *str, struct pt_regs *regs)
6159 {
6160 static int die_counter;
6161 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6162 while (rw &&
6163 count++ < 30 &&
6164 kstack_valid(tp, (unsigned long) rw)) {
6165 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6166 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6167 (void *) rw->ins[7]);
6168
6169 rw = kernel_stack_up(rw);
6170 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6171 }
6172 user_instruction_dump ((unsigned int __user *) regs->tpc);
6173 }
6174 - if (regs->tstate & TSTATE_PRIV)
6175 + if (regs->tstate & TSTATE_PRIV) {
6176 + gr_handle_kernel_exploit();
6177 do_exit(SIGKILL);
6178 + }
6179 do_exit(SIGSEGV);
6180 }
6181 EXPORT_SYMBOL(die_if_kernel);
6182 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6183 index f81d038..e7a4680 100644
6184 --- a/arch/sparc/kernel/unaligned_64.c
6185 +++ b/arch/sparc/kernel/unaligned_64.c
6186 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6187 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6188
6189 if (__ratelimit(&ratelimit)) {
6190 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6191 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6192 regs->tpc, (void *) regs->tpc);
6193 }
6194 }
6195 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6196 index dff4096..bd9a388 100644
6197 --- a/arch/sparc/lib/Makefile
6198 +++ b/arch/sparc/lib/Makefile
6199 @@ -2,7 +2,7 @@
6200 #
6201
6202 asflags-y := -ansi -DST_DIV0=0x02
6203 -ccflags-y := -Werror
6204 +#ccflags-y := -Werror
6205
6206 lib-$(CONFIG_SPARC32) += ashrdi3.o
6207 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6208 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6209 index 4d502da..527c48d 100644
6210 --- a/arch/sparc/lib/atomic_64.S
6211 +++ b/arch/sparc/lib/atomic_64.S
6212 @@ -17,7 +17,12 @@
6213 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6214 BACKOFF_SETUP(%o2)
6215 1: lduw [%o1], %g1
6216 - add %g1, %o0, %g7
6217 + addcc %g1, %o0, %g7
6218 +
6219 +#ifdef CONFIG_PAX_REFCOUNT
6220 + tvs %icc, 6
6221 +#endif
6222 +
6223 cas [%o1], %g1, %g7
6224 cmp %g1, %g7
6225 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6226 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6227 2: BACKOFF_SPIN(%o2, %o3, 1b)
6228 ENDPROC(atomic_add)
6229
6230 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6231 + BACKOFF_SETUP(%o2)
6232 +1: lduw [%o1], %g1
6233 + add %g1, %o0, %g7
6234 + cas [%o1], %g1, %g7
6235 + cmp %g1, %g7
6236 + bne,pn %icc, 2f
6237 + nop
6238 + retl
6239 + nop
6240 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6241 +ENDPROC(atomic_add_unchecked)
6242 +
6243 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6244 BACKOFF_SETUP(%o2)
6245 1: lduw [%o1], %g1
6246 - sub %g1, %o0, %g7
6247 + subcc %g1, %o0, %g7
6248 +
6249 +#ifdef CONFIG_PAX_REFCOUNT
6250 + tvs %icc, 6
6251 +#endif
6252 +
6253 cas [%o1], %g1, %g7
6254 cmp %g1, %g7
6255 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6256 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6257 2: BACKOFF_SPIN(%o2, %o3, 1b)
6258 ENDPROC(atomic_sub)
6259
6260 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6261 + BACKOFF_SETUP(%o2)
6262 +1: lduw [%o1], %g1
6263 + sub %g1, %o0, %g7
6264 + cas [%o1], %g1, %g7
6265 + cmp %g1, %g7
6266 + bne,pn %icc, 2f
6267 + nop
6268 + retl
6269 + nop
6270 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6271 +ENDPROC(atomic_sub_unchecked)
6272 +
6273 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6274 BACKOFF_SETUP(%o2)
6275 1: lduw [%o1], %g1
6276 - add %g1, %o0, %g7
6277 + addcc %g1, %o0, %g7
6278 +
6279 +#ifdef CONFIG_PAX_REFCOUNT
6280 + tvs %icc, 6
6281 +#endif
6282 +
6283 cas [%o1], %g1, %g7
6284 cmp %g1, %g7
6285 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6286 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6287 2: BACKOFF_SPIN(%o2, %o3, 1b)
6288 ENDPROC(atomic_add_ret)
6289
6290 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6291 + BACKOFF_SETUP(%o2)
6292 +1: lduw [%o1], %g1
6293 + addcc %g1, %o0, %g7
6294 + cas [%o1], %g1, %g7
6295 + cmp %g1, %g7
6296 + bne,pn %icc, 2f
6297 + add %g7, %o0, %g7
6298 + sra %g7, 0, %o0
6299 + retl
6300 + nop
6301 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6302 +ENDPROC(atomic_add_ret_unchecked)
6303 +
6304 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6305 BACKOFF_SETUP(%o2)
6306 1: lduw [%o1], %g1
6307 - sub %g1, %o0, %g7
6308 + subcc %g1, %o0, %g7
6309 +
6310 +#ifdef CONFIG_PAX_REFCOUNT
6311 + tvs %icc, 6
6312 +#endif
6313 +
6314 cas [%o1], %g1, %g7
6315 cmp %g1, %g7
6316 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6317 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6318 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6319 BACKOFF_SETUP(%o2)
6320 1: ldx [%o1], %g1
6321 - add %g1, %o0, %g7
6322 + addcc %g1, %o0, %g7
6323 +
6324 +#ifdef CONFIG_PAX_REFCOUNT
6325 + tvs %xcc, 6
6326 +#endif
6327 +
6328 casx [%o1], %g1, %g7
6329 cmp %g1, %g7
6330 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6331 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6332 2: BACKOFF_SPIN(%o2, %o3, 1b)
6333 ENDPROC(atomic64_add)
6334
6335 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6336 + BACKOFF_SETUP(%o2)
6337 +1: ldx [%o1], %g1
6338 + addcc %g1, %o0, %g7
6339 + casx [%o1], %g1, %g7
6340 + cmp %g1, %g7
6341 + bne,pn %xcc, 2f
6342 + nop
6343 + retl
6344 + nop
6345 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6346 +ENDPROC(atomic64_add_unchecked)
6347 +
6348 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6349 BACKOFF_SETUP(%o2)
6350 1: ldx [%o1], %g1
6351 - sub %g1, %o0, %g7
6352 + subcc %g1, %o0, %g7
6353 +
6354 +#ifdef CONFIG_PAX_REFCOUNT
6355 + tvs %xcc, 6
6356 +#endif
6357 +
6358 casx [%o1], %g1, %g7
6359 cmp %g1, %g7
6360 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6361 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6362 2: BACKOFF_SPIN(%o2, %o3, 1b)
6363 ENDPROC(atomic64_sub)
6364
6365 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6366 + BACKOFF_SETUP(%o2)
6367 +1: ldx [%o1], %g1
6368 + subcc %g1, %o0, %g7
6369 + casx [%o1], %g1, %g7
6370 + cmp %g1, %g7
6371 + bne,pn %xcc, 2f
6372 + nop
6373 + retl
6374 + nop
6375 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6376 +ENDPROC(atomic64_sub_unchecked)
6377 +
6378 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6379 BACKOFF_SETUP(%o2)
6380 1: ldx [%o1], %g1
6381 - add %g1, %o0, %g7
6382 + addcc %g1, %o0, %g7
6383 +
6384 +#ifdef CONFIG_PAX_REFCOUNT
6385 + tvs %xcc, 6
6386 +#endif
6387 +
6388 casx [%o1], %g1, %g7
6389 cmp %g1, %g7
6390 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6391 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6392 2: BACKOFF_SPIN(%o2, %o3, 1b)
6393 ENDPROC(atomic64_add_ret)
6394
6395 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6396 + BACKOFF_SETUP(%o2)
6397 +1: ldx [%o1], %g1
6398 + addcc %g1, %o0, %g7
6399 + casx [%o1], %g1, %g7
6400 + cmp %g1, %g7
6401 + bne,pn %xcc, 2f
6402 + add %g7, %o0, %g7
6403 + mov %g7, %o0
6404 + retl
6405 + nop
6406 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6407 +ENDPROC(atomic64_add_ret_unchecked)
6408 +
6409 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6410 BACKOFF_SETUP(%o2)
6411 1: ldx [%o1], %g1
6412 - sub %g1, %o0, %g7
6413 + subcc %g1, %o0, %g7
6414 +
6415 +#ifdef CONFIG_PAX_REFCOUNT
6416 + tvs %xcc, 6
6417 +#endif
6418 +
6419 casx [%o1], %g1, %g7
6420 cmp %g1, %g7
6421 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6422 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6423 index 3b31218..345c609 100644
6424 --- a/arch/sparc/lib/ksyms.c
6425 +++ b/arch/sparc/lib/ksyms.c
6426 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6427
6428 /* Atomic counter implementation. */
6429 EXPORT_SYMBOL(atomic_add);
6430 +EXPORT_SYMBOL(atomic_add_unchecked);
6431 EXPORT_SYMBOL(atomic_add_ret);
6432 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6433 EXPORT_SYMBOL(atomic_sub);
6434 +EXPORT_SYMBOL(atomic_sub_unchecked);
6435 EXPORT_SYMBOL(atomic_sub_ret);
6436 EXPORT_SYMBOL(atomic64_add);
6437 +EXPORT_SYMBOL(atomic64_add_unchecked);
6438 EXPORT_SYMBOL(atomic64_add_ret);
6439 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6440 EXPORT_SYMBOL(atomic64_sub);
6441 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6442 EXPORT_SYMBOL(atomic64_sub_ret);
6443
6444 /* Atomic bit operations. */
6445 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6446 index 30c3ecc..736f015 100644
6447 --- a/arch/sparc/mm/Makefile
6448 +++ b/arch/sparc/mm/Makefile
6449 @@ -2,7 +2,7 @@
6450 #
6451
6452 asflags-y := -ansi
6453 -ccflags-y := -Werror
6454 +#ccflags-y := -Werror
6455
6456 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6457 obj-y += fault_$(BITS).o
6458 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6459 index 77ac917..baf45db 100644
6460 --- a/arch/sparc/mm/fault_32.c
6461 +++ b/arch/sparc/mm/fault_32.c
6462 @@ -21,6 +21,9 @@
6463 #include <linux/perf_event.h>
6464 #include <linux/interrupt.h>
6465 #include <linux/kdebug.h>
6466 +#include <linux/slab.h>
6467 +#include <linux/pagemap.h>
6468 +#include <linux/compiler.h>
6469
6470 #include <asm/page.h>
6471 #include <asm/pgtable.h>
6472 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6473 return safe_compute_effective_address(regs, insn);
6474 }
6475
6476 +#ifdef CONFIG_PAX_PAGEEXEC
6477 +#ifdef CONFIG_PAX_DLRESOLVE
6478 +static void pax_emuplt_close(struct vm_area_struct *vma)
6479 +{
6480 + vma->vm_mm->call_dl_resolve = 0UL;
6481 +}
6482 +
6483 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6484 +{
6485 + unsigned int *kaddr;
6486 +
6487 + vmf->page = alloc_page(GFP_HIGHUSER);
6488 + if (!vmf->page)
6489 + return VM_FAULT_OOM;
6490 +
6491 + kaddr = kmap(vmf->page);
6492 + memset(kaddr, 0, PAGE_SIZE);
6493 + kaddr[0] = 0x9DE3BFA8U; /* save */
6494 + flush_dcache_page(vmf->page);
6495 + kunmap(vmf->page);
6496 + return VM_FAULT_MAJOR;
6497 +}
6498 +
6499 +static const struct vm_operations_struct pax_vm_ops = {
6500 + .close = pax_emuplt_close,
6501 + .fault = pax_emuplt_fault
6502 +};
6503 +
6504 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6505 +{
6506 + int ret;
6507 +
6508 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6509 + vma->vm_mm = current->mm;
6510 + vma->vm_start = addr;
6511 + vma->vm_end = addr + PAGE_SIZE;
6512 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6513 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6514 + vma->vm_ops = &pax_vm_ops;
6515 +
6516 + ret = insert_vm_struct(current->mm, vma);
6517 + if (ret)
6518 + return ret;
6519 +
6520 + ++current->mm->total_vm;
6521 + return 0;
6522 +}
6523 +#endif
6524 +
6525 +/*
6526 + * PaX: decide what to do with offenders (regs->pc = fault address)
6527 + *
6528 + * returns 1 when task should be killed
6529 + * 2 when patched PLT trampoline was detected
6530 + * 3 when unpatched PLT trampoline was detected
6531 + */
6532 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6533 +{
6534 +
6535 +#ifdef CONFIG_PAX_EMUPLT
6536 + int err;
6537 +
6538 + do { /* PaX: patched PLT emulation #1 */
6539 + unsigned int sethi1, sethi2, jmpl;
6540 +
6541 + err = get_user(sethi1, (unsigned int *)regs->pc);
6542 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6543 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6544 +
6545 + if (err)
6546 + break;
6547 +
6548 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6549 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6550 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6551 + {
6552 + unsigned int addr;
6553 +
6554 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6555 + addr = regs->u_regs[UREG_G1];
6556 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6557 + regs->pc = addr;
6558 + regs->npc = addr+4;
6559 + return 2;
6560 + }
6561 + } while (0);
6562 +
6563 + do { /* PaX: patched PLT emulation #2 */
6564 + unsigned int ba;
6565 +
6566 + err = get_user(ba, (unsigned int *)regs->pc);
6567 +
6568 + if (err)
6569 + break;
6570 +
6571 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6572 + unsigned int addr;
6573 +
6574 + if ((ba & 0xFFC00000U) == 0x30800000U)
6575 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6576 + else
6577 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6578 + regs->pc = addr;
6579 + regs->npc = addr+4;
6580 + return 2;
6581 + }
6582 + } while (0);
6583 +
6584 + do { /* PaX: patched PLT emulation #3 */
6585 + unsigned int sethi, bajmpl, nop;
6586 +
6587 + err = get_user(sethi, (unsigned int *)regs->pc);
6588 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6589 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6590 +
6591 + if (err)
6592 + break;
6593 +
6594 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6595 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6596 + nop == 0x01000000U)
6597 + {
6598 + unsigned int addr;
6599 +
6600 + addr = (sethi & 0x003FFFFFU) << 10;
6601 + regs->u_regs[UREG_G1] = addr;
6602 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6603 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6604 + else
6605 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6606 + regs->pc = addr;
6607 + regs->npc = addr+4;
6608 + return 2;
6609 + }
6610 + } while (0);
6611 +
6612 + do { /* PaX: unpatched PLT emulation step 1 */
6613 + unsigned int sethi, ba, nop;
6614 +
6615 + err = get_user(sethi, (unsigned int *)regs->pc);
6616 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6617 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6618 +
6619 + if (err)
6620 + break;
6621 +
6622 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6623 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6624 + nop == 0x01000000U)
6625 + {
6626 + unsigned int addr, save, call;
6627 +
6628 + if ((ba & 0xFFC00000U) == 0x30800000U)
6629 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6630 + else
6631 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6632 +
6633 + err = get_user(save, (unsigned int *)addr);
6634 + err |= get_user(call, (unsigned int *)(addr+4));
6635 + err |= get_user(nop, (unsigned int *)(addr+8));
6636 + if (err)
6637 + break;
6638 +
6639 +#ifdef CONFIG_PAX_DLRESOLVE
6640 + if (save == 0x9DE3BFA8U &&
6641 + (call & 0xC0000000U) == 0x40000000U &&
6642 + nop == 0x01000000U)
6643 + {
6644 + struct vm_area_struct *vma;
6645 + unsigned long call_dl_resolve;
6646 +
6647 + down_read(&current->mm->mmap_sem);
6648 + call_dl_resolve = current->mm->call_dl_resolve;
6649 + up_read(&current->mm->mmap_sem);
6650 + if (likely(call_dl_resolve))
6651 + goto emulate;
6652 +
6653 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6654 +
6655 + down_write(&current->mm->mmap_sem);
6656 + if (current->mm->call_dl_resolve) {
6657 + call_dl_resolve = current->mm->call_dl_resolve;
6658 + up_write(&current->mm->mmap_sem);
6659 + if (vma)
6660 + kmem_cache_free(vm_area_cachep, vma);
6661 + goto emulate;
6662 + }
6663 +
6664 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6665 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6666 + up_write(&current->mm->mmap_sem);
6667 + if (vma)
6668 + kmem_cache_free(vm_area_cachep, vma);
6669 + return 1;
6670 + }
6671 +
6672 + if (pax_insert_vma(vma, call_dl_resolve)) {
6673 + up_write(&current->mm->mmap_sem);
6674 + kmem_cache_free(vm_area_cachep, vma);
6675 + return 1;
6676 + }
6677 +
6678 + current->mm->call_dl_resolve = call_dl_resolve;
6679 + up_write(&current->mm->mmap_sem);
6680 +
6681 +emulate:
6682 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6683 + regs->pc = call_dl_resolve;
6684 + regs->npc = addr+4;
6685 + return 3;
6686 + }
6687 +#endif
6688 +
6689 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6690 + if ((save & 0xFFC00000U) == 0x05000000U &&
6691 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6692 + nop == 0x01000000U)
6693 + {
6694 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6695 + regs->u_regs[UREG_G2] = addr + 4;
6696 + addr = (save & 0x003FFFFFU) << 10;
6697 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6698 + regs->pc = addr;
6699 + regs->npc = addr+4;
6700 + return 3;
6701 + }
6702 + }
6703 + } while (0);
6704 +
6705 + do { /* PaX: unpatched PLT emulation step 2 */
6706 + unsigned int save, call, nop;
6707 +
6708 + err = get_user(save, (unsigned int *)(regs->pc-4));
6709 + err |= get_user(call, (unsigned int *)regs->pc);
6710 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6711 + if (err)
6712 + break;
6713 +
6714 + if (save == 0x9DE3BFA8U &&
6715 + (call & 0xC0000000U) == 0x40000000U &&
6716 + nop == 0x01000000U)
6717 + {
6718 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6719 +
6720 + regs->u_regs[UREG_RETPC] = regs->pc;
6721 + regs->pc = dl_resolve;
6722 + regs->npc = dl_resolve+4;
6723 + return 3;
6724 + }
6725 + } while (0);
6726 +#endif
6727 +
6728 + return 1;
6729 +}
6730 +
6731 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6732 +{
6733 + unsigned long i;
6734 +
6735 + printk(KERN_ERR "PAX: bytes at PC: ");
6736 + for (i = 0; i < 8; i++) {
6737 + unsigned int c;
6738 + if (get_user(c, (unsigned int *)pc+i))
6739 + printk(KERN_CONT "???????? ");
6740 + else
6741 + printk(KERN_CONT "%08x ", c);
6742 + }
6743 + printk("\n");
6744 +}
6745 +#endif
6746 +
6747 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6748 int text_fault)
6749 {
6750 @@ -230,6 +504,24 @@ good_area:
6751 if (!(vma->vm_flags & VM_WRITE))
6752 goto bad_area;
6753 } else {
6754 +
6755 +#ifdef CONFIG_PAX_PAGEEXEC
6756 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6757 + up_read(&mm->mmap_sem);
6758 + switch (pax_handle_fetch_fault(regs)) {
6759 +
6760 +#ifdef CONFIG_PAX_EMUPLT
6761 + case 2:
6762 + case 3:
6763 + return;
6764 +#endif
6765 +
6766 + }
6767 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6768 + do_group_exit(SIGKILL);
6769 + }
6770 +#endif
6771 +
6772 /* Allow reads even for write-only mappings */
6773 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6774 goto bad_area;
6775 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6776 index 1fe0429..8dd5dd5 100644
6777 --- a/arch/sparc/mm/fault_64.c
6778 +++ b/arch/sparc/mm/fault_64.c
6779 @@ -21,6 +21,9 @@
6780 #include <linux/kprobes.h>
6781 #include <linux/kdebug.h>
6782 #include <linux/percpu.h>
6783 +#include <linux/slab.h>
6784 +#include <linux/pagemap.h>
6785 +#include <linux/compiler.h>
6786
6787 #include <asm/page.h>
6788 #include <asm/pgtable.h>
6789 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6790 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6791 regs->tpc);
6792 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6793 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6794 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6795 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6796 dump_stack();
6797 unhandled_fault(regs->tpc, current, regs);
6798 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6799 show_regs(regs);
6800 }
6801
6802 +#ifdef CONFIG_PAX_PAGEEXEC
6803 +#ifdef CONFIG_PAX_DLRESOLVE
6804 +static void pax_emuplt_close(struct vm_area_struct *vma)
6805 +{
6806 + vma->vm_mm->call_dl_resolve = 0UL;
6807 +}
6808 +
6809 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6810 +{
6811 + unsigned int *kaddr;
6812 +
6813 + vmf->page = alloc_page(GFP_HIGHUSER);
6814 + if (!vmf->page)
6815 + return VM_FAULT_OOM;
6816 +
6817 + kaddr = kmap(vmf->page);
6818 + memset(kaddr, 0, PAGE_SIZE);
6819 + kaddr[0] = 0x9DE3BFA8U; /* save */
6820 + flush_dcache_page(vmf->page);
6821 + kunmap(vmf->page);
6822 + return VM_FAULT_MAJOR;
6823 +}
6824 +
6825 +static const struct vm_operations_struct pax_vm_ops = {
6826 + .close = pax_emuplt_close,
6827 + .fault = pax_emuplt_fault
6828 +};
6829 +
6830 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6831 +{
6832 + int ret;
6833 +
6834 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6835 + vma->vm_mm = current->mm;
6836 + vma->vm_start = addr;
6837 + vma->vm_end = addr + PAGE_SIZE;
6838 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6839 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6840 + vma->vm_ops = &pax_vm_ops;
6841 +
6842 + ret = insert_vm_struct(current->mm, vma);
6843 + if (ret)
6844 + return ret;
6845 +
6846 + ++current->mm->total_vm;
6847 + return 0;
6848 +}
6849 +#endif
6850 +
6851 +/*
6852 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6853 + *
6854 + * returns 1 when task should be killed
6855 + * 2 when patched PLT trampoline was detected
6856 + * 3 when unpatched PLT trampoline was detected
6857 + */
6858 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6859 +{
6860 +
6861 +#ifdef CONFIG_PAX_EMUPLT
6862 + int err;
6863 +
6864 + do { /* PaX: patched PLT emulation #1 */
6865 + unsigned int sethi1, sethi2, jmpl;
6866 +
6867 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6868 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6869 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6870 +
6871 + if (err)
6872 + break;
6873 +
6874 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6875 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6876 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6877 + {
6878 + unsigned long addr;
6879 +
6880 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6881 + addr = regs->u_regs[UREG_G1];
6882 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6883 +
6884 + if (test_thread_flag(TIF_32BIT))
6885 + addr &= 0xFFFFFFFFUL;
6886 +
6887 + regs->tpc = addr;
6888 + regs->tnpc = addr+4;
6889 + return 2;
6890 + }
6891 + } while (0);
6892 +
6893 + do { /* PaX: patched PLT emulation #2 */
6894 + unsigned int ba;
6895 +
6896 + err = get_user(ba, (unsigned int *)regs->tpc);
6897 +
6898 + if (err)
6899 + break;
6900 +
6901 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6902 + unsigned long addr;
6903 +
6904 + if ((ba & 0xFFC00000U) == 0x30800000U)
6905 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6906 + else
6907 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6908 +
6909 + if (test_thread_flag(TIF_32BIT))
6910 + addr &= 0xFFFFFFFFUL;
6911 +
6912 + regs->tpc = addr;
6913 + regs->tnpc = addr+4;
6914 + return 2;
6915 + }
6916 + } while (0);
6917 +
6918 + do { /* PaX: patched PLT emulation #3 */
6919 + unsigned int sethi, bajmpl, nop;
6920 +
6921 + err = get_user(sethi, (unsigned int *)regs->tpc);
6922 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6923 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6924 +
6925 + if (err)
6926 + break;
6927 +
6928 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6929 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6930 + nop == 0x01000000U)
6931 + {
6932 + unsigned long addr;
6933 +
6934 + addr = (sethi & 0x003FFFFFU) << 10;
6935 + regs->u_regs[UREG_G1] = addr;
6936 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6937 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6938 + else
6939 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6940 +
6941 + if (test_thread_flag(TIF_32BIT))
6942 + addr &= 0xFFFFFFFFUL;
6943 +
6944 + regs->tpc = addr;
6945 + regs->tnpc = addr+4;
6946 + return 2;
6947 + }
6948 + } while (0);
6949 +
6950 + do { /* PaX: patched PLT emulation #4 */
6951 + unsigned int sethi, mov1, call, mov2;
6952 +
6953 + err = get_user(sethi, (unsigned int *)regs->tpc);
6954 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
6955 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
6956 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
6957 +
6958 + if (err)
6959 + break;
6960 +
6961 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6962 + mov1 == 0x8210000FU &&
6963 + (call & 0xC0000000U) == 0x40000000U &&
6964 + mov2 == 0x9E100001U)
6965 + {
6966 + unsigned long addr;
6967 +
6968 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
6969 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
6970 +
6971 + if (test_thread_flag(TIF_32BIT))
6972 + addr &= 0xFFFFFFFFUL;
6973 +
6974 + regs->tpc = addr;
6975 + regs->tnpc = addr+4;
6976 + return 2;
6977 + }
6978 + } while (0);
6979 +
6980 + do { /* PaX: patched PLT emulation #5 */
6981 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
6982 +
6983 + err = get_user(sethi, (unsigned int *)regs->tpc);
6984 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
6985 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
6986 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
6987 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
6988 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
6989 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
6990 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
6991 +
6992 + if (err)
6993 + break;
6994 +
6995 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6996 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
6997 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
6998 + (or1 & 0xFFFFE000U) == 0x82106000U &&
6999 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7000 + sllx == 0x83287020U &&
7001 + jmpl == 0x81C04005U &&
7002 + nop == 0x01000000U)
7003 + {
7004 + unsigned long addr;
7005 +
7006 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7007 + regs->u_regs[UREG_G1] <<= 32;
7008 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7009 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7010 + regs->tpc = addr;
7011 + regs->tnpc = addr+4;
7012 + return 2;
7013 + }
7014 + } while (0);
7015 +
7016 + do { /* PaX: patched PLT emulation #6 */
7017 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7018 +
7019 + err = get_user(sethi, (unsigned int *)regs->tpc);
7020 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7021 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7022 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7023 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7024 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7025 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7026 +
7027 + if (err)
7028 + break;
7029 +
7030 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7031 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7032 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7033 + sllx == 0x83287020U &&
7034 + (or & 0xFFFFE000U) == 0x8A116000U &&
7035 + jmpl == 0x81C04005U &&
7036 + nop == 0x01000000U)
7037 + {
7038 + unsigned long addr;
7039 +
7040 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7041 + regs->u_regs[UREG_G1] <<= 32;
7042 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7043 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7044 + regs->tpc = addr;
7045 + regs->tnpc = addr+4;
7046 + return 2;
7047 + }
7048 + } while (0);
7049 +
7050 + do { /* PaX: unpatched PLT emulation step 1 */
7051 + unsigned int sethi, ba, nop;
7052 +
7053 + err = get_user(sethi, (unsigned int *)regs->tpc);
7054 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7055 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7056 +
7057 + if (err)
7058 + break;
7059 +
7060 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7061 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7062 + nop == 0x01000000U)
7063 + {
7064 + unsigned long addr;
7065 + unsigned int save, call;
7066 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7067 +
7068 + if ((ba & 0xFFC00000U) == 0x30800000U)
7069 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7070 + else
7071 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7072 +
7073 + if (test_thread_flag(TIF_32BIT))
7074 + addr &= 0xFFFFFFFFUL;
7075 +
7076 + err = get_user(save, (unsigned int *)addr);
7077 + err |= get_user(call, (unsigned int *)(addr+4));
7078 + err |= get_user(nop, (unsigned int *)(addr+8));
7079 + if (err)
7080 + break;
7081 +
7082 +#ifdef CONFIG_PAX_DLRESOLVE
7083 + if (save == 0x9DE3BFA8U &&
7084 + (call & 0xC0000000U) == 0x40000000U &&
7085 + nop == 0x01000000U)
7086 + {
7087 + struct vm_area_struct *vma;
7088 + unsigned long call_dl_resolve;
7089 +
7090 + down_read(&current->mm->mmap_sem);
7091 + call_dl_resolve = current->mm->call_dl_resolve;
7092 + up_read(&current->mm->mmap_sem);
7093 + if (likely(call_dl_resolve))
7094 + goto emulate;
7095 +
7096 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7097 +
7098 + down_write(&current->mm->mmap_sem);
7099 + if (current->mm->call_dl_resolve) {
7100 + call_dl_resolve = current->mm->call_dl_resolve;
7101 + up_write(&current->mm->mmap_sem);
7102 + if (vma)
7103 + kmem_cache_free(vm_area_cachep, vma);
7104 + goto emulate;
7105 + }
7106 +
7107 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7108 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7109 + up_write(&current->mm->mmap_sem);
7110 + if (vma)
7111 + kmem_cache_free(vm_area_cachep, vma);
7112 + return 1;
7113 + }
7114 +
7115 + if (pax_insert_vma(vma, call_dl_resolve)) {
7116 + up_write(&current->mm->mmap_sem);
7117 + kmem_cache_free(vm_area_cachep, vma);
7118 + return 1;
7119 + }
7120 +
7121 + current->mm->call_dl_resolve = call_dl_resolve;
7122 + up_write(&current->mm->mmap_sem);
7123 +
7124 +emulate:
7125 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7126 + regs->tpc = call_dl_resolve;
7127 + regs->tnpc = addr+4;
7128 + return 3;
7129 + }
7130 +#endif
7131 +
7132 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7133 + if ((save & 0xFFC00000U) == 0x05000000U &&
7134 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7135 + nop == 0x01000000U)
7136 + {
7137 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7138 + regs->u_regs[UREG_G2] = addr + 4;
7139 + addr = (save & 0x003FFFFFU) << 10;
7140 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7141 +
7142 + if (test_thread_flag(TIF_32BIT))
7143 + addr &= 0xFFFFFFFFUL;
7144 +
7145 + regs->tpc = addr;
7146 + regs->tnpc = addr+4;
7147 + return 3;
7148 + }
7149 +
7150 + /* PaX: 64-bit PLT stub */
7151 + err = get_user(sethi1, (unsigned int *)addr);
7152 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7153 + err |= get_user(or1, (unsigned int *)(addr+8));
7154 + err |= get_user(or2, (unsigned int *)(addr+12));
7155 + err |= get_user(sllx, (unsigned int *)(addr+16));
7156 + err |= get_user(add, (unsigned int *)(addr+20));
7157 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7158 + err |= get_user(nop, (unsigned int *)(addr+28));
7159 + if (err)
7160 + break;
7161 +
7162 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7163 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7164 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7165 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7166 + sllx == 0x89293020U &&
7167 + add == 0x8A010005U &&
7168 + jmpl == 0x89C14000U &&
7169 + nop == 0x01000000U)
7170 + {
7171 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7172 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7173 + regs->u_regs[UREG_G4] <<= 32;
7174 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7175 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7176 + regs->u_regs[UREG_G4] = addr + 24;
7177 + addr = regs->u_regs[UREG_G5];
7178 + regs->tpc = addr;
7179 + regs->tnpc = addr+4;
7180 + return 3;
7181 + }
7182 + }
7183 + } while (0);
7184 +
7185 +#ifdef CONFIG_PAX_DLRESOLVE
7186 + do { /* PaX: unpatched PLT emulation step 2 */
7187 + unsigned int save, call, nop;
7188 +
7189 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7190 + err |= get_user(call, (unsigned int *)regs->tpc);
7191 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7192 + if (err)
7193 + break;
7194 +
7195 + if (save == 0x9DE3BFA8U &&
7196 + (call & 0xC0000000U) == 0x40000000U &&
7197 + nop == 0x01000000U)
7198 + {
7199 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7200 +
7201 + if (test_thread_flag(TIF_32BIT))
7202 + dl_resolve &= 0xFFFFFFFFUL;
7203 +
7204 + regs->u_regs[UREG_RETPC] = regs->tpc;
7205 + regs->tpc = dl_resolve;
7206 + regs->tnpc = dl_resolve+4;
7207 + return 3;
7208 + }
7209 + } while (0);
7210 +#endif
7211 +
7212 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7213 + unsigned int sethi, ba, nop;
7214 +
7215 + err = get_user(sethi, (unsigned int *)regs->tpc);
7216 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7217 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7218 +
7219 + if (err)
7220 + break;
7221 +
7222 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7223 + (ba & 0xFFF00000U) == 0x30600000U &&
7224 + nop == 0x01000000U)
7225 + {
7226 + unsigned long addr;
7227 +
7228 + addr = (sethi & 0x003FFFFFU) << 10;
7229 + regs->u_regs[UREG_G1] = addr;
7230 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7231 +
7232 + if (test_thread_flag(TIF_32BIT))
7233 + addr &= 0xFFFFFFFFUL;
7234 +
7235 + regs->tpc = addr;
7236 + regs->tnpc = addr+4;
7237 + return 2;
7238 + }
7239 + } while (0);
7240 +
7241 +#endif
7242 +
7243 + return 1;
7244 +}
7245 +
7246 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7247 +{
7248 + unsigned long i;
7249 +
7250 + printk(KERN_ERR "PAX: bytes at PC: ");
7251 + for (i = 0; i < 8; i++) {
7252 + unsigned int c;
7253 + if (get_user(c, (unsigned int *)pc+i))
7254 + printk(KERN_CONT "???????? ");
7255 + else
7256 + printk(KERN_CONT "%08x ", c);
7257 + }
7258 + printk("\n");
7259 +}
7260 +#endif
7261 +
7262 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7263 {
7264 struct mm_struct *mm = current->mm;
7265 @@ -343,6 +806,29 @@ retry:
7266 if (!vma)
7267 goto bad_area;
7268
7269 +#ifdef CONFIG_PAX_PAGEEXEC
7270 + /* PaX: detect ITLB misses on non-exec pages */
7271 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7272 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7273 + {
7274 + if (address != regs->tpc)
7275 + goto good_area;
7276 +
7277 + up_read(&mm->mmap_sem);
7278 + switch (pax_handle_fetch_fault(regs)) {
7279 +
7280 +#ifdef CONFIG_PAX_EMUPLT
7281 + case 2:
7282 + case 3:
7283 + return;
7284 +#endif
7285 +
7286 + }
7287 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7288 + do_group_exit(SIGKILL);
7289 + }
7290 +#endif
7291 +
7292 /* Pure DTLB misses do not tell us whether the fault causing
7293 * load/store/atomic was a write or not, it only says that there
7294 * was no match. So in such a case we (carefully) read the
7295 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7296 index 07e1453..0a7d9e9 100644
7297 --- a/arch/sparc/mm/hugetlbpage.c
7298 +++ b/arch/sparc/mm/hugetlbpage.c
7299 @@ -67,7 +67,7 @@ full_search:
7300 }
7301 return -ENOMEM;
7302 }
7303 - if (likely(!vma || addr + len <= vma->vm_start)) {
7304 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7305 /*
7306 * Remember the place where we stopped the search:
7307 */
7308 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7309 /* make sure it can fit in the remaining address space */
7310 if (likely(addr > len)) {
7311 vma = find_vma(mm, addr-len);
7312 - if (!vma || addr <= vma->vm_start) {
7313 + if (check_heap_stack_gap(vma, addr - len, len)) {
7314 /* remember the address as a hint for next time */
7315 return (mm->free_area_cache = addr-len);
7316 }
7317 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7318 if (unlikely(mm->mmap_base < len))
7319 goto bottomup;
7320
7321 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7322 + addr = mm->mmap_base - len;
7323
7324 do {
7325 + addr &= HPAGE_MASK;
7326 /*
7327 * Lookup failure means no vma is above this address,
7328 * else if new region fits below vma->vm_start,
7329 * return with success:
7330 */
7331 vma = find_vma(mm, addr);
7332 - if (likely(!vma || addr+len <= vma->vm_start)) {
7333 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7334 /* remember the address as a hint for next time */
7335 return (mm->free_area_cache = addr);
7336 }
7337 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7338 mm->cached_hole_size = vma->vm_start - addr;
7339
7340 /* try just below the current vma->vm_start */
7341 - addr = (vma->vm_start-len) & HPAGE_MASK;
7342 - } while (likely(len < vma->vm_start));
7343 + addr = skip_heap_stack_gap(vma, len);
7344 + } while (!IS_ERR_VALUE(addr));
7345
7346 bottomup:
7347 /*
7348 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7349 if (addr) {
7350 addr = ALIGN(addr, HPAGE_SIZE);
7351 vma = find_vma(mm, addr);
7352 - if (task_size - len >= addr &&
7353 - (!vma || addr + len <= vma->vm_start))
7354 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7355 return addr;
7356 }
7357 if (mm->get_unmapped_area == arch_get_unmapped_area)
7358 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7359 index f4500c6..889656c 100644
7360 --- a/arch/tile/include/asm/atomic_64.h
7361 +++ b/arch/tile/include/asm/atomic_64.h
7362 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7363
7364 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7365
7366 +#define atomic64_read_unchecked(v) atomic64_read(v)
7367 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7368 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7369 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7370 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7371 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7372 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7373 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7374 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7375 +
7376 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7377 #define smp_mb__before_atomic_dec() smp_mb()
7378 #define smp_mb__after_atomic_dec() smp_mb()
7379 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7380 index a9a5299..0fce79e 100644
7381 --- a/arch/tile/include/asm/cache.h
7382 +++ b/arch/tile/include/asm/cache.h
7383 @@ -15,11 +15,12 @@
7384 #ifndef _ASM_TILE_CACHE_H
7385 #define _ASM_TILE_CACHE_H
7386
7387 +#include <linux/const.h>
7388 #include <arch/chip.h>
7389
7390 /* bytes per L1 data cache line */
7391 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7392 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7393 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7394
7395 /* bytes per L2 cache line */
7396 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7397 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7398 index 9ab078a..d6635c2 100644
7399 --- a/arch/tile/include/asm/uaccess.h
7400 +++ b/arch/tile/include/asm/uaccess.h
7401 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7402 const void __user *from,
7403 unsigned long n)
7404 {
7405 - int sz = __compiletime_object_size(to);
7406 + size_t sz = __compiletime_object_size(to);
7407
7408 - if (likely(sz == -1 || sz >= n))
7409 + if (likely(sz == (size_t)-1 || sz >= n))
7410 n = _copy_from_user(to, from, n);
7411 else
7412 copy_from_user_overflow();
7413 diff --git a/arch/um/Makefile b/arch/um/Makefile
7414 index 0970910..9f65c40 100644
7415 --- a/arch/um/Makefile
7416 +++ b/arch/um/Makefile
7417 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7418 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7419 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7420
7421 +ifdef CONSTIFY_PLUGIN
7422 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7423 +endif
7424 +
7425 #This will adjust *FLAGS accordingly to the platform.
7426 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7427
7428 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7429 index 19e1bdd..3665b77 100644
7430 --- a/arch/um/include/asm/cache.h
7431 +++ b/arch/um/include/asm/cache.h
7432 @@ -1,6 +1,7 @@
7433 #ifndef __UM_CACHE_H
7434 #define __UM_CACHE_H
7435
7436 +#include <linux/const.h>
7437
7438 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7439 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7440 @@ -12,6 +13,6 @@
7441 # define L1_CACHE_SHIFT 5
7442 #endif
7443
7444 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7445 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7446
7447 #endif
7448 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7449 index 2e0a6b1..a64d0f5 100644
7450 --- a/arch/um/include/asm/kmap_types.h
7451 +++ b/arch/um/include/asm/kmap_types.h
7452 @@ -8,6 +8,6 @@
7453
7454 /* No more #include "asm/arch/kmap_types.h" ! */
7455
7456 -#define KM_TYPE_NR 14
7457 +#define KM_TYPE_NR 15
7458
7459 #endif
7460 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7461 index 7cfc3ce..cbd1a58 100644
7462 --- a/arch/um/include/asm/page.h
7463 +++ b/arch/um/include/asm/page.h
7464 @@ -14,6 +14,9 @@
7465 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7466 #define PAGE_MASK (~(PAGE_SIZE-1))
7467
7468 +#define ktla_ktva(addr) (addr)
7469 +#define ktva_ktla(addr) (addr)
7470 +
7471 #ifndef __ASSEMBLY__
7472
7473 struct page;
7474 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7475 index 0032f92..cd151e0 100644
7476 --- a/arch/um/include/asm/pgtable-3level.h
7477 +++ b/arch/um/include/asm/pgtable-3level.h
7478 @@ -58,6 +58,7 @@
7479 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7480 #define pud_populate(mm, pud, pmd) \
7481 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7482 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7483
7484 #ifdef CONFIG_64BIT
7485 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7486 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7487 index c5f5afa..6abce4b 100644
7488 --- a/arch/um/kernel/process.c
7489 +++ b/arch/um/kernel/process.c
7490 @@ -402,22 +402,6 @@ int singlestepping(void * t)
7491 return 2;
7492 }
7493
7494 -/*
7495 - * Only x86 and x86_64 have an arch_align_stack().
7496 - * All other arches have "#define arch_align_stack(x) (x)"
7497 - * in their asm/system.h
7498 - * As this is included in UML from asm-um/system-generic.h,
7499 - * we can use it to behave as the subarch does.
7500 - */
7501 -#ifndef arch_align_stack
7502 -unsigned long arch_align_stack(unsigned long sp)
7503 -{
7504 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7505 - sp -= get_random_int() % 8192;
7506 - return sp & ~0xf;
7507 -}
7508 -#endif
7509 -
7510 unsigned long get_wchan(struct task_struct *p)
7511 {
7512 unsigned long stack_page, sp, ip;
7513 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7514 index ad8f795..2c7eec6 100644
7515 --- a/arch/unicore32/include/asm/cache.h
7516 +++ b/arch/unicore32/include/asm/cache.h
7517 @@ -12,8 +12,10 @@
7518 #ifndef __UNICORE_CACHE_H__
7519 #define __UNICORE_CACHE_H__
7520
7521 -#define L1_CACHE_SHIFT (5)
7522 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7523 +#include <linux/const.h>
7524 +
7525 +#define L1_CACHE_SHIFT 5
7526 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7527
7528 /*
7529 * Memory returned by kmalloc() may be used for DMA, so we must make
7530 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7531 index 50a1d1f..c26369f 100644
7532 --- a/arch/x86/Kconfig
7533 +++ b/arch/x86/Kconfig
7534 @@ -220,7 +220,7 @@ config X86_HT
7535
7536 config X86_32_LAZY_GS
7537 def_bool y
7538 - depends on X86_32 && !CC_STACKPROTECTOR
7539 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7540
7541 config ARCH_HWEIGHT_CFLAGS
7542 string
7543 @@ -1049,7 +1049,7 @@ choice
7544
7545 config NOHIGHMEM
7546 bool "off"
7547 - depends on !X86_NUMAQ
7548 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7549 ---help---
7550 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7551 However, the address space of 32-bit x86 processors is only 4
7552 @@ -1086,7 +1086,7 @@ config NOHIGHMEM
7553
7554 config HIGHMEM4G
7555 bool "4GB"
7556 - depends on !X86_NUMAQ
7557 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7558 ---help---
7559 Select this if you have a 32-bit processor and between 1 and 4
7560 gigabytes of physical RAM.
7561 @@ -1140,7 +1140,7 @@ config PAGE_OFFSET
7562 hex
7563 default 0xB0000000 if VMSPLIT_3G_OPT
7564 default 0x80000000 if VMSPLIT_2G
7565 - default 0x78000000 if VMSPLIT_2G_OPT
7566 + default 0x70000000 if VMSPLIT_2G_OPT
7567 default 0x40000000 if VMSPLIT_1G
7568 default 0xC0000000
7569 depends on X86_32
7570 @@ -1528,6 +1528,7 @@ config SECCOMP
7571
7572 config CC_STACKPROTECTOR
7573 bool "Enable -fstack-protector buffer overflow detection"
7574 + depends on X86_64 || !PAX_MEMORY_UDEREF
7575 ---help---
7576 This option turns on the -fstack-protector GCC feature. This
7577 feature puts, at the beginning of functions, a canary value on
7578 @@ -1585,6 +1586,7 @@ config KEXEC_JUMP
7579 config PHYSICAL_START
7580 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7581 default "0x1000000"
7582 + range 0x400000 0x40000000
7583 ---help---
7584 This gives the physical address where the kernel is loaded.
7585
7586 @@ -1648,6 +1650,7 @@ config X86_NEED_RELOCS
7587 config PHYSICAL_ALIGN
7588 hex "Alignment value to which kernel should be aligned" if X86_32
7589 default "0x1000000"
7590 + range 0x400000 0x1000000 if PAX_KERNEXEC
7591 range 0x2000 0x1000000
7592 ---help---
7593 This value puts the alignment restrictions on physical address
7594 @@ -1679,9 +1682,10 @@ config HOTPLUG_CPU
7595 Say N if you want to disable CPU hotplug.
7596
7597 config COMPAT_VDSO
7598 - def_bool y
7599 + def_bool n
7600 prompt "Compat VDSO support"
7601 depends on X86_32 || IA32_EMULATION
7602 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7603 ---help---
7604 Map the 32-bit VDSO to the predictable old-style address too.
7605
7606 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7607 index 706e12e..62e4feb 100644
7608 --- a/arch/x86/Kconfig.cpu
7609 +++ b/arch/x86/Kconfig.cpu
7610 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7611
7612 config X86_F00F_BUG
7613 def_bool y
7614 - depends on M586MMX || M586TSC || M586 || M486 || M386
7615 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7616
7617 config X86_INVD_BUG
7618 def_bool y
7619 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7620
7621 config X86_ALIGNMENT_16
7622 def_bool y
7623 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7624 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7625
7626 config X86_INTEL_USERCOPY
7627 def_bool y
7628 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7629 # generates cmov.
7630 config X86_CMOV
7631 def_bool y
7632 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7633 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7634
7635 config X86_MINIMUM_CPU_FAMILY
7636 int
7637 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7638 index b322f12..652d0d9 100644
7639 --- a/arch/x86/Kconfig.debug
7640 +++ b/arch/x86/Kconfig.debug
7641 @@ -84,7 +84,7 @@ config X86_PTDUMP
7642 config DEBUG_RODATA
7643 bool "Write protect kernel read-only data structures"
7644 default y
7645 - depends on DEBUG_KERNEL
7646 + depends on DEBUG_KERNEL && BROKEN
7647 ---help---
7648 Mark the kernel read-only data as write-protected in the pagetables,
7649 in order to catch accidental (and incorrect) writes to such const
7650 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7651
7652 config DEBUG_SET_MODULE_RONX
7653 bool "Set loadable kernel module data as NX and text as RO"
7654 - depends on MODULES
7655 + depends on MODULES && BROKEN
7656 ---help---
7657 This option helps catch unintended modifications to loadable
7658 kernel module's text and read-only data. It also prevents execution
7659 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
7660
7661 config DEBUG_STRICT_USER_COPY_CHECKS
7662 bool "Strict copy size checks"
7663 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7664 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7665 ---help---
7666 Enabling this option turns a certain set of sanity checks for user
7667 copy operations into compile time failures.
7668 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7669 index 58790bd..fc2f239 100644
7670 --- a/arch/x86/Makefile
7671 +++ b/arch/x86/Makefile
7672 @@ -50,6 +50,7 @@ else
7673 UTS_MACHINE := x86_64
7674 CHECKFLAGS += -D__x86_64__ -m64
7675
7676 + biarch := $(call cc-option,-m64)
7677 KBUILD_AFLAGS += -m64
7678 KBUILD_CFLAGS += -m64
7679
7680 @@ -229,3 +230,12 @@ define archhelp
7681 echo ' FDARGS="..." arguments for the booted kernel'
7682 echo ' FDINITRD=file initrd for the booted kernel'
7683 endef
7684 +
7685 +define OLD_LD
7686 +
7687 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7688 +*** Please upgrade your binutils to 2.18 or newer
7689 +endef
7690 +
7691 +archprepare:
7692 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7693 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7694 index f7535be..37db2d1 100644
7695 --- a/arch/x86/boot/Makefile
7696 +++ b/arch/x86/boot/Makefile
7697 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7698 $(call cc-option, -fno-stack-protector) \
7699 $(call cc-option, -mpreferred-stack-boundary=2)
7700 KBUILD_CFLAGS += $(call cc-option, -m32)
7701 +ifdef CONSTIFY_PLUGIN
7702 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7703 +endif
7704 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7705 GCOV_PROFILE := n
7706
7707 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7708 index 878e4b9..20537ab 100644
7709 --- a/arch/x86/boot/bitops.h
7710 +++ b/arch/x86/boot/bitops.h
7711 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7712 u8 v;
7713 const u32 *p = (const u32 *)addr;
7714
7715 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7716 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7717 return v;
7718 }
7719
7720 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7721
7722 static inline void set_bit(int nr, void *addr)
7723 {
7724 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7725 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7726 }
7727
7728 #endif /* BOOT_BITOPS_H */
7729 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7730 index 18997e5..83d9c67 100644
7731 --- a/arch/x86/boot/boot.h
7732 +++ b/arch/x86/boot/boot.h
7733 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7734 static inline u16 ds(void)
7735 {
7736 u16 seg;
7737 - asm("movw %%ds,%0" : "=rm" (seg));
7738 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7739 return seg;
7740 }
7741
7742 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7743 static inline int memcmp(const void *s1, const void *s2, size_t len)
7744 {
7745 u8 diff;
7746 - asm("repe; cmpsb; setnz %0"
7747 + asm volatile("repe; cmpsb; setnz %0"
7748 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7749 return diff;
7750 }
7751 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7752 index 8a84501..b2d165f 100644
7753 --- a/arch/x86/boot/compressed/Makefile
7754 +++ b/arch/x86/boot/compressed/Makefile
7755 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7756 KBUILD_CFLAGS += $(cflags-y)
7757 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7758 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7759 +ifdef CONSTIFY_PLUGIN
7760 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7761 +endif
7762
7763 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7764 GCOV_PROFILE := n
7765 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7766 index b3e0227..f2c02d5 100644
7767 --- a/arch/x86/boot/compressed/eboot.c
7768 +++ b/arch/x86/boot/compressed/eboot.c
7769 @@ -142,7 +142,6 @@ again:
7770 *addr = max_addr;
7771 }
7772
7773 -free_pool:
7774 efi_call_phys1(sys_table->boottime->free_pool, map);
7775
7776 fail:
7777 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7778 if (i == map_size / desc_size)
7779 status = EFI_NOT_FOUND;
7780
7781 -free_pool:
7782 efi_call_phys1(sys_table->boottime->free_pool, map);
7783 fail:
7784 return status;
7785 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7786 index aa4aaf1..6656f2f 100644
7787 --- a/arch/x86/boot/compressed/head_32.S
7788 +++ b/arch/x86/boot/compressed/head_32.S
7789 @@ -116,7 +116,7 @@ preferred_addr:
7790 notl %eax
7791 andl %eax, %ebx
7792 #else
7793 - movl $LOAD_PHYSICAL_ADDR, %ebx
7794 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7795 #endif
7796
7797 /* Target address to relocate to for decompression */
7798 @@ -202,7 +202,7 @@ relocated:
7799 * and where it was actually loaded.
7800 */
7801 movl %ebp, %ebx
7802 - subl $LOAD_PHYSICAL_ADDR, %ebx
7803 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7804 jz 2f /* Nothing to be done if loaded at compiled addr. */
7805 /*
7806 * Process relocations.
7807 @@ -210,8 +210,7 @@ relocated:
7808
7809 1: subl $4, %edi
7810 movl (%edi), %ecx
7811 - testl %ecx, %ecx
7812 - jz 2f
7813 + jecxz 2f
7814 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7815 jmp 1b
7816 2:
7817 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7818 index 2c4b171..e1fa5b1 100644
7819 --- a/arch/x86/boot/compressed/head_64.S
7820 +++ b/arch/x86/boot/compressed/head_64.S
7821 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7822 notl %eax
7823 andl %eax, %ebx
7824 #else
7825 - movl $LOAD_PHYSICAL_ADDR, %ebx
7826 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7827 #endif
7828
7829 /* Target address to relocate to for decompression */
7830 @@ -273,7 +273,7 @@ preferred_addr:
7831 notq %rax
7832 andq %rax, %rbp
7833 #else
7834 - movq $LOAD_PHYSICAL_ADDR, %rbp
7835 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7836 #endif
7837
7838 /* Target address to relocate to for decompression */
7839 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7840 index 88f7ff6..ed695dd 100644
7841 --- a/arch/x86/boot/compressed/misc.c
7842 +++ b/arch/x86/boot/compressed/misc.c
7843 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
7844 case PT_LOAD:
7845 #ifdef CONFIG_RELOCATABLE
7846 dest = output;
7847 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7848 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7849 #else
7850 dest = (void *)(phdr->p_paddr);
7851 #endif
7852 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7853 error("Destination address too large");
7854 #endif
7855 #ifndef CONFIG_RELOCATABLE
7856 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7857 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7858 error("Wrong destination address");
7859 #endif
7860
7861 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7862 index 4d3ff03..e4972ff 100644
7863 --- a/arch/x86/boot/cpucheck.c
7864 +++ b/arch/x86/boot/cpucheck.c
7865 @@ -74,7 +74,7 @@ static int has_fpu(void)
7866 u16 fcw = -1, fsw = -1;
7867 u32 cr0;
7868
7869 - asm("movl %%cr0,%0" : "=r" (cr0));
7870 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7871 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7872 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7873 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7874 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7875 {
7876 u32 f0, f1;
7877
7878 - asm("pushfl ; "
7879 + asm volatile("pushfl ; "
7880 "pushfl ; "
7881 "popl %0 ; "
7882 "movl %0,%1 ; "
7883 @@ -115,7 +115,7 @@ static void get_flags(void)
7884 set_bit(X86_FEATURE_FPU, cpu.flags);
7885
7886 if (has_eflag(X86_EFLAGS_ID)) {
7887 - asm("cpuid"
7888 + asm volatile("cpuid"
7889 : "=a" (max_intel_level),
7890 "=b" (cpu_vendor[0]),
7891 "=d" (cpu_vendor[1]),
7892 @@ -124,7 +124,7 @@ static void get_flags(void)
7893
7894 if (max_intel_level >= 0x00000001 &&
7895 max_intel_level <= 0x0000ffff) {
7896 - asm("cpuid"
7897 + asm volatile("cpuid"
7898 : "=a" (tfms),
7899 "=c" (cpu.flags[4]),
7900 "=d" (cpu.flags[0])
7901 @@ -136,7 +136,7 @@ static void get_flags(void)
7902 cpu.model += ((tfms >> 16) & 0xf) << 4;
7903 }
7904
7905 - asm("cpuid"
7906 + asm volatile("cpuid"
7907 : "=a" (max_amd_level)
7908 : "a" (0x80000000)
7909 : "ebx", "ecx", "edx");
7910 @@ -144,7 +144,7 @@ static void get_flags(void)
7911 if (max_amd_level >= 0x80000001 &&
7912 max_amd_level <= 0x8000ffff) {
7913 u32 eax = 0x80000001;
7914 - asm("cpuid"
7915 + asm volatile("cpuid"
7916 : "+a" (eax),
7917 "=c" (cpu.flags[6]),
7918 "=d" (cpu.flags[1])
7919 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7920 u32 ecx = MSR_K7_HWCR;
7921 u32 eax, edx;
7922
7923 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7924 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7925 eax &= ~(1 << 15);
7926 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7927 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7928
7929 get_flags(); /* Make sure it really did something */
7930 err = check_flags();
7931 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7932 u32 ecx = MSR_VIA_FCR;
7933 u32 eax, edx;
7934
7935 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7936 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7937 eax |= (1<<1)|(1<<7);
7938 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7939 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7940
7941 set_bit(X86_FEATURE_CX8, cpu.flags);
7942 err = check_flags();
7943 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7944 u32 eax, edx;
7945 u32 level = 1;
7946
7947 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7948 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7949 - asm("cpuid"
7950 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7951 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
7952 + asm volatile("cpuid"
7953 : "+a" (level), "=d" (cpu.flags[0])
7954 : : "ecx", "ebx");
7955 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7956 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7957
7958 err = check_flags();
7959 }
7960 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
7961 index b4e15dd..8ac59ce 100644
7962 --- a/arch/x86/boot/header.S
7963 +++ b/arch/x86/boot/header.S
7964 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
7965 # single linked list of
7966 # struct setup_data
7967
7968 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
7969 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
7970
7971 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
7972 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
7973 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
7974 +#else
7975 #define VO_INIT_SIZE (VO__end - VO__text)
7976 +#endif
7977 #if ZO_INIT_SIZE > VO_INIT_SIZE
7978 #define INIT_SIZE ZO_INIT_SIZE
7979 #else
7980 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
7981 index db75d07..8e6d0af 100644
7982 --- a/arch/x86/boot/memory.c
7983 +++ b/arch/x86/boot/memory.c
7984 @@ -19,7 +19,7 @@
7985
7986 static int detect_memory_e820(void)
7987 {
7988 - int count = 0;
7989 + unsigned int count = 0;
7990 struct biosregs ireg, oreg;
7991 struct e820entry *desc = boot_params.e820_map;
7992 static struct e820entry buf; /* static so it is zeroed */
7993 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
7994 index 11e8c6e..fdbb1ed 100644
7995 --- a/arch/x86/boot/video-vesa.c
7996 +++ b/arch/x86/boot/video-vesa.c
7997 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
7998
7999 boot_params.screen_info.vesapm_seg = oreg.es;
8000 boot_params.screen_info.vesapm_off = oreg.di;
8001 + boot_params.screen_info.vesapm_size = oreg.cx;
8002 }
8003
8004 /*
8005 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8006 index 43eda28..5ab5fdb 100644
8007 --- a/arch/x86/boot/video.c
8008 +++ b/arch/x86/boot/video.c
8009 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8010 static unsigned int get_entry(void)
8011 {
8012 char entry_buf[4];
8013 - int i, len = 0;
8014 + unsigned int i, len = 0;
8015 int key;
8016 unsigned int v;
8017
8018 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8019 index 5b577d5..3c1fed4 100644
8020 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8021 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8022 @@ -8,6 +8,8 @@
8023 * including this sentence is retained in full.
8024 */
8025
8026 +#include <asm/alternative-asm.h>
8027 +
8028 .extern crypto_ft_tab
8029 .extern crypto_it_tab
8030 .extern crypto_fl_tab
8031 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8032 je B192; \
8033 leaq 32(r9),r9;
8034
8035 +#define ret pax_force_retaddr 0, 1; ret
8036 +
8037 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8038 movq r1,r2; \
8039 movq r3,r4; \
8040 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8041 index 3470624..201259d 100644
8042 --- a/arch/x86/crypto/aesni-intel_asm.S
8043 +++ b/arch/x86/crypto/aesni-intel_asm.S
8044 @@ -31,6 +31,7 @@
8045
8046 #include <linux/linkage.h>
8047 #include <asm/inst.h>
8048 +#include <asm/alternative-asm.h>
8049
8050 #ifdef __x86_64__
8051 .data
8052 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8053 pop %r14
8054 pop %r13
8055 pop %r12
8056 + pax_force_retaddr 0, 1
8057 ret
8058 +ENDPROC(aesni_gcm_dec)
8059
8060
8061 /*****************************************************************************
8062 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8063 pop %r14
8064 pop %r13
8065 pop %r12
8066 + pax_force_retaddr 0, 1
8067 ret
8068 +ENDPROC(aesni_gcm_enc)
8069
8070 #endif
8071
8072 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8073 pxor %xmm1, %xmm0
8074 movaps %xmm0, (TKEYP)
8075 add $0x10, TKEYP
8076 + pax_force_retaddr_bts
8077 ret
8078
8079 .align 4
8080 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8081 shufps $0b01001110, %xmm2, %xmm1
8082 movaps %xmm1, 0x10(TKEYP)
8083 add $0x20, TKEYP
8084 + pax_force_retaddr_bts
8085 ret
8086
8087 .align 4
8088 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8089
8090 movaps %xmm0, (TKEYP)
8091 add $0x10, TKEYP
8092 + pax_force_retaddr_bts
8093 ret
8094
8095 .align 4
8096 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8097 pxor %xmm1, %xmm2
8098 movaps %xmm2, (TKEYP)
8099 add $0x10, TKEYP
8100 + pax_force_retaddr_bts
8101 ret
8102
8103 /*
8104 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8105 #ifndef __x86_64__
8106 popl KEYP
8107 #endif
8108 + pax_force_retaddr 0, 1
8109 ret
8110 +ENDPROC(aesni_set_key)
8111
8112 /*
8113 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8114 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8115 popl KLEN
8116 popl KEYP
8117 #endif
8118 + pax_force_retaddr 0, 1
8119 ret
8120 +ENDPROC(aesni_enc)
8121
8122 /*
8123 * _aesni_enc1: internal ABI
8124 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8125 AESENC KEY STATE
8126 movaps 0x70(TKEYP), KEY
8127 AESENCLAST KEY STATE
8128 + pax_force_retaddr_bts
8129 ret
8130
8131 /*
8132 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8133 AESENCLAST KEY STATE2
8134 AESENCLAST KEY STATE3
8135 AESENCLAST KEY STATE4
8136 + pax_force_retaddr_bts
8137 ret
8138
8139 /*
8140 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8141 popl KLEN
8142 popl KEYP
8143 #endif
8144 + pax_force_retaddr 0, 1
8145 ret
8146 +ENDPROC(aesni_dec)
8147
8148 /*
8149 * _aesni_dec1: internal ABI
8150 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8151 AESDEC KEY STATE
8152 movaps 0x70(TKEYP), KEY
8153 AESDECLAST KEY STATE
8154 + pax_force_retaddr_bts
8155 ret
8156
8157 /*
8158 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8159 AESDECLAST KEY STATE2
8160 AESDECLAST KEY STATE3
8161 AESDECLAST KEY STATE4
8162 + pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8167 popl KEYP
8168 popl LEN
8169 #endif
8170 + pax_force_retaddr 0, 1
8171 ret
8172 +ENDPROC(aesni_ecb_enc)
8173
8174 /*
8175 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8176 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8177 popl KEYP
8178 popl LEN
8179 #endif
8180 + pax_force_retaddr 0, 1
8181 ret
8182 +ENDPROC(aesni_ecb_dec)
8183
8184 /*
8185 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8186 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8187 popl LEN
8188 popl IVP
8189 #endif
8190 + pax_force_retaddr 0, 1
8191 ret
8192 +ENDPROC(aesni_cbc_enc)
8193
8194 /*
8195 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8196 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8197 popl LEN
8198 popl IVP
8199 #endif
8200 + pax_force_retaddr 0, 1
8201 ret
8202 +ENDPROC(aesni_cbc_dec)
8203
8204 #ifdef __x86_64__
8205 .align 16
8206 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8207 mov $1, TCTR_LOW
8208 MOVQ_R64_XMM TCTR_LOW INC
8209 MOVQ_R64_XMM CTR TCTR_LOW
8210 + pax_force_retaddr_bts
8211 ret
8212
8213 /*
8214 @@ -2554,6 +2582,7 @@ _aesni_inc:
8215 .Linc_low:
8216 movaps CTR, IV
8217 PSHUFB_XMM BSWAP_MASK IV
8218 + pax_force_retaddr_bts
8219 ret
8220
8221 /*
8222 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8223 .Lctr_enc_ret:
8224 movups IV, (IVP)
8225 .Lctr_enc_just_ret:
8226 + pax_force_retaddr 0, 1
8227 ret
8228 +ENDPROC(aesni_ctr_enc)
8229 #endif
8230 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8231 index 391d245..67f35c2 100644
8232 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8233 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8234 @@ -20,6 +20,8 @@
8235 *
8236 */
8237
8238 +#include <asm/alternative-asm.h>
8239 +
8240 .file "blowfish-x86_64-asm.S"
8241 .text
8242
8243 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8244 jnz __enc_xor;
8245
8246 write_block();
8247 + pax_force_retaddr 0, 1
8248 ret;
8249 __enc_xor:
8250 xor_block();
8251 + pax_force_retaddr 0, 1
8252 ret;
8253
8254 .align 8
8255 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8256
8257 movq %r11, %rbp;
8258
8259 + pax_force_retaddr 0, 1
8260 ret;
8261
8262 /**********************************************************************
8263 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8264
8265 popq %rbx;
8266 popq %rbp;
8267 + pax_force_retaddr 0, 1
8268 ret;
8269
8270 __enc_xor4:
8271 @@ -349,6 +355,7 @@ __enc_xor4:
8272
8273 popq %rbx;
8274 popq %rbp;
8275 + pax_force_retaddr 0, 1
8276 ret;
8277
8278 .align 8
8279 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8280 popq %rbx;
8281 popq %rbp;
8282
8283 + pax_force_retaddr 0, 1
8284 ret;
8285
8286 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8287 index 0b33743..7a56206 100644
8288 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8289 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8290 @@ -20,6 +20,8 @@
8291 *
8292 */
8293
8294 +#include <asm/alternative-asm.h>
8295 +
8296 .file "camellia-x86_64-asm_64.S"
8297 .text
8298
8299 @@ -229,12 +231,14 @@ __enc_done:
8300 enc_outunpack(mov, RT1);
8301
8302 movq RRBP, %rbp;
8303 + pax_force_retaddr 0, 1
8304 ret;
8305
8306 __enc_xor:
8307 enc_outunpack(xor, RT1);
8308
8309 movq RRBP, %rbp;
8310 + pax_force_retaddr 0, 1
8311 ret;
8312
8313 .global camellia_dec_blk;
8314 @@ -275,6 +279,7 @@ __dec_rounds16:
8315 dec_outunpack();
8316
8317 movq RRBP, %rbp;
8318 + pax_force_retaddr 0, 1
8319 ret;
8320
8321 /**********************************************************************
8322 @@ -468,6 +473,7 @@ __enc2_done:
8323
8324 movq RRBP, %rbp;
8325 popq %rbx;
8326 + pax_force_retaddr 0, 1
8327 ret;
8328
8329 __enc2_xor:
8330 @@ -475,6 +481,7 @@ __enc2_xor:
8331
8332 movq RRBP, %rbp;
8333 popq %rbx;
8334 + pax_force_retaddr 0, 1
8335 ret;
8336
8337 .global camellia_dec_blk_2way;
8338 @@ -517,4 +524,5 @@ __dec2_rounds16:
8339
8340 movq RRBP, %rbp;
8341 movq RXOR, %rbx;
8342 + pax_force_retaddr 0, 1
8343 ret;
8344 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8345 index 6214a9b..1f4fc9a 100644
8346 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8347 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8348 @@ -1,3 +1,5 @@
8349 +#include <asm/alternative-asm.h>
8350 +
8351 # enter ECRYPT_encrypt_bytes
8352 .text
8353 .p2align 5
8354 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8355 add %r11,%rsp
8356 mov %rdi,%rax
8357 mov %rsi,%rdx
8358 + pax_force_retaddr 0, 1
8359 ret
8360 # bytesatleast65:
8361 ._bytesatleast65:
8362 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8363 add %r11,%rsp
8364 mov %rdi,%rax
8365 mov %rsi,%rdx
8366 + pax_force_retaddr
8367 ret
8368 # enter ECRYPT_ivsetup
8369 .text
8370 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8371 add %r11,%rsp
8372 mov %rdi,%rax
8373 mov %rsi,%rdx
8374 + pax_force_retaddr
8375 ret
8376 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8377 index 504106b..4e50951 100644
8378 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8379 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
8380 @@ -24,6 +24,8 @@
8381 *
8382 */
8383
8384 +#include <asm/alternative-asm.h>
8385 +
8386 .file "serpent-avx-x86_64-asm_64.S"
8387 .text
8388
8389 @@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
8390 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8391 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8392
8393 + pax_force_retaddr
8394 ret;
8395
8396 __enc_xor8:
8397 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8398 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8399
8400 + pax_force_retaddr
8401 ret;
8402
8403 .align 8
8404 @@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
8405 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8406 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8407
8408 + pax_force_retaddr
8409 ret;
8410 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8411 index 3ee1ff0..cbc568b 100644
8412 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8413 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8414 @@ -24,6 +24,8 @@
8415 *
8416 */
8417
8418 +#include <asm/alternative-asm.h>
8419 +
8420 .file "serpent-sse2-x86_64-asm_64.S"
8421 .text
8422
8423 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8424 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8425 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8426
8427 + pax_force_retaddr
8428 ret;
8429
8430 __enc_xor8:
8431 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8432 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8433
8434 + pax_force_retaddr
8435 ret;
8436
8437 .align 8
8438 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8439 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8440 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8441
8442 + pax_force_retaddr
8443 ret;
8444 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8445 index 49d6987..df66bd4 100644
8446 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8447 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8448 @@ -28,6 +28,8 @@
8449 * (at your option) any later version.
8450 */
8451
8452 +#include <asm/alternative-asm.h>
8453 +
8454 #define CTX %rdi // arg1
8455 #define BUF %rsi // arg2
8456 #define CNT %rdx // arg3
8457 @@ -104,6 +106,7 @@
8458 pop %r12
8459 pop %rbp
8460 pop %rbx
8461 + pax_force_retaddr 0, 1
8462 ret
8463
8464 .size \name, .-\name
8465 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8466 index 35f4557..16b379f 100644
8467 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8468 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
8469 @@ -21,6 +21,8 @@
8470 *
8471 */
8472
8473 +#include <asm/alternative-asm.h>
8474 +
8475 .file "twofish-avx-x86_64-asm_64.S"
8476 .text
8477
8478 @@ -250,12 +252,14 @@ __twofish_enc_blk_8way:
8479 outunpack_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8480 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8481
8482 + pax_force_retaddr
8483 ret;
8484
8485 __enc_xor8:
8486 outunpack_xor_blocks(%rsi, RC1, RD1, RA1, RB1, RK1, RX, RY, RK2);
8487 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX, RY, RK2);
8488
8489 + pax_force_retaddr
8490 ret;
8491
8492 .align 8
8493 @@ -297,4 +301,5 @@ twofish_dec_blk_8way:
8494 outunpack_blocks(%rsi, RA1, RB1, RC1, RD1, RK1, RX, RY, RK2);
8495 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX, RY, RK2);
8496
8497 + pax_force_retaddr
8498 ret;
8499 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8500 index 5b012a2..36d5364 100644
8501 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8502 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8503 @@ -20,6 +20,8 @@
8504 *
8505 */
8506
8507 +#include <asm/alternative-asm.h>
8508 +
8509 .file "twofish-x86_64-asm-3way.S"
8510 .text
8511
8512 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8513 popq %r13;
8514 popq %r14;
8515 popq %r15;
8516 + pax_force_retaddr 0, 1
8517 ret;
8518
8519 __enc_xor3:
8520 @@ -271,6 +274,7 @@ __enc_xor3:
8521 popq %r13;
8522 popq %r14;
8523 popq %r15;
8524 + pax_force_retaddr 0, 1
8525 ret;
8526
8527 .global twofish_dec_blk_3way
8528 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8529 popq %r13;
8530 popq %r14;
8531 popq %r15;
8532 + pax_force_retaddr 0, 1
8533 ret;
8534
8535 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8536 index 7bcf3fc..f53832f 100644
8537 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8538 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8539 @@ -21,6 +21,7 @@
8540 .text
8541
8542 #include <asm/asm-offsets.h>
8543 +#include <asm/alternative-asm.h>
8544
8545 #define a_offset 0
8546 #define b_offset 4
8547 @@ -268,6 +269,7 @@ twofish_enc_blk:
8548
8549 popq R1
8550 movq $1,%rax
8551 + pax_force_retaddr 0, 1
8552 ret
8553
8554 twofish_dec_blk:
8555 @@ -319,4 +321,5 @@ twofish_dec_blk:
8556
8557 popq R1
8558 movq $1,%rax
8559 + pax_force_retaddr 0, 1
8560 ret
8561 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8562 index 07b3a68..bd2a388 100644
8563 --- a/arch/x86/ia32/ia32_aout.c
8564 +++ b/arch/x86/ia32/ia32_aout.c
8565 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8566 unsigned long dump_start, dump_size;
8567 struct user32 dump;
8568
8569 + memset(&dump, 0, sizeof(dump));
8570 +
8571 fs = get_fs();
8572 set_fs(KERNEL_DS);
8573 has_dumped = 1;
8574 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8575 index 673ac9b..7a8c5df 100644
8576 --- a/arch/x86/ia32/ia32_signal.c
8577 +++ b/arch/x86/ia32/ia32_signal.c
8578 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8579 }
8580 seg = get_fs();
8581 set_fs(KERNEL_DS);
8582 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8583 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8584 set_fs(seg);
8585 if (ret >= 0 && uoss_ptr) {
8586 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8587 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8588 */
8589 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8590 size_t frame_size,
8591 - void **fpstate)
8592 + void __user **fpstate)
8593 {
8594 unsigned long sp;
8595
8596 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8597
8598 if (used_math()) {
8599 sp = sp - sig_xstate_ia32_size;
8600 - *fpstate = (struct _fpstate_ia32 *) sp;
8601 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8602 if (save_i387_xstate_ia32(*fpstate) < 0)
8603 return (void __user *) -1L;
8604 }
8605 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8606 sp -= frame_size;
8607 /* Align the stack pointer according to the i386 ABI,
8608 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8609 - sp = ((sp + 4) & -16ul) - 4;
8610 + sp = ((sp - 12) & -16ul) - 4;
8611 return (void __user *) sp;
8612 }
8613
8614 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8615 * These are actually not used anymore, but left because some
8616 * gdb versions depend on them as a marker.
8617 */
8618 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8619 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8620 } put_user_catch(err);
8621
8622 if (err)
8623 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8624 0xb8,
8625 __NR_ia32_rt_sigreturn,
8626 0x80cd,
8627 - 0,
8628 + 0
8629 };
8630
8631 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8632 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8633
8634 if (ka->sa.sa_flags & SA_RESTORER)
8635 restorer = ka->sa.sa_restorer;
8636 + else if (current->mm->context.vdso)
8637 + /* Return stub is in 32bit vsyscall page */
8638 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8639 else
8640 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8641 - rt_sigreturn);
8642 + restorer = &frame->retcode;
8643 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8644
8645 /*
8646 * Not actually used anymore, but left because some gdb
8647 * versions need it.
8648 */
8649 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8650 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8651 } put_user_catch(err);
8652
8653 if (err)
8654 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8655 index 20e5f7b..f33c779 100644
8656 --- a/arch/x86/ia32/ia32entry.S
8657 +++ b/arch/x86/ia32/ia32entry.S
8658 @@ -14,8 +14,10 @@
8659 #include <asm/segment.h>
8660 #include <asm/irqflags.h>
8661 #include <asm/asm.h>
8662 +#include <asm/pgtable.h>
8663 #include <linux/linkage.h>
8664 #include <linux/err.h>
8665 +#include <asm/alternative-asm.h>
8666
8667 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8668 #include <linux/elf-em.h>
8669 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8670 ENDPROC(native_irq_enable_sysexit)
8671 #endif
8672
8673 + .macro pax_enter_kernel_user
8674 + pax_set_fptr_mask
8675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8676 + call pax_enter_kernel_user
8677 +#endif
8678 + .endm
8679 +
8680 + .macro pax_exit_kernel_user
8681 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8682 + call pax_exit_kernel_user
8683 +#endif
8684 +#ifdef CONFIG_PAX_RANDKSTACK
8685 + pushq %rax
8686 + pushq %r11
8687 + call pax_randomize_kstack
8688 + popq %r11
8689 + popq %rax
8690 +#endif
8691 + .endm
8692 +
8693 +.macro pax_erase_kstack
8694 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8695 + call pax_erase_kstack
8696 +#endif
8697 +.endm
8698 +
8699 /*
8700 * 32bit SYSENTER instruction entry.
8701 *
8702 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8703 CFI_REGISTER rsp,rbp
8704 SWAPGS_UNSAFE_STACK
8705 movq PER_CPU_VAR(kernel_stack), %rsp
8706 - addq $(KERNEL_STACK_OFFSET),%rsp
8707 - /*
8708 - * No need to follow this irqs on/off section: the syscall
8709 - * disabled irqs, here we enable it straight after entry:
8710 - */
8711 - ENABLE_INTERRUPTS(CLBR_NONE)
8712 movl %ebp,%ebp /* zero extension */
8713 pushq_cfi $__USER32_DS
8714 /*CFI_REL_OFFSET ss,0*/
8715 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8716 CFI_REL_OFFSET rsp,0
8717 pushfq_cfi
8718 /*CFI_REL_OFFSET rflags,0*/
8719 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8720 - CFI_REGISTER rip,r10
8721 + orl $X86_EFLAGS_IF,(%rsp)
8722 + GET_THREAD_INFO(%r11)
8723 + movl TI_sysenter_return(%r11), %r11d
8724 + CFI_REGISTER rip,r11
8725 pushq_cfi $__USER32_CS
8726 /*CFI_REL_OFFSET cs,0*/
8727 movl %eax, %eax
8728 - pushq_cfi %r10
8729 + pushq_cfi %r11
8730 CFI_REL_OFFSET rip,0
8731 pushq_cfi %rax
8732 cld
8733 SAVE_ARGS 0,1,0
8734 + pax_enter_kernel_user
8735 +
8736 +#ifdef CONFIG_PAX_RANDKSTACK
8737 + pax_erase_kstack
8738 +#endif
8739 +
8740 + /*
8741 + * No need to follow this irqs on/off section: the syscall
8742 + * disabled irqs, here we enable it straight after entry:
8743 + */
8744 + ENABLE_INTERRUPTS(CLBR_NONE)
8745 /* no need to do an access_ok check here because rbp has been
8746 32bit zero extended */
8747 +
8748 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8749 + mov $PAX_USER_SHADOW_BASE,%r11
8750 + add %r11,%rbp
8751 +#endif
8752 +
8753 1: movl (%rbp),%ebp
8754 _ASM_EXTABLE(1b,ia32_badarg)
8755 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8756 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8757 + GET_THREAD_INFO(%r11)
8758 + orl $TS_COMPAT,TI_status(%r11)
8759 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8760 CFI_REMEMBER_STATE
8761 jnz sysenter_tracesys
8762 cmpq $(IA32_NR_syscalls-1),%rax
8763 @@ -159,12 +201,15 @@ sysenter_do_call:
8764 sysenter_dispatch:
8765 call *ia32_sys_call_table(,%rax,8)
8766 movq %rax,RAX-ARGOFFSET(%rsp)
8767 + GET_THREAD_INFO(%r11)
8768 DISABLE_INTERRUPTS(CLBR_NONE)
8769 TRACE_IRQS_OFF
8770 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8771 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8772 jnz sysexit_audit
8773 sysexit_from_sys_call:
8774 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8775 + pax_exit_kernel_user
8776 + pax_erase_kstack
8777 + andl $~TS_COMPAT,TI_status(%r11)
8778 /* clear IF, that popfq doesn't enable interrupts early */
8779 andl $~0x200,EFLAGS-R11(%rsp)
8780 movl RIP-R11(%rsp),%edx /* User %eip */
8781 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8782 movl %eax,%esi /* 2nd arg: syscall number */
8783 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8784 call __audit_syscall_entry
8785 +
8786 + pax_erase_kstack
8787 +
8788 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8789 cmpq $(IA32_NR_syscalls-1),%rax
8790 ja ia32_badsys
8791 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8792 .endm
8793
8794 .macro auditsys_exit exit
8795 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8796 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8797 jnz ia32_ret_from_sys_call
8798 TRACE_IRQS_ON
8799 sti
8800 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8801 1: setbe %al /* 1 if error, 0 if not */
8802 movzbl %al,%edi /* zero-extend that into %edi */
8803 call __audit_syscall_exit
8804 + GET_THREAD_INFO(%r11)
8805 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8806 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8807 cli
8808 TRACE_IRQS_OFF
8809 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8810 + testl %edi,TI_flags(%r11)
8811 jz \exit
8812 CLEAR_RREGS -ARGOFFSET
8813 jmp int_with_check
8814 @@ -234,7 +283,7 @@ sysexit_audit:
8815
8816 sysenter_tracesys:
8817 #ifdef CONFIG_AUDITSYSCALL
8818 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8819 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8820 jz sysenter_auditsys
8821 #endif
8822 SAVE_REST
8823 @@ -246,6 +295,9 @@ sysenter_tracesys:
8824 RESTORE_REST
8825 cmpq $(IA32_NR_syscalls-1),%rax
8826 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8827 +
8828 + pax_erase_kstack
8829 +
8830 jmp sysenter_do_call
8831 CFI_ENDPROC
8832 ENDPROC(ia32_sysenter_target)
8833 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8834 ENTRY(ia32_cstar_target)
8835 CFI_STARTPROC32 simple
8836 CFI_SIGNAL_FRAME
8837 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8838 + CFI_DEF_CFA rsp,0
8839 CFI_REGISTER rip,rcx
8840 /*CFI_REGISTER rflags,r11*/
8841 SWAPGS_UNSAFE_STACK
8842 movl %esp,%r8d
8843 CFI_REGISTER rsp,r8
8844 movq PER_CPU_VAR(kernel_stack),%rsp
8845 + SAVE_ARGS 8*6,0,0
8846 + pax_enter_kernel_user
8847 +
8848 +#ifdef CONFIG_PAX_RANDKSTACK
8849 + pax_erase_kstack
8850 +#endif
8851 +
8852 /*
8853 * No need to follow this irqs on/off section: the syscall
8854 * disabled irqs and here we enable it straight after entry:
8855 */
8856 ENABLE_INTERRUPTS(CLBR_NONE)
8857 - SAVE_ARGS 8,0,0
8858 movl %eax,%eax /* zero extension */
8859 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8860 movq %rcx,RIP-ARGOFFSET(%rsp)
8861 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8862 /* no need to do an access_ok check here because r8 has been
8863 32bit zero extended */
8864 /* hardware stack frame is complete now */
8865 +
8866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8867 + mov $PAX_USER_SHADOW_BASE,%r11
8868 + add %r11,%r8
8869 +#endif
8870 +
8871 1: movl (%r8),%r9d
8872 _ASM_EXTABLE(1b,ia32_badarg)
8873 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8874 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8875 + GET_THREAD_INFO(%r11)
8876 + orl $TS_COMPAT,TI_status(%r11)
8877 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8878 CFI_REMEMBER_STATE
8879 jnz cstar_tracesys
8880 cmpq $IA32_NR_syscalls-1,%rax
8881 @@ -314,12 +379,15 @@ cstar_do_call:
8882 cstar_dispatch:
8883 call *ia32_sys_call_table(,%rax,8)
8884 movq %rax,RAX-ARGOFFSET(%rsp)
8885 + GET_THREAD_INFO(%r11)
8886 DISABLE_INTERRUPTS(CLBR_NONE)
8887 TRACE_IRQS_OFF
8888 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8889 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8890 jnz sysretl_audit
8891 sysretl_from_sys_call:
8892 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8893 + pax_exit_kernel_user
8894 + pax_erase_kstack
8895 + andl $~TS_COMPAT,TI_status(%r11)
8896 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8897 movl RIP-ARGOFFSET(%rsp),%ecx
8898 CFI_REGISTER rip,rcx
8899 @@ -347,7 +415,7 @@ sysretl_audit:
8900
8901 cstar_tracesys:
8902 #ifdef CONFIG_AUDITSYSCALL
8903 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8904 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8905 jz cstar_auditsys
8906 #endif
8907 xchgl %r9d,%ebp
8908 @@ -361,6 +429,9 @@ cstar_tracesys:
8909 xchgl %ebp,%r9d
8910 cmpq $(IA32_NR_syscalls-1),%rax
8911 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8912 +
8913 + pax_erase_kstack
8914 +
8915 jmp cstar_do_call
8916 END(ia32_cstar_target)
8917
8918 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8919 CFI_REL_OFFSET rip,RIP-RIP
8920 PARAVIRT_ADJUST_EXCEPTION_FRAME
8921 SWAPGS
8922 - /*
8923 - * No need to follow this irqs on/off section: the syscall
8924 - * disabled irqs and here we enable it straight after entry:
8925 - */
8926 - ENABLE_INTERRUPTS(CLBR_NONE)
8927 movl %eax,%eax
8928 pushq_cfi %rax
8929 cld
8930 /* note the registers are not zero extended to the sf.
8931 this could be a problem. */
8932 SAVE_ARGS 0,1,0
8933 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8934 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8935 + pax_enter_kernel_user
8936 +
8937 +#ifdef CONFIG_PAX_RANDKSTACK
8938 + pax_erase_kstack
8939 +#endif
8940 +
8941 + /*
8942 + * No need to follow this irqs on/off section: the syscall
8943 + * disabled irqs and here we enable it straight after entry:
8944 + */
8945 + ENABLE_INTERRUPTS(CLBR_NONE)
8946 + GET_THREAD_INFO(%r11)
8947 + orl $TS_COMPAT,TI_status(%r11)
8948 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8949 jnz ia32_tracesys
8950 cmpq $(IA32_NR_syscalls-1),%rax
8951 ja ia32_badsys
8952 @@ -436,6 +514,9 @@ ia32_tracesys:
8953 RESTORE_REST
8954 cmpq $(IA32_NR_syscalls-1),%rax
8955 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8956 +
8957 + pax_erase_kstack
8958 +
8959 jmp ia32_do_call
8960 END(ia32_syscall)
8961
8962 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8963 index 4540bec..714d913 100644
8964 --- a/arch/x86/ia32/sys_ia32.c
8965 +++ b/arch/x86/ia32/sys_ia32.c
8966 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8967 */
8968 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8969 {
8970 - typeof(ubuf->st_uid) uid = 0;
8971 - typeof(ubuf->st_gid) gid = 0;
8972 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8973 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8974 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8975 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8976 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8977 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8978 return ret;
8979 }
8980
8981 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8982 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8983 int options)
8984 {
8985 return compat_sys_wait4(pid, stat_addr, options, NULL);
8986 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8987 mm_segment_t old_fs = get_fs();
8988
8989 set_fs(KERNEL_DS);
8990 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8991 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8992 set_fs(old_fs);
8993 if (put_compat_timespec(&t, interval))
8994 return -EFAULT;
8995 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8996 mm_segment_t old_fs = get_fs();
8997
8998 set_fs(KERNEL_DS);
8999 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
9000 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
9001 set_fs(old_fs);
9002 if (!ret) {
9003 switch (_NSIG_WORDS) {
9004 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
9005 if (copy_siginfo_from_user32(&info, uinfo))
9006 return -EFAULT;
9007 set_fs(KERNEL_DS);
9008 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9009 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9010 set_fs(old_fs);
9011 return ret;
9012 }
9013 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9014 return -EFAULT;
9015
9016 set_fs(KERNEL_DS);
9017 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9018 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9019 count);
9020 set_fs(old_fs);
9021
9022 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9023 index 952bd01..7692c6f 100644
9024 --- a/arch/x86/include/asm/alternative-asm.h
9025 +++ b/arch/x86/include/asm/alternative-asm.h
9026 @@ -15,6 +15,45 @@
9027 .endm
9028 #endif
9029
9030 +#ifdef KERNEXEC_PLUGIN
9031 + .macro pax_force_retaddr_bts rip=0
9032 + btsq $63,\rip(%rsp)
9033 + .endm
9034 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9035 + .macro pax_force_retaddr rip=0, reload=0
9036 + btsq $63,\rip(%rsp)
9037 + .endm
9038 + .macro pax_force_fptr ptr
9039 + btsq $63,\ptr
9040 + .endm
9041 + .macro pax_set_fptr_mask
9042 + .endm
9043 +#endif
9044 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9045 + .macro pax_force_retaddr rip=0, reload=0
9046 + .if \reload
9047 + pax_set_fptr_mask
9048 + .endif
9049 + orq %r10,\rip(%rsp)
9050 + .endm
9051 + .macro pax_force_fptr ptr
9052 + orq %r10,\ptr
9053 + .endm
9054 + .macro pax_set_fptr_mask
9055 + movabs $0x8000000000000000,%r10
9056 + .endm
9057 +#endif
9058 +#else
9059 + .macro pax_force_retaddr rip=0, reload=0
9060 + .endm
9061 + .macro pax_force_fptr ptr
9062 + .endm
9063 + .macro pax_force_retaddr_bts rip=0
9064 + .endm
9065 + .macro pax_set_fptr_mask
9066 + .endm
9067 +#endif
9068 +
9069 .macro altinstruction_entry orig alt feature orig_len alt_len
9070 .long \orig - .
9071 .long \alt - .
9072 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9073 index 7078068..f58bcda 100644
9074 --- a/arch/x86/include/asm/alternative.h
9075 +++ b/arch/x86/include/asm/alternative.h
9076 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9077 ".section .discard,\"aw\",@progbits\n" \
9078 DISCARD_ENTRY(1) \
9079 ".previous\n" \
9080 - ".section .altinstr_replacement, \"ax\"\n" \
9081 + ".section .altinstr_replacement, \"a\"\n" \
9082 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
9083 ".previous"
9084
9085 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9086 DISCARD_ENTRY(1) \
9087 DISCARD_ENTRY(2) \
9088 ".previous\n" \
9089 - ".section .altinstr_replacement, \"ax\"\n" \
9090 + ".section .altinstr_replacement, \"a\"\n" \
9091 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
9092 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
9093 ".previous"
9094 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9095 index f342612..b3fe911 100644
9096 --- a/arch/x86/include/asm/apic.h
9097 +++ b/arch/x86/include/asm/apic.h
9098 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9099
9100 #ifdef CONFIG_X86_LOCAL_APIC
9101
9102 -extern unsigned int apic_verbosity;
9103 +extern int apic_verbosity;
9104 extern int local_apic_timer_c2_ok;
9105
9106 extern int disable_apic;
9107 @@ -391,7 +391,7 @@ struct apic {
9108 */
9109 int (*x86_32_numa_cpu_node)(int cpu);
9110 #endif
9111 -};
9112 +} __do_const;
9113
9114 /*
9115 * Pointer to the local APIC driver in use on this system (there's
9116 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9117 index 20370c6..a2eb9b0 100644
9118 --- a/arch/x86/include/asm/apm.h
9119 +++ b/arch/x86/include/asm/apm.h
9120 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_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 %%al\n\t"
9127 "popl %%ebp\n\t"
9128 "popl %%edi\n\t"
9129 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9130 __asm__ __volatile__(APM_DO_ZERO_SEGS
9131 "pushl %%edi\n\t"
9132 "pushl %%ebp\n\t"
9133 - "lcall *%%cs:apm_bios_entry\n\t"
9134 + "lcall *%%ss:apm_bios_entry\n\t"
9135 "setc %%bl\n\t"
9136 "popl %%ebp\n\t"
9137 "popl %%edi\n\t"
9138 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9139 index 58cb6d4..a4b806c 100644
9140 --- a/arch/x86/include/asm/atomic.h
9141 +++ b/arch/x86/include/asm/atomic.h
9142 @@ -22,7 +22,18 @@
9143 */
9144 static inline int atomic_read(const atomic_t *v)
9145 {
9146 - return (*(volatile int *)&(v)->counter);
9147 + return (*(volatile const int *)&(v)->counter);
9148 +}
9149 +
9150 +/**
9151 + * atomic_read_unchecked - read atomic variable
9152 + * @v: pointer of type atomic_unchecked_t
9153 + *
9154 + * Atomically reads the value of @v.
9155 + */
9156 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9157 +{
9158 + return (*(volatile const int *)&(v)->counter);
9159 }
9160
9161 /**
9162 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9163 }
9164
9165 /**
9166 + * atomic_set_unchecked - set atomic variable
9167 + * @v: pointer of type atomic_unchecked_t
9168 + * @i: required value
9169 + *
9170 + * Atomically sets the value of @v to @i.
9171 + */
9172 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9173 +{
9174 + v->counter = i;
9175 +}
9176 +
9177 +/**
9178 * atomic_add - add integer to atomic variable
9179 * @i: integer value to add
9180 * @v: pointer of type atomic_t
9181 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9182 */
9183 static inline void atomic_add(int i, atomic_t *v)
9184 {
9185 - asm volatile(LOCK_PREFIX "addl %1,%0"
9186 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9187 +
9188 +#ifdef CONFIG_PAX_REFCOUNT
9189 + "jno 0f\n"
9190 + LOCK_PREFIX "subl %1,%0\n"
9191 + "int $4\n0:\n"
9192 + _ASM_EXTABLE(0b, 0b)
9193 +#endif
9194 +
9195 + : "+m" (v->counter)
9196 + : "ir" (i));
9197 +}
9198 +
9199 +/**
9200 + * atomic_add_unchecked - add integer to atomic variable
9201 + * @i: integer value to add
9202 + * @v: pointer of type atomic_unchecked_t
9203 + *
9204 + * Atomically adds @i to @v.
9205 + */
9206 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9207 +{
9208 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9209 : "+m" (v->counter)
9210 : "ir" (i));
9211 }
9212 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9213 */
9214 static inline void atomic_sub(int i, atomic_t *v)
9215 {
9216 - asm volatile(LOCK_PREFIX "subl %1,%0"
9217 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9218 +
9219 +#ifdef CONFIG_PAX_REFCOUNT
9220 + "jno 0f\n"
9221 + LOCK_PREFIX "addl %1,%0\n"
9222 + "int $4\n0:\n"
9223 + _ASM_EXTABLE(0b, 0b)
9224 +#endif
9225 +
9226 + : "+m" (v->counter)
9227 + : "ir" (i));
9228 +}
9229 +
9230 +/**
9231 + * atomic_sub_unchecked - subtract integer from atomic variable
9232 + * @i: integer value to subtract
9233 + * @v: pointer of type atomic_unchecked_t
9234 + *
9235 + * Atomically subtracts @i from @v.
9236 + */
9237 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9238 +{
9239 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9240 : "+m" (v->counter)
9241 : "ir" (i));
9242 }
9243 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9244 {
9245 unsigned char c;
9246
9247 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9248 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9249 +
9250 +#ifdef CONFIG_PAX_REFCOUNT
9251 + "jno 0f\n"
9252 + LOCK_PREFIX "addl %2,%0\n"
9253 + "int $4\n0:\n"
9254 + _ASM_EXTABLE(0b, 0b)
9255 +#endif
9256 +
9257 + "sete %1\n"
9258 : "+m" (v->counter), "=qm" (c)
9259 : "ir" (i) : "memory");
9260 return c;
9261 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9262 */
9263 static inline void atomic_inc(atomic_t *v)
9264 {
9265 - asm volatile(LOCK_PREFIX "incl %0"
9266 + asm volatile(LOCK_PREFIX "incl %0\n"
9267 +
9268 +#ifdef CONFIG_PAX_REFCOUNT
9269 + "jno 0f\n"
9270 + LOCK_PREFIX "decl %0\n"
9271 + "int $4\n0:\n"
9272 + _ASM_EXTABLE(0b, 0b)
9273 +#endif
9274 +
9275 + : "+m" (v->counter));
9276 +}
9277 +
9278 +/**
9279 + * atomic_inc_unchecked - increment atomic variable
9280 + * @v: pointer of type atomic_unchecked_t
9281 + *
9282 + * Atomically increments @v by 1.
9283 + */
9284 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9285 +{
9286 + asm volatile(LOCK_PREFIX "incl %0\n"
9287 : "+m" (v->counter));
9288 }
9289
9290 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9291 */
9292 static inline void atomic_dec(atomic_t *v)
9293 {
9294 - asm volatile(LOCK_PREFIX "decl %0"
9295 + asm volatile(LOCK_PREFIX "decl %0\n"
9296 +
9297 +#ifdef CONFIG_PAX_REFCOUNT
9298 + "jno 0f\n"
9299 + LOCK_PREFIX "incl %0\n"
9300 + "int $4\n0:\n"
9301 + _ASM_EXTABLE(0b, 0b)
9302 +#endif
9303 +
9304 + : "+m" (v->counter));
9305 +}
9306 +
9307 +/**
9308 + * atomic_dec_unchecked - decrement atomic variable
9309 + * @v: pointer of type atomic_unchecked_t
9310 + *
9311 + * Atomically decrements @v by 1.
9312 + */
9313 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9314 +{
9315 + asm volatile(LOCK_PREFIX "decl %0\n"
9316 : "+m" (v->counter));
9317 }
9318
9319 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9320 {
9321 unsigned char c;
9322
9323 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9324 + asm volatile(LOCK_PREFIX "decl %0\n"
9325 +
9326 +#ifdef CONFIG_PAX_REFCOUNT
9327 + "jno 0f\n"
9328 + LOCK_PREFIX "incl %0\n"
9329 + "int $4\n0:\n"
9330 + _ASM_EXTABLE(0b, 0b)
9331 +#endif
9332 +
9333 + "sete %1\n"
9334 : "+m" (v->counter), "=qm" (c)
9335 : : "memory");
9336 return c != 0;
9337 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9338 {
9339 unsigned char c;
9340
9341 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9342 + asm volatile(LOCK_PREFIX "incl %0\n"
9343 +
9344 +#ifdef CONFIG_PAX_REFCOUNT
9345 + "jno 0f\n"
9346 + LOCK_PREFIX "decl %0\n"
9347 + "int $4\n0:\n"
9348 + _ASM_EXTABLE(0b, 0b)
9349 +#endif
9350 +
9351 + "sete %1\n"
9352 + : "+m" (v->counter), "=qm" (c)
9353 + : : "memory");
9354 + return c != 0;
9355 +}
9356 +
9357 +/**
9358 + * atomic_inc_and_test_unchecked - increment and test
9359 + * @v: pointer of type atomic_unchecked_t
9360 + *
9361 + * Atomically increments @v by 1
9362 + * and returns true if the result is zero, or false for all
9363 + * other cases.
9364 + */
9365 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9366 +{
9367 + unsigned char c;
9368 +
9369 + asm volatile(LOCK_PREFIX "incl %0\n"
9370 + "sete %1\n"
9371 : "+m" (v->counter), "=qm" (c)
9372 : : "memory");
9373 return c != 0;
9374 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9375 {
9376 unsigned char c;
9377
9378 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9379 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9380 +
9381 +#ifdef CONFIG_PAX_REFCOUNT
9382 + "jno 0f\n"
9383 + LOCK_PREFIX "subl %2,%0\n"
9384 + "int $4\n0:\n"
9385 + _ASM_EXTABLE(0b, 0b)
9386 +#endif
9387 +
9388 + "sets %1\n"
9389 : "+m" (v->counter), "=qm" (c)
9390 : "ir" (i) : "memory");
9391 return c;
9392 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9393 goto no_xadd;
9394 #endif
9395 /* Modern 486+ processor */
9396 - return i + xadd(&v->counter, i);
9397 + return i + xadd_check_overflow(&v->counter, i);
9398
9399 #ifdef CONFIG_M386
9400 no_xadd: /* Legacy 386 processor */
9401 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9402 }
9403
9404 /**
9405 + * atomic_add_return_unchecked - add integer and return
9406 + * @i: integer value to add
9407 + * @v: pointer of type atomic_unchecked_t
9408 + *
9409 + * Atomically adds @i to @v and returns @i + @v
9410 + */
9411 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9412 +{
9413 +#ifdef CONFIG_M386
9414 + int __i;
9415 + unsigned long flags;
9416 + if (unlikely(boot_cpu_data.x86 <= 3))
9417 + goto no_xadd;
9418 +#endif
9419 + /* Modern 486+ processor */
9420 + return i + xadd(&v->counter, i);
9421 +
9422 +#ifdef CONFIG_M386
9423 +no_xadd: /* Legacy 386 processor */
9424 + raw_local_irq_save(flags);
9425 + __i = atomic_read_unchecked(v);
9426 + atomic_set_unchecked(v, i + __i);
9427 + raw_local_irq_restore(flags);
9428 + return i + __i;
9429 +#endif
9430 +}
9431 +
9432 +/**
9433 * atomic_sub_return - subtract integer and return
9434 * @v: pointer of type atomic_t
9435 * @i: integer value to subtract
9436 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9437 }
9438
9439 #define atomic_inc_return(v) (atomic_add_return(1, v))
9440 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9441 +{
9442 + return atomic_add_return_unchecked(1, v);
9443 +}
9444 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9445
9446 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9447 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9448 return cmpxchg(&v->counter, old, new);
9449 }
9450
9451 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9452 +{
9453 + return cmpxchg(&v->counter, old, new);
9454 +}
9455 +
9456 static inline int atomic_xchg(atomic_t *v, int new)
9457 {
9458 return xchg(&v->counter, new);
9459 }
9460
9461 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9462 +{
9463 + return xchg(&v->counter, new);
9464 +}
9465 +
9466 /**
9467 * __atomic_add_unless - add unless the number is already a given value
9468 * @v: pointer of type atomic_t
9469 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9470 */
9471 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9472 {
9473 - int c, old;
9474 + int c, old, new;
9475 c = atomic_read(v);
9476 for (;;) {
9477 - if (unlikely(c == (u)))
9478 + if (unlikely(c == u))
9479 break;
9480 - old = atomic_cmpxchg((v), c, c + (a));
9481 +
9482 + asm volatile("addl %2,%0\n"
9483 +
9484 +#ifdef CONFIG_PAX_REFCOUNT
9485 + "jno 0f\n"
9486 + "subl %2,%0\n"
9487 + "int $4\n0:\n"
9488 + _ASM_EXTABLE(0b, 0b)
9489 +#endif
9490 +
9491 + : "=r" (new)
9492 + : "0" (c), "ir" (a));
9493 +
9494 + old = atomic_cmpxchg(v, c, new);
9495 if (likely(old == c))
9496 break;
9497 c = old;
9498 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9499 return c;
9500 }
9501
9502 +/**
9503 + * atomic_inc_not_zero_hint - increment if not null
9504 + * @v: pointer of type atomic_t
9505 + * @hint: probable value of the atomic before the increment
9506 + *
9507 + * This version of atomic_inc_not_zero() gives a hint of probable
9508 + * value of the atomic. This helps processor to not read the memory
9509 + * before doing the atomic read/modify/write cycle, lowering
9510 + * number of bus transactions on some arches.
9511 + *
9512 + * Returns: 0 if increment was not done, 1 otherwise.
9513 + */
9514 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9515 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9516 +{
9517 + int val, c = hint, new;
9518 +
9519 + /* sanity test, should be removed by compiler if hint is a constant */
9520 + if (!hint)
9521 + return __atomic_add_unless(v, 1, 0);
9522 +
9523 + do {
9524 + asm volatile("incl %0\n"
9525 +
9526 +#ifdef CONFIG_PAX_REFCOUNT
9527 + "jno 0f\n"
9528 + "decl %0\n"
9529 + "int $4\n0:\n"
9530 + _ASM_EXTABLE(0b, 0b)
9531 +#endif
9532 +
9533 + : "=r" (new)
9534 + : "0" (c));
9535 +
9536 + val = atomic_cmpxchg(v, c, new);
9537 + if (val == c)
9538 + return 1;
9539 + c = val;
9540 + } while (c);
9541 +
9542 + return 0;
9543 +}
9544
9545 /*
9546 * atomic_dec_if_positive - decrement by 1 if old value positive
9547 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9548 #endif
9549
9550 /* These are x86-specific, used by some header files */
9551 -#define atomic_clear_mask(mask, addr) \
9552 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9553 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9554 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9555 +{
9556 + asm volatile(LOCK_PREFIX "andl %1,%0"
9557 + : "+m" (v->counter)
9558 + : "r" (~(mask))
9559 + : "memory");
9560 +}
9561
9562 -#define atomic_set_mask(mask, addr) \
9563 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9564 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9565 - : "memory")
9566 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9567 +{
9568 + asm volatile(LOCK_PREFIX "andl %1,%0"
9569 + : "+m" (v->counter)
9570 + : "r" (~(mask))
9571 + : "memory");
9572 +}
9573 +
9574 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9575 +{
9576 + asm volatile(LOCK_PREFIX "orl %1,%0"
9577 + : "+m" (v->counter)
9578 + : "r" (mask)
9579 + : "memory");
9580 +}
9581 +
9582 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9583 +{
9584 + asm volatile(LOCK_PREFIX "orl %1,%0"
9585 + : "+m" (v->counter)
9586 + : "r" (mask)
9587 + : "memory");
9588 +}
9589
9590 /* Atomic operations are already serializing on x86 */
9591 #define smp_mb__before_atomic_dec() barrier()
9592 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9593 index b154de7..aadebd8 100644
9594 --- a/arch/x86/include/asm/atomic64_32.h
9595 +++ b/arch/x86/include/asm/atomic64_32.h
9596 @@ -12,6 +12,14 @@ typedef struct {
9597 u64 __aligned(8) counter;
9598 } atomic64_t;
9599
9600 +#ifdef CONFIG_PAX_REFCOUNT
9601 +typedef struct {
9602 + u64 __aligned(8) counter;
9603 +} atomic64_unchecked_t;
9604 +#else
9605 +typedef atomic64_t atomic64_unchecked_t;
9606 +#endif
9607 +
9608 #define ATOMIC64_INIT(val) { (val) }
9609
9610 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9611 @@ -37,21 +45,31 @@ typedef struct {
9612 ATOMIC64_DECL_ONE(sym##_386)
9613
9614 ATOMIC64_DECL_ONE(add_386);
9615 +ATOMIC64_DECL_ONE(add_unchecked_386);
9616 ATOMIC64_DECL_ONE(sub_386);
9617 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9618 ATOMIC64_DECL_ONE(inc_386);
9619 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9620 ATOMIC64_DECL_ONE(dec_386);
9621 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9622 #endif
9623
9624 #define alternative_atomic64(f, out, in...) \
9625 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9626
9627 ATOMIC64_DECL(read);
9628 +ATOMIC64_DECL(read_unchecked);
9629 ATOMIC64_DECL(set);
9630 +ATOMIC64_DECL(set_unchecked);
9631 ATOMIC64_DECL(xchg);
9632 ATOMIC64_DECL(add_return);
9633 +ATOMIC64_DECL(add_return_unchecked);
9634 ATOMIC64_DECL(sub_return);
9635 +ATOMIC64_DECL(sub_return_unchecked);
9636 ATOMIC64_DECL(inc_return);
9637 +ATOMIC64_DECL(inc_return_unchecked);
9638 ATOMIC64_DECL(dec_return);
9639 +ATOMIC64_DECL(dec_return_unchecked);
9640 ATOMIC64_DECL(dec_if_positive);
9641 ATOMIC64_DECL(inc_not_zero);
9642 ATOMIC64_DECL(add_unless);
9643 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9644 }
9645
9646 /**
9647 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9648 + * @p: pointer to type atomic64_unchecked_t
9649 + * @o: expected value
9650 + * @n: new value
9651 + *
9652 + * Atomically sets @v to @n if it was equal to @o and returns
9653 + * the old value.
9654 + */
9655 +
9656 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9657 +{
9658 + return cmpxchg64(&v->counter, o, n);
9659 +}
9660 +
9661 +/**
9662 * atomic64_xchg - xchg atomic64 variable
9663 * @v: pointer to type atomic64_t
9664 * @n: value to assign
9665 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9666 }
9667
9668 /**
9669 + * atomic64_set_unchecked - set atomic64 variable
9670 + * @v: pointer to type atomic64_unchecked_t
9671 + * @n: value to assign
9672 + *
9673 + * Atomically sets the value of @v to @n.
9674 + */
9675 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9676 +{
9677 + unsigned high = (unsigned)(i >> 32);
9678 + unsigned low = (unsigned)i;
9679 + alternative_atomic64(set, /* no output */,
9680 + "S" (v), "b" (low), "c" (high)
9681 + : "eax", "edx", "memory");
9682 +}
9683 +
9684 +/**
9685 * atomic64_read - read atomic64 variable
9686 * @v: pointer to type atomic64_t
9687 *
9688 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9689 }
9690
9691 /**
9692 + * atomic64_read_unchecked - read atomic64 variable
9693 + * @v: pointer to type atomic64_unchecked_t
9694 + *
9695 + * Atomically reads the value of @v and returns it.
9696 + */
9697 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9698 +{
9699 + long long r;
9700 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9701 + return r;
9702 + }
9703 +
9704 +/**
9705 * atomic64_add_return - add and return
9706 * @i: integer value to add
9707 * @v: pointer to type atomic64_t
9708 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9709 return i;
9710 }
9711
9712 +/**
9713 + * atomic64_add_return_unchecked - add and return
9714 + * @i: integer value to add
9715 + * @v: pointer to type atomic64_unchecked_t
9716 + *
9717 + * Atomically adds @i to @v and returns @i + *@v
9718 + */
9719 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9720 +{
9721 + alternative_atomic64(add_return_unchecked,
9722 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9723 + ASM_NO_INPUT_CLOBBER("memory"));
9724 + return i;
9725 +}
9726 +
9727 /*
9728 * Other variants with different arithmetic operators:
9729 */
9730 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9731 return a;
9732 }
9733
9734 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9735 +{
9736 + long long a;
9737 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9738 + "S" (v) : "memory", "ecx");
9739 + return a;
9740 +}
9741 +
9742 static inline long long atomic64_dec_return(atomic64_t *v)
9743 {
9744 long long a;
9745 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9746 }
9747
9748 /**
9749 + * atomic64_add_unchecked - add integer to atomic64 variable
9750 + * @i: integer value to add
9751 + * @v: pointer to type atomic64_unchecked_t
9752 + *
9753 + * Atomically adds @i to @v.
9754 + */
9755 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9756 +{
9757 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9758 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9759 + ASM_NO_INPUT_CLOBBER("memory"));
9760 + return i;
9761 +}
9762 +
9763 +/**
9764 * atomic64_sub - subtract the atomic64 variable
9765 * @i: integer value to subtract
9766 * @v: pointer to type atomic64_t
9767 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9768 index 0e1cbfc..5623683 100644
9769 --- a/arch/x86/include/asm/atomic64_64.h
9770 +++ b/arch/x86/include/asm/atomic64_64.h
9771 @@ -18,7 +18,19 @@
9772 */
9773 static inline long atomic64_read(const atomic64_t *v)
9774 {
9775 - return (*(volatile long *)&(v)->counter);
9776 + return (*(volatile const long *)&(v)->counter);
9777 +}
9778 +
9779 +/**
9780 + * atomic64_read_unchecked - read atomic64 variable
9781 + * @v: pointer of type atomic64_unchecked_t
9782 + *
9783 + * Atomically reads the value of @v.
9784 + * Doesn't imply a read memory barrier.
9785 + */
9786 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9787 +{
9788 + return (*(volatile const long *)&(v)->counter);
9789 }
9790
9791 /**
9792 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9793 }
9794
9795 /**
9796 + * atomic64_set_unchecked - set atomic64 variable
9797 + * @v: pointer to type atomic64_unchecked_t
9798 + * @i: required value
9799 + *
9800 + * Atomically sets the value of @v to @i.
9801 + */
9802 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9803 +{
9804 + v->counter = i;
9805 +}
9806 +
9807 +/**
9808 * atomic64_add - add integer to atomic64 variable
9809 * @i: integer value to add
9810 * @v: pointer to type atomic64_t
9811 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9812 */
9813 static inline void atomic64_add(long i, atomic64_t *v)
9814 {
9815 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9816 +
9817 +#ifdef CONFIG_PAX_REFCOUNT
9818 + "jno 0f\n"
9819 + LOCK_PREFIX "subq %1,%0\n"
9820 + "int $4\n0:\n"
9821 + _ASM_EXTABLE(0b, 0b)
9822 +#endif
9823 +
9824 + : "=m" (v->counter)
9825 + : "er" (i), "m" (v->counter));
9826 +}
9827 +
9828 +/**
9829 + * atomic64_add_unchecked - add integer to atomic64 variable
9830 + * @i: integer value to add
9831 + * @v: pointer to type atomic64_unchecked_t
9832 + *
9833 + * Atomically adds @i to @v.
9834 + */
9835 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9836 +{
9837 asm volatile(LOCK_PREFIX "addq %1,%0"
9838 : "=m" (v->counter)
9839 : "er" (i), "m" (v->counter));
9840 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9841 */
9842 static inline void atomic64_sub(long i, atomic64_t *v)
9843 {
9844 - asm volatile(LOCK_PREFIX "subq %1,%0"
9845 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9846 +
9847 +#ifdef CONFIG_PAX_REFCOUNT
9848 + "jno 0f\n"
9849 + LOCK_PREFIX "addq %1,%0\n"
9850 + "int $4\n0:\n"
9851 + _ASM_EXTABLE(0b, 0b)
9852 +#endif
9853 +
9854 + : "=m" (v->counter)
9855 + : "er" (i), "m" (v->counter));
9856 +}
9857 +
9858 +/**
9859 + * atomic64_sub_unchecked - subtract the atomic64 variable
9860 + * @i: integer value to subtract
9861 + * @v: pointer to type atomic64_unchecked_t
9862 + *
9863 + * Atomically subtracts @i from @v.
9864 + */
9865 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9866 +{
9867 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9868 : "=m" (v->counter)
9869 : "er" (i), "m" (v->counter));
9870 }
9871 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9872 {
9873 unsigned char c;
9874
9875 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9876 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9877 +
9878 +#ifdef CONFIG_PAX_REFCOUNT
9879 + "jno 0f\n"
9880 + LOCK_PREFIX "addq %2,%0\n"
9881 + "int $4\n0:\n"
9882 + _ASM_EXTABLE(0b, 0b)
9883 +#endif
9884 +
9885 + "sete %1\n"
9886 : "=m" (v->counter), "=qm" (c)
9887 : "er" (i), "m" (v->counter) : "memory");
9888 return c;
9889 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9890 */
9891 static inline void atomic64_inc(atomic64_t *v)
9892 {
9893 + asm volatile(LOCK_PREFIX "incq %0\n"
9894 +
9895 +#ifdef CONFIG_PAX_REFCOUNT
9896 + "jno 0f\n"
9897 + LOCK_PREFIX "decq %0\n"
9898 + "int $4\n0:\n"
9899 + _ASM_EXTABLE(0b, 0b)
9900 +#endif
9901 +
9902 + : "=m" (v->counter)
9903 + : "m" (v->counter));
9904 +}
9905 +
9906 +/**
9907 + * atomic64_inc_unchecked - increment atomic64 variable
9908 + * @v: pointer to type atomic64_unchecked_t
9909 + *
9910 + * Atomically increments @v by 1.
9911 + */
9912 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9913 +{
9914 asm volatile(LOCK_PREFIX "incq %0"
9915 : "=m" (v->counter)
9916 : "m" (v->counter));
9917 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9918 */
9919 static inline void atomic64_dec(atomic64_t *v)
9920 {
9921 - asm volatile(LOCK_PREFIX "decq %0"
9922 + asm volatile(LOCK_PREFIX "decq %0\n"
9923 +
9924 +#ifdef CONFIG_PAX_REFCOUNT
9925 + "jno 0f\n"
9926 + LOCK_PREFIX "incq %0\n"
9927 + "int $4\n0:\n"
9928 + _ASM_EXTABLE(0b, 0b)
9929 +#endif
9930 +
9931 + : "=m" (v->counter)
9932 + : "m" (v->counter));
9933 +}
9934 +
9935 +/**
9936 + * atomic64_dec_unchecked - decrement atomic64 variable
9937 + * @v: pointer to type atomic64_t
9938 + *
9939 + * Atomically decrements @v by 1.
9940 + */
9941 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9942 +{
9943 + asm volatile(LOCK_PREFIX "decq %0\n"
9944 : "=m" (v->counter)
9945 : "m" (v->counter));
9946 }
9947 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9948 {
9949 unsigned char c;
9950
9951 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9952 + asm volatile(LOCK_PREFIX "decq %0\n"
9953 +
9954 +#ifdef CONFIG_PAX_REFCOUNT
9955 + "jno 0f\n"
9956 + LOCK_PREFIX "incq %0\n"
9957 + "int $4\n0:\n"
9958 + _ASM_EXTABLE(0b, 0b)
9959 +#endif
9960 +
9961 + "sete %1\n"
9962 : "=m" (v->counter), "=qm" (c)
9963 : "m" (v->counter) : "memory");
9964 return c != 0;
9965 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9966 {
9967 unsigned char c;
9968
9969 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9970 + asm volatile(LOCK_PREFIX "incq %0\n"
9971 +
9972 +#ifdef CONFIG_PAX_REFCOUNT
9973 + "jno 0f\n"
9974 + LOCK_PREFIX "decq %0\n"
9975 + "int $4\n0:\n"
9976 + _ASM_EXTABLE(0b, 0b)
9977 +#endif
9978 +
9979 + "sete %1\n"
9980 : "=m" (v->counter), "=qm" (c)
9981 : "m" (v->counter) : "memory");
9982 return c != 0;
9983 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9984 {
9985 unsigned char c;
9986
9987 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9988 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9989 +
9990 +#ifdef CONFIG_PAX_REFCOUNT
9991 + "jno 0f\n"
9992 + LOCK_PREFIX "subq %2,%0\n"
9993 + "int $4\n0:\n"
9994 + _ASM_EXTABLE(0b, 0b)
9995 +#endif
9996 +
9997 + "sets %1\n"
9998 : "=m" (v->counter), "=qm" (c)
9999 : "er" (i), "m" (v->counter) : "memory");
10000 return c;
10001 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
10002 */
10003 static inline long atomic64_add_return(long i, atomic64_t *v)
10004 {
10005 + return i + xadd_check_overflow(&v->counter, i);
10006 +}
10007 +
10008 +/**
10009 + * atomic64_add_return_unchecked - add and return
10010 + * @i: integer value to add
10011 + * @v: pointer to type atomic64_unchecked_t
10012 + *
10013 + * Atomically adds @i to @v and returns @i + @v
10014 + */
10015 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10016 +{
10017 return i + xadd(&v->counter, i);
10018 }
10019
10020 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10021 }
10022
10023 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10024 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10025 +{
10026 + return atomic64_add_return_unchecked(1, v);
10027 +}
10028 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10029
10030 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10031 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10032 return cmpxchg(&v->counter, old, new);
10033 }
10034
10035 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10036 +{
10037 + return cmpxchg(&v->counter, old, new);
10038 +}
10039 +
10040 static inline long atomic64_xchg(atomic64_t *v, long new)
10041 {
10042 return xchg(&v->counter, new);
10043 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10044 */
10045 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10046 {
10047 - long c, old;
10048 + long c, old, new;
10049 c = atomic64_read(v);
10050 for (;;) {
10051 - if (unlikely(c == (u)))
10052 + if (unlikely(c == u))
10053 break;
10054 - old = atomic64_cmpxchg((v), c, c + (a));
10055 +
10056 + asm volatile("add %2,%0\n"
10057 +
10058 +#ifdef CONFIG_PAX_REFCOUNT
10059 + "jno 0f\n"
10060 + "sub %2,%0\n"
10061 + "int $4\n0:\n"
10062 + _ASM_EXTABLE(0b, 0b)
10063 +#endif
10064 +
10065 + : "=r" (new)
10066 + : "0" (c), "ir" (a));
10067 +
10068 + old = atomic64_cmpxchg(v, c, new);
10069 if (likely(old == c))
10070 break;
10071 c = old;
10072 }
10073 - return c != (u);
10074 + return c != u;
10075 }
10076
10077 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10078 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10079 index 72f5009..2f8b9a9 100644
10080 --- a/arch/x86/include/asm/bitops.h
10081 +++ b/arch/x86/include/asm/bitops.h
10082 @@ -40,7 +40,7 @@
10083 * a mask operation on a byte.
10084 */
10085 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10086 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10087 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10088 #define CONST_MASK(nr) (1 << ((nr) & 7))
10089
10090 /**
10091 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10092 index b13fe63..0dab13a 100644
10093 --- a/arch/x86/include/asm/boot.h
10094 +++ b/arch/x86/include/asm/boot.h
10095 @@ -11,10 +11,15 @@
10096 #include <asm/pgtable_types.h>
10097
10098 /* Physical address where kernel should be loaded. */
10099 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10100 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10101 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10102 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10103
10104 +#ifndef __ASSEMBLY__
10105 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10106 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10107 +#endif
10108 +
10109 /* Minimum kernel alignment, as a power of two */
10110 #ifdef CONFIG_X86_64
10111 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10112 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10113 index 48f99f1..d78ebf9 100644
10114 --- a/arch/x86/include/asm/cache.h
10115 +++ b/arch/x86/include/asm/cache.h
10116 @@ -5,12 +5,13 @@
10117
10118 /* L1 cache line size */
10119 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10120 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10121 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10122
10123 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10124 +#define __read_only __attribute__((__section__(".data..read_only")))
10125
10126 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10127 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10128 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10129
10130 #ifdef CONFIG_X86_VSMP
10131 #ifdef CONFIG_SMP
10132 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10133 index 9863ee3..4a1f8e1 100644
10134 --- a/arch/x86/include/asm/cacheflush.h
10135 +++ b/arch/x86/include/asm/cacheflush.h
10136 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10137 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10138
10139 if (pg_flags == _PGMT_DEFAULT)
10140 - return -1;
10141 + return ~0UL;
10142 else if (pg_flags == _PGMT_WC)
10143 return _PAGE_CACHE_WC;
10144 else if (pg_flags == _PGMT_UC_MINUS)
10145 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10146 index 46fc474..b02b0f9 100644
10147 --- a/arch/x86/include/asm/checksum_32.h
10148 +++ b/arch/x86/include/asm/checksum_32.h
10149 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10150 int len, __wsum sum,
10151 int *src_err_ptr, int *dst_err_ptr);
10152
10153 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10154 + int len, __wsum sum,
10155 + int *src_err_ptr, int *dst_err_ptr);
10156 +
10157 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10158 + int len, __wsum sum,
10159 + int *src_err_ptr, int *dst_err_ptr);
10160 +
10161 /*
10162 * Note: when you get a NULL pointer exception here this means someone
10163 * passed in an incorrect kernel address to one of these functions.
10164 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10165 int *err_ptr)
10166 {
10167 might_sleep();
10168 - return csum_partial_copy_generic((__force void *)src, dst,
10169 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10170 len, sum, err_ptr, NULL);
10171 }
10172
10173 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10174 {
10175 might_sleep();
10176 if (access_ok(VERIFY_WRITE, dst, len))
10177 - return csum_partial_copy_generic(src, (__force void *)dst,
10178 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10179 len, sum, NULL, err_ptr);
10180
10181 if (len)
10182 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10183 index 99480e5..d81165b 100644
10184 --- a/arch/x86/include/asm/cmpxchg.h
10185 +++ b/arch/x86/include/asm/cmpxchg.h
10186 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10187 __compiletime_error("Bad argument size for cmpxchg");
10188 extern void __xadd_wrong_size(void)
10189 __compiletime_error("Bad argument size for xadd");
10190 +extern void __xadd_check_overflow_wrong_size(void)
10191 + __compiletime_error("Bad argument size for xadd_check_overflow");
10192 extern void __add_wrong_size(void)
10193 __compiletime_error("Bad argument size for add");
10194 +extern void __add_check_overflow_wrong_size(void)
10195 + __compiletime_error("Bad argument size for add_check_overflow");
10196
10197 /*
10198 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10199 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10200 __ret; \
10201 })
10202
10203 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10204 + ({ \
10205 + __typeof__ (*(ptr)) __ret = (arg); \
10206 + switch (sizeof(*(ptr))) { \
10207 + case __X86_CASE_L: \
10208 + asm volatile (lock #op "l %0, %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 + case __X86_CASE_Q: \
10217 + asm volatile (lock #op "q %q0, %1\n" \
10218 + "jno 0f\n" \
10219 + "mov %0,%1\n" \
10220 + "int $4\n0:\n" \
10221 + _ASM_EXTABLE(0b, 0b) \
10222 + : "+r" (__ret), "+m" (*(ptr)) \
10223 + : : "memory", "cc"); \
10224 + break; \
10225 + default: \
10226 + __ ## op ## _check_overflow_wrong_size(); \
10227 + } \
10228 + __ret; \
10229 + })
10230 +
10231 /*
10232 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10233 * Since this is generally used to protect other memory information, we
10234 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10235 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10236 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10237
10238 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10239 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10240 +
10241 #define __add(ptr, inc, lock) \
10242 ({ \
10243 __typeof__ (*(ptr)) __ret = (inc); \
10244 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10245 index 6b7ee5f..9d664b3 100644
10246 --- a/arch/x86/include/asm/cpufeature.h
10247 +++ b/arch/x86/include/asm/cpufeature.h
10248 @@ -202,13 +202,14 @@
10249 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10250 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10251 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10252 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10253 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10254 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10255 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10256 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10257 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10258 #define X86_FEATURE_RDSEED (9*32+18) /* The RDSEED instruction */
10259 #define X86_FEATURE_ADX (9*32+19) /* The ADCX and ADOX instructions */
10260 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10261
10262 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10263
10264 @@ -373,7 +374,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10265 ".section .discard,\"aw\",@progbits\n"
10266 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10267 ".previous\n"
10268 - ".section .altinstr_replacement,\"ax\"\n"
10269 + ".section .altinstr_replacement,\"a\"\n"
10270 "3: movb $1,%0\n"
10271 "4:\n"
10272 ".previous\n"
10273 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10274 index 8bf1c06..f723dfd 100644
10275 --- a/arch/x86/include/asm/desc.h
10276 +++ b/arch/x86/include/asm/desc.h
10277 @@ -4,6 +4,7 @@
10278 #include <asm/desc_defs.h>
10279 #include <asm/ldt.h>
10280 #include <asm/mmu.h>
10281 +#include <asm/pgtable.h>
10282
10283 #include <linux/smp.h>
10284 #include <linux/percpu.h>
10285 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10286
10287 desc->type = (info->read_exec_only ^ 1) << 1;
10288 desc->type |= info->contents << 2;
10289 + desc->type |= info->seg_not_present ^ 1;
10290
10291 desc->s = 1;
10292 desc->dpl = 0x3;
10293 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10294 }
10295
10296 extern struct desc_ptr idt_descr;
10297 -extern gate_desc idt_table[];
10298 extern struct desc_ptr nmi_idt_descr;
10299 -extern gate_desc nmi_idt_table[];
10300 -
10301 -struct gdt_page {
10302 - struct desc_struct gdt[GDT_ENTRIES];
10303 -} __attribute__((aligned(PAGE_SIZE)));
10304 -
10305 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10306 +extern gate_desc idt_table[256];
10307 +extern gate_desc nmi_idt_table[256];
10308
10309 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10310 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10311 {
10312 - return per_cpu(gdt_page, cpu).gdt;
10313 + return cpu_gdt_table[cpu];
10314 }
10315
10316 #ifdef CONFIG_X86_64
10317 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10318 unsigned long base, unsigned dpl, unsigned flags,
10319 unsigned short seg)
10320 {
10321 - gate->a = (seg << 16) | (base & 0xffff);
10322 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10323 + gate->gate.offset_low = base;
10324 + gate->gate.seg = seg;
10325 + gate->gate.reserved = 0;
10326 + gate->gate.type = type;
10327 + gate->gate.s = 0;
10328 + gate->gate.dpl = dpl;
10329 + gate->gate.p = 1;
10330 + gate->gate.offset_high = base >> 16;
10331 }
10332
10333 #endif
10334 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10335
10336 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10337 {
10338 + pax_open_kernel();
10339 memcpy(&idt[entry], gate, sizeof(*gate));
10340 + pax_close_kernel();
10341 }
10342
10343 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10344 {
10345 + pax_open_kernel();
10346 memcpy(&ldt[entry], desc, 8);
10347 + pax_close_kernel();
10348 }
10349
10350 static inline void
10351 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10352 default: size = sizeof(*gdt); break;
10353 }
10354
10355 + pax_open_kernel();
10356 memcpy(&gdt[entry], desc, size);
10357 + pax_close_kernel();
10358 }
10359
10360 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10361 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10362
10363 static inline void native_load_tr_desc(void)
10364 {
10365 + pax_open_kernel();
10366 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10367 + pax_close_kernel();
10368 }
10369
10370 static inline void native_load_gdt(const struct desc_ptr *dtr)
10371 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10372 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10373 unsigned int i;
10374
10375 + pax_open_kernel();
10376 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10377 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10378 + pax_close_kernel();
10379 }
10380
10381 #define _LDT_empty(info) \
10382 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10383 }
10384
10385 #ifdef CONFIG_X86_64
10386 -static inline void set_nmi_gate(int gate, void *addr)
10387 +static inline void set_nmi_gate(int gate, const void *addr)
10388 {
10389 gate_desc s;
10390
10391 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10392 }
10393 #endif
10394
10395 -static inline void _set_gate(int gate, unsigned type, void *addr,
10396 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10397 unsigned dpl, unsigned ist, unsigned seg)
10398 {
10399 gate_desc s;
10400 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10401 * Pentium F0 0F bugfix can have resulted in the mapped
10402 * IDT being write-protected.
10403 */
10404 -static inline void set_intr_gate(unsigned int n, void *addr)
10405 +static inline void set_intr_gate(unsigned int n, const void *addr)
10406 {
10407 BUG_ON((unsigned)n > 0xFF);
10408 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10409 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10410 /*
10411 * This routine sets up an interrupt gate at directory privilege level 3.
10412 */
10413 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10414 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10415 {
10416 BUG_ON((unsigned)n > 0xFF);
10417 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10418 }
10419
10420 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10421 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10422 {
10423 BUG_ON((unsigned)n > 0xFF);
10424 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10425 }
10426
10427 -static inline void set_trap_gate(unsigned int n, void *addr)
10428 +static inline void set_trap_gate(unsigned int n, const void *addr)
10429 {
10430 BUG_ON((unsigned)n > 0xFF);
10431 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10432 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10433 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10434 {
10435 BUG_ON((unsigned)n > 0xFF);
10436 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10437 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10438 }
10439
10440 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10441 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10442 {
10443 BUG_ON((unsigned)n > 0xFF);
10444 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10445 }
10446
10447 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10448 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10449 {
10450 BUG_ON((unsigned)n > 0xFF);
10451 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10452 }
10453
10454 +#ifdef CONFIG_X86_32
10455 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10456 +{
10457 + struct desc_struct d;
10458 +
10459 + if (likely(limit))
10460 + limit = (limit - 1UL) >> PAGE_SHIFT;
10461 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10462 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10463 +}
10464 +#endif
10465 +
10466 #endif /* _ASM_X86_DESC_H */
10467 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10468 index 278441f..b95a174 100644
10469 --- a/arch/x86/include/asm/desc_defs.h
10470 +++ b/arch/x86/include/asm/desc_defs.h
10471 @@ -31,6 +31,12 @@ struct desc_struct {
10472 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10473 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10474 };
10475 + struct {
10476 + u16 offset_low;
10477 + u16 seg;
10478 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10479 + unsigned offset_high: 16;
10480 + } gate;
10481 };
10482 } __attribute__((packed));
10483
10484 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10485 index 3778256..c5d4fce 100644
10486 --- a/arch/x86/include/asm/e820.h
10487 +++ b/arch/x86/include/asm/e820.h
10488 @@ -69,7 +69,7 @@ struct e820map {
10489 #define ISA_START_ADDRESS 0xa0000
10490 #define ISA_END_ADDRESS 0x100000
10491
10492 -#define BIOS_BEGIN 0x000a0000
10493 +#define BIOS_BEGIN 0x000c0000
10494 #define BIOS_END 0x00100000
10495
10496 #define BIOS_ROM_BASE 0xffe00000
10497 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10498 index 5939f44..f8845f6 100644
10499 --- a/arch/x86/include/asm/elf.h
10500 +++ b/arch/x86/include/asm/elf.h
10501 @@ -243,7 +243,25 @@ extern int force_personality32;
10502 the loader. We need to make sure that it is out of the way of the program
10503 that it will "exec", and that there is sufficient room for the brk. */
10504
10505 +#ifdef CONFIG_PAX_SEGMEXEC
10506 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10507 +#else
10508 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10509 +#endif
10510 +
10511 +#ifdef CONFIG_PAX_ASLR
10512 +#ifdef CONFIG_X86_32
10513 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10514 +
10515 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10516 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10517 +#else
10518 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10519 +
10520 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10521 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10522 +#endif
10523 +#endif
10524
10525 /* This yields a mask that user programs can use to figure out what
10526 instruction set this CPU supports. This could be done in user space,
10527 @@ -296,16 +314,12 @@ do { \
10528
10529 #define ARCH_DLINFO \
10530 do { \
10531 - if (vdso_enabled) \
10532 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10533 - (unsigned long)current->mm->context.vdso); \
10534 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10535 } while (0)
10536
10537 #define ARCH_DLINFO_X32 \
10538 do { \
10539 - if (vdso_enabled) \
10540 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10541 - (unsigned long)current->mm->context.vdso); \
10542 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10543 } while (0)
10544
10545 #define AT_SYSINFO 32
10546 @@ -320,7 +334,7 @@ else \
10547
10548 #endif /* !CONFIG_X86_32 */
10549
10550 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10551 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10552
10553 #define VDSO_ENTRY \
10554 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10555 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10556 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10557 #define compat_arch_setup_additional_pages syscall32_setup_pages
10558
10559 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10560 -#define arch_randomize_brk arch_randomize_brk
10561 -
10562 /*
10563 * True on X86_32 or when emulating IA32 on X86_64
10564 */
10565 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10566 index 75ce3f4..882e801 100644
10567 --- a/arch/x86/include/asm/emergency-restart.h
10568 +++ b/arch/x86/include/asm/emergency-restart.h
10569 @@ -13,6 +13,6 @@ enum reboot_type {
10570
10571 extern enum reboot_type reboot_type;
10572
10573 -extern void machine_emergency_restart(void);
10574 +extern void machine_emergency_restart(void) __noreturn;
10575
10576 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10577 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10578 index 75f4c6d..ee3eb8f 100644
10579 --- a/arch/x86/include/asm/fpu-internal.h
10580 +++ b/arch/x86/include/asm/fpu-internal.h
10581 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10582 {
10583 int err;
10584
10585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10586 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10587 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10588 +#endif
10589 +
10590 /* See comment in fxsave() below. */
10591 #ifdef CONFIG_AS_FXSAVEQ
10592 asm volatile("1: fxrstorq %[fx]\n\t"
10593 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10594 {
10595 int err;
10596
10597 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10598 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10599 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10600 +#endif
10601 +
10602 /*
10603 * Clear the bytes not touched by the fxsave and reserved
10604 * for the SW usage.
10605 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10606 "emms\n\t" /* clear stack tags */
10607 "fildl %P[addr]", /* set F?P to defined value */
10608 X86_FEATURE_FXSAVE_LEAK,
10609 - [addr] "m" (tsk->thread.fpu.has_fpu));
10610 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10611
10612 return fpu_restore_checking(&tsk->thread.fpu);
10613 }
10614 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10615 index 71ecbcb..bac10b7 100644
10616 --- a/arch/x86/include/asm/futex.h
10617 +++ b/arch/x86/include/asm/futex.h
10618 @@ -11,16 +11,18 @@
10619 #include <asm/processor.h>
10620
10621 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10622 + typecheck(u32 __user *, uaddr); \
10623 asm volatile("1:\t" insn "\n" \
10624 "2:\t.section .fixup,\"ax\"\n" \
10625 "3:\tmov\t%3, %1\n" \
10626 "\tjmp\t2b\n" \
10627 "\t.previous\n" \
10628 _ASM_EXTABLE(1b, 3b) \
10629 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10630 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10631 : "i" (-EFAULT), "0" (oparg), "1" (0))
10632
10633 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10634 + typecheck(u32 __user *, uaddr); \
10635 asm volatile("1:\tmovl %2, %0\n" \
10636 "\tmovl\t%0, %3\n" \
10637 "\t" insn "\n" \
10638 @@ -33,7 +35,7 @@
10639 _ASM_EXTABLE(1b, 4b) \
10640 _ASM_EXTABLE(2b, 4b) \
10641 : "=&a" (oldval), "=&r" (ret), \
10642 - "+m" (*uaddr), "=&r" (tem) \
10643 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10644 : "r" (oparg), "i" (-EFAULT), "1" (0))
10645
10646 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10647 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10648
10649 switch (op) {
10650 case FUTEX_OP_SET:
10651 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10652 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10653 break;
10654 case FUTEX_OP_ADD:
10655 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10656 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10657 uaddr, oparg);
10658 break;
10659 case FUTEX_OP_OR:
10660 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10661 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10662 return -EFAULT;
10663
10664 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10665 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10666 "2:\t.section .fixup, \"ax\"\n"
10667 "3:\tmov %3, %0\n"
10668 "\tjmp 2b\n"
10669 "\t.previous\n"
10670 _ASM_EXTABLE(1b, 3b)
10671 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10672 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10673 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10674 : "memory"
10675 );
10676 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10677 index eb92a6e..b98b2f4 100644
10678 --- a/arch/x86/include/asm/hw_irq.h
10679 +++ b/arch/x86/include/asm/hw_irq.h
10680 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10681 extern void enable_IO_APIC(void);
10682
10683 /* Statistics */
10684 -extern atomic_t irq_err_count;
10685 -extern atomic_t irq_mis_count;
10686 +extern atomic_unchecked_t irq_err_count;
10687 +extern atomic_unchecked_t irq_mis_count;
10688
10689 /* EISA */
10690 extern void eisa_set_level_irq(unsigned int irq);
10691 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10692 index d8e8eef..99f81ae 100644
10693 --- a/arch/x86/include/asm/io.h
10694 +++ b/arch/x86/include/asm/io.h
10695 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10696
10697 #include <linux/vmalloc.h>
10698
10699 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10700 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10701 +{
10702 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10703 +}
10704 +
10705 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10706 +{
10707 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10708 +}
10709 +
10710 /*
10711 * Convert a virtual cached pointer to an uncached pointer
10712 */
10713 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10714 index bba3cf8..06bc8da 100644
10715 --- a/arch/x86/include/asm/irqflags.h
10716 +++ b/arch/x86/include/asm/irqflags.h
10717 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10718 sti; \
10719 sysexit
10720
10721 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10722 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10723 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10724 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10725 +
10726 #else
10727 #define INTERRUPT_RETURN iret
10728 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10729 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10730 index 5478825..839e88c 100644
10731 --- a/arch/x86/include/asm/kprobes.h
10732 +++ b/arch/x86/include/asm/kprobes.h
10733 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10734 #define RELATIVEJUMP_SIZE 5
10735 #define RELATIVECALL_OPCODE 0xe8
10736 #define RELATIVE_ADDR_SIZE 4
10737 -#define MAX_STACK_SIZE 64
10738 -#define MIN_STACK_SIZE(ADDR) \
10739 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10740 - THREAD_SIZE - (unsigned long)(ADDR))) \
10741 - ? (MAX_STACK_SIZE) \
10742 - : (((unsigned long)current_thread_info()) + \
10743 - THREAD_SIZE - (unsigned long)(ADDR)))
10744 +#define MAX_STACK_SIZE 64UL
10745 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10746
10747 #define flush_insn_slot(p) do { } while (0)
10748
10749 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10750 index 09155d6..d2e6df9 100644
10751 --- a/arch/x86/include/asm/kvm_host.h
10752 +++ b/arch/x86/include/asm/kvm_host.h
10753 @@ -694,7 +694,7 @@ struct kvm_x86_ops {
10754 int (*check_intercept)(struct kvm_vcpu *vcpu,
10755 struct x86_instruction_info *info,
10756 enum x86_intercept_stage stage);
10757 -};
10758 +} __do_const;
10759
10760 struct kvm_arch_async_pf {
10761 u32 token;
10762 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10763 index c8bed0d..e5721fa 100644
10764 --- a/arch/x86/include/asm/local.h
10765 +++ b/arch/x86/include/asm/local.h
10766 @@ -17,26 +17,58 @@ typedef struct {
10767
10768 static inline void local_inc(local_t *l)
10769 {
10770 - asm volatile(_ASM_INC "%0"
10771 + asm volatile(_ASM_INC "%0\n"
10772 +
10773 +#ifdef CONFIG_PAX_REFCOUNT
10774 + "jno 0f\n"
10775 + _ASM_DEC "%0\n"
10776 + "int $4\n0:\n"
10777 + _ASM_EXTABLE(0b, 0b)
10778 +#endif
10779 +
10780 : "+m" (l->a.counter));
10781 }
10782
10783 static inline void local_dec(local_t *l)
10784 {
10785 - asm volatile(_ASM_DEC "%0"
10786 + asm volatile(_ASM_DEC "%0\n"
10787 +
10788 +#ifdef CONFIG_PAX_REFCOUNT
10789 + "jno 0f\n"
10790 + _ASM_INC "%0\n"
10791 + "int $4\n0:\n"
10792 + _ASM_EXTABLE(0b, 0b)
10793 +#endif
10794 +
10795 : "+m" (l->a.counter));
10796 }
10797
10798 static inline void local_add(long i, local_t *l)
10799 {
10800 - asm volatile(_ASM_ADD "%1,%0"
10801 + asm volatile(_ASM_ADD "%1,%0\n"
10802 +
10803 +#ifdef CONFIG_PAX_REFCOUNT
10804 + "jno 0f\n"
10805 + _ASM_SUB "%1,%0\n"
10806 + "int $4\n0:\n"
10807 + _ASM_EXTABLE(0b, 0b)
10808 +#endif
10809 +
10810 : "+m" (l->a.counter)
10811 : "ir" (i));
10812 }
10813
10814 static inline void local_sub(long i, local_t *l)
10815 {
10816 - asm volatile(_ASM_SUB "%1,%0"
10817 + asm volatile(_ASM_SUB "%1,%0\n"
10818 +
10819 +#ifdef CONFIG_PAX_REFCOUNT
10820 + "jno 0f\n"
10821 + _ASM_ADD "%1,%0\n"
10822 + "int $4\n0:\n"
10823 + _ASM_EXTABLE(0b, 0b)
10824 +#endif
10825 +
10826 : "+m" (l->a.counter)
10827 : "ir" (i));
10828 }
10829 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10830 {
10831 unsigned char c;
10832
10833 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10834 + asm volatile(_ASM_SUB "%2,%0\n"
10835 +
10836 +#ifdef CONFIG_PAX_REFCOUNT
10837 + "jno 0f\n"
10838 + _ASM_ADD "%2,%0\n"
10839 + "int $4\n0:\n"
10840 + _ASM_EXTABLE(0b, 0b)
10841 +#endif
10842 +
10843 + "sete %1\n"
10844 : "+m" (l->a.counter), "=qm" (c)
10845 : "ir" (i) : "memory");
10846 return c;
10847 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10848 {
10849 unsigned char c;
10850
10851 - asm volatile(_ASM_DEC "%0; sete %1"
10852 + asm volatile(_ASM_DEC "%0\n"
10853 +
10854 +#ifdef CONFIG_PAX_REFCOUNT
10855 + "jno 0f\n"
10856 + _ASM_INC "%0\n"
10857 + "int $4\n0:\n"
10858 + _ASM_EXTABLE(0b, 0b)
10859 +#endif
10860 +
10861 + "sete %1\n"
10862 : "+m" (l->a.counter), "=qm" (c)
10863 : : "memory");
10864 return c != 0;
10865 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10866 {
10867 unsigned char c;
10868
10869 - asm volatile(_ASM_INC "%0; sete %1"
10870 + asm volatile(_ASM_INC "%0\n"
10871 +
10872 +#ifdef CONFIG_PAX_REFCOUNT
10873 + "jno 0f\n"
10874 + _ASM_DEC "%0\n"
10875 + "int $4\n0:\n"
10876 + _ASM_EXTABLE(0b, 0b)
10877 +#endif
10878 +
10879 + "sete %1\n"
10880 : "+m" (l->a.counter), "=qm" (c)
10881 : : "memory");
10882 return c != 0;
10883 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10884 {
10885 unsigned char c;
10886
10887 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10888 + asm volatile(_ASM_ADD "%2,%0\n"
10889 +
10890 +#ifdef CONFIG_PAX_REFCOUNT
10891 + "jno 0f\n"
10892 + _ASM_SUB "%2,%0\n"
10893 + "int $4\n0:\n"
10894 + _ASM_EXTABLE(0b, 0b)
10895 +#endif
10896 +
10897 + "sets %1\n"
10898 : "+m" (l->a.counter), "=qm" (c)
10899 : "ir" (i) : "memory");
10900 return c;
10901 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10902 #endif
10903 /* Modern 486+ processor */
10904 __i = i;
10905 - asm volatile(_ASM_XADD "%0, %1;"
10906 + asm volatile(_ASM_XADD "%0, %1\n"
10907 +
10908 +#ifdef CONFIG_PAX_REFCOUNT
10909 + "jno 0f\n"
10910 + _ASM_MOV "%0,%1\n"
10911 + "int $4\n0:\n"
10912 + _ASM_EXTABLE(0b, 0b)
10913 +#endif
10914 +
10915 : "+r" (i), "+m" (l->a.counter)
10916 : : "memory");
10917 return i + __i;
10918 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10919 index 593e51d..fa69c9a 100644
10920 --- a/arch/x86/include/asm/mman.h
10921 +++ b/arch/x86/include/asm/mman.h
10922 @@ -5,4 +5,14 @@
10923
10924 #include <asm-generic/mman.h>
10925
10926 +#ifdef __KERNEL__
10927 +#ifndef __ASSEMBLY__
10928 +#ifdef CONFIG_X86_32
10929 +#define arch_mmap_check i386_mmap_check
10930 +int i386_mmap_check(unsigned long addr, unsigned long len,
10931 + unsigned long flags);
10932 +#endif
10933 +#endif
10934 +#endif
10935 +
10936 #endif /* _ASM_X86_MMAN_H */
10937 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10938 index 5f55e69..e20bfb1 100644
10939 --- a/arch/x86/include/asm/mmu.h
10940 +++ b/arch/x86/include/asm/mmu.h
10941 @@ -9,7 +9,7 @@
10942 * we put the segment information here.
10943 */
10944 typedef struct {
10945 - void *ldt;
10946 + struct desc_struct *ldt;
10947 int size;
10948
10949 #ifdef CONFIG_X86_64
10950 @@ -18,7 +18,19 @@ typedef struct {
10951 #endif
10952
10953 struct mutex lock;
10954 - void *vdso;
10955 + unsigned long vdso;
10956 +
10957 +#ifdef CONFIG_X86_32
10958 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10959 + unsigned long user_cs_base;
10960 + unsigned long user_cs_limit;
10961 +
10962 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10963 + cpumask_t cpu_user_cs_mask;
10964 +#endif
10965 +
10966 +#endif
10967 +#endif
10968 } mm_context_t;
10969
10970 #ifdef CONFIG_SMP
10971 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10972 index cdbf367..adb37ac 100644
10973 --- a/arch/x86/include/asm/mmu_context.h
10974 +++ b/arch/x86/include/asm/mmu_context.h
10975 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10976
10977 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10978 {
10979 +
10980 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10981 + unsigned int i;
10982 + pgd_t *pgd;
10983 +
10984 + pax_open_kernel();
10985 + pgd = get_cpu_pgd(smp_processor_id());
10986 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10987 + set_pgd_batched(pgd+i, native_make_pgd(0));
10988 + pax_close_kernel();
10989 +#endif
10990 +
10991 #ifdef CONFIG_SMP
10992 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10993 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10994 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10995 struct task_struct *tsk)
10996 {
10997 unsigned cpu = smp_processor_id();
10998 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10999 + int tlbstate = TLBSTATE_OK;
11000 +#endif
11001
11002 if (likely(prev != next)) {
11003 #ifdef CONFIG_SMP
11004 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11005 + tlbstate = this_cpu_read(cpu_tlbstate.state);
11006 +#endif
11007 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11008 this_cpu_write(cpu_tlbstate.active_mm, next);
11009 #endif
11010 cpumask_set_cpu(cpu, mm_cpumask(next));
11011
11012 /* Re-load page tables */
11013 +#ifdef CONFIG_PAX_PER_CPU_PGD
11014 + pax_open_kernel();
11015 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11016 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11017 + pax_close_kernel();
11018 + load_cr3(get_cpu_pgd(cpu));
11019 +#else
11020 load_cr3(next->pgd);
11021 +#endif
11022
11023 /* stop flush ipis for the previous mm */
11024 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11025 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11026 */
11027 if (unlikely(prev->context.ldt != next->context.ldt))
11028 load_LDT_nolock(&next->context);
11029 - }
11030 +
11031 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11032 + if (!(__supported_pte_mask & _PAGE_NX)) {
11033 + smp_mb__before_clear_bit();
11034 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11035 + smp_mb__after_clear_bit();
11036 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11037 + }
11038 +#endif
11039 +
11040 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11041 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11042 + prev->context.user_cs_limit != next->context.user_cs_limit))
11043 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11044 #ifdef CONFIG_SMP
11045 + else if (unlikely(tlbstate != TLBSTATE_OK))
11046 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11047 +#endif
11048 +#endif
11049 +
11050 + }
11051 else {
11052 +
11053 +#ifdef CONFIG_PAX_PER_CPU_PGD
11054 + pax_open_kernel();
11055 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11056 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11057 + pax_close_kernel();
11058 + load_cr3(get_cpu_pgd(cpu));
11059 +#endif
11060 +
11061 +#ifdef CONFIG_SMP
11062 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11063 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11064
11065 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11066 * tlb flush IPI delivery. We must reload CR3
11067 * to make sure to use no freed page tables.
11068 */
11069 +
11070 +#ifndef CONFIG_PAX_PER_CPU_PGD
11071 load_cr3(next->pgd);
11072 +#endif
11073 +
11074 load_LDT_nolock(&next->context);
11075 +
11076 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11077 + if (!(__supported_pte_mask & _PAGE_NX))
11078 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11079 +#endif
11080 +
11081 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11082 +#ifdef CONFIG_PAX_PAGEEXEC
11083 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11084 +#endif
11085 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11086 +#endif
11087 +
11088 }
11089 +#endif
11090 }
11091 -#endif
11092 }
11093
11094 #define activate_mm(prev, next) \
11095 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11096 index 9eae775..c914fea 100644
11097 --- a/arch/x86/include/asm/module.h
11098 +++ b/arch/x86/include/asm/module.h
11099 @@ -5,6 +5,7 @@
11100
11101 #ifdef CONFIG_X86_64
11102 /* X86_64 does not define MODULE_PROC_FAMILY */
11103 +#define MODULE_PROC_FAMILY ""
11104 #elif defined CONFIG_M386
11105 #define MODULE_PROC_FAMILY "386 "
11106 #elif defined CONFIG_M486
11107 @@ -59,8 +60,20 @@
11108 #error unknown processor family
11109 #endif
11110
11111 -#ifdef CONFIG_X86_32
11112 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11113 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11114 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11115 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11116 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11117 +#else
11118 +#define MODULE_PAX_KERNEXEC ""
11119 #endif
11120
11121 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11122 +#define MODULE_PAX_UDEREF "UDEREF "
11123 +#else
11124 +#define MODULE_PAX_UDEREF ""
11125 +#endif
11126 +
11127 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11128 +
11129 #endif /* _ASM_X86_MODULE_H */
11130 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11131 index 320f7bb..e89f8f8 100644
11132 --- a/arch/x86/include/asm/page_64_types.h
11133 +++ b/arch/x86/include/asm/page_64_types.h
11134 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11135
11136 /* duplicated to the one in bootmem.h */
11137 extern unsigned long max_pfn;
11138 -extern unsigned long phys_base;
11139 +extern const unsigned long phys_base;
11140
11141 extern unsigned long __phys_addr(unsigned long);
11142 #define __phys_reloc_hide(x) (x)
11143 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11144 index a0facf3..c017b15 100644
11145 --- a/arch/x86/include/asm/paravirt.h
11146 +++ b/arch/x86/include/asm/paravirt.h
11147 @@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11148 val);
11149 }
11150
11151 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11152 +{
11153 + pgdval_t val = native_pgd_val(pgd);
11154 +
11155 + if (sizeof(pgdval_t) > sizeof(long))
11156 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11157 + val, (u64)val >> 32);
11158 + else
11159 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11160 + val);
11161 +}
11162 +
11163 static inline void pgd_clear(pgd_t *pgdp)
11164 {
11165 set_pgd(pgdp, __pgd(0));
11166 @@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11167 pv_mmu_ops.set_fixmap(idx, phys, flags);
11168 }
11169
11170 +#ifdef CONFIG_PAX_KERNEXEC
11171 +static inline unsigned long pax_open_kernel(void)
11172 +{
11173 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11174 +}
11175 +
11176 +static inline unsigned long pax_close_kernel(void)
11177 +{
11178 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11179 +}
11180 +#else
11181 +static inline unsigned long pax_open_kernel(void) { return 0; }
11182 +static inline unsigned long pax_close_kernel(void) { return 0; }
11183 +#endif
11184 +
11185 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11186
11187 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11188 @@ -929,7 +956,7 @@ extern void default_banner(void);
11189
11190 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11191 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11192 -#define PARA_INDIRECT(addr) *%cs:addr
11193 +#define PARA_INDIRECT(addr) *%ss:addr
11194 #endif
11195
11196 #define INTERRUPT_RETURN \
11197 @@ -1004,6 +1031,21 @@ extern void default_banner(void);
11198 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11199 CLBR_NONE, \
11200 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11201 +
11202 +#define GET_CR0_INTO_RDI \
11203 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11204 + mov %rax,%rdi
11205 +
11206 +#define SET_RDI_INTO_CR0 \
11207 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11208 +
11209 +#define GET_CR3_INTO_RDI \
11210 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11211 + mov %rax,%rdi
11212 +
11213 +#define SET_RDI_INTO_CR3 \
11214 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11215 +
11216 #endif /* CONFIG_X86_32 */
11217
11218 #endif /* __ASSEMBLY__ */
11219 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11220 index 142236e..6a6b4a6 100644
11221 --- a/arch/x86/include/asm/paravirt_types.h
11222 +++ b/arch/x86/include/asm/paravirt_types.h
11223 @@ -84,20 +84,20 @@ struct pv_init_ops {
11224 */
11225 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11226 unsigned long addr, unsigned len);
11227 -};
11228 +} __no_const;
11229
11230
11231 struct pv_lazy_ops {
11232 /* Set deferred update mode, used for batching operations. */
11233 void (*enter)(void);
11234 void (*leave)(void);
11235 -};
11236 +} __no_const;
11237
11238 struct pv_time_ops {
11239 unsigned long long (*sched_clock)(void);
11240 unsigned long long (*steal_clock)(int cpu);
11241 unsigned long (*get_tsc_khz)(void);
11242 -};
11243 +} __no_const;
11244
11245 struct pv_cpu_ops {
11246 /* hooks for various privileged instructions */
11247 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
11248
11249 void (*start_context_switch)(struct task_struct *prev);
11250 void (*end_context_switch)(struct task_struct *next);
11251 -};
11252 +} __no_const;
11253
11254 struct pv_irq_ops {
11255 /*
11256 @@ -222,7 +222,7 @@ struct pv_apic_ops {
11257 unsigned long start_eip,
11258 unsigned long start_esp);
11259 #endif
11260 -};
11261 +} __no_const;
11262
11263 struct pv_mmu_ops {
11264 unsigned long (*read_cr2)(void);
11265 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
11266 struct paravirt_callee_save make_pud;
11267
11268 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11269 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11270 #endif /* PAGETABLE_LEVELS == 4 */
11271 #endif /* PAGETABLE_LEVELS >= 3 */
11272
11273 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
11274 an mfn. We can tell which is which from the index. */
11275 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11276 phys_addr_t phys, pgprot_t flags);
11277 +
11278 +#ifdef CONFIG_PAX_KERNEXEC
11279 + unsigned long (*pax_open_kernel)(void);
11280 + unsigned long (*pax_close_kernel)(void);
11281 +#endif
11282 +
11283 };
11284
11285 struct arch_spinlock;
11286 @@ -333,7 +340,7 @@ struct pv_lock_ops {
11287 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11288 int (*spin_trylock)(struct arch_spinlock *lock);
11289 void (*spin_unlock)(struct arch_spinlock *lock);
11290 -};
11291 +} __no_const;
11292
11293 /* This contains all the paravirt structures: we get a convenient
11294 * number for each function using the offset which we use to indicate
11295 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11296 index b4389a4..7024269 100644
11297 --- a/arch/x86/include/asm/pgalloc.h
11298 +++ b/arch/x86/include/asm/pgalloc.h
11299 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11300 pmd_t *pmd, pte_t *pte)
11301 {
11302 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11303 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11304 +}
11305 +
11306 +static inline void pmd_populate_user(struct mm_struct *mm,
11307 + pmd_t *pmd, pte_t *pte)
11308 +{
11309 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11310 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11311 }
11312
11313 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11314
11315 #ifdef CONFIG_X86_PAE
11316 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11317 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11318 +{
11319 + pud_populate(mm, pudp, pmd);
11320 +}
11321 #else /* !CONFIG_X86_PAE */
11322 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11323 {
11324 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11325 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11326 }
11327 +
11328 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11329 +{
11330 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11331 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11332 +}
11333 #endif /* CONFIG_X86_PAE */
11334
11335 #if PAGETABLE_LEVELS > 3
11336 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11337 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11338 }
11339
11340 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11341 +{
11342 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11343 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11344 +}
11345 +
11346 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11347 {
11348 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11349 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11350 index f2b489c..4f7e2e5 100644
11351 --- a/arch/x86/include/asm/pgtable-2level.h
11352 +++ b/arch/x86/include/asm/pgtable-2level.h
11353 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11354
11355 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11356 {
11357 + pax_open_kernel();
11358 *pmdp = pmd;
11359 + pax_close_kernel();
11360 }
11361
11362 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11363 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11364 index 4cc9f2b..5fd9226 100644
11365 --- a/arch/x86/include/asm/pgtable-3level.h
11366 +++ b/arch/x86/include/asm/pgtable-3level.h
11367 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11368
11369 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11370 {
11371 + pax_open_kernel();
11372 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11373 + pax_close_kernel();
11374 }
11375
11376 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11377 {
11378 + pax_open_kernel();
11379 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11380 + pax_close_kernel();
11381 }
11382
11383 /*
11384 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11385 index c3520d7..cf742ef 100644
11386 --- a/arch/x86/include/asm/pgtable.h
11387 +++ b/arch/x86/include/asm/pgtable.h
11388 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11389
11390 #ifndef __PAGETABLE_PUD_FOLDED
11391 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11392 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11393 #define pgd_clear(pgd) native_pgd_clear(pgd)
11394 #endif
11395
11396 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11397
11398 #define arch_end_context_switch(prev) do {} while(0)
11399
11400 +#define pax_open_kernel() native_pax_open_kernel()
11401 +#define pax_close_kernel() native_pax_close_kernel()
11402 #endif /* CONFIG_PARAVIRT */
11403
11404 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11405 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11406 +
11407 +#ifdef CONFIG_PAX_KERNEXEC
11408 +static inline unsigned long native_pax_open_kernel(void)
11409 +{
11410 + unsigned long cr0;
11411 +
11412 + preempt_disable();
11413 + barrier();
11414 + cr0 = read_cr0() ^ X86_CR0_WP;
11415 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11416 + write_cr0(cr0);
11417 + return cr0 ^ X86_CR0_WP;
11418 +}
11419 +
11420 +static inline unsigned long native_pax_close_kernel(void)
11421 +{
11422 + unsigned long cr0;
11423 +
11424 + cr0 = read_cr0() ^ X86_CR0_WP;
11425 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11426 + write_cr0(cr0);
11427 + barrier();
11428 + preempt_enable_no_resched();
11429 + return cr0 ^ X86_CR0_WP;
11430 +}
11431 +#else
11432 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11433 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11434 +#endif
11435 +
11436 /*
11437 * The following only work if pte_present() is true.
11438 * Undefined behaviour if not..
11439 */
11440 +static inline int pte_user(pte_t pte)
11441 +{
11442 + return pte_val(pte) & _PAGE_USER;
11443 +}
11444 +
11445 static inline int pte_dirty(pte_t pte)
11446 {
11447 return pte_flags(pte) & _PAGE_DIRTY;
11448 @@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11449 return pte_clear_flags(pte, _PAGE_RW);
11450 }
11451
11452 +static inline pte_t pte_mkread(pte_t pte)
11453 +{
11454 + return __pte(pte_val(pte) | _PAGE_USER);
11455 +}
11456 +
11457 static inline pte_t pte_mkexec(pte_t pte)
11458 {
11459 - return pte_clear_flags(pte, _PAGE_NX);
11460 +#ifdef CONFIG_X86_PAE
11461 + if (__supported_pte_mask & _PAGE_NX)
11462 + return pte_clear_flags(pte, _PAGE_NX);
11463 + else
11464 +#endif
11465 + return pte_set_flags(pte, _PAGE_USER);
11466 +}
11467 +
11468 +static inline pte_t pte_exprotect(pte_t pte)
11469 +{
11470 +#ifdef CONFIG_X86_PAE
11471 + if (__supported_pte_mask & _PAGE_NX)
11472 + return pte_set_flags(pte, _PAGE_NX);
11473 + else
11474 +#endif
11475 + return pte_clear_flags(pte, _PAGE_USER);
11476 }
11477
11478 static inline pte_t pte_mkdirty(pte_t pte)
11479 @@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11480 #endif
11481
11482 #ifndef __ASSEMBLY__
11483 +
11484 +#ifdef CONFIG_PAX_PER_CPU_PGD
11485 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11486 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11487 +{
11488 + return cpu_pgd[cpu];
11489 +}
11490 +#endif
11491 +
11492 #include <linux/mm_types.h>
11493
11494 static inline int pte_none(pte_t pte)
11495 @@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11496
11497 static inline int pgd_bad(pgd_t pgd)
11498 {
11499 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11500 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11501 }
11502
11503 static inline int pgd_none(pgd_t pgd)
11504 @@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
11505 * pgd_offset() returns a (pgd_t *)
11506 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11507 */
11508 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11509 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11510 +
11511 +#ifdef CONFIG_PAX_PER_CPU_PGD
11512 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11513 +#endif
11514 +
11515 /*
11516 * a shortcut which implies the use of the kernel's pgd, instead
11517 * of a process's
11518 @@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
11519 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11520 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11521
11522 +#ifdef CONFIG_X86_32
11523 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11524 +#else
11525 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11526 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11527 +
11528 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11529 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11530 +#else
11531 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11532 +#endif
11533 +
11534 +#endif
11535 +
11536 #ifndef __ASSEMBLY__
11537
11538 extern int direct_gbpages;
11539 @@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11540 * dst and src can be on the same page, but the range must not overlap,
11541 * and must not cross a page boundary.
11542 */
11543 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11544 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11545 {
11546 - memcpy(dst, src, count * sizeof(pgd_t));
11547 + pax_open_kernel();
11548 + while (count--)
11549 + *dst++ = *src++;
11550 + pax_close_kernel();
11551 }
11552
11553 +#ifdef CONFIG_PAX_PER_CPU_PGD
11554 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11555 +#endif
11556 +
11557 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11558 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11559 +#else
11560 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11561 +#endif
11562
11563 #include <asm-generic/pgtable.h>
11564 #endif /* __ASSEMBLY__ */
11565 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11566 index 0c92113..34a77c6 100644
11567 --- a/arch/x86/include/asm/pgtable_32.h
11568 +++ b/arch/x86/include/asm/pgtable_32.h
11569 @@ -25,9 +25,6 @@
11570 struct mm_struct;
11571 struct vm_area_struct;
11572
11573 -extern pgd_t swapper_pg_dir[1024];
11574 -extern pgd_t initial_page_table[1024];
11575 -
11576 static inline void pgtable_cache_init(void) { }
11577 static inline void check_pgt_cache(void) { }
11578 void paging_init(void);
11579 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11580 # include <asm/pgtable-2level.h>
11581 #endif
11582
11583 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11584 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11585 +#ifdef CONFIG_X86_PAE
11586 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11587 +#endif
11588 +
11589 #if defined(CONFIG_HIGHPTE)
11590 #define pte_offset_map(dir, address) \
11591 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11592 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11593 /* Clear a kernel PTE and flush it from the TLB */
11594 #define kpte_clear_flush(ptep, vaddr) \
11595 do { \
11596 + pax_open_kernel(); \
11597 pte_clear(&init_mm, (vaddr), (ptep)); \
11598 + pax_close_kernel(); \
11599 __flush_tlb_one((vaddr)); \
11600 } while (0)
11601
11602 @@ -74,6 +79,9 @@ do { \
11603
11604 #endif /* !__ASSEMBLY__ */
11605
11606 +#define HAVE_ARCH_UNMAPPED_AREA
11607 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11608 +
11609 /*
11610 * kern_addr_valid() is (1) for FLATMEM and (0) for
11611 * SPARSEMEM and DISCONTIGMEM
11612 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11613 index ed5903b..c7fe163 100644
11614 --- a/arch/x86/include/asm/pgtable_32_types.h
11615 +++ b/arch/x86/include/asm/pgtable_32_types.h
11616 @@ -8,7 +8,7 @@
11617 */
11618 #ifdef CONFIG_X86_PAE
11619 # include <asm/pgtable-3level_types.h>
11620 -# define PMD_SIZE (1UL << PMD_SHIFT)
11621 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11622 # define PMD_MASK (~(PMD_SIZE - 1))
11623 #else
11624 # include <asm/pgtable-2level_types.h>
11625 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11626 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11627 #endif
11628
11629 +#ifdef CONFIG_PAX_KERNEXEC
11630 +#ifndef __ASSEMBLY__
11631 +extern unsigned char MODULES_EXEC_VADDR[];
11632 +extern unsigned char MODULES_EXEC_END[];
11633 +#endif
11634 +#include <asm/boot.h>
11635 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11636 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11637 +#else
11638 +#define ktla_ktva(addr) (addr)
11639 +#define ktva_ktla(addr) (addr)
11640 +#endif
11641 +
11642 #define MODULES_VADDR VMALLOC_START
11643 #define MODULES_END VMALLOC_END
11644 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11645 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11646 index 8251be0..4ea8b46 100644
11647 --- a/arch/x86/include/asm/pgtable_64.h
11648 +++ b/arch/x86/include/asm/pgtable_64.h
11649 @@ -16,10 +16,14 @@
11650
11651 extern pud_t level3_kernel_pgt[512];
11652 extern pud_t level3_ident_pgt[512];
11653 +extern pud_t level3_vmalloc_start_pgt[512];
11654 +extern pud_t level3_vmalloc_end_pgt[512];
11655 +extern pud_t level3_vmemmap_pgt[512];
11656 +extern pud_t level2_vmemmap_pgt[512];
11657 extern pmd_t level2_kernel_pgt[512];
11658 extern pmd_t level2_fixmap_pgt[512];
11659 -extern pmd_t level2_ident_pgt[512];
11660 -extern pgd_t init_level4_pgt[];
11661 +extern pmd_t level2_ident_pgt[512*2];
11662 +extern pgd_t init_level4_pgt[512];
11663
11664 #define swapper_pg_dir init_level4_pgt
11665
11666 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11667
11668 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11669 {
11670 + pax_open_kernel();
11671 *pmdp = pmd;
11672 + pax_close_kernel();
11673 }
11674
11675 static inline void native_pmd_clear(pmd_t *pmd)
11676 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11677
11678 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11679 {
11680 + pax_open_kernel();
11681 *pudp = pud;
11682 + pax_close_kernel();
11683 }
11684
11685 static inline void native_pud_clear(pud_t *pud)
11686 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11687
11688 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11689 {
11690 + pax_open_kernel();
11691 + *pgdp = pgd;
11692 + pax_close_kernel();
11693 +}
11694 +
11695 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11696 +{
11697 *pgdp = pgd;
11698 }
11699
11700 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11701 index 766ea16..5b96cb3 100644
11702 --- a/arch/x86/include/asm/pgtable_64_types.h
11703 +++ b/arch/x86/include/asm/pgtable_64_types.h
11704 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11705 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11706 #define MODULES_END _AC(0xffffffffff000000, UL)
11707 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11708 +#define MODULES_EXEC_VADDR MODULES_VADDR
11709 +#define MODULES_EXEC_END MODULES_END
11710 +
11711 +#define ktla_ktva(addr) (addr)
11712 +#define ktva_ktla(addr) (addr)
11713
11714 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11715 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11716 index 013286a..8b42f4f 100644
11717 --- a/arch/x86/include/asm/pgtable_types.h
11718 +++ b/arch/x86/include/asm/pgtable_types.h
11719 @@ -16,13 +16,12 @@
11720 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11721 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11722 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11723 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11724 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11725 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11726 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11727 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11728 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11729 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11730 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11731 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11732 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11733 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11734
11735 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11736 @@ -40,7 +39,6 @@
11737 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11738 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11739 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11740 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11741 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11742 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11743 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11744 @@ -57,8 +55,10 @@
11745
11746 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11747 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11748 -#else
11749 +#elif defined(CONFIG_KMEMCHECK)
11750 #define _PAGE_NX (_AT(pteval_t, 0))
11751 +#else
11752 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11753 #endif
11754
11755 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11756 @@ -96,6 +96,9 @@
11757 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11758 _PAGE_ACCESSED)
11759
11760 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11761 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11762 +
11763 #define __PAGE_KERNEL_EXEC \
11764 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11765 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11766 @@ -106,7 +109,7 @@
11767 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11768 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11769 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11770 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11771 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11772 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11773 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11774 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11775 @@ -168,8 +171,8 @@
11776 * bits are combined, this will alow user to access the high address mapped
11777 * VDSO in the presence of CONFIG_COMPAT_VDSO
11778 */
11779 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11780 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11781 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11782 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11783 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11784 #endif
11785
11786 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11787 {
11788 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11789 }
11790 +#endif
11791
11792 +#if PAGETABLE_LEVELS == 3
11793 +#include <asm-generic/pgtable-nopud.h>
11794 +#endif
11795 +
11796 +#if PAGETABLE_LEVELS == 2
11797 +#include <asm-generic/pgtable-nopmd.h>
11798 +#endif
11799 +
11800 +#ifndef __ASSEMBLY__
11801 #if PAGETABLE_LEVELS > 3
11802 typedef struct { pudval_t pud; } pud_t;
11803
11804 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11805 return pud.pud;
11806 }
11807 #else
11808 -#include <asm-generic/pgtable-nopud.h>
11809 -
11810 static inline pudval_t native_pud_val(pud_t pud)
11811 {
11812 return native_pgd_val(pud.pgd);
11813 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11814 return pmd.pmd;
11815 }
11816 #else
11817 -#include <asm-generic/pgtable-nopmd.h>
11818 -
11819 static inline pmdval_t native_pmd_val(pmd_t pmd)
11820 {
11821 return native_pgd_val(pmd.pud.pgd);
11822 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11823
11824 extern pteval_t __supported_pte_mask;
11825 extern void set_nx(void);
11826 -extern int nx_enabled;
11827
11828 #define pgprot_writecombine pgprot_writecombine
11829 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11830 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11831 index aea1d1d..680cf09 100644
11832 --- a/arch/x86/include/asm/processor-flags.h
11833 +++ b/arch/x86/include/asm/processor-flags.h
11834 @@ -65,6 +65,7 @@
11835 #define X86_CR4_PCIDE 0x00020000 /* enable PCID support */
11836 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11837 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11838 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11839
11840 /*
11841 * x86-64 Task Priority Register, CR8
11842 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11843 index d048cad..45e350f 100644
11844 --- a/arch/x86/include/asm/processor.h
11845 +++ b/arch/x86/include/asm/processor.h
11846 @@ -289,7 +289,7 @@ struct tss_struct {
11847
11848 } ____cacheline_aligned;
11849
11850 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11851 +extern struct tss_struct init_tss[NR_CPUS];
11852
11853 /*
11854 * Save the original ist values for checking stack pointers during debugging
11855 @@ -822,11 +822,18 @@ static inline void spin_lock_prefetch(const void *x)
11856 */
11857 #define TASK_SIZE PAGE_OFFSET
11858 #define TASK_SIZE_MAX TASK_SIZE
11859 +
11860 +#ifdef CONFIG_PAX_SEGMEXEC
11861 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11862 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11863 +#else
11864 #define STACK_TOP TASK_SIZE
11865 -#define STACK_TOP_MAX STACK_TOP
11866 +#endif
11867 +
11868 +#define STACK_TOP_MAX TASK_SIZE
11869
11870 #define INIT_THREAD { \
11871 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11872 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11873 .vm86_info = NULL, \
11874 .sysenter_cs = __KERNEL_CS, \
11875 .io_bitmap_ptr = NULL, \
11876 @@ -840,7 +847,7 @@ static inline void spin_lock_prefetch(const void *x)
11877 */
11878 #define INIT_TSS { \
11879 .x86_tss = { \
11880 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11881 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11882 .ss0 = __KERNEL_DS, \
11883 .ss1 = __KERNEL_CS, \
11884 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11885 @@ -851,11 +858,7 @@ static inline void spin_lock_prefetch(const void *x)
11886 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11887
11888 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11889 -#define KSTK_TOP(info) \
11890 -({ \
11891 - unsigned long *__ptr = (unsigned long *)(info); \
11892 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11893 -})
11894 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11895
11896 /*
11897 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11898 @@ -870,7 +873,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11899 #define task_pt_regs(task) \
11900 ({ \
11901 struct pt_regs *__regs__; \
11902 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11903 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11904 __regs__ - 1; \
11905 })
11906
11907 @@ -880,13 +883,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11908 /*
11909 * User space process size. 47bits minus one guard page.
11910 */
11911 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11912 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11913
11914 /* This decides where the kernel will search for a free chunk of vm
11915 * space during mmap's.
11916 */
11917 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11918 - 0xc0000000 : 0xFFFFe000)
11919 + 0xc0000000 : 0xFFFFf000)
11920
11921 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11922 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11923 @@ -897,11 +900,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11924 #define STACK_TOP_MAX TASK_SIZE_MAX
11925
11926 #define INIT_THREAD { \
11927 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11928 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11929 }
11930
11931 #define INIT_TSS { \
11932 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11933 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11934 }
11935
11936 /*
11937 @@ -929,6 +932,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11938 */
11939 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11940
11941 +#ifdef CONFIG_PAX_SEGMEXEC
11942 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11943 +#endif
11944 +
11945 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11946
11947 /* Get/set a process' ability to use the timestamp counter instruction */
11948 @@ -989,12 +996,12 @@ extern bool cpu_has_amd_erratum(const int *);
11949 #define cpu_has_amd_erratum(x) (false)
11950 #endif /* CONFIG_CPU_SUP_AMD */
11951
11952 -extern unsigned long arch_align_stack(unsigned long sp);
11953 +#define arch_align_stack(x) ((x) & ~0xfUL)
11954 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11955
11956 void default_idle(void);
11957 bool set_pm_idle_to_default(void);
11958
11959 -void stop_this_cpu(void *dummy);
11960 +void stop_this_cpu(void *dummy) __noreturn;
11961
11962 #endif /* _ASM_X86_PROCESSOR_H */
11963 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11964 index dcfde52..dbfea06 100644
11965 --- a/arch/x86/include/asm/ptrace.h
11966 +++ b/arch/x86/include/asm/ptrace.h
11967 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11968 }
11969
11970 /*
11971 - * user_mode_vm(regs) determines whether a register set came from user mode.
11972 + * user_mode(regs) determines whether a register set came from user mode.
11973 * This is true if V8086 mode was enabled OR if the register set was from
11974 * protected mode with RPL-3 CS value. This tricky test checks that with
11975 * one comparison. Many places in the kernel can bypass this full check
11976 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11977 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11978 + * be used.
11979 */
11980 -static inline int user_mode(struct pt_regs *regs)
11981 +static inline int user_mode_novm(struct pt_regs *regs)
11982 {
11983 #ifdef CONFIG_X86_32
11984 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11985 #else
11986 - return !!(regs->cs & 3);
11987 + return !!(regs->cs & SEGMENT_RPL_MASK);
11988 #endif
11989 }
11990
11991 -static inline int user_mode_vm(struct pt_regs *regs)
11992 +static inline int user_mode(struct pt_regs *regs)
11993 {
11994 #ifdef CONFIG_X86_32
11995 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11996 USER_RPL;
11997 #else
11998 - return user_mode(regs);
11999 + return user_mode_novm(regs);
12000 #endif
12001 }
12002
12003 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
12004 #ifdef CONFIG_X86_64
12005 static inline bool user_64bit_mode(struct pt_regs *regs)
12006 {
12007 + unsigned long cs = regs->cs & 0xffff;
12008 #ifndef CONFIG_PARAVIRT
12009 /*
12010 * On non-paravirt systems, this is the only long mode CPL 3
12011 * selector. We do not allow long mode selectors in the LDT.
12012 */
12013 - return regs->cs == __USER_CS;
12014 + return cs == __USER_CS;
12015 #else
12016 /* Headers are too twisted for this to go in paravirt.h. */
12017 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12018 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12019 #endif
12020 }
12021 #endif
12022 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12023 index fe1ec5b..dc5c3fe 100644
12024 --- a/arch/x86/include/asm/realmode.h
12025 +++ b/arch/x86/include/asm/realmode.h
12026 @@ -22,16 +22,14 @@ struct real_mode_header {
12027 #endif
12028 /* APM/BIOS reboot */
12029 u32 machine_real_restart_asm;
12030 -#ifdef CONFIG_X86_64
12031 u32 machine_real_restart_seg;
12032 -#endif
12033 };
12034
12035 /* This must match data at trampoline_32/64.S */
12036 struct trampoline_header {
12037 #ifdef CONFIG_X86_32
12038 u32 start;
12039 - u16 gdt_pad;
12040 + u16 boot_cs;
12041 u16 gdt_limit;
12042 u32 gdt_base;
12043 #else
12044 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12045 index a82c4f1..ac45053 100644
12046 --- a/arch/x86/include/asm/reboot.h
12047 +++ b/arch/x86/include/asm/reboot.h
12048 @@ -6,13 +6,13 @@
12049 struct pt_regs;
12050
12051 struct machine_ops {
12052 - void (*restart)(char *cmd);
12053 - void (*halt)(void);
12054 - void (*power_off)(void);
12055 + void (* __noreturn restart)(char *cmd);
12056 + void (* __noreturn halt)(void);
12057 + void (* __noreturn power_off)(void);
12058 void (*shutdown)(void);
12059 void (*crash_shutdown)(struct pt_regs *);
12060 - void (*emergency_restart)(void);
12061 -};
12062 + void (* __noreturn emergency_restart)(void);
12063 +} __no_const;
12064
12065 extern struct machine_ops machine_ops;
12066
12067 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12068 index 2dbe4a7..ce1db00 100644
12069 --- a/arch/x86/include/asm/rwsem.h
12070 +++ b/arch/x86/include/asm/rwsem.h
12071 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12072 {
12073 asm volatile("# beginning down_read\n\t"
12074 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12075 +
12076 +#ifdef CONFIG_PAX_REFCOUNT
12077 + "jno 0f\n"
12078 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12079 + "int $4\n0:\n"
12080 + _ASM_EXTABLE(0b, 0b)
12081 +#endif
12082 +
12083 /* adds 0x00000001 */
12084 " jns 1f\n"
12085 " call call_rwsem_down_read_failed\n"
12086 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12087 "1:\n\t"
12088 " mov %1,%2\n\t"
12089 " add %3,%2\n\t"
12090 +
12091 +#ifdef CONFIG_PAX_REFCOUNT
12092 + "jno 0f\n"
12093 + "sub %3,%2\n"
12094 + "int $4\n0:\n"
12095 + _ASM_EXTABLE(0b, 0b)
12096 +#endif
12097 +
12098 " jle 2f\n\t"
12099 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12100 " jnz 1b\n\t"
12101 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12102 long tmp;
12103 asm volatile("# beginning down_write\n\t"
12104 LOCK_PREFIX " xadd %1,(%2)\n\t"
12105 +
12106 +#ifdef CONFIG_PAX_REFCOUNT
12107 + "jno 0f\n"
12108 + "mov %1,(%2)\n"
12109 + "int $4\n0:\n"
12110 + _ASM_EXTABLE(0b, 0b)
12111 +#endif
12112 +
12113 /* adds 0xffff0001, returns the old value */
12114 " test %1,%1\n\t"
12115 /* was the count 0 before? */
12116 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12117 long tmp;
12118 asm volatile("# beginning __up_read\n\t"
12119 LOCK_PREFIX " xadd %1,(%2)\n\t"
12120 +
12121 +#ifdef CONFIG_PAX_REFCOUNT
12122 + "jno 0f\n"
12123 + "mov %1,(%2)\n"
12124 + "int $4\n0:\n"
12125 + _ASM_EXTABLE(0b, 0b)
12126 +#endif
12127 +
12128 /* subtracts 1, returns the old value */
12129 " jns 1f\n\t"
12130 " call call_rwsem_wake\n" /* expects old value in %edx */
12131 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12132 long tmp;
12133 asm volatile("# beginning __up_write\n\t"
12134 LOCK_PREFIX " xadd %1,(%2)\n\t"
12135 +
12136 +#ifdef CONFIG_PAX_REFCOUNT
12137 + "jno 0f\n"
12138 + "mov %1,(%2)\n"
12139 + "int $4\n0:\n"
12140 + _ASM_EXTABLE(0b, 0b)
12141 +#endif
12142 +
12143 /* subtracts 0xffff0001, returns the old value */
12144 " jns 1f\n\t"
12145 " call call_rwsem_wake\n" /* expects old value in %edx */
12146 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12147 {
12148 asm volatile("# beginning __downgrade_write\n\t"
12149 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12150 +
12151 +#ifdef CONFIG_PAX_REFCOUNT
12152 + "jno 0f\n"
12153 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12154 + "int $4\n0:\n"
12155 + _ASM_EXTABLE(0b, 0b)
12156 +#endif
12157 +
12158 /*
12159 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12160 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12161 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12162 */
12163 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12164 {
12165 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12166 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12167 +
12168 +#ifdef CONFIG_PAX_REFCOUNT
12169 + "jno 0f\n"
12170 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12171 + "int $4\n0:\n"
12172 + _ASM_EXTABLE(0b, 0b)
12173 +#endif
12174 +
12175 : "+m" (sem->count)
12176 : "er" (delta));
12177 }
12178 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12179 */
12180 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12181 {
12182 - return delta + xadd(&sem->count, delta);
12183 + return delta + xadd_check_overflow(&sem->count, delta);
12184 }
12185
12186 #endif /* __KERNEL__ */
12187 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12188 index c48a950..c6d7468 100644
12189 --- a/arch/x86/include/asm/segment.h
12190 +++ b/arch/x86/include/asm/segment.h
12191 @@ -64,10 +64,15 @@
12192 * 26 - ESPFIX small SS
12193 * 27 - per-cpu [ offset to per-cpu data area ]
12194 * 28 - stack_canary-20 [ for stack protector ]
12195 - * 29 - unused
12196 - * 30 - unused
12197 + * 29 - PCI BIOS CS
12198 + * 30 - PCI BIOS DS
12199 * 31 - TSS for double fault handler
12200 */
12201 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12202 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12203 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12204 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12205 +
12206 #define GDT_ENTRY_TLS_MIN 6
12207 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12208
12209 @@ -79,6 +84,8 @@
12210
12211 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12212
12213 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12214 +
12215 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12216
12217 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12218 @@ -104,6 +111,12 @@
12219 #define __KERNEL_STACK_CANARY 0
12220 #endif
12221
12222 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12223 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12224 +
12225 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12226 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12227 +
12228 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12229
12230 /*
12231 @@ -141,7 +154,7 @@
12232 */
12233
12234 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12235 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12236 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12237
12238
12239 #else
12240 @@ -165,6 +178,8 @@
12241 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12242 #define __USER32_DS __USER_DS
12243
12244 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12245 +
12246 #define GDT_ENTRY_TSS 8 /* needs two entries */
12247 #define GDT_ENTRY_LDT 10 /* needs two entries */
12248 #define GDT_ENTRY_TLS_MIN 12
12249 @@ -185,6 +200,7 @@
12250 #endif
12251
12252 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12253 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12254 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12255 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12256 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12257 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12258 {
12259 unsigned long __limit;
12260 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12261 - return __limit + 1;
12262 + return __limit;
12263 }
12264
12265 #endif /* !__ASSEMBLY__ */
12266 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12267 index 4f19a15..9e14f27 100644
12268 --- a/arch/x86/include/asm/smp.h
12269 +++ b/arch/x86/include/asm/smp.h
12270 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
12271 /* cpus sharing the last level cache: */
12272 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
12273 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
12274 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
12275 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
12276
12277 static inline struct cpumask *cpu_sibling_mask(int cpu)
12278 {
12279 @@ -79,7 +79,7 @@ struct smp_ops {
12280
12281 void (*send_call_func_ipi)(const struct cpumask *mask);
12282 void (*send_call_func_single_ipi)(int cpu);
12283 -};
12284 +} __no_const;
12285
12286 /* Globals due to paravirt */
12287 extern void set_cpu_sibling_map(int cpu);
12288 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12289 extern int safe_smp_processor_id(void);
12290
12291 #elif defined(CONFIG_X86_64_SMP)
12292 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12293 -
12294 -#define stack_smp_processor_id() \
12295 -({ \
12296 - struct thread_info *ti; \
12297 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12298 - ti->cpu; \
12299 -})
12300 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12301 +#define stack_smp_processor_id() raw_smp_processor_id()
12302 #define safe_smp_processor_id() smp_processor_id()
12303
12304 #endif
12305 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12306 index 33692ea..350a534 100644
12307 --- a/arch/x86/include/asm/spinlock.h
12308 +++ b/arch/x86/include/asm/spinlock.h
12309 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12310 static inline void arch_read_lock(arch_rwlock_t *rw)
12311 {
12312 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12313 +
12314 +#ifdef CONFIG_PAX_REFCOUNT
12315 + "jno 0f\n"
12316 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12317 + "int $4\n0:\n"
12318 + _ASM_EXTABLE(0b, 0b)
12319 +#endif
12320 +
12321 "jns 1f\n"
12322 "call __read_lock_failed\n\t"
12323 "1:\n"
12324 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12325 static inline void arch_write_lock(arch_rwlock_t *rw)
12326 {
12327 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12328 +
12329 +#ifdef CONFIG_PAX_REFCOUNT
12330 + "jno 0f\n"
12331 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12332 + "int $4\n0:\n"
12333 + _ASM_EXTABLE(0b, 0b)
12334 +#endif
12335 +
12336 "jz 1f\n"
12337 "call __write_lock_failed\n\t"
12338 "1:\n"
12339 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12340
12341 static inline void arch_read_unlock(arch_rwlock_t *rw)
12342 {
12343 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12344 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12345 +
12346 +#ifdef CONFIG_PAX_REFCOUNT
12347 + "jno 0f\n"
12348 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12349 + "int $4\n0:\n"
12350 + _ASM_EXTABLE(0b, 0b)
12351 +#endif
12352 +
12353 :"+m" (rw->lock) : : "memory");
12354 }
12355
12356 static inline void arch_write_unlock(arch_rwlock_t *rw)
12357 {
12358 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12359 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12360 +
12361 +#ifdef CONFIG_PAX_REFCOUNT
12362 + "jno 0f\n"
12363 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12364 + "int $4\n0:\n"
12365 + _ASM_EXTABLE(0b, 0b)
12366 +#endif
12367 +
12368 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12369 }
12370
12371 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12372 index 6a99859..03cb807 100644
12373 --- a/arch/x86/include/asm/stackprotector.h
12374 +++ b/arch/x86/include/asm/stackprotector.h
12375 @@ -47,7 +47,7 @@
12376 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12377 */
12378 #define GDT_STACK_CANARY_INIT \
12379 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12380 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12381
12382 /*
12383 * Initialize the stackprotector canary value.
12384 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12385
12386 static inline void load_stack_canary_segment(void)
12387 {
12388 -#ifdef CONFIG_X86_32
12389 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12390 asm volatile ("mov %0, %%gs" : : "r" (0));
12391 #endif
12392 }
12393 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12394 index 70bbe39..4ae2bd4 100644
12395 --- a/arch/x86/include/asm/stacktrace.h
12396 +++ b/arch/x86/include/asm/stacktrace.h
12397 @@ -11,28 +11,20 @@
12398
12399 extern int kstack_depth_to_print;
12400
12401 -struct thread_info;
12402 +struct task_struct;
12403 struct stacktrace_ops;
12404
12405 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12406 - unsigned long *stack,
12407 - unsigned long bp,
12408 - const struct stacktrace_ops *ops,
12409 - void *data,
12410 - unsigned long *end,
12411 - int *graph);
12412 +typedef unsigned long walk_stack_t(struct task_struct *task,
12413 + void *stack_start,
12414 + unsigned long *stack,
12415 + unsigned long bp,
12416 + const struct stacktrace_ops *ops,
12417 + void *data,
12418 + unsigned long *end,
12419 + int *graph);
12420
12421 -extern unsigned long
12422 -print_context_stack(struct thread_info *tinfo,
12423 - unsigned long *stack, unsigned long bp,
12424 - const struct stacktrace_ops *ops, void *data,
12425 - unsigned long *end, int *graph);
12426 -
12427 -extern unsigned long
12428 -print_context_stack_bp(struct thread_info *tinfo,
12429 - unsigned long *stack, unsigned long bp,
12430 - const struct stacktrace_ops *ops, void *data,
12431 - unsigned long *end, int *graph);
12432 +extern walk_stack_t print_context_stack;
12433 +extern walk_stack_t print_context_stack_bp;
12434
12435 /* Generic stack tracer with callbacks */
12436
12437 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12438 void (*address)(void *data, unsigned long address, int reliable);
12439 /* On negative return stop dumping */
12440 int (*stack)(void *data, char *name);
12441 - walk_stack_t walk_stack;
12442 + walk_stack_t *walk_stack;
12443 };
12444
12445 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12446 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12447 index 4ec45b3..a4f0a8a 100644
12448 --- a/arch/x86/include/asm/switch_to.h
12449 +++ b/arch/x86/include/asm/switch_to.h
12450 @@ -108,7 +108,7 @@ do { \
12451 "call __switch_to\n\t" \
12452 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12453 __switch_canary \
12454 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12455 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12456 "movq %%rax,%%rdi\n\t" \
12457 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12458 "jnz ret_from_fork\n\t" \
12459 @@ -119,7 +119,7 @@ do { \
12460 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12461 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12462 [_tif_fork] "i" (_TIF_FORK), \
12463 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12464 + [thread_info] "m" (current_tinfo), \
12465 [current_task] "m" (current_task) \
12466 __switch_canary_iparam \
12467 : "memory", "cc" __EXTRA_CLOBBER)
12468 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12469 index 3fda9db4..4ca1c61 100644
12470 --- a/arch/x86/include/asm/sys_ia32.h
12471 +++ b/arch/x86/include/asm/sys_ia32.h
12472 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12473 struct old_sigaction32 __user *);
12474 asmlinkage long sys32_alarm(unsigned int);
12475
12476 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12477 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12478 asmlinkage long sys32_sysfs(int, u32, u32);
12479
12480 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12481 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12482 index 89f794f..1422765 100644
12483 --- a/arch/x86/include/asm/thread_info.h
12484 +++ b/arch/x86/include/asm/thread_info.h
12485 @@ -10,6 +10,7 @@
12486 #include <linux/compiler.h>
12487 #include <asm/page.h>
12488 #include <asm/types.h>
12489 +#include <asm/percpu.h>
12490
12491 /*
12492 * low level task data that entry.S needs immediate access to
12493 @@ -24,7 +25,6 @@ struct exec_domain;
12494 #include <linux/atomic.h>
12495
12496 struct thread_info {
12497 - struct task_struct *task; /* main task structure */
12498 struct exec_domain *exec_domain; /* execution domain */
12499 __u32 flags; /* low level flags */
12500 __u32 status; /* thread synchronous flags */
12501 @@ -34,19 +34,13 @@ struct thread_info {
12502 mm_segment_t addr_limit;
12503 struct restart_block restart_block;
12504 void __user *sysenter_return;
12505 -#ifdef CONFIG_X86_32
12506 - unsigned long previous_esp; /* ESP of the previous stack in
12507 - case of nested (IRQ) stacks
12508 - */
12509 - __u8 supervisor_stack[0];
12510 -#endif
12511 + unsigned long lowest_stack;
12512 unsigned int sig_on_uaccess_error:1;
12513 unsigned int uaccess_err:1; /* uaccess failed */
12514 };
12515
12516 -#define INIT_THREAD_INFO(tsk) \
12517 +#define INIT_THREAD_INFO \
12518 { \
12519 - .task = &tsk, \
12520 .exec_domain = &default_exec_domain, \
12521 .flags = 0, \
12522 .cpu = 0, \
12523 @@ -57,7 +51,7 @@ struct thread_info {
12524 }, \
12525 }
12526
12527 -#define init_thread_info (init_thread_union.thread_info)
12528 +#define init_thread_info (init_thread_union.stack)
12529 #define init_stack (init_thread_union.stack)
12530
12531 #else /* !__ASSEMBLY__ */
12532 @@ -98,6 +92,7 @@ struct thread_info {
12533 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12534 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12535 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12536 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12537
12538 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12539 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12540 @@ -122,16 +117,18 @@ struct thread_info {
12541 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12542 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12543 #define _TIF_X32 (1 << TIF_X32)
12544 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12545
12546 /* work to do in syscall_trace_enter() */
12547 #define _TIF_WORK_SYSCALL_ENTRY \
12548 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12549 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12550 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12551 + _TIF_GRSEC_SETXID)
12552
12553 /* work to do in syscall_trace_leave() */
12554 #define _TIF_WORK_SYSCALL_EXIT \
12555 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12556 - _TIF_SYSCALL_TRACEPOINT)
12557 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12558
12559 /* work to do on interrupt/exception return */
12560 #define _TIF_WORK_MASK \
12561 @@ -141,7 +138,8 @@ struct thread_info {
12562
12563 /* work to do on any return to user space */
12564 #define _TIF_ALLWORK_MASK \
12565 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12566 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12567 + _TIF_GRSEC_SETXID)
12568
12569 /* Only used for 64 bit */
12570 #define _TIF_DO_NOTIFY_MASK \
12571 @@ -157,45 +155,40 @@ struct thread_info {
12572
12573 #define PREEMPT_ACTIVE 0x10000000
12574
12575 -#ifdef CONFIG_X86_32
12576 -
12577 -#define STACK_WARN (THREAD_SIZE/8)
12578 -/*
12579 - * macros/functions for gaining access to the thread information structure
12580 - *
12581 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12582 - */
12583 -#ifndef __ASSEMBLY__
12584 -
12585 -
12586 -/* how to get the current stack pointer from C */
12587 -register unsigned long current_stack_pointer asm("esp") __used;
12588 -
12589 -/* how to get the thread information struct from C */
12590 -static inline struct thread_info *current_thread_info(void)
12591 -{
12592 - return (struct thread_info *)
12593 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12594 -}
12595 -
12596 -#else /* !__ASSEMBLY__ */
12597 -
12598 +#ifdef __ASSEMBLY__
12599 /* how to get the thread information struct from ASM */
12600 #define GET_THREAD_INFO(reg) \
12601 - movl $-THREAD_SIZE, reg; \
12602 - andl %esp, reg
12603 + mov PER_CPU_VAR(current_tinfo), reg
12604
12605 /* use this one if reg already contains %esp */
12606 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12607 - andl $-THREAD_SIZE, reg
12608 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12609 +#else
12610 +/* how to get the thread information struct from C */
12611 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12612 +
12613 +static __always_inline struct thread_info *current_thread_info(void)
12614 +{
12615 + return this_cpu_read_stable(current_tinfo);
12616 +}
12617 +#endif
12618 +
12619 +#ifdef CONFIG_X86_32
12620 +
12621 +#define STACK_WARN (THREAD_SIZE/8)
12622 +/*
12623 + * macros/functions for gaining access to the thread information structure
12624 + *
12625 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12626 + */
12627 +#ifndef __ASSEMBLY__
12628 +
12629 +/* how to get the current stack pointer from C */
12630 +register unsigned long current_stack_pointer asm("esp") __used;
12631
12632 #endif
12633
12634 #else /* X86_32 */
12635
12636 -#include <asm/percpu.h>
12637 -#define KERNEL_STACK_OFFSET (5*8)
12638 -
12639 /*
12640 * macros/functions for gaining access to the thread information structure
12641 * preempt_count needs to be 1 initially, until the scheduler is functional.
12642 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12643 #ifndef __ASSEMBLY__
12644 DECLARE_PER_CPU(unsigned long, kernel_stack);
12645
12646 -static inline struct thread_info *current_thread_info(void)
12647 -{
12648 - struct thread_info *ti;
12649 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12650 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12651 - return ti;
12652 -}
12653 -
12654 -#else /* !__ASSEMBLY__ */
12655 -
12656 -/* how to get the thread information struct from ASM */
12657 -#define GET_THREAD_INFO(reg) \
12658 - movq PER_CPU_VAR(kernel_stack),reg ; \
12659 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12660 -
12661 -/*
12662 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12663 - * a certain register (to be used in assembler memory operands).
12664 - */
12665 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12666 -
12667 +/* how to get the current stack pointer from C */
12668 +register unsigned long current_stack_pointer asm("rsp") __used;
12669 #endif
12670
12671 #endif /* !X86_32 */
12672 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12673 extern void arch_task_cache_init(void);
12674 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12675 extern void arch_release_task_struct(struct task_struct *tsk);
12676 +
12677 +#define __HAVE_THREAD_FUNCTIONS
12678 +#define task_thread_info(task) (&(task)->tinfo)
12679 +#define task_stack_page(task) ((task)->stack)
12680 +#define setup_thread_stack(p, org) do {} while (0)
12681 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12682 +
12683 #endif
12684 #endif /* _ASM_X86_THREAD_INFO_H */
12685 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12686 index e1f3a17..1ab364d 100644
12687 --- a/arch/x86/include/asm/uaccess.h
12688 +++ b/arch/x86/include/asm/uaccess.h
12689 @@ -7,12 +7,15 @@
12690 #include <linux/compiler.h>
12691 #include <linux/thread_info.h>
12692 #include <linux/string.h>
12693 +#include <linux/sched.h>
12694 #include <asm/asm.h>
12695 #include <asm/page.h>
12696
12697 #define VERIFY_READ 0
12698 #define VERIFY_WRITE 1
12699
12700 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12701 +
12702 /*
12703 * The fs value determines whether argument validity checking should be
12704 * performed or not. If get_fs() == USER_DS, checking is performed, with
12705 @@ -28,7 +31,12 @@
12706
12707 #define get_ds() (KERNEL_DS)
12708 #define get_fs() (current_thread_info()->addr_limit)
12709 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12710 +void __set_fs(mm_segment_t x);
12711 +void set_fs(mm_segment_t x);
12712 +#else
12713 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12714 +#endif
12715
12716 #define segment_eq(a, b) ((a).seg == (b).seg)
12717
12718 @@ -76,8 +84,33 @@
12719 * checks that the pointer is in the user space range - after calling
12720 * this function, memory access functions may still return -EFAULT.
12721 */
12722 -#define access_ok(type, addr, size) \
12723 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12724 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12725 +#define access_ok(type, addr, size) \
12726 +({ \
12727 + long __size = size; \
12728 + unsigned long __addr = (unsigned long)addr; \
12729 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12730 + unsigned long __end_ao = __addr + __size - 1; \
12731 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12732 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12733 + while(__addr_ao <= __end_ao) { \
12734 + char __c_ao; \
12735 + __addr_ao += PAGE_SIZE; \
12736 + if (__size > PAGE_SIZE) \
12737 + cond_resched(); \
12738 + if (__get_user(__c_ao, (char __user *)__addr)) \
12739 + break; \
12740 + if (type != VERIFY_WRITE) { \
12741 + __addr = __addr_ao; \
12742 + continue; \
12743 + } \
12744 + if (__put_user(__c_ao, (char __user *)__addr)) \
12745 + break; \
12746 + __addr = __addr_ao; \
12747 + } \
12748 + } \
12749 + __ret_ao; \
12750 +})
12751
12752 /*
12753 * The exception table consists of pairs of addresses relative to the
12754 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12755 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12756 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12757
12758 -
12759 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12760 +#define __copyuser_seg "gs;"
12761 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12762 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12763 +#else
12764 +#define __copyuser_seg
12765 +#define __COPYUSER_SET_ES
12766 +#define __COPYUSER_RESTORE_ES
12767 +#endif
12768
12769 #ifdef CONFIG_X86_32
12770 #define __put_user_asm_u64(x, addr, err, errret) \
12771 - asm volatile("1: movl %%eax,0(%2)\n" \
12772 - "2: movl %%edx,4(%2)\n" \
12773 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12774 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12775 "3:\n" \
12776 ".section .fixup,\"ax\"\n" \
12777 "4: movl %3,%0\n" \
12778 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12779 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12780
12781 #define __put_user_asm_ex_u64(x, addr) \
12782 - asm volatile("1: movl %%eax,0(%1)\n" \
12783 - "2: movl %%edx,4(%1)\n" \
12784 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12785 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12786 "3:\n" \
12787 _ASM_EXTABLE_EX(1b, 2b) \
12788 _ASM_EXTABLE_EX(2b, 3b) \
12789 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12790 __typeof__(*(ptr)) __pu_val; \
12791 __chk_user_ptr(ptr); \
12792 might_fault(); \
12793 - __pu_val = x; \
12794 + __pu_val = (x); \
12795 switch (sizeof(*(ptr))) { \
12796 case 1: \
12797 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12798 @@ -379,7 +420,7 @@ do { \
12799 } while (0)
12800
12801 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12802 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12803 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12804 "2:\n" \
12805 ".section .fixup,\"ax\"\n" \
12806 "3: mov %3,%0\n" \
12807 @@ -387,7 +428,7 @@ do { \
12808 " jmp 2b\n" \
12809 ".previous\n" \
12810 _ASM_EXTABLE(1b, 3b) \
12811 - : "=r" (err), ltype(x) \
12812 + : "=r" (err), ltype (x) \
12813 : "m" (__m(addr)), "i" (errret), "0" (err))
12814
12815 #define __get_user_size_ex(x, ptr, size) \
12816 @@ -412,7 +453,7 @@ do { \
12817 } while (0)
12818
12819 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12820 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12821 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12822 "2:\n" \
12823 _ASM_EXTABLE_EX(1b, 2b) \
12824 : ltype(x) : "m" (__m(addr)))
12825 @@ -429,13 +470,24 @@ do { \
12826 int __gu_err; \
12827 unsigned long __gu_val; \
12828 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12829 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12830 + (x) = (__typeof__(*(ptr)))__gu_val; \
12831 __gu_err; \
12832 })
12833
12834 /* FIXME: this hack is definitely wrong -AK */
12835 struct __large_struct { unsigned long buf[100]; };
12836 -#define __m(x) (*(struct __large_struct __user *)(x))
12837 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12838 +#define ____m(x) \
12839 +({ \
12840 + unsigned long ____x = (unsigned long)(x); \
12841 + if (____x < PAX_USER_SHADOW_BASE) \
12842 + ____x += PAX_USER_SHADOW_BASE; \
12843 + (void __user *)____x; \
12844 +})
12845 +#else
12846 +#define ____m(x) (x)
12847 +#endif
12848 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12849
12850 /*
12851 * Tell gcc we read from memory instead of writing: this is because
12852 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12853 * aliasing issues.
12854 */
12855 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12856 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12857 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12858 "2:\n" \
12859 ".section .fixup,\"ax\"\n" \
12860 "3: mov %3,%0\n" \
12861 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12862 ".previous\n" \
12863 _ASM_EXTABLE(1b, 3b) \
12864 : "=r"(err) \
12865 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12866 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12867
12868 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12869 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12870 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12871 "2:\n" \
12872 _ASM_EXTABLE_EX(1b, 2b) \
12873 : : ltype(x), "m" (__m(addr)))
12874 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12875 * On error, the variable @x is set to zero.
12876 */
12877
12878 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12879 +#define __get_user(x, ptr) get_user((x), (ptr))
12880 +#else
12881 #define __get_user(x, ptr) \
12882 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12883 +#endif
12884
12885 /**
12886 * __put_user: - Write a simple value into user space, with less checking.
12887 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12888 * Returns zero on success, or -EFAULT on error.
12889 */
12890
12891 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12892 +#define __put_user(x, ptr) put_user((x), (ptr))
12893 +#else
12894 #define __put_user(x, ptr) \
12895 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12896 +#endif
12897
12898 #define __get_user_unaligned __get_user
12899 #define __put_user_unaligned __put_user
12900 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12901 #define get_user_ex(x, ptr) do { \
12902 unsigned long __gue_val; \
12903 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12904 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12905 + (x) = (__typeof__(*(ptr)))__gue_val; \
12906 } while (0)
12907
12908 #ifdef CONFIG_X86_WP_WORKS_OK
12909 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12910 index 576e39b..ccd0a39 100644
12911 --- a/arch/x86/include/asm/uaccess_32.h
12912 +++ b/arch/x86/include/asm/uaccess_32.h
12913 @@ -11,15 +11,15 @@
12914 #include <asm/page.h>
12915
12916 unsigned long __must_check __copy_to_user_ll
12917 - (void __user *to, const void *from, unsigned long n);
12918 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12919 unsigned long __must_check __copy_from_user_ll
12920 - (void *to, const void __user *from, unsigned long n);
12921 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12922 unsigned long __must_check __copy_from_user_ll_nozero
12923 - (void *to, const void __user *from, unsigned long n);
12924 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12925 unsigned long __must_check __copy_from_user_ll_nocache
12926 - (void *to, const void __user *from, unsigned long n);
12927 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12928 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12929 - (void *to, const void __user *from, unsigned long n);
12930 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12931
12932 /**
12933 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12934 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12935 static __always_inline unsigned long __must_check
12936 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12937 {
12938 + if ((long)n < 0)
12939 + return n;
12940 +
12941 if (__builtin_constant_p(n)) {
12942 unsigned long ret;
12943
12944 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12945 return ret;
12946 }
12947 }
12948 + if (!__builtin_constant_p(n))
12949 + check_object_size(from, n, true);
12950 return __copy_to_user_ll(to, from, n);
12951 }
12952
12953 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12954 __copy_to_user(void __user *to, const void *from, unsigned long n)
12955 {
12956 might_fault();
12957 +
12958 return __copy_to_user_inatomic(to, from, n);
12959 }
12960
12961 static __always_inline unsigned long
12962 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12963 {
12964 + if ((long)n < 0)
12965 + return n;
12966 +
12967 /* Avoid zeroing the tail if the copy fails..
12968 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12969 * but as the zeroing behaviour is only significant when n is not
12970 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12971 __copy_from_user(void *to, const void __user *from, unsigned long n)
12972 {
12973 might_fault();
12974 +
12975 + if ((long)n < 0)
12976 + return n;
12977 +
12978 if (__builtin_constant_p(n)) {
12979 unsigned long ret;
12980
12981 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12982 return ret;
12983 }
12984 }
12985 + if (!__builtin_constant_p(n))
12986 + check_object_size(to, n, false);
12987 return __copy_from_user_ll(to, from, n);
12988 }
12989
12990 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12991 const void __user *from, unsigned long n)
12992 {
12993 might_fault();
12994 +
12995 + if ((long)n < 0)
12996 + return n;
12997 +
12998 if (__builtin_constant_p(n)) {
12999 unsigned long ret;
13000
13001 @@ -181,15 +200,19 @@ static __always_inline unsigned long
13002 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
13003 unsigned long n)
13004 {
13005 - return __copy_from_user_ll_nocache_nozero(to, from, n);
13006 + if ((long)n < 0)
13007 + return n;
13008 +
13009 + return __copy_from_user_ll_nocache_nozero(to, from, n);
13010 }
13011
13012 -unsigned long __must_check copy_to_user(void __user *to,
13013 - const void *from, unsigned long n);
13014 -unsigned long __must_check _copy_from_user(void *to,
13015 - const void __user *from,
13016 - unsigned long n);
13017 -
13018 +extern void copy_to_user_overflow(void)
13019 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13020 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13021 +#else
13022 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13023 +#endif
13024 +;
13025
13026 extern void copy_from_user_overflow(void)
13027 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13028 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13029 #endif
13030 ;
13031
13032 -static inline unsigned long __must_check copy_from_user(void *to,
13033 - const void __user *from,
13034 - unsigned long n)
13035 +/**
13036 + * copy_to_user: - Copy a block of data into user space.
13037 + * @to: Destination address, in user space.
13038 + * @from: Source address, in kernel space.
13039 + * @n: Number of bytes to copy.
13040 + *
13041 + * Context: User context only. This function may sleep.
13042 + *
13043 + * Copy data from kernel space to user space.
13044 + *
13045 + * Returns number of bytes that could not be copied.
13046 + * On success, this will be zero.
13047 + */
13048 +static inline unsigned long __must_check
13049 +copy_to_user(void __user *to, const void *from, unsigned long n)
13050 {
13051 - int sz = __compiletime_object_size(to);
13052 + size_t sz = __compiletime_object_size(from);
13053
13054 - if (likely(sz == -1 || sz >= n))
13055 - n = _copy_from_user(to, from, n);
13056 - else
13057 + if (unlikely(sz != (size_t)-1 && sz < n))
13058 + copy_to_user_overflow();
13059 + else if (access_ok(VERIFY_WRITE, to, n))
13060 + n = __copy_to_user(to, from, n);
13061 + return n;
13062 +}
13063 +
13064 +/**
13065 + * copy_from_user: - Copy a block of data from user space.
13066 + * @to: Destination address, in kernel space.
13067 + * @from: Source address, in user space.
13068 + * @n: Number of bytes to copy.
13069 + *
13070 + * Context: User context only. This function may sleep.
13071 + *
13072 + * Copy data from user space to kernel space.
13073 + *
13074 + * Returns number of bytes that could not be copied.
13075 + * On success, this will be zero.
13076 + *
13077 + * If some data could not be copied, this function will pad the copied
13078 + * data to the requested size using zero bytes.
13079 + */
13080 +static inline unsigned long __must_check
13081 +copy_from_user(void *to, const void __user *from, unsigned long n)
13082 +{
13083 + size_t sz = __compiletime_object_size(to);
13084 +
13085 + if (unlikely(sz != (size_t)-1 && sz < n))
13086 copy_from_user_overflow();
13087 -
13088 + else if (access_ok(VERIFY_READ, from, n))
13089 + n = __copy_from_user(to, from, n);
13090 + else if ((long)n > 0) {
13091 + if (!__builtin_constant_p(n))
13092 + check_object_size(to, n, false);
13093 + memset(to, 0, n);
13094 + }
13095 return n;
13096 }
13097
13098 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13099 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13100 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13101 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13102
13103 #endif /* _ASM_X86_UACCESS_32_H */
13104 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13105 index d8def8b..ac7fc15 100644
13106 --- a/arch/x86/include/asm/uaccess_64.h
13107 +++ b/arch/x86/include/asm/uaccess_64.h
13108 @@ -10,6 +10,9 @@
13109 #include <asm/alternative.h>
13110 #include <asm/cpufeature.h>
13111 #include <asm/page.h>
13112 +#include <asm/pgtable.h>
13113 +
13114 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13115
13116 /*
13117 * Copy To/From Userspace
13118 @@ -17,13 +20,13 @@
13119
13120 /* Handles exceptions in both to and from, but doesn't do access_ok */
13121 __must_check unsigned long
13122 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
13123 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
13124 __must_check unsigned long
13125 -copy_user_generic_string(void *to, const void *from, unsigned len);
13126 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
13127 __must_check unsigned long
13128 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13129 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
13130
13131 -static __always_inline __must_check unsigned long
13132 +static __always_inline __must_check __size_overflow(3) unsigned long
13133 copy_user_generic(void *to, const void *from, unsigned len)
13134 {
13135 unsigned ret;
13136 @@ -41,142 +44,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13137 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13138 "=d" (len)),
13139 "1" (to), "2" (from), "3" (len)
13140 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13141 + : "memory", "rcx", "r8", "r9", "r11");
13142 return ret;
13143 }
13144
13145 +static __always_inline __must_check unsigned long
13146 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13147 +static __always_inline __must_check unsigned long
13148 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13149 __must_check unsigned long
13150 -_copy_to_user(void __user *to, const void *from, unsigned len);
13151 -__must_check unsigned long
13152 -_copy_from_user(void *to, const void __user *from, unsigned len);
13153 -__must_check unsigned long
13154 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13155 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13156 +
13157 +extern void copy_to_user_overflow(void)
13158 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13159 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13160 +#else
13161 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13162 +#endif
13163 +;
13164 +
13165 +extern void copy_from_user_overflow(void)
13166 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13167 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13168 +#else
13169 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13170 +#endif
13171 +;
13172
13173 static inline unsigned long __must_check copy_from_user(void *to,
13174 const void __user *from,
13175 unsigned long n)
13176 {
13177 - int sz = __compiletime_object_size(to);
13178 -
13179 might_fault();
13180 - if (likely(sz == -1 || sz >= n))
13181 - n = _copy_from_user(to, from, n);
13182 -#ifdef CONFIG_DEBUG_VM
13183 - else
13184 - WARN(1, "Buffer overflow detected!\n");
13185 -#endif
13186 +
13187 + if (access_ok(VERIFY_READ, from, n))
13188 + n = __copy_from_user(to, from, n);
13189 + else if (n < INT_MAX) {
13190 + if (!__builtin_constant_p(n))
13191 + check_object_size(to, n, false);
13192 + memset(to, 0, n);
13193 + }
13194 return n;
13195 }
13196
13197 static __always_inline __must_check
13198 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13199 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13200 {
13201 might_fault();
13202
13203 - return _copy_to_user(dst, src, size);
13204 + if (access_ok(VERIFY_WRITE, dst, size))
13205 + size = __copy_to_user(dst, src, size);
13206 + return size;
13207 }
13208
13209 static __always_inline __must_check
13210 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13211 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13212 {
13213 - int ret = 0;
13214 + size_t sz = __compiletime_object_size(dst);
13215 + unsigned ret = 0;
13216
13217 might_fault();
13218 - if (!__builtin_constant_p(size))
13219 - return copy_user_generic(dst, (__force void *)src, size);
13220 +
13221 + if (size > INT_MAX)
13222 + return size;
13223 +
13224 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13225 + if (!__access_ok(VERIFY_READ, src, size))
13226 + return size;
13227 +#endif
13228 +
13229 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13230 + copy_from_user_overflow();
13231 + return size;
13232 + }
13233 +
13234 + if (!__builtin_constant_p(size)) {
13235 + check_object_size(dst, size, false);
13236 +
13237 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13238 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13239 + src += PAX_USER_SHADOW_BASE;
13240 +#endif
13241 +
13242 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13243 + }
13244 switch (size) {
13245 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13246 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13247 ret, "b", "b", "=q", 1);
13248 return ret;
13249 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13250 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13251 ret, "w", "w", "=r", 2);
13252 return ret;
13253 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13254 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13255 ret, "l", "k", "=r", 4);
13256 return ret;
13257 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13258 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13259 ret, "q", "", "=r", 8);
13260 return ret;
13261 case 10:
13262 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13263 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13264 ret, "q", "", "=r", 10);
13265 if (unlikely(ret))
13266 return ret;
13267 __get_user_asm(*(u16 *)(8 + (char *)dst),
13268 - (u16 __user *)(8 + (char __user *)src),
13269 + (const u16 __user *)(8 + (const char __user *)src),
13270 ret, "w", "w", "=r", 2);
13271 return ret;
13272 case 16:
13273 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13274 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13275 ret, "q", "", "=r", 16);
13276 if (unlikely(ret))
13277 return ret;
13278 __get_user_asm(*(u64 *)(8 + (char *)dst),
13279 - (u64 __user *)(8 + (char __user *)src),
13280 + (const u64 __user *)(8 + (const char __user *)src),
13281 ret, "q", "", "=r", 8);
13282 return ret;
13283 default:
13284 - return copy_user_generic(dst, (__force void *)src, size);
13285 +
13286 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13287 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13288 + src += PAX_USER_SHADOW_BASE;
13289 +#endif
13290 +
13291 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13292 }
13293 }
13294
13295 static __always_inline __must_check
13296 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13297 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13298 {
13299 - int ret = 0;
13300 + size_t sz = __compiletime_object_size(src);
13301 + unsigned ret = 0;
13302
13303 might_fault();
13304 - if (!__builtin_constant_p(size))
13305 - return copy_user_generic((__force void *)dst, src, size);
13306 +
13307 + if (size > INT_MAX)
13308 + return size;
13309 +
13310 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13311 + if (!__access_ok(VERIFY_WRITE, dst, size))
13312 + return size;
13313 +#endif
13314 +
13315 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13316 + copy_to_user_overflow();
13317 + return size;
13318 + }
13319 +
13320 + if (!__builtin_constant_p(size)) {
13321 + check_object_size(src, size, true);
13322 +
13323 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13324 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13325 + dst += PAX_USER_SHADOW_BASE;
13326 +#endif
13327 +
13328 + return copy_user_generic((__force_kernel void *)dst, src, size);
13329 + }
13330 switch (size) {
13331 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13332 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13333 ret, "b", "b", "iq", 1);
13334 return ret;
13335 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13336 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13337 ret, "w", "w", "ir", 2);
13338 return ret;
13339 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13340 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13341 ret, "l", "k", "ir", 4);
13342 return ret;
13343 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13344 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13345 ret, "q", "", "er", 8);
13346 return ret;
13347 case 10:
13348 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13349 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13350 ret, "q", "", "er", 10);
13351 if (unlikely(ret))
13352 return ret;
13353 asm("":::"memory");
13354 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13355 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13356 ret, "w", "w", "ir", 2);
13357 return ret;
13358 case 16:
13359 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13360 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13361 ret, "q", "", "er", 16);
13362 if (unlikely(ret))
13363 return ret;
13364 asm("":::"memory");
13365 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13366 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13367 ret, "q", "", "er", 8);
13368 return ret;
13369 default:
13370 - return copy_user_generic((__force void *)dst, src, size);
13371 +
13372 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13373 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13374 + dst += PAX_USER_SHADOW_BASE;
13375 +#endif
13376 +
13377 + return copy_user_generic((__force_kernel void *)dst, src, size);
13378 }
13379 }
13380
13381 static __always_inline __must_check
13382 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13383 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13384 {
13385 - int ret = 0;
13386 + unsigned ret = 0;
13387
13388 might_fault();
13389 - if (!__builtin_constant_p(size))
13390 - return copy_user_generic((__force void *)dst,
13391 - (__force void *)src, size);
13392 +
13393 + if (size > INT_MAX)
13394 + return size;
13395 +
13396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13397 + if (!__access_ok(VERIFY_READ, src, size))
13398 + return size;
13399 + if (!__access_ok(VERIFY_WRITE, dst, size))
13400 + return size;
13401 +#endif
13402 +
13403 + if (!__builtin_constant_p(size)) {
13404 +
13405 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13406 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13407 + src += PAX_USER_SHADOW_BASE;
13408 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13409 + dst += PAX_USER_SHADOW_BASE;
13410 +#endif
13411 +
13412 + return copy_user_generic((__force_kernel void *)dst,
13413 + (__force_kernel const void *)src, size);
13414 + }
13415 switch (size) {
13416 case 1: {
13417 u8 tmp;
13418 - __get_user_asm(tmp, (u8 __user *)src,
13419 + __get_user_asm(tmp, (const u8 __user *)src,
13420 ret, "b", "b", "=q", 1);
13421 if (likely(!ret))
13422 __put_user_asm(tmp, (u8 __user *)dst,
13423 @@ -185,7 +284,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13424 }
13425 case 2: {
13426 u16 tmp;
13427 - __get_user_asm(tmp, (u16 __user *)src,
13428 + __get_user_asm(tmp, (const u16 __user *)src,
13429 ret, "w", "w", "=r", 2);
13430 if (likely(!ret))
13431 __put_user_asm(tmp, (u16 __user *)dst,
13432 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13433
13434 case 4: {
13435 u32 tmp;
13436 - __get_user_asm(tmp, (u32 __user *)src,
13437 + __get_user_asm(tmp, (const u32 __user *)src,
13438 ret, "l", "k", "=r", 4);
13439 if (likely(!ret))
13440 __put_user_asm(tmp, (u32 __user *)dst,
13441 @@ -204,7 +303,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13442 }
13443 case 8: {
13444 u64 tmp;
13445 - __get_user_asm(tmp, (u64 __user *)src,
13446 + __get_user_asm(tmp, (const u64 __user *)src,
13447 ret, "q", "", "=r", 8);
13448 if (likely(!ret))
13449 __put_user_asm(tmp, (u64 __user *)dst,
13450 @@ -212,44 +311,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13451 return ret;
13452 }
13453 default:
13454 - return copy_user_generic((__force void *)dst,
13455 - (__force void *)src, size);
13456 +
13457 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13458 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13459 + src += PAX_USER_SHADOW_BASE;
13460 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13461 + dst += PAX_USER_SHADOW_BASE;
13462 +#endif
13463 +
13464 + return copy_user_generic((__force_kernel void *)dst,
13465 + (__force_kernel const void *)src, size);
13466 }
13467 }
13468
13469 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13470 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13471 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13472 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13473
13474 static __must_check __always_inline int
13475 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13476 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13477 {
13478 - return copy_user_generic(dst, (__force const void *)src, size);
13479 + if (size > INT_MAX)
13480 + return size;
13481 +
13482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13483 + if (!__access_ok(VERIFY_READ, src, size))
13484 + return size;
13485 +
13486 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13487 + src += PAX_USER_SHADOW_BASE;
13488 +#endif
13489 +
13490 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13491 }
13492
13493 -static __must_check __always_inline int
13494 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13495 +static __must_check __always_inline unsigned long
13496 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13497 {
13498 - return copy_user_generic((__force void *)dst, src, size);
13499 + if (size > INT_MAX)
13500 + return size;
13501 +
13502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13503 + if (!__access_ok(VERIFY_WRITE, dst, size))
13504 + return size;
13505 +
13506 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13507 + dst += PAX_USER_SHADOW_BASE;
13508 +#endif
13509 +
13510 + return copy_user_generic((__force_kernel void *)dst, src, size);
13511 }
13512
13513 -extern long __copy_user_nocache(void *dst, const void __user *src,
13514 - unsigned size, int zerorest);
13515 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13516 + unsigned long size, int zerorest) __size_overflow(3);
13517
13518 -static inline int
13519 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13520 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13521 {
13522 might_sleep();
13523 +
13524 + if (size > INT_MAX)
13525 + return size;
13526 +
13527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13528 + if (!__access_ok(VERIFY_READ, src, size))
13529 + return size;
13530 +#endif
13531 +
13532 return __copy_user_nocache(dst, src, size, 1);
13533 }
13534
13535 -static inline int
13536 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13537 - unsigned size)
13538 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13539 + unsigned long size)
13540 {
13541 + if (size > INT_MAX)
13542 + return size;
13543 +
13544 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13545 + if (!__access_ok(VERIFY_READ, src, size))
13546 + return size;
13547 +#endif
13548 +
13549 return __copy_user_nocache(dst, src, size, 0);
13550 }
13551
13552 -unsigned long
13553 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13554 +extern unsigned long
13555 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13556
13557 #endif /* _ASM_X86_UACCESS_64_H */
13558 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13559 index bb05228..d763d5b 100644
13560 --- a/arch/x86/include/asm/vdso.h
13561 +++ b/arch/x86/include/asm/vdso.h
13562 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13563 #define VDSO32_SYMBOL(base, name) \
13564 ({ \
13565 extern const char VDSO32_##name[]; \
13566 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13567 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13568 })
13569 #endif
13570
13571 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13572 index 5b238981..77fdd78 100644
13573 --- a/arch/x86/include/asm/word-at-a-time.h
13574 +++ b/arch/x86/include/asm/word-at-a-time.h
13575 @@ -11,7 +11,7 @@
13576 * and shift, for example.
13577 */
13578 struct word_at_a_time {
13579 - const unsigned long one_bits, high_bits;
13580 + unsigned long one_bits, high_bits;
13581 };
13582
13583 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13584 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13585 index 38155f6..e4184ba 100644
13586 --- a/arch/x86/include/asm/x86_init.h
13587 +++ b/arch/x86/include/asm/x86_init.h
13588 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13589 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13590 void (*find_smp_config)(void);
13591 void (*get_smp_config)(unsigned int early);
13592 -};
13593 +} __no_const;
13594
13595 /**
13596 * struct x86_init_resources - platform specific resource related ops
13597 @@ -43,7 +43,7 @@ struct x86_init_resources {
13598 void (*probe_roms)(void);
13599 void (*reserve_resources)(void);
13600 char *(*memory_setup)(void);
13601 -};
13602 +} __no_const;
13603
13604 /**
13605 * struct x86_init_irqs - platform specific interrupt setup
13606 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13607 void (*pre_vector_init)(void);
13608 void (*intr_init)(void);
13609 void (*trap_init)(void);
13610 -};
13611 +} __no_const;
13612
13613 /**
13614 * struct x86_init_oem - oem platform specific customizing functions
13615 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13616 struct x86_init_oem {
13617 void (*arch_setup)(void);
13618 void (*banner)(void);
13619 -};
13620 +} __no_const;
13621
13622 /**
13623 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13624 @@ -77,7 +77,7 @@ struct x86_init_oem {
13625 */
13626 struct x86_init_mapping {
13627 void (*pagetable_reserve)(u64 start, u64 end);
13628 -};
13629 +} __no_const;
13630
13631 /**
13632 * struct x86_init_paging - platform specific paging functions
13633 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13634 struct x86_init_paging {
13635 void (*pagetable_setup_start)(pgd_t *base);
13636 void (*pagetable_setup_done)(pgd_t *base);
13637 -};
13638 +} __no_const;
13639
13640 /**
13641 * struct x86_init_timers - platform specific timer setup
13642 @@ -102,7 +102,7 @@ struct x86_init_timers {
13643 void (*tsc_pre_init)(void);
13644 void (*timer_init)(void);
13645 void (*wallclock_init)(void);
13646 -};
13647 +} __no_const;
13648
13649 /**
13650 * struct x86_init_iommu - platform specific iommu setup
13651 @@ -110,7 +110,7 @@ struct x86_init_timers {
13652 */
13653 struct x86_init_iommu {
13654 int (*iommu_init)(void);
13655 -};
13656 +} __no_const;
13657
13658 /**
13659 * struct x86_init_pci - platform specific pci init functions
13660 @@ -124,7 +124,7 @@ struct x86_init_pci {
13661 int (*init)(void);
13662 void (*init_irq)(void);
13663 void (*fixup_irqs)(void);
13664 -};
13665 +} __no_const;
13666
13667 /**
13668 * struct x86_init_ops - functions for platform specific setup
13669 @@ -140,7 +140,7 @@ struct x86_init_ops {
13670 struct x86_init_timers timers;
13671 struct x86_init_iommu iommu;
13672 struct x86_init_pci pci;
13673 -};
13674 +} __no_const;
13675
13676 /**
13677 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13678 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13679 void (*setup_percpu_clockev)(void);
13680 void (*early_percpu_clock_init)(void);
13681 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13682 -};
13683 +} __no_const;
13684
13685 /**
13686 * struct x86_platform_ops - platform specific runtime functions
13687 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13688 void (*save_sched_clock_state)(void);
13689 void (*restore_sched_clock_state)(void);
13690 void (*apic_post_init)(void);
13691 -};
13692 +} __no_const;
13693
13694 struct pci_dev;
13695
13696 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13697 void (*teardown_msi_irq)(unsigned int irq);
13698 void (*teardown_msi_irqs)(struct pci_dev *dev);
13699 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13700 -};
13701 +} __no_const;
13702
13703 struct x86_io_apic_ops {
13704 void (*init) (void);
13705 unsigned int (*read) (unsigned int apic, unsigned int reg);
13706 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13707 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13708 -};
13709 +} __no_const;
13710
13711 extern struct x86_init_ops x86_init;
13712 extern struct x86_cpuinit_ops x86_cpuinit;
13713 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13714 index 8a1b6f9..a29c4e4 100644
13715 --- a/arch/x86/include/asm/xsave.h
13716 +++ b/arch/x86/include/asm/xsave.h
13717 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13718 {
13719 int err;
13720
13721 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13722 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13723 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13724 +#endif
13725 +
13726 /*
13727 * Clear the xsave header first, so that reserved fields are
13728 * initialized to zero.
13729 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13730 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13731 {
13732 int err;
13733 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13734 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13735 u32 lmask = mask;
13736 u32 hmask = mask >> 32;
13737
13738 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13739 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13740 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13741 +#endif
13742 +
13743 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13744 "2:\n"
13745 ".section .fixup,\"ax\"\n"
13746 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13747 index 1b8e5a0..354fd59 100644
13748 --- a/arch/x86/kernel/acpi/sleep.c
13749 +++ b/arch/x86/kernel/acpi/sleep.c
13750 @@ -69,8 +69,12 @@ int acpi_suspend_lowlevel(void)
13751 #else /* CONFIG_64BIT */
13752 #ifdef CONFIG_SMP
13753 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13754 +
13755 + pax_open_kernel();
13756 early_gdt_descr.address =
13757 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13758 + pax_close_kernel();
13759 +
13760 initial_gs = per_cpu_offset(smp_processor_id());
13761 #endif
13762 initial_code = (unsigned long)wakeup_long64;
13763 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13764 index 13ab720..95d5442 100644
13765 --- a/arch/x86/kernel/acpi/wakeup_32.S
13766 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13767 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13768 # and restore the stack ... but you need gdt for this to work
13769 movl saved_context_esp, %esp
13770
13771 - movl %cs:saved_magic, %eax
13772 - cmpl $0x12345678, %eax
13773 + cmpl $0x12345678, saved_magic
13774 jne bogus_magic
13775
13776 # jump to place where we left off
13777 - movl saved_eip, %eax
13778 - jmp *%eax
13779 + jmp *(saved_eip)
13780
13781 bogus_magic:
13782 jmp bogus_magic
13783 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13784 index ced4534..3e75d69 100644
13785 --- a/arch/x86/kernel/alternative.c
13786 +++ b/arch/x86/kernel/alternative.c
13787 @@ -281,6 +281,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13788 */
13789 for (a = start; a < end; a++) {
13790 instr = (u8 *)&a->instr_offset + a->instr_offset;
13791 +
13792 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13793 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13794 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13795 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13796 +#endif
13797 +
13798 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13799 BUG_ON(a->replacementlen > a->instrlen);
13800 BUG_ON(a->instrlen > sizeof(insnbuf));
13801 @@ -312,10 +319,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13802 for (poff = start; poff < end; poff++) {
13803 u8 *ptr = (u8 *)poff + *poff;
13804
13805 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13806 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13807 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13808 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13809 +#endif
13810 +
13811 if (!*poff || ptr < text || ptr >= text_end)
13812 continue;
13813 /* turn DS segment override prefix into lock prefix */
13814 - if (*ptr == 0x3e)
13815 + if (*ktla_ktva(ptr) == 0x3e)
13816 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13817 };
13818 mutex_unlock(&text_mutex);
13819 @@ -333,10 +346,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13820 for (poff = start; poff < end; poff++) {
13821 u8 *ptr = (u8 *)poff + *poff;
13822
13823 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13824 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13825 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13826 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13827 +#endif
13828 +
13829 if (!*poff || ptr < text || ptr >= text_end)
13830 continue;
13831 /* turn lock prefix into DS segment override prefix */
13832 - if (*ptr == 0xf0)
13833 + if (*ktla_ktva(ptr) == 0xf0)
13834 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13835 };
13836 mutex_unlock(&text_mutex);
13837 @@ -505,7 +524,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13838
13839 BUG_ON(p->len > MAX_PATCH_LEN);
13840 /* prep the buffer with the original instructions */
13841 - memcpy(insnbuf, p->instr, p->len);
13842 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13843 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13844 (unsigned long)p->instr, p->len);
13845
13846 @@ -573,7 +592,7 @@ void __init alternative_instructions(void)
13847 if (smp_alt_once)
13848 free_init_pages("SMP alternatives",
13849 (unsigned long)__smp_locks,
13850 - (unsigned long)__smp_locks_end);
13851 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13852
13853 restart_nmi();
13854 }
13855 @@ -590,13 +609,17 @@ void __init alternative_instructions(void)
13856 * instructions. And on the local CPU you need to be protected again NMI or MCE
13857 * handlers seeing an inconsistent instruction while you patch.
13858 */
13859 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13860 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13861 size_t len)
13862 {
13863 unsigned long flags;
13864 local_irq_save(flags);
13865 - memcpy(addr, opcode, len);
13866 +
13867 + pax_open_kernel();
13868 + memcpy(ktla_ktva(addr), opcode, len);
13869 sync_core();
13870 + pax_close_kernel();
13871 +
13872 local_irq_restore(flags);
13873 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13874 that causes hangs on some VIA CPUs. */
13875 @@ -618,36 +641,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13876 */
13877 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13878 {
13879 - unsigned long flags;
13880 - char *vaddr;
13881 + unsigned char *vaddr = ktla_ktva(addr);
13882 struct page *pages[2];
13883 - int i;
13884 + size_t i;
13885
13886 if (!core_kernel_text((unsigned long)addr)) {
13887 - pages[0] = vmalloc_to_page(addr);
13888 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13889 + pages[0] = vmalloc_to_page(vaddr);
13890 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13891 } else {
13892 - pages[0] = virt_to_page(addr);
13893 + pages[0] = virt_to_page(vaddr);
13894 WARN_ON(!PageReserved(pages[0]));
13895 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13896 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13897 }
13898 BUG_ON(!pages[0]);
13899 - local_irq_save(flags);
13900 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13901 - if (pages[1])
13902 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13903 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13904 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13905 - clear_fixmap(FIX_TEXT_POKE0);
13906 - if (pages[1])
13907 - clear_fixmap(FIX_TEXT_POKE1);
13908 - local_flush_tlb();
13909 - sync_core();
13910 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13911 - that causes hangs on some VIA CPUs. */
13912 + text_poke_early(addr, opcode, len);
13913 for (i = 0; i < len; i++)
13914 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13915 - local_irq_restore(flags);
13916 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13917 return addr;
13918 }
13919
13920 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13921 index 24deb30..94a3426 100644
13922 --- a/arch/x86/kernel/apic/apic.c
13923 +++ b/arch/x86/kernel/apic/apic.c
13924 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13925 /*
13926 * Debug level, exported for io_apic.c
13927 */
13928 -unsigned int apic_verbosity;
13929 +int apic_verbosity;
13930
13931 int pic_mode;
13932
13933 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13934 apic_write(APIC_ESR, 0);
13935 v1 = apic_read(APIC_ESR);
13936 ack_APIC_irq();
13937 - atomic_inc(&irq_err_count);
13938 + atomic_inc_unchecked(&irq_err_count);
13939
13940 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13941 smp_processor_id(), v0 , v1);
13942 @@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
13943 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
13944 /* Should happen once for each apic */
13945 WARN_ON((*drv)->eoi_write == eoi_write);
13946 - (*drv)->eoi_write = eoi_write;
13947 + pax_open_kernel();
13948 + *(void **)&(*drv)->eoi_write = eoi_write;
13949 + pax_close_kernel();
13950 }
13951 }
13952
13953 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13954 index c265593..137c4ac 100644
13955 --- a/arch/x86/kernel/apic/io_apic.c
13956 +++ b/arch/x86/kernel/apic/io_apic.c
13957 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13958 }
13959 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13960
13961 -void lock_vector_lock(void)
13962 +void lock_vector_lock(void) __acquires(vector_lock)
13963 {
13964 /* Used to the online set of cpus does not change
13965 * during assign_irq_vector.
13966 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13967 raw_spin_lock(&vector_lock);
13968 }
13969
13970 -void unlock_vector_lock(void)
13971 +void unlock_vector_lock(void) __releases(vector_lock)
13972 {
13973 raw_spin_unlock(&vector_lock);
13974 }
13975 @@ -2408,7 +2408,7 @@ static void ack_apic_edge(struct irq_data *data)
13976 ack_APIC_irq();
13977 }
13978
13979 -atomic_t irq_mis_count;
13980 +atomic_unchecked_t irq_mis_count;
13981
13982 #ifdef CONFIG_GENERIC_PENDING_IRQ
13983 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13984 @@ -2549,7 +2549,7 @@ static void ack_apic_level(struct irq_data *data)
13985 * at the cpu.
13986 */
13987 if (!(v & (1 << (i & 0x1f)))) {
13988 - atomic_inc(&irq_mis_count);
13989 + atomic_inc_unchecked(&irq_mis_count);
13990
13991 eoi_ioapic_irq(irq, cfg);
13992 }
13993 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13994 index d65464e..1035d31 100644
13995 --- a/arch/x86/kernel/apm_32.c
13996 +++ b/arch/x86/kernel/apm_32.c
13997 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
13998 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13999 * even though they are called in protected mode.
14000 */
14001 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
14002 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
14003 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
14004
14005 static const char driver_version[] = "1.16ac"; /* no spaces */
14006 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
14007 BUG_ON(cpu != 0);
14008 gdt = get_cpu_gdt_table(cpu);
14009 save_desc_40 = gdt[0x40 / 8];
14010 +
14011 + pax_open_kernel();
14012 gdt[0x40 / 8] = bad_bios_desc;
14013 + pax_close_kernel();
14014
14015 apm_irq_save(flags);
14016 APM_DO_SAVE_SEGS;
14017 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
14018 &call->esi);
14019 APM_DO_RESTORE_SEGS;
14020 apm_irq_restore(flags);
14021 +
14022 + pax_open_kernel();
14023 gdt[0x40 / 8] = save_desc_40;
14024 + pax_close_kernel();
14025 +
14026 put_cpu();
14027
14028 return call->eax & 0xff;
14029 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
14030 BUG_ON(cpu != 0);
14031 gdt = get_cpu_gdt_table(cpu);
14032 save_desc_40 = gdt[0x40 / 8];
14033 +
14034 + pax_open_kernel();
14035 gdt[0x40 / 8] = bad_bios_desc;
14036 + pax_close_kernel();
14037
14038 apm_irq_save(flags);
14039 APM_DO_SAVE_SEGS;
14040 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
14041 &call->eax);
14042 APM_DO_RESTORE_SEGS;
14043 apm_irq_restore(flags);
14044 +
14045 + pax_open_kernel();
14046 gdt[0x40 / 8] = save_desc_40;
14047 + pax_close_kernel();
14048 +
14049 put_cpu();
14050 return error;
14051 }
14052 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14053 * code to that CPU.
14054 */
14055 gdt = get_cpu_gdt_table(0);
14056 +
14057 + pax_open_kernel();
14058 set_desc_base(&gdt[APM_CS >> 3],
14059 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14060 set_desc_base(&gdt[APM_CS_16 >> 3],
14061 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14062 set_desc_base(&gdt[APM_DS >> 3],
14063 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14064 + pax_close_kernel();
14065
14066 proc_create("apm", 0, NULL, &apm_file_ops);
14067
14068 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14069 index 68de2dc..1f3c720 100644
14070 --- a/arch/x86/kernel/asm-offsets.c
14071 +++ b/arch/x86/kernel/asm-offsets.c
14072 @@ -33,6 +33,8 @@ void common(void) {
14073 OFFSET(TI_status, thread_info, status);
14074 OFFSET(TI_addr_limit, thread_info, addr_limit);
14075 OFFSET(TI_preempt_count, thread_info, preempt_count);
14076 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14077 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14078
14079 BLANK();
14080 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14081 @@ -53,8 +55,26 @@ void common(void) {
14082 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14083 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14084 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14085 +
14086 +#ifdef CONFIG_PAX_KERNEXEC
14087 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14088 #endif
14089
14090 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14091 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14092 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14093 +#ifdef CONFIG_X86_64
14094 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14095 +#endif
14096 +#endif
14097 +
14098 +#endif
14099 +
14100 + BLANK();
14101 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14102 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14103 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14104 +
14105 #ifdef CONFIG_XEN
14106 BLANK();
14107 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14108 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14109 index 1b4754f..fbb4227 100644
14110 --- a/arch/x86/kernel/asm-offsets_64.c
14111 +++ b/arch/x86/kernel/asm-offsets_64.c
14112 @@ -76,6 +76,7 @@ int main(void)
14113 BLANK();
14114 #undef ENTRY
14115
14116 + DEFINE(TSS_size, sizeof(struct tss_struct));
14117 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14118 BLANK();
14119
14120 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14121 index d30a6a9..79becab 100644
14122 --- a/arch/x86/kernel/cpu/Makefile
14123 +++ b/arch/x86/kernel/cpu/Makefile
14124 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14125 CFLAGS_REMOVE_perf_event.o = -pg
14126 endif
14127
14128 -# Make sure load_percpu_segment has no stackprotector
14129 -nostackp := $(call cc-option, -fno-stack-protector)
14130 -CFLAGS_common.o := $(nostackp)
14131 -
14132 obj-y := intel_cacheinfo.o scattered.o topology.o
14133 obj-y += proc.o capflags.o powerflags.o common.o
14134 obj-y += vmware.o hypervisor.o mshyperv.o
14135 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14136 index 9d92e19..49d7d79 100644
14137 --- a/arch/x86/kernel/cpu/amd.c
14138 +++ b/arch/x86/kernel/cpu/amd.c
14139 @@ -724,7 +724,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14140 unsigned int size)
14141 {
14142 /* AMD errata T13 (order #21922) */
14143 - if ((c->x86 == 6)) {
14144 + if (c->x86 == 6) {
14145 /* Duron Rev A0 */
14146 if (c->x86_model == 3 && c->x86_mask == 0)
14147 size = 64;
14148 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14149 index a5fbc3c..2254849 100644
14150 --- a/arch/x86/kernel/cpu/common.c
14151 +++ b/arch/x86/kernel/cpu/common.c
14152 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14153
14154 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14155
14156 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14157 -#ifdef CONFIG_X86_64
14158 - /*
14159 - * We need valid kernel segments for data and code in long mode too
14160 - * IRET will check the segment types kkeil 2000/10/28
14161 - * Also sysret mandates a special GDT layout
14162 - *
14163 - * TLS descriptors are currently at a different place compared to i386.
14164 - * Hopefully nobody expects them at a fixed place (Wine?)
14165 - */
14166 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14167 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14168 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14169 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14170 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14171 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14172 -#else
14173 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14174 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14175 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14176 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14177 - /*
14178 - * Segments used for calling PnP BIOS have byte granularity.
14179 - * They code segments and data segments have fixed 64k limits,
14180 - * the transfer segment sizes are set at run time.
14181 - */
14182 - /* 32-bit code */
14183 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14184 - /* 16-bit code */
14185 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14186 - /* 16-bit data */
14187 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14188 - /* 16-bit data */
14189 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14190 - /* 16-bit data */
14191 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14192 - /*
14193 - * The APM segments have byte granularity and their bases
14194 - * are set at run time. All have 64k limits.
14195 - */
14196 - /* 32-bit code */
14197 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14198 - /* 16-bit code */
14199 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14200 - /* data */
14201 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14202 -
14203 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14204 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14205 - GDT_STACK_CANARY_INIT
14206 -#endif
14207 -} };
14208 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14209 -
14210 static int __init x86_xsave_setup(char *s)
14211 {
14212 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14213 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14214 {
14215 struct desc_ptr gdt_descr;
14216
14217 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14218 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14219 gdt_descr.size = GDT_SIZE - 1;
14220 load_gdt(&gdt_descr);
14221 /* Reload the per-cpu base */
14222 @@ -872,6 +818,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14223 /* Filter out anything that depends on CPUID levels we don't have */
14224 filter_cpuid_features(c, true);
14225
14226 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14227 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14228 +#endif
14229 +
14230 /* If the model name is still unset, do table lookup. */
14231 if (!c->x86_model_id[0]) {
14232 const char *p;
14233 @@ -1054,10 +1004,12 @@ static __init int setup_disablecpuid(char *arg)
14234 }
14235 __setup("clearcpuid=", setup_disablecpuid);
14236
14237 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14238 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14239 +
14240 #ifdef CONFIG_X86_64
14241 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14242 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14243 - (unsigned long) nmi_idt_table };
14244 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14245
14246 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14247 irq_stack_union) __aligned(PAGE_SIZE);
14248 @@ -1071,7 +1023,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14249 EXPORT_PER_CPU_SYMBOL(current_task);
14250
14251 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14252 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14253 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14254 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14255
14256 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14257 @@ -1165,7 +1117,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14258 {
14259 memset(regs, 0, sizeof(struct pt_regs));
14260 regs->fs = __KERNEL_PERCPU;
14261 - regs->gs = __KERNEL_STACK_CANARY;
14262 + savesegment(gs, regs->gs);
14263
14264 return regs;
14265 }
14266 @@ -1220,7 +1172,7 @@ void __cpuinit cpu_init(void)
14267 int i;
14268
14269 cpu = stack_smp_processor_id();
14270 - t = &per_cpu(init_tss, cpu);
14271 + t = init_tss + cpu;
14272 oist = &per_cpu(orig_ist, cpu);
14273
14274 #ifdef CONFIG_NUMA
14275 @@ -1246,7 +1198,7 @@ void __cpuinit cpu_init(void)
14276 switch_to_new_gdt(cpu);
14277 loadsegment(fs, 0);
14278
14279 - load_idt((const struct desc_ptr *)&idt_descr);
14280 + load_idt(&idt_descr);
14281
14282 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14283 syscall_init();
14284 @@ -1255,7 +1207,6 @@ void __cpuinit cpu_init(void)
14285 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14286 barrier();
14287
14288 - x86_configure_nx();
14289 if (cpu != 0)
14290 enable_x2apic();
14291
14292 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
14293 {
14294 int cpu = smp_processor_id();
14295 struct task_struct *curr = current;
14296 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14297 + struct tss_struct *t = init_tss + cpu;
14298 struct thread_struct *thread = &curr->thread;
14299
14300 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14301 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14302 index 0a4ce29..f211176 100644
14303 --- a/arch/x86/kernel/cpu/intel.c
14304 +++ b/arch/x86/kernel/cpu/intel.c
14305 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14306 * Update the IDT descriptor and reload the IDT so that
14307 * it uses the read-only mapped virtual address.
14308 */
14309 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14310 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14311 load_idt(&idt_descr);
14312 }
14313 #endif
14314 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14315 index 292d025..b520c94 100644
14316 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14317 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14318 @@ -45,6 +45,7 @@
14319 #include <asm/processor.h>
14320 #include <asm/mce.h>
14321 #include <asm/msr.h>
14322 +#include <asm/local.h>
14323
14324 #include "mce-internal.h"
14325
14326 @@ -253,7 +254,7 @@ static void print_mce(struct mce *m)
14327 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14328 m->cs, m->ip);
14329
14330 - if (m->cs == __KERNEL_CS)
14331 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14332 print_symbol("{%s}", m->ip);
14333 pr_cont("\n");
14334 }
14335 @@ -286,10 +287,10 @@ static void print_mce(struct mce *m)
14336
14337 #define PANIC_TIMEOUT 5 /* 5 seconds */
14338
14339 -static atomic_t mce_paniced;
14340 +static atomic_unchecked_t mce_paniced;
14341
14342 static int fake_panic;
14343 -static atomic_t mce_fake_paniced;
14344 +static atomic_unchecked_t mce_fake_paniced;
14345
14346 /* Panic in progress. Enable interrupts and wait for final IPI */
14347 static void wait_for_panic(void)
14348 @@ -313,7 +314,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14349 /*
14350 * Make sure only one CPU runs in machine check panic
14351 */
14352 - if (atomic_inc_return(&mce_paniced) > 1)
14353 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14354 wait_for_panic();
14355 barrier();
14356
14357 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14358 console_verbose();
14359 } else {
14360 /* Don't log too much for fake panic */
14361 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14362 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14363 return;
14364 }
14365 /* First print corrected ones that are still unlogged */
14366 @@ -693,7 +694,7 @@ static int mce_timed_out(u64 *t)
14367 * might have been modified by someone else.
14368 */
14369 rmb();
14370 - if (atomic_read(&mce_paniced))
14371 + if (atomic_read_unchecked(&mce_paniced))
14372 wait_for_panic();
14373 if (!monarch_timeout)
14374 goto out;
14375 @@ -1619,7 +1620,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14376 }
14377
14378 /* Call the installed machine check handler for this CPU setup. */
14379 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14380 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14381 unexpected_machine_check;
14382
14383 /*
14384 @@ -1642,7 +1643,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14385 return;
14386 }
14387
14388 + pax_open_kernel();
14389 machine_check_vector = do_machine_check;
14390 + pax_close_kernel();
14391
14392 __mcheck_cpu_init_generic();
14393 __mcheck_cpu_init_vendor(c);
14394 @@ -1656,7 +1659,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14395 */
14396
14397 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14398 -static int mce_chrdev_open_count; /* #times opened */
14399 +static local_t mce_chrdev_open_count; /* #times opened */
14400 static int mce_chrdev_open_exclu; /* already open exclusive? */
14401
14402 static int mce_chrdev_open(struct inode *inode, struct file *file)
14403 @@ -1664,7 +1667,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14404 spin_lock(&mce_chrdev_state_lock);
14405
14406 if (mce_chrdev_open_exclu ||
14407 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14408 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14409 spin_unlock(&mce_chrdev_state_lock);
14410
14411 return -EBUSY;
14412 @@ -1672,7 +1675,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14413
14414 if (file->f_flags & O_EXCL)
14415 mce_chrdev_open_exclu = 1;
14416 - mce_chrdev_open_count++;
14417 + local_inc(&mce_chrdev_open_count);
14418
14419 spin_unlock(&mce_chrdev_state_lock);
14420
14421 @@ -1683,7 +1686,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14422 {
14423 spin_lock(&mce_chrdev_state_lock);
14424
14425 - mce_chrdev_open_count--;
14426 + local_dec(&mce_chrdev_open_count);
14427 mce_chrdev_open_exclu = 0;
14428
14429 spin_unlock(&mce_chrdev_state_lock);
14430 @@ -2407,7 +2410,7 @@ struct dentry *mce_get_debugfs_dir(void)
14431 static void mce_reset(void)
14432 {
14433 cpu_missing = 0;
14434 - atomic_set(&mce_fake_paniced, 0);
14435 + atomic_set_unchecked(&mce_fake_paniced, 0);
14436 atomic_set(&mce_executing, 0);
14437 atomic_set(&mce_callin, 0);
14438 atomic_set(&global_nwo, 0);
14439 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14440 index 2d5454c..51987eb 100644
14441 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14442 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14443 @@ -11,6 +11,7 @@
14444 #include <asm/processor.h>
14445 #include <asm/mce.h>
14446 #include <asm/msr.h>
14447 +#include <asm/pgtable.h>
14448
14449 /* By default disabled */
14450 int mce_p5_enabled __read_mostly;
14451 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14452 if (!cpu_has(c, X86_FEATURE_MCE))
14453 return;
14454
14455 + pax_open_kernel();
14456 machine_check_vector = pentium_machine_check;
14457 + pax_close_kernel();
14458 /* Make sure the vector pointer is visible before we enable MCEs: */
14459 wmb();
14460
14461 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14462 index 2d7998f..17c9de1 100644
14463 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14464 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14465 @@ -10,6 +10,7 @@
14466 #include <asm/processor.h>
14467 #include <asm/mce.h>
14468 #include <asm/msr.h>
14469 +#include <asm/pgtable.h>
14470
14471 /* Machine check handler for WinChip C6: */
14472 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14473 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14474 {
14475 u32 lo, hi;
14476
14477 + pax_open_kernel();
14478 machine_check_vector = winchip_machine_check;
14479 + pax_close_kernel();
14480 /* Make sure the vector pointer is visible before we enable MCEs: */
14481 wmb();
14482
14483 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14484 index 6b96110..0da73eb 100644
14485 --- a/arch/x86/kernel/cpu/mtrr/main.c
14486 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14487 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14488 u64 size_or_mask, size_and_mask;
14489 static bool mtrr_aps_delayed_init;
14490
14491 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14492 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14493
14494 const struct mtrr_ops *mtrr_if;
14495
14496 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14497 index df5e41f..816c719 100644
14498 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14499 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14500 @@ -25,7 +25,7 @@ struct mtrr_ops {
14501 int (*validate_add_page)(unsigned long base, unsigned long size,
14502 unsigned int type);
14503 int (*have_wrcomb)(void);
14504 -};
14505 +} __do_const;
14506
14507 extern int generic_get_free_region(unsigned long base, unsigned long size,
14508 int replace_reg);
14509 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14510 index 915b876..171f845 100644
14511 --- a/arch/x86/kernel/cpu/perf_event.c
14512 +++ b/arch/x86/kernel/cpu/perf_event.c
14513 @@ -1757,7 +1757,7 @@ static unsigned long get_segment_base(unsigned int segment)
14514 if (idx > GDT_ENTRIES)
14515 return 0;
14516
14517 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
14518 + desc = get_cpu_gdt_table(smp_processor_id());
14519 }
14520
14521 return get_desc_base(desc + idx);
14522 @@ -1847,7 +1847,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14523 break;
14524
14525 perf_callchain_store(entry, frame.return_address);
14526 - fp = frame.next_frame;
14527 + fp = (const void __force_user *)frame.next_frame;
14528 }
14529 }
14530
14531 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14532 index 6bca492..36e4496 100644
14533 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14534 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14535 @@ -1947,10 +1947,10 @@ __init int intel_pmu_init(void)
14536 * v2 and above have a perf capabilities MSR
14537 */
14538 if (version > 1) {
14539 - u64 capabilities;
14540 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14541
14542 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14543 - x86_pmu.intel_cap.capabilities = capabilities;
14544 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14545 + x86_pmu.intel_cap.capabilities = capabilities;
14546 }
14547
14548 intel_ds_init();
14549 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14550 index 13ad899..f642b9a 100644
14551 --- a/arch/x86/kernel/crash.c
14552 +++ b/arch/x86/kernel/crash.c
14553 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14554 {
14555 #ifdef CONFIG_X86_32
14556 struct pt_regs fixed_regs;
14557 -#endif
14558
14559 -#ifdef CONFIG_X86_32
14560 - if (!user_mode_vm(regs)) {
14561 + if (!user_mode(regs)) {
14562 crash_fixup_ss_esp(&fixed_regs, regs);
14563 regs = &fixed_regs;
14564 }
14565 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14566 index 37250fe..bf2ec74 100644
14567 --- a/arch/x86/kernel/doublefault_32.c
14568 +++ b/arch/x86/kernel/doublefault_32.c
14569 @@ -11,7 +11,7 @@
14570
14571 #define DOUBLEFAULT_STACKSIZE (1024)
14572 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14573 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14574 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14575
14576 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14577
14578 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14579 unsigned long gdt, tss;
14580
14581 store_gdt(&gdt_desc);
14582 - gdt = gdt_desc.address;
14583 + gdt = (unsigned long)gdt_desc.address;
14584
14585 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14586
14587 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14588 /* 0x2 bit is always set */
14589 .flags = X86_EFLAGS_SF | 0x2,
14590 .sp = STACK_START,
14591 - .es = __USER_DS,
14592 + .es = __KERNEL_DS,
14593 .cs = __KERNEL_CS,
14594 .ss = __KERNEL_DS,
14595 - .ds = __USER_DS,
14596 + .ds = __KERNEL_DS,
14597 .fs = __KERNEL_PERCPU,
14598
14599 .__cr3 = __pa_nodebug(swapper_pg_dir),
14600 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14601 index ae42418b..787c16b 100644
14602 --- a/arch/x86/kernel/dumpstack.c
14603 +++ b/arch/x86/kernel/dumpstack.c
14604 @@ -2,6 +2,9 @@
14605 * Copyright (C) 1991, 1992 Linus Torvalds
14606 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14607 */
14608 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14609 +#define __INCLUDED_BY_HIDESYM 1
14610 +#endif
14611 #include <linux/kallsyms.h>
14612 #include <linux/kprobes.h>
14613 #include <linux/uaccess.h>
14614 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14615 static void
14616 print_ftrace_graph_addr(unsigned long addr, void *data,
14617 const struct stacktrace_ops *ops,
14618 - struct thread_info *tinfo, int *graph)
14619 + struct task_struct *task, int *graph)
14620 {
14621 - struct task_struct *task;
14622 unsigned long ret_addr;
14623 int index;
14624
14625 if (addr != (unsigned long)return_to_handler)
14626 return;
14627
14628 - task = tinfo->task;
14629 index = task->curr_ret_stack;
14630
14631 if (!task->ret_stack || index < *graph)
14632 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14633 static inline void
14634 print_ftrace_graph_addr(unsigned long addr, void *data,
14635 const struct stacktrace_ops *ops,
14636 - struct thread_info *tinfo, int *graph)
14637 + struct task_struct *task, int *graph)
14638 { }
14639 #endif
14640
14641 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14642 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14643 */
14644
14645 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14646 - void *p, unsigned int size, void *end)
14647 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14648 {
14649 - void *t = tinfo;
14650 if (end) {
14651 if (p < end && p >= (end-THREAD_SIZE))
14652 return 1;
14653 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14654 }
14655
14656 unsigned long
14657 -print_context_stack(struct thread_info *tinfo,
14658 +print_context_stack(struct task_struct *task, void *stack_start,
14659 unsigned long *stack, unsigned long bp,
14660 const struct stacktrace_ops *ops, void *data,
14661 unsigned long *end, int *graph)
14662 {
14663 struct stack_frame *frame = (struct stack_frame *)bp;
14664
14665 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14666 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14667 unsigned long addr;
14668
14669 addr = *stack;
14670 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14671 } else {
14672 ops->address(data, addr, 0);
14673 }
14674 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14675 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14676 }
14677 stack++;
14678 }
14679 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14680 EXPORT_SYMBOL_GPL(print_context_stack);
14681
14682 unsigned long
14683 -print_context_stack_bp(struct thread_info *tinfo,
14684 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14685 unsigned long *stack, unsigned long bp,
14686 const struct stacktrace_ops *ops, void *data,
14687 unsigned long *end, int *graph)
14688 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14689 struct stack_frame *frame = (struct stack_frame *)bp;
14690 unsigned long *ret_addr = &frame->return_address;
14691
14692 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14693 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14694 unsigned long addr = *ret_addr;
14695
14696 if (!__kernel_text_address(addr))
14697 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14698 ops->address(data, addr, 1);
14699 frame = frame->next_frame;
14700 ret_addr = &frame->return_address;
14701 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14702 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14703 }
14704
14705 return (unsigned long)frame;
14706 @@ -189,7 +188,7 @@ void dump_stack(void)
14707
14708 bp = stack_frame(current, NULL);
14709 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14710 - current->pid, current->comm, print_tainted(),
14711 + task_pid_nr(current), current->comm, print_tainted(),
14712 init_utsname()->release,
14713 (int)strcspn(init_utsname()->version, " "),
14714 init_utsname()->version);
14715 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14716 }
14717 EXPORT_SYMBOL_GPL(oops_begin);
14718
14719 +extern void gr_handle_kernel_exploit(void);
14720 +
14721 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14722 {
14723 if (regs && kexec_should_crash(current))
14724 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14725 panic("Fatal exception in interrupt");
14726 if (panic_on_oops)
14727 panic("Fatal exception");
14728 - do_exit(signr);
14729 +
14730 + gr_handle_kernel_exploit();
14731 +
14732 + do_group_exit(signr);
14733 }
14734
14735 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14736 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14737 print_modules();
14738 show_regs(regs);
14739 #ifdef CONFIG_X86_32
14740 - if (user_mode_vm(regs)) {
14741 + if (user_mode(regs)) {
14742 sp = regs->sp;
14743 ss = regs->ss & 0xffff;
14744 } else {
14745 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14746 unsigned long flags = oops_begin();
14747 int sig = SIGSEGV;
14748
14749 - if (!user_mode_vm(regs))
14750 + if (!user_mode(regs))
14751 report_bug(regs->ip, regs);
14752
14753 if (__die(str, regs, err))
14754 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14755 index 1038a41..ac7e5f6 100644
14756 --- a/arch/x86/kernel/dumpstack_32.c
14757 +++ b/arch/x86/kernel/dumpstack_32.c
14758 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14759 bp = stack_frame(task, regs);
14760
14761 for (;;) {
14762 - struct thread_info *context;
14763 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14764
14765 - context = (struct thread_info *)
14766 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14767 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14768 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14769
14770 - stack = (unsigned long *)context->previous_esp;
14771 - if (!stack)
14772 + if (stack_start == task_stack_page(task))
14773 break;
14774 + stack = *(unsigned long **)stack_start;
14775 if (ops->stack(data, "IRQ") < 0)
14776 break;
14777 touch_nmi_watchdog();
14778 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
14779 {
14780 int i;
14781
14782 - __show_regs(regs, !user_mode_vm(regs));
14783 + __show_regs(regs, !user_mode(regs));
14784
14785 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14786 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14787 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
14788 * When in-kernel, we also print out the stack and code at the
14789 * time of the fault..
14790 */
14791 - if (!user_mode_vm(regs)) {
14792 + if (!user_mode(regs)) {
14793 unsigned int code_prologue = code_bytes * 43 / 64;
14794 unsigned int code_len = code_bytes;
14795 unsigned char c;
14796 u8 *ip;
14797 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14798
14799 pr_emerg("Stack:\n");
14800 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14801
14802 pr_emerg("Code:");
14803
14804 - ip = (u8 *)regs->ip - code_prologue;
14805 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14806 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14807 /* try starting at IP */
14808 - ip = (u8 *)regs->ip;
14809 + ip = (u8 *)regs->ip + cs_base;
14810 code_len = code_len - code_prologue + 1;
14811 }
14812 for (i = 0; i < code_len; i++, ip++) {
14813 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
14814 pr_cont(" Bad EIP value.");
14815 break;
14816 }
14817 - if (ip == (u8 *)regs->ip)
14818 + if (ip == (u8 *)regs->ip + cs_base)
14819 pr_cont(" <%02x>", c);
14820 else
14821 pr_cont(" %02x", c);
14822 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
14823 {
14824 unsigned short ud2;
14825
14826 + ip = ktla_ktva(ip);
14827 if (ip < PAGE_OFFSET)
14828 return 0;
14829 if (probe_kernel_address((unsigned short *)ip, ud2))
14830 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
14831
14832 return ud2 == 0x0b0f;
14833 }
14834 +
14835 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14836 +void pax_check_alloca(unsigned long size)
14837 +{
14838 + unsigned long sp = (unsigned long)&sp, stack_left;
14839 +
14840 + /* all kernel stacks are of the same size */
14841 + stack_left = sp & (THREAD_SIZE - 1);
14842 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14843 +}
14844 +EXPORT_SYMBOL(pax_check_alloca);
14845 +#endif
14846 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14847 index b653675..33190c0 100644
14848 --- a/arch/x86/kernel/dumpstack_64.c
14849 +++ b/arch/x86/kernel/dumpstack_64.c
14850 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14851 unsigned long *irq_stack_end =
14852 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14853 unsigned used = 0;
14854 - struct thread_info *tinfo;
14855 int graph = 0;
14856 unsigned long dummy;
14857 + void *stack_start;
14858
14859 if (!task)
14860 task = current;
14861 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14862 * current stack address. If the stacks consist of nested
14863 * exceptions
14864 */
14865 - tinfo = task_thread_info(task);
14866 for (;;) {
14867 char *id;
14868 unsigned long *estack_end;
14869 +
14870 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14871 &used, &id);
14872
14873 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 if (ops->stack(data, id) < 0)
14875 break;
14876
14877 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14878 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14879 data, estack_end, &graph);
14880 ops->stack(data, "<EOE>");
14881 /*
14882 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14883 * second-to-last pointer (index -2 to end) in the
14884 * exception stack:
14885 */
14886 + if ((u16)estack_end[-1] != __KERNEL_DS)
14887 + goto out;
14888 stack = (unsigned long *) estack_end[-2];
14889 continue;
14890 }
14891 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14892 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14893 if (ops->stack(data, "IRQ") < 0)
14894 break;
14895 - bp = ops->walk_stack(tinfo, stack, bp,
14896 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14897 ops, data, irq_stack_end, &graph);
14898 /*
14899 * We link to the next stack (which would be
14900 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14901 /*
14902 * This handles the process stack:
14903 */
14904 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14905 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14906 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14907 +out:
14908 put_cpu();
14909 }
14910 EXPORT_SYMBOL(dump_trace);
14911 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
14912
14913 return ud2 == 0x0b0f;
14914 }
14915 +
14916 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14917 +void pax_check_alloca(unsigned long size)
14918 +{
14919 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14920 + unsigned cpu, used;
14921 + char *id;
14922 +
14923 + /* check the process stack first */
14924 + stack_start = (unsigned long)task_stack_page(current);
14925 + stack_end = stack_start + THREAD_SIZE;
14926 + if (likely(stack_start <= sp && sp < stack_end)) {
14927 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14928 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14929 + return;
14930 + }
14931 +
14932 + cpu = get_cpu();
14933 +
14934 + /* check the irq stacks */
14935 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14936 + stack_start = stack_end - IRQ_STACK_SIZE;
14937 + if (stack_start <= sp && sp < stack_end) {
14938 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14939 + put_cpu();
14940 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14941 + return;
14942 + }
14943 +
14944 + /* check the exception stacks */
14945 + used = 0;
14946 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14947 + stack_start = stack_end - EXCEPTION_STKSZ;
14948 + if (stack_end && stack_start <= sp && sp < stack_end) {
14949 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14950 + put_cpu();
14951 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14952 + return;
14953 + }
14954 +
14955 + put_cpu();
14956 +
14957 + /* unknown stack */
14958 + BUG();
14959 +}
14960 +EXPORT_SYMBOL(pax_check_alloca);
14961 +#endif
14962 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14963 index 9b9f18b..9fcaa04 100644
14964 --- a/arch/x86/kernel/early_printk.c
14965 +++ b/arch/x86/kernel/early_printk.c
14966 @@ -7,6 +7,7 @@
14967 #include <linux/pci_regs.h>
14968 #include <linux/pci_ids.h>
14969 #include <linux/errno.h>
14970 +#include <linux/sched.h>
14971 #include <asm/io.h>
14972 #include <asm/processor.h>
14973 #include <asm/fcntl.h>
14974 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14975 index 623f288..8bdd78a 100644
14976 --- a/arch/x86/kernel/entry_32.S
14977 +++ b/arch/x86/kernel/entry_32.S
14978 @@ -176,13 +176,153 @@
14979 /*CFI_REL_OFFSET gs, PT_GS*/
14980 .endm
14981 .macro SET_KERNEL_GS reg
14982 +
14983 +#ifdef CONFIG_CC_STACKPROTECTOR
14984 movl $(__KERNEL_STACK_CANARY), \reg
14985 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14986 + movl $(__USER_DS), \reg
14987 +#else
14988 + xorl \reg, \reg
14989 +#endif
14990 +
14991 movl \reg, %gs
14992 .endm
14993
14994 #endif /* CONFIG_X86_32_LAZY_GS */
14995
14996 -.macro SAVE_ALL
14997 +.macro pax_enter_kernel
14998 +#ifdef CONFIG_PAX_KERNEXEC
14999 + call pax_enter_kernel
15000 +#endif
15001 +.endm
15002 +
15003 +.macro pax_exit_kernel
15004 +#ifdef CONFIG_PAX_KERNEXEC
15005 + call pax_exit_kernel
15006 +#endif
15007 +.endm
15008 +
15009 +#ifdef CONFIG_PAX_KERNEXEC
15010 +ENTRY(pax_enter_kernel)
15011 +#ifdef CONFIG_PARAVIRT
15012 + pushl %eax
15013 + pushl %ecx
15014 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
15015 + mov %eax, %esi
15016 +#else
15017 + mov %cr0, %esi
15018 +#endif
15019 + bts $16, %esi
15020 + jnc 1f
15021 + mov %cs, %esi
15022 + cmp $__KERNEL_CS, %esi
15023 + jz 3f
15024 + ljmp $__KERNEL_CS, $3f
15025 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
15026 +2:
15027 +#ifdef CONFIG_PARAVIRT
15028 + mov %esi, %eax
15029 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15030 +#else
15031 + mov %esi, %cr0
15032 +#endif
15033 +3:
15034 +#ifdef CONFIG_PARAVIRT
15035 + popl %ecx
15036 + popl %eax
15037 +#endif
15038 + ret
15039 +ENDPROC(pax_enter_kernel)
15040 +
15041 +ENTRY(pax_exit_kernel)
15042 +#ifdef CONFIG_PARAVIRT
15043 + pushl %eax
15044 + pushl %ecx
15045 +#endif
15046 + mov %cs, %esi
15047 + cmp $__KERNEXEC_KERNEL_CS, %esi
15048 + jnz 2f
15049 +#ifdef CONFIG_PARAVIRT
15050 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15051 + mov %eax, %esi
15052 +#else
15053 + mov %cr0, %esi
15054 +#endif
15055 + btr $16, %esi
15056 + ljmp $__KERNEL_CS, $1f
15057 +1:
15058 +#ifdef CONFIG_PARAVIRT
15059 + mov %esi, %eax
15060 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15061 +#else
15062 + mov %esi, %cr0
15063 +#endif
15064 +2:
15065 +#ifdef CONFIG_PARAVIRT
15066 + popl %ecx
15067 + popl %eax
15068 +#endif
15069 + ret
15070 +ENDPROC(pax_exit_kernel)
15071 +#endif
15072 +
15073 +.macro pax_erase_kstack
15074 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15075 + call pax_erase_kstack
15076 +#endif
15077 +.endm
15078 +
15079 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15080 +/*
15081 + * ebp: thread_info
15082 + */
15083 +ENTRY(pax_erase_kstack)
15084 + pushl %edi
15085 + pushl %ecx
15086 + pushl %eax
15087 +
15088 + mov TI_lowest_stack(%ebp), %edi
15089 + mov $-0xBEEF, %eax
15090 + std
15091 +
15092 +1: mov %edi, %ecx
15093 + and $THREAD_SIZE_asm - 1, %ecx
15094 + shr $2, %ecx
15095 + repne scasl
15096 + jecxz 2f
15097 +
15098 + cmp $2*16, %ecx
15099 + jc 2f
15100 +
15101 + mov $2*16, %ecx
15102 + repe scasl
15103 + jecxz 2f
15104 + jne 1b
15105 +
15106 +2: cld
15107 + mov %esp, %ecx
15108 + sub %edi, %ecx
15109 +
15110 + cmp $THREAD_SIZE_asm, %ecx
15111 + jb 3f
15112 + ud2
15113 +3:
15114 +
15115 + shr $2, %ecx
15116 + rep stosl
15117 +
15118 + mov TI_task_thread_sp0(%ebp), %edi
15119 + sub $128, %edi
15120 + mov %edi, TI_lowest_stack(%ebp)
15121 +
15122 + popl %eax
15123 + popl %ecx
15124 + popl %edi
15125 + ret
15126 +ENDPROC(pax_erase_kstack)
15127 +#endif
15128 +
15129 +.macro __SAVE_ALL _DS
15130 cld
15131 PUSH_GS
15132 pushl_cfi %fs
15133 @@ -205,7 +345,7 @@
15134 CFI_REL_OFFSET ecx, 0
15135 pushl_cfi %ebx
15136 CFI_REL_OFFSET ebx, 0
15137 - movl $(__USER_DS), %edx
15138 + movl $\_DS, %edx
15139 movl %edx, %ds
15140 movl %edx, %es
15141 movl $(__KERNEL_PERCPU), %edx
15142 @@ -213,6 +353,15 @@
15143 SET_KERNEL_GS %edx
15144 .endm
15145
15146 +.macro SAVE_ALL
15147 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15148 + __SAVE_ALL __KERNEL_DS
15149 + pax_enter_kernel
15150 +#else
15151 + __SAVE_ALL __USER_DS
15152 +#endif
15153 +.endm
15154 +
15155 .macro RESTORE_INT_REGS
15156 popl_cfi %ebx
15157 CFI_RESTORE ebx
15158 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15159 popfl_cfi
15160 jmp syscall_exit
15161 CFI_ENDPROC
15162 -END(ret_from_fork)
15163 +ENDPROC(ret_from_fork)
15164
15165 /*
15166 * Interrupt exit functions should be protected against kprobes
15167 @@ -329,7 +478,15 @@ ret_from_intr:
15168 andl $SEGMENT_RPL_MASK, %eax
15169 #endif
15170 cmpl $USER_RPL, %eax
15171 +
15172 +#ifdef CONFIG_PAX_KERNEXEC
15173 + jae resume_userspace
15174 +
15175 + pax_exit_kernel
15176 + jmp resume_kernel
15177 +#else
15178 jb resume_kernel # not returning to v8086 or userspace
15179 +#endif
15180
15181 ENTRY(resume_userspace)
15182 LOCKDEP_SYS_EXIT
15183 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15184 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15185 # int/exception return?
15186 jne work_pending
15187 - jmp restore_all
15188 -END(ret_from_exception)
15189 + jmp restore_all_pax
15190 +ENDPROC(ret_from_exception)
15191
15192 #ifdef CONFIG_PREEMPT
15193 ENTRY(resume_kernel)
15194 @@ -357,7 +514,7 @@ need_resched:
15195 jz restore_all
15196 call preempt_schedule_irq
15197 jmp need_resched
15198 -END(resume_kernel)
15199 +ENDPROC(resume_kernel)
15200 #endif
15201 CFI_ENDPROC
15202 /*
15203 @@ -391,28 +548,43 @@ sysenter_past_esp:
15204 /*CFI_REL_OFFSET cs, 0*/
15205 /*
15206 * Push current_thread_info()->sysenter_return to the stack.
15207 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15208 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15209 */
15210 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15211 + pushl_cfi $0
15212 CFI_REL_OFFSET eip, 0
15213
15214 pushl_cfi %eax
15215 SAVE_ALL
15216 + GET_THREAD_INFO(%ebp)
15217 + movl TI_sysenter_return(%ebp),%ebp
15218 + movl %ebp,PT_EIP(%esp)
15219 ENABLE_INTERRUPTS(CLBR_NONE)
15220
15221 /*
15222 * Load the potential sixth argument from user stack.
15223 * Careful about security.
15224 */
15225 + movl PT_OLDESP(%esp),%ebp
15226 +
15227 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15228 + mov PT_OLDSS(%esp),%ds
15229 +1: movl %ds:(%ebp),%ebp
15230 + push %ss
15231 + pop %ds
15232 +#else
15233 cmpl $__PAGE_OFFSET-3,%ebp
15234 jae syscall_fault
15235 1: movl (%ebp),%ebp
15236 +#endif
15237 +
15238 movl %ebp,PT_EBP(%esp)
15239 _ASM_EXTABLE(1b,syscall_fault)
15240
15241 GET_THREAD_INFO(%ebp)
15242
15243 +#ifdef CONFIG_PAX_RANDKSTACK
15244 + pax_erase_kstack
15245 +#endif
15246 +
15247 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15248 jnz sysenter_audit
15249 sysenter_do_call:
15250 @@ -427,12 +599,24 @@ sysenter_do_call:
15251 testl $_TIF_ALLWORK_MASK, %ecx
15252 jne sysexit_audit
15253 sysenter_exit:
15254 +
15255 +#ifdef CONFIG_PAX_RANDKSTACK
15256 + pushl_cfi %eax
15257 + movl %esp, %eax
15258 + call pax_randomize_kstack
15259 + popl_cfi %eax
15260 +#endif
15261 +
15262 + pax_erase_kstack
15263 +
15264 /* if something modifies registers it must also disable sysexit */
15265 movl PT_EIP(%esp), %edx
15266 movl PT_OLDESP(%esp), %ecx
15267 xorl %ebp,%ebp
15268 TRACE_IRQS_ON
15269 1: mov PT_FS(%esp), %fs
15270 +2: mov PT_DS(%esp), %ds
15271 +3: mov PT_ES(%esp), %es
15272 PTGS_TO_GS
15273 ENABLE_INTERRUPTS_SYSEXIT
15274
15275 @@ -449,6 +633,9 @@ sysenter_audit:
15276 movl %eax,%edx /* 2nd arg: syscall number */
15277 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15278 call __audit_syscall_entry
15279 +
15280 + pax_erase_kstack
15281 +
15282 pushl_cfi %ebx
15283 movl PT_EAX(%esp),%eax /* reload syscall number */
15284 jmp sysenter_do_call
15285 @@ -474,10 +661,16 @@ sysexit_audit:
15286
15287 CFI_ENDPROC
15288 .pushsection .fixup,"ax"
15289 -2: movl $0,PT_FS(%esp)
15290 +4: movl $0,PT_FS(%esp)
15291 + jmp 1b
15292 +5: movl $0,PT_DS(%esp)
15293 + jmp 1b
15294 +6: movl $0,PT_ES(%esp)
15295 jmp 1b
15296 .popsection
15297 - _ASM_EXTABLE(1b,2b)
15298 + _ASM_EXTABLE(1b,4b)
15299 + _ASM_EXTABLE(2b,5b)
15300 + _ASM_EXTABLE(3b,6b)
15301 PTGS_TO_GS_EX
15302 ENDPROC(ia32_sysenter_target)
15303
15304 @@ -491,6 +684,11 @@ ENTRY(system_call)
15305 pushl_cfi %eax # save orig_eax
15306 SAVE_ALL
15307 GET_THREAD_INFO(%ebp)
15308 +
15309 +#ifdef CONFIG_PAX_RANDKSTACK
15310 + pax_erase_kstack
15311 +#endif
15312 +
15313 # system call tracing in operation / emulation
15314 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15315 jnz syscall_trace_entry
15316 @@ -509,6 +707,15 @@ syscall_exit:
15317 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15318 jne syscall_exit_work
15319
15320 +restore_all_pax:
15321 +
15322 +#ifdef CONFIG_PAX_RANDKSTACK
15323 + movl %esp, %eax
15324 + call pax_randomize_kstack
15325 +#endif
15326 +
15327 + pax_erase_kstack
15328 +
15329 restore_all:
15330 TRACE_IRQS_IRET
15331 restore_all_notrace:
15332 @@ -565,14 +772,34 @@ ldt_ss:
15333 * compensating for the offset by changing to the ESPFIX segment with
15334 * a base address that matches for the difference.
15335 */
15336 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15337 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15338 mov %esp, %edx /* load kernel esp */
15339 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15340 mov %dx, %ax /* eax: new kernel esp */
15341 sub %eax, %edx /* offset (low word is 0) */
15342 +#ifdef CONFIG_SMP
15343 + movl PER_CPU_VAR(cpu_number), %ebx
15344 + shll $PAGE_SHIFT_asm, %ebx
15345 + addl $cpu_gdt_table, %ebx
15346 +#else
15347 + movl $cpu_gdt_table, %ebx
15348 +#endif
15349 shr $16, %edx
15350 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15351 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15352 +
15353 +#ifdef CONFIG_PAX_KERNEXEC
15354 + mov %cr0, %esi
15355 + btr $16, %esi
15356 + mov %esi, %cr0
15357 +#endif
15358 +
15359 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15360 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15361 +
15362 +#ifdef CONFIG_PAX_KERNEXEC
15363 + bts $16, %esi
15364 + mov %esi, %cr0
15365 +#endif
15366 +
15367 pushl_cfi $__ESPFIX_SS
15368 pushl_cfi %eax /* new kernel esp */
15369 /* Disable interrupts, but do not irqtrace this section: we
15370 @@ -601,35 +828,23 @@ work_resched:
15371 movl TI_flags(%ebp), %ecx
15372 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15373 # than syscall tracing?
15374 - jz restore_all
15375 + jz restore_all_pax
15376 testb $_TIF_NEED_RESCHED, %cl
15377 jnz work_resched
15378
15379 work_notifysig: # deal with pending signals and
15380 # notify-resume requests
15381 + movl %esp, %eax
15382 #ifdef CONFIG_VM86
15383 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15384 - movl %esp, %eax
15385 - jne work_notifysig_v86 # returning to kernel-space or
15386 + jz 1f # returning to kernel-space or
15387 # vm86-space
15388 - TRACE_IRQS_ON
15389 - ENABLE_INTERRUPTS(CLBR_NONE)
15390 - movb PT_CS(%esp), %bl
15391 - andb $SEGMENT_RPL_MASK, %bl
15392 - cmpb $USER_RPL, %bl
15393 - jb resume_kernel
15394 - xorl %edx, %edx
15395 - call do_notify_resume
15396 - jmp resume_userspace
15397
15398 - ALIGN
15399 -work_notifysig_v86:
15400 pushl_cfi %ecx # save ti_flags for do_notify_resume
15401 call save_v86_state # %eax contains pt_regs pointer
15402 popl_cfi %ecx
15403 movl %eax, %esp
15404 -#else
15405 - movl %esp, %eax
15406 +1:
15407 #endif
15408 TRACE_IRQS_ON
15409 ENABLE_INTERRUPTS(CLBR_NONE)
15410 @@ -640,7 +855,7 @@ work_notifysig_v86:
15411 xorl %edx, %edx
15412 call do_notify_resume
15413 jmp resume_userspace
15414 -END(work_pending)
15415 +ENDPROC(work_pending)
15416
15417 # perform syscall exit tracing
15418 ALIGN
15419 @@ -648,11 +863,14 @@ syscall_trace_entry:
15420 movl $-ENOSYS,PT_EAX(%esp)
15421 movl %esp, %eax
15422 call syscall_trace_enter
15423 +
15424 + pax_erase_kstack
15425 +
15426 /* What it returned is what we'll actually use. */
15427 cmpl $(NR_syscalls), %eax
15428 jnae syscall_call
15429 jmp syscall_exit
15430 -END(syscall_trace_entry)
15431 +ENDPROC(syscall_trace_entry)
15432
15433 # perform syscall exit tracing
15434 ALIGN
15435 @@ -665,20 +883,24 @@ syscall_exit_work:
15436 movl %esp, %eax
15437 call syscall_trace_leave
15438 jmp resume_userspace
15439 -END(syscall_exit_work)
15440 +ENDPROC(syscall_exit_work)
15441 CFI_ENDPROC
15442
15443 RING0_INT_FRAME # can't unwind into user space anyway
15444 syscall_fault:
15445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15446 + push %ss
15447 + pop %ds
15448 +#endif
15449 GET_THREAD_INFO(%ebp)
15450 movl $-EFAULT,PT_EAX(%esp)
15451 jmp resume_userspace
15452 -END(syscall_fault)
15453 +ENDPROC(syscall_fault)
15454
15455 syscall_badsys:
15456 movl $-ENOSYS,PT_EAX(%esp)
15457 jmp resume_userspace
15458 -END(syscall_badsys)
15459 +ENDPROC(syscall_badsys)
15460 CFI_ENDPROC
15461 /*
15462 * End of kprobes section
15463 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15464 CFI_ENDPROC
15465 ENDPROC(ptregs_clone)
15466
15467 + ALIGN;
15468 +ENTRY(kernel_execve)
15469 + CFI_STARTPROC
15470 + pushl_cfi %ebp
15471 + sub $PT_OLDSS+4,%esp
15472 + pushl_cfi %edi
15473 + pushl_cfi %ecx
15474 + pushl_cfi %eax
15475 + lea 3*4(%esp),%edi
15476 + mov $PT_OLDSS/4+1,%ecx
15477 + xorl %eax,%eax
15478 + rep stosl
15479 + popl_cfi %eax
15480 + popl_cfi %ecx
15481 + popl_cfi %edi
15482 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15483 + pushl_cfi %esp
15484 + call sys_execve
15485 + add $4,%esp
15486 + CFI_ADJUST_CFA_OFFSET -4
15487 + GET_THREAD_INFO(%ebp)
15488 + test %eax,%eax
15489 + jz syscall_exit
15490 + add $PT_OLDSS+4,%esp
15491 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15492 + popl_cfi %ebp
15493 + ret
15494 + CFI_ENDPROC
15495 +ENDPROC(kernel_execve)
15496 +
15497 .macro FIXUP_ESPFIX_STACK
15498 /*
15499 * Switch back for ESPFIX stack to the normal zerobased stack
15500 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15501 * normal stack and adjusts ESP with the matching offset.
15502 */
15503 /* fixup the stack */
15504 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15505 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15506 +#ifdef CONFIG_SMP
15507 + movl PER_CPU_VAR(cpu_number), %ebx
15508 + shll $PAGE_SHIFT_asm, %ebx
15509 + addl $cpu_gdt_table, %ebx
15510 +#else
15511 + movl $cpu_gdt_table, %ebx
15512 +#endif
15513 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15514 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15515 shl $16, %eax
15516 addl %esp, %eax /* the adjusted stack pointer */
15517 pushl_cfi $__KERNEL_DS
15518 @@ -813,7 +1072,7 @@ vector=vector+1
15519 .endr
15520 2: jmp common_interrupt
15521 .endr
15522 -END(irq_entries_start)
15523 +ENDPROC(irq_entries_start)
15524
15525 .previous
15526 END(interrupt)
15527 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15528 pushl_cfi $do_coprocessor_error
15529 jmp error_code
15530 CFI_ENDPROC
15531 -END(coprocessor_error)
15532 +ENDPROC(coprocessor_error)
15533
15534 ENTRY(simd_coprocessor_error)
15535 RING0_INT_FRAME
15536 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15537 #endif
15538 jmp error_code
15539 CFI_ENDPROC
15540 -END(simd_coprocessor_error)
15541 +ENDPROC(simd_coprocessor_error)
15542
15543 ENTRY(device_not_available)
15544 RING0_INT_FRAME
15545 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15546 pushl_cfi $do_device_not_available
15547 jmp error_code
15548 CFI_ENDPROC
15549 -END(device_not_available)
15550 +ENDPROC(device_not_available)
15551
15552 #ifdef CONFIG_PARAVIRT
15553 ENTRY(native_iret)
15554 iret
15555 _ASM_EXTABLE(native_iret, iret_exc)
15556 -END(native_iret)
15557 +ENDPROC(native_iret)
15558
15559 ENTRY(native_irq_enable_sysexit)
15560 sti
15561 sysexit
15562 -END(native_irq_enable_sysexit)
15563 +ENDPROC(native_irq_enable_sysexit)
15564 #endif
15565
15566 ENTRY(overflow)
15567 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15568 pushl_cfi $do_overflow
15569 jmp error_code
15570 CFI_ENDPROC
15571 -END(overflow)
15572 +ENDPROC(overflow)
15573
15574 ENTRY(bounds)
15575 RING0_INT_FRAME
15576 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15577 pushl_cfi $do_bounds
15578 jmp error_code
15579 CFI_ENDPROC
15580 -END(bounds)
15581 +ENDPROC(bounds)
15582
15583 ENTRY(invalid_op)
15584 RING0_INT_FRAME
15585 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15586 pushl_cfi $do_invalid_op
15587 jmp error_code
15588 CFI_ENDPROC
15589 -END(invalid_op)
15590 +ENDPROC(invalid_op)
15591
15592 ENTRY(coprocessor_segment_overrun)
15593 RING0_INT_FRAME
15594 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15595 pushl_cfi $do_coprocessor_segment_overrun
15596 jmp error_code
15597 CFI_ENDPROC
15598 -END(coprocessor_segment_overrun)
15599 +ENDPROC(coprocessor_segment_overrun)
15600
15601 ENTRY(invalid_TSS)
15602 RING0_EC_FRAME
15603 pushl_cfi $do_invalid_TSS
15604 jmp error_code
15605 CFI_ENDPROC
15606 -END(invalid_TSS)
15607 +ENDPROC(invalid_TSS)
15608
15609 ENTRY(segment_not_present)
15610 RING0_EC_FRAME
15611 pushl_cfi $do_segment_not_present
15612 jmp error_code
15613 CFI_ENDPROC
15614 -END(segment_not_present)
15615 +ENDPROC(segment_not_present)
15616
15617 ENTRY(stack_segment)
15618 RING0_EC_FRAME
15619 pushl_cfi $do_stack_segment
15620 jmp error_code
15621 CFI_ENDPROC
15622 -END(stack_segment)
15623 +ENDPROC(stack_segment)
15624
15625 ENTRY(alignment_check)
15626 RING0_EC_FRAME
15627 pushl_cfi $do_alignment_check
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(alignment_check)
15631 +ENDPROC(alignment_check)
15632
15633 ENTRY(divide_error)
15634 RING0_INT_FRAME
15635 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15636 pushl_cfi $do_divide_error
15637 jmp error_code
15638 CFI_ENDPROC
15639 -END(divide_error)
15640 +ENDPROC(divide_error)
15641
15642 #ifdef CONFIG_X86_MCE
15643 ENTRY(machine_check)
15644 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15645 pushl_cfi machine_check_vector
15646 jmp error_code
15647 CFI_ENDPROC
15648 -END(machine_check)
15649 +ENDPROC(machine_check)
15650 #endif
15651
15652 ENTRY(spurious_interrupt_bug)
15653 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15654 pushl_cfi $do_spurious_interrupt_bug
15655 jmp error_code
15656 CFI_ENDPROC
15657 -END(spurious_interrupt_bug)
15658 +ENDPROC(spurious_interrupt_bug)
15659 /*
15660 * End of kprobes section
15661 */
15662 @@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15663
15664 ENTRY(mcount)
15665 ret
15666 -END(mcount)
15667 +ENDPROC(mcount)
15668
15669 ENTRY(ftrace_caller)
15670 cmpl $0, function_trace_stop
15671 @@ -1129,7 +1388,7 @@ ftrace_graph_call:
15672 .globl ftrace_stub
15673 ftrace_stub:
15674 ret
15675 -END(ftrace_caller)
15676 +ENDPROC(ftrace_caller)
15677
15678 #else /* ! CONFIG_DYNAMIC_FTRACE */
15679
15680 @@ -1165,7 +1424,7 @@ trace:
15681 popl %ecx
15682 popl %eax
15683 jmp ftrace_stub
15684 -END(mcount)
15685 +ENDPROC(mcount)
15686 #endif /* CONFIG_DYNAMIC_FTRACE */
15687 #endif /* CONFIG_FUNCTION_TRACER */
15688
15689 @@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15690 popl %ecx
15691 popl %eax
15692 ret
15693 -END(ftrace_graph_caller)
15694 +ENDPROC(ftrace_graph_caller)
15695
15696 .globl return_to_handler
15697 return_to_handler:
15698 @@ -1241,15 +1500,18 @@ error_code:
15699 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15700 REG_TO_PTGS %ecx
15701 SET_KERNEL_GS %ecx
15702 - movl $(__USER_DS), %ecx
15703 + movl $(__KERNEL_DS), %ecx
15704 movl %ecx, %ds
15705 movl %ecx, %es
15706 +
15707 + pax_enter_kernel
15708 +
15709 TRACE_IRQS_OFF
15710 movl %esp,%eax # pt_regs pointer
15711 call *%edi
15712 jmp ret_from_exception
15713 CFI_ENDPROC
15714 -END(page_fault)
15715 +ENDPROC(page_fault)
15716
15717 /*
15718 * Debug traps and NMI can happen at the one SYSENTER instruction
15719 @@ -1291,7 +1553,7 @@ debug_stack_correct:
15720 call do_debug
15721 jmp ret_from_exception
15722 CFI_ENDPROC
15723 -END(debug)
15724 +ENDPROC(debug)
15725
15726 /*
15727 * NMI is doubly nasty. It can happen _while_ we're handling
15728 @@ -1328,6 +1590,9 @@ nmi_stack_correct:
15729 xorl %edx,%edx # zero error code
15730 movl %esp,%eax # pt_regs pointer
15731 call do_nmi
15732 +
15733 + pax_exit_kernel
15734 +
15735 jmp restore_all_notrace
15736 CFI_ENDPROC
15737
15738 @@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15739 FIXUP_ESPFIX_STACK # %eax == %esp
15740 xorl %edx,%edx # zero error code
15741 call do_nmi
15742 +
15743 + pax_exit_kernel
15744 +
15745 RESTORE_REGS
15746 lss 12+4(%esp), %esp # back to espfix stack
15747 CFI_ADJUST_CFA_OFFSET -24
15748 jmp irq_return
15749 CFI_ENDPROC
15750 -END(nmi)
15751 +ENDPROC(nmi)
15752
15753 ENTRY(int3)
15754 RING0_INT_FRAME
15755 @@ -1381,14 +1649,14 @@ ENTRY(int3)
15756 call do_int3
15757 jmp ret_from_exception
15758 CFI_ENDPROC
15759 -END(int3)
15760 +ENDPROC(int3)
15761
15762 ENTRY(general_protection)
15763 RING0_EC_FRAME
15764 pushl_cfi $do_general_protection
15765 jmp error_code
15766 CFI_ENDPROC
15767 -END(general_protection)
15768 +ENDPROC(general_protection)
15769
15770 #ifdef CONFIG_KVM_GUEST
15771 ENTRY(async_page_fault)
15772 @@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15773 pushl_cfi $do_async_page_fault
15774 jmp error_code
15775 CFI_ENDPROC
15776 -END(async_page_fault)
15777 +ENDPROC(async_page_fault)
15778 #endif
15779
15780 /*
15781 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15782 index 69babd8..4270a51 100644
15783 --- a/arch/x86/kernel/entry_64.S
15784 +++ b/arch/x86/kernel/entry_64.S
15785 @@ -57,6 +57,8 @@
15786 #include <asm/percpu.h>
15787 #include <asm/asm.h>
15788 #include <linux/err.h>
15789 +#include <asm/pgtable.h>
15790 +#include <asm/alternative-asm.h>
15791
15792 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15793 #include <linux/elf-em.h>
15794 @@ -70,8 +72,9 @@
15795 #ifdef CONFIG_FUNCTION_TRACER
15796 #ifdef CONFIG_DYNAMIC_FTRACE
15797 ENTRY(mcount)
15798 + pax_force_retaddr
15799 retq
15800 -END(mcount)
15801 +ENDPROC(mcount)
15802
15803 ENTRY(ftrace_caller)
15804 cmpl $0, function_trace_stop
15805 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15806 #endif
15807
15808 GLOBAL(ftrace_stub)
15809 + pax_force_retaddr
15810 retq
15811 -END(ftrace_caller)
15812 +ENDPROC(ftrace_caller)
15813
15814 #else /* ! CONFIG_DYNAMIC_FTRACE */
15815 ENTRY(mcount)
15816 @@ -114,6 +118,7 @@ ENTRY(mcount)
15817 #endif
15818
15819 GLOBAL(ftrace_stub)
15820 + pax_force_retaddr
15821 retq
15822
15823 trace:
15824 @@ -123,12 +128,13 @@ trace:
15825 movq 8(%rbp), %rsi
15826 subq $MCOUNT_INSN_SIZE, %rdi
15827
15828 + pax_force_fptr ftrace_trace_function
15829 call *ftrace_trace_function
15830
15831 MCOUNT_RESTORE_FRAME
15832
15833 jmp ftrace_stub
15834 -END(mcount)
15835 +ENDPROC(mcount)
15836 #endif /* CONFIG_DYNAMIC_FTRACE */
15837 #endif /* CONFIG_FUNCTION_TRACER */
15838
15839 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15840
15841 MCOUNT_RESTORE_FRAME
15842
15843 + pax_force_retaddr
15844 retq
15845 -END(ftrace_graph_caller)
15846 +ENDPROC(ftrace_graph_caller)
15847
15848 GLOBAL(return_to_handler)
15849 subq $24, %rsp
15850 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15851 movq 8(%rsp), %rdx
15852 movq (%rsp), %rax
15853 addq $24, %rsp
15854 + pax_force_fptr %rdi
15855 jmp *%rdi
15856 #endif
15857
15858 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15859 ENDPROC(native_usergs_sysret64)
15860 #endif /* CONFIG_PARAVIRT */
15861
15862 + .macro ljmpq sel, off
15863 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15864 + .byte 0x48; ljmp *1234f(%rip)
15865 + .pushsection .rodata
15866 + .align 16
15867 + 1234: .quad \off; .word \sel
15868 + .popsection
15869 +#else
15870 + pushq $\sel
15871 + pushq $\off
15872 + lretq
15873 +#endif
15874 + .endm
15875 +
15876 + .macro pax_enter_kernel
15877 + pax_set_fptr_mask
15878 +#ifdef CONFIG_PAX_KERNEXEC
15879 + call pax_enter_kernel
15880 +#endif
15881 + .endm
15882 +
15883 + .macro pax_exit_kernel
15884 +#ifdef CONFIG_PAX_KERNEXEC
15885 + call pax_exit_kernel
15886 +#endif
15887 + .endm
15888 +
15889 +#ifdef CONFIG_PAX_KERNEXEC
15890 +ENTRY(pax_enter_kernel)
15891 + pushq %rdi
15892 +
15893 +#ifdef CONFIG_PARAVIRT
15894 + PV_SAVE_REGS(CLBR_RDI)
15895 +#endif
15896 +
15897 + GET_CR0_INTO_RDI
15898 + bts $16,%rdi
15899 + jnc 3f
15900 + mov %cs,%edi
15901 + cmp $__KERNEL_CS,%edi
15902 + jnz 2f
15903 +1:
15904 +
15905 +#ifdef CONFIG_PARAVIRT
15906 + PV_RESTORE_REGS(CLBR_RDI)
15907 +#endif
15908 +
15909 + popq %rdi
15910 + pax_force_retaddr
15911 + retq
15912 +
15913 +2: ljmpq __KERNEL_CS,1f
15914 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15915 +4: SET_RDI_INTO_CR0
15916 + jmp 1b
15917 +ENDPROC(pax_enter_kernel)
15918 +
15919 +ENTRY(pax_exit_kernel)
15920 + pushq %rdi
15921 +
15922 +#ifdef CONFIG_PARAVIRT
15923 + PV_SAVE_REGS(CLBR_RDI)
15924 +#endif
15925 +
15926 + mov %cs,%rdi
15927 + cmp $__KERNEXEC_KERNEL_CS,%edi
15928 + jz 2f
15929 +1:
15930 +
15931 +#ifdef CONFIG_PARAVIRT
15932 + PV_RESTORE_REGS(CLBR_RDI);
15933 +#endif
15934 +
15935 + popq %rdi
15936 + pax_force_retaddr
15937 + retq
15938 +
15939 +2: GET_CR0_INTO_RDI
15940 + btr $16,%rdi
15941 + ljmpq __KERNEL_CS,3f
15942 +3: SET_RDI_INTO_CR0
15943 + jmp 1b
15944 +#ifdef CONFIG_PARAVIRT
15945 + PV_RESTORE_REGS(CLBR_RDI);
15946 +#endif
15947 +
15948 + popq %rdi
15949 + pax_force_retaddr
15950 + retq
15951 +ENDPROC(pax_exit_kernel)
15952 +#endif
15953 +
15954 + .macro pax_enter_kernel_user
15955 + pax_set_fptr_mask
15956 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15957 + call pax_enter_kernel_user
15958 +#endif
15959 + .endm
15960 +
15961 + .macro pax_exit_kernel_user
15962 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15963 + call pax_exit_kernel_user
15964 +#endif
15965 +#ifdef CONFIG_PAX_RANDKSTACK
15966 + pushq %rax
15967 + call pax_randomize_kstack
15968 + popq %rax
15969 +#endif
15970 + .endm
15971 +
15972 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15973 +ENTRY(pax_enter_kernel_user)
15974 + pushq %rdi
15975 + pushq %rbx
15976 +
15977 +#ifdef CONFIG_PARAVIRT
15978 + PV_SAVE_REGS(CLBR_RDI)
15979 +#endif
15980 +
15981 + GET_CR3_INTO_RDI
15982 + mov %rdi,%rbx
15983 + add $__START_KERNEL_map,%rbx
15984 + sub phys_base(%rip),%rbx
15985 +
15986 +#ifdef CONFIG_PARAVIRT
15987 + pushq %rdi
15988 + cmpl $0, pv_info+PARAVIRT_enabled
15989 + jz 1f
15990 + i = 0
15991 + .rept USER_PGD_PTRS
15992 + mov i*8(%rbx),%rsi
15993 + mov $0,%sil
15994 + lea i*8(%rbx),%rdi
15995 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15996 + i = i + 1
15997 + .endr
15998 + jmp 2f
15999 +1:
16000 +#endif
16001 +
16002 + i = 0
16003 + .rept USER_PGD_PTRS
16004 + movb $0,i*8(%rbx)
16005 + i = i + 1
16006 + .endr
16007 +
16008 +#ifdef CONFIG_PARAVIRT
16009 +2: popq %rdi
16010 +#endif
16011 + SET_RDI_INTO_CR3
16012 +
16013 +#ifdef CONFIG_PAX_KERNEXEC
16014 + GET_CR0_INTO_RDI
16015 + bts $16,%rdi
16016 + SET_RDI_INTO_CR0
16017 +#endif
16018 +
16019 +#ifdef CONFIG_PARAVIRT
16020 + PV_RESTORE_REGS(CLBR_RDI)
16021 +#endif
16022 +
16023 + popq %rbx
16024 + popq %rdi
16025 + pax_force_retaddr
16026 + retq
16027 +ENDPROC(pax_enter_kernel_user)
16028 +
16029 +ENTRY(pax_exit_kernel_user)
16030 + push %rdi
16031 +
16032 +#ifdef CONFIG_PARAVIRT
16033 + pushq %rbx
16034 + PV_SAVE_REGS(CLBR_RDI)
16035 +#endif
16036 +
16037 +#ifdef CONFIG_PAX_KERNEXEC
16038 + GET_CR0_INTO_RDI
16039 + btr $16,%rdi
16040 + SET_RDI_INTO_CR0
16041 +#endif
16042 +
16043 + GET_CR3_INTO_RDI
16044 + add $__START_KERNEL_map,%rdi
16045 + sub phys_base(%rip),%rdi
16046 +
16047 +#ifdef CONFIG_PARAVIRT
16048 + cmpl $0, pv_info+PARAVIRT_enabled
16049 + jz 1f
16050 + mov %rdi,%rbx
16051 + i = 0
16052 + .rept USER_PGD_PTRS
16053 + mov i*8(%rbx),%rsi
16054 + mov $0x67,%sil
16055 + lea i*8(%rbx),%rdi
16056 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16057 + i = i + 1
16058 + .endr
16059 + jmp 2f
16060 +1:
16061 +#endif
16062 +
16063 + i = 0
16064 + .rept USER_PGD_PTRS
16065 + movb $0x67,i*8(%rdi)
16066 + i = i + 1
16067 + .endr
16068 +
16069 +#ifdef CONFIG_PARAVIRT
16070 +2: PV_RESTORE_REGS(CLBR_RDI)
16071 + popq %rbx
16072 +#endif
16073 +
16074 + popq %rdi
16075 + pax_force_retaddr
16076 + retq
16077 +ENDPROC(pax_exit_kernel_user)
16078 +#endif
16079 +
16080 +.macro pax_erase_kstack
16081 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16082 + call pax_erase_kstack
16083 +#endif
16084 +.endm
16085 +
16086 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16087 +ENTRY(pax_erase_kstack)
16088 + pushq %rdi
16089 + pushq %rcx
16090 + pushq %rax
16091 + pushq %r11
16092 +
16093 + GET_THREAD_INFO(%r11)
16094 + mov TI_lowest_stack(%r11), %rdi
16095 + mov $-0xBEEF, %rax
16096 + std
16097 +
16098 +1: mov %edi, %ecx
16099 + and $THREAD_SIZE_asm - 1, %ecx
16100 + shr $3, %ecx
16101 + repne scasq
16102 + jecxz 2f
16103 +
16104 + cmp $2*8, %ecx
16105 + jc 2f
16106 +
16107 + mov $2*8, %ecx
16108 + repe scasq
16109 + jecxz 2f
16110 + jne 1b
16111 +
16112 +2: cld
16113 + mov %esp, %ecx
16114 + sub %edi, %ecx
16115 +
16116 + cmp $THREAD_SIZE_asm, %rcx
16117 + jb 3f
16118 + ud2
16119 +3:
16120 +
16121 + shr $3, %ecx
16122 + rep stosq
16123 +
16124 + mov TI_task_thread_sp0(%r11), %rdi
16125 + sub $256, %rdi
16126 + mov %rdi, TI_lowest_stack(%r11)
16127 +
16128 + popq %r11
16129 + popq %rax
16130 + popq %rcx
16131 + popq %rdi
16132 + pax_force_retaddr
16133 + ret
16134 +ENDPROC(pax_erase_kstack)
16135 +#endif
16136
16137 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16138 #ifdef CONFIG_TRACE_IRQFLAGS
16139 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16140 .endm
16141
16142 .macro UNFAKE_STACK_FRAME
16143 - addq $8*6, %rsp
16144 - CFI_ADJUST_CFA_OFFSET -(6*8)
16145 + addq $8*6 + ARG_SKIP, %rsp
16146 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16147 .endm
16148
16149 /*
16150 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16151 movq %rsp, %rsi
16152
16153 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16154 - testl $3, CS-RBP(%rsi)
16155 + testb $3, CS-RBP(%rsi)
16156 je 1f
16157 SWAPGS
16158 /*
16159 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16160 movq_cfi r15, R15+16
16161 movq %r11, 8(%rsp) /* return address */
16162 FIXUP_TOP_OF_STACK %r11, 16
16163 + pax_force_retaddr
16164 ret
16165 CFI_ENDPROC
16166 -END(save_rest)
16167 +ENDPROC(save_rest)
16168
16169 /* save complete stack frame */
16170 .pushsection .kprobes.text, "ax"
16171 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16172 js 1f /* negative -> in kernel */
16173 SWAPGS
16174 xorl %ebx,%ebx
16175 -1: ret
16176 +1: pax_force_retaddr_bts
16177 + ret
16178 CFI_ENDPROC
16179 -END(save_paranoid)
16180 +ENDPROC(save_paranoid)
16181 .popsection
16182
16183 /*
16184 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16185
16186 RESTORE_REST
16187
16188 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16189 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16190 jz retint_restore_args
16191
16192 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16193 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16194 jmp ret_from_sys_call # go to the SYSRET fastpath
16195
16196 CFI_ENDPROC
16197 -END(ret_from_fork)
16198 +ENDPROC(ret_from_fork)
16199
16200 /*
16201 * System call entry. Up to 6 arguments in registers are supported.
16202 @@ -495,7 +779,7 @@ END(ret_from_fork)
16203 ENTRY(system_call)
16204 CFI_STARTPROC simple
16205 CFI_SIGNAL_FRAME
16206 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16207 + CFI_DEF_CFA rsp,0
16208 CFI_REGISTER rip,rcx
16209 /*CFI_REGISTER rflags,r11*/
16210 SWAPGS_UNSAFE_STACK
16211 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16212
16213 movq %rsp,PER_CPU_VAR(old_rsp)
16214 movq PER_CPU_VAR(kernel_stack),%rsp
16215 + SAVE_ARGS 8*6,0
16216 + pax_enter_kernel_user
16217 +
16218 +#ifdef CONFIG_PAX_RANDKSTACK
16219 + pax_erase_kstack
16220 +#endif
16221 +
16222 /*
16223 * No need to follow this irqs off/on section - it's straight
16224 * and short:
16225 */
16226 ENABLE_INTERRUPTS(CLBR_NONE)
16227 - SAVE_ARGS 8,0
16228 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16229 movq %rcx,RIP-ARGOFFSET(%rsp)
16230 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16231 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16232 + GET_THREAD_INFO(%rcx)
16233 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16234 jnz tracesys
16235 system_call_fastpath:
16236 #if __SYSCALL_MASK == ~0
16237 @@ -527,7 +818,7 @@ system_call_fastpath:
16238 cmpl $__NR_syscall_max,%eax
16239 #endif
16240 ja badsys
16241 - movq %r10,%rcx
16242 + movq R10-ARGOFFSET(%rsp),%rcx
16243 call *sys_call_table(,%rax,8) # XXX: rip relative
16244 movq %rax,RAX-ARGOFFSET(%rsp)
16245 /*
16246 @@ -541,10 +832,13 @@ sysret_check:
16247 LOCKDEP_SYS_EXIT
16248 DISABLE_INTERRUPTS(CLBR_NONE)
16249 TRACE_IRQS_OFF
16250 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16251 + GET_THREAD_INFO(%rcx)
16252 + movl TI_flags(%rcx),%edx
16253 andl %edi,%edx
16254 jnz sysret_careful
16255 CFI_REMEMBER_STATE
16256 + pax_exit_kernel_user
16257 + pax_erase_kstack
16258 /*
16259 * sysretq will re-enable interrupts:
16260 */
16261 @@ -596,14 +890,18 @@ badsys:
16262 * jump back to the normal fast path.
16263 */
16264 auditsys:
16265 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16266 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16267 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16268 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16269 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16270 movq %rax,%rsi /* 2nd arg: syscall number */
16271 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16272 call __audit_syscall_entry
16273 +
16274 + pax_erase_kstack
16275 +
16276 LOAD_ARGS 0 /* reload call-clobbered registers */
16277 + pax_set_fptr_mask
16278 jmp system_call_fastpath
16279
16280 /*
16281 @@ -624,7 +922,7 @@ sysret_audit:
16282 /* Do syscall tracing */
16283 tracesys:
16284 #ifdef CONFIG_AUDITSYSCALL
16285 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16286 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16287 jz auditsys
16288 #endif
16289 SAVE_REST
16290 @@ -632,12 +930,16 @@ tracesys:
16291 FIXUP_TOP_OF_STACK %rdi
16292 movq %rsp,%rdi
16293 call syscall_trace_enter
16294 +
16295 + pax_erase_kstack
16296 +
16297 /*
16298 * Reload arg registers from stack in case ptrace changed them.
16299 * We don't reload %rax because syscall_trace_enter() returned
16300 * the value it wants us to use in the table lookup.
16301 */
16302 LOAD_ARGS ARGOFFSET, 1
16303 + pax_set_fptr_mask
16304 RESTORE_REST
16305 #if __SYSCALL_MASK == ~0
16306 cmpq $__NR_syscall_max,%rax
16307 @@ -646,7 +948,7 @@ tracesys:
16308 cmpl $__NR_syscall_max,%eax
16309 #endif
16310 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16311 - movq %r10,%rcx /* fixup for C */
16312 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16313 call *sys_call_table(,%rax,8)
16314 movq %rax,RAX-ARGOFFSET(%rsp)
16315 /* Use IRET because user could have changed frame */
16316 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16317 andl %edi,%edx
16318 jnz int_careful
16319 andl $~TS_COMPAT,TI_status(%rcx)
16320 - jmp retint_swapgs
16321 + pax_exit_kernel_user
16322 + pax_erase_kstack
16323 + jmp retint_swapgs_pax
16324
16325 /* Either reschedule or signal or syscall exit tracking needed. */
16326 /* First do a reschedule test. */
16327 @@ -713,7 +1017,7 @@ int_restore_rest:
16328 TRACE_IRQS_OFF
16329 jmp int_with_check
16330 CFI_ENDPROC
16331 -END(system_call)
16332 +ENDPROC(system_call)
16333
16334 /*
16335 * Certain special system calls that need to save a complete full stack frame.
16336 @@ -729,7 +1033,7 @@ ENTRY(\label)
16337 call \func
16338 jmp ptregscall_common
16339 CFI_ENDPROC
16340 -END(\label)
16341 +ENDPROC(\label)
16342 .endm
16343
16344 PTREGSCALL stub_clone, sys_clone, %r8
16345 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16346 movq_cfi_restore R12+8, r12
16347 movq_cfi_restore RBP+8, rbp
16348 movq_cfi_restore RBX+8, rbx
16349 + pax_force_retaddr
16350 ret $REST_SKIP /* pop extended registers */
16351 CFI_ENDPROC
16352 -END(ptregscall_common)
16353 +ENDPROC(ptregscall_common)
16354
16355 ENTRY(stub_execve)
16356 CFI_STARTPROC
16357 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16358 RESTORE_REST
16359 jmp int_ret_from_sys_call
16360 CFI_ENDPROC
16361 -END(stub_execve)
16362 +ENDPROC(stub_execve)
16363
16364 /*
16365 * sigreturn is special because it needs to restore all registers on return.
16366 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16367 RESTORE_REST
16368 jmp int_ret_from_sys_call
16369 CFI_ENDPROC
16370 -END(stub_rt_sigreturn)
16371 +ENDPROC(stub_rt_sigreturn)
16372
16373 #ifdef CONFIG_X86_X32_ABI
16374 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16375 @@ -851,7 +1156,7 @@ vector=vector+1
16376 2: jmp common_interrupt
16377 .endr
16378 CFI_ENDPROC
16379 -END(irq_entries_start)
16380 +ENDPROC(irq_entries_start)
16381
16382 .previous
16383 END(interrupt)
16384 @@ -871,6 +1176,16 @@ END(interrupt)
16385 subq $ORIG_RAX-RBP, %rsp
16386 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16387 SAVE_ARGS_IRQ
16388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16389 + testb $3, CS(%rdi)
16390 + jnz 1f
16391 + pax_enter_kernel
16392 + jmp 2f
16393 +1: pax_enter_kernel_user
16394 +2:
16395 +#else
16396 + pax_enter_kernel
16397 +#endif
16398 call \func
16399 .endm
16400
16401 @@ -902,7 +1217,7 @@ ret_from_intr:
16402
16403 exit_intr:
16404 GET_THREAD_INFO(%rcx)
16405 - testl $3,CS-ARGOFFSET(%rsp)
16406 + testb $3,CS-ARGOFFSET(%rsp)
16407 je retint_kernel
16408
16409 /* Interrupt came from user space */
16410 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16411 * The iretq could re-enable interrupts:
16412 */
16413 DISABLE_INTERRUPTS(CLBR_ANY)
16414 + pax_exit_kernel_user
16415 +retint_swapgs_pax:
16416 TRACE_IRQS_IRETQ
16417 SWAPGS
16418 jmp restore_args
16419
16420 retint_restore_args: /* return to kernel space */
16421 DISABLE_INTERRUPTS(CLBR_ANY)
16422 + pax_exit_kernel
16423 + pax_force_retaddr RIP-ARGOFFSET
16424 /*
16425 * The iretq could re-enable interrupts:
16426 */
16427 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16428 #endif
16429
16430 CFI_ENDPROC
16431 -END(common_interrupt)
16432 +ENDPROC(common_interrupt)
16433 /*
16434 * End of kprobes section
16435 */
16436 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16437 interrupt \do_sym
16438 jmp ret_from_intr
16439 CFI_ENDPROC
16440 -END(\sym)
16441 +ENDPROC(\sym)
16442 .endm
16443
16444 #ifdef CONFIG_SMP
16445 @@ -1084,12 +1403,22 @@ ENTRY(\sym)
16446 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16447 call error_entry
16448 DEFAULT_FRAME 0
16449 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16450 + testb $3, CS(%rsp)
16451 + jnz 1f
16452 + pax_enter_kernel
16453 + jmp 2f
16454 +1: pax_enter_kernel_user
16455 +2:
16456 +#else
16457 + pax_enter_kernel
16458 +#endif
16459 movq %rsp,%rdi /* pt_regs pointer */
16460 xorl %esi,%esi /* no error code */
16461 call \do_sym
16462 jmp error_exit /* %ebx: no swapgs flag */
16463 CFI_ENDPROC
16464 -END(\sym)
16465 +ENDPROC(\sym)
16466 .endm
16467
16468 .macro paranoidzeroentry sym do_sym
16469 @@ -1101,15 +1430,25 @@ ENTRY(\sym)
16470 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16471 call save_paranoid
16472 TRACE_IRQS_OFF
16473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16474 + testb $3, CS(%rsp)
16475 + jnz 1f
16476 + pax_enter_kernel
16477 + jmp 2f
16478 +1: pax_enter_kernel_user
16479 +2:
16480 +#else
16481 + pax_enter_kernel
16482 +#endif
16483 movq %rsp,%rdi /* pt_regs pointer */
16484 xorl %esi,%esi /* no error code */
16485 call \do_sym
16486 jmp paranoid_exit /* %ebx: no swapgs flag */
16487 CFI_ENDPROC
16488 -END(\sym)
16489 +ENDPROC(\sym)
16490 .endm
16491
16492 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16493 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16494 .macro paranoidzeroentry_ist sym do_sym ist
16495 ENTRY(\sym)
16496 INTR_FRAME
16497 @@ -1119,14 +1458,30 @@ ENTRY(\sym)
16498 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16499 call save_paranoid
16500 TRACE_IRQS_OFF_DEBUG
16501 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16502 + testb $3, CS(%rsp)
16503 + jnz 1f
16504 + pax_enter_kernel
16505 + jmp 2f
16506 +1: pax_enter_kernel_user
16507 +2:
16508 +#else
16509 + pax_enter_kernel
16510 +#endif
16511 movq %rsp,%rdi /* pt_regs pointer */
16512 xorl %esi,%esi /* no error code */
16513 +#ifdef CONFIG_SMP
16514 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16515 + lea init_tss(%r12), %r12
16516 +#else
16517 + lea init_tss(%rip), %r12
16518 +#endif
16519 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16520 call \do_sym
16521 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16522 jmp paranoid_exit /* %ebx: no swapgs flag */
16523 CFI_ENDPROC
16524 -END(\sym)
16525 +ENDPROC(\sym)
16526 .endm
16527
16528 .macro errorentry sym do_sym
16529 @@ -1137,13 +1492,23 @@ ENTRY(\sym)
16530 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16531 call error_entry
16532 DEFAULT_FRAME 0
16533 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16534 + testb $3, CS(%rsp)
16535 + jnz 1f
16536 + pax_enter_kernel
16537 + jmp 2f
16538 +1: pax_enter_kernel_user
16539 +2:
16540 +#else
16541 + pax_enter_kernel
16542 +#endif
16543 movq %rsp,%rdi /* pt_regs pointer */
16544 movq ORIG_RAX(%rsp),%rsi /* get error code */
16545 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16546 call \do_sym
16547 jmp error_exit /* %ebx: no swapgs flag */
16548 CFI_ENDPROC
16549 -END(\sym)
16550 +ENDPROC(\sym)
16551 .endm
16552
16553 /* error code is on the stack already */
16554 @@ -1156,13 +1521,23 @@ ENTRY(\sym)
16555 call save_paranoid
16556 DEFAULT_FRAME 0
16557 TRACE_IRQS_OFF
16558 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16559 + testb $3, CS(%rsp)
16560 + jnz 1f
16561 + pax_enter_kernel
16562 + jmp 2f
16563 +1: pax_enter_kernel_user
16564 +2:
16565 +#else
16566 + pax_enter_kernel
16567 +#endif
16568 movq %rsp,%rdi /* pt_regs pointer */
16569 movq ORIG_RAX(%rsp),%rsi /* get error code */
16570 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16571 call \do_sym
16572 jmp paranoid_exit /* %ebx: no swapgs flag */
16573 CFI_ENDPROC
16574 -END(\sym)
16575 +ENDPROC(\sym)
16576 .endm
16577
16578 zeroentry divide_error do_divide_error
16579 @@ -1192,9 +1567,10 @@ gs_change:
16580 2: mfence /* workaround */
16581 SWAPGS
16582 popfq_cfi
16583 + pax_force_retaddr
16584 ret
16585 CFI_ENDPROC
16586 -END(native_load_gs_index)
16587 +ENDPROC(native_load_gs_index)
16588
16589 _ASM_EXTABLE(gs_change,bad_gs)
16590 .section .fixup,"ax"
16591 @@ -1213,13 +1589,14 @@ ENTRY(kernel_thread_helper)
16592 * Here we are in the child and the registers are set as they were
16593 * at kernel_thread() invocation in the parent.
16594 */
16595 + pax_force_fptr %rsi
16596 call *%rsi
16597 # exit
16598 mov %eax, %edi
16599 call do_exit
16600 ud2 # padding for call trace
16601 CFI_ENDPROC
16602 -END(kernel_thread_helper)
16603 +ENDPROC(kernel_thread_helper)
16604
16605 /*
16606 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16607 @@ -1246,11 +1623,11 @@ ENTRY(kernel_execve)
16608 RESTORE_REST
16609 testq %rax,%rax
16610 je int_ret_from_sys_call
16611 - RESTORE_ARGS
16612 UNFAKE_STACK_FRAME
16613 + pax_force_retaddr
16614 ret
16615 CFI_ENDPROC
16616 -END(kernel_execve)
16617 +ENDPROC(kernel_execve)
16618
16619 /* Call softirq on interrupt stack. Interrupts are off. */
16620 ENTRY(call_softirq)
16621 @@ -1268,9 +1645,10 @@ ENTRY(call_softirq)
16622 CFI_DEF_CFA_REGISTER rsp
16623 CFI_ADJUST_CFA_OFFSET -8
16624 decl PER_CPU_VAR(irq_count)
16625 + pax_force_retaddr
16626 ret
16627 CFI_ENDPROC
16628 -END(call_softirq)
16629 +ENDPROC(call_softirq)
16630
16631 #ifdef CONFIG_XEN
16632 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16633 @@ -1308,7 +1686,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16634 decl PER_CPU_VAR(irq_count)
16635 jmp error_exit
16636 CFI_ENDPROC
16637 -END(xen_do_hypervisor_callback)
16638 +ENDPROC(xen_do_hypervisor_callback)
16639
16640 /*
16641 * Hypervisor uses this for application faults while it executes.
16642 @@ -1367,7 +1745,7 @@ ENTRY(xen_failsafe_callback)
16643 SAVE_ALL
16644 jmp error_exit
16645 CFI_ENDPROC
16646 -END(xen_failsafe_callback)
16647 +ENDPROC(xen_failsafe_callback)
16648
16649 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16650 xen_hvm_callback_vector xen_evtchn_do_upcall
16651 @@ -1416,16 +1794,31 @@ ENTRY(paranoid_exit)
16652 TRACE_IRQS_OFF_DEBUG
16653 testl %ebx,%ebx /* swapgs needed? */
16654 jnz paranoid_restore
16655 - testl $3,CS(%rsp)
16656 + testb $3,CS(%rsp)
16657 jnz paranoid_userspace
16658 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16659 + pax_exit_kernel
16660 + TRACE_IRQS_IRETQ 0
16661 + SWAPGS_UNSAFE_STACK
16662 + RESTORE_ALL 8
16663 + pax_force_retaddr_bts
16664 + jmp irq_return
16665 +#endif
16666 paranoid_swapgs:
16667 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16668 + pax_exit_kernel_user
16669 +#else
16670 + pax_exit_kernel
16671 +#endif
16672 TRACE_IRQS_IRETQ 0
16673 SWAPGS_UNSAFE_STACK
16674 RESTORE_ALL 8
16675 jmp irq_return
16676 paranoid_restore:
16677 + pax_exit_kernel
16678 TRACE_IRQS_IRETQ_DEBUG 0
16679 RESTORE_ALL 8
16680 + pax_force_retaddr_bts
16681 jmp irq_return
16682 paranoid_userspace:
16683 GET_THREAD_INFO(%rcx)
16684 @@ -1454,7 +1847,7 @@ paranoid_schedule:
16685 TRACE_IRQS_OFF
16686 jmp paranoid_userspace
16687 CFI_ENDPROC
16688 -END(paranoid_exit)
16689 +ENDPROC(paranoid_exit)
16690
16691 /*
16692 * Exception entry point. This expects an error code/orig_rax on the stack.
16693 @@ -1481,12 +1874,13 @@ ENTRY(error_entry)
16694 movq_cfi r14, R14+8
16695 movq_cfi r15, R15+8
16696 xorl %ebx,%ebx
16697 - testl $3,CS+8(%rsp)
16698 + testb $3,CS+8(%rsp)
16699 je error_kernelspace
16700 error_swapgs:
16701 SWAPGS
16702 error_sti:
16703 TRACE_IRQS_OFF
16704 + pax_force_retaddr_bts
16705 ret
16706
16707 /*
16708 @@ -1513,7 +1907,7 @@ bstep_iret:
16709 movq %rcx,RIP+8(%rsp)
16710 jmp error_swapgs
16711 CFI_ENDPROC
16712 -END(error_entry)
16713 +ENDPROC(error_entry)
16714
16715
16716 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16717 @@ -1533,7 +1927,7 @@ ENTRY(error_exit)
16718 jnz retint_careful
16719 jmp retint_swapgs
16720 CFI_ENDPROC
16721 -END(error_exit)
16722 +ENDPROC(error_exit)
16723
16724 /*
16725 * Test if a given stack is an NMI stack or not.
16726 @@ -1591,9 +1985,11 @@ ENTRY(nmi)
16727 * If %cs was not the kernel segment, then the NMI triggered in user
16728 * space, which means it is definitely not nested.
16729 */
16730 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16731 + je 1f
16732 cmpl $__KERNEL_CS, 16(%rsp)
16733 jne first_nmi
16734 -
16735 +1:
16736 /*
16737 * Check the special variable on the stack to see if NMIs are
16738 * executing.
16739 @@ -1752,6 +2148,17 @@ end_repeat_nmi:
16740 */
16741 movq %cr2, %r12
16742
16743 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16744 + testb $3, CS(%rsp)
16745 + jnz 1f
16746 + pax_enter_kernel
16747 + jmp 2f
16748 +1: pax_enter_kernel_user
16749 +2:
16750 +#else
16751 + pax_enter_kernel
16752 +#endif
16753 +
16754 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16755 movq %rsp,%rdi
16756 movq $-1,%rsi
16757 @@ -1767,21 +2174,32 @@ end_repeat_nmi:
16758 testl %ebx,%ebx /* swapgs needed? */
16759 jnz nmi_restore
16760 nmi_swapgs:
16761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16762 + pax_exit_kernel_user
16763 +#else
16764 + pax_exit_kernel
16765 +#endif
16766 SWAPGS_UNSAFE_STACK
16767 + RESTORE_ALL 8
16768 + /* Clear the NMI executing stack variable */
16769 + movq $0, 10*8(%rsp)
16770 + jmp irq_return
16771 nmi_restore:
16772 + pax_exit_kernel
16773 RESTORE_ALL 8
16774 + pax_force_retaddr_bts
16775 /* Clear the NMI executing stack variable */
16776 movq $0, 10*8(%rsp)
16777 jmp irq_return
16778 CFI_ENDPROC
16779 -END(nmi)
16780 +ENDPROC(nmi)
16781
16782 ENTRY(ignore_sysret)
16783 CFI_STARTPROC
16784 mov $-ENOSYS,%eax
16785 sysret
16786 CFI_ENDPROC
16787 -END(ignore_sysret)
16788 +ENDPROC(ignore_sysret)
16789
16790 /*
16791 * End of kprobes section
16792 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16793 index c3a7cb4..3ad00dc 100644
16794 --- a/arch/x86/kernel/ftrace.c
16795 +++ b/arch/x86/kernel/ftrace.c
16796 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16797 {
16798 unsigned char replaced[MCOUNT_INSN_SIZE];
16799
16800 + ip = ktla_ktva(ip);
16801 +
16802 /*
16803 * Note: Due to modules and __init, code can
16804 * disappear and change, we need to protect against faulting
16805 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16806 unsigned char old[MCOUNT_INSN_SIZE], *new;
16807 int ret;
16808
16809 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16810 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16811 new = ftrace_call_replace(ip, (unsigned long)func);
16812
16813 /* See comment above by declaration of modifying_ftrace_code */
16814 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16815 {
16816 unsigned char code[MCOUNT_INSN_SIZE];
16817
16818 + ip = ktla_ktva(ip);
16819 +
16820 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16821 return -EFAULT;
16822
16823 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16824 index c18f59d..9c0c9f6 100644
16825 --- a/arch/x86/kernel/head32.c
16826 +++ b/arch/x86/kernel/head32.c
16827 @@ -18,6 +18,7 @@
16828 #include <asm/io_apic.h>
16829 #include <asm/bios_ebda.h>
16830 #include <asm/tlbflush.h>
16831 +#include <asm/boot.h>
16832
16833 static void __init i386_default_early_setup(void)
16834 {
16835 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16836
16837 void __init i386_start_kernel(void)
16838 {
16839 - memblock_reserve(__pa_symbol(&_text),
16840 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16841 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16842
16843 #ifdef CONFIG_BLK_DEV_INITRD
16844 /* Reserve INITRD */
16845 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16846 index d42ab17..cb1b997 100644
16847 --- a/arch/x86/kernel/head_32.S
16848 +++ b/arch/x86/kernel/head_32.S
16849 @@ -26,6 +26,12 @@
16850 /* Physical address */
16851 #define pa(X) ((X) - __PAGE_OFFSET)
16852
16853 +#ifdef CONFIG_PAX_KERNEXEC
16854 +#define ta(X) (X)
16855 +#else
16856 +#define ta(X) ((X) - __PAGE_OFFSET)
16857 +#endif
16858 +
16859 /*
16860 * References to members of the new_cpu_data structure.
16861 */
16862 @@ -55,11 +61,7 @@
16863 * and small than max_low_pfn, otherwise will waste some page table entries
16864 */
16865
16866 -#if PTRS_PER_PMD > 1
16867 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16868 -#else
16869 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16870 -#endif
16871 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16872
16873 /* Number of possible pages in the lowmem region */
16874 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16875 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16876 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16877
16878 /*
16879 + * Real beginning of normal "text" segment
16880 + */
16881 +ENTRY(stext)
16882 +ENTRY(_stext)
16883 +
16884 +/*
16885 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16886 * %esi points to the real-mode code as a 32-bit pointer.
16887 * CS and DS must be 4 GB flat segments, but we don't depend on
16888 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16889 * can.
16890 */
16891 __HEAD
16892 +
16893 +#ifdef CONFIG_PAX_KERNEXEC
16894 + jmp startup_32
16895 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16896 +.fill PAGE_SIZE-5,1,0xcc
16897 +#endif
16898 +
16899 ENTRY(startup_32)
16900 movl pa(stack_start),%ecx
16901
16902 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16903 2:
16904 leal -__PAGE_OFFSET(%ecx),%esp
16905
16906 +#ifdef CONFIG_SMP
16907 + movl $pa(cpu_gdt_table),%edi
16908 + movl $__per_cpu_load,%eax
16909 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16910 + rorl $16,%eax
16911 + movb %al,__KERNEL_PERCPU + 4(%edi)
16912 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16913 + movl $__per_cpu_end - 1,%eax
16914 + subl $__per_cpu_start,%eax
16915 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16916 +#endif
16917 +
16918 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16919 + movl $NR_CPUS,%ecx
16920 + movl $pa(cpu_gdt_table),%edi
16921 +1:
16922 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16923 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16924 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16925 + addl $PAGE_SIZE_asm,%edi
16926 + loop 1b
16927 +#endif
16928 +
16929 +#ifdef CONFIG_PAX_KERNEXEC
16930 + movl $pa(boot_gdt),%edi
16931 + movl $__LOAD_PHYSICAL_ADDR,%eax
16932 + movw %ax,__BOOT_CS + 2(%edi)
16933 + rorl $16,%eax
16934 + movb %al,__BOOT_CS + 4(%edi)
16935 + movb %ah,__BOOT_CS + 7(%edi)
16936 + rorl $16,%eax
16937 +
16938 + ljmp $(__BOOT_CS),$1f
16939 +1:
16940 +
16941 + movl $NR_CPUS,%ecx
16942 + movl $pa(cpu_gdt_table),%edi
16943 + addl $__PAGE_OFFSET,%eax
16944 +1:
16945 + movw %ax,__KERNEL_CS + 2(%edi)
16946 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16947 + rorl $16,%eax
16948 + movb %al,__KERNEL_CS + 4(%edi)
16949 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16950 + movb %ah,__KERNEL_CS + 7(%edi)
16951 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16952 + rorl $16,%eax
16953 + addl $PAGE_SIZE_asm,%edi
16954 + loop 1b
16955 +#endif
16956 +
16957 /*
16958 * Clear BSS first so that there are no surprises...
16959 */
16960 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16961 movl %eax, pa(max_pfn_mapped)
16962
16963 /* Do early initialization of the fixmap area */
16964 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16965 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16966 +#ifdef CONFIG_COMPAT_VDSO
16967 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16968 +#else
16969 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16970 +#endif
16971 #else /* Not PAE */
16972
16973 page_pde_offset = (__PAGE_OFFSET >> 20);
16974 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16975 movl %eax, pa(max_pfn_mapped)
16976
16977 /* Do early initialization of the fixmap area */
16978 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16979 - movl %eax,pa(initial_page_table+0xffc)
16980 +#ifdef CONFIG_COMPAT_VDSO
16981 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16982 +#else
16983 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16984 +#endif
16985 #endif
16986
16987 #ifdef CONFIG_PARAVIRT
16988 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16989 cmpl $num_subarch_entries, %eax
16990 jae bad_subarch
16991
16992 - movl pa(subarch_entries)(,%eax,4), %eax
16993 - subl $__PAGE_OFFSET, %eax
16994 - jmp *%eax
16995 + jmp *pa(subarch_entries)(,%eax,4)
16996
16997 bad_subarch:
16998 WEAK(lguest_entry)
16999 @@ -256,10 +326,10 @@ WEAK(xen_entry)
17000 __INITDATA
17001
17002 subarch_entries:
17003 - .long default_entry /* normal x86/PC */
17004 - .long lguest_entry /* lguest hypervisor */
17005 - .long xen_entry /* Xen hypervisor */
17006 - .long default_entry /* Moorestown MID */
17007 + .long ta(default_entry) /* normal x86/PC */
17008 + .long ta(lguest_entry) /* lguest hypervisor */
17009 + .long ta(xen_entry) /* Xen hypervisor */
17010 + .long ta(default_entry) /* Moorestown MID */
17011 num_subarch_entries = (. - subarch_entries) / 4
17012 .previous
17013 #else
17014 @@ -310,6 +380,7 @@ default_entry:
17015 orl %edx,%eax
17016 movl %eax,%cr4
17017
17018 +#ifdef CONFIG_X86_PAE
17019 testb $X86_CR4_PAE, %al # check if PAE is enabled
17020 jz 6f
17021
17022 @@ -338,6 +409,9 @@ default_entry:
17023 /* Make changes effective */
17024 wrmsr
17025
17026 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
17027 +#endif
17028 +
17029 6:
17030
17031 /*
17032 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
17033 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17034 movl %eax,%ss # after changing gdt.
17035
17036 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17037 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17038 movl %eax,%ds
17039 movl %eax,%es
17040
17041 movl $(__KERNEL_PERCPU), %eax
17042 movl %eax,%fs # set this cpu's percpu
17043
17044 +#ifdef CONFIG_CC_STACKPROTECTOR
17045 movl $(__KERNEL_STACK_CANARY),%eax
17046 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17047 + movl $(__USER_DS),%eax
17048 +#else
17049 + xorl %eax,%eax
17050 +#endif
17051 movl %eax,%gs
17052
17053 xorl %eax,%eax # Clear LDT
17054 @@ -520,8 +600,11 @@ setup_once:
17055 * relocation. Manually set base address in stack canary
17056 * segment descriptor.
17057 */
17058 - movl $gdt_page,%eax
17059 + movl $cpu_gdt_table,%eax
17060 movl $stack_canary,%ecx
17061 +#ifdef CONFIG_SMP
17062 + addl $__per_cpu_load,%ecx
17063 +#endif
17064 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17065 shrl $16, %ecx
17066 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17067 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
17068 /* This is global to keep gas from relaxing the jumps */
17069 ENTRY(early_idt_handler)
17070 cld
17071 - cmpl $2,%ss:early_recursion_flag
17072 + cmpl $1,%ss:early_recursion_flag
17073 je hlt_loop
17074 incl %ss:early_recursion_flag
17075
17076 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
17077 pushl (20+6*4)(%esp) /* trapno */
17078 pushl $fault_msg
17079 call printk
17080 -#endif
17081 call dump_stack
17082 +#endif
17083 hlt_loop:
17084 hlt
17085 jmp hlt_loop
17086 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
17087 /* This is the default interrupt "handler" :-) */
17088 ALIGN
17089 ignore_int:
17090 - cld
17091 #ifdef CONFIG_PRINTK
17092 + cmpl $2,%ss:early_recursion_flag
17093 + je hlt_loop
17094 + incl %ss:early_recursion_flag
17095 + cld
17096 pushl %eax
17097 pushl %ecx
17098 pushl %edx
17099 @@ -620,9 +706,6 @@ ignore_int:
17100 movl $(__KERNEL_DS),%eax
17101 movl %eax,%ds
17102 movl %eax,%es
17103 - cmpl $2,early_recursion_flag
17104 - je hlt_loop
17105 - incl early_recursion_flag
17106 pushl 16(%esp)
17107 pushl 24(%esp)
17108 pushl 32(%esp)
17109 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17110 /*
17111 * BSS section
17112 */
17113 -__PAGE_ALIGNED_BSS
17114 - .align PAGE_SIZE
17115 #ifdef CONFIG_X86_PAE
17116 +.section .initial_pg_pmd,"a",@progbits
17117 initial_pg_pmd:
17118 .fill 1024*KPMDS,4,0
17119 #else
17120 +.section .initial_page_table,"a",@progbits
17121 ENTRY(initial_page_table)
17122 .fill 1024,4,0
17123 #endif
17124 +.section .initial_pg_fixmap,"a",@progbits
17125 initial_pg_fixmap:
17126 .fill 1024,4,0
17127 +.section .empty_zero_page,"a",@progbits
17128 ENTRY(empty_zero_page)
17129 .fill 4096,1,0
17130 +.section .swapper_pg_dir,"a",@progbits
17131 ENTRY(swapper_pg_dir)
17132 +#ifdef CONFIG_X86_PAE
17133 + .fill 4,8,0
17134 +#else
17135 .fill 1024,4,0
17136 +#endif
17137 +
17138 +/*
17139 + * The IDT has to be page-aligned to simplify the Pentium
17140 + * F0 0F bug workaround.. We have a special link segment
17141 + * for this.
17142 + */
17143 +.section .idt,"a",@progbits
17144 +ENTRY(idt_table)
17145 + .fill 256,8,0
17146
17147 /*
17148 * This starts the data section.
17149 */
17150 #ifdef CONFIG_X86_PAE
17151 -__PAGE_ALIGNED_DATA
17152 - /* Page-aligned for the benefit of paravirt? */
17153 - .align PAGE_SIZE
17154 +.section .initial_page_table,"a",@progbits
17155 ENTRY(initial_page_table)
17156 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17157 # if KPMDS == 3
17158 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17159 # error "Kernel PMDs should be 1, 2 or 3"
17160 # endif
17161 .align PAGE_SIZE /* needs to be page-sized too */
17162 +
17163 +#ifdef CONFIG_PAX_PER_CPU_PGD
17164 +ENTRY(cpu_pgd)
17165 + .rept NR_CPUS
17166 + .fill 4,8,0
17167 + .endr
17168 +#endif
17169 +
17170 #endif
17171
17172 .data
17173 .balign 4
17174 ENTRY(stack_start)
17175 - .long init_thread_union+THREAD_SIZE
17176 + .long init_thread_union+THREAD_SIZE-8
17177
17178 __INITRODATA
17179 int_msg:
17180 @@ -730,7 +835,7 @@ fault_msg:
17181 * segment size, and 32-bit linear address value:
17182 */
17183
17184 - .data
17185 +.section .rodata,"a",@progbits
17186 .globl boot_gdt_descr
17187 .globl idt_descr
17188
17189 @@ -739,7 +844,7 @@ fault_msg:
17190 .word 0 # 32 bit align gdt_desc.address
17191 boot_gdt_descr:
17192 .word __BOOT_DS+7
17193 - .long boot_gdt - __PAGE_OFFSET
17194 + .long pa(boot_gdt)
17195
17196 .word 0 # 32-bit align idt_desc.address
17197 idt_descr:
17198 @@ -750,7 +855,7 @@ idt_descr:
17199 .word 0 # 32 bit align gdt_desc.address
17200 ENTRY(early_gdt_descr)
17201 .word GDT_ENTRIES*8-1
17202 - .long gdt_page /* Overwritten for secondary CPUs */
17203 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17204
17205 /*
17206 * The boot_gdt must mirror the equivalent in setup.S and is
17207 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17208 .align L1_CACHE_BYTES
17209 ENTRY(boot_gdt)
17210 .fill GDT_ENTRY_BOOT_CS,8,0
17211 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17212 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17213 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17214 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17215 +
17216 + .align PAGE_SIZE_asm
17217 +ENTRY(cpu_gdt_table)
17218 + .rept NR_CPUS
17219 + .quad 0x0000000000000000 /* NULL descriptor */
17220 + .quad 0x0000000000000000 /* 0x0b reserved */
17221 + .quad 0x0000000000000000 /* 0x13 reserved */
17222 + .quad 0x0000000000000000 /* 0x1b reserved */
17223 +
17224 +#ifdef CONFIG_PAX_KERNEXEC
17225 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17226 +#else
17227 + .quad 0x0000000000000000 /* 0x20 unused */
17228 +#endif
17229 +
17230 + .quad 0x0000000000000000 /* 0x28 unused */
17231 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17232 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17233 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17234 + .quad 0x0000000000000000 /* 0x4b reserved */
17235 + .quad 0x0000000000000000 /* 0x53 reserved */
17236 + .quad 0x0000000000000000 /* 0x5b reserved */
17237 +
17238 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17239 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17240 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17241 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17242 +
17243 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17244 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17245 +
17246 + /*
17247 + * Segments used for calling PnP BIOS have byte granularity.
17248 + * The code segments and data segments have fixed 64k limits,
17249 + * the transfer segment sizes are set at run time.
17250 + */
17251 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17252 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17253 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17254 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17255 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17256 +
17257 + /*
17258 + * The APM segments have byte granularity and their bases
17259 + * are set at run time. All have 64k limits.
17260 + */
17261 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17262 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17263 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17264 +
17265 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17266 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17267 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17268 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17269 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17270 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17271 +
17272 + /* Be sure this is zeroed to avoid false validations in Xen */
17273 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17274 + .endr
17275 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17276 index 94bf9cc..400455a 100644
17277 --- a/arch/x86/kernel/head_64.S
17278 +++ b/arch/x86/kernel/head_64.S
17279 @@ -20,6 +20,8 @@
17280 #include <asm/processor-flags.h>
17281 #include <asm/percpu.h>
17282 #include <asm/nops.h>
17283 +#include <asm/cpufeature.h>
17284 +#include <asm/alternative-asm.h>
17285
17286 #ifdef CONFIG_PARAVIRT
17287 #include <asm/asm-offsets.h>
17288 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17289 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17290 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17291 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17292 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17293 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17294 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17295 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17296 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17297 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17298
17299 .text
17300 __HEAD
17301 @@ -88,35 +96,23 @@ startup_64:
17302 */
17303 addq %rbp, init_level4_pgt + 0(%rip)
17304 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17305 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17306 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17307 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17308 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17309
17310 addq %rbp, level3_ident_pgt + 0(%rip)
17311 +#ifndef CONFIG_XEN
17312 + addq %rbp, level3_ident_pgt + 8(%rip)
17313 +#endif
17314
17315 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17316 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17317 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17318 +
17319 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17320 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17321
17322 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17323 -
17324 - /* Add an Identity mapping if I am above 1G */
17325 - leaq _text(%rip), %rdi
17326 - andq $PMD_PAGE_MASK, %rdi
17327 -
17328 - movq %rdi, %rax
17329 - shrq $PUD_SHIFT, %rax
17330 - andq $(PTRS_PER_PUD - 1), %rax
17331 - jz ident_complete
17332 -
17333 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17334 - leaq level3_ident_pgt(%rip), %rbx
17335 - movq %rdx, 0(%rbx, %rax, 8)
17336 -
17337 - movq %rdi, %rax
17338 - shrq $PMD_SHIFT, %rax
17339 - andq $(PTRS_PER_PMD - 1), %rax
17340 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17341 - leaq level2_spare_pgt(%rip), %rbx
17342 - movq %rdx, 0(%rbx, %rax, 8)
17343 -ident_complete:
17344 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17345
17346 /*
17347 * Fixup the kernel text+data virtual addresses. Note that
17348 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17349 * after the boot processor executes this code.
17350 */
17351
17352 - /* Enable PAE mode and PGE */
17353 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17354 + /* Enable PAE mode and PSE/PGE */
17355 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17356 movq %rax, %cr4
17357
17358 /* Setup early boot stage 4 level pagetables. */
17359 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17360 movl $MSR_EFER, %ecx
17361 rdmsr
17362 btsl $_EFER_SCE, %eax /* Enable System Call */
17363 - btl $20,%edi /* No Execute supported? */
17364 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17365 jnc 1f
17366 btsl $_EFER_NX, %eax
17367 + leaq init_level4_pgt(%rip), %rdi
17368 +#ifndef CONFIG_EFI
17369 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17370 +#endif
17371 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17372 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17373 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17374 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17375 1: wrmsr /* Make changes effective */
17376
17377 /* Setup cr0 */
17378 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17379 * jump. In addition we need to ensure %cs is set so we make this
17380 * a far return.
17381 */
17382 + pax_set_fptr_mask
17383 movq initial_code(%rip),%rax
17384 pushq $0 # fake return address to stop unwinder
17385 pushq $__KERNEL_CS # set correct cs
17386 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17387 bad_address:
17388 jmp bad_address
17389
17390 - .section ".init.text","ax"
17391 + __INIT
17392 .globl early_idt_handlers
17393 early_idt_handlers:
17394 # 104(%rsp) %rflags
17395 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17396 addq $16,%rsp # drop vector number and error code
17397 decl early_recursion_flag(%rip)
17398 INTERRUPT_RETURN
17399 + .previous
17400
17401 + __INITDATA
17402 .balign 4
17403 early_recursion_flag:
17404 .long 0
17405 + .previous
17406
17407 + .section .rodata,"a",@progbits
17408 #ifdef CONFIG_EARLY_PRINTK
17409 early_idt_msg:
17410 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17411 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17412 #endif /* CONFIG_EARLY_PRINTK */
17413 .previous
17414
17415 + .section .rodata,"a",@progbits
17416 #define NEXT_PAGE(name) \
17417 .balign PAGE_SIZE; \
17418 ENTRY(name)
17419 @@ -372,7 +382,6 @@ ENTRY(name)
17420 i = i + 1 ; \
17421 .endr
17422
17423 - .data
17424 /*
17425 * This default setting generates an ident mapping at address 0x100000
17426 * and a mapping for the kernel that precisely maps virtual address
17427 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17428 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17429 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17430 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17431 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17432 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17433 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17434 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17435 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17436 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17437 .org init_level4_pgt + L4_START_KERNEL*8, 0
17438 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17439 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17440
17441 +#ifdef CONFIG_PAX_PER_CPU_PGD
17442 +NEXT_PAGE(cpu_pgd)
17443 + .rept NR_CPUS
17444 + .fill 512,8,0
17445 + .endr
17446 +#endif
17447 +
17448 NEXT_PAGE(level3_ident_pgt)
17449 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17450 +#ifdef CONFIG_XEN
17451 .fill 511,8,0
17452 +#else
17453 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17454 + .fill 510,8,0
17455 +#endif
17456 +
17457 +NEXT_PAGE(level3_vmalloc_start_pgt)
17458 + .fill 512,8,0
17459 +
17460 +NEXT_PAGE(level3_vmalloc_end_pgt)
17461 + .fill 512,8,0
17462 +
17463 +NEXT_PAGE(level3_vmemmap_pgt)
17464 + .fill L3_VMEMMAP_START,8,0
17465 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17466
17467 NEXT_PAGE(level3_kernel_pgt)
17468 .fill L3_START_KERNEL,8,0
17469 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17470 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17471 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17472
17473 +NEXT_PAGE(level2_vmemmap_pgt)
17474 + .fill 512,8,0
17475 +
17476 NEXT_PAGE(level2_fixmap_pgt)
17477 - .fill 506,8,0
17478 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17479 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17480 - .fill 5,8,0
17481 + .fill 507,8,0
17482 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17483 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17484 + .fill 4,8,0
17485
17486 -NEXT_PAGE(level1_fixmap_pgt)
17487 +NEXT_PAGE(level1_vsyscall_pgt)
17488 .fill 512,8,0
17489
17490 -NEXT_PAGE(level2_ident_pgt)
17491 - /* Since I easily can, map the first 1G.
17492 + /* Since I easily can, map the first 2G.
17493 * Don't set NX because code runs from these pages.
17494 */
17495 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17496 +NEXT_PAGE(level2_ident_pgt)
17497 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17498
17499 NEXT_PAGE(level2_kernel_pgt)
17500 /*
17501 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17502 * If you want to increase this then increase MODULES_VADDR
17503 * too.)
17504 */
17505 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17506 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17507 -
17508 -NEXT_PAGE(level2_spare_pgt)
17509 - .fill 512, 8, 0
17510 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17511
17512 #undef PMDS
17513 #undef NEXT_PAGE
17514
17515 - .data
17516 + .align PAGE_SIZE
17517 +ENTRY(cpu_gdt_table)
17518 + .rept NR_CPUS
17519 + .quad 0x0000000000000000 /* NULL descriptor */
17520 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17521 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17522 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17523 + .quad 0x00cffb000000ffff /* __USER32_CS */
17524 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17525 + .quad 0x00affb000000ffff /* __USER_CS */
17526 +
17527 +#ifdef CONFIG_PAX_KERNEXEC
17528 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17529 +#else
17530 + .quad 0x0 /* unused */
17531 +#endif
17532 +
17533 + .quad 0,0 /* TSS */
17534 + .quad 0,0 /* LDT */
17535 + .quad 0,0,0 /* three TLS descriptors */
17536 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17537 + /* asm/segment.h:GDT_ENTRIES must match this */
17538 +
17539 + /* zero the remaining page */
17540 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17541 + .endr
17542 +
17543 .align 16
17544 .globl early_gdt_descr
17545 early_gdt_descr:
17546 .word GDT_ENTRIES*8-1
17547 early_gdt_descr_base:
17548 - .quad INIT_PER_CPU_VAR(gdt_page)
17549 + .quad cpu_gdt_table
17550
17551 ENTRY(phys_base)
17552 /* This must match the first entry in level2_kernel_pgt */
17553 .quad 0x0000000000000000
17554
17555 #include "../../x86/xen/xen-head.S"
17556 -
17557 - .section .bss, "aw", @nobits
17558 +
17559 + .section .rodata,"a",@progbits
17560 .align L1_CACHE_BYTES
17561 ENTRY(idt_table)
17562 - .skip IDT_ENTRIES * 16
17563 + .fill 512,8,0
17564
17565 .align L1_CACHE_BYTES
17566 ENTRY(nmi_idt_table)
17567 - .skip IDT_ENTRIES * 16
17568 + .fill 512,8,0
17569
17570 __PAGE_ALIGNED_BSS
17571 .align PAGE_SIZE
17572 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17573 index 9c3bd4a..e1d9b35 100644
17574 --- a/arch/x86/kernel/i386_ksyms_32.c
17575 +++ b/arch/x86/kernel/i386_ksyms_32.c
17576 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17577 EXPORT_SYMBOL(cmpxchg8b_emu);
17578 #endif
17579
17580 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17581 +
17582 /* Networking helper routines. */
17583 EXPORT_SYMBOL(csum_partial_copy_generic);
17584 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17585 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17586
17587 EXPORT_SYMBOL(__get_user_1);
17588 EXPORT_SYMBOL(__get_user_2);
17589 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17590
17591 EXPORT_SYMBOL(csum_partial);
17592 EXPORT_SYMBOL(empty_zero_page);
17593 +
17594 +#ifdef CONFIG_PAX_KERNEXEC
17595 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17596 +#endif
17597 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17598 index f250431..54097e7 100644
17599 --- a/arch/x86/kernel/i387.c
17600 +++ b/arch/x86/kernel/i387.c
17601 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17602 static inline bool interrupted_user_mode(void)
17603 {
17604 struct pt_regs *regs = get_irq_regs();
17605 - return regs && user_mode_vm(regs);
17606 + return regs && user_mode(regs);
17607 }
17608
17609 /*
17610 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17611 index 36d1853..bf25736 100644
17612 --- a/arch/x86/kernel/i8259.c
17613 +++ b/arch/x86/kernel/i8259.c
17614 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17615 "spurious 8259A interrupt: IRQ%d.\n", irq);
17616 spurious_irq_mask |= irqmask;
17617 }
17618 - atomic_inc(&irq_err_count);
17619 + atomic_inc_unchecked(&irq_err_count);
17620 /*
17621 * Theoretically we do not have to handle this IRQ,
17622 * but in Linux this does not cause problems and is
17623 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17624 index 8c96897..be66bfa 100644
17625 --- a/arch/x86/kernel/ioport.c
17626 +++ b/arch/x86/kernel/ioport.c
17627 @@ -6,6 +6,7 @@
17628 #include <linux/sched.h>
17629 #include <linux/kernel.h>
17630 #include <linux/capability.h>
17631 +#include <linux/security.h>
17632 #include <linux/errno.h>
17633 #include <linux/types.h>
17634 #include <linux/ioport.h>
17635 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17636
17637 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17638 return -EINVAL;
17639 +#ifdef CONFIG_GRKERNSEC_IO
17640 + if (turn_on && grsec_disable_privio) {
17641 + gr_handle_ioperm();
17642 + return -EPERM;
17643 + }
17644 +#endif
17645 if (turn_on && !capable(CAP_SYS_RAWIO))
17646 return -EPERM;
17647
17648 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17649 * because the ->io_bitmap_max value must match the bitmap
17650 * contents:
17651 */
17652 - tss = &per_cpu(init_tss, get_cpu());
17653 + tss = init_tss + get_cpu();
17654
17655 if (turn_on)
17656 bitmap_clear(t->io_bitmap_ptr, from, num);
17657 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17658 return -EINVAL;
17659 /* Trying to gain more privileges? */
17660 if (level > old) {
17661 +#ifdef CONFIG_GRKERNSEC_IO
17662 + if (grsec_disable_privio) {
17663 + gr_handle_iopl();
17664 + return -EPERM;
17665 + }
17666 +#endif
17667 if (!capable(CAP_SYS_RAWIO))
17668 return -EPERM;
17669 }
17670 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17671 index d44f782..31ab01e 100644
17672 --- a/arch/x86/kernel/irq.c
17673 +++ b/arch/x86/kernel/irq.c
17674 @@ -18,7 +18,7 @@
17675 #include <asm/mce.h>
17676 #include <asm/hw_irq.h>
17677
17678 -atomic_t irq_err_count;
17679 +atomic_unchecked_t irq_err_count;
17680
17681 /* Function pointer for generic interrupt vector handling */
17682 void (*x86_platform_ipi_callback)(void) = NULL;
17683 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17684 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17685 seq_printf(p, " Machine check polls\n");
17686 #endif
17687 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17688 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17689 #if defined(CONFIG_X86_IO_APIC)
17690 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17691 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17692 #endif
17693 return 0;
17694 }
17695 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17696
17697 u64 arch_irq_stat(void)
17698 {
17699 - u64 sum = atomic_read(&irq_err_count);
17700 + u64 sum = atomic_read_unchecked(&irq_err_count);
17701
17702 #ifdef CONFIG_X86_IO_APIC
17703 - sum += atomic_read(&irq_mis_count);
17704 + sum += atomic_read_unchecked(&irq_mis_count);
17705 #endif
17706 return sum;
17707 }
17708 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17709 index 344faf8..355f60d 100644
17710 --- a/arch/x86/kernel/irq_32.c
17711 +++ b/arch/x86/kernel/irq_32.c
17712 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17713 __asm__ __volatile__("andl %%esp,%0" :
17714 "=r" (sp) : "0" (THREAD_SIZE - 1));
17715
17716 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17717 + return sp < STACK_WARN;
17718 }
17719
17720 static void print_stack_overflow(void)
17721 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17722 * per-CPU IRQ handling contexts (thread information and stack)
17723 */
17724 union irq_ctx {
17725 - struct thread_info tinfo;
17726 - u32 stack[THREAD_SIZE/sizeof(u32)];
17727 + unsigned long previous_esp;
17728 + u32 stack[THREAD_SIZE/sizeof(u32)];
17729 } __attribute__((aligned(THREAD_SIZE)));
17730
17731 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17732 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17733 static inline int
17734 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17735 {
17736 - union irq_ctx *curctx, *irqctx;
17737 + union irq_ctx *irqctx;
17738 u32 *isp, arg1, arg2;
17739
17740 - curctx = (union irq_ctx *) current_thread_info();
17741 irqctx = __this_cpu_read(hardirq_ctx);
17742
17743 /*
17744 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17745 * handler) we can't do that and just have to keep using the
17746 * current stack (which is the irq stack already after all)
17747 */
17748 - if (unlikely(curctx == irqctx))
17749 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17750 return 0;
17751
17752 /* build the stack frame on the IRQ stack */
17753 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17754 - irqctx->tinfo.task = curctx->tinfo.task;
17755 - irqctx->tinfo.previous_esp = current_stack_pointer;
17756 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17757 + irqctx->previous_esp = current_stack_pointer;
17758
17759 - /* Copy the preempt_count so that the [soft]irq checks work. */
17760 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17761 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17762 + __set_fs(MAKE_MM_SEG(0));
17763 +#endif
17764
17765 if (unlikely(overflow))
17766 call_on_stack(print_stack_overflow, isp);
17767 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17768 : "0" (irq), "1" (desc), "2" (isp),
17769 "D" (desc->handle_irq)
17770 : "memory", "cc", "ecx");
17771 +
17772 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17773 + __set_fs(current_thread_info()->addr_limit);
17774 +#endif
17775 +
17776 return 1;
17777 }
17778
17779 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17780 */
17781 void __cpuinit irq_ctx_init(int cpu)
17782 {
17783 - union irq_ctx *irqctx;
17784 -
17785 if (per_cpu(hardirq_ctx, cpu))
17786 return;
17787
17788 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17789 - THREADINFO_GFP,
17790 - THREAD_SIZE_ORDER));
17791 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17792 - irqctx->tinfo.cpu = cpu;
17793 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17794 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17795 -
17796 - per_cpu(hardirq_ctx, cpu) = irqctx;
17797 -
17798 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17799 - THREADINFO_GFP,
17800 - THREAD_SIZE_ORDER));
17801 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17802 - irqctx->tinfo.cpu = cpu;
17803 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17804 -
17805 - per_cpu(softirq_ctx, cpu) = irqctx;
17806 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17807 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17808 +
17809 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17810 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17811
17812 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17813 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17814 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17815 asmlinkage void do_softirq(void)
17816 {
17817 unsigned long flags;
17818 - struct thread_info *curctx;
17819 union irq_ctx *irqctx;
17820 u32 *isp;
17821
17822 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17823 local_irq_save(flags);
17824
17825 if (local_softirq_pending()) {
17826 - curctx = current_thread_info();
17827 irqctx = __this_cpu_read(softirq_ctx);
17828 - irqctx->tinfo.task = curctx->task;
17829 - irqctx->tinfo.previous_esp = current_stack_pointer;
17830 + irqctx->previous_esp = current_stack_pointer;
17831
17832 /* build the stack frame on the softirq stack */
17833 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17834 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17835 +
17836 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17837 + __set_fs(MAKE_MM_SEG(0));
17838 +#endif
17839
17840 call_on_stack(__do_softirq, isp);
17841 +
17842 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17843 + __set_fs(current_thread_info()->addr_limit);
17844 +#endif
17845 +
17846 /*
17847 * Shouldn't happen, we returned above if in_interrupt():
17848 */
17849 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17850 if (unlikely(!desc))
17851 return false;
17852
17853 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17854 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17855 if (unlikely(overflow))
17856 print_stack_overflow();
17857 desc->handle_irq(irq, desc);
17858 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17859 index d04d3ec..ea4b374 100644
17860 --- a/arch/x86/kernel/irq_64.c
17861 +++ b/arch/x86/kernel/irq_64.c
17862 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17863 u64 estack_top, estack_bottom;
17864 u64 curbase = (u64)task_stack_page(current);
17865
17866 - if (user_mode_vm(regs))
17867 + if (user_mode(regs))
17868 return;
17869
17870 if (regs->sp >= curbase + sizeof(struct thread_info) +
17871 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17872 index dc1404b..bbc43e7 100644
17873 --- a/arch/x86/kernel/kdebugfs.c
17874 +++ b/arch/x86/kernel/kdebugfs.c
17875 @@ -27,7 +27,7 @@ struct setup_data_node {
17876 u32 len;
17877 };
17878
17879 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17880 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17881 size_t count, loff_t *ppos)
17882 {
17883 struct setup_data_node *node = file->private_data;
17884 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17885 index 3f61904..873cea9 100644
17886 --- a/arch/x86/kernel/kgdb.c
17887 +++ b/arch/x86/kernel/kgdb.c
17888 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17889 #ifdef CONFIG_X86_32
17890 switch (regno) {
17891 case GDB_SS:
17892 - if (!user_mode_vm(regs))
17893 + if (!user_mode(regs))
17894 *(unsigned long *)mem = __KERNEL_DS;
17895 break;
17896 case GDB_SP:
17897 - if (!user_mode_vm(regs))
17898 + if (!user_mode(regs))
17899 *(unsigned long *)mem = kernel_stack_pointer(regs);
17900 break;
17901 case GDB_GS:
17902 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17903 case 'k':
17904 /* clear the trace bit */
17905 linux_regs->flags &= ~X86_EFLAGS_TF;
17906 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17907 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17908
17909 /* set the trace bit if we're stepping */
17910 if (remcomInBuffer[0] == 's') {
17911 linux_regs->flags |= X86_EFLAGS_TF;
17912 - atomic_set(&kgdb_cpu_doing_single_step,
17913 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17914 raw_smp_processor_id());
17915 }
17916
17917 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17918
17919 switch (cmd) {
17920 case DIE_DEBUG:
17921 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17922 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17923 if (user_mode(regs))
17924 return single_step_cont(regs, args);
17925 break;
17926 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17927 index c5e410e..da6aaf9 100644
17928 --- a/arch/x86/kernel/kprobes-opt.c
17929 +++ b/arch/x86/kernel/kprobes-opt.c
17930 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17931 * Verify if the address gap is in 2GB range, because this uses
17932 * a relative jump.
17933 */
17934 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17935 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17936 if (abs(rel) > 0x7fffffff)
17937 return -ERANGE;
17938
17939 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17940 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17941
17942 /* Set probe function call */
17943 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17944 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17945
17946 /* Set returning jmp instruction at the tail of out-of-line buffer */
17947 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17948 - (u8 *)op->kp.addr + op->optinsn.size);
17949 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17950
17951 flush_icache_range((unsigned long) buf,
17952 (unsigned long) buf + TMPL_END_IDX +
17953 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17954 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17955
17956 /* Backup instructions which will be replaced by jump address */
17957 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17958 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17959 RELATIVE_ADDR_SIZE);
17960
17961 insn_buf[0] = RELATIVEJUMP_OPCODE;
17962 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17963 index e2f751e..dffa2a0 100644
17964 --- a/arch/x86/kernel/kprobes.c
17965 +++ b/arch/x86/kernel/kprobes.c
17966 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17967 } __attribute__((packed)) *insn;
17968
17969 insn = (struct __arch_relative_insn *)from;
17970 +
17971 + pax_open_kernel();
17972 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17973 insn->op = op;
17974 + pax_close_kernel();
17975 }
17976
17977 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17978 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17979 kprobe_opcode_t opcode;
17980 kprobe_opcode_t *orig_opcodes = opcodes;
17981
17982 - if (search_exception_tables((unsigned long)opcodes))
17983 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17984 return 0; /* Page fault may occur on this address. */
17985
17986 retry:
17987 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17988 /* Another subsystem puts a breakpoint, failed to recover */
17989 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17990 return 0;
17991 + pax_open_kernel();
17992 memcpy(dest, insn.kaddr, insn.length);
17993 + pax_close_kernel();
17994
17995 #ifdef CONFIG_X86_64
17996 if (insn_rip_relative(&insn)) {
17997 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17998 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17999 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
18000 disp = (u8 *) dest + insn_offset_displacement(&insn);
18001 + pax_open_kernel();
18002 *(s32 *) disp = (s32) newdisp;
18003 + pax_close_kernel();
18004 }
18005 #endif
18006 return insn.length;
18007 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18008 * nor set current_kprobe, because it doesn't use single
18009 * stepping.
18010 */
18011 - regs->ip = (unsigned long)p->ainsn.insn;
18012 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18013 preempt_enable_no_resched();
18014 return;
18015 }
18016 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
18017 if (p->opcode == BREAKPOINT_INSTRUCTION)
18018 regs->ip = (unsigned long)p->addr;
18019 else
18020 - regs->ip = (unsigned long)p->ainsn.insn;
18021 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
18022 }
18023
18024 /*
18025 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
18026 setup_singlestep(p, regs, kcb, 0);
18027 return 1;
18028 }
18029 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18030 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18031 /*
18032 * The breakpoint instruction was removed right
18033 * after we hit it. Another cpu has removed
18034 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18035 " movq %rax, 152(%rsp)\n"
18036 RESTORE_REGS_STRING
18037 " popfq\n"
18038 +#ifdef KERNEXEC_PLUGIN
18039 + " btsq $63,(%rsp)\n"
18040 +#endif
18041 #else
18042 " pushf\n"
18043 SAVE_REGS_STRING
18044 @@ -765,7 +775,7 @@ static void __kprobes
18045 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18046 {
18047 unsigned long *tos = stack_addr(regs);
18048 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18049 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18050 unsigned long orig_ip = (unsigned long)p->addr;
18051 kprobe_opcode_t *insn = p->ainsn.insn;
18052
18053 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18054 struct die_args *args = data;
18055 int ret = NOTIFY_DONE;
18056
18057 - if (args->regs && user_mode_vm(args->regs))
18058 + if (args->regs && user_mode(args->regs))
18059 return ret;
18060
18061 switch (val) {
18062 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18063 index ebc9873..1b9724b 100644
18064 --- a/arch/x86/kernel/ldt.c
18065 +++ b/arch/x86/kernel/ldt.c
18066 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18067 if (reload) {
18068 #ifdef CONFIG_SMP
18069 preempt_disable();
18070 - load_LDT(pc);
18071 + load_LDT_nolock(pc);
18072 if (!cpumask_equal(mm_cpumask(current->mm),
18073 cpumask_of(smp_processor_id())))
18074 smp_call_function(flush_ldt, current->mm, 1);
18075 preempt_enable();
18076 #else
18077 - load_LDT(pc);
18078 + load_LDT_nolock(pc);
18079 #endif
18080 }
18081 if (oldsize) {
18082 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18083 return err;
18084
18085 for (i = 0; i < old->size; i++)
18086 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18087 + write_ldt_entry(new->ldt, i, old->ldt + i);
18088 return 0;
18089 }
18090
18091 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18092 retval = copy_ldt(&mm->context, &old_mm->context);
18093 mutex_unlock(&old_mm->context.lock);
18094 }
18095 +
18096 + if (tsk == current) {
18097 + mm->context.vdso = 0;
18098 +
18099 +#ifdef CONFIG_X86_32
18100 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18101 + mm->context.user_cs_base = 0UL;
18102 + mm->context.user_cs_limit = ~0UL;
18103 +
18104 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18105 + cpus_clear(mm->context.cpu_user_cs_mask);
18106 +#endif
18107 +
18108 +#endif
18109 +#endif
18110 +
18111 + }
18112 +
18113 return retval;
18114 }
18115
18116 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18117 }
18118 }
18119
18120 +#ifdef CONFIG_PAX_SEGMEXEC
18121 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18122 + error = -EINVAL;
18123 + goto out_unlock;
18124 + }
18125 +#endif
18126 +
18127 fill_ldt(&ldt, &ldt_info);
18128 if (oldmode)
18129 ldt.avl = 0;
18130 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18131 index 5b19e4d..6476a76 100644
18132 --- a/arch/x86/kernel/machine_kexec_32.c
18133 +++ b/arch/x86/kernel/machine_kexec_32.c
18134 @@ -26,7 +26,7 @@
18135 #include <asm/cacheflush.h>
18136 #include <asm/debugreg.h>
18137
18138 -static void set_idt(void *newidt, __u16 limit)
18139 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18140 {
18141 struct desc_ptr curidt;
18142
18143 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18144 }
18145
18146
18147 -static void set_gdt(void *newgdt, __u16 limit)
18148 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18149 {
18150 struct desc_ptr curgdt;
18151
18152 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18153 }
18154
18155 control_page = page_address(image->control_code_page);
18156 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18157 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18158
18159 relocate_kernel_ptr = control_page;
18160 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18161 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18162 index 0327e2b..e43737b 100644
18163 --- a/arch/x86/kernel/microcode_intel.c
18164 +++ b/arch/x86/kernel/microcode_intel.c
18165 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18166
18167 static int get_ucode_user(void *to, const void *from, size_t n)
18168 {
18169 - return copy_from_user(to, from, n);
18170 + return copy_from_user(to, (const void __force_user *)from, n);
18171 }
18172
18173 static enum ucode_state
18174 request_microcode_user(int cpu, const void __user *buf, size_t size)
18175 {
18176 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18177 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18178 }
18179
18180 static void microcode_fini_cpu(int cpu)
18181 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18182 index 216a4d7..b328f09 100644
18183 --- a/arch/x86/kernel/module.c
18184 +++ b/arch/x86/kernel/module.c
18185 @@ -43,15 +43,60 @@ do { \
18186 } while (0)
18187 #endif
18188
18189 -void *module_alloc(unsigned long size)
18190 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18191 {
18192 - if (PAGE_ALIGN(size) > MODULES_LEN)
18193 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18194 return NULL;
18195 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18196 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18197 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18198 -1, __builtin_return_address(0));
18199 }
18200
18201 +void *module_alloc(unsigned long size)
18202 +{
18203 +
18204 +#ifdef CONFIG_PAX_KERNEXEC
18205 + return __module_alloc(size, PAGE_KERNEL);
18206 +#else
18207 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18208 +#endif
18209 +
18210 +}
18211 +
18212 +#ifdef CONFIG_PAX_KERNEXEC
18213 +#ifdef CONFIG_X86_32
18214 +void *module_alloc_exec(unsigned long size)
18215 +{
18216 + struct vm_struct *area;
18217 +
18218 + if (size == 0)
18219 + return NULL;
18220 +
18221 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18222 + return area ? area->addr : NULL;
18223 +}
18224 +EXPORT_SYMBOL(module_alloc_exec);
18225 +
18226 +void module_free_exec(struct module *mod, void *module_region)
18227 +{
18228 + vunmap(module_region);
18229 +}
18230 +EXPORT_SYMBOL(module_free_exec);
18231 +#else
18232 +void module_free_exec(struct module *mod, void *module_region)
18233 +{
18234 + module_free(mod, module_region);
18235 +}
18236 +EXPORT_SYMBOL(module_free_exec);
18237 +
18238 +void *module_alloc_exec(unsigned long size)
18239 +{
18240 + return __module_alloc(size, PAGE_KERNEL_RX);
18241 +}
18242 +EXPORT_SYMBOL(module_alloc_exec);
18243 +#endif
18244 +#endif
18245 +
18246 #ifdef CONFIG_X86_32
18247 int apply_relocate(Elf32_Shdr *sechdrs,
18248 const char *strtab,
18249 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18250 unsigned int i;
18251 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18252 Elf32_Sym *sym;
18253 - uint32_t *location;
18254 + uint32_t *plocation, location;
18255
18256 DEBUGP("Applying relocate section %u to %u\n",
18257 relsec, sechdrs[relsec].sh_info);
18258 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18259 /* This is where to make the change */
18260 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18261 - + rel[i].r_offset;
18262 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18263 + location = (uint32_t)plocation;
18264 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18265 + plocation = ktla_ktva((void *)plocation);
18266 /* This is the symbol it is referring to. Note that all
18267 undefined symbols have been resolved. */
18268 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18269 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18270 switch (ELF32_R_TYPE(rel[i].r_info)) {
18271 case R_386_32:
18272 /* We add the value into the location given */
18273 - *location += sym->st_value;
18274 + pax_open_kernel();
18275 + *plocation += sym->st_value;
18276 + pax_close_kernel();
18277 break;
18278 case R_386_PC32:
18279 /* Add the value, subtract its position */
18280 - *location += sym->st_value - (uint32_t)location;
18281 + pax_open_kernel();
18282 + *plocation += sym->st_value - location;
18283 + pax_close_kernel();
18284 break;
18285 default:
18286 pr_err("%s: Unknown relocation: %u\n",
18287 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18288 case R_X86_64_NONE:
18289 break;
18290 case R_X86_64_64:
18291 + pax_open_kernel();
18292 *(u64 *)loc = val;
18293 + pax_close_kernel();
18294 break;
18295 case R_X86_64_32:
18296 + pax_open_kernel();
18297 *(u32 *)loc = val;
18298 + pax_close_kernel();
18299 if (val != *(u32 *)loc)
18300 goto overflow;
18301 break;
18302 case R_X86_64_32S:
18303 + pax_open_kernel();
18304 *(s32 *)loc = val;
18305 + pax_close_kernel();
18306 if ((s64)val != *(s32 *)loc)
18307 goto overflow;
18308 break;
18309 case R_X86_64_PC32:
18310 val -= (u64)loc;
18311 + pax_open_kernel();
18312 *(u32 *)loc = val;
18313 + pax_close_kernel();
18314 +
18315 #if 0
18316 if ((s64)val != *(s32 *)loc)
18317 goto overflow;
18318 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18319 index f84f5c5..e27e54b 100644
18320 --- a/arch/x86/kernel/nmi.c
18321 +++ b/arch/x86/kernel/nmi.c
18322 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
18323 dotraplinkage notrace __kprobes void
18324 do_nmi(struct pt_regs *regs, long error_code)
18325 {
18326 +
18327 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18328 + if (!user_mode(regs)) {
18329 + unsigned long cs = regs->cs & 0xFFFF;
18330 + unsigned long ip = ktva_ktla(regs->ip);
18331 +
18332 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18333 + regs->ip = ip;
18334 + }
18335 +#endif
18336 +
18337 nmi_nesting_preprocess(regs);
18338
18339 nmi_enter();
18340 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18341 index 676b8c7..870ba04 100644
18342 --- a/arch/x86/kernel/paravirt-spinlocks.c
18343 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18344 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18345 arch_spin_lock(lock);
18346 }
18347
18348 -struct pv_lock_ops pv_lock_ops = {
18349 +struct pv_lock_ops pv_lock_ops __read_only = {
18350 #ifdef CONFIG_SMP
18351 .spin_is_locked = __ticket_spin_is_locked,
18352 .spin_is_contended = __ticket_spin_is_contended,
18353 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18354 index 17fff18..7bb2088 100644
18355 --- a/arch/x86/kernel/paravirt.c
18356 +++ b/arch/x86/kernel/paravirt.c
18357 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18358 {
18359 return x;
18360 }
18361 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18362 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18363 +#endif
18364
18365 void __init default_banner(void)
18366 {
18367 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18368 if (opfunc == NULL)
18369 /* If there's no function, patch it with a ud2a (BUG) */
18370 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18371 - else if (opfunc == _paravirt_nop)
18372 + else if (opfunc == (void *)_paravirt_nop)
18373 /* If the operation is a nop, then nop the callsite */
18374 ret = paravirt_patch_nop();
18375
18376 /* identity functions just return their single argument */
18377 - else if (opfunc == _paravirt_ident_32)
18378 + else if (opfunc == (void *)_paravirt_ident_32)
18379 ret = paravirt_patch_ident_32(insnbuf, len);
18380 - else if (opfunc == _paravirt_ident_64)
18381 + else if (opfunc == (void *)_paravirt_ident_64)
18382 ret = paravirt_patch_ident_64(insnbuf, len);
18383 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18384 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18385 + ret = paravirt_patch_ident_64(insnbuf, len);
18386 +#endif
18387
18388 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18389 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18390 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18391 if (insn_len > len || start == NULL)
18392 insn_len = len;
18393 else
18394 - memcpy(insnbuf, start, insn_len);
18395 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18396
18397 return insn_len;
18398 }
18399 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18400 preempt_enable();
18401 }
18402
18403 -struct pv_info pv_info = {
18404 +struct pv_info pv_info __read_only = {
18405 .name = "bare hardware",
18406 .paravirt_enabled = 0,
18407 .kernel_rpl = 0,
18408 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18409 #endif
18410 };
18411
18412 -struct pv_init_ops pv_init_ops = {
18413 +struct pv_init_ops pv_init_ops __read_only = {
18414 .patch = native_patch,
18415 };
18416
18417 -struct pv_time_ops pv_time_ops = {
18418 +struct pv_time_ops pv_time_ops __read_only = {
18419 .sched_clock = native_sched_clock,
18420 .steal_clock = native_steal_clock,
18421 };
18422
18423 -struct pv_irq_ops pv_irq_ops = {
18424 +struct pv_irq_ops pv_irq_ops __read_only = {
18425 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18426 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18427 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18428 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18429 #endif
18430 };
18431
18432 -struct pv_cpu_ops pv_cpu_ops = {
18433 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18434 .cpuid = native_cpuid,
18435 .get_debugreg = native_get_debugreg,
18436 .set_debugreg = native_set_debugreg,
18437 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18438 .end_context_switch = paravirt_nop,
18439 };
18440
18441 -struct pv_apic_ops pv_apic_ops = {
18442 +struct pv_apic_ops pv_apic_ops __read_only = {
18443 #ifdef CONFIG_X86_LOCAL_APIC
18444 .startup_ipi_hook = paravirt_nop,
18445 #endif
18446 };
18447
18448 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18449 +#ifdef CONFIG_X86_32
18450 +#ifdef CONFIG_X86_PAE
18451 +/* 64-bit pagetable entries */
18452 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18453 +#else
18454 /* 32-bit pagetable entries */
18455 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18456 +#endif
18457 #else
18458 /* 64-bit pagetable entries */
18459 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18460 #endif
18461
18462 -struct pv_mmu_ops pv_mmu_ops = {
18463 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18464
18465 .read_cr2 = native_read_cr2,
18466 .write_cr2 = native_write_cr2,
18467 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18468 .make_pud = PTE_IDENT,
18469
18470 .set_pgd = native_set_pgd,
18471 + .set_pgd_batched = native_set_pgd_batched,
18472 #endif
18473 #endif /* PAGETABLE_LEVELS >= 3 */
18474
18475 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18476 },
18477
18478 .set_fixmap = native_set_fixmap,
18479 +
18480 +#ifdef CONFIG_PAX_KERNEXEC
18481 + .pax_open_kernel = native_pax_open_kernel,
18482 + .pax_close_kernel = native_pax_close_kernel,
18483 +#endif
18484 +
18485 };
18486
18487 EXPORT_SYMBOL_GPL(pv_time_ops);
18488 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18489 index 35ccf75..7a15747 100644
18490 --- a/arch/x86/kernel/pci-iommu_table.c
18491 +++ b/arch/x86/kernel/pci-iommu_table.c
18492 @@ -2,7 +2,7 @@
18493 #include <asm/iommu_table.h>
18494 #include <linux/string.h>
18495 #include <linux/kallsyms.h>
18496 -
18497 +#include <linux/sched.h>
18498
18499 #define DEBUG 1
18500
18501 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18502 index ef6a845..8028ed3 100644
18503 --- a/arch/x86/kernel/process.c
18504 +++ b/arch/x86/kernel/process.c
18505 @@ -36,7 +36,8 @@
18506 * section. Since TSS's are completely CPU-local, we want them
18507 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18508 */
18509 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18510 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18511 +EXPORT_SYMBOL(init_tss);
18512
18513 #ifdef CONFIG_X86_64
18514 static DEFINE_PER_CPU(unsigned char, is_idle);
18515 @@ -94,7 +95,7 @@ void arch_task_cache_init(void)
18516 task_xstate_cachep =
18517 kmem_cache_create("task_xstate", xstate_size,
18518 __alignof__(union thread_xstate),
18519 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18520 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18521 }
18522
18523 static inline void drop_fpu(struct task_struct *tsk)
18524 @@ -117,7 +118,7 @@ void exit_thread(void)
18525 unsigned long *bp = t->io_bitmap_ptr;
18526
18527 if (bp) {
18528 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18529 + struct tss_struct *tss = init_tss + get_cpu();
18530
18531 t->io_bitmap_ptr = NULL;
18532 clear_thread_flag(TIF_IO_BITMAP);
18533 @@ -148,7 +149,7 @@ void show_regs_common(void)
18534 board = dmi_get_system_info(DMI_BOARD_NAME);
18535
18536 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
18537 - current->pid, current->comm, print_tainted(),
18538 + task_pid_nr(current), current->comm, print_tainted(),
18539 init_utsname()->release,
18540 (int)strcspn(init_utsname()->version, " "),
18541 init_utsname()->version,
18542 @@ -161,6 +162,9 @@ void flush_thread(void)
18543 {
18544 struct task_struct *tsk = current;
18545
18546 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18547 + loadsegment(gs, 0);
18548 +#endif
18549 flush_ptrace_hw_breakpoint(tsk);
18550 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18551 drop_fpu(tsk);
18552 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18553 regs.di = (unsigned long) arg;
18554
18555 #ifdef CONFIG_X86_32
18556 - regs.ds = __USER_DS;
18557 - regs.es = __USER_DS;
18558 + regs.ds = __KERNEL_DS;
18559 + regs.es = __KERNEL_DS;
18560 regs.fs = __KERNEL_PERCPU;
18561 - regs.gs = __KERNEL_STACK_CANARY;
18562 + savesegment(gs, regs.gs);
18563 #else
18564 regs.ss = __KERNEL_DS;
18565 #endif
18566 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18567 void exit_idle(void)
18568 {
18569 /* idle loop has pid 0 */
18570 - if (current->pid)
18571 + if (task_pid_nr(current))
18572 return;
18573 __exit_idle();
18574 }
18575 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18576
18577 return ret;
18578 }
18579 -void stop_this_cpu(void *dummy)
18580 +__noreturn void stop_this_cpu(void *dummy)
18581 {
18582 local_irq_disable();
18583 /*
18584 @@ -744,16 +748,37 @@ static int __init idle_setup(char *str)
18585 }
18586 early_param("idle", idle_setup);
18587
18588 -unsigned long arch_align_stack(unsigned long sp)
18589 +#ifdef CONFIG_PAX_RANDKSTACK
18590 +void pax_randomize_kstack(struct pt_regs *regs)
18591 {
18592 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18593 - sp -= get_random_int() % 8192;
18594 - return sp & ~0xf;
18595 -}
18596 + struct thread_struct *thread = &current->thread;
18597 + unsigned long time;
18598
18599 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18600 -{
18601 - unsigned long range_end = mm->brk + 0x02000000;
18602 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18603 -}
18604 + if (!randomize_va_space)
18605 + return;
18606 +
18607 + if (v8086_mode(regs))
18608 + return;
18609
18610 + rdtscl(time);
18611 +
18612 + /* P4 seems to return a 0 LSB, ignore it */
18613 +#ifdef CONFIG_MPENTIUM4
18614 + time &= 0x3EUL;
18615 + time <<= 2;
18616 +#elif defined(CONFIG_X86_64)
18617 + time &= 0xFUL;
18618 + time <<= 4;
18619 +#else
18620 + time &= 0x1FUL;
18621 + time <<= 3;
18622 +#endif
18623 +
18624 + thread->sp0 ^= time;
18625 + load_sp0(init_tss + smp_processor_id(), thread);
18626 +
18627 +#ifdef CONFIG_X86_64
18628 + this_cpu_write(kernel_stack, thread->sp0);
18629 +#endif
18630 +}
18631 +#endif
18632 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18633 index 516fa18..80bd9e6 100644
18634 --- a/arch/x86/kernel/process_32.c
18635 +++ b/arch/x86/kernel/process_32.c
18636 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18637 unsigned long thread_saved_pc(struct task_struct *tsk)
18638 {
18639 return ((unsigned long *)tsk->thread.sp)[3];
18640 +//XXX return tsk->thread.eip;
18641 }
18642
18643 void __show_regs(struct pt_regs *regs, int all)
18644 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18645 unsigned long sp;
18646 unsigned short ss, gs;
18647
18648 - if (user_mode_vm(regs)) {
18649 + if (user_mode(regs)) {
18650 sp = regs->sp;
18651 ss = regs->ss & 0xffff;
18652 - gs = get_user_gs(regs);
18653 } else {
18654 sp = kernel_stack_pointer(regs);
18655 savesegment(ss, ss);
18656 - savesegment(gs, gs);
18657 }
18658 + gs = get_user_gs(regs);
18659
18660 show_regs_common();
18661
18662 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18663 struct task_struct *tsk;
18664 int err;
18665
18666 - childregs = task_pt_regs(p);
18667 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18668 *childregs = *regs;
18669 childregs->ax = 0;
18670 childregs->sp = sp;
18671
18672 p->thread.sp = (unsigned long) childregs;
18673 p->thread.sp0 = (unsigned long) (childregs+1);
18674 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18675
18676 p->thread.ip = (unsigned long) ret_from_fork;
18677
18678 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18679 struct thread_struct *prev = &prev_p->thread,
18680 *next = &next_p->thread;
18681 int cpu = smp_processor_id();
18682 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18683 + struct tss_struct *tss = init_tss + cpu;
18684 fpu_switch_t fpu;
18685
18686 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18687 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18688 */
18689 lazy_save_gs(prev->gs);
18690
18691 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18692 + __set_fs(task_thread_info(next_p)->addr_limit);
18693 +#endif
18694 +
18695 /*
18696 * Load the per-thread Thread-Local Storage descriptor.
18697 */
18698 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18699 */
18700 arch_end_context_switch(next_p);
18701
18702 + this_cpu_write(current_task, next_p);
18703 + this_cpu_write(current_tinfo, &next_p->tinfo);
18704 +
18705 /*
18706 * Restore %gs if needed (which is common)
18707 */
18708 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18709
18710 switch_fpu_finish(next_p, fpu);
18711
18712 - this_cpu_write(current_task, next_p);
18713 -
18714 return prev_p;
18715 }
18716
18717 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18718 } while (count++ < 16);
18719 return 0;
18720 }
18721 -
18722 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18723 index 0a980c9..1d0e689 100644
18724 --- a/arch/x86/kernel/process_64.c
18725 +++ b/arch/x86/kernel/process_64.c
18726 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18727 struct pt_regs *childregs;
18728 struct task_struct *me = current;
18729
18730 - childregs = ((struct pt_regs *)
18731 - (THREAD_SIZE + task_stack_page(p))) - 1;
18732 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18733 *childregs = *regs;
18734
18735 childregs->ax = 0;
18736 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18737 p->thread.sp = (unsigned long) childregs;
18738 p->thread.sp0 = (unsigned long) (childregs+1);
18739 p->thread.usersp = me->thread.usersp;
18740 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18741
18742 set_tsk_thread_flag(p, TIF_FORK);
18743
18744 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18745 struct thread_struct *prev = &prev_p->thread;
18746 struct thread_struct *next = &next_p->thread;
18747 int cpu = smp_processor_id();
18748 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18749 + struct tss_struct *tss = init_tss + cpu;
18750 unsigned fsindex, gsindex;
18751 fpu_switch_t fpu;
18752
18753 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18754 prev->usersp = this_cpu_read(old_rsp);
18755 this_cpu_write(old_rsp, next->usersp);
18756 this_cpu_write(current_task, next_p);
18757 + this_cpu_write(current_tinfo, &next_p->tinfo);
18758
18759 - this_cpu_write(kernel_stack,
18760 - (unsigned long)task_stack_page(next_p) +
18761 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18762 + this_cpu_write(kernel_stack, next->sp0);
18763
18764 /*
18765 * Now maybe reload the debug registers and handle I/O bitmaps
18766 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18767 if (!p || p == current || p->state == TASK_RUNNING)
18768 return 0;
18769 stack = (unsigned long)task_stack_page(p);
18770 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18771 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18772 return 0;
18773 fp = *(u64 *)(p->thread.sp);
18774 do {
18775 - if (fp < (unsigned long)stack ||
18776 - fp >= (unsigned long)stack+THREAD_SIZE)
18777 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18778 return 0;
18779 ip = *(u64 *)(fp+8);
18780 if (!in_sched_functions(ip))
18781 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18782 index c4c6a5c..905f440 100644
18783 --- a/arch/x86/kernel/ptrace.c
18784 +++ b/arch/x86/kernel/ptrace.c
18785 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18786 unsigned long addr, unsigned long data)
18787 {
18788 int ret;
18789 - unsigned long __user *datap = (unsigned long __user *)data;
18790 + unsigned long __user *datap = (__force unsigned long __user *)data;
18791
18792 switch (request) {
18793 /* read the word at location addr in the USER area. */
18794 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18795 if ((int) addr < 0)
18796 return -EIO;
18797 ret = do_get_thread_area(child, addr,
18798 - (struct user_desc __user *)data);
18799 + (__force struct user_desc __user *) data);
18800 break;
18801
18802 case PTRACE_SET_THREAD_AREA:
18803 if ((int) addr < 0)
18804 return -EIO;
18805 ret = do_set_thread_area(child, addr,
18806 - (struct user_desc __user *)data, 0);
18807 + (__force struct user_desc __user *) data, 0);
18808 break;
18809 #endif
18810
18811 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18812 memset(info, 0, sizeof(*info));
18813 info->si_signo = SIGTRAP;
18814 info->si_code = si_code;
18815 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18816 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18817 }
18818
18819 void user_single_step_siginfo(struct task_struct *tsk,
18820 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18821 # define IS_IA32 0
18822 #endif
18823
18824 +#ifdef CONFIG_GRKERNSEC_SETXID
18825 +extern void gr_delayed_cred_worker(void);
18826 +#endif
18827 +
18828 /*
18829 * We must return the syscall number to actually look up in the table.
18830 * This can be -1L to skip running any syscall at all.
18831 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18832 {
18833 long ret = 0;
18834
18835 +#ifdef CONFIG_GRKERNSEC_SETXID
18836 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18837 + gr_delayed_cred_worker();
18838 +#endif
18839 +
18840 /*
18841 * If we stepped into a sysenter/syscall insn, it trapped in
18842 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18843 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18844 {
18845 bool step;
18846
18847 +#ifdef CONFIG_GRKERNSEC_SETXID
18848 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18849 + gr_delayed_cred_worker();
18850 +#endif
18851 +
18852 audit_syscall_exit(regs);
18853
18854 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18855 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18856 index 42eb330..139955c 100644
18857 --- a/arch/x86/kernel/pvclock.c
18858 +++ b/arch/x86/kernel/pvclock.c
18859 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18860 return pv_tsc_khz;
18861 }
18862
18863 -static atomic64_t last_value = ATOMIC64_INIT(0);
18864 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18865
18866 void pvclock_resume(void)
18867 {
18868 - atomic64_set(&last_value, 0);
18869 + atomic64_set_unchecked(&last_value, 0);
18870 }
18871
18872 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18873 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18874 * updating at the same time, and one of them could be slightly behind,
18875 * making the assumption that last_value always go forward fail to hold.
18876 */
18877 - last = atomic64_read(&last_value);
18878 + last = atomic64_read_unchecked(&last_value);
18879 do {
18880 if (ret < last)
18881 return last;
18882 - last = atomic64_cmpxchg(&last_value, last, ret);
18883 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18884 } while (unlikely(last != ret));
18885
18886 return ret;
18887 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18888 index 52190a9..8074389 100644
18889 --- a/arch/x86/kernel/reboot.c
18890 +++ b/arch/x86/kernel/reboot.c
18891 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18892 EXPORT_SYMBOL(pm_power_off);
18893
18894 static const struct desc_ptr no_idt = {};
18895 -static int reboot_mode;
18896 +static unsigned short reboot_mode;
18897 enum reboot_type reboot_type = BOOT_ACPI;
18898 int reboot_force;
18899
18900 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18901
18902 void __noreturn machine_real_restart(unsigned int type)
18903 {
18904 +
18905 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18906 + struct desc_struct *gdt;
18907 +#endif
18908 +
18909 local_irq_disable();
18910
18911 /*
18912 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
18913
18914 /* Jump to the identity-mapped low memory code */
18915 #ifdef CONFIG_X86_32
18916 - asm volatile("jmpl *%0" : :
18917 +
18918 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18919 + gdt = get_cpu_gdt_table(smp_processor_id());
18920 + pax_open_kernel();
18921 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18922 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18923 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18924 + loadsegment(ds, __KERNEL_DS);
18925 + loadsegment(es, __KERNEL_DS);
18926 + loadsegment(ss, __KERNEL_DS);
18927 +#endif
18928 +#ifdef CONFIG_PAX_KERNEXEC
18929 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18930 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18931 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18932 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18933 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18934 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18935 +#endif
18936 + pax_close_kernel();
18937 +#endif
18938 +
18939 + asm volatile("ljmpl *%0" : :
18940 "rm" (real_mode_header->machine_real_restart_asm),
18941 "a" (type));
18942 #else
18943 @@ -539,7 +566,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18944 * try to force a triple fault and then cycle between hitting the keyboard
18945 * controller and doing that
18946 */
18947 -static void native_machine_emergency_restart(void)
18948 +static void __noreturn native_machine_emergency_restart(void)
18949 {
18950 int i;
18951 int attempt = 0;
18952 @@ -662,13 +689,13 @@ void native_machine_shutdown(void)
18953 #endif
18954 }
18955
18956 -static void __machine_emergency_restart(int emergency)
18957 +static void __noreturn __machine_emergency_restart(int emergency)
18958 {
18959 reboot_emergency = emergency;
18960 machine_ops.emergency_restart();
18961 }
18962
18963 -static void native_machine_restart(char *__unused)
18964 +static void __noreturn native_machine_restart(char *__unused)
18965 {
18966 pr_notice("machine restart\n");
18967
18968 @@ -677,7 +704,7 @@ static void native_machine_restart(char *__unused)
18969 __machine_emergency_restart(0);
18970 }
18971
18972 -static void native_machine_halt(void)
18973 +static void __noreturn native_machine_halt(void)
18974 {
18975 /* Stop other cpus and apics */
18976 machine_shutdown();
18977 @@ -687,7 +714,7 @@ static void native_machine_halt(void)
18978 stop_this_cpu(NULL);
18979 }
18980
18981 -static void native_machine_power_off(void)
18982 +static void __noreturn native_machine_power_off(void)
18983 {
18984 if (pm_power_off) {
18985 if (!reboot_force)
18986 @@ -696,6 +723,7 @@ static void native_machine_power_off(void)
18987 }
18988 /* A fallback in case there is no PM info available */
18989 tboot_shutdown(TB_SHUTDOWN_HALT);
18990 + unreachable();
18991 }
18992
18993 struct machine_ops machine_ops = {
18994 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18995 index 7a6f3b3..bed145d7 100644
18996 --- a/arch/x86/kernel/relocate_kernel_64.S
18997 +++ b/arch/x86/kernel/relocate_kernel_64.S
18998 @@ -11,6 +11,7 @@
18999 #include <asm/kexec.h>
19000 #include <asm/processor-flags.h>
19001 #include <asm/pgtable_types.h>
19002 +#include <asm/alternative-asm.h>
19003
19004 /*
19005 * Must be relocatable PIC code callable as a C function
19006 @@ -160,13 +161,14 @@ identity_mapped:
19007 xorq %rbp, %rbp
19008 xorq %r8, %r8
19009 xorq %r9, %r9
19010 - xorq %r10, %r9
19011 + xorq %r10, %r10
19012 xorq %r11, %r11
19013 xorq %r12, %r12
19014 xorq %r13, %r13
19015 xorq %r14, %r14
19016 xorq %r15, %r15
19017
19018 + pax_force_retaddr 0, 1
19019 ret
19020
19021 1:
19022 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19023 index f4b9b80..0d05de1 100644
19024 --- a/arch/x86/kernel/setup.c
19025 +++ b/arch/x86/kernel/setup.c
19026 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19027
19028 switch (data->type) {
19029 case SETUP_E820_EXT:
19030 - parse_e820_ext(data);
19031 + parse_e820_ext((struct setup_data __force_kernel *)data);
19032 break;
19033 case SETUP_DTB:
19034 add_dtb(pa_data);
19035 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19036 * area (640->1Mb) as ram even though it is not.
19037 * take them out.
19038 */
19039 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19040 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19041 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19042 }
19043
19044 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19045
19046 if (!boot_params.hdr.root_flags)
19047 root_mountflags &= ~MS_RDONLY;
19048 - init_mm.start_code = (unsigned long) _text;
19049 - init_mm.end_code = (unsigned long) _etext;
19050 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19051 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19052 init_mm.end_data = (unsigned long) _edata;
19053 init_mm.brk = _brk_end;
19054
19055 - code_resource.start = virt_to_phys(_text);
19056 - code_resource.end = virt_to_phys(_etext)-1;
19057 - data_resource.start = virt_to_phys(_etext);
19058 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19059 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19060 + data_resource.start = virt_to_phys(_sdata);
19061 data_resource.end = virt_to_phys(_edata)-1;
19062 bss_resource.start = virt_to_phys(&__bss_start);
19063 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19064 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19065 index 5cdff03..5810740 100644
19066 --- a/arch/x86/kernel/setup_percpu.c
19067 +++ b/arch/x86/kernel/setup_percpu.c
19068 @@ -21,19 +21,17 @@
19069 #include <asm/cpu.h>
19070 #include <asm/stackprotector.h>
19071
19072 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
19073 +#ifdef CONFIG_SMP
19074 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19075 EXPORT_PER_CPU_SYMBOL(cpu_number);
19076 +#endif
19077
19078 -#ifdef CONFIG_X86_64
19079 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19080 -#else
19081 -#define BOOT_PERCPU_OFFSET 0
19082 -#endif
19083
19084 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19085 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19086
19087 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19088 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19089 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19090 };
19091 EXPORT_SYMBOL(__per_cpu_offset);
19092 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19093 {
19094 #ifdef CONFIG_X86_32
19095 struct desc_struct gdt;
19096 + unsigned long base = per_cpu_offset(cpu);
19097
19098 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19099 - 0x2 | DESCTYPE_S, 0x8);
19100 - gdt.s = 1;
19101 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19102 + 0x83 | DESCTYPE_S, 0xC);
19103 write_gdt_entry(get_cpu_gdt_table(cpu),
19104 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19105 #endif
19106 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19107 /* alrighty, percpu areas up and running */
19108 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19109 for_each_possible_cpu(cpu) {
19110 +#ifdef CONFIG_CC_STACKPROTECTOR
19111 +#ifdef CONFIG_X86_32
19112 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19113 +#endif
19114 +#endif
19115 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19116 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19117 per_cpu(cpu_number, cpu) = cpu;
19118 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19119 */
19120 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19121 #endif
19122 +#ifdef CONFIG_CC_STACKPROTECTOR
19123 +#ifdef CONFIG_X86_32
19124 + if (!cpu)
19125 + per_cpu(stack_canary.canary, cpu) = canary;
19126 +#endif
19127 +#endif
19128 /*
19129 * Up to this point, the boot CPU has been using .init.data
19130 * area. Reload any changed state for the boot CPU.
19131 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19132 index b280908..6de349e 100644
19133 --- a/arch/x86/kernel/signal.c
19134 +++ b/arch/x86/kernel/signal.c
19135 @@ -194,7 +194,7 @@ static unsigned long align_sigframe(unsigned long sp)
19136 * Align the stack pointer according to the i386 ABI,
19137 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19138 */
19139 - sp = ((sp + 4) & -16ul) - 4;
19140 + sp = ((sp - 12) & -16ul) - 4;
19141 #else /* !CONFIG_X86_32 */
19142 sp = round_down(sp, 16) - 8;
19143 #endif
19144 @@ -245,11 +245,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19145 * Return an always-bogus address instead so we will die with SIGSEGV.
19146 */
19147 if (onsigstack && !likely(on_sig_stack(sp)))
19148 - return (void __user *)-1L;
19149 + return (__force void __user *)-1L;
19150
19151 /* save i387 state */
19152 if (used_math() && save_i387_xstate(*fpstate) < 0)
19153 - return (void __user *)-1L;
19154 + return (__force void __user *)-1L;
19155
19156 return (void __user *)sp;
19157 }
19158 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19159 }
19160
19161 if (current->mm->context.vdso)
19162 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19163 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19164 else
19165 - restorer = &frame->retcode;
19166 + restorer = (void __user *)&frame->retcode;
19167 if (ka->sa.sa_flags & SA_RESTORER)
19168 restorer = ka->sa.sa_restorer;
19169
19170 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19171 * reasons and because gdb uses it as a signature to notice
19172 * signal handler stack frames.
19173 */
19174 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19175 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19176
19177 if (err)
19178 return -EFAULT;
19179 @@ -374,7 +374,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19180 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19181
19182 /* Set up to return from userspace. */
19183 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19184 + if (current->mm->context.vdso)
19185 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19186 + else
19187 + restorer = (void __user *)&frame->retcode;
19188 if (ka->sa.sa_flags & SA_RESTORER)
19189 restorer = ka->sa.sa_restorer;
19190 put_user_ex(restorer, &frame->pretcode);
19191 @@ -386,7 +389,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19192 * reasons and because gdb uses it as a signature to notice
19193 * signal handler stack frames.
19194 */
19195 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19196 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19197 } put_user_catch(err);
19198
19199 if (err)
19200 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19201 index 7c5a8c3..88d422f 100644
19202 --- a/arch/x86/kernel/smpboot.c
19203 +++ b/arch/x86/kernel/smpboot.c
19204 @@ -670,6 +670,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19205 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19206 (THREAD_SIZE + task_stack_page(idle))) - 1);
19207 per_cpu(current_task, cpu) = idle;
19208 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19209
19210 #ifdef CONFIG_X86_32
19211 /* Stack for startup_32 can be just as for start_secondary onwards */
19212 @@ -677,11 +678,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19213 #else
19214 clear_tsk_thread_flag(idle, TIF_FORK);
19215 initial_gs = per_cpu_offset(cpu);
19216 - per_cpu(kernel_stack, cpu) =
19217 - (unsigned long)task_stack_page(idle) -
19218 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19219 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19220 #endif
19221 +
19222 + pax_open_kernel();
19223 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19224 + pax_close_kernel();
19225 +
19226 initial_code = (unsigned long)start_secondary;
19227 stack_start = idle->thread.sp;
19228
19229 @@ -817,6 +820,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19230
19231 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19232
19233 +#ifdef CONFIG_PAX_PER_CPU_PGD
19234 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19235 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19236 + KERNEL_PGD_PTRS);
19237 +#endif
19238 +
19239 err = do_boot_cpu(apicid, cpu, tidle);
19240 if (err) {
19241 pr_debug("do_boot_cpu failed %d\n", err);
19242 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19243 index c346d11..d43b163 100644
19244 --- a/arch/x86/kernel/step.c
19245 +++ b/arch/x86/kernel/step.c
19246 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19247 struct desc_struct *desc;
19248 unsigned long base;
19249
19250 - seg &= ~7UL;
19251 + seg >>= 3;
19252
19253 mutex_lock(&child->mm->context.lock);
19254 - if (unlikely((seg >> 3) >= child->mm->context.size))
19255 + if (unlikely(seg >= child->mm->context.size))
19256 addr = -1L; /* bogus selector, access would fault */
19257 else {
19258 desc = child->mm->context.ldt + seg;
19259 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19260 addr += base;
19261 }
19262 mutex_unlock(&child->mm->context.lock);
19263 - }
19264 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19265 + addr = ktla_ktva(addr);
19266
19267 return addr;
19268 }
19269 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19270 unsigned char opcode[15];
19271 unsigned long addr = convert_ip_to_linear(child, regs);
19272
19273 + if (addr == -EINVAL)
19274 + return 0;
19275 +
19276 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19277 for (i = 0; i < copied; i++) {
19278 switch (opcode[i]) {
19279 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19280 index 0b0cb5f..db6b9ed 100644
19281 --- a/arch/x86/kernel/sys_i386_32.c
19282 +++ b/arch/x86/kernel/sys_i386_32.c
19283 @@ -24,17 +24,224 @@
19284
19285 #include <asm/syscalls.h>
19286
19287 -/*
19288 - * Do a system call from kernel instead of calling sys_execve so we
19289 - * end up with proper pt_regs.
19290 - */
19291 -int kernel_execve(const char *filename,
19292 - const char *const argv[],
19293 - const char *const envp[])
19294 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19295 {
19296 - long __res;
19297 - asm volatile ("int $0x80"
19298 - : "=a" (__res)
19299 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19300 - return __res;
19301 + unsigned long pax_task_size = TASK_SIZE;
19302 +
19303 +#ifdef CONFIG_PAX_SEGMEXEC
19304 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19305 + pax_task_size = SEGMEXEC_TASK_SIZE;
19306 +#endif
19307 +
19308 + if (len > pax_task_size || addr > pax_task_size - len)
19309 + return -EINVAL;
19310 +
19311 + return 0;
19312 +}
19313 +
19314 +unsigned long
19315 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19316 + unsigned long len, unsigned long pgoff, unsigned long flags)
19317 +{
19318 + struct mm_struct *mm = current->mm;
19319 + struct vm_area_struct *vma;
19320 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19321 +
19322 +#ifdef CONFIG_PAX_SEGMEXEC
19323 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19324 + pax_task_size = SEGMEXEC_TASK_SIZE;
19325 +#endif
19326 +
19327 + pax_task_size -= PAGE_SIZE;
19328 +
19329 + if (len > pax_task_size)
19330 + return -ENOMEM;
19331 +
19332 + if (flags & MAP_FIXED)
19333 + return addr;
19334 +
19335 +#ifdef CONFIG_PAX_RANDMMAP
19336 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19337 +#endif
19338 +
19339 + if (addr) {
19340 + addr = PAGE_ALIGN(addr);
19341 + if (pax_task_size - len >= addr) {
19342 + vma = find_vma(mm, addr);
19343 + if (check_heap_stack_gap(vma, addr, len))
19344 + return addr;
19345 + }
19346 + }
19347 + if (len > mm->cached_hole_size) {
19348 + start_addr = addr = mm->free_area_cache;
19349 + } else {
19350 + start_addr = addr = mm->mmap_base;
19351 + mm->cached_hole_size = 0;
19352 + }
19353 +
19354 +#ifdef CONFIG_PAX_PAGEEXEC
19355 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19356 + start_addr = 0x00110000UL;
19357 +
19358 +#ifdef CONFIG_PAX_RANDMMAP
19359 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19360 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19361 +#endif
19362 +
19363 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19364 + start_addr = addr = mm->mmap_base;
19365 + else
19366 + addr = start_addr;
19367 + }
19368 +#endif
19369 +
19370 +full_search:
19371 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19372 + /* At this point: (!vma || addr < vma->vm_end). */
19373 + if (pax_task_size - len < addr) {
19374 + /*
19375 + * Start a new search - just in case we missed
19376 + * some holes.
19377 + */
19378 + if (start_addr != mm->mmap_base) {
19379 + start_addr = addr = mm->mmap_base;
19380 + mm->cached_hole_size = 0;
19381 + goto full_search;
19382 + }
19383 + return -ENOMEM;
19384 + }
19385 + if (check_heap_stack_gap(vma, addr, len))
19386 + break;
19387 + if (addr + mm->cached_hole_size < vma->vm_start)
19388 + mm->cached_hole_size = vma->vm_start - addr;
19389 + addr = vma->vm_end;
19390 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19391 + start_addr = addr = mm->mmap_base;
19392 + mm->cached_hole_size = 0;
19393 + goto full_search;
19394 + }
19395 + }
19396 +
19397 + /*
19398 + * Remember the place where we stopped the search:
19399 + */
19400 + mm->free_area_cache = addr + len;
19401 + return addr;
19402 +}
19403 +
19404 +unsigned long
19405 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19406 + const unsigned long len, const unsigned long pgoff,
19407 + const unsigned long flags)
19408 +{
19409 + struct vm_area_struct *vma;
19410 + struct mm_struct *mm = current->mm;
19411 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19412 +
19413 +#ifdef CONFIG_PAX_SEGMEXEC
19414 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19415 + pax_task_size = SEGMEXEC_TASK_SIZE;
19416 +#endif
19417 +
19418 + pax_task_size -= PAGE_SIZE;
19419 +
19420 + /* requested length too big for entire address space */
19421 + if (len > pax_task_size)
19422 + return -ENOMEM;
19423 +
19424 + if (flags & MAP_FIXED)
19425 + return addr;
19426 +
19427 +#ifdef CONFIG_PAX_PAGEEXEC
19428 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19429 + goto bottomup;
19430 +#endif
19431 +
19432 +#ifdef CONFIG_PAX_RANDMMAP
19433 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19434 +#endif
19435 +
19436 + /* requesting a specific address */
19437 + if (addr) {
19438 + addr = PAGE_ALIGN(addr);
19439 + if (pax_task_size - len >= addr) {
19440 + vma = find_vma(mm, addr);
19441 + if (check_heap_stack_gap(vma, addr, len))
19442 + return addr;
19443 + }
19444 + }
19445 +
19446 + /* check if free_area_cache is useful for us */
19447 + if (len <= mm->cached_hole_size) {
19448 + mm->cached_hole_size = 0;
19449 + mm->free_area_cache = mm->mmap_base;
19450 + }
19451 +
19452 + /* either no address requested or can't fit in requested address hole */
19453 + addr = mm->free_area_cache;
19454 +
19455 + /* make sure it can fit in the remaining address space */
19456 + if (addr > len) {
19457 + vma = find_vma(mm, addr-len);
19458 + if (check_heap_stack_gap(vma, addr - len, len))
19459 + /* remember the address as a hint for next time */
19460 + return (mm->free_area_cache = addr-len);
19461 + }
19462 +
19463 + if (mm->mmap_base < len)
19464 + goto bottomup;
19465 +
19466 + addr = mm->mmap_base-len;
19467 +
19468 + do {
19469 + /*
19470 + * Lookup failure means no vma is above this address,
19471 + * else if new region fits below vma->vm_start,
19472 + * return with success:
19473 + */
19474 + vma = find_vma(mm, addr);
19475 + if (check_heap_stack_gap(vma, addr, len))
19476 + /* remember the address as a hint for next time */
19477 + return (mm->free_area_cache = addr);
19478 +
19479 + /* remember the largest hole we saw so far */
19480 + if (addr + mm->cached_hole_size < vma->vm_start)
19481 + mm->cached_hole_size = vma->vm_start - addr;
19482 +
19483 + /* try just below the current vma->vm_start */
19484 + addr = skip_heap_stack_gap(vma, len);
19485 + } while (!IS_ERR_VALUE(addr));
19486 +
19487 +bottomup:
19488 + /*
19489 + * A failed mmap() very likely causes application failure,
19490 + * so fall back to the bottom-up function here. This scenario
19491 + * can happen with large stack limits and large mmap()
19492 + * allocations.
19493 + */
19494 +
19495 +#ifdef CONFIG_PAX_SEGMEXEC
19496 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19497 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19498 + else
19499 +#endif
19500 +
19501 + mm->mmap_base = TASK_UNMAPPED_BASE;
19502 +
19503 +#ifdef CONFIG_PAX_RANDMMAP
19504 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19505 + mm->mmap_base += mm->delta_mmap;
19506 +#endif
19507 +
19508 + mm->free_area_cache = mm->mmap_base;
19509 + mm->cached_hole_size = ~0UL;
19510 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19511 + /*
19512 + * Restore the topdown base:
19513 + */
19514 + mm->mmap_base = base;
19515 + mm->free_area_cache = base;
19516 + mm->cached_hole_size = ~0UL;
19517 +
19518 + return addr;
19519 }
19520 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19521 index b4d3c39..82bb73b 100644
19522 --- a/arch/x86/kernel/sys_x86_64.c
19523 +++ b/arch/x86/kernel/sys_x86_64.c
19524 @@ -95,8 +95,8 @@ out:
19525 return error;
19526 }
19527
19528 -static void find_start_end(unsigned long flags, unsigned long *begin,
19529 - unsigned long *end)
19530 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19531 + unsigned long *begin, unsigned long *end)
19532 {
19533 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19534 unsigned long new_begin;
19535 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19536 *begin = new_begin;
19537 }
19538 } else {
19539 - *begin = TASK_UNMAPPED_BASE;
19540 + *begin = mm->mmap_base;
19541 *end = TASK_SIZE;
19542 }
19543 }
19544 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19545 if (flags & MAP_FIXED)
19546 return addr;
19547
19548 - find_start_end(flags, &begin, &end);
19549 + find_start_end(mm, flags, &begin, &end);
19550
19551 if (len > end)
19552 return -ENOMEM;
19553
19554 +#ifdef CONFIG_PAX_RANDMMAP
19555 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19556 +#endif
19557 +
19558 if (addr) {
19559 addr = PAGE_ALIGN(addr);
19560 vma = find_vma(mm, addr);
19561 - if (end - len >= addr &&
19562 - (!vma || addr + len <= vma->vm_start))
19563 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19564 return addr;
19565 }
19566 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19567 @@ -172,7 +175,7 @@ full_search:
19568 }
19569 return -ENOMEM;
19570 }
19571 - if (!vma || addr + len <= vma->vm_start) {
19572 + if (check_heap_stack_gap(vma, addr, len)) {
19573 /*
19574 * Remember the place where we stopped the search:
19575 */
19576 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19577 {
19578 struct vm_area_struct *vma;
19579 struct mm_struct *mm = current->mm;
19580 - unsigned long addr = addr0, start_addr;
19581 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19582
19583 /* requested length too big for entire address space */
19584 if (len > TASK_SIZE)
19585 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19586 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19587 goto bottomup;
19588
19589 +#ifdef CONFIG_PAX_RANDMMAP
19590 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19591 +#endif
19592 +
19593 /* requesting a specific address */
19594 if (addr) {
19595 addr = PAGE_ALIGN(addr);
19596 - vma = find_vma(mm, addr);
19597 - if (TASK_SIZE - len >= addr &&
19598 - (!vma || addr + len <= vma->vm_start))
19599 - return addr;
19600 + if (TASK_SIZE - len >= addr) {
19601 + vma = find_vma(mm, addr);
19602 + if (check_heap_stack_gap(vma, addr, len))
19603 + return addr;
19604 + }
19605 }
19606
19607 /* check if free_area_cache is useful for us */
19608 @@ -240,7 +248,7 @@ try_again:
19609 * return with success:
19610 */
19611 vma = find_vma(mm, addr);
19612 - if (!vma || addr+len <= vma->vm_start)
19613 + if (check_heap_stack_gap(vma, addr, len))
19614 /* remember the address as a hint for next time */
19615 return mm->free_area_cache = addr;
19616
19617 @@ -249,8 +257,8 @@ try_again:
19618 mm->cached_hole_size = vma->vm_start - addr;
19619
19620 /* try just below the current vma->vm_start */
19621 - addr = vma->vm_start-len;
19622 - } while (len < vma->vm_start);
19623 + addr = skip_heap_stack_gap(vma, len);
19624 + } while (!IS_ERR_VALUE(addr));
19625
19626 fail:
19627 /*
19628 @@ -270,13 +278,21 @@ bottomup:
19629 * can happen with large stack limits and large mmap()
19630 * allocations.
19631 */
19632 + mm->mmap_base = TASK_UNMAPPED_BASE;
19633 +
19634 +#ifdef CONFIG_PAX_RANDMMAP
19635 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19636 + mm->mmap_base += mm->delta_mmap;
19637 +#endif
19638 +
19639 + mm->free_area_cache = mm->mmap_base;
19640 mm->cached_hole_size = ~0UL;
19641 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19642 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19643 /*
19644 * Restore the topdown base:
19645 */
19646 - mm->free_area_cache = mm->mmap_base;
19647 + mm->mmap_base = base;
19648 + mm->free_area_cache = base;
19649 mm->cached_hole_size = ~0UL;
19650
19651 return addr;
19652 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19653 index f84fe00..93fe08f 100644
19654 --- a/arch/x86/kernel/tboot.c
19655 +++ b/arch/x86/kernel/tboot.c
19656 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19657
19658 void tboot_shutdown(u32 shutdown_type)
19659 {
19660 - void (*shutdown)(void);
19661 + void (* __noreturn shutdown)(void);
19662
19663 if (!tboot_enabled())
19664 return;
19665 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19666
19667 switch_to_tboot_pt();
19668
19669 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19670 + shutdown = (void *)tboot->shutdown_entry;
19671 shutdown();
19672
19673 /* should not reach here */
19674 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19675 return 0;
19676 }
19677
19678 -static atomic_t ap_wfs_count;
19679 +static atomic_unchecked_t ap_wfs_count;
19680
19681 static int tboot_wait_for_aps(int num_aps)
19682 {
19683 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19684 {
19685 switch (action) {
19686 case CPU_DYING:
19687 - atomic_inc(&ap_wfs_count);
19688 + atomic_inc_unchecked(&ap_wfs_count);
19689 if (num_online_cpus() == 1)
19690 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19691 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19692 return NOTIFY_BAD;
19693 break;
19694 }
19695 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19696
19697 tboot_create_trampoline();
19698
19699 - atomic_set(&ap_wfs_count, 0);
19700 + atomic_set_unchecked(&ap_wfs_count, 0);
19701 register_hotcpu_notifier(&tboot_cpu_notifier);
19702
19703 acpi_os_set_prepare_sleep(&tboot_sleep);
19704 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19705 index 24d3c91..d06b473 100644
19706 --- a/arch/x86/kernel/time.c
19707 +++ b/arch/x86/kernel/time.c
19708 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19709 {
19710 unsigned long pc = instruction_pointer(regs);
19711
19712 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19713 + if (!user_mode(regs) && in_lock_functions(pc)) {
19714 #ifdef CONFIG_FRAME_POINTER
19715 - return *(unsigned long *)(regs->bp + sizeof(long));
19716 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19717 #else
19718 unsigned long *sp =
19719 (unsigned long *)kernel_stack_pointer(regs);
19720 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19721 * or above a saved flags. Eflags has bits 22-31 zero,
19722 * kernel addresses don't.
19723 */
19724 +
19725 +#ifdef CONFIG_PAX_KERNEXEC
19726 + return ktla_ktva(sp[0]);
19727 +#else
19728 if (sp[0] >> 22)
19729 return sp[0];
19730 if (sp[1] >> 22)
19731 return sp[1];
19732 #endif
19733 +
19734 +#endif
19735 }
19736 return pc;
19737 }
19738 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19739 index 9d9d2f9..cad418a 100644
19740 --- a/arch/x86/kernel/tls.c
19741 +++ b/arch/x86/kernel/tls.c
19742 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19743 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19744 return -EINVAL;
19745
19746 +#ifdef CONFIG_PAX_SEGMEXEC
19747 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19748 + return -EINVAL;
19749 +#endif
19750 +
19751 set_tls_desc(p, idx, &info, 1);
19752
19753 return 0;
19754 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19755
19756 if (kbuf)
19757 info = kbuf;
19758 - else if (__copy_from_user(infobuf, ubuf, count))
19759 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19760 return -EFAULT;
19761 else
19762 info = infobuf;
19763 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19764 index b481341..5918bbe 100644
19765 --- a/arch/x86/kernel/traps.c
19766 +++ b/arch/x86/kernel/traps.c
19767 @@ -70,12 +70,6 @@ asmlinkage int system_call(void);
19768
19769 /* Do we ignore FPU interrupts ? */
19770 char ignore_fpu_irq;
19771 -
19772 -/*
19773 - * The IDT has to be page-aligned to simplify the Pentium
19774 - * F0 0F bug workaround.
19775 - */
19776 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19777 #endif
19778
19779 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19780 @@ -108,13 +102,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19781 }
19782
19783 static void __kprobes
19784 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19785 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19786 long error_code, siginfo_t *info)
19787 {
19788 struct task_struct *tsk = current;
19789
19790 #ifdef CONFIG_X86_32
19791 - if (regs->flags & X86_VM_MASK) {
19792 + if (v8086_mode(regs)) {
19793 /*
19794 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19795 * On nmi (interrupt 2), do_trap should not be called.
19796 @@ -125,7 +119,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19797 }
19798 #endif
19799
19800 - if (!user_mode(regs))
19801 + if (!user_mode_novm(regs))
19802 goto kernel_trap;
19803
19804 #ifdef CONFIG_X86_32
19805 @@ -147,7 +141,7 @@ trap_signal:
19806 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
19807 printk_ratelimit()) {
19808 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19809 - tsk->comm, tsk->pid, str,
19810 + tsk->comm, task_pid_nr(tsk), str,
19811 regs->ip, regs->sp, error_code);
19812 print_vma_addr(" in ", regs->ip);
19813 pr_cont("\n");
19814 @@ -164,8 +158,20 @@ kernel_trap:
19815 if (!fixup_exception(regs)) {
19816 tsk->thread.error_code = error_code;
19817 tsk->thread.trap_nr = trapnr;
19818 +
19819 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19820 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19821 + str = "PAX: suspicious stack segment fault";
19822 +#endif
19823 +
19824 die(str, regs, error_code);
19825 }
19826 +
19827 +#ifdef CONFIG_PAX_REFCOUNT
19828 + if (trapnr == 4)
19829 + pax_report_refcount_overflow(regs);
19830 +#endif
19831 +
19832 return;
19833
19834 #ifdef CONFIG_X86_32
19835 @@ -258,14 +264,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19836 conditional_sti(regs);
19837
19838 #ifdef CONFIG_X86_32
19839 - if (regs->flags & X86_VM_MASK)
19840 + if (v8086_mode(regs))
19841 goto gp_in_vm86;
19842 #endif
19843
19844 tsk = current;
19845 - if (!user_mode(regs))
19846 + if (!user_mode_novm(regs))
19847 goto gp_in_kernel;
19848
19849 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19850 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19851 + struct mm_struct *mm = tsk->mm;
19852 + unsigned long limit;
19853 +
19854 + down_write(&mm->mmap_sem);
19855 + limit = mm->context.user_cs_limit;
19856 + if (limit < TASK_SIZE) {
19857 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19858 + up_write(&mm->mmap_sem);
19859 + return;
19860 + }
19861 + up_write(&mm->mmap_sem);
19862 + }
19863 +#endif
19864 +
19865 tsk->thread.error_code = error_code;
19866 tsk->thread.trap_nr = X86_TRAP_GP;
19867
19868 @@ -297,6 +319,13 @@ gp_in_kernel:
19869 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19870 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19871 return;
19872 +
19873 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19874 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19875 + die("PAX: suspicious general protection fault", regs, error_code);
19876 + else
19877 +#endif
19878 +
19879 die("general protection fault", regs, error_code);
19880 }
19881
19882 @@ -432,7 +461,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19883 /* It's safe to allow irq's after DR6 has been saved */
19884 preempt_conditional_sti(regs);
19885
19886 - if (regs->flags & X86_VM_MASK) {
19887 + if (v8086_mode(regs)) {
19888 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19889 X86_TRAP_DB);
19890 preempt_conditional_cli(regs);
19891 @@ -447,7 +476,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19892 * We already checked v86 mode above, so we can check for kernel mode
19893 * by just checking the CPL of CS.
19894 */
19895 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19896 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19897 tsk->thread.debugreg6 &= ~DR_STEP;
19898 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19899 regs->flags &= ~X86_EFLAGS_TF;
19900 @@ -478,7 +507,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19901 return;
19902 conditional_sti(regs);
19903
19904 - if (!user_mode_vm(regs))
19905 + if (!user_mode(regs))
19906 {
19907 if (!fixup_exception(regs)) {
19908 task->thread.error_code = error_code;
19909 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19910 index 36fd420..7e5892d 100644
19911 --- a/arch/x86/kernel/uprobes.c
19912 +++ b/arch/x86/kernel/uprobes.c
19913 @@ -607,7 +607,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19914 int ret = NOTIFY_DONE;
19915
19916 /* We are only interested in userspace traps */
19917 - if (regs && !user_mode_vm(regs))
19918 + if (regs && !user_mode(regs))
19919 return NOTIFY_DONE;
19920
19921 switch (val) {
19922 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19923 index b9242ba..50c5edd 100644
19924 --- a/arch/x86/kernel/verify_cpu.S
19925 +++ b/arch/x86/kernel/verify_cpu.S
19926 @@ -20,6 +20,7 @@
19927 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19928 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19929 * arch/x86/kernel/head_32.S: processor startup
19930 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19931 *
19932 * verify_cpu, returns the status of longmode and SSE in register %eax.
19933 * 0: Success 1: Failure
19934 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19935 index 54abcc0..eb6c848 100644
19936 --- a/arch/x86/kernel/vm86_32.c
19937 +++ b/arch/x86/kernel/vm86_32.c
19938 @@ -43,6 +43,7 @@
19939 #include <linux/ptrace.h>
19940 #include <linux/audit.h>
19941 #include <linux/stddef.h>
19942 +#include <linux/grsecurity.h>
19943
19944 #include <asm/uaccess.h>
19945 #include <asm/io.h>
19946 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19947 do_exit(SIGSEGV);
19948 }
19949
19950 - tss = &per_cpu(init_tss, get_cpu());
19951 + tss = init_tss + get_cpu();
19952 current->thread.sp0 = current->thread.saved_sp0;
19953 current->thread.sysenter_cs = __KERNEL_CS;
19954 load_sp0(tss, &current->thread);
19955 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19956 struct task_struct *tsk;
19957 int tmp, ret = -EPERM;
19958
19959 +#ifdef CONFIG_GRKERNSEC_VM86
19960 + if (!capable(CAP_SYS_RAWIO)) {
19961 + gr_handle_vm86();
19962 + goto out;
19963 + }
19964 +#endif
19965 +
19966 tsk = current;
19967 if (tsk->thread.saved_sp0)
19968 goto out;
19969 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19970 int tmp, ret;
19971 struct vm86plus_struct __user *v86;
19972
19973 +#ifdef CONFIG_GRKERNSEC_VM86
19974 + if (!capable(CAP_SYS_RAWIO)) {
19975 + gr_handle_vm86();
19976 + ret = -EPERM;
19977 + goto out;
19978 + }
19979 +#endif
19980 +
19981 tsk = current;
19982 switch (cmd) {
19983 case VM86_REQUEST_IRQ:
19984 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19985 tsk->thread.saved_fs = info->regs32->fs;
19986 tsk->thread.saved_gs = get_user_gs(info->regs32);
19987
19988 - tss = &per_cpu(init_tss, get_cpu());
19989 + tss = init_tss + get_cpu();
19990 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19991 if (cpu_has_sep)
19992 tsk->thread.sysenter_cs = 0;
19993 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19994 goto cannot_handle;
19995 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19996 goto cannot_handle;
19997 - intr_ptr = (unsigned long __user *) (i << 2);
19998 + intr_ptr = (__force unsigned long __user *) (i << 2);
19999 if (get_user(segoffs, intr_ptr))
20000 goto cannot_handle;
20001 if ((segoffs >> 16) == BIOSSEG)
20002 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
20003 index 22a1530..8fbaaad 100644
20004 --- a/arch/x86/kernel/vmlinux.lds.S
20005 +++ b/arch/x86/kernel/vmlinux.lds.S
20006 @@ -26,6 +26,13 @@
20007 #include <asm/page_types.h>
20008 #include <asm/cache.h>
20009 #include <asm/boot.h>
20010 +#include <asm/segment.h>
20011 +
20012 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20013 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20014 +#else
20015 +#define __KERNEL_TEXT_OFFSET 0
20016 +#endif
20017
20018 #undef i386 /* in case the preprocessor is a 32bit one */
20019
20020 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20021
20022 PHDRS {
20023 text PT_LOAD FLAGS(5); /* R_E */
20024 +#ifdef CONFIG_X86_32
20025 + module PT_LOAD FLAGS(5); /* R_E */
20026 +#endif
20027 +#ifdef CONFIG_XEN
20028 + rodata PT_LOAD FLAGS(5); /* R_E */
20029 +#else
20030 + rodata PT_LOAD FLAGS(4); /* R__ */
20031 +#endif
20032 data PT_LOAD FLAGS(6); /* RW_ */
20033 -#ifdef CONFIG_X86_64
20034 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20035 #ifdef CONFIG_SMP
20036 percpu PT_LOAD FLAGS(6); /* RW_ */
20037 #endif
20038 + text.init PT_LOAD FLAGS(5); /* R_E */
20039 + text.exit PT_LOAD FLAGS(5); /* R_E */
20040 init PT_LOAD FLAGS(7); /* RWE */
20041 -#endif
20042 note PT_NOTE FLAGS(0); /* ___ */
20043 }
20044
20045 SECTIONS
20046 {
20047 #ifdef CONFIG_X86_32
20048 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20049 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20050 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20051 #else
20052 - . = __START_KERNEL;
20053 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20054 + . = __START_KERNEL;
20055 #endif
20056
20057 /* Text and read-only data */
20058 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20059 - _text = .;
20060 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20061 /* bootstrapping code */
20062 +#ifdef CONFIG_X86_32
20063 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20064 +#else
20065 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20066 +#endif
20067 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20068 + _text = .;
20069 HEAD_TEXT
20070 #ifdef CONFIG_X86_32
20071 . = ALIGN(PAGE_SIZE);
20072 @@ -108,13 +128,48 @@ SECTIONS
20073 IRQENTRY_TEXT
20074 *(.fixup)
20075 *(.gnu.warning)
20076 - /* End of text section */
20077 - _etext = .;
20078 } :text = 0x9090
20079
20080 - NOTES :text :note
20081 + . += __KERNEL_TEXT_OFFSET;
20082
20083 - EXCEPTION_TABLE(16) :text = 0x9090
20084 +#ifdef CONFIG_X86_32
20085 + . = ALIGN(PAGE_SIZE);
20086 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20087 +
20088 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20089 + MODULES_EXEC_VADDR = .;
20090 + BYTE(0)
20091 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20092 + . = ALIGN(HPAGE_SIZE) - 1;
20093 + MODULES_EXEC_END = .;
20094 +#endif
20095 +
20096 + } :module
20097 +#endif
20098 +
20099 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20100 + /* End of text section */
20101 + BYTE(0)
20102 + _etext = . - __KERNEL_TEXT_OFFSET;
20103 + }
20104 +
20105 +#ifdef CONFIG_X86_32
20106 + . = ALIGN(PAGE_SIZE);
20107 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20108 + *(.idt)
20109 + . = ALIGN(PAGE_SIZE);
20110 + *(.empty_zero_page)
20111 + *(.initial_pg_fixmap)
20112 + *(.initial_pg_pmd)
20113 + *(.initial_page_table)
20114 + *(.swapper_pg_dir)
20115 + } :rodata
20116 +#endif
20117 +
20118 + . = ALIGN(PAGE_SIZE);
20119 + NOTES :rodata :note
20120 +
20121 + EXCEPTION_TABLE(16) :rodata
20122
20123 #if defined(CONFIG_DEBUG_RODATA)
20124 /* .text should occupy whole number of pages */
20125 @@ -126,16 +181,20 @@ SECTIONS
20126
20127 /* Data */
20128 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20129 +
20130 +#ifdef CONFIG_PAX_KERNEXEC
20131 + . = ALIGN(HPAGE_SIZE);
20132 +#else
20133 + . = ALIGN(PAGE_SIZE);
20134 +#endif
20135 +
20136 /* Start of data section */
20137 _sdata = .;
20138
20139 /* init_task */
20140 INIT_TASK_DATA(THREAD_SIZE)
20141
20142 -#ifdef CONFIG_X86_32
20143 - /* 32 bit has nosave before _edata */
20144 NOSAVE_DATA
20145 -#endif
20146
20147 PAGE_ALIGNED_DATA(PAGE_SIZE)
20148
20149 @@ -176,12 +235,19 @@ SECTIONS
20150 #endif /* CONFIG_X86_64 */
20151
20152 /* Init code and data - will be freed after init */
20153 - . = ALIGN(PAGE_SIZE);
20154 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20155 + BYTE(0)
20156 +
20157 +#ifdef CONFIG_PAX_KERNEXEC
20158 + . = ALIGN(HPAGE_SIZE);
20159 +#else
20160 + . = ALIGN(PAGE_SIZE);
20161 +#endif
20162 +
20163 __init_begin = .; /* paired with __init_end */
20164 - }
20165 + } :init.begin
20166
20167 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20168 +#ifdef CONFIG_SMP
20169 /*
20170 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20171 * output PHDR, so the next output section - .init.text - should
20172 @@ -190,12 +256,27 @@ SECTIONS
20173 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20174 #endif
20175
20176 - INIT_TEXT_SECTION(PAGE_SIZE)
20177 -#ifdef CONFIG_X86_64
20178 - :init
20179 -#endif
20180 + . = ALIGN(PAGE_SIZE);
20181 + init_begin = .;
20182 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20183 + VMLINUX_SYMBOL(_sinittext) = .;
20184 + INIT_TEXT
20185 + VMLINUX_SYMBOL(_einittext) = .;
20186 + . = ALIGN(PAGE_SIZE);
20187 + } :text.init
20188
20189 - INIT_DATA_SECTION(16)
20190 + /*
20191 + * .exit.text is discard at runtime, not link time, to deal with
20192 + * references from .altinstructions and .eh_frame
20193 + */
20194 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20195 + EXIT_TEXT
20196 + . = ALIGN(16);
20197 + } :text.exit
20198 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20199 +
20200 + . = ALIGN(PAGE_SIZE);
20201 + INIT_DATA_SECTION(16) :init
20202
20203 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20204 __x86_cpu_dev_start = .;
20205 @@ -257,19 +338,12 @@ SECTIONS
20206 }
20207
20208 . = ALIGN(8);
20209 - /*
20210 - * .exit.text is discard at runtime, not link time, to deal with
20211 - * references from .altinstructions and .eh_frame
20212 - */
20213 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20214 - EXIT_TEXT
20215 - }
20216
20217 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20218 EXIT_DATA
20219 }
20220
20221 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20222 +#ifndef CONFIG_SMP
20223 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20224 #endif
20225
20226 @@ -288,16 +362,10 @@ SECTIONS
20227 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20228 __smp_locks = .;
20229 *(.smp_locks)
20230 - . = ALIGN(PAGE_SIZE);
20231 __smp_locks_end = .;
20232 + . = ALIGN(PAGE_SIZE);
20233 }
20234
20235 -#ifdef CONFIG_X86_64
20236 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20237 - NOSAVE_DATA
20238 - }
20239 -#endif
20240 -
20241 /* BSS */
20242 . = ALIGN(PAGE_SIZE);
20243 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20244 @@ -313,6 +381,7 @@ SECTIONS
20245 __brk_base = .;
20246 . += 64 * 1024; /* 64k alignment slop space */
20247 *(.brk_reservation) /* areas brk users have reserved */
20248 + . = ALIGN(HPAGE_SIZE);
20249 __brk_limit = .;
20250 }
20251
20252 @@ -339,13 +408,12 @@ SECTIONS
20253 * for the boot processor.
20254 */
20255 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20256 -INIT_PER_CPU(gdt_page);
20257 INIT_PER_CPU(irq_stack_union);
20258
20259 /*
20260 * Build-time check on the image size:
20261 */
20262 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20263 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20264 "kernel image bigger than KERNEL_IMAGE_SIZE");
20265
20266 #ifdef CONFIG_SMP
20267 diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
20268 index 992f890..fc38904 100644
20269 --- a/arch/x86/kernel/vsmp_64.c
20270 +++ b/arch/x86/kernel/vsmp_64.c
20271 @@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
20272 static void vsmp_apic_post_init(void)
20273 {
20274 /* need to update phys_pkg_id */
20275 - apic->phys_pkg_id = apicid_phys_pkg_id;
20276 - apic->vector_allocation_domain = fill_vector_allocation_domain;
20277 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
20278 + *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
20279 }
20280
20281 void __init vsmp_init(void)
20282 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20283 index 8d141b3..40a0fe4 100644
20284 --- a/arch/x86/kernel/vsyscall_64.c
20285 +++ b/arch/x86/kernel/vsyscall_64.c
20286 @@ -56,15 +56,13 @@
20287 DEFINE_VVAR(int, vgetcpu_mode);
20288 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20289
20290 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20291 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20292
20293 static int __init vsyscall_setup(char *str)
20294 {
20295 if (str) {
20296 if (!strcmp("emulate", str))
20297 vsyscall_mode = EMULATE;
20298 - else if (!strcmp("native", str))
20299 - vsyscall_mode = NATIVE;
20300 else if (!strcmp("none", str))
20301 vsyscall_mode = NONE;
20302 else
20303 @@ -306,8 +304,7 @@ done:
20304 return true;
20305
20306 sigsegv:
20307 - force_sig(SIGSEGV, current);
20308 - return true;
20309 + do_group_exit(SIGKILL);
20310 }
20311
20312 /*
20313 @@ -360,10 +357,7 @@ void __init map_vsyscall(void)
20314 extern char __vvar_page;
20315 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20316
20317 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20318 - vsyscall_mode == NATIVE
20319 - ? PAGE_KERNEL_VSYSCALL
20320 - : PAGE_KERNEL_VVAR);
20321 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20322 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20323 (unsigned long)VSYSCALL_START);
20324
20325 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20326 index 6020f6f..bedd6e3 100644
20327 --- a/arch/x86/kernel/x8664_ksyms_64.c
20328 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20329 @@ -30,8 +30,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
20330 EXPORT_SYMBOL(copy_user_generic_unrolled);
20331 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
20332 EXPORT_SYMBOL(__copy_user_nocache);
20333 -EXPORT_SYMBOL(_copy_from_user);
20334 -EXPORT_SYMBOL(_copy_to_user);
20335
20336 EXPORT_SYMBOL(copy_page);
20337 EXPORT_SYMBOL(clear_page);
20338 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20339 index 3d3e207..1a73ab2 100644
20340 --- a/arch/x86/kernel/xsave.c
20341 +++ b/arch/x86/kernel/xsave.c
20342 @@ -132,7 +132,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20343 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20344 return -EINVAL;
20345
20346 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20347 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20348 fx_sw_user->extended_size -
20349 FP_XSTATE_MAGIC2_SIZE));
20350 if (err)
20351 @@ -268,7 +268,7 @@ fx_only:
20352 * the other extended state.
20353 */
20354 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20355 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20356 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20357 }
20358
20359 /*
20360 @@ -297,7 +297,7 @@ int restore_i387_xstate(void __user *buf)
20361 if (use_xsave())
20362 err = restore_user_xstate(buf);
20363 else
20364 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20365 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20366 buf);
20367 if (unlikely(err)) {
20368 /*
20369 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20370 index 0595f13..b544fa3 100644
20371 --- a/arch/x86/kvm/cpuid.c
20372 +++ b/arch/x86/kvm/cpuid.c
20373 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20374 struct kvm_cpuid2 *cpuid,
20375 struct kvm_cpuid_entry2 __user *entries)
20376 {
20377 - int r;
20378 + int r, i;
20379
20380 r = -E2BIG;
20381 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20382 goto out;
20383 r = -EFAULT;
20384 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20385 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20386 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20387 goto out;
20388 + for (i = 0; i < cpuid->nent; ++i) {
20389 + struct kvm_cpuid_entry2 cpuid_entry;
20390 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20391 + goto out;
20392 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20393 + }
20394 vcpu->arch.cpuid_nent = cpuid->nent;
20395 kvm_apic_set_version(vcpu);
20396 kvm_x86_ops->cpuid_update(vcpu);
20397 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20398 struct kvm_cpuid2 *cpuid,
20399 struct kvm_cpuid_entry2 __user *entries)
20400 {
20401 - int r;
20402 + int r, i;
20403
20404 r = -E2BIG;
20405 if (cpuid->nent < vcpu->arch.cpuid_nent)
20406 goto out;
20407 r = -EFAULT;
20408 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20409 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20410 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20411 goto out;
20412 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20413 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20414 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20415 + goto out;
20416 + }
20417 return 0;
20418
20419 out:
20420 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20421 index a3b57a2..ebbe732 100644
20422 --- a/arch/x86/kvm/emulate.c
20423 +++ b/arch/x86/kvm/emulate.c
20424 @@ -256,6 +256,7 @@ struct gprefix {
20425
20426 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20427 do { \
20428 + unsigned long _tmp; \
20429 __asm__ __volatile__ ( \
20430 _PRE_EFLAGS("0", "4", "2") \
20431 _op _suffix " %"_x"3,%1; " \
20432 @@ -270,8 +271,6 @@ struct gprefix {
20433 /* Raw emulation: instruction has two explicit operands. */
20434 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20435 do { \
20436 - unsigned long _tmp; \
20437 - \
20438 switch ((ctxt)->dst.bytes) { \
20439 case 2: \
20440 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20441 @@ -287,7 +286,6 @@ struct gprefix {
20442
20443 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20444 do { \
20445 - unsigned long _tmp; \
20446 switch ((ctxt)->dst.bytes) { \
20447 case 1: \
20448 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20449 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20450 index ce87878..ab48aa3 100644
20451 --- a/arch/x86/kvm/lapic.c
20452 +++ b/arch/x86/kvm/lapic.c
20453 @@ -54,7 +54,7 @@
20454 #define APIC_BUS_CYCLE_NS 1
20455
20456 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20457 -#define apic_debug(fmt, arg...)
20458 +#define apic_debug(fmt, arg...) do {} while (0)
20459
20460 #define APIC_LVT_NUM 6
20461 /* 14 is the version for Xeon and Pentium 8.4.8*/
20462 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20463 index bb7cf01..0348a05 100644
20464 --- a/arch/x86/kvm/paging_tmpl.h
20465 +++ b/arch/x86/kvm/paging_tmpl.h
20466 @@ -196,7 +196,7 @@ retry_walk:
20467 if (unlikely(kvm_is_error_hva(host_addr)))
20468 goto error;
20469
20470 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20471 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20472 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20473 goto error;
20474
20475 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20476 index baead95..90feeb4 100644
20477 --- a/arch/x86/kvm/svm.c
20478 +++ b/arch/x86/kvm/svm.c
20479 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20480 int cpu = raw_smp_processor_id();
20481
20482 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20483 +
20484 + pax_open_kernel();
20485 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20486 + pax_close_kernel();
20487 +
20488 load_TR_desc();
20489 }
20490
20491 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20492 #endif
20493 #endif
20494
20495 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20496 + __set_fs(current_thread_info()->addr_limit);
20497 +#endif
20498 +
20499 reload_tss(vcpu);
20500
20501 local_irq_disable();
20502 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20503 index b1eb202..254e292 100644
20504 --- a/arch/x86/kvm/vmx.c
20505 +++ b/arch/x86/kvm/vmx.c
20506 @@ -1331,7 +1331,11 @@ static void reload_tss(void)
20507 struct desc_struct *descs;
20508
20509 descs = (void *)gdt->address;
20510 +
20511 + pax_open_kernel();
20512 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20513 + pax_close_kernel();
20514 +
20515 load_TR_desc();
20516 }
20517
20518 @@ -1541,6 +1545,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20519 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20520 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20521
20522 +#ifdef CONFIG_PAX_PER_CPU_PGD
20523 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20524 +#endif
20525 +
20526 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20527 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20528 vmx->loaded_vmcs->cpu = cpu;
20529 @@ -2674,8 +2682,11 @@ static __init int hardware_setup(void)
20530 if (!cpu_has_vmx_flexpriority())
20531 flexpriority_enabled = 0;
20532
20533 - if (!cpu_has_vmx_tpr_shadow())
20534 - kvm_x86_ops->update_cr8_intercept = NULL;
20535 + if (!cpu_has_vmx_tpr_shadow()) {
20536 + pax_open_kernel();
20537 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20538 + pax_close_kernel();
20539 + }
20540
20541 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20542 kvm_disable_largepages();
20543 @@ -3745,7 +3756,10 @@ static void vmx_set_constant_host_state(void)
20544
20545 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20546 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20547 +
20548 +#ifndef CONFIG_PAX_PER_CPU_PGD
20549 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20550 +#endif
20551
20552 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20553 #ifdef CONFIG_X86_64
20554 @@ -3767,7 +3781,7 @@ static void vmx_set_constant_host_state(void)
20555 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20556
20557 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20558 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20559 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20560
20561 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20562 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20563 @@ -6321,6 +6335,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20564 "jmp .Lkvm_vmx_return \n\t"
20565 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20566 ".Lkvm_vmx_return: "
20567 +
20568 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20569 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20570 + ".Lkvm_vmx_return2: "
20571 +#endif
20572 +
20573 /* Save guest registers, load host registers, keep flags */
20574 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20575 "pop %0 \n\t"
20576 @@ -6369,6 +6389,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20577 #endif
20578 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20579 [wordsize]"i"(sizeof(ulong))
20580 +
20581 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20582 + ,[cs]"i"(__KERNEL_CS)
20583 +#endif
20584 +
20585 : "cc", "memory"
20586 , R"ax", R"bx", R"di", R"si"
20587 #ifdef CONFIG_X86_64
20588 @@ -6376,7 +6401,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20589 #endif
20590 );
20591
20592 -#ifndef CONFIG_X86_64
20593 +#ifdef CONFIG_X86_32
20594 /*
20595 * The sysexit path does not restore ds/es, so we must set them to
20596 * a reasonable value ourselves.
20597 @@ -6385,8 +6410,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20598 * may be executed in interrupt context, which saves and restore segments
20599 * around it, nullifying its effect.
20600 */
20601 - loadsegment(ds, __USER_DS);
20602 - loadsegment(es, __USER_DS);
20603 + loadsegment(ds, __KERNEL_DS);
20604 + loadsegment(es, __KERNEL_DS);
20605 + loadsegment(ss, __KERNEL_DS);
20606 +
20607 +#ifdef CONFIG_PAX_KERNEXEC
20608 + loadsegment(fs, __KERNEL_PERCPU);
20609 +#endif
20610 +
20611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20612 + __set_fs(current_thread_info()->addr_limit);
20613 +#endif
20614 +
20615 #endif
20616
20617 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20618 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20619 index 2966c84..207d0cb 100644
20620 --- a/arch/x86/kvm/x86.c
20621 +++ b/arch/x86/kvm/x86.c
20622 @@ -1379,8 +1379,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20623 {
20624 struct kvm *kvm = vcpu->kvm;
20625 int lm = is_long_mode(vcpu);
20626 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20627 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20628 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20629 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20630 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20631 : kvm->arch.xen_hvm_config.blob_size_32;
20632 u32 page_num = data & ~PAGE_MASK;
20633 @@ -2243,6 +2243,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20634 if (n < msr_list.nmsrs)
20635 goto out;
20636 r = -EFAULT;
20637 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20638 + goto out;
20639 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20640 num_msrs_to_save * sizeof(u32)))
20641 goto out;
20642 @@ -2368,7 +2370,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20643 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20644 struct kvm_interrupt *irq)
20645 {
20646 - if (irq->irq < 0 || irq->irq >= 256)
20647 + if (irq->irq >= 256)
20648 return -EINVAL;
20649 if (irqchip_in_kernel(vcpu->kvm))
20650 return -ENXIO;
20651 @@ -4889,7 +4891,7 @@ static void kvm_set_mmio_spte_mask(void)
20652 kvm_mmu_set_mmio_spte_mask(mask);
20653 }
20654
20655 -int kvm_arch_init(void *opaque)
20656 +int kvm_arch_init(const void *opaque)
20657 {
20658 int r;
20659 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20660 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20661 index 642d880..cc9ebac 100644
20662 --- a/arch/x86/lguest/boot.c
20663 +++ b/arch/x86/lguest/boot.c
20664 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20665
20666 static void set_lguest_basic_apic_ops(void)
20667 {
20668 - apic->read = lguest_apic_read;
20669 - apic->write = lguest_apic_write;
20670 - apic->icr_read = lguest_apic_icr_read;
20671 - apic->icr_write = lguest_apic_icr_write;
20672 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20673 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20674 + *(void **)&apic->read = lguest_apic_read;
20675 + *(void **)&apic->write = lguest_apic_write;
20676 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20677 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20678 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20679 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20680 };
20681 #endif
20682
20683 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20684 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20685 * Launcher to reboot us.
20686 */
20687 -static void lguest_restart(char *reason)
20688 +static __noreturn void lguest_restart(char *reason)
20689 {
20690 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20691 + BUG();
20692 }
20693
20694 /*G:050
20695 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20696 index 00933d5..3a64af9 100644
20697 --- a/arch/x86/lib/atomic64_386_32.S
20698 +++ b/arch/x86/lib/atomic64_386_32.S
20699 @@ -48,6 +48,10 @@ BEGIN(read)
20700 movl (v), %eax
20701 movl 4(v), %edx
20702 RET_ENDP
20703 +BEGIN(read_unchecked)
20704 + movl (v), %eax
20705 + movl 4(v), %edx
20706 +RET_ENDP
20707 #undef v
20708
20709 #define v %esi
20710 @@ -55,6 +59,10 @@ BEGIN(set)
20711 movl %ebx, (v)
20712 movl %ecx, 4(v)
20713 RET_ENDP
20714 +BEGIN(set_unchecked)
20715 + movl %ebx, (v)
20716 + movl %ecx, 4(v)
20717 +RET_ENDP
20718 #undef v
20719
20720 #define v %esi
20721 @@ -70,6 +78,20 @@ RET_ENDP
20722 BEGIN(add)
20723 addl %eax, (v)
20724 adcl %edx, 4(v)
20725 +
20726 +#ifdef CONFIG_PAX_REFCOUNT
20727 + jno 0f
20728 + subl %eax, (v)
20729 + sbbl %edx, 4(v)
20730 + int $4
20731 +0:
20732 + _ASM_EXTABLE(0b, 0b)
20733 +#endif
20734 +
20735 +RET_ENDP
20736 +BEGIN(add_unchecked)
20737 + addl %eax, (v)
20738 + adcl %edx, 4(v)
20739 RET_ENDP
20740 #undef v
20741
20742 @@ -77,6 +99,24 @@ RET_ENDP
20743 BEGIN(add_return)
20744 addl (v), %eax
20745 adcl 4(v), %edx
20746 +
20747 +#ifdef CONFIG_PAX_REFCOUNT
20748 + into
20749 +1234:
20750 + _ASM_EXTABLE(1234b, 2f)
20751 +#endif
20752 +
20753 + movl %eax, (v)
20754 + movl %edx, 4(v)
20755 +
20756 +#ifdef CONFIG_PAX_REFCOUNT
20757 +2:
20758 +#endif
20759 +
20760 +RET_ENDP
20761 +BEGIN(add_return_unchecked)
20762 + addl (v), %eax
20763 + adcl 4(v), %edx
20764 movl %eax, (v)
20765 movl %edx, 4(v)
20766 RET_ENDP
20767 @@ -86,6 +126,20 @@ RET_ENDP
20768 BEGIN(sub)
20769 subl %eax, (v)
20770 sbbl %edx, 4(v)
20771 +
20772 +#ifdef CONFIG_PAX_REFCOUNT
20773 + jno 0f
20774 + addl %eax, (v)
20775 + adcl %edx, 4(v)
20776 + int $4
20777 +0:
20778 + _ASM_EXTABLE(0b, 0b)
20779 +#endif
20780 +
20781 +RET_ENDP
20782 +BEGIN(sub_unchecked)
20783 + subl %eax, (v)
20784 + sbbl %edx, 4(v)
20785 RET_ENDP
20786 #undef v
20787
20788 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20789 sbbl $0, %edx
20790 addl (v), %eax
20791 adcl 4(v), %edx
20792 +
20793 +#ifdef CONFIG_PAX_REFCOUNT
20794 + into
20795 +1234:
20796 + _ASM_EXTABLE(1234b, 2f)
20797 +#endif
20798 +
20799 + movl %eax, (v)
20800 + movl %edx, 4(v)
20801 +
20802 +#ifdef CONFIG_PAX_REFCOUNT
20803 +2:
20804 +#endif
20805 +
20806 +RET_ENDP
20807 +BEGIN(sub_return_unchecked)
20808 + negl %edx
20809 + negl %eax
20810 + sbbl $0, %edx
20811 + addl (v), %eax
20812 + adcl 4(v), %edx
20813 movl %eax, (v)
20814 movl %edx, 4(v)
20815 RET_ENDP
20816 @@ -105,6 +180,20 @@ RET_ENDP
20817 BEGIN(inc)
20818 addl $1, (v)
20819 adcl $0, 4(v)
20820 +
20821 +#ifdef CONFIG_PAX_REFCOUNT
20822 + jno 0f
20823 + subl $1, (v)
20824 + sbbl $0, 4(v)
20825 + int $4
20826 +0:
20827 + _ASM_EXTABLE(0b, 0b)
20828 +#endif
20829 +
20830 +RET_ENDP
20831 +BEGIN(inc_unchecked)
20832 + addl $1, (v)
20833 + adcl $0, 4(v)
20834 RET_ENDP
20835 #undef v
20836
20837 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20838 movl 4(v), %edx
20839 addl $1, %eax
20840 adcl $0, %edx
20841 +
20842 +#ifdef CONFIG_PAX_REFCOUNT
20843 + into
20844 +1234:
20845 + _ASM_EXTABLE(1234b, 2f)
20846 +#endif
20847 +
20848 + movl %eax, (v)
20849 + movl %edx, 4(v)
20850 +
20851 +#ifdef CONFIG_PAX_REFCOUNT
20852 +2:
20853 +#endif
20854 +
20855 +RET_ENDP
20856 +BEGIN(inc_return_unchecked)
20857 + movl (v), %eax
20858 + movl 4(v), %edx
20859 + addl $1, %eax
20860 + adcl $0, %edx
20861 movl %eax, (v)
20862 movl %edx, 4(v)
20863 RET_ENDP
20864 @@ -123,6 +232,20 @@ RET_ENDP
20865 BEGIN(dec)
20866 subl $1, (v)
20867 sbbl $0, 4(v)
20868 +
20869 +#ifdef CONFIG_PAX_REFCOUNT
20870 + jno 0f
20871 + addl $1, (v)
20872 + adcl $0, 4(v)
20873 + int $4
20874 +0:
20875 + _ASM_EXTABLE(0b, 0b)
20876 +#endif
20877 +
20878 +RET_ENDP
20879 +BEGIN(dec_unchecked)
20880 + subl $1, (v)
20881 + sbbl $0, 4(v)
20882 RET_ENDP
20883 #undef v
20884
20885 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20886 movl 4(v), %edx
20887 subl $1, %eax
20888 sbbl $0, %edx
20889 +
20890 +#ifdef CONFIG_PAX_REFCOUNT
20891 + into
20892 +1234:
20893 + _ASM_EXTABLE(1234b, 2f)
20894 +#endif
20895 +
20896 + movl %eax, (v)
20897 + movl %edx, 4(v)
20898 +
20899 +#ifdef CONFIG_PAX_REFCOUNT
20900 +2:
20901 +#endif
20902 +
20903 +RET_ENDP
20904 +BEGIN(dec_return_unchecked)
20905 + movl (v), %eax
20906 + movl 4(v), %edx
20907 + subl $1, %eax
20908 + sbbl $0, %edx
20909 movl %eax, (v)
20910 movl %edx, 4(v)
20911 RET_ENDP
20912 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20913 adcl %edx, %edi
20914 addl (v), %eax
20915 adcl 4(v), %edx
20916 +
20917 +#ifdef CONFIG_PAX_REFCOUNT
20918 + into
20919 +1234:
20920 + _ASM_EXTABLE(1234b, 2f)
20921 +#endif
20922 +
20923 cmpl %eax, %ecx
20924 je 3f
20925 1:
20926 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20927 1:
20928 addl $1, %eax
20929 adcl $0, %edx
20930 +
20931 +#ifdef CONFIG_PAX_REFCOUNT
20932 + into
20933 +1234:
20934 + _ASM_EXTABLE(1234b, 2f)
20935 +#endif
20936 +
20937 movl %eax, (v)
20938 movl %edx, 4(v)
20939 movl $1, %eax
20940 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20941 movl 4(v), %edx
20942 subl $1, %eax
20943 sbbl $0, %edx
20944 +
20945 +#ifdef CONFIG_PAX_REFCOUNT
20946 + into
20947 +1234:
20948 + _ASM_EXTABLE(1234b, 1f)
20949 +#endif
20950 +
20951 js 1f
20952 movl %eax, (v)
20953 movl %edx, 4(v)
20954 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20955 index f5cc9eb..51fa319 100644
20956 --- a/arch/x86/lib/atomic64_cx8_32.S
20957 +++ b/arch/x86/lib/atomic64_cx8_32.S
20958 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20959 CFI_STARTPROC
20960
20961 read64 %ecx
20962 + pax_force_retaddr
20963 ret
20964 CFI_ENDPROC
20965 ENDPROC(atomic64_read_cx8)
20966
20967 +ENTRY(atomic64_read_unchecked_cx8)
20968 + CFI_STARTPROC
20969 +
20970 + read64 %ecx
20971 + pax_force_retaddr
20972 + ret
20973 + CFI_ENDPROC
20974 +ENDPROC(atomic64_read_unchecked_cx8)
20975 +
20976 ENTRY(atomic64_set_cx8)
20977 CFI_STARTPROC
20978
20979 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20980 cmpxchg8b (%esi)
20981 jne 1b
20982
20983 + pax_force_retaddr
20984 ret
20985 CFI_ENDPROC
20986 ENDPROC(atomic64_set_cx8)
20987
20988 +ENTRY(atomic64_set_unchecked_cx8)
20989 + CFI_STARTPROC
20990 +
20991 +1:
20992 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20993 + * are atomic on 586 and newer */
20994 + cmpxchg8b (%esi)
20995 + jne 1b
20996 +
20997 + pax_force_retaddr
20998 + ret
20999 + CFI_ENDPROC
21000 +ENDPROC(atomic64_set_unchecked_cx8)
21001 +
21002 ENTRY(atomic64_xchg_cx8)
21003 CFI_STARTPROC
21004
21005 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
21006 cmpxchg8b (%esi)
21007 jne 1b
21008
21009 + pax_force_retaddr
21010 ret
21011 CFI_ENDPROC
21012 ENDPROC(atomic64_xchg_cx8)
21013
21014 -.macro addsub_return func ins insc
21015 -ENTRY(atomic64_\func\()_return_cx8)
21016 +.macro addsub_return func ins insc unchecked=""
21017 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21018 CFI_STARTPROC
21019 SAVE ebp
21020 SAVE ebx
21021 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
21022 movl %edx, %ecx
21023 \ins\()l %esi, %ebx
21024 \insc\()l %edi, %ecx
21025 +
21026 +.ifb \unchecked
21027 +#ifdef CONFIG_PAX_REFCOUNT
21028 + into
21029 +2:
21030 + _ASM_EXTABLE(2b, 3f)
21031 +#endif
21032 +.endif
21033 +
21034 LOCK_PREFIX
21035 cmpxchg8b (%ebp)
21036 jne 1b
21037 -
21038 -10:
21039 movl %ebx, %eax
21040 movl %ecx, %edx
21041 +
21042 +.ifb \unchecked
21043 +#ifdef CONFIG_PAX_REFCOUNT
21044 +3:
21045 +#endif
21046 +.endif
21047 +
21048 RESTORE edi
21049 RESTORE esi
21050 RESTORE ebx
21051 RESTORE ebp
21052 + pax_force_retaddr
21053 ret
21054 CFI_ENDPROC
21055 -ENDPROC(atomic64_\func\()_return_cx8)
21056 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21057 .endm
21058
21059 addsub_return add add adc
21060 addsub_return sub sub sbb
21061 +addsub_return add add adc _unchecked
21062 +addsub_return sub sub sbb _unchecked
21063
21064 -.macro incdec_return func ins insc
21065 -ENTRY(atomic64_\func\()_return_cx8)
21066 +.macro incdec_return func ins insc unchecked=""
21067 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21068 CFI_STARTPROC
21069 SAVE ebx
21070
21071 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21072 movl %edx, %ecx
21073 \ins\()l $1, %ebx
21074 \insc\()l $0, %ecx
21075 +
21076 +.ifb \unchecked
21077 +#ifdef CONFIG_PAX_REFCOUNT
21078 + into
21079 +2:
21080 + _ASM_EXTABLE(2b, 3f)
21081 +#endif
21082 +.endif
21083 +
21084 LOCK_PREFIX
21085 cmpxchg8b (%esi)
21086 jne 1b
21087
21088 -10:
21089 movl %ebx, %eax
21090 movl %ecx, %edx
21091 +
21092 +.ifb \unchecked
21093 +#ifdef CONFIG_PAX_REFCOUNT
21094 +3:
21095 +#endif
21096 +.endif
21097 +
21098 RESTORE ebx
21099 + pax_force_retaddr
21100 ret
21101 CFI_ENDPROC
21102 -ENDPROC(atomic64_\func\()_return_cx8)
21103 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21104 .endm
21105
21106 incdec_return inc add adc
21107 incdec_return dec sub sbb
21108 +incdec_return inc add adc _unchecked
21109 +incdec_return dec sub sbb _unchecked
21110
21111 ENTRY(atomic64_dec_if_positive_cx8)
21112 CFI_STARTPROC
21113 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21114 movl %edx, %ecx
21115 subl $1, %ebx
21116 sbb $0, %ecx
21117 +
21118 +#ifdef CONFIG_PAX_REFCOUNT
21119 + into
21120 +1234:
21121 + _ASM_EXTABLE(1234b, 2f)
21122 +#endif
21123 +
21124 js 2f
21125 LOCK_PREFIX
21126 cmpxchg8b (%esi)
21127 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21128 movl %ebx, %eax
21129 movl %ecx, %edx
21130 RESTORE ebx
21131 + pax_force_retaddr
21132 ret
21133 CFI_ENDPROC
21134 ENDPROC(atomic64_dec_if_positive_cx8)
21135 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21136 movl %edx, %ecx
21137 addl %ebp, %ebx
21138 adcl %edi, %ecx
21139 +
21140 +#ifdef CONFIG_PAX_REFCOUNT
21141 + into
21142 +1234:
21143 + _ASM_EXTABLE(1234b, 3f)
21144 +#endif
21145 +
21146 LOCK_PREFIX
21147 cmpxchg8b (%esi)
21148 jne 1b
21149 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21150 CFI_ADJUST_CFA_OFFSET -8
21151 RESTORE ebx
21152 RESTORE ebp
21153 + pax_force_retaddr
21154 ret
21155 4:
21156 cmpl %edx, 4(%esp)
21157 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21158 xorl %ecx, %ecx
21159 addl $1, %ebx
21160 adcl %edx, %ecx
21161 +
21162 +#ifdef CONFIG_PAX_REFCOUNT
21163 + into
21164 +1234:
21165 + _ASM_EXTABLE(1234b, 3f)
21166 +#endif
21167 +
21168 LOCK_PREFIX
21169 cmpxchg8b (%esi)
21170 jne 1b
21171 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21172 movl $1, %eax
21173 3:
21174 RESTORE ebx
21175 + pax_force_retaddr
21176 ret
21177 CFI_ENDPROC
21178 ENDPROC(atomic64_inc_not_zero_cx8)
21179 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21180 index 2af5df3..62b1a5a 100644
21181 --- a/arch/x86/lib/checksum_32.S
21182 +++ b/arch/x86/lib/checksum_32.S
21183 @@ -29,7 +29,8 @@
21184 #include <asm/dwarf2.h>
21185 #include <asm/errno.h>
21186 #include <asm/asm.h>
21187 -
21188 +#include <asm/segment.h>
21189 +
21190 /*
21191 * computes a partial checksum, e.g. for TCP/UDP fragments
21192 */
21193 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21194
21195 #define ARGBASE 16
21196 #define FP 12
21197 -
21198 -ENTRY(csum_partial_copy_generic)
21199 +
21200 +ENTRY(csum_partial_copy_generic_to_user)
21201 CFI_STARTPROC
21202 +
21203 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21204 + pushl_cfi %gs
21205 + popl_cfi %es
21206 + jmp csum_partial_copy_generic
21207 +#endif
21208 +
21209 +ENTRY(csum_partial_copy_generic_from_user)
21210 +
21211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21212 + pushl_cfi %gs
21213 + popl_cfi %ds
21214 +#endif
21215 +
21216 +ENTRY(csum_partial_copy_generic)
21217 subl $4,%esp
21218 CFI_ADJUST_CFA_OFFSET 4
21219 pushl_cfi %edi
21220 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21221 jmp 4f
21222 SRC(1: movw (%esi), %bx )
21223 addl $2, %esi
21224 -DST( movw %bx, (%edi) )
21225 +DST( movw %bx, %es:(%edi) )
21226 addl $2, %edi
21227 addw %bx, %ax
21228 adcl $0, %eax
21229 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21230 SRC(1: movl (%esi), %ebx )
21231 SRC( movl 4(%esi), %edx )
21232 adcl %ebx, %eax
21233 -DST( movl %ebx, (%edi) )
21234 +DST( movl %ebx, %es:(%edi) )
21235 adcl %edx, %eax
21236 -DST( movl %edx, 4(%edi) )
21237 +DST( movl %edx, %es:4(%edi) )
21238
21239 SRC( movl 8(%esi), %ebx )
21240 SRC( movl 12(%esi), %edx )
21241 adcl %ebx, %eax
21242 -DST( movl %ebx, 8(%edi) )
21243 +DST( movl %ebx, %es:8(%edi) )
21244 adcl %edx, %eax
21245 -DST( movl %edx, 12(%edi) )
21246 +DST( movl %edx, %es:12(%edi) )
21247
21248 SRC( movl 16(%esi), %ebx )
21249 SRC( movl 20(%esi), %edx )
21250 adcl %ebx, %eax
21251 -DST( movl %ebx, 16(%edi) )
21252 +DST( movl %ebx, %es:16(%edi) )
21253 adcl %edx, %eax
21254 -DST( movl %edx, 20(%edi) )
21255 +DST( movl %edx, %es:20(%edi) )
21256
21257 SRC( movl 24(%esi), %ebx )
21258 SRC( movl 28(%esi), %edx )
21259 adcl %ebx, %eax
21260 -DST( movl %ebx, 24(%edi) )
21261 +DST( movl %ebx, %es:24(%edi) )
21262 adcl %edx, %eax
21263 -DST( movl %edx, 28(%edi) )
21264 +DST( movl %edx, %es:28(%edi) )
21265
21266 lea 32(%esi), %esi
21267 lea 32(%edi), %edi
21268 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21269 shrl $2, %edx # This clears CF
21270 SRC(3: movl (%esi), %ebx )
21271 adcl %ebx, %eax
21272 -DST( movl %ebx, (%edi) )
21273 +DST( movl %ebx, %es:(%edi) )
21274 lea 4(%esi), %esi
21275 lea 4(%edi), %edi
21276 dec %edx
21277 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21278 jb 5f
21279 SRC( movw (%esi), %cx )
21280 leal 2(%esi), %esi
21281 -DST( movw %cx, (%edi) )
21282 +DST( movw %cx, %es:(%edi) )
21283 leal 2(%edi), %edi
21284 je 6f
21285 shll $16,%ecx
21286 SRC(5: movb (%esi), %cl )
21287 -DST( movb %cl, (%edi) )
21288 +DST( movb %cl, %es:(%edi) )
21289 6: addl %ecx, %eax
21290 adcl $0, %eax
21291 7:
21292 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21293
21294 6001:
21295 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21296 - movl $-EFAULT, (%ebx)
21297 + movl $-EFAULT, %ss:(%ebx)
21298
21299 # zero the complete destination - computing the rest
21300 # is too much work
21301 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21302
21303 6002:
21304 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21305 - movl $-EFAULT,(%ebx)
21306 + movl $-EFAULT,%ss:(%ebx)
21307 jmp 5000b
21308
21309 .previous
21310
21311 + pushl_cfi %ss
21312 + popl_cfi %ds
21313 + pushl_cfi %ss
21314 + popl_cfi %es
21315 popl_cfi %ebx
21316 CFI_RESTORE ebx
21317 popl_cfi %esi
21318 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21319 popl_cfi %ecx # equivalent to addl $4,%esp
21320 ret
21321 CFI_ENDPROC
21322 -ENDPROC(csum_partial_copy_generic)
21323 +ENDPROC(csum_partial_copy_generic_to_user)
21324
21325 #else
21326
21327 /* Version for PentiumII/PPro */
21328
21329 #define ROUND1(x) \
21330 + nop; nop; nop; \
21331 SRC(movl x(%esi), %ebx ) ; \
21332 addl %ebx, %eax ; \
21333 - DST(movl %ebx, x(%edi) ) ;
21334 + DST(movl %ebx, %es:x(%edi)) ;
21335
21336 #define ROUND(x) \
21337 + nop; nop; nop; \
21338 SRC(movl x(%esi), %ebx ) ; \
21339 adcl %ebx, %eax ; \
21340 - DST(movl %ebx, x(%edi) ) ;
21341 + DST(movl %ebx, %es:x(%edi)) ;
21342
21343 #define ARGBASE 12
21344 -
21345 -ENTRY(csum_partial_copy_generic)
21346 +
21347 +ENTRY(csum_partial_copy_generic_to_user)
21348 CFI_STARTPROC
21349 +
21350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21351 + pushl_cfi %gs
21352 + popl_cfi %es
21353 + jmp csum_partial_copy_generic
21354 +#endif
21355 +
21356 +ENTRY(csum_partial_copy_generic_from_user)
21357 +
21358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21359 + pushl_cfi %gs
21360 + popl_cfi %ds
21361 +#endif
21362 +
21363 +ENTRY(csum_partial_copy_generic)
21364 pushl_cfi %ebx
21365 CFI_REL_OFFSET ebx, 0
21366 pushl_cfi %edi
21367 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21368 subl %ebx, %edi
21369 lea -1(%esi),%edx
21370 andl $-32,%edx
21371 - lea 3f(%ebx,%ebx), %ebx
21372 + lea 3f(%ebx,%ebx,2), %ebx
21373 testl %esi, %esi
21374 jmp *%ebx
21375 1: addl $64,%esi
21376 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21377 jb 5f
21378 SRC( movw (%esi), %dx )
21379 leal 2(%esi), %esi
21380 -DST( movw %dx, (%edi) )
21381 +DST( movw %dx, %es:(%edi) )
21382 leal 2(%edi), %edi
21383 je 6f
21384 shll $16,%edx
21385 5:
21386 SRC( movb (%esi), %dl )
21387 -DST( movb %dl, (%edi) )
21388 +DST( movb %dl, %es:(%edi) )
21389 6: addl %edx, %eax
21390 adcl $0, %eax
21391 7:
21392 .section .fixup, "ax"
21393 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21394 - movl $-EFAULT, (%ebx)
21395 + movl $-EFAULT, %ss:(%ebx)
21396 # zero the complete destination (computing the rest is too much work)
21397 movl ARGBASE+8(%esp),%edi # dst
21398 movl ARGBASE+12(%esp),%ecx # len
21399 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21400 rep; stosb
21401 jmp 7b
21402 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21403 - movl $-EFAULT, (%ebx)
21404 + movl $-EFAULT, %ss:(%ebx)
21405 jmp 7b
21406 .previous
21407
21408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21409 + pushl_cfi %ss
21410 + popl_cfi %ds
21411 + pushl_cfi %ss
21412 + popl_cfi %es
21413 +#endif
21414 +
21415 popl_cfi %esi
21416 CFI_RESTORE esi
21417 popl_cfi %edi
21418 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21419 CFI_RESTORE ebx
21420 ret
21421 CFI_ENDPROC
21422 -ENDPROC(csum_partial_copy_generic)
21423 +ENDPROC(csum_partial_copy_generic_to_user)
21424
21425 #undef ROUND
21426 #undef ROUND1
21427 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21428 index f2145cf..cea889d 100644
21429 --- a/arch/x86/lib/clear_page_64.S
21430 +++ b/arch/x86/lib/clear_page_64.S
21431 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21432 movl $4096/8,%ecx
21433 xorl %eax,%eax
21434 rep stosq
21435 + pax_force_retaddr
21436 ret
21437 CFI_ENDPROC
21438 ENDPROC(clear_page_c)
21439 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21440 movl $4096,%ecx
21441 xorl %eax,%eax
21442 rep stosb
21443 + pax_force_retaddr
21444 ret
21445 CFI_ENDPROC
21446 ENDPROC(clear_page_c_e)
21447 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21448 leaq 64(%rdi),%rdi
21449 jnz .Lloop
21450 nop
21451 + pax_force_retaddr
21452 ret
21453 CFI_ENDPROC
21454 .Lclear_page_end:
21455 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21456
21457 #include <asm/cpufeature.h>
21458
21459 - .section .altinstr_replacement,"ax"
21460 + .section .altinstr_replacement,"a"
21461 1: .byte 0xeb /* jmp <disp8> */
21462 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21463 2: .byte 0xeb /* jmp <disp8> */
21464 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21465 index 1e572c5..2a162cd 100644
21466 --- a/arch/x86/lib/cmpxchg16b_emu.S
21467 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21468 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21469
21470 popf
21471 mov $1, %al
21472 + pax_force_retaddr
21473 ret
21474
21475 not_same:
21476 popf
21477 xor %al,%al
21478 + pax_force_retaddr
21479 ret
21480
21481 CFI_ENDPROC
21482 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21483 index 6b34d04..dccb07f 100644
21484 --- a/arch/x86/lib/copy_page_64.S
21485 +++ b/arch/x86/lib/copy_page_64.S
21486 @@ -9,6 +9,7 @@ copy_page_c:
21487 CFI_STARTPROC
21488 movl $4096/8,%ecx
21489 rep movsq
21490 + pax_force_retaddr
21491 ret
21492 CFI_ENDPROC
21493 ENDPROC(copy_page_c)
21494 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21495
21496 ENTRY(copy_page)
21497 CFI_STARTPROC
21498 - subq $2*8,%rsp
21499 - CFI_ADJUST_CFA_OFFSET 2*8
21500 + subq $3*8,%rsp
21501 + CFI_ADJUST_CFA_OFFSET 3*8
21502 movq %rbx,(%rsp)
21503 CFI_REL_OFFSET rbx, 0
21504 movq %r12,1*8(%rsp)
21505 CFI_REL_OFFSET r12, 1*8
21506 + movq %r13,2*8(%rsp)
21507 + CFI_REL_OFFSET r13, 2*8
21508
21509 movl $(4096/64)-5,%ecx
21510 .p2align 4
21511 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21512 movq 16 (%rsi), %rdx
21513 movq 24 (%rsi), %r8
21514 movq 32 (%rsi), %r9
21515 - movq 40 (%rsi), %r10
21516 + movq 40 (%rsi), %r13
21517 movq 48 (%rsi), %r11
21518 movq 56 (%rsi), %r12
21519
21520 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21521 movq %rdx, 16 (%rdi)
21522 movq %r8, 24 (%rdi)
21523 movq %r9, 32 (%rdi)
21524 - movq %r10, 40 (%rdi)
21525 + movq %r13, 40 (%rdi)
21526 movq %r11, 48 (%rdi)
21527 movq %r12, 56 (%rdi)
21528
21529 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21530 movq 16 (%rsi), %rdx
21531 movq 24 (%rsi), %r8
21532 movq 32 (%rsi), %r9
21533 - movq 40 (%rsi), %r10
21534 + movq 40 (%rsi), %r13
21535 movq 48 (%rsi), %r11
21536 movq 56 (%rsi), %r12
21537
21538 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21539 movq %rdx, 16 (%rdi)
21540 movq %r8, 24 (%rdi)
21541 movq %r9, 32 (%rdi)
21542 - movq %r10, 40 (%rdi)
21543 + movq %r13, 40 (%rdi)
21544 movq %r11, 48 (%rdi)
21545 movq %r12, 56 (%rdi)
21546
21547 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21548 CFI_RESTORE rbx
21549 movq 1*8(%rsp),%r12
21550 CFI_RESTORE r12
21551 - addq $2*8,%rsp
21552 - CFI_ADJUST_CFA_OFFSET -2*8
21553 + movq 2*8(%rsp),%r13
21554 + CFI_RESTORE r13
21555 + addq $3*8,%rsp
21556 + CFI_ADJUST_CFA_OFFSET -3*8
21557 + pax_force_retaddr
21558 ret
21559 .Lcopy_page_end:
21560 CFI_ENDPROC
21561 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21562
21563 #include <asm/cpufeature.h>
21564
21565 - .section .altinstr_replacement,"ax"
21566 + .section .altinstr_replacement,"a"
21567 1: .byte 0xeb /* jmp <disp8> */
21568 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21569 2:
21570 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21571 index 5b2995f..78e7644 100644
21572 --- a/arch/x86/lib/copy_user_64.S
21573 +++ b/arch/x86/lib/copy_user_64.S
21574 @@ -17,6 +17,7 @@
21575 #include <asm/cpufeature.h>
21576 #include <asm/alternative-asm.h>
21577 #include <asm/asm.h>
21578 +#include <asm/pgtable.h>
21579
21580 /*
21581 * By placing feature2 after feature1 in altinstructions section, we logically
21582 @@ -30,7 +31,7 @@
21583 .byte 0xe9 /* 32bit jump */
21584 .long \orig-1f /* by default jump to orig */
21585 1:
21586 - .section .altinstr_replacement,"ax"
21587 + .section .altinstr_replacement,"a"
21588 2: .byte 0xe9 /* near jump with 32bit immediate */
21589 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21590 3: .byte 0xe9 /* near jump with 32bit immediate */
21591 @@ -69,47 +70,20 @@
21592 #endif
21593 .endm
21594
21595 -/* Standard copy_to_user with segment limit checking */
21596 -ENTRY(_copy_to_user)
21597 - CFI_STARTPROC
21598 - GET_THREAD_INFO(%rax)
21599 - movq %rdi,%rcx
21600 - addq %rdx,%rcx
21601 - jc bad_to_user
21602 - cmpq TI_addr_limit(%rax),%rcx
21603 - ja bad_to_user
21604 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21605 - copy_user_generic_unrolled,copy_user_generic_string, \
21606 - copy_user_enhanced_fast_string
21607 - CFI_ENDPROC
21608 -ENDPROC(_copy_to_user)
21609 -
21610 -/* Standard copy_from_user with segment limit checking */
21611 -ENTRY(_copy_from_user)
21612 - CFI_STARTPROC
21613 - GET_THREAD_INFO(%rax)
21614 - movq %rsi,%rcx
21615 - addq %rdx,%rcx
21616 - jc bad_from_user
21617 - cmpq TI_addr_limit(%rax),%rcx
21618 - ja bad_from_user
21619 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21620 - copy_user_generic_unrolled,copy_user_generic_string, \
21621 - copy_user_enhanced_fast_string
21622 - CFI_ENDPROC
21623 -ENDPROC(_copy_from_user)
21624 -
21625 .section .fixup,"ax"
21626 /* must zero dest */
21627 ENTRY(bad_from_user)
21628 bad_from_user:
21629 CFI_STARTPROC
21630 + testl %edx,%edx
21631 + js bad_to_user
21632 movl %edx,%ecx
21633 xorl %eax,%eax
21634 rep
21635 stosb
21636 bad_to_user:
21637 movl %edx,%eax
21638 + pax_force_retaddr
21639 ret
21640 CFI_ENDPROC
21641 ENDPROC(bad_from_user)
21642 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21643 jz 17f
21644 1: movq (%rsi),%r8
21645 2: movq 1*8(%rsi),%r9
21646 -3: movq 2*8(%rsi),%r10
21647 +3: movq 2*8(%rsi),%rax
21648 4: movq 3*8(%rsi),%r11
21649 5: movq %r8,(%rdi)
21650 6: movq %r9,1*8(%rdi)
21651 -7: movq %r10,2*8(%rdi)
21652 +7: movq %rax,2*8(%rdi)
21653 8: movq %r11,3*8(%rdi)
21654 9: movq 4*8(%rsi),%r8
21655 10: movq 5*8(%rsi),%r9
21656 -11: movq 6*8(%rsi),%r10
21657 +11: movq 6*8(%rsi),%rax
21658 12: movq 7*8(%rsi),%r11
21659 13: movq %r8,4*8(%rdi)
21660 14: movq %r9,5*8(%rdi)
21661 -15: movq %r10,6*8(%rdi)
21662 +15: movq %rax,6*8(%rdi)
21663 16: movq %r11,7*8(%rdi)
21664 leaq 64(%rsi),%rsi
21665 leaq 64(%rdi),%rdi
21666 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21667 decl %ecx
21668 jnz 21b
21669 23: xor %eax,%eax
21670 + pax_force_retaddr
21671 ret
21672
21673 .section .fixup,"ax"
21674 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21675 3: rep
21676 movsb
21677 4: xorl %eax,%eax
21678 + pax_force_retaddr
21679 ret
21680
21681 .section .fixup,"ax"
21682 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21683 1: rep
21684 movsb
21685 2: xorl %eax,%eax
21686 + pax_force_retaddr
21687 ret
21688
21689 .section .fixup,"ax"
21690 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21691 index cacddc7..09d49e4 100644
21692 --- a/arch/x86/lib/copy_user_nocache_64.S
21693 +++ b/arch/x86/lib/copy_user_nocache_64.S
21694 @@ -8,6 +8,7 @@
21695
21696 #include <linux/linkage.h>
21697 #include <asm/dwarf2.h>
21698 +#include <asm/alternative-asm.h>
21699
21700 #define FIX_ALIGNMENT 1
21701
21702 @@ -15,6 +16,7 @@
21703 #include <asm/asm-offsets.h>
21704 #include <asm/thread_info.h>
21705 #include <asm/asm.h>
21706 +#include <asm/pgtable.h>
21707
21708 .macro ALIGN_DESTINATION
21709 #ifdef FIX_ALIGNMENT
21710 @@ -48,6 +50,15 @@
21711 */
21712 ENTRY(__copy_user_nocache)
21713 CFI_STARTPROC
21714 +
21715 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21716 + mov $PAX_USER_SHADOW_BASE,%rcx
21717 + cmp %rcx,%rsi
21718 + jae 1f
21719 + add %rcx,%rsi
21720 +1:
21721 +#endif
21722 +
21723 cmpl $8,%edx
21724 jb 20f /* less then 8 bytes, go to byte copy loop */
21725 ALIGN_DESTINATION
21726 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21727 jz 17f
21728 1: movq (%rsi),%r8
21729 2: movq 1*8(%rsi),%r9
21730 -3: movq 2*8(%rsi),%r10
21731 +3: movq 2*8(%rsi),%rax
21732 4: movq 3*8(%rsi),%r11
21733 5: movnti %r8,(%rdi)
21734 6: movnti %r9,1*8(%rdi)
21735 -7: movnti %r10,2*8(%rdi)
21736 +7: movnti %rax,2*8(%rdi)
21737 8: movnti %r11,3*8(%rdi)
21738 9: movq 4*8(%rsi),%r8
21739 10: movq 5*8(%rsi),%r9
21740 -11: movq 6*8(%rsi),%r10
21741 +11: movq 6*8(%rsi),%rax
21742 12: movq 7*8(%rsi),%r11
21743 13: movnti %r8,4*8(%rdi)
21744 14: movnti %r9,5*8(%rdi)
21745 -15: movnti %r10,6*8(%rdi)
21746 +15: movnti %rax,6*8(%rdi)
21747 16: movnti %r11,7*8(%rdi)
21748 leaq 64(%rsi),%rsi
21749 leaq 64(%rdi),%rdi
21750 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21751 jnz 21b
21752 23: xorl %eax,%eax
21753 sfence
21754 + pax_force_retaddr
21755 ret
21756
21757 .section .fixup,"ax"
21758 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21759 index 2419d5f..953ee51 100644
21760 --- a/arch/x86/lib/csum-copy_64.S
21761 +++ b/arch/x86/lib/csum-copy_64.S
21762 @@ -9,6 +9,7 @@
21763 #include <asm/dwarf2.h>
21764 #include <asm/errno.h>
21765 #include <asm/asm.h>
21766 +#include <asm/alternative-asm.h>
21767
21768 /*
21769 * Checksum copy with exception handling.
21770 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21771 CFI_RESTORE rbp
21772 addq $7*8, %rsp
21773 CFI_ADJUST_CFA_OFFSET -7*8
21774 + pax_force_retaddr 0, 1
21775 ret
21776 CFI_RESTORE_STATE
21777
21778 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21779 index 25b7ae8..3b52ccd 100644
21780 --- a/arch/x86/lib/csum-wrappers_64.c
21781 +++ b/arch/x86/lib/csum-wrappers_64.c
21782 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21783 len -= 2;
21784 }
21785 }
21786 - isum = csum_partial_copy_generic((__force const void *)src,
21787 +
21788 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21789 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21790 + src += PAX_USER_SHADOW_BASE;
21791 +#endif
21792 +
21793 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21794 dst, len, isum, errp, NULL);
21795 if (unlikely(*errp))
21796 goto out_err;
21797 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21798 }
21799
21800 *errp = 0;
21801 - return csum_partial_copy_generic(src, (void __force *)dst,
21802 +
21803 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21804 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21805 + dst += PAX_USER_SHADOW_BASE;
21806 +#endif
21807 +
21808 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21809 len, isum, NULL, errp);
21810 }
21811 EXPORT_SYMBOL(csum_partial_copy_to_user);
21812 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21813 index b33b1fb..219f389 100644
21814 --- a/arch/x86/lib/getuser.S
21815 +++ b/arch/x86/lib/getuser.S
21816 @@ -33,15 +33,38 @@
21817 #include <asm/asm-offsets.h>
21818 #include <asm/thread_info.h>
21819 #include <asm/asm.h>
21820 +#include <asm/segment.h>
21821 +#include <asm/pgtable.h>
21822 +#include <asm/alternative-asm.h>
21823 +
21824 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21825 +#define __copyuser_seg gs;
21826 +#else
21827 +#define __copyuser_seg
21828 +#endif
21829
21830 .text
21831 ENTRY(__get_user_1)
21832 CFI_STARTPROC
21833 +
21834 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21835 GET_THREAD_INFO(%_ASM_DX)
21836 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21837 jae bad_get_user
21838 -1: movzb (%_ASM_AX),%edx
21839 +
21840 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21841 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21842 + cmp %_ASM_DX,%_ASM_AX
21843 + jae 1234f
21844 + add %_ASM_DX,%_ASM_AX
21845 +1234:
21846 +#endif
21847 +
21848 +#endif
21849 +
21850 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21851 xor %eax,%eax
21852 + pax_force_retaddr
21853 ret
21854 CFI_ENDPROC
21855 ENDPROC(__get_user_1)
21856 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21857 ENTRY(__get_user_2)
21858 CFI_STARTPROC
21859 add $1,%_ASM_AX
21860 +
21861 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21862 jc bad_get_user
21863 GET_THREAD_INFO(%_ASM_DX)
21864 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21865 jae bad_get_user
21866 -2: movzwl -1(%_ASM_AX),%edx
21867 +
21868 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21869 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21870 + cmp %_ASM_DX,%_ASM_AX
21871 + jae 1234f
21872 + add %_ASM_DX,%_ASM_AX
21873 +1234:
21874 +#endif
21875 +
21876 +#endif
21877 +
21878 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21879 xor %eax,%eax
21880 + pax_force_retaddr
21881 ret
21882 CFI_ENDPROC
21883 ENDPROC(__get_user_2)
21884 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21885 ENTRY(__get_user_4)
21886 CFI_STARTPROC
21887 add $3,%_ASM_AX
21888 +
21889 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21890 jc bad_get_user
21891 GET_THREAD_INFO(%_ASM_DX)
21892 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21893 jae bad_get_user
21894 -3: mov -3(%_ASM_AX),%edx
21895 +
21896 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21897 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21898 + cmp %_ASM_DX,%_ASM_AX
21899 + jae 1234f
21900 + add %_ASM_DX,%_ASM_AX
21901 +1234:
21902 +#endif
21903 +
21904 +#endif
21905 +
21906 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21907 xor %eax,%eax
21908 + pax_force_retaddr
21909 ret
21910 CFI_ENDPROC
21911 ENDPROC(__get_user_4)
21912 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21913 GET_THREAD_INFO(%_ASM_DX)
21914 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21915 jae bad_get_user
21916 +
21917 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21918 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21919 + cmp %_ASM_DX,%_ASM_AX
21920 + jae 1234f
21921 + add %_ASM_DX,%_ASM_AX
21922 +1234:
21923 +#endif
21924 +
21925 4: movq -7(%_ASM_AX),%_ASM_DX
21926 xor %eax,%eax
21927 + pax_force_retaddr
21928 ret
21929 CFI_ENDPROC
21930 ENDPROC(__get_user_8)
21931 @@ -91,6 +152,7 @@ bad_get_user:
21932 CFI_STARTPROC
21933 xor %edx,%edx
21934 mov $(-EFAULT),%_ASM_AX
21935 + pax_force_retaddr
21936 ret
21937 CFI_ENDPROC
21938 END(bad_get_user)
21939 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21940 index b1e6c4b..21ae8fc 100644
21941 --- a/arch/x86/lib/insn.c
21942 +++ b/arch/x86/lib/insn.c
21943 @@ -21,6 +21,11 @@
21944 #include <linux/string.h>
21945 #include <asm/inat.h>
21946 #include <asm/insn.h>
21947 +#ifdef __KERNEL__
21948 +#include <asm/pgtable_types.h>
21949 +#else
21950 +#define ktla_ktva(addr) addr
21951 +#endif
21952
21953 /* Verify next sizeof(t) bytes can be on the same instruction */
21954 #define validate_next(t, insn, n) \
21955 @@ -49,8 +54,8 @@
21956 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21957 {
21958 memset(insn, 0, sizeof(*insn));
21959 - insn->kaddr = kaddr;
21960 - insn->next_byte = kaddr;
21961 + insn->kaddr = ktla_ktva(kaddr);
21962 + insn->next_byte = ktla_ktva(kaddr);
21963 insn->x86_64 = x86_64 ? 1 : 0;
21964 insn->opnd_bytes = 4;
21965 if (x86_64)
21966 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21967 index 05a95e7..326f2fa 100644
21968 --- a/arch/x86/lib/iomap_copy_64.S
21969 +++ b/arch/x86/lib/iomap_copy_64.S
21970 @@ -17,6 +17,7 @@
21971
21972 #include <linux/linkage.h>
21973 #include <asm/dwarf2.h>
21974 +#include <asm/alternative-asm.h>
21975
21976 /*
21977 * override generic version in lib/iomap_copy.c
21978 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21979 CFI_STARTPROC
21980 movl %edx,%ecx
21981 rep movsd
21982 + pax_force_retaddr
21983 ret
21984 CFI_ENDPROC
21985 ENDPROC(__iowrite32_copy)
21986 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21987 index 1c273be..da9cc0e 100644
21988 --- a/arch/x86/lib/memcpy_64.S
21989 +++ b/arch/x86/lib/memcpy_64.S
21990 @@ -33,6 +33,7 @@
21991 rep movsq
21992 movl %edx, %ecx
21993 rep movsb
21994 + pax_force_retaddr
21995 ret
21996 .Lmemcpy_e:
21997 .previous
21998 @@ -49,6 +50,7 @@
21999 movq %rdi, %rax
22000 movq %rdx, %rcx
22001 rep movsb
22002 + pax_force_retaddr
22003 ret
22004 .Lmemcpy_e_e:
22005 .previous
22006 @@ -76,13 +78,13 @@ ENTRY(memcpy)
22007 */
22008 movq 0*8(%rsi), %r8
22009 movq 1*8(%rsi), %r9
22010 - movq 2*8(%rsi), %r10
22011 + movq 2*8(%rsi), %rcx
22012 movq 3*8(%rsi), %r11
22013 leaq 4*8(%rsi), %rsi
22014
22015 movq %r8, 0*8(%rdi)
22016 movq %r9, 1*8(%rdi)
22017 - movq %r10, 2*8(%rdi)
22018 + movq %rcx, 2*8(%rdi)
22019 movq %r11, 3*8(%rdi)
22020 leaq 4*8(%rdi), %rdi
22021 jae .Lcopy_forward_loop
22022 @@ -105,12 +107,12 @@ ENTRY(memcpy)
22023 subq $0x20, %rdx
22024 movq -1*8(%rsi), %r8
22025 movq -2*8(%rsi), %r9
22026 - movq -3*8(%rsi), %r10
22027 + movq -3*8(%rsi), %rcx
22028 movq -4*8(%rsi), %r11
22029 leaq -4*8(%rsi), %rsi
22030 movq %r8, -1*8(%rdi)
22031 movq %r9, -2*8(%rdi)
22032 - movq %r10, -3*8(%rdi)
22033 + movq %rcx, -3*8(%rdi)
22034 movq %r11, -4*8(%rdi)
22035 leaq -4*8(%rdi), %rdi
22036 jae .Lcopy_backward_loop
22037 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22038 */
22039 movq 0*8(%rsi), %r8
22040 movq 1*8(%rsi), %r9
22041 - movq -2*8(%rsi, %rdx), %r10
22042 + movq -2*8(%rsi, %rdx), %rcx
22043 movq -1*8(%rsi, %rdx), %r11
22044 movq %r8, 0*8(%rdi)
22045 movq %r9, 1*8(%rdi)
22046 - movq %r10, -2*8(%rdi, %rdx)
22047 + movq %rcx, -2*8(%rdi, %rdx)
22048 movq %r11, -1*8(%rdi, %rdx)
22049 + pax_force_retaddr
22050 retq
22051 .p2align 4
22052 .Lless_16bytes:
22053 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22054 movq -1*8(%rsi, %rdx), %r9
22055 movq %r8, 0*8(%rdi)
22056 movq %r9, -1*8(%rdi, %rdx)
22057 + pax_force_retaddr
22058 retq
22059 .p2align 4
22060 .Lless_8bytes:
22061 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22062 movl -4(%rsi, %rdx), %r8d
22063 movl %ecx, (%rdi)
22064 movl %r8d, -4(%rdi, %rdx)
22065 + pax_force_retaddr
22066 retq
22067 .p2align 4
22068 .Lless_3bytes:
22069 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22070 movb %cl, (%rdi)
22071
22072 .Lend:
22073 + pax_force_retaddr
22074 retq
22075 CFI_ENDPROC
22076 ENDPROC(memcpy)
22077 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22078 index ee16461..c39c199 100644
22079 --- a/arch/x86/lib/memmove_64.S
22080 +++ b/arch/x86/lib/memmove_64.S
22081 @@ -61,13 +61,13 @@ ENTRY(memmove)
22082 5:
22083 sub $0x20, %rdx
22084 movq 0*8(%rsi), %r11
22085 - movq 1*8(%rsi), %r10
22086 + movq 1*8(%rsi), %rcx
22087 movq 2*8(%rsi), %r9
22088 movq 3*8(%rsi), %r8
22089 leaq 4*8(%rsi), %rsi
22090
22091 movq %r11, 0*8(%rdi)
22092 - movq %r10, 1*8(%rdi)
22093 + movq %rcx, 1*8(%rdi)
22094 movq %r9, 2*8(%rdi)
22095 movq %r8, 3*8(%rdi)
22096 leaq 4*8(%rdi), %rdi
22097 @@ -81,10 +81,10 @@ ENTRY(memmove)
22098 4:
22099 movq %rdx, %rcx
22100 movq -8(%rsi, %rdx), %r11
22101 - lea -8(%rdi, %rdx), %r10
22102 + lea -8(%rdi, %rdx), %r9
22103 shrq $3, %rcx
22104 rep movsq
22105 - movq %r11, (%r10)
22106 + movq %r11, (%r9)
22107 jmp 13f
22108 .Lmemmove_end_forward:
22109
22110 @@ -95,14 +95,14 @@ ENTRY(memmove)
22111 7:
22112 movq %rdx, %rcx
22113 movq (%rsi), %r11
22114 - movq %rdi, %r10
22115 + movq %rdi, %r9
22116 leaq -8(%rsi, %rdx), %rsi
22117 leaq -8(%rdi, %rdx), %rdi
22118 shrq $3, %rcx
22119 std
22120 rep movsq
22121 cld
22122 - movq %r11, (%r10)
22123 + movq %r11, (%r9)
22124 jmp 13f
22125
22126 /*
22127 @@ -127,13 +127,13 @@ ENTRY(memmove)
22128 8:
22129 subq $0x20, %rdx
22130 movq -1*8(%rsi), %r11
22131 - movq -2*8(%rsi), %r10
22132 + movq -2*8(%rsi), %rcx
22133 movq -3*8(%rsi), %r9
22134 movq -4*8(%rsi), %r8
22135 leaq -4*8(%rsi), %rsi
22136
22137 movq %r11, -1*8(%rdi)
22138 - movq %r10, -2*8(%rdi)
22139 + movq %rcx, -2*8(%rdi)
22140 movq %r9, -3*8(%rdi)
22141 movq %r8, -4*8(%rdi)
22142 leaq -4*8(%rdi), %rdi
22143 @@ -151,11 +151,11 @@ ENTRY(memmove)
22144 * Move data from 16 bytes to 31 bytes.
22145 */
22146 movq 0*8(%rsi), %r11
22147 - movq 1*8(%rsi), %r10
22148 + movq 1*8(%rsi), %rcx
22149 movq -2*8(%rsi, %rdx), %r9
22150 movq -1*8(%rsi, %rdx), %r8
22151 movq %r11, 0*8(%rdi)
22152 - movq %r10, 1*8(%rdi)
22153 + movq %rcx, 1*8(%rdi)
22154 movq %r9, -2*8(%rdi, %rdx)
22155 movq %r8, -1*8(%rdi, %rdx)
22156 jmp 13f
22157 @@ -167,9 +167,9 @@ ENTRY(memmove)
22158 * Move data from 8 bytes to 15 bytes.
22159 */
22160 movq 0*8(%rsi), %r11
22161 - movq -1*8(%rsi, %rdx), %r10
22162 + movq -1*8(%rsi, %rdx), %r9
22163 movq %r11, 0*8(%rdi)
22164 - movq %r10, -1*8(%rdi, %rdx)
22165 + movq %r9, -1*8(%rdi, %rdx)
22166 jmp 13f
22167 10:
22168 cmpq $4, %rdx
22169 @@ -178,9 +178,9 @@ ENTRY(memmove)
22170 * Move data from 4 bytes to 7 bytes.
22171 */
22172 movl (%rsi), %r11d
22173 - movl -4(%rsi, %rdx), %r10d
22174 + movl -4(%rsi, %rdx), %r9d
22175 movl %r11d, (%rdi)
22176 - movl %r10d, -4(%rdi, %rdx)
22177 + movl %r9d, -4(%rdi, %rdx)
22178 jmp 13f
22179 11:
22180 cmp $2, %rdx
22181 @@ -189,9 +189,9 @@ ENTRY(memmove)
22182 * Move data from 2 bytes to 3 bytes.
22183 */
22184 movw (%rsi), %r11w
22185 - movw -2(%rsi, %rdx), %r10w
22186 + movw -2(%rsi, %rdx), %r9w
22187 movw %r11w, (%rdi)
22188 - movw %r10w, -2(%rdi, %rdx)
22189 + movw %r9w, -2(%rdi, %rdx)
22190 jmp 13f
22191 12:
22192 cmp $1, %rdx
22193 @@ -202,6 +202,7 @@ ENTRY(memmove)
22194 movb (%rsi), %r11b
22195 movb %r11b, (%rdi)
22196 13:
22197 + pax_force_retaddr
22198 retq
22199 CFI_ENDPROC
22200
22201 @@ -210,6 +211,7 @@ ENTRY(memmove)
22202 /* Forward moving data. */
22203 movq %rdx, %rcx
22204 rep movsb
22205 + pax_force_retaddr
22206 retq
22207 .Lmemmove_end_forward_efs:
22208 .previous
22209 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22210 index 2dcb380..963660a 100644
22211 --- a/arch/x86/lib/memset_64.S
22212 +++ b/arch/x86/lib/memset_64.S
22213 @@ -30,6 +30,7 @@
22214 movl %edx,%ecx
22215 rep stosb
22216 movq %r9,%rax
22217 + pax_force_retaddr
22218 ret
22219 .Lmemset_e:
22220 .previous
22221 @@ -52,6 +53,7 @@
22222 movq %rdx,%rcx
22223 rep stosb
22224 movq %r9,%rax
22225 + pax_force_retaddr
22226 ret
22227 .Lmemset_e_e:
22228 .previous
22229 @@ -59,7 +61,7 @@
22230 ENTRY(memset)
22231 ENTRY(__memset)
22232 CFI_STARTPROC
22233 - movq %rdi,%r10
22234 + movq %rdi,%r11
22235
22236 /* expand byte value */
22237 movzbl %sil,%ecx
22238 @@ -117,7 +119,8 @@ ENTRY(__memset)
22239 jnz .Lloop_1
22240
22241 .Lende:
22242 - movq %r10,%rax
22243 + movq %r11,%rax
22244 + pax_force_retaddr
22245 ret
22246
22247 CFI_RESTORE_STATE
22248 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22249 index c9f2d9b..e7fd2c0 100644
22250 --- a/arch/x86/lib/mmx_32.c
22251 +++ b/arch/x86/lib/mmx_32.c
22252 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22253 {
22254 void *p;
22255 int i;
22256 + unsigned long cr0;
22257
22258 if (unlikely(in_interrupt()))
22259 return __memcpy(to, from, len);
22260 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22261 kernel_fpu_begin();
22262
22263 __asm__ __volatile__ (
22264 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22265 - " prefetch 64(%0)\n"
22266 - " prefetch 128(%0)\n"
22267 - " prefetch 192(%0)\n"
22268 - " prefetch 256(%0)\n"
22269 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22270 + " prefetch 64(%1)\n"
22271 + " prefetch 128(%1)\n"
22272 + " prefetch 192(%1)\n"
22273 + " prefetch 256(%1)\n"
22274 "2: \n"
22275 ".section .fixup, \"ax\"\n"
22276 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22277 + "3: \n"
22278 +
22279 +#ifdef CONFIG_PAX_KERNEXEC
22280 + " movl %%cr0, %0\n"
22281 + " movl %0, %%eax\n"
22282 + " andl $0xFFFEFFFF, %%eax\n"
22283 + " movl %%eax, %%cr0\n"
22284 +#endif
22285 +
22286 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22287 +
22288 +#ifdef CONFIG_PAX_KERNEXEC
22289 + " movl %0, %%cr0\n"
22290 +#endif
22291 +
22292 " jmp 2b\n"
22293 ".previous\n"
22294 _ASM_EXTABLE(1b, 3b)
22295 - : : "r" (from));
22296 + : "=&r" (cr0) : "r" (from) : "ax");
22297
22298 for ( ; i > 5; i--) {
22299 __asm__ __volatile__ (
22300 - "1: prefetch 320(%0)\n"
22301 - "2: movq (%0), %%mm0\n"
22302 - " movq 8(%0), %%mm1\n"
22303 - " movq 16(%0), %%mm2\n"
22304 - " movq 24(%0), %%mm3\n"
22305 - " movq %%mm0, (%1)\n"
22306 - " movq %%mm1, 8(%1)\n"
22307 - " movq %%mm2, 16(%1)\n"
22308 - " movq %%mm3, 24(%1)\n"
22309 - " movq 32(%0), %%mm0\n"
22310 - " movq 40(%0), %%mm1\n"
22311 - " movq 48(%0), %%mm2\n"
22312 - " movq 56(%0), %%mm3\n"
22313 - " movq %%mm0, 32(%1)\n"
22314 - " movq %%mm1, 40(%1)\n"
22315 - " movq %%mm2, 48(%1)\n"
22316 - " movq %%mm3, 56(%1)\n"
22317 + "1: prefetch 320(%1)\n"
22318 + "2: movq (%1), %%mm0\n"
22319 + " movq 8(%1), %%mm1\n"
22320 + " movq 16(%1), %%mm2\n"
22321 + " movq 24(%1), %%mm3\n"
22322 + " movq %%mm0, (%2)\n"
22323 + " movq %%mm1, 8(%2)\n"
22324 + " movq %%mm2, 16(%2)\n"
22325 + " movq %%mm3, 24(%2)\n"
22326 + " movq 32(%1), %%mm0\n"
22327 + " movq 40(%1), %%mm1\n"
22328 + " movq 48(%1), %%mm2\n"
22329 + " movq 56(%1), %%mm3\n"
22330 + " movq %%mm0, 32(%2)\n"
22331 + " movq %%mm1, 40(%2)\n"
22332 + " movq %%mm2, 48(%2)\n"
22333 + " movq %%mm3, 56(%2)\n"
22334 ".section .fixup, \"ax\"\n"
22335 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22336 + "3:\n"
22337 +
22338 +#ifdef CONFIG_PAX_KERNEXEC
22339 + " movl %%cr0, %0\n"
22340 + " movl %0, %%eax\n"
22341 + " andl $0xFFFEFFFF, %%eax\n"
22342 + " movl %%eax, %%cr0\n"
22343 +#endif
22344 +
22345 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22346 +
22347 +#ifdef CONFIG_PAX_KERNEXEC
22348 + " movl %0, %%cr0\n"
22349 +#endif
22350 +
22351 " jmp 2b\n"
22352 ".previous\n"
22353 _ASM_EXTABLE(1b, 3b)
22354 - : : "r" (from), "r" (to) : "memory");
22355 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22356
22357 from += 64;
22358 to += 64;
22359 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22360 static void fast_copy_page(void *to, void *from)
22361 {
22362 int i;
22363 + unsigned long cr0;
22364
22365 kernel_fpu_begin();
22366
22367 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22368 * but that is for later. -AV
22369 */
22370 __asm__ __volatile__(
22371 - "1: prefetch (%0)\n"
22372 - " prefetch 64(%0)\n"
22373 - " prefetch 128(%0)\n"
22374 - " prefetch 192(%0)\n"
22375 - " prefetch 256(%0)\n"
22376 + "1: prefetch (%1)\n"
22377 + " prefetch 64(%1)\n"
22378 + " prefetch 128(%1)\n"
22379 + " prefetch 192(%1)\n"
22380 + " prefetch 256(%1)\n"
22381 "2: \n"
22382 ".section .fixup, \"ax\"\n"
22383 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22384 + "3: \n"
22385 +
22386 +#ifdef CONFIG_PAX_KERNEXEC
22387 + " movl %%cr0, %0\n"
22388 + " movl %0, %%eax\n"
22389 + " andl $0xFFFEFFFF, %%eax\n"
22390 + " movl %%eax, %%cr0\n"
22391 +#endif
22392 +
22393 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22394 +
22395 +#ifdef CONFIG_PAX_KERNEXEC
22396 + " movl %0, %%cr0\n"
22397 +#endif
22398 +
22399 " jmp 2b\n"
22400 ".previous\n"
22401 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22402 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22403
22404 for (i = 0; i < (4096-320)/64; i++) {
22405 __asm__ __volatile__ (
22406 - "1: prefetch 320(%0)\n"
22407 - "2: movq (%0), %%mm0\n"
22408 - " movntq %%mm0, (%1)\n"
22409 - " movq 8(%0), %%mm1\n"
22410 - " movntq %%mm1, 8(%1)\n"
22411 - " movq 16(%0), %%mm2\n"
22412 - " movntq %%mm2, 16(%1)\n"
22413 - " movq 24(%0), %%mm3\n"
22414 - " movntq %%mm3, 24(%1)\n"
22415 - " movq 32(%0), %%mm4\n"
22416 - " movntq %%mm4, 32(%1)\n"
22417 - " movq 40(%0), %%mm5\n"
22418 - " movntq %%mm5, 40(%1)\n"
22419 - " movq 48(%0), %%mm6\n"
22420 - " movntq %%mm6, 48(%1)\n"
22421 - " movq 56(%0), %%mm7\n"
22422 - " movntq %%mm7, 56(%1)\n"
22423 + "1: prefetch 320(%1)\n"
22424 + "2: movq (%1), %%mm0\n"
22425 + " movntq %%mm0, (%2)\n"
22426 + " movq 8(%1), %%mm1\n"
22427 + " movntq %%mm1, 8(%2)\n"
22428 + " movq 16(%1), %%mm2\n"
22429 + " movntq %%mm2, 16(%2)\n"
22430 + " movq 24(%1), %%mm3\n"
22431 + " movntq %%mm3, 24(%2)\n"
22432 + " movq 32(%1), %%mm4\n"
22433 + " movntq %%mm4, 32(%2)\n"
22434 + " movq 40(%1), %%mm5\n"
22435 + " movntq %%mm5, 40(%2)\n"
22436 + " movq 48(%1), %%mm6\n"
22437 + " movntq %%mm6, 48(%2)\n"
22438 + " movq 56(%1), %%mm7\n"
22439 + " movntq %%mm7, 56(%2)\n"
22440 ".section .fixup, \"ax\"\n"
22441 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22442 + "3:\n"
22443 +
22444 +#ifdef CONFIG_PAX_KERNEXEC
22445 + " movl %%cr0, %0\n"
22446 + " movl %0, %%eax\n"
22447 + " andl $0xFFFEFFFF, %%eax\n"
22448 + " movl %%eax, %%cr0\n"
22449 +#endif
22450 +
22451 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22452 +
22453 +#ifdef CONFIG_PAX_KERNEXEC
22454 + " movl %0, %%cr0\n"
22455 +#endif
22456 +
22457 " jmp 2b\n"
22458 ".previous\n"
22459 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22460 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22461
22462 from += 64;
22463 to += 64;
22464 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22465 static void fast_copy_page(void *to, void *from)
22466 {
22467 int i;
22468 + unsigned long cr0;
22469
22470 kernel_fpu_begin();
22471
22472 __asm__ __volatile__ (
22473 - "1: prefetch (%0)\n"
22474 - " prefetch 64(%0)\n"
22475 - " prefetch 128(%0)\n"
22476 - " prefetch 192(%0)\n"
22477 - " prefetch 256(%0)\n"
22478 + "1: prefetch (%1)\n"
22479 + " prefetch 64(%1)\n"
22480 + " prefetch 128(%1)\n"
22481 + " prefetch 192(%1)\n"
22482 + " prefetch 256(%1)\n"
22483 "2: \n"
22484 ".section .fixup, \"ax\"\n"
22485 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22486 + "3: \n"
22487 +
22488 +#ifdef CONFIG_PAX_KERNEXEC
22489 + " movl %%cr0, %0\n"
22490 + " movl %0, %%eax\n"
22491 + " andl $0xFFFEFFFF, %%eax\n"
22492 + " movl %%eax, %%cr0\n"
22493 +#endif
22494 +
22495 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22496 +
22497 +#ifdef CONFIG_PAX_KERNEXEC
22498 + " movl %0, %%cr0\n"
22499 +#endif
22500 +
22501 " jmp 2b\n"
22502 ".previous\n"
22503 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22504 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22505
22506 for (i = 0; i < 4096/64; i++) {
22507 __asm__ __volatile__ (
22508 - "1: prefetch 320(%0)\n"
22509 - "2: movq (%0), %%mm0\n"
22510 - " movq 8(%0), %%mm1\n"
22511 - " movq 16(%0), %%mm2\n"
22512 - " movq 24(%0), %%mm3\n"
22513 - " movq %%mm0, (%1)\n"
22514 - " movq %%mm1, 8(%1)\n"
22515 - " movq %%mm2, 16(%1)\n"
22516 - " movq %%mm3, 24(%1)\n"
22517 - " movq 32(%0), %%mm0\n"
22518 - " movq 40(%0), %%mm1\n"
22519 - " movq 48(%0), %%mm2\n"
22520 - " movq 56(%0), %%mm3\n"
22521 - " movq %%mm0, 32(%1)\n"
22522 - " movq %%mm1, 40(%1)\n"
22523 - " movq %%mm2, 48(%1)\n"
22524 - " movq %%mm3, 56(%1)\n"
22525 + "1: prefetch 320(%1)\n"
22526 + "2: movq (%1), %%mm0\n"
22527 + " movq 8(%1), %%mm1\n"
22528 + " movq 16(%1), %%mm2\n"
22529 + " movq 24(%1), %%mm3\n"
22530 + " movq %%mm0, (%2)\n"
22531 + " movq %%mm1, 8(%2)\n"
22532 + " movq %%mm2, 16(%2)\n"
22533 + " movq %%mm3, 24(%2)\n"
22534 + " movq 32(%1), %%mm0\n"
22535 + " movq 40(%1), %%mm1\n"
22536 + " movq 48(%1), %%mm2\n"
22537 + " movq 56(%1), %%mm3\n"
22538 + " movq %%mm0, 32(%2)\n"
22539 + " movq %%mm1, 40(%2)\n"
22540 + " movq %%mm2, 48(%2)\n"
22541 + " movq %%mm3, 56(%2)\n"
22542 ".section .fixup, \"ax\"\n"
22543 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22544 + "3:\n"
22545 +
22546 +#ifdef CONFIG_PAX_KERNEXEC
22547 + " movl %%cr0, %0\n"
22548 + " movl %0, %%eax\n"
22549 + " andl $0xFFFEFFFF, %%eax\n"
22550 + " movl %%eax, %%cr0\n"
22551 +#endif
22552 +
22553 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22554 +
22555 +#ifdef CONFIG_PAX_KERNEXEC
22556 + " movl %0, %%cr0\n"
22557 +#endif
22558 +
22559 " jmp 2b\n"
22560 ".previous\n"
22561 _ASM_EXTABLE(1b, 3b)
22562 - : : "r" (from), "r" (to) : "memory");
22563 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22564
22565 from += 64;
22566 to += 64;
22567 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22568 index f6d13ee..aca5f0b 100644
22569 --- a/arch/x86/lib/msr-reg.S
22570 +++ b/arch/x86/lib/msr-reg.S
22571 @@ -3,6 +3,7 @@
22572 #include <asm/dwarf2.h>
22573 #include <asm/asm.h>
22574 #include <asm/msr.h>
22575 +#include <asm/alternative-asm.h>
22576
22577 #ifdef CONFIG_X86_64
22578 /*
22579 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
22580 CFI_STARTPROC
22581 pushq_cfi %rbx
22582 pushq_cfi %rbp
22583 - movq %rdi, %r10 /* Save pointer */
22584 + movq %rdi, %r9 /* Save pointer */
22585 xorl %r11d, %r11d /* Return value */
22586 movl (%rdi), %eax
22587 movl 4(%rdi), %ecx
22588 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
22589 movl 28(%rdi), %edi
22590 CFI_REMEMBER_STATE
22591 1: \op
22592 -2: movl %eax, (%r10)
22593 +2: movl %eax, (%r9)
22594 movl %r11d, %eax /* Return value */
22595 - movl %ecx, 4(%r10)
22596 - movl %edx, 8(%r10)
22597 - movl %ebx, 12(%r10)
22598 - movl %ebp, 20(%r10)
22599 - movl %esi, 24(%r10)
22600 - movl %edi, 28(%r10)
22601 + movl %ecx, 4(%r9)
22602 + movl %edx, 8(%r9)
22603 + movl %ebx, 12(%r9)
22604 + movl %ebp, 20(%r9)
22605 + movl %esi, 24(%r9)
22606 + movl %edi, 28(%r9)
22607 popq_cfi %rbp
22608 popq_cfi %rbx
22609 + pax_force_retaddr
22610 ret
22611 3:
22612 CFI_RESTORE_STATE
22613 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22614 index 7f951c8..ebd573a 100644
22615 --- a/arch/x86/lib/putuser.S
22616 +++ b/arch/x86/lib/putuser.S
22617 @@ -15,7 +15,9 @@
22618 #include <asm/thread_info.h>
22619 #include <asm/errno.h>
22620 #include <asm/asm.h>
22621 -
22622 +#include <asm/segment.h>
22623 +#include <asm/pgtable.h>
22624 +#include <asm/alternative-asm.h>
22625
22626 /*
22627 * __put_user_X
22628 @@ -29,52 +31,119 @@
22629 * as they get called from within inline assembly.
22630 */
22631
22632 -#define ENTER CFI_STARTPROC ; \
22633 - GET_THREAD_INFO(%_ASM_BX)
22634 -#define EXIT ret ; \
22635 +#define ENTER CFI_STARTPROC
22636 +#define EXIT pax_force_retaddr; ret ; \
22637 CFI_ENDPROC
22638
22639 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22640 +#define _DEST %_ASM_CX,%_ASM_BX
22641 +#else
22642 +#define _DEST %_ASM_CX
22643 +#endif
22644 +
22645 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22646 +#define __copyuser_seg gs;
22647 +#else
22648 +#define __copyuser_seg
22649 +#endif
22650 +
22651 .text
22652 ENTRY(__put_user_1)
22653 ENTER
22654 +
22655 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22656 + GET_THREAD_INFO(%_ASM_BX)
22657 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22658 jae bad_put_user
22659 -1: movb %al,(%_ASM_CX)
22660 +
22661 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22662 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22663 + cmp %_ASM_BX,%_ASM_CX
22664 + jb 1234f
22665 + xor %ebx,%ebx
22666 +1234:
22667 +#endif
22668 +
22669 +#endif
22670 +
22671 +1: __copyuser_seg movb %al,(_DEST)
22672 xor %eax,%eax
22673 EXIT
22674 ENDPROC(__put_user_1)
22675
22676 ENTRY(__put_user_2)
22677 ENTER
22678 +
22679 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22680 + GET_THREAD_INFO(%_ASM_BX)
22681 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22682 sub $1,%_ASM_BX
22683 cmp %_ASM_BX,%_ASM_CX
22684 jae bad_put_user
22685 -2: movw %ax,(%_ASM_CX)
22686 +
22687 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22688 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22689 + cmp %_ASM_BX,%_ASM_CX
22690 + jb 1234f
22691 + xor %ebx,%ebx
22692 +1234:
22693 +#endif
22694 +
22695 +#endif
22696 +
22697 +2: __copyuser_seg movw %ax,(_DEST)
22698 xor %eax,%eax
22699 EXIT
22700 ENDPROC(__put_user_2)
22701
22702 ENTRY(__put_user_4)
22703 ENTER
22704 +
22705 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22706 + GET_THREAD_INFO(%_ASM_BX)
22707 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22708 sub $3,%_ASM_BX
22709 cmp %_ASM_BX,%_ASM_CX
22710 jae bad_put_user
22711 -3: movl %eax,(%_ASM_CX)
22712 +
22713 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22714 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22715 + cmp %_ASM_BX,%_ASM_CX
22716 + jb 1234f
22717 + xor %ebx,%ebx
22718 +1234:
22719 +#endif
22720 +
22721 +#endif
22722 +
22723 +3: __copyuser_seg movl %eax,(_DEST)
22724 xor %eax,%eax
22725 EXIT
22726 ENDPROC(__put_user_4)
22727
22728 ENTRY(__put_user_8)
22729 ENTER
22730 +
22731 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22732 + GET_THREAD_INFO(%_ASM_BX)
22733 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22734 sub $7,%_ASM_BX
22735 cmp %_ASM_BX,%_ASM_CX
22736 jae bad_put_user
22737 -4: mov %_ASM_AX,(%_ASM_CX)
22738 +
22739 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22740 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22741 + cmp %_ASM_BX,%_ASM_CX
22742 + jb 1234f
22743 + xor %ebx,%ebx
22744 +1234:
22745 +#endif
22746 +
22747 +#endif
22748 +
22749 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22750 #ifdef CONFIG_X86_32
22751 -5: movl %edx,4(%_ASM_CX)
22752 +5: __copyuser_seg movl %edx,4(_DEST)
22753 #endif
22754 xor %eax,%eax
22755 EXIT
22756 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22757 index 1cad221..de671ee 100644
22758 --- a/arch/x86/lib/rwlock.S
22759 +++ b/arch/x86/lib/rwlock.S
22760 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22761 FRAME
22762 0: LOCK_PREFIX
22763 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22764 +
22765 +#ifdef CONFIG_PAX_REFCOUNT
22766 + jno 1234f
22767 + LOCK_PREFIX
22768 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22769 + int $4
22770 +1234:
22771 + _ASM_EXTABLE(1234b, 1234b)
22772 +#endif
22773 +
22774 1: rep; nop
22775 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22776 jne 1b
22777 LOCK_PREFIX
22778 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22779 +
22780 +#ifdef CONFIG_PAX_REFCOUNT
22781 + jno 1234f
22782 + LOCK_PREFIX
22783 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22784 + int $4
22785 +1234:
22786 + _ASM_EXTABLE(1234b, 1234b)
22787 +#endif
22788 +
22789 jnz 0b
22790 ENDFRAME
22791 + pax_force_retaddr
22792 ret
22793 CFI_ENDPROC
22794 END(__write_lock_failed)
22795 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22796 FRAME
22797 0: LOCK_PREFIX
22798 READ_LOCK_SIZE(inc) (%__lock_ptr)
22799 +
22800 +#ifdef CONFIG_PAX_REFCOUNT
22801 + jno 1234f
22802 + LOCK_PREFIX
22803 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22804 + int $4
22805 +1234:
22806 + _ASM_EXTABLE(1234b, 1234b)
22807 +#endif
22808 +
22809 1: rep; nop
22810 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22811 js 1b
22812 LOCK_PREFIX
22813 READ_LOCK_SIZE(dec) (%__lock_ptr)
22814 +
22815 +#ifdef CONFIG_PAX_REFCOUNT
22816 + jno 1234f
22817 + LOCK_PREFIX
22818 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22819 + int $4
22820 +1234:
22821 + _ASM_EXTABLE(1234b, 1234b)
22822 +#endif
22823 +
22824 js 0b
22825 ENDFRAME
22826 + pax_force_retaddr
22827 ret
22828 CFI_ENDPROC
22829 END(__read_lock_failed)
22830 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22831 index 5dff5f0..cadebf4 100644
22832 --- a/arch/x86/lib/rwsem.S
22833 +++ b/arch/x86/lib/rwsem.S
22834 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22835 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22836 CFI_RESTORE __ASM_REG(dx)
22837 restore_common_regs
22838 + pax_force_retaddr
22839 ret
22840 CFI_ENDPROC
22841 ENDPROC(call_rwsem_down_read_failed)
22842 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22843 movq %rax,%rdi
22844 call rwsem_down_write_failed
22845 restore_common_regs
22846 + pax_force_retaddr
22847 ret
22848 CFI_ENDPROC
22849 ENDPROC(call_rwsem_down_write_failed)
22850 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22851 movq %rax,%rdi
22852 call rwsem_wake
22853 restore_common_regs
22854 -1: ret
22855 +1: pax_force_retaddr
22856 + ret
22857 CFI_ENDPROC
22858 ENDPROC(call_rwsem_wake)
22859
22860 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22861 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22862 CFI_RESTORE __ASM_REG(dx)
22863 restore_common_regs
22864 + pax_force_retaddr
22865 ret
22866 CFI_ENDPROC
22867 ENDPROC(call_rwsem_downgrade_wake)
22868 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22869 index a63efd6..ccecad8 100644
22870 --- a/arch/x86/lib/thunk_64.S
22871 +++ b/arch/x86/lib/thunk_64.S
22872 @@ -8,6 +8,7 @@
22873 #include <linux/linkage.h>
22874 #include <asm/dwarf2.h>
22875 #include <asm/calling.h>
22876 +#include <asm/alternative-asm.h>
22877
22878 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22879 .macro THUNK name, func, put_ret_addr_in_rdi=0
22880 @@ -41,5 +42,6 @@
22881 SAVE_ARGS
22882 restore:
22883 RESTORE_ARGS
22884 + pax_force_retaddr
22885 ret
22886 CFI_ENDPROC
22887 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22888 index 1781b2f..90368dd 100644
22889 --- a/arch/x86/lib/usercopy_32.c
22890 +++ b/arch/x86/lib/usercopy_32.c
22891 @@ -42,10 +42,12 @@ do { \
22892 int __d0; \
22893 might_fault(); \
22894 __asm__ __volatile__( \
22895 + __COPYUSER_SET_ES \
22896 "0: rep; stosl\n" \
22897 " movl %2,%0\n" \
22898 "1: rep; stosb\n" \
22899 "2:\n" \
22900 + __COPYUSER_RESTORE_ES \
22901 ".section .fixup,\"ax\"\n" \
22902 "3: lea 0(%2,%0,4),%0\n" \
22903 " jmp 2b\n" \
22904 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22905
22906 #ifdef CONFIG_X86_INTEL_USERCOPY
22907 static unsigned long
22908 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22909 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22910 {
22911 int d0, d1;
22912 __asm__ __volatile__(
22913 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22914 " .align 2,0x90\n"
22915 "3: movl 0(%4), %%eax\n"
22916 "4: movl 4(%4), %%edx\n"
22917 - "5: movl %%eax, 0(%3)\n"
22918 - "6: movl %%edx, 4(%3)\n"
22919 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22920 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22921 "7: movl 8(%4), %%eax\n"
22922 "8: movl 12(%4),%%edx\n"
22923 - "9: movl %%eax, 8(%3)\n"
22924 - "10: movl %%edx, 12(%3)\n"
22925 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22926 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22927 "11: movl 16(%4), %%eax\n"
22928 "12: movl 20(%4), %%edx\n"
22929 - "13: movl %%eax, 16(%3)\n"
22930 - "14: movl %%edx, 20(%3)\n"
22931 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22932 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22933 "15: movl 24(%4), %%eax\n"
22934 "16: movl 28(%4), %%edx\n"
22935 - "17: movl %%eax, 24(%3)\n"
22936 - "18: movl %%edx, 28(%3)\n"
22937 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22938 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22939 "19: movl 32(%4), %%eax\n"
22940 "20: movl 36(%4), %%edx\n"
22941 - "21: movl %%eax, 32(%3)\n"
22942 - "22: movl %%edx, 36(%3)\n"
22943 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22944 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22945 "23: movl 40(%4), %%eax\n"
22946 "24: movl 44(%4), %%edx\n"
22947 - "25: movl %%eax, 40(%3)\n"
22948 - "26: movl %%edx, 44(%3)\n"
22949 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22950 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22951 "27: movl 48(%4), %%eax\n"
22952 "28: movl 52(%4), %%edx\n"
22953 - "29: movl %%eax, 48(%3)\n"
22954 - "30: movl %%edx, 52(%3)\n"
22955 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22956 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22957 "31: movl 56(%4), %%eax\n"
22958 "32: movl 60(%4), %%edx\n"
22959 - "33: movl %%eax, 56(%3)\n"
22960 - "34: movl %%edx, 60(%3)\n"
22961 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22962 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22963 " addl $-64, %0\n"
22964 " addl $64, %4\n"
22965 " addl $64, %3\n"
22966 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22967 " shrl $2, %0\n"
22968 " andl $3, %%eax\n"
22969 " cld\n"
22970 + __COPYUSER_SET_ES
22971 "99: rep; movsl\n"
22972 "36: movl %%eax, %0\n"
22973 "37: rep; movsb\n"
22974 "100:\n"
22975 + __COPYUSER_RESTORE_ES
22976 ".section .fixup,\"ax\"\n"
22977 "101: lea 0(%%eax,%0,4),%0\n"
22978 " jmp 100b\n"
22979 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22980 }
22981
22982 static unsigned long
22983 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22984 +{
22985 + int d0, d1;
22986 + __asm__ __volatile__(
22987 + " .align 2,0x90\n"
22988 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22989 + " cmpl $67, %0\n"
22990 + " jbe 3f\n"
22991 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22992 + " .align 2,0x90\n"
22993 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22994 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22995 + "5: movl %%eax, 0(%3)\n"
22996 + "6: movl %%edx, 4(%3)\n"
22997 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22998 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22999 + "9: movl %%eax, 8(%3)\n"
23000 + "10: movl %%edx, 12(%3)\n"
23001 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
23002 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
23003 + "13: movl %%eax, 16(%3)\n"
23004 + "14: movl %%edx, 20(%3)\n"
23005 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
23006 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
23007 + "17: movl %%eax, 24(%3)\n"
23008 + "18: movl %%edx, 28(%3)\n"
23009 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
23010 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
23011 + "21: movl %%eax, 32(%3)\n"
23012 + "22: movl %%edx, 36(%3)\n"
23013 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
23014 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
23015 + "25: movl %%eax, 40(%3)\n"
23016 + "26: movl %%edx, 44(%3)\n"
23017 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
23018 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
23019 + "29: movl %%eax, 48(%3)\n"
23020 + "30: movl %%edx, 52(%3)\n"
23021 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
23022 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
23023 + "33: movl %%eax, 56(%3)\n"
23024 + "34: movl %%edx, 60(%3)\n"
23025 + " addl $-64, %0\n"
23026 + " addl $64, %4\n"
23027 + " addl $64, %3\n"
23028 + " cmpl $63, %0\n"
23029 + " ja 1b\n"
23030 + "35: movl %0, %%eax\n"
23031 + " shrl $2, %0\n"
23032 + " andl $3, %%eax\n"
23033 + " cld\n"
23034 + "99: rep; "__copyuser_seg" movsl\n"
23035 + "36: movl %%eax, %0\n"
23036 + "37: rep; "__copyuser_seg" movsb\n"
23037 + "100:\n"
23038 + ".section .fixup,\"ax\"\n"
23039 + "101: lea 0(%%eax,%0,4),%0\n"
23040 + " jmp 100b\n"
23041 + ".previous\n"
23042 + _ASM_EXTABLE(1b,100b)
23043 + _ASM_EXTABLE(2b,100b)
23044 + _ASM_EXTABLE(3b,100b)
23045 + _ASM_EXTABLE(4b,100b)
23046 + _ASM_EXTABLE(5b,100b)
23047 + _ASM_EXTABLE(6b,100b)
23048 + _ASM_EXTABLE(7b,100b)
23049 + _ASM_EXTABLE(8b,100b)
23050 + _ASM_EXTABLE(9b,100b)
23051 + _ASM_EXTABLE(10b,100b)
23052 + _ASM_EXTABLE(11b,100b)
23053 + _ASM_EXTABLE(12b,100b)
23054 + _ASM_EXTABLE(13b,100b)
23055 + _ASM_EXTABLE(14b,100b)
23056 + _ASM_EXTABLE(15b,100b)
23057 + _ASM_EXTABLE(16b,100b)
23058 + _ASM_EXTABLE(17b,100b)
23059 + _ASM_EXTABLE(18b,100b)
23060 + _ASM_EXTABLE(19b,100b)
23061 + _ASM_EXTABLE(20b,100b)
23062 + _ASM_EXTABLE(21b,100b)
23063 + _ASM_EXTABLE(22b,100b)
23064 + _ASM_EXTABLE(23b,100b)
23065 + _ASM_EXTABLE(24b,100b)
23066 + _ASM_EXTABLE(25b,100b)
23067 + _ASM_EXTABLE(26b,100b)
23068 + _ASM_EXTABLE(27b,100b)
23069 + _ASM_EXTABLE(28b,100b)
23070 + _ASM_EXTABLE(29b,100b)
23071 + _ASM_EXTABLE(30b,100b)
23072 + _ASM_EXTABLE(31b,100b)
23073 + _ASM_EXTABLE(32b,100b)
23074 + _ASM_EXTABLE(33b,100b)
23075 + _ASM_EXTABLE(34b,100b)
23076 + _ASM_EXTABLE(35b,100b)
23077 + _ASM_EXTABLE(36b,100b)
23078 + _ASM_EXTABLE(37b,100b)
23079 + _ASM_EXTABLE(99b,101b)
23080 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23081 + : "1"(to), "2"(from), "0"(size)
23082 + : "eax", "edx", "memory");
23083 + return size;
23084 +}
23085 +
23086 +static unsigned long __size_overflow(3)
23087 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23088 {
23089 int d0, d1;
23090 __asm__ __volatile__(
23091 " .align 2,0x90\n"
23092 - "0: movl 32(%4), %%eax\n"
23093 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23094 " cmpl $67, %0\n"
23095 " jbe 2f\n"
23096 - "1: movl 64(%4), %%eax\n"
23097 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23098 " .align 2,0x90\n"
23099 - "2: movl 0(%4), %%eax\n"
23100 - "21: movl 4(%4), %%edx\n"
23101 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23102 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23103 " movl %%eax, 0(%3)\n"
23104 " movl %%edx, 4(%3)\n"
23105 - "3: movl 8(%4), %%eax\n"
23106 - "31: movl 12(%4),%%edx\n"
23107 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23108 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23109 " movl %%eax, 8(%3)\n"
23110 " movl %%edx, 12(%3)\n"
23111 - "4: movl 16(%4), %%eax\n"
23112 - "41: movl 20(%4), %%edx\n"
23113 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23114 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23115 " movl %%eax, 16(%3)\n"
23116 " movl %%edx, 20(%3)\n"
23117 - "10: movl 24(%4), %%eax\n"
23118 - "51: movl 28(%4), %%edx\n"
23119 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23120 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23121 " movl %%eax, 24(%3)\n"
23122 " movl %%edx, 28(%3)\n"
23123 - "11: movl 32(%4), %%eax\n"
23124 - "61: movl 36(%4), %%edx\n"
23125 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23126 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23127 " movl %%eax, 32(%3)\n"
23128 " movl %%edx, 36(%3)\n"
23129 - "12: movl 40(%4), %%eax\n"
23130 - "71: movl 44(%4), %%edx\n"
23131 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23132 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23133 " movl %%eax, 40(%3)\n"
23134 " movl %%edx, 44(%3)\n"
23135 - "13: movl 48(%4), %%eax\n"
23136 - "81: movl 52(%4), %%edx\n"
23137 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23138 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23139 " movl %%eax, 48(%3)\n"
23140 " movl %%edx, 52(%3)\n"
23141 - "14: movl 56(%4), %%eax\n"
23142 - "91: movl 60(%4), %%edx\n"
23143 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23144 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23145 " movl %%eax, 56(%3)\n"
23146 " movl %%edx, 60(%3)\n"
23147 " addl $-64, %0\n"
23148 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23149 " shrl $2, %0\n"
23150 " andl $3, %%eax\n"
23151 " cld\n"
23152 - "6: rep; movsl\n"
23153 + "6: rep; "__copyuser_seg" movsl\n"
23154 " movl %%eax,%0\n"
23155 - "7: rep; movsb\n"
23156 + "7: rep; "__copyuser_seg" movsb\n"
23157 "8:\n"
23158 ".section .fixup,\"ax\"\n"
23159 "9: lea 0(%%eax,%0,4),%0\n"
23160 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23161 * hyoshiok@miraclelinux.com
23162 */
23163
23164 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23165 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23166 const void __user *from, unsigned long size)
23167 {
23168 int d0, d1;
23169
23170 __asm__ __volatile__(
23171 " .align 2,0x90\n"
23172 - "0: movl 32(%4), %%eax\n"
23173 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23174 " cmpl $67, %0\n"
23175 " jbe 2f\n"
23176 - "1: movl 64(%4), %%eax\n"
23177 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23178 " .align 2,0x90\n"
23179 - "2: movl 0(%4), %%eax\n"
23180 - "21: movl 4(%4), %%edx\n"
23181 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23182 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23183 " movnti %%eax, 0(%3)\n"
23184 " movnti %%edx, 4(%3)\n"
23185 - "3: movl 8(%4), %%eax\n"
23186 - "31: movl 12(%4),%%edx\n"
23187 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23188 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23189 " movnti %%eax, 8(%3)\n"
23190 " movnti %%edx, 12(%3)\n"
23191 - "4: movl 16(%4), %%eax\n"
23192 - "41: movl 20(%4), %%edx\n"
23193 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23194 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23195 " movnti %%eax, 16(%3)\n"
23196 " movnti %%edx, 20(%3)\n"
23197 - "10: movl 24(%4), %%eax\n"
23198 - "51: movl 28(%4), %%edx\n"
23199 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23200 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23201 " movnti %%eax, 24(%3)\n"
23202 " movnti %%edx, 28(%3)\n"
23203 - "11: movl 32(%4), %%eax\n"
23204 - "61: movl 36(%4), %%edx\n"
23205 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23206 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23207 " movnti %%eax, 32(%3)\n"
23208 " movnti %%edx, 36(%3)\n"
23209 - "12: movl 40(%4), %%eax\n"
23210 - "71: movl 44(%4), %%edx\n"
23211 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23212 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23213 " movnti %%eax, 40(%3)\n"
23214 " movnti %%edx, 44(%3)\n"
23215 - "13: movl 48(%4), %%eax\n"
23216 - "81: movl 52(%4), %%edx\n"
23217 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23218 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23219 " movnti %%eax, 48(%3)\n"
23220 " movnti %%edx, 52(%3)\n"
23221 - "14: movl 56(%4), %%eax\n"
23222 - "91: movl 60(%4), %%edx\n"
23223 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23224 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23225 " movnti %%eax, 56(%3)\n"
23226 " movnti %%edx, 60(%3)\n"
23227 " addl $-64, %0\n"
23228 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23229 " shrl $2, %0\n"
23230 " andl $3, %%eax\n"
23231 " cld\n"
23232 - "6: rep; movsl\n"
23233 + "6: rep; "__copyuser_seg" movsl\n"
23234 " movl %%eax,%0\n"
23235 - "7: rep; movsb\n"
23236 + "7: rep; "__copyuser_seg" movsb\n"
23237 "8:\n"
23238 ".section .fixup,\"ax\"\n"
23239 "9: lea 0(%%eax,%0,4),%0\n"
23240 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23241 return size;
23242 }
23243
23244 -static unsigned long __copy_user_intel_nocache(void *to,
23245 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23246 const void __user *from, unsigned long size)
23247 {
23248 int d0, d1;
23249
23250 __asm__ __volatile__(
23251 " .align 2,0x90\n"
23252 - "0: movl 32(%4), %%eax\n"
23253 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23254 " cmpl $67, %0\n"
23255 " jbe 2f\n"
23256 - "1: movl 64(%4), %%eax\n"
23257 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23258 " .align 2,0x90\n"
23259 - "2: movl 0(%4), %%eax\n"
23260 - "21: movl 4(%4), %%edx\n"
23261 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23262 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23263 " movnti %%eax, 0(%3)\n"
23264 " movnti %%edx, 4(%3)\n"
23265 - "3: movl 8(%4), %%eax\n"
23266 - "31: movl 12(%4),%%edx\n"
23267 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23268 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23269 " movnti %%eax, 8(%3)\n"
23270 " movnti %%edx, 12(%3)\n"
23271 - "4: movl 16(%4), %%eax\n"
23272 - "41: movl 20(%4), %%edx\n"
23273 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23274 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23275 " movnti %%eax, 16(%3)\n"
23276 " movnti %%edx, 20(%3)\n"
23277 - "10: movl 24(%4), %%eax\n"
23278 - "51: movl 28(%4), %%edx\n"
23279 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23280 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23281 " movnti %%eax, 24(%3)\n"
23282 " movnti %%edx, 28(%3)\n"
23283 - "11: movl 32(%4), %%eax\n"
23284 - "61: movl 36(%4), %%edx\n"
23285 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23286 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23287 " movnti %%eax, 32(%3)\n"
23288 " movnti %%edx, 36(%3)\n"
23289 - "12: movl 40(%4), %%eax\n"
23290 - "71: movl 44(%4), %%edx\n"
23291 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23292 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23293 " movnti %%eax, 40(%3)\n"
23294 " movnti %%edx, 44(%3)\n"
23295 - "13: movl 48(%4), %%eax\n"
23296 - "81: movl 52(%4), %%edx\n"
23297 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23298 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23299 " movnti %%eax, 48(%3)\n"
23300 " movnti %%edx, 52(%3)\n"
23301 - "14: movl 56(%4), %%eax\n"
23302 - "91: movl 60(%4), %%edx\n"
23303 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23304 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23305 " movnti %%eax, 56(%3)\n"
23306 " movnti %%edx, 60(%3)\n"
23307 " addl $-64, %0\n"
23308 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23309 " shrl $2, %0\n"
23310 " andl $3, %%eax\n"
23311 " cld\n"
23312 - "6: rep; movsl\n"
23313 + "6: rep; "__copyuser_seg" movsl\n"
23314 " movl %%eax,%0\n"
23315 - "7: rep; movsb\n"
23316 + "7: rep; "__copyuser_seg" movsb\n"
23317 "8:\n"
23318 ".section .fixup,\"ax\"\n"
23319 "9: lea 0(%%eax,%0,4),%0\n"
23320 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23321 */
23322 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23323 unsigned long size);
23324 -unsigned long __copy_user_intel(void __user *to, const void *from,
23325 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23326 + unsigned long size);
23327 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23328 unsigned long size);
23329 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23330 const void __user *from, unsigned long size);
23331 #endif /* CONFIG_X86_INTEL_USERCOPY */
23332
23333 /* Generic arbitrary sized copy. */
23334 -#define __copy_user(to, from, size) \
23335 +#define __copy_user(to, from, size, prefix, set, restore) \
23336 do { \
23337 int __d0, __d1, __d2; \
23338 __asm__ __volatile__( \
23339 + set \
23340 " cmp $7,%0\n" \
23341 " jbe 1f\n" \
23342 " movl %1,%0\n" \
23343 " negl %0\n" \
23344 " andl $7,%0\n" \
23345 " subl %0,%3\n" \
23346 - "4: rep; movsb\n" \
23347 + "4: rep; "prefix"movsb\n" \
23348 " movl %3,%0\n" \
23349 " shrl $2,%0\n" \
23350 " andl $3,%3\n" \
23351 " .align 2,0x90\n" \
23352 - "0: rep; movsl\n" \
23353 + "0: rep; "prefix"movsl\n" \
23354 " movl %3,%0\n" \
23355 - "1: rep; movsb\n" \
23356 + "1: rep; "prefix"movsb\n" \
23357 "2:\n" \
23358 + restore \
23359 ".section .fixup,\"ax\"\n" \
23360 "5: addl %3,%0\n" \
23361 " jmp 2b\n" \
23362 @@ -537,14 +649,14 @@ do { \
23363 " negl %0\n" \
23364 " andl $7,%0\n" \
23365 " subl %0,%3\n" \
23366 - "4: rep; movsb\n" \
23367 + "4: rep; "__copyuser_seg"movsb\n" \
23368 " movl %3,%0\n" \
23369 " shrl $2,%0\n" \
23370 " andl $3,%3\n" \
23371 " .align 2,0x90\n" \
23372 - "0: rep; movsl\n" \
23373 + "0: rep; "__copyuser_seg"movsl\n" \
23374 " movl %3,%0\n" \
23375 - "1: rep; movsb\n" \
23376 + "1: rep; "__copyuser_seg"movsb\n" \
23377 "2:\n" \
23378 ".section .fixup,\"ax\"\n" \
23379 "5: addl %3,%0\n" \
23380 @@ -627,9 +739,9 @@ survive:
23381 }
23382 #endif
23383 if (movsl_is_ok(to, from, n))
23384 - __copy_user(to, from, n);
23385 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23386 else
23387 - n = __copy_user_intel(to, from, n);
23388 + n = __generic_copy_to_user_intel(to, from, n);
23389 return n;
23390 }
23391 EXPORT_SYMBOL(__copy_to_user_ll);
23392 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23393 unsigned long n)
23394 {
23395 if (movsl_is_ok(to, from, n))
23396 - __copy_user(to, from, n);
23397 + __copy_user(to, from, n, __copyuser_seg, "", "");
23398 else
23399 - n = __copy_user_intel((void __user *)to,
23400 - (const void *)from, n);
23401 + n = __generic_copy_from_user_intel(to, from, n);
23402 return n;
23403 }
23404 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23405 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23406 if (n > 64 && cpu_has_xmm2)
23407 n = __copy_user_intel_nocache(to, from, n);
23408 else
23409 - __copy_user(to, from, n);
23410 + __copy_user(to, from, n, __copyuser_seg, "", "");
23411 #else
23412 - __copy_user(to, from, n);
23413 + __copy_user(to, from, n, __copyuser_seg, "", "");
23414 #endif
23415 return n;
23416 }
23417 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23418
23419 -/**
23420 - * copy_to_user: - Copy a block of data into user space.
23421 - * @to: Destination address, in user space.
23422 - * @from: Source address, in kernel space.
23423 - * @n: Number of bytes to copy.
23424 - *
23425 - * Context: User context only. This function may sleep.
23426 - *
23427 - * Copy data from kernel space to user space.
23428 - *
23429 - * Returns number of bytes that could not be copied.
23430 - * On success, this will be zero.
23431 - */
23432 -unsigned long
23433 -copy_to_user(void __user *to, const void *from, unsigned long n)
23434 -{
23435 - if (access_ok(VERIFY_WRITE, to, n))
23436 - n = __copy_to_user(to, from, n);
23437 - return n;
23438 -}
23439 -EXPORT_SYMBOL(copy_to_user);
23440 -
23441 -/**
23442 - * copy_from_user: - Copy a block of data from user space.
23443 - * @to: Destination address, in kernel space.
23444 - * @from: Source address, in user space.
23445 - * @n: Number of bytes to copy.
23446 - *
23447 - * Context: User context only. This function may sleep.
23448 - *
23449 - * Copy data from user space to kernel space.
23450 - *
23451 - * Returns number of bytes that could not be copied.
23452 - * On success, this will be zero.
23453 - *
23454 - * If some data could not be copied, this function will pad the copied
23455 - * data to the requested size using zero bytes.
23456 - */
23457 -unsigned long
23458 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23459 -{
23460 - if (access_ok(VERIFY_READ, from, n))
23461 - n = __copy_from_user(to, from, n);
23462 - else
23463 - memset(to, 0, n);
23464 - return n;
23465 -}
23466 -EXPORT_SYMBOL(_copy_from_user);
23467 -
23468 void copy_from_user_overflow(void)
23469 {
23470 WARN(1, "Buffer overflow detected!\n");
23471 }
23472 EXPORT_SYMBOL(copy_from_user_overflow);
23473 +
23474 +void copy_to_user_overflow(void)
23475 +{
23476 + WARN(1, "Buffer overflow detected!\n");
23477 +}
23478 +EXPORT_SYMBOL(copy_to_user_overflow);
23479 +
23480 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23481 +void __set_fs(mm_segment_t x)
23482 +{
23483 + switch (x.seg) {
23484 + case 0:
23485 + loadsegment(gs, 0);
23486 + break;
23487 + case TASK_SIZE_MAX:
23488 + loadsegment(gs, __USER_DS);
23489 + break;
23490 + case -1UL:
23491 + loadsegment(gs, __KERNEL_DS);
23492 + break;
23493 + default:
23494 + BUG();
23495 + }
23496 + return;
23497 +}
23498 +EXPORT_SYMBOL(__set_fs);
23499 +
23500 +void set_fs(mm_segment_t x)
23501 +{
23502 + current_thread_info()->addr_limit = x;
23503 + __set_fs(x);
23504 +}
23505 +EXPORT_SYMBOL(set_fs);
23506 +#endif
23507 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23508 index e5b130b..6690d31 100644
23509 --- a/arch/x86/lib/usercopy_64.c
23510 +++ b/arch/x86/lib/usercopy_64.c
23511 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23512 {
23513 long __d0;
23514 might_fault();
23515 +
23516 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23517 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23518 + addr += PAX_USER_SHADOW_BASE;
23519 +#endif
23520 +
23521 /* no memory constraint because it doesn't change any memory gcc knows
23522 about */
23523 asm volatile(
23524 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23525 }
23526 EXPORT_SYMBOL(clear_user);
23527
23528 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23529 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23530 {
23531 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23532 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23533 - }
23534 - return len;
23535 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23536 +
23537 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23538 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23539 + to += PAX_USER_SHADOW_BASE;
23540 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23541 + from += PAX_USER_SHADOW_BASE;
23542 +#endif
23543 +
23544 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23545 + }
23546 + return len;
23547 }
23548 EXPORT_SYMBOL(copy_in_user);
23549
23550 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23551 * it is not necessary to optimize tail handling.
23552 */
23553 unsigned long
23554 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23555 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23556 {
23557 char c;
23558 unsigned zero_len;
23559 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23560 break;
23561 return len;
23562 }
23563 +
23564 +void copy_from_user_overflow(void)
23565 +{
23566 + WARN(1, "Buffer overflow detected!\n");
23567 +}
23568 +EXPORT_SYMBOL(copy_from_user_overflow);
23569 +
23570 +void copy_to_user_overflow(void)
23571 +{
23572 + WARN(1, "Buffer overflow detected!\n");
23573 +}
23574 +EXPORT_SYMBOL(copy_to_user_overflow);
23575 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23576 index 903ec1e..c4166b2 100644
23577 --- a/arch/x86/mm/extable.c
23578 +++ b/arch/x86/mm/extable.c
23579 @@ -6,12 +6,24 @@
23580 static inline unsigned long
23581 ex_insn_addr(const struct exception_table_entry *x)
23582 {
23583 - return (unsigned long)&x->insn + x->insn;
23584 + unsigned long reloc = 0;
23585 +
23586 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23587 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23588 +#endif
23589 +
23590 + return (unsigned long)&x->insn + x->insn + reloc;
23591 }
23592 static inline unsigned long
23593 ex_fixup_addr(const struct exception_table_entry *x)
23594 {
23595 - return (unsigned long)&x->fixup + x->fixup;
23596 + unsigned long reloc = 0;
23597 +
23598 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23599 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23600 +#endif
23601 +
23602 + return (unsigned long)&x->fixup + x->fixup + reloc;
23603 }
23604
23605 int fixup_exception(struct pt_regs *regs)
23606 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23607 unsigned long new_ip;
23608
23609 #ifdef CONFIG_PNPBIOS
23610 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23611 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23612 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23613 extern u32 pnp_bios_is_utter_crap;
23614 pnp_bios_is_utter_crap = 1;
23615 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23616 i += 4;
23617 p->fixup -= i;
23618 i += 4;
23619 +
23620 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23621 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23622 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23623 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23624 +#endif
23625 +
23626 }
23627 }
23628
23629 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23630 index 76dcd9d..e9dffde 100644
23631 --- a/arch/x86/mm/fault.c
23632 +++ b/arch/x86/mm/fault.c
23633 @@ -13,11 +13,18 @@
23634 #include <linux/perf_event.h> /* perf_sw_event */
23635 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23636 #include <linux/prefetch.h> /* prefetchw */
23637 +#include <linux/unistd.h>
23638 +#include <linux/compiler.h>
23639
23640 #include <asm/traps.h> /* dotraplinkage, ... */
23641 #include <asm/pgalloc.h> /* pgd_*(), ... */
23642 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23643 #include <asm/fixmap.h> /* VSYSCALL_START */
23644 +#include <asm/tlbflush.h>
23645 +
23646 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23647 +#include <asm/stacktrace.h>
23648 +#endif
23649
23650 /*
23651 * Page fault error code bits:
23652 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23653 int ret = 0;
23654
23655 /* kprobe_running() needs smp_processor_id() */
23656 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23657 + if (kprobes_built_in() && !user_mode(regs)) {
23658 preempt_disable();
23659 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23660 ret = 1;
23661 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23662 return !instr_lo || (instr_lo>>1) == 1;
23663 case 0x00:
23664 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23665 - if (probe_kernel_address(instr, opcode))
23666 + if (user_mode(regs)) {
23667 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23668 + return 0;
23669 + } else if (probe_kernel_address(instr, opcode))
23670 return 0;
23671
23672 *prefetch = (instr_lo == 0xF) &&
23673 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23674 while (instr < max_instr) {
23675 unsigned char opcode;
23676
23677 - if (probe_kernel_address(instr, opcode))
23678 + if (user_mode(regs)) {
23679 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23680 + break;
23681 + } else if (probe_kernel_address(instr, opcode))
23682 break;
23683
23684 instr++;
23685 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23686 force_sig_info(si_signo, &info, tsk);
23687 }
23688
23689 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23690 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23691 +#endif
23692 +
23693 +#ifdef CONFIG_PAX_EMUTRAMP
23694 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23695 +#endif
23696 +
23697 +#ifdef CONFIG_PAX_PAGEEXEC
23698 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23699 +{
23700 + pgd_t *pgd;
23701 + pud_t *pud;
23702 + pmd_t *pmd;
23703 +
23704 + pgd = pgd_offset(mm, address);
23705 + if (!pgd_present(*pgd))
23706 + return NULL;
23707 + pud = pud_offset(pgd, address);
23708 + if (!pud_present(*pud))
23709 + return NULL;
23710 + pmd = pmd_offset(pud, address);
23711 + if (!pmd_present(*pmd))
23712 + return NULL;
23713 + return pmd;
23714 +}
23715 +#endif
23716 +
23717 DEFINE_SPINLOCK(pgd_lock);
23718 LIST_HEAD(pgd_list);
23719
23720 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23721 for (address = VMALLOC_START & PMD_MASK;
23722 address >= TASK_SIZE && address < FIXADDR_TOP;
23723 address += PMD_SIZE) {
23724 +
23725 +#ifdef CONFIG_PAX_PER_CPU_PGD
23726 + unsigned long cpu;
23727 +#else
23728 struct page *page;
23729 +#endif
23730
23731 spin_lock(&pgd_lock);
23732 +
23733 +#ifdef CONFIG_PAX_PER_CPU_PGD
23734 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23735 + pgd_t *pgd = get_cpu_pgd(cpu);
23736 + pmd_t *ret;
23737 +#else
23738 list_for_each_entry(page, &pgd_list, lru) {
23739 + pgd_t *pgd = page_address(page);
23740 spinlock_t *pgt_lock;
23741 pmd_t *ret;
23742
23743 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23744 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23745
23746 spin_lock(pgt_lock);
23747 - ret = vmalloc_sync_one(page_address(page), address);
23748 +#endif
23749 +
23750 + ret = vmalloc_sync_one(pgd, address);
23751 +
23752 +#ifndef CONFIG_PAX_PER_CPU_PGD
23753 spin_unlock(pgt_lock);
23754 +#endif
23755
23756 if (!ret)
23757 break;
23758 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23759 * an interrupt in the middle of a task switch..
23760 */
23761 pgd_paddr = read_cr3();
23762 +
23763 +#ifdef CONFIG_PAX_PER_CPU_PGD
23764 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23765 +#endif
23766 +
23767 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23768 if (!pmd_k)
23769 return -1;
23770 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23771 * happen within a race in page table update. In the later
23772 * case just flush:
23773 */
23774 +
23775 +#ifdef CONFIG_PAX_PER_CPU_PGD
23776 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23777 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23778 +#else
23779 pgd = pgd_offset(current->active_mm, address);
23780 +#endif
23781 +
23782 pgd_ref = pgd_offset_k(address);
23783 if (pgd_none(*pgd_ref))
23784 return -1;
23785 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23786 static int is_errata100(struct pt_regs *regs, unsigned long address)
23787 {
23788 #ifdef CONFIG_X86_64
23789 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23790 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23791 return 1;
23792 #endif
23793 return 0;
23794 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23795 }
23796
23797 static const char nx_warning[] = KERN_CRIT
23798 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23799 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23800
23801 static void
23802 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23803 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23804 if (!oops_may_print())
23805 return;
23806
23807 - if (error_code & PF_INSTR) {
23808 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23809 unsigned int level;
23810
23811 pte_t *pte = lookup_address(address, &level);
23812
23813 if (pte && pte_present(*pte) && !pte_exec(*pte))
23814 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23815 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23816 }
23817
23818 +#ifdef CONFIG_PAX_KERNEXEC
23819 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23820 + if (current->signal->curr_ip)
23821 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23822 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23823 + else
23824 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23825 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23826 + }
23827 +#endif
23828 +
23829 printk(KERN_ALERT "BUG: unable to handle kernel ");
23830 if (address < PAGE_SIZE)
23831 printk(KERN_CONT "NULL pointer dereference");
23832 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23833 }
23834 #endif
23835
23836 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23837 + if (pax_is_fetch_fault(regs, error_code, address)) {
23838 +
23839 +#ifdef CONFIG_PAX_EMUTRAMP
23840 + switch (pax_handle_fetch_fault(regs)) {
23841 + case 2:
23842 + return;
23843 + }
23844 +#endif
23845 +
23846 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23847 + do_group_exit(SIGKILL);
23848 + }
23849 +#endif
23850 +
23851 if (unlikely(show_unhandled_signals))
23852 show_signal_msg(regs, error_code, address, tsk);
23853
23854 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23855 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23856 printk(KERN_ERR
23857 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23858 - tsk->comm, tsk->pid, address);
23859 + tsk->comm, task_pid_nr(tsk), address);
23860 code = BUS_MCEERR_AR;
23861 }
23862 #endif
23863 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23864 return 1;
23865 }
23866
23867 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23868 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23869 +{
23870 + pte_t *pte;
23871 + pmd_t *pmd;
23872 + spinlock_t *ptl;
23873 + unsigned char pte_mask;
23874 +
23875 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23876 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23877 + return 0;
23878 +
23879 + /* PaX: it's our fault, let's handle it if we can */
23880 +
23881 + /* PaX: take a look at read faults before acquiring any locks */
23882 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23883 + /* instruction fetch attempt from a protected page in user mode */
23884 + up_read(&mm->mmap_sem);
23885 +
23886 +#ifdef CONFIG_PAX_EMUTRAMP
23887 + switch (pax_handle_fetch_fault(regs)) {
23888 + case 2:
23889 + return 1;
23890 + }
23891 +#endif
23892 +
23893 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23894 + do_group_exit(SIGKILL);
23895 + }
23896 +
23897 + pmd = pax_get_pmd(mm, address);
23898 + if (unlikely(!pmd))
23899 + return 0;
23900 +
23901 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23902 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23903 + pte_unmap_unlock(pte, ptl);
23904 + return 0;
23905 + }
23906 +
23907 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23908 + /* write attempt to a protected page in user mode */
23909 + pte_unmap_unlock(pte, ptl);
23910 + return 0;
23911 + }
23912 +
23913 +#ifdef CONFIG_SMP
23914 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23915 +#else
23916 + if (likely(address > get_limit(regs->cs)))
23917 +#endif
23918 + {
23919 + set_pte(pte, pte_mkread(*pte));
23920 + __flush_tlb_one(address);
23921 + pte_unmap_unlock(pte, ptl);
23922 + up_read(&mm->mmap_sem);
23923 + return 1;
23924 + }
23925 +
23926 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23927 +
23928 + /*
23929 + * PaX: fill DTLB with user rights and retry
23930 + */
23931 + __asm__ __volatile__ (
23932 + "orb %2,(%1)\n"
23933 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23934 +/*
23935 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23936 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23937 + * page fault when examined during a TLB load attempt. this is true not only
23938 + * for PTEs holding a non-present entry but also present entries that will
23939 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23940 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23941 + * for our target pages since their PTEs are simply not in the TLBs at all.
23942 +
23943 + * the best thing in omitting it is that we gain around 15-20% speed in the
23944 + * fast path of the page fault handler and can get rid of tracing since we
23945 + * can no longer flush unintended entries.
23946 + */
23947 + "invlpg (%0)\n"
23948 +#endif
23949 + __copyuser_seg"testb $0,(%0)\n"
23950 + "xorb %3,(%1)\n"
23951 + :
23952 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23953 + : "memory", "cc");
23954 + pte_unmap_unlock(pte, ptl);
23955 + up_read(&mm->mmap_sem);
23956 + return 1;
23957 +}
23958 +#endif
23959 +
23960 /*
23961 * Handle a spurious fault caused by a stale TLB entry.
23962 *
23963 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23964 static inline int
23965 access_error(unsigned long error_code, struct vm_area_struct *vma)
23966 {
23967 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23968 + return 1;
23969 +
23970 if (error_code & PF_WRITE) {
23971 /* write, present and write, not present: */
23972 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23973 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23974 {
23975 struct vm_area_struct *vma;
23976 struct task_struct *tsk;
23977 - unsigned long address;
23978 struct mm_struct *mm;
23979 int fault;
23980 int write = error_code & PF_WRITE;
23981 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23982 (write ? FAULT_FLAG_WRITE : 0);
23983
23984 - tsk = current;
23985 - mm = tsk->mm;
23986 -
23987 /* Get the faulting address: */
23988 - address = read_cr2();
23989 + unsigned long address = read_cr2();
23990 +
23991 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23992 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23993 + if (!search_exception_tables(regs->ip)) {
23994 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23995 + bad_area_nosemaphore(regs, error_code, address);
23996 + return;
23997 + }
23998 + if (address < PAX_USER_SHADOW_BASE) {
23999 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
24000 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
24001 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
24002 + } else
24003 + address -= PAX_USER_SHADOW_BASE;
24004 + }
24005 +#endif
24006 +
24007 + tsk = current;
24008 + mm = tsk->mm;
24009
24010 /*
24011 * Detect and handle instructions that would cause a page fault for
24012 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
24013 * User-mode registers count as a user access even for any
24014 * potential system fault or CPU buglet:
24015 */
24016 - if (user_mode_vm(regs)) {
24017 + if (user_mode(regs)) {
24018 local_irq_enable();
24019 error_code |= PF_USER;
24020 } else {
24021 @@ -1132,6 +1339,11 @@ retry:
24022 might_sleep();
24023 }
24024
24025 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
24026 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
24027 + return;
24028 +#endif
24029 +
24030 vma = find_vma(mm, address);
24031 if (unlikely(!vma)) {
24032 bad_area(regs, error_code, address);
24033 @@ -1143,18 +1355,24 @@ retry:
24034 bad_area(regs, error_code, address);
24035 return;
24036 }
24037 - if (error_code & PF_USER) {
24038 - /*
24039 - * Accessing the stack below %sp is always a bug.
24040 - * The large cushion allows instructions like enter
24041 - * and pusha to work. ("enter $65535, $31" pushes
24042 - * 32 pointers and then decrements %sp by 65535.)
24043 - */
24044 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24045 - bad_area(regs, error_code, address);
24046 - return;
24047 - }
24048 + /*
24049 + * Accessing the stack below %sp is always a bug.
24050 + * The large cushion allows instructions like enter
24051 + * and pusha to work. ("enter $65535, $31" pushes
24052 + * 32 pointers and then decrements %sp by 65535.)
24053 + */
24054 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24055 + bad_area(regs, error_code, address);
24056 + return;
24057 }
24058 +
24059 +#ifdef CONFIG_PAX_SEGMEXEC
24060 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24061 + bad_area(regs, error_code, address);
24062 + return;
24063 + }
24064 +#endif
24065 +
24066 if (unlikely(expand_stack(vma, address))) {
24067 bad_area(regs, error_code, address);
24068 return;
24069 @@ -1209,3 +1427,292 @@ good_area:
24070
24071 up_read(&mm->mmap_sem);
24072 }
24073 +
24074 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24075 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24076 +{
24077 + struct mm_struct *mm = current->mm;
24078 + unsigned long ip = regs->ip;
24079 +
24080 + if (v8086_mode(regs))
24081 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24082 +
24083 +#ifdef CONFIG_PAX_PAGEEXEC
24084 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24085 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24086 + return true;
24087 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24088 + return true;
24089 + return false;
24090 + }
24091 +#endif
24092 +
24093 +#ifdef CONFIG_PAX_SEGMEXEC
24094 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24095 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24096 + return true;
24097 + return false;
24098 + }
24099 +#endif
24100 +
24101 + return false;
24102 +}
24103 +#endif
24104 +
24105 +#ifdef CONFIG_PAX_EMUTRAMP
24106 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24107 +{
24108 + int err;
24109 +
24110 + do { /* PaX: libffi trampoline emulation */
24111 + unsigned char mov, jmp;
24112 + unsigned int addr1, addr2;
24113 +
24114 +#ifdef CONFIG_X86_64
24115 + if ((regs->ip + 9) >> 32)
24116 + break;
24117 +#endif
24118 +
24119 + err = get_user(mov, (unsigned char __user *)regs->ip);
24120 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24121 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24122 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24123 +
24124 + if (err)
24125 + break;
24126 +
24127 + if (mov == 0xB8 && jmp == 0xE9) {
24128 + regs->ax = addr1;
24129 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24130 + return 2;
24131 + }
24132 + } while (0);
24133 +
24134 + do { /* PaX: gcc trampoline emulation #1 */
24135 + unsigned char mov1, mov2;
24136 + unsigned short jmp;
24137 + unsigned int addr1, addr2;
24138 +
24139 +#ifdef CONFIG_X86_64
24140 + if ((regs->ip + 11) >> 32)
24141 + break;
24142 +#endif
24143 +
24144 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24145 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24146 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24147 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24148 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24149 +
24150 + if (err)
24151 + break;
24152 +
24153 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24154 + regs->cx = addr1;
24155 + regs->ax = addr2;
24156 + regs->ip = addr2;
24157 + return 2;
24158 + }
24159 + } while (0);
24160 +
24161 + do { /* PaX: gcc trampoline emulation #2 */
24162 + unsigned char mov, jmp;
24163 + unsigned int addr1, addr2;
24164 +
24165 +#ifdef CONFIG_X86_64
24166 + if ((regs->ip + 9) >> 32)
24167 + break;
24168 +#endif
24169 +
24170 + err = get_user(mov, (unsigned char __user *)regs->ip);
24171 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24172 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24173 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24174 +
24175 + if (err)
24176 + break;
24177 +
24178 + if (mov == 0xB9 && jmp == 0xE9) {
24179 + regs->cx = addr1;
24180 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24181 + return 2;
24182 + }
24183 + } while (0);
24184 +
24185 + return 1; /* PaX in action */
24186 +}
24187 +
24188 +#ifdef CONFIG_X86_64
24189 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24190 +{
24191 + int err;
24192 +
24193 + do { /* PaX: libffi trampoline emulation */
24194 + unsigned short mov1, mov2, jmp1;
24195 + unsigned char stcclc, jmp2;
24196 + unsigned long addr1, addr2;
24197 +
24198 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24199 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24200 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24201 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24202 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24203 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24204 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24205 +
24206 + if (err)
24207 + break;
24208 +
24209 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24210 + regs->r11 = addr1;
24211 + regs->r10 = addr2;
24212 + if (stcclc == 0xF8)
24213 + regs->flags &= ~X86_EFLAGS_CF;
24214 + else
24215 + regs->flags |= X86_EFLAGS_CF;
24216 + regs->ip = addr1;
24217 + return 2;
24218 + }
24219 + } while (0);
24220 +
24221 + do { /* PaX: gcc trampoline emulation #1 */
24222 + unsigned short mov1, mov2, jmp1;
24223 + unsigned char jmp2;
24224 + unsigned int addr1;
24225 + unsigned long addr2;
24226 +
24227 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24228 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24229 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24230 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24231 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24232 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24233 +
24234 + if (err)
24235 + break;
24236 +
24237 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24238 + regs->r11 = addr1;
24239 + regs->r10 = addr2;
24240 + regs->ip = addr1;
24241 + return 2;
24242 + }
24243 + } while (0);
24244 +
24245 + do { /* PaX: gcc trampoline emulation #2 */
24246 + unsigned short mov1, mov2, jmp1;
24247 + unsigned char jmp2;
24248 + unsigned long addr1, addr2;
24249 +
24250 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24251 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24252 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24253 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24254 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24255 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24256 +
24257 + if (err)
24258 + break;
24259 +
24260 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24261 + regs->r11 = addr1;
24262 + regs->r10 = addr2;
24263 + regs->ip = addr1;
24264 + return 2;
24265 + }
24266 + } while (0);
24267 +
24268 + return 1; /* PaX in action */
24269 +}
24270 +#endif
24271 +
24272 +/*
24273 + * PaX: decide what to do with offenders (regs->ip = fault address)
24274 + *
24275 + * returns 1 when task should be killed
24276 + * 2 when gcc trampoline was detected
24277 + */
24278 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24279 +{
24280 + if (v8086_mode(regs))
24281 + return 1;
24282 +
24283 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24284 + return 1;
24285 +
24286 +#ifdef CONFIG_X86_32
24287 + return pax_handle_fetch_fault_32(regs);
24288 +#else
24289 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24290 + return pax_handle_fetch_fault_32(regs);
24291 + else
24292 + return pax_handle_fetch_fault_64(regs);
24293 +#endif
24294 +}
24295 +#endif
24296 +
24297 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24298 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24299 +{
24300 + long i;
24301 +
24302 + printk(KERN_ERR "PAX: bytes at PC: ");
24303 + for (i = 0; i < 20; i++) {
24304 + unsigned char c;
24305 + if (get_user(c, (unsigned char __force_user *)pc+i))
24306 + printk(KERN_CONT "?? ");
24307 + else
24308 + printk(KERN_CONT "%02x ", c);
24309 + }
24310 + printk("\n");
24311 +
24312 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24313 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24314 + unsigned long c;
24315 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24316 +#ifdef CONFIG_X86_32
24317 + printk(KERN_CONT "???????? ");
24318 +#else
24319 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24320 + printk(KERN_CONT "???????? ???????? ");
24321 + else
24322 + printk(KERN_CONT "???????????????? ");
24323 +#endif
24324 + } else {
24325 +#ifdef CONFIG_X86_64
24326 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24327 + printk(KERN_CONT "%08x ", (unsigned int)c);
24328 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24329 + } else
24330 +#endif
24331 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24332 + }
24333 + }
24334 + printk("\n");
24335 +}
24336 +#endif
24337 +
24338 +/**
24339 + * probe_kernel_write(): safely attempt to write to a location
24340 + * @dst: address to write to
24341 + * @src: pointer to the data that shall be written
24342 + * @size: size of the data chunk
24343 + *
24344 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24345 + * happens, handle that and return -EFAULT.
24346 + */
24347 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24348 +{
24349 + long ret;
24350 + mm_segment_t old_fs = get_fs();
24351 +
24352 + set_fs(KERNEL_DS);
24353 + pagefault_disable();
24354 + pax_open_kernel();
24355 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24356 + pax_close_kernel();
24357 + pagefault_enable();
24358 + set_fs(old_fs);
24359 +
24360 + return ret ? -EFAULT : 0;
24361 +}
24362 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24363 index dd74e46..7d26398 100644
24364 --- a/arch/x86/mm/gup.c
24365 +++ b/arch/x86/mm/gup.c
24366 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24367 addr = start;
24368 len = (unsigned long) nr_pages << PAGE_SHIFT;
24369 end = start + len;
24370 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24371 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24372 (void __user *)start, len)))
24373 return 0;
24374
24375 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24376 index 6f31ee5..8ee4164 100644
24377 --- a/arch/x86/mm/highmem_32.c
24378 +++ b/arch/x86/mm/highmem_32.c
24379 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24380 idx = type + KM_TYPE_NR*smp_processor_id();
24381 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24382 BUG_ON(!pte_none(*(kmap_pte-idx)));
24383 +
24384 + pax_open_kernel();
24385 set_pte(kmap_pte-idx, mk_pte(page, prot));
24386 + pax_close_kernel();
24387 +
24388 arch_flush_lazy_mmu_mode();
24389
24390 return (void *)vaddr;
24391 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24392 index b91e485..d00e7c9 100644
24393 --- a/arch/x86/mm/hugetlbpage.c
24394 +++ b/arch/x86/mm/hugetlbpage.c
24395 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24396 struct hstate *h = hstate_file(file);
24397 struct mm_struct *mm = current->mm;
24398 struct vm_area_struct *vma;
24399 - unsigned long start_addr;
24400 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24401 +
24402 +#ifdef CONFIG_PAX_SEGMEXEC
24403 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24404 + pax_task_size = SEGMEXEC_TASK_SIZE;
24405 +#endif
24406 +
24407 + pax_task_size -= PAGE_SIZE;
24408
24409 if (len > mm->cached_hole_size) {
24410 - start_addr = mm->free_area_cache;
24411 + start_addr = mm->free_area_cache;
24412 } else {
24413 - start_addr = TASK_UNMAPPED_BASE;
24414 - mm->cached_hole_size = 0;
24415 + start_addr = mm->mmap_base;
24416 + mm->cached_hole_size = 0;
24417 }
24418
24419 full_search:
24420 @@ -291,26 +298,27 @@ full_search:
24421
24422 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24423 /* At this point: (!vma || addr < vma->vm_end). */
24424 - if (TASK_SIZE - len < addr) {
24425 + if (pax_task_size - len < addr) {
24426 /*
24427 * Start a new search - just in case we missed
24428 * some holes.
24429 */
24430 - if (start_addr != TASK_UNMAPPED_BASE) {
24431 - start_addr = TASK_UNMAPPED_BASE;
24432 + if (start_addr != mm->mmap_base) {
24433 + start_addr = mm->mmap_base;
24434 mm->cached_hole_size = 0;
24435 goto full_search;
24436 }
24437 return -ENOMEM;
24438 }
24439 - if (!vma || addr + len <= vma->vm_start) {
24440 - mm->free_area_cache = addr + len;
24441 - return addr;
24442 - }
24443 + if (check_heap_stack_gap(vma, addr, len))
24444 + break;
24445 if (addr + mm->cached_hole_size < vma->vm_start)
24446 mm->cached_hole_size = vma->vm_start - addr;
24447 addr = ALIGN(vma->vm_end, huge_page_size(h));
24448 }
24449 +
24450 + mm->free_area_cache = addr + len;
24451 + return addr;
24452 }
24453
24454 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24455 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24456 struct mm_struct *mm = current->mm;
24457 struct vm_area_struct *vma;
24458 unsigned long base = mm->mmap_base;
24459 - unsigned long addr = addr0;
24460 + unsigned long addr;
24461 unsigned long largest_hole = mm->cached_hole_size;
24462 - unsigned long start_addr;
24463
24464 /* don't allow allocations above current base */
24465 if (mm->free_area_cache > base)
24466 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24467 largest_hole = 0;
24468 mm->free_area_cache = base;
24469 }
24470 -try_again:
24471 - start_addr = mm->free_area_cache;
24472
24473 /* make sure it can fit in the remaining address space */
24474 if (mm->free_area_cache < len)
24475 goto fail;
24476
24477 /* either no address requested or can't fit in requested address hole */
24478 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24479 + addr = mm->free_area_cache - len;
24480 do {
24481 + addr &= huge_page_mask(h);
24482 /*
24483 * Lookup failure means no vma is above this address,
24484 * i.e. return with success:
24485 @@ -351,10 +357,10 @@ try_again:
24486 if (!vma)
24487 return addr;
24488
24489 - if (addr + len <= vma->vm_start) {
24490 + if (check_heap_stack_gap(vma, addr, len)) {
24491 /* remember the address as a hint for next time */
24492 - mm->cached_hole_size = largest_hole;
24493 - return (mm->free_area_cache = addr);
24494 + mm->cached_hole_size = largest_hole;
24495 + return (mm->free_area_cache = addr);
24496 } else if (mm->free_area_cache == vma->vm_end) {
24497 /* pull free_area_cache down to the first hole */
24498 mm->free_area_cache = vma->vm_start;
24499 @@ -363,29 +369,34 @@ try_again:
24500
24501 /* remember the largest hole we saw so far */
24502 if (addr + largest_hole < vma->vm_start)
24503 - largest_hole = vma->vm_start - addr;
24504 + largest_hole = vma->vm_start - addr;
24505
24506 /* try just below the current vma->vm_start */
24507 - addr = (vma->vm_start - len) & huge_page_mask(h);
24508 - } while (len <= vma->vm_start);
24509 + addr = skip_heap_stack_gap(vma, len);
24510 + } while (!IS_ERR_VALUE(addr));
24511
24512 fail:
24513 /*
24514 - * if hint left us with no space for the requested
24515 - * mapping then try again:
24516 - */
24517 - if (start_addr != base) {
24518 - mm->free_area_cache = base;
24519 - largest_hole = 0;
24520 - goto try_again;
24521 - }
24522 - /*
24523 * A failed mmap() very likely causes application failure,
24524 * so fall back to the bottom-up function here. This scenario
24525 * can happen with large stack limits and large mmap()
24526 * allocations.
24527 */
24528 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24529 +
24530 +#ifdef CONFIG_PAX_SEGMEXEC
24531 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24532 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24533 + else
24534 +#endif
24535 +
24536 + mm->mmap_base = TASK_UNMAPPED_BASE;
24537 +
24538 +#ifdef CONFIG_PAX_RANDMMAP
24539 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24540 + mm->mmap_base += mm->delta_mmap;
24541 +#endif
24542 +
24543 + mm->free_area_cache = mm->mmap_base;
24544 mm->cached_hole_size = ~0UL;
24545 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24546 len, pgoff, flags);
24547 @@ -393,6 +404,7 @@ fail:
24548 /*
24549 * Restore the topdown base:
24550 */
24551 + mm->mmap_base = base;
24552 mm->free_area_cache = base;
24553 mm->cached_hole_size = ~0UL;
24554
24555 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24556 struct hstate *h = hstate_file(file);
24557 struct mm_struct *mm = current->mm;
24558 struct vm_area_struct *vma;
24559 + unsigned long pax_task_size = TASK_SIZE;
24560
24561 if (len & ~huge_page_mask(h))
24562 return -EINVAL;
24563 - if (len > TASK_SIZE)
24564 +
24565 +#ifdef CONFIG_PAX_SEGMEXEC
24566 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24567 + pax_task_size = SEGMEXEC_TASK_SIZE;
24568 +#endif
24569 +
24570 + pax_task_size -= PAGE_SIZE;
24571 +
24572 + if (len > pax_task_size)
24573 return -ENOMEM;
24574
24575 if (flags & MAP_FIXED) {
24576 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24577 if (addr) {
24578 addr = ALIGN(addr, huge_page_size(h));
24579 vma = find_vma(mm, addr);
24580 - if (TASK_SIZE - len >= addr &&
24581 - (!vma || addr + len <= vma->vm_start))
24582 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24583 return addr;
24584 }
24585 if (mm->get_unmapped_area == arch_get_unmapped_area)
24586 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24587 index ab1f6a9..e16d764 100644
24588 --- a/arch/x86/mm/init.c
24589 +++ b/arch/x86/mm/init.c
24590 @@ -16,6 +16,8 @@
24591 #include <asm/tlb.h>
24592 #include <asm/proto.h>
24593 #include <asm/dma.h> /* for MAX_DMA_PFN */
24594 +#include <asm/desc.h>
24595 +#include <asm/bios_ebda.h>
24596
24597 unsigned long __initdata pgt_buf_start;
24598 unsigned long __meminitdata pgt_buf_end;
24599 @@ -38,7 +40,7 @@ struct map_range {
24600 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24601 int use_pse, int use_gbpages)
24602 {
24603 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24604 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24605 phys_addr_t base;
24606
24607 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24608 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24609 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24610 * mmio resources as well as potential bios/acpi data regions.
24611 */
24612 +
24613 +#ifdef CONFIG_GRKERNSEC_KMEM
24614 +static unsigned int ebda_start __read_only;
24615 +static unsigned int ebda_end __read_only;
24616 +#endif
24617 +
24618 int devmem_is_allowed(unsigned long pagenr)
24619 {
24620 - if (pagenr < 256)
24621 +#ifdef CONFIG_GRKERNSEC_KMEM
24622 + /* allow BDA */
24623 + if (!pagenr)
24624 return 1;
24625 + /* allow EBDA */
24626 + if (pagenr >= ebda_start && pagenr < ebda_end)
24627 + return 1;
24628 +#else
24629 + if (!pagenr)
24630 + return 1;
24631 +#ifdef CONFIG_VM86
24632 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24633 + return 1;
24634 +#endif
24635 +#endif
24636 +
24637 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24638 + return 1;
24639 +#ifdef CONFIG_GRKERNSEC_KMEM
24640 + /* throw out everything else below 1MB */
24641 + if (pagenr <= 256)
24642 + return 0;
24643 +#endif
24644 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24645 return 0;
24646 if (!page_is_ram(pagenr))
24647 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24648 #endif
24649 }
24650
24651 +#ifdef CONFIG_GRKERNSEC_KMEM
24652 +static inline void gr_init_ebda(void)
24653 +{
24654 + unsigned int ebda_addr;
24655 + unsigned int ebda_size = 0;
24656 +
24657 + ebda_addr = get_bios_ebda();
24658 + if (ebda_addr) {
24659 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24660 + ebda_size <<= 10;
24661 + }
24662 + if (ebda_addr && ebda_size) {
24663 + ebda_start = ebda_addr >> PAGE_SHIFT;
24664 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24665 + } else {
24666 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24667 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24668 + }
24669 +}
24670 +#else
24671 +static inline void gr_init_ebda(void) { }
24672 +#endif
24673 +
24674 void free_initmem(void)
24675 {
24676 +#ifdef CONFIG_PAX_KERNEXEC
24677 +#ifdef CONFIG_X86_32
24678 + /* PaX: limit KERNEL_CS to actual size */
24679 + unsigned long addr, limit;
24680 + struct desc_struct d;
24681 + int cpu;
24682 +#else
24683 + pgd_t *pgd;
24684 + pud_t *pud;
24685 + pmd_t *pmd;
24686 + unsigned long addr, end;
24687 +#endif
24688 +#endif
24689 +
24690 + gr_init_ebda();
24691 +
24692 +#ifdef CONFIG_PAX_KERNEXEC
24693 +#ifdef CONFIG_X86_32
24694 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24695 + limit = (limit - 1UL) >> PAGE_SHIFT;
24696 +
24697 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24698 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24699 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24700 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24701 + }
24702 +
24703 + /* PaX: make KERNEL_CS read-only */
24704 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24705 + if (!paravirt_enabled())
24706 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24707 +/*
24708 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24709 + pgd = pgd_offset_k(addr);
24710 + pud = pud_offset(pgd, addr);
24711 + pmd = pmd_offset(pud, addr);
24712 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24713 + }
24714 +*/
24715 +#ifdef CONFIG_X86_PAE
24716 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24717 +/*
24718 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24719 + pgd = pgd_offset_k(addr);
24720 + pud = pud_offset(pgd, addr);
24721 + pmd = pmd_offset(pud, addr);
24722 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24723 + }
24724 +*/
24725 +#endif
24726 +
24727 +#ifdef CONFIG_MODULES
24728 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24729 +#endif
24730 +
24731 +#else
24732 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24733 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24734 + pgd = pgd_offset_k(addr);
24735 + pud = pud_offset(pgd, addr);
24736 + pmd = pmd_offset(pud, addr);
24737 + if (!pmd_present(*pmd))
24738 + continue;
24739 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24740 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24741 + else
24742 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24743 + }
24744 +
24745 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24746 + end = addr + KERNEL_IMAGE_SIZE;
24747 + for (; addr < end; addr += PMD_SIZE) {
24748 + pgd = pgd_offset_k(addr);
24749 + pud = pud_offset(pgd, addr);
24750 + pmd = pmd_offset(pud, addr);
24751 + if (!pmd_present(*pmd))
24752 + continue;
24753 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24754 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24755 + }
24756 +#endif
24757 +
24758 + flush_tlb_all();
24759 +#endif
24760 +
24761 free_init_pages("unused kernel memory",
24762 (unsigned long)(&__init_begin),
24763 (unsigned long)(&__init_end));
24764 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24765 index 575d86f..4987469 100644
24766 --- a/arch/x86/mm/init_32.c
24767 +++ b/arch/x86/mm/init_32.c
24768 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24769 }
24770
24771 /*
24772 - * Creates a middle page table and puts a pointer to it in the
24773 - * given global directory entry. This only returns the gd entry
24774 - * in non-PAE compilation mode, since the middle layer is folded.
24775 - */
24776 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24777 -{
24778 - pud_t *pud;
24779 - pmd_t *pmd_table;
24780 -
24781 -#ifdef CONFIG_X86_PAE
24782 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24783 - if (after_bootmem)
24784 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24785 - else
24786 - pmd_table = (pmd_t *)alloc_low_page();
24787 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24788 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24789 - pud = pud_offset(pgd, 0);
24790 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24791 -
24792 - return pmd_table;
24793 - }
24794 -#endif
24795 - pud = pud_offset(pgd, 0);
24796 - pmd_table = pmd_offset(pud, 0);
24797 -
24798 - return pmd_table;
24799 -}
24800 -
24801 -/*
24802 * Create a page table and place a pointer to it in a middle page
24803 * directory entry:
24804 */
24805 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24806 page_table = (pte_t *)alloc_low_page();
24807
24808 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24809 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24810 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24811 +#else
24812 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24813 +#endif
24814 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24815 }
24816
24817 return pte_offset_kernel(pmd, 0);
24818 }
24819
24820 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24821 +{
24822 + pud_t *pud;
24823 + pmd_t *pmd_table;
24824 +
24825 + pud = pud_offset(pgd, 0);
24826 + pmd_table = pmd_offset(pud, 0);
24827 +
24828 + return pmd_table;
24829 +}
24830 +
24831 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24832 {
24833 int pgd_idx = pgd_index(vaddr);
24834 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24835 int pgd_idx, pmd_idx;
24836 unsigned long vaddr;
24837 pgd_t *pgd;
24838 + pud_t *pud;
24839 pmd_t *pmd;
24840 pte_t *pte = NULL;
24841
24842 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24843 pgd = pgd_base + pgd_idx;
24844
24845 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24846 - pmd = one_md_table_init(pgd);
24847 - pmd = pmd + pmd_index(vaddr);
24848 + pud = pud_offset(pgd, vaddr);
24849 + pmd = pmd_offset(pud, vaddr);
24850 +
24851 +#ifdef CONFIG_X86_PAE
24852 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24853 +#endif
24854 +
24855 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24856 pmd++, pmd_idx++) {
24857 pte = page_table_kmap_check(one_page_table_init(pmd),
24858 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24859 }
24860 }
24861
24862 -static inline int is_kernel_text(unsigned long addr)
24863 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24864 {
24865 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24866 - return 1;
24867 - return 0;
24868 + if ((start > ktla_ktva((unsigned long)_etext) ||
24869 + end <= ktla_ktva((unsigned long)_stext)) &&
24870 + (start > ktla_ktva((unsigned long)_einittext) ||
24871 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24872 +
24873 +#ifdef CONFIG_ACPI_SLEEP
24874 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24875 +#endif
24876 +
24877 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24878 + return 0;
24879 + return 1;
24880 }
24881
24882 /*
24883 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24884 unsigned long last_map_addr = end;
24885 unsigned long start_pfn, end_pfn;
24886 pgd_t *pgd_base = swapper_pg_dir;
24887 - int pgd_idx, pmd_idx, pte_ofs;
24888 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24889 unsigned long pfn;
24890 pgd_t *pgd;
24891 + pud_t *pud;
24892 pmd_t *pmd;
24893 pte_t *pte;
24894 unsigned pages_2m, pages_4k;
24895 @@ -280,8 +281,13 @@ repeat:
24896 pfn = start_pfn;
24897 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24898 pgd = pgd_base + pgd_idx;
24899 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24900 - pmd = one_md_table_init(pgd);
24901 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24902 + pud = pud_offset(pgd, 0);
24903 + pmd = pmd_offset(pud, 0);
24904 +
24905 +#ifdef CONFIG_X86_PAE
24906 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24907 +#endif
24908
24909 if (pfn >= end_pfn)
24910 continue;
24911 @@ -293,14 +299,13 @@ repeat:
24912 #endif
24913 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24914 pmd++, pmd_idx++) {
24915 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24916 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24917
24918 /*
24919 * Map with big pages if possible, otherwise
24920 * create normal page tables:
24921 */
24922 if (use_pse) {
24923 - unsigned int addr2;
24924 pgprot_t prot = PAGE_KERNEL_LARGE;
24925 /*
24926 * first pass will use the same initial
24927 @@ -310,11 +315,7 @@ repeat:
24928 __pgprot(PTE_IDENT_ATTR |
24929 _PAGE_PSE);
24930
24931 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24932 - PAGE_OFFSET + PAGE_SIZE-1;
24933 -
24934 - if (is_kernel_text(addr) ||
24935 - is_kernel_text(addr2))
24936 + if (is_kernel_text(address, address + PMD_SIZE))
24937 prot = PAGE_KERNEL_LARGE_EXEC;
24938
24939 pages_2m++;
24940 @@ -331,7 +332,7 @@ repeat:
24941 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24942 pte += pte_ofs;
24943 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24944 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24945 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24946 pgprot_t prot = PAGE_KERNEL;
24947 /*
24948 * first pass will use the same initial
24949 @@ -339,7 +340,7 @@ repeat:
24950 */
24951 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24952
24953 - if (is_kernel_text(addr))
24954 + if (is_kernel_text(address, address + PAGE_SIZE))
24955 prot = PAGE_KERNEL_EXEC;
24956
24957 pages_4k++;
24958 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24959
24960 pud = pud_offset(pgd, va);
24961 pmd = pmd_offset(pud, va);
24962 - if (!pmd_present(*pmd))
24963 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24964 break;
24965
24966 pte = pte_offset_kernel(pmd, va);
24967 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24968
24969 static void __init pagetable_init(void)
24970 {
24971 - pgd_t *pgd_base = swapper_pg_dir;
24972 -
24973 - permanent_kmaps_init(pgd_base);
24974 + permanent_kmaps_init(swapper_pg_dir);
24975 }
24976
24977 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24978 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24979 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24980
24981 /* user-defined highmem size */
24982 @@ -734,6 +733,12 @@ void __init mem_init(void)
24983
24984 pci_iommu_alloc();
24985
24986 +#ifdef CONFIG_PAX_PER_CPU_PGD
24987 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24988 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24989 + KERNEL_PGD_PTRS);
24990 +#endif
24991 +
24992 #ifdef CONFIG_FLATMEM
24993 BUG_ON(!mem_map);
24994 #endif
24995 @@ -760,7 +765,7 @@ void __init mem_init(void)
24996 reservedpages++;
24997
24998 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24999 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
25000 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
25001 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
25002
25003 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
25004 @@ -801,10 +806,10 @@ void __init mem_init(void)
25005 ((unsigned long)&__init_end -
25006 (unsigned long)&__init_begin) >> 10,
25007
25008 - (unsigned long)&_etext, (unsigned long)&_edata,
25009 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
25010 + (unsigned long)&_sdata, (unsigned long)&_edata,
25011 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
25012
25013 - (unsigned long)&_text, (unsigned long)&_etext,
25014 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
25015 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
25016
25017 /*
25018 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
25019 if (!kernel_set_to_readonly)
25020 return;
25021
25022 + start = ktla_ktva(start);
25023 pr_debug("Set kernel text: %lx - %lx for read write\n",
25024 start, start+size);
25025
25026 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
25027 if (!kernel_set_to_readonly)
25028 return;
25029
25030 + start = ktla_ktva(start);
25031 pr_debug("Set kernel text: %lx - %lx for read only\n",
25032 start, start+size);
25033
25034 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25035 unsigned long start = PFN_ALIGN(_text);
25036 unsigned long size = PFN_ALIGN(_etext) - start;
25037
25038 + start = ktla_ktva(start);
25039 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25040 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25041 size >> 10);
25042 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25043 index 2b6b4a3..c17210d 100644
25044 --- a/arch/x86/mm/init_64.c
25045 +++ b/arch/x86/mm/init_64.c
25046 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25047 * around without checking the pgd every time.
25048 */
25049
25050 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25051 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25052 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25053
25054 int force_personality32;
25055 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25056
25057 for (address = start; address <= end; address += PGDIR_SIZE) {
25058 const pgd_t *pgd_ref = pgd_offset_k(address);
25059 +
25060 +#ifdef CONFIG_PAX_PER_CPU_PGD
25061 + unsigned long cpu;
25062 +#else
25063 struct page *page;
25064 +#endif
25065
25066 if (pgd_none(*pgd_ref))
25067 continue;
25068
25069 spin_lock(&pgd_lock);
25070 +
25071 +#ifdef CONFIG_PAX_PER_CPU_PGD
25072 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25073 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25074 +#else
25075 list_for_each_entry(page, &pgd_list, lru) {
25076 pgd_t *pgd;
25077 spinlock_t *pgt_lock;
25078 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25079 /* the pgt_lock only for Xen */
25080 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25081 spin_lock(pgt_lock);
25082 +#endif
25083
25084 if (pgd_none(*pgd))
25085 set_pgd(pgd, *pgd_ref);
25086 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25087 BUG_ON(pgd_page_vaddr(*pgd)
25088 != pgd_page_vaddr(*pgd_ref));
25089
25090 +#ifndef CONFIG_PAX_PER_CPU_PGD
25091 spin_unlock(pgt_lock);
25092 +#endif
25093 +
25094 }
25095 spin_unlock(&pgd_lock);
25096 }
25097 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25098 {
25099 if (pgd_none(*pgd)) {
25100 pud_t *pud = (pud_t *)spp_getpage();
25101 - pgd_populate(&init_mm, pgd, pud);
25102 + pgd_populate_kernel(&init_mm, pgd, pud);
25103 if (pud != pud_offset(pgd, 0))
25104 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25105 pud, pud_offset(pgd, 0));
25106 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25107 {
25108 if (pud_none(*pud)) {
25109 pmd_t *pmd = (pmd_t *) spp_getpage();
25110 - pud_populate(&init_mm, pud, pmd);
25111 + pud_populate_kernel(&init_mm, pud, pmd);
25112 if (pmd != pmd_offset(pud, 0))
25113 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25114 pmd, pmd_offset(pud, 0));
25115 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25116 pmd = fill_pmd(pud, vaddr);
25117 pte = fill_pte(pmd, vaddr);
25118
25119 + pax_open_kernel();
25120 set_pte(pte, new_pte);
25121 + pax_close_kernel();
25122
25123 /*
25124 * It's enough to flush this one mapping.
25125 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25126 pgd = pgd_offset_k((unsigned long)__va(phys));
25127 if (pgd_none(*pgd)) {
25128 pud = (pud_t *) spp_getpage();
25129 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25130 - _PAGE_USER));
25131 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25132 }
25133 pud = pud_offset(pgd, (unsigned long)__va(phys));
25134 if (pud_none(*pud)) {
25135 pmd = (pmd_t *) spp_getpage();
25136 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25137 - _PAGE_USER));
25138 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25139 }
25140 pmd = pmd_offset(pud, phys);
25141 BUG_ON(!pmd_none(*pmd));
25142 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25143 if (pfn >= pgt_buf_top)
25144 panic("alloc_low_page: ran out of memory");
25145
25146 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25147 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25148 clear_page(adr);
25149 *phys = pfn * PAGE_SIZE;
25150 return adr;
25151 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25152
25153 phys = __pa(virt);
25154 left = phys & (PAGE_SIZE - 1);
25155 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25156 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25157 adr = (void *)(((unsigned long)adr) | left);
25158
25159 return adr;
25160 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25161 unmap_low_page(pmd);
25162
25163 spin_lock(&init_mm.page_table_lock);
25164 - pud_populate(&init_mm, pud, __va(pmd_phys));
25165 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25166 spin_unlock(&init_mm.page_table_lock);
25167 }
25168 __flush_tlb_all();
25169 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25170 unmap_low_page(pud);
25171
25172 spin_lock(&init_mm.page_table_lock);
25173 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25174 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25175 spin_unlock(&init_mm.page_table_lock);
25176 pgd_changed = true;
25177 }
25178 @@ -686,6 +700,12 @@ void __init mem_init(void)
25179
25180 pci_iommu_alloc();
25181
25182 +#ifdef CONFIG_PAX_PER_CPU_PGD
25183 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25184 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25185 + KERNEL_PGD_PTRS);
25186 +#endif
25187 +
25188 /* clear_bss() already clear the empty_zero_page */
25189
25190 reservedpages = 0;
25191 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25192 static struct vm_area_struct gate_vma = {
25193 .vm_start = VSYSCALL_START,
25194 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25195 - .vm_page_prot = PAGE_READONLY_EXEC,
25196 - .vm_flags = VM_READ | VM_EXEC
25197 + .vm_page_prot = PAGE_READONLY,
25198 + .vm_flags = VM_READ
25199 };
25200
25201 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25202 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25203
25204 const char *arch_vma_name(struct vm_area_struct *vma)
25205 {
25206 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25207 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25208 return "[vdso]";
25209 if (vma == &gate_vma)
25210 return "[vsyscall]";
25211 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25212 index 7b179b4..6bd1777 100644
25213 --- a/arch/x86/mm/iomap_32.c
25214 +++ b/arch/x86/mm/iomap_32.c
25215 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25216 type = kmap_atomic_idx_push();
25217 idx = type + KM_TYPE_NR * smp_processor_id();
25218 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25219 +
25220 + pax_open_kernel();
25221 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25222 + pax_close_kernel();
25223 +
25224 arch_flush_lazy_mmu_mode();
25225
25226 return (void *)vaddr;
25227 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25228 index 78fe3f1..8293b6f 100644
25229 --- a/arch/x86/mm/ioremap.c
25230 +++ b/arch/x86/mm/ioremap.c
25231 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25232 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25233 int is_ram = page_is_ram(pfn);
25234
25235 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25236 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25237 return NULL;
25238 WARN_ON_ONCE(is_ram);
25239 }
25240 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25241
25242 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25243 if (page_is_ram(start >> PAGE_SHIFT))
25244 +#ifdef CONFIG_HIGHMEM
25245 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25246 +#endif
25247 return __va(phys);
25248
25249 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25250 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25251 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25252
25253 static __initdata int after_paging_init;
25254 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25255 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25256
25257 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25258 {
25259 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25260 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25261
25262 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25263 - memset(bm_pte, 0, sizeof(bm_pte));
25264 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25265 + pmd_populate_user(&init_mm, pmd, bm_pte);
25266
25267 /*
25268 * The boot-ioremap range spans multiple pmds, for which
25269 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25270 index d87dd6d..bf3fa66 100644
25271 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25272 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25273 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25274 * memory (e.g. tracked pages)? For now, we need this to avoid
25275 * invoking kmemcheck for PnP BIOS calls.
25276 */
25277 - if (regs->flags & X86_VM_MASK)
25278 + if (v8086_mode(regs))
25279 return false;
25280 - if (regs->cs != __KERNEL_CS)
25281 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25282 return false;
25283
25284 pte = kmemcheck_pte_lookup(address);
25285 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25286 index 845df68..1d8d29f 100644
25287 --- a/arch/x86/mm/mmap.c
25288 +++ b/arch/x86/mm/mmap.c
25289 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25290 * Leave an at least ~128 MB hole with possible stack randomization.
25291 */
25292 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25293 -#define MAX_GAP (TASK_SIZE/6*5)
25294 +#define MAX_GAP (pax_task_size/6*5)
25295
25296 static int mmap_is_legacy(void)
25297 {
25298 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25299 return rnd << PAGE_SHIFT;
25300 }
25301
25302 -static unsigned long mmap_base(void)
25303 +static unsigned long mmap_base(struct mm_struct *mm)
25304 {
25305 unsigned long gap = rlimit(RLIMIT_STACK);
25306 + unsigned long pax_task_size = TASK_SIZE;
25307 +
25308 +#ifdef CONFIG_PAX_SEGMEXEC
25309 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25310 + pax_task_size = SEGMEXEC_TASK_SIZE;
25311 +#endif
25312
25313 if (gap < MIN_GAP)
25314 gap = MIN_GAP;
25315 else if (gap > MAX_GAP)
25316 gap = MAX_GAP;
25317
25318 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25319 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25320 }
25321
25322 /*
25323 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25324 * does, but not when emulating X86_32
25325 */
25326 -static unsigned long mmap_legacy_base(void)
25327 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25328 {
25329 - if (mmap_is_ia32())
25330 + if (mmap_is_ia32()) {
25331 +
25332 +#ifdef CONFIG_PAX_SEGMEXEC
25333 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25334 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25335 + else
25336 +#endif
25337 +
25338 return TASK_UNMAPPED_BASE;
25339 - else
25340 + } else
25341 return TASK_UNMAPPED_BASE + mmap_rnd();
25342 }
25343
25344 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25345 void arch_pick_mmap_layout(struct mm_struct *mm)
25346 {
25347 if (mmap_is_legacy()) {
25348 - mm->mmap_base = mmap_legacy_base();
25349 + mm->mmap_base = mmap_legacy_base(mm);
25350 +
25351 +#ifdef CONFIG_PAX_RANDMMAP
25352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25353 + mm->mmap_base += mm->delta_mmap;
25354 +#endif
25355 +
25356 mm->get_unmapped_area = arch_get_unmapped_area;
25357 mm->unmap_area = arch_unmap_area;
25358 } else {
25359 - mm->mmap_base = mmap_base();
25360 + mm->mmap_base = mmap_base(mm);
25361 +
25362 +#ifdef CONFIG_PAX_RANDMMAP
25363 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25364 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25365 +#endif
25366 +
25367 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25368 mm->unmap_area = arch_unmap_area_topdown;
25369 }
25370 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25371 index dc0b727..dc9d71a 100644
25372 --- a/arch/x86/mm/mmio-mod.c
25373 +++ b/arch/x86/mm/mmio-mod.c
25374 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25375 break;
25376 default:
25377 {
25378 - unsigned char *ip = (unsigned char *)instptr;
25379 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25380 my_trace->opcode = MMIO_UNKNOWN_OP;
25381 my_trace->width = 0;
25382 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25383 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25384 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25385 void __iomem *addr)
25386 {
25387 - static atomic_t next_id;
25388 + static atomic_unchecked_t next_id;
25389 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25390 /* These are page-unaligned. */
25391 struct mmiotrace_map map = {
25392 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25393 .private = trace
25394 },
25395 .phys = offset,
25396 - .id = atomic_inc_return(&next_id)
25397 + .id = atomic_inc_return_unchecked(&next_id)
25398 };
25399 map.map_id = trace->id;
25400
25401 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25402 index b008656..773eac2 100644
25403 --- a/arch/x86/mm/pageattr-test.c
25404 +++ b/arch/x86/mm/pageattr-test.c
25405 @@ -36,7 +36,7 @@ enum {
25406
25407 static int pte_testbit(pte_t pte)
25408 {
25409 - return pte_flags(pte) & _PAGE_UNUSED1;
25410 + return pte_flags(pte) & _PAGE_CPA_TEST;
25411 }
25412
25413 struct split_state {
25414 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25415 index a718e0d..45efc32 100644
25416 --- a/arch/x86/mm/pageattr.c
25417 +++ b/arch/x86/mm/pageattr.c
25418 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25419 */
25420 #ifdef CONFIG_PCI_BIOS
25421 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25422 - pgprot_val(forbidden) |= _PAGE_NX;
25423 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25424 #endif
25425
25426 /*
25427 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25428 * Does not cover __inittext since that is gone later on. On
25429 * 64bit we do not enforce !NX on the low mapping
25430 */
25431 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25432 - pgprot_val(forbidden) |= _PAGE_NX;
25433 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25434 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25435
25436 +#ifdef CONFIG_DEBUG_RODATA
25437 /*
25438 * The .rodata section needs to be read-only. Using the pfn
25439 * catches all aliases.
25440 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25441 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25442 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25443 pgprot_val(forbidden) |= _PAGE_RW;
25444 +#endif
25445
25446 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25447 /*
25448 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25449 }
25450 #endif
25451
25452 +#ifdef CONFIG_PAX_KERNEXEC
25453 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25454 + pgprot_val(forbidden) |= _PAGE_RW;
25455 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25456 + }
25457 +#endif
25458 +
25459 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25460
25461 return prot;
25462 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25463 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25464 {
25465 /* change init_mm */
25466 + pax_open_kernel();
25467 set_pte_atomic(kpte, pte);
25468 +
25469 #ifdef CONFIG_X86_32
25470 if (!SHARED_KERNEL_PMD) {
25471 +
25472 +#ifdef CONFIG_PAX_PER_CPU_PGD
25473 + unsigned long cpu;
25474 +#else
25475 struct page *page;
25476 +#endif
25477
25478 +#ifdef CONFIG_PAX_PER_CPU_PGD
25479 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25480 + pgd_t *pgd = get_cpu_pgd(cpu);
25481 +#else
25482 list_for_each_entry(page, &pgd_list, lru) {
25483 - pgd_t *pgd;
25484 + pgd_t *pgd = (pgd_t *)page_address(page);
25485 +#endif
25486 +
25487 pud_t *pud;
25488 pmd_t *pmd;
25489
25490 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25491 + pgd += pgd_index(address);
25492 pud = pud_offset(pgd, address);
25493 pmd = pmd_offset(pud, address);
25494 set_pte_atomic((pte_t *)pmd, pte);
25495 }
25496 }
25497 #endif
25498 + pax_close_kernel();
25499 }
25500
25501 static int
25502 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25503 index 3d68ef6..7f69136 100644
25504 --- a/arch/x86/mm/pat.c
25505 +++ b/arch/x86/mm/pat.c
25506 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25507
25508 if (!entry) {
25509 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25510 - current->comm, current->pid, start, end - 1);
25511 + current->comm, task_pid_nr(current), start, end - 1);
25512 return -EINVAL;
25513 }
25514
25515 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25516
25517 while (cursor < to) {
25518 if (!devmem_is_allowed(pfn)) {
25519 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25520 - current->comm, from, to - 1);
25521 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25522 + current->comm, from, to - 1, cursor);
25523 return 0;
25524 }
25525 cursor += PAGE_SIZE;
25526 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25527 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25528 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25529 "for [mem %#010Lx-%#010Lx]\n",
25530 - current->comm, current->pid,
25531 + current->comm, task_pid_nr(current),
25532 cattr_name(flags),
25533 base, (unsigned long long)(base + size-1));
25534 return -EINVAL;
25535 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25536 flags = lookup_memtype(paddr);
25537 if (want_flags != flags) {
25538 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25539 - current->comm, current->pid,
25540 + current->comm, task_pid_nr(current),
25541 cattr_name(want_flags),
25542 (unsigned long long)paddr,
25543 (unsigned long long)(paddr + size - 1),
25544 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25545 free_memtype(paddr, paddr + size);
25546 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25547 " for [mem %#010Lx-%#010Lx], got %s\n",
25548 - current->comm, current->pid,
25549 + current->comm, task_pid_nr(current),
25550 cattr_name(want_flags),
25551 (unsigned long long)paddr,
25552 (unsigned long long)(paddr + size - 1),
25553 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25554 index 9f0614d..92ae64a 100644
25555 --- a/arch/x86/mm/pf_in.c
25556 +++ b/arch/x86/mm/pf_in.c
25557 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25558 int i;
25559 enum reason_type rv = OTHERS;
25560
25561 - p = (unsigned char *)ins_addr;
25562 + p = (unsigned char *)ktla_ktva(ins_addr);
25563 p += skip_prefix(p, &prf);
25564 p += get_opcode(p, &opcode);
25565
25566 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25567 struct prefix_bits prf;
25568 int i;
25569
25570 - p = (unsigned char *)ins_addr;
25571 + p = (unsigned char *)ktla_ktva(ins_addr);
25572 p += skip_prefix(p, &prf);
25573 p += get_opcode(p, &opcode);
25574
25575 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25576 struct prefix_bits prf;
25577 int i;
25578
25579 - p = (unsigned char *)ins_addr;
25580 + p = (unsigned char *)ktla_ktva(ins_addr);
25581 p += skip_prefix(p, &prf);
25582 p += get_opcode(p, &opcode);
25583
25584 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25585 struct prefix_bits prf;
25586 int i;
25587
25588 - p = (unsigned char *)ins_addr;
25589 + p = (unsigned char *)ktla_ktva(ins_addr);
25590 p += skip_prefix(p, &prf);
25591 p += get_opcode(p, &opcode);
25592 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25593 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25594 struct prefix_bits prf;
25595 int i;
25596
25597 - p = (unsigned char *)ins_addr;
25598 + p = (unsigned char *)ktla_ktva(ins_addr);
25599 p += skip_prefix(p, &prf);
25600 p += get_opcode(p, &opcode);
25601 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25602 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25603 index 8573b83..4f3ed7e 100644
25604 --- a/arch/x86/mm/pgtable.c
25605 +++ b/arch/x86/mm/pgtable.c
25606 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25607 list_del(&page->lru);
25608 }
25609
25610 -#define UNSHARED_PTRS_PER_PGD \
25611 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25612 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25613 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25614
25615 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25616 +{
25617 + unsigned int count = USER_PGD_PTRS;
25618
25619 + while (count--)
25620 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25621 +}
25622 +#endif
25623 +
25624 +#ifdef CONFIG_PAX_PER_CPU_PGD
25625 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25626 +{
25627 + unsigned int count = USER_PGD_PTRS;
25628 +
25629 + while (count--) {
25630 + pgd_t pgd;
25631 +
25632 +#ifdef CONFIG_X86_64
25633 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25634 +#else
25635 + pgd = *src++;
25636 +#endif
25637 +
25638 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25639 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25640 +#endif
25641 +
25642 + *dst++ = pgd;
25643 + }
25644 +
25645 +}
25646 +#endif
25647 +
25648 +#ifdef CONFIG_X86_64
25649 +#define pxd_t pud_t
25650 +#define pyd_t pgd_t
25651 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25652 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25653 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25654 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25655 +#define PYD_SIZE PGDIR_SIZE
25656 +#else
25657 +#define pxd_t pmd_t
25658 +#define pyd_t pud_t
25659 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25660 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25661 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25662 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25663 +#define PYD_SIZE PUD_SIZE
25664 +#endif
25665 +
25666 +#ifdef CONFIG_PAX_PER_CPU_PGD
25667 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25668 +static inline void pgd_dtor(pgd_t *pgd) {}
25669 +#else
25670 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25671 {
25672 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25673 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25674 pgd_list_del(pgd);
25675 spin_unlock(&pgd_lock);
25676 }
25677 +#endif
25678
25679 /*
25680 * List of all pgd's needed for non-PAE so it can invalidate entries
25681 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25682 * -- wli
25683 */
25684
25685 -#ifdef CONFIG_X86_PAE
25686 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25687 /*
25688 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25689 * updating the top-level pagetable entries to guarantee the
25690 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25691 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25692 * and initialize the kernel pmds here.
25693 */
25694 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25695 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25696
25697 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25698 {
25699 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25700 */
25701 flush_tlb_mm(mm);
25702 }
25703 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25704 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25705 #else /* !CONFIG_X86_PAE */
25706
25707 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25708 -#define PREALLOCATED_PMDS 0
25709 +#define PREALLOCATED_PXDS 0
25710
25711 #endif /* CONFIG_X86_PAE */
25712
25713 -static void free_pmds(pmd_t *pmds[])
25714 +static void free_pxds(pxd_t *pxds[])
25715 {
25716 int i;
25717
25718 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25719 - if (pmds[i])
25720 - free_page((unsigned long)pmds[i]);
25721 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25722 + if (pxds[i])
25723 + free_page((unsigned long)pxds[i]);
25724 }
25725
25726 -static int preallocate_pmds(pmd_t *pmds[])
25727 +static int preallocate_pxds(pxd_t *pxds[])
25728 {
25729 int i;
25730 bool failed = false;
25731
25732 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25733 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25734 - if (pmd == NULL)
25735 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25736 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25737 + if (pxd == NULL)
25738 failed = true;
25739 - pmds[i] = pmd;
25740 + pxds[i] = pxd;
25741 }
25742
25743 if (failed) {
25744 - free_pmds(pmds);
25745 + free_pxds(pxds);
25746 return -ENOMEM;
25747 }
25748
25749 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25750 * preallocate which never got a corresponding vma will need to be
25751 * freed manually.
25752 */
25753 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25754 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25755 {
25756 int i;
25757
25758 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25759 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25760 pgd_t pgd = pgdp[i];
25761
25762 if (pgd_val(pgd) != 0) {
25763 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25764 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25765
25766 - pgdp[i] = native_make_pgd(0);
25767 + set_pgd(pgdp + i, native_make_pgd(0));
25768
25769 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25770 - pmd_free(mm, pmd);
25771 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25772 + pxd_free(mm, pxd);
25773 }
25774 }
25775 }
25776
25777 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25778 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25779 {
25780 - pud_t *pud;
25781 + pyd_t *pyd;
25782 unsigned long addr;
25783 int i;
25784
25785 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25786 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25787 return;
25788
25789 - pud = pud_offset(pgd, 0);
25790 +#ifdef CONFIG_X86_64
25791 + pyd = pyd_offset(mm, 0L);
25792 +#else
25793 + pyd = pyd_offset(pgd, 0L);
25794 +#endif
25795
25796 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25797 - i++, pud++, addr += PUD_SIZE) {
25798 - pmd_t *pmd = pmds[i];
25799 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25800 + i++, pyd++, addr += PYD_SIZE) {
25801 + pxd_t *pxd = pxds[i];
25802
25803 if (i >= KERNEL_PGD_BOUNDARY)
25804 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25805 - sizeof(pmd_t) * PTRS_PER_PMD);
25806 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25807 + sizeof(pxd_t) * PTRS_PER_PMD);
25808
25809 - pud_populate(mm, pud, pmd);
25810 + pyd_populate(mm, pyd, pxd);
25811 }
25812 }
25813
25814 pgd_t *pgd_alloc(struct mm_struct *mm)
25815 {
25816 pgd_t *pgd;
25817 - pmd_t *pmds[PREALLOCATED_PMDS];
25818 + pxd_t *pxds[PREALLOCATED_PXDS];
25819
25820 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25821
25822 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25823
25824 mm->pgd = pgd;
25825
25826 - if (preallocate_pmds(pmds) != 0)
25827 + if (preallocate_pxds(pxds) != 0)
25828 goto out_free_pgd;
25829
25830 if (paravirt_pgd_alloc(mm) != 0)
25831 - goto out_free_pmds;
25832 + goto out_free_pxds;
25833
25834 /*
25835 * Make sure that pre-populating the pmds is atomic with
25836 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25837 spin_lock(&pgd_lock);
25838
25839 pgd_ctor(mm, pgd);
25840 - pgd_prepopulate_pmd(mm, pgd, pmds);
25841 + pgd_prepopulate_pxd(mm, pgd, pxds);
25842
25843 spin_unlock(&pgd_lock);
25844
25845 return pgd;
25846
25847 -out_free_pmds:
25848 - free_pmds(pmds);
25849 +out_free_pxds:
25850 + free_pxds(pxds);
25851 out_free_pgd:
25852 free_page((unsigned long)pgd);
25853 out:
25854 @@ -295,7 +356,7 @@ out:
25855
25856 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25857 {
25858 - pgd_mop_up_pmds(mm, pgd);
25859 + pgd_mop_up_pxds(mm, pgd);
25860 pgd_dtor(pgd);
25861 paravirt_pgd_free(mm, pgd);
25862 free_page((unsigned long)pgd);
25863 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25864 index a69bcb8..19068ab 100644
25865 --- a/arch/x86/mm/pgtable_32.c
25866 +++ b/arch/x86/mm/pgtable_32.c
25867 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25868 return;
25869 }
25870 pte = pte_offset_kernel(pmd, vaddr);
25871 +
25872 + pax_open_kernel();
25873 if (pte_val(pteval))
25874 set_pte_at(&init_mm, vaddr, pte, pteval);
25875 else
25876 pte_clear(&init_mm, vaddr, pte);
25877 + pax_close_kernel();
25878
25879 /*
25880 * It's enough to flush this one mapping.
25881 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25882 index 410531d..0f16030 100644
25883 --- a/arch/x86/mm/setup_nx.c
25884 +++ b/arch/x86/mm/setup_nx.c
25885 @@ -5,8 +5,10 @@
25886 #include <asm/pgtable.h>
25887 #include <asm/proto.h>
25888
25889 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25890 static int disable_nx __cpuinitdata;
25891
25892 +#ifndef CONFIG_PAX_PAGEEXEC
25893 /*
25894 * noexec = on|off
25895 *
25896 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25897 return 0;
25898 }
25899 early_param("noexec", noexec_setup);
25900 +#endif
25901 +
25902 +#endif
25903
25904 void __cpuinit x86_configure_nx(void)
25905 {
25906 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25907 if (cpu_has_nx && !disable_nx)
25908 __supported_pte_mask |= _PAGE_NX;
25909 else
25910 +#endif
25911 __supported_pte_mask &= ~_PAGE_NX;
25912 }
25913
25914 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25915 index 613cd83..3a21f1c 100644
25916 --- a/arch/x86/mm/tlb.c
25917 +++ b/arch/x86/mm/tlb.c
25918 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
25919 BUG();
25920 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25921 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25922 +
25923 +#ifndef CONFIG_PAX_PER_CPU_PGD
25924 load_cr3(swapper_pg_dir);
25925 +#endif
25926 +
25927 }
25928 }
25929 EXPORT_SYMBOL_GPL(leave_mm);
25930 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25931 index 877b9a1..a8ecf42 100644
25932 --- a/arch/x86/net/bpf_jit.S
25933 +++ b/arch/x86/net/bpf_jit.S
25934 @@ -9,6 +9,7 @@
25935 */
25936 #include <linux/linkage.h>
25937 #include <asm/dwarf2.h>
25938 +#include <asm/alternative-asm.h>
25939
25940 /*
25941 * Calling convention :
25942 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25943 jle bpf_slow_path_word
25944 mov (SKBDATA,%rsi),%eax
25945 bswap %eax /* ntohl() */
25946 + pax_force_retaddr
25947 ret
25948
25949 sk_load_half:
25950 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25951 jle bpf_slow_path_half
25952 movzwl (SKBDATA,%rsi),%eax
25953 rol $8,%ax # ntohs()
25954 + pax_force_retaddr
25955 ret
25956
25957 sk_load_byte:
25958 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25959 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25960 jle bpf_slow_path_byte
25961 movzbl (SKBDATA,%rsi),%eax
25962 + pax_force_retaddr
25963 ret
25964
25965 /**
25966 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25967 movzbl (SKBDATA,%rsi),%ebx
25968 and $15,%bl
25969 shl $2,%bl
25970 + pax_force_retaddr
25971 ret
25972
25973 /* rsi contains offset and can be scratched */
25974 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25975 js bpf_error
25976 mov -12(%rbp),%eax
25977 bswap %eax
25978 + pax_force_retaddr
25979 ret
25980
25981 bpf_slow_path_half:
25982 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25983 mov -12(%rbp),%ax
25984 rol $8,%ax
25985 movzwl %ax,%eax
25986 + pax_force_retaddr
25987 ret
25988
25989 bpf_slow_path_byte:
25990 bpf_slow_path_common(1)
25991 js bpf_error
25992 movzbl -12(%rbp),%eax
25993 + pax_force_retaddr
25994 ret
25995
25996 bpf_slow_path_byte_msh:
25997 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25998 and $15,%al
25999 shl $2,%al
26000 xchg %eax,%ebx
26001 + pax_force_retaddr
26002 ret
26003
26004 #define sk_negative_common(SIZE) \
26005 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
26006 sk_negative_common(4)
26007 mov (%rax), %eax
26008 bswap %eax
26009 + pax_force_retaddr
26010 ret
26011
26012 bpf_slow_path_half_neg:
26013 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
26014 mov (%rax),%ax
26015 rol $8,%ax
26016 movzwl %ax,%eax
26017 + pax_force_retaddr
26018 ret
26019
26020 bpf_slow_path_byte_neg:
26021 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
26022 .globl sk_load_byte_negative_offset
26023 sk_negative_common(1)
26024 movzbl (%rax), %eax
26025 + pax_force_retaddr
26026 ret
26027
26028 bpf_slow_path_byte_msh_neg:
26029 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26030 and $15,%al
26031 shl $2,%al
26032 xchg %eax,%ebx
26033 + pax_force_retaddr
26034 ret
26035
26036 bpf_error:
26037 @@ -197,4 +210,5 @@ bpf_error:
26038 xor %eax,%eax
26039 mov -8(%rbp),%rbx
26040 leaveq
26041 + pax_force_retaddr
26042 ret
26043 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26044 index 33643a8..8e44870 100644
26045 --- a/arch/x86/net/bpf_jit_comp.c
26046 +++ b/arch/x86/net/bpf_jit_comp.c
26047 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26048 set_fs(old_fs);
26049 }
26050
26051 +struct bpf_jit_work {
26052 + struct work_struct work;
26053 + void *image;
26054 +};
26055 +
26056 #define CHOOSE_LOAD_FUNC(K, func) \
26057 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26058
26059 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26060 if (addrs == NULL)
26061 return;
26062
26063 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26064 + if (!fp->work)
26065 + goto out;
26066 +
26067 /* Before first pass, make a rough estimation of addrs[]
26068 * each bpf instruction is translated to less than 64 bytes
26069 */
26070 @@ -593,17 +602,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26071 break;
26072 default:
26073 /* hmm, too complex filter, give up with jit compiler */
26074 - goto out;
26075 + goto error;
26076 }
26077 ilen = prog - temp;
26078 if (image) {
26079 if (unlikely(proglen + ilen > oldproglen)) {
26080 pr_err("bpb_jit_compile fatal error\n");
26081 - kfree(addrs);
26082 - module_free(NULL, image);
26083 - return;
26084 + module_free_exec(NULL, image);
26085 + goto error;
26086 }
26087 + pax_open_kernel();
26088 memcpy(image + proglen, temp, ilen);
26089 + pax_close_kernel();
26090 }
26091 proglen += ilen;
26092 addrs[i] = proglen;
26093 @@ -624,11 +634,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26094 break;
26095 }
26096 if (proglen == oldproglen) {
26097 - image = module_alloc(max_t(unsigned int,
26098 - proglen,
26099 - sizeof(struct work_struct)));
26100 + image = module_alloc_exec(proglen);
26101 if (!image)
26102 - goto out;
26103 + goto error;
26104 }
26105 oldproglen = proglen;
26106 }
26107 @@ -644,7 +652,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26108 bpf_flush_icache(image, image + proglen);
26109
26110 fp->bpf_func = (void *)image;
26111 - }
26112 + } else
26113 +error:
26114 + kfree(fp->work);
26115 +
26116 out:
26117 kfree(addrs);
26118 return;
26119 @@ -652,18 +663,20 @@ out:
26120
26121 static void jit_free_defer(struct work_struct *arg)
26122 {
26123 - module_free(NULL, arg);
26124 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26125 + kfree(arg);
26126 }
26127
26128 /* run from softirq, we must use a work_struct to call
26129 - * module_free() from process context
26130 + * module_free_exec() from process context
26131 */
26132 void bpf_jit_free(struct sk_filter *fp)
26133 {
26134 if (fp->bpf_func != sk_run_filter) {
26135 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26136 + struct work_struct *work = &fp->work->work;
26137
26138 INIT_WORK(work, jit_free_defer);
26139 + fp->work->image = fp->bpf_func;
26140 schedule_work(work);
26141 }
26142 }
26143 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26144 index d6aa6e8..266395a 100644
26145 --- a/arch/x86/oprofile/backtrace.c
26146 +++ b/arch/x86/oprofile/backtrace.c
26147 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26148 struct stack_frame_ia32 *fp;
26149 unsigned long bytes;
26150
26151 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26152 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26153 if (bytes != sizeof(bufhead))
26154 return NULL;
26155
26156 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26157 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26158
26159 oprofile_add_trace(bufhead[0].return_address);
26160
26161 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26162 struct stack_frame bufhead[2];
26163 unsigned long bytes;
26164
26165 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26166 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26167 if (bytes != sizeof(bufhead))
26168 return NULL;
26169
26170 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26171 {
26172 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26173
26174 - if (!user_mode_vm(regs)) {
26175 + if (!user_mode(regs)) {
26176 unsigned long stack = kernel_stack_pointer(regs);
26177 if (depth)
26178 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26179 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26180 index e14a2ff..3fd6b58 100644
26181 --- a/arch/x86/pci/mrst.c
26182 +++ b/arch/x86/pci/mrst.c
26183 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26184 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26185 pci_mmcfg_late_init();
26186 pcibios_enable_irq = mrst_pci_irq_enable;
26187 - pci_root_ops = pci_mrst_ops;
26188 + pax_open_kernel();
26189 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26190 + pax_close_kernel();
26191 pci_soc_mode = 1;
26192 /* Continue with standard init */
26193 return 1;
26194 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26195 index da8fe05..7ee6704 100644
26196 --- a/arch/x86/pci/pcbios.c
26197 +++ b/arch/x86/pci/pcbios.c
26198 @@ -79,50 +79,93 @@ union bios32 {
26199 static struct {
26200 unsigned long address;
26201 unsigned short segment;
26202 -} bios32_indirect = { 0, __KERNEL_CS };
26203 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26204
26205 /*
26206 * Returns the entry point for the given service, NULL on error
26207 */
26208
26209 -static unsigned long bios32_service(unsigned long service)
26210 +static unsigned long __devinit bios32_service(unsigned long service)
26211 {
26212 unsigned char return_code; /* %al */
26213 unsigned long address; /* %ebx */
26214 unsigned long length; /* %ecx */
26215 unsigned long entry; /* %edx */
26216 unsigned long flags;
26217 + struct desc_struct d, *gdt;
26218
26219 local_irq_save(flags);
26220 - __asm__("lcall *(%%edi); cld"
26221 +
26222 + gdt = get_cpu_gdt_table(smp_processor_id());
26223 +
26224 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26225 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26226 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26227 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26228 +
26229 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26230 : "=a" (return_code),
26231 "=b" (address),
26232 "=c" (length),
26233 "=d" (entry)
26234 : "0" (service),
26235 "1" (0),
26236 - "D" (&bios32_indirect));
26237 + "D" (&bios32_indirect),
26238 + "r"(__PCIBIOS_DS)
26239 + : "memory");
26240 +
26241 + pax_open_kernel();
26242 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26243 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26244 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26245 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26246 + pax_close_kernel();
26247 +
26248 local_irq_restore(flags);
26249
26250 switch (return_code) {
26251 - case 0:
26252 - return address + entry;
26253 - case 0x80: /* Not present */
26254 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26255 - return 0;
26256 - default: /* Shouldn't happen */
26257 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26258 - service, return_code);
26259 + case 0: {
26260 + int cpu;
26261 + unsigned char flags;
26262 +
26263 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26264 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26265 + printk(KERN_WARNING "bios32_service: not valid\n");
26266 return 0;
26267 + }
26268 + address = address + PAGE_OFFSET;
26269 + length += 16UL; /* some BIOSs underreport this... */
26270 + flags = 4;
26271 + if (length >= 64*1024*1024) {
26272 + length >>= PAGE_SHIFT;
26273 + flags |= 8;
26274 + }
26275 +
26276 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26277 + gdt = get_cpu_gdt_table(cpu);
26278 + pack_descriptor(&d, address, length, 0x9b, flags);
26279 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26280 + pack_descriptor(&d, address, length, 0x93, flags);
26281 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26282 + }
26283 + return entry;
26284 + }
26285 + case 0x80: /* Not present */
26286 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26287 + return 0;
26288 + default: /* Shouldn't happen */
26289 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26290 + service, return_code);
26291 + return 0;
26292 }
26293 }
26294
26295 static struct {
26296 unsigned long address;
26297 unsigned short segment;
26298 -} pci_indirect = { 0, __KERNEL_CS };
26299 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26300
26301 -static int pci_bios_present;
26302 +static int pci_bios_present __read_only;
26303
26304 static int __devinit check_pcibios(void)
26305 {
26306 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26307 unsigned long flags, pcibios_entry;
26308
26309 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26310 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26311 + pci_indirect.address = pcibios_entry;
26312
26313 local_irq_save(flags);
26314 - __asm__(
26315 - "lcall *(%%edi); cld\n\t"
26316 + __asm__("movw %w6, %%ds\n\t"
26317 + "lcall *%%ss:(%%edi); cld\n\t"
26318 + "push %%ss\n\t"
26319 + "pop %%ds\n\t"
26320 "jc 1f\n\t"
26321 "xor %%ah, %%ah\n"
26322 "1:"
26323 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26324 "=b" (ebx),
26325 "=c" (ecx)
26326 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26327 - "D" (&pci_indirect)
26328 + "D" (&pci_indirect),
26329 + "r" (__PCIBIOS_DS)
26330 : "memory");
26331 local_irq_restore(flags);
26332
26333 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26334
26335 switch (len) {
26336 case 1:
26337 - __asm__("lcall *(%%esi); cld\n\t"
26338 + __asm__("movw %w6, %%ds\n\t"
26339 + "lcall *%%ss:(%%esi); cld\n\t"
26340 + "push %%ss\n\t"
26341 + "pop %%ds\n\t"
26342 "jc 1f\n\t"
26343 "xor %%ah, %%ah\n"
26344 "1:"
26345 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26346 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26347 "b" (bx),
26348 "D" ((long)reg),
26349 - "S" (&pci_indirect));
26350 + "S" (&pci_indirect),
26351 + "r" (__PCIBIOS_DS));
26352 /*
26353 * Zero-extend the result beyond 8 bits, do not trust the
26354 * BIOS having done it:
26355 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26356 *value &= 0xff;
26357 break;
26358 case 2:
26359 - __asm__("lcall *(%%esi); cld\n\t"
26360 + __asm__("movw %w6, %%ds\n\t"
26361 + "lcall *%%ss:(%%esi); cld\n\t"
26362 + "push %%ss\n\t"
26363 + "pop %%ds\n\t"
26364 "jc 1f\n\t"
26365 "xor %%ah, %%ah\n"
26366 "1:"
26367 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26368 : "1" (PCIBIOS_READ_CONFIG_WORD),
26369 "b" (bx),
26370 "D" ((long)reg),
26371 - "S" (&pci_indirect));
26372 + "S" (&pci_indirect),
26373 + "r" (__PCIBIOS_DS));
26374 /*
26375 * Zero-extend the result beyond 16 bits, do not trust the
26376 * BIOS having done it:
26377 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26378 *value &= 0xffff;
26379 break;
26380 case 4:
26381 - __asm__("lcall *(%%esi); cld\n\t"
26382 + __asm__("movw %w6, %%ds\n\t"
26383 + "lcall *%%ss:(%%esi); cld\n\t"
26384 + "push %%ss\n\t"
26385 + "pop %%ds\n\t"
26386 "jc 1f\n\t"
26387 "xor %%ah, %%ah\n"
26388 "1:"
26389 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26390 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26391 "b" (bx),
26392 "D" ((long)reg),
26393 - "S" (&pci_indirect));
26394 + "S" (&pci_indirect),
26395 + "r" (__PCIBIOS_DS));
26396 break;
26397 }
26398
26399 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26400
26401 switch (len) {
26402 case 1:
26403 - __asm__("lcall *(%%esi); cld\n\t"
26404 + __asm__("movw %w6, %%ds\n\t"
26405 + "lcall *%%ss:(%%esi); cld\n\t"
26406 + "push %%ss\n\t"
26407 + "pop %%ds\n\t"
26408 "jc 1f\n\t"
26409 "xor %%ah, %%ah\n"
26410 "1:"
26411 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26412 "c" (value),
26413 "b" (bx),
26414 "D" ((long)reg),
26415 - "S" (&pci_indirect));
26416 + "S" (&pci_indirect),
26417 + "r" (__PCIBIOS_DS));
26418 break;
26419 case 2:
26420 - __asm__("lcall *(%%esi); cld\n\t"
26421 + __asm__("movw %w6, %%ds\n\t"
26422 + "lcall *%%ss:(%%esi); cld\n\t"
26423 + "push %%ss\n\t"
26424 + "pop %%ds\n\t"
26425 "jc 1f\n\t"
26426 "xor %%ah, %%ah\n"
26427 "1:"
26428 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26429 "c" (value),
26430 "b" (bx),
26431 "D" ((long)reg),
26432 - "S" (&pci_indirect));
26433 + "S" (&pci_indirect),
26434 + "r" (__PCIBIOS_DS));
26435 break;
26436 case 4:
26437 - __asm__("lcall *(%%esi); cld\n\t"
26438 + __asm__("movw %w6, %%ds\n\t"
26439 + "lcall *%%ss:(%%esi); cld\n\t"
26440 + "push %%ss\n\t"
26441 + "pop %%ds\n\t"
26442 "jc 1f\n\t"
26443 "xor %%ah, %%ah\n"
26444 "1:"
26445 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26446 "c" (value),
26447 "b" (bx),
26448 "D" ((long)reg),
26449 - "S" (&pci_indirect));
26450 + "S" (&pci_indirect),
26451 + "r" (__PCIBIOS_DS));
26452 break;
26453 }
26454
26455 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26456
26457 DBG("PCI: Fetching IRQ routing table... ");
26458 __asm__("push %%es\n\t"
26459 + "movw %w8, %%ds\n\t"
26460 "push %%ds\n\t"
26461 "pop %%es\n\t"
26462 - "lcall *(%%esi); cld\n\t"
26463 + "lcall *%%ss:(%%esi); cld\n\t"
26464 "pop %%es\n\t"
26465 + "push %%ss\n\t"
26466 + "pop %%ds\n"
26467 "jc 1f\n\t"
26468 "xor %%ah, %%ah\n"
26469 "1:"
26470 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26471 "1" (0),
26472 "D" ((long) &opt),
26473 "S" (&pci_indirect),
26474 - "m" (opt)
26475 + "m" (opt),
26476 + "r" (__PCIBIOS_DS)
26477 : "memory");
26478 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26479 if (ret & 0xff00)
26480 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26481 {
26482 int ret;
26483
26484 - __asm__("lcall *(%%esi); cld\n\t"
26485 + __asm__("movw %w5, %%ds\n\t"
26486 + "lcall *%%ss:(%%esi); cld\n\t"
26487 + "push %%ss\n\t"
26488 + "pop %%ds\n"
26489 "jc 1f\n\t"
26490 "xor %%ah, %%ah\n"
26491 "1:"
26492 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26493 : "0" (PCIBIOS_SET_PCI_HW_INT),
26494 "b" ((dev->bus->number << 8) | dev->devfn),
26495 "c" ((irq << 8) | (pin + 10)),
26496 - "S" (&pci_indirect));
26497 + "S" (&pci_indirect),
26498 + "r" (__PCIBIOS_DS));
26499 return !(ret & 0xff00);
26500 }
26501 EXPORT_SYMBOL(pcibios_set_irq_routing);
26502 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26503 index 40e4469..1ab536e 100644
26504 --- a/arch/x86/platform/efi/efi_32.c
26505 +++ b/arch/x86/platform/efi/efi_32.c
26506 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26507 {
26508 struct desc_ptr gdt_descr;
26509
26510 +#ifdef CONFIG_PAX_KERNEXEC
26511 + struct desc_struct d;
26512 +#endif
26513 +
26514 local_irq_save(efi_rt_eflags);
26515
26516 load_cr3(initial_page_table);
26517 __flush_tlb_all();
26518
26519 +#ifdef CONFIG_PAX_KERNEXEC
26520 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26521 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26522 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26523 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26524 +#endif
26525 +
26526 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26527 gdt_descr.size = GDT_SIZE - 1;
26528 load_gdt(&gdt_descr);
26529 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26530 {
26531 struct desc_ptr gdt_descr;
26532
26533 +#ifdef CONFIG_PAX_KERNEXEC
26534 + struct desc_struct d;
26535 +
26536 + memset(&d, 0, sizeof d);
26537 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26538 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26539 +#endif
26540 +
26541 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26542 gdt_descr.size = GDT_SIZE - 1;
26543 load_gdt(&gdt_descr);
26544 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26545 index fbe66e6..eae5e38 100644
26546 --- a/arch/x86/platform/efi/efi_stub_32.S
26547 +++ b/arch/x86/platform/efi/efi_stub_32.S
26548 @@ -6,7 +6,9 @@
26549 */
26550
26551 #include <linux/linkage.h>
26552 +#include <linux/init.h>
26553 #include <asm/page_types.h>
26554 +#include <asm/segment.h>
26555
26556 /*
26557 * efi_call_phys(void *, ...) is a function with variable parameters.
26558 @@ -20,7 +22,7 @@
26559 * service functions will comply with gcc calling convention, too.
26560 */
26561
26562 -.text
26563 +__INIT
26564 ENTRY(efi_call_phys)
26565 /*
26566 * 0. The function can only be called in Linux kernel. So CS has been
26567 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26568 * The mapping of lower virtual memory has been created in prelog and
26569 * epilog.
26570 */
26571 - movl $1f, %edx
26572 - subl $__PAGE_OFFSET, %edx
26573 - jmp *%edx
26574 +#ifdef CONFIG_PAX_KERNEXEC
26575 + movl $(__KERNEXEC_EFI_DS), %edx
26576 + mov %edx, %ds
26577 + mov %edx, %es
26578 + mov %edx, %ss
26579 + addl $2f,(1f)
26580 + ljmp *(1f)
26581 +
26582 +__INITDATA
26583 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26584 +.previous
26585 +
26586 +2:
26587 + subl $2b,(1b)
26588 +#else
26589 + jmp 1f-__PAGE_OFFSET
26590 1:
26591 +#endif
26592
26593 /*
26594 * 2. Now on the top of stack is the return
26595 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26596 * parameter 2, ..., param n. To make things easy, we save the return
26597 * address of efi_call_phys in a global variable.
26598 */
26599 - popl %edx
26600 - movl %edx, saved_return_addr
26601 - /* get the function pointer into ECX*/
26602 - popl %ecx
26603 - movl %ecx, efi_rt_function_ptr
26604 - movl $2f, %edx
26605 - subl $__PAGE_OFFSET, %edx
26606 - pushl %edx
26607 + popl (saved_return_addr)
26608 + popl (efi_rt_function_ptr)
26609
26610 /*
26611 * 3. Clear PG bit in %CR0.
26612 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26613 /*
26614 * 5. Call the physical function.
26615 */
26616 - jmp *%ecx
26617 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26618
26619 -2:
26620 /*
26621 * 6. After EFI runtime service returns, control will return to
26622 * following instruction. We'd better readjust stack pointer first.
26623 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26624 movl %cr0, %edx
26625 orl $0x80000000, %edx
26626 movl %edx, %cr0
26627 - jmp 1f
26628 -1:
26629 +
26630 /*
26631 * 8. Now restore the virtual mode from flat mode by
26632 * adding EIP with PAGE_OFFSET.
26633 */
26634 - movl $1f, %edx
26635 - jmp *%edx
26636 +#ifdef CONFIG_PAX_KERNEXEC
26637 + movl $(__KERNEL_DS), %edx
26638 + mov %edx, %ds
26639 + mov %edx, %es
26640 + mov %edx, %ss
26641 + ljmp $(__KERNEL_CS),$1f
26642 +#else
26643 + jmp 1f+__PAGE_OFFSET
26644 +#endif
26645 1:
26646
26647 /*
26648 * 9. Balance the stack. And because EAX contain the return value,
26649 * we'd better not clobber it.
26650 */
26651 - leal efi_rt_function_ptr, %edx
26652 - movl (%edx), %ecx
26653 - pushl %ecx
26654 + pushl (efi_rt_function_ptr)
26655
26656 /*
26657 - * 10. Push the saved return address onto the stack and return.
26658 + * 10. Return to the saved return address.
26659 */
26660 - leal saved_return_addr, %edx
26661 - movl (%edx), %ecx
26662 - pushl %ecx
26663 - ret
26664 + jmpl *(saved_return_addr)
26665 ENDPROC(efi_call_phys)
26666 .previous
26667
26668 -.data
26669 +__INITDATA
26670 saved_return_addr:
26671 .long 0
26672 efi_rt_function_ptr:
26673 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26674 index 4c07cca..2c8427d 100644
26675 --- a/arch/x86/platform/efi/efi_stub_64.S
26676 +++ b/arch/x86/platform/efi/efi_stub_64.S
26677 @@ -7,6 +7,7 @@
26678 */
26679
26680 #include <linux/linkage.h>
26681 +#include <asm/alternative-asm.h>
26682
26683 #define SAVE_XMM \
26684 mov %rsp, %rax; \
26685 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26686 call *%rdi
26687 addq $32, %rsp
26688 RESTORE_XMM
26689 + pax_force_retaddr 0, 1
26690 ret
26691 ENDPROC(efi_call0)
26692
26693 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26694 call *%rdi
26695 addq $32, %rsp
26696 RESTORE_XMM
26697 + pax_force_retaddr 0, 1
26698 ret
26699 ENDPROC(efi_call1)
26700
26701 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26702 call *%rdi
26703 addq $32, %rsp
26704 RESTORE_XMM
26705 + pax_force_retaddr 0, 1
26706 ret
26707 ENDPROC(efi_call2)
26708
26709 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26710 call *%rdi
26711 addq $32, %rsp
26712 RESTORE_XMM
26713 + pax_force_retaddr 0, 1
26714 ret
26715 ENDPROC(efi_call3)
26716
26717 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26718 call *%rdi
26719 addq $32, %rsp
26720 RESTORE_XMM
26721 + pax_force_retaddr 0, 1
26722 ret
26723 ENDPROC(efi_call4)
26724
26725 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26726 call *%rdi
26727 addq $48, %rsp
26728 RESTORE_XMM
26729 + pax_force_retaddr 0, 1
26730 ret
26731 ENDPROC(efi_call5)
26732
26733 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26734 call *%rdi
26735 addq $48, %rsp
26736 RESTORE_XMM
26737 + pax_force_retaddr 0, 1
26738 ret
26739 ENDPROC(efi_call6)
26740 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26741 index fd41a92..9c33628 100644
26742 --- a/arch/x86/platform/mrst/mrst.c
26743 +++ b/arch/x86/platform/mrst/mrst.c
26744 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26745 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26746 int sfi_mrtc_num;
26747
26748 -static void mrst_power_off(void)
26749 +static __noreturn void mrst_power_off(void)
26750 {
26751 + BUG();
26752 }
26753
26754 -static void mrst_reboot(void)
26755 +static __noreturn void mrst_reboot(void)
26756 {
26757 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26758 + BUG();
26759 }
26760
26761 /* parse all the mtimer info to a static mtimer array */
26762 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26763 index 218cdb1..fd55c08 100644
26764 --- a/arch/x86/power/cpu.c
26765 +++ b/arch/x86/power/cpu.c
26766 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26767 static void fix_processor_context(void)
26768 {
26769 int cpu = smp_processor_id();
26770 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26771 + struct tss_struct *t = init_tss + cpu;
26772
26773 set_tss_desc(cpu, t); /*
26774 * This just modifies memory; should not be
26775 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26776 */
26777
26778 #ifdef CONFIG_X86_64
26779 + pax_open_kernel();
26780 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26781 + pax_close_kernel();
26782
26783 syscall_init(); /* This sets MSR_*STAR and related */
26784 #endif
26785 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26786 index cbca565..bae7133 100644
26787 --- a/arch/x86/realmode/init.c
26788 +++ b/arch/x86/realmode/init.c
26789 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26790 __va(real_mode_header->trampoline_header);
26791
26792 #ifdef CONFIG_X86_32
26793 - trampoline_header->start = __pa(startup_32_smp);
26794 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26795 +
26796 +#ifdef CONFIG_PAX_KERNEXEC
26797 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26798 +#endif
26799 +
26800 + trampoline_header->boot_cs = __BOOT_CS;
26801 trampoline_header->gdt_limit = __BOOT_DS + 7;
26802 trampoline_header->gdt_base = __pa(boot_gdt);
26803 #else
26804 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26805 index 8869287..d577672 100644
26806 --- a/arch/x86/realmode/rm/Makefile
26807 +++ b/arch/x86/realmode/rm/Makefile
26808 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26809 $(call cc-option, -fno-unit-at-a-time)) \
26810 $(call cc-option, -fno-stack-protector) \
26811 $(call cc-option, -mpreferred-stack-boundary=2)
26812 +ifdef CONSTIFY_PLUGIN
26813 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26814 +endif
26815 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26816 GCOV_PROFILE := n
26817 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
26818 index a28221d..93c40f1 100644
26819 --- a/arch/x86/realmode/rm/header.S
26820 +++ b/arch/x86/realmode/rm/header.S
26821 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
26822 #endif
26823 /* APM/BIOS reboot */
26824 .long pa_machine_real_restart_asm
26825 -#ifdef CONFIG_X86_64
26826 +#ifdef CONFIG_X86_32
26827 + .long __KERNEL_CS
26828 +#else
26829 .long __KERNEL32_CS
26830 #endif
26831 END(real_mode_header)
26832 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26833 index c1b2791..f9e31c7 100644
26834 --- a/arch/x86/realmode/rm/trampoline_32.S
26835 +++ b/arch/x86/realmode/rm/trampoline_32.S
26836 @@ -25,6 +25,12 @@
26837 #include <asm/page_types.h>
26838 #include "realmode.h"
26839
26840 +#ifdef CONFIG_PAX_KERNEXEC
26841 +#define ta(X) (X)
26842 +#else
26843 +#define ta(X) (pa_ ## X)
26844 +#endif
26845 +
26846 .text
26847 .code16
26848
26849 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26850
26851 cli # We should be safe anyway
26852
26853 - movl tr_start, %eax # where we need to go
26854 -
26855 movl $0xA5A5A5A5, trampoline_status
26856 # write marker for master knows we're running
26857
26858 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26859 movw $1, %dx # protected mode (PE) bit
26860 lmsw %dx # into protected mode
26861
26862 - ljmpl $__BOOT_CS, $pa_startup_32
26863 + ljmpl *(trampoline_header)
26864
26865 .section ".text32","ax"
26866 .code32
26867 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26868 .balign 8
26869 GLOBAL(trampoline_header)
26870 tr_start: .space 4
26871 - tr_gdt_pad: .space 2
26872 + tr_boot_cs: .space 2
26873 tr_gdt: .space 6
26874 END(trampoline_header)
26875
26876 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26877 index bb360dc..3e5945f 100644
26878 --- a/arch/x86/realmode/rm/trampoline_64.S
26879 +++ b/arch/x86/realmode/rm/trampoline_64.S
26880 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26881 wrmsr
26882
26883 # Enable paging and in turn activate Long Mode
26884 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26885 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26886 movl %eax, %cr0
26887
26888 /*
26889 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26890 index 5a1847d..deccb30 100644
26891 --- a/arch/x86/tools/relocs.c
26892 +++ b/arch/x86/tools/relocs.c
26893 @@ -12,10 +12,13 @@
26894 #include <regex.h>
26895 #include <tools/le_byteshift.h>
26896
26897 +#include "../../../include/generated/autoconf.h"
26898 +
26899 static void die(char *fmt, ...);
26900
26901 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26902 static Elf32_Ehdr ehdr;
26903 +static Elf32_Phdr *phdr;
26904 static unsigned long reloc_count, reloc_idx;
26905 static unsigned long *relocs;
26906 static unsigned long reloc16_count, reloc16_idx;
26907 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26908 }
26909 }
26910
26911 +static void read_phdrs(FILE *fp)
26912 +{
26913 + unsigned int i;
26914 +
26915 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26916 + if (!phdr) {
26917 + die("Unable to allocate %d program headers\n",
26918 + ehdr.e_phnum);
26919 + }
26920 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26921 + die("Seek to %d failed: %s\n",
26922 + ehdr.e_phoff, strerror(errno));
26923 + }
26924 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26925 + die("Cannot read ELF program headers: %s\n",
26926 + strerror(errno));
26927 + }
26928 + for(i = 0; i < ehdr.e_phnum; i++) {
26929 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26930 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26931 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26932 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26933 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26934 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26935 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26936 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26937 + }
26938 +
26939 +}
26940 +
26941 static void read_shdrs(FILE *fp)
26942 {
26943 - int i;
26944 + unsigned int i;
26945 Elf32_Shdr shdr;
26946
26947 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26948 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26949
26950 static void read_strtabs(FILE *fp)
26951 {
26952 - int i;
26953 + unsigned int i;
26954 for (i = 0; i < ehdr.e_shnum; i++) {
26955 struct section *sec = &secs[i];
26956 if (sec->shdr.sh_type != SHT_STRTAB) {
26957 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26958
26959 static void read_symtabs(FILE *fp)
26960 {
26961 - int i,j;
26962 + unsigned int i,j;
26963 for (i = 0; i < ehdr.e_shnum; i++) {
26964 struct section *sec = &secs[i];
26965 if (sec->shdr.sh_type != SHT_SYMTAB) {
26966 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26967 }
26968
26969
26970 -static void read_relocs(FILE *fp)
26971 +static void read_relocs(FILE *fp, int use_real_mode)
26972 {
26973 - int i,j;
26974 + unsigned int i,j;
26975 + uint32_t base;
26976 +
26977 for (i = 0; i < ehdr.e_shnum; i++) {
26978 struct section *sec = &secs[i];
26979 if (sec->shdr.sh_type != SHT_REL) {
26980 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26981 die("Cannot read symbol table: %s\n",
26982 strerror(errno));
26983 }
26984 + base = 0;
26985 +
26986 +#ifdef CONFIG_X86_32
26987 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26988 + if (phdr[j].p_type != PT_LOAD )
26989 + continue;
26990 + 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)
26991 + continue;
26992 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26993 + break;
26994 + }
26995 +#endif
26996 +
26997 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26998 Elf32_Rel *rel = &sec->reltab[j];
26999 - rel->r_offset = elf32_to_cpu(rel->r_offset);
27000 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
27001 rel->r_info = elf32_to_cpu(rel->r_info);
27002 }
27003 }
27004 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
27005
27006 static void print_absolute_symbols(void)
27007 {
27008 - int i;
27009 + unsigned int i;
27010 printf("Absolute symbols\n");
27011 printf(" Num: Value Size Type Bind Visibility Name\n");
27012 for (i = 0; i < ehdr.e_shnum; i++) {
27013 struct section *sec = &secs[i];
27014 char *sym_strtab;
27015 - int j;
27016 + unsigned int j;
27017
27018 if (sec->shdr.sh_type != SHT_SYMTAB) {
27019 continue;
27020 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
27021
27022 static void print_absolute_relocs(void)
27023 {
27024 - int i, printed = 0;
27025 + unsigned int i, printed = 0;
27026
27027 for (i = 0; i < ehdr.e_shnum; i++) {
27028 struct section *sec = &secs[i];
27029 struct section *sec_applies, *sec_symtab;
27030 char *sym_strtab;
27031 Elf32_Sym *sh_symtab;
27032 - int j;
27033 + unsigned int j;
27034 if (sec->shdr.sh_type != SHT_REL) {
27035 continue;
27036 }
27037 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
27038 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27039 int use_real_mode)
27040 {
27041 - int i;
27042 + unsigned int i;
27043 /* Walk through the relocations */
27044 for (i = 0; i < ehdr.e_shnum; i++) {
27045 char *sym_strtab;
27046 Elf32_Sym *sh_symtab;
27047 struct section *sec_applies, *sec_symtab;
27048 - int j;
27049 + unsigned int j;
27050 struct section *sec = &secs[i];
27051
27052 if (sec->shdr.sh_type != SHT_REL) {
27053 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27054 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27055 r_type = ELF32_R_TYPE(rel->r_info);
27056
27057 + if (!use_real_mode) {
27058 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27059 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27060 + continue;
27061 +
27062 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27063 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27064 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27065 + continue;
27066 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27067 + continue;
27068 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27069 + continue;
27070 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27071 + continue;
27072 +#endif
27073 + }
27074 +
27075 shn_abs = sym->st_shndx == SHN_ABS;
27076
27077 switch (r_type) {
27078 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27079
27080 static void emit_relocs(int as_text, int use_real_mode)
27081 {
27082 - int i;
27083 + unsigned int i;
27084 /* Count how many relocations I have and allocate space for them. */
27085 reloc_count = 0;
27086 walk_relocs(count_reloc, use_real_mode);
27087 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27088 fname, strerror(errno));
27089 }
27090 read_ehdr(fp);
27091 + read_phdrs(fp);
27092 read_shdrs(fp);
27093 read_strtabs(fp);
27094 read_symtabs(fp);
27095 - read_relocs(fp);
27096 + read_relocs(fp, use_real_mode);
27097 if (show_absolute_syms) {
27098 print_absolute_symbols();
27099 return 0;
27100 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27101 index fd14be1..e3c79c0 100644
27102 --- a/arch/x86/vdso/Makefile
27103 +++ b/arch/x86/vdso/Makefile
27104 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27105 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27106 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27107
27108 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27109 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27110 GCOV_PROFILE := n
27111
27112 #
27113 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27114 index 0faad64..39ef157 100644
27115 --- a/arch/x86/vdso/vdso32-setup.c
27116 +++ b/arch/x86/vdso/vdso32-setup.c
27117 @@ -25,6 +25,7 @@
27118 #include <asm/tlbflush.h>
27119 #include <asm/vdso.h>
27120 #include <asm/proto.h>
27121 +#include <asm/mman.h>
27122
27123 enum {
27124 VDSO_DISABLED = 0,
27125 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27126 void enable_sep_cpu(void)
27127 {
27128 int cpu = get_cpu();
27129 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27130 + struct tss_struct *tss = init_tss + cpu;
27131
27132 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27133 put_cpu();
27134 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27135 gate_vma.vm_start = FIXADDR_USER_START;
27136 gate_vma.vm_end = FIXADDR_USER_END;
27137 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27138 - gate_vma.vm_page_prot = __P101;
27139 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27140
27141 return 0;
27142 }
27143 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27144 if (compat)
27145 addr = VDSO_HIGH_BASE;
27146 else {
27147 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27148 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27149 if (IS_ERR_VALUE(addr)) {
27150 ret = addr;
27151 goto up_fail;
27152 }
27153 }
27154
27155 - current->mm->context.vdso = (void *)addr;
27156 + current->mm->context.vdso = addr;
27157
27158 if (compat_uses_vma || !compat) {
27159 /*
27160 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27161 }
27162
27163 current_thread_info()->sysenter_return =
27164 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27165 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27166
27167 up_fail:
27168 if (ret)
27169 - current->mm->context.vdso = NULL;
27170 + current->mm->context.vdso = 0;
27171
27172 up_write(&mm->mmap_sem);
27173
27174 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27175
27176 const char *arch_vma_name(struct vm_area_struct *vma)
27177 {
27178 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27179 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27180 return "[vdso]";
27181 +
27182 +#ifdef CONFIG_PAX_SEGMEXEC
27183 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27184 + return "[vdso]";
27185 +#endif
27186 +
27187 return NULL;
27188 }
27189
27190 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27191 * Check to see if the corresponding task was created in compat vdso
27192 * mode.
27193 */
27194 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27195 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27196 return &gate_vma;
27197 return NULL;
27198 }
27199 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27200 index 00aaf04..4a26505 100644
27201 --- a/arch/x86/vdso/vma.c
27202 +++ b/arch/x86/vdso/vma.c
27203 @@ -16,8 +16,6 @@
27204 #include <asm/vdso.h>
27205 #include <asm/page.h>
27206
27207 -unsigned int __read_mostly vdso_enabled = 1;
27208 -
27209 extern char vdso_start[], vdso_end[];
27210 extern unsigned short vdso_sync_cpuid;
27211
27212 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27213 * unaligned here as a result of stack start randomization.
27214 */
27215 addr = PAGE_ALIGN(addr);
27216 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27217
27218 return addr;
27219 }
27220 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27221 unsigned size)
27222 {
27223 struct mm_struct *mm = current->mm;
27224 - unsigned long addr;
27225 + unsigned long addr = 0;
27226 int ret;
27227
27228 - if (!vdso_enabled)
27229 - return 0;
27230 -
27231 down_write(&mm->mmap_sem);
27232 +
27233 +#ifdef CONFIG_PAX_RANDMMAP
27234 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27235 +#endif
27236 +
27237 addr = vdso_addr(mm->start_stack, size);
27238 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27239 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27240 if (IS_ERR_VALUE(addr)) {
27241 ret = addr;
27242 goto up_fail;
27243 }
27244
27245 - current->mm->context.vdso = (void *)addr;
27246 + mm->context.vdso = addr;
27247
27248 ret = install_special_mapping(mm, addr, size,
27249 VM_READ|VM_EXEC|
27250 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27251 pages);
27252 - if (ret) {
27253 - current->mm->context.vdso = NULL;
27254 - goto up_fail;
27255 - }
27256 + if (ret)
27257 + mm->context.vdso = 0;
27258
27259 up_fail:
27260 up_write(&mm->mmap_sem);
27261 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27262 vdsox32_size);
27263 }
27264 #endif
27265 -
27266 -static __init int vdso_setup(char *s)
27267 -{
27268 - vdso_enabled = simple_strtoul(s, NULL, 0);
27269 - return 0;
27270 -}
27271 -__setup("vdso=", vdso_setup);
27272 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27273 index 1fbe75a..c22e01f 100644
27274 --- a/arch/x86/xen/enlighten.c
27275 +++ b/arch/x86/xen/enlighten.c
27276 @@ -98,8 +98,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27277
27278 struct shared_info xen_dummy_shared_info;
27279
27280 -void *xen_initial_gdt;
27281 -
27282 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27283 __read_mostly int xen_have_vector_callback;
27284 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27285 @@ -917,21 +915,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27286
27287 static void set_xen_basic_apic_ops(void)
27288 {
27289 - apic->read = xen_apic_read;
27290 - apic->write = xen_apic_write;
27291 - apic->icr_read = xen_apic_icr_read;
27292 - apic->icr_write = xen_apic_icr_write;
27293 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27294 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27295 - apic->set_apic_id = xen_set_apic_id;
27296 - apic->get_apic_id = xen_get_apic_id;
27297 + *(void **)&apic->read = xen_apic_read;
27298 + *(void **)&apic->write = xen_apic_write;
27299 + *(void **)&apic->icr_read = xen_apic_icr_read;
27300 + *(void **)&apic->icr_write = xen_apic_icr_write;
27301 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27302 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27303 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27304 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27305
27306 #ifdef CONFIG_SMP
27307 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27308 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27309 - apic->send_IPI_mask = xen_send_IPI_mask;
27310 - apic->send_IPI_all = xen_send_IPI_all;
27311 - apic->send_IPI_self = xen_send_IPI_self;
27312 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27313 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27314 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27315 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27316 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27317 #endif
27318 }
27319
27320 @@ -1205,30 +1203,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27321 #endif
27322 };
27323
27324 -static void xen_reboot(int reason)
27325 +static __noreturn void xen_reboot(int reason)
27326 {
27327 struct sched_shutdown r = { .reason = reason };
27328
27329 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27330 - BUG();
27331 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27332 + BUG();
27333 }
27334
27335 -static void xen_restart(char *msg)
27336 +static __noreturn void xen_restart(char *msg)
27337 {
27338 xen_reboot(SHUTDOWN_reboot);
27339 }
27340
27341 -static void xen_emergency_restart(void)
27342 +static __noreturn void xen_emergency_restart(void)
27343 {
27344 xen_reboot(SHUTDOWN_reboot);
27345 }
27346
27347 -static void xen_machine_halt(void)
27348 +static __noreturn void xen_machine_halt(void)
27349 {
27350 xen_reboot(SHUTDOWN_poweroff);
27351 }
27352
27353 -static void xen_machine_power_off(void)
27354 +static __noreturn void xen_machine_power_off(void)
27355 {
27356 if (pm_power_off)
27357 pm_power_off();
27358 @@ -1331,7 +1329,17 @@ asmlinkage void __init xen_start_kernel(void)
27359 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27360
27361 /* Work out if we support NX */
27362 - x86_configure_nx();
27363 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27364 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27365 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27366 + unsigned l, h;
27367 +
27368 + __supported_pte_mask |= _PAGE_NX;
27369 + rdmsr(MSR_EFER, l, h);
27370 + l |= EFER_NX;
27371 + wrmsr(MSR_EFER, l, h);
27372 + }
27373 +#endif
27374
27375 xen_setup_features();
27376
27377 @@ -1362,13 +1370,6 @@ asmlinkage void __init xen_start_kernel(void)
27378
27379 machine_ops = xen_machine_ops;
27380
27381 - /*
27382 - * The only reliable way to retain the initial address of the
27383 - * percpu gdt_page is to remember it here, so we can go and
27384 - * mark it RW later, when the initial percpu area is freed.
27385 - */
27386 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27387 -
27388 xen_smp_init();
27389
27390 #ifdef CONFIG_ACPI_NUMA
27391 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27392 index 5141d80..6c9fb41 100644
27393 --- a/arch/x86/xen/mmu.c
27394 +++ b/arch/x86/xen/mmu.c
27395 @@ -1765,6 +1765,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27396 convert_pfn_mfn(init_level4_pgt);
27397 convert_pfn_mfn(level3_ident_pgt);
27398 convert_pfn_mfn(level3_kernel_pgt);
27399 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27400 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27401 + convert_pfn_mfn(level3_vmemmap_pgt);
27402
27403 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27404 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27405 @@ -1783,7 +1786,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27406 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27407 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27408 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27409 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27410 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27411 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27412 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27413 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27414 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27415 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27416
27417 @@ -1967,6 +1974,7 @@ static void __init xen_post_allocator_init(void)
27418 pv_mmu_ops.set_pud = xen_set_pud;
27419 #if PAGETABLE_LEVELS == 4
27420 pv_mmu_ops.set_pgd = xen_set_pgd;
27421 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27422 #endif
27423
27424 /* This will work as long as patching hasn't happened yet
27425 @@ -2048,6 +2056,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27426 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27427 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27428 .set_pgd = xen_set_pgd_hyper,
27429 + .set_pgd_batched = xen_set_pgd_hyper,
27430
27431 .alloc_pud = xen_alloc_pmd_init,
27432 .release_pud = xen_release_pmd_init,
27433 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27434 index f58dca7..ad21f52 100644
27435 --- a/arch/x86/xen/smp.c
27436 +++ b/arch/x86/xen/smp.c
27437 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27438 {
27439 BUG_ON(smp_processor_id() != 0);
27440 native_smp_prepare_boot_cpu();
27441 -
27442 - /* We've switched to the "real" per-cpu gdt, so make sure the
27443 - old memory can be recycled */
27444 - make_lowmem_page_readwrite(xen_initial_gdt);
27445 -
27446 xen_filter_cpu_maps();
27447 xen_setup_vcpu_info_placement();
27448 }
27449 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27450 gdt = get_cpu_gdt_table(cpu);
27451
27452 ctxt->flags = VGCF_IN_KERNEL;
27453 - ctxt->user_regs.ds = __USER_DS;
27454 - ctxt->user_regs.es = __USER_DS;
27455 + ctxt->user_regs.ds = __KERNEL_DS;
27456 + ctxt->user_regs.es = __KERNEL_DS;
27457 ctxt->user_regs.ss = __KERNEL_DS;
27458 #ifdef CONFIG_X86_32
27459 ctxt->user_regs.fs = __KERNEL_PERCPU;
27460 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27461 + savesegment(gs, ctxt->user_regs.gs);
27462 #else
27463 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27464 #endif
27465 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27466 int rc;
27467
27468 per_cpu(current_task, cpu) = idle;
27469 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27470 #ifdef CONFIG_X86_32
27471 irq_ctx_init(cpu);
27472 #else
27473 clear_tsk_thread_flag(idle, TIF_FORK);
27474 - per_cpu(kernel_stack, cpu) =
27475 - (unsigned long)task_stack_page(idle) -
27476 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27477 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27478 #endif
27479 xen_setup_runstate_info(cpu);
27480 xen_setup_timer(cpu);
27481 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27482 index f9643fc..602e8af 100644
27483 --- a/arch/x86/xen/xen-asm_32.S
27484 +++ b/arch/x86/xen/xen-asm_32.S
27485 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27486 ESP_OFFSET=4 # bytes pushed onto stack
27487
27488 /*
27489 - * Store vcpu_info pointer for easy access. Do it this way to
27490 - * avoid having to reload %fs
27491 + * Store vcpu_info pointer for easy access.
27492 */
27493 #ifdef CONFIG_SMP
27494 - GET_THREAD_INFO(%eax)
27495 - movl TI_cpu(%eax), %eax
27496 - movl __per_cpu_offset(,%eax,4), %eax
27497 - mov xen_vcpu(%eax), %eax
27498 + push %fs
27499 + mov $(__KERNEL_PERCPU), %eax
27500 + mov %eax, %fs
27501 + mov PER_CPU_VAR(xen_vcpu), %eax
27502 + pop %fs
27503 #else
27504 movl xen_vcpu, %eax
27505 #endif
27506 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27507 index aaa7291..3f77960 100644
27508 --- a/arch/x86/xen/xen-head.S
27509 +++ b/arch/x86/xen/xen-head.S
27510 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27511 #ifdef CONFIG_X86_32
27512 mov %esi,xen_start_info
27513 mov $init_thread_union+THREAD_SIZE,%esp
27514 +#ifdef CONFIG_SMP
27515 + movl $cpu_gdt_table,%edi
27516 + movl $__per_cpu_load,%eax
27517 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27518 + rorl $16,%eax
27519 + movb %al,__KERNEL_PERCPU + 4(%edi)
27520 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27521 + movl $__per_cpu_end - 1,%eax
27522 + subl $__per_cpu_start,%eax
27523 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27524 +#endif
27525 #else
27526 mov %rsi,xen_start_info
27527 mov $init_thread_union+THREAD_SIZE,%rsp
27528 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27529 index 202d4c1..99b072a 100644
27530 --- a/arch/x86/xen/xen-ops.h
27531 +++ b/arch/x86/xen/xen-ops.h
27532 @@ -10,8 +10,6 @@
27533 extern const char xen_hypervisor_callback[];
27534 extern const char xen_failsafe_callback[];
27535
27536 -extern void *xen_initial_gdt;
27537 -
27538 struct trap_info;
27539 void xen_copy_trap_info(struct trap_info *traps);
27540
27541 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27542 index 525bd3d..ef888b1 100644
27543 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27544 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27545 @@ -119,9 +119,9 @@
27546 ----------------------------------------------------------------------*/
27547
27548 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27549 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27550 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27551 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27552 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27553
27554 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27555 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27556 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27557 index 2f33760..835e50a 100644
27558 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27559 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27560 @@ -11,6 +11,7 @@
27561 #ifndef _XTENSA_CORE_H
27562 #define _XTENSA_CORE_H
27563
27564 +#include <linux/const.h>
27565
27566 /****************************************************************************
27567 Parameters Useful for Any Code, USER or PRIVILEGED
27568 @@ -112,9 +113,9 @@
27569 ----------------------------------------------------------------------*/
27570
27571 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27572 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27573 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27574 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27575 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27576
27577 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27578 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27579 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27580 index af00795..2bb8105 100644
27581 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27582 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27583 @@ -11,6 +11,7 @@
27584 #ifndef _XTENSA_CORE_CONFIGURATION_H
27585 #define _XTENSA_CORE_CONFIGURATION_H
27586
27587 +#include <linux/const.h>
27588
27589 /****************************************************************************
27590 Parameters Useful for Any Code, USER or PRIVILEGED
27591 @@ -118,9 +119,9 @@
27592 ----------------------------------------------------------------------*/
27593
27594 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27595 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27596 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27597 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27598 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27599
27600 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27601 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27602 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27603 index 58916af..9cb880b 100644
27604 --- a/block/blk-iopoll.c
27605 +++ b/block/blk-iopoll.c
27606 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27607 }
27608 EXPORT_SYMBOL(blk_iopoll_complete);
27609
27610 -static void blk_iopoll_softirq(struct softirq_action *h)
27611 +static void blk_iopoll_softirq(void)
27612 {
27613 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27614 int rearm = 0, budget = blk_iopoll_budget;
27615 diff --git a/block/blk-map.c b/block/blk-map.c
27616 index 623e1cd..ca1e109 100644
27617 --- a/block/blk-map.c
27618 +++ b/block/blk-map.c
27619 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27620 if (!len || !kbuf)
27621 return -EINVAL;
27622
27623 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27624 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27625 if (do_copy)
27626 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27627 else
27628 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27629 index 467c8de..4bddc6d 100644
27630 --- a/block/blk-softirq.c
27631 +++ b/block/blk-softirq.c
27632 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27633 * Softirq action handler - move entries to local list and loop over them
27634 * while passing them to the queue registered handler.
27635 */
27636 -static void blk_done_softirq(struct softirq_action *h)
27637 +static void blk_done_softirq(void)
27638 {
27639 struct list_head *cpu_list, local_list;
27640
27641 diff --git a/block/bsg.c b/block/bsg.c
27642 index ff64ae3..593560c 100644
27643 --- a/block/bsg.c
27644 +++ b/block/bsg.c
27645 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27646 struct sg_io_v4 *hdr, struct bsg_device *bd,
27647 fmode_t has_write_perm)
27648 {
27649 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27650 + unsigned char *cmdptr;
27651 +
27652 if (hdr->request_len > BLK_MAX_CDB) {
27653 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27654 if (!rq->cmd)
27655 return -ENOMEM;
27656 - }
27657 + cmdptr = rq->cmd;
27658 + } else
27659 + cmdptr = tmpcmd;
27660
27661 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27662 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27663 hdr->request_len))
27664 return -EFAULT;
27665
27666 + if (cmdptr != rq->cmd)
27667 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27668 +
27669 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27670 if (blk_verify_command(rq->cmd, has_write_perm))
27671 return -EPERM;
27672 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27673 index 7c668c8..db3521c 100644
27674 --- a/block/compat_ioctl.c
27675 +++ b/block/compat_ioctl.c
27676 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27677 err |= __get_user(f->spec1, &uf->spec1);
27678 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27679 err |= __get_user(name, &uf->name);
27680 - f->name = compat_ptr(name);
27681 + f->name = (void __force_kernel *)compat_ptr(name);
27682 if (err) {
27683 err = -EFAULT;
27684 goto out;
27685 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27686 index 6296b40..417c00f 100644
27687 --- a/block/partitions/efi.c
27688 +++ b/block/partitions/efi.c
27689 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27690 if (!gpt)
27691 return NULL;
27692
27693 + if (!le32_to_cpu(gpt->num_partition_entries))
27694 + return NULL;
27695 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27696 + if (!pte)
27697 + return NULL;
27698 +
27699 count = le32_to_cpu(gpt->num_partition_entries) *
27700 le32_to_cpu(gpt->sizeof_partition_entry);
27701 - if (!count)
27702 - return NULL;
27703 - pte = kzalloc(count, GFP_KERNEL);
27704 - if (!pte)
27705 - return NULL;
27706 -
27707 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27708 (u8 *) pte,
27709 count) < count) {
27710 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27711 index 9a87daa..fb17486 100644
27712 --- a/block/scsi_ioctl.c
27713 +++ b/block/scsi_ioctl.c
27714 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27715 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27716 struct sg_io_hdr *hdr, fmode_t mode)
27717 {
27718 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27719 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27720 + unsigned char *cmdptr;
27721 +
27722 + if (rq->cmd != rq->__cmd)
27723 + cmdptr = rq->cmd;
27724 + else
27725 + cmdptr = tmpcmd;
27726 +
27727 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27728 return -EFAULT;
27729 +
27730 + if (cmdptr != rq->cmd)
27731 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27732 +
27733 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27734 return -EPERM;
27735
27736 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27737 int err;
27738 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27739 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27740 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27741 + unsigned char *cmdptr;
27742
27743 if (!sic)
27744 return -EINVAL;
27745 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27746 */
27747 err = -EFAULT;
27748 rq->cmd_len = cmdlen;
27749 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27750 +
27751 + if (rq->cmd != rq->__cmd)
27752 + cmdptr = rq->cmd;
27753 + else
27754 + cmdptr = tmpcmd;
27755 +
27756 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27757 goto error;
27758
27759 + if (rq->cmd != cmdptr)
27760 + memcpy(rq->cmd, cmdptr, cmdlen);
27761 +
27762 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27763 goto error;
27764
27765 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27766 index 671d4d6..5f24030 100644
27767 --- a/crypto/cryptd.c
27768 +++ b/crypto/cryptd.c
27769 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27770
27771 struct cryptd_blkcipher_request_ctx {
27772 crypto_completion_t complete;
27773 -};
27774 +} __no_const;
27775
27776 struct cryptd_hash_ctx {
27777 struct crypto_shash *child;
27778 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27779
27780 struct cryptd_aead_request_ctx {
27781 crypto_completion_t complete;
27782 -};
27783 +} __no_const;
27784
27785 static void cryptd_queue_worker(struct work_struct *work);
27786
27787 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27788 index e6defd8..c26a225 100644
27789 --- a/drivers/acpi/apei/cper.c
27790 +++ b/drivers/acpi/apei/cper.c
27791 @@ -38,12 +38,12 @@
27792 */
27793 u64 cper_next_record_id(void)
27794 {
27795 - static atomic64_t seq;
27796 + static atomic64_unchecked_t seq;
27797
27798 - if (!atomic64_read(&seq))
27799 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27800 + if (!atomic64_read_unchecked(&seq))
27801 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27802
27803 - return atomic64_inc_return(&seq);
27804 + return atomic64_inc_return_unchecked(&seq);
27805 }
27806 EXPORT_SYMBOL_GPL(cper_next_record_id);
27807
27808 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27809 index 7586544..636a2f0 100644
27810 --- a/drivers/acpi/ec_sys.c
27811 +++ b/drivers/acpi/ec_sys.c
27812 @@ -12,6 +12,7 @@
27813 #include <linux/acpi.h>
27814 #include <linux/debugfs.h>
27815 #include <linux/module.h>
27816 +#include <linux/uaccess.h>
27817 #include "internal.h"
27818
27819 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27820 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27821 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27822 */
27823 unsigned int size = EC_SPACE_SIZE;
27824 - u8 *data = (u8 *) buf;
27825 + u8 data;
27826 loff_t init_off = *off;
27827 int err = 0;
27828
27829 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27830 size = count;
27831
27832 while (size) {
27833 - err = ec_read(*off, &data[*off - init_off]);
27834 + err = ec_read(*off, &data);
27835 if (err)
27836 return err;
27837 + if (put_user(data, &buf[*off - init_off]))
27838 + return -EFAULT;
27839 *off += 1;
27840 size--;
27841 }
27842 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27843
27844 unsigned int size = count;
27845 loff_t init_off = *off;
27846 - u8 *data = (u8 *) buf;
27847 int err = 0;
27848
27849 if (*off >= EC_SPACE_SIZE)
27850 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27851 }
27852
27853 while (size) {
27854 - u8 byte_write = data[*off - init_off];
27855 + u8 byte_write;
27856 + if (get_user(byte_write, &buf[*off - init_off]))
27857 + return -EFAULT;
27858 err = ec_write(*off, byte_write);
27859 if (err)
27860 return err;
27861 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27862 index 251c7b62..000462d 100644
27863 --- a/drivers/acpi/proc.c
27864 +++ b/drivers/acpi/proc.c
27865 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27866 size_t count, loff_t * ppos)
27867 {
27868 struct list_head *node, *next;
27869 - char strbuf[5];
27870 - char str[5] = "";
27871 - unsigned int len = count;
27872 + char strbuf[5] = {0};
27873
27874 - if (len > 4)
27875 - len = 4;
27876 - if (len < 0)
27877 + if (count > 4)
27878 + count = 4;
27879 + if (copy_from_user(strbuf, buffer, count))
27880 return -EFAULT;
27881 -
27882 - if (copy_from_user(strbuf, buffer, len))
27883 - return -EFAULT;
27884 - strbuf[len] = '\0';
27885 - sscanf(strbuf, "%s", str);
27886 + strbuf[count] = '\0';
27887
27888 mutex_lock(&acpi_device_lock);
27889 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27890 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27891 if (!dev->wakeup.flags.valid)
27892 continue;
27893
27894 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27895 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27896 if (device_can_wakeup(&dev->dev)) {
27897 bool enable = !device_may_wakeup(&dev->dev);
27898 device_set_wakeup_enable(&dev->dev, enable);
27899 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27900 index bfc31cb..8213ce1 100644
27901 --- a/drivers/acpi/processor_driver.c
27902 +++ b/drivers/acpi/processor_driver.c
27903 @@ -551,7 +551,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27904 return 0;
27905 #endif
27906
27907 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27908 + BUG_ON(pr->id >= nr_cpu_ids);
27909
27910 /*
27911 * Buggy BIOS check
27912 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27913 index 8e1039c..ea9cbd4 100644
27914 --- a/drivers/ata/libata-core.c
27915 +++ b/drivers/ata/libata-core.c
27916 @@ -4750,7 +4750,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27917 struct ata_port *ap;
27918 unsigned int tag;
27919
27920 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27921 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27922 ap = qc->ap;
27923
27924 qc->flags = 0;
27925 @@ -4766,7 +4766,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27926 struct ata_port *ap;
27927 struct ata_link *link;
27928
27929 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27930 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27931 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27932 ap = qc->ap;
27933 link = qc->dev->link;
27934 @@ -5828,6 +5828,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27935 return;
27936
27937 spin_lock(&lock);
27938 + pax_open_kernel();
27939
27940 for (cur = ops->inherits; cur; cur = cur->inherits) {
27941 void **inherit = (void **)cur;
27942 @@ -5841,8 +5842,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27943 if (IS_ERR(*pp))
27944 *pp = NULL;
27945
27946 - ops->inherits = NULL;
27947 + *(struct ata_port_operations **)&ops->inherits = NULL;
27948
27949 + pax_close_kernel();
27950 spin_unlock(&lock);
27951 }
27952
27953 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27954 index bfaa5cb..3ba1cc3 100644
27955 --- a/drivers/ata/pata_arasan_cf.c
27956 +++ b/drivers/ata/pata_arasan_cf.c
27957 @@ -854,7 +854,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27958 /* Handle platform specific quirks */
27959 if (pdata->quirk) {
27960 if (pdata->quirk & CF_BROKEN_PIO) {
27961 - ap->ops->set_piomode = NULL;
27962 + pax_open_kernel();
27963 + *(void **)&ap->ops->set_piomode = NULL;
27964 + pax_close_kernel();
27965 ap->pio_mask = 0;
27966 }
27967 if (pdata->quirk & CF_BROKEN_MWDMA)
27968 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27969 index f9b983a..887b9d8 100644
27970 --- a/drivers/atm/adummy.c
27971 +++ b/drivers/atm/adummy.c
27972 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27973 vcc->pop(vcc, skb);
27974 else
27975 dev_kfree_skb_any(skb);
27976 - atomic_inc(&vcc->stats->tx);
27977 + atomic_inc_unchecked(&vcc->stats->tx);
27978
27979 return 0;
27980 }
27981 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27982 index 89b30f3..7964211 100644
27983 --- a/drivers/atm/ambassador.c
27984 +++ b/drivers/atm/ambassador.c
27985 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27986 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27987
27988 // VC layer stats
27989 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27990 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27991
27992 // free the descriptor
27993 kfree (tx_descr);
27994 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27995 dump_skb ("<<<", vc, skb);
27996
27997 // VC layer stats
27998 - atomic_inc(&atm_vcc->stats->rx);
27999 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28000 __net_timestamp(skb);
28001 // end of our responsibility
28002 atm_vcc->push (atm_vcc, skb);
28003 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
28004 } else {
28005 PRINTK (KERN_INFO, "dropped over-size frame");
28006 // should we count this?
28007 - atomic_inc(&atm_vcc->stats->rx_drop);
28008 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28009 }
28010
28011 } else {
28012 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
28013 }
28014
28015 if (check_area (skb->data, skb->len)) {
28016 - atomic_inc(&atm_vcc->stats->tx_err);
28017 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
28018 return -ENOMEM; // ?
28019 }
28020
28021 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
28022 index b22d71c..d6e1049 100644
28023 --- a/drivers/atm/atmtcp.c
28024 +++ b/drivers/atm/atmtcp.c
28025 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28026 if (vcc->pop) vcc->pop(vcc,skb);
28027 else dev_kfree_skb(skb);
28028 if (dev_data) return 0;
28029 - atomic_inc(&vcc->stats->tx_err);
28030 + atomic_inc_unchecked(&vcc->stats->tx_err);
28031 return -ENOLINK;
28032 }
28033 size = skb->len+sizeof(struct atmtcp_hdr);
28034 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28035 if (!new_skb) {
28036 if (vcc->pop) vcc->pop(vcc,skb);
28037 else dev_kfree_skb(skb);
28038 - atomic_inc(&vcc->stats->tx_err);
28039 + atomic_inc_unchecked(&vcc->stats->tx_err);
28040 return -ENOBUFS;
28041 }
28042 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
28043 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28044 if (vcc->pop) vcc->pop(vcc,skb);
28045 else dev_kfree_skb(skb);
28046 out_vcc->push(out_vcc,new_skb);
28047 - atomic_inc(&vcc->stats->tx);
28048 - atomic_inc(&out_vcc->stats->rx);
28049 + atomic_inc_unchecked(&vcc->stats->tx);
28050 + atomic_inc_unchecked(&out_vcc->stats->rx);
28051 return 0;
28052 }
28053
28054 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28055 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28056 read_unlock(&vcc_sklist_lock);
28057 if (!out_vcc) {
28058 - atomic_inc(&vcc->stats->tx_err);
28059 + atomic_inc_unchecked(&vcc->stats->tx_err);
28060 goto done;
28061 }
28062 skb_pull(skb,sizeof(struct atmtcp_hdr));
28063 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28064 __net_timestamp(new_skb);
28065 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28066 out_vcc->push(out_vcc,new_skb);
28067 - atomic_inc(&vcc->stats->tx);
28068 - atomic_inc(&out_vcc->stats->rx);
28069 + atomic_inc_unchecked(&vcc->stats->tx);
28070 + atomic_inc_unchecked(&out_vcc->stats->rx);
28071 done:
28072 if (vcc->pop) vcc->pop(vcc,skb);
28073 else dev_kfree_skb(skb);
28074 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28075 index 2059ee4..faf51c7 100644
28076 --- a/drivers/atm/eni.c
28077 +++ b/drivers/atm/eni.c
28078 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28079 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28080 vcc->dev->number);
28081 length = 0;
28082 - atomic_inc(&vcc->stats->rx_err);
28083 + atomic_inc_unchecked(&vcc->stats->rx_err);
28084 }
28085 else {
28086 length = ATM_CELL_SIZE-1; /* no HEC */
28087 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28088 size);
28089 }
28090 eff = length = 0;
28091 - atomic_inc(&vcc->stats->rx_err);
28092 + atomic_inc_unchecked(&vcc->stats->rx_err);
28093 }
28094 else {
28095 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28096 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28097 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28098 vcc->dev->number,vcc->vci,length,size << 2,descr);
28099 length = eff = 0;
28100 - atomic_inc(&vcc->stats->rx_err);
28101 + atomic_inc_unchecked(&vcc->stats->rx_err);
28102 }
28103 }
28104 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28105 @@ -767,7 +767,7 @@ rx_dequeued++;
28106 vcc->push(vcc,skb);
28107 pushed++;
28108 }
28109 - atomic_inc(&vcc->stats->rx);
28110 + atomic_inc_unchecked(&vcc->stats->rx);
28111 }
28112 wake_up(&eni_dev->rx_wait);
28113 }
28114 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28115 PCI_DMA_TODEVICE);
28116 if (vcc->pop) vcc->pop(vcc,skb);
28117 else dev_kfree_skb_irq(skb);
28118 - atomic_inc(&vcc->stats->tx);
28119 + atomic_inc_unchecked(&vcc->stats->tx);
28120 wake_up(&eni_dev->tx_wait);
28121 dma_complete++;
28122 }
28123 @@ -1567,7 +1567,7 @@ tx_complete++;
28124 /*--------------------------------- entries ---------------------------------*/
28125
28126
28127 -static const char *media_name[] __devinitdata = {
28128 +static const char *media_name[] __devinitconst = {
28129 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28130 "UTP", "05?", "06?", "07?", /* 4- 7 */
28131 "TAXI","09?", "10?", "11?", /* 8-11 */
28132 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28133 index 86fed1b..6dc4721 100644
28134 --- a/drivers/atm/firestream.c
28135 +++ b/drivers/atm/firestream.c
28136 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28137 }
28138 }
28139
28140 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28141 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28142
28143 fs_dprintk (FS_DEBUG_TXMEM, "i");
28144 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28145 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28146 #endif
28147 skb_put (skb, qe->p1 & 0xffff);
28148 ATM_SKB(skb)->vcc = atm_vcc;
28149 - atomic_inc(&atm_vcc->stats->rx);
28150 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28151 __net_timestamp(skb);
28152 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28153 atm_vcc->push (atm_vcc, skb);
28154 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28155 kfree (pe);
28156 }
28157 if (atm_vcc)
28158 - atomic_inc(&atm_vcc->stats->rx_drop);
28159 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28160 break;
28161 case 0x1f: /* Reassembly abort: no buffers. */
28162 /* Silently increment error counter. */
28163 if (atm_vcc)
28164 - atomic_inc(&atm_vcc->stats->rx_drop);
28165 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28166 break;
28167 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28168 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28169 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28170 index 361f5ae..7fc552d 100644
28171 --- a/drivers/atm/fore200e.c
28172 +++ b/drivers/atm/fore200e.c
28173 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28174 #endif
28175 /* check error condition */
28176 if (*entry->status & STATUS_ERROR)
28177 - atomic_inc(&vcc->stats->tx_err);
28178 + atomic_inc_unchecked(&vcc->stats->tx_err);
28179 else
28180 - atomic_inc(&vcc->stats->tx);
28181 + atomic_inc_unchecked(&vcc->stats->tx);
28182 }
28183 }
28184
28185 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28186 if (skb == NULL) {
28187 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28188
28189 - atomic_inc(&vcc->stats->rx_drop);
28190 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28191 return -ENOMEM;
28192 }
28193
28194 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28195
28196 dev_kfree_skb_any(skb);
28197
28198 - atomic_inc(&vcc->stats->rx_drop);
28199 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28200 return -ENOMEM;
28201 }
28202
28203 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28204
28205 vcc->push(vcc, skb);
28206 - atomic_inc(&vcc->stats->rx);
28207 + atomic_inc_unchecked(&vcc->stats->rx);
28208
28209 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28210
28211 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28212 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28213 fore200e->atm_dev->number,
28214 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28215 - atomic_inc(&vcc->stats->rx_err);
28216 + atomic_inc_unchecked(&vcc->stats->rx_err);
28217 }
28218 }
28219
28220 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28221 goto retry_here;
28222 }
28223
28224 - atomic_inc(&vcc->stats->tx_err);
28225 + atomic_inc_unchecked(&vcc->stats->tx_err);
28226
28227 fore200e->tx_sat++;
28228 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28229 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28230 index b182c2f..1c6fa8a 100644
28231 --- a/drivers/atm/he.c
28232 +++ b/drivers/atm/he.c
28233 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28234
28235 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28236 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28237 - atomic_inc(&vcc->stats->rx_drop);
28238 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28239 goto return_host_buffers;
28240 }
28241
28242 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28243 RBRQ_LEN_ERR(he_dev->rbrq_head)
28244 ? "LEN_ERR" : "",
28245 vcc->vpi, vcc->vci);
28246 - atomic_inc(&vcc->stats->rx_err);
28247 + atomic_inc_unchecked(&vcc->stats->rx_err);
28248 goto return_host_buffers;
28249 }
28250
28251 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28252 vcc->push(vcc, skb);
28253 spin_lock(&he_dev->global_lock);
28254
28255 - atomic_inc(&vcc->stats->rx);
28256 + atomic_inc_unchecked(&vcc->stats->rx);
28257
28258 return_host_buffers:
28259 ++pdus_assembled;
28260 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28261 tpd->vcc->pop(tpd->vcc, tpd->skb);
28262 else
28263 dev_kfree_skb_any(tpd->skb);
28264 - atomic_inc(&tpd->vcc->stats->tx_err);
28265 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28266 }
28267 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28268 return;
28269 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28270 vcc->pop(vcc, skb);
28271 else
28272 dev_kfree_skb_any(skb);
28273 - atomic_inc(&vcc->stats->tx_err);
28274 + atomic_inc_unchecked(&vcc->stats->tx_err);
28275 return -EINVAL;
28276 }
28277
28278 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28279 vcc->pop(vcc, skb);
28280 else
28281 dev_kfree_skb_any(skb);
28282 - atomic_inc(&vcc->stats->tx_err);
28283 + atomic_inc_unchecked(&vcc->stats->tx_err);
28284 return -EINVAL;
28285 }
28286 #endif
28287 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28288 vcc->pop(vcc, skb);
28289 else
28290 dev_kfree_skb_any(skb);
28291 - atomic_inc(&vcc->stats->tx_err);
28292 + atomic_inc_unchecked(&vcc->stats->tx_err);
28293 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28294 return -ENOMEM;
28295 }
28296 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28297 vcc->pop(vcc, skb);
28298 else
28299 dev_kfree_skb_any(skb);
28300 - atomic_inc(&vcc->stats->tx_err);
28301 + atomic_inc_unchecked(&vcc->stats->tx_err);
28302 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28303 return -ENOMEM;
28304 }
28305 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28306 __enqueue_tpd(he_dev, tpd, cid);
28307 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28308
28309 - atomic_inc(&vcc->stats->tx);
28310 + atomic_inc_unchecked(&vcc->stats->tx);
28311
28312 return 0;
28313 }
28314 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28315 index 7d01c2a..4e3ac01 100644
28316 --- a/drivers/atm/horizon.c
28317 +++ b/drivers/atm/horizon.c
28318 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28319 {
28320 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28321 // VC layer stats
28322 - atomic_inc(&vcc->stats->rx);
28323 + atomic_inc_unchecked(&vcc->stats->rx);
28324 __net_timestamp(skb);
28325 // end of our responsibility
28326 vcc->push (vcc, skb);
28327 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28328 dev->tx_iovec = NULL;
28329
28330 // VC layer stats
28331 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28332 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28333
28334 // free the skb
28335 hrz_kfree_skb (skb);
28336 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28337 index 8974bd2..b856f85 100644
28338 --- a/drivers/atm/idt77252.c
28339 +++ b/drivers/atm/idt77252.c
28340 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28341 else
28342 dev_kfree_skb(skb);
28343
28344 - atomic_inc(&vcc->stats->tx);
28345 + atomic_inc_unchecked(&vcc->stats->tx);
28346 }
28347
28348 atomic_dec(&scq->used);
28349 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28350 if ((sb = dev_alloc_skb(64)) == NULL) {
28351 printk("%s: Can't allocate buffers for aal0.\n",
28352 card->name);
28353 - atomic_add(i, &vcc->stats->rx_drop);
28354 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28355 break;
28356 }
28357 if (!atm_charge(vcc, sb->truesize)) {
28358 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28359 card->name);
28360 - atomic_add(i - 1, &vcc->stats->rx_drop);
28361 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28362 dev_kfree_skb(sb);
28363 break;
28364 }
28365 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28366 ATM_SKB(sb)->vcc = vcc;
28367 __net_timestamp(sb);
28368 vcc->push(vcc, sb);
28369 - atomic_inc(&vcc->stats->rx);
28370 + atomic_inc_unchecked(&vcc->stats->rx);
28371
28372 cell += ATM_CELL_PAYLOAD;
28373 }
28374 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28375 "(CDC: %08x)\n",
28376 card->name, len, rpp->len, readl(SAR_REG_CDC));
28377 recycle_rx_pool_skb(card, rpp);
28378 - atomic_inc(&vcc->stats->rx_err);
28379 + atomic_inc_unchecked(&vcc->stats->rx_err);
28380 return;
28381 }
28382 if (stat & SAR_RSQE_CRC) {
28383 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28384 recycle_rx_pool_skb(card, rpp);
28385 - atomic_inc(&vcc->stats->rx_err);
28386 + atomic_inc_unchecked(&vcc->stats->rx_err);
28387 return;
28388 }
28389 if (skb_queue_len(&rpp->queue) > 1) {
28390 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28391 RXPRINTK("%s: Can't alloc RX skb.\n",
28392 card->name);
28393 recycle_rx_pool_skb(card, rpp);
28394 - atomic_inc(&vcc->stats->rx_err);
28395 + atomic_inc_unchecked(&vcc->stats->rx_err);
28396 return;
28397 }
28398 if (!atm_charge(vcc, skb->truesize)) {
28399 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28400 __net_timestamp(skb);
28401
28402 vcc->push(vcc, skb);
28403 - atomic_inc(&vcc->stats->rx);
28404 + atomic_inc_unchecked(&vcc->stats->rx);
28405
28406 return;
28407 }
28408 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28409 __net_timestamp(skb);
28410
28411 vcc->push(vcc, skb);
28412 - atomic_inc(&vcc->stats->rx);
28413 + atomic_inc_unchecked(&vcc->stats->rx);
28414
28415 if (skb->truesize > SAR_FB_SIZE_3)
28416 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28417 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28418 if (vcc->qos.aal != ATM_AAL0) {
28419 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28420 card->name, vpi, vci);
28421 - atomic_inc(&vcc->stats->rx_drop);
28422 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28423 goto drop;
28424 }
28425
28426 if ((sb = dev_alloc_skb(64)) == NULL) {
28427 printk("%s: Can't allocate buffers for AAL0.\n",
28428 card->name);
28429 - atomic_inc(&vcc->stats->rx_err);
28430 + atomic_inc_unchecked(&vcc->stats->rx_err);
28431 goto drop;
28432 }
28433
28434 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28435 ATM_SKB(sb)->vcc = vcc;
28436 __net_timestamp(sb);
28437 vcc->push(vcc, sb);
28438 - atomic_inc(&vcc->stats->rx);
28439 + atomic_inc_unchecked(&vcc->stats->rx);
28440
28441 drop:
28442 skb_pull(queue, 64);
28443 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28444
28445 if (vc == NULL) {
28446 printk("%s: NULL connection in send().\n", card->name);
28447 - atomic_inc(&vcc->stats->tx_err);
28448 + atomic_inc_unchecked(&vcc->stats->tx_err);
28449 dev_kfree_skb(skb);
28450 return -EINVAL;
28451 }
28452 if (!test_bit(VCF_TX, &vc->flags)) {
28453 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28454 - atomic_inc(&vcc->stats->tx_err);
28455 + atomic_inc_unchecked(&vcc->stats->tx_err);
28456 dev_kfree_skb(skb);
28457 return -EINVAL;
28458 }
28459 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28460 break;
28461 default:
28462 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28463 - atomic_inc(&vcc->stats->tx_err);
28464 + atomic_inc_unchecked(&vcc->stats->tx_err);
28465 dev_kfree_skb(skb);
28466 return -EINVAL;
28467 }
28468
28469 if (skb_shinfo(skb)->nr_frags != 0) {
28470 printk("%s: No scatter-gather yet.\n", card->name);
28471 - atomic_inc(&vcc->stats->tx_err);
28472 + atomic_inc_unchecked(&vcc->stats->tx_err);
28473 dev_kfree_skb(skb);
28474 return -EINVAL;
28475 }
28476 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28477
28478 err = queue_skb(card, vc, skb, oam);
28479 if (err) {
28480 - atomic_inc(&vcc->stats->tx_err);
28481 + atomic_inc_unchecked(&vcc->stats->tx_err);
28482 dev_kfree_skb(skb);
28483 return err;
28484 }
28485 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28486 skb = dev_alloc_skb(64);
28487 if (!skb) {
28488 printk("%s: Out of memory in send_oam().\n", card->name);
28489 - atomic_inc(&vcc->stats->tx_err);
28490 + atomic_inc_unchecked(&vcc->stats->tx_err);
28491 return -ENOMEM;
28492 }
28493 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28494 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28495 index 96cce6d..62c3ec5 100644
28496 --- a/drivers/atm/iphase.c
28497 +++ b/drivers/atm/iphase.c
28498 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28499 status = (u_short) (buf_desc_ptr->desc_mode);
28500 if (status & (RX_CER | RX_PTE | RX_OFL))
28501 {
28502 - atomic_inc(&vcc->stats->rx_err);
28503 + atomic_inc_unchecked(&vcc->stats->rx_err);
28504 IF_ERR(printk("IA: bad packet, dropping it");)
28505 if (status & RX_CER) {
28506 IF_ERR(printk(" cause: packet CRC error\n");)
28507 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28508 len = dma_addr - buf_addr;
28509 if (len > iadev->rx_buf_sz) {
28510 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28511 - atomic_inc(&vcc->stats->rx_err);
28512 + atomic_inc_unchecked(&vcc->stats->rx_err);
28513 goto out_free_desc;
28514 }
28515
28516 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28517 ia_vcc = INPH_IA_VCC(vcc);
28518 if (ia_vcc == NULL)
28519 {
28520 - atomic_inc(&vcc->stats->rx_err);
28521 + atomic_inc_unchecked(&vcc->stats->rx_err);
28522 atm_return(vcc, skb->truesize);
28523 dev_kfree_skb_any(skb);
28524 goto INCR_DLE;
28525 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28526 if ((length > iadev->rx_buf_sz) || (length >
28527 (skb->len - sizeof(struct cpcs_trailer))))
28528 {
28529 - atomic_inc(&vcc->stats->rx_err);
28530 + atomic_inc_unchecked(&vcc->stats->rx_err);
28531 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28532 length, skb->len);)
28533 atm_return(vcc, skb->truesize);
28534 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28535
28536 IF_RX(printk("rx_dle_intr: skb push");)
28537 vcc->push(vcc,skb);
28538 - atomic_inc(&vcc->stats->rx);
28539 + atomic_inc_unchecked(&vcc->stats->rx);
28540 iadev->rx_pkt_cnt++;
28541 }
28542 INCR_DLE:
28543 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28544 {
28545 struct k_sonet_stats *stats;
28546 stats = &PRIV(_ia_dev[board])->sonet_stats;
28547 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28548 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28549 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28550 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28551 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28552 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28553 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28554 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28555 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28556 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28557 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28558 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28559 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28560 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28561 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28562 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28563 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28564 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28565 }
28566 ia_cmds.status = 0;
28567 break;
28568 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28569 if ((desc == 0) || (desc > iadev->num_tx_desc))
28570 {
28571 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28572 - atomic_inc(&vcc->stats->tx);
28573 + atomic_inc_unchecked(&vcc->stats->tx);
28574 if (vcc->pop)
28575 vcc->pop(vcc, skb);
28576 else
28577 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28578 ATM_DESC(skb) = vcc->vci;
28579 skb_queue_tail(&iadev->tx_dma_q, skb);
28580
28581 - atomic_inc(&vcc->stats->tx);
28582 + atomic_inc_unchecked(&vcc->stats->tx);
28583 iadev->tx_pkt_cnt++;
28584 /* Increment transaction counter */
28585 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28586
28587 #if 0
28588 /* add flow control logic */
28589 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28590 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28591 if (iavcc->vc_desc_cnt > 10) {
28592 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28593 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28594 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28595 index 68c7588..7036683 100644
28596 --- a/drivers/atm/lanai.c
28597 +++ b/drivers/atm/lanai.c
28598 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28599 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28600 lanai_endtx(lanai, lvcc);
28601 lanai_free_skb(lvcc->tx.atmvcc, skb);
28602 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28603 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28604 }
28605
28606 /* Try to fill the buffer - don't call unless there is backlog */
28607 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28608 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28609 __net_timestamp(skb);
28610 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28611 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28612 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28613 out:
28614 lvcc->rx.buf.ptr = end;
28615 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28616 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28617 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28618 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28619 lanai->stats.service_rxnotaal5++;
28620 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28621 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28622 return 0;
28623 }
28624 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28625 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28626 int bytes;
28627 read_unlock(&vcc_sklist_lock);
28628 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28629 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28630 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28631 lvcc->stats.x.aal5.service_trash++;
28632 bytes = (SERVICE_GET_END(s) * 16) -
28633 (((unsigned long) lvcc->rx.buf.ptr) -
28634 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28635 }
28636 if (s & SERVICE_STREAM) {
28637 read_unlock(&vcc_sklist_lock);
28638 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28639 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28640 lvcc->stats.x.aal5.service_stream++;
28641 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28642 "PDU on VCI %d!\n", lanai->number, vci);
28643 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28644 return 0;
28645 }
28646 DPRINTK("got rx crc error on vci %d\n", vci);
28647 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28648 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28649 lvcc->stats.x.aal5.service_rxcrc++;
28650 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28651 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28652 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28653 index 1c70c45..300718d 100644
28654 --- a/drivers/atm/nicstar.c
28655 +++ b/drivers/atm/nicstar.c
28656 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28657 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28658 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28659 card->index);
28660 - atomic_inc(&vcc->stats->tx_err);
28661 + atomic_inc_unchecked(&vcc->stats->tx_err);
28662 dev_kfree_skb_any(skb);
28663 return -EINVAL;
28664 }
28665 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28666 if (!vc->tx) {
28667 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28668 card->index);
28669 - atomic_inc(&vcc->stats->tx_err);
28670 + atomic_inc_unchecked(&vcc->stats->tx_err);
28671 dev_kfree_skb_any(skb);
28672 return -EINVAL;
28673 }
28674 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28675 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28676 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28677 card->index);
28678 - atomic_inc(&vcc->stats->tx_err);
28679 + atomic_inc_unchecked(&vcc->stats->tx_err);
28680 dev_kfree_skb_any(skb);
28681 return -EINVAL;
28682 }
28683
28684 if (skb_shinfo(skb)->nr_frags != 0) {
28685 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28686 - atomic_inc(&vcc->stats->tx_err);
28687 + atomic_inc_unchecked(&vcc->stats->tx_err);
28688 dev_kfree_skb_any(skb);
28689 return -EINVAL;
28690 }
28691 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28692 }
28693
28694 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28695 - atomic_inc(&vcc->stats->tx_err);
28696 + atomic_inc_unchecked(&vcc->stats->tx_err);
28697 dev_kfree_skb_any(skb);
28698 return -EIO;
28699 }
28700 - atomic_inc(&vcc->stats->tx);
28701 + atomic_inc_unchecked(&vcc->stats->tx);
28702
28703 return 0;
28704 }
28705 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28706 printk
28707 ("nicstar%d: Can't allocate buffers for aal0.\n",
28708 card->index);
28709 - atomic_add(i, &vcc->stats->rx_drop);
28710 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28711 break;
28712 }
28713 if (!atm_charge(vcc, sb->truesize)) {
28714 RXPRINTK
28715 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28716 card->index);
28717 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28718 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28719 dev_kfree_skb_any(sb);
28720 break;
28721 }
28722 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28723 ATM_SKB(sb)->vcc = vcc;
28724 __net_timestamp(sb);
28725 vcc->push(vcc, sb);
28726 - atomic_inc(&vcc->stats->rx);
28727 + atomic_inc_unchecked(&vcc->stats->rx);
28728 cell += ATM_CELL_PAYLOAD;
28729 }
28730
28731 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28732 if (iovb == NULL) {
28733 printk("nicstar%d: Out of iovec buffers.\n",
28734 card->index);
28735 - atomic_inc(&vcc->stats->rx_drop);
28736 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28737 recycle_rx_buf(card, skb);
28738 return;
28739 }
28740 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28741 small or large buffer itself. */
28742 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28743 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28744 - atomic_inc(&vcc->stats->rx_err);
28745 + atomic_inc_unchecked(&vcc->stats->rx_err);
28746 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28747 NS_MAX_IOVECS);
28748 NS_PRV_IOVCNT(iovb) = 0;
28749 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28750 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28751 card->index);
28752 which_list(card, skb);
28753 - atomic_inc(&vcc->stats->rx_err);
28754 + atomic_inc_unchecked(&vcc->stats->rx_err);
28755 recycle_rx_buf(card, skb);
28756 vc->rx_iov = NULL;
28757 recycle_iov_buf(card, iovb);
28758 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28759 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28760 card->index);
28761 which_list(card, skb);
28762 - atomic_inc(&vcc->stats->rx_err);
28763 + atomic_inc_unchecked(&vcc->stats->rx_err);
28764 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28765 NS_PRV_IOVCNT(iovb));
28766 vc->rx_iov = NULL;
28767 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28768 printk(" - PDU size mismatch.\n");
28769 else
28770 printk(".\n");
28771 - atomic_inc(&vcc->stats->rx_err);
28772 + atomic_inc_unchecked(&vcc->stats->rx_err);
28773 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28774 NS_PRV_IOVCNT(iovb));
28775 vc->rx_iov = NULL;
28776 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28777 /* skb points to a small buffer */
28778 if (!atm_charge(vcc, skb->truesize)) {
28779 push_rxbufs(card, skb);
28780 - atomic_inc(&vcc->stats->rx_drop);
28781 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28782 } else {
28783 skb_put(skb, len);
28784 dequeue_sm_buf(card, skb);
28785 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28786 ATM_SKB(skb)->vcc = vcc;
28787 __net_timestamp(skb);
28788 vcc->push(vcc, skb);
28789 - atomic_inc(&vcc->stats->rx);
28790 + atomic_inc_unchecked(&vcc->stats->rx);
28791 }
28792 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28793 struct sk_buff *sb;
28794 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28795 if (len <= NS_SMBUFSIZE) {
28796 if (!atm_charge(vcc, sb->truesize)) {
28797 push_rxbufs(card, sb);
28798 - atomic_inc(&vcc->stats->rx_drop);
28799 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28800 } else {
28801 skb_put(sb, len);
28802 dequeue_sm_buf(card, sb);
28803 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28804 ATM_SKB(sb)->vcc = vcc;
28805 __net_timestamp(sb);
28806 vcc->push(vcc, sb);
28807 - atomic_inc(&vcc->stats->rx);
28808 + atomic_inc_unchecked(&vcc->stats->rx);
28809 }
28810
28811 push_rxbufs(card, skb);
28812 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28813
28814 if (!atm_charge(vcc, skb->truesize)) {
28815 push_rxbufs(card, skb);
28816 - atomic_inc(&vcc->stats->rx_drop);
28817 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28818 } else {
28819 dequeue_lg_buf(card, skb);
28820 #ifdef NS_USE_DESTRUCTORS
28821 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28822 ATM_SKB(skb)->vcc = vcc;
28823 __net_timestamp(skb);
28824 vcc->push(vcc, skb);
28825 - atomic_inc(&vcc->stats->rx);
28826 + atomic_inc_unchecked(&vcc->stats->rx);
28827 }
28828
28829 push_rxbufs(card, sb);
28830 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28831 printk
28832 ("nicstar%d: Out of huge buffers.\n",
28833 card->index);
28834 - atomic_inc(&vcc->stats->rx_drop);
28835 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28836 recycle_iovec_rx_bufs(card,
28837 (struct iovec *)
28838 iovb->data,
28839 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28840 card->hbpool.count++;
28841 } else
28842 dev_kfree_skb_any(hb);
28843 - atomic_inc(&vcc->stats->rx_drop);
28844 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28845 } else {
28846 /* Copy the small buffer to the huge buffer */
28847 sb = (struct sk_buff *)iov->iov_base;
28848 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28849 #endif /* NS_USE_DESTRUCTORS */
28850 __net_timestamp(hb);
28851 vcc->push(vcc, hb);
28852 - atomic_inc(&vcc->stats->rx);
28853 + atomic_inc_unchecked(&vcc->stats->rx);
28854 }
28855 }
28856
28857 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28858 index 9851093..adb2b1e 100644
28859 --- a/drivers/atm/solos-pci.c
28860 +++ b/drivers/atm/solos-pci.c
28861 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28862 }
28863 atm_charge(vcc, skb->truesize);
28864 vcc->push(vcc, skb);
28865 - atomic_inc(&vcc->stats->rx);
28866 + atomic_inc_unchecked(&vcc->stats->rx);
28867 break;
28868
28869 case PKT_STATUS:
28870 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28871 vcc = SKB_CB(oldskb)->vcc;
28872
28873 if (vcc) {
28874 - atomic_inc(&vcc->stats->tx);
28875 + atomic_inc_unchecked(&vcc->stats->tx);
28876 solos_pop(vcc, oldskb);
28877 } else
28878 dev_kfree_skb_irq(oldskb);
28879 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28880 index 0215934..ce9f5b1 100644
28881 --- a/drivers/atm/suni.c
28882 +++ b/drivers/atm/suni.c
28883 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28884
28885
28886 #define ADD_LIMITED(s,v) \
28887 - atomic_add((v),&stats->s); \
28888 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28889 + atomic_add_unchecked((v),&stats->s); \
28890 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28891
28892
28893 static void suni_hz(unsigned long from_timer)
28894 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28895 index 5120a96..e2572bd 100644
28896 --- a/drivers/atm/uPD98402.c
28897 +++ b/drivers/atm/uPD98402.c
28898 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28899 struct sonet_stats tmp;
28900 int error = 0;
28901
28902 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28903 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28904 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28905 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28906 if (zero && !error) {
28907 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28908
28909
28910 #define ADD_LIMITED(s,v) \
28911 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28912 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28913 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28914 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28915 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28916 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28917
28918
28919 static void stat_event(struct atm_dev *dev)
28920 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28921 if (reason & uPD98402_INT_PFM) stat_event(dev);
28922 if (reason & uPD98402_INT_PCO) {
28923 (void) GET(PCOCR); /* clear interrupt cause */
28924 - atomic_add(GET(HECCT),
28925 + atomic_add_unchecked(GET(HECCT),
28926 &PRIV(dev)->sonet_stats.uncorr_hcs);
28927 }
28928 if ((reason & uPD98402_INT_RFO) &&
28929 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28930 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28931 uPD98402_INT_LOS),PIMR); /* enable them */
28932 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28933 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28934 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28935 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28936 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28937 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28938 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28939 return 0;
28940 }
28941
28942 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28943 index abe4e20..83c4727 100644
28944 --- a/drivers/atm/zatm.c
28945 +++ b/drivers/atm/zatm.c
28946 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28947 }
28948 if (!size) {
28949 dev_kfree_skb_irq(skb);
28950 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28951 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28952 continue;
28953 }
28954 if (!atm_charge(vcc,skb->truesize)) {
28955 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28956 skb->len = size;
28957 ATM_SKB(skb)->vcc = vcc;
28958 vcc->push(vcc,skb);
28959 - atomic_inc(&vcc->stats->rx);
28960 + atomic_inc_unchecked(&vcc->stats->rx);
28961 }
28962 zout(pos & 0xffff,MTA(mbx));
28963 #if 0 /* probably a stupid idea */
28964 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28965 skb_queue_head(&zatm_vcc->backlog,skb);
28966 break;
28967 }
28968 - atomic_inc(&vcc->stats->tx);
28969 + atomic_inc_unchecked(&vcc->stats->tx);
28970 wake_up(&zatm_vcc->tx_wait);
28971 }
28972
28973 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28974 index deb4a45..211eff2 100644
28975 --- a/drivers/base/devtmpfs.c
28976 +++ b/drivers/base/devtmpfs.c
28977 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
28978 if (!thread)
28979 return 0;
28980
28981 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28982 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28983 if (err)
28984 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28985 else
28986 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28987 index cbb463b..babe2cf 100644
28988 --- a/drivers/base/power/wakeup.c
28989 +++ b/drivers/base/power/wakeup.c
28990 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28991 * They need to be modified together atomically, so it's better to use one
28992 * atomic variable to hold them both.
28993 */
28994 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28995 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28996
28997 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28998 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28999
29000 static void split_counters(unsigned int *cnt, unsigned int *inpr)
29001 {
29002 - unsigned int comb = atomic_read(&combined_event_count);
29003 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
29004
29005 *cnt = (comb >> IN_PROGRESS_BITS);
29006 *inpr = comb & MAX_IN_PROGRESS;
29007 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
29008 ws->start_prevent_time = ws->last_time;
29009
29010 /* Increment the counter of events in progress. */
29011 - cec = atomic_inc_return(&combined_event_count);
29012 + cec = atomic_inc_return_unchecked(&combined_event_count);
29013
29014 trace_wakeup_source_activate(ws->name, cec);
29015 }
29016 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
29017 * Increment the counter of registered wakeup events and decrement the
29018 * couter of wakeup events in progress simultaneously.
29019 */
29020 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
29021 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
29022 trace_wakeup_source_deactivate(ws->name, cec);
29023
29024 split_counters(&cnt, &inpr);
29025 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
29026 index b0f553b..77b928b 100644
29027 --- a/drivers/block/cciss.c
29028 +++ b/drivers/block/cciss.c
29029 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
29030 int err;
29031 u32 cp;
29032
29033 + memset(&arg64, 0, sizeof(arg64));
29034 +
29035 err = 0;
29036 err |=
29037 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
29038 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
29039 while (!list_empty(&h->reqQ)) {
29040 c = list_entry(h->reqQ.next, CommandList_struct, list);
29041 /* can't do anything if fifo is full */
29042 - if ((h->access.fifo_full(h))) {
29043 + if ((h->access->fifo_full(h))) {
29044 dev_warn(&h->pdev->dev, "fifo full\n");
29045 break;
29046 }
29047 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29048 h->Qdepth--;
29049
29050 /* Tell the controller execute command */
29051 - h->access.submit_command(h, c);
29052 + h->access->submit_command(h, c);
29053
29054 /* Put job onto the completed Q */
29055 addQ(&h->cmpQ, c);
29056 @@ -3443,17 +3445,17 @@ startio:
29057
29058 static inline unsigned long get_next_completion(ctlr_info_t *h)
29059 {
29060 - return h->access.command_completed(h);
29061 + return h->access->command_completed(h);
29062 }
29063
29064 static inline int interrupt_pending(ctlr_info_t *h)
29065 {
29066 - return h->access.intr_pending(h);
29067 + return h->access->intr_pending(h);
29068 }
29069
29070 static inline long interrupt_not_for_us(ctlr_info_t *h)
29071 {
29072 - return ((h->access.intr_pending(h) == 0) ||
29073 + return ((h->access->intr_pending(h) == 0) ||
29074 (h->interrupts_enabled == 0));
29075 }
29076
29077 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29078 u32 a;
29079
29080 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29081 - return h->access.command_completed(h);
29082 + return h->access->command_completed(h);
29083
29084 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29085 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29086 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29087 trans_support & CFGTBL_Trans_use_short_tags);
29088
29089 /* Change the access methods to the performant access methods */
29090 - h->access = SA5_performant_access;
29091 + h->access = &SA5_performant_access;
29092 h->transMethod = CFGTBL_Trans_Performant;
29093
29094 return;
29095 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29096 if (prod_index < 0)
29097 return -ENODEV;
29098 h->product_name = products[prod_index].product_name;
29099 - h->access = *(products[prod_index].access);
29100 + h->access = products[prod_index].access;
29101
29102 if (cciss_board_disabled(h)) {
29103 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29104 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29105 }
29106
29107 /* make sure the board interrupts are off */
29108 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29109 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29110 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29111 if (rc)
29112 goto clean2;
29113 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29114 * fake ones to scoop up any residual completions.
29115 */
29116 spin_lock_irqsave(&h->lock, flags);
29117 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29118 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29119 spin_unlock_irqrestore(&h->lock, flags);
29120 free_irq(h->intr[h->intr_mode], h);
29121 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29122 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29123 dev_info(&h->pdev->dev, "Board READY.\n");
29124 dev_info(&h->pdev->dev,
29125 "Waiting for stale completions to drain.\n");
29126 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29127 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29128 msleep(10000);
29129 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29130 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29131
29132 rc = controller_reset_failed(h->cfgtable);
29133 if (rc)
29134 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29135 cciss_scsi_setup(h);
29136
29137 /* Turn the interrupts on so we can service requests */
29138 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29139 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29140
29141 /* Get the firmware version */
29142 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29143 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29144 kfree(flush_buf);
29145 if (return_code != IO_OK)
29146 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29147 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29148 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29149 free_irq(h->intr[h->intr_mode], h);
29150 }
29151
29152 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29153 index 7fda30e..eb5dfe0 100644
29154 --- a/drivers/block/cciss.h
29155 +++ b/drivers/block/cciss.h
29156 @@ -101,7 +101,7 @@ struct ctlr_info
29157 /* information about each logical volume */
29158 drive_info_struct *drv[CISS_MAX_LUN];
29159
29160 - struct access_method access;
29161 + struct access_method *access;
29162
29163 /* queue and queue Info */
29164 struct list_head reqQ;
29165 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29166 index 9125bbe..eede5c8 100644
29167 --- a/drivers/block/cpqarray.c
29168 +++ b/drivers/block/cpqarray.c
29169 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29170 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29171 goto Enomem4;
29172 }
29173 - hba[i]->access.set_intr_mask(hba[i], 0);
29174 + hba[i]->access->set_intr_mask(hba[i], 0);
29175 if (request_irq(hba[i]->intr, do_ida_intr,
29176 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29177 {
29178 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29179 add_timer(&hba[i]->timer);
29180
29181 /* Enable IRQ now that spinlock and rate limit timer are set up */
29182 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29183 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29184
29185 for(j=0; j<NWD; j++) {
29186 struct gendisk *disk = ida_gendisk[i][j];
29187 @@ -694,7 +694,7 @@ DBGINFO(
29188 for(i=0; i<NR_PRODUCTS; i++) {
29189 if (board_id == products[i].board_id) {
29190 c->product_name = products[i].product_name;
29191 - c->access = *(products[i].access);
29192 + c->access = products[i].access;
29193 break;
29194 }
29195 }
29196 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29197 hba[ctlr]->intr = intr;
29198 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29199 hba[ctlr]->product_name = products[j].product_name;
29200 - hba[ctlr]->access = *(products[j].access);
29201 + hba[ctlr]->access = products[j].access;
29202 hba[ctlr]->ctlr = ctlr;
29203 hba[ctlr]->board_id = board_id;
29204 hba[ctlr]->pci_dev = NULL; /* not PCI */
29205 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29206
29207 while((c = h->reqQ) != NULL) {
29208 /* Can't do anything if we're busy */
29209 - if (h->access.fifo_full(h) == 0)
29210 + if (h->access->fifo_full(h) == 0)
29211 return;
29212
29213 /* Get the first entry from the request Q */
29214 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29215 h->Qdepth--;
29216
29217 /* Tell the controller to do our bidding */
29218 - h->access.submit_command(h, c);
29219 + h->access->submit_command(h, c);
29220
29221 /* Get onto the completion Q */
29222 addQ(&h->cmpQ, c);
29223 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29224 unsigned long flags;
29225 __u32 a,a1;
29226
29227 - istat = h->access.intr_pending(h);
29228 + istat = h->access->intr_pending(h);
29229 /* Is this interrupt for us? */
29230 if (istat == 0)
29231 return IRQ_NONE;
29232 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29233 */
29234 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29235 if (istat & FIFO_NOT_EMPTY) {
29236 - while((a = h->access.command_completed(h))) {
29237 + while((a = h->access->command_completed(h))) {
29238 a1 = a; a &= ~3;
29239 if ((c = h->cmpQ) == NULL)
29240 {
29241 @@ -1449,11 +1449,11 @@ static int sendcmd(
29242 /*
29243 * Disable interrupt
29244 */
29245 - info_p->access.set_intr_mask(info_p, 0);
29246 + info_p->access->set_intr_mask(info_p, 0);
29247 /* Make sure there is room in the command FIFO */
29248 /* Actually it should be completely empty at this time. */
29249 for (i = 200000; i > 0; i--) {
29250 - temp = info_p->access.fifo_full(info_p);
29251 + temp = info_p->access->fifo_full(info_p);
29252 if (temp != 0) {
29253 break;
29254 }
29255 @@ -1466,7 +1466,7 @@ DBG(
29256 /*
29257 * Send the cmd
29258 */
29259 - info_p->access.submit_command(info_p, c);
29260 + info_p->access->submit_command(info_p, c);
29261 complete = pollcomplete(ctlr);
29262
29263 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29264 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29265 * we check the new geometry. Then turn interrupts back on when
29266 * we're done.
29267 */
29268 - host->access.set_intr_mask(host, 0);
29269 + host->access->set_intr_mask(host, 0);
29270 getgeometry(ctlr);
29271 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29272 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29273
29274 for(i=0; i<NWD; i++) {
29275 struct gendisk *disk = ida_gendisk[ctlr][i];
29276 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29277 /* Wait (up to 2 seconds) for a command to complete */
29278
29279 for (i = 200000; i > 0; i--) {
29280 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29281 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29282 if (done == 0) {
29283 udelay(10); /* a short fixed delay */
29284 } else
29285 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29286 index be73e9d..7fbf140 100644
29287 --- a/drivers/block/cpqarray.h
29288 +++ b/drivers/block/cpqarray.h
29289 @@ -99,7 +99,7 @@ struct ctlr_info {
29290 drv_info_t drv[NWD];
29291 struct proc_dir_entry *proc;
29292
29293 - struct access_method access;
29294 + struct access_method *access;
29295
29296 cmdlist_t *reqQ;
29297 cmdlist_t *cmpQ;
29298 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29299 index b953cc7..e3dc580 100644
29300 --- a/drivers/block/drbd/drbd_int.h
29301 +++ b/drivers/block/drbd/drbd_int.h
29302 @@ -735,7 +735,7 @@ struct drbd_request;
29303 struct drbd_epoch {
29304 struct list_head list;
29305 unsigned int barrier_nr;
29306 - atomic_t epoch_size; /* increased on every request added. */
29307 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29308 atomic_t active; /* increased on every req. added, and dec on every finished. */
29309 unsigned long flags;
29310 };
29311 @@ -1116,7 +1116,7 @@ struct drbd_conf {
29312 void *int_dig_in;
29313 void *int_dig_vv;
29314 wait_queue_head_t seq_wait;
29315 - atomic_t packet_seq;
29316 + atomic_unchecked_t packet_seq;
29317 unsigned int peer_seq;
29318 spinlock_t peer_seq_lock;
29319 unsigned int minor;
29320 @@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29321
29322 static inline void drbd_tcp_cork(struct socket *sock)
29323 {
29324 - int __user val = 1;
29325 + int val = 1;
29326 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29327 - (char __user *)&val, sizeof(val));
29328 + (char __force_user *)&val, sizeof(val));
29329 }
29330
29331 static inline void drbd_tcp_uncork(struct socket *sock)
29332 {
29333 - int __user val = 0;
29334 + int val = 0;
29335 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29336 - (char __user *)&val, sizeof(val));
29337 + (char __force_user *)&val, sizeof(val));
29338 }
29339
29340 static inline void drbd_tcp_nodelay(struct socket *sock)
29341 {
29342 - int __user val = 1;
29343 + int val = 1;
29344 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29345 - (char __user *)&val, sizeof(val));
29346 + (char __force_user *)&val, sizeof(val));
29347 }
29348
29349 static inline void drbd_tcp_quickack(struct socket *sock)
29350 {
29351 - int __user val = 2;
29352 + int val = 2;
29353 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29354 - (char __user *)&val, sizeof(val));
29355 + (char __force_user *)&val, sizeof(val));
29356 }
29357
29358 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29359 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29360 index f93a032..71c87bf 100644
29361 --- a/drivers/block/drbd/drbd_main.c
29362 +++ b/drivers/block/drbd/drbd_main.c
29363 @@ -2567,7 +2567,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29364 p.sector = sector;
29365 p.block_id = block_id;
29366 p.blksize = blksize;
29367 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29368 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29369
29370 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29371 return false;
29372 @@ -2865,7 +2865,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29373
29374 p.sector = cpu_to_be64(req->sector);
29375 p.block_id = (unsigned long)req;
29376 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29377 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29378
29379 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29380
29381 @@ -3150,7 +3150,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29382 atomic_set(&mdev->unacked_cnt, 0);
29383 atomic_set(&mdev->local_cnt, 0);
29384 atomic_set(&mdev->net_cnt, 0);
29385 - atomic_set(&mdev->packet_seq, 0);
29386 + atomic_set_unchecked(&mdev->packet_seq, 0);
29387 atomic_set(&mdev->pp_in_use, 0);
29388 atomic_set(&mdev->pp_in_use_by_net, 0);
29389 atomic_set(&mdev->rs_sect_in, 0);
29390 @@ -3232,8 +3232,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29391 mdev->receiver.t_state);
29392
29393 /* no need to lock it, I'm the only thread alive */
29394 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29395 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29396 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29397 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29398 mdev->al_writ_cnt =
29399 mdev->bm_writ_cnt =
29400 mdev->read_cnt =
29401 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29402 index edb490a..ecd69da 100644
29403 --- a/drivers/block/drbd/drbd_nl.c
29404 +++ b/drivers/block/drbd/drbd_nl.c
29405 @@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29406 module_put(THIS_MODULE);
29407 }
29408
29409 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29410 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29411
29412 static unsigned short *
29413 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29414 @@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29415 cn_reply->id.idx = CN_IDX_DRBD;
29416 cn_reply->id.val = CN_VAL_DRBD;
29417
29418 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29419 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29420 cn_reply->ack = 0; /* not used here. */
29421 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29422 (int)((char *)tl - (char *)reply->tag_list);
29423 @@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29424 cn_reply->id.idx = CN_IDX_DRBD;
29425 cn_reply->id.val = CN_VAL_DRBD;
29426
29427 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29428 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29429 cn_reply->ack = 0; /* not used here. */
29430 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29431 (int)((char *)tl - (char *)reply->tag_list);
29432 @@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29433 cn_reply->id.idx = CN_IDX_DRBD;
29434 cn_reply->id.val = CN_VAL_DRBD;
29435
29436 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29437 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29438 cn_reply->ack = 0; // not used here.
29439 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29440 (int)((char*)tl - (char*)reply->tag_list);
29441 @@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29442 cn_reply->id.idx = CN_IDX_DRBD;
29443 cn_reply->id.val = CN_VAL_DRBD;
29444
29445 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29446 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29447 cn_reply->ack = 0; /* not used here. */
29448 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29449 (int)((char *)tl - (char *)reply->tag_list);
29450 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29451 index c74ca2d..860c819 100644
29452 --- a/drivers/block/drbd/drbd_receiver.c
29453 +++ b/drivers/block/drbd/drbd_receiver.c
29454 @@ -898,7 +898,7 @@ retry:
29455 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29456 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29457
29458 - atomic_set(&mdev->packet_seq, 0);
29459 + atomic_set_unchecked(&mdev->packet_seq, 0);
29460 mdev->peer_seq = 0;
29461
29462 if (drbd_send_protocol(mdev) == -1)
29463 @@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29464 do {
29465 next_epoch = NULL;
29466
29467 - epoch_size = atomic_read(&epoch->epoch_size);
29468 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29469
29470 switch (ev & ~EV_CLEANUP) {
29471 case EV_PUT:
29472 @@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29473 rv = FE_DESTROYED;
29474 } else {
29475 epoch->flags = 0;
29476 - atomic_set(&epoch->epoch_size, 0);
29477 + atomic_set_unchecked(&epoch->epoch_size, 0);
29478 /* atomic_set(&epoch->active, 0); is already zero */
29479 if (rv == FE_STILL_LIVE)
29480 rv = FE_RECYCLED;
29481 @@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29482 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29483 drbd_flush(mdev);
29484
29485 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29486 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29487 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29488 if (epoch)
29489 break;
29490 }
29491
29492 epoch = mdev->current_epoch;
29493 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29494 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29495
29496 D_ASSERT(atomic_read(&epoch->active) == 0);
29497 D_ASSERT(epoch->flags == 0);
29498 @@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29499 }
29500
29501 epoch->flags = 0;
29502 - atomic_set(&epoch->epoch_size, 0);
29503 + atomic_set_unchecked(&epoch->epoch_size, 0);
29504 atomic_set(&epoch->active, 0);
29505
29506 spin_lock(&mdev->epoch_lock);
29507 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29508 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29509 list_add(&epoch->list, &mdev->current_epoch->list);
29510 mdev->current_epoch = epoch;
29511 mdev->epochs++;
29512 @@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29513 spin_unlock(&mdev->peer_seq_lock);
29514
29515 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29516 - atomic_inc(&mdev->current_epoch->epoch_size);
29517 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29518 return drbd_drain_block(mdev, data_size);
29519 }
29520
29521 @@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29522
29523 spin_lock(&mdev->epoch_lock);
29524 e->epoch = mdev->current_epoch;
29525 - atomic_inc(&e->epoch->epoch_size);
29526 + atomic_inc_unchecked(&e->epoch->epoch_size);
29527 atomic_inc(&e->epoch->active);
29528 spin_unlock(&mdev->epoch_lock);
29529
29530 @@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29531 D_ASSERT(list_empty(&mdev->done_ee));
29532
29533 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29534 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29535 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29536 D_ASSERT(list_empty(&mdev->current_epoch->list));
29537 }
29538
29539 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29540 index 3bba655..6151b66 100644
29541 --- a/drivers/block/loop.c
29542 +++ b/drivers/block/loop.c
29543 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29544 mm_segment_t old_fs = get_fs();
29545
29546 set_fs(get_ds());
29547 - bw = file->f_op->write(file, buf, len, &pos);
29548 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29549 set_fs(old_fs);
29550 if (likely(bw == len))
29551 return 0;
29552 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29553 index ea6f632..eafb192 100644
29554 --- a/drivers/char/Kconfig
29555 +++ b/drivers/char/Kconfig
29556 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29557
29558 config DEVKMEM
29559 bool "/dev/kmem virtual device support"
29560 - default y
29561 + default n
29562 + depends on !GRKERNSEC_KMEM
29563 help
29564 Say Y here if you want to support the /dev/kmem device. The
29565 /dev/kmem device is rarely used, but can be used for certain
29566 @@ -581,6 +582,7 @@ config DEVPORT
29567 bool
29568 depends on !M68K
29569 depends on ISA || PCI
29570 + depends on !GRKERNSEC_KMEM
29571 default y
29572
29573 source "drivers/s390/char/Kconfig"
29574 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29575 index 2e04433..22afc64 100644
29576 --- a/drivers/char/agp/frontend.c
29577 +++ b/drivers/char/agp/frontend.c
29578 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29579 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29580 return -EFAULT;
29581
29582 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29583 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29584 return -EFAULT;
29585
29586 client = agp_find_client_by_pid(reserve.pid);
29587 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29588 index 21cb980..f15107c 100644
29589 --- a/drivers/char/genrtc.c
29590 +++ b/drivers/char/genrtc.c
29591 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29592 switch (cmd) {
29593
29594 case RTC_PLL_GET:
29595 + memset(&pll, 0, sizeof(pll));
29596 if (get_rtc_pll(&pll))
29597 return -EINVAL;
29598 else
29599 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29600 index dfd7876..c0b0885 100644
29601 --- a/drivers/char/hpet.c
29602 +++ b/drivers/char/hpet.c
29603 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29604 }
29605
29606 static int
29607 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29608 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29609 struct hpet_info *info)
29610 {
29611 struct hpet_timer __iomem *timer;
29612 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29613 index 2c29942..604c5ba 100644
29614 --- a/drivers/char/ipmi/ipmi_msghandler.c
29615 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29616 @@ -420,7 +420,7 @@ struct ipmi_smi {
29617 struct proc_dir_entry *proc_dir;
29618 char proc_dir_name[10];
29619
29620 - atomic_t stats[IPMI_NUM_STATS];
29621 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29622
29623 /*
29624 * run_to_completion duplicate of smb_info, smi_info
29625 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29626
29627
29628 #define ipmi_inc_stat(intf, stat) \
29629 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29630 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29631 #define ipmi_get_stat(intf, stat) \
29632 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29633 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29634
29635 static int is_lan_addr(struct ipmi_addr *addr)
29636 {
29637 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29638 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29639 init_waitqueue_head(&intf->waitq);
29640 for (i = 0; i < IPMI_NUM_STATS; i++)
29641 - atomic_set(&intf->stats[i], 0);
29642 + atomic_set_unchecked(&intf->stats[i], 0);
29643
29644 intf->proc_dir = NULL;
29645
29646 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29647 index 83f85cf..279e63f 100644
29648 --- a/drivers/char/ipmi/ipmi_si_intf.c
29649 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29650 @@ -275,7 +275,7 @@ struct smi_info {
29651 unsigned char slave_addr;
29652
29653 /* Counters and things for the proc filesystem. */
29654 - atomic_t stats[SI_NUM_STATS];
29655 + atomic_unchecked_t stats[SI_NUM_STATS];
29656
29657 struct task_struct *thread;
29658
29659 @@ -284,9 +284,9 @@ struct smi_info {
29660 };
29661
29662 #define smi_inc_stat(smi, stat) \
29663 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29664 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29665 #define smi_get_stat(smi, stat) \
29666 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29667 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29668
29669 #define SI_MAX_PARMS 4
29670
29671 @@ -3193,7 +3193,7 @@ static int try_smi_init(struct smi_info *new_smi)
29672 atomic_set(&new_smi->req_events, 0);
29673 new_smi->run_to_completion = 0;
29674 for (i = 0; i < SI_NUM_STATS; i++)
29675 - atomic_set(&new_smi->stats[i], 0);
29676 + atomic_set_unchecked(&new_smi->stats[i], 0);
29677
29678 new_smi->interrupt_disabled = 1;
29679 atomic_set(&new_smi->stop_operation, 0);
29680 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29681 index 47ff7e4..0c7d340 100644
29682 --- a/drivers/char/mbcs.c
29683 +++ b/drivers/char/mbcs.c
29684 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29685 return 0;
29686 }
29687
29688 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29689 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29690 {
29691 .part_num = MBCS_PART_NUM,
29692 .mfg_num = MBCS_MFG_NUM,
29693 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29694 index e5eedfa..fcab50ea 100644
29695 --- a/drivers/char/mem.c
29696 +++ b/drivers/char/mem.c
29697 @@ -18,6 +18,7 @@
29698 #include <linux/raw.h>
29699 #include <linux/tty.h>
29700 #include <linux/capability.h>
29701 +#include <linux/security.h>
29702 #include <linux/ptrace.h>
29703 #include <linux/device.h>
29704 #include <linux/highmem.h>
29705 @@ -37,6 +38,10 @@
29706
29707 #define DEVPORT_MINOR 4
29708
29709 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29710 +extern const struct file_operations grsec_fops;
29711 +#endif
29712 +
29713 static inline unsigned long size_inside_page(unsigned long start,
29714 unsigned long size)
29715 {
29716 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29717
29718 while (cursor < to) {
29719 if (!devmem_is_allowed(pfn)) {
29720 +#ifdef CONFIG_GRKERNSEC_KMEM
29721 + gr_handle_mem_readwrite(from, to);
29722 +#else
29723 printk(KERN_INFO
29724 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29725 current->comm, from, to);
29726 +#endif
29727 return 0;
29728 }
29729 cursor += PAGE_SIZE;
29730 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29731 }
29732 return 1;
29733 }
29734 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29735 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29736 +{
29737 + return 0;
29738 +}
29739 #else
29740 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29741 {
29742 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29743
29744 while (count > 0) {
29745 unsigned long remaining;
29746 + char *temp;
29747
29748 sz = size_inside_page(p, count);
29749
29750 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29751 if (!ptr)
29752 return -EFAULT;
29753
29754 - remaining = copy_to_user(buf, ptr, sz);
29755 +#ifdef CONFIG_PAX_USERCOPY
29756 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29757 + if (!temp) {
29758 + unxlate_dev_mem_ptr(p, ptr);
29759 + return -ENOMEM;
29760 + }
29761 + memcpy(temp, ptr, sz);
29762 +#else
29763 + temp = ptr;
29764 +#endif
29765 +
29766 + remaining = copy_to_user(buf, temp, sz);
29767 +
29768 +#ifdef CONFIG_PAX_USERCOPY
29769 + kfree(temp);
29770 +#endif
29771 +
29772 unxlate_dev_mem_ptr(p, ptr);
29773 if (remaining)
29774 return -EFAULT;
29775 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29776 size_t count, loff_t *ppos)
29777 {
29778 unsigned long p = *ppos;
29779 - ssize_t low_count, read, sz;
29780 + ssize_t low_count, read, sz, err = 0;
29781 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29782 - int err = 0;
29783
29784 read = 0;
29785 if (p < (unsigned long) high_memory) {
29786 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29787 }
29788 #endif
29789 while (low_count > 0) {
29790 + char *temp;
29791 +
29792 sz = size_inside_page(p, low_count);
29793
29794 /*
29795 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29796 */
29797 kbuf = xlate_dev_kmem_ptr((char *)p);
29798
29799 - if (copy_to_user(buf, kbuf, sz))
29800 +#ifdef CONFIG_PAX_USERCOPY
29801 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29802 + if (!temp)
29803 + return -ENOMEM;
29804 + memcpy(temp, kbuf, sz);
29805 +#else
29806 + temp = kbuf;
29807 +#endif
29808 +
29809 + err = copy_to_user(buf, temp, sz);
29810 +
29811 +#ifdef CONFIG_PAX_USERCOPY
29812 + kfree(temp);
29813 +#endif
29814 +
29815 + if (err)
29816 return -EFAULT;
29817 buf += sz;
29818 p += sz;
29819 @@ -833,6 +880,9 @@ static const struct memdev {
29820 #ifdef CONFIG_CRASH_DUMP
29821 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29822 #endif
29823 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29824 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29825 +#endif
29826 };
29827
29828 static int memory_open(struct inode *inode, struct file *filp)
29829 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29830 index 9df78e2..01ba9ae 100644
29831 --- a/drivers/char/nvram.c
29832 +++ b/drivers/char/nvram.c
29833 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29834
29835 spin_unlock_irq(&rtc_lock);
29836
29837 - if (copy_to_user(buf, contents, tmp - contents))
29838 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29839 return -EFAULT;
29840
29841 *ppos = i;
29842 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29843 index 0a484b4..f48ccd1 100644
29844 --- a/drivers/char/pcmcia/synclink_cs.c
29845 +++ b/drivers/char/pcmcia/synclink_cs.c
29846 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29847
29848 if (debug_level >= DEBUG_LEVEL_INFO)
29849 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29850 - __FILE__,__LINE__, info->device_name, port->count);
29851 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29852
29853 - WARN_ON(!port->count);
29854 + WARN_ON(!atomic_read(&port->count));
29855
29856 if (tty_port_close_start(port, tty, filp) == 0)
29857 goto cleanup;
29858 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29859 cleanup:
29860 if (debug_level >= DEBUG_LEVEL_INFO)
29861 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29862 - tty->driver->name, port->count);
29863 + tty->driver->name, atomic_read(&port->count));
29864 }
29865
29866 /* Wait until the transmitter is empty.
29867 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29868
29869 if (debug_level >= DEBUG_LEVEL_INFO)
29870 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29871 - __FILE__,__LINE__,tty->driver->name, port->count);
29872 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29873
29874 /* If port is closing, signal caller to try again */
29875 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29876 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29877 goto cleanup;
29878 }
29879 spin_lock(&port->lock);
29880 - port->count++;
29881 + atomic_inc(&port->count);
29882 spin_unlock(&port->lock);
29883 spin_unlock_irqrestore(&info->netlock, flags);
29884
29885 - if (port->count == 1) {
29886 + if (atomic_read(&port->count) == 1) {
29887 /* 1st open on this device, init hardware */
29888 retval = startup(info, tty);
29889 if (retval < 0)
29890 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29891 unsigned short new_crctype;
29892
29893 /* return error if TTY interface open */
29894 - if (info->port.count)
29895 + if (atomic_read(&info->port.count))
29896 return -EBUSY;
29897
29898 switch (encoding)
29899 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29900
29901 /* arbitrate between network and tty opens */
29902 spin_lock_irqsave(&info->netlock, flags);
29903 - if (info->port.count != 0 || info->netcount != 0) {
29904 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29905 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29906 spin_unlock_irqrestore(&info->netlock, flags);
29907 return -EBUSY;
29908 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29909 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29910
29911 /* return error if TTY interface open */
29912 - if (info->port.count)
29913 + if (atomic_read(&info->port.count))
29914 return -EBUSY;
29915
29916 if (cmd != SIOCWANDEV)
29917 diff --git a/drivers/char/random.c b/drivers/char/random.c
29918 index b86eae9..4192a7a 100644
29919 --- a/drivers/char/random.c
29920 +++ b/drivers/char/random.c
29921 @@ -272,8 +272,13 @@
29922 /*
29923 * Configuration information
29924 */
29925 +#ifdef CONFIG_GRKERNSEC_RANDNET
29926 +#define INPUT_POOL_WORDS 512
29927 +#define OUTPUT_POOL_WORDS 128
29928 +#else
29929 #define INPUT_POOL_WORDS 128
29930 #define OUTPUT_POOL_WORDS 32
29931 +#endif
29932 #define SEC_XFER_SIZE 512
29933 #define EXTRACT_SIZE 10
29934
29935 @@ -313,10 +318,17 @@ static struct poolinfo {
29936 int poolwords;
29937 int tap1, tap2, tap3, tap4, tap5;
29938 } poolinfo_table[] = {
29939 +#ifdef CONFIG_GRKERNSEC_RANDNET
29940 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29941 + { 512, 411, 308, 208, 104, 1 },
29942 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29943 + { 128, 103, 76, 51, 25, 1 },
29944 +#else
29945 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29946 { 128, 103, 76, 51, 25, 1 },
29947 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29948 { 32, 26, 20, 14, 7, 1 },
29949 +#endif
29950 #if 0
29951 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29952 { 2048, 1638, 1231, 819, 411, 1 },
29953 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29954 input_rotate += i ? 7 : 14;
29955 }
29956
29957 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29958 - ACCESS_ONCE(r->add_ptr) = i;
29959 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29960 + ACCESS_ONCE_RW(r->add_ptr) = i;
29961 smp_wmb();
29962
29963 if (out)
29964 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29965 }
29966 #endif
29967
29968 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29969 +u64 latent_entropy;
29970 +
29971 +__init void transfer_latent_entropy(void)
29972 +{
29973 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29974 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29975 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29976 +}
29977 +#endif
29978 +
29979 /*********************************************************************
29980 *
29981 * Entropy extraction routines
29982 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29983
29984 extract_buf(r, tmp);
29985 i = min_t(int, nbytes, EXTRACT_SIZE);
29986 - if (copy_to_user(buf, tmp, i)) {
29987 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29988 ret = -EFAULT;
29989 break;
29990 }
29991 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29992 #include <linux/sysctl.h>
29993
29994 static int min_read_thresh = 8, min_write_thresh;
29995 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29996 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29997 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29998 static char sysctl_bootid[16];
29999
30000 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
30001 index f877805..403375a 100644
30002 --- a/drivers/char/sonypi.c
30003 +++ b/drivers/char/sonypi.c
30004 @@ -54,6 +54,7 @@
30005
30006 #include <asm/uaccess.h>
30007 #include <asm/io.h>
30008 +#include <asm/local.h>
30009
30010 #include <linux/sonypi.h>
30011
30012 @@ -490,7 +491,7 @@ static struct sonypi_device {
30013 spinlock_t fifo_lock;
30014 wait_queue_head_t fifo_proc_list;
30015 struct fasync_struct *fifo_async;
30016 - int open_count;
30017 + local_t open_count;
30018 int model;
30019 struct input_dev *input_jog_dev;
30020 struct input_dev *input_key_dev;
30021 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
30022 static int sonypi_misc_release(struct inode *inode, struct file *file)
30023 {
30024 mutex_lock(&sonypi_device.lock);
30025 - sonypi_device.open_count--;
30026 + local_dec(&sonypi_device.open_count);
30027 mutex_unlock(&sonypi_device.lock);
30028 return 0;
30029 }
30030 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
30031 {
30032 mutex_lock(&sonypi_device.lock);
30033 /* Flush input queue on first open */
30034 - if (!sonypi_device.open_count)
30035 + if (!local_read(&sonypi_device.open_count))
30036 kfifo_reset(&sonypi_device.fifo);
30037 - sonypi_device.open_count++;
30038 + local_inc(&sonypi_device.open_count);
30039 mutex_unlock(&sonypi_device.lock);
30040
30041 return 0;
30042 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
30043 index 817f0ee..cd3b75d 100644
30044 --- a/drivers/char/tpm/tpm.c
30045 +++ b/drivers/char/tpm/tpm.c
30046 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30047 chip->vendor.req_complete_val)
30048 goto out_recv;
30049
30050 - if ((status == chip->vendor.req_canceled)) {
30051 + if (status == chip->vendor.req_canceled) {
30052 dev_err(chip->dev, "Operation Canceled\n");
30053 rc = -ECANCELED;
30054 goto out;
30055 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30056 index 0636520..169c1d0 100644
30057 --- a/drivers/char/tpm/tpm_bios.c
30058 +++ b/drivers/char/tpm/tpm_bios.c
30059 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30060 event = addr;
30061
30062 if ((event->event_type == 0 && event->event_size == 0) ||
30063 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30064 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30065 return NULL;
30066
30067 return addr;
30068 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30069 return NULL;
30070
30071 if ((event->event_type == 0 && event->event_size == 0) ||
30072 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30073 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30074 return NULL;
30075
30076 (*pos)++;
30077 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30078 int i;
30079
30080 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30081 - seq_putc(m, data[i]);
30082 + if (!seq_putc(m, data[i]))
30083 + return -EFAULT;
30084
30085 return 0;
30086 }
30087 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30088 log->bios_event_log_end = log->bios_event_log + len;
30089
30090 virt = acpi_os_map_memory(start, len);
30091 + if (!virt) {
30092 + kfree(log->bios_event_log);
30093 + log->bios_event_log = NULL;
30094 + return -EFAULT;
30095 + }
30096
30097 - memcpy(log->bios_event_log, virt, len);
30098 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30099
30100 acpi_os_unmap_memory(virt, len);
30101 return 0;
30102 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30103 index cdf2f54..e55c197 100644
30104 --- a/drivers/char/virtio_console.c
30105 +++ b/drivers/char/virtio_console.c
30106 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30107 if (to_user) {
30108 ssize_t ret;
30109
30110 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30111 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30112 if (ret)
30113 return -EFAULT;
30114 } else {
30115 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30116 if (!port_has_data(port) && !port->host_connected)
30117 return 0;
30118
30119 - return fill_readbuf(port, ubuf, count, true);
30120 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30121 }
30122
30123 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30124 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30125 index e164c55..3aabb50 100644
30126 --- a/drivers/edac/edac_pci_sysfs.c
30127 +++ b/drivers/edac/edac_pci_sysfs.c
30128 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30129 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30130 static int edac_pci_poll_msec = 1000; /* one second workq period */
30131
30132 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30133 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30134 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30135 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30136
30137 static struct kobject *edac_pci_top_main_kobj;
30138 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30139 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30140 edac_printk(KERN_CRIT, EDAC_PCI,
30141 "Signaled System Error on %s\n",
30142 pci_name(dev));
30143 - atomic_inc(&pci_nonparity_count);
30144 + atomic_inc_unchecked(&pci_nonparity_count);
30145 }
30146
30147 if (status & (PCI_STATUS_PARITY)) {
30148 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30149 "Master Data Parity Error on %s\n",
30150 pci_name(dev));
30151
30152 - atomic_inc(&pci_parity_count);
30153 + atomic_inc_unchecked(&pci_parity_count);
30154 }
30155
30156 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30157 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30158 "Detected Parity Error on %s\n",
30159 pci_name(dev));
30160
30161 - atomic_inc(&pci_parity_count);
30162 + atomic_inc_unchecked(&pci_parity_count);
30163 }
30164 }
30165
30166 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30167 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30168 "Signaled System Error on %s\n",
30169 pci_name(dev));
30170 - atomic_inc(&pci_nonparity_count);
30171 + atomic_inc_unchecked(&pci_nonparity_count);
30172 }
30173
30174 if (status & (PCI_STATUS_PARITY)) {
30175 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30176 "Master Data Parity Error on "
30177 "%s\n", pci_name(dev));
30178
30179 - atomic_inc(&pci_parity_count);
30180 + atomic_inc_unchecked(&pci_parity_count);
30181 }
30182
30183 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30184 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30185 "Detected Parity Error on %s\n",
30186 pci_name(dev));
30187
30188 - atomic_inc(&pci_parity_count);
30189 + atomic_inc_unchecked(&pci_parity_count);
30190 }
30191 }
30192 }
30193 @@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
30194 if (!check_pci_errors)
30195 return;
30196
30197 - before_count = atomic_read(&pci_parity_count);
30198 + before_count = atomic_read_unchecked(&pci_parity_count);
30199
30200 /* scan all PCI devices looking for a Parity Error on devices and
30201 * bridges.
30202 @@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
30203 /* Only if operator has selected panic on PCI Error */
30204 if (edac_pci_get_panic_on_pe()) {
30205 /* If the count is different 'after' from 'before' */
30206 - if (before_count != atomic_read(&pci_parity_count))
30207 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30208 panic("EDAC: PCI Parity Error");
30209 }
30210 }
30211 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30212 index 8c87a5e..a19cbd7 100644
30213 --- a/drivers/edac/mce_amd.h
30214 +++ b/drivers/edac/mce_amd.h
30215 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30216 struct amd_decoder_ops {
30217 bool (*dc_mce)(u16, u8);
30218 bool (*ic_mce)(u16, u8);
30219 -};
30220 +} __no_const;
30221
30222 void amd_report_gart_errors(bool);
30223 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30224 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30225 index 57ea7f4..789e3c3 100644
30226 --- a/drivers/firewire/core-card.c
30227 +++ b/drivers/firewire/core-card.c
30228 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30229
30230 void fw_core_remove_card(struct fw_card *card)
30231 {
30232 - struct fw_card_driver dummy_driver = dummy_driver_template;
30233 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30234
30235 card->driver->update_phy_reg(card, 4,
30236 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30237 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30238 index 2783f69..9f4b0cc 100644
30239 --- a/drivers/firewire/core-cdev.c
30240 +++ b/drivers/firewire/core-cdev.c
30241 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30242 int ret;
30243
30244 if ((request->channels == 0 && request->bandwidth == 0) ||
30245 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30246 - request->bandwidth < 0)
30247 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30248 return -EINVAL;
30249
30250 r = kmalloc(sizeof(*r), GFP_KERNEL);
30251 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30252 index 87d6f2d..5bf9d90 100644
30253 --- a/drivers/firewire/core-transaction.c
30254 +++ b/drivers/firewire/core-transaction.c
30255 @@ -37,6 +37,7 @@
30256 #include <linux/timer.h>
30257 #include <linux/types.h>
30258 #include <linux/workqueue.h>
30259 +#include <linux/sched.h>
30260
30261 #include <asm/byteorder.h>
30262
30263 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30264 index 515a42c..5ecf3ba 100644
30265 --- a/drivers/firewire/core.h
30266 +++ b/drivers/firewire/core.h
30267 @@ -111,6 +111,7 @@ struct fw_card_driver {
30268
30269 int (*stop_iso)(struct fw_iso_context *ctx);
30270 };
30271 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30272
30273 void fw_card_initialize(struct fw_card *card,
30274 const struct fw_card_driver *driver, struct device *device);
30275 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30276 index b298158..7ed8432 100644
30277 --- a/drivers/firmware/dmi_scan.c
30278 +++ b/drivers/firmware/dmi_scan.c
30279 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30280 }
30281 }
30282 else {
30283 - /*
30284 - * no iounmap() for that ioremap(); it would be a no-op, but
30285 - * it's so early in setup that sucker gets confused into doing
30286 - * what it shouldn't if we actually call it.
30287 - */
30288 p = dmi_ioremap(0xF0000, 0x10000);
30289 if (p == NULL)
30290 goto error;
30291 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30292 if (buf == NULL)
30293 return -1;
30294
30295 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30296 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30297
30298 iounmap(buf);
30299 return 0;
30300 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30301 index 82d5c20..44a7177 100644
30302 --- a/drivers/gpio/gpio-vr41xx.c
30303 +++ b/drivers/gpio/gpio-vr41xx.c
30304 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30305 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30306 maskl, pendl, maskh, pendh);
30307
30308 - atomic_inc(&irq_err_count);
30309 + atomic_inc_unchecked(&irq_err_count);
30310
30311 return -EINVAL;
30312 }
30313 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30314 index 3252e70..b5314ace 100644
30315 --- a/drivers/gpu/drm/drm_crtc_helper.c
30316 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30317 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30318 struct drm_crtc *tmp;
30319 int crtc_mask = 1;
30320
30321 - WARN(!crtc, "checking null crtc?\n");
30322 + BUG_ON(!crtc);
30323
30324 dev = crtc->dev;
30325
30326 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30327 index 9238de4..a27c72a 100644
30328 --- a/drivers/gpu/drm/drm_drv.c
30329 +++ b/drivers/gpu/drm/drm_drv.c
30330 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
30331 /**
30332 * Copy and IOCTL return string to user space
30333 */
30334 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30335 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30336 {
30337 int len;
30338
30339 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
30340 return -ENODEV;
30341
30342 atomic_inc(&dev->ioctl_count);
30343 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30344 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30345 ++file_priv->ioctl_count;
30346
30347 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30348 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30349 index 5062eec..4e3e51f 100644
30350 --- a/drivers/gpu/drm/drm_fops.c
30351 +++ b/drivers/gpu/drm/drm_fops.c
30352 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30353 }
30354
30355 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30356 - atomic_set(&dev->counts[i], 0);
30357 + atomic_set_unchecked(&dev->counts[i], 0);
30358
30359 dev->sigdata.lock = NULL;
30360
30361 @@ -134,8 +134,8 @@ int drm_open(struct inode *inode, struct file *filp)
30362
30363 retcode = drm_open_helper(inode, filp, dev);
30364 if (!retcode) {
30365 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30366 - if (!dev->open_count++)
30367 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30368 + if (local_inc_return(&dev->open_count) == 1)
30369 retcode = drm_setup(dev);
30370 }
30371 if (!retcode) {
30372 @@ -422,7 +422,7 @@ int drm_release(struct inode *inode, struct file *filp)
30373
30374 mutex_lock(&drm_global_mutex);
30375
30376 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30377 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30378
30379 if (dev->driver->preclose)
30380 dev->driver->preclose(dev, file_priv);
30381 @@ -431,10 +431,10 @@ int drm_release(struct inode *inode, struct file *filp)
30382 * Begin inline drm_release
30383 */
30384
30385 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30386 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30387 task_pid_nr(current),
30388 (long)old_encode_dev(file_priv->minor->device),
30389 - dev->open_count);
30390 + local_read(&dev->open_count));
30391
30392 /* Release any auth tokens that might point to this file_priv,
30393 (do that under the drm_global_mutex) */
30394 @@ -530,8 +530,8 @@ int drm_release(struct inode *inode, struct file *filp)
30395 * End inline drm_release
30396 */
30397
30398 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30399 - if (!--dev->open_count) {
30400 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30401 + if (local_dec_and_test(&dev->open_count)) {
30402 if (atomic_read(&dev->ioctl_count)) {
30403 DRM_ERROR("Device busy: %d\n",
30404 atomic_read(&dev->ioctl_count));
30405 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30406 index c87dc96..326055d 100644
30407 --- a/drivers/gpu/drm/drm_global.c
30408 +++ b/drivers/gpu/drm/drm_global.c
30409 @@ -36,7 +36,7 @@
30410 struct drm_global_item {
30411 struct mutex mutex;
30412 void *object;
30413 - int refcount;
30414 + atomic_t refcount;
30415 };
30416
30417 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30418 @@ -49,7 +49,7 @@ void drm_global_init(void)
30419 struct drm_global_item *item = &glob[i];
30420 mutex_init(&item->mutex);
30421 item->object = NULL;
30422 - item->refcount = 0;
30423 + atomic_set(&item->refcount, 0);
30424 }
30425 }
30426
30427 @@ -59,7 +59,7 @@ void drm_global_release(void)
30428 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30429 struct drm_global_item *item = &glob[i];
30430 BUG_ON(item->object != NULL);
30431 - BUG_ON(item->refcount != 0);
30432 + BUG_ON(atomic_read(&item->refcount) != 0);
30433 }
30434 }
30435
30436 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30437 void *object;
30438
30439 mutex_lock(&item->mutex);
30440 - if (item->refcount == 0) {
30441 + if (atomic_read(&item->refcount) == 0) {
30442 item->object = kzalloc(ref->size, GFP_KERNEL);
30443 if (unlikely(item->object == NULL)) {
30444 ret = -ENOMEM;
30445 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30446 goto out_err;
30447
30448 }
30449 - ++item->refcount;
30450 + atomic_inc(&item->refcount);
30451 ref->object = item->object;
30452 object = item->object;
30453 mutex_unlock(&item->mutex);
30454 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30455 struct drm_global_item *item = &glob[ref->global_type];
30456
30457 mutex_lock(&item->mutex);
30458 - BUG_ON(item->refcount == 0);
30459 + BUG_ON(atomic_read(&item->refcount) == 0);
30460 BUG_ON(ref->object != item->object);
30461 - if (--item->refcount == 0) {
30462 + if (atomic_dec_and_test(&item->refcount)) {
30463 ref->release(ref);
30464 item->object = NULL;
30465 }
30466 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30467 index 8928edb..0c79258 100644
30468 --- a/drivers/gpu/drm/drm_info.c
30469 +++ b/drivers/gpu/drm/drm_info.c
30470 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30471 struct drm_local_map *map;
30472 struct drm_map_list *r_list;
30473
30474 - /* Hardcoded from _DRM_FRAME_BUFFER,
30475 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30476 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30477 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30478 + static const char * const types[] = {
30479 + [_DRM_FRAME_BUFFER] = "FB",
30480 + [_DRM_REGISTERS] = "REG",
30481 + [_DRM_SHM] = "SHM",
30482 + [_DRM_AGP] = "AGP",
30483 + [_DRM_SCATTER_GATHER] = "SG",
30484 + [_DRM_CONSISTENT] = "PCI",
30485 + [_DRM_GEM] = "GEM" };
30486 const char *type;
30487 int i;
30488
30489 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30490 map = r_list->map;
30491 if (!map)
30492 continue;
30493 - if (map->type < 0 || map->type > 5)
30494 + if (map->type >= ARRAY_SIZE(types))
30495 type = "??";
30496 else
30497 type = types[map->type];
30498 @@ -254,7 +258,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30499 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30500 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30501 vma->vm_flags & VM_IO ? 'i' : '-',
30502 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30503 + 0);
30504 +#else
30505 vma->vm_pgoff);
30506 +#endif
30507
30508 #if defined(__i386__)
30509 pgprot = pgprot_val(vma->vm_page_prot);
30510 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30511 index 637fcc3..e890b33 100644
30512 --- a/drivers/gpu/drm/drm_ioc32.c
30513 +++ b/drivers/gpu/drm/drm_ioc32.c
30514 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30515 request = compat_alloc_user_space(nbytes);
30516 if (!access_ok(VERIFY_WRITE, request, nbytes))
30517 return -EFAULT;
30518 - list = (struct drm_buf_desc *) (request + 1);
30519 + list = (struct drm_buf_desc __user *) (request + 1);
30520
30521 if (__put_user(count, &request->count)
30522 || __put_user(list, &request->list))
30523 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30524 request = compat_alloc_user_space(nbytes);
30525 if (!access_ok(VERIFY_WRITE, request, nbytes))
30526 return -EFAULT;
30527 - list = (struct drm_buf_pub *) (request + 1);
30528 + list = (struct drm_buf_pub __user *) (request + 1);
30529
30530 if (__put_user(count, &request->count)
30531 || __put_user(list, &request->list))
30532 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30533 index 64a62c6..ceab35e 100644
30534 --- a/drivers/gpu/drm/drm_ioctl.c
30535 +++ b/drivers/gpu/drm/drm_ioctl.c
30536 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30537 stats->data[i].value =
30538 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30539 else
30540 - stats->data[i].value = atomic_read(&dev->counts[i]);
30541 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30542 stats->data[i].type = dev->types[i];
30543 }
30544
30545 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30546 index 3203955..c8090af 100644
30547 --- a/drivers/gpu/drm/drm_lock.c
30548 +++ b/drivers/gpu/drm/drm_lock.c
30549 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30550 if (drm_lock_take(&master->lock, lock->context)) {
30551 master->lock.file_priv = file_priv;
30552 master->lock.lock_time = jiffies;
30553 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30554 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30555 break; /* Got lock */
30556 }
30557
30558 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30559 return -EINVAL;
30560 }
30561
30562 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30563 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30564
30565 if (drm_lock_free(&master->lock, lock->context)) {
30566 /* FIXME: Should really bail out here. */
30567 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30568 index 21bcd4a..8e074e0 100644
30569 --- a/drivers/gpu/drm/drm_stub.c
30570 +++ b/drivers/gpu/drm/drm_stub.c
30571 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30572
30573 drm_device_set_unplugged(dev);
30574
30575 - if (dev->open_count == 0) {
30576 + if (local_read(&dev->open_count) == 0) {
30577 drm_put_dev(dev);
30578 }
30579 mutex_unlock(&drm_global_mutex);
30580 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30581 index 463ec68..f5bd2b5 100644
30582 --- a/drivers/gpu/drm/i810/i810_dma.c
30583 +++ b/drivers/gpu/drm/i810/i810_dma.c
30584 @@ -946,8 +946,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30585 dma->buflist[vertex->idx],
30586 vertex->discard, vertex->used);
30587
30588 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30589 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30590 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30591 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30592 sarea_priv->last_enqueue = dev_priv->counter - 1;
30593 sarea_priv->last_dispatch = (int)hw_status[5];
30594
30595 @@ -1107,8 +1107,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30596 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30597 mc->last_render);
30598
30599 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30600 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30601 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30602 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30603 sarea_priv->last_enqueue = dev_priv->counter - 1;
30604 sarea_priv->last_dispatch = (int)hw_status[5];
30605
30606 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30607 index 6e0acad..93c8289 100644
30608 --- a/drivers/gpu/drm/i810/i810_drv.h
30609 +++ b/drivers/gpu/drm/i810/i810_drv.h
30610 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30611 int page_flipping;
30612
30613 wait_queue_head_t irq_queue;
30614 - atomic_t irq_received;
30615 - atomic_t irq_emitted;
30616 + atomic_unchecked_t irq_received;
30617 + atomic_unchecked_t irq_emitted;
30618
30619 int front_offset;
30620 } drm_i810_private_t;
30621 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30622 index 359f6e8..ada68fd 100644
30623 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30624 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30625 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30626 I915_READ(GTIMR));
30627 }
30628 seq_printf(m, "Interrupts received: %d\n",
30629 - atomic_read(&dev_priv->irq_received));
30630 + atomic_read_unchecked(&dev_priv->irq_received));
30631 for (i = 0; i < I915_NUM_RINGS; i++) {
30632 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30633 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30634 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30635 index 914c0df..d47d380 100644
30636 --- a/drivers/gpu/drm/i915/i915_dma.c
30637 +++ b/drivers/gpu/drm/i915/i915_dma.c
30638 @@ -1269,7 +1269,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30639 bool can_switch;
30640
30641 spin_lock(&dev->count_lock);
30642 - can_switch = (dev->open_count == 0);
30643 + can_switch = (local_read(&dev->open_count) == 0);
30644 spin_unlock(&dev->count_lock);
30645 return can_switch;
30646 }
30647 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30648 index 627fe35..c9a7346 100644
30649 --- a/drivers/gpu/drm/i915/i915_drv.h
30650 +++ b/drivers/gpu/drm/i915/i915_drv.h
30651 @@ -272,12 +272,12 @@ struct drm_i915_display_funcs {
30652 /* render clock increase/decrease */
30653 /* display clock increase/decrease */
30654 /* pll clock increase/decrease */
30655 -};
30656 +} __no_const;
30657
30658 struct drm_i915_gt_funcs {
30659 void (*force_wake_get)(struct drm_i915_private *dev_priv);
30660 void (*force_wake_put)(struct drm_i915_private *dev_priv);
30661 -};
30662 +} __no_const;
30663
30664 struct intel_device_info {
30665 u8 gen;
30666 @@ -408,7 +408,7 @@ typedef struct drm_i915_private {
30667 int current_page;
30668 int page_flipping;
30669
30670 - atomic_t irq_received;
30671 + atomic_unchecked_t irq_received;
30672
30673 /* protects the irq masks */
30674 spinlock_t irq_lock;
30675 @@ -1014,7 +1014,7 @@ struct drm_i915_gem_object {
30676 * will be page flipped away on the next vblank. When it
30677 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30678 */
30679 - atomic_t pending_flip;
30680 + atomic_unchecked_t pending_flip;
30681 };
30682
30683 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30684 @@ -1482,7 +1482,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30685 struct drm_i915_private *dev_priv, unsigned port);
30686 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30687 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30688 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30689 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30690 {
30691 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30692 }
30693 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30694 index ff2819e..6b5997b 100644
30695 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30696 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30697 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30698 i915_gem_clflush_object(obj);
30699
30700 if (obj->base.pending_write_domain)
30701 - cd->flips |= atomic_read(&obj->pending_flip);
30702 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30703
30704 /* The actual obj->write_domain will be updated with
30705 * pending_write_domain after we emit the accumulated flush for all
30706 @@ -906,9 +906,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30707
30708 static int
30709 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30710 - int count)
30711 + unsigned int count)
30712 {
30713 - int i;
30714 + unsigned int i;
30715
30716 for (i = 0; i < count; i++) {
30717 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30718 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30719 index 73fa3e1..ab2e9b9 100644
30720 --- a/drivers/gpu/drm/i915/i915_irq.c
30721 +++ b/drivers/gpu/drm/i915/i915_irq.c
30722 @@ -514,7 +514,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30723 u32 pipe_stats[I915_MAX_PIPES];
30724 bool blc_event;
30725
30726 - atomic_inc(&dev_priv->irq_received);
30727 + atomic_inc_unchecked(&dev_priv->irq_received);
30728
30729 while (true) {
30730 iir = I915_READ(VLV_IIR);
30731 @@ -661,7 +661,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30732 irqreturn_t ret = IRQ_NONE;
30733 int i;
30734
30735 - atomic_inc(&dev_priv->irq_received);
30736 + atomic_inc_unchecked(&dev_priv->irq_received);
30737
30738 /* disable master interrupt before clearing iir */
30739 de_ier = I915_READ(DEIER);
30740 @@ -736,7 +736,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30741 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30742 u32 hotplug_mask;
30743
30744 - atomic_inc(&dev_priv->irq_received);
30745 + atomic_inc_unchecked(&dev_priv->irq_received);
30746
30747 /* disable master interrupt before clearing iir */
30748 de_ier = I915_READ(DEIER);
30749 @@ -1717,7 +1717,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30750 {
30751 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30752
30753 - atomic_set(&dev_priv->irq_received, 0);
30754 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30755
30756 I915_WRITE(HWSTAM, 0xeffe);
30757
30758 @@ -1743,7 +1743,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30759 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30760 int pipe;
30761
30762 - atomic_set(&dev_priv->irq_received, 0);
30763 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30764
30765 /* VLV magic */
30766 I915_WRITE(VLV_IMR, 0);
30767 @@ -2048,7 +2048,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30768 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30769 int pipe;
30770
30771 - atomic_set(&dev_priv->irq_received, 0);
30772 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30773
30774 for_each_pipe(pipe)
30775 I915_WRITE(PIPESTAT(pipe), 0);
30776 @@ -2099,7 +2099,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30777 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30778 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30779
30780 - atomic_inc(&dev_priv->irq_received);
30781 + atomic_inc_unchecked(&dev_priv->irq_received);
30782
30783 iir = I915_READ16(IIR);
30784 if (iir == 0)
30785 @@ -2184,7 +2184,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30786 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30787 int pipe;
30788
30789 - atomic_set(&dev_priv->irq_received, 0);
30790 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30791
30792 if (I915_HAS_HOTPLUG(dev)) {
30793 I915_WRITE(PORT_HOTPLUG_EN, 0);
30794 @@ -2279,7 +2279,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30795 };
30796 int pipe, ret = IRQ_NONE;
30797
30798 - atomic_inc(&dev_priv->irq_received);
30799 + atomic_inc_unchecked(&dev_priv->irq_received);
30800
30801 iir = I915_READ(IIR);
30802 do {
30803 @@ -2405,7 +2405,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30804 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30805 int pipe;
30806
30807 - atomic_set(&dev_priv->irq_received, 0);
30808 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30809
30810 I915_WRITE(PORT_HOTPLUG_EN, 0);
30811 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
30812 @@ -2512,7 +2512,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30813 int irq_received;
30814 int ret = IRQ_NONE, pipe;
30815
30816 - atomic_inc(&dev_priv->irq_received);
30817 + atomic_inc_unchecked(&dev_priv->irq_received);
30818
30819 iir = I915_READ(IIR);
30820
30821 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30822 index 0c7f4aa..c4771ed 100644
30823 --- a/drivers/gpu/drm/i915/intel_display.c
30824 +++ b/drivers/gpu/drm/i915/intel_display.c
30825 @@ -2182,7 +2182,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30826
30827 wait_event(dev_priv->pending_flip_queue,
30828 atomic_read(&dev_priv->mm.wedged) ||
30829 - atomic_read(&obj->pending_flip) == 0);
30830 + atomic_read_unchecked(&obj->pending_flip) == 0);
30831
30832 /* Big Hammer, we also need to ensure that any pending
30833 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30834 @@ -6168,7 +6168,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30835
30836 obj = work->old_fb_obj;
30837
30838 - atomic_clear_mask(1 << intel_crtc->plane,
30839 + atomic_clear_mask_unchecked(1 << intel_crtc->plane,
30840 &obj->pending_flip.counter);
30841
30842 wake_up(&dev_priv->pending_flip_queue);
30843 @@ -6515,7 +6515,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30844 /* Block clients from rendering to the new back buffer until
30845 * the flip occurs and the object is no longer visible.
30846 */
30847 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30848 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30849
30850 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30851 if (ret)
30852 @@ -6530,7 +6530,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30853 return 0;
30854
30855 cleanup_pending:
30856 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30857 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30858 drm_gem_object_unreference(&work->old_fb_obj->base);
30859 drm_gem_object_unreference(&obj->base);
30860 mutex_unlock(&dev->struct_mutex);
30861 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30862 index 54558a0..2d97005 100644
30863 --- a/drivers/gpu/drm/mga/mga_drv.h
30864 +++ b/drivers/gpu/drm/mga/mga_drv.h
30865 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30866 u32 clear_cmd;
30867 u32 maccess;
30868
30869 - atomic_t vbl_received; /**< Number of vblanks received. */
30870 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30871 wait_queue_head_t fence_queue;
30872 - atomic_t last_fence_retired;
30873 + atomic_unchecked_t last_fence_retired;
30874 u32 next_fence_to_post;
30875
30876 unsigned int fb_cpp;
30877 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30878 index 2581202..f230a8d9 100644
30879 --- a/drivers/gpu/drm/mga/mga_irq.c
30880 +++ b/drivers/gpu/drm/mga/mga_irq.c
30881 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30882 if (crtc != 0)
30883 return 0;
30884
30885 - return atomic_read(&dev_priv->vbl_received);
30886 + return atomic_read_unchecked(&dev_priv->vbl_received);
30887 }
30888
30889
30890 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30891 /* VBLANK interrupt */
30892 if (status & MGA_VLINEPEN) {
30893 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30894 - atomic_inc(&dev_priv->vbl_received);
30895 + atomic_inc_unchecked(&dev_priv->vbl_received);
30896 drm_handle_vblank(dev, 0);
30897 handled = 1;
30898 }
30899 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30900 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30901 MGA_WRITE(MGA_PRIMEND, prim_end);
30902
30903 - atomic_inc(&dev_priv->last_fence_retired);
30904 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30905 DRM_WAKEUP(&dev_priv->fence_queue);
30906 handled = 1;
30907 }
30908 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30909 * using fences.
30910 */
30911 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30912 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30913 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30914 - *sequence) <= (1 << 23)));
30915
30916 *sequence = cur_fence;
30917 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30918 index a0a3fe3..209bf10 100644
30919 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30920 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30921 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30922 struct bit_table {
30923 const char id;
30924 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30925 -};
30926 +} __no_const;
30927
30928 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30929
30930 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30931 index 4f2cc95..9c6c510 100644
30932 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30933 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30934 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30935 u32 handle, u16 class);
30936 void (*set_tile_region)(struct drm_device *dev, int i);
30937 void (*tlb_flush)(struct drm_device *, int engine);
30938 -};
30939 +} __no_const;
30940
30941 struct nouveau_instmem_engine {
30942 void *priv;
30943 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30944 struct nouveau_mc_engine {
30945 int (*init)(struct drm_device *dev);
30946 void (*takedown)(struct drm_device *dev);
30947 -};
30948 +} __no_const;
30949
30950 struct nouveau_timer_engine {
30951 int (*init)(struct drm_device *dev);
30952 void (*takedown)(struct drm_device *dev);
30953 uint64_t (*read)(struct drm_device *dev);
30954 -};
30955 +} __no_const;
30956
30957 struct nouveau_fb_engine {
30958 int num_tiles;
30959 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30960 void (*put)(struct drm_device *, struct nouveau_mem **);
30961
30962 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30963 -};
30964 +} __no_const;
30965
30966 struct nouveau_engine {
30967 struct nouveau_instmem_engine instmem;
30968 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30969 struct drm_global_reference mem_global_ref;
30970 struct ttm_bo_global_ref bo_global_ref;
30971 struct ttm_bo_device bdev;
30972 - atomic_t validate_sequence;
30973 + atomic_unchecked_t validate_sequence;
30974 int (*move)(struct nouveau_channel *,
30975 struct ttm_buffer_object *,
30976 struct ttm_mem_reg *, struct ttm_mem_reg *);
30977 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30978 index af7cfb8..aadc2a3 100644
30979 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30980 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30981 @@ -318,7 +318,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30982 int trycnt = 0;
30983 int ret, i;
30984
30985 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30986 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30987 retry:
30988 if (++trycnt > 100000) {
30989 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30990 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30991 index c610144..97440e2 100644
30992 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30993 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30994 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30995 bool can_switch;
30996
30997 spin_lock(&dev->count_lock);
30998 - can_switch = (dev->open_count == 0);
30999 + can_switch = (local_read(&dev->open_count) == 0);
31000 spin_unlock(&dev->count_lock);
31001 return can_switch;
31002 }
31003 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
31004 index 93240bd..c490f60 100644
31005 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
31006 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
31007 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
31008 }
31009
31010 if (nv_encoder->dcb->type == OUTPUT_DP) {
31011 - struct dp_train_func func = {
31012 + static struct dp_train_func func = {
31013 .link_set = nv50_sor_dp_link_set,
31014 .train_set = nv50_sor_dp_train_set,
31015 .train_adj = nv50_sor_dp_train_adj
31016 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
31017 index 8a2fc89..3a5cf40 100644
31018 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
31019 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
31020 @@ -1367,7 +1367,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
31021 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
31022
31023 if (nv_encoder->dcb->type == OUTPUT_DP) {
31024 - struct dp_train_func func = {
31025 + static struct dp_train_func func = {
31026 .link_set = nvd0_sor_dp_link_set,
31027 .train_set = nvd0_sor_dp_train_set,
31028 .train_adj = nvd0_sor_dp_train_adj
31029 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
31030 index bcac90b..53bfc76 100644
31031 --- a/drivers/gpu/drm/r128/r128_cce.c
31032 +++ b/drivers/gpu/drm/r128/r128_cce.c
31033 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
31034
31035 /* GH: Simple idle check.
31036 */
31037 - atomic_set(&dev_priv->idle_count, 0);
31038 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31039
31040 /* We don't support anything other than bus-mastering ring mode,
31041 * but the ring can be in either AGP or PCI space for the ring
31042 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
31043 index 930c71b..499aded 100644
31044 --- a/drivers/gpu/drm/r128/r128_drv.h
31045 +++ b/drivers/gpu/drm/r128/r128_drv.h
31046 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31047 int is_pci;
31048 unsigned long cce_buffers_offset;
31049
31050 - atomic_t idle_count;
31051 + atomic_unchecked_t idle_count;
31052
31053 int page_flipping;
31054 int current_page;
31055 u32 crtc_offset;
31056 u32 crtc_offset_cntl;
31057
31058 - atomic_t vbl_received;
31059 + atomic_unchecked_t vbl_received;
31060
31061 u32 color_fmt;
31062 unsigned int front_offset;
31063 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31064 index 429d5a0..7e899ed 100644
31065 --- a/drivers/gpu/drm/r128/r128_irq.c
31066 +++ b/drivers/gpu/drm/r128/r128_irq.c
31067 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31068 if (crtc != 0)
31069 return 0;
31070
31071 - return atomic_read(&dev_priv->vbl_received);
31072 + return atomic_read_unchecked(&dev_priv->vbl_received);
31073 }
31074
31075 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31076 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31077 /* VBLANK interrupt */
31078 if (status & R128_CRTC_VBLANK_INT) {
31079 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31080 - atomic_inc(&dev_priv->vbl_received);
31081 + atomic_inc_unchecked(&dev_priv->vbl_received);
31082 drm_handle_vblank(dev, 0);
31083 return IRQ_HANDLED;
31084 }
31085 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31086 index a9e33ce..09edd4b 100644
31087 --- a/drivers/gpu/drm/r128/r128_state.c
31088 +++ b/drivers/gpu/drm/r128/r128_state.c
31089 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31090
31091 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31092 {
31093 - if (atomic_read(&dev_priv->idle_count) == 0)
31094 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31095 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31096 else
31097 - atomic_set(&dev_priv->idle_count, 0);
31098 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31099 }
31100
31101 #endif
31102 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31103 index 5a82b6b..9e69c73 100644
31104 --- a/drivers/gpu/drm/radeon/mkregtable.c
31105 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31106 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31107 regex_t mask_rex;
31108 regmatch_t match[4];
31109 char buf[1024];
31110 - size_t end;
31111 + long end;
31112 int len;
31113 int done = 0;
31114 int r;
31115 unsigned o;
31116 struct offset *offset;
31117 char last_reg_s[10];
31118 - int last_reg;
31119 + unsigned long last_reg;
31120
31121 if (regcomp
31122 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31123 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31124 index 59a1531..3bab49b 100644
31125 --- a/drivers/gpu/drm/radeon/radeon.h
31126 +++ b/drivers/gpu/drm/radeon/radeon.h
31127 @@ -711,7 +711,7 @@ struct r600_blit_cp_primitives {
31128 int x2, int y2);
31129 void (*draw_auto)(struct radeon_device *rdev);
31130 void (*set_default_state)(struct radeon_device *rdev);
31131 -};
31132 +} __no_const;
31133
31134 struct r600_blit {
31135 struct radeon_bo *shader_obj;
31136 @@ -1216,7 +1216,7 @@ struct radeon_asic {
31137 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31138 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31139 } pflip;
31140 -};
31141 +} __no_const;
31142
31143 /*
31144 * Asic structures
31145 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31146 index 7a3daeb..5016171 100644
31147 --- a/drivers/gpu/drm/radeon/radeon_device.c
31148 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31149 @@ -952,7 +952,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31150 bool can_switch;
31151
31152 spin_lock(&dev->count_lock);
31153 - can_switch = (dev->open_count == 0);
31154 + can_switch = (local_read(&dev->open_count) == 0);
31155 spin_unlock(&dev->count_lock);
31156 return can_switch;
31157 }
31158 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31159 index a1b59ca..86f2d44 100644
31160 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31161 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31162 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31163
31164 /* SW interrupt */
31165 wait_queue_head_t swi_queue;
31166 - atomic_t swi_emitted;
31167 + atomic_unchecked_t swi_emitted;
31168 int vblank_crtc;
31169 uint32_t irq_enable_reg;
31170 uint32_t r500_disp_irq_reg;
31171 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31172 index 48b7cea..342236f 100644
31173 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31174 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31175 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31176 request = compat_alloc_user_space(sizeof(*request));
31177 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31178 || __put_user(req32.param, &request->param)
31179 - || __put_user((void __user *)(unsigned long)req32.value,
31180 + || __put_user((unsigned long)req32.value,
31181 &request->value))
31182 return -EFAULT;
31183
31184 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31185 index 00da384..32f972d 100644
31186 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31187 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31188 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31189 unsigned int ret;
31190 RING_LOCALS;
31191
31192 - atomic_inc(&dev_priv->swi_emitted);
31193 - ret = atomic_read(&dev_priv->swi_emitted);
31194 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31195 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31196
31197 BEGIN_RING(4);
31198 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31199 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31200 drm_radeon_private_t *dev_priv =
31201 (drm_radeon_private_t *) dev->dev_private;
31202
31203 - atomic_set(&dev_priv->swi_emitted, 0);
31204 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31205 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31206
31207 dev->max_vblank_count = 0x001fffff;
31208 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31209 index e8422ae..d22d4a8 100644
31210 --- a/drivers/gpu/drm/radeon/radeon_state.c
31211 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31212 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31213 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31214 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31215
31216 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31217 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31218 sarea_priv->nbox * sizeof(depth_boxes[0])))
31219 return -EFAULT;
31220
31221 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31222 {
31223 drm_radeon_private_t *dev_priv = dev->dev_private;
31224 drm_radeon_getparam_t *param = data;
31225 - int value;
31226 + int value = 0;
31227
31228 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31229
31230 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31231 index 5b71c71..650f9e4 100644
31232 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31233 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31234 @@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31235 }
31236 if (unlikely(ttm_vm_ops == NULL)) {
31237 ttm_vm_ops = vma->vm_ops;
31238 - radeon_ttm_vm_ops = *ttm_vm_ops;
31239 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31240 + pax_open_kernel();
31241 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31242 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31243 + pax_close_kernel();
31244 }
31245 vma->vm_ops = &radeon_ttm_vm_ops;
31246 return 0;
31247 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31248 index 3b663fc..57850f4 100644
31249 --- a/drivers/gpu/drm/radeon/rs690.c
31250 +++ b/drivers/gpu/drm/radeon/rs690.c
31251 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31252 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31253 rdev->pm.sideport_bandwidth.full)
31254 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31255 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31256 + read_delay_latency.full = dfixed_const(800 * 1000);
31257 read_delay_latency.full = dfixed_div(read_delay_latency,
31258 rdev->pm.igp_sideport_mclk);
31259 + a.full = dfixed_const(370);
31260 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31261 } else {
31262 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31263 rdev->pm.k8_bandwidth.full)
31264 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31265 index ebc6fac..a8313ed 100644
31266 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31267 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31268 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31269 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31270 struct shrink_control *sc)
31271 {
31272 - static atomic_t start_pool = ATOMIC_INIT(0);
31273 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31274 unsigned i;
31275 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31276 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31277 struct ttm_page_pool *pool;
31278 int shrink_pages = sc->nr_to_scan;
31279
31280 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31281 index 88edacc..1e5412b 100644
31282 --- a/drivers/gpu/drm/via/via_drv.h
31283 +++ b/drivers/gpu/drm/via/via_drv.h
31284 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31285 typedef uint32_t maskarray_t[5];
31286
31287 typedef struct drm_via_irq {
31288 - atomic_t irq_received;
31289 + atomic_unchecked_t irq_received;
31290 uint32_t pending_mask;
31291 uint32_t enable_mask;
31292 wait_queue_head_t irq_queue;
31293 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31294 struct timeval last_vblank;
31295 int last_vblank_valid;
31296 unsigned usec_per_vblank;
31297 - atomic_t vbl_received;
31298 + atomic_unchecked_t vbl_received;
31299 drm_via_state_t hc_state;
31300 char pci_buf[VIA_PCI_BUF_SIZE];
31301 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31302 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31303 index d391f48..10c8ca3 100644
31304 --- a/drivers/gpu/drm/via/via_irq.c
31305 +++ b/drivers/gpu/drm/via/via_irq.c
31306 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31307 if (crtc != 0)
31308 return 0;
31309
31310 - return atomic_read(&dev_priv->vbl_received);
31311 + return atomic_read_unchecked(&dev_priv->vbl_received);
31312 }
31313
31314 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31315 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31316
31317 status = VIA_READ(VIA_REG_INTERRUPT);
31318 if (status & VIA_IRQ_VBLANK_PENDING) {
31319 - atomic_inc(&dev_priv->vbl_received);
31320 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31321 + atomic_inc_unchecked(&dev_priv->vbl_received);
31322 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31323 do_gettimeofday(&cur_vblank);
31324 if (dev_priv->last_vblank_valid) {
31325 dev_priv->usec_per_vblank =
31326 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31327 dev_priv->last_vblank = cur_vblank;
31328 dev_priv->last_vblank_valid = 1;
31329 }
31330 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31331 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31332 DRM_DEBUG("US per vblank is: %u\n",
31333 dev_priv->usec_per_vblank);
31334 }
31335 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31336
31337 for (i = 0; i < dev_priv->num_irqs; ++i) {
31338 if (status & cur_irq->pending_mask) {
31339 - atomic_inc(&cur_irq->irq_received);
31340 + atomic_inc_unchecked(&cur_irq->irq_received);
31341 DRM_WAKEUP(&cur_irq->irq_queue);
31342 handled = 1;
31343 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31344 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31345 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31346 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31347 masks[irq][4]));
31348 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31349 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31350 } else {
31351 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31352 (((cur_irq_sequence =
31353 - atomic_read(&cur_irq->irq_received)) -
31354 + atomic_read_unchecked(&cur_irq->irq_received)) -
31355 *sequence) <= (1 << 23)));
31356 }
31357 *sequence = cur_irq_sequence;
31358 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31359 }
31360
31361 for (i = 0; i < dev_priv->num_irqs; ++i) {
31362 - atomic_set(&cur_irq->irq_received, 0);
31363 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31364 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31365 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31366 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31367 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31368 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31369 case VIA_IRQ_RELATIVE:
31370 irqwait->request.sequence +=
31371 - atomic_read(&cur_irq->irq_received);
31372 + atomic_read_unchecked(&cur_irq->irq_received);
31373 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31374 case VIA_IRQ_ABSOLUTE:
31375 break;
31376 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31377 index 29c984f..4084f1a 100644
31378 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31379 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31380 @@ -263,7 +263,7 @@ struct vmw_private {
31381 * Fencing and IRQs.
31382 */
31383
31384 - atomic_t marker_seq;
31385 + atomic_unchecked_t marker_seq;
31386 wait_queue_head_t fence_queue;
31387 wait_queue_head_t fifo_queue;
31388 int fence_queue_waiters; /* Protected by hw_mutex */
31389 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31390 index a0c2f12..68ae6cb 100644
31391 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31392 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31393 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31394 (unsigned int) min,
31395 (unsigned int) fifo->capabilities);
31396
31397 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31398 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31399 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31400 vmw_marker_queue_init(&fifo->marker_queue);
31401 return vmw_fifo_send_fence(dev_priv, &dummy);
31402 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31403 if (reserveable)
31404 iowrite32(bytes, fifo_mem +
31405 SVGA_FIFO_RESERVED);
31406 - return fifo_mem + (next_cmd >> 2);
31407 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31408 } else {
31409 need_bounce = true;
31410 }
31411 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31412
31413 fm = vmw_fifo_reserve(dev_priv, bytes);
31414 if (unlikely(fm == NULL)) {
31415 - *seqno = atomic_read(&dev_priv->marker_seq);
31416 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31417 ret = -ENOMEM;
31418 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31419 false, 3*HZ);
31420 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31421 }
31422
31423 do {
31424 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31425 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31426 } while (*seqno == 0);
31427
31428 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31429 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31430 index cabc95f..14b3d77 100644
31431 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31432 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31433 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31434 * emitted. Then the fence is stale and signaled.
31435 */
31436
31437 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31438 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31439 > VMW_FENCE_WRAP);
31440
31441 return ret;
31442 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31443
31444 if (fifo_idle)
31445 down_read(&fifo_state->rwsem);
31446 - signal_seq = atomic_read(&dev_priv->marker_seq);
31447 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31448 ret = 0;
31449
31450 for (;;) {
31451 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31452 index 8a8725c..afed796 100644
31453 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31454 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31455 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31456 while (!vmw_lag_lt(queue, us)) {
31457 spin_lock(&queue->lock);
31458 if (list_empty(&queue->head))
31459 - seqno = atomic_read(&dev_priv->marker_seq);
31460 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31461 else {
31462 marker = list_first_entry(&queue->head,
31463 struct vmw_marker, head);
31464 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31465 index 5de3bb3..08e5063 100644
31466 --- a/drivers/hid/hid-core.c
31467 +++ b/drivers/hid/hid-core.c
31468 @@ -2177,7 +2177,7 @@ static bool hid_ignore(struct hid_device *hdev)
31469
31470 int hid_add_device(struct hid_device *hdev)
31471 {
31472 - static atomic_t id = ATOMIC_INIT(0);
31473 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31474 int ret;
31475
31476 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31477 @@ -2212,7 +2212,7 @@ int hid_add_device(struct hid_device *hdev)
31478 /* XXX hack, any other cleaner solution after the driver core
31479 * is converted to allow more than 20 bytes as the device name? */
31480 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31481 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31482 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31483
31484 hid_debug_register(hdev, dev_name(&hdev->dev));
31485 ret = device_add(&hdev->dev);
31486 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31487 index eec3291..8ed706b 100644
31488 --- a/drivers/hid/hid-wiimote-debug.c
31489 +++ b/drivers/hid/hid-wiimote-debug.c
31490 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31491 else if (size == 0)
31492 return -EIO;
31493
31494 - if (copy_to_user(u, buf, size))
31495 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31496 return -EFAULT;
31497
31498 *off += size;
31499 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31500 index 14599e2..711c965 100644
31501 --- a/drivers/hid/usbhid/hiddev.c
31502 +++ b/drivers/hid/usbhid/hiddev.c
31503 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31504 break;
31505
31506 case HIDIOCAPPLICATION:
31507 - if (arg < 0 || arg >= hid->maxapplication)
31508 + if (arg >= hid->maxapplication)
31509 break;
31510
31511 for (i = 0; i < hid->maxcollection; i++)
31512 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31513 index 4065374..10ed7dc 100644
31514 --- a/drivers/hv/channel.c
31515 +++ b/drivers/hv/channel.c
31516 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31517 int ret = 0;
31518 int t;
31519
31520 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31521 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31522 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31523 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31524
31525 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31526 if (ret)
31527 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31528 index 86f8885..ab9cb2b 100644
31529 --- a/drivers/hv/hv.c
31530 +++ b/drivers/hv/hv.c
31531 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31532 u64 output_address = (output) ? virt_to_phys(output) : 0;
31533 u32 output_address_hi = output_address >> 32;
31534 u32 output_address_lo = output_address & 0xFFFFFFFF;
31535 - void *hypercall_page = hv_context.hypercall_page;
31536 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31537
31538 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31539 "=a"(hv_status_lo) : "d" (control_hi),
31540 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31541 index 0614ff3..f0b2b5c 100644
31542 --- a/drivers/hv/hyperv_vmbus.h
31543 +++ b/drivers/hv/hyperv_vmbus.h
31544 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31545 struct vmbus_connection {
31546 enum vmbus_connect_state conn_state;
31547
31548 - atomic_t next_gpadl_handle;
31549 + atomic_unchecked_t next_gpadl_handle;
31550
31551 /*
31552 * Represents channel interrupts. Each bit position represents a
31553 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31554 index 4748086..3abf845 100644
31555 --- a/drivers/hv/vmbus_drv.c
31556 +++ b/drivers/hv/vmbus_drv.c
31557 @@ -662,10 +662,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31558 {
31559 int ret = 0;
31560
31561 - static atomic_t device_num = ATOMIC_INIT(0);
31562 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31563
31564 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31565 - atomic_inc_return(&device_num));
31566 + atomic_inc_return_unchecked(&device_num));
31567
31568 child_device_obj->device.bus = &hv_bus;
31569 child_device_obj->device.parent = &hv_acpi_dev->dev;
31570 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31571 index 8b011d0..3de24a1 100644
31572 --- a/drivers/hwmon/sht15.c
31573 +++ b/drivers/hwmon/sht15.c
31574 @@ -166,7 +166,7 @@ struct sht15_data {
31575 int supply_uV;
31576 bool supply_uV_valid;
31577 struct work_struct update_supply_work;
31578 - atomic_t interrupt_handled;
31579 + atomic_unchecked_t interrupt_handled;
31580 };
31581
31582 /**
31583 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31584 return ret;
31585
31586 gpio_direction_input(data->pdata->gpio_data);
31587 - atomic_set(&data->interrupt_handled, 0);
31588 + atomic_set_unchecked(&data->interrupt_handled, 0);
31589
31590 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31591 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31592 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31593 /* Only relevant if the interrupt hasn't occurred. */
31594 - if (!atomic_read(&data->interrupt_handled))
31595 + if (!atomic_read_unchecked(&data->interrupt_handled))
31596 schedule_work(&data->read_work);
31597 }
31598 ret = wait_event_timeout(data->wait_queue,
31599 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31600
31601 /* First disable the interrupt */
31602 disable_irq_nosync(irq);
31603 - atomic_inc(&data->interrupt_handled);
31604 + atomic_inc_unchecked(&data->interrupt_handled);
31605 /* Then schedule a reading work struct */
31606 if (data->state != SHT15_READING_NOTHING)
31607 schedule_work(&data->read_work);
31608 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31609 * If not, then start the interrupt again - care here as could
31610 * have gone low in meantime so verify it hasn't!
31611 */
31612 - atomic_set(&data->interrupt_handled, 0);
31613 + atomic_set_unchecked(&data->interrupt_handled, 0);
31614 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31615 /* If still not occurred or another handler was scheduled */
31616 if (gpio_get_value(data->pdata->gpio_data)
31617 - || atomic_read(&data->interrupt_handled))
31618 + || atomic_read_unchecked(&data->interrupt_handled))
31619 return;
31620 }
31621
31622 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31623 index 378fcb5..5e91fa8 100644
31624 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31625 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31626 @@ -43,7 +43,7 @@
31627 extern struct i2c_adapter amd756_smbus;
31628
31629 static struct i2c_adapter *s4882_adapter;
31630 -static struct i2c_algorithm *s4882_algo;
31631 +static i2c_algorithm_no_const *s4882_algo;
31632
31633 /* Wrapper access functions for multiplexed SMBus */
31634 static DEFINE_MUTEX(amd756_lock);
31635 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31636 index 29015eb..af2d8e9 100644
31637 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31638 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31639 @@ -41,7 +41,7 @@
31640 extern struct i2c_adapter *nforce2_smbus;
31641
31642 static struct i2c_adapter *s4985_adapter;
31643 -static struct i2c_algorithm *s4985_algo;
31644 +static i2c_algorithm_no_const *s4985_algo;
31645
31646 /* Wrapper access functions for multiplexed SMBus */
31647 static DEFINE_MUTEX(nforce2_lock);
31648 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31649 index 1038c38..eb92f51 100644
31650 --- a/drivers/i2c/i2c-mux.c
31651 +++ b/drivers/i2c/i2c-mux.c
31652 @@ -30,7 +30,7 @@
31653 /* multiplexer per channel data */
31654 struct i2c_mux_priv {
31655 struct i2c_adapter adap;
31656 - struct i2c_algorithm algo;
31657 + i2c_algorithm_no_const algo;
31658
31659 struct i2c_adapter *parent;
31660 void *mux_priv; /* the mux chip/device */
31661 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31662 index 57d00ca..0145194 100644
31663 --- a/drivers/ide/aec62xx.c
31664 +++ b/drivers/ide/aec62xx.c
31665 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31666 .cable_detect = atp86x_cable_detect,
31667 };
31668
31669 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31670 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31671 { /* 0: AEC6210 */
31672 .name = DRV_NAME,
31673 .init_chipset = init_chipset_aec62xx,
31674 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31675 index 2c8016a..911a27c 100644
31676 --- a/drivers/ide/alim15x3.c
31677 +++ b/drivers/ide/alim15x3.c
31678 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31679 .dma_sff_read_status = ide_dma_sff_read_status,
31680 };
31681
31682 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31683 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31684 .name = DRV_NAME,
31685 .init_chipset = init_chipset_ali15x3,
31686 .init_hwif = init_hwif_ali15x3,
31687 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31688 index 3747b25..56fc995 100644
31689 --- a/drivers/ide/amd74xx.c
31690 +++ b/drivers/ide/amd74xx.c
31691 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31692 .udma_mask = udma, \
31693 }
31694
31695 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31696 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31697 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31698 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31699 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31700 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31701 index 15f0ead..cb43480 100644
31702 --- a/drivers/ide/atiixp.c
31703 +++ b/drivers/ide/atiixp.c
31704 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31705 .cable_detect = atiixp_cable_detect,
31706 };
31707
31708 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31709 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31710 { /* 0: IXP200/300/400/700 */
31711 .name = DRV_NAME,
31712 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31713 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31714 index 5f80312..d1fc438 100644
31715 --- a/drivers/ide/cmd64x.c
31716 +++ b/drivers/ide/cmd64x.c
31717 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31718 .dma_sff_read_status = ide_dma_sff_read_status,
31719 };
31720
31721 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31722 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31723 { /* 0: CMD643 */
31724 .name = DRV_NAME,
31725 .init_chipset = init_chipset_cmd64x,
31726 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31727 index 2c1e5f7..1444762 100644
31728 --- a/drivers/ide/cs5520.c
31729 +++ b/drivers/ide/cs5520.c
31730 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31731 .set_dma_mode = cs5520_set_dma_mode,
31732 };
31733
31734 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31735 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31736 .name = DRV_NAME,
31737 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31738 .port_ops = &cs5520_port_ops,
31739 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31740 index 4dc4eb9..49b40ad 100644
31741 --- a/drivers/ide/cs5530.c
31742 +++ b/drivers/ide/cs5530.c
31743 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31744 .udma_filter = cs5530_udma_filter,
31745 };
31746
31747 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31748 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31749 .name = DRV_NAME,
31750 .init_chipset = init_chipset_cs5530,
31751 .init_hwif = init_hwif_cs5530,
31752 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31753 index 5059faf..18d4c85 100644
31754 --- a/drivers/ide/cs5535.c
31755 +++ b/drivers/ide/cs5535.c
31756 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31757 .cable_detect = cs5535_cable_detect,
31758 };
31759
31760 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31761 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31762 .name = DRV_NAME,
31763 .port_ops = &cs5535_port_ops,
31764 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31765 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31766 index 847553f..3ffb49d 100644
31767 --- a/drivers/ide/cy82c693.c
31768 +++ b/drivers/ide/cy82c693.c
31769 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31770 .set_dma_mode = cy82c693_set_dma_mode,
31771 };
31772
31773 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31774 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31775 .name = DRV_NAME,
31776 .init_iops = init_iops_cy82c693,
31777 .port_ops = &cy82c693_port_ops,
31778 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31779 index 58c51cd..4aec3b8 100644
31780 --- a/drivers/ide/hpt366.c
31781 +++ b/drivers/ide/hpt366.c
31782 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31783 }
31784 };
31785
31786 -static const struct hpt_info hpt36x __devinitdata = {
31787 +static const struct hpt_info hpt36x __devinitconst = {
31788 .chip_name = "HPT36x",
31789 .chip_type = HPT36x,
31790 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31791 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31792 .timings = &hpt36x_timings
31793 };
31794
31795 -static const struct hpt_info hpt370 __devinitdata = {
31796 +static const struct hpt_info hpt370 __devinitconst = {
31797 .chip_name = "HPT370",
31798 .chip_type = HPT370,
31799 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31800 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31801 .timings = &hpt37x_timings
31802 };
31803
31804 -static const struct hpt_info hpt370a __devinitdata = {
31805 +static const struct hpt_info hpt370a __devinitconst = {
31806 .chip_name = "HPT370A",
31807 .chip_type = HPT370A,
31808 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31809 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31810 .timings = &hpt37x_timings
31811 };
31812
31813 -static const struct hpt_info hpt374 __devinitdata = {
31814 +static const struct hpt_info hpt374 __devinitconst = {
31815 .chip_name = "HPT374",
31816 .chip_type = HPT374,
31817 .udma_mask = ATA_UDMA5,
31818 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31819 .timings = &hpt37x_timings
31820 };
31821
31822 -static const struct hpt_info hpt372 __devinitdata = {
31823 +static const struct hpt_info hpt372 __devinitconst = {
31824 .chip_name = "HPT372",
31825 .chip_type = HPT372,
31826 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31827 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31828 .timings = &hpt37x_timings
31829 };
31830
31831 -static const struct hpt_info hpt372a __devinitdata = {
31832 +static const struct hpt_info hpt372a __devinitconst = {
31833 .chip_name = "HPT372A",
31834 .chip_type = HPT372A,
31835 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31836 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31837 .timings = &hpt37x_timings
31838 };
31839
31840 -static const struct hpt_info hpt302 __devinitdata = {
31841 +static const struct hpt_info hpt302 __devinitconst = {
31842 .chip_name = "HPT302",
31843 .chip_type = HPT302,
31844 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31845 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31846 .timings = &hpt37x_timings
31847 };
31848
31849 -static const struct hpt_info hpt371 __devinitdata = {
31850 +static const struct hpt_info hpt371 __devinitconst = {
31851 .chip_name = "HPT371",
31852 .chip_type = HPT371,
31853 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31854 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31855 .timings = &hpt37x_timings
31856 };
31857
31858 -static const struct hpt_info hpt372n __devinitdata = {
31859 +static const struct hpt_info hpt372n __devinitconst = {
31860 .chip_name = "HPT372N",
31861 .chip_type = HPT372N,
31862 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31863 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31864 .timings = &hpt37x_timings
31865 };
31866
31867 -static const struct hpt_info hpt302n __devinitdata = {
31868 +static const struct hpt_info hpt302n __devinitconst = {
31869 .chip_name = "HPT302N",
31870 .chip_type = HPT302N,
31871 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31872 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31873 .timings = &hpt37x_timings
31874 };
31875
31876 -static const struct hpt_info hpt371n __devinitdata = {
31877 +static const struct hpt_info hpt371n __devinitconst = {
31878 .chip_name = "HPT371N",
31879 .chip_type = HPT371N,
31880 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31881 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31882 .dma_sff_read_status = ide_dma_sff_read_status,
31883 };
31884
31885 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31886 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31887 { /* 0: HPT36x */
31888 .name = DRV_NAME,
31889 .init_chipset = init_chipset_hpt366,
31890 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31891 index 8126824..55a2798 100644
31892 --- a/drivers/ide/ide-cd.c
31893 +++ b/drivers/ide/ide-cd.c
31894 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31895 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31896 if ((unsigned long)buf & alignment
31897 || blk_rq_bytes(rq) & q->dma_pad_mask
31898 - || object_is_on_stack(buf))
31899 + || object_starts_on_stack(buf))
31900 drive->dma = 0;
31901 }
31902 }
31903 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31904 index 7f56b73..dab5b67 100644
31905 --- a/drivers/ide/ide-pci-generic.c
31906 +++ b/drivers/ide/ide-pci-generic.c
31907 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31908 .udma_mask = ATA_UDMA6, \
31909 }
31910
31911 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31912 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31913 /* 0: Unknown */
31914 DECLARE_GENERIC_PCI_DEV(0),
31915
31916 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31917 index 560e66d..d5dd180 100644
31918 --- a/drivers/ide/it8172.c
31919 +++ b/drivers/ide/it8172.c
31920 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31921 .set_dma_mode = it8172_set_dma_mode,
31922 };
31923
31924 -static const struct ide_port_info it8172_port_info __devinitdata = {
31925 +static const struct ide_port_info it8172_port_info __devinitconst = {
31926 .name = DRV_NAME,
31927 .port_ops = &it8172_port_ops,
31928 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31929 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31930 index 46816ba..1847aeb 100644
31931 --- a/drivers/ide/it8213.c
31932 +++ b/drivers/ide/it8213.c
31933 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31934 .cable_detect = it8213_cable_detect,
31935 };
31936
31937 -static const struct ide_port_info it8213_chipset __devinitdata = {
31938 +static const struct ide_port_info it8213_chipset __devinitconst = {
31939 .name = DRV_NAME,
31940 .enablebits = { {0x41, 0x80, 0x80} },
31941 .port_ops = &it8213_port_ops,
31942 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31943 index 2e3169f..c5611db 100644
31944 --- a/drivers/ide/it821x.c
31945 +++ b/drivers/ide/it821x.c
31946 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31947 .cable_detect = it821x_cable_detect,
31948 };
31949
31950 -static const struct ide_port_info it821x_chipset __devinitdata = {
31951 +static const struct ide_port_info it821x_chipset __devinitconst = {
31952 .name = DRV_NAME,
31953 .init_chipset = init_chipset_it821x,
31954 .init_hwif = init_hwif_it821x,
31955 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31956 index 74c2c4a..efddd7d 100644
31957 --- a/drivers/ide/jmicron.c
31958 +++ b/drivers/ide/jmicron.c
31959 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31960 .cable_detect = jmicron_cable_detect,
31961 };
31962
31963 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31964 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31965 .name = DRV_NAME,
31966 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31967 .port_ops = &jmicron_port_ops,
31968 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31969 index 95327a2..73f78d8 100644
31970 --- a/drivers/ide/ns87415.c
31971 +++ b/drivers/ide/ns87415.c
31972 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31973 .dma_sff_read_status = superio_dma_sff_read_status,
31974 };
31975
31976 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31977 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31978 .name = DRV_NAME,
31979 .init_hwif = init_hwif_ns87415,
31980 .tp_ops = &ns87415_tp_ops,
31981 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31982 index 1a53a4c..39edc66 100644
31983 --- a/drivers/ide/opti621.c
31984 +++ b/drivers/ide/opti621.c
31985 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31986 .set_pio_mode = opti621_set_pio_mode,
31987 };
31988
31989 -static const struct ide_port_info opti621_chipset __devinitdata = {
31990 +static const struct ide_port_info opti621_chipset __devinitconst = {
31991 .name = DRV_NAME,
31992 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31993 .port_ops = &opti621_port_ops,
31994 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31995 index 9546fe2..2e5ceb6 100644
31996 --- a/drivers/ide/pdc202xx_new.c
31997 +++ b/drivers/ide/pdc202xx_new.c
31998 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31999 .udma_mask = udma, \
32000 }
32001
32002 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
32003 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
32004 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
32005 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
32006 };
32007 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
32008 index 3a35ec6..5634510 100644
32009 --- a/drivers/ide/pdc202xx_old.c
32010 +++ b/drivers/ide/pdc202xx_old.c
32011 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
32012 .max_sectors = sectors, \
32013 }
32014
32015 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
32016 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
32017 { /* 0: PDC20246 */
32018 .name = DRV_NAME,
32019 .init_chipset = init_chipset_pdc202xx,
32020 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
32021 index 1892e81..fe0fd60 100644
32022 --- a/drivers/ide/piix.c
32023 +++ b/drivers/ide/piix.c
32024 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
32025 .udma_mask = udma, \
32026 }
32027
32028 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
32029 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
32030 /* 0: MPIIX */
32031 { /*
32032 * MPIIX actually has only a single IDE channel mapped to
32033 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32034 index a6414a8..c04173e 100644
32035 --- a/drivers/ide/rz1000.c
32036 +++ b/drivers/ide/rz1000.c
32037 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32038 }
32039 }
32040
32041 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32042 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32043 .name = DRV_NAME,
32044 .host_flags = IDE_HFLAG_NO_DMA,
32045 };
32046 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32047 index 356b9b5..d4758eb 100644
32048 --- a/drivers/ide/sc1200.c
32049 +++ b/drivers/ide/sc1200.c
32050 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32051 .dma_sff_read_status = ide_dma_sff_read_status,
32052 };
32053
32054 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32055 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32056 .name = DRV_NAME,
32057 .port_ops = &sc1200_port_ops,
32058 .dma_ops = &sc1200_dma_ops,
32059 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32060 index b7f5b0c..9701038 100644
32061 --- a/drivers/ide/scc_pata.c
32062 +++ b/drivers/ide/scc_pata.c
32063 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32064 .dma_sff_read_status = scc_dma_sff_read_status,
32065 };
32066
32067 -static const struct ide_port_info scc_chipset __devinitdata = {
32068 +static const struct ide_port_info scc_chipset __devinitconst = {
32069 .name = "sccIDE",
32070 .init_iops = init_iops_scc,
32071 .init_dma = scc_init_dma,
32072 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32073 index 35fb8da..24d72ef 100644
32074 --- a/drivers/ide/serverworks.c
32075 +++ b/drivers/ide/serverworks.c
32076 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32077 .cable_detect = svwks_cable_detect,
32078 };
32079
32080 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32081 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32082 { /* 0: OSB4 */
32083 .name = DRV_NAME,
32084 .init_chipset = init_chipset_svwks,
32085 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32086 index ddeda44..46f7e30 100644
32087 --- a/drivers/ide/siimage.c
32088 +++ b/drivers/ide/siimage.c
32089 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32090 .udma_mask = ATA_UDMA6, \
32091 }
32092
32093 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32094 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32095 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32096 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32097 };
32098 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32099 index 4a00225..09e61b4 100644
32100 --- a/drivers/ide/sis5513.c
32101 +++ b/drivers/ide/sis5513.c
32102 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32103 .cable_detect = sis_cable_detect,
32104 };
32105
32106 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32107 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32108 .name = DRV_NAME,
32109 .init_chipset = init_chipset_sis5513,
32110 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32111 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32112 index f21dc2a..d051cd2 100644
32113 --- a/drivers/ide/sl82c105.c
32114 +++ b/drivers/ide/sl82c105.c
32115 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32116 .dma_sff_read_status = ide_dma_sff_read_status,
32117 };
32118
32119 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32120 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32121 .name = DRV_NAME,
32122 .init_chipset = init_chipset_sl82c105,
32123 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32124 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32125 index 864ffe0..863a5e9 100644
32126 --- a/drivers/ide/slc90e66.c
32127 +++ b/drivers/ide/slc90e66.c
32128 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32129 .cable_detect = slc90e66_cable_detect,
32130 };
32131
32132 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32133 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32134 .name = DRV_NAME,
32135 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32136 .port_ops = &slc90e66_port_ops,
32137 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32138 index 4799d5c..1794678 100644
32139 --- a/drivers/ide/tc86c001.c
32140 +++ b/drivers/ide/tc86c001.c
32141 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32142 .dma_sff_read_status = ide_dma_sff_read_status,
32143 };
32144
32145 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32146 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32147 .name = DRV_NAME,
32148 .init_hwif = init_hwif_tc86c001,
32149 .port_ops = &tc86c001_port_ops,
32150 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32151 index 281c914..55ce1b8 100644
32152 --- a/drivers/ide/triflex.c
32153 +++ b/drivers/ide/triflex.c
32154 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32155 .set_dma_mode = triflex_set_mode,
32156 };
32157
32158 -static const struct ide_port_info triflex_device __devinitdata = {
32159 +static const struct ide_port_info triflex_device __devinitconst = {
32160 .name = DRV_NAME,
32161 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32162 .port_ops = &triflex_port_ops,
32163 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32164 index 4b42ca0..e494a98 100644
32165 --- a/drivers/ide/trm290.c
32166 +++ b/drivers/ide/trm290.c
32167 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32168 .dma_check = trm290_dma_check,
32169 };
32170
32171 -static const struct ide_port_info trm290_chipset __devinitdata = {
32172 +static const struct ide_port_info trm290_chipset __devinitconst = {
32173 .name = DRV_NAME,
32174 .init_hwif = init_hwif_trm290,
32175 .tp_ops = &trm290_tp_ops,
32176 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32177 index f46f49c..eb77678 100644
32178 --- a/drivers/ide/via82cxxx.c
32179 +++ b/drivers/ide/via82cxxx.c
32180 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32181 .cable_detect = via82cxxx_cable_detect,
32182 };
32183
32184 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32185 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32186 .name = DRV_NAME,
32187 .init_chipset = init_chipset_via82cxxx,
32188 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32189 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32190 index 73d4531..c90cd2d 100644
32191 --- a/drivers/ieee802154/fakehard.c
32192 +++ b/drivers/ieee802154/fakehard.c
32193 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32194 phy->transmit_power = 0xbf;
32195
32196 dev->netdev_ops = &fake_ops;
32197 - dev->ml_priv = &fake_mlme;
32198 + dev->ml_priv = (void *)&fake_mlme;
32199
32200 priv = netdev_priv(dev);
32201 priv->phy = phy;
32202 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32203 index d67999f..4c5d083 100644
32204 --- a/drivers/infiniband/core/cm.c
32205 +++ b/drivers/infiniband/core/cm.c
32206 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32207
32208 struct cm_counter_group {
32209 struct kobject obj;
32210 - atomic_long_t counter[CM_ATTR_COUNT];
32211 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32212 };
32213
32214 struct cm_counter_attribute {
32215 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32216 struct ib_mad_send_buf *msg = NULL;
32217 int ret;
32218
32219 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32220 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32221 counter[CM_REQ_COUNTER]);
32222
32223 /* Quick state check to discard duplicate REQs. */
32224 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32225 if (!cm_id_priv)
32226 return;
32227
32228 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32229 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32230 counter[CM_REP_COUNTER]);
32231 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32232 if (ret)
32233 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32234 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32235 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32236 spin_unlock_irq(&cm_id_priv->lock);
32237 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32238 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32239 counter[CM_RTU_COUNTER]);
32240 goto out;
32241 }
32242 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32243 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32244 dreq_msg->local_comm_id);
32245 if (!cm_id_priv) {
32246 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32247 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32248 counter[CM_DREQ_COUNTER]);
32249 cm_issue_drep(work->port, work->mad_recv_wc);
32250 return -EINVAL;
32251 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32252 case IB_CM_MRA_REP_RCVD:
32253 break;
32254 case IB_CM_TIMEWAIT:
32255 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32256 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32257 counter[CM_DREQ_COUNTER]);
32258 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32259 goto unlock;
32260 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32261 cm_free_msg(msg);
32262 goto deref;
32263 case IB_CM_DREQ_RCVD:
32264 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32265 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32266 counter[CM_DREQ_COUNTER]);
32267 goto unlock;
32268 default:
32269 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32270 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32271 cm_id_priv->msg, timeout)) {
32272 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32273 - atomic_long_inc(&work->port->
32274 + atomic_long_inc_unchecked(&work->port->
32275 counter_group[CM_RECV_DUPLICATES].
32276 counter[CM_MRA_COUNTER]);
32277 goto out;
32278 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32279 break;
32280 case IB_CM_MRA_REQ_RCVD:
32281 case IB_CM_MRA_REP_RCVD:
32282 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32283 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32284 counter[CM_MRA_COUNTER]);
32285 /* fall through */
32286 default:
32287 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32288 case IB_CM_LAP_IDLE:
32289 break;
32290 case IB_CM_MRA_LAP_SENT:
32291 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32292 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32293 counter[CM_LAP_COUNTER]);
32294 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32295 goto unlock;
32296 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32297 cm_free_msg(msg);
32298 goto deref;
32299 case IB_CM_LAP_RCVD:
32300 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32301 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32302 counter[CM_LAP_COUNTER]);
32303 goto unlock;
32304 default:
32305 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32306 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32307 if (cur_cm_id_priv) {
32308 spin_unlock_irq(&cm.lock);
32309 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32310 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32311 counter[CM_SIDR_REQ_COUNTER]);
32312 goto out; /* Duplicate message. */
32313 }
32314 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32315 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32316 msg->retries = 1;
32317
32318 - atomic_long_add(1 + msg->retries,
32319 + atomic_long_add_unchecked(1 + msg->retries,
32320 &port->counter_group[CM_XMIT].counter[attr_index]);
32321 if (msg->retries)
32322 - atomic_long_add(msg->retries,
32323 + atomic_long_add_unchecked(msg->retries,
32324 &port->counter_group[CM_XMIT_RETRIES].
32325 counter[attr_index]);
32326
32327 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32328 }
32329
32330 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32331 - atomic_long_inc(&port->counter_group[CM_RECV].
32332 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32333 counter[attr_id - CM_ATTR_ID_OFFSET]);
32334
32335 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32336 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32337 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32338
32339 return sprintf(buf, "%ld\n",
32340 - atomic_long_read(&group->counter[cm_attr->index]));
32341 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32342 }
32343
32344 static const struct sysfs_ops cm_counter_ops = {
32345 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32346 index 176c8f9..2627b62 100644
32347 --- a/drivers/infiniband/core/fmr_pool.c
32348 +++ b/drivers/infiniband/core/fmr_pool.c
32349 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32350
32351 struct task_struct *thread;
32352
32353 - atomic_t req_ser;
32354 - atomic_t flush_ser;
32355 + atomic_unchecked_t req_ser;
32356 + atomic_unchecked_t flush_ser;
32357
32358 wait_queue_head_t force_wait;
32359 };
32360 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32361 struct ib_fmr_pool *pool = pool_ptr;
32362
32363 do {
32364 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32365 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32366 ib_fmr_batch_release(pool);
32367
32368 - atomic_inc(&pool->flush_ser);
32369 + atomic_inc_unchecked(&pool->flush_ser);
32370 wake_up_interruptible(&pool->force_wait);
32371
32372 if (pool->flush_function)
32373 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32374 }
32375
32376 set_current_state(TASK_INTERRUPTIBLE);
32377 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32378 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32379 !kthread_should_stop())
32380 schedule();
32381 __set_current_state(TASK_RUNNING);
32382 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32383 pool->dirty_watermark = params->dirty_watermark;
32384 pool->dirty_len = 0;
32385 spin_lock_init(&pool->pool_lock);
32386 - atomic_set(&pool->req_ser, 0);
32387 - atomic_set(&pool->flush_ser, 0);
32388 + atomic_set_unchecked(&pool->req_ser, 0);
32389 + atomic_set_unchecked(&pool->flush_ser, 0);
32390 init_waitqueue_head(&pool->force_wait);
32391
32392 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32393 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32394 }
32395 spin_unlock_irq(&pool->pool_lock);
32396
32397 - serial = atomic_inc_return(&pool->req_ser);
32398 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32399 wake_up_process(pool->thread);
32400
32401 if (wait_event_interruptible(pool->force_wait,
32402 - atomic_read(&pool->flush_ser) - serial >= 0))
32403 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32404 return -EINTR;
32405
32406 return 0;
32407 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32408 } else {
32409 list_add_tail(&fmr->list, &pool->dirty_list);
32410 if (++pool->dirty_len >= pool->dirty_watermark) {
32411 - atomic_inc(&pool->req_ser);
32412 + atomic_inc_unchecked(&pool->req_ser);
32413 wake_up_process(pool->thread);
32414 }
32415 }
32416 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32417 index 57e07c6..56d09d4 100644
32418 --- a/drivers/infiniband/hw/cxgb4/mem.c
32419 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32420 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32421 int err;
32422 struct fw_ri_tpte tpt;
32423 u32 stag_idx;
32424 - static atomic_t key;
32425 + static atomic_unchecked_t key;
32426
32427 if (c4iw_fatal_error(rdev))
32428 return -EIO;
32429 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32430 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32431 rdev->stats.stag.max = rdev->stats.stag.cur;
32432 mutex_unlock(&rdev->stats.lock);
32433 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32434 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32435 }
32436 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32437 __func__, stag_state, type, pdid, stag_idx);
32438 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32439 index 79b3dbc..96e5fcc 100644
32440 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32441 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32442 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32443 struct ib_atomic_eth *ateth;
32444 struct ipath_ack_entry *e;
32445 u64 vaddr;
32446 - atomic64_t *maddr;
32447 + atomic64_unchecked_t *maddr;
32448 u64 sdata;
32449 u32 rkey;
32450 u8 next;
32451 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32452 IB_ACCESS_REMOTE_ATOMIC)))
32453 goto nack_acc_unlck;
32454 /* Perform atomic OP and save result. */
32455 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32456 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32457 sdata = be64_to_cpu(ateth->swap_data);
32458 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32459 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32460 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32461 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32462 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32463 be64_to_cpu(ateth->compare_data),
32464 sdata);
32465 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32466 index 1f95bba..9530f87 100644
32467 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32468 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32469 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32470 unsigned long flags;
32471 struct ib_wc wc;
32472 u64 sdata;
32473 - atomic64_t *maddr;
32474 + atomic64_unchecked_t *maddr;
32475 enum ib_wc_status send_status;
32476
32477 /*
32478 @@ -382,11 +382,11 @@ again:
32479 IB_ACCESS_REMOTE_ATOMIC)))
32480 goto acc_err;
32481 /* Perform atomic OP and save result. */
32482 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32483 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32484 sdata = wqe->wr.wr.atomic.compare_add;
32485 *(u64 *) sqp->s_sge.sge.vaddr =
32486 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32487 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32488 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32489 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32490 sdata, wqe->wr.wr.atomic.swap);
32491 goto send_comp;
32492 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32493 index 7140199..da60063 100644
32494 --- a/drivers/infiniband/hw/nes/nes.c
32495 +++ b/drivers/infiniband/hw/nes/nes.c
32496 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32497 LIST_HEAD(nes_adapter_list);
32498 static LIST_HEAD(nes_dev_list);
32499
32500 -atomic_t qps_destroyed;
32501 +atomic_unchecked_t qps_destroyed;
32502
32503 static unsigned int ee_flsh_adapter;
32504 static unsigned int sysfs_nonidx_addr;
32505 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32506 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32507 struct nes_adapter *nesadapter = nesdev->nesadapter;
32508
32509 - atomic_inc(&qps_destroyed);
32510 + atomic_inc_unchecked(&qps_destroyed);
32511
32512 /* Free the control structures */
32513
32514 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32515 index c438e46..ca30356 100644
32516 --- a/drivers/infiniband/hw/nes/nes.h
32517 +++ b/drivers/infiniband/hw/nes/nes.h
32518 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32519 extern unsigned int wqm_quanta;
32520 extern struct list_head nes_adapter_list;
32521
32522 -extern atomic_t cm_connects;
32523 -extern atomic_t cm_accepts;
32524 -extern atomic_t cm_disconnects;
32525 -extern atomic_t cm_closes;
32526 -extern atomic_t cm_connecteds;
32527 -extern atomic_t cm_connect_reqs;
32528 -extern atomic_t cm_rejects;
32529 -extern atomic_t mod_qp_timouts;
32530 -extern atomic_t qps_created;
32531 -extern atomic_t qps_destroyed;
32532 -extern atomic_t sw_qps_destroyed;
32533 +extern atomic_unchecked_t cm_connects;
32534 +extern atomic_unchecked_t cm_accepts;
32535 +extern atomic_unchecked_t cm_disconnects;
32536 +extern atomic_unchecked_t cm_closes;
32537 +extern atomic_unchecked_t cm_connecteds;
32538 +extern atomic_unchecked_t cm_connect_reqs;
32539 +extern atomic_unchecked_t cm_rejects;
32540 +extern atomic_unchecked_t mod_qp_timouts;
32541 +extern atomic_unchecked_t qps_created;
32542 +extern atomic_unchecked_t qps_destroyed;
32543 +extern atomic_unchecked_t sw_qps_destroyed;
32544 extern u32 mh_detected;
32545 extern u32 mh_pauses_sent;
32546 extern u32 cm_packets_sent;
32547 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32548 extern u32 cm_packets_received;
32549 extern u32 cm_packets_dropped;
32550 extern u32 cm_packets_retrans;
32551 -extern atomic_t cm_listens_created;
32552 -extern atomic_t cm_listens_destroyed;
32553 +extern atomic_unchecked_t cm_listens_created;
32554 +extern atomic_unchecked_t cm_listens_destroyed;
32555 extern u32 cm_backlog_drops;
32556 -extern atomic_t cm_loopbacks;
32557 -extern atomic_t cm_nodes_created;
32558 -extern atomic_t cm_nodes_destroyed;
32559 -extern atomic_t cm_accel_dropped_pkts;
32560 -extern atomic_t cm_resets_recvd;
32561 -extern atomic_t pau_qps_created;
32562 -extern atomic_t pau_qps_destroyed;
32563 +extern atomic_unchecked_t cm_loopbacks;
32564 +extern atomic_unchecked_t cm_nodes_created;
32565 +extern atomic_unchecked_t cm_nodes_destroyed;
32566 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32567 +extern atomic_unchecked_t cm_resets_recvd;
32568 +extern atomic_unchecked_t pau_qps_created;
32569 +extern atomic_unchecked_t pau_qps_destroyed;
32570
32571 extern u32 int_mod_timer_init;
32572 extern u32 int_mod_cq_depth_256;
32573 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32574 index 020e95c..fbb3450 100644
32575 --- a/drivers/infiniband/hw/nes/nes_cm.c
32576 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32577 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32578 u32 cm_packets_retrans;
32579 u32 cm_packets_created;
32580 u32 cm_packets_received;
32581 -atomic_t cm_listens_created;
32582 -atomic_t cm_listens_destroyed;
32583 +atomic_unchecked_t cm_listens_created;
32584 +atomic_unchecked_t cm_listens_destroyed;
32585 u32 cm_backlog_drops;
32586 -atomic_t cm_loopbacks;
32587 -atomic_t cm_nodes_created;
32588 -atomic_t cm_nodes_destroyed;
32589 -atomic_t cm_accel_dropped_pkts;
32590 -atomic_t cm_resets_recvd;
32591 +atomic_unchecked_t cm_loopbacks;
32592 +atomic_unchecked_t cm_nodes_created;
32593 +atomic_unchecked_t cm_nodes_destroyed;
32594 +atomic_unchecked_t cm_accel_dropped_pkts;
32595 +atomic_unchecked_t cm_resets_recvd;
32596
32597 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32598 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32599 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32600
32601 static struct nes_cm_core *g_cm_core;
32602
32603 -atomic_t cm_connects;
32604 -atomic_t cm_accepts;
32605 -atomic_t cm_disconnects;
32606 -atomic_t cm_closes;
32607 -atomic_t cm_connecteds;
32608 -atomic_t cm_connect_reqs;
32609 -atomic_t cm_rejects;
32610 +atomic_unchecked_t cm_connects;
32611 +atomic_unchecked_t cm_accepts;
32612 +atomic_unchecked_t cm_disconnects;
32613 +atomic_unchecked_t cm_closes;
32614 +atomic_unchecked_t cm_connecteds;
32615 +atomic_unchecked_t cm_connect_reqs;
32616 +atomic_unchecked_t cm_rejects;
32617
32618 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32619 {
32620 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32621 kfree(listener);
32622 listener = NULL;
32623 ret = 0;
32624 - atomic_inc(&cm_listens_destroyed);
32625 + atomic_inc_unchecked(&cm_listens_destroyed);
32626 } else {
32627 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32628 }
32629 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32630 cm_node->rem_mac);
32631
32632 add_hte_node(cm_core, cm_node);
32633 - atomic_inc(&cm_nodes_created);
32634 + atomic_inc_unchecked(&cm_nodes_created);
32635
32636 return cm_node;
32637 }
32638 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32639 }
32640
32641 atomic_dec(&cm_core->node_cnt);
32642 - atomic_inc(&cm_nodes_destroyed);
32643 + atomic_inc_unchecked(&cm_nodes_destroyed);
32644 nesqp = cm_node->nesqp;
32645 if (nesqp) {
32646 nesqp->cm_node = NULL;
32647 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32648
32649 static void drop_packet(struct sk_buff *skb)
32650 {
32651 - atomic_inc(&cm_accel_dropped_pkts);
32652 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32653 dev_kfree_skb_any(skb);
32654 }
32655
32656 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32657 {
32658
32659 int reset = 0; /* whether to send reset in case of err.. */
32660 - atomic_inc(&cm_resets_recvd);
32661 + atomic_inc_unchecked(&cm_resets_recvd);
32662 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32663 " refcnt=%d\n", cm_node, cm_node->state,
32664 atomic_read(&cm_node->ref_count));
32665 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32666 rem_ref_cm_node(cm_node->cm_core, cm_node);
32667 return NULL;
32668 }
32669 - atomic_inc(&cm_loopbacks);
32670 + atomic_inc_unchecked(&cm_loopbacks);
32671 loopbackremotenode->loopbackpartner = cm_node;
32672 loopbackremotenode->tcp_cntxt.rcv_wscale =
32673 NES_CM_DEFAULT_RCV_WND_SCALE;
32674 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32675 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32676 else {
32677 rem_ref_cm_node(cm_core, cm_node);
32678 - atomic_inc(&cm_accel_dropped_pkts);
32679 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32680 dev_kfree_skb_any(skb);
32681 }
32682 break;
32683 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32684
32685 if ((cm_id) && (cm_id->event_handler)) {
32686 if (issue_disconn) {
32687 - atomic_inc(&cm_disconnects);
32688 + atomic_inc_unchecked(&cm_disconnects);
32689 cm_event.event = IW_CM_EVENT_DISCONNECT;
32690 cm_event.status = disconn_status;
32691 cm_event.local_addr = cm_id->local_addr;
32692 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32693 }
32694
32695 if (issue_close) {
32696 - atomic_inc(&cm_closes);
32697 + atomic_inc_unchecked(&cm_closes);
32698 nes_disconnect(nesqp, 1);
32699
32700 cm_id->provider_data = nesqp;
32701 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32702
32703 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32704 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32705 - atomic_inc(&cm_accepts);
32706 + atomic_inc_unchecked(&cm_accepts);
32707
32708 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32709 netdev_refcnt_read(nesvnic->netdev));
32710 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32711 struct nes_cm_core *cm_core;
32712 u8 *start_buff;
32713
32714 - atomic_inc(&cm_rejects);
32715 + atomic_inc_unchecked(&cm_rejects);
32716 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32717 loopback = cm_node->loopbackpartner;
32718 cm_core = cm_node->cm_core;
32719 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32720 ntohl(cm_id->local_addr.sin_addr.s_addr),
32721 ntohs(cm_id->local_addr.sin_port));
32722
32723 - atomic_inc(&cm_connects);
32724 + atomic_inc_unchecked(&cm_connects);
32725 nesqp->active_conn = 1;
32726
32727 /* cache the cm_id in the qp */
32728 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32729 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32730 return err;
32731 }
32732 - atomic_inc(&cm_listens_created);
32733 + atomic_inc_unchecked(&cm_listens_created);
32734 }
32735
32736 cm_id->add_ref(cm_id);
32737 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32738
32739 if (nesqp->destroyed)
32740 return;
32741 - atomic_inc(&cm_connecteds);
32742 + atomic_inc_unchecked(&cm_connecteds);
32743 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32744 " local port 0x%04X. jiffies = %lu.\n",
32745 nesqp->hwqp.qp_id,
32746 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32747
32748 cm_id->add_ref(cm_id);
32749 ret = cm_id->event_handler(cm_id, &cm_event);
32750 - atomic_inc(&cm_closes);
32751 + atomic_inc_unchecked(&cm_closes);
32752 cm_event.event = IW_CM_EVENT_CLOSE;
32753 cm_event.status = 0;
32754 cm_event.provider_data = cm_id->provider_data;
32755 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32756 return;
32757 cm_id = cm_node->cm_id;
32758
32759 - atomic_inc(&cm_connect_reqs);
32760 + atomic_inc_unchecked(&cm_connect_reqs);
32761 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32762 cm_node, cm_id, jiffies);
32763
32764 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32765 return;
32766 cm_id = cm_node->cm_id;
32767
32768 - atomic_inc(&cm_connect_reqs);
32769 + atomic_inc_unchecked(&cm_connect_reqs);
32770 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32771 cm_node, cm_id, jiffies);
32772
32773 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32774 index 3ba7be3..c81f6ff 100644
32775 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32776 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32777 @@ -40,8 +40,8 @@
32778 #include "nes.h"
32779 #include "nes_mgt.h"
32780
32781 -atomic_t pau_qps_created;
32782 -atomic_t pau_qps_destroyed;
32783 +atomic_unchecked_t pau_qps_created;
32784 +atomic_unchecked_t pau_qps_destroyed;
32785
32786 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32787 {
32788 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32789 {
32790 struct sk_buff *skb;
32791 unsigned long flags;
32792 - atomic_inc(&pau_qps_destroyed);
32793 + atomic_inc_unchecked(&pau_qps_destroyed);
32794
32795 /* Free packets that have not yet been forwarded */
32796 /* Lock is acquired by skb_dequeue when removing the skb */
32797 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32798 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32799 skb_queue_head_init(&nesqp->pau_list);
32800 spin_lock_init(&nesqp->pau_lock);
32801 - atomic_inc(&pau_qps_created);
32802 + atomic_inc_unchecked(&pau_qps_created);
32803 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32804 }
32805
32806 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32807 index f3a3ecf..57d311d 100644
32808 --- a/drivers/infiniband/hw/nes/nes_nic.c
32809 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32810 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32811 target_stat_values[++index] = mh_detected;
32812 target_stat_values[++index] = mh_pauses_sent;
32813 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32814 - target_stat_values[++index] = atomic_read(&cm_connects);
32815 - target_stat_values[++index] = atomic_read(&cm_accepts);
32816 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32817 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32818 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32819 - target_stat_values[++index] = atomic_read(&cm_rejects);
32820 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32821 - target_stat_values[++index] = atomic_read(&qps_created);
32822 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32823 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32824 - target_stat_values[++index] = atomic_read(&cm_closes);
32825 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32826 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32827 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32828 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32829 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32830 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32831 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32832 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32833 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32834 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32835 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32836 target_stat_values[++index] = cm_packets_sent;
32837 target_stat_values[++index] = cm_packets_bounced;
32838 target_stat_values[++index] = cm_packets_created;
32839 target_stat_values[++index] = cm_packets_received;
32840 target_stat_values[++index] = cm_packets_dropped;
32841 target_stat_values[++index] = cm_packets_retrans;
32842 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32843 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32844 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32845 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32846 target_stat_values[++index] = cm_backlog_drops;
32847 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32848 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32849 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32850 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32851 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32852 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32853 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32854 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32855 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32856 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32857 target_stat_values[++index] = nesadapter->free_4kpbl;
32858 target_stat_values[++index] = nesadapter->free_256pbl;
32859 target_stat_values[++index] = int_mod_timer_init;
32860 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32861 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32862 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32863 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32864 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32865 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32866 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32867 }
32868
32869 /**
32870 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32871 index 8b8812d..a5e1133 100644
32872 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32873 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32874 @@ -46,9 +46,9 @@
32875
32876 #include <rdma/ib_umem.h>
32877
32878 -atomic_t mod_qp_timouts;
32879 -atomic_t qps_created;
32880 -atomic_t sw_qps_destroyed;
32881 +atomic_unchecked_t mod_qp_timouts;
32882 +atomic_unchecked_t qps_created;
32883 +atomic_unchecked_t sw_qps_destroyed;
32884
32885 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32886
32887 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32888 if (init_attr->create_flags)
32889 return ERR_PTR(-EINVAL);
32890
32891 - atomic_inc(&qps_created);
32892 + atomic_inc_unchecked(&qps_created);
32893 switch (init_attr->qp_type) {
32894 case IB_QPT_RC:
32895 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32896 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32897 struct iw_cm_event cm_event;
32898 int ret = 0;
32899
32900 - atomic_inc(&sw_qps_destroyed);
32901 + atomic_inc_unchecked(&sw_qps_destroyed);
32902 nesqp->destroyed = 1;
32903
32904 /* Blow away the connection if it exists. */
32905 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32906 index 7b1b8669..4b69f85 100644
32907 --- a/drivers/infiniband/hw/qib/qib.h
32908 +++ b/drivers/infiniband/hw/qib/qib.h
32909 @@ -51,6 +51,7 @@
32910 #include <linux/completion.h>
32911 #include <linux/kref.h>
32912 #include <linux/sched.h>
32913 +#include <linux/slab.h>
32914
32915 #include "qib_common.h"
32916 #include "qib_verbs.h"
32917 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32918 index da739d9..da1c7f4 100644
32919 --- a/drivers/input/gameport/gameport.c
32920 +++ b/drivers/input/gameport/gameport.c
32921 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32922 */
32923 static void gameport_init_port(struct gameport *gameport)
32924 {
32925 - static atomic_t gameport_no = ATOMIC_INIT(0);
32926 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32927
32928 __module_get(THIS_MODULE);
32929
32930 mutex_init(&gameport->drv_mutex);
32931 device_initialize(&gameport->dev);
32932 dev_set_name(&gameport->dev, "gameport%lu",
32933 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32934 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32935 gameport->dev.bus = &gameport_bus;
32936 gameport->dev.release = gameport_release_port;
32937 if (gameport->parent)
32938 diff --git a/drivers/input/input.c b/drivers/input/input.c
32939 index 8921c61..f5cd63d 100644
32940 --- a/drivers/input/input.c
32941 +++ b/drivers/input/input.c
32942 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32943 */
32944 int input_register_device(struct input_dev *dev)
32945 {
32946 - static atomic_t input_no = ATOMIC_INIT(0);
32947 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32948 struct input_handler *handler;
32949 const char *path;
32950 int error;
32951 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32952 dev->setkeycode = input_default_setkeycode;
32953
32954 dev_set_name(&dev->dev, "input%ld",
32955 - (unsigned long) atomic_inc_return(&input_no) - 1);
32956 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32957
32958 error = device_add(&dev->dev);
32959 if (error)
32960 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32961 index 04c69af..5f92d00 100644
32962 --- a/drivers/input/joystick/sidewinder.c
32963 +++ b/drivers/input/joystick/sidewinder.c
32964 @@ -30,6 +30,7 @@
32965 #include <linux/kernel.h>
32966 #include <linux/module.h>
32967 #include <linux/slab.h>
32968 +#include <linux/sched.h>
32969 #include <linux/init.h>
32970 #include <linux/input.h>
32971 #include <linux/gameport.h>
32972 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32973 index 83811e4..0822b90 100644
32974 --- a/drivers/input/joystick/xpad.c
32975 +++ b/drivers/input/joystick/xpad.c
32976 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32977
32978 static int xpad_led_probe(struct usb_xpad *xpad)
32979 {
32980 - static atomic_t led_seq = ATOMIC_INIT(0);
32981 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32982 long led_no;
32983 struct xpad_led *led;
32984 struct led_classdev *led_cdev;
32985 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32986 if (!led)
32987 return -ENOMEM;
32988
32989 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32990 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32991
32992 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32993 led->xpad = xpad;
32994 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32995 index 0110b5a..d3ad144 100644
32996 --- a/drivers/input/mousedev.c
32997 +++ b/drivers/input/mousedev.c
32998 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32999
33000 spin_unlock_irq(&client->packet_lock);
33001
33002 - if (copy_to_user(buffer, data, count))
33003 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
33004 return -EFAULT;
33005
33006 return count;
33007 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
33008 index d0f7533..fb8215b 100644
33009 --- a/drivers/input/serio/serio.c
33010 +++ b/drivers/input/serio/serio.c
33011 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
33012 */
33013 static void serio_init_port(struct serio *serio)
33014 {
33015 - static atomic_t serio_no = ATOMIC_INIT(0);
33016 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
33017
33018 __module_get(THIS_MODULE);
33019
33020 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
33021 mutex_init(&serio->drv_mutex);
33022 device_initialize(&serio->dev);
33023 dev_set_name(&serio->dev, "serio%ld",
33024 - (long)atomic_inc_return(&serio_no) - 1);
33025 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
33026 serio->dev.bus = &serio_bus;
33027 serio->dev.release = serio_release_port;
33028 serio->dev.groups = serio_device_attr_groups;
33029 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
33030 index 38c4bd8..58965d9 100644
33031 --- a/drivers/isdn/capi/capi.c
33032 +++ b/drivers/isdn/capi/capi.c
33033 @@ -83,8 +83,8 @@ struct capiminor {
33034
33035 struct capi20_appl *ap;
33036 u32 ncci;
33037 - atomic_t datahandle;
33038 - atomic_t msgid;
33039 + atomic_unchecked_t datahandle;
33040 + atomic_unchecked_t msgid;
33041
33042 struct tty_port port;
33043 int ttyinstop;
33044 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33045 capimsg_setu16(s, 2, mp->ap->applid);
33046 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33047 capimsg_setu8 (s, 5, CAPI_RESP);
33048 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33049 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33050 capimsg_setu32(s, 8, mp->ncci);
33051 capimsg_setu16(s, 12, datahandle);
33052 }
33053 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33054 mp->outbytes -= len;
33055 spin_unlock_bh(&mp->outlock);
33056
33057 - datahandle = atomic_inc_return(&mp->datahandle);
33058 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33059 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33060 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33061 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33062 capimsg_setu16(skb->data, 2, mp->ap->applid);
33063 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33064 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33065 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33066 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33067 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33068 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33069 capimsg_setu16(skb->data, 16, len); /* Data length */
33070 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33071 index a6d9fd2..afdb8a3 100644
33072 --- a/drivers/isdn/gigaset/interface.c
33073 +++ b/drivers/isdn/gigaset/interface.c
33074 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33075 }
33076 tty->driver_data = cs;
33077
33078 - ++cs->port.count;
33079 + atomic_inc(&cs->port.count);
33080
33081 - if (cs->port.count == 1) {
33082 + if (atomic_read(&cs->port.count) == 1) {
33083 tty_port_tty_set(&cs->port, tty);
33084 tty->low_latency = 1;
33085 }
33086 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33087
33088 if (!cs->connected)
33089 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33090 - else if (!cs->port.count)
33091 + else if (!atomic_read(&cs->port.count))
33092 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33093 - else if (!--cs->port.count)
33094 + else if (!atomic_dec_return(&cs->port.count))
33095 tty_port_tty_set(&cs->port, NULL);
33096
33097 mutex_unlock(&cs->mutex);
33098 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33099 index 821f7ac..28d4030 100644
33100 --- a/drivers/isdn/hardware/avm/b1.c
33101 +++ b/drivers/isdn/hardware/avm/b1.c
33102 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33103 }
33104 if (left) {
33105 if (t4file->user) {
33106 - if (copy_from_user(buf, dp, left))
33107 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33108 return -EFAULT;
33109 } else {
33110 memcpy(buf, dp, left);
33111 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33112 }
33113 if (left) {
33114 if (config->user) {
33115 - if (copy_from_user(buf, dp, left))
33116 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33117 return -EFAULT;
33118 } else {
33119 memcpy(buf, dp, left);
33120 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33121 index dd6b53a..19d9ee6 100644
33122 --- a/drivers/isdn/hardware/eicon/divasync.h
33123 +++ b/drivers/isdn/hardware/eicon/divasync.h
33124 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33125 } diva_didd_add_adapter_t;
33126 typedef struct _diva_didd_remove_adapter {
33127 IDI_CALL p_request;
33128 -} diva_didd_remove_adapter_t;
33129 +} __no_const diva_didd_remove_adapter_t;
33130 typedef struct _diva_didd_read_adapter_array {
33131 void *buffer;
33132 dword length;
33133 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33134 index d303e65..28bcb7b 100644
33135 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33136 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33137 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33138 typedef struct _diva_os_idi_adapter_interface {
33139 diva_init_card_proc_t cleanup_adapter_proc;
33140 diva_cmd_card_proc_t cmd_proc;
33141 -} diva_os_idi_adapter_interface_t;
33142 +} __no_const diva_os_idi_adapter_interface_t;
33143
33144 typedef struct _diva_os_xdi_adapter {
33145 struct list_head link;
33146 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33147 index 7bc5067..fd36232 100644
33148 --- a/drivers/isdn/i4l/isdn_tty.c
33149 +++ b/drivers/isdn/i4l/isdn_tty.c
33150 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33151 port = &info->port;
33152 #ifdef ISDN_DEBUG_MODEM_OPEN
33153 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33154 - port->count);
33155 + atomic_read(&port->count))
33156 #endif
33157 - port->count++;
33158 + atomic_inc(&port->count);
33159 tty->driver_data = info;
33160 port->tty = tty;
33161 tty->port = port;
33162 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33163 #endif
33164 return;
33165 }
33166 - if ((tty->count == 1) && (port->count != 1)) {
33167 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33168 /*
33169 * Uh, oh. tty->count is 1, which means that the tty
33170 * structure will be freed. Info->count should always
33171 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33172 * serial port won't be shutdown.
33173 */
33174 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33175 - "info->count is %d\n", port->count);
33176 - port->count = 1;
33177 + "info->count is %d\n", atomic_read(&port->count));
33178 + atomic_set(&port->count, 1);
33179 }
33180 - if (--port->count < 0) {
33181 + if (atomic_dec_return(&port->count) < 0) {
33182 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33183 - info->line, port->count);
33184 - port->count = 0;
33185 + info->line, atomic_read(&port->count));
33186 + atomic_set(&port->count, 0);
33187 }
33188 - if (port->count) {
33189 + if (atomic_read(&port->count)) {
33190 #ifdef ISDN_DEBUG_MODEM_OPEN
33191 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33192 #endif
33193 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33194 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33195 return;
33196 isdn_tty_shutdown(info);
33197 - port->count = 0;
33198 + atomic_set(&port->count, 0);
33199 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33200 port->tty = NULL;
33201 wake_up_interruptible(&port->open_wait);
33202 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33203 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33204 modem_info *info = &dev->mdm.info[i];
33205
33206 - if (info->port.count == 0)
33207 + if (atomic_read(&info->port.count) == 0)
33208 continue;
33209 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33210 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33211 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33212 index e74df7c..03a03ba 100644
33213 --- a/drivers/isdn/icn/icn.c
33214 +++ b/drivers/isdn/icn/icn.c
33215 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33216 if (count > len)
33217 count = len;
33218 if (user) {
33219 - if (copy_from_user(msg, buf, count))
33220 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33221 return -EFAULT;
33222 } else
33223 memcpy(msg, buf, count);
33224 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33225 index b5fdcb7..5b6c59f 100644
33226 --- a/drivers/lguest/core.c
33227 +++ b/drivers/lguest/core.c
33228 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33229 * it's worked so far. The end address needs +1 because __get_vm_area
33230 * allocates an extra guard page, so we need space for that.
33231 */
33232 +
33233 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33234 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33235 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33236 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33237 +#else
33238 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33239 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33240 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33241 +#endif
33242 +
33243 if (!switcher_vma) {
33244 err = -ENOMEM;
33245 printk("lguest: could not map switcher pages high\n");
33246 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33247 * Now the Switcher is mapped at the right address, we can't fail!
33248 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33249 */
33250 - memcpy(switcher_vma->addr, start_switcher_text,
33251 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33252 end_switcher_text - start_switcher_text);
33253
33254 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33255 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33256 index 39809035..ce25c5e 100644
33257 --- a/drivers/lguest/x86/core.c
33258 +++ b/drivers/lguest/x86/core.c
33259 @@ -59,7 +59,7 @@ static struct {
33260 /* Offset from where switcher.S was compiled to where we've copied it */
33261 static unsigned long switcher_offset(void)
33262 {
33263 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33264 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33265 }
33266
33267 /* This cpu's struct lguest_pages. */
33268 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33269 * These copies are pretty cheap, so we do them unconditionally: */
33270 /* Save the current Host top-level page directory.
33271 */
33272 +
33273 +#ifdef CONFIG_PAX_PER_CPU_PGD
33274 + pages->state.host_cr3 = read_cr3();
33275 +#else
33276 pages->state.host_cr3 = __pa(current->mm->pgd);
33277 +#endif
33278 +
33279 /*
33280 * Set up the Guest's page tables to see this CPU's pages (and no
33281 * other CPU's pages).
33282 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33283 * compiled-in switcher code and the high-mapped copy we just made.
33284 */
33285 for (i = 0; i < IDT_ENTRIES; i++)
33286 - default_idt_entries[i] += switcher_offset();
33287 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33288
33289 /*
33290 * Set up the Switcher's per-cpu areas.
33291 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33292 * it will be undisturbed when we switch. To change %cs and jump we
33293 * need this structure to feed to Intel's "lcall" instruction.
33294 */
33295 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33296 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33297 lguest_entry.segment = LGUEST_CS;
33298
33299 /*
33300 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33301 index 40634b0..4f5855e 100644
33302 --- a/drivers/lguest/x86/switcher_32.S
33303 +++ b/drivers/lguest/x86/switcher_32.S
33304 @@ -87,6 +87,7 @@
33305 #include <asm/page.h>
33306 #include <asm/segment.h>
33307 #include <asm/lguest.h>
33308 +#include <asm/processor-flags.h>
33309
33310 // We mark the start of the code to copy
33311 // It's placed in .text tho it's never run here
33312 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33313 // Changes type when we load it: damn Intel!
33314 // For after we switch over our page tables
33315 // That entry will be read-only: we'd crash.
33316 +
33317 +#ifdef CONFIG_PAX_KERNEXEC
33318 + mov %cr0, %edx
33319 + xor $X86_CR0_WP, %edx
33320 + mov %edx, %cr0
33321 +#endif
33322 +
33323 movl $(GDT_ENTRY_TSS*8), %edx
33324 ltr %dx
33325
33326 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33327 // Let's clear it again for our return.
33328 // The GDT descriptor of the Host
33329 // Points to the table after two "size" bytes
33330 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33331 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33332 // Clear "used" from type field (byte 5, bit 2)
33333 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33334 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33335 +
33336 +#ifdef CONFIG_PAX_KERNEXEC
33337 + mov %cr0, %eax
33338 + xor $X86_CR0_WP, %eax
33339 + mov %eax, %cr0
33340 +#endif
33341
33342 // Once our page table's switched, the Guest is live!
33343 // The Host fades as we run this final step.
33344 @@ -295,13 +309,12 @@ deliver_to_host:
33345 // I consulted gcc, and it gave
33346 // These instructions, which I gladly credit:
33347 leal (%edx,%ebx,8), %eax
33348 - movzwl (%eax),%edx
33349 - movl 4(%eax), %eax
33350 - xorw %ax, %ax
33351 - orl %eax, %edx
33352 + movl 4(%eax), %edx
33353 + movw (%eax), %dx
33354 // Now the address of the handler's in %edx
33355 // We call it now: its "iret" drops us home.
33356 - jmp *%edx
33357 + ljmp $__KERNEL_CS, $1f
33358 +1: jmp *%edx
33359
33360 // Every interrupt can come to us here
33361 // But we must truly tell each apart.
33362 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33363 index 20e5c2c..9e849a9 100644
33364 --- a/drivers/macintosh/macio_asic.c
33365 +++ b/drivers/macintosh/macio_asic.c
33366 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33367 * MacIO is matched against any Apple ID, it's probe() function
33368 * will then decide wether it applies or not
33369 */
33370 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33371 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33372 .vendor = PCI_VENDOR_ID_APPLE,
33373 .device = PCI_ANY_ID,
33374 .subvendor = PCI_ANY_ID,
33375 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33376 index 94e7f6b..2f4a0d8 100644
33377 --- a/drivers/md/bitmap.c
33378 +++ b/drivers/md/bitmap.c
33379 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33380 chunk_kb ? "KB" : "B");
33381 if (bitmap->storage.file) {
33382 seq_printf(seq, ", file: ");
33383 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33384 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33385 }
33386
33387 seq_printf(seq, "\n");
33388 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33389 index afd9598..528d8f9 100644
33390 --- a/drivers/md/dm-ioctl.c
33391 +++ b/drivers/md/dm-ioctl.c
33392 @@ -1593,7 +1593,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33393 cmd == DM_LIST_VERSIONS_CMD)
33394 return 0;
33395
33396 - if ((cmd == DM_DEV_CREATE_CMD)) {
33397 + if (cmd == DM_DEV_CREATE_CMD) {
33398 if (!*param->name) {
33399 DMWARN("name not supplied when creating device");
33400 return -EINVAL;
33401 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33402 index bc5ddba8..b961159 100644
33403 --- a/drivers/md/dm-raid1.c
33404 +++ b/drivers/md/dm-raid1.c
33405 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33406
33407 struct mirror {
33408 struct mirror_set *ms;
33409 - atomic_t error_count;
33410 + atomic_unchecked_t error_count;
33411 unsigned long error_type;
33412 struct dm_dev *dev;
33413 sector_t offset;
33414 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33415 struct mirror *m;
33416
33417 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33418 - if (!atomic_read(&m->error_count))
33419 + if (!atomic_read_unchecked(&m->error_count))
33420 return m;
33421
33422 return NULL;
33423 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33424 * simple way to tell if a device has encountered
33425 * errors.
33426 */
33427 - atomic_inc(&m->error_count);
33428 + atomic_inc_unchecked(&m->error_count);
33429
33430 if (test_and_set_bit(error_type, &m->error_type))
33431 return;
33432 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33433 struct mirror *m = get_default_mirror(ms);
33434
33435 do {
33436 - if (likely(!atomic_read(&m->error_count)))
33437 + if (likely(!atomic_read_unchecked(&m->error_count)))
33438 return m;
33439
33440 if (m-- == ms->mirror)
33441 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33442 {
33443 struct mirror *default_mirror = get_default_mirror(m->ms);
33444
33445 - return !atomic_read(&default_mirror->error_count);
33446 + return !atomic_read_unchecked(&default_mirror->error_count);
33447 }
33448
33449 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33450 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33451 */
33452 if (likely(region_in_sync(ms, region, 1)))
33453 m = choose_mirror(ms, bio->bi_sector);
33454 - else if (m && atomic_read(&m->error_count))
33455 + else if (m && atomic_read_unchecked(&m->error_count))
33456 m = NULL;
33457
33458 if (likely(m))
33459 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33460 }
33461
33462 ms->mirror[mirror].ms = ms;
33463 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33464 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33465 ms->mirror[mirror].error_type = 0;
33466 ms->mirror[mirror].offset = offset;
33467
33468 @@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
33469 */
33470 static char device_status_char(struct mirror *m)
33471 {
33472 - if (!atomic_read(&(m->error_count)))
33473 + if (!atomic_read_unchecked(&(m->error_count)))
33474 return 'A';
33475
33476 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33477 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33478 index a087bf2..4c94786 100644
33479 --- a/drivers/md/dm-stripe.c
33480 +++ b/drivers/md/dm-stripe.c
33481 @@ -20,7 +20,7 @@ struct stripe {
33482 struct dm_dev *dev;
33483 sector_t physical_start;
33484
33485 - atomic_t error_count;
33486 + atomic_unchecked_t error_count;
33487 };
33488
33489 struct stripe_c {
33490 @@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33491 kfree(sc);
33492 return r;
33493 }
33494 - atomic_set(&(sc->stripe[i].error_count), 0);
33495 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33496 }
33497
33498 ti->private = sc;
33499 @@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
33500 DMEMIT("%d ", sc->stripes);
33501 for (i = 0; i < sc->stripes; i++) {
33502 DMEMIT("%s ", sc->stripe[i].dev->name);
33503 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33504 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33505 'D' : 'A';
33506 }
33507 buffer[i] = '\0';
33508 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33509 */
33510 for (i = 0; i < sc->stripes; i++)
33511 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33512 - atomic_inc(&(sc->stripe[i].error_count));
33513 - if (atomic_read(&(sc->stripe[i].error_count)) <
33514 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33515 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33516 DM_IO_ERROR_THRESHOLD)
33517 schedule_work(&sc->trigger_event);
33518 }
33519 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33520 index 100368e..64262ce 100644
33521 --- a/drivers/md/dm-table.c
33522 +++ b/drivers/md/dm-table.c
33523 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33524 if (!dev_size)
33525 return 0;
33526
33527 - if ((start >= dev_size) || (start + len > dev_size)) {
33528 + if ((start >= dev_size) || (len > dev_size - start)) {
33529 DMWARN("%s: %s too small for target: "
33530 "start=%llu, len=%llu, dev_size=%llu",
33531 dm_device_name(ti->table->md), bdevname(bdev, b),
33532 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33533 index 693e149..b7e0fde 100644
33534 --- a/drivers/md/dm-thin-metadata.c
33535 +++ b/drivers/md/dm-thin-metadata.c
33536 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33537 {
33538 pmd->info.tm = pmd->tm;
33539 pmd->info.levels = 2;
33540 - pmd->info.value_type.context = pmd->data_sm;
33541 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33542 pmd->info.value_type.size = sizeof(__le64);
33543 pmd->info.value_type.inc = data_block_inc;
33544 pmd->info.value_type.dec = data_block_dec;
33545 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
33546
33547 pmd->bl_info.tm = pmd->tm;
33548 pmd->bl_info.levels = 1;
33549 - pmd->bl_info.value_type.context = pmd->data_sm;
33550 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33551 pmd->bl_info.value_type.size = sizeof(__le64);
33552 pmd->bl_info.value_type.inc = data_block_inc;
33553 pmd->bl_info.value_type.dec = data_block_dec;
33554 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33555 index 67ffa39..cb3b1dd 100644
33556 --- a/drivers/md/dm.c
33557 +++ b/drivers/md/dm.c
33558 @@ -176,9 +176,9 @@ struct mapped_device {
33559 /*
33560 * Event handling.
33561 */
33562 - atomic_t event_nr;
33563 + atomic_unchecked_t event_nr;
33564 wait_queue_head_t eventq;
33565 - atomic_t uevent_seq;
33566 + atomic_unchecked_t uevent_seq;
33567 struct list_head uevent_list;
33568 spinlock_t uevent_lock; /* Protect access to uevent_list */
33569
33570 @@ -1887,8 +1887,8 @@ static struct mapped_device *alloc_dev(int minor)
33571 rwlock_init(&md->map_lock);
33572 atomic_set(&md->holders, 1);
33573 atomic_set(&md->open_count, 0);
33574 - atomic_set(&md->event_nr, 0);
33575 - atomic_set(&md->uevent_seq, 0);
33576 + atomic_set_unchecked(&md->event_nr, 0);
33577 + atomic_set_unchecked(&md->uevent_seq, 0);
33578 INIT_LIST_HEAD(&md->uevent_list);
33579 spin_lock_init(&md->uevent_lock);
33580
33581 @@ -2022,7 +2022,7 @@ static void event_callback(void *context)
33582
33583 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33584
33585 - atomic_inc(&md->event_nr);
33586 + atomic_inc_unchecked(&md->event_nr);
33587 wake_up(&md->eventq);
33588 }
33589
33590 @@ -2677,18 +2677,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33591
33592 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33593 {
33594 - return atomic_add_return(1, &md->uevent_seq);
33595 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33596 }
33597
33598 uint32_t dm_get_event_nr(struct mapped_device *md)
33599 {
33600 - return atomic_read(&md->event_nr);
33601 + return atomic_read_unchecked(&md->event_nr);
33602 }
33603
33604 int dm_wait_event(struct mapped_device *md, int event_nr)
33605 {
33606 return wait_event_interruptible(md->eventq,
33607 - (event_nr != atomic_read(&md->event_nr)));
33608 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33609 }
33610
33611 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33612 diff --git a/drivers/md/md.c b/drivers/md/md.c
33613 index 308e87b..7f365d6 100644
33614 --- a/drivers/md/md.c
33615 +++ b/drivers/md/md.c
33616 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33617 * start build, activate spare
33618 */
33619 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33620 -static atomic_t md_event_count;
33621 +static atomic_unchecked_t md_event_count;
33622 void md_new_event(struct mddev *mddev)
33623 {
33624 - atomic_inc(&md_event_count);
33625 + atomic_inc_unchecked(&md_event_count);
33626 wake_up(&md_event_waiters);
33627 }
33628 EXPORT_SYMBOL_GPL(md_new_event);
33629 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33630 */
33631 static void md_new_event_inintr(struct mddev *mddev)
33632 {
33633 - atomic_inc(&md_event_count);
33634 + atomic_inc_unchecked(&md_event_count);
33635 wake_up(&md_event_waiters);
33636 }
33637
33638 @@ -1519,7 +1519,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33639 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33640 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33641 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33642 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33643 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33644
33645 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33646 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33647 @@ -1763,7 +1763,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33648 else
33649 sb->resync_offset = cpu_to_le64(0);
33650
33651 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33652 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33653
33654 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33655 sb->size = cpu_to_le64(mddev->dev_sectors);
33656 @@ -2757,7 +2757,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33657 static ssize_t
33658 errors_show(struct md_rdev *rdev, char *page)
33659 {
33660 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33661 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33662 }
33663
33664 static ssize_t
33665 @@ -2766,7 +2766,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33666 char *e;
33667 unsigned long n = simple_strtoul(buf, &e, 10);
33668 if (*buf && (*e == 0 || *e == '\n')) {
33669 - atomic_set(&rdev->corrected_errors, n);
33670 + atomic_set_unchecked(&rdev->corrected_errors, n);
33671 return len;
33672 }
33673 return -EINVAL;
33674 @@ -3213,8 +3213,8 @@ int md_rdev_init(struct md_rdev *rdev)
33675 rdev->sb_loaded = 0;
33676 rdev->bb_page = NULL;
33677 atomic_set(&rdev->nr_pending, 0);
33678 - atomic_set(&rdev->read_errors, 0);
33679 - atomic_set(&rdev->corrected_errors, 0);
33680 + atomic_set_unchecked(&rdev->read_errors, 0);
33681 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33682
33683 INIT_LIST_HEAD(&rdev->same_set);
33684 init_waitqueue_head(&rdev->blocked_wait);
33685 @@ -6947,7 +6947,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33686
33687 spin_unlock(&pers_lock);
33688 seq_printf(seq, "\n");
33689 - seq->poll_event = atomic_read(&md_event_count);
33690 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33691 return 0;
33692 }
33693 if (v == (void*)2) {
33694 @@ -7050,7 +7050,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33695 return error;
33696
33697 seq = file->private_data;
33698 - seq->poll_event = atomic_read(&md_event_count);
33699 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33700 return error;
33701 }
33702
33703 @@ -7064,7 +7064,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33704 /* always allow read */
33705 mask = POLLIN | POLLRDNORM;
33706
33707 - if (seq->poll_event != atomic_read(&md_event_count))
33708 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33709 mask |= POLLERR | POLLPRI;
33710 return mask;
33711 }
33712 @@ -7108,7 +7108,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33713 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33714 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33715 (int)part_stat_read(&disk->part0, sectors[1]) -
33716 - atomic_read(&disk->sync_io);
33717 + atomic_read_unchecked(&disk->sync_io);
33718 /* sync IO will cause sync_io to increase before the disk_stats
33719 * as sync_io is counted when a request starts, and
33720 * disk_stats is counted when it completes.
33721 diff --git a/drivers/md/md.h b/drivers/md/md.h
33722 index f385b03..b600be8 100644
33723 --- a/drivers/md/md.h
33724 +++ b/drivers/md/md.h
33725 @@ -94,13 +94,13 @@ struct md_rdev {
33726 * only maintained for arrays that
33727 * support hot removal
33728 */
33729 - atomic_t read_errors; /* number of consecutive read errors that
33730 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33731 * we have tried to ignore.
33732 */
33733 struct timespec last_read_error; /* monotonic time since our
33734 * last read error
33735 */
33736 - atomic_t corrected_errors; /* number of corrected read errors,
33737 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33738 * for reporting to userspace and storing
33739 * in superblock.
33740 */
33741 @@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33742
33743 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33744 {
33745 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33746 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33747 }
33748
33749 struct md_personality
33750 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33751 index f6d29e6..7917f5e 100644
33752 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33753 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33754 @@ -22,7 +22,7 @@
33755 * Space map interface.
33756 */
33757 struct sm_disk {
33758 - struct dm_space_map sm;
33759 + dm_space_map_no_const sm;
33760
33761 struct ll_disk ll;
33762 struct ll_disk old_ll;
33763 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33764 index e89ae5e..062e4c2 100644
33765 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33766 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33767 @@ -43,7 +43,7 @@ struct block_op {
33768 };
33769
33770 struct sm_metadata {
33771 - struct dm_space_map sm;
33772 + dm_space_map_no_const sm;
33773
33774 struct ll_disk ll;
33775 struct ll_disk old_ll;
33776 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33777 index 1cbfc6b..56e1dbb 100644
33778 --- a/drivers/md/persistent-data/dm-space-map.h
33779 +++ b/drivers/md/persistent-data/dm-space-map.h
33780 @@ -60,6 +60,7 @@ struct dm_space_map {
33781 int (*root_size)(struct dm_space_map *sm, size_t *result);
33782 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33783 };
33784 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33785
33786 /*----------------------------------------------------------------*/
33787
33788 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33789 index 611b5f7..cee0bfb 100644
33790 --- a/drivers/md/raid1.c
33791 +++ b/drivers/md/raid1.c
33792 @@ -1810,7 +1810,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33793 if (r1_sync_page_io(rdev, sect, s,
33794 bio->bi_io_vec[idx].bv_page,
33795 READ) != 0)
33796 - atomic_add(s, &rdev->corrected_errors);
33797 + atomic_add_unchecked(s, &rdev->corrected_errors);
33798 }
33799 sectors -= s;
33800 sect += s;
33801 @@ -2032,7 +2032,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33802 test_bit(In_sync, &rdev->flags)) {
33803 if (r1_sync_page_io(rdev, sect, s,
33804 conf->tmppage, READ)) {
33805 - atomic_add(s, &rdev->corrected_errors);
33806 + atomic_add_unchecked(s, &rdev->corrected_errors);
33807 printk(KERN_INFO
33808 "md/raid1:%s: read error corrected "
33809 "(%d sectors at %llu on %s)\n",
33810 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33811 index 0138a72..eab8fc6 100644
33812 --- a/drivers/md/raid10.c
33813 +++ b/drivers/md/raid10.c
33814 @@ -1810,7 +1810,7 @@ static void end_sync_read(struct bio *bio, int error)
33815 /* The write handler will notice the lack of
33816 * R10BIO_Uptodate and record any errors etc
33817 */
33818 - atomic_add(r10_bio->sectors,
33819 + atomic_add_unchecked(r10_bio->sectors,
33820 &conf->mirrors[d].rdev->corrected_errors);
33821
33822 /* for reconstruct, we always reschedule after a read.
33823 @@ -2159,7 +2159,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33824 {
33825 struct timespec cur_time_mon;
33826 unsigned long hours_since_last;
33827 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33828 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33829
33830 ktime_get_ts(&cur_time_mon);
33831
33832 @@ -2181,9 +2181,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33833 * overflowing the shift of read_errors by hours_since_last.
33834 */
33835 if (hours_since_last >= 8 * sizeof(read_errors))
33836 - atomic_set(&rdev->read_errors, 0);
33837 + atomic_set_unchecked(&rdev->read_errors, 0);
33838 else
33839 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33840 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33841 }
33842
33843 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33844 @@ -2237,8 +2237,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33845 return;
33846
33847 check_decay_read_errors(mddev, rdev);
33848 - atomic_inc(&rdev->read_errors);
33849 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33850 + atomic_inc_unchecked(&rdev->read_errors);
33851 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33852 char b[BDEVNAME_SIZE];
33853 bdevname(rdev->bdev, b);
33854
33855 @@ -2246,7 +2246,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33856 "md/raid10:%s: %s: Raid device exceeded "
33857 "read_error threshold [cur %d:max %d]\n",
33858 mdname(mddev), b,
33859 - atomic_read(&rdev->read_errors), max_read_errors);
33860 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33861 printk(KERN_NOTICE
33862 "md/raid10:%s: %s: Failing raid device\n",
33863 mdname(mddev), b);
33864 @@ -2401,7 +2401,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33865 sect +
33866 choose_data_offset(r10_bio, rdev)),
33867 bdevname(rdev->bdev, b));
33868 - atomic_add(s, &rdev->corrected_errors);
33869 + atomic_add_unchecked(s, &rdev->corrected_errors);
33870 }
33871
33872 rdev_dec_pending(rdev, mddev);
33873 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33874 index 0689173..35df76c 100644
33875 --- a/drivers/md/raid5.c
33876 +++ b/drivers/md/raid5.c
33877 @@ -1756,21 +1756,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
33878 mdname(conf->mddev), STRIPE_SECTORS,
33879 (unsigned long long)s,
33880 bdevname(rdev->bdev, b));
33881 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33882 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33883 clear_bit(R5_ReadError, &sh->dev[i].flags);
33884 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33885 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
33886 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
33887
33888 - if (atomic_read(&rdev->read_errors))
33889 - atomic_set(&rdev->read_errors, 0);
33890 + if (atomic_read_unchecked(&rdev->read_errors))
33891 + atomic_set_unchecked(&rdev->read_errors, 0);
33892 } else {
33893 const char *bdn = bdevname(rdev->bdev, b);
33894 int retry = 0;
33895 int set_bad = 0;
33896
33897 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33898 - atomic_inc(&rdev->read_errors);
33899 + atomic_inc_unchecked(&rdev->read_errors);
33900 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33901 printk_ratelimited(
33902 KERN_WARNING
33903 @@ -1798,7 +1798,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33904 mdname(conf->mddev),
33905 (unsigned long long)s,
33906 bdn);
33907 - } else if (atomic_read(&rdev->read_errors)
33908 + } else if (atomic_read_unchecked(&rdev->read_errors)
33909 > conf->max_nr_stripes)
33910 printk(KERN_WARNING
33911 "md/raid:%s: Too many read errors, failing device %s.\n",
33912 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33913 index ebf3f05..b1f3e77 100644
33914 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33915 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33916 @@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
33917 .subvendor = _subvend, .subdevice = _subdev, \
33918 .driver_data = (unsigned long)&_driverdata }
33919
33920 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33921 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33922 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33923 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33924 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33925 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33926 index fa7188a..04a045e 100644
33927 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33928 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33929 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33930 union {
33931 dmx_ts_cb ts;
33932 dmx_section_cb sec;
33933 - } cb;
33934 + } __no_const cb;
33935
33936 struct dvb_demux *demux;
33937 void *priv;
33938 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33939 index 39eab73..60033e7 100644
33940 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33941 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33942 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33943 const struct dvb_device *template, void *priv, int type)
33944 {
33945 struct dvb_device *dvbdev;
33946 - struct file_operations *dvbdevfops;
33947 + file_operations_no_const *dvbdevfops;
33948 struct device *clsdev;
33949 int minor;
33950 int id;
33951 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33952 index 3940bb0..fb3952a 100644
33953 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33954 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33955 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33956
33957 struct dib0700_adapter_state {
33958 int (*set_param_save) (struct dvb_frontend *);
33959 -};
33960 +} __no_const;
33961
33962 static int dib7070_set_param_override(struct dvb_frontend *fe)
33963 {
33964 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33965 index 9382895..ac8093c 100644
33966 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33967 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33968 @@ -95,7 +95,7 @@ struct su3000_state {
33969
33970 struct s6x0_state {
33971 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33972 -};
33973 +} __no_const;
33974
33975 /* debug */
33976 static int dvb_usb_dw2102_debug;
33977 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33978 index 404f63a..4796533 100644
33979 --- a/drivers/media/dvb/frontends/dib3000.h
33980 +++ b/drivers/media/dvb/frontends/dib3000.h
33981 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33982 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33983 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33984 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33985 -};
33986 +} __no_const;
33987
33988 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33989 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33990 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33991 index 72ee8de..eae0c80 100644
33992 --- a/drivers/media/dvb/ngene/ngene-cards.c
33993 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33994 @@ -479,7 +479,7 @@ static struct ngene_info ngene_info_m780 = {
33995
33996 /****************************************************************************/
33997
33998 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33999 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
34000 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
34001 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
34002 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
34003 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
34004 index 697a421..16c5a5f 100644
34005 --- a/drivers/media/radio/radio-cadet.c
34006 +++ b/drivers/media/radio/radio-cadet.c
34007 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34008 unsigned char readbuf[RDS_BUFFER];
34009 int i = 0;
34010
34011 + if (count > RDS_BUFFER)
34012 + return -EFAULT;
34013 mutex_lock(&dev->lock);
34014 if (dev->rdsstat == 0)
34015 cadet_start_rds(dev);
34016 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34017 while (i < count && dev->rdsin != dev->rdsout)
34018 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34019
34020 - if (i && copy_to_user(data, readbuf, i))
34021 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34022 i = -EFAULT;
34023 unlock:
34024 mutex_unlock(&dev->lock);
34025 diff --git a/drivers/media/radio/radio-tea5777.h b/drivers/media/radio/radio-tea5777.h
34026 index 55cbd78..428b0da 100644
34027 --- a/drivers/media/radio/radio-tea5777.h
34028 +++ b/drivers/media/radio/radio-tea5777.h
34029 @@ -63,7 +63,7 @@ struct radio_tea5777_ops {
34030
34031 struct radio_tea5777 {
34032 struct v4l2_device *v4l2_dev;
34033 - struct v4l2_file_operations fops;
34034 + v4l2_file_operations_no_const fops;
34035 struct video_device vd; /* video device */
34036 bool has_am; /* Device can tune to AM freqs */
34037 bool write_before_read; /* must write before read quirk */
34038 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34039 index 9cde353..8c6a1c3 100644
34040 --- a/drivers/media/video/au0828/au0828.h
34041 +++ b/drivers/media/video/au0828/au0828.h
34042 @@ -191,7 +191,7 @@ struct au0828_dev {
34043
34044 /* I2C */
34045 struct i2c_adapter i2c_adap;
34046 - struct i2c_algorithm i2c_algo;
34047 + i2c_algorithm_no_const i2c_algo;
34048 struct i2c_client i2c_client;
34049 u32 i2c_rc;
34050
34051 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34052 index dfac6e3..c26de31 100644
34053 --- a/drivers/media/video/cx88/cx88-alsa.c
34054 +++ b/drivers/media/video/cx88/cx88-alsa.c
34055 @@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34056 * Only boards with eeprom and byte 1 at eeprom=1 have it
34057 */
34058
34059 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34060 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34061 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34062 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34063 {0, }
34064 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34065 index 88cf9d9..bbc4b2c 100644
34066 --- a/drivers/media/video/omap/omap_vout.c
34067 +++ b/drivers/media/video/omap/omap_vout.c
34068 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34069 OMAP_VIDEO2,
34070 };
34071
34072 -static struct videobuf_queue_ops video_vbq_ops;
34073 /* Variables configurable through module params*/
34074 static u32 video1_numbuffers = 3;
34075 static u32 video2_numbuffers = 3;
34076 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34077 {
34078 struct videobuf_queue *q;
34079 struct omap_vout_device *vout = NULL;
34080 + static struct videobuf_queue_ops video_vbq_ops = {
34081 + .buf_setup = omap_vout_buffer_setup,
34082 + .buf_prepare = omap_vout_buffer_prepare,
34083 + .buf_release = omap_vout_buffer_release,
34084 + .buf_queue = omap_vout_buffer_queue,
34085 + };
34086
34087 vout = video_drvdata(file);
34088 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34089 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34090 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34091
34092 q = &vout->vbq;
34093 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34094 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34095 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34096 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34097 spin_lock_init(&vout->vbq_lock);
34098
34099 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34100 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34101 index 036952f..80d356d 100644
34102 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34103 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34104 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34105
34106 /* I2C stuff */
34107 struct i2c_adapter i2c_adap;
34108 - struct i2c_algorithm i2c_algo;
34109 + i2c_algorithm_no_const i2c_algo;
34110 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34111 int i2c_cx25840_hack_state;
34112 int i2c_linked;
34113 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34114 index 02194c0..091733b 100644
34115 --- a/drivers/media/video/timblogiw.c
34116 +++ b/drivers/media/video/timblogiw.c
34117 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34118
34119 /* Platform device functions */
34120
34121 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34122 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34123 .vidioc_querycap = timblogiw_querycap,
34124 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34125 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34126 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34127 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34128 };
34129
34130 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34131 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34132 .owner = THIS_MODULE,
34133 .open = timblogiw_open,
34134 .release = timblogiw_close,
34135 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34136 index d99db56..a16b959 100644
34137 --- a/drivers/message/fusion/mptbase.c
34138 +++ b/drivers/message/fusion/mptbase.c
34139 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34140 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34141 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34142
34143 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34144 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34145 +#else
34146 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34147 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34148 +#endif
34149 +
34150 /*
34151 * Rounding UP to nearest 4-kB boundary here...
34152 */
34153 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34154 index 551262e..7551198 100644
34155 --- a/drivers/message/fusion/mptsas.c
34156 +++ b/drivers/message/fusion/mptsas.c
34157 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34158 return 0;
34159 }
34160
34161 +static inline void
34162 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34163 +{
34164 + if (phy_info->port_details) {
34165 + phy_info->port_details->rphy = rphy;
34166 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34167 + ioc->name, rphy));
34168 + }
34169 +
34170 + if (rphy) {
34171 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34172 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34173 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34174 + ioc->name, rphy, rphy->dev.release));
34175 + }
34176 +}
34177 +
34178 /* no mutex */
34179 static void
34180 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34181 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34182 return NULL;
34183 }
34184
34185 -static inline void
34186 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34187 -{
34188 - if (phy_info->port_details) {
34189 - phy_info->port_details->rphy = rphy;
34190 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34191 - ioc->name, rphy));
34192 - }
34193 -
34194 - if (rphy) {
34195 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34196 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34197 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34198 - ioc->name, rphy, rphy->dev.release));
34199 - }
34200 -}
34201 -
34202 static inline struct sas_port *
34203 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34204 {
34205 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34206 index 0c3ced7..1fe34ec 100644
34207 --- a/drivers/message/fusion/mptscsih.c
34208 +++ b/drivers/message/fusion/mptscsih.c
34209 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34210
34211 h = shost_priv(SChost);
34212
34213 - if (h) {
34214 - if (h->info_kbuf == NULL)
34215 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34216 - return h->info_kbuf;
34217 - h->info_kbuf[0] = '\0';
34218 + if (!h)
34219 + return NULL;
34220
34221 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34222 - h->info_kbuf[size-1] = '\0';
34223 - }
34224 + if (h->info_kbuf == NULL)
34225 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34226 + return h->info_kbuf;
34227 + h->info_kbuf[0] = '\0';
34228 +
34229 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34230 + h->info_kbuf[size-1] = '\0';
34231
34232 return h->info_kbuf;
34233 }
34234 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34235 index 8001aa6..b137580 100644
34236 --- a/drivers/message/i2o/i2o_proc.c
34237 +++ b/drivers/message/i2o/i2o_proc.c
34238 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
34239 "Array Controller Device"
34240 };
34241
34242 -static char *chtostr(char *tmp, u8 *chars, int n)
34243 -{
34244 - tmp[0] = 0;
34245 - return strncat(tmp, (char *)chars, n);
34246 -}
34247 -
34248 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34249 char *group)
34250 {
34251 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34252 } *result;
34253
34254 i2o_exec_execute_ddm_table ddm_table;
34255 - char tmp[28 + 1];
34256
34257 result = kmalloc(sizeof(*result), GFP_KERNEL);
34258 if (!result)
34259 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34260
34261 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34262 seq_printf(seq, "%-#8x", ddm_table.module_id);
34263 - seq_printf(seq, "%-29s",
34264 - chtostr(tmp, ddm_table.module_name_version, 28));
34265 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34266 seq_printf(seq, "%9d ", ddm_table.data_size);
34267 seq_printf(seq, "%8d", ddm_table.code_size);
34268
34269 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34270
34271 i2o_driver_result_table *result;
34272 i2o_driver_store_table *dst;
34273 - char tmp[28 + 1];
34274
34275 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
34276 if (result == NULL)
34277 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34278
34279 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34280 seq_printf(seq, "%-#8x", dst->module_id);
34281 - seq_printf(seq, "%-29s",
34282 - chtostr(tmp, dst->module_name_version, 28));
34283 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
34284 + seq_printf(seq, "%-.28s", dst->module_name_version);
34285 + seq_printf(seq, "%-.8s", dst->date);
34286 seq_printf(seq, "%8d ", dst->module_size);
34287 seq_printf(seq, "%8d ", dst->mpb_size);
34288 seq_printf(seq, "0x%04x", dst->module_flags);
34289 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34290 // == (allow) 512d bytes (max)
34291 static u16 *work16 = (u16 *) work32;
34292 int token;
34293 - char tmp[16 + 1];
34294
34295 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
34296
34297 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34298 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34299 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34300 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34301 - seq_printf(seq, "Vendor info : %s\n",
34302 - chtostr(tmp, (u8 *) (work32 + 2), 16));
34303 - seq_printf(seq, "Product info : %s\n",
34304 - chtostr(tmp, (u8 *) (work32 + 6), 16));
34305 - seq_printf(seq, "Description : %s\n",
34306 - chtostr(tmp, (u8 *) (work32 + 10), 16));
34307 - seq_printf(seq, "Product rev. : %s\n",
34308 - chtostr(tmp, (u8 *) (work32 + 14), 8));
34309 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34310 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34311 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34312 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34313
34314 seq_printf(seq, "Serial number : ");
34315 print_serial_number(seq, (u8 *) (work32 + 16),
34316 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34317 u8 pad[256]; // allow up to 256 byte (max) serial number
34318 } result;
34319
34320 - char tmp[24 + 1];
34321 -
34322 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
34323
34324 if (token < 0) {
34325 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34326 }
34327
34328 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34329 - seq_printf(seq, "Module name : %s\n",
34330 - chtostr(tmp, result.module_name, 24));
34331 - seq_printf(seq, "Module revision : %s\n",
34332 - chtostr(tmp, result.module_rev, 8));
34333 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34334 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34335
34336 seq_printf(seq, "Serial number : ");
34337 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34338 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34339 u8 instance_number[4];
34340 } result;
34341
34342 - char tmp[64 + 1];
34343 -
34344 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
34345
34346 if (token < 0) {
34347 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34348 return 0;
34349 }
34350
34351 - seq_printf(seq, "Device name : %s\n",
34352 - chtostr(tmp, result.device_name, 64));
34353 - seq_printf(seq, "Service name : %s\n",
34354 - chtostr(tmp, result.service_name, 64));
34355 - seq_printf(seq, "Physical name : %s\n",
34356 - chtostr(tmp, result.physical_location, 64));
34357 - seq_printf(seq, "Instance number : %s\n",
34358 - chtostr(tmp, result.instance_number, 4));
34359 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34360 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34361 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34362 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34363
34364 return 0;
34365 }
34366 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34367 index a8c08f3..155fe3d 100644
34368 --- a/drivers/message/i2o/iop.c
34369 +++ b/drivers/message/i2o/iop.c
34370 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34371
34372 spin_lock_irqsave(&c->context_list_lock, flags);
34373
34374 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34375 - atomic_inc(&c->context_list_counter);
34376 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34377 + atomic_inc_unchecked(&c->context_list_counter);
34378
34379 - entry->context = atomic_read(&c->context_list_counter);
34380 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34381
34382 list_add(&entry->list, &c->context_list);
34383
34384 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34385
34386 #if BITS_PER_LONG == 64
34387 spin_lock_init(&c->context_list_lock);
34388 - atomic_set(&c->context_list_counter, 0);
34389 + atomic_set_unchecked(&c->context_list_counter, 0);
34390 INIT_LIST_HEAD(&c->context_list);
34391 #endif
34392
34393 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34394 index 7ce65f4..e66e9bc 100644
34395 --- a/drivers/mfd/abx500-core.c
34396 +++ b/drivers/mfd/abx500-core.c
34397 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34398
34399 struct abx500_device_entry {
34400 struct list_head list;
34401 - struct abx500_ops ops;
34402 + abx500_ops_no_const ops;
34403 struct device *dev;
34404 };
34405
34406 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34407 index 965c480..71f2db9 100644
34408 --- a/drivers/mfd/janz-cmodio.c
34409 +++ b/drivers/mfd/janz-cmodio.c
34410 @@ -13,6 +13,7 @@
34411
34412 #include <linux/kernel.h>
34413 #include <linux/module.h>
34414 +#include <linux/slab.h>
34415 #include <linux/init.h>
34416 #include <linux/pci.h>
34417 #include <linux/interrupt.h>
34418 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34419 index a981e2a..5ca0c8b 100644
34420 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34421 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34422 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34423 * the lid is closed. This leads to interrupts as soon as a little move
34424 * is done.
34425 */
34426 - atomic_inc(&lis3->count);
34427 + atomic_inc_unchecked(&lis3->count);
34428
34429 wake_up_interruptible(&lis3->misc_wait);
34430 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34431 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34432 if (lis3->pm_dev)
34433 pm_runtime_get_sync(lis3->pm_dev);
34434
34435 - atomic_set(&lis3->count, 0);
34436 + atomic_set_unchecked(&lis3->count, 0);
34437 return 0;
34438 }
34439
34440 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34441 add_wait_queue(&lis3->misc_wait, &wait);
34442 while (true) {
34443 set_current_state(TASK_INTERRUPTIBLE);
34444 - data = atomic_xchg(&lis3->count, 0);
34445 + data = atomic_xchg_unchecked(&lis3->count, 0);
34446 if (data)
34447 break;
34448
34449 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34450 struct lis3lv02d, miscdev);
34451
34452 poll_wait(file, &lis3->misc_wait, wait);
34453 - if (atomic_read(&lis3->count))
34454 + if (atomic_read_unchecked(&lis3->count))
34455 return POLLIN | POLLRDNORM;
34456 return 0;
34457 }
34458 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34459 index 2b1482a..5d33616 100644
34460 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34461 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34462 @@ -266,7 +266,7 @@ struct lis3lv02d {
34463 struct input_polled_dev *idev; /* input device */
34464 struct platform_device *pdev; /* platform device */
34465 struct regulator_bulk_data regulators[2];
34466 - atomic_t count; /* interrupt count after last read */
34467 + atomic_unchecked_t count; /* interrupt count after last read */
34468 union axis_conversion ac; /* hw -> logical axis */
34469 int mapped_btns[3];
34470
34471 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34472 index 2f30bad..c4c13d0 100644
34473 --- a/drivers/misc/sgi-gru/gruhandles.c
34474 +++ b/drivers/misc/sgi-gru/gruhandles.c
34475 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34476 unsigned long nsec;
34477
34478 nsec = CLKS2NSEC(clks);
34479 - atomic_long_inc(&mcs_op_statistics[op].count);
34480 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34481 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34482 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34483 if (mcs_op_statistics[op].max < nsec)
34484 mcs_op_statistics[op].max = nsec;
34485 }
34486 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34487 index 950dbe9..eeef0f8 100644
34488 --- a/drivers/misc/sgi-gru/gruprocfs.c
34489 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34490 @@ -32,9 +32,9 @@
34491
34492 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34493
34494 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34495 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34496 {
34497 - unsigned long val = atomic_long_read(v);
34498 + unsigned long val = atomic_long_read_unchecked(v);
34499
34500 seq_printf(s, "%16lu %s\n", val, id);
34501 }
34502 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34503
34504 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34505 for (op = 0; op < mcsop_last; op++) {
34506 - count = atomic_long_read(&mcs_op_statistics[op].count);
34507 - total = atomic_long_read(&mcs_op_statistics[op].total);
34508 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34509 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34510 max = mcs_op_statistics[op].max;
34511 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34512 count ? total / count : 0, max);
34513 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34514 index 5c3ce24..4915ccb 100644
34515 --- a/drivers/misc/sgi-gru/grutables.h
34516 +++ b/drivers/misc/sgi-gru/grutables.h
34517 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34518 * GRU statistics.
34519 */
34520 struct gru_stats_s {
34521 - atomic_long_t vdata_alloc;
34522 - atomic_long_t vdata_free;
34523 - atomic_long_t gts_alloc;
34524 - atomic_long_t gts_free;
34525 - atomic_long_t gms_alloc;
34526 - atomic_long_t gms_free;
34527 - atomic_long_t gts_double_allocate;
34528 - atomic_long_t assign_context;
34529 - atomic_long_t assign_context_failed;
34530 - atomic_long_t free_context;
34531 - atomic_long_t load_user_context;
34532 - atomic_long_t load_kernel_context;
34533 - atomic_long_t lock_kernel_context;
34534 - atomic_long_t unlock_kernel_context;
34535 - atomic_long_t steal_user_context;
34536 - atomic_long_t steal_kernel_context;
34537 - atomic_long_t steal_context_failed;
34538 - atomic_long_t nopfn;
34539 - atomic_long_t asid_new;
34540 - atomic_long_t asid_next;
34541 - atomic_long_t asid_wrap;
34542 - atomic_long_t asid_reuse;
34543 - atomic_long_t intr;
34544 - atomic_long_t intr_cbr;
34545 - atomic_long_t intr_tfh;
34546 - atomic_long_t intr_spurious;
34547 - atomic_long_t intr_mm_lock_failed;
34548 - atomic_long_t call_os;
34549 - atomic_long_t call_os_wait_queue;
34550 - atomic_long_t user_flush_tlb;
34551 - atomic_long_t user_unload_context;
34552 - atomic_long_t user_exception;
34553 - atomic_long_t set_context_option;
34554 - atomic_long_t check_context_retarget_intr;
34555 - atomic_long_t check_context_unload;
34556 - atomic_long_t tlb_dropin;
34557 - atomic_long_t tlb_preload_page;
34558 - atomic_long_t tlb_dropin_fail_no_asid;
34559 - atomic_long_t tlb_dropin_fail_upm;
34560 - atomic_long_t tlb_dropin_fail_invalid;
34561 - atomic_long_t tlb_dropin_fail_range_active;
34562 - atomic_long_t tlb_dropin_fail_idle;
34563 - atomic_long_t tlb_dropin_fail_fmm;
34564 - atomic_long_t tlb_dropin_fail_no_exception;
34565 - atomic_long_t tfh_stale_on_fault;
34566 - atomic_long_t mmu_invalidate_range;
34567 - atomic_long_t mmu_invalidate_page;
34568 - atomic_long_t flush_tlb;
34569 - atomic_long_t flush_tlb_gru;
34570 - atomic_long_t flush_tlb_gru_tgh;
34571 - atomic_long_t flush_tlb_gru_zero_asid;
34572 + atomic_long_unchecked_t vdata_alloc;
34573 + atomic_long_unchecked_t vdata_free;
34574 + atomic_long_unchecked_t gts_alloc;
34575 + atomic_long_unchecked_t gts_free;
34576 + atomic_long_unchecked_t gms_alloc;
34577 + atomic_long_unchecked_t gms_free;
34578 + atomic_long_unchecked_t gts_double_allocate;
34579 + atomic_long_unchecked_t assign_context;
34580 + atomic_long_unchecked_t assign_context_failed;
34581 + atomic_long_unchecked_t free_context;
34582 + atomic_long_unchecked_t load_user_context;
34583 + atomic_long_unchecked_t load_kernel_context;
34584 + atomic_long_unchecked_t lock_kernel_context;
34585 + atomic_long_unchecked_t unlock_kernel_context;
34586 + atomic_long_unchecked_t steal_user_context;
34587 + atomic_long_unchecked_t steal_kernel_context;
34588 + atomic_long_unchecked_t steal_context_failed;
34589 + atomic_long_unchecked_t nopfn;
34590 + atomic_long_unchecked_t asid_new;
34591 + atomic_long_unchecked_t asid_next;
34592 + atomic_long_unchecked_t asid_wrap;
34593 + atomic_long_unchecked_t asid_reuse;
34594 + atomic_long_unchecked_t intr;
34595 + atomic_long_unchecked_t intr_cbr;
34596 + atomic_long_unchecked_t intr_tfh;
34597 + atomic_long_unchecked_t intr_spurious;
34598 + atomic_long_unchecked_t intr_mm_lock_failed;
34599 + atomic_long_unchecked_t call_os;
34600 + atomic_long_unchecked_t call_os_wait_queue;
34601 + atomic_long_unchecked_t user_flush_tlb;
34602 + atomic_long_unchecked_t user_unload_context;
34603 + atomic_long_unchecked_t user_exception;
34604 + atomic_long_unchecked_t set_context_option;
34605 + atomic_long_unchecked_t check_context_retarget_intr;
34606 + atomic_long_unchecked_t check_context_unload;
34607 + atomic_long_unchecked_t tlb_dropin;
34608 + atomic_long_unchecked_t tlb_preload_page;
34609 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34610 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34611 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34612 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34613 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34614 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34615 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34616 + atomic_long_unchecked_t tfh_stale_on_fault;
34617 + atomic_long_unchecked_t mmu_invalidate_range;
34618 + atomic_long_unchecked_t mmu_invalidate_page;
34619 + atomic_long_unchecked_t flush_tlb;
34620 + atomic_long_unchecked_t flush_tlb_gru;
34621 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34622 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34623
34624 - atomic_long_t copy_gpa;
34625 - atomic_long_t read_gpa;
34626 + atomic_long_unchecked_t copy_gpa;
34627 + atomic_long_unchecked_t read_gpa;
34628
34629 - atomic_long_t mesq_receive;
34630 - atomic_long_t mesq_receive_none;
34631 - atomic_long_t mesq_send;
34632 - atomic_long_t mesq_send_failed;
34633 - atomic_long_t mesq_noop;
34634 - atomic_long_t mesq_send_unexpected_error;
34635 - atomic_long_t mesq_send_lb_overflow;
34636 - atomic_long_t mesq_send_qlimit_reached;
34637 - atomic_long_t mesq_send_amo_nacked;
34638 - atomic_long_t mesq_send_put_nacked;
34639 - atomic_long_t mesq_page_overflow;
34640 - atomic_long_t mesq_qf_locked;
34641 - atomic_long_t mesq_qf_noop_not_full;
34642 - atomic_long_t mesq_qf_switch_head_failed;
34643 - atomic_long_t mesq_qf_unexpected_error;
34644 - atomic_long_t mesq_noop_unexpected_error;
34645 - atomic_long_t mesq_noop_lb_overflow;
34646 - atomic_long_t mesq_noop_qlimit_reached;
34647 - atomic_long_t mesq_noop_amo_nacked;
34648 - atomic_long_t mesq_noop_put_nacked;
34649 - atomic_long_t mesq_noop_page_overflow;
34650 + atomic_long_unchecked_t mesq_receive;
34651 + atomic_long_unchecked_t mesq_receive_none;
34652 + atomic_long_unchecked_t mesq_send;
34653 + atomic_long_unchecked_t mesq_send_failed;
34654 + atomic_long_unchecked_t mesq_noop;
34655 + atomic_long_unchecked_t mesq_send_unexpected_error;
34656 + atomic_long_unchecked_t mesq_send_lb_overflow;
34657 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34658 + atomic_long_unchecked_t mesq_send_amo_nacked;
34659 + atomic_long_unchecked_t mesq_send_put_nacked;
34660 + atomic_long_unchecked_t mesq_page_overflow;
34661 + atomic_long_unchecked_t mesq_qf_locked;
34662 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34663 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34664 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34665 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34666 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34667 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34668 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34669 + atomic_long_unchecked_t mesq_noop_put_nacked;
34670 + atomic_long_unchecked_t mesq_noop_page_overflow;
34671
34672 };
34673
34674 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34675 tghop_invalidate, mcsop_last};
34676
34677 struct mcs_op_statistic {
34678 - atomic_long_t count;
34679 - atomic_long_t total;
34680 + atomic_long_unchecked_t count;
34681 + atomic_long_unchecked_t total;
34682 unsigned long max;
34683 };
34684
34685 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34686
34687 #define STAT(id) do { \
34688 if (gru_options & OPT_STATS) \
34689 - atomic_long_inc(&gru_stats.id); \
34690 + atomic_long_inc_unchecked(&gru_stats.id); \
34691 } while (0)
34692
34693 #ifdef CONFIG_SGI_GRU_DEBUG
34694 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34695 index c862cd4..0d176fe 100644
34696 --- a/drivers/misc/sgi-xp/xp.h
34697 +++ b/drivers/misc/sgi-xp/xp.h
34698 @@ -288,7 +288,7 @@ struct xpc_interface {
34699 xpc_notify_func, void *);
34700 void (*received) (short, int, void *);
34701 enum xp_retval (*partid_to_nasids) (short, void *);
34702 -};
34703 +} __no_const;
34704
34705 extern struct xpc_interface xpc_interface;
34706
34707 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34708 index b94d5f7..7f494c5 100644
34709 --- a/drivers/misc/sgi-xp/xpc.h
34710 +++ b/drivers/misc/sgi-xp/xpc.h
34711 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34712 void (*received_payload) (struct xpc_channel *, void *);
34713 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34714 };
34715 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34716
34717 /* struct xpc_partition act_state values (for XPC HB) */
34718
34719 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34720 /* found in xpc_main.c */
34721 extern struct device *xpc_part;
34722 extern struct device *xpc_chan;
34723 -extern struct xpc_arch_operations xpc_arch_ops;
34724 +extern xpc_arch_operations_no_const xpc_arch_ops;
34725 extern int xpc_disengage_timelimit;
34726 extern int xpc_disengage_timedout;
34727 extern int xpc_activate_IRQ_rcvd;
34728 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34729 index 8d082b4..aa749ae 100644
34730 --- a/drivers/misc/sgi-xp/xpc_main.c
34731 +++ b/drivers/misc/sgi-xp/xpc_main.c
34732 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34733 .notifier_call = xpc_system_die,
34734 };
34735
34736 -struct xpc_arch_operations xpc_arch_ops;
34737 +xpc_arch_operations_no_const xpc_arch_ops;
34738
34739 /*
34740 * Timer function to enforce the timelimit on the partition disengage.
34741 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34742 index 504da71..9722d43 100644
34743 --- a/drivers/mmc/host/sdhci-pci.c
34744 +++ b/drivers/mmc/host/sdhci-pci.c
34745 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34746 .probe = via_probe,
34747 };
34748
34749 -static const struct pci_device_id pci_ids[] __devinitdata = {
34750 +static const struct pci_device_id pci_ids[] __devinitconst = {
34751 {
34752 .vendor = PCI_VENDOR_ID_RICOH,
34753 .device = PCI_DEVICE_ID_RICOH_R5C822,
34754 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34755 index a4eb8b5..8c0628f 100644
34756 --- a/drivers/mtd/devices/doc2000.c
34757 +++ b/drivers/mtd/devices/doc2000.c
34758 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34759
34760 /* The ECC will not be calculated correctly if less than 512 is written */
34761 /* DBB-
34762 - if (len != 0x200 && eccbuf)
34763 + if (len != 0x200)
34764 printk(KERN_WARNING
34765 "ECC needs a full sector write (adr: %lx size %lx)\n",
34766 (long) to, (long) len);
34767 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34768 index 0650aaf..7718762 100644
34769 --- a/drivers/mtd/nand/denali.c
34770 +++ b/drivers/mtd/nand/denali.c
34771 @@ -26,6 +26,7 @@
34772 #include <linux/pci.h>
34773 #include <linux/mtd/mtd.h>
34774 #include <linux/module.h>
34775 +#include <linux/slab.h>
34776
34777 #include "denali.h"
34778
34779 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34780 index 51b9d6a..52af9a7 100644
34781 --- a/drivers/mtd/nftlmount.c
34782 +++ b/drivers/mtd/nftlmount.c
34783 @@ -24,6 +24,7 @@
34784 #include <asm/errno.h>
34785 #include <linux/delay.h>
34786 #include <linux/slab.h>
34787 +#include <linux/sched.h>
34788 #include <linux/mtd/mtd.h>
34789 #include <linux/mtd/nand.h>
34790 #include <linux/mtd/nftl.h>
34791 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34792 index 57d64b8..623dd86 100644
34793 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34794 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34795 @@ -2845,7 +2845,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34796 */
34797
34798 #define ATL2_PARAM(X, desc) \
34799 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34800 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34801 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34802 MODULE_PARM_DESC(X, desc);
34803 #else
34804 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34805 index f83e033..8b4f43a 100644
34806 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34807 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34808 @@ -486,7 +486,7 @@ struct bnx2x_rx_mode_obj {
34809
34810 int (*wait_comp)(struct bnx2x *bp,
34811 struct bnx2x_rx_mode_ramrod_params *p);
34812 -};
34813 +} __no_const;
34814
34815 /********************** Set multicast group ***********************************/
34816
34817 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34818 index 6d52cb2..bc95640 100644
34819 --- a/drivers/net/ethernet/broadcom/tg3.h
34820 +++ b/drivers/net/ethernet/broadcom/tg3.h
34821 @@ -140,6 +140,7 @@
34822 #define CHIPREV_ID_5750_A0 0x4000
34823 #define CHIPREV_ID_5750_A1 0x4001
34824 #define CHIPREV_ID_5750_A3 0x4003
34825 +#define CHIPREV_ID_5750_C1 0x4201
34826 #define CHIPREV_ID_5750_C2 0x4202
34827 #define CHIPREV_ID_5752_A0_HW 0x5000
34828 #define CHIPREV_ID_5752_A0 0x6000
34829 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34830 index 8cffcdf..aadf043 100644
34831 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34832 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34833 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34834 */
34835 struct l2t_skb_cb {
34836 arp_failure_handler_func arp_failure_handler;
34837 -};
34838 +} __no_const;
34839
34840 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34841
34842 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34843 index f879e92..726f20f 100644
34844 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34845 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34846 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34847 for (i=0; i<ETH_ALEN; i++) {
34848 tmp.addr[i] = dev->dev_addr[i];
34849 }
34850 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34851 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34852 break;
34853
34854 case DE4X5_SET_HWADDR: /* Set the hardware address */
34855 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34856 spin_lock_irqsave(&lp->lock, flags);
34857 memcpy(&statbuf, &lp->pktStats, ioc->len);
34858 spin_unlock_irqrestore(&lp->lock, flags);
34859 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34860 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34861 return -EFAULT;
34862 break;
34863 }
34864 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34865 index ed7d1dc..d426748 100644
34866 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34867 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34868 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34869 {NULL}};
34870
34871
34872 -static const char *block_name[] __devinitdata = {
34873 +static const char *block_name[] __devinitconst = {
34874 "21140 non-MII",
34875 "21140 MII PHY",
34876 "21142 Serial PHY",
34877 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34878 index 75d45f8..3d9c55b 100644
34879 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34880 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34881 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34882 struct uli_phy_ops {
34883 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34884 u16 (*read)(struct uli526x_board_info *, u8, u8);
34885 - } phy;
34886 + } __no_const phy;
34887 struct net_device *next_dev; /* next device */
34888 struct pci_dev *pdev; /* PCI device */
34889 spinlock_t lock;
34890 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34891 index 4d1ffca..7c1ec4d 100644
34892 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34893 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34894 @@ -236,7 +236,7 @@ struct pci_id_info {
34895 int drv_flags; /* Driver use, intended as capability flags. */
34896 };
34897
34898 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34899 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34900 { /* Sometime a Level-One switch card. */
34901 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34902 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34903 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34904 index d7bb52a..3b83588 100644
34905 --- a/drivers/net/ethernet/dlink/sundance.c
34906 +++ b/drivers/net/ethernet/dlink/sundance.c
34907 @@ -218,7 +218,7 @@ enum {
34908 struct pci_id_info {
34909 const char *name;
34910 };
34911 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34912 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34913 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34914 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34915 {"D-Link DFE-580TX 4 port Server Adapter"},
34916 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34917 index 78b8aa8..dd6323a 100644
34918 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34919 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34920 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34921
34922 if (wrapped)
34923 newacc += 65536;
34924 - ACCESS_ONCE(*acc) = newacc;
34925 + ACCESS_ONCE_RW(*acc) = newacc;
34926 }
34927
34928 void be_parse_stats(struct be_adapter *adapter)
34929 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34930 index 74d749e..eefb1bd 100644
34931 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34932 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34933 @@ -31,6 +31,8 @@
34934 #include <linux/netdevice.h>
34935 #include <linux/phy.h>
34936 #include <linux/platform_device.h>
34937 +#include <linux/interrupt.h>
34938 +#include <linux/irqreturn.h>
34939 #include <net/ip.h>
34940
34941 #include "ftgmac100.h"
34942 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34943 index b901a01..1ff32ee 100644
34944 --- a/drivers/net/ethernet/faraday/ftmac100.c
34945 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34946 @@ -31,6 +31,8 @@
34947 #include <linux/module.h>
34948 #include <linux/netdevice.h>
34949 #include <linux/platform_device.h>
34950 +#include <linux/interrupt.h>
34951 +#include <linux/irqreturn.h>
34952
34953 #include "ftmac100.h"
34954
34955 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34956 index 9d71c9c..0e4a0ac 100644
34957 --- a/drivers/net/ethernet/fealnx.c
34958 +++ b/drivers/net/ethernet/fealnx.c
34959 @@ -150,7 +150,7 @@ struct chip_info {
34960 int flags;
34961 };
34962
34963 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
34964 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
34965 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34966 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
34967 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
34968 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
34969 index cb3356c..c302a98 100644
34970 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
34971 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
34972 @@ -181,7 +181,7 @@ struct e1000_info;
34973 #define E1000_TXDCTL_DMA_BURST_ENABLE \
34974 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
34975 E1000_TXDCTL_COUNT_DESC | \
34976 - (5 << 16) | /* wthresh must be +1 more than desired */\
34977 + (1 << 16) | /* wthresh must be +1 more than desired */\
34978 (1 << 8) | /* hthresh */ \
34979 0x1f) /* pthresh */
34980
34981 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
34982 index ed5b409..ec37828 100644
34983 --- a/drivers/net/ethernet/intel/e1000e/hw.h
34984 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
34985 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
34986 void (*rar_set)(struct e1000_hw *, u8 *, u32);
34987 s32 (*read_mac_addr)(struct e1000_hw *);
34988 };
34989 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
34990
34991 /*
34992 * When to use various PHY register access functions:
34993 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
34994 void (*power_up)(struct e1000_hw *);
34995 void (*power_down)(struct e1000_hw *);
34996 };
34997 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
34998
34999 /* Function pointers for the NVM. */
35000 struct e1000_nvm_operations {
35001 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35002 s32 (*validate)(struct e1000_hw *);
35003 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35004 };
35005 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35006
35007 struct e1000_mac_info {
35008 - struct e1000_mac_operations ops;
35009 + e1000_mac_operations_no_const ops;
35010 u8 addr[ETH_ALEN];
35011 u8 perm_addr[ETH_ALEN];
35012
35013 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35014 };
35015
35016 struct e1000_phy_info {
35017 - struct e1000_phy_operations ops;
35018 + e1000_phy_operations_no_const ops;
35019
35020 enum e1000_phy_type type;
35021
35022 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35023 };
35024
35025 struct e1000_nvm_info {
35026 - struct e1000_nvm_operations ops;
35027 + e1000_nvm_operations_no_const ops;
35028
35029 enum e1000_nvm_type type;
35030 enum e1000_nvm_override override;
35031 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35032 index c2a51dc..c2bd262 100644
35033 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35034 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35035 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35036 void (*release_swfw_sync)(struct e1000_hw *, u16);
35037
35038 };
35039 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35040
35041 struct e1000_phy_operations {
35042 s32 (*acquire)(struct e1000_hw *);
35043 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35044 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35045 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35046 };
35047 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35048
35049 struct e1000_nvm_operations {
35050 s32 (*acquire)(struct e1000_hw *);
35051 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35052 s32 (*validate)(struct e1000_hw *);
35053 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35054 };
35055 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35056
35057 struct e1000_info {
35058 s32 (*get_invariants)(struct e1000_hw *);
35059 @@ -364,7 +367,7 @@ struct e1000_info {
35060 extern const struct e1000_info e1000_82575_info;
35061
35062 struct e1000_mac_info {
35063 - struct e1000_mac_operations ops;
35064 + e1000_mac_operations_no_const ops;
35065
35066 u8 addr[6];
35067 u8 perm_addr[6];
35068 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35069 };
35070
35071 struct e1000_phy_info {
35072 - struct e1000_phy_operations ops;
35073 + e1000_phy_operations_no_const ops;
35074
35075 enum e1000_phy_type type;
35076
35077 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35078 };
35079
35080 struct e1000_nvm_info {
35081 - struct e1000_nvm_operations ops;
35082 + e1000_nvm_operations_no_const ops;
35083 enum e1000_nvm_type type;
35084 enum e1000_nvm_override override;
35085
35086 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35087 s32 (*check_for_ack)(struct e1000_hw *, u16);
35088 s32 (*check_for_rst)(struct e1000_hw *, u16);
35089 };
35090 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35091
35092 struct e1000_mbx_stats {
35093 u32 msgs_tx;
35094 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35095 };
35096
35097 struct e1000_mbx_info {
35098 - struct e1000_mbx_operations ops;
35099 + e1000_mbx_operations_no_const ops;
35100 struct e1000_mbx_stats stats;
35101 u32 timeout;
35102 u32 usec_delay;
35103 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35104 index 57db3c6..aa825fc 100644
35105 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35106 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35107 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35108 s32 (*read_mac_addr)(struct e1000_hw *);
35109 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35110 };
35111 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35112
35113 struct e1000_mac_info {
35114 - struct e1000_mac_operations ops;
35115 + e1000_mac_operations_no_const ops;
35116 u8 addr[6];
35117 u8 perm_addr[6];
35118
35119 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35120 s32 (*check_for_ack)(struct e1000_hw *);
35121 s32 (*check_for_rst)(struct e1000_hw *);
35122 };
35123 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35124
35125 struct e1000_mbx_stats {
35126 u32 msgs_tx;
35127 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35128 };
35129
35130 struct e1000_mbx_info {
35131 - struct e1000_mbx_operations ops;
35132 + e1000_mbx_operations_no_const ops;
35133 struct e1000_mbx_stats stats;
35134 u32 timeout;
35135 u32 usec_delay;
35136 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35137 index 3456d56..b688d81 100644
35138 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35139 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35140 @@ -884,7 +884,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35141 /* store the new cycle speed */
35142 adapter->cycle_speed = cycle_speed;
35143
35144 - ACCESS_ONCE(adapter->base_incval) = incval;
35145 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35146 smp_mb();
35147
35148 /* grab the ptp lock */
35149 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35150 index 400f86a..7f2e062 100644
35151 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35152 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35153 @@ -2799,6 +2799,7 @@ struct ixgbe_eeprom_operations {
35154 s32 (*update_checksum)(struct ixgbe_hw *);
35155 u16 (*calc_checksum)(struct ixgbe_hw *);
35156 };
35157 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35158
35159 struct ixgbe_mac_operations {
35160 s32 (*init_hw)(struct ixgbe_hw *);
35161 @@ -2865,6 +2866,7 @@ struct ixgbe_mac_operations {
35162 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35163 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35164 };
35165 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35166
35167 struct ixgbe_phy_operations {
35168 s32 (*identify)(struct ixgbe_hw *);
35169 @@ -2884,9 +2886,10 @@ struct ixgbe_phy_operations {
35170 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35171 s32 (*check_overtemp)(struct ixgbe_hw *);
35172 };
35173 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35174
35175 struct ixgbe_eeprom_info {
35176 - struct ixgbe_eeprom_operations ops;
35177 + ixgbe_eeprom_operations_no_const ops;
35178 enum ixgbe_eeprom_type type;
35179 u32 semaphore_delay;
35180 u16 word_size;
35181 @@ -2896,7 +2899,7 @@ struct ixgbe_eeprom_info {
35182
35183 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35184 struct ixgbe_mac_info {
35185 - struct ixgbe_mac_operations ops;
35186 + ixgbe_mac_operations_no_const ops;
35187 enum ixgbe_mac_type type;
35188 u8 addr[ETH_ALEN];
35189 u8 perm_addr[ETH_ALEN];
35190 @@ -2926,7 +2929,7 @@ struct ixgbe_mac_info {
35191 };
35192
35193 struct ixgbe_phy_info {
35194 - struct ixgbe_phy_operations ops;
35195 + ixgbe_phy_operations_no_const ops;
35196 struct mdio_if_info mdio;
35197 enum ixgbe_phy_type type;
35198 u32 id;
35199 @@ -2954,6 +2957,7 @@ struct ixgbe_mbx_operations {
35200 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35201 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35202 };
35203 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35204
35205 struct ixgbe_mbx_stats {
35206 u32 msgs_tx;
35207 @@ -2965,7 +2969,7 @@ struct ixgbe_mbx_stats {
35208 };
35209
35210 struct ixgbe_mbx_info {
35211 - struct ixgbe_mbx_operations ops;
35212 + ixgbe_mbx_operations_no_const ops;
35213 struct ixgbe_mbx_stats stats;
35214 u32 timeout;
35215 u32 usec_delay;
35216 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35217 index 25c951d..cc7cf33 100644
35218 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35219 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35220 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35221 s32 (*clear_vfta)(struct ixgbe_hw *);
35222 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35223 };
35224 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35225
35226 enum ixgbe_mac_type {
35227 ixgbe_mac_unknown = 0,
35228 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35229 };
35230
35231 struct ixgbe_mac_info {
35232 - struct ixgbe_mac_operations ops;
35233 + ixgbe_mac_operations_no_const ops;
35234 u8 addr[6];
35235 u8 perm_addr[6];
35236
35237 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35238 s32 (*check_for_ack)(struct ixgbe_hw *);
35239 s32 (*check_for_rst)(struct ixgbe_hw *);
35240 };
35241 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35242
35243 struct ixgbe_mbx_stats {
35244 u32 msgs_tx;
35245 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35246 };
35247
35248 struct ixgbe_mbx_info {
35249 - struct ixgbe_mbx_operations ops;
35250 + ixgbe_mbx_operations_no_const ops;
35251 struct ixgbe_mbx_stats stats;
35252 u32 timeout;
35253 u32 udelay;
35254 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35255 index 9e0c1ee..8471f77 100644
35256 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35257 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35258 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35259 void (*link_down)(struct __vxge_hw_device *devh);
35260 void (*crit_err)(struct __vxge_hw_device *devh,
35261 enum vxge_hw_event type, u64 ext_data);
35262 -};
35263 +} __no_const;
35264
35265 /*
35266 * struct __vxge_hw_blockpool_entry - Block private data structure
35267 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35268 index 4a518a3..936b334 100644
35269 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35270 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35271 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35272 struct vxge_hw_mempool_dma *dma_object,
35273 u32 index,
35274 u32 is_last);
35275 -};
35276 +} __no_const;
35277
35278 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35279 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35280 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35281 index b47d5b3..273a516 100644
35282 --- a/drivers/net/ethernet/realtek/r8169.c
35283 +++ b/drivers/net/ethernet/realtek/r8169.c
35284 @@ -745,22 +745,22 @@ struct rtl8169_private {
35285 struct mdio_ops {
35286 void (*write)(struct rtl8169_private *, int, int);
35287 int (*read)(struct rtl8169_private *, int);
35288 - } mdio_ops;
35289 + } __no_const mdio_ops;
35290
35291 struct pll_power_ops {
35292 void (*down)(struct rtl8169_private *);
35293 void (*up)(struct rtl8169_private *);
35294 - } pll_power_ops;
35295 + } __no_const pll_power_ops;
35296
35297 struct jumbo_ops {
35298 void (*enable)(struct rtl8169_private *);
35299 void (*disable)(struct rtl8169_private *);
35300 - } jumbo_ops;
35301 + } __no_const jumbo_ops;
35302
35303 struct csi_ops {
35304 void (*write)(struct rtl8169_private *, int, int);
35305 u32 (*read)(struct rtl8169_private *, int);
35306 - } csi_ops;
35307 + } __no_const csi_ops;
35308
35309 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35310 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35311 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35312 index 4613591..d816601 100644
35313 --- a/drivers/net/ethernet/sis/sis190.c
35314 +++ b/drivers/net/ethernet/sis/sis190.c
35315 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35316 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35317 struct net_device *dev)
35318 {
35319 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35320 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35321 struct sis190_private *tp = netdev_priv(dev);
35322 struct pci_dev *isa_bridge;
35323 u8 reg, tmp8;
35324 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35325 index 0c74a70..3bc6f68 100644
35326 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35327 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35328 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35329
35330 writel(value, ioaddr + MMC_CNTRL);
35331
35332 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35333 - MMC_CNTRL, value);
35334 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35335 +// MMC_CNTRL, value);
35336 }
35337
35338 /* To mask all all interrupts.*/
35339 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35340 index 95ceb35..318fc12 100644
35341 --- a/drivers/net/hyperv/hyperv_net.h
35342 +++ b/drivers/net/hyperv/hyperv_net.h
35343 @@ -99,7 +99,7 @@ struct rndis_device {
35344
35345 enum rndis_device_state state;
35346 bool link_state;
35347 - atomic_t new_req_id;
35348 + atomic_unchecked_t new_req_id;
35349
35350 spinlock_t request_lock;
35351 struct list_head req_list;
35352 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35353 index 1e88a10..1b01736 100644
35354 --- a/drivers/net/hyperv/rndis_filter.c
35355 +++ b/drivers/net/hyperv/rndis_filter.c
35356 @@ -99,7 +99,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35357 * template
35358 */
35359 set = &rndis_msg->msg.set_req;
35360 - set->req_id = atomic_inc_return(&dev->new_req_id);
35361 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35362
35363 /* Add to the request list */
35364 spin_lock_irqsave(&dev->request_lock, flags);
35365 @@ -730,7 +730,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35366
35367 /* Setup the rndis set */
35368 halt = &request->request_msg.msg.halt_req;
35369 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35370 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35371
35372 /* Ignore return since this msg is optional. */
35373 rndis_filter_send_request(dev, request);
35374 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35375 index 5c05572..389610b 100644
35376 --- a/drivers/net/ppp/ppp_generic.c
35377 +++ b/drivers/net/ppp/ppp_generic.c
35378 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35379 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35380 struct ppp_stats stats;
35381 struct ppp_comp_stats cstats;
35382 - char *vers;
35383
35384 switch (cmd) {
35385 case SIOCGPPPSTATS:
35386 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35387 break;
35388
35389 case SIOCGPPPVER:
35390 - vers = PPP_VERSION;
35391 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35392 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35393 break;
35394 err = 0;
35395 break;
35396 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35397 index 3a16d4f..a311cec 100644
35398 --- a/drivers/net/tun.c
35399 +++ b/drivers/net/tun.c
35400 @@ -1367,7 +1367,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35401 }
35402
35403 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35404 - unsigned long arg, int ifreq_len)
35405 + unsigned long arg, size_t ifreq_len)
35406 {
35407 struct tun_file *tfile = file->private_data;
35408 struct tun_struct *tun;
35409 @@ -1378,6 +1378,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35410 int vnet_hdr_sz;
35411 int ret;
35412
35413 + if (ifreq_len > sizeof ifr)
35414 + return -EFAULT;
35415 +
35416 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35417 if (copy_from_user(&ifr, argp, ifreq_len))
35418 return -EFAULT;
35419 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35420 index 62f30b4..ff99dfd 100644
35421 --- a/drivers/net/usb/hso.c
35422 +++ b/drivers/net/usb/hso.c
35423 @@ -71,7 +71,7 @@
35424 #include <asm/byteorder.h>
35425 #include <linux/serial_core.h>
35426 #include <linux/serial.h>
35427 -
35428 +#include <asm/local.h>
35429
35430 #define MOD_AUTHOR "Option Wireless"
35431 #define MOD_DESCRIPTION "USB High Speed Option driver"
35432 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35433 struct urb *urb;
35434
35435 urb = serial->rx_urb[0];
35436 - if (serial->port.count > 0) {
35437 + if (atomic_read(&serial->port.count) > 0) {
35438 count = put_rxbuf_data(urb, serial);
35439 if (count == -1)
35440 return;
35441 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35442 DUMP1(urb->transfer_buffer, urb->actual_length);
35443
35444 /* Anyone listening? */
35445 - if (serial->port.count == 0)
35446 + if (atomic_read(&serial->port.count) == 0)
35447 return;
35448
35449 if (status == 0) {
35450 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35451 tty_port_tty_set(&serial->port, tty);
35452
35453 /* check for port already opened, if not set the termios */
35454 - serial->port.count++;
35455 - if (serial->port.count == 1) {
35456 + if (atomic_inc_return(&serial->port.count) == 1) {
35457 serial->rx_state = RX_IDLE;
35458 /* Force default termio settings */
35459 _hso_serial_set_termios(tty, NULL);
35460 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35461 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35462 if (result) {
35463 hso_stop_serial_device(serial->parent);
35464 - serial->port.count--;
35465 + atomic_dec(&serial->port.count);
35466 kref_put(&serial->parent->ref, hso_serial_ref_free);
35467 }
35468 } else {
35469 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35470
35471 /* reset the rts and dtr */
35472 /* do the actual close */
35473 - serial->port.count--;
35474 + atomic_dec(&serial->port.count);
35475
35476 - if (serial->port.count <= 0) {
35477 - serial->port.count = 0;
35478 + if (atomic_read(&serial->port.count) <= 0) {
35479 + atomic_set(&serial->port.count, 0);
35480 tty_port_tty_set(&serial->port, NULL);
35481 if (!usb_gone)
35482 hso_stop_serial_device(serial->parent);
35483 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35484
35485 /* the actual setup */
35486 spin_lock_irqsave(&serial->serial_lock, flags);
35487 - if (serial->port.count)
35488 + if (atomic_read(&serial->port.count))
35489 _hso_serial_set_termios(tty, old);
35490 else
35491 tty->termios = old;
35492 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35493 D1("Pending read interrupt on port %d\n", i);
35494 spin_lock(&serial->serial_lock);
35495 if (serial->rx_state == RX_IDLE &&
35496 - serial->port.count > 0) {
35497 + atomic_read(&serial->port.count) > 0) {
35498 /* Setup and send a ctrl req read on
35499 * port i */
35500 if (!serial->rx_urb_filled[0]) {
35501 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35502 /* Start all serial ports */
35503 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35504 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35505 - if (dev2ser(serial_table[i])->port.count) {
35506 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35507 result =
35508 hso_start_serial_device(serial_table[i], GFP_NOIO);
35509 hso_kick_transmit(dev2ser(serial_table[i]));
35510 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35511 index 6169fbd..40e8422 100644
35512 --- a/drivers/net/wireless/ath/ath.h
35513 +++ b/drivers/net/wireless/ath/ath.h
35514 @@ -119,6 +119,7 @@ struct ath_ops {
35515 void (*write_flush) (void *);
35516 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35517 };
35518 +typedef struct ath_ops __no_const ath_ops_no_const;
35519
35520 struct ath_common;
35521 struct ath_bus_ops;
35522 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35523 index 8d78253..bebbb68 100644
35524 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35525 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35526 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35527 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35528 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35529
35530 - ACCESS_ONCE(ads->ds_link) = i->link;
35531 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35532 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35533 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35534
35535 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35536 ctl6 = SM(i->keytype, AR_EncrType);
35537 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35538
35539 if ((i->is_first || i->is_last) &&
35540 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35541 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35542 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35543 | set11nTries(i->rates, 1)
35544 | set11nTries(i->rates, 2)
35545 | set11nTries(i->rates, 3)
35546 | (i->dur_update ? AR_DurUpdateEna : 0)
35547 | SM(0, AR_BurstDur);
35548
35549 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35550 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35551 | set11nRate(i->rates, 1)
35552 | set11nRate(i->rates, 2)
35553 | set11nRate(i->rates, 3);
35554 } else {
35555 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35556 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35557 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35558 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35559 }
35560
35561 if (!i->is_first) {
35562 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35563 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35564 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35565 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35566 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35567 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35568 return;
35569 }
35570
35571 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35572 break;
35573 }
35574
35575 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35576 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35577 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35578 | SM(i->txpower, AR_XmitPower)
35579 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35580 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35581 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35582 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35583
35584 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35585 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35586 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35587 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35588
35589 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35590 return;
35591
35592 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35593 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35594 | set11nPktDurRTSCTS(i->rates, 1);
35595
35596 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35597 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35598 | set11nPktDurRTSCTS(i->rates, 3);
35599
35600 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35601 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35602 | set11nRateFlags(i->rates, 1)
35603 | set11nRateFlags(i->rates, 2)
35604 | set11nRateFlags(i->rates, 3)
35605 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35606 index 78816b8..1fcdfae 100644
35607 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35608 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35609 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35610 (i->qcu << AR_TxQcuNum_S) | desc_len;
35611
35612 checksum += val;
35613 - ACCESS_ONCE(ads->info) = val;
35614 + ACCESS_ONCE_RW(ads->info) = val;
35615
35616 checksum += i->link;
35617 - ACCESS_ONCE(ads->link) = i->link;
35618 + ACCESS_ONCE_RW(ads->link) = i->link;
35619
35620 checksum += i->buf_addr[0];
35621 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35622 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35623 checksum += i->buf_addr[1];
35624 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35625 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35626 checksum += i->buf_addr[2];
35627 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35628 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35629 checksum += i->buf_addr[3];
35630 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35631 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35632
35633 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35634 - ACCESS_ONCE(ads->ctl3) = val;
35635 + ACCESS_ONCE_RW(ads->ctl3) = val;
35636 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35637 - ACCESS_ONCE(ads->ctl5) = val;
35638 + ACCESS_ONCE_RW(ads->ctl5) = val;
35639 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35640 - ACCESS_ONCE(ads->ctl7) = val;
35641 + ACCESS_ONCE_RW(ads->ctl7) = val;
35642 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35643 - ACCESS_ONCE(ads->ctl9) = val;
35644 + ACCESS_ONCE_RW(ads->ctl9) = val;
35645
35646 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35647 - ACCESS_ONCE(ads->ctl10) = checksum;
35648 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35649
35650 if (i->is_first || i->is_last) {
35651 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35652 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35653 | set11nTries(i->rates, 1)
35654 | set11nTries(i->rates, 2)
35655 | set11nTries(i->rates, 3)
35656 | (i->dur_update ? AR_DurUpdateEna : 0)
35657 | SM(0, AR_BurstDur);
35658
35659 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35660 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35661 | set11nRate(i->rates, 1)
35662 | set11nRate(i->rates, 2)
35663 | set11nRate(i->rates, 3);
35664 } else {
35665 - ACCESS_ONCE(ads->ctl13) = 0;
35666 - ACCESS_ONCE(ads->ctl14) = 0;
35667 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35668 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35669 }
35670
35671 ads->ctl20 = 0;
35672 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35673
35674 ctl17 = SM(i->keytype, AR_EncrType);
35675 if (!i->is_first) {
35676 - ACCESS_ONCE(ads->ctl11) = 0;
35677 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35678 - ACCESS_ONCE(ads->ctl15) = 0;
35679 - ACCESS_ONCE(ads->ctl16) = 0;
35680 - ACCESS_ONCE(ads->ctl17) = ctl17;
35681 - ACCESS_ONCE(ads->ctl18) = 0;
35682 - ACCESS_ONCE(ads->ctl19) = 0;
35683 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35684 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35685 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35686 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35687 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35688 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35689 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35690 return;
35691 }
35692
35693 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35694 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35695 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35696 | SM(i->txpower, AR_XmitPower)
35697 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35698 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35699 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35700 ctl12 |= SM(val, AR_PAPRDChainMask);
35701
35702 - ACCESS_ONCE(ads->ctl12) = ctl12;
35703 - ACCESS_ONCE(ads->ctl17) = ctl17;
35704 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35705 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35706
35707 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35708 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35709 | set11nPktDurRTSCTS(i->rates, 1);
35710
35711 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35712 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35713 | set11nPktDurRTSCTS(i->rates, 3);
35714
35715 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35716 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35717 | set11nRateFlags(i->rates, 1)
35718 | set11nRateFlags(i->rates, 2)
35719 | set11nRateFlags(i->rates, 3)
35720 | SM(i->rtscts_rate, AR_RTSCTSRate);
35721
35722 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35723 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35724 }
35725
35726 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35727 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35728 index de6968f..29ac4c1 100644
35729 --- a/drivers/net/wireless/ath/ath9k/hw.h
35730 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35731 @@ -656,7 +656,7 @@ struct ath_hw_private_ops {
35732
35733 /* ANI */
35734 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35735 -};
35736 +} __no_const;
35737
35738 /**
35739 * struct ath_hw_ops - callbacks used by hardware code and driver code
35740 @@ -686,7 +686,7 @@ struct ath_hw_ops {
35741 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35742 struct ath_hw_antcomb_conf *antconf);
35743
35744 -};
35745 +} __no_const;
35746
35747 struct ath_nf_limits {
35748 s16 max;
35749 @@ -706,7 +706,7 @@ enum ath_cal_list {
35750 #define AH_FASTCC 0x4
35751
35752 struct ath_hw {
35753 - struct ath_ops reg_ops;
35754 + ath_ops_no_const reg_ops;
35755
35756 struct ieee80211_hw *hw;
35757 struct ath_common common;
35758 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35759 index af00e2c..ab04d34 100644
35760 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35761 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35762 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35763 void (*carrsuppr)(struct brcms_phy *);
35764 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35765 void (*detach)(struct brcms_phy *);
35766 -};
35767 +} __no_const;
35768
35769 struct brcms_phy {
35770 struct brcms_phy_pub pubpi_ro;
35771 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35772 index faec404..a5277f1 100644
35773 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35774 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35775 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35776 */
35777 if (il3945_mod_params.disable_hw_scan) {
35778 D_INFO("Disabling hw_scan\n");
35779 - il3945_mac_ops.hw_scan = NULL;
35780 + pax_open_kernel();
35781 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35782 + pax_close_kernel();
35783 }
35784
35785 D_INFO("*** LOAD DRIVER ***\n");
35786 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35787 index a47b306..297daf2 100644
35788 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35789 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
35790 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35791 {
35792 struct iwl_priv *priv = file->private_data;
35793 char buf[64];
35794 - int buf_size;
35795 + size_t buf_size;
35796 u32 offset, len;
35797
35798 memset(buf, 0, sizeof(buf));
35799 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35800 struct iwl_priv *priv = file->private_data;
35801
35802 char buf[8];
35803 - int buf_size;
35804 + size_t buf_size;
35805 u32 reset_flag;
35806
35807 memset(buf, 0, sizeof(buf));
35808 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_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 ht40;
35815
35816 memset(buf, 0, sizeof(buf));
35817 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_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 value;
35824
35825 memset(buf, 0, sizeof(buf));
35826 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_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 clear;
35833
35834 memset(buf, 0, sizeof(buf));
35835 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_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 trace;
35842
35843 memset(buf, 0, sizeof(buf));
35844 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_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 missed;
35851
35852 memset(buf, 0, sizeof(buf));
35853 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_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 plcp;
35860
35861 memset(buf, 0, sizeof(buf));
35862 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_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 int flush;
35869
35870 memset(buf, 0, sizeof(buf));
35871 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35872
35873 struct iwl_priv *priv = file->private_data;
35874 char buf[8];
35875 - int buf_size;
35876 + size_t buf_size;
35877 int rts;
35878
35879 if (!priv->cfg->ht_params)
35880 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
35881 {
35882 struct iwl_priv *priv = file->private_data;
35883 char buf[8];
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 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
35890 struct iwl_priv *priv = file->private_data;
35891 u32 event_log_flag;
35892 char buf[8];
35893 - int buf_size;
35894 + size_t buf_size;
35895
35896 /* check that the interface is up */
35897 if (!iwl_is_ready(priv))
35898 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
35899 struct iwl_priv *priv = file->private_data;
35900 char buf[8];
35901 u32 calib_disabled;
35902 - int buf_size;
35903 + size_t buf_size;
35904
35905 memset(buf, 0, sizeof(buf));
35906 buf_size = min(count, sizeof(buf) - 1);
35907 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
35908 index dbeebef..b45a152 100644
35909 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
35910 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
35911 @@ -1944,7 +1944,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
35912 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
35913
35914 char buf[8];
35915 - int buf_size;
35916 + size_t buf_size;
35917 u32 reset_flag;
35918
35919 memset(buf, 0, sizeof(buf));
35920 @@ -1965,7 +1965,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
35921 {
35922 struct iwl_trans *trans = file->private_data;
35923 char buf[8];
35924 - int buf_size;
35925 + size_t buf_size;
35926 int csr;
35927
35928 memset(buf, 0, sizeof(buf));
35929 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
35930 index 0083839..fcb7225 100644
35931 --- a/drivers/net/wireless/mac80211_hwsim.c
35932 +++ b/drivers/net/wireless/mac80211_hwsim.c
35933 @@ -1748,9 +1748,11 @@ static int __init init_mac80211_hwsim(void)
35934 return -EINVAL;
35935
35936 if (fake_hw_scan) {
35937 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35938 - mac80211_hwsim_ops.sw_scan_start = NULL;
35939 - mac80211_hwsim_ops.sw_scan_complete = NULL;
35940 + pax_open_kernel();
35941 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
35942 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
35943 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
35944 + pax_close_kernel();
35945 }
35946
35947 spin_lock_init(&hwsim_radio_lock);
35948 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
35949 index e7c2a82..582e228 100644
35950 --- a/drivers/net/wireless/mwifiex/main.h
35951 +++ b/drivers/net/wireless/mwifiex/main.h
35952 @@ -571,7 +571,7 @@ struct mwifiex_if_ops {
35953 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
35954 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
35955 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
35956 -};
35957 +} __no_const;
35958
35959 struct mwifiex_adapter {
35960 u8 iface_type;
35961 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
35962 index 7a4ae9e..56e00bd 100644
35963 --- a/drivers/net/wireless/rndis_wlan.c
35964 +++ b/drivers/net/wireless/rndis_wlan.c
35965 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
35966
35967 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
35968
35969 - if (rts_threshold < 0 || rts_threshold > 2347)
35970 + if (rts_threshold > 2347)
35971 rts_threshold = 2347;
35972
35973 tmp = cpu_to_le32(rts_threshold);
35974 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
35975 index 8afb546..0c0dc5c 100644
35976 --- a/drivers/net/wireless/rt2x00/rt2x00.h
35977 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
35978 @@ -397,7 +397,7 @@ struct rt2x00_intf {
35979 * for hardware which doesn't support hardware
35980 * sequence counting.
35981 */
35982 - atomic_t seqno;
35983 + atomic_unchecked_t seqno;
35984 };
35985
35986 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
35987 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
35988 index f7e74a0..da71431 100644
35989 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
35990 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
35991 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
35992 * sequence counter given by mac80211.
35993 */
35994 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
35995 - seqno = atomic_add_return(0x10, &intf->seqno);
35996 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
35997 else
35998 - seqno = atomic_read(&intf->seqno);
35999 + seqno = atomic_read_unchecked(&intf->seqno);
36000
36001 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36002 hdr->seq_ctrl |= cpu_to_le16(seqno);
36003 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36004 index fd02060..74ee481 100644
36005 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36006 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36007 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36008 void (*reset)(struct wl1251 *wl);
36009 void (*enable_irq)(struct wl1251 *wl);
36010 void (*disable_irq)(struct wl1251 *wl);
36011 -};
36012 +} __no_const;
36013
36014 struct wl1251 {
36015 struct ieee80211_hw *hw;
36016 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36017 index 0ce7a8e..56a0ccf 100644
36018 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36019 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36020 @@ -81,7 +81,7 @@ struct wlcore_ops {
36021 struct ieee80211_sta *sta,
36022 struct ieee80211_key_conf *key_conf);
36023 u32 (*pre_pkt_send)(struct wl1271 *wl, u32 buf_offset, u32 last_len);
36024 -};
36025 +} __no_const;
36026
36027 enum wlcore_partitions {
36028 PART_DOWN,
36029 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36030 index f34b5b2..b5abb9f 100644
36031 --- a/drivers/oprofile/buffer_sync.c
36032 +++ b/drivers/oprofile/buffer_sync.c
36033 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36034 if (cookie == NO_COOKIE)
36035 offset = pc;
36036 if (cookie == INVALID_COOKIE) {
36037 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36038 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36039 offset = pc;
36040 }
36041 if (cookie != last_cookie) {
36042 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36043 /* add userspace sample */
36044
36045 if (!mm) {
36046 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36047 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36048 return 0;
36049 }
36050
36051 cookie = lookup_dcookie(mm, s->eip, &offset);
36052
36053 if (cookie == INVALID_COOKIE) {
36054 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36055 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36056 return 0;
36057 }
36058
36059 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36060 /* ignore backtraces if failed to add a sample */
36061 if (state == sb_bt_start) {
36062 state = sb_bt_ignore;
36063 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36064 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36065 }
36066 }
36067 release_mm(mm);
36068 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36069 index c0cc4e7..44d4e54 100644
36070 --- a/drivers/oprofile/event_buffer.c
36071 +++ b/drivers/oprofile/event_buffer.c
36072 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36073 }
36074
36075 if (buffer_pos == buffer_size) {
36076 - atomic_inc(&oprofile_stats.event_lost_overflow);
36077 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36078 return;
36079 }
36080
36081 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36082 index ed2c3ec..deda85a 100644
36083 --- a/drivers/oprofile/oprof.c
36084 +++ b/drivers/oprofile/oprof.c
36085 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36086 if (oprofile_ops.switch_events())
36087 return;
36088
36089 - atomic_inc(&oprofile_stats.multiplex_counter);
36090 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36091 start_switch_worker();
36092 }
36093
36094 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36095 index 917d28e..d62d981 100644
36096 --- a/drivers/oprofile/oprofile_stats.c
36097 +++ b/drivers/oprofile/oprofile_stats.c
36098 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36099 cpu_buf->sample_invalid_eip = 0;
36100 }
36101
36102 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36103 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36104 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36105 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36106 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36107 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36108 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36109 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36110 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36111 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36112 }
36113
36114
36115 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36116 index 38b6fc0..b5cbfce 100644
36117 --- a/drivers/oprofile/oprofile_stats.h
36118 +++ b/drivers/oprofile/oprofile_stats.h
36119 @@ -13,11 +13,11 @@
36120 #include <linux/atomic.h>
36121
36122 struct oprofile_stat_struct {
36123 - atomic_t sample_lost_no_mm;
36124 - atomic_t sample_lost_no_mapping;
36125 - atomic_t bt_lost_no_mapping;
36126 - atomic_t event_lost_overflow;
36127 - atomic_t multiplex_counter;
36128 + atomic_unchecked_t sample_lost_no_mm;
36129 + atomic_unchecked_t sample_lost_no_mapping;
36130 + atomic_unchecked_t bt_lost_no_mapping;
36131 + atomic_unchecked_t event_lost_overflow;
36132 + atomic_unchecked_t multiplex_counter;
36133 };
36134
36135 extern struct oprofile_stat_struct oprofile_stats;
36136 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36137 index 849357c..b83c1e0 100644
36138 --- a/drivers/oprofile/oprofilefs.c
36139 +++ b/drivers/oprofile/oprofilefs.c
36140 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36141
36142
36143 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36144 - char const *name, atomic_t *val)
36145 + char const *name, atomic_unchecked_t *val)
36146 {
36147 return __oprofilefs_create_file(sb, root, name,
36148 &atomic_ro_fops, 0444, val);
36149 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36150 index 3f56bc0..707d642 100644
36151 --- a/drivers/parport/procfs.c
36152 +++ b/drivers/parport/procfs.c
36153 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36154
36155 *ppos += len;
36156
36157 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36158 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36159 }
36160
36161 #ifdef CONFIG_PARPORT_1284
36162 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36163
36164 *ppos += len;
36165
36166 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36167 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36168 }
36169 #endif /* IEEE1284.3 support. */
36170
36171 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36172 index 9fff878..ad0ad53 100644
36173 --- a/drivers/pci/hotplug/cpci_hotplug.h
36174 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36175 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36176 int (*hardware_test) (struct slot* slot, u32 value);
36177 u8 (*get_power) (struct slot* slot);
36178 int (*set_power) (struct slot* slot, int value);
36179 -};
36180 +} __no_const;
36181
36182 struct cpci_hp_controller {
36183 unsigned int irq;
36184 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36185 index 76ba8a1..20ca857 100644
36186 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36187 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36188 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36189
36190 void compaq_nvram_init (void __iomem *rom_start)
36191 {
36192 +
36193 +#ifndef CONFIG_PAX_KERNEXEC
36194 if (rom_start) {
36195 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36196 }
36197 +#endif
36198 +
36199 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36200
36201 /* initialize our int15 lock */
36202 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36203 index b500840..d7159d3 100644
36204 --- a/drivers/pci/pcie/aspm.c
36205 +++ b/drivers/pci/pcie/aspm.c
36206 @@ -27,9 +27,9 @@
36207 #define MODULE_PARAM_PREFIX "pcie_aspm."
36208
36209 /* Note: those are not register definitions */
36210 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36211 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36212 -#define ASPM_STATE_L1 (4) /* L1 state */
36213 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36214 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36215 +#define ASPM_STATE_L1 (4U) /* L1 state */
36216 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36217 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36218
36219 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36220 index 61859d0..124539e 100644
36221 --- a/drivers/pci/probe.c
36222 +++ b/drivers/pci/probe.c
36223 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36224 struct pci_bus_region region;
36225 bool bar_too_big = false, bar_disabled = false;
36226
36227 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36228 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36229
36230 /* No printks while decoding is disabled! */
36231 if (!dev->mmio_always_on) {
36232 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36233 index 27911b5..5b6db88 100644
36234 --- a/drivers/pci/proc.c
36235 +++ b/drivers/pci/proc.c
36236 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36237 static int __init pci_proc_init(void)
36238 {
36239 struct pci_dev *dev = NULL;
36240 +
36241 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36242 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36243 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36244 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36245 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36246 +#endif
36247 +#else
36248 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36249 +#endif
36250 proc_create("devices", 0, proc_bus_pci_dir,
36251 &proc_bus_pci_dev_operations);
36252 proc_initialized = 1;
36253 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36254 index 52daaa8..d6b81eb 100644
36255 --- a/drivers/platform/x86/thinkpad_acpi.c
36256 +++ b/drivers/platform/x86/thinkpad_acpi.c
36257 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
36258 return 0;
36259 }
36260
36261 -void static hotkey_mask_warn_incomplete_mask(void)
36262 +static void hotkey_mask_warn_incomplete_mask(void)
36263 {
36264 /* log only what the user can fix... */
36265 const u32 wantedmask = hotkey_driver_mask &
36266 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36267 }
36268 }
36269
36270 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36271 - struct tp_nvram_state *newn,
36272 - const u32 event_mask)
36273 -{
36274 -
36275 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36276 do { \
36277 if ((event_mask & (1 << __scancode)) && \
36278 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36279 tpacpi_hotkey_send_key(__scancode); \
36280 } while (0)
36281
36282 - void issue_volchange(const unsigned int oldvol,
36283 - const unsigned int newvol)
36284 - {
36285 - unsigned int i = oldvol;
36286 +static void issue_volchange(const unsigned int oldvol,
36287 + const unsigned int newvol,
36288 + const u32 event_mask)
36289 +{
36290 + unsigned int i = oldvol;
36291
36292 - while (i > newvol) {
36293 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36294 - i--;
36295 - }
36296 - while (i < newvol) {
36297 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36298 - i++;
36299 - }
36300 + while (i > newvol) {
36301 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36302 + i--;
36303 }
36304 + while (i < newvol) {
36305 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36306 + i++;
36307 + }
36308 +}
36309
36310 - void issue_brightnesschange(const unsigned int oldbrt,
36311 - const unsigned int newbrt)
36312 - {
36313 - unsigned int i = oldbrt;
36314 +static void issue_brightnesschange(const unsigned int oldbrt,
36315 + const unsigned int newbrt,
36316 + const u32 event_mask)
36317 +{
36318 + unsigned int i = oldbrt;
36319
36320 - while (i > newbrt) {
36321 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36322 - i--;
36323 - }
36324 - while (i < newbrt) {
36325 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36326 - i++;
36327 - }
36328 + while (i > newbrt) {
36329 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36330 + i--;
36331 + }
36332 + while (i < newbrt) {
36333 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36334 + i++;
36335 }
36336 +}
36337
36338 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36339 + struct tp_nvram_state *newn,
36340 + const u32 event_mask)
36341 +{
36342 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36343 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36344 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36345 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36346 oldn->volume_level != newn->volume_level) {
36347 /* recently muted, or repeated mute keypress, or
36348 * multiple presses ending in mute */
36349 - issue_volchange(oldn->volume_level, newn->volume_level);
36350 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36351 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36352 }
36353 } else {
36354 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36355 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36356 }
36357 if (oldn->volume_level != newn->volume_level) {
36358 - issue_volchange(oldn->volume_level, newn->volume_level);
36359 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36360 } else if (oldn->volume_toggle != newn->volume_toggle) {
36361 /* repeated vol up/down keypress at end of scale ? */
36362 if (newn->volume_level == 0)
36363 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36364 /* handle brightness */
36365 if (oldn->brightness_level != newn->brightness_level) {
36366 issue_brightnesschange(oldn->brightness_level,
36367 - newn->brightness_level);
36368 + newn->brightness_level,
36369 + event_mask);
36370 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36371 /* repeated key presses that didn't change state */
36372 if (newn->brightness_level == 0)
36373 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36374 && !tp_features.bright_unkfw)
36375 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36376 }
36377 +}
36378
36379 #undef TPACPI_COMPARE_KEY
36380 #undef TPACPI_MAY_SEND_KEY
36381 -}
36382
36383 /*
36384 * Polling driver
36385 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36386 index 769d265..a3a05ca 100644
36387 --- a/drivers/pnp/pnpbios/bioscalls.c
36388 +++ b/drivers/pnp/pnpbios/bioscalls.c
36389 @@ -58,7 +58,7 @@ do { \
36390 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36391 } while(0)
36392
36393 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36394 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36395 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36396
36397 /*
36398 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36399
36400 cpu = get_cpu();
36401 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36402 +
36403 + pax_open_kernel();
36404 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36405 + pax_close_kernel();
36406
36407 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36408 spin_lock_irqsave(&pnp_bios_lock, flags);
36409 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36410 :"memory");
36411 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36412
36413 + pax_open_kernel();
36414 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36415 + pax_close_kernel();
36416 +
36417 put_cpu();
36418
36419 /* If we get here and this is set then the PnP BIOS faulted on us. */
36420 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36421 return status;
36422 }
36423
36424 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36425 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36426 {
36427 int i;
36428
36429 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36430 pnp_bios_callpoint.offset = header->fields.pm16offset;
36431 pnp_bios_callpoint.segment = PNP_CS16;
36432
36433 + pax_open_kernel();
36434 +
36435 for_each_possible_cpu(i) {
36436 struct desc_struct *gdt = get_cpu_gdt_table(i);
36437 if (!gdt)
36438 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36439 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36440 (unsigned long)__va(header->fields.pm16dseg));
36441 }
36442 +
36443 + pax_close_kernel();
36444 }
36445 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36446 index b0ecacb..7c9da2e 100644
36447 --- a/drivers/pnp/resource.c
36448 +++ b/drivers/pnp/resource.c
36449 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36450 return 1;
36451
36452 /* check if the resource is valid */
36453 - if (*irq < 0 || *irq > 15)
36454 + if (*irq > 15)
36455 return 0;
36456
36457 /* check if the resource is reserved */
36458 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36459 return 1;
36460
36461 /* check if the resource is valid */
36462 - if (*dma < 0 || *dma == 4 || *dma > 7)
36463 + if (*dma == 4 || *dma > 7)
36464 return 0;
36465
36466 /* check if the resource is reserved */
36467 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36468 index 181ddec..774b6da 100644
36469 --- a/drivers/power/bq27x00_battery.c
36470 +++ b/drivers/power/bq27x00_battery.c
36471 @@ -80,7 +80,7 @@
36472 struct bq27x00_device_info;
36473 struct bq27x00_access_methods {
36474 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36475 -};
36476 +} __no_const;
36477
36478 enum bq27x00_chip { BQ27000, BQ27500, BQ27425};
36479
36480 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36481 index 8d53174..04c65de 100644
36482 --- a/drivers/regulator/max8660.c
36483 +++ b/drivers/regulator/max8660.c
36484 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36485 max8660->shadow_regs[MAX8660_OVER1] = 5;
36486 } else {
36487 /* Otherwise devices can be toggled via software */
36488 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36489 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36490 + pax_open_kernel();
36491 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36492 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36493 + pax_close_kernel();
36494 }
36495
36496 /*
36497 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36498 index b388b74..ed82573 100644
36499 --- a/drivers/regulator/mc13892-regulator.c
36500 +++ b/drivers/regulator/mc13892-regulator.c
36501 @@ -565,10 +565,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36502 }
36503 mc13xxx_unlock(mc13892);
36504
36505 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36506 + pax_open_kernel();
36507 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36508 = mc13892_vcam_set_mode;
36509 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36510 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36511 = mc13892_vcam_get_mode;
36512 + pax_close_kernel();
36513
36514 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36515 ARRAY_SIZE(mc13892_regulators));
36516 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36517 index cace6d3..f623fda 100644
36518 --- a/drivers/rtc/rtc-dev.c
36519 +++ b/drivers/rtc/rtc-dev.c
36520 @@ -14,6 +14,7 @@
36521 #include <linux/module.h>
36522 #include <linux/rtc.h>
36523 #include <linux/sched.h>
36524 +#include <linux/grsecurity.h>
36525 #include "rtc-core.h"
36526
36527 static dev_t rtc_devt;
36528 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36529 if (copy_from_user(&tm, uarg, sizeof(tm)))
36530 return -EFAULT;
36531
36532 + gr_log_timechange();
36533 +
36534 return rtc_set_time(rtc, &tm);
36535
36536 case RTC_PIE_ON:
36537 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36538 index 9e933a8..4f969f7 100644
36539 --- a/drivers/scsi/aacraid/aacraid.h
36540 +++ b/drivers/scsi/aacraid/aacraid.h
36541 @@ -503,7 +503,7 @@ struct adapter_ops
36542 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36543 /* Administrative operations */
36544 int (*adapter_comm)(struct aac_dev * dev, int comm);
36545 -};
36546 +} __no_const;
36547
36548 /*
36549 * Define which interrupt handler needs to be installed
36550 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36551 index 7199534..cb7f158 100644
36552 --- a/drivers/scsi/aacraid/linit.c
36553 +++ b/drivers/scsi/aacraid/linit.c
36554 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36555 #elif defined(__devinitconst)
36556 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36557 #else
36558 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36559 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36560 #endif
36561 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36562 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36563 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36564 index ff80552..1c4120c 100644
36565 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36566 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36567 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36568 .lldd_ata_set_dmamode = asd_set_dmamode,
36569 };
36570
36571 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36572 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36573 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36574 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36575 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36576 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36577 index 4ad7e36..d004679 100644
36578 --- a/drivers/scsi/bfa/bfa.h
36579 +++ b/drivers/scsi/bfa/bfa.h
36580 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36581 u32 *end);
36582 int cpe_vec_q0;
36583 int rme_vec_q0;
36584 -};
36585 +} __no_const;
36586 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36587
36588 struct bfa_faa_cbfn_s {
36589 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36590 index f0f80e2..8ec946b 100644
36591 --- a/drivers/scsi/bfa/bfa_fcpim.c
36592 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36593 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36594
36595 bfa_iotag_attach(fcp);
36596
36597 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36598 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36599 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36600 (fcp->num_itns * sizeof(struct bfa_itn_s));
36601 memset(fcp->itn_arr, 0,
36602 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36603 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36604 {
36605 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36606 - struct bfa_itn_s *itn;
36607 + bfa_itn_s_no_const *itn;
36608
36609 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36610 itn->isr = isr;
36611 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36612 index 36f26da..38a34a8 100644
36613 --- a/drivers/scsi/bfa/bfa_fcpim.h
36614 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36615 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36616 struct bfa_itn_s {
36617 bfa_isr_func_t isr;
36618 };
36619 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36620
36621 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36622 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36623 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36624 struct list_head iotag_tio_free_q; /* free IO resources */
36625 struct list_head iotag_unused_q; /* unused IO resources*/
36626 struct bfa_iotag_s *iotag_arr;
36627 - struct bfa_itn_s *itn_arr;
36628 + bfa_itn_s_no_const *itn_arr;
36629 int num_ioim_reqs;
36630 int num_fwtio_reqs;
36631 int num_itns;
36632 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36633 index 1a99d4b..e85d64b 100644
36634 --- a/drivers/scsi/bfa/bfa_ioc.h
36635 +++ b/drivers/scsi/bfa/bfa_ioc.h
36636 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36637 bfa_ioc_disable_cbfn_t disable_cbfn;
36638 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36639 bfa_ioc_reset_cbfn_t reset_cbfn;
36640 -};
36641 +} __no_const;
36642
36643 /*
36644 * IOC event notification mechanism.
36645 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36646 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36647 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36648 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36649 -};
36650 +} __no_const;
36651
36652 /*
36653 * Queue element to wait for room in request queue. FIFO order is
36654 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36655 index 593085a..47aa999 100644
36656 --- a/drivers/scsi/hosts.c
36657 +++ b/drivers/scsi/hosts.c
36658 @@ -42,7 +42,7 @@
36659 #include "scsi_logging.h"
36660
36661
36662 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36663 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
36664
36665
36666 static void scsi_host_cls_release(struct device *dev)
36667 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36668 * subtract one because we increment first then return, but we need to
36669 * know what the next host number was before increment
36670 */
36671 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36672 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36673 shost->dma_channel = 0xff;
36674
36675 /* These three are default values which can be overridden */
36676 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36677 index f9823f2..7bc3e81 100644
36678 --- a/drivers/scsi/hpsa.c
36679 +++ b/drivers/scsi/hpsa.c
36680 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36681 unsigned long flags;
36682
36683 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36684 - return h->access.command_completed(h, q);
36685 + return h->access->command_completed(h, q);
36686
36687 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36688 a = rq->head[rq->current_entry];
36689 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36690 while (!list_empty(&h->reqQ)) {
36691 c = list_entry(h->reqQ.next, struct CommandList, list);
36692 /* can't do anything if fifo is full */
36693 - if ((h->access.fifo_full(h))) {
36694 + if ((h->access->fifo_full(h))) {
36695 dev_warn(&h->pdev->dev, "fifo full\n");
36696 break;
36697 }
36698 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36699
36700 /* Tell the controller execute command */
36701 spin_unlock_irqrestore(&h->lock, flags);
36702 - h->access.submit_command(h, c);
36703 + h->access->submit_command(h, c);
36704 spin_lock_irqsave(&h->lock, flags);
36705 }
36706 spin_unlock_irqrestore(&h->lock, flags);
36707 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36708
36709 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36710 {
36711 - return h->access.command_completed(h, q);
36712 + return h->access->command_completed(h, q);
36713 }
36714
36715 static inline bool interrupt_pending(struct ctlr_info *h)
36716 {
36717 - return h->access.intr_pending(h);
36718 + return h->access->intr_pending(h);
36719 }
36720
36721 static inline long interrupt_not_for_us(struct ctlr_info *h)
36722 {
36723 - return (h->access.intr_pending(h) == 0) ||
36724 + return (h->access->intr_pending(h) == 0) ||
36725 (h->interrupts_enabled == 0);
36726 }
36727
36728 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36729 if (prod_index < 0)
36730 return -ENODEV;
36731 h->product_name = products[prod_index].product_name;
36732 - h->access = *(products[prod_index].access);
36733 + h->access = products[prod_index].access;
36734
36735 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36736 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36737 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36738
36739 assert_spin_locked(&lockup_detector_lock);
36740 remove_ctlr_from_lockup_detector_list(h);
36741 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36742 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36743 spin_lock_irqsave(&h->lock, flags);
36744 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36745 spin_unlock_irqrestore(&h->lock, flags);
36746 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36747 }
36748
36749 /* make sure the board interrupts are off */
36750 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36751 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36752
36753 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36754 goto clean2;
36755 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36756 * fake ones to scoop up any residual completions.
36757 */
36758 spin_lock_irqsave(&h->lock, flags);
36759 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36760 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36761 spin_unlock_irqrestore(&h->lock, flags);
36762 free_irqs(h);
36763 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36764 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36765 dev_info(&h->pdev->dev, "Board READY.\n");
36766 dev_info(&h->pdev->dev,
36767 "Waiting for stale completions to drain.\n");
36768 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36769 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36770 msleep(10000);
36771 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36772 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36773
36774 rc = controller_reset_failed(h->cfgtable);
36775 if (rc)
36776 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36777 }
36778
36779 /* Turn the interrupts on so we can service requests */
36780 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36781 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36782
36783 hpsa_hba_inquiry(h);
36784 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36785 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36786 * To write all data in the battery backed cache to disks
36787 */
36788 hpsa_flush_cache(h);
36789 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36790 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36791 hpsa_free_irqs_and_disable_msix(h);
36792 }
36793
36794 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36795 return;
36796 }
36797 /* Change the access methods to the performant access methods */
36798 - h->access = SA5_performant_access;
36799 + h->access = &SA5_performant_access;
36800 h->transMethod = CFGTBL_Trans_Performant;
36801 }
36802
36803 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36804 index 9816479..c5d4e97 100644
36805 --- a/drivers/scsi/hpsa.h
36806 +++ b/drivers/scsi/hpsa.h
36807 @@ -79,7 +79,7 @@ struct ctlr_info {
36808 unsigned int msix_vector;
36809 unsigned int msi_vector;
36810 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36811 - struct access_method access;
36812 + struct access_method *access;
36813
36814 /* queue and queue Info */
36815 struct list_head reqQ;
36816 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36817 index f2df059..a3a9930 100644
36818 --- a/drivers/scsi/ips.h
36819 +++ b/drivers/scsi/ips.h
36820 @@ -1027,7 +1027,7 @@ typedef struct {
36821 int (*intr)(struct ips_ha *);
36822 void (*enableint)(struct ips_ha *);
36823 uint32_t (*statupd)(struct ips_ha *);
36824 -} ips_hw_func_t;
36825 +} __no_const ips_hw_func_t;
36826
36827 typedef struct ips_ha {
36828 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36829 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36830 index c772d8d..35c362c 100644
36831 --- a/drivers/scsi/libfc/fc_exch.c
36832 +++ b/drivers/scsi/libfc/fc_exch.c
36833 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
36834 u16 pool_max_index;
36835
36836 struct {
36837 - atomic_t no_free_exch;
36838 - atomic_t no_free_exch_xid;
36839 - atomic_t xid_not_found;
36840 - atomic_t xid_busy;
36841 - atomic_t seq_not_found;
36842 - atomic_t non_bls_resp;
36843 + atomic_unchecked_t no_free_exch;
36844 + atomic_unchecked_t no_free_exch_xid;
36845 + atomic_unchecked_t xid_not_found;
36846 + atomic_unchecked_t xid_busy;
36847 + atomic_unchecked_t seq_not_found;
36848 + atomic_unchecked_t non_bls_resp;
36849 } stats;
36850 };
36851
36852 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36853 /* allocate memory for exchange */
36854 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36855 if (!ep) {
36856 - atomic_inc(&mp->stats.no_free_exch);
36857 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36858 goto out;
36859 }
36860 memset(ep, 0, sizeof(*ep));
36861 @@ -786,7 +786,7 @@ out:
36862 return ep;
36863 err:
36864 spin_unlock_bh(&pool->lock);
36865 - atomic_inc(&mp->stats.no_free_exch_xid);
36866 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36867 mempool_free(ep, mp->ep_pool);
36868 return NULL;
36869 }
36870 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36871 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36872 ep = fc_exch_find(mp, xid);
36873 if (!ep) {
36874 - atomic_inc(&mp->stats.xid_not_found);
36875 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36876 reject = FC_RJT_OX_ID;
36877 goto out;
36878 }
36879 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36880 ep = fc_exch_find(mp, xid);
36881 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
36882 if (ep) {
36883 - atomic_inc(&mp->stats.xid_busy);
36884 + atomic_inc_unchecked(&mp->stats.xid_busy);
36885 reject = FC_RJT_RX_ID;
36886 goto rel;
36887 }
36888 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36889 }
36890 xid = ep->xid; /* get our XID */
36891 } else if (!ep) {
36892 - atomic_inc(&mp->stats.xid_not_found);
36893 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36894 reject = FC_RJT_RX_ID; /* XID not found */
36895 goto out;
36896 }
36897 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36898 } else {
36899 sp = &ep->seq;
36900 if (sp->id != fh->fh_seq_id) {
36901 - atomic_inc(&mp->stats.seq_not_found);
36902 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36903 if (f_ctl & FC_FC_END_SEQ) {
36904 /*
36905 * Update sequence_id based on incoming last
36906 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36907
36908 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
36909 if (!ep) {
36910 - atomic_inc(&mp->stats.xid_not_found);
36911 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36912 goto out;
36913 }
36914 if (ep->esb_stat & ESB_ST_COMPLETE) {
36915 - atomic_inc(&mp->stats.xid_not_found);
36916 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36917 goto rel;
36918 }
36919 if (ep->rxid == FC_XID_UNKNOWN)
36920 ep->rxid = ntohs(fh->fh_rx_id);
36921 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
36922 - atomic_inc(&mp->stats.xid_not_found);
36923 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36924 goto rel;
36925 }
36926 if (ep->did != ntoh24(fh->fh_s_id) &&
36927 ep->did != FC_FID_FLOGI) {
36928 - atomic_inc(&mp->stats.xid_not_found);
36929 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36930 goto rel;
36931 }
36932 sof = fr_sof(fp);
36933 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36934 sp->ssb_stat |= SSB_ST_RESP;
36935 sp->id = fh->fh_seq_id;
36936 } else if (sp->id != fh->fh_seq_id) {
36937 - atomic_inc(&mp->stats.seq_not_found);
36938 + atomic_inc_unchecked(&mp->stats.seq_not_found);
36939 goto rel;
36940 }
36941
36942 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
36943 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
36944
36945 if (!sp)
36946 - atomic_inc(&mp->stats.xid_not_found);
36947 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36948 else
36949 - atomic_inc(&mp->stats.non_bls_resp);
36950 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
36951
36952 fc_frame_free(fp);
36953 }
36954 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
36955
36956 list_for_each_entry(ema, &lport->ema_list, ema_list) {
36957 mp = ema->mp;
36958 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
36959 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
36960 st->fc_no_free_exch_xid +=
36961 - atomic_read(&mp->stats.no_free_exch_xid);
36962 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
36963 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
36964 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
36965 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
36966 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
36967 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
36968 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
36969 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
36970 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
36971 }
36972 }
36973 EXPORT_SYMBOL(fc_exch_update_stats);
36974 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
36975 index a59fcdc..abe55f3 100644
36976 --- a/drivers/scsi/libsas/sas_ata.c
36977 +++ b/drivers/scsi/libsas/sas_ata.c
36978 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
36979 .postreset = ata_std_postreset,
36980 .error_handler = ata_std_error_handler,
36981 .post_internal_cmd = sas_ata_post_internal,
36982 - .qc_defer = ata_std_qc_defer,
36983 + .qc_defer = ata_std_qc_defer,
36984 .qc_prep = ata_noop_qc_prep,
36985 .qc_issue = sas_ata_qc_issue,
36986 .qc_fill_rtf = sas_ata_qc_fill_rtf,
36987 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
36988 index a65c05a..a39e402 100644
36989 --- a/drivers/scsi/lpfc/lpfc.h
36990 +++ b/drivers/scsi/lpfc/lpfc.h
36991 @@ -420,7 +420,7 @@ struct lpfc_vport {
36992 struct dentry *debug_nodelist;
36993 struct dentry *vport_debugfs_root;
36994 struct lpfc_debugfs_trc *disc_trc;
36995 - atomic_t disc_trc_cnt;
36996 + atomic_unchecked_t disc_trc_cnt;
36997 #endif
36998 uint8_t stat_data_enabled;
36999 uint8_t stat_data_blocked;
37000 @@ -834,8 +834,8 @@ struct lpfc_hba {
37001 struct timer_list fabric_block_timer;
37002 unsigned long bit_flags;
37003 #define FABRIC_COMANDS_BLOCKED 0
37004 - atomic_t num_rsrc_err;
37005 - atomic_t num_cmd_success;
37006 + atomic_unchecked_t num_rsrc_err;
37007 + atomic_unchecked_t num_cmd_success;
37008 unsigned long last_rsrc_error_time;
37009 unsigned long last_ramp_down_time;
37010 unsigned long last_ramp_up_time;
37011 @@ -871,7 +871,7 @@ struct lpfc_hba {
37012
37013 struct dentry *debug_slow_ring_trc;
37014 struct lpfc_debugfs_trc *slow_ring_trc;
37015 - atomic_t slow_ring_trc_cnt;
37016 + atomic_unchecked_t slow_ring_trc_cnt;
37017 /* iDiag debugfs sub-directory */
37018 struct dentry *idiag_root;
37019 struct dentry *idiag_pci_cfg;
37020 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37021 index 3217d63..c417981 100644
37022 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37023 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37024 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37025
37026 #include <linux/debugfs.h>
37027
37028 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37029 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37030 static unsigned long lpfc_debugfs_start_time = 0L;
37031
37032 /* iDiag */
37033 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37034 lpfc_debugfs_enable = 0;
37035
37036 len = 0;
37037 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37038 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37039 (lpfc_debugfs_max_disc_trc - 1);
37040 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37041 dtp = vport->disc_trc + i;
37042 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37043 lpfc_debugfs_enable = 0;
37044
37045 len = 0;
37046 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37047 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37048 (lpfc_debugfs_max_slow_ring_trc - 1);
37049 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37050 dtp = phba->slow_ring_trc + i;
37051 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37052 !vport || !vport->disc_trc)
37053 return;
37054
37055 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37056 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37057 (lpfc_debugfs_max_disc_trc - 1);
37058 dtp = vport->disc_trc + index;
37059 dtp->fmt = fmt;
37060 dtp->data1 = data1;
37061 dtp->data2 = data2;
37062 dtp->data3 = data3;
37063 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37064 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37065 dtp->jif = jiffies;
37066 #endif
37067 return;
37068 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37069 !phba || !phba->slow_ring_trc)
37070 return;
37071
37072 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37073 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37074 (lpfc_debugfs_max_slow_ring_trc - 1);
37075 dtp = phba->slow_ring_trc + index;
37076 dtp->fmt = fmt;
37077 dtp->data1 = data1;
37078 dtp->data2 = data2;
37079 dtp->data3 = data3;
37080 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37081 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37082 dtp->jif = jiffies;
37083 #endif
37084 return;
37085 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37086 "slow_ring buffer\n");
37087 goto debug_failed;
37088 }
37089 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37090 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37091 memset(phba->slow_ring_trc, 0,
37092 (sizeof(struct lpfc_debugfs_trc) *
37093 lpfc_debugfs_max_slow_ring_trc));
37094 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37095 "buffer\n");
37096 goto debug_failed;
37097 }
37098 - atomic_set(&vport->disc_trc_cnt, 0);
37099 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37100
37101 snprintf(name, sizeof(name), "discovery_trace");
37102 vport->debug_disc_trc =
37103 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37104 index 45c1520..35ba744 100644
37105 --- a/drivers/scsi/lpfc/lpfc_init.c
37106 +++ b/drivers/scsi/lpfc/lpfc_init.c
37107 @@ -10478,8 +10478,10 @@ lpfc_init(void)
37108 "misc_register returned with status %d", error);
37109
37110 if (lpfc_enable_npiv) {
37111 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37112 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37113 + pax_open_kernel();
37114 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37115 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37116 + pax_close_kernel();
37117 }
37118 lpfc_transport_template =
37119 fc_attach_transport(&lpfc_transport_functions);
37120 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37121 index 925975d..0f1fc07 100644
37122 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37123 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37124 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37125 uint32_t evt_posted;
37126
37127 spin_lock_irqsave(&phba->hbalock, flags);
37128 - atomic_inc(&phba->num_rsrc_err);
37129 + atomic_inc_unchecked(&phba->num_rsrc_err);
37130 phba->last_rsrc_error_time = jiffies;
37131
37132 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37133 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37134 unsigned long flags;
37135 struct lpfc_hba *phba = vport->phba;
37136 uint32_t evt_posted;
37137 - atomic_inc(&phba->num_cmd_success);
37138 + atomic_inc_unchecked(&phba->num_cmd_success);
37139
37140 if (vport->cfg_lun_queue_depth <= queue_depth)
37141 return;
37142 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37143 unsigned long num_rsrc_err, num_cmd_success;
37144 int i;
37145
37146 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37147 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37148 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37149 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37150
37151 /*
37152 * The error and success command counters are global per
37153 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37154 }
37155 }
37156 lpfc_destroy_vport_work_array(phba, vports);
37157 - atomic_set(&phba->num_rsrc_err, 0);
37158 - atomic_set(&phba->num_cmd_success, 0);
37159 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37160 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37161 }
37162
37163 /**
37164 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37165 }
37166 }
37167 lpfc_destroy_vport_work_array(phba, vports);
37168 - atomic_set(&phba->num_rsrc_err, 0);
37169 - atomic_set(&phba->num_cmd_success, 0);
37170 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37171 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37172 }
37173
37174 /**
37175 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37176 index ea8a0b4..812a124 100644
37177 --- a/drivers/scsi/pmcraid.c
37178 +++ b/drivers/scsi/pmcraid.c
37179 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37180 res->scsi_dev = scsi_dev;
37181 scsi_dev->hostdata = res;
37182 res->change_detected = 0;
37183 - atomic_set(&res->read_failures, 0);
37184 - atomic_set(&res->write_failures, 0);
37185 + atomic_set_unchecked(&res->read_failures, 0);
37186 + atomic_set_unchecked(&res->write_failures, 0);
37187 rc = 0;
37188 }
37189 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37190 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37191
37192 /* If this was a SCSI read/write command keep count of errors */
37193 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37194 - atomic_inc(&res->read_failures);
37195 + atomic_inc_unchecked(&res->read_failures);
37196 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37197 - atomic_inc(&res->write_failures);
37198 + atomic_inc_unchecked(&res->write_failures);
37199
37200 if (!RES_IS_GSCSI(res->cfg_entry) &&
37201 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37202 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37203 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37204 * hrrq_id assigned here in queuecommand
37205 */
37206 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37207 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37208 pinstance->num_hrrq;
37209 cmd->cmd_done = pmcraid_io_done;
37210
37211 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37212 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37213 * hrrq_id assigned here in queuecommand
37214 */
37215 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37216 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37217 pinstance->num_hrrq;
37218
37219 if (request_size) {
37220 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37221
37222 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37223 /* add resources only after host is added into system */
37224 - if (!atomic_read(&pinstance->expose_resources))
37225 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37226 return;
37227
37228 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37229 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37230 init_waitqueue_head(&pinstance->reset_wait_q);
37231
37232 atomic_set(&pinstance->outstanding_cmds, 0);
37233 - atomic_set(&pinstance->last_message_id, 0);
37234 - atomic_set(&pinstance->expose_resources, 0);
37235 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37236 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37237
37238 INIT_LIST_HEAD(&pinstance->free_res_q);
37239 INIT_LIST_HEAD(&pinstance->used_res_q);
37240 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37241 /* Schedule worker thread to handle CCN and take care of adding and
37242 * removing devices to OS
37243 */
37244 - atomic_set(&pinstance->expose_resources, 1);
37245 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37246 schedule_work(&pinstance->worker_q);
37247 return rc;
37248
37249 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37250 index e1d150f..6c6df44 100644
37251 --- a/drivers/scsi/pmcraid.h
37252 +++ b/drivers/scsi/pmcraid.h
37253 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37254 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37255
37256 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37257 - atomic_t last_message_id;
37258 + atomic_unchecked_t last_message_id;
37259
37260 /* configuration table */
37261 struct pmcraid_config_table *cfg_table;
37262 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37263 atomic_t outstanding_cmds;
37264
37265 /* should add/delete resources to mid-layer now ?*/
37266 - atomic_t expose_resources;
37267 + atomic_unchecked_t expose_resources;
37268
37269
37270
37271 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37272 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37273 };
37274 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37275 - atomic_t read_failures; /* count of failed READ commands */
37276 - atomic_t write_failures; /* count of failed WRITE commands */
37277 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37278 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37279
37280 /* To indicate add/delete/modify during CCN */
37281 u8 change_detected;
37282 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37283 index 5ab9530..2dd80f7 100644
37284 --- a/drivers/scsi/qla2xxx/qla_attr.c
37285 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37286 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37287 return 0;
37288 }
37289
37290 -struct fc_function_template qla2xxx_transport_functions = {
37291 +fc_function_template_no_const qla2xxx_transport_functions = {
37292
37293 .show_host_node_name = 1,
37294 .show_host_port_name = 1,
37295 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37296 .bsg_timeout = qla24xx_bsg_timeout,
37297 };
37298
37299 -struct fc_function_template qla2xxx_transport_vport_functions = {
37300 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37301
37302 .show_host_node_name = 1,
37303 .show_host_port_name = 1,
37304 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37305 index 39007f5..7fafc64 100644
37306 --- a/drivers/scsi/qla2xxx/qla_def.h
37307 +++ b/drivers/scsi/qla2xxx/qla_def.h
37308 @@ -2284,7 +2284,7 @@ struct isp_operations {
37309 int (*start_scsi) (srb_t *);
37310 int (*abort_isp) (struct scsi_qla_host *);
37311 int (*iospace_config)(struct qla_hw_data*);
37312 -};
37313 +} __no_const;
37314
37315 /* MSI-X Support *************************************************************/
37316
37317 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37318 index 9eacd2d..d79629c 100644
37319 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37320 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37321 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37322 struct device_attribute;
37323 extern struct device_attribute *qla2x00_host_attrs[];
37324 struct fc_function_template;
37325 -extern struct fc_function_template qla2xxx_transport_functions;
37326 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37327 +extern fc_function_template_no_const qla2xxx_transport_functions;
37328 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37329 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37330 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37331 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37332 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37333 index 7fdba7f..1b4b2c2 100644
37334 --- a/drivers/scsi/qla4xxx/ql4_def.h
37335 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37336 @@ -268,7 +268,7 @@ struct ddb_entry {
37337 * (4000 only) */
37338 atomic_t relogin_timer; /* Max Time to wait for
37339 * relogin to complete */
37340 - atomic_t relogin_retry_count; /* Num of times relogin has been
37341 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37342 * retried */
37343 uint32_t default_time2wait; /* Default Min time between
37344 * relogins (+aens) */
37345 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37346 index 9da4266..377b3b6 100644
37347 --- a/drivers/scsi/qla4xxx/ql4_os.c
37348 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37349 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37350 */
37351 if (!iscsi_is_session_online(cls_sess)) {
37352 /* Reset retry relogin timer */
37353 - atomic_inc(&ddb_entry->relogin_retry_count);
37354 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37355 DEBUG2(ql4_printk(KERN_INFO, ha,
37356 "%s: index[%d] relogin timed out-retrying"
37357 " relogin (%d), retry (%d)\n", __func__,
37358 ddb_entry->fw_ddb_index,
37359 - atomic_read(&ddb_entry->relogin_retry_count),
37360 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37361 ddb_entry->default_time2wait + 4));
37362 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37363 atomic_set(&ddb_entry->retry_relogin_timer,
37364 @@ -4635,7 +4635,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37365
37366 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37367 atomic_set(&ddb_entry->relogin_timer, 0);
37368 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37369 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37370 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37371 ddb_entry->default_relogin_timeout =
37372 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37373 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37374 index 2936b44..546ecdb 100644
37375 --- a/drivers/scsi/scsi.c
37376 +++ b/drivers/scsi/scsi.c
37377 @@ -660,7 +660,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37378 unsigned long timeout;
37379 int rtn = 0;
37380
37381 - atomic_inc(&cmd->device->iorequest_cnt);
37382 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37383
37384 /* check if the device is still usable */
37385 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37386 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37387 index faa790f..7e351ddd 100644
37388 --- a/drivers/scsi/scsi_lib.c
37389 +++ b/drivers/scsi/scsi_lib.c
37390 @@ -1442,7 +1442,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37391 shost = sdev->host;
37392 scsi_init_cmd_errh(cmd);
37393 cmd->result = DID_NO_CONNECT << 16;
37394 - atomic_inc(&cmd->device->iorequest_cnt);
37395 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37396
37397 /*
37398 * SCSI request completion path will do scsi_device_unbusy(),
37399 @@ -1468,9 +1468,9 @@ static void scsi_softirq_done(struct request *rq)
37400
37401 INIT_LIST_HEAD(&cmd->eh_entry);
37402
37403 - atomic_inc(&cmd->device->iodone_cnt);
37404 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37405 if (cmd->result)
37406 - atomic_inc(&cmd->device->ioerr_cnt);
37407 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37408
37409 disposition = scsi_decide_disposition(cmd);
37410 if (disposition != SUCCESS &&
37411 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37412 index ce5224c..8c6d071 100644
37413 --- a/drivers/scsi/scsi_sysfs.c
37414 +++ b/drivers/scsi/scsi_sysfs.c
37415 @@ -661,7 +661,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37416 char *buf) \
37417 { \
37418 struct scsi_device *sdev = to_scsi_device(dev); \
37419 - unsigned long long count = atomic_read(&sdev->field); \
37420 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37421 return snprintf(buf, 20, "0x%llx\n", count); \
37422 } \
37423 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37424 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37425 index 84a1fdf..693b0d6 100644
37426 --- a/drivers/scsi/scsi_tgt_lib.c
37427 +++ b/drivers/scsi/scsi_tgt_lib.c
37428 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37429 int err;
37430
37431 dprintk("%lx %u\n", uaddr, len);
37432 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37433 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37434 if (err) {
37435 /*
37436 * TODO: need to fixup sg_tablesize, max_segment_size,
37437 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37438 index e894ca7..de9d7660 100644
37439 --- a/drivers/scsi/scsi_transport_fc.c
37440 +++ b/drivers/scsi/scsi_transport_fc.c
37441 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37442 * Netlink Infrastructure
37443 */
37444
37445 -static atomic_t fc_event_seq;
37446 +static atomic_unchecked_t fc_event_seq;
37447
37448 /**
37449 * fc_get_event_number - Obtain the next sequential FC event number
37450 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37451 u32
37452 fc_get_event_number(void)
37453 {
37454 - return atomic_add_return(1, &fc_event_seq);
37455 + return atomic_add_return_unchecked(1, &fc_event_seq);
37456 }
37457 EXPORT_SYMBOL(fc_get_event_number);
37458
37459 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37460 {
37461 int error;
37462
37463 - atomic_set(&fc_event_seq, 0);
37464 + atomic_set_unchecked(&fc_event_seq, 0);
37465
37466 error = transport_class_register(&fc_host_class);
37467 if (error)
37468 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37469 char *cp;
37470
37471 *val = simple_strtoul(buf, &cp, 0);
37472 - if ((*cp && (*cp != '\n')) || (*val < 0))
37473 + if (*cp && (*cp != '\n'))
37474 return -EINVAL;
37475 /*
37476 * Check for overflow; dev_loss_tmo is u32
37477 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37478 index fa1dfaa..4bb620c 100644
37479 --- a/drivers/scsi/scsi_transport_iscsi.c
37480 +++ b/drivers/scsi/scsi_transport_iscsi.c
37481 @@ -79,7 +79,7 @@ struct iscsi_internal {
37482 struct transport_container session_cont;
37483 };
37484
37485 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37486 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37487 static struct workqueue_struct *iscsi_eh_timer_workq;
37488
37489 static DEFINE_IDA(iscsi_sess_ida);
37490 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37491 int err;
37492
37493 ihost = shost->shost_data;
37494 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37495 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37496
37497 if (target_id == ISCSI_MAX_TARGET) {
37498 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37499 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
37500 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37501 ISCSI_TRANSPORT_VERSION);
37502
37503 - atomic_set(&iscsi_session_nr, 0);
37504 + atomic_set_unchecked(&iscsi_session_nr, 0);
37505
37506 err = class_register(&iscsi_transport_class);
37507 if (err)
37508 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37509 index 21a045e..ec89e03 100644
37510 --- a/drivers/scsi/scsi_transport_srp.c
37511 +++ b/drivers/scsi/scsi_transport_srp.c
37512 @@ -33,7 +33,7 @@
37513 #include "scsi_transport_srp_internal.h"
37514
37515 struct srp_host_attrs {
37516 - atomic_t next_port_id;
37517 + atomic_unchecked_t next_port_id;
37518 };
37519 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37520
37521 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37522 struct Scsi_Host *shost = dev_to_shost(dev);
37523 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37524
37525 - atomic_set(&srp_host->next_port_id, 0);
37526 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37527 return 0;
37528 }
37529
37530 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37531 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37532 rport->roles = ids->roles;
37533
37534 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37535 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37536 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37537
37538 transport_setup_device(&rport->dev);
37539 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
37540 index 4df73e5..b691c58 100644
37541 --- a/drivers/scsi/sd.c
37542 +++ b/drivers/scsi/sd.c
37543 @@ -2709,7 +2709,7 @@ static int sd_probe(struct device *dev)
37544 sdkp->disk = gd;
37545 sdkp->index = index;
37546 atomic_set(&sdkp->openers, 0);
37547 - atomic_set(&sdkp->device->ioerr_cnt, 0);
37548 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
37549
37550 if (!sdp->request_queue->rq_timeout) {
37551 if (sdp->type != TYPE_MOD)
37552 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37553 index 9c5c5f2..8414557 100644
37554 --- a/drivers/scsi/sg.c
37555 +++ b/drivers/scsi/sg.c
37556 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37557 sdp->disk->disk_name,
37558 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37559 NULL,
37560 - (char *)arg);
37561 + (char __user *)arg);
37562 case BLKTRACESTART:
37563 return blk_trace_startstop(sdp->device->request_queue, 1);
37564 case BLKTRACESTOP:
37565 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37566 index 84c2861..ece0a31 100644
37567 --- a/drivers/spi/spi.c
37568 +++ b/drivers/spi/spi.c
37569 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37570 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37571
37572 /* portable code must never pass more than 32 bytes */
37573 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37574 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37575
37576 static u8 *buf;
37577
37578 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37579 index 34afc16..ffe44dd 100644
37580 --- a/drivers/staging/octeon/ethernet-rx.c
37581 +++ b/drivers/staging/octeon/ethernet-rx.c
37582 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37583 /* Increment RX stats for virtual ports */
37584 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37585 #ifdef CONFIG_64BIT
37586 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37587 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37588 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37589 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37590 #else
37591 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37592 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37593 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37594 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37595 #endif
37596 }
37597 netif_receive_skb(skb);
37598 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37599 dev->name);
37600 */
37601 #ifdef CONFIG_64BIT
37602 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37603 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37604 #else
37605 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37606 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37607 #endif
37608 dev_kfree_skb_irq(skb);
37609 }
37610 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37611 index 683bedc..86dba9a 100644
37612 --- a/drivers/staging/octeon/ethernet.c
37613 +++ b/drivers/staging/octeon/ethernet.c
37614 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37615 * since the RX tasklet also increments it.
37616 */
37617 #ifdef CONFIG_64BIT
37618 - atomic64_add(rx_status.dropped_packets,
37619 - (atomic64_t *)&priv->stats.rx_dropped);
37620 + atomic64_add_unchecked(rx_status.dropped_packets,
37621 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37622 #else
37623 - atomic_add(rx_status.dropped_packets,
37624 - (atomic_t *)&priv->stats.rx_dropped);
37625 + atomic_add_unchecked(rx_status.dropped_packets,
37626 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37627 #endif
37628 }
37629
37630 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37631 index dc23395..cf7e9b1 100644
37632 --- a/drivers/staging/rtl8712/rtl871x_io.h
37633 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37634 @@ -108,7 +108,7 @@ struct _io_ops {
37635 u8 *pmem);
37636 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37637 u8 *pmem);
37638 -};
37639 +} __no_const;
37640
37641 struct io_req {
37642 struct list_head list;
37643 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37644 index c7b5e8b..783d6cb 100644
37645 --- a/drivers/staging/sbe-2t3e3/netdev.c
37646 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37647 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37648 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37649
37650 if (rlen)
37651 - if (copy_to_user(data, &resp, rlen))
37652 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37653 return -EFAULT;
37654
37655 return 0;
37656 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37657 index 5d89c0f..9261317 100644
37658 --- a/drivers/staging/usbip/usbip_common.h
37659 +++ b/drivers/staging/usbip/usbip_common.h
37660 @@ -289,7 +289,7 @@ struct usbip_device {
37661 void (*shutdown)(struct usbip_device *);
37662 void (*reset)(struct usbip_device *);
37663 void (*unusable)(struct usbip_device *);
37664 - } eh_ops;
37665 + } __no_const eh_ops;
37666 };
37667
37668 #define kthread_get_run(threadfn, data, namefmt, ...) \
37669 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37670 index c66b8b3..a4a035b 100644
37671 --- a/drivers/staging/usbip/vhci.h
37672 +++ b/drivers/staging/usbip/vhci.h
37673 @@ -83,7 +83,7 @@ struct vhci_hcd {
37674 unsigned resuming:1;
37675 unsigned long re_timeout;
37676
37677 - atomic_t seqnum;
37678 + atomic_unchecked_t seqnum;
37679
37680 /*
37681 * NOTE:
37682 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37683 index 12a9a5f..afd8295 100644
37684 --- a/drivers/staging/usbip/vhci_hcd.c
37685 +++ b/drivers/staging/usbip/vhci_hcd.c
37686 @@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
37687 return;
37688 }
37689
37690 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37691 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37692 if (priv->seqnum == 0xffff)
37693 dev_info(&urb->dev->dev, "seqnum max\n");
37694
37695 @@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37696 return -ENOMEM;
37697 }
37698
37699 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37700 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37701 if (unlink->seqnum == 0xffff)
37702 pr_info("seqnum max\n");
37703
37704 @@ -911,7 +911,7 @@ static int vhci_start(struct usb_hcd *hcd)
37705 vdev->rhport = rhport;
37706 }
37707
37708 - atomic_set(&vhci->seqnum, 0);
37709 + atomic_set_unchecked(&vhci->seqnum, 0);
37710 spin_lock_init(&vhci->lock);
37711
37712 hcd->power_budget = 0; /* no limit */
37713 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37714 index f0eaf04..5a82e06 100644
37715 --- a/drivers/staging/usbip/vhci_rx.c
37716 +++ b/drivers/staging/usbip/vhci_rx.c
37717 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37718 if (!urb) {
37719 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37720 pr_info("max seqnum %d\n",
37721 - atomic_read(&the_controller->seqnum));
37722 + atomic_read_unchecked(&the_controller->seqnum));
37723 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37724 return;
37725 }
37726 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37727 index 6ac6f45..1b208ba 100644
37728 --- a/drivers/staging/vt6655/hostap.c
37729 +++ b/drivers/staging/vt6655/hostap.c
37730 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
37731 *
37732 */
37733
37734 +static net_device_ops_no_const apdev_netdev_ops;
37735 +
37736 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37737 {
37738 PSDevice apdev_priv;
37739 struct net_device *dev = pDevice->dev;
37740 int ret;
37741 - const struct net_device_ops apdev_netdev_ops = {
37742 - .ndo_start_xmit = pDevice->tx_80211,
37743 - };
37744
37745 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37746
37747 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37748 *apdev_priv = *pDevice;
37749 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37750
37751 + /* only half broken now */
37752 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37753 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37754
37755 pDevice->apdev->type = ARPHRD_IEEE80211;
37756 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37757 index 682002a..35ed5cf 100644
37758 --- a/drivers/staging/vt6656/hostap.c
37759 +++ b/drivers/staging/vt6656/hostap.c
37760 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
37761 *
37762 */
37763
37764 +static net_device_ops_no_const apdev_netdev_ops;
37765 +
37766 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37767 {
37768 PSDevice apdev_priv;
37769 struct net_device *dev = pDevice->dev;
37770 int ret;
37771 - const struct net_device_ops apdev_netdev_ops = {
37772 - .ndo_start_xmit = pDevice->tx_80211,
37773 - };
37774
37775 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37776
37777 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37778 *apdev_priv = *pDevice;
37779 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37780
37781 + /* only half broken now */
37782 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37783 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37784
37785 pDevice->apdev->type = ARPHRD_IEEE80211;
37786 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37787 index 7843dfd..3db105f 100644
37788 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37789 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37790 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37791
37792 struct usbctlx_completor {
37793 int (*complete) (struct usbctlx_completor *);
37794 -};
37795 +} __no_const;
37796
37797 static int
37798 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37799 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37800 index eaa9021..43f023b 100644
37801 --- a/drivers/staging/zcache/tmem.c
37802 +++ b/drivers/staging/zcache/tmem.c
37803 @@ -39,7 +39,7 @@
37804 * A tmem host implementation must use this function to register callbacks
37805 * for memory allocation.
37806 */
37807 -static struct tmem_hostops tmem_hostops;
37808 +static tmem_hostops_no_const tmem_hostops;
37809
37810 static void tmem_objnode_tree_init(void);
37811
37812 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37813 * A tmem host implementation must use this function to register
37814 * callbacks for a page-accessible memory (PAM) implementation
37815 */
37816 -static struct tmem_pamops tmem_pamops;
37817 +static tmem_pamops_no_const tmem_pamops;
37818
37819 void tmem_register_pamops(struct tmem_pamops *m)
37820 {
37821 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37822 index 0d4aa82..f7832d4 100644
37823 --- a/drivers/staging/zcache/tmem.h
37824 +++ b/drivers/staging/zcache/tmem.h
37825 @@ -180,6 +180,7 @@ struct tmem_pamops {
37826 void (*new_obj)(struct tmem_obj *);
37827 int (*replace_in_obj)(void *, struct tmem_obj *);
37828 };
37829 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37830 extern void tmem_register_pamops(struct tmem_pamops *m);
37831
37832 /* memory allocation methods provided by the host implementation */
37833 @@ -189,6 +190,7 @@ struct tmem_hostops {
37834 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37835 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37836 };
37837 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37838 extern void tmem_register_hostops(struct tmem_hostops *m);
37839
37840 /* core tmem accessor functions */
37841 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37842 index 269f544..32def0d 100644
37843 --- a/drivers/target/target_core_transport.c
37844 +++ b/drivers/target/target_core_transport.c
37845 @@ -1098,7 +1098,7 @@ struct se_device *transport_add_device_to_core_hba(
37846 spin_lock_init(&dev->se_port_lock);
37847 spin_lock_init(&dev->se_tmr_lock);
37848 spin_lock_init(&dev->qf_cmd_lock);
37849 - atomic_set(&dev->dev_ordered_id, 0);
37850 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37851
37852 se_dev_set_default_attribs(dev, dev_limits);
37853
37854 @@ -1288,7 +1288,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37855 * Used to determine when ORDERED commands should go from
37856 * Dormant to Active status.
37857 */
37858 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37859 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37860 smp_mb__after_atomic_inc();
37861 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37862 cmd->se_ordered_id, cmd->sam_task_attr,
37863 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37864 index e61cabd..7617d26 100644
37865 --- a/drivers/tty/cyclades.c
37866 +++ b/drivers/tty/cyclades.c
37867 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37868 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37869 info->port.count);
37870 #endif
37871 - info->port.count++;
37872 + atomic_inc(&info->port.count);
37873 #ifdef CY_DEBUG_COUNT
37874 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37875 - current->pid, info->port.count);
37876 + current->pid, atomic_read(&info->port.count));
37877 #endif
37878
37879 /*
37880 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37881 for (j = 0; j < cy_card[i].nports; j++) {
37882 info = &cy_card[i].ports[j];
37883
37884 - if (info->port.count) {
37885 + if (atomic_read(&info->port.count)) {
37886 /* XXX is the ldisc num worth this? */
37887 struct tty_struct *tty;
37888 struct tty_ldisc *ld;
37889 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37890 index 2d691eb..be02ebd 100644
37891 --- a/drivers/tty/hvc/hvc_console.c
37892 +++ b/drivers/tty/hvc/hvc_console.c
37893 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37894
37895 spin_lock_irqsave(&hp->port.lock, flags);
37896 /* Check and then increment for fast path open. */
37897 - if (hp->port.count++ > 0) {
37898 + if (atomic_inc_return(&hp->port.count) > 1) {
37899 spin_unlock_irqrestore(&hp->port.lock, flags);
37900 hvc_kick();
37901 return 0;
37902 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37903
37904 spin_lock_irqsave(&hp->port.lock, flags);
37905
37906 - if (--hp->port.count == 0) {
37907 + if (atomic_dec_return(&hp->port.count) == 0) {
37908 spin_unlock_irqrestore(&hp->port.lock, flags);
37909 /* We are done with the tty pointer now. */
37910 tty_port_tty_set(&hp->port, NULL);
37911 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
37912 */
37913 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
37914 } else {
37915 - if (hp->port.count < 0)
37916 + if (atomic_read(&hp->port.count) < 0)
37917 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
37918 - hp->vtermno, hp->port.count);
37919 + hp->vtermno, atomic_read(&hp->port.count));
37920 spin_unlock_irqrestore(&hp->port.lock, flags);
37921 }
37922
37923 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
37924 * open->hangup case this can be called after the final close so prevent
37925 * that from happening for now.
37926 */
37927 - if (hp->port.count <= 0) {
37928 + if (atomic_read(&hp->port.count) <= 0) {
37929 spin_unlock_irqrestore(&hp->port.lock, flags);
37930 return;
37931 }
37932
37933 - temp_open_count = hp->port.count;
37934 - hp->port.count = 0;
37935 + temp_open_count = atomic_read(&hp->port.count);
37936 + atomic_set(&hp->port.count, 0);
37937 spin_unlock_irqrestore(&hp->port.lock, flags);
37938 tty_port_tty_set(&hp->port, NULL);
37939
37940 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
37941 return -EPIPE;
37942
37943 /* FIXME what's this (unprotected) check for? */
37944 - if (hp->port.count <= 0)
37945 + if (atomic_read(&hp->port.count) <= 0)
37946 return -EIO;
37947
37948 spin_lock_irqsave(&hp->lock, flags);
37949 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
37950 index d56788c..12d8f85 100644
37951 --- a/drivers/tty/hvc/hvcs.c
37952 +++ b/drivers/tty/hvc/hvcs.c
37953 @@ -83,6 +83,7 @@
37954 #include <asm/hvcserver.h>
37955 #include <asm/uaccess.h>
37956 #include <asm/vio.h>
37957 +#include <asm/local.h>
37958
37959 /*
37960 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
37961 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
37962
37963 spin_lock_irqsave(&hvcsd->lock, flags);
37964
37965 - if (hvcsd->port.count > 0) {
37966 + if (atomic_read(&hvcsd->port.count) > 0) {
37967 spin_unlock_irqrestore(&hvcsd->lock, flags);
37968 printk(KERN_INFO "HVCS: vterm state unchanged. "
37969 "The hvcs device node is still in use.\n");
37970 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
37971 if ((retval = hvcs_partner_connect(hvcsd)))
37972 goto error_release;
37973
37974 - hvcsd->port.count = 1;
37975 + atomic_set(&hvcsd->port.count, 1);
37976 hvcsd->port.tty = tty;
37977 tty->driver_data = hvcsd;
37978
37979 @@ -1168,7 +1169,7 @@ fast_open:
37980
37981 spin_lock_irqsave(&hvcsd->lock, flags);
37982 tty_port_get(&hvcsd->port);
37983 - hvcsd->port.count++;
37984 + atomic_inc(&hvcsd->port.count);
37985 hvcsd->todo_mask |= HVCS_SCHED_READ;
37986 spin_unlock_irqrestore(&hvcsd->lock, flags);
37987
37988 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37989 hvcsd = tty->driver_data;
37990
37991 spin_lock_irqsave(&hvcsd->lock, flags);
37992 - if (--hvcsd->port.count == 0) {
37993 + if (atomic_dec_and_test(&hvcsd->port.count)) {
37994
37995 vio_disable_interrupts(hvcsd->vdev);
37996
37997 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
37998 free_irq(irq, hvcsd);
37999 tty_port_put(&hvcsd->port);
38000 return;
38001 - } else if (hvcsd->port.count < 0) {
38002 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38003 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38004 " is missmanaged.\n",
38005 - hvcsd->vdev->unit_address, hvcsd->port.count);
38006 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38007 }
38008
38009 spin_unlock_irqrestore(&hvcsd->lock, flags);
38010 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38011
38012 spin_lock_irqsave(&hvcsd->lock, flags);
38013 /* Preserve this so that we know how many kref refs to put */
38014 - temp_open_count = hvcsd->port.count;
38015 + temp_open_count = atomic_read(&hvcsd->port.count);
38016
38017 /*
38018 * Don't kref put inside the spinlock because the destruction
38019 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38020 tty->driver_data = NULL;
38021 hvcsd->port.tty = NULL;
38022
38023 - hvcsd->port.count = 0;
38024 + atomic_set(&hvcsd->port.count, 0);
38025
38026 /* This will drop any buffered data on the floor which is OK in a hangup
38027 * scenario. */
38028 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38029 * the middle of a write operation? This is a crummy place to do this
38030 * but we want to keep it all in the spinlock.
38031 */
38032 - if (hvcsd->port.count <= 0) {
38033 + if (atomic_read(&hvcsd->port.count) <= 0) {
38034 spin_unlock_irqrestore(&hvcsd->lock, flags);
38035 return -ENODEV;
38036 }
38037 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38038 {
38039 struct hvcs_struct *hvcsd = tty->driver_data;
38040
38041 - if (!hvcsd || hvcsd->port.count <= 0)
38042 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38043 return 0;
38044
38045 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38046 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38047 index f8b5fa0..4ba9f89 100644
38048 --- a/drivers/tty/ipwireless/tty.c
38049 +++ b/drivers/tty/ipwireless/tty.c
38050 @@ -29,6 +29,7 @@
38051 #include <linux/tty_driver.h>
38052 #include <linux/tty_flip.h>
38053 #include <linux/uaccess.h>
38054 +#include <asm/local.h>
38055
38056 #include "tty.h"
38057 #include "network.h"
38058 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38059 mutex_unlock(&tty->ipw_tty_mutex);
38060 return -ENODEV;
38061 }
38062 - if (tty->port.count == 0)
38063 + if (atomic_read(&tty->port.count) == 0)
38064 tty->tx_bytes_queued = 0;
38065
38066 - tty->port.count++;
38067 + atomic_inc(&tty->port.count);
38068
38069 tty->port.tty = linux_tty;
38070 linux_tty->driver_data = tty;
38071 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38072
38073 static void do_ipw_close(struct ipw_tty *tty)
38074 {
38075 - tty->port.count--;
38076 -
38077 - if (tty->port.count == 0) {
38078 + if (atomic_dec_return(&tty->port.count) == 0) {
38079 struct tty_struct *linux_tty = tty->port.tty;
38080
38081 if (linux_tty != NULL) {
38082 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38083 return;
38084
38085 mutex_lock(&tty->ipw_tty_mutex);
38086 - if (tty->port.count == 0) {
38087 + if (atomic_read(&tty->port.count) == 0) {
38088 mutex_unlock(&tty->ipw_tty_mutex);
38089 return;
38090 }
38091 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38092 return;
38093 }
38094
38095 - if (!tty->port.count) {
38096 + if (!atomic_read(&tty->port.count)) {
38097 mutex_unlock(&tty->ipw_tty_mutex);
38098 return;
38099 }
38100 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38101 return -ENODEV;
38102
38103 mutex_lock(&tty->ipw_tty_mutex);
38104 - if (!tty->port.count) {
38105 + if (!atomic_read(&tty->port.count)) {
38106 mutex_unlock(&tty->ipw_tty_mutex);
38107 return -EINVAL;
38108 }
38109 @@ -252,7 +251,7 @@ static int ipw_write_room(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 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38118 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38119 if (!tty)
38120 return 0;
38121
38122 - if (!tty->port.count)
38123 + if (!atomic_read(&tty->port.count))
38124 return 0;
38125
38126 return tty->tx_bytes_queued;
38127 @@ -375,7 +374,7 @@ static int ipw_tiocmget(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 return get_control_lines(tty);
38136 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38137 if (!tty)
38138 return -ENODEV;
38139
38140 - if (!tty->port.count)
38141 + if (!atomic_read(&tty->port.count))
38142 return -EINVAL;
38143
38144 return set_control_lines(tty, set, clear);
38145 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38146 if (!tty)
38147 return -ENODEV;
38148
38149 - if (!tty->port.count)
38150 + if (!atomic_read(&tty->port.count))
38151 return -EINVAL;
38152
38153 /* FIXME: Exactly how is the tty object locked here .. */
38154 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38155 * are gone */
38156 mutex_lock(&ttyj->ipw_tty_mutex);
38157 }
38158 - while (ttyj->port.count)
38159 + while (atomic_read(&ttyj->port.count))
38160 do_ipw_close(ttyj);
38161 ipwireless_disassociate_network_ttys(network,
38162 ttyj->channel_idx);
38163 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38164 index 324467d..504cc25 100644
38165 --- a/drivers/tty/moxa.c
38166 +++ b/drivers/tty/moxa.c
38167 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38168 }
38169
38170 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38171 - ch->port.count++;
38172 + atomic_inc(&ch->port.count);
38173 tty->driver_data = ch;
38174 tty_port_tty_set(&ch->port, tty);
38175 mutex_lock(&ch->port.mutex);
38176 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38177 index 90dff82..08119c3 100644
38178 --- a/drivers/tty/n_gsm.c
38179 +++ b/drivers/tty/n_gsm.c
38180 @@ -1639,7 +1639,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38181 kref_init(&dlci->ref);
38182 mutex_init(&dlci->mutex);
38183 dlci->fifo = &dlci->_fifo;
38184 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38185 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38186 kfree(dlci);
38187 return NULL;
38188 }
38189 @@ -2909,7 +2909,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38190 if (dlci == NULL)
38191 return -ENOMEM;
38192 port = &dlci->port;
38193 - port->count++;
38194 + atomic_inc(&port->count);
38195 tty->driver_data = dlci;
38196 dlci_get(dlci);
38197 dlci_get(dlci->gsm->dlci[0]);
38198 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38199 index 26f0d0e..b7c4273 100644
38200 --- a/drivers/tty/n_tty.c
38201 +++ b/drivers/tty/n_tty.c
38202 @@ -2124,6 +2124,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38203 {
38204 *ops = tty_ldisc_N_TTY;
38205 ops->owner = NULL;
38206 - ops->refcount = ops->flags = 0;
38207 + atomic_set(&ops->refcount, 0);
38208 + ops->flags = 0;
38209 }
38210 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38211 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38212 index 5505ffc..7affff9 100644
38213 --- a/drivers/tty/pty.c
38214 +++ b/drivers/tty/pty.c
38215 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38216 panic("Couldn't register Unix98 pts driver");
38217
38218 /* Now create the /dev/ptmx special device */
38219 + pax_open_kernel();
38220 tty_default_fops(&ptmx_fops);
38221 - ptmx_fops.open = ptmx_open;
38222 + *(void **)&ptmx_fops.open = ptmx_open;
38223 + pax_close_kernel();
38224
38225 cdev_init(&ptmx_cdev, &ptmx_fops);
38226 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38227 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38228 index 777d5f9..56d67ca 100644
38229 --- a/drivers/tty/rocket.c
38230 +++ b/drivers/tty/rocket.c
38231 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38232 tty->driver_data = info;
38233 tty_port_tty_set(port, tty);
38234
38235 - if (port->count++ == 0) {
38236 + if (atomic_inc_return(&port->count) == 1) {
38237 atomic_inc(&rp_num_ports_open);
38238
38239 #ifdef ROCKET_DEBUG_OPEN
38240 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38241 #endif
38242 }
38243 #ifdef ROCKET_DEBUG_OPEN
38244 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38245 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38246 #endif
38247
38248 /*
38249 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38250 spin_unlock_irqrestore(&info->port.lock, flags);
38251 return;
38252 }
38253 - if (info->port.count)
38254 + if (atomic_read(&info->port.count))
38255 atomic_dec(&rp_num_ports_open);
38256 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38257 spin_unlock_irqrestore(&info->port.lock, flags);
38258 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38259 index 2b42a01..32a2ed3 100644
38260 --- a/drivers/tty/serial/kgdboc.c
38261 +++ b/drivers/tty/serial/kgdboc.c
38262 @@ -24,8 +24,9 @@
38263 #define MAX_CONFIG_LEN 40
38264
38265 static struct kgdb_io kgdboc_io_ops;
38266 +static struct kgdb_io kgdboc_io_ops_console;
38267
38268 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38269 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38270 static int configured = -1;
38271
38272 static char config[MAX_CONFIG_LEN];
38273 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38274 kgdboc_unregister_kbd();
38275 if (configured == 1)
38276 kgdb_unregister_io_module(&kgdboc_io_ops);
38277 + else if (configured == 2)
38278 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38279 }
38280
38281 static int configure_kgdboc(void)
38282 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38283 int err;
38284 char *cptr = config;
38285 struct console *cons;
38286 + int is_console = 0;
38287
38288 err = kgdboc_option_setup(config);
38289 if (err || !strlen(config) || isspace(config[0]))
38290 goto noconfig;
38291
38292 err = -ENODEV;
38293 - kgdboc_io_ops.is_console = 0;
38294 kgdb_tty_driver = NULL;
38295
38296 kgdboc_use_kms = 0;
38297 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38298 int idx;
38299 if (cons->device && cons->device(cons, &idx) == p &&
38300 idx == tty_line) {
38301 - kgdboc_io_ops.is_console = 1;
38302 + is_console = 1;
38303 break;
38304 }
38305 cons = cons->next;
38306 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38307 kgdb_tty_line = tty_line;
38308
38309 do_register:
38310 - err = kgdb_register_io_module(&kgdboc_io_ops);
38311 + if (is_console) {
38312 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38313 + configured = 2;
38314 + } else {
38315 + err = kgdb_register_io_module(&kgdboc_io_ops);
38316 + configured = 1;
38317 + }
38318 if (err)
38319 goto noconfig;
38320
38321 - configured = 1;
38322 -
38323 return 0;
38324
38325 noconfig:
38326 @@ -213,7 +220,7 @@ noconfig:
38327 static int __init init_kgdboc(void)
38328 {
38329 /* Already configured? */
38330 - if (configured == 1)
38331 + if (configured >= 1)
38332 return 0;
38333
38334 return configure_kgdboc();
38335 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38336 if (config[len - 1] == '\n')
38337 config[len - 1] = '\0';
38338
38339 - if (configured == 1)
38340 + if (configured >= 1)
38341 cleanup_kgdboc();
38342
38343 /* Go and configure with the new params. */
38344 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38345 .post_exception = kgdboc_post_exp_handler,
38346 };
38347
38348 +static struct kgdb_io kgdboc_io_ops_console = {
38349 + .name = "kgdboc",
38350 + .read_char = kgdboc_get_char,
38351 + .write_char = kgdboc_put_char,
38352 + .pre_exception = kgdboc_pre_exp_handler,
38353 + .post_exception = kgdboc_post_exp_handler,
38354 + .is_console = 1
38355 +};
38356 +
38357 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38358 /* This is only available if kgdboc is a built in for early debugging */
38359 static int __init kgdboc_early_init(char *opt)
38360 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38361 index a21dc8e..fe43e9e 100644
38362 --- a/drivers/tty/serial/serial_core.c
38363 +++ b/drivers/tty/serial/serial_core.c
38364 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38365 uart_flush_buffer(tty);
38366 uart_shutdown(tty, state);
38367 spin_lock_irqsave(&port->lock, flags);
38368 - port->count = 0;
38369 + atomic_set(&port->count, 0);
38370 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38371 spin_unlock_irqrestore(&port->lock, flags);
38372 tty_port_tty_set(port, NULL);
38373 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38374 goto end;
38375 }
38376
38377 - port->count++;
38378 + atomic_inc(&port->count);
38379 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38380 retval = -ENXIO;
38381 goto err_dec_count;
38382 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38383 /*
38384 * Make sure the device is in D0 state.
38385 */
38386 - if (port->count == 1)
38387 + if (atomic_read(&port->count) == 1)
38388 uart_change_pm(state, 0);
38389
38390 /*
38391 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38392 end:
38393 return retval;
38394 err_dec_count:
38395 - port->count--;
38396 + atomic_inc(&port->count);
38397 mutex_unlock(&port->mutex);
38398 goto end;
38399 }
38400 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38401 index 593d40a..bdc61f3 100644
38402 --- a/drivers/tty/synclink.c
38403 +++ b/drivers/tty/synclink.c
38404 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38405
38406 if (debug_level >= DEBUG_LEVEL_INFO)
38407 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38408 - __FILE__,__LINE__, info->device_name, info->port.count);
38409 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38410
38411 if (tty_port_close_start(&info->port, tty, filp) == 0)
38412 goto cleanup;
38413 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38414 cleanup:
38415 if (debug_level >= DEBUG_LEVEL_INFO)
38416 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38417 - tty->driver->name, info->port.count);
38418 + tty->driver->name, atomic_read(&info->port.count));
38419
38420 } /* end of mgsl_close() */
38421
38422 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38423
38424 mgsl_flush_buffer(tty);
38425 shutdown(info);
38426 -
38427 - info->port.count = 0;
38428 +
38429 + atomic_set(&info->port.count, 0);
38430 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38431 info->port.tty = NULL;
38432
38433 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38434
38435 if (debug_level >= DEBUG_LEVEL_INFO)
38436 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38437 - __FILE__,__LINE__, tty->driver->name, port->count );
38438 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38439
38440 spin_lock_irqsave(&info->irq_spinlock, flags);
38441 if (!tty_hung_up_p(filp)) {
38442 extra_count = true;
38443 - port->count--;
38444 + atomic_dec(&port->count);
38445 }
38446 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38447 port->blocked_open++;
38448 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38449
38450 if (debug_level >= DEBUG_LEVEL_INFO)
38451 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38452 - __FILE__,__LINE__, tty->driver->name, port->count );
38453 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38454
38455 tty_unlock();
38456 schedule();
38457 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38458
38459 /* FIXME: Racy on hangup during close wait */
38460 if (extra_count)
38461 - port->count++;
38462 + atomic_inc(&port->count);
38463 port->blocked_open--;
38464
38465 if (debug_level >= DEBUG_LEVEL_INFO)
38466 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38467 - __FILE__,__LINE__, tty->driver->name, port->count );
38468 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38469
38470 if (!retval)
38471 port->flags |= ASYNC_NORMAL_ACTIVE;
38472 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38473
38474 if (debug_level >= DEBUG_LEVEL_INFO)
38475 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38476 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38477 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38478
38479 /* If port is closing, signal caller to try again */
38480 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38481 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38482 spin_unlock_irqrestore(&info->netlock, flags);
38483 goto cleanup;
38484 }
38485 - info->port.count++;
38486 + atomic_inc(&info->port.count);
38487 spin_unlock_irqrestore(&info->netlock, flags);
38488
38489 - if (info->port.count == 1) {
38490 + if (atomic_read(&info->port.count) == 1) {
38491 /* 1st open on this device, init hardware */
38492 retval = startup(info);
38493 if (retval < 0)
38494 @@ -3444,8 +3444,8 @@ cleanup:
38495 if (retval) {
38496 if (tty->count == 1)
38497 info->port.tty = NULL; /* tty layer will release tty struct */
38498 - if(info->port.count)
38499 - info->port.count--;
38500 + if (atomic_read(&info->port.count))
38501 + atomic_dec(&info->port.count);
38502 }
38503
38504 return retval;
38505 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38506 unsigned short new_crctype;
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 switch (encoding)
38514 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38515
38516 /* arbitrate between network and tty opens */
38517 spin_lock_irqsave(&info->netlock, flags);
38518 - if (info->port.count != 0 || info->netcount != 0) {
38519 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38520 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38521 spin_unlock_irqrestore(&info->netlock, flags);
38522 return -EBUSY;
38523 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38524 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38525
38526 /* return error if TTY interface open */
38527 - if (info->port.count)
38528 + if (atomic_read(&info->port.count))
38529 return -EBUSY;
38530
38531 if (cmd != SIOCWANDEV)
38532 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38533 index aa1debf..9297a16 100644
38534 --- a/drivers/tty/synclink_gt.c
38535 +++ b/drivers/tty/synclink_gt.c
38536 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38537 tty->driver_data = info;
38538 info->port.tty = tty;
38539
38540 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38541 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38542
38543 /* If port is closing, signal caller to try again */
38544 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38545 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38546 mutex_unlock(&info->port.mutex);
38547 goto cleanup;
38548 }
38549 - info->port.count++;
38550 + atomic_inc(&info->port.count);
38551 spin_unlock_irqrestore(&info->netlock, flags);
38552
38553 - if (info->port.count == 1) {
38554 + if (atomic_read(&info->port.count) == 1) {
38555 /* 1st open on this device, init hardware */
38556 retval = startup(info);
38557 if (retval < 0) {
38558 @@ -716,8 +716,8 @@ cleanup:
38559 if (retval) {
38560 if (tty->count == 1)
38561 info->port.tty = NULL; /* tty layer will release tty struct */
38562 - if(info->port.count)
38563 - info->port.count--;
38564 + if(atomic_read(&info->port.count))
38565 + atomic_dec(&info->port.count);
38566 }
38567
38568 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38569 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38570
38571 if (sanity_check(info, tty->name, "close"))
38572 return;
38573 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38574 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38575
38576 if (tty_port_close_start(&info->port, tty, filp) == 0)
38577 goto cleanup;
38578 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38579 tty_port_close_end(&info->port, tty);
38580 info->port.tty = NULL;
38581 cleanup:
38582 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38583 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38584 }
38585
38586 static void hangup(struct tty_struct *tty)
38587 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38588 shutdown(info);
38589
38590 spin_lock_irqsave(&info->port.lock, flags);
38591 - info->port.count = 0;
38592 + atomic_set(&info->port.count, 0);
38593 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38594 info->port.tty = NULL;
38595 spin_unlock_irqrestore(&info->port.lock, flags);
38596 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38597 unsigned short new_crctype;
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 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38605 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38606
38607 /* arbitrate between network and tty opens */
38608 spin_lock_irqsave(&info->netlock, flags);
38609 - if (info->port.count != 0 || info->netcount != 0) {
38610 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38611 DBGINFO(("%s hdlc_open busy\n", dev->name));
38612 spin_unlock_irqrestore(&info->netlock, flags);
38613 return -EBUSY;
38614 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38615 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38616
38617 /* return error if TTY interface open */
38618 - if (info->port.count)
38619 + if (atomic_read(&info->port.count))
38620 return -EBUSY;
38621
38622 if (cmd != SIOCWANDEV)
38623 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38624 if (port == NULL)
38625 continue;
38626 spin_lock(&port->lock);
38627 - if ((port->port.count || port->netcount) &&
38628 + if ((atomic_read(&port->port.count) || port->netcount) &&
38629 port->pending_bh && !port->bh_running &&
38630 !port->bh_requested) {
38631 DBGISR(("%s bh queued\n", port->device_name));
38632 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38633 spin_lock_irqsave(&info->lock, flags);
38634 if (!tty_hung_up_p(filp)) {
38635 extra_count = true;
38636 - port->count--;
38637 + atomic_dec(&port->count);
38638 }
38639 spin_unlock_irqrestore(&info->lock, flags);
38640 port->blocked_open++;
38641 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38642 remove_wait_queue(&port->open_wait, &wait);
38643
38644 if (extra_count)
38645 - port->count++;
38646 + atomic_inc(&port->count);
38647 port->blocked_open--;
38648
38649 if (!retval)
38650 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38651 index a3dddc1..8905ab2 100644
38652 --- a/drivers/tty/synclinkmp.c
38653 +++ b/drivers/tty/synclinkmp.c
38654 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38655
38656 if (debug_level >= DEBUG_LEVEL_INFO)
38657 printk("%s(%d):%s open(), old ref count = %d\n",
38658 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38659 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38660
38661 /* If port is closing, signal caller to try again */
38662 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38663 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38664 spin_unlock_irqrestore(&info->netlock, flags);
38665 goto cleanup;
38666 }
38667 - info->port.count++;
38668 + atomic_inc(&info->port.count);
38669 spin_unlock_irqrestore(&info->netlock, flags);
38670
38671 - if (info->port.count == 1) {
38672 + if (atomic_read(&info->port.count) == 1) {
38673 /* 1st open on this device, init hardware */
38674 retval = startup(info);
38675 if (retval < 0)
38676 @@ -788,8 +788,8 @@ cleanup:
38677 if (retval) {
38678 if (tty->count == 1)
38679 info->port.tty = NULL; /* tty layer will release tty struct */
38680 - if(info->port.count)
38681 - info->port.count--;
38682 + if(atomic_read(&info->port.count))
38683 + atomic_dec(&info->port.count);
38684 }
38685
38686 return retval;
38687 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38688
38689 if (debug_level >= DEBUG_LEVEL_INFO)
38690 printk("%s(%d):%s close() entry, count=%d\n",
38691 - __FILE__,__LINE__, info->device_name, info->port.count);
38692 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38693
38694 if (tty_port_close_start(&info->port, tty, filp) == 0)
38695 goto cleanup;
38696 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38697 cleanup:
38698 if (debug_level >= DEBUG_LEVEL_INFO)
38699 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38700 - tty->driver->name, info->port.count);
38701 + tty->driver->name, atomic_read(&info->port.count));
38702 }
38703
38704 /* Called by tty_hangup() when a hangup is signaled.
38705 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38706 shutdown(info);
38707
38708 spin_lock_irqsave(&info->port.lock, flags);
38709 - info->port.count = 0;
38710 + atomic_set(&info->port.count, 0);
38711 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38712 info->port.tty = NULL;
38713 spin_unlock_irqrestore(&info->port.lock, flags);
38714 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38715 unsigned short new_crctype;
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 switch (encoding)
38723 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38724
38725 /* arbitrate between network and tty opens */
38726 spin_lock_irqsave(&info->netlock, flags);
38727 - if (info->port.count != 0 || info->netcount != 0) {
38728 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38729 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38730 spin_unlock_irqrestore(&info->netlock, flags);
38731 return -EBUSY;
38732 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38733 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38734
38735 /* return error if TTY interface open */
38736 - if (info->port.count)
38737 + if (atomic_read(&info->port.count))
38738 return -EBUSY;
38739
38740 if (cmd != SIOCWANDEV)
38741 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38742 * do not request bottom half processing if the
38743 * device is not open in a normal mode.
38744 */
38745 - if ( port && (port->port.count || port->netcount) &&
38746 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38747 port->pending_bh && !port->bh_running &&
38748 !port->bh_requested ) {
38749 if ( debug_level >= DEBUG_LEVEL_ISR )
38750 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38751
38752 if (debug_level >= DEBUG_LEVEL_INFO)
38753 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38754 - __FILE__,__LINE__, tty->driver->name, port->count );
38755 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38756
38757 spin_lock_irqsave(&info->lock, flags);
38758 if (!tty_hung_up_p(filp)) {
38759 extra_count = true;
38760 - port->count--;
38761 + atomic_dec(&port->count);
38762 }
38763 spin_unlock_irqrestore(&info->lock, flags);
38764 port->blocked_open++;
38765 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38766
38767 if (debug_level >= DEBUG_LEVEL_INFO)
38768 printk("%s(%d):%s block_til_ready() count=%d\n",
38769 - __FILE__,__LINE__, tty->driver->name, port->count );
38770 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38771
38772 tty_unlock();
38773 schedule();
38774 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38775 remove_wait_queue(&port->open_wait, &wait);
38776
38777 if (extra_count)
38778 - port->count++;
38779 + atomic_inc(&port->count);
38780 port->blocked_open--;
38781
38782 if (debug_level >= DEBUG_LEVEL_INFO)
38783 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38784 - __FILE__,__LINE__, tty->driver->name, port->count );
38785 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38786
38787 if (!retval)
38788 port->flags |= ASYNC_NORMAL_ACTIVE;
38789 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38790 index 05728894..b9d44c6 100644
38791 --- a/drivers/tty/sysrq.c
38792 +++ b/drivers/tty/sysrq.c
38793 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38794 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38795 size_t count, loff_t *ppos)
38796 {
38797 - if (count) {
38798 + if (count && capable(CAP_SYS_ADMIN)) {
38799 char c;
38800
38801 if (get_user(c, buf))
38802 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38803 index b425c79..08a3f06 100644
38804 --- a/drivers/tty/tty_io.c
38805 +++ b/drivers/tty/tty_io.c
38806 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38807
38808 void tty_default_fops(struct file_operations *fops)
38809 {
38810 - *fops = tty_fops;
38811 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38812 }
38813
38814 /*
38815 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38816 index 6f99c99..8947bc4 100644
38817 --- a/drivers/tty/tty_ldisc.c
38818 +++ b/drivers/tty/tty_ldisc.c
38819 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38820 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38821 struct tty_ldisc_ops *ldo = ld->ops;
38822
38823 - ldo->refcount--;
38824 + atomic_dec(&ldo->refcount);
38825 module_put(ldo->owner);
38826 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38827
38828 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38829 spin_lock_irqsave(&tty_ldisc_lock, flags);
38830 tty_ldiscs[disc] = new_ldisc;
38831 new_ldisc->num = disc;
38832 - new_ldisc->refcount = 0;
38833 + atomic_set(&new_ldisc->refcount, 0);
38834 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38835
38836 return ret;
38837 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38838 return -EINVAL;
38839
38840 spin_lock_irqsave(&tty_ldisc_lock, flags);
38841 - if (tty_ldiscs[disc]->refcount)
38842 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38843 ret = -EBUSY;
38844 else
38845 tty_ldiscs[disc] = NULL;
38846 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38847 if (ldops) {
38848 ret = ERR_PTR(-EAGAIN);
38849 if (try_module_get(ldops->owner)) {
38850 - ldops->refcount++;
38851 + atomic_inc(&ldops->refcount);
38852 ret = ldops;
38853 }
38854 }
38855 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38856 unsigned long flags;
38857
38858 spin_lock_irqsave(&tty_ldisc_lock, flags);
38859 - ldops->refcount--;
38860 + atomic_dec(&ldops->refcount);
38861 module_put(ldops->owner);
38862 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38863 }
38864 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38865 index bf6e238..d401c04 100644
38866 --- a/drivers/tty/tty_port.c
38867 +++ b/drivers/tty/tty_port.c
38868 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38869 unsigned long flags;
38870
38871 spin_lock_irqsave(&port->lock, flags);
38872 - port->count = 0;
38873 + atomic_set(&port->count, 0);
38874 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38875 if (port->tty) {
38876 set_bit(TTY_IO_ERROR, &port->tty->flags);
38877 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38878 /* The port lock protects the port counts */
38879 spin_lock_irqsave(&port->lock, flags);
38880 if (!tty_hung_up_p(filp))
38881 - port->count--;
38882 + atomic_dec(&port->count);
38883 port->blocked_open++;
38884 spin_unlock_irqrestore(&port->lock, flags);
38885
38886 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38887 we must not mess that up further */
38888 spin_lock_irqsave(&port->lock, flags);
38889 if (!tty_hung_up_p(filp))
38890 - port->count++;
38891 + atomic_inc(&port->count);
38892 port->blocked_open--;
38893 if (retval == 0)
38894 port->flags |= ASYNC_NORMAL_ACTIVE;
38895 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38896 return 0;
38897 }
38898
38899 - if (tty->count == 1 && port->count != 1) {
38900 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
38901 printk(KERN_WARNING
38902 "tty_port_close_start: tty->count = 1 port count = %d.\n",
38903 - port->count);
38904 - port->count = 1;
38905 + atomic_read(&port->count));
38906 + atomic_set(&port->count, 1);
38907 }
38908 - if (--port->count < 0) {
38909 + if (atomic_dec_return(&port->count) < 0) {
38910 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
38911 - port->count);
38912 - port->count = 0;
38913 + atomic_read(&port->count));
38914 + atomic_set(&port->count, 0);
38915 }
38916
38917 - if (port->count) {
38918 + if (atomic_read(&port->count)) {
38919 spin_unlock_irqrestore(&port->lock, flags);
38920 if (port->ops->drop)
38921 port->ops->drop(port);
38922 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
38923 {
38924 spin_lock_irq(&port->lock);
38925 if (!tty_hung_up_p(filp))
38926 - ++port->count;
38927 + atomic_inc(&port->count);
38928 spin_unlock_irq(&port->lock);
38929 tty_port_tty_set(port, tty);
38930
38931 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
38932 index 770a854..e5d3db3 100644
38933 --- a/drivers/tty/vt/keyboard.c
38934 +++ b/drivers/tty/vt/keyboard.c
38935 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
38936 kbd->kbdmode == VC_OFF) &&
38937 value != KVAL(K_SAK))
38938 return; /* SAK is allowed even in raw mode */
38939 +
38940 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
38941 + {
38942 + void *func = fn_handler[value];
38943 + if (func == fn_show_state || func == fn_show_ptregs ||
38944 + func == fn_show_mem)
38945 + return;
38946 + }
38947 +#endif
38948 +
38949 fn_handler[value](vc);
38950 }
38951
38952 @@ -1805,9 +1815,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38953 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
38954 return -EFAULT;
38955
38956 - if (!capable(CAP_SYS_TTY_CONFIG))
38957 - perm = 0;
38958 -
38959 switch (cmd) {
38960 case KDGKBENT:
38961 /* Ensure another thread doesn't free it under us */
38962 @@ -1822,6 +1829,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
38963 spin_unlock_irqrestore(&kbd_event_lock, flags);
38964 return put_user(val, &user_kbe->kb_value);
38965 case KDSKBENT:
38966 + if (!capable(CAP_SYS_TTY_CONFIG))
38967 + perm = 0;
38968 +
38969 if (!perm)
38970 return -EPERM;
38971 if (!i && v == K_NOSUCHMAP) {
38972 @@ -1912,9 +1922,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38973 int i, j, k;
38974 int ret;
38975
38976 - if (!capable(CAP_SYS_TTY_CONFIG))
38977 - perm = 0;
38978 -
38979 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
38980 if (!kbs) {
38981 ret = -ENOMEM;
38982 @@ -1948,6 +1955,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
38983 kfree(kbs);
38984 return ((p && *p) ? -EOVERFLOW : 0);
38985 case KDSKBSENT:
38986 + if (!capable(CAP_SYS_TTY_CONFIG))
38987 + perm = 0;
38988 +
38989 if (!perm) {
38990 ret = -EPERM;
38991 goto reterr;
38992 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
38993 index a783d53..cb30d94 100644
38994 --- a/drivers/uio/uio.c
38995 +++ b/drivers/uio/uio.c
38996 @@ -25,6 +25,7 @@
38997 #include <linux/kobject.h>
38998 #include <linux/cdev.h>
38999 #include <linux/uio_driver.h>
39000 +#include <asm/local.h>
39001
39002 #define UIO_MAX_DEVICES (1U << MINORBITS)
39003
39004 @@ -32,10 +33,10 @@ struct uio_device {
39005 struct module *owner;
39006 struct device *dev;
39007 int minor;
39008 - atomic_t event;
39009 + atomic_unchecked_t event;
39010 struct fasync_struct *async_queue;
39011 wait_queue_head_t wait;
39012 - int vma_count;
39013 + local_t vma_count;
39014 struct uio_info *info;
39015 struct kobject *map_dir;
39016 struct kobject *portio_dir;
39017 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39018 struct device_attribute *attr, char *buf)
39019 {
39020 struct uio_device *idev = dev_get_drvdata(dev);
39021 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39022 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39023 }
39024
39025 static struct device_attribute uio_class_attributes[] = {
39026 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39027 {
39028 struct uio_device *idev = info->uio_dev;
39029
39030 - atomic_inc(&idev->event);
39031 + atomic_inc_unchecked(&idev->event);
39032 wake_up_interruptible(&idev->wait);
39033 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39034 }
39035 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39036 }
39037
39038 listener->dev = idev;
39039 - listener->event_count = atomic_read(&idev->event);
39040 + listener->event_count = atomic_read_unchecked(&idev->event);
39041 filep->private_data = listener;
39042
39043 if (idev->info->open) {
39044 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39045 return -EIO;
39046
39047 poll_wait(filep, &idev->wait, wait);
39048 - if (listener->event_count != atomic_read(&idev->event))
39049 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39050 return POLLIN | POLLRDNORM;
39051 return 0;
39052 }
39053 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39054 do {
39055 set_current_state(TASK_INTERRUPTIBLE);
39056
39057 - event_count = atomic_read(&idev->event);
39058 + event_count = atomic_read_unchecked(&idev->event);
39059 if (event_count != listener->event_count) {
39060 if (copy_to_user(buf, &event_count, count))
39061 retval = -EFAULT;
39062 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39063 static void uio_vma_open(struct vm_area_struct *vma)
39064 {
39065 struct uio_device *idev = vma->vm_private_data;
39066 - idev->vma_count++;
39067 + local_inc(&idev->vma_count);
39068 }
39069
39070 static void uio_vma_close(struct vm_area_struct *vma)
39071 {
39072 struct uio_device *idev = vma->vm_private_data;
39073 - idev->vma_count--;
39074 + local_dec(&idev->vma_count);
39075 }
39076
39077 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39078 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39079 idev->owner = owner;
39080 idev->info = info;
39081 init_waitqueue_head(&idev->wait);
39082 - atomic_set(&idev->event, 0);
39083 + atomic_set_unchecked(&idev->event, 0);
39084
39085 ret = uio_get_minor(idev);
39086 if (ret)
39087 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39088 index b7eb86a..36d28af 100644
39089 --- a/drivers/usb/atm/cxacru.c
39090 +++ b/drivers/usb/atm/cxacru.c
39091 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39092 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39093 if (ret < 2)
39094 return -EINVAL;
39095 - if (index < 0 || index > 0x7f)
39096 + if (index > 0x7f)
39097 return -EINVAL;
39098 pos += tmp;
39099
39100 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39101 index ee62b35..b663594 100644
39102 --- a/drivers/usb/atm/usbatm.c
39103 +++ b/drivers/usb/atm/usbatm.c
39104 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39105 if (printk_ratelimit())
39106 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39107 __func__, vpi, vci);
39108 - atomic_inc(&vcc->stats->rx_err);
39109 + atomic_inc_unchecked(&vcc->stats->rx_err);
39110 return;
39111 }
39112
39113 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39114 if (length > ATM_MAX_AAL5_PDU) {
39115 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39116 __func__, length, vcc);
39117 - atomic_inc(&vcc->stats->rx_err);
39118 + atomic_inc_unchecked(&vcc->stats->rx_err);
39119 goto out;
39120 }
39121
39122 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39123 if (sarb->len < pdu_length) {
39124 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39125 __func__, pdu_length, sarb->len, vcc);
39126 - atomic_inc(&vcc->stats->rx_err);
39127 + atomic_inc_unchecked(&vcc->stats->rx_err);
39128 goto out;
39129 }
39130
39131 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39132 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39133 __func__, vcc);
39134 - atomic_inc(&vcc->stats->rx_err);
39135 + atomic_inc_unchecked(&vcc->stats->rx_err);
39136 goto out;
39137 }
39138
39139 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39140 if (printk_ratelimit())
39141 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39142 __func__, length);
39143 - atomic_inc(&vcc->stats->rx_drop);
39144 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39145 goto out;
39146 }
39147
39148 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39149
39150 vcc->push(vcc, skb);
39151
39152 - atomic_inc(&vcc->stats->rx);
39153 + atomic_inc_unchecked(&vcc->stats->rx);
39154 out:
39155 skb_trim(sarb, 0);
39156 }
39157 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39158 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39159
39160 usbatm_pop(vcc, skb);
39161 - atomic_inc(&vcc->stats->tx);
39162 + atomic_inc_unchecked(&vcc->stats->tx);
39163
39164 skb = skb_dequeue(&instance->sndqueue);
39165 }
39166 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39167 if (!left--)
39168 return sprintf(page,
39169 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39170 - atomic_read(&atm_dev->stats.aal5.tx),
39171 - atomic_read(&atm_dev->stats.aal5.tx_err),
39172 - atomic_read(&atm_dev->stats.aal5.rx),
39173 - atomic_read(&atm_dev->stats.aal5.rx_err),
39174 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39175 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39176 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39177 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39178 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39179 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39180
39181 if (!left--) {
39182 if (instance->disconnected)
39183 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39184 index 3440812..2a4ef1f 100644
39185 --- a/drivers/usb/core/devices.c
39186 +++ b/drivers/usb/core/devices.c
39187 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39188 * time it gets called.
39189 */
39190 static struct device_connect_event {
39191 - atomic_t count;
39192 + atomic_unchecked_t count;
39193 wait_queue_head_t wait;
39194 } device_event = {
39195 .count = ATOMIC_INIT(1),
39196 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39197
39198 void usbfs_conn_disc_event(void)
39199 {
39200 - atomic_add(2, &device_event.count);
39201 + atomic_add_unchecked(2, &device_event.count);
39202 wake_up(&device_event.wait);
39203 }
39204
39205 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39206
39207 poll_wait(file, &device_event.wait, wait);
39208
39209 - event_count = atomic_read(&device_event.count);
39210 + event_count = atomic_read_unchecked(&device_event.count);
39211 if (file->f_version != event_count) {
39212 file->f_version = event_count;
39213 return POLLIN | POLLRDNORM;
39214 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39215 index 89dcf15..481800b 100644
39216 --- a/drivers/usb/early/ehci-dbgp.c
39217 +++ b/drivers/usb/early/ehci-dbgp.c
39218 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39219
39220 #ifdef CONFIG_KGDB
39221 static struct kgdb_io kgdbdbgp_io_ops;
39222 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39223 +static struct kgdb_io kgdbdbgp_io_ops_console;
39224 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39225 #else
39226 #define dbgp_kgdb_mode (0)
39227 #endif
39228 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39229 .write_char = kgdbdbgp_write_char,
39230 };
39231
39232 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39233 + .name = "kgdbdbgp",
39234 + .read_char = kgdbdbgp_read_char,
39235 + .write_char = kgdbdbgp_write_char,
39236 + .is_console = 1
39237 +};
39238 +
39239 static int kgdbdbgp_wait_time;
39240
39241 static int __init kgdbdbgp_parse_config(char *str)
39242 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39243 ptr++;
39244 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39245 }
39246 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39247 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39248 + if (early_dbgp_console.index != -1)
39249 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39250 + else
39251 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39252
39253 return 0;
39254 }
39255 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39256 index da6d479..80ed10b 100644
39257 --- a/drivers/usb/gadget/u_serial.c
39258 +++ b/drivers/usb/gadget/u_serial.c
39259 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39260 spin_lock_irq(&port->port_lock);
39261
39262 /* already open? Great. */
39263 - if (port->port.count) {
39264 + if (atomic_read(&port->port.count)) {
39265 status = 0;
39266 - port->port.count++;
39267 + atomic_inc(&port->port.count);
39268
39269 /* currently opening/closing? wait ... */
39270 } else if (port->openclose) {
39271 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39272 tty->driver_data = port;
39273 port->port.tty = tty;
39274
39275 - port->port.count = 1;
39276 + atomic_set(&port->port.count, 1);
39277 port->openclose = false;
39278
39279 /* if connected, start the I/O stream */
39280 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39281
39282 spin_lock_irq(&port->port_lock);
39283
39284 - if (port->port.count != 1) {
39285 - if (port->port.count == 0)
39286 + if (atomic_read(&port->port.count) != 1) {
39287 + if (atomic_read(&port->port.count) == 0)
39288 WARN_ON(1);
39289 else
39290 - --port->port.count;
39291 + atomic_dec(&port->port.count);
39292 goto exit;
39293 }
39294
39295 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39296 * and sleep if necessary
39297 */
39298 port->openclose = true;
39299 - port->port.count = 0;
39300 + atomic_set(&port->port.count, 0);
39301
39302 gser = port->port_usb;
39303 if (gser && gser->disconnect)
39304 @@ -1156,7 +1156,7 @@ static int gs_closed(struct gs_port *port)
39305 int cond;
39306
39307 spin_lock_irq(&port->port_lock);
39308 - cond = (port->port.count == 0) && !port->openclose;
39309 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39310 spin_unlock_irq(&port->port_lock);
39311 return cond;
39312 }
39313 @@ -1269,7 +1269,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39314 /* if it's already open, start I/O ... and notify the serial
39315 * protocol about open/close status (connect/disconnect).
39316 */
39317 - if (port->port.count) {
39318 + if (atomic_read(&port->port.count)) {
39319 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39320 gs_start_io(port);
39321 if (gser->connect)
39322 @@ -1316,7 +1316,7 @@ void gserial_disconnect(struct gserial *gser)
39323
39324 port->port_usb = NULL;
39325 gser->ioport = NULL;
39326 - if (port->port.count > 0 || port->openclose) {
39327 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39328 wake_up_interruptible(&port->drain_wait);
39329 if (port->port.tty)
39330 tty_hangup(port->port.tty);
39331 @@ -1332,7 +1332,7 @@ void gserial_disconnect(struct gserial *gser)
39332
39333 /* finally, free any unused/unusable I/O buffers */
39334 spin_lock_irqsave(&port->port_lock, flags);
39335 - if (port->port.count == 0 && !port->openclose)
39336 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39337 gs_buf_free(&port->port_write_buf);
39338 gs_free_requests(gser->out, &port->read_pool, NULL);
39339 gs_free_requests(gser->out, &port->read_queue, NULL);
39340 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39341 index b9cca6d..75c75df 100644
39342 --- a/drivers/usb/serial/console.c
39343 +++ b/drivers/usb/serial/console.c
39344 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39345
39346 info->port = port;
39347
39348 - ++port->port.count;
39349 + atomic_inc(&port->port.count);
39350 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39351 if (serial->type->set_termios) {
39352 /*
39353 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39354 }
39355 /* Now that any required fake tty operations are completed restore
39356 * the tty port count */
39357 - --port->port.count;
39358 + atomic_dec(&port->port.count);
39359 /* The console is special in terms of closing the device so
39360 * indicate this port is now acting as a system console. */
39361 port->port.console = 1;
39362 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39363 free_tty:
39364 kfree(tty);
39365 reset_open_count:
39366 - port->port.count = 0;
39367 + atomic_set(&port->port.count, 0);
39368 usb_autopm_put_interface(serial->interface);
39369 error_get_interface:
39370 usb_serial_put(serial);
39371 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39372 index d6bea3e..60b250e 100644
39373 --- a/drivers/usb/wusbcore/wa-hc.h
39374 +++ b/drivers/usb/wusbcore/wa-hc.h
39375 @@ -192,7 +192,7 @@ struct wahc {
39376 struct list_head xfer_delayed_list;
39377 spinlock_t xfer_list_lock;
39378 struct work_struct xfer_work;
39379 - atomic_t xfer_id_count;
39380 + atomic_unchecked_t xfer_id_count;
39381 };
39382
39383
39384 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39385 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39386 spin_lock_init(&wa->xfer_list_lock);
39387 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39388 - atomic_set(&wa->xfer_id_count, 1);
39389 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39390 }
39391
39392 /**
39393 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39394 index 57c01ab..8a05959 100644
39395 --- a/drivers/usb/wusbcore/wa-xfer.c
39396 +++ b/drivers/usb/wusbcore/wa-xfer.c
39397 @@ -296,7 +296,7 @@ out:
39398 */
39399 static void wa_xfer_id_init(struct wa_xfer *xfer)
39400 {
39401 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39402 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39403 }
39404
39405 /*
39406 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39407 index ef82a0d..da8a0b3 100644
39408 --- a/drivers/vhost/vhost.c
39409 +++ b/drivers/vhost/vhost.c
39410 @@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39411 return 0;
39412 }
39413
39414 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39415 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39416 {
39417 struct file *eventfp, *filep = NULL,
39418 *pollstart = NULL, *pollstop = NULL;
39419 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39420 index 747442d..7c0c434 100644
39421 --- a/drivers/video/aty/aty128fb.c
39422 +++ b/drivers/video/aty/aty128fb.c
39423 @@ -149,7 +149,7 @@ enum {
39424 };
39425
39426 /* Must match above enum */
39427 -static const char *r128_family[] __devinitdata = {
39428 +static const char *r128_family[] __devinitconst = {
39429 "AGP",
39430 "PCI",
39431 "PRO AGP",
39432 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39433 index 5c3960d..15cf8fc 100644
39434 --- a/drivers/video/fbcmap.c
39435 +++ b/drivers/video/fbcmap.c
39436 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39437 rc = -ENODEV;
39438 goto out;
39439 }
39440 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39441 - !info->fbops->fb_setcmap)) {
39442 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39443 rc = -EINVAL;
39444 goto out1;
39445 }
39446 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39447 index 0dff12a..2ef47b3 100644
39448 --- a/drivers/video/fbmem.c
39449 +++ b/drivers/video/fbmem.c
39450 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39451 image->dx += image->width + 8;
39452 }
39453 } else if (rotate == FB_ROTATE_UD) {
39454 - for (x = 0; x < num && image->dx >= 0; x++) {
39455 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39456 info->fbops->fb_imageblit(info, image);
39457 image->dx -= image->width + 8;
39458 }
39459 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39460 image->dy += image->height + 8;
39461 }
39462 } else if (rotate == FB_ROTATE_CCW) {
39463 - for (x = 0; x < num && image->dy >= 0; x++) {
39464 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39465 info->fbops->fb_imageblit(info, image);
39466 image->dy -= image->height + 8;
39467 }
39468 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39469 return -EFAULT;
39470 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39471 return -EINVAL;
39472 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39473 + if (con2fb.framebuffer >= FB_MAX)
39474 return -EINVAL;
39475 if (!registered_fb[con2fb.framebuffer])
39476 request_module("fb%d", con2fb.framebuffer);
39477 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39478 index 5a5d092..265c5ed 100644
39479 --- a/drivers/video/geode/gx1fb_core.c
39480 +++ b/drivers/video/geode/gx1fb_core.c
39481 @@ -29,7 +29,7 @@ static int crt_option = 1;
39482 static char panel_option[32] = "";
39483
39484 /* Modes relevant to the GX1 (taken from modedb.c) */
39485 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39486 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39487 /* 640x480-60 VESA */
39488 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39489 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39490 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39491 index 0fad23f..0e9afa4 100644
39492 --- a/drivers/video/gxt4500.c
39493 +++ b/drivers/video/gxt4500.c
39494 @@ -156,7 +156,7 @@ struct gxt4500_par {
39495 static char *mode_option;
39496
39497 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39498 -static const struct fb_videomode defaultmode __devinitdata = {
39499 +static const struct fb_videomode defaultmode __devinitconst = {
39500 .refresh = 60,
39501 .xres = 1280,
39502 .yres = 1024,
39503 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39504 return 0;
39505 }
39506
39507 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39508 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39509 .id = "IBM GXT4500P",
39510 .type = FB_TYPE_PACKED_PIXELS,
39511 .visual = FB_VISUAL_PSEUDOCOLOR,
39512 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39513 index 7672d2e..b56437f 100644
39514 --- a/drivers/video/i810/i810_accel.c
39515 +++ b/drivers/video/i810/i810_accel.c
39516 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39517 }
39518 }
39519 printk("ringbuffer lockup!!!\n");
39520 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39521 i810_report_error(mmio);
39522 par->dev_flags |= LOCKUP;
39523 info->pixmap.scan_align = 1;
39524 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39525 index b83f361..2b05a91 100644
39526 --- a/drivers/video/i810/i810_main.c
39527 +++ b/drivers/video/i810/i810_main.c
39528 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39529 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39530
39531 /* PCI */
39532 -static const char *i810_pci_list[] __devinitdata = {
39533 +static const char *i810_pci_list[] __devinitconst = {
39534 "Intel(R) 810 Framebuffer Device" ,
39535 "Intel(R) 810-DC100 Framebuffer Device" ,
39536 "Intel(R) 810E Framebuffer Device" ,
39537 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39538 index de36693..3c63fc2 100644
39539 --- a/drivers/video/jz4740_fb.c
39540 +++ b/drivers/video/jz4740_fb.c
39541 @@ -136,7 +136,7 @@ struct jzfb {
39542 uint32_t pseudo_palette[16];
39543 };
39544
39545 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39546 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39547 .id = "JZ4740 FB",
39548 .type = FB_TYPE_PACKED_PIXELS,
39549 .visual = FB_VISUAL_TRUECOLOR,
39550 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39551 index 3c14e43..eafa544 100644
39552 --- a/drivers/video/logo/logo_linux_clut224.ppm
39553 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39554 @@ -1,1604 +1,1123 @@
39555 P3
39556 -# Standard 224-color Linux logo
39557 80 80
39558 255
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 - 6 6 6 6 6 6 10 10 10 10 10 10
39569 - 10 10 10 6 6 6 6 6 6 6 6 6
39570 - 0 0 0 0 0 0 0 0 0 0 0 0
39571 - 0 0 0 0 0 0 0 0 0 0 0 0
39572 - 0 0 0 0 0 0 0 0 0 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 0 0 0 0 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 6 6 6 10 10 10 14 14 14
39588 - 22 22 22 26 26 26 30 30 30 34 34 34
39589 - 30 30 30 30 30 30 26 26 26 18 18 18
39590 - 14 14 14 10 10 10 6 6 6 0 0 0
39591 - 0 0 0 0 0 0 0 0 0 0 0 0
39592 - 0 0 0 0 0 0 0 0 0 0 0 0
39593 - 0 0 0 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 1 0 0 1 0 0 0
39601 - 0 0 0 0 0 0 0 0 0 0 0 0
39602 - 0 0 0 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 - 6 6 6 14 14 14 26 26 26 42 42 42
39608 - 54 54 54 66 66 66 78 78 78 78 78 78
39609 - 78 78 78 74 74 74 66 66 66 54 54 54
39610 - 42 42 42 26 26 26 18 18 18 10 10 10
39611 - 6 6 6 0 0 0 0 0 0 0 0 0
39612 - 0 0 0 0 0 0 0 0 0 0 0 0
39613 - 0 0 0 0 0 0 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 1 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 0 0 0 0 0 0 0 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 10 10 10
39627 - 22 22 22 42 42 42 66 66 66 86 86 86
39628 - 66 66 66 38 38 38 38 38 38 22 22 22
39629 - 26 26 26 34 34 34 54 54 54 66 66 66
39630 - 86 86 86 70 70 70 46 46 46 26 26 26
39631 - 14 14 14 6 6 6 0 0 0 0 0 0
39632 - 0 0 0 0 0 0 0 0 0 0 0 0
39633 - 0 0 0 0 0 0 0 0 0 0 0 0
39634 - 0 0 0 0 0 0 0 0 0 0 0 0
39635 - 0 0 0 0 0 0 0 0 0 0 0 0
39636 - 0 0 0 0 0 0 0 0 0 0 0 0
39637 - 0 0 0 0 0 0 0 0 0 0 0 0
39638 - 0 0 0 0 0 0 0 0 0 0 0 0
39639 - 0 0 0 0 0 0 0 0 0 0 0 0
39640 - 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
39647 - 50 50 50 82 82 82 58 58 58 6 6 6
39648 - 2 2 6 2 2 6 2 2 6 2 2 6
39649 - 2 2 6 2 2 6 2 2 6 2 2 6
39650 - 6 6 6 54 54 54 86 86 86 66 66 66
39651 - 38 38 38 18 18 18 6 6 6 0 0 0
39652 - 0 0 0 0 0 0 0 0 0 0 0 0
39653 - 0 0 0 0 0 0 0 0 0 0 0 0
39654 - 0 0 0 0 0 0 0 0 0 0 0 0
39655 - 0 0 0 0 0 0 0 0 0 0 0 0
39656 - 0 0 0 0 0 0 0 0 0 0 0 0
39657 - 0 0 0 0 0 0 0 0 0 0 0 0
39658 - 0 0 0 0 0 0 0 0 0 0 0 0
39659 - 0 0 0 0 0 0 0 0 0 0 0 0
39660 - 0 0 0 0 0 0 0 0 0 0 0 0
39661 - 0 0 0 0 0 0 0 0 0 0 0 0
39662 - 0 0 0 0 0 0 0 0 0 0 0 0
39663 - 0 0 0 0 0 0 0 0 0 0 0 0
39664 - 0 0 0 0 0 0 0 0 0 0 0 0
39665 - 0 0 0 0 0 0 0 0 0 0 0 0
39666 - 0 0 0 6 6 6 22 22 22 50 50 50
39667 - 78 78 78 34 34 34 2 2 6 2 2 6
39668 - 2 2 6 2 2 6 2 2 6 2 2 6
39669 - 2 2 6 2 2 6 2 2 6 2 2 6
39670 - 2 2 6 2 2 6 6 6 6 70 70 70
39671 - 78 78 78 46 46 46 22 22 22 6 6 6
39672 - 0 0 0 0 0 0 0 0 0 0 0 0
39673 - 0 0 0 0 0 0 0 0 0 0 0 0
39674 - 0 0 0 0 0 0 0 0 0 0 0 0
39675 - 0 0 0 0 0 0 0 0 0 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 0 0 0 0 0 0 0 0 0
39680 - 0 0 1 0 0 1 0 0 1 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 0 0 0 0 0 0 0 0 0 0 0 0
39685 - 0 0 0 0 0 0 0 0 0 0 0 0
39686 - 6 6 6 18 18 18 42 42 42 82 82 82
39687 - 26 26 26 2 2 6 2 2 6 2 2 6
39688 - 2 2 6 2 2 6 2 2 6 2 2 6
39689 - 2 2 6 2 2 6 2 2 6 14 14 14
39690 - 46 46 46 34 34 34 6 6 6 2 2 6
39691 - 42 42 42 78 78 78 42 42 42 18 18 18
39692 - 6 6 6 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 1 0 0 0 0 0 1 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 0 0 0 0 0 0 0 0 0
39704 - 0 0 0 0 0 0 0 0 0 0 0 0
39705 - 0 0 0 0 0 0 0 0 0 0 0 0
39706 - 10 10 10 30 30 30 66 66 66 58 58 58
39707 - 2 2 6 2 2 6 2 2 6 2 2 6
39708 - 2 2 6 2 2 6 2 2 6 2 2 6
39709 - 2 2 6 2 2 6 2 2 6 26 26 26
39710 - 86 86 86 101 101 101 46 46 46 10 10 10
39711 - 2 2 6 58 58 58 70 70 70 34 34 34
39712 - 10 10 10 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 0 0 0
39715 - 0 0 0 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 0 0 0 0 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 1 0 0 1 0 0 1 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 - 14 14 14 42 42 42 86 86 86 10 10 10
39727 - 2 2 6 2 2 6 2 2 6 2 2 6
39728 - 2 2 6 2 2 6 2 2 6 2 2 6
39729 - 2 2 6 2 2 6 2 2 6 30 30 30
39730 - 94 94 94 94 94 94 58 58 58 26 26 26
39731 - 2 2 6 6 6 6 78 78 78 54 54 54
39732 - 22 22 22 6 6 6 0 0 0 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 0 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 0 0 0
39743 - 0 0 0 0 0 0 0 0 0 0 0 0
39744 - 0 0 0 0 0 0 0 0 0 0 0 0
39745 - 0 0 0 0 0 0 0 0 0 6 6 6
39746 - 22 22 22 62 62 62 62 62 62 2 2 6
39747 - 2 2 6 2 2 6 2 2 6 2 2 6
39748 - 2 2 6 2 2 6 2 2 6 2 2 6
39749 - 2 2 6 2 2 6 2 2 6 26 26 26
39750 - 54 54 54 38 38 38 18 18 18 10 10 10
39751 - 2 2 6 2 2 6 34 34 34 82 82 82
39752 - 38 38 38 14 14 14 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 0 0 0 0 0 0 0 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 1 0 0 1 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 0 0 0 0 0 0
39763 - 0 0 0 0 0 0 0 0 0 0 0 0
39764 - 0 0 0 0 0 0 0 0 0 0 0 0
39765 - 0 0 0 0 0 0 0 0 0 6 6 6
39766 - 30 30 30 78 78 78 30 30 30 2 2 6
39767 - 2 2 6 2 2 6 2 2 6 2 2 6
39768 - 2 2 6 2 2 6 2 2 6 2 2 6
39769 - 2 2 6 2 2 6 2 2 6 10 10 10
39770 - 10 10 10 2 2 6 2 2 6 2 2 6
39771 - 2 2 6 2 2 6 2 2 6 78 78 78
39772 - 50 50 50 18 18 18 6 6 6 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 1 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 0 0 0 0 0 0 0 0 0
39783 - 0 0 0 0 0 0 0 0 0 0 0 0
39784 - 0 0 0 0 0 0 0 0 0 0 0 0
39785 - 0 0 0 0 0 0 0 0 0 10 10 10
39786 - 38 38 38 86 86 86 14 14 14 2 2 6
39787 - 2 2 6 2 2 6 2 2 6 2 2 6
39788 - 2 2 6 2 2 6 2 2 6 2 2 6
39789 - 2 2 6 2 2 6 2 2 6 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 54 54 54
39792 - 66 66 66 26 26 26 6 6 6 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 0 0 0 0 0 0 0 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 1 0 0 1 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 0 0 0 0 0 0 0 0 0 0 0 0
39803 - 0 0 0 0 0 0 0 0 0 0 0 0
39804 - 0 0 0 0 0 0 0 0 0 0 0 0
39805 - 0 0 0 0 0 0 0 0 0 14 14 14
39806 - 42 42 42 82 82 82 2 2 6 2 2 6
39807 - 2 2 6 6 6 6 10 10 10 2 2 6
39808 - 2 2 6 2 2 6 2 2 6 2 2 6
39809 - 2 2 6 2 2 6 2 2 6 6 6 6
39810 - 14 14 14 10 10 10 2 2 6 2 2 6
39811 - 2 2 6 2 2 6 2 2 6 18 18 18
39812 - 82 82 82 34 34 34 10 10 10 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 0 0 0 0 0 0 0 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 1 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 0 0 0 0 0 0 0 0 0 0 0 0
39823 - 0 0 0 0 0 0 0 0 0 0 0 0
39824 - 0 0 0 0 0 0 0 0 0 0 0 0
39825 - 0 0 0 0 0 0 0 0 0 14 14 14
39826 - 46 46 46 86 86 86 2 2 6 2 2 6
39827 - 6 6 6 6 6 6 22 22 22 34 34 34
39828 - 6 6 6 2 2 6 2 2 6 2 2 6
39829 - 2 2 6 2 2 6 18 18 18 34 34 34
39830 - 10 10 10 50 50 50 22 22 22 2 2 6
39831 - 2 2 6 2 2 6 2 2 6 10 10 10
39832 - 86 86 86 42 42 42 14 14 14 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 0 0 0 0 0 0 0 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39846 - 46 46 46 86 86 86 2 2 6 2 2 6
39847 - 38 38 38 116 116 116 94 94 94 22 22 22
39848 - 22 22 22 2 2 6 2 2 6 2 2 6
39849 - 14 14 14 86 86 86 138 138 138 162 162 162
39850 -154 154 154 38 38 38 26 26 26 6 6 6
39851 - 2 2 6 2 2 6 2 2 6 2 2 6
39852 - 86 86 86 46 46 46 14 14 14 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 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 0 0 0 0
39862 - 0 0 0 0 0 0 0 0 0 0 0 0
39863 - 0 0 0 0 0 0 0 0 0 0 0 0
39864 - 0 0 0 0 0 0 0 0 0 0 0 0
39865 - 0 0 0 0 0 0 0 0 0 14 14 14
39866 - 46 46 46 86 86 86 2 2 6 14 14 14
39867 -134 134 134 198 198 198 195 195 195 116 116 116
39868 - 10 10 10 2 2 6 2 2 6 6 6 6
39869 -101 98 89 187 187 187 210 210 210 218 218 218
39870 -214 214 214 134 134 134 14 14 14 6 6 6
39871 - 2 2 6 2 2 6 2 2 6 2 2 6
39872 - 86 86 86 50 50 50 18 18 18 6 6 6
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 0 0 0 0 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 1 0 0 0
39880 - 0 0 1 0 0 1 0 0 1 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 14 14 14
39886 - 46 46 46 86 86 86 2 2 6 54 54 54
39887 -218 218 218 195 195 195 226 226 226 246 246 246
39888 - 58 58 58 2 2 6 2 2 6 30 30 30
39889 -210 210 210 253 253 253 174 174 174 123 123 123
39890 -221 221 221 234 234 234 74 74 74 2 2 6
39891 - 2 2 6 2 2 6 2 2 6 2 2 6
39892 - 70 70 70 58 58 58 22 22 22 6 6 6
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 0 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 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 0 0 0 0
39902 - 0 0 0 0 0 0 0 0 0 0 0 0
39903 - 0 0 0 0 0 0 0 0 0 0 0 0
39904 - 0 0 0 0 0 0 0 0 0 0 0 0
39905 - 0 0 0 0 0 0 0 0 0 14 14 14
39906 - 46 46 46 82 82 82 2 2 6 106 106 106
39907 -170 170 170 26 26 26 86 86 86 226 226 226
39908 -123 123 123 10 10 10 14 14 14 46 46 46
39909 -231 231 231 190 190 190 6 6 6 70 70 70
39910 - 90 90 90 238 238 238 158 158 158 2 2 6
39911 - 2 2 6 2 2 6 2 2 6 2 2 6
39912 - 70 70 70 58 58 58 22 22 22 6 6 6
39913 - 0 0 0 0 0 0 0 0 0 0 0 0
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 0 0 0 0 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 1 0 0 0
39920 - 0 0 1 0 0 1 0 0 1 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 0 0 0
39922 - 0 0 0 0 0 0 0 0 0 0 0 0
39923 - 0 0 0 0 0 0 0 0 0 0 0 0
39924 - 0 0 0 0 0 0 0 0 0 0 0 0
39925 - 0 0 0 0 0 0 0 0 0 14 14 14
39926 - 42 42 42 86 86 86 6 6 6 116 116 116
39927 -106 106 106 6 6 6 70 70 70 149 149 149
39928 -128 128 128 18 18 18 38 38 38 54 54 54
39929 -221 221 221 106 106 106 2 2 6 14 14 14
39930 - 46 46 46 190 190 190 198 198 198 2 2 6
39931 - 2 2 6 2 2 6 2 2 6 2 2 6
39932 - 74 74 74 62 62 62 22 22 22 6 6 6
39933 - 0 0 0 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 0 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 1 0 0 0
39940 - 0 0 1 0 0 0 0 0 1 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 0 0 0
39942 - 0 0 0 0 0 0 0 0 0 0 0 0
39943 - 0 0 0 0 0 0 0 0 0 0 0 0
39944 - 0 0 0 0 0 0 0 0 0 0 0 0
39945 - 0 0 0 0 0 0 0 0 0 14 14 14
39946 - 42 42 42 94 94 94 14 14 14 101 101 101
39947 -128 128 128 2 2 6 18 18 18 116 116 116
39948 -118 98 46 121 92 8 121 92 8 98 78 10
39949 -162 162 162 106 106 106 2 2 6 2 2 6
39950 - 2 2 6 195 195 195 195 195 195 6 6 6
39951 - 2 2 6 2 2 6 2 2 6 2 2 6
39952 - 74 74 74 62 62 62 22 22 22 6 6 6
39953 - 0 0 0 0 0 0 0 0 0 0 0 0
39954 - 0 0 0 0 0 0 0 0 0 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 0 0 0 0 0 0 0 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 1 0 0 1
39960 - 0 0 1 0 0 0 0 0 1 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 10 10 10
39966 - 38 38 38 90 90 90 14 14 14 58 58 58
39967 -210 210 210 26 26 26 54 38 6 154 114 10
39968 -226 170 11 236 186 11 225 175 15 184 144 12
39969 -215 174 15 175 146 61 37 26 9 2 2 6
39970 - 70 70 70 246 246 246 138 138 138 2 2 6
39971 - 2 2 6 2 2 6 2 2 6 2 2 6
39972 - 70 70 70 66 66 66 26 26 26 6 6 6
39973 - 0 0 0 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 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 10 10 10
39986 - 38 38 38 86 86 86 14 14 14 10 10 10
39987 -195 195 195 188 164 115 192 133 9 225 175 15
39988 -239 182 13 234 190 10 232 195 16 232 200 30
39989 -245 207 45 241 208 19 232 195 16 184 144 12
39990 -218 194 134 211 206 186 42 42 42 2 2 6
39991 - 2 2 6 2 2 6 2 2 6 2 2 6
39992 - 50 50 50 74 74 74 30 30 30 6 6 6
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 0 0 0 0
39996 - 0 0 0 0 0 0 0 0 0 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 0 0 0
40002 - 0 0 0 0 0 0 0 0 0 0 0 0
40003 - 0 0 0 0 0 0 0 0 0 0 0 0
40004 - 0 0 0 0 0 0 0 0 0 0 0 0
40005 - 0 0 0 0 0 0 0 0 0 10 10 10
40006 - 34 34 34 86 86 86 14 14 14 2 2 6
40007 -121 87 25 192 133 9 219 162 10 239 182 13
40008 -236 186 11 232 195 16 241 208 19 244 214 54
40009 -246 218 60 246 218 38 246 215 20 241 208 19
40010 -241 208 19 226 184 13 121 87 25 2 2 6
40011 - 2 2 6 2 2 6 2 2 6 2 2 6
40012 - 50 50 50 82 82 82 34 34 34 10 10 10
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 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 10 10 10
40026 - 34 34 34 82 82 82 30 30 30 61 42 6
40027 -180 123 7 206 145 10 230 174 11 239 182 13
40028 -234 190 10 238 202 15 241 208 19 246 218 74
40029 -246 218 38 246 215 20 246 215 20 246 215 20
40030 -226 184 13 215 174 15 184 144 12 6 6 6
40031 - 2 2 6 2 2 6 2 2 6 2 2 6
40032 - 26 26 26 94 94 94 42 42 42 14 14 14
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 0 0 0 0
40036 - 0 0 0 0 0 0 0 0 0 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 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 10 10 10
40046 - 30 30 30 78 78 78 50 50 50 104 69 6
40047 -192 133 9 216 158 10 236 178 12 236 186 11
40048 -232 195 16 241 208 19 244 214 54 245 215 43
40049 -246 215 20 246 215 20 241 208 19 198 155 10
40050 -200 144 11 216 158 10 156 118 10 2 2 6
40051 - 2 2 6 2 2 6 2 2 6 2 2 6
40052 - 6 6 6 90 90 90 54 54 54 18 18 18
40053 - 6 6 6 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 0 0 0 0
40056 - 0 0 0 0 0 0 0 0 0 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 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 10 10 10
40066 - 30 30 30 78 78 78 46 46 46 22 22 22
40067 -137 92 6 210 162 10 239 182 13 238 190 10
40068 -238 202 15 241 208 19 246 215 20 246 215 20
40069 -241 208 19 203 166 17 185 133 11 210 150 10
40070 -216 158 10 210 150 10 102 78 10 2 2 6
40071 - 6 6 6 54 54 54 14 14 14 2 2 6
40072 - 2 2 6 62 62 62 74 74 74 30 30 30
40073 - 10 10 10 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 0 0 0 0
40076 - 0 0 0 0 0 0 0 0 0 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 0 0 0
40082 - 0 0 0 0 0 0 0 0 0 0 0 0
40083 - 0 0 0 0 0 0 0 0 0 0 0 0
40084 - 0 0 0 0 0 0 0 0 0 0 0 0
40085 - 0 0 0 0 0 0 0 0 0 10 10 10
40086 - 34 34 34 78 78 78 50 50 50 6 6 6
40087 - 94 70 30 139 102 15 190 146 13 226 184 13
40088 -232 200 30 232 195 16 215 174 15 190 146 13
40089 -168 122 10 192 133 9 210 150 10 213 154 11
40090 -202 150 34 182 157 106 101 98 89 2 2 6
40091 - 2 2 6 78 78 78 116 116 116 58 58 58
40092 - 2 2 6 22 22 22 90 90 90 46 46 46
40093 - 18 18 18 6 6 6 0 0 0 0 0 0
40094 - 0 0 0 0 0 0 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 0 0 0
40102 - 0 0 0 0 0 0 0 0 0 0 0 0
40103 - 0 0 0 0 0 0 0 0 0 0 0 0
40104 - 0 0 0 0 0 0 0 0 0 0 0 0
40105 - 0 0 0 0 0 0 0 0 0 10 10 10
40106 - 38 38 38 86 86 86 50 50 50 6 6 6
40107 -128 128 128 174 154 114 156 107 11 168 122 10
40108 -198 155 10 184 144 12 197 138 11 200 144 11
40109 -206 145 10 206 145 10 197 138 11 188 164 115
40110 -195 195 195 198 198 198 174 174 174 14 14 14
40111 - 2 2 6 22 22 22 116 116 116 116 116 116
40112 - 22 22 22 2 2 6 74 74 74 70 70 70
40113 - 30 30 30 10 10 10 0 0 0 0 0 0
40114 - 0 0 0 0 0 0 0 0 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 0 0 0
40122 - 0 0 0 0 0 0 0 0 0 0 0 0
40123 - 0 0 0 0 0 0 0 0 0 0 0 0
40124 - 0 0 0 0 0 0 0 0 0 0 0 0
40125 - 0 0 0 0 0 0 6 6 6 18 18 18
40126 - 50 50 50 101 101 101 26 26 26 10 10 10
40127 -138 138 138 190 190 190 174 154 114 156 107 11
40128 -197 138 11 200 144 11 197 138 11 192 133 9
40129 -180 123 7 190 142 34 190 178 144 187 187 187
40130 -202 202 202 221 221 221 214 214 214 66 66 66
40131 - 2 2 6 2 2 6 50 50 50 62 62 62
40132 - 6 6 6 2 2 6 10 10 10 90 90 90
40133 - 50 50 50 18 18 18 6 6 6 0 0 0
40134 - 0 0 0 0 0 0 0 0 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 0 0 0
40142 - 0 0 0 0 0 0 0 0 0 0 0 0
40143 - 0 0 0 0 0 0 0 0 0 0 0 0
40144 - 0 0 0 0 0 0 0 0 0 0 0 0
40145 - 0 0 0 0 0 0 10 10 10 34 34 34
40146 - 74 74 74 74 74 74 2 2 6 6 6 6
40147 -144 144 144 198 198 198 190 190 190 178 166 146
40148 -154 121 60 156 107 11 156 107 11 168 124 44
40149 -174 154 114 187 187 187 190 190 190 210 210 210
40150 -246 246 246 253 253 253 253 253 253 182 182 182
40151 - 6 6 6 2 2 6 2 2 6 2 2 6
40152 - 2 2 6 2 2 6 2 2 6 62 62 62
40153 - 74 74 74 34 34 34 14 14 14 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 0 0 0
40162 - 0 0 0 0 0 0 0 0 0 0 0 0
40163 - 0 0 0 0 0 0 0 0 0 0 0 0
40164 - 0 0 0 0 0 0 0 0 0 0 0 0
40165 - 0 0 0 10 10 10 22 22 22 54 54 54
40166 - 94 94 94 18 18 18 2 2 6 46 46 46
40167 -234 234 234 221 221 221 190 190 190 190 190 190
40168 -190 190 190 187 187 187 187 187 187 190 190 190
40169 -190 190 190 195 195 195 214 214 214 242 242 242
40170 -253 253 253 253 253 253 253 253 253 253 253 253
40171 - 82 82 82 2 2 6 2 2 6 2 2 6
40172 - 2 2 6 2 2 6 2 2 6 14 14 14
40173 - 86 86 86 54 54 54 22 22 22 6 6 6
40174 - 0 0 0 0 0 0 0 0 0 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 0 0 0
40182 - 0 0 0 0 0 0 0 0 0 0 0 0
40183 - 0 0 0 0 0 0 0 0 0 0 0 0
40184 - 0 0 0 0 0 0 0 0 0 0 0 0
40185 - 6 6 6 18 18 18 46 46 46 90 90 90
40186 - 46 46 46 18 18 18 6 6 6 182 182 182
40187 -253 253 253 246 246 246 206 206 206 190 190 190
40188 -190 190 190 190 190 190 190 190 190 190 190 190
40189 -206 206 206 231 231 231 250 250 250 253 253 253
40190 -253 253 253 253 253 253 253 253 253 253 253 253
40191 -202 202 202 14 14 14 2 2 6 2 2 6
40192 - 2 2 6 2 2 6 2 2 6 2 2 6
40193 - 42 42 42 86 86 86 42 42 42 18 18 18
40194 - 6 6 6 0 0 0 0 0 0 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 0 0 0
40202 - 0 0 0 0 0 0 0 0 0 0 0 0
40203 - 0 0 0 0 0 0 0 0 0 0 0 0
40204 - 0 0 0 0 0 0 0 0 0 6 6 6
40205 - 14 14 14 38 38 38 74 74 74 66 66 66
40206 - 2 2 6 6 6 6 90 90 90 250 250 250
40207 -253 253 253 253 253 253 238 238 238 198 198 198
40208 -190 190 190 190 190 190 195 195 195 221 221 221
40209 -246 246 246 253 253 253 253 253 253 253 253 253
40210 -253 253 253 253 253 253 253 253 253 253 253 253
40211 -253 253 253 82 82 82 2 2 6 2 2 6
40212 - 2 2 6 2 2 6 2 2 6 2 2 6
40213 - 2 2 6 78 78 78 70 70 70 34 34 34
40214 - 14 14 14 6 6 6 0 0 0 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 0 0 0
40222 - 0 0 0 0 0 0 0 0 0 0 0 0
40223 - 0 0 0 0 0 0 0 0 0 0 0 0
40224 - 0 0 0 0 0 0 0 0 0 14 14 14
40225 - 34 34 34 66 66 66 78 78 78 6 6 6
40226 - 2 2 6 18 18 18 218 218 218 253 253 253
40227 -253 253 253 253 253 253 253 253 253 246 246 246
40228 -226 226 226 231 231 231 246 246 246 253 253 253
40229 -253 253 253 253 253 253 253 253 253 253 253 253
40230 -253 253 253 253 253 253 253 253 253 253 253 253
40231 -253 253 253 178 178 178 2 2 6 2 2 6
40232 - 2 2 6 2 2 6 2 2 6 2 2 6
40233 - 2 2 6 18 18 18 90 90 90 62 62 62
40234 - 30 30 30 10 10 10 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 0 0 0 0 0 0
40242 - 0 0 0 0 0 0 0 0 0 0 0 0
40243 - 0 0 0 0 0 0 0 0 0 0 0 0
40244 - 0 0 0 0 0 0 10 10 10 26 26 26
40245 - 58 58 58 90 90 90 18 18 18 2 2 6
40246 - 2 2 6 110 110 110 253 253 253 253 253 253
40247 -253 253 253 253 253 253 253 253 253 253 253 253
40248 -250 250 250 253 253 253 253 253 253 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 231 231 231 18 18 18 2 2 6
40252 - 2 2 6 2 2 6 2 2 6 2 2 6
40253 - 2 2 6 2 2 6 18 18 18 94 94 94
40254 - 54 54 54 26 26 26 10 10 10 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 0 0 0 0 0 0
40262 - 0 0 0 0 0 0 0 0 0 0 0 0
40263 - 0 0 0 0 0 0 0 0 0 0 0 0
40264 - 0 0 0 6 6 6 22 22 22 50 50 50
40265 - 90 90 90 26 26 26 2 2 6 2 2 6
40266 - 14 14 14 195 195 195 250 250 250 253 253 253
40267 -253 253 253 253 253 253 253 253 253 253 253 253
40268 -253 253 253 253 253 253 253 253 253 253 253 253
40269 -253 253 253 253 253 253 253 253 253 253 253 253
40270 -253 253 253 253 253 253 253 253 253 253 253 253
40271 -250 250 250 242 242 242 54 54 54 2 2 6
40272 - 2 2 6 2 2 6 2 2 6 2 2 6
40273 - 2 2 6 2 2 6 2 2 6 38 38 38
40274 - 86 86 86 50 50 50 22 22 22 6 6 6
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 0 0 0 0 0 0 0 0 0
40282 - 0 0 0 0 0 0 0 0 0 0 0 0
40283 - 0 0 0 0 0 0 0 0 0 0 0 0
40284 - 6 6 6 14 14 14 38 38 38 82 82 82
40285 - 34 34 34 2 2 6 2 2 6 2 2 6
40286 - 42 42 42 195 195 195 246 246 246 253 253 253
40287 -253 253 253 253 253 253 253 253 253 250 250 250
40288 -242 242 242 242 242 242 250 250 250 253 253 253
40289 -253 253 253 253 253 253 253 253 253 253 253 253
40290 -253 253 253 250 250 250 246 246 246 238 238 238
40291 -226 226 226 231 231 231 101 101 101 6 6 6
40292 - 2 2 6 2 2 6 2 2 6 2 2 6
40293 - 2 2 6 2 2 6 2 2 6 2 2 6
40294 - 38 38 38 82 82 82 42 42 42 14 14 14
40295 - 6 6 6 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 0 0 0 0 0 0 0 0 0 0 0 0
40302 - 0 0 0 0 0 0 0 0 0 0 0 0
40303 - 0 0 0 0 0 0 0 0 0 0 0 0
40304 - 10 10 10 26 26 26 62 62 62 66 66 66
40305 - 2 2 6 2 2 6 2 2 6 6 6 6
40306 - 70 70 70 170 170 170 206 206 206 234 234 234
40307 -246 246 246 250 250 250 250 250 250 238 238 238
40308 -226 226 226 231 231 231 238 238 238 250 250 250
40309 -250 250 250 250 250 250 246 246 246 231 231 231
40310 -214 214 214 206 206 206 202 202 202 202 202 202
40311 -198 198 198 202 202 202 182 182 182 18 18 18
40312 - 2 2 6 2 2 6 2 2 6 2 2 6
40313 - 2 2 6 2 2 6 2 2 6 2 2 6
40314 - 2 2 6 62 62 62 66 66 66 30 30 30
40315 - 10 10 10 0 0 0 0 0 0 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 0 0 0
40321 - 0 0 0 0 0 0 0 0 0 0 0 0
40322 - 0 0 0 0 0 0 0 0 0 0 0 0
40323 - 0 0 0 0 0 0 0 0 0 0 0 0
40324 - 14 14 14 42 42 42 82 82 82 18 18 18
40325 - 2 2 6 2 2 6 2 2 6 10 10 10
40326 - 94 94 94 182 182 182 218 218 218 242 242 242
40327 -250 250 250 253 253 253 253 253 253 250 250 250
40328 -234 234 234 253 253 253 253 253 253 253 253 253
40329 -253 253 253 253 253 253 253 253 253 246 246 246
40330 -238 238 238 226 226 226 210 210 210 202 202 202
40331 -195 195 195 195 195 195 210 210 210 158 158 158
40332 - 6 6 6 14 14 14 50 50 50 14 14 14
40333 - 2 2 6 2 2 6 2 2 6 2 2 6
40334 - 2 2 6 6 6 6 86 86 86 46 46 46
40335 - 18 18 18 6 6 6 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 0 0 0
40341 - 0 0 0 0 0 0 0 0 0 0 0 0
40342 - 0 0 0 0 0 0 0 0 0 0 0 0
40343 - 0 0 0 0 0 0 0 0 0 6 6 6
40344 - 22 22 22 54 54 54 70 70 70 2 2 6
40345 - 2 2 6 10 10 10 2 2 6 22 22 22
40346 -166 166 166 231 231 231 250 250 250 253 253 253
40347 -253 253 253 253 253 253 253 253 253 250 250 250
40348 -242 242 242 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 246 246 246
40351 -231 231 231 206 206 206 198 198 198 226 226 226
40352 - 94 94 94 2 2 6 6 6 6 38 38 38
40353 - 30 30 30 2 2 6 2 2 6 2 2 6
40354 - 2 2 6 2 2 6 62 62 62 66 66 66
40355 - 26 26 26 10 10 10 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 0 0 0 0 0 0
40361 - 0 0 0 0 0 0 0 0 0 0 0 0
40362 - 0 0 0 0 0 0 0 0 0 0 0 0
40363 - 0 0 0 0 0 0 0 0 0 10 10 10
40364 - 30 30 30 74 74 74 50 50 50 2 2 6
40365 - 26 26 26 26 26 26 2 2 6 106 106 106
40366 -238 238 238 253 253 253 253 253 253 253 253 253
40367 -253 253 253 253 253 253 253 253 253 253 253 253
40368 -253 253 253 253 253 253 253 253 253 253 253 253
40369 -253 253 253 253 253 253 253 253 253 253 253 253
40370 -253 253 253 253 253 253 253 253 253 253 253 253
40371 -253 253 253 246 246 246 218 218 218 202 202 202
40372 -210 210 210 14 14 14 2 2 6 2 2 6
40373 - 30 30 30 22 22 22 2 2 6 2 2 6
40374 - 2 2 6 2 2 6 18 18 18 86 86 86
40375 - 42 42 42 14 14 14 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 0 0 0 0 0 0 0 0 0
40381 - 0 0 0 0 0 0 0 0 0 0 0 0
40382 - 0 0 0 0 0 0 0 0 0 0 0 0
40383 - 0 0 0 0 0 0 0 0 0 14 14 14
40384 - 42 42 42 90 90 90 22 22 22 2 2 6
40385 - 42 42 42 2 2 6 18 18 18 218 218 218
40386 -253 253 253 253 253 253 253 253 253 253 253 253
40387 -253 253 253 253 253 253 253 253 253 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 250 250 250 221 221 221
40392 -218 218 218 101 101 101 2 2 6 14 14 14
40393 - 18 18 18 38 38 38 10 10 10 2 2 6
40394 - 2 2 6 2 2 6 2 2 6 78 78 78
40395 - 58 58 58 22 22 22 6 6 6 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 0 0 0 0 0 0 0 0 0 0 0 0
40401 - 0 0 0 0 0 0 0 0 0 0 0 0
40402 - 0 0 0 0 0 0 0 0 0 0 0 0
40403 - 0 0 0 0 0 0 6 6 6 18 18 18
40404 - 54 54 54 82 82 82 2 2 6 26 26 26
40405 - 22 22 22 2 2 6 123 123 123 253 253 253
40406 -253 253 253 253 253 253 253 253 253 253 253 253
40407 -253 253 253 253 253 253 253 253 253 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 253 253 253
40410 -253 253 253 253 253 253 253 253 253 253 253 253
40411 -253 253 253 253 253 253 253 253 253 250 250 250
40412 -238 238 238 198 198 198 6 6 6 38 38 38
40413 - 58 58 58 26 26 26 38 38 38 2 2 6
40414 - 2 2 6 2 2 6 2 2 6 46 46 46
40415 - 78 78 78 30 30 30 10 10 10 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 0 0 0 0 0 0 0 0 0 0 0 0
40421 - 0 0 0 0 0 0 0 0 0 0 0 0
40422 - 0 0 0 0 0 0 0 0 0 0 0 0
40423 - 0 0 0 0 0 0 10 10 10 30 30 30
40424 - 74 74 74 58 58 58 2 2 6 42 42 42
40425 - 2 2 6 22 22 22 231 231 231 253 253 253
40426 -253 253 253 253 253 253 253 253 253 253 253 253
40427 -253 253 253 253 253 253 253 253 253 250 250 250
40428 -253 253 253 253 253 253 253 253 253 253 253 253
40429 -253 253 253 253 253 253 253 253 253 253 253 253
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 246 246 246 46 46 46 38 38 38
40433 - 42 42 42 14 14 14 38 38 38 14 14 14
40434 - 2 2 6 2 2 6 2 2 6 6 6 6
40435 - 86 86 86 46 46 46 14 14 14 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 0 0 0 0 0 0 0 0 0 0 0 0
40441 - 0 0 0 0 0 0 0 0 0 0 0 0
40442 - 0 0 0 0 0 0 0 0 0 0 0 0
40443 - 0 0 0 6 6 6 14 14 14 42 42 42
40444 - 90 90 90 18 18 18 18 18 18 26 26 26
40445 - 2 2 6 116 116 116 253 253 253 253 253 253
40446 -253 253 253 253 253 253 253 253 253 253 253 253
40447 -253 253 253 253 253 253 250 250 250 238 238 238
40448 -253 253 253 253 253 253 253 253 253 253 253 253
40449 -253 253 253 253 253 253 253 253 253 253 253 253
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 94 94 94 6 6 6
40453 - 2 2 6 2 2 6 10 10 10 34 34 34
40454 - 2 2 6 2 2 6 2 2 6 2 2 6
40455 - 74 74 74 58 58 58 22 22 22 6 6 6
40456 - 0 0 0 0 0 0 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 0 0 0
40460 - 0 0 0 0 0 0 0 0 0 0 0 0
40461 - 0 0 0 0 0 0 0 0 0 0 0 0
40462 - 0 0 0 0 0 0 0 0 0 0 0 0
40463 - 0 0 0 10 10 10 26 26 26 66 66 66
40464 - 82 82 82 2 2 6 38 38 38 6 6 6
40465 - 14 14 14 210 210 210 253 253 253 253 253 253
40466 -253 253 253 253 253 253 253 253 253 253 253 253
40467 -253 253 253 253 253 253 246 246 246 242 242 242
40468 -253 253 253 253 253 253 253 253 253 253 253 253
40469 -253 253 253 253 253 253 253 253 253 253 253 253
40470 -253 253 253 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 144 144 144 2 2 6
40473 - 2 2 6 2 2 6 2 2 6 46 46 46
40474 - 2 2 6 2 2 6 2 2 6 2 2 6
40475 - 42 42 42 74 74 74 30 30 30 10 10 10
40476 - 0 0 0 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 0 0 0
40480 - 0 0 0 0 0 0 0 0 0 0 0 0
40481 - 0 0 0 0 0 0 0 0 0 0 0 0
40482 - 0 0 0 0 0 0 0 0 0 0 0 0
40483 - 6 6 6 14 14 14 42 42 42 90 90 90
40484 - 26 26 26 6 6 6 42 42 42 2 2 6
40485 - 74 74 74 250 250 250 253 253 253 253 253 253
40486 -253 253 253 253 253 253 253 253 253 253 253 253
40487 -253 253 253 253 253 253 242 242 242 242 242 242
40488 -253 253 253 253 253 253 253 253 253 253 253 253
40489 -253 253 253 253 253 253 253 253 253 253 253 253
40490 -253 253 253 253 253 253 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 182 182 182 2 2 6
40493 - 2 2 6 2 2 6 2 2 6 46 46 46
40494 - 2 2 6 2 2 6 2 2 6 2 2 6
40495 - 10 10 10 86 86 86 38 38 38 10 10 10
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 0 0 0
40500 - 0 0 0 0 0 0 0 0 0 0 0 0
40501 - 0 0 0 0 0 0 0 0 0 0 0 0
40502 - 0 0 0 0 0 0 0 0 0 0 0 0
40503 - 10 10 10 26 26 26 66 66 66 82 82 82
40504 - 2 2 6 22 22 22 18 18 18 2 2 6
40505 -149 149 149 253 253 253 253 253 253 253 253 253
40506 -253 253 253 253 253 253 253 253 253 253 253 253
40507 -253 253 253 253 253 253 234 234 234 242 242 242
40508 -253 253 253 253 253 253 253 253 253 253 253 253
40509 -253 253 253 253 253 253 253 253 253 253 253 253
40510 -253 253 253 253 253 253 253 253 253 253 253 253
40511 -253 253 253 253 253 253 253 253 253 253 253 253
40512 -253 253 253 253 253 253 206 206 206 2 2 6
40513 - 2 2 6 2 2 6 2 2 6 38 38 38
40514 - 2 2 6 2 2 6 2 2 6 2 2 6
40515 - 6 6 6 86 86 86 46 46 46 14 14 14
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 0 0 0 0 0 0
40520 - 0 0 0 0 0 0 0 0 0 0 0 0
40521 - 0 0 0 0 0 0 0 0 0 0 0 0
40522 - 0 0 0 0 0 0 0 0 0 6 6 6
40523 - 18 18 18 46 46 46 86 86 86 18 18 18
40524 - 2 2 6 34 34 34 10 10 10 6 6 6
40525 -210 210 210 253 253 253 253 253 253 253 253 253
40526 -253 253 253 253 253 253 253 253 253 253 253 253
40527 -253 253 253 253 253 253 234 234 234 242 242 242
40528 -253 253 253 253 253 253 253 253 253 253 253 253
40529 -253 253 253 253 253 253 253 253 253 253 253 253
40530 -253 253 253 253 253 253 253 253 253 253 253 253
40531 -253 253 253 253 253 253 253 253 253 253 253 253
40532 -253 253 253 253 253 253 221 221 221 6 6 6
40533 - 2 2 6 2 2 6 6 6 6 30 30 30
40534 - 2 2 6 2 2 6 2 2 6 2 2 6
40535 - 2 2 6 82 82 82 54 54 54 18 18 18
40536 - 6 6 6 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 0 0 0 0 0 0
40540 - 0 0 0 0 0 0 0 0 0 0 0 0
40541 - 0 0 0 0 0 0 0 0 0 0 0 0
40542 - 0 0 0 0 0 0 0 0 0 10 10 10
40543 - 26 26 26 66 66 66 62 62 62 2 2 6
40544 - 2 2 6 38 38 38 10 10 10 26 26 26
40545 -238 238 238 253 253 253 253 253 253 253 253 253
40546 -253 253 253 253 253 253 253 253 253 253 253 253
40547 -253 253 253 253 253 253 231 231 231 238 238 238
40548 -253 253 253 253 253 253 253 253 253 253 253 253
40549 -253 253 253 253 253 253 253 253 253 253 253 253
40550 -253 253 253 253 253 253 253 253 253 253 253 253
40551 -253 253 253 253 253 253 253 253 253 253 253 253
40552 -253 253 253 253 253 253 231 231 231 6 6 6
40553 - 2 2 6 2 2 6 10 10 10 30 30 30
40554 - 2 2 6 2 2 6 2 2 6 2 2 6
40555 - 2 2 6 66 66 66 58 58 58 22 22 22
40556 - 6 6 6 0 0 0 0 0 0 0 0 0
40557 - 0 0 0 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 0 0 0 0 0 0 0 0 0
40560 - 0 0 0 0 0 0 0 0 0 0 0 0
40561 - 0 0 0 0 0 0 0 0 0 0 0 0
40562 - 0 0 0 0 0 0 0 0 0 10 10 10
40563 - 38 38 38 78 78 78 6 6 6 2 2 6
40564 - 2 2 6 46 46 46 14 14 14 42 42 42
40565 -246 246 246 253 253 253 253 253 253 253 253 253
40566 -253 253 253 253 253 253 253 253 253 253 253 253
40567 -253 253 253 253 253 253 231 231 231 242 242 242
40568 -253 253 253 253 253 253 253 253 253 253 253 253
40569 -253 253 253 253 253 253 253 253 253 253 253 253
40570 -253 253 253 253 253 253 253 253 253 253 253 253
40571 -253 253 253 253 253 253 253 253 253 253 253 253
40572 -253 253 253 253 253 253 234 234 234 10 10 10
40573 - 2 2 6 2 2 6 22 22 22 14 14 14
40574 - 2 2 6 2 2 6 2 2 6 2 2 6
40575 - 2 2 6 66 66 66 62 62 62 22 22 22
40576 - 6 6 6 0 0 0 0 0 0 0 0 0
40577 - 0 0 0 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 0 0 0 0 0 0 0 0 0
40580 - 0 0 0 0 0 0 0 0 0 0 0 0
40581 - 0 0 0 0 0 0 0 0 0 0 0 0
40582 - 0 0 0 0 0 0 6 6 6 18 18 18
40583 - 50 50 50 74 74 74 2 2 6 2 2 6
40584 - 14 14 14 70 70 70 34 34 34 62 62 62
40585 -250 250 250 253 253 253 253 253 253 253 253 253
40586 -253 253 253 253 253 253 253 253 253 253 253 253
40587 -253 253 253 253 253 253 231 231 231 246 246 246
40588 -253 253 253 253 253 253 253 253 253 253 253 253
40589 -253 253 253 253 253 253 253 253 253 253 253 253
40590 -253 253 253 253 253 253 253 253 253 253 253 253
40591 -253 253 253 253 253 253 253 253 253 253 253 253
40592 -253 253 253 253 253 253 234 234 234 14 14 14
40593 - 2 2 6 2 2 6 30 30 30 2 2 6
40594 - 2 2 6 2 2 6 2 2 6 2 2 6
40595 - 2 2 6 66 66 66 62 62 62 22 22 22
40596 - 6 6 6 0 0 0 0 0 0 0 0 0
40597 - 0 0 0 0 0 0 0 0 0 0 0 0
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 0 0 0 0 0 0 0 0 0 0 0 0
40600 - 0 0 0 0 0 0 0 0 0 0 0 0
40601 - 0 0 0 0 0 0 0 0 0 0 0 0
40602 - 0 0 0 0 0 0 6 6 6 18 18 18
40603 - 54 54 54 62 62 62 2 2 6 2 2 6
40604 - 2 2 6 30 30 30 46 46 46 70 70 70
40605 -250 250 250 253 253 253 253 253 253 253 253 253
40606 -253 253 253 253 253 253 253 253 253 253 253 253
40607 -253 253 253 253 253 253 231 231 231 246 246 246
40608 -253 253 253 253 253 253 253 253 253 253 253 253
40609 -253 253 253 253 253 253 253 253 253 253 253 253
40610 -253 253 253 253 253 253 253 253 253 253 253 253
40611 -253 253 253 253 253 253 253 253 253 253 253 253
40612 -253 253 253 253 253 253 226 226 226 10 10 10
40613 - 2 2 6 6 6 6 30 30 30 2 2 6
40614 - 2 2 6 2 2 6 2 2 6 2 2 6
40615 - 2 2 6 66 66 66 58 58 58 22 22 22
40616 - 6 6 6 0 0 0 0 0 0 0 0 0
40617 - 0 0 0 0 0 0 0 0 0 0 0 0
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 0 0 0 0 0 0 0 0 0 0 0 0
40620 - 0 0 0 0 0 0 0 0 0 0 0 0
40621 - 0 0 0 0 0 0 0 0 0 0 0 0
40622 - 0 0 0 0 0 0 6 6 6 22 22 22
40623 - 58 58 58 62 62 62 2 2 6 2 2 6
40624 - 2 2 6 2 2 6 30 30 30 78 78 78
40625 -250 250 250 253 253 253 253 253 253 253 253 253
40626 -253 253 253 253 253 253 253 253 253 253 253 253
40627 -253 253 253 253 253 253 231 231 231 246 246 246
40628 -253 253 253 253 253 253 253 253 253 253 253 253
40629 -253 253 253 253 253 253 253 253 253 253 253 253
40630 -253 253 253 253 253 253 253 253 253 253 253 253
40631 -253 253 253 253 253 253 253 253 253 253 253 253
40632 -253 253 253 253 253 253 206 206 206 2 2 6
40633 - 22 22 22 34 34 34 18 14 6 22 22 22
40634 - 26 26 26 18 18 18 6 6 6 2 2 6
40635 - 2 2 6 82 82 82 54 54 54 18 18 18
40636 - 6 6 6 0 0 0 0 0 0 0 0 0
40637 - 0 0 0 0 0 0 0 0 0 0 0 0
40638 - 0 0 0 0 0 0 0 0 0 0 0 0
40639 - 0 0 0 0 0 0 0 0 0 0 0 0
40640 - 0 0 0 0 0 0 0 0 0 0 0 0
40641 - 0 0 0 0 0 0 0 0 0 0 0 0
40642 - 0 0 0 0 0 0 6 6 6 26 26 26
40643 - 62 62 62 106 106 106 74 54 14 185 133 11
40644 -210 162 10 121 92 8 6 6 6 62 62 62
40645 -238 238 238 253 253 253 253 253 253 253 253 253
40646 -253 253 253 253 253 253 253 253 253 253 253 253
40647 -253 253 253 253 253 253 231 231 231 246 246 246
40648 -253 253 253 253 253 253 253 253 253 253 253 253
40649 -253 253 253 253 253 253 253 253 253 253 253 253
40650 -253 253 253 253 253 253 253 253 253 253 253 253
40651 -253 253 253 253 253 253 253 253 253 253 253 253
40652 -253 253 253 253 253 253 158 158 158 18 18 18
40653 - 14 14 14 2 2 6 2 2 6 2 2 6
40654 - 6 6 6 18 18 18 66 66 66 38 38 38
40655 - 6 6 6 94 94 94 50 50 50 18 18 18
40656 - 6 6 6 0 0 0 0 0 0 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 0 0 0
40659 - 0 0 0 0 0 0 0 0 0 0 0 0
40660 - 0 0 0 0 0 0 0 0 0 0 0 0
40661 - 0 0 0 0 0 0 0 0 0 6 6 6
40662 - 10 10 10 10 10 10 18 18 18 38 38 38
40663 - 78 78 78 142 134 106 216 158 10 242 186 14
40664 -246 190 14 246 190 14 156 118 10 10 10 10
40665 - 90 90 90 238 238 238 253 253 253 253 253 253
40666 -253 253 253 253 253 253 253 253 253 253 253 253
40667 -253 253 253 253 253 253 231 231 231 250 250 250
40668 -253 253 253 253 253 253 253 253 253 253 253 253
40669 -253 253 253 253 253 253 253 253 253 253 253 253
40670 -253 253 253 253 253 253 253 253 253 253 253 253
40671 -253 253 253 253 253 253 253 253 253 246 230 190
40672 -238 204 91 238 204 91 181 142 44 37 26 9
40673 - 2 2 6 2 2 6 2 2 6 2 2 6
40674 - 2 2 6 2 2 6 38 38 38 46 46 46
40675 - 26 26 26 106 106 106 54 54 54 18 18 18
40676 - 6 6 6 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 0 0 0
40679 - 0 0 0 0 0 0 0 0 0 0 0 0
40680 - 0 0 0 0 0 0 0 0 0 0 0 0
40681 - 0 0 0 6 6 6 14 14 14 22 22 22
40682 - 30 30 30 38 38 38 50 50 50 70 70 70
40683 -106 106 106 190 142 34 226 170 11 242 186 14
40684 -246 190 14 246 190 14 246 190 14 154 114 10
40685 - 6 6 6 74 74 74 226 226 226 253 253 253
40686 -253 253 253 253 253 253 253 253 253 253 253 253
40687 -253 253 253 253 253 253 231 231 231 250 250 250
40688 -253 253 253 253 253 253 253 253 253 253 253 253
40689 -253 253 253 253 253 253 253 253 253 253 253 253
40690 -253 253 253 253 253 253 253 253 253 253 253 253
40691 -253 253 253 253 253 253 253 253 253 228 184 62
40692 -241 196 14 241 208 19 232 195 16 38 30 10
40693 - 2 2 6 2 2 6 2 2 6 2 2 6
40694 - 2 2 6 6 6 6 30 30 30 26 26 26
40695 -203 166 17 154 142 90 66 66 66 26 26 26
40696 - 6 6 6 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 0 0 0 0 0 0
40699 - 0 0 0 0 0 0 0 0 0 0 0 0
40700 - 0 0 0 0 0 0 0 0 0 0 0 0
40701 - 6 6 6 18 18 18 38 38 38 58 58 58
40702 - 78 78 78 86 86 86 101 101 101 123 123 123
40703 -175 146 61 210 150 10 234 174 13 246 186 14
40704 -246 190 14 246 190 14 246 190 14 238 190 10
40705 -102 78 10 2 2 6 46 46 46 198 198 198
40706 -253 253 253 253 253 253 253 253 253 253 253 253
40707 -253 253 253 253 253 253 234 234 234 242 242 242
40708 -253 253 253 253 253 253 253 253 253 253 253 253
40709 -253 253 253 253 253 253 253 253 253 253 253 253
40710 -253 253 253 253 253 253 253 253 253 253 253 253
40711 -253 253 253 253 253 253 253 253 253 224 178 62
40712 -242 186 14 241 196 14 210 166 10 22 18 6
40713 - 2 2 6 2 2 6 2 2 6 2 2 6
40714 - 2 2 6 2 2 6 6 6 6 121 92 8
40715 -238 202 15 232 195 16 82 82 82 34 34 34
40716 - 10 10 10 0 0 0 0 0 0 0 0 0
40717 - 0 0 0 0 0 0 0 0 0 0 0 0
40718 - 0 0 0 0 0 0 0 0 0 0 0 0
40719 - 0 0 0 0 0 0 0 0 0 0 0 0
40720 - 0 0 0 0 0 0 0 0 0 0 0 0
40721 - 14 14 14 38 38 38 70 70 70 154 122 46
40722 -190 142 34 200 144 11 197 138 11 197 138 11
40723 -213 154 11 226 170 11 242 186 14 246 190 14
40724 -246 190 14 246 190 14 246 190 14 246 190 14
40725 -225 175 15 46 32 6 2 2 6 22 22 22
40726 -158 158 158 250 250 250 253 253 253 253 253 253
40727 -253 253 253 253 253 253 253 253 253 253 253 253
40728 -253 253 253 253 253 253 253 253 253 253 253 253
40729 -253 253 253 253 253 253 253 253 253 253 253 253
40730 -253 253 253 253 253 253 253 253 253 253 253 253
40731 -253 253 253 250 250 250 242 242 242 224 178 62
40732 -239 182 13 236 186 11 213 154 11 46 32 6
40733 - 2 2 6 2 2 6 2 2 6 2 2 6
40734 - 2 2 6 2 2 6 61 42 6 225 175 15
40735 -238 190 10 236 186 11 112 100 78 42 42 42
40736 - 14 14 14 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 0 0 0
40738 - 0 0 0 0 0 0 0 0 0 0 0 0
40739 - 0 0 0 0 0 0 0 0 0 0 0 0
40740 - 0 0 0 0 0 0 0 0 0 6 6 6
40741 - 22 22 22 54 54 54 154 122 46 213 154 11
40742 -226 170 11 230 174 11 226 170 11 226 170 11
40743 -236 178 12 242 186 14 246 190 14 246 190 14
40744 -246 190 14 246 190 14 246 190 14 246 190 14
40745 -241 196 14 184 144 12 10 10 10 2 2 6
40746 - 6 6 6 116 116 116 242 242 242 253 253 253
40747 -253 253 253 253 253 253 253 253 253 253 253 253
40748 -253 253 253 253 253 253 253 253 253 253 253 253
40749 -253 253 253 253 253 253 253 253 253 253 253 253
40750 -253 253 253 253 253 253 253 253 253 253 253 253
40751 -253 253 253 231 231 231 198 198 198 214 170 54
40752 -236 178 12 236 178 12 210 150 10 137 92 6
40753 - 18 14 6 2 2 6 2 2 6 2 2 6
40754 - 6 6 6 70 47 6 200 144 11 236 178 12
40755 -239 182 13 239 182 13 124 112 88 58 58 58
40756 - 22 22 22 6 6 6 0 0 0 0 0 0
40757 - 0 0 0 0 0 0 0 0 0 0 0 0
40758 - 0 0 0 0 0 0 0 0 0 0 0 0
40759 - 0 0 0 0 0 0 0 0 0 0 0 0
40760 - 0 0 0 0 0 0 0 0 0 10 10 10
40761 - 30 30 30 70 70 70 180 133 36 226 170 11
40762 -239 182 13 242 186 14 242 186 14 246 186 14
40763 -246 190 14 246 190 14 246 190 14 246 190 14
40764 -246 190 14 246 190 14 246 190 14 246 190 14
40765 -246 190 14 232 195 16 98 70 6 2 2 6
40766 - 2 2 6 2 2 6 66 66 66 221 221 221
40767 -253 253 253 253 253 253 253 253 253 253 253 253
40768 -253 253 253 253 253 253 253 253 253 253 253 253
40769 -253 253 253 253 253 253 253 253 253 253 253 253
40770 -253 253 253 253 253 253 253 253 253 253 253 253
40771 -253 253 253 206 206 206 198 198 198 214 166 58
40772 -230 174 11 230 174 11 216 158 10 192 133 9
40773 -163 110 8 116 81 8 102 78 10 116 81 8
40774 -167 114 7 197 138 11 226 170 11 239 182 13
40775 -242 186 14 242 186 14 162 146 94 78 78 78
40776 - 34 34 34 14 14 14 6 6 6 0 0 0
40777 - 0 0 0 0 0 0 0 0 0 0 0 0
40778 - 0 0 0 0 0 0 0 0 0 0 0 0
40779 - 0 0 0 0 0 0 0 0 0 0 0 0
40780 - 0 0 0 0 0 0 0 0 0 6 6 6
40781 - 30 30 30 78 78 78 190 142 34 226 170 11
40782 -239 182 13 246 190 14 246 190 14 246 190 14
40783 -246 190 14 246 190 14 246 190 14 246 190 14
40784 -246 190 14 246 190 14 246 190 14 246 190 14
40785 -246 190 14 241 196 14 203 166 17 22 18 6
40786 - 2 2 6 2 2 6 2 2 6 38 38 38
40787 -218 218 218 253 253 253 253 253 253 253 253 253
40788 -253 253 253 253 253 253 253 253 253 253 253 253
40789 -253 253 253 253 253 253 253 253 253 253 253 253
40790 -253 253 253 253 253 253 253 253 253 253 253 253
40791 -250 250 250 206 206 206 198 198 198 202 162 69
40792 -226 170 11 236 178 12 224 166 10 210 150 10
40793 -200 144 11 197 138 11 192 133 9 197 138 11
40794 -210 150 10 226 170 11 242 186 14 246 190 14
40795 -246 190 14 246 186 14 225 175 15 124 112 88
40796 - 62 62 62 30 30 30 14 14 14 6 6 6
40797 - 0 0 0 0 0 0 0 0 0 0 0 0
40798 - 0 0 0 0 0 0 0 0 0 0 0 0
40799 - 0 0 0 0 0 0 0 0 0 0 0 0
40800 - 0 0 0 0 0 0 0 0 0 10 10 10
40801 - 30 30 30 78 78 78 174 135 50 224 166 10
40802 -239 182 13 246 190 14 246 190 14 246 190 14
40803 -246 190 14 246 190 14 246 190 14 246 190 14
40804 -246 190 14 246 190 14 246 190 14 246 190 14
40805 -246 190 14 246 190 14 241 196 14 139 102 15
40806 - 2 2 6 2 2 6 2 2 6 2 2 6
40807 - 78 78 78 250 250 250 253 253 253 253 253 253
40808 -253 253 253 253 253 253 253 253 253 253 253 253
40809 -253 253 253 253 253 253 253 253 253 253 253 253
40810 -253 253 253 253 253 253 253 253 253 253 253 253
40811 -250 250 250 214 214 214 198 198 198 190 150 46
40812 -219 162 10 236 178 12 234 174 13 224 166 10
40813 -216 158 10 213 154 11 213 154 11 216 158 10
40814 -226 170 11 239 182 13 246 190 14 246 190 14
40815 -246 190 14 246 190 14 242 186 14 206 162 42
40816 -101 101 101 58 58 58 30 30 30 14 14 14
40817 - 6 6 6 0 0 0 0 0 0 0 0 0
40818 - 0 0 0 0 0 0 0 0 0 0 0 0
40819 - 0 0 0 0 0 0 0 0 0 0 0 0
40820 - 0 0 0 0 0 0 0 0 0 10 10 10
40821 - 30 30 30 74 74 74 174 135 50 216 158 10
40822 -236 178 12 246 190 14 246 190 14 246 190 14
40823 -246 190 14 246 190 14 246 190 14 246 190 14
40824 -246 190 14 246 190 14 246 190 14 246 190 14
40825 -246 190 14 246 190 14 241 196 14 226 184 13
40826 - 61 42 6 2 2 6 2 2 6 2 2 6
40827 - 22 22 22 238 238 238 253 253 253 253 253 253
40828 -253 253 253 253 253 253 253 253 253 253 253 253
40829 -253 253 253 253 253 253 253 253 253 253 253 253
40830 -253 253 253 253 253 253 253 253 253 253 253 253
40831 -253 253 253 226 226 226 187 187 187 180 133 36
40832 -216 158 10 236 178 12 239 182 13 236 178 12
40833 -230 174 11 226 170 11 226 170 11 230 174 11
40834 -236 178 12 242 186 14 246 190 14 246 190 14
40835 -246 190 14 246 190 14 246 186 14 239 182 13
40836 -206 162 42 106 106 106 66 66 66 34 34 34
40837 - 14 14 14 6 6 6 0 0 0 0 0 0
40838 - 0 0 0 0 0 0 0 0 0 0 0 0
40839 - 0 0 0 0 0 0 0 0 0 0 0 0
40840 - 0 0 0 0 0 0 0 0 0 6 6 6
40841 - 26 26 26 70 70 70 163 133 67 213 154 11
40842 -236 178 12 246 190 14 246 190 14 246 190 14
40843 -246 190 14 246 190 14 246 190 14 246 190 14
40844 -246 190 14 246 190 14 246 190 14 246 190 14
40845 -246 190 14 246 190 14 246 190 14 241 196 14
40846 -190 146 13 18 14 6 2 2 6 2 2 6
40847 - 46 46 46 246 246 246 253 253 253 253 253 253
40848 -253 253 253 253 253 253 253 253 253 253 253 253
40849 -253 253 253 253 253 253 253 253 253 253 253 253
40850 -253 253 253 253 253 253 253 253 253 253 253 253
40851 -253 253 253 221 221 221 86 86 86 156 107 11
40852 -216 158 10 236 178 12 242 186 14 246 186 14
40853 -242 186 14 239 182 13 239 182 13 242 186 14
40854 -242 186 14 246 186 14 246 190 14 246 190 14
40855 -246 190 14 246 190 14 246 190 14 246 190 14
40856 -242 186 14 225 175 15 142 122 72 66 66 66
40857 - 30 30 30 10 10 10 0 0 0 0 0 0
40858 - 0 0 0 0 0 0 0 0 0 0 0 0
40859 - 0 0 0 0 0 0 0 0 0 0 0 0
40860 - 0 0 0 0 0 0 0 0 0 6 6 6
40861 - 26 26 26 70 70 70 163 133 67 210 150 10
40862 -236 178 12 246 190 14 246 190 14 246 190 14
40863 -246 190 14 246 190 14 246 190 14 246 190 14
40864 -246 190 14 246 190 14 246 190 14 246 190 14
40865 -246 190 14 246 190 14 246 190 14 246 190 14
40866 -232 195 16 121 92 8 34 34 34 106 106 106
40867 -221 221 221 253 253 253 253 253 253 253 253 253
40868 -253 253 253 253 253 253 253 253 253 253 253 253
40869 -253 253 253 253 253 253 253 253 253 253 253 253
40870 -253 253 253 253 253 253 253 253 253 253 253 253
40871 -242 242 242 82 82 82 18 14 6 163 110 8
40872 -216 158 10 236 178 12 242 186 14 246 190 14
40873 -246 190 14 246 190 14 246 190 14 246 190 14
40874 -246 190 14 246 190 14 246 190 14 246 190 14
40875 -246 190 14 246 190 14 246 190 14 246 190 14
40876 -246 190 14 246 190 14 242 186 14 163 133 67
40877 - 46 46 46 18 18 18 6 6 6 0 0 0
40878 - 0 0 0 0 0 0 0 0 0 0 0 0
40879 - 0 0 0 0 0 0 0 0 0 0 0 0
40880 - 0 0 0 0 0 0 0 0 0 10 10 10
40881 - 30 30 30 78 78 78 163 133 67 210 150 10
40882 -236 178 12 246 186 14 246 190 14 246 190 14
40883 -246 190 14 246 190 14 246 190 14 246 190 14
40884 -246 190 14 246 190 14 246 190 14 246 190 14
40885 -246 190 14 246 190 14 246 190 14 246 190 14
40886 -241 196 14 215 174 15 190 178 144 253 253 253
40887 -253 253 253 253 253 253 253 253 253 253 253 253
40888 -253 253 253 253 253 253 253 253 253 253 253 253
40889 -253 253 253 253 253 253 253 253 253 253 253 253
40890 -253 253 253 253 253 253 253 253 253 218 218 218
40891 - 58 58 58 2 2 6 22 18 6 167 114 7
40892 -216 158 10 236 178 12 246 186 14 246 190 14
40893 -246 190 14 246 190 14 246 190 14 246 190 14
40894 -246 190 14 246 190 14 246 190 14 246 190 14
40895 -246 190 14 246 190 14 246 190 14 246 190 14
40896 -246 190 14 246 186 14 242 186 14 190 150 46
40897 - 54 54 54 22 22 22 6 6 6 0 0 0
40898 - 0 0 0 0 0 0 0 0 0 0 0 0
40899 - 0 0 0 0 0 0 0 0 0 0 0 0
40900 - 0 0 0 0 0 0 0 0 0 14 14 14
40901 - 38 38 38 86 86 86 180 133 36 213 154 11
40902 -236 178 12 246 186 14 246 190 14 246 190 14
40903 -246 190 14 246 190 14 246 190 14 246 190 14
40904 -246 190 14 246 190 14 246 190 14 246 190 14
40905 -246 190 14 246 190 14 246 190 14 246 190 14
40906 -246 190 14 232 195 16 190 146 13 214 214 214
40907 -253 253 253 253 253 253 253 253 253 253 253 253
40908 -253 253 253 253 253 253 253 253 253 253 253 253
40909 -253 253 253 253 253 253 253 253 253 253 253 253
40910 -253 253 253 250 250 250 170 170 170 26 26 26
40911 - 2 2 6 2 2 6 37 26 9 163 110 8
40912 -219 162 10 239 182 13 246 186 14 246 190 14
40913 -246 190 14 246 190 14 246 190 14 246 190 14
40914 -246 190 14 246 190 14 246 190 14 246 190 14
40915 -246 190 14 246 190 14 246 190 14 246 190 14
40916 -246 186 14 236 178 12 224 166 10 142 122 72
40917 - 46 46 46 18 18 18 6 6 6 0 0 0
40918 - 0 0 0 0 0 0 0 0 0 0 0 0
40919 - 0 0 0 0 0 0 0 0 0 0 0 0
40920 - 0 0 0 0 0 0 6 6 6 18 18 18
40921 - 50 50 50 109 106 95 192 133 9 224 166 10
40922 -242 186 14 246 190 14 246 190 14 246 190 14
40923 -246 190 14 246 190 14 246 190 14 246 190 14
40924 -246 190 14 246 190 14 246 190 14 246 190 14
40925 -246 190 14 246 190 14 246 190 14 246 190 14
40926 -242 186 14 226 184 13 210 162 10 142 110 46
40927 -226 226 226 253 253 253 253 253 253 253 253 253
40928 -253 253 253 253 253 253 253 253 253 253 253 253
40929 -253 253 253 253 253 253 253 253 253 253 253 253
40930 -198 198 198 66 66 66 2 2 6 2 2 6
40931 - 2 2 6 2 2 6 50 34 6 156 107 11
40932 -219 162 10 239 182 13 246 186 14 246 190 14
40933 -246 190 14 246 190 14 246 190 14 246 190 14
40934 -246 190 14 246 190 14 246 190 14 246 190 14
40935 -246 190 14 246 190 14 246 190 14 242 186 14
40936 -234 174 13 213 154 11 154 122 46 66 66 66
40937 - 30 30 30 10 10 10 0 0 0 0 0 0
40938 - 0 0 0 0 0 0 0 0 0 0 0 0
40939 - 0 0 0 0 0 0 0 0 0 0 0 0
40940 - 0 0 0 0 0 0 6 6 6 22 22 22
40941 - 58 58 58 154 121 60 206 145 10 234 174 13
40942 -242 186 14 246 186 14 246 190 14 246 190 14
40943 -246 190 14 246 190 14 246 190 14 246 190 14
40944 -246 190 14 246 190 14 246 190 14 246 190 14
40945 -246 190 14 246 190 14 246 190 14 246 190 14
40946 -246 186 14 236 178 12 210 162 10 163 110 8
40947 - 61 42 6 138 138 138 218 218 218 250 250 250
40948 -253 253 253 253 253 253 253 253 253 250 250 250
40949 -242 242 242 210 210 210 144 144 144 66 66 66
40950 - 6 6 6 2 2 6 2 2 6 2 2 6
40951 - 2 2 6 2 2 6 61 42 6 163 110 8
40952 -216 158 10 236 178 12 246 190 14 246 190 14
40953 -246 190 14 246 190 14 246 190 14 246 190 14
40954 -246 190 14 246 190 14 246 190 14 246 190 14
40955 -246 190 14 239 182 13 230 174 11 216 158 10
40956 -190 142 34 124 112 88 70 70 70 38 38 38
40957 - 18 18 18 6 6 6 0 0 0 0 0 0
40958 - 0 0 0 0 0 0 0 0 0 0 0 0
40959 - 0 0 0 0 0 0 0 0 0 0 0 0
40960 - 0 0 0 0 0 0 6 6 6 22 22 22
40961 - 62 62 62 168 124 44 206 145 10 224 166 10
40962 -236 178 12 239 182 13 242 186 14 242 186 14
40963 -246 186 14 246 190 14 246 190 14 246 190 14
40964 -246 190 14 246 190 14 246 190 14 246 190 14
40965 -246 190 14 246 190 14 246 190 14 246 190 14
40966 -246 190 14 236 178 12 216 158 10 175 118 6
40967 - 80 54 7 2 2 6 6 6 6 30 30 30
40968 - 54 54 54 62 62 62 50 50 50 38 38 38
40969 - 14 14 14 2 2 6 2 2 6 2 2 6
40970 - 2 2 6 2 2 6 2 2 6 2 2 6
40971 - 2 2 6 6 6 6 80 54 7 167 114 7
40972 -213 154 11 236 178 12 246 190 14 246 190 14
40973 -246 190 14 246 190 14 246 190 14 246 190 14
40974 -246 190 14 242 186 14 239 182 13 239 182 13
40975 -230 174 11 210 150 10 174 135 50 124 112 88
40976 - 82 82 82 54 54 54 34 34 34 18 18 18
40977 - 6 6 6 0 0 0 0 0 0 0 0 0
40978 - 0 0 0 0 0 0 0 0 0 0 0 0
40979 - 0 0 0 0 0 0 0 0 0 0 0 0
40980 - 0 0 0 0 0 0 6 6 6 18 18 18
40981 - 50 50 50 158 118 36 192 133 9 200 144 11
40982 -216 158 10 219 162 10 224 166 10 226 170 11
40983 -230 174 11 236 178 12 239 182 13 239 182 13
40984 -242 186 14 246 186 14 246 190 14 246 190 14
40985 -246 190 14 246 190 14 246 190 14 246 190 14
40986 -246 186 14 230 174 11 210 150 10 163 110 8
40987 -104 69 6 10 10 10 2 2 6 2 2 6
40988 - 2 2 6 2 2 6 2 2 6 2 2 6
40989 - 2 2 6 2 2 6 2 2 6 2 2 6
40990 - 2 2 6 2 2 6 2 2 6 2 2 6
40991 - 2 2 6 6 6 6 91 60 6 167 114 7
40992 -206 145 10 230 174 11 242 186 14 246 190 14
40993 -246 190 14 246 190 14 246 186 14 242 186 14
40994 -239 182 13 230 174 11 224 166 10 213 154 11
40995 -180 133 36 124 112 88 86 86 86 58 58 58
40996 - 38 38 38 22 22 22 10 10 10 6 6 6
40997 - 0 0 0 0 0 0 0 0 0 0 0 0
40998 - 0 0 0 0 0 0 0 0 0 0 0 0
40999 - 0 0 0 0 0 0 0 0 0 0 0 0
41000 - 0 0 0 0 0 0 0 0 0 14 14 14
41001 - 34 34 34 70 70 70 138 110 50 158 118 36
41002 -167 114 7 180 123 7 192 133 9 197 138 11
41003 -200 144 11 206 145 10 213 154 11 219 162 10
41004 -224 166 10 230 174 11 239 182 13 242 186 14
41005 -246 186 14 246 186 14 246 186 14 246 186 14
41006 -239 182 13 216 158 10 185 133 11 152 99 6
41007 -104 69 6 18 14 6 2 2 6 2 2 6
41008 - 2 2 6 2 2 6 2 2 6 2 2 6
41009 - 2 2 6 2 2 6 2 2 6 2 2 6
41010 - 2 2 6 2 2 6 2 2 6 2 2 6
41011 - 2 2 6 6 6 6 80 54 7 152 99 6
41012 -192 133 9 219 162 10 236 178 12 239 182 13
41013 -246 186 14 242 186 14 239 182 13 236 178 12
41014 -224 166 10 206 145 10 192 133 9 154 121 60
41015 - 94 94 94 62 62 62 42 42 42 22 22 22
41016 - 14 14 14 6 6 6 0 0 0 0 0 0
41017 - 0 0 0 0 0 0 0 0 0 0 0 0
41018 - 0 0 0 0 0 0 0 0 0 0 0 0
41019 - 0 0 0 0 0 0 0 0 0 0 0 0
41020 - 0 0 0 0 0 0 0 0 0 6 6 6
41021 - 18 18 18 34 34 34 58 58 58 78 78 78
41022 -101 98 89 124 112 88 142 110 46 156 107 11
41023 -163 110 8 167 114 7 175 118 6 180 123 7
41024 -185 133 11 197 138 11 210 150 10 219 162 10
41025 -226 170 11 236 178 12 236 178 12 234 174 13
41026 -219 162 10 197 138 11 163 110 8 130 83 6
41027 - 91 60 6 10 10 10 2 2 6 2 2 6
41028 - 18 18 18 38 38 38 38 38 38 38 38 38
41029 - 38 38 38 38 38 38 38 38 38 38 38 38
41030 - 38 38 38 38 38 38 26 26 26 2 2 6
41031 - 2 2 6 6 6 6 70 47 6 137 92 6
41032 -175 118 6 200 144 11 219 162 10 230 174 11
41033 -234 174 13 230 174 11 219 162 10 210 150 10
41034 -192 133 9 163 110 8 124 112 88 82 82 82
41035 - 50 50 50 30 30 30 14 14 14 6 6 6
41036 - 0 0 0 0 0 0 0 0 0 0 0 0
41037 - 0 0 0 0 0 0 0 0 0 0 0 0
41038 - 0 0 0 0 0 0 0 0 0 0 0 0
41039 - 0 0 0 0 0 0 0 0 0 0 0 0
41040 - 0 0 0 0 0 0 0 0 0 0 0 0
41041 - 6 6 6 14 14 14 22 22 22 34 34 34
41042 - 42 42 42 58 58 58 74 74 74 86 86 86
41043 -101 98 89 122 102 70 130 98 46 121 87 25
41044 -137 92 6 152 99 6 163 110 8 180 123 7
41045 -185 133 11 197 138 11 206 145 10 200 144 11
41046 -180 123 7 156 107 11 130 83 6 104 69 6
41047 - 50 34 6 54 54 54 110 110 110 101 98 89
41048 - 86 86 86 82 82 82 78 78 78 78 78 78
41049 - 78 78 78 78 78 78 78 78 78 78 78 78
41050 - 78 78 78 82 82 82 86 86 86 94 94 94
41051 -106 106 106 101 101 101 86 66 34 124 80 6
41052 -156 107 11 180 123 7 192 133 9 200 144 11
41053 -206 145 10 200 144 11 192 133 9 175 118 6
41054 -139 102 15 109 106 95 70 70 70 42 42 42
41055 - 22 22 22 10 10 10 0 0 0 0 0 0
41056 - 0 0 0 0 0 0 0 0 0 0 0 0
41057 - 0 0 0 0 0 0 0 0 0 0 0 0
41058 - 0 0 0 0 0 0 0 0 0 0 0 0
41059 - 0 0 0 0 0 0 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 6 6 6 10 10 10
41062 - 14 14 14 22 22 22 30 30 30 38 38 38
41063 - 50 50 50 62 62 62 74 74 74 90 90 90
41064 -101 98 89 112 100 78 121 87 25 124 80 6
41065 -137 92 6 152 99 6 152 99 6 152 99 6
41066 -138 86 6 124 80 6 98 70 6 86 66 30
41067 -101 98 89 82 82 82 58 58 58 46 46 46
41068 - 38 38 38 34 34 34 34 34 34 34 34 34
41069 - 34 34 34 34 34 34 34 34 34 34 34 34
41070 - 34 34 34 34 34 34 38 38 38 42 42 42
41071 - 54 54 54 82 82 82 94 86 76 91 60 6
41072 -134 86 6 156 107 11 167 114 7 175 118 6
41073 -175 118 6 167 114 7 152 99 6 121 87 25
41074 -101 98 89 62 62 62 34 34 34 18 18 18
41075 - 6 6 6 0 0 0 0 0 0 0 0 0
41076 - 0 0 0 0 0 0 0 0 0 0 0 0
41077 - 0 0 0 0 0 0 0 0 0 0 0 0
41078 - 0 0 0 0 0 0 0 0 0 0 0 0
41079 - 0 0 0 0 0 0 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 6 6 6 6 6 6 10 10 10
41083 - 18 18 18 22 22 22 30 30 30 42 42 42
41084 - 50 50 50 66 66 66 86 86 86 101 98 89
41085 -106 86 58 98 70 6 104 69 6 104 69 6
41086 -104 69 6 91 60 6 82 62 34 90 90 90
41087 - 62 62 62 38 38 38 22 22 22 14 14 14
41088 - 10 10 10 10 10 10 10 10 10 10 10 10
41089 - 10 10 10 10 10 10 6 6 6 10 10 10
41090 - 10 10 10 10 10 10 10 10 10 14 14 14
41091 - 22 22 22 42 42 42 70 70 70 89 81 66
41092 - 80 54 7 104 69 6 124 80 6 137 92 6
41093 -134 86 6 116 81 8 100 82 52 86 86 86
41094 - 58 58 58 30 30 30 14 14 14 6 6 6
41095 - 0 0 0 0 0 0 0 0 0 0 0 0
41096 - 0 0 0 0 0 0 0 0 0 0 0 0
41097 - 0 0 0 0 0 0 0 0 0 0 0 0
41098 - 0 0 0 0 0 0 0 0 0 0 0 0
41099 - 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
41104 - 18 18 18 26 26 26 38 38 38 54 54 54
41105 - 70 70 70 86 86 86 94 86 76 89 81 66
41106 - 89 81 66 86 86 86 74 74 74 50 50 50
41107 - 30 30 30 14 14 14 6 6 6 0 0 0
41108 - 0 0 0 0 0 0 0 0 0 0 0 0
41109 - 0 0 0 0 0 0 0 0 0 0 0 0
41110 - 0 0 0 0 0 0 0 0 0 0 0 0
41111 - 6 6 6 18 18 18 34 34 34 58 58 58
41112 - 82 82 82 89 81 66 89 81 66 89 81 66
41113 - 94 86 66 94 86 76 74 74 74 50 50 50
41114 - 26 26 26 14 14 14 6 6 6 0 0 0
41115 - 0 0 0 0 0 0 0 0 0 0 0 0
41116 - 0 0 0 0 0 0 0 0 0 0 0 0
41117 - 0 0 0 0 0 0 0 0 0 0 0 0
41118 - 0 0 0 0 0 0 0 0 0 0 0 0
41119 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
41125 - 30 30 30 38 38 38 46 46 46 54 54 54
41126 - 50 50 50 42 42 42 30 30 30 18 18 18
41127 - 10 10 10 0 0 0 0 0 0 0 0 0
41128 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 14 14 14 26 26 26
41132 - 38 38 38 50 50 50 58 58 58 58 58 58
41133 - 54 54 54 42 42 42 30 30 30 18 18 18
41134 - 10 10 10 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 0 0 0 0 0 0
41136 - 0 0 0 0 0 0 0 0 0 0 0 0
41137 - 0 0 0 0 0 0 0 0 0 0 0 0
41138 - 0 0 0 0 0 0 0 0 0 0 0 0
41139 - 0 0 0 0 0 0 0 0 0 0 0 0
41140 - 0 0 0 0 0 0 0 0 0 0 0 0
41141 - 0 0 0 0 0 0 0 0 0 0 0 0
41142 - 0 0 0 0 0 0 0 0 0 0 0 0
41143 - 0 0 0 0 0 0 0 0 0 0 0 0
41144 - 0 0 0 0 0 0 0 0 0 6 6 6
41145 - 6 6 6 10 10 10 14 14 14 18 18 18
41146 - 18 18 18 14 14 14 10 10 10 6 6 6
41147 - 0 0 0 0 0 0 0 0 0 0 0 0
41148 - 0 0 0 0 0 0 0 0 0 0 0 0
41149 - 0 0 0 0 0 0 0 0 0 0 0 0
41150 - 0 0 0 0 0 0 0 0 0 0 0 0
41151 - 0 0 0 0 0 0 0 0 0 6 6 6
41152 - 14 14 14 18 18 18 22 22 22 22 22 22
41153 - 18 18 18 14 14 14 10 10 10 6 6 6
41154 - 0 0 0 0 0 0 0 0 0 0 0 0
41155 - 0 0 0 0 0 0 0 0 0 0 0 0
41156 - 0 0 0 0 0 0 0 0 0 0 0 0
41157 - 0 0 0 0 0 0 0 0 0 0 0 0
41158 - 0 0 0 0 0 0 0 0 0 0 0 0
41159 +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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
41229 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
41235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41242 +4 4 4 4 4 4
41243 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41247 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41248 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41252 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41253 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41254 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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
41257 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41261 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41262 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41263 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41266 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41267 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41268 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41269 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41270 +4 4 4 4 4 4
41271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41275 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41276 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41277 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41281 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41282 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41283 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41289 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41290 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41291 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41294 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41295 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41296 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41297 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41298 +4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41303 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41304 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41305 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41306 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41308 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41309 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41310 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41311 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41316 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41317 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41318 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41319 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41320 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41321 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41322 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41323 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41324 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41325 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41326 +4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41330 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41331 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41332 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41333 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41334 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41335 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41336 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41337 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41338 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41339 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41344 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41345 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41346 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41347 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41348 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41349 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41350 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41351 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41352 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41353 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41358 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41359 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41360 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41361 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41362 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41363 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41364 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41365 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41366 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41367 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4
41369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41371 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41372 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41373 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41374 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41375 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41376 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41377 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41378 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41379 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41380 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41381 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41382 +4 4 4 4 4 4
41383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41384 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41385 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41386 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41387 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41388 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41389 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41390 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41391 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41392 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41393 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41394 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41395 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41396 +4 4 4 4 4 4
41397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41398 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41399 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41400 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41401 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41402 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41403 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41404 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41405 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41406 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41407 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41408 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41409 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41410 +0 0 0 4 4 4
41411 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41412 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41413 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41414 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41415 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41416 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41417 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41418 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41419 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41420 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41421 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41422 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41423 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41424 +2 0 0 0 0 0
41425 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41426 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41427 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41428 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41429 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41430 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41431 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41432 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41433 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41434 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41435 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41436 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41437 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41438 +37 38 37 0 0 0
41439 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41440 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41441 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41442 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41443 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41444 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41445 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41446 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41447 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41448 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41449 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41450 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41451 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41452 +85 115 134 4 0 0
41453 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41454 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41455 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41456 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41457 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41458 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41459 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41460 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41461 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41462 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41463 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41464 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41465 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41466 +60 73 81 4 0 0
41467 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41468 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41469 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41470 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41471 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41472 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41473 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41474 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41475 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41476 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41477 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41478 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41479 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41480 +16 19 21 4 0 0
41481 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41482 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41483 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41484 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41485 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41486 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41487 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41488 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41489 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41490 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41491 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41492 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41493 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41494 +4 0 0 4 3 3
41495 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41496 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41497 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41499 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41500 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41501 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41502 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41503 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41504 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41505 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41506 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41507 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41508 +3 2 2 4 4 4
41509 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41510 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41511 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41512 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41513 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41514 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41515 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41516 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41517 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41518 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41519 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41520 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41521 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41522 +4 4 4 4 4 4
41523 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41524 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41525 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41526 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41527 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41528 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41529 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41530 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41531 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41532 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41533 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41534 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41535 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41536 +4 4 4 4 4 4
41537 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41538 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41539 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41540 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41541 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41542 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41543 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41544 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41545 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41546 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41547 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41548 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41549 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41550 +5 5 5 5 5 5
41551 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41552 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41553 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41554 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41555 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41556 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41557 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41558 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41559 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41560 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41561 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41562 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41563 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41564 +5 5 5 4 4 4
41565 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41566 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41567 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41568 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41569 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41570 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41571 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41572 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41573 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41574 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41575 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41576 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41577 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41578 +4 4 4 4 4 4
41579 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41580 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41581 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41582 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41583 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41584 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41585 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41586 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41587 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41588 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41589 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41590 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41591 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41592 +4 4 4 4 4 4
41593 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41594 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41595 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41596 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41597 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41598 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41599 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41600 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41601 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41602 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41603 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41604 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41605 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41606 +4 4 4 4 4 4
41607 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41608 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41609 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41610 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41611 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41612 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41613 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41614 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41615 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41616 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41617 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41618 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41619 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41620 +4 4 4 4 4 4
41621 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41622 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41623 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41624 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41625 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41626 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41627 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41628 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41629 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41630 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41631 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41632 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41633 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41634 +4 4 4 4 4 4
41635 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41636 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41637 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41638 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41639 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41640 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41641 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41642 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41643 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41644 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41645 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41646 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41647 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41648 +4 4 4 4 4 4
41649 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41650 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41651 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41652 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41653 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41654 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41655 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41656 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41657 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41658 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41659 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41660 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41661 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41662 +4 4 4 4 4 4
41663 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41664 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41665 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41666 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41667 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41668 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41669 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41670 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41671 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41672 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41673 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41675 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41676 +4 4 4 4 4 4
41677 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41678 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41679 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41680 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41681 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41682 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41683 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41684 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41685 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41686 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41687 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41690 +4 4 4 4 4 4
41691 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41692 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41693 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41694 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41695 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41696 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41697 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41698 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41699 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41700 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41701 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41704 +4 4 4 4 4 4
41705 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41706 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41707 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41708 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41709 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41710 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41711 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41712 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41713 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41714 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41715 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41718 +4 4 4 4 4 4
41719 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41720 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41721 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41722 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41723 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41724 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41725 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41726 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41727 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41728 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41729 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41732 +4 4 4 4 4 4
41733 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41734 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41735 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41736 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41737 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41738 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41739 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41740 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41741 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41742 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41743 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41746 +4 4 4 4 4 4
41747 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41748 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41749 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41750 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41751 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41752 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41753 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41754 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41755 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41756 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41757 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41760 +4 4 4 4 4 4
41761 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41762 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41763 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41764 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41765 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41766 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41767 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41768 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41769 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41770 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41771 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41774 +4 4 4 4 4 4
41775 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41776 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41777 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41778 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41779 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41780 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41781 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41782 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41783 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41784 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41785 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41788 +4 4 4 4 4 4
41789 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41790 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41791 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41792 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41793 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41794 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41795 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41796 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41797 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41798 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41799 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41801 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41802 +4 4 4 4 4 4
41803 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41804 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41805 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41806 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41807 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41808 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41809 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41810 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41811 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41812 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41813 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41815 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41816 +4 4 4 4 4 4
41817 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41818 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41819 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41820 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41821 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41822 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41823 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41824 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41825 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41826 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41827 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41829 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41830 +4 4 4 4 4 4
41831 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41832 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41833 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41834 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41835 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41836 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41837 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41838 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41839 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41840 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41841 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41843 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41844 +4 4 4 4 4 4
41845 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41846 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41847 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41848 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41849 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41850 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41851 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41852 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41853 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41854 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41855 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41857 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41858 +4 4 4 4 4 4
41859 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41860 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41861 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41862 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41863 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41864 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41865 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41866 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41867 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41868 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41869 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41871 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41872 +4 4 4 4 4 4
41873 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41874 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41875 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41876 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41877 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41878 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41879 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41880 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41881 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41882 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41883 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41885 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41886 +4 4 4 4 4 4
41887 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
41888 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
41889 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
41890 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
41891 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41892 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
41893 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
41894 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
41895 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
41896 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41897 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41899 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41900 +4 4 4 4 4 4
41901 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41902 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
41903 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
41904 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
41905 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
41906 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
41907 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
41908 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
41909 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
41910 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41911 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41914 +4 4 4 4 4 4
41915 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
41916 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
41917 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
41918 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
41919 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
41920 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
41921 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
41922 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
41923 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
41924 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
41925 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41928 +4 4 4 4 4 4
41929 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
41930 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41931 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
41932 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
41933 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
41934 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
41935 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
41936 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
41937 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
41938 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
41939 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41942 +4 4 4 4 4 4
41943 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
41944 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
41945 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
41946 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
41947 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
41948 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
41949 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41950 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
41951 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
41952 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
41953 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41956 +4 4 4 4 4 4
41957 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
41958 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
41959 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
41960 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
41961 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
41962 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
41963 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
41964 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
41965 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
41966 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
41967 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41970 +4 4 4 4 4 4
41971 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
41972 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
41973 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
41974 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
41975 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
41976 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
41977 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
41978 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
41979 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
41980 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
41981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41984 +4 4 4 4 4 4
41985 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
41986 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
41987 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
41988 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
41989 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
41990 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
41991 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
41992 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
41993 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
41994 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
41995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41998 +4 4 4 4 4 4
41999 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42000 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42001 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42002 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42003 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42004 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42005 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42006 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42007 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42008 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42012 +4 4 4 4 4 4
42013 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42014 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42015 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42016 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42017 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42018 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42019 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42020 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42021 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42022 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42026 +4 4 4 4 4 4
42027 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42028 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42029 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42030 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42031 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42032 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42033 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42034 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42035 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42036 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42040 +4 4 4 4 4 4
42041 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42042 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42043 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42044 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42045 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42046 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42047 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42048 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42049 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42050 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42051 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42054 +4 4 4 4 4 4
42055 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42056 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42057 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42058 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42059 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42060 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42061 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42062 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42063 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42064 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42065 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42068 +4 4 4 4 4 4
42069 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42070 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42071 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42072 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42073 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42074 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42075 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42076 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
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 4 4 4 4 4 4 4 4 4 4 4 4
42079 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42082 +4 4 4 4 4 4
42083 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42084 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42085 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42086 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42087 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42088 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42089 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42090 +6 6 6 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42096 +4 4 4 4 4 4
42097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42098 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42099 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42100 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42101 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42102 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42103 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42104 +4 0 0 4 3 3 6 6 6 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
42109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42110 +4 4 4 4 4 4
42111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42112 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42113 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42114 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42115 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42116 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42117 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42118 +6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42124 +4 4 4 4 4 4
42125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42126 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42127 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42128 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42129 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42130 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42131 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42132 +5 5 5 5 5 5 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 4 4 4 4 4 4 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 4 4 4
42138 +4 4 4 4 4 4
42139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42141 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42142 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42143 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42144 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42145 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42146 +4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42152 +4 4 4 4 4 4
42153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42156 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42157 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42158 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42159 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
42163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42166 +4 4 4 4 4 4
42167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42170 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42171 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42172 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42173 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
42177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4
42181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42184 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42185 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42186 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42187 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4
42195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42199 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42200 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42201 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4
42209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42213 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42214 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42215 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4
42223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42227 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42228 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42229 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4
42237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42241 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42242 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42243 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
42247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4
42251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42256 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
42261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264 +4 4 4 4 4 4
42265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42268 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42269 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42270 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42278 +4 4 4 4 4 4
42279 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42280 index 8af6414..658c030 100644
42281 --- a/drivers/video/udlfb.c
42282 +++ b/drivers/video/udlfb.c
42283 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42284 dlfb_urb_completion(urb);
42285
42286 error:
42287 - atomic_add(bytes_sent, &dev->bytes_sent);
42288 - atomic_add(bytes_identical, &dev->bytes_identical);
42289 - atomic_add(width*height*2, &dev->bytes_rendered);
42290 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42291 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42292 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42293 end_cycles = get_cycles();
42294 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42295 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42296 >> 10)), /* Kcycles */
42297 &dev->cpu_kcycles_used);
42298
42299 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42300 dlfb_urb_completion(urb);
42301
42302 error:
42303 - atomic_add(bytes_sent, &dev->bytes_sent);
42304 - atomic_add(bytes_identical, &dev->bytes_identical);
42305 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42306 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42307 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42308 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42309 end_cycles = get_cycles();
42310 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42311 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42312 >> 10)), /* Kcycles */
42313 &dev->cpu_kcycles_used);
42314 }
42315 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_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_rendered));
42320 + atomic_read_unchecked(&dev->bytes_rendered));
42321 }
42322
42323 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42324 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_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->bytes_identical));
42329 + atomic_read_unchecked(&dev->bytes_identical));
42330 }
42331
42332 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42333 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42334 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42335 struct dlfb_data *dev = fb_info->par;
42336 return snprintf(buf, PAGE_SIZE, "%u\n",
42337 - atomic_read(&dev->bytes_sent));
42338 + atomic_read_unchecked(&dev->bytes_sent));
42339 }
42340
42341 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42342 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42343 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42344 struct dlfb_data *dev = fb_info->par;
42345 return snprintf(buf, PAGE_SIZE, "%u\n",
42346 - atomic_read(&dev->cpu_kcycles_used));
42347 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42348 }
42349
42350 static ssize_t edid_show(
42351 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42352 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42353 struct dlfb_data *dev = fb_info->par;
42354
42355 - atomic_set(&dev->bytes_rendered, 0);
42356 - atomic_set(&dev->bytes_identical, 0);
42357 - atomic_set(&dev->bytes_sent, 0);
42358 - atomic_set(&dev->cpu_kcycles_used, 0);
42359 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42360 + atomic_set_unchecked(&dev->bytes_identical, 0);
42361 + atomic_set_unchecked(&dev->bytes_sent, 0);
42362 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42363
42364 return count;
42365 }
42366 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42367 index b0e2a42..e2df3ad 100644
42368 --- a/drivers/video/uvesafb.c
42369 +++ b/drivers/video/uvesafb.c
42370 @@ -19,6 +19,7 @@
42371 #include <linux/io.h>
42372 #include <linux/mutex.h>
42373 #include <linux/slab.h>
42374 +#include <linux/moduleloader.h>
42375 #include <video/edid.h>
42376 #include <video/uvesafb.h>
42377 #ifdef CONFIG_X86
42378 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42379 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42380 par->pmi_setpal = par->ypan = 0;
42381 } else {
42382 +
42383 +#ifdef CONFIG_PAX_KERNEXEC
42384 +#ifdef CONFIG_MODULES
42385 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42386 +#endif
42387 + if (!par->pmi_code) {
42388 + par->pmi_setpal = par->ypan = 0;
42389 + return 0;
42390 + }
42391 +#endif
42392 +
42393 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42394 + task->t.regs.edi);
42395 +
42396 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42397 + pax_open_kernel();
42398 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42399 + pax_close_kernel();
42400 +
42401 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42402 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42403 +#else
42404 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42405 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42406 +#endif
42407 +
42408 printk(KERN_INFO "uvesafb: protected mode interface info at "
42409 "%04x:%04x\n",
42410 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42411 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42412 par->ypan = ypan;
42413
42414 if (par->pmi_setpal || par->ypan) {
42415 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42416 if (__supported_pte_mask & _PAGE_NX) {
42417 par->pmi_setpal = par->ypan = 0;
42418 printk(KERN_WARNING "uvesafb: NX protection is actively."
42419 "We have better not to use the PMI.\n");
42420 - } else {
42421 + } else
42422 +#endif
42423 uvesafb_vbe_getpmi(task, par);
42424 - }
42425 }
42426 #else
42427 /* The protected mode interface is not available on non-x86. */
42428 @@ -1836,6 +1860,11 @@ out:
42429 if (par->vbe_modes)
42430 kfree(par->vbe_modes);
42431
42432 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42433 + if (par->pmi_code)
42434 + module_free_exec(NULL, par->pmi_code);
42435 +#endif
42436 +
42437 framebuffer_release(info);
42438 return err;
42439 }
42440 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42441 kfree(par->vbe_state_orig);
42442 if (par->vbe_state_saved)
42443 kfree(par->vbe_state_saved);
42444 +
42445 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42446 + if (par->pmi_code)
42447 + module_free_exec(NULL, par->pmi_code);
42448 +#endif
42449 +
42450 }
42451
42452 framebuffer_release(info);
42453 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42454 index 501b340..86bd4cf 100644
42455 --- a/drivers/video/vesafb.c
42456 +++ b/drivers/video/vesafb.c
42457 @@ -9,6 +9,7 @@
42458 */
42459
42460 #include <linux/module.h>
42461 +#include <linux/moduleloader.h>
42462 #include <linux/kernel.h>
42463 #include <linux/errno.h>
42464 #include <linux/string.h>
42465 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42466 static int vram_total __initdata; /* Set total amount of memory */
42467 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42468 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42469 -static void (*pmi_start)(void) __read_mostly;
42470 -static void (*pmi_pal) (void) __read_mostly;
42471 +static void (*pmi_start)(void) __read_only;
42472 +static void (*pmi_pal) (void) __read_only;
42473 static int depth __read_mostly;
42474 static int vga_compat __read_mostly;
42475 /* --------------------------------------------------------------------- */
42476 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42477 unsigned int size_vmode;
42478 unsigned int size_remap;
42479 unsigned int size_total;
42480 + void *pmi_code = NULL;
42481
42482 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42483 return -ENODEV;
42484 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42485 size_remap = size_total;
42486 vesafb_fix.smem_len = size_remap;
42487
42488 -#ifndef __i386__
42489 - screen_info.vesapm_seg = 0;
42490 -#endif
42491 -
42492 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42493 printk(KERN_WARNING
42494 "vesafb: cannot reserve video memory at 0x%lx\n",
42495 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42496 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42497 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42498
42499 +#ifdef __i386__
42500 +
42501 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42502 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42503 + if (!pmi_code)
42504 +#elif !defined(CONFIG_PAX_KERNEXEC)
42505 + if (0)
42506 +#endif
42507 +
42508 +#endif
42509 + screen_info.vesapm_seg = 0;
42510 +
42511 if (screen_info.vesapm_seg) {
42512 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42513 - screen_info.vesapm_seg,screen_info.vesapm_off);
42514 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42515 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42516 }
42517
42518 if (screen_info.vesapm_seg < 0xc000)
42519 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42520
42521 if (ypan || pmi_setpal) {
42522 unsigned short *pmi_base;
42523 +
42524 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42525 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42526 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42527 +
42528 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42529 + pax_open_kernel();
42530 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42531 +#else
42532 + pmi_code = pmi_base;
42533 +#endif
42534 +
42535 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42536 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42537 +
42538 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42539 + pmi_start = ktva_ktla(pmi_start);
42540 + pmi_pal = ktva_ktla(pmi_pal);
42541 + pax_close_kernel();
42542 +#endif
42543 +
42544 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42545 if (pmi_base[3]) {
42546 printk(KERN_INFO "vesafb: pmi: ports = ");
42547 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42548 info->node, info->fix.id);
42549 return 0;
42550 err:
42551 +
42552 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42553 + module_free_exec(NULL, pmi_code);
42554 +#endif
42555 +
42556 if (info->screen_base)
42557 iounmap(info->screen_base);
42558 framebuffer_release(info);
42559 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42560 index 88714ae..16c2e11 100644
42561 --- a/drivers/video/via/via_clock.h
42562 +++ b/drivers/video/via/via_clock.h
42563 @@ -56,7 +56,7 @@ struct via_clock {
42564
42565 void (*set_engine_pll_state)(u8 state);
42566 void (*set_engine_pll)(struct via_pll_config config);
42567 -};
42568 +} __no_const;
42569
42570
42571 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42572 diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
42573 index 453db0c..604973e 100644
42574 --- a/drivers/virtio/virtio_mmio.c
42575 +++ b/drivers/virtio/virtio_mmio.c
42576 @@ -521,7 +521,7 @@ static int vm_cmdline_set(const char *device,
42577
42578 resources[0].end = memparse(device, &str) - 1;
42579
42580 - processed = sscanf(str, "@%lli:%u%n:%d%n",
42581 + processed = sscanf(str, "@%lli:%llu%n:%d%n",
42582 &base, &resources[1].start, &consumed,
42583 &vm_cmdline_id, &consumed);
42584
42585 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42586 index e56c934..fc22f4b 100644
42587 --- a/drivers/xen/xen-pciback/conf_space.h
42588 +++ b/drivers/xen/xen-pciback/conf_space.h
42589 @@ -44,15 +44,15 @@ struct config_field {
42590 struct {
42591 conf_dword_write write;
42592 conf_dword_read read;
42593 - } dw;
42594 + } __no_const dw;
42595 struct {
42596 conf_word_write write;
42597 conf_word_read read;
42598 - } w;
42599 + } __no_const w;
42600 struct {
42601 conf_byte_write write;
42602 conf_byte_read read;
42603 - } b;
42604 + } __no_const b;
42605 } u;
42606 struct list_head list;
42607 };
42608 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42609 index cbf9dbb..35c3af7 100644
42610 --- a/fs/9p/vfs_inode.c
42611 +++ b/fs/9p/vfs_inode.c
42612 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42613 void
42614 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42615 {
42616 - char *s = nd_get_link(nd);
42617 + const char *s = nd_get_link(nd);
42618
42619 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42620 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42621 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42622 index 0225742..1cd4732 100644
42623 --- a/fs/Kconfig.binfmt
42624 +++ b/fs/Kconfig.binfmt
42625 @@ -89,7 +89,7 @@ config HAVE_AOUT
42626
42627 config BINFMT_AOUT
42628 tristate "Kernel support for a.out and ECOFF binaries"
42629 - depends on HAVE_AOUT
42630 + depends on HAVE_AOUT && BROKEN
42631 ---help---
42632 A.out (Assembler.OUTput) is a set of formats for libraries and
42633 executables used in the earliest versions of UNIX. Linux used
42634 diff --git a/fs/aio.c b/fs/aio.c
42635 index 71f613c..9d01f1f 100644
42636 --- a/fs/aio.c
42637 +++ b/fs/aio.c
42638 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42639 size += sizeof(struct io_event) * nr_events;
42640 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42641
42642 - if (nr_pages < 0)
42643 + if (nr_pages <= 0)
42644 return -EINVAL;
42645
42646 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42647 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42648 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42649 {
42650 ssize_t ret;
42651 + struct iovec iovstack;
42652
42653 #ifdef CONFIG_COMPAT
42654 if (compat)
42655 ret = compat_rw_copy_check_uvector(type,
42656 (struct compat_iovec __user *)kiocb->ki_buf,
42657 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42658 + kiocb->ki_nbytes, 1, &iovstack,
42659 &kiocb->ki_iovec);
42660 else
42661 #endif
42662 ret = rw_copy_check_uvector(type,
42663 (struct iovec __user *)kiocb->ki_buf,
42664 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42665 + kiocb->ki_nbytes, 1, &iovstack,
42666 &kiocb->ki_iovec);
42667 if (ret < 0)
42668 goto out;
42669 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42670 if (ret < 0)
42671 goto out;
42672
42673 + if (kiocb->ki_iovec == &iovstack) {
42674 + kiocb->ki_inline_vec = iovstack;
42675 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42676 + }
42677 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42678 kiocb->ki_cur_seg = 0;
42679 /* ki_nbytes/left now reflect bytes instead of segs */
42680 diff --git a/fs/attr.c b/fs/attr.c
42681 index 29e38a1..2bc037b 100644
42682 --- a/fs/attr.c
42683 +++ b/fs/attr.c
42684 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42685 unsigned long limit;
42686
42687 limit = rlimit(RLIMIT_FSIZE);
42688 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42689 if (limit != RLIM_INFINITY && offset > limit)
42690 goto out_sig;
42691 if (offset > inode->i_sb->s_maxbytes)
42692 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42693 index da8876d..4456166 100644
42694 --- a/fs/autofs4/waitq.c
42695 +++ b/fs/autofs4/waitq.c
42696 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42697 {
42698 unsigned long sigpipe, flags;
42699 mm_segment_t fs;
42700 - const char *data = (const char *)addr;
42701 + const char __user *data = (const char __force_user *)addr;
42702 ssize_t wr = 0;
42703
42704 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42705 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42706 return 1;
42707 }
42708
42709 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42710 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42711 +#endif
42712 +
42713 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42714 enum autofs_notify notify)
42715 {
42716 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42717
42718 /* If this is a direct mount request create a dummy name */
42719 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42720 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42721 + /* this name does get written to userland via autofs4_write() */
42722 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42723 +#else
42724 qstr.len = sprintf(name, "%p", dentry);
42725 +#endif
42726 else {
42727 qstr.len = autofs4_getpath(sbi, dentry, &name);
42728 if (!qstr.len) {
42729 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42730 index cf7f3c6..f61080d 100644
42731 --- a/fs/befs/linuxvfs.c
42732 +++ b/fs/befs/linuxvfs.c
42733 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42734 {
42735 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42736 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42737 - char *link = nd_get_link(nd);
42738 + const char *link = nd_get_link(nd);
42739 if (!IS_ERR(link))
42740 kfree(link);
42741 }
42742 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42743 index d146e18..12d1bd1 100644
42744 --- a/fs/binfmt_aout.c
42745 +++ b/fs/binfmt_aout.c
42746 @@ -16,6 +16,7 @@
42747 #include <linux/string.h>
42748 #include <linux/fs.h>
42749 #include <linux/file.h>
42750 +#include <linux/security.h>
42751 #include <linux/stat.h>
42752 #include <linux/fcntl.h>
42753 #include <linux/ptrace.h>
42754 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42755 #endif
42756 # define START_STACK(u) ((void __user *)u.start_stack)
42757
42758 + memset(&dump, 0, sizeof(dump));
42759 +
42760 fs = get_fs();
42761 set_fs(KERNEL_DS);
42762 has_dumped = 1;
42763 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42764
42765 /* If the size of the dump file exceeds the rlimit, then see what would happen
42766 if we wrote the stack, but not the data area. */
42767 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42768 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42769 dump.u_dsize = 0;
42770
42771 /* Make sure we have enough room to write the stack and data areas. */
42772 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42773 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42774 dump.u_ssize = 0;
42775
42776 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42777 rlim = rlimit(RLIMIT_DATA);
42778 if (rlim >= RLIM_INFINITY)
42779 rlim = ~0;
42780 +
42781 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42782 if (ex.a_data + ex.a_bss > rlim)
42783 return -ENOMEM;
42784
42785 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42786
42787 install_exec_creds(bprm);
42788
42789 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42790 + current->mm->pax_flags = 0UL;
42791 +#endif
42792 +
42793 +#ifdef CONFIG_PAX_PAGEEXEC
42794 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42795 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42796 +
42797 +#ifdef CONFIG_PAX_EMUTRAMP
42798 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42799 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42800 +#endif
42801 +
42802 +#ifdef CONFIG_PAX_MPROTECT
42803 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42804 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42805 +#endif
42806 +
42807 + }
42808 +#endif
42809 +
42810 if (N_MAGIC(ex) == OMAGIC) {
42811 unsigned long text_addr, map_size;
42812 loff_t pos;
42813 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42814 }
42815
42816 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42817 - PROT_READ | PROT_WRITE | PROT_EXEC,
42818 + PROT_READ | PROT_WRITE,
42819 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42820 fd_offset + ex.a_text);
42821 if (error != N_DATADDR(ex)) {
42822 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42823 index 0225fdd..9f0ef53 100644
42824 --- a/fs/binfmt_elf.c
42825 +++ b/fs/binfmt_elf.c
42826 @@ -32,6 +32,7 @@
42827 #include <linux/elf.h>
42828 #include <linux/utsname.h>
42829 #include <linux/coredump.h>
42830 +#include <linux/xattr.h>
42831 #include <asm/uaccess.h>
42832 #include <asm/param.h>
42833 #include <asm/page.h>
42834 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42835 #define elf_core_dump NULL
42836 #endif
42837
42838 +#ifdef CONFIG_PAX_MPROTECT
42839 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42840 +#endif
42841 +
42842 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42843 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42844 #else
42845 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42846 .load_binary = load_elf_binary,
42847 .load_shlib = load_elf_library,
42848 .core_dump = elf_core_dump,
42849 +
42850 +#ifdef CONFIG_PAX_MPROTECT
42851 + .handle_mprotect= elf_handle_mprotect,
42852 +#endif
42853 +
42854 .min_coredump = ELF_EXEC_PAGESIZE,
42855 };
42856
42857 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42858
42859 static int set_brk(unsigned long start, unsigned long end)
42860 {
42861 + unsigned long e = end;
42862 +
42863 start = ELF_PAGEALIGN(start);
42864 end = ELF_PAGEALIGN(end);
42865 if (end > start) {
42866 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42867 if (BAD_ADDR(addr))
42868 return addr;
42869 }
42870 - current->mm->start_brk = current->mm->brk = end;
42871 + current->mm->start_brk = current->mm->brk = e;
42872 return 0;
42873 }
42874
42875 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42876 elf_addr_t __user *u_rand_bytes;
42877 const char *k_platform = ELF_PLATFORM;
42878 const char *k_base_platform = ELF_BASE_PLATFORM;
42879 - unsigned char k_rand_bytes[16];
42880 + u32 k_rand_bytes[4];
42881 int items;
42882 elf_addr_t *elf_info;
42883 int ei_index = 0;
42884 const struct cred *cred = current_cred();
42885 struct vm_area_struct *vma;
42886 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42887
42888 /*
42889 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42890 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42891 * Generate 16 random bytes for userspace PRNG seeding.
42892 */
42893 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42894 - u_rand_bytes = (elf_addr_t __user *)
42895 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42896 + srandom32(k_rand_bytes[0] ^ random32());
42897 + srandom32(k_rand_bytes[1] ^ random32());
42898 + srandom32(k_rand_bytes[2] ^ random32());
42899 + srandom32(k_rand_bytes[3] ^ random32());
42900 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
42901 + u_rand_bytes = (elf_addr_t __user *) p;
42902 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
42903 return -EFAULT;
42904
42905 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42906 return -EFAULT;
42907 current->mm->env_end = p;
42908
42909 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
42910 +
42911 /* Put the elf_info on the stack in the right place. */
42912 sp = (elf_addr_t __user *)envp + 1;
42913 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
42914 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
42915 return -EFAULT;
42916 return 0;
42917 }
42918 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42919 {
42920 struct elf_phdr *elf_phdata;
42921 struct elf_phdr *eppnt;
42922 - unsigned long load_addr = 0;
42923 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
42924 int load_addr_set = 0;
42925 unsigned long last_bss = 0, elf_bss = 0;
42926 - unsigned long error = ~0UL;
42927 + unsigned long error = -EINVAL;
42928 unsigned long total_size;
42929 int retval, i, size;
42930
42931 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42932 goto out_close;
42933 }
42934
42935 +#ifdef CONFIG_PAX_SEGMEXEC
42936 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
42937 + pax_task_size = SEGMEXEC_TASK_SIZE;
42938 +#endif
42939 +
42940 eppnt = elf_phdata;
42941 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
42942 if (eppnt->p_type == PT_LOAD) {
42943 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
42944 k = load_addr + eppnt->p_vaddr;
42945 if (BAD_ADDR(k) ||
42946 eppnt->p_filesz > eppnt->p_memsz ||
42947 - eppnt->p_memsz > TASK_SIZE ||
42948 - TASK_SIZE - eppnt->p_memsz < k) {
42949 + eppnt->p_memsz > pax_task_size ||
42950 + pax_task_size - eppnt->p_memsz < k) {
42951 error = -ENOMEM;
42952 goto out_close;
42953 }
42954 @@ -523,6 +547,311 @@ out:
42955 return error;
42956 }
42957
42958 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
42959 +#ifdef CONFIG_PAX_SOFTMODE
42960 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
42961 +{
42962 + unsigned long pax_flags = 0UL;
42963 +
42964 +#ifdef CONFIG_PAX_PAGEEXEC
42965 + if (elf_phdata->p_flags & PF_PAGEEXEC)
42966 + pax_flags |= MF_PAX_PAGEEXEC;
42967 +#endif
42968 +
42969 +#ifdef CONFIG_PAX_SEGMEXEC
42970 + if (elf_phdata->p_flags & PF_SEGMEXEC)
42971 + pax_flags |= MF_PAX_SEGMEXEC;
42972 +#endif
42973 +
42974 +#ifdef CONFIG_PAX_EMUTRAMP
42975 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
42976 + pax_flags |= MF_PAX_EMUTRAMP;
42977 +#endif
42978 +
42979 +#ifdef CONFIG_PAX_MPROTECT
42980 + if (elf_phdata->p_flags & PF_MPROTECT)
42981 + pax_flags |= MF_PAX_MPROTECT;
42982 +#endif
42983 +
42984 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
42985 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
42986 + pax_flags |= MF_PAX_RANDMMAP;
42987 +#endif
42988 +
42989 + return pax_flags;
42990 +}
42991 +#endif
42992 +
42993 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
42994 +{
42995 + unsigned long pax_flags = 0UL;
42996 +
42997 +#ifdef CONFIG_PAX_PAGEEXEC
42998 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
42999 + pax_flags |= MF_PAX_PAGEEXEC;
43000 +#endif
43001 +
43002 +#ifdef CONFIG_PAX_SEGMEXEC
43003 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43004 + pax_flags |= MF_PAX_SEGMEXEC;
43005 +#endif
43006 +
43007 +#ifdef CONFIG_PAX_EMUTRAMP
43008 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43009 + pax_flags |= MF_PAX_EMUTRAMP;
43010 +#endif
43011 +
43012 +#ifdef CONFIG_PAX_MPROTECT
43013 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43014 + pax_flags |= MF_PAX_MPROTECT;
43015 +#endif
43016 +
43017 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43018 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43019 + pax_flags |= MF_PAX_RANDMMAP;
43020 +#endif
43021 +
43022 + return pax_flags;
43023 +}
43024 +#endif
43025 +
43026 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43027 +#ifdef CONFIG_PAX_SOFTMODE
43028 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43029 +{
43030 + unsigned long pax_flags = 0UL;
43031 +
43032 +#ifdef CONFIG_PAX_PAGEEXEC
43033 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43034 + pax_flags |= MF_PAX_PAGEEXEC;
43035 +#endif
43036 +
43037 +#ifdef CONFIG_PAX_SEGMEXEC
43038 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43039 + pax_flags |= MF_PAX_SEGMEXEC;
43040 +#endif
43041 +
43042 +#ifdef CONFIG_PAX_EMUTRAMP
43043 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43044 + pax_flags |= MF_PAX_EMUTRAMP;
43045 +#endif
43046 +
43047 +#ifdef CONFIG_PAX_MPROTECT
43048 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43049 + pax_flags |= MF_PAX_MPROTECT;
43050 +#endif
43051 +
43052 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43053 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43054 + pax_flags |= MF_PAX_RANDMMAP;
43055 +#endif
43056 +
43057 + return pax_flags;
43058 +}
43059 +#endif
43060 +
43061 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43062 +{
43063 + unsigned long pax_flags = 0UL;
43064 +
43065 +#ifdef CONFIG_PAX_PAGEEXEC
43066 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43067 + pax_flags |= MF_PAX_PAGEEXEC;
43068 +#endif
43069 +
43070 +#ifdef CONFIG_PAX_SEGMEXEC
43071 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43072 + pax_flags |= MF_PAX_SEGMEXEC;
43073 +#endif
43074 +
43075 +#ifdef CONFIG_PAX_EMUTRAMP
43076 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43077 + pax_flags |= MF_PAX_EMUTRAMP;
43078 +#endif
43079 +
43080 +#ifdef CONFIG_PAX_MPROTECT
43081 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43082 + pax_flags |= MF_PAX_MPROTECT;
43083 +#endif
43084 +
43085 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43086 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43087 + pax_flags |= MF_PAX_RANDMMAP;
43088 +#endif
43089 +
43090 + return pax_flags;
43091 +}
43092 +#endif
43093 +
43094 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43095 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43096 +{
43097 + unsigned long pax_flags = 0UL;
43098 +
43099 +#ifdef CONFIG_PAX_EI_PAX
43100 +
43101 +#ifdef CONFIG_PAX_PAGEEXEC
43102 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43103 + pax_flags |= MF_PAX_PAGEEXEC;
43104 +#endif
43105 +
43106 +#ifdef CONFIG_PAX_SEGMEXEC
43107 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43108 + pax_flags |= MF_PAX_SEGMEXEC;
43109 +#endif
43110 +
43111 +#ifdef CONFIG_PAX_EMUTRAMP
43112 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43113 + pax_flags |= MF_PAX_EMUTRAMP;
43114 +#endif
43115 +
43116 +#ifdef CONFIG_PAX_MPROTECT
43117 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43118 + pax_flags |= MF_PAX_MPROTECT;
43119 +#endif
43120 +
43121 +#ifdef CONFIG_PAX_ASLR
43122 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43123 + pax_flags |= MF_PAX_RANDMMAP;
43124 +#endif
43125 +
43126 +#else
43127 +
43128 +#ifdef CONFIG_PAX_PAGEEXEC
43129 + pax_flags |= MF_PAX_PAGEEXEC;
43130 +#endif
43131 +
43132 +#ifdef CONFIG_PAX_SEGMEXEC
43133 + pax_flags |= MF_PAX_SEGMEXEC;
43134 +#endif
43135 +
43136 +#ifdef CONFIG_PAX_MPROTECT
43137 + pax_flags |= MF_PAX_MPROTECT;
43138 +#endif
43139 +
43140 +#ifdef CONFIG_PAX_RANDMMAP
43141 + if (randomize_va_space)
43142 + pax_flags |= MF_PAX_RANDMMAP;
43143 +#endif
43144 +
43145 +#endif
43146 +
43147 + return pax_flags;
43148 +}
43149 +
43150 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43151 +{
43152 +
43153 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43154 + unsigned long i;
43155 +
43156 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43157 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43158 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43159 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43160 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43161 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43162 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43163 + return ~0UL;
43164 +
43165 +#ifdef CONFIG_PAX_SOFTMODE
43166 + if (pax_softmode)
43167 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43168 + else
43169 +#endif
43170 +
43171 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43172 + break;
43173 + }
43174 +#endif
43175 +
43176 + return ~0UL;
43177 +}
43178 +
43179 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43180 +{
43181 +
43182 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43183 + ssize_t xattr_size, i;
43184 + unsigned char xattr_value[5];
43185 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43186 +
43187 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43188 + if (xattr_size <= 0)
43189 + return ~0UL;
43190 +
43191 + for (i = 0; i < xattr_size; i++)
43192 + switch (xattr_value[i]) {
43193 + default:
43194 + return ~0UL;
43195 +
43196 +#define parse_flag(option1, option2, flag) \
43197 + case option1: \
43198 + pax_flags_hardmode |= MF_PAX_##flag; \
43199 + break; \
43200 + case option2: \
43201 + pax_flags_softmode |= MF_PAX_##flag; \
43202 + break;
43203 +
43204 + parse_flag('p', 'P', PAGEEXEC);
43205 + parse_flag('e', 'E', EMUTRAMP);
43206 + parse_flag('m', 'M', MPROTECT);
43207 + parse_flag('r', 'R', RANDMMAP);
43208 + parse_flag('s', 'S', SEGMEXEC);
43209 +
43210 +#undef parse_flag
43211 + }
43212 +
43213 + if (pax_flags_hardmode & pax_flags_softmode)
43214 + return ~0UL;
43215 +
43216 +#ifdef CONFIG_PAX_SOFTMODE
43217 + if (pax_softmode)
43218 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43219 + else
43220 +#endif
43221 +
43222 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43223 +#else
43224 + return ~0UL;
43225 +#endif
43226 +
43227 +}
43228 +
43229 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43230 +{
43231 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43232 +
43233 + pax_flags = pax_parse_ei_pax(elf_ex);
43234 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43235 + xattr_pax_flags = pax_parse_xattr_pax(file);
43236 +
43237 + if (pt_pax_flags == ~0UL)
43238 + pt_pax_flags = xattr_pax_flags;
43239 + else if (xattr_pax_flags == ~0UL)
43240 + xattr_pax_flags = pt_pax_flags;
43241 + if (pt_pax_flags != xattr_pax_flags)
43242 + return -EINVAL;
43243 + if (pt_pax_flags != ~0UL)
43244 + pax_flags = pt_pax_flags;
43245 +
43246 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43247 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43248 + if ((__supported_pte_mask & _PAGE_NX))
43249 + pax_flags &= ~MF_PAX_SEGMEXEC;
43250 + else
43251 + pax_flags &= ~MF_PAX_PAGEEXEC;
43252 + }
43253 +#endif
43254 +
43255 + if (0 > pax_check_flags(&pax_flags))
43256 + return -EINVAL;
43257 +
43258 + current->mm->pax_flags = pax_flags;
43259 + return 0;
43260 +}
43261 +#endif
43262 +
43263 /*
43264 * These are the functions used to load ELF style executables and shared
43265 * libraries. There is no binary dependent code anywhere else.
43266 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43267 {
43268 unsigned int random_variable = 0;
43269
43270 +#ifdef CONFIG_PAX_RANDUSTACK
43271 + if (randomize_va_space)
43272 + return stack_top - current->mm->delta_stack;
43273 +#endif
43274 +
43275 if ((current->flags & PF_RANDOMIZE) &&
43276 !(current->personality & ADDR_NO_RANDOMIZE)) {
43277 random_variable = get_random_int() & STACK_RND_MASK;
43278 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43279 unsigned long load_addr = 0, load_bias = 0;
43280 int load_addr_set = 0;
43281 char * elf_interpreter = NULL;
43282 - unsigned long error;
43283 + unsigned long error = 0;
43284 struct elf_phdr *elf_ppnt, *elf_phdata;
43285 unsigned long elf_bss, elf_brk;
43286 int retval, i;
43287 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43288 unsigned long start_code, end_code, start_data, end_data;
43289 unsigned long reloc_func_desc __maybe_unused = 0;
43290 int executable_stack = EXSTACK_DEFAULT;
43291 - unsigned long def_flags = 0;
43292 struct {
43293 struct elfhdr elf_ex;
43294 struct elfhdr interp_elf_ex;
43295 } *loc;
43296 + unsigned long pax_task_size = TASK_SIZE;
43297
43298 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43299 if (!loc) {
43300 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43301 goto out_free_dentry;
43302
43303 /* OK, This is the point of no return */
43304 - current->mm->def_flags = def_flags;
43305 +
43306 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43307 + current->mm->pax_flags = 0UL;
43308 +#endif
43309 +
43310 +#ifdef CONFIG_PAX_DLRESOLVE
43311 + current->mm->call_dl_resolve = 0UL;
43312 +#endif
43313 +
43314 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43315 + current->mm->call_syscall = 0UL;
43316 +#endif
43317 +
43318 +#ifdef CONFIG_PAX_ASLR
43319 + current->mm->delta_mmap = 0UL;
43320 + current->mm->delta_stack = 0UL;
43321 +#endif
43322 +
43323 + current->mm->def_flags = 0;
43324 +
43325 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43326 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43327 + send_sig(SIGKILL, current, 0);
43328 + goto out_free_dentry;
43329 + }
43330 +#endif
43331 +
43332 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43333 + pax_set_initial_flags(bprm);
43334 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43335 + if (pax_set_initial_flags_func)
43336 + (pax_set_initial_flags_func)(bprm);
43337 +#endif
43338 +
43339 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43340 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43341 + current->mm->context.user_cs_limit = PAGE_SIZE;
43342 + current->mm->def_flags |= VM_PAGEEXEC;
43343 + }
43344 +#endif
43345 +
43346 +#ifdef CONFIG_PAX_SEGMEXEC
43347 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43348 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43349 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43350 + pax_task_size = SEGMEXEC_TASK_SIZE;
43351 + current->mm->def_flags |= VM_NOHUGEPAGE;
43352 + }
43353 +#endif
43354 +
43355 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43356 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43357 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43358 + put_cpu();
43359 + }
43360 +#endif
43361
43362 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43363 may depend on the personality. */
43364 SET_PERSONALITY(loc->elf_ex);
43365 +
43366 +#ifdef CONFIG_PAX_ASLR
43367 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43368 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43369 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43370 + }
43371 +#endif
43372 +
43373 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43374 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43375 + executable_stack = EXSTACK_DISABLE_X;
43376 + current->personality &= ~READ_IMPLIES_EXEC;
43377 + } else
43378 +#endif
43379 +
43380 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43381 current->personality |= READ_IMPLIES_EXEC;
43382
43383 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43384 #else
43385 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43386 #endif
43387 +
43388 +#ifdef CONFIG_PAX_RANDMMAP
43389 + /* PaX: randomize base address at the default exe base if requested */
43390 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43391 +#ifdef CONFIG_SPARC64
43392 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43393 +#else
43394 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43395 +#endif
43396 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43397 + elf_flags |= MAP_FIXED;
43398 + }
43399 +#endif
43400 +
43401 }
43402
43403 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43404 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43405 * allowed task size. Note that p_filesz must always be
43406 * <= p_memsz so it is only necessary to check p_memsz.
43407 */
43408 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43409 - elf_ppnt->p_memsz > TASK_SIZE ||
43410 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43411 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43412 + elf_ppnt->p_memsz > pax_task_size ||
43413 + pax_task_size - elf_ppnt->p_memsz < k) {
43414 /* set_brk can never work. Avoid overflows. */
43415 send_sig(SIGKILL, current, 0);
43416 retval = -EINVAL;
43417 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43418 goto out_free_dentry;
43419 }
43420 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43421 - send_sig(SIGSEGV, current, 0);
43422 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43423 - goto out_free_dentry;
43424 + /*
43425 + * This bss-zeroing can fail if the ELF
43426 + * file specifies odd protections. So
43427 + * we don't check the return value
43428 + */
43429 }
43430
43431 +#ifdef CONFIG_PAX_RANDMMAP
43432 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43433 + unsigned long start, size;
43434 +
43435 + start = ELF_PAGEALIGN(elf_brk);
43436 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43437 + down_read(&current->mm->mmap_sem);
43438 + retval = -ENOMEM;
43439 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43440 + unsigned long prot = PROT_NONE;
43441 +
43442 + up_read(&current->mm->mmap_sem);
43443 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43444 +// if (current->personality & ADDR_NO_RANDOMIZE)
43445 +// prot = PROT_READ;
43446 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43447 + retval = IS_ERR_VALUE(start) ? start : 0;
43448 + } else
43449 + up_read(&current->mm->mmap_sem);
43450 + if (retval == 0)
43451 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43452 + if (retval < 0) {
43453 + send_sig(SIGKILL, current, 0);
43454 + goto out_free_dentry;
43455 + }
43456 + }
43457 +#endif
43458 +
43459 if (elf_interpreter) {
43460 unsigned long uninitialized_var(interp_map_addr);
43461
43462 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43463 * Decide what to dump of a segment, part, all or none.
43464 */
43465 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43466 - unsigned long mm_flags)
43467 + unsigned long mm_flags, long signr)
43468 {
43469 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43470
43471 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43472 if (vma->vm_file == NULL)
43473 return 0;
43474
43475 - if (FILTER(MAPPED_PRIVATE))
43476 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43477 goto whole;
43478
43479 /*
43480 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43481 {
43482 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43483 int i = 0;
43484 - do
43485 + do {
43486 i += 2;
43487 - while (auxv[i - 2] != AT_NULL);
43488 + } while (auxv[i - 2] != AT_NULL);
43489 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43490 }
43491
43492 @@ -1879,14 +2327,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43493 }
43494
43495 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43496 - unsigned long mm_flags)
43497 + struct coredump_params *cprm)
43498 {
43499 struct vm_area_struct *vma;
43500 size_t size = 0;
43501
43502 for (vma = first_vma(current, gate_vma); vma != NULL;
43503 vma = next_vma(vma, gate_vma))
43504 - size += vma_dump_size(vma, mm_flags);
43505 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43506 return size;
43507 }
43508
43509 @@ -1980,7 +2428,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43510
43511 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43512
43513 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43514 + offset += elf_core_vma_data_size(gate_vma, cprm);
43515 offset += elf_core_extra_data_size();
43516 e_shoff = offset;
43517
43518 @@ -1994,10 +2442,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43519 offset = dataoff;
43520
43521 size += sizeof(*elf);
43522 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43523 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43524 goto end_coredump;
43525
43526 size += sizeof(*phdr4note);
43527 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43528 if (size > cprm->limit
43529 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43530 goto end_coredump;
43531 @@ -2011,7 +2461,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43532 phdr.p_offset = offset;
43533 phdr.p_vaddr = vma->vm_start;
43534 phdr.p_paddr = 0;
43535 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43536 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43537 phdr.p_memsz = vma->vm_end - vma->vm_start;
43538 offset += phdr.p_filesz;
43539 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43540 @@ -2022,6 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43541 phdr.p_align = ELF_EXEC_PAGESIZE;
43542
43543 size += sizeof(phdr);
43544 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43545 if (size > cprm->limit
43546 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43547 goto end_coredump;
43548 @@ -2046,7 +2497,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43549 unsigned long addr;
43550 unsigned long end;
43551
43552 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43553 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43554
43555 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43556 struct page *page;
43557 @@ -2055,6 +2506,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43558 page = get_dump_page(addr);
43559 if (page) {
43560 void *kaddr = kmap(page);
43561 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43562 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43563 !dump_write(cprm->file, kaddr,
43564 PAGE_SIZE);
43565 @@ -2072,6 +2524,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43566
43567 if (e_phnum == PN_XNUM) {
43568 size += sizeof(*shdr4extnum);
43569 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43570 if (size > cprm->limit
43571 || !dump_write(cprm->file, shdr4extnum,
43572 sizeof(*shdr4extnum)))
43573 @@ -2092,6 +2545,97 @@ out:
43574
43575 #endif /* CONFIG_ELF_CORE */
43576
43577 +#ifdef CONFIG_PAX_MPROTECT
43578 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43579 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43580 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43581 + *
43582 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43583 + * basis because we want to allow the common case and not the special ones.
43584 + */
43585 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43586 +{
43587 + struct elfhdr elf_h;
43588 + struct elf_phdr elf_p;
43589 + unsigned long i;
43590 + unsigned long oldflags;
43591 + bool is_textrel_rw, is_textrel_rx, is_relro;
43592 +
43593 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43594 + return;
43595 +
43596 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43597 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43598 +
43599 +#ifdef CONFIG_PAX_ELFRELOCS
43600 + /* possible TEXTREL */
43601 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43602 + 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);
43603 +#else
43604 + is_textrel_rw = false;
43605 + is_textrel_rx = false;
43606 +#endif
43607 +
43608 + /* possible RELRO */
43609 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43610 +
43611 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43612 + return;
43613 +
43614 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43615 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43616 +
43617 +#ifdef CONFIG_PAX_ETEXECRELOCS
43618 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43619 +#else
43620 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43621 +#endif
43622 +
43623 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43624 + !elf_check_arch(&elf_h) ||
43625 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43626 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43627 + return;
43628 +
43629 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43630 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43631 + return;
43632 + switch (elf_p.p_type) {
43633 + case PT_DYNAMIC:
43634 + if (!is_textrel_rw && !is_textrel_rx)
43635 + continue;
43636 + i = 0UL;
43637 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43638 + elf_dyn dyn;
43639 +
43640 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43641 + return;
43642 + if (dyn.d_tag == DT_NULL)
43643 + return;
43644 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43645 + gr_log_textrel(vma);
43646 + if (is_textrel_rw)
43647 + vma->vm_flags |= VM_MAYWRITE;
43648 + else
43649 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43650 + vma->vm_flags &= ~VM_MAYWRITE;
43651 + return;
43652 + }
43653 + i++;
43654 + }
43655 + return;
43656 +
43657 + case PT_GNU_RELRO:
43658 + if (!is_relro)
43659 + continue;
43660 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43661 + vma->vm_flags &= ~VM_MAYWRITE;
43662 + return;
43663 + }
43664 + }
43665 +}
43666 +#endif
43667 +
43668 static int __init init_elf_binfmt(void)
43669 {
43670 register_binfmt(&elf_format);
43671 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43672 index 178cb70..8972997 100644
43673 --- a/fs/binfmt_flat.c
43674 +++ b/fs/binfmt_flat.c
43675 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43676 realdatastart = (unsigned long) -ENOMEM;
43677 printk("Unable to allocate RAM for process data, errno %d\n",
43678 (int)-realdatastart);
43679 + down_write(&current->mm->mmap_sem);
43680 vm_munmap(textpos, text_len);
43681 + up_write(&current->mm->mmap_sem);
43682 ret = realdatastart;
43683 goto err;
43684 }
43685 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43686 }
43687 if (IS_ERR_VALUE(result)) {
43688 printk("Unable to read data+bss, errno %d\n", (int)-result);
43689 + down_write(&current->mm->mmap_sem);
43690 vm_munmap(textpos, text_len);
43691 vm_munmap(realdatastart, len);
43692 + up_write(&current->mm->mmap_sem);
43693 ret = result;
43694 goto err;
43695 }
43696 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43697 }
43698 if (IS_ERR_VALUE(result)) {
43699 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43700 + down_write(&current->mm->mmap_sem);
43701 vm_munmap(textpos, text_len + data_len + extra +
43702 MAX_SHARED_LIBS * sizeof(unsigned long));
43703 + up_write(&current->mm->mmap_sem);
43704 ret = result;
43705 goto err;
43706 }
43707 diff --git a/fs/bio.c b/fs/bio.c
43708 index 71072ab..439851b 100644
43709 --- a/fs/bio.c
43710 +++ b/fs/bio.c
43711 @@ -842,7 +842,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43712 /*
43713 * Overflow, abort
43714 */
43715 - if (end < start)
43716 + if (end < start || end - start > INT_MAX - nr_pages)
43717 return ERR_PTR(-EINVAL);
43718
43719 nr_pages += end - start;
43720 @@ -976,7 +976,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43721 /*
43722 * Overflow, abort
43723 */
43724 - if (end < start)
43725 + if (end < start || end - start > INT_MAX - nr_pages)
43726 return ERR_PTR(-EINVAL);
43727
43728 nr_pages += end - start;
43729 @@ -1238,7 +1238,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43730 const int read = bio_data_dir(bio) == READ;
43731 struct bio_map_data *bmd = bio->bi_private;
43732 int i;
43733 - char *p = bmd->sgvecs[0].iov_base;
43734 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43735
43736 __bio_for_each_segment(bvec, bio, i, 0) {
43737 char *addr = page_address(bvec->bv_page);
43738 diff --git a/fs/block_dev.c b/fs/block_dev.c
43739 index 38e721b..7a9c5bc 100644
43740 --- a/fs/block_dev.c
43741 +++ b/fs/block_dev.c
43742 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43743 else if (bdev->bd_contains == bdev)
43744 return true; /* is a whole device which isn't held */
43745
43746 - else if (whole->bd_holder == bd_may_claim)
43747 + else if (whole->bd_holder == (void *)bd_may_claim)
43748 return true; /* is a partition of a device that is being partitioned */
43749 else if (whole->bd_holder != NULL)
43750 return false; /* is a partition of a held device */
43751 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43752 index 9197e2e..7f731f8 100644
43753 --- a/fs/btrfs/check-integrity.c
43754 +++ b/fs/btrfs/check-integrity.c
43755 @@ -155,7 +155,7 @@ struct btrfsic_block {
43756 union {
43757 bio_end_io_t *bio;
43758 bh_end_io_t *bh;
43759 - } orig_bio_bh_end_io;
43760 + } __no_const orig_bio_bh_end_io;
43761 int submit_bio_bh_rw;
43762 u64 flush_gen; /* only valid if !never_written */
43763 };
43764 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43765 index 6d183f6..f47cc7a 100644
43766 --- a/fs/btrfs/ctree.c
43767 +++ b/fs/btrfs/ctree.c
43768 @@ -1037,9 +1037,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43769 free_extent_buffer(buf);
43770 add_root_to_dirty_list(root);
43771 } else {
43772 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43773 - parent_start = parent->start;
43774 - else
43775 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43776 + if (parent)
43777 + parent_start = parent->start;
43778 + else
43779 + parent_start = 0;
43780 + } else
43781 parent_start = 0;
43782
43783 WARN_ON(trans->transid != btrfs_header_generation(parent));
43784 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43785 index ec154f9..bf617a7 100644
43786 --- a/fs/btrfs/inode.c
43787 +++ b/fs/btrfs/inode.c
43788 @@ -7126,7 +7126,7 @@ fail:
43789 return -ENOMEM;
43790 }
43791
43792 -static int btrfs_getattr(struct vfsmount *mnt,
43793 +int btrfs_getattr(struct vfsmount *mnt,
43794 struct dentry *dentry, struct kstat *stat)
43795 {
43796 struct inode *inode = dentry->d_inode;
43797 @@ -7140,6 +7140,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43798 return 0;
43799 }
43800
43801 +EXPORT_SYMBOL(btrfs_getattr);
43802 +
43803 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43804 +{
43805 + return BTRFS_I(inode)->root->anon_dev;
43806 +}
43807 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43808 +
43809 /*
43810 * If a file is moved, it will inherit the cow and compression flags of the new
43811 * directory.
43812 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43813 index 9df50fa..6cd20d0 100644
43814 --- a/fs/btrfs/ioctl.c
43815 +++ b/fs/btrfs/ioctl.c
43816 @@ -2942,9 +2942,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43817 for (i = 0; i < num_types; i++) {
43818 struct btrfs_space_info *tmp;
43819
43820 + /* Don't copy in more than we allocated */
43821 if (!slot_count)
43822 break;
43823
43824 + slot_count--;
43825 +
43826 info = NULL;
43827 rcu_read_lock();
43828 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43829 @@ -2966,10 +2969,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43830 memcpy(dest, &space, sizeof(space));
43831 dest++;
43832 space_args.total_spaces++;
43833 - slot_count--;
43834 }
43835 - if (!slot_count)
43836 - break;
43837 }
43838 up_read(&info->groups_sem);
43839 }
43840 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43841 index 4da0865..01c4778 100644
43842 --- a/fs/btrfs/relocation.c
43843 +++ b/fs/btrfs/relocation.c
43844 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43845 }
43846 spin_unlock(&rc->reloc_root_tree.lock);
43847
43848 - BUG_ON((struct btrfs_root *)node->data != root);
43849 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43850
43851 if (!del) {
43852 spin_lock(&rc->reloc_root_tree.lock);
43853 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43854 index 622f469..e8d2d55 100644
43855 --- a/fs/cachefiles/bind.c
43856 +++ b/fs/cachefiles/bind.c
43857 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43858 args);
43859
43860 /* start by checking things over */
43861 - ASSERT(cache->fstop_percent >= 0 &&
43862 - cache->fstop_percent < cache->fcull_percent &&
43863 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43864 cache->fcull_percent < cache->frun_percent &&
43865 cache->frun_percent < 100);
43866
43867 - ASSERT(cache->bstop_percent >= 0 &&
43868 - cache->bstop_percent < cache->bcull_percent &&
43869 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43870 cache->bcull_percent < cache->brun_percent &&
43871 cache->brun_percent < 100);
43872
43873 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43874 index 0a1467b..6a53245 100644
43875 --- a/fs/cachefiles/daemon.c
43876 +++ b/fs/cachefiles/daemon.c
43877 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43878 if (n > buflen)
43879 return -EMSGSIZE;
43880
43881 - if (copy_to_user(_buffer, buffer, n) != 0)
43882 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43883 return -EFAULT;
43884
43885 return n;
43886 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43887 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43888 return -EIO;
43889
43890 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43891 + if (datalen > PAGE_SIZE - 1)
43892 return -EOPNOTSUPP;
43893
43894 /* drag the command string into the kernel so we can parse it */
43895 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43896 if (args[0] != '%' || args[1] != '\0')
43897 return -EINVAL;
43898
43899 - if (fstop < 0 || fstop >= cache->fcull_percent)
43900 + if (fstop >= cache->fcull_percent)
43901 return cachefiles_daemon_range_error(cache, args);
43902
43903 cache->fstop_percent = fstop;
43904 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
43905 if (args[0] != '%' || args[1] != '\0')
43906 return -EINVAL;
43907
43908 - if (bstop < 0 || bstop >= cache->bcull_percent)
43909 + if (bstop >= cache->bcull_percent)
43910 return cachefiles_daemon_range_error(cache, args);
43911
43912 cache->bstop_percent = bstop;
43913 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
43914 index bd6bc1b..b627b53 100644
43915 --- a/fs/cachefiles/internal.h
43916 +++ b/fs/cachefiles/internal.h
43917 @@ -57,7 +57,7 @@ struct cachefiles_cache {
43918 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
43919 struct rb_root active_nodes; /* active nodes (can't be culled) */
43920 rwlock_t active_lock; /* lock for active_nodes */
43921 - atomic_t gravecounter; /* graveyard uniquifier */
43922 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
43923 unsigned frun_percent; /* when to stop culling (% files) */
43924 unsigned fcull_percent; /* when to start culling (% files) */
43925 unsigned fstop_percent; /* when to stop allocating (% files) */
43926 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
43927 * proc.c
43928 */
43929 #ifdef CONFIG_CACHEFILES_HISTOGRAM
43930 -extern atomic_t cachefiles_lookup_histogram[HZ];
43931 -extern atomic_t cachefiles_mkdir_histogram[HZ];
43932 -extern atomic_t cachefiles_create_histogram[HZ];
43933 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43934 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43935 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
43936
43937 extern int __init cachefiles_proc_init(void);
43938 extern void cachefiles_proc_cleanup(void);
43939 static inline
43940 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
43941 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
43942 {
43943 unsigned long jif = jiffies - start_jif;
43944 if (jif >= HZ)
43945 jif = HZ - 1;
43946 - atomic_inc(&histogram[jif]);
43947 + atomic_inc_unchecked(&histogram[jif]);
43948 }
43949
43950 #else
43951 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
43952 index b0b5f7c..039bb26 100644
43953 --- a/fs/cachefiles/namei.c
43954 +++ b/fs/cachefiles/namei.c
43955 @@ -318,7 +318,7 @@ try_again:
43956 /* first step is to make up a grave dentry in the graveyard */
43957 sprintf(nbuffer, "%08x%08x",
43958 (uint32_t) get_seconds(),
43959 - (uint32_t) atomic_inc_return(&cache->gravecounter));
43960 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
43961
43962 /* do the multiway lock magic */
43963 trap = lock_rename(cache->graveyard, dir);
43964 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
43965 index eccd339..4c1d995 100644
43966 --- a/fs/cachefiles/proc.c
43967 +++ b/fs/cachefiles/proc.c
43968 @@ -14,9 +14,9 @@
43969 #include <linux/seq_file.h>
43970 #include "internal.h"
43971
43972 -atomic_t cachefiles_lookup_histogram[HZ];
43973 -atomic_t cachefiles_mkdir_histogram[HZ];
43974 -atomic_t cachefiles_create_histogram[HZ];
43975 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
43976 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
43977 +atomic_unchecked_t cachefiles_create_histogram[HZ];
43978
43979 /*
43980 * display the latency histogram
43981 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
43982 return 0;
43983 default:
43984 index = (unsigned long) v - 3;
43985 - x = atomic_read(&cachefiles_lookup_histogram[index]);
43986 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
43987 - z = atomic_read(&cachefiles_create_histogram[index]);
43988 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
43989 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
43990 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
43991 if (x == 0 && y == 0 && z == 0)
43992 return 0;
43993
43994 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
43995 index c994691..2a1537f 100644
43996 --- a/fs/cachefiles/rdwr.c
43997 +++ b/fs/cachefiles/rdwr.c
43998 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
43999 old_fs = get_fs();
44000 set_fs(KERNEL_DS);
44001 ret = file->f_op->write(
44002 - file, (const void __user *) data, len, &pos);
44003 + file, (const void __force_user *) data, len, &pos);
44004 set_fs(old_fs);
44005 kunmap(page);
44006 if (ret != len)
44007 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44008 index e5b7731..b9c59fb 100644
44009 --- a/fs/ceph/dir.c
44010 +++ b/fs/ceph/dir.c
44011 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44012 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44013 struct ceph_mds_client *mdsc = fsc->mdsc;
44014 unsigned frag = fpos_frag(filp->f_pos);
44015 - int off = fpos_off(filp->f_pos);
44016 + unsigned int off = fpos_off(filp->f_pos);
44017 int err;
44018 u32 ftype;
44019 struct ceph_mds_reply_info_parsed *rinfo;
44020 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44021 index d9ea6ed..1e6c8ac 100644
44022 --- a/fs/cifs/cifs_debug.c
44023 +++ b/fs/cifs/cifs_debug.c
44024 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44025
44026 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44027 #ifdef CONFIG_CIFS_STATS2
44028 - atomic_set(&totBufAllocCount, 0);
44029 - atomic_set(&totSmBufAllocCount, 0);
44030 + atomic_set_unchecked(&totBufAllocCount, 0);
44031 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44032 #endif /* CONFIG_CIFS_STATS2 */
44033 spin_lock(&cifs_tcp_ses_lock);
44034 list_for_each(tmp1, &cifs_tcp_ses_list) {
44035 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44036 tcon = list_entry(tmp3,
44037 struct cifs_tcon,
44038 tcon_list);
44039 - atomic_set(&tcon->num_smbs_sent, 0);
44040 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44041 if (server->ops->clear_stats)
44042 server->ops->clear_stats(tcon);
44043 }
44044 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44045 smBufAllocCount.counter, cifs_min_small);
44046 #ifdef CONFIG_CIFS_STATS2
44047 seq_printf(m, "Total Large %d Small %d Allocations\n",
44048 - atomic_read(&totBufAllocCount),
44049 - atomic_read(&totSmBufAllocCount));
44050 + atomic_read_unchecked(&totBufAllocCount),
44051 + atomic_read_unchecked(&totSmBufAllocCount));
44052 #endif /* CONFIG_CIFS_STATS2 */
44053
44054 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44055 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44056 if (tcon->need_reconnect)
44057 seq_puts(m, "\tDISCONNECTED ");
44058 seq_printf(m, "\nSMBs: %d",
44059 - atomic_read(&tcon->num_smbs_sent));
44060 + atomic_read_unchecked(&tcon->num_smbs_sent));
44061 if (server->ops->print_stats)
44062 server->ops->print_stats(m, tcon);
44063 }
44064 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44065 index db8a404..c712e2e 100644
44066 --- a/fs/cifs/cifsfs.c
44067 +++ b/fs/cifs/cifsfs.c
44068 @@ -1003,7 +1003,7 @@ cifs_init_request_bufs(void)
44069 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
44070 cifs_req_cachep = kmem_cache_create("cifs_request",
44071 CIFSMaxBufSize + max_hdr_size, 0,
44072 - SLAB_HWCACHE_ALIGN, NULL);
44073 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44074 if (cifs_req_cachep == NULL)
44075 return -ENOMEM;
44076
44077 @@ -1030,7 +1030,7 @@ cifs_init_request_bufs(void)
44078 efficient to alloc 1 per page off the slab compared to 17K (5page)
44079 alloc of large cifs buffers even when page debugging is on */
44080 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44081 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44082 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44083 NULL);
44084 if (cifs_sm_req_cachep == NULL) {
44085 mempool_destroy(cifs_req_poolp);
44086 @@ -1115,8 +1115,8 @@ init_cifs(void)
44087 atomic_set(&bufAllocCount, 0);
44088 atomic_set(&smBufAllocCount, 0);
44089 #ifdef CONFIG_CIFS_STATS2
44090 - atomic_set(&totBufAllocCount, 0);
44091 - atomic_set(&totSmBufAllocCount, 0);
44092 + atomic_set_unchecked(&totBufAllocCount, 0);
44093 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44094 #endif /* CONFIG_CIFS_STATS2 */
44095
44096 atomic_set(&midCount, 0);
44097 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44098 index 977dc0e..ba48ab9 100644
44099 --- a/fs/cifs/cifsglob.h
44100 +++ b/fs/cifs/cifsglob.h
44101 @@ -590,35 +590,35 @@ struct cifs_tcon {
44102 __u16 Flags; /* optional support bits */
44103 enum statusEnum tidStatus;
44104 #ifdef CONFIG_CIFS_STATS
44105 - atomic_t num_smbs_sent;
44106 + atomic_unchecked_t num_smbs_sent;
44107 union {
44108 struct {
44109 - atomic_t num_writes;
44110 - atomic_t num_reads;
44111 - atomic_t num_flushes;
44112 - atomic_t num_oplock_brks;
44113 - atomic_t num_opens;
44114 - atomic_t num_closes;
44115 - atomic_t num_deletes;
44116 - atomic_t num_mkdirs;
44117 - atomic_t num_posixopens;
44118 - atomic_t num_posixmkdirs;
44119 - atomic_t num_rmdirs;
44120 - atomic_t num_renames;
44121 - atomic_t num_t2renames;
44122 - atomic_t num_ffirst;
44123 - atomic_t num_fnext;
44124 - atomic_t num_fclose;
44125 - atomic_t num_hardlinks;
44126 - atomic_t num_symlinks;
44127 - atomic_t num_locks;
44128 - atomic_t num_acl_get;
44129 - atomic_t num_acl_set;
44130 + atomic_unchecked_t num_writes;
44131 + atomic_unchecked_t num_reads;
44132 + atomic_unchecked_t num_flushes;
44133 + atomic_unchecked_t num_oplock_brks;
44134 + atomic_unchecked_t num_opens;
44135 + atomic_unchecked_t num_closes;
44136 + atomic_unchecked_t num_deletes;
44137 + atomic_unchecked_t num_mkdirs;
44138 + atomic_unchecked_t num_posixopens;
44139 + atomic_unchecked_t num_posixmkdirs;
44140 + atomic_unchecked_t num_rmdirs;
44141 + atomic_unchecked_t num_renames;
44142 + atomic_unchecked_t num_t2renames;
44143 + atomic_unchecked_t num_ffirst;
44144 + atomic_unchecked_t num_fnext;
44145 + atomic_unchecked_t num_fclose;
44146 + atomic_unchecked_t num_hardlinks;
44147 + atomic_unchecked_t num_symlinks;
44148 + atomic_unchecked_t num_locks;
44149 + atomic_unchecked_t num_acl_get;
44150 + atomic_unchecked_t num_acl_set;
44151 } cifs_stats;
44152 #ifdef CONFIG_CIFS_SMB2
44153 struct {
44154 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44155 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44156 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
44157 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
44158 } smb2_stats;
44159 #endif /* CONFIG_CIFS_SMB2 */
44160 } stats;
44161 @@ -862,7 +862,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
44162 }
44163
44164 #ifdef CONFIG_CIFS_STATS
44165 -#define cifs_stats_inc atomic_inc
44166 +#define cifs_stats_inc atomic_inc_unchecked
44167
44168 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44169 unsigned int bytes)
44170 @@ -1227,8 +1227,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44171 /* Various Debug counters */
44172 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44173 #ifdef CONFIG_CIFS_STATS2
44174 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44175 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44176 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44177 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44178 #endif
44179 GLOBAL_EXTERN atomic_t smBufAllocCount;
44180 GLOBAL_EXTERN atomic_t midCount;
44181 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44182 index e6ce3b1..adc21fd 100644
44183 --- a/fs/cifs/link.c
44184 +++ b/fs/cifs/link.c
44185 @@ -602,7 +602,7 @@ symlink_exit:
44186
44187 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44188 {
44189 - char *p = nd_get_link(nd);
44190 + const char *p = nd_get_link(nd);
44191 if (!IS_ERR(p))
44192 kfree(p);
44193 }
44194 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44195 index ce41fee..ac0d27a 100644
44196 --- a/fs/cifs/misc.c
44197 +++ b/fs/cifs/misc.c
44198 @@ -169,7 +169,7 @@ cifs_buf_get(void)
44199 memset(ret_buf, 0, buf_size + 3);
44200 atomic_inc(&bufAllocCount);
44201 #ifdef CONFIG_CIFS_STATS2
44202 - atomic_inc(&totBufAllocCount);
44203 + atomic_inc_unchecked(&totBufAllocCount);
44204 #endif /* CONFIG_CIFS_STATS2 */
44205 }
44206
44207 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
44208 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44209 atomic_inc(&smBufAllocCount);
44210 #ifdef CONFIG_CIFS_STATS2
44211 - atomic_inc(&totSmBufAllocCount);
44212 + atomic_inc_unchecked(&totSmBufAllocCount);
44213 #endif /* CONFIG_CIFS_STATS2 */
44214
44215 }
44216 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
44217 index 3129ac7..cc4a948 100644
44218 --- a/fs/cifs/smb1ops.c
44219 +++ b/fs/cifs/smb1ops.c
44220 @@ -524,27 +524,27 @@ static void
44221 cifs_clear_stats(struct cifs_tcon *tcon)
44222 {
44223 #ifdef CONFIG_CIFS_STATS
44224 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
44225 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
44226 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
44227 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44228 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
44229 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
44230 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44231 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
44232 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
44233 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
44234 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
44235 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
44236 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
44237 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
44238 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
44239 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
44240 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
44241 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
44242 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
44243 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
44244 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
44245 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
44246 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
44247 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
44248 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
44249 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
44250 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
44251 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
44252 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
44253 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
44254 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
44255 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
44256 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
44257 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
44258 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
44259 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
44260 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
44261 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
44262 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
44263 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
44264 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
44265 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
44266 #endif
44267 }
44268
44269 @@ -553,36 +553,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44270 {
44271 #ifdef CONFIG_CIFS_STATS
44272 seq_printf(m, " Oplocks breaks: %d",
44273 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
44274 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
44275 seq_printf(m, "\nReads: %d Bytes: %llu",
44276 - atomic_read(&tcon->stats.cifs_stats.num_reads),
44277 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
44278 (long long)(tcon->bytes_read));
44279 seq_printf(m, "\nWrites: %d Bytes: %llu",
44280 - atomic_read(&tcon->stats.cifs_stats.num_writes),
44281 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
44282 (long long)(tcon->bytes_written));
44283 seq_printf(m, "\nFlushes: %d",
44284 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
44285 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
44286 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
44287 - atomic_read(&tcon->stats.cifs_stats.num_locks),
44288 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
44289 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
44290 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
44291 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
44292 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
44293 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
44294 - atomic_read(&tcon->stats.cifs_stats.num_opens),
44295 - atomic_read(&tcon->stats.cifs_stats.num_closes),
44296 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
44297 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
44298 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
44299 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
44300 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
44301 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
44302 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
44303 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
44304 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
44305 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44306 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
44307 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
44308 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
44309 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
44310 seq_printf(m, "\nRenames: %d T2 Renames %d",
44311 - atomic_read(&tcon->stats.cifs_stats.num_renames),
44312 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
44313 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
44314 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
44315 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
44316 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
44317 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
44318 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
44319 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
44320 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
44321 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
44322 #endif
44323 }
44324
44325 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
44326 index 826209b..fa460f4 100644
44327 --- a/fs/cifs/smb2ops.c
44328 +++ b/fs/cifs/smb2ops.c
44329 @@ -219,8 +219,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
44330 #ifdef CONFIG_CIFS_STATS
44331 int i;
44332 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
44333 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44334 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44335 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
44336 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
44337 }
44338 #endif
44339 }
44340 @@ -229,66 +229,66 @@ static void
44341 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
44342 {
44343 #ifdef CONFIG_CIFS_STATS
44344 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44345 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44346 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
44347 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
44348 seq_printf(m, "\nNegotiates: %d sent %d failed",
44349 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
44350 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
44351 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
44352 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
44353 seq_printf(m, "\nSessionSetups: %d sent %d failed",
44354 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
44355 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
44356 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
44357 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
44358 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
44359 seq_printf(m, "\nLogoffs: %d sent %d failed",
44360 - atomic_read(&sent[SMB2_LOGOFF_HE]),
44361 - atomic_read(&failed[SMB2_LOGOFF_HE]));
44362 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
44363 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
44364 seq_printf(m, "\nTreeConnects: %d sent %d failed",
44365 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
44366 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
44367 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
44368 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
44369 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
44370 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
44371 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
44372 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
44373 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
44374 seq_printf(m, "\nCreates: %d sent %d failed",
44375 - atomic_read(&sent[SMB2_CREATE_HE]),
44376 - atomic_read(&failed[SMB2_CREATE_HE]));
44377 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
44378 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
44379 seq_printf(m, "\nCloses: %d sent %d failed",
44380 - atomic_read(&sent[SMB2_CLOSE_HE]),
44381 - atomic_read(&failed[SMB2_CLOSE_HE]));
44382 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
44383 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
44384 seq_printf(m, "\nFlushes: %d sent %d failed",
44385 - atomic_read(&sent[SMB2_FLUSH_HE]),
44386 - atomic_read(&failed[SMB2_FLUSH_HE]));
44387 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
44388 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
44389 seq_printf(m, "\nReads: %d sent %d failed",
44390 - atomic_read(&sent[SMB2_READ_HE]),
44391 - atomic_read(&failed[SMB2_READ_HE]));
44392 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
44393 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
44394 seq_printf(m, "\nWrites: %d sent %d failed",
44395 - atomic_read(&sent[SMB2_WRITE_HE]),
44396 - atomic_read(&failed[SMB2_WRITE_HE]));
44397 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
44398 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
44399 seq_printf(m, "\nLocks: %d sent %d failed",
44400 - atomic_read(&sent[SMB2_LOCK_HE]),
44401 - atomic_read(&failed[SMB2_LOCK_HE]));
44402 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
44403 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
44404 seq_printf(m, "\nIOCTLs: %d sent %d failed",
44405 - atomic_read(&sent[SMB2_IOCTL_HE]),
44406 - atomic_read(&failed[SMB2_IOCTL_HE]));
44407 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
44408 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
44409 seq_printf(m, "\nCancels: %d sent %d failed",
44410 - atomic_read(&sent[SMB2_CANCEL_HE]),
44411 - atomic_read(&failed[SMB2_CANCEL_HE]));
44412 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
44413 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
44414 seq_printf(m, "\nEchos: %d sent %d failed",
44415 - atomic_read(&sent[SMB2_ECHO_HE]),
44416 - atomic_read(&failed[SMB2_ECHO_HE]));
44417 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
44418 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
44419 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
44420 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
44421 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
44422 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
44423 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
44424 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
44425 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
44426 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
44427 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
44428 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
44429 seq_printf(m, "\nQueryInfos: %d sent %d failed",
44430 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
44431 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
44432 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
44433 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
44434 seq_printf(m, "\nSetInfos: %d sent %d failed",
44435 - atomic_read(&sent[SMB2_SET_INFO_HE]),
44436 - atomic_read(&failed[SMB2_SET_INFO_HE]));
44437 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
44438 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
44439 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
44440 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
44441 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
44442 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
44443 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
44444 #endif
44445 }
44446
44447 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44448 index 958ae0e..505c9d0 100644
44449 --- a/fs/coda/cache.c
44450 +++ b/fs/coda/cache.c
44451 @@ -24,7 +24,7 @@
44452 #include "coda_linux.h"
44453 #include "coda_cache.h"
44454
44455 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44456 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44457
44458 /* replace or extend an acl cache hit */
44459 void coda_cache_enter(struct inode *inode, int mask)
44460 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44461 struct coda_inode_info *cii = ITOC(inode);
44462
44463 spin_lock(&cii->c_lock);
44464 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44465 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44466 if (cii->c_uid != current_fsuid()) {
44467 cii->c_uid = current_fsuid();
44468 cii->c_cached_perm = mask;
44469 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44470 {
44471 struct coda_inode_info *cii = ITOC(inode);
44472 spin_lock(&cii->c_lock);
44473 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44474 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44475 spin_unlock(&cii->c_lock);
44476 }
44477
44478 /* remove all acl caches */
44479 void coda_cache_clear_all(struct super_block *sb)
44480 {
44481 - atomic_inc(&permission_epoch);
44482 + atomic_inc_unchecked(&permission_epoch);
44483 }
44484
44485
44486 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44487 spin_lock(&cii->c_lock);
44488 hit = (mask & cii->c_cached_perm) == mask &&
44489 cii->c_uid == current_fsuid() &&
44490 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44491 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44492 spin_unlock(&cii->c_lock);
44493
44494 return hit;
44495 diff --git a/fs/compat.c b/fs/compat.c
44496 index 1bdb350..9f28287 100644
44497 --- a/fs/compat.c
44498 +++ b/fs/compat.c
44499 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44500
44501 set_fs(KERNEL_DS);
44502 /* The __user pointer cast is valid because of the set_fs() */
44503 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44504 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44505 set_fs(oldfs);
44506 /* truncating is ok because it's a user address */
44507 if (!ret)
44508 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44509 goto out;
44510
44511 ret = -EINVAL;
44512 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44513 + if (nr_segs > UIO_MAXIOV)
44514 goto out;
44515 if (nr_segs > fast_segs) {
44516 ret = -ENOMEM;
44517 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44518
44519 struct compat_readdir_callback {
44520 struct compat_old_linux_dirent __user *dirent;
44521 + struct file * file;
44522 int result;
44523 };
44524
44525 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44526 buf->result = -EOVERFLOW;
44527 return -EOVERFLOW;
44528 }
44529 +
44530 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44531 + return 0;
44532 +
44533 buf->result++;
44534 dirent = buf->dirent;
44535 if (!access_ok(VERIFY_WRITE, dirent,
44536 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44537
44538 buf.result = 0;
44539 buf.dirent = dirent;
44540 + buf.file = file;
44541
44542 error = vfs_readdir(file, compat_fillonedir, &buf);
44543 if (buf.result)
44544 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44545 struct compat_getdents_callback {
44546 struct compat_linux_dirent __user *current_dir;
44547 struct compat_linux_dirent __user *previous;
44548 + struct file * file;
44549 int count;
44550 int error;
44551 };
44552 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44553 buf->error = -EOVERFLOW;
44554 return -EOVERFLOW;
44555 }
44556 +
44557 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44558 + return 0;
44559 +
44560 dirent = buf->previous;
44561 if (dirent) {
44562 if (__put_user(offset, &dirent->d_off))
44563 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44564 buf.previous = NULL;
44565 buf.count = count;
44566 buf.error = 0;
44567 + buf.file = file;
44568
44569 error = vfs_readdir(file, compat_filldir, &buf);
44570 if (error >= 0)
44571 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44572 struct compat_getdents_callback64 {
44573 struct linux_dirent64 __user *current_dir;
44574 struct linux_dirent64 __user *previous;
44575 + struct file * file;
44576 int count;
44577 int error;
44578 };
44579 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44580 buf->error = -EINVAL; /* only used if we fail.. */
44581 if (reclen > buf->count)
44582 return -EINVAL;
44583 +
44584 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44585 + return 0;
44586 +
44587 dirent = buf->previous;
44588
44589 if (dirent) {
44590 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44591 buf.previous = NULL;
44592 buf.count = count;
44593 buf.error = 0;
44594 + buf.file = file;
44595
44596 error = vfs_readdir(file, compat_filldir64, &buf);
44597 if (error >= 0)
44598 error = buf.error;
44599 lastdirent = buf.previous;
44600 if (lastdirent) {
44601 - typeof(lastdirent->d_off) d_off = file->f_pos;
44602 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44603 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44604 error = -EFAULT;
44605 else
44606 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44607 index 112e45a..b59845b 100644
44608 --- a/fs/compat_binfmt_elf.c
44609 +++ b/fs/compat_binfmt_elf.c
44610 @@ -30,11 +30,13 @@
44611 #undef elf_phdr
44612 #undef elf_shdr
44613 #undef elf_note
44614 +#undef elf_dyn
44615 #undef elf_addr_t
44616 #define elfhdr elf32_hdr
44617 #define elf_phdr elf32_phdr
44618 #define elf_shdr elf32_shdr
44619 #define elf_note elf32_note
44620 +#define elf_dyn Elf32_Dyn
44621 #define elf_addr_t Elf32_Addr
44622
44623 /*
44624 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44625 index debdfe0..75d31d4 100644
44626 --- a/fs/compat_ioctl.c
44627 +++ b/fs/compat_ioctl.c
44628 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44629
44630 err = get_user(palp, &up->palette);
44631 err |= get_user(length, &up->length);
44632 + if (err)
44633 + return -EFAULT;
44634
44635 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44636 err = put_user(compat_ptr(palp), &up_native->palette);
44637 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44638 return -EFAULT;
44639 if (__get_user(udata, &ss32->iomem_base))
44640 return -EFAULT;
44641 - ss.iomem_base = compat_ptr(udata);
44642 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44643 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44644 __get_user(ss.port_high, &ss32->port_high))
44645 return -EFAULT;
44646 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44647 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44648 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44649 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44650 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44651 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44652 return -EFAULT;
44653
44654 return ioctl_preallocate(file, p);
44655 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44656 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44657 {
44658 unsigned int a, b;
44659 - a = *(unsigned int *)p;
44660 - b = *(unsigned int *)q;
44661 + a = *(const unsigned int *)p;
44662 + b = *(const unsigned int *)q;
44663 if (a > b)
44664 return 1;
44665 if (a < b)
44666 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44667 index 7414ae2..d98ad6d 100644
44668 --- a/fs/configfs/dir.c
44669 +++ b/fs/configfs/dir.c
44670 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44671 }
44672 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44673 struct configfs_dirent *next;
44674 - const char * name;
44675 + const unsigned char * name;
44676 + char d_name[sizeof(next->s_dentry->d_iname)];
44677 int len;
44678 struct inode *inode = NULL;
44679
44680 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44681 continue;
44682
44683 name = configfs_get_name(next);
44684 - len = strlen(name);
44685 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44686 + len = next->s_dentry->d_name.len;
44687 + memcpy(d_name, name, len);
44688 + name = d_name;
44689 + } else
44690 + len = strlen(name);
44691
44692 /*
44693 * We'll have a dentry and an inode for
44694 diff --git a/fs/dcache.c b/fs/dcache.c
44695 index 693f95b..95f1223 100644
44696 --- a/fs/dcache.c
44697 +++ b/fs/dcache.c
44698 @@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
44699 mempages -= reserve;
44700
44701 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44702 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44703 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44704
44705 dcache_init();
44706 inode_init();
44707 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44708 index 4733eab..71ef6fa 100644
44709 --- a/fs/debugfs/inode.c
44710 +++ b/fs/debugfs/inode.c
44711 @@ -406,7 +406,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44712 */
44713 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44714 {
44715 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44716 + return __create_file(name, S_IFDIR | S_IRWXU,
44717 +#else
44718 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44719 +#endif
44720 parent, NULL, NULL);
44721 }
44722 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44723 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44724 index cc7709e..7e7211f 100644
44725 --- a/fs/ecryptfs/inode.c
44726 +++ b/fs/ecryptfs/inode.c
44727 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44728 old_fs = get_fs();
44729 set_fs(get_ds());
44730 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44731 - (char __user *)lower_buf,
44732 + (char __force_user *)lower_buf,
44733 PATH_MAX);
44734 set_fs(old_fs);
44735 if (rc < 0)
44736 @@ -706,7 +706,7 @@ out:
44737 static void
44738 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44739 {
44740 - char *buf = nd_get_link(nd);
44741 + const char *buf = nd_get_link(nd);
44742 if (!IS_ERR(buf)) {
44743 /* Free the char* */
44744 kfree(buf);
44745 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44746 index 412e6ed..4292d22 100644
44747 --- a/fs/ecryptfs/miscdev.c
44748 +++ b/fs/ecryptfs/miscdev.c
44749 @@ -315,7 +315,7 @@ check_list:
44750 goto out_unlock_msg_ctx;
44751 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44752 if (msg_ctx->msg) {
44753 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44754 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44755 goto out_unlock_msg_ctx;
44756 i += packet_length_size;
44757 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44758 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44759 index b2a34a1..162fa69 100644
44760 --- a/fs/ecryptfs/read_write.c
44761 +++ b/fs/ecryptfs/read_write.c
44762 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44763 return -EIO;
44764 fs_save = get_fs();
44765 set_fs(get_ds());
44766 - rc = vfs_write(lower_file, data, size, &offset);
44767 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44768 set_fs(fs_save);
44769 mark_inode_dirty_sync(ecryptfs_inode);
44770 return rc;
44771 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44772 return -EIO;
44773 fs_save = get_fs();
44774 set_fs(get_ds());
44775 - rc = vfs_read(lower_file, data, size, &offset);
44776 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44777 set_fs(fs_save);
44778 return rc;
44779 }
44780 diff --git a/fs/exec.c b/fs/exec.c
44781 index 574cf4d..dfe774a 100644
44782 --- a/fs/exec.c
44783 +++ b/fs/exec.c
44784 @@ -55,6 +55,15 @@
44785 #include <linux/pipe_fs_i.h>
44786 #include <linux/oom.h>
44787 #include <linux/compat.h>
44788 +#include <linux/random.h>
44789 +#include <linux/seq_file.h>
44790 +
44791 +#ifdef CONFIG_PAX_REFCOUNT
44792 +#include <linux/kallsyms.h>
44793 +#include <linux/kdebug.h>
44794 +#endif
44795 +
44796 +#include <trace/events/fs.h>
44797
44798 #include <asm/uaccess.h>
44799 #include <asm/mmu_context.h>
44800 @@ -66,6 +75,18 @@
44801
44802 #include <trace/events/sched.h>
44803
44804 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44805 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44806 +{
44807 + 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");
44808 +}
44809 +#endif
44810 +
44811 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44812 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44813 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44814 +#endif
44815 +
44816 int core_uses_pid;
44817 char core_pattern[CORENAME_MAX_SIZE] = "core";
44818 unsigned int core_pipe_limit;
44819 @@ -75,7 +96,7 @@ struct core_name {
44820 char *corename;
44821 int used, size;
44822 };
44823 -static atomic_t call_count = ATOMIC_INIT(1);
44824 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44825
44826 /* The maximal length of core_pattern is also specified in sysctl.c */
44827
44828 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44829 int write)
44830 {
44831 struct page *page;
44832 - int ret;
44833
44834 -#ifdef CONFIG_STACK_GROWSUP
44835 - if (write) {
44836 - ret = expand_downwards(bprm->vma, pos);
44837 - if (ret < 0)
44838 - return NULL;
44839 - }
44840 -#endif
44841 - ret = get_user_pages(current, bprm->mm, pos,
44842 - 1, write, 1, &page, NULL);
44843 - if (ret <= 0)
44844 + if (0 > expand_downwards(bprm->vma, pos))
44845 + return NULL;
44846 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44847 return NULL;
44848
44849 if (write) {
44850 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44851 if (size <= ARG_MAX)
44852 return page;
44853
44854 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44855 + // only allow 512KB for argv+env on suid/sgid binaries
44856 + // to prevent easy ASLR exhaustion
44857 + if (((bprm->cred->euid != current_euid()) ||
44858 + (bprm->cred->egid != current_egid())) &&
44859 + (size > (512 * 1024))) {
44860 + put_page(page);
44861 + return NULL;
44862 + }
44863 +#endif
44864 +
44865 /*
44866 * Limit to 1/4-th the stack size for the argv+env strings.
44867 * This ensures that:
44868 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44869 vma->vm_end = STACK_TOP_MAX;
44870 vma->vm_start = vma->vm_end - PAGE_SIZE;
44871 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44872 +
44873 +#ifdef CONFIG_PAX_SEGMEXEC
44874 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44875 +#endif
44876 +
44877 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44878 INIT_LIST_HEAD(&vma->anon_vma_chain);
44879
44880 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44881 mm->stack_vm = mm->total_vm = 1;
44882 up_write(&mm->mmap_sem);
44883 bprm->p = vma->vm_end - sizeof(void *);
44884 +
44885 +#ifdef CONFIG_PAX_RANDUSTACK
44886 + if (randomize_va_space)
44887 + bprm->p ^= random32() & ~PAGE_MASK;
44888 +#endif
44889 +
44890 return 0;
44891 err:
44892 up_write(&mm->mmap_sem);
44893 @@ -395,19 +430,7 @@ err:
44894 return err;
44895 }
44896
44897 -struct user_arg_ptr {
44898 -#ifdef CONFIG_COMPAT
44899 - bool is_compat;
44900 -#endif
44901 - union {
44902 - const char __user *const __user *native;
44903 -#ifdef CONFIG_COMPAT
44904 - compat_uptr_t __user *compat;
44905 -#endif
44906 - } ptr;
44907 -};
44908 -
44909 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44910 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44911 {
44912 const char __user *native;
44913
44914 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44915 compat_uptr_t compat;
44916
44917 if (get_user(compat, argv.ptr.compat + nr))
44918 - return ERR_PTR(-EFAULT);
44919 + return (const char __force_user *)ERR_PTR(-EFAULT);
44920
44921 return compat_ptr(compat);
44922 }
44923 #endif
44924
44925 if (get_user(native, argv.ptr.native + nr))
44926 - return ERR_PTR(-EFAULT);
44927 + return (const char __force_user *)ERR_PTR(-EFAULT);
44928
44929 return native;
44930 }
44931 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44932 if (!p)
44933 break;
44934
44935 - if (IS_ERR(p))
44936 + if (IS_ERR((const char __force_kernel *)p))
44937 return -EFAULT;
44938
44939 if (i++ >= max)
44940 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44941
44942 ret = -EFAULT;
44943 str = get_user_arg_ptr(argv, argc);
44944 - if (IS_ERR(str))
44945 + if (IS_ERR((const char __force_kernel *)str))
44946 goto out;
44947
44948 len = strnlen_user(str, MAX_ARG_STRLEN);
44949 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44950 int r;
44951 mm_segment_t oldfs = get_fs();
44952 struct user_arg_ptr argv = {
44953 - .ptr.native = (const char __user *const __user *)__argv,
44954 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44955 };
44956
44957 set_fs(KERNEL_DS);
44958 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44959 unsigned long new_end = old_end - shift;
44960 struct mmu_gather tlb;
44961
44962 - BUG_ON(new_start > new_end);
44963 + if (new_start >= new_end || new_start < mmap_min_addr)
44964 + return -ENOMEM;
44965
44966 /*
44967 * ensure there are no vmas between where we want to go
44968 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44969 if (vma != find_vma(mm, new_start))
44970 return -EFAULT;
44971
44972 +#ifdef CONFIG_PAX_SEGMEXEC
44973 + BUG_ON(pax_find_mirror_vma(vma));
44974 +#endif
44975 +
44976 /*
44977 * cover the whole range: [new_start, old_end)
44978 */
44979 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44980 stack_top = arch_align_stack(stack_top);
44981 stack_top = PAGE_ALIGN(stack_top);
44982
44983 - if (unlikely(stack_top < mmap_min_addr) ||
44984 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44985 - return -ENOMEM;
44986 -
44987 stack_shift = vma->vm_end - stack_top;
44988
44989 bprm->p -= stack_shift;
44990 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44991 bprm->exec -= stack_shift;
44992
44993 down_write(&mm->mmap_sem);
44994 +
44995 + /* Move stack pages down in memory. */
44996 + if (stack_shift) {
44997 + ret = shift_arg_pages(vma, stack_shift);
44998 + if (ret)
44999 + goto out_unlock;
45000 + }
45001 +
45002 vm_flags = VM_STACK_FLAGS;
45003
45004 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45005 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45006 + vm_flags &= ~VM_EXEC;
45007 +
45008 +#ifdef CONFIG_PAX_MPROTECT
45009 + if (mm->pax_flags & MF_PAX_MPROTECT)
45010 + vm_flags &= ~VM_MAYEXEC;
45011 +#endif
45012 +
45013 + }
45014 +#endif
45015 +
45016 /*
45017 * Adjust stack execute permissions; explicitly enable for
45018 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45019 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45020 goto out_unlock;
45021 BUG_ON(prev != vma);
45022
45023 - /* Move stack pages down in memory. */
45024 - if (stack_shift) {
45025 - ret = shift_arg_pages(vma, stack_shift);
45026 - if (ret)
45027 - goto out_unlock;
45028 - }
45029 -
45030 /* mprotect_fixup is overkill to remove the temporary stack flags */
45031 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45032
45033 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45034
45035 fsnotify_open(file);
45036
45037 + trace_open_exec(name);
45038 +
45039 err = deny_write_access(file);
45040 if (err)
45041 goto exit;
45042 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45043 old_fs = get_fs();
45044 set_fs(get_ds());
45045 /* The cast to a user pointer is valid due to the set_fs() */
45046 - result = vfs_read(file, (void __user *)addr, count, &pos);
45047 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45048 set_fs(old_fs);
45049 return result;
45050 }
45051 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45052 }
45053 rcu_read_unlock();
45054
45055 - if (p->fs->users > n_fs) {
45056 + if (atomic_read(&p->fs->users) > n_fs) {
45057 bprm->unsafe |= LSM_UNSAFE_SHARE;
45058 } else {
45059 res = -EAGAIN;
45060 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45061
45062 EXPORT_SYMBOL(search_binary_handler);
45063
45064 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45065 +static DEFINE_PER_CPU(u64, exec_counter);
45066 +static int __init init_exec_counters(void)
45067 +{
45068 + unsigned int cpu;
45069 +
45070 + for_each_possible_cpu(cpu) {
45071 + per_cpu(exec_counter, cpu) = (u64)cpu;
45072 + }
45073 +
45074 + return 0;
45075 +}
45076 +early_initcall(init_exec_counters);
45077 +static inline void increment_exec_counter(void)
45078 +{
45079 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45080 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45081 +}
45082 +#else
45083 +static inline void increment_exec_counter(void) {}
45084 +#endif
45085 +
45086 /*
45087 * sys_execve() executes a new program.
45088 */
45089 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45090 struct user_arg_ptr envp,
45091 struct pt_regs *regs)
45092 {
45093 +#ifdef CONFIG_GRKERNSEC
45094 + struct file *old_exec_file;
45095 + struct acl_subject_label *old_acl;
45096 + struct rlimit old_rlim[RLIM_NLIMITS];
45097 +#endif
45098 struct linux_binprm *bprm;
45099 struct file *file;
45100 struct files_struct *displaced;
45101 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45102 int retval;
45103 const struct cred *cred = current_cred();
45104
45105 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45106 +
45107 /*
45108 * We move the actual failure in case of RLIMIT_NPROC excess from
45109 * set*uid() to execve() because too many poorly written programs
45110 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45111 if (IS_ERR(file))
45112 goto out_unmark;
45113
45114 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45115 + retval = -EPERM;
45116 + goto out_file;
45117 + }
45118 +
45119 sched_exec();
45120
45121 bprm->file = file;
45122 bprm->filename = filename;
45123 bprm->interp = filename;
45124
45125 + if (gr_process_user_ban()) {
45126 + retval = -EPERM;
45127 + goto out_file;
45128 + }
45129 +
45130 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45131 + retval = -EACCES;
45132 + goto out_file;
45133 + }
45134 +
45135 retval = bprm_mm_init(bprm);
45136 if (retval)
45137 goto out_file;
45138 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45139 if (retval < 0)
45140 goto out;
45141
45142 +#ifdef CONFIG_GRKERNSEC
45143 + old_acl = current->acl;
45144 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45145 + old_exec_file = current->exec_file;
45146 + get_file(file);
45147 + current->exec_file = file;
45148 +#endif
45149 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45150 + /* limit suid stack to 8MB
45151 + we saved the old limits above and will restore them if this exec fails
45152 + */
45153 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45154 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45155 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45156 +#endif
45157 +
45158 + if (!gr_tpe_allow(file)) {
45159 + retval = -EACCES;
45160 + goto out_fail;
45161 + }
45162 +
45163 + if (gr_check_crash_exec(file)) {
45164 + retval = -EACCES;
45165 + goto out_fail;
45166 + }
45167 +
45168 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45169 + bprm->unsafe);
45170 + if (retval < 0)
45171 + goto out_fail;
45172 +
45173 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45174 if (retval < 0)
45175 - goto out;
45176 + goto out_fail;
45177
45178 bprm->exec = bprm->p;
45179 retval = copy_strings(bprm->envc, envp, bprm);
45180 if (retval < 0)
45181 - goto out;
45182 + goto out_fail;
45183
45184 retval = copy_strings(bprm->argc, argv, bprm);
45185 if (retval < 0)
45186 - goto out;
45187 + goto out_fail;
45188 +
45189 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45190 +
45191 + gr_handle_exec_args(bprm, argv);
45192
45193 retval = search_binary_handler(bprm,regs);
45194 if (retval < 0)
45195 - goto out;
45196 + goto out_fail;
45197 +#ifdef CONFIG_GRKERNSEC
45198 + if (old_exec_file)
45199 + fput(old_exec_file);
45200 +#endif
45201
45202 /* execve succeeded */
45203 +
45204 + increment_exec_counter();
45205 current->fs->in_exec = 0;
45206 current->in_execve = 0;
45207 acct_update_integrals(current);
45208 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45209 put_files_struct(displaced);
45210 return retval;
45211
45212 +out_fail:
45213 +#ifdef CONFIG_GRKERNSEC
45214 + current->acl = old_acl;
45215 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45216 + fput(current->exec_file);
45217 + current->exec_file = old_exec_file;
45218 +#endif
45219 +
45220 out:
45221 if (bprm->mm) {
45222 acct_arg_size(bprm, 0);
45223 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45224 {
45225 char *old_corename = cn->corename;
45226
45227 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45228 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45229 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45230
45231 if (!cn->corename) {
45232 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45233 int pid_in_pattern = 0;
45234 int err = 0;
45235
45236 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45237 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45238 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45239 cn->used = 0;
45240
45241 @@ -1830,6 +1962,250 @@ out:
45242 return ispipe;
45243 }
45244
45245 +int pax_check_flags(unsigned long *flags)
45246 +{
45247 + int retval = 0;
45248 +
45249 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45250 + if (*flags & MF_PAX_SEGMEXEC)
45251 + {
45252 + *flags &= ~MF_PAX_SEGMEXEC;
45253 + retval = -EINVAL;
45254 + }
45255 +#endif
45256 +
45257 + if ((*flags & MF_PAX_PAGEEXEC)
45258 +
45259 +#ifdef CONFIG_PAX_PAGEEXEC
45260 + && (*flags & MF_PAX_SEGMEXEC)
45261 +#endif
45262 +
45263 + )
45264 + {
45265 + *flags &= ~MF_PAX_PAGEEXEC;
45266 + retval = -EINVAL;
45267 + }
45268 +
45269 + if ((*flags & MF_PAX_MPROTECT)
45270 +
45271 +#ifdef CONFIG_PAX_MPROTECT
45272 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45273 +#endif
45274 +
45275 + )
45276 + {
45277 + *flags &= ~MF_PAX_MPROTECT;
45278 + retval = -EINVAL;
45279 + }
45280 +
45281 + if ((*flags & MF_PAX_EMUTRAMP)
45282 +
45283 +#ifdef CONFIG_PAX_EMUTRAMP
45284 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45285 +#endif
45286 +
45287 + )
45288 + {
45289 + *flags &= ~MF_PAX_EMUTRAMP;
45290 + retval = -EINVAL;
45291 + }
45292 +
45293 + return retval;
45294 +}
45295 +
45296 +EXPORT_SYMBOL(pax_check_flags);
45297 +
45298 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45299 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45300 +{
45301 + struct task_struct *tsk = current;
45302 + struct mm_struct *mm = current->mm;
45303 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45304 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45305 + char *path_exec = NULL;
45306 + char *path_fault = NULL;
45307 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45308 +
45309 + if (buffer_exec && buffer_fault) {
45310 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45311 +
45312 + down_read(&mm->mmap_sem);
45313 + vma = mm->mmap;
45314 + while (vma && (!vma_exec || !vma_fault)) {
45315 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45316 + vma_exec = vma;
45317 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45318 + vma_fault = vma;
45319 + vma = vma->vm_next;
45320 + }
45321 + if (vma_exec) {
45322 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45323 + if (IS_ERR(path_exec))
45324 + path_exec = "<path too long>";
45325 + else {
45326 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45327 + if (path_exec) {
45328 + *path_exec = 0;
45329 + path_exec = buffer_exec;
45330 + } else
45331 + path_exec = "<path too long>";
45332 + }
45333 + }
45334 + if (vma_fault) {
45335 + start = vma_fault->vm_start;
45336 + end = vma_fault->vm_end;
45337 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45338 + if (vma_fault->vm_file) {
45339 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45340 + if (IS_ERR(path_fault))
45341 + path_fault = "<path too long>";
45342 + else {
45343 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45344 + if (path_fault) {
45345 + *path_fault = 0;
45346 + path_fault = buffer_fault;
45347 + } else
45348 + path_fault = "<path too long>";
45349 + }
45350 + } else
45351 + path_fault = "<anonymous mapping>";
45352 + }
45353 + up_read(&mm->mmap_sem);
45354 + }
45355 + if (tsk->signal->curr_ip)
45356 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45357 + else
45358 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45359 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45360 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45361 + task_uid(tsk), task_euid(tsk), pc, sp);
45362 + free_page((unsigned long)buffer_exec);
45363 + free_page((unsigned long)buffer_fault);
45364 + pax_report_insns(regs, pc, sp);
45365 + do_coredump(SIGKILL, SIGKILL, regs);
45366 +}
45367 +#endif
45368 +
45369 +#ifdef CONFIG_PAX_REFCOUNT
45370 +void pax_report_refcount_overflow(struct pt_regs *regs)
45371 +{
45372 + if (current->signal->curr_ip)
45373 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45374 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45375 + else
45376 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45377 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45378 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45379 + show_regs(regs);
45380 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45381 +}
45382 +#endif
45383 +
45384 +#ifdef CONFIG_PAX_USERCOPY
45385 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45386 +static noinline int check_stack_object(const void *obj, unsigned long len)
45387 +{
45388 + const void * const stack = task_stack_page(current);
45389 + const void * const stackend = stack + THREAD_SIZE;
45390 +
45391 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45392 + const void *frame = NULL;
45393 + const void *oldframe;
45394 +#endif
45395 +
45396 + if (obj + len < obj)
45397 + return -1;
45398 +
45399 + if (obj + len <= stack || stackend <= obj)
45400 + return 0;
45401 +
45402 + if (obj < stack || stackend < obj + len)
45403 + return -1;
45404 +
45405 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45406 + oldframe = __builtin_frame_address(1);
45407 + if (oldframe)
45408 + frame = __builtin_frame_address(2);
45409 + /*
45410 + low ----------------------------------------------> high
45411 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45412 + ^----------------^
45413 + allow copies only within here
45414 + */
45415 + while (stack <= frame && frame < stackend) {
45416 + /* if obj + len extends past the last frame, this
45417 + check won't pass and the next frame will be 0,
45418 + causing us to bail out and correctly report
45419 + the copy as invalid
45420 + */
45421 + if (obj + len <= frame)
45422 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45423 + oldframe = frame;
45424 + frame = *(const void * const *)frame;
45425 + }
45426 + return -1;
45427 +#else
45428 + return 1;
45429 +#endif
45430 +}
45431 +
45432 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45433 +{
45434 + if (current->signal->curr_ip)
45435 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45436 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45437 + else
45438 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45439 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45440 + dump_stack();
45441 + gr_handle_kernel_exploit();
45442 + do_group_exit(SIGKILL);
45443 +}
45444 +#endif
45445 +
45446 +void check_object_size(const void *ptr, unsigned long n, bool to)
45447 +{
45448 +
45449 +#ifdef CONFIG_PAX_USERCOPY
45450 + const char *type;
45451 +
45452 + if (!n)
45453 + return;
45454 +
45455 + type = check_heap_object(ptr, n, to);
45456 + if (!type) {
45457 + if (check_stack_object(ptr, n) != -1)
45458 + return;
45459 + type = "<process stack>";
45460 + }
45461 +
45462 + pax_report_usercopy(ptr, n, to, type);
45463 +#endif
45464 +
45465 +}
45466 +EXPORT_SYMBOL(check_object_size);
45467 +
45468 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45469 +void pax_track_stack(void)
45470 +{
45471 + unsigned long sp = (unsigned long)&sp;
45472 + if (sp < current_thread_info()->lowest_stack &&
45473 + sp > (unsigned long)task_stack_page(current))
45474 + current_thread_info()->lowest_stack = sp;
45475 +}
45476 +EXPORT_SYMBOL(pax_track_stack);
45477 +#endif
45478 +
45479 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45480 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45481 +{
45482 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45483 + dump_stack();
45484 + do_group_exit(SIGKILL);
45485 +}
45486 +EXPORT_SYMBOL(report_size_overflow);
45487 +#endif
45488 +
45489 static int zap_process(struct task_struct *start, int exit_code)
45490 {
45491 struct task_struct *t;
45492 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45493 pipe = file->f_path.dentry->d_inode->i_pipe;
45494
45495 pipe_lock(pipe);
45496 - pipe->readers++;
45497 - pipe->writers--;
45498 + atomic_inc(&pipe->readers);
45499 + atomic_dec(&pipe->writers);
45500
45501 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45502 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45503 wake_up_interruptible_sync(&pipe->wait);
45504 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45505 pipe_wait(pipe);
45506 }
45507
45508 - pipe->readers--;
45509 - pipe->writers++;
45510 + atomic_dec(&pipe->readers);
45511 + atomic_inc(&pipe->writers);
45512 pipe_unlock(pipe);
45513
45514 }
45515 @@ -2105,7 +2481,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45516 int flag = 0;
45517 int ispipe;
45518 bool need_nonrelative = false;
45519 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45520 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45521 struct coredump_params cprm = {
45522 .signr = signr,
45523 .regs = regs,
45524 @@ -2120,6 +2496,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45525
45526 audit_core_dumps(signr);
45527
45528 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45529 + gr_handle_brute_attach(current, cprm.mm_flags);
45530 +
45531 binfmt = mm->binfmt;
45532 if (!binfmt || !binfmt->core_dump)
45533 goto fail;
45534 @@ -2190,7 +2569,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45535 }
45536 cprm.limit = RLIM_INFINITY;
45537
45538 - dump_count = atomic_inc_return(&core_dump_count);
45539 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45540 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45541 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45542 task_tgid_vnr(current), current->comm);
45543 @@ -2217,6 +2596,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45544 } else {
45545 struct inode *inode;
45546
45547 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45548 +
45549 if (cprm.limit < binfmt->min_coredump)
45550 goto fail_unlock;
45551
45552 @@ -2268,7 +2649,7 @@ close_fail:
45553 filp_close(cprm.file, NULL);
45554 fail_dropcount:
45555 if (ispipe)
45556 - atomic_dec(&core_dump_count);
45557 + atomic_dec_unchecked(&core_dump_count);
45558 fail_unlock:
45559 kfree(cn.corename);
45560 fail_corename:
45561 @@ -2287,7 +2668,7 @@ fail:
45562 */
45563 int dump_write(struct file *file, const void *addr, int nr)
45564 {
45565 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45566 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45567 }
45568 EXPORT_SYMBOL(dump_write);
45569
45570 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45571 index 376aa77..59a129c 100644
45572 --- a/fs/ext2/balloc.c
45573 +++ b/fs/ext2/balloc.c
45574 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45575
45576 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45577 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45578 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45579 + if (free_blocks < root_blocks + 1 &&
45580 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45581 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45582 - !in_group_p (sbi->s_resgid))) {
45583 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45584 return 0;
45585 }
45586 return 1;
45587 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45588 index 90d901f..159975f 100644
45589 --- a/fs/ext3/balloc.c
45590 +++ b/fs/ext3/balloc.c
45591 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45592
45593 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45594 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45595 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45596 + if (free_blocks < root_blocks + 1 &&
45597 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45598 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45599 - !in_group_p (sbi->s_resgid))) {
45600 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45601 return 0;
45602 }
45603 return 1;
45604 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45605 index 1b50890..e56c5ad 100644
45606 --- a/fs/ext4/balloc.c
45607 +++ b/fs/ext4/balloc.c
45608 @@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45609 /* Hm, nope. Are (enough) root reserved clusters available? */
45610 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45611 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45612 - capable(CAP_SYS_RESOURCE) ||
45613 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45614 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45615 + capable_nolog(CAP_SYS_RESOURCE)) {
45616
45617 if (free_clusters >= (nclusters + dirty_clusters))
45618 return 1;
45619 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45620 index c3411d4..30e4f1b 100644
45621 --- a/fs/ext4/ext4.h
45622 +++ b/fs/ext4/ext4.h
45623 @@ -1248,19 +1248,19 @@ struct ext4_sb_info {
45624 unsigned long s_mb_last_start;
45625
45626 /* stats for buddy allocator */
45627 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45628 - atomic_t s_bal_success; /* we found long enough chunks */
45629 - atomic_t s_bal_allocated; /* in blocks */
45630 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45631 - atomic_t s_bal_goals; /* goal hits */
45632 - atomic_t s_bal_breaks; /* too long searches */
45633 - atomic_t s_bal_2orders; /* 2^order hits */
45634 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45635 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45636 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45637 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45638 + atomic_unchecked_t s_bal_goals; /* goal hits */
45639 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45640 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45641 spinlock_t s_bal_lock;
45642 unsigned long s_mb_buddies_generated;
45643 unsigned long long s_mb_generation_time;
45644 - atomic_t s_mb_lost_chunks;
45645 - atomic_t s_mb_preallocated;
45646 - atomic_t s_mb_discarded;
45647 + atomic_unchecked_t s_mb_lost_chunks;
45648 + atomic_unchecked_t s_mb_preallocated;
45649 + atomic_unchecked_t s_mb_discarded;
45650 atomic_t s_lock_busy;
45651
45652 /* locality groups */
45653 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45654 index 8eae947..53fc27a 100644
45655 --- a/fs/ext4/mballoc.c
45656 +++ b/fs/ext4/mballoc.c
45657 @@ -1746,7 +1746,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45658 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45659
45660 if (EXT4_SB(sb)->s_mb_stats)
45661 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45662 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45663
45664 break;
45665 }
45666 @@ -2040,7 +2040,7 @@ repeat:
45667 ac->ac_status = AC_STATUS_CONTINUE;
45668 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45669 cr = 3;
45670 - atomic_inc(&sbi->s_mb_lost_chunks);
45671 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45672 goto repeat;
45673 }
45674 }
45675 @@ -2551,25 +2551,25 @@ int ext4_mb_release(struct super_block *sb)
45676 if (sbi->s_mb_stats) {
45677 ext4_msg(sb, KERN_INFO,
45678 "mballoc: %u blocks %u reqs (%u success)",
45679 - atomic_read(&sbi->s_bal_allocated),
45680 - atomic_read(&sbi->s_bal_reqs),
45681 - atomic_read(&sbi->s_bal_success));
45682 + atomic_read_unchecked(&sbi->s_bal_allocated),
45683 + atomic_read_unchecked(&sbi->s_bal_reqs),
45684 + atomic_read_unchecked(&sbi->s_bal_success));
45685 ext4_msg(sb, KERN_INFO,
45686 "mballoc: %u extents scanned, %u goal hits, "
45687 "%u 2^N hits, %u breaks, %u lost",
45688 - atomic_read(&sbi->s_bal_ex_scanned),
45689 - atomic_read(&sbi->s_bal_goals),
45690 - atomic_read(&sbi->s_bal_2orders),
45691 - atomic_read(&sbi->s_bal_breaks),
45692 - atomic_read(&sbi->s_mb_lost_chunks));
45693 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45694 + atomic_read_unchecked(&sbi->s_bal_goals),
45695 + atomic_read_unchecked(&sbi->s_bal_2orders),
45696 + atomic_read_unchecked(&sbi->s_bal_breaks),
45697 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45698 ext4_msg(sb, KERN_INFO,
45699 "mballoc: %lu generated and it took %Lu",
45700 sbi->s_mb_buddies_generated,
45701 sbi->s_mb_generation_time);
45702 ext4_msg(sb, KERN_INFO,
45703 "mballoc: %u preallocated, %u discarded",
45704 - atomic_read(&sbi->s_mb_preallocated),
45705 - atomic_read(&sbi->s_mb_discarded));
45706 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45707 + atomic_read_unchecked(&sbi->s_mb_discarded));
45708 }
45709
45710 free_percpu(sbi->s_locality_groups);
45711 @@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45712 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45713
45714 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45715 - atomic_inc(&sbi->s_bal_reqs);
45716 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45717 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45718 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45719 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45720 - atomic_inc(&sbi->s_bal_success);
45721 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45722 + atomic_inc_unchecked(&sbi->s_bal_success);
45723 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45724 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45725 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45726 - atomic_inc(&sbi->s_bal_goals);
45727 + atomic_inc_unchecked(&sbi->s_bal_goals);
45728 if (ac->ac_found > sbi->s_mb_max_to_scan)
45729 - atomic_inc(&sbi->s_bal_breaks);
45730 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45731 }
45732
45733 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45734 @@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45735 trace_ext4_mb_new_inode_pa(ac, pa);
45736
45737 ext4_mb_use_inode_pa(ac, pa);
45738 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45739 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45740
45741 ei = EXT4_I(ac->ac_inode);
45742 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45743 @@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45744 trace_ext4_mb_new_group_pa(ac, pa);
45745
45746 ext4_mb_use_group_pa(ac, pa);
45747 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45748 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45749
45750 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45751 lg = ac->ac_lg;
45752 @@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45753 * from the bitmap and continue.
45754 */
45755 }
45756 - atomic_add(free, &sbi->s_mb_discarded);
45757 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45758
45759 return err;
45760 }
45761 @@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45762 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45763 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45764 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45765 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45766 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45767 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45768
45769 return 0;
45770 diff --git a/fs/fcntl.c b/fs/fcntl.c
45771 index 887b5ba..0e3f2c3 100644
45772 --- a/fs/fcntl.c
45773 +++ b/fs/fcntl.c
45774 @@ -225,6 +225,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45775 if (err)
45776 return err;
45777
45778 + if (gr_handle_chroot_fowner(pid, type))
45779 + return -ENOENT;
45780 + if (gr_check_protected_task_fowner(pid, type))
45781 + return -EACCES;
45782 +
45783 f_modown(filp, pid, type, force);
45784 return 0;
45785 }
45786 @@ -267,7 +272,7 @@ pid_t f_getown(struct file *filp)
45787
45788 static int f_setown_ex(struct file *filp, unsigned long arg)
45789 {
45790 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45791 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45792 struct f_owner_ex owner;
45793 struct pid *pid;
45794 int type;
45795 @@ -307,7 +312,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45796
45797 static int f_getown_ex(struct file *filp, unsigned long arg)
45798 {
45799 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45800 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45801 struct f_owner_ex owner;
45802 int ret = 0;
45803
45804 @@ -374,6 +379,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45805 switch (cmd) {
45806 case F_DUPFD:
45807 case F_DUPFD_CLOEXEC:
45808 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45809 if (arg >= rlimit(RLIMIT_NOFILE))
45810 break;
45811 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45812 diff --git a/fs/fifo.c b/fs/fifo.c
45813 index cf6f434..3d7942c 100644
45814 --- a/fs/fifo.c
45815 +++ b/fs/fifo.c
45816 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45817 */
45818 filp->f_op = &read_pipefifo_fops;
45819 pipe->r_counter++;
45820 - if (pipe->readers++ == 0)
45821 + if (atomic_inc_return(&pipe->readers) == 1)
45822 wake_up_partner(inode);
45823
45824 - if (!pipe->writers) {
45825 + if (!atomic_read(&pipe->writers)) {
45826 if ((filp->f_flags & O_NONBLOCK)) {
45827 /* suppress POLLHUP until we have
45828 * seen a writer */
45829 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45830 * errno=ENXIO when there is no process reading the FIFO.
45831 */
45832 ret = -ENXIO;
45833 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45834 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45835 goto err;
45836
45837 filp->f_op = &write_pipefifo_fops;
45838 pipe->w_counter++;
45839 - if (!pipe->writers++)
45840 + if (atomic_inc_return(&pipe->writers) == 1)
45841 wake_up_partner(inode);
45842
45843 - if (!pipe->readers) {
45844 + if (!atomic_read(&pipe->readers)) {
45845 if (wait_for_partner(inode, &pipe->r_counter))
45846 goto err_wr;
45847 }
45848 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45849 */
45850 filp->f_op = &rdwr_pipefifo_fops;
45851
45852 - pipe->readers++;
45853 - pipe->writers++;
45854 + atomic_inc(&pipe->readers);
45855 + atomic_inc(&pipe->writers);
45856 pipe->r_counter++;
45857 pipe->w_counter++;
45858 - if (pipe->readers == 1 || pipe->writers == 1)
45859 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45860 wake_up_partner(inode);
45861 break;
45862
45863 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45864 return 0;
45865
45866 err_rd:
45867 - if (!--pipe->readers)
45868 + if (atomic_dec_and_test(&pipe->readers))
45869 wake_up_interruptible(&pipe->wait);
45870 ret = -ERESTARTSYS;
45871 goto err;
45872
45873 err_wr:
45874 - if (!--pipe->writers)
45875 + if (atomic_dec_and_test(&pipe->writers))
45876 wake_up_interruptible(&pipe->wait);
45877 ret = -ERESTARTSYS;
45878 goto err;
45879
45880 err:
45881 - if (!pipe->readers && !pipe->writers)
45882 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45883 free_pipe_info(inode);
45884
45885 err_nocleanup:
45886 diff --git a/fs/file.c b/fs/file.c
45887 index ba3f605..fade102 100644
45888 --- a/fs/file.c
45889 +++ b/fs/file.c
45890 @@ -15,6 +15,7 @@
45891 #include <linux/slab.h>
45892 #include <linux/vmalloc.h>
45893 #include <linux/file.h>
45894 +#include <linux/security.h>
45895 #include <linux/fdtable.h>
45896 #include <linux/bitops.h>
45897 #include <linux/interrupt.h>
45898 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45899 * N.B. For clone tasks sharing a files structure, this test
45900 * will limit the total number of files that can be opened.
45901 */
45902 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45903 if (nr >= rlimit(RLIMIT_NOFILE))
45904 return -EMFILE;
45905
45906 diff --git a/fs/filesystems.c b/fs/filesystems.c
45907 index 96f2428..f5eeb8e 100644
45908 --- a/fs/filesystems.c
45909 +++ b/fs/filesystems.c
45910 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45911 int len = dot ? dot - name : strlen(name);
45912
45913 fs = __get_fs_type(name, len);
45914 +
45915 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45916 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45917 +#else
45918 if (!fs && (request_module("%.*s", len, name) == 0))
45919 +#endif
45920 fs = __get_fs_type(name, len);
45921
45922 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45923 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45924 index 5df4775..9d9336f 100644
45925 --- a/fs/fs_struct.c
45926 +++ b/fs/fs_struct.c
45927 @@ -4,6 +4,7 @@
45928 #include <linux/path.h>
45929 #include <linux/slab.h>
45930 #include <linux/fs_struct.h>
45931 +#include <linux/grsecurity.h>
45932 #include "internal.h"
45933
45934 /*
45935 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
45936 write_seqcount_begin(&fs->seq);
45937 old_root = fs->root;
45938 fs->root = *path;
45939 + gr_set_chroot_entries(current, path);
45940 write_seqcount_end(&fs->seq);
45941 spin_unlock(&fs->lock);
45942 if (old_root.dentry)
45943 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
45944 return 1;
45945 }
45946
45947 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
45948 +{
45949 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
45950 + return 0;
45951 + *p = *new;
45952 +
45953 + /* This function is only called from pivot_root(). Leave our
45954 + gr_chroot_dentry and is_chrooted flags as-is, so that a
45955 + pivoted root isn't treated as a chroot
45956 + */
45957 + //gr_set_chroot_entries(task, new);
45958 +
45959 + return 1;
45960 +}
45961 +
45962 void chroot_fs_refs(struct path *old_root, struct path *new_root)
45963 {
45964 struct task_struct *g, *p;
45965 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
45966 int hits = 0;
45967 spin_lock(&fs->lock);
45968 write_seqcount_begin(&fs->seq);
45969 - hits += replace_path(&fs->root, old_root, new_root);
45970 + hits += replace_root_path(p, &fs->root, old_root, new_root);
45971 hits += replace_path(&fs->pwd, old_root, new_root);
45972 write_seqcount_end(&fs->seq);
45973 while (hits--) {
45974 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
45975 task_lock(tsk);
45976 spin_lock(&fs->lock);
45977 tsk->fs = NULL;
45978 - kill = !--fs->users;
45979 + gr_clear_chroot_entries(tsk);
45980 + kill = !atomic_dec_return(&fs->users);
45981 spin_unlock(&fs->lock);
45982 task_unlock(tsk);
45983 if (kill)
45984 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45985 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
45986 /* We don't need to lock fs - think why ;-) */
45987 if (fs) {
45988 - fs->users = 1;
45989 + atomic_set(&fs->users, 1);
45990 fs->in_exec = 0;
45991 spin_lock_init(&fs->lock);
45992 seqcount_init(&fs->seq);
45993 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
45994 spin_lock(&old->lock);
45995 fs->root = old->root;
45996 path_get(&fs->root);
45997 + /* instead of calling gr_set_chroot_entries here,
45998 + we call it from every caller of this function
45999 + */
46000 fs->pwd = old->pwd;
46001 path_get(&fs->pwd);
46002 spin_unlock(&old->lock);
46003 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
46004
46005 task_lock(current);
46006 spin_lock(&fs->lock);
46007 - kill = !--fs->users;
46008 + kill = !atomic_dec_return(&fs->users);
46009 current->fs = new_fs;
46010 + gr_set_chroot_entries(current, &new_fs->root);
46011 spin_unlock(&fs->lock);
46012 task_unlock(current);
46013
46014 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46015
46016 int current_umask(void)
46017 {
46018 - return current->fs->umask;
46019 + return current->fs->umask | gr_acl_umask();
46020 }
46021 EXPORT_SYMBOL(current_umask);
46022
46023 /* to be mentioned only in INIT_TASK */
46024 struct fs_struct init_fs = {
46025 - .users = 1,
46026 + .users = ATOMIC_INIT(1),
46027 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46028 .seq = SEQCNT_ZERO,
46029 .umask = 0022,
46030 @@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
46031 task_lock(current);
46032
46033 spin_lock(&init_fs.lock);
46034 - init_fs.users++;
46035 + atomic_inc(&init_fs.users);
46036 spin_unlock(&init_fs.lock);
46037
46038 spin_lock(&fs->lock);
46039 current->fs = &init_fs;
46040 - kill = !--fs->users;
46041 + gr_set_chroot_entries(current, &current->fs->root);
46042 + kill = !atomic_dec_return(&fs->users);
46043 spin_unlock(&fs->lock);
46044
46045 task_unlock(current);
46046 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46047 index 9905350..02eaec4 100644
46048 --- a/fs/fscache/cookie.c
46049 +++ b/fs/fscache/cookie.c
46050 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46051 parent ? (char *) parent->def->name : "<no-parent>",
46052 def->name, netfs_data);
46053
46054 - fscache_stat(&fscache_n_acquires);
46055 + fscache_stat_unchecked(&fscache_n_acquires);
46056
46057 /* if there's no parent cookie, then we don't create one here either */
46058 if (!parent) {
46059 - fscache_stat(&fscache_n_acquires_null);
46060 + fscache_stat_unchecked(&fscache_n_acquires_null);
46061 _leave(" [no parent]");
46062 return NULL;
46063 }
46064 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46065 /* allocate and initialise a cookie */
46066 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46067 if (!cookie) {
46068 - fscache_stat(&fscache_n_acquires_oom);
46069 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46070 _leave(" [ENOMEM]");
46071 return NULL;
46072 }
46073 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46074
46075 switch (cookie->def->type) {
46076 case FSCACHE_COOKIE_TYPE_INDEX:
46077 - fscache_stat(&fscache_n_cookie_index);
46078 + fscache_stat_unchecked(&fscache_n_cookie_index);
46079 break;
46080 case FSCACHE_COOKIE_TYPE_DATAFILE:
46081 - fscache_stat(&fscache_n_cookie_data);
46082 + fscache_stat_unchecked(&fscache_n_cookie_data);
46083 break;
46084 default:
46085 - fscache_stat(&fscache_n_cookie_special);
46086 + fscache_stat_unchecked(&fscache_n_cookie_special);
46087 break;
46088 }
46089
46090 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46091 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46092 atomic_dec(&parent->n_children);
46093 __fscache_cookie_put(cookie);
46094 - fscache_stat(&fscache_n_acquires_nobufs);
46095 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46096 _leave(" = NULL");
46097 return NULL;
46098 }
46099 }
46100
46101 - fscache_stat(&fscache_n_acquires_ok);
46102 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46103 _leave(" = %p", cookie);
46104 return cookie;
46105 }
46106 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46107 cache = fscache_select_cache_for_object(cookie->parent);
46108 if (!cache) {
46109 up_read(&fscache_addremove_sem);
46110 - fscache_stat(&fscache_n_acquires_no_cache);
46111 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46112 _leave(" = -ENOMEDIUM [no cache]");
46113 return -ENOMEDIUM;
46114 }
46115 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46116 object = cache->ops->alloc_object(cache, cookie);
46117 fscache_stat_d(&fscache_n_cop_alloc_object);
46118 if (IS_ERR(object)) {
46119 - fscache_stat(&fscache_n_object_no_alloc);
46120 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46121 ret = PTR_ERR(object);
46122 goto error;
46123 }
46124
46125 - fscache_stat(&fscache_n_object_alloc);
46126 + fscache_stat_unchecked(&fscache_n_object_alloc);
46127
46128 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46129
46130 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46131 struct fscache_object *object;
46132 struct hlist_node *_p;
46133
46134 - fscache_stat(&fscache_n_updates);
46135 + fscache_stat_unchecked(&fscache_n_updates);
46136
46137 if (!cookie) {
46138 - fscache_stat(&fscache_n_updates_null);
46139 + fscache_stat_unchecked(&fscache_n_updates_null);
46140 _leave(" [no cookie]");
46141 return;
46142 }
46143 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46144 struct fscache_object *object;
46145 unsigned long event;
46146
46147 - fscache_stat(&fscache_n_relinquishes);
46148 + fscache_stat_unchecked(&fscache_n_relinquishes);
46149 if (retire)
46150 - fscache_stat(&fscache_n_relinquishes_retire);
46151 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46152
46153 if (!cookie) {
46154 - fscache_stat(&fscache_n_relinquishes_null);
46155 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46156 _leave(" [no cookie]");
46157 return;
46158 }
46159 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46160
46161 /* wait for the cookie to finish being instantiated (or to fail) */
46162 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46163 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46164 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46165 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46166 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46167 }
46168 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46169 index f6aad48..88dcf26 100644
46170 --- a/fs/fscache/internal.h
46171 +++ b/fs/fscache/internal.h
46172 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46173 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46174 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46175
46176 -extern atomic_t fscache_n_op_pend;
46177 -extern atomic_t fscache_n_op_run;
46178 -extern atomic_t fscache_n_op_enqueue;
46179 -extern atomic_t fscache_n_op_deferred_release;
46180 -extern atomic_t fscache_n_op_release;
46181 -extern atomic_t fscache_n_op_gc;
46182 -extern atomic_t fscache_n_op_cancelled;
46183 -extern atomic_t fscache_n_op_rejected;
46184 +extern atomic_unchecked_t fscache_n_op_pend;
46185 +extern atomic_unchecked_t fscache_n_op_run;
46186 +extern atomic_unchecked_t fscache_n_op_enqueue;
46187 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46188 +extern atomic_unchecked_t fscache_n_op_release;
46189 +extern atomic_unchecked_t fscache_n_op_gc;
46190 +extern atomic_unchecked_t fscache_n_op_cancelled;
46191 +extern atomic_unchecked_t fscache_n_op_rejected;
46192
46193 -extern atomic_t fscache_n_attr_changed;
46194 -extern atomic_t fscache_n_attr_changed_ok;
46195 -extern atomic_t fscache_n_attr_changed_nobufs;
46196 -extern atomic_t fscache_n_attr_changed_nomem;
46197 -extern atomic_t fscache_n_attr_changed_calls;
46198 +extern atomic_unchecked_t fscache_n_attr_changed;
46199 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46200 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46201 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46202 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46203
46204 -extern atomic_t fscache_n_allocs;
46205 -extern atomic_t fscache_n_allocs_ok;
46206 -extern atomic_t fscache_n_allocs_wait;
46207 -extern atomic_t fscache_n_allocs_nobufs;
46208 -extern atomic_t fscache_n_allocs_intr;
46209 -extern atomic_t fscache_n_allocs_object_dead;
46210 -extern atomic_t fscache_n_alloc_ops;
46211 -extern atomic_t fscache_n_alloc_op_waits;
46212 +extern atomic_unchecked_t fscache_n_allocs;
46213 +extern atomic_unchecked_t fscache_n_allocs_ok;
46214 +extern atomic_unchecked_t fscache_n_allocs_wait;
46215 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46216 +extern atomic_unchecked_t fscache_n_allocs_intr;
46217 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46218 +extern atomic_unchecked_t fscache_n_alloc_ops;
46219 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46220
46221 -extern atomic_t fscache_n_retrievals;
46222 -extern atomic_t fscache_n_retrievals_ok;
46223 -extern atomic_t fscache_n_retrievals_wait;
46224 -extern atomic_t fscache_n_retrievals_nodata;
46225 -extern atomic_t fscache_n_retrievals_nobufs;
46226 -extern atomic_t fscache_n_retrievals_intr;
46227 -extern atomic_t fscache_n_retrievals_nomem;
46228 -extern atomic_t fscache_n_retrievals_object_dead;
46229 -extern atomic_t fscache_n_retrieval_ops;
46230 -extern atomic_t fscache_n_retrieval_op_waits;
46231 +extern atomic_unchecked_t fscache_n_retrievals;
46232 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46233 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46234 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46235 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46236 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46237 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46238 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46239 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46240 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46241
46242 -extern atomic_t fscache_n_stores;
46243 -extern atomic_t fscache_n_stores_ok;
46244 -extern atomic_t fscache_n_stores_again;
46245 -extern atomic_t fscache_n_stores_nobufs;
46246 -extern atomic_t fscache_n_stores_oom;
46247 -extern atomic_t fscache_n_store_ops;
46248 -extern atomic_t fscache_n_store_calls;
46249 -extern atomic_t fscache_n_store_pages;
46250 -extern atomic_t fscache_n_store_radix_deletes;
46251 -extern atomic_t fscache_n_store_pages_over_limit;
46252 +extern atomic_unchecked_t fscache_n_stores;
46253 +extern atomic_unchecked_t fscache_n_stores_ok;
46254 +extern atomic_unchecked_t fscache_n_stores_again;
46255 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46256 +extern atomic_unchecked_t fscache_n_stores_oom;
46257 +extern atomic_unchecked_t fscache_n_store_ops;
46258 +extern atomic_unchecked_t fscache_n_store_calls;
46259 +extern atomic_unchecked_t fscache_n_store_pages;
46260 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46261 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46262
46263 -extern atomic_t fscache_n_store_vmscan_not_storing;
46264 -extern atomic_t fscache_n_store_vmscan_gone;
46265 -extern atomic_t fscache_n_store_vmscan_busy;
46266 -extern atomic_t fscache_n_store_vmscan_cancelled;
46267 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46268 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46269 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46270 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46271
46272 -extern atomic_t fscache_n_marks;
46273 -extern atomic_t fscache_n_uncaches;
46274 +extern atomic_unchecked_t fscache_n_marks;
46275 +extern atomic_unchecked_t fscache_n_uncaches;
46276
46277 -extern atomic_t fscache_n_acquires;
46278 -extern atomic_t fscache_n_acquires_null;
46279 -extern atomic_t fscache_n_acquires_no_cache;
46280 -extern atomic_t fscache_n_acquires_ok;
46281 -extern atomic_t fscache_n_acquires_nobufs;
46282 -extern atomic_t fscache_n_acquires_oom;
46283 +extern atomic_unchecked_t fscache_n_acquires;
46284 +extern atomic_unchecked_t fscache_n_acquires_null;
46285 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46286 +extern atomic_unchecked_t fscache_n_acquires_ok;
46287 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46288 +extern atomic_unchecked_t fscache_n_acquires_oom;
46289
46290 -extern atomic_t fscache_n_updates;
46291 -extern atomic_t fscache_n_updates_null;
46292 -extern atomic_t fscache_n_updates_run;
46293 +extern atomic_unchecked_t fscache_n_updates;
46294 +extern atomic_unchecked_t fscache_n_updates_null;
46295 +extern atomic_unchecked_t fscache_n_updates_run;
46296
46297 -extern atomic_t fscache_n_relinquishes;
46298 -extern atomic_t fscache_n_relinquishes_null;
46299 -extern atomic_t fscache_n_relinquishes_waitcrt;
46300 -extern atomic_t fscache_n_relinquishes_retire;
46301 +extern atomic_unchecked_t fscache_n_relinquishes;
46302 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46303 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46304 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46305
46306 -extern atomic_t fscache_n_cookie_index;
46307 -extern atomic_t fscache_n_cookie_data;
46308 -extern atomic_t fscache_n_cookie_special;
46309 +extern atomic_unchecked_t fscache_n_cookie_index;
46310 +extern atomic_unchecked_t fscache_n_cookie_data;
46311 +extern atomic_unchecked_t fscache_n_cookie_special;
46312
46313 -extern atomic_t fscache_n_object_alloc;
46314 -extern atomic_t fscache_n_object_no_alloc;
46315 -extern atomic_t fscache_n_object_lookups;
46316 -extern atomic_t fscache_n_object_lookups_negative;
46317 -extern atomic_t fscache_n_object_lookups_positive;
46318 -extern atomic_t fscache_n_object_lookups_timed_out;
46319 -extern atomic_t fscache_n_object_created;
46320 -extern atomic_t fscache_n_object_avail;
46321 -extern atomic_t fscache_n_object_dead;
46322 +extern atomic_unchecked_t fscache_n_object_alloc;
46323 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46324 +extern atomic_unchecked_t fscache_n_object_lookups;
46325 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46326 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46327 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46328 +extern atomic_unchecked_t fscache_n_object_created;
46329 +extern atomic_unchecked_t fscache_n_object_avail;
46330 +extern atomic_unchecked_t fscache_n_object_dead;
46331
46332 -extern atomic_t fscache_n_checkaux_none;
46333 -extern atomic_t fscache_n_checkaux_okay;
46334 -extern atomic_t fscache_n_checkaux_update;
46335 -extern atomic_t fscache_n_checkaux_obsolete;
46336 +extern atomic_unchecked_t fscache_n_checkaux_none;
46337 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46338 +extern atomic_unchecked_t fscache_n_checkaux_update;
46339 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46340
46341 extern atomic_t fscache_n_cop_alloc_object;
46342 extern atomic_t fscache_n_cop_lookup_object;
46343 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46344 atomic_inc(stat);
46345 }
46346
46347 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46348 +{
46349 + atomic_inc_unchecked(stat);
46350 +}
46351 +
46352 static inline void fscache_stat_d(atomic_t *stat)
46353 {
46354 atomic_dec(stat);
46355 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46356
46357 #define __fscache_stat(stat) (NULL)
46358 #define fscache_stat(stat) do {} while (0)
46359 +#define fscache_stat_unchecked(stat) do {} while (0)
46360 #define fscache_stat_d(stat) do {} while (0)
46361 #endif
46362
46363 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46364 index b6b897c..0ffff9c 100644
46365 --- a/fs/fscache/object.c
46366 +++ b/fs/fscache/object.c
46367 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46368 /* update the object metadata on disk */
46369 case FSCACHE_OBJECT_UPDATING:
46370 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46371 - fscache_stat(&fscache_n_updates_run);
46372 + fscache_stat_unchecked(&fscache_n_updates_run);
46373 fscache_stat(&fscache_n_cop_update_object);
46374 object->cache->ops->update_object(object);
46375 fscache_stat_d(&fscache_n_cop_update_object);
46376 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46377 spin_lock(&object->lock);
46378 object->state = FSCACHE_OBJECT_DEAD;
46379 spin_unlock(&object->lock);
46380 - fscache_stat(&fscache_n_object_dead);
46381 + fscache_stat_unchecked(&fscache_n_object_dead);
46382 goto terminal_transit;
46383
46384 /* handle the parent cache of this object being withdrawn from
46385 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46386 spin_lock(&object->lock);
46387 object->state = FSCACHE_OBJECT_DEAD;
46388 spin_unlock(&object->lock);
46389 - fscache_stat(&fscache_n_object_dead);
46390 + fscache_stat_unchecked(&fscache_n_object_dead);
46391 goto terminal_transit;
46392
46393 /* complain about the object being woken up once it is
46394 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46395 parent->cookie->def->name, cookie->def->name,
46396 object->cache->tag->name);
46397
46398 - fscache_stat(&fscache_n_object_lookups);
46399 + fscache_stat_unchecked(&fscache_n_object_lookups);
46400 fscache_stat(&fscache_n_cop_lookup_object);
46401 ret = object->cache->ops->lookup_object(object);
46402 fscache_stat_d(&fscache_n_cop_lookup_object);
46403 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46404 if (ret == -ETIMEDOUT) {
46405 /* probably stuck behind another object, so move this one to
46406 * the back of the queue */
46407 - fscache_stat(&fscache_n_object_lookups_timed_out);
46408 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46409 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46410 }
46411
46412 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46413
46414 spin_lock(&object->lock);
46415 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46416 - fscache_stat(&fscache_n_object_lookups_negative);
46417 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46418
46419 /* transit here to allow write requests to begin stacking up
46420 * and read requests to begin returning ENODATA */
46421 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46422 * result, in which case there may be data available */
46423 spin_lock(&object->lock);
46424 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46425 - fscache_stat(&fscache_n_object_lookups_positive);
46426 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46427
46428 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46429
46430 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46431 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46432 } else {
46433 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46434 - fscache_stat(&fscache_n_object_created);
46435 + fscache_stat_unchecked(&fscache_n_object_created);
46436
46437 object->state = FSCACHE_OBJECT_AVAILABLE;
46438 spin_unlock(&object->lock);
46439 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46440 fscache_enqueue_dependents(object);
46441
46442 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46443 - fscache_stat(&fscache_n_object_avail);
46444 + fscache_stat_unchecked(&fscache_n_object_avail);
46445
46446 _leave("");
46447 }
46448 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46449 enum fscache_checkaux result;
46450
46451 if (!object->cookie->def->check_aux) {
46452 - fscache_stat(&fscache_n_checkaux_none);
46453 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46454 return FSCACHE_CHECKAUX_OKAY;
46455 }
46456
46457 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46458 switch (result) {
46459 /* entry okay as is */
46460 case FSCACHE_CHECKAUX_OKAY:
46461 - fscache_stat(&fscache_n_checkaux_okay);
46462 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46463 break;
46464
46465 /* entry requires update */
46466 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46467 - fscache_stat(&fscache_n_checkaux_update);
46468 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46469 break;
46470
46471 /* entry requires deletion */
46472 case FSCACHE_CHECKAUX_OBSOLETE:
46473 - fscache_stat(&fscache_n_checkaux_obsolete);
46474 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46475 break;
46476
46477 default:
46478 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46479 index 30afdfa..2256596 100644
46480 --- a/fs/fscache/operation.c
46481 +++ b/fs/fscache/operation.c
46482 @@ -17,7 +17,7 @@
46483 #include <linux/slab.h>
46484 #include "internal.h"
46485
46486 -atomic_t fscache_op_debug_id;
46487 +atomic_unchecked_t fscache_op_debug_id;
46488 EXPORT_SYMBOL(fscache_op_debug_id);
46489
46490 /**
46491 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46492 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46493 ASSERTCMP(atomic_read(&op->usage), >, 0);
46494
46495 - fscache_stat(&fscache_n_op_enqueue);
46496 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46497 switch (op->flags & FSCACHE_OP_TYPE) {
46498 case FSCACHE_OP_ASYNC:
46499 _debug("queue async");
46500 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46501 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46502 if (op->processor)
46503 fscache_enqueue_operation(op);
46504 - fscache_stat(&fscache_n_op_run);
46505 + fscache_stat_unchecked(&fscache_n_op_run);
46506 }
46507
46508 /*
46509 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46510 if (object->n_ops > 1) {
46511 atomic_inc(&op->usage);
46512 list_add_tail(&op->pend_link, &object->pending_ops);
46513 - fscache_stat(&fscache_n_op_pend);
46514 + fscache_stat_unchecked(&fscache_n_op_pend);
46515 } else if (!list_empty(&object->pending_ops)) {
46516 atomic_inc(&op->usage);
46517 list_add_tail(&op->pend_link, &object->pending_ops);
46518 - fscache_stat(&fscache_n_op_pend);
46519 + fscache_stat_unchecked(&fscache_n_op_pend);
46520 fscache_start_operations(object);
46521 } else {
46522 ASSERTCMP(object->n_in_progress, ==, 0);
46523 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46524 object->n_exclusive++; /* reads and writes must wait */
46525 atomic_inc(&op->usage);
46526 list_add_tail(&op->pend_link, &object->pending_ops);
46527 - fscache_stat(&fscache_n_op_pend);
46528 + fscache_stat_unchecked(&fscache_n_op_pend);
46529 ret = 0;
46530 } else {
46531 /* not allowed to submit ops in any other state */
46532 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46533 if (object->n_exclusive > 0) {
46534 atomic_inc(&op->usage);
46535 list_add_tail(&op->pend_link, &object->pending_ops);
46536 - fscache_stat(&fscache_n_op_pend);
46537 + fscache_stat_unchecked(&fscache_n_op_pend);
46538 } else if (!list_empty(&object->pending_ops)) {
46539 atomic_inc(&op->usage);
46540 list_add_tail(&op->pend_link, &object->pending_ops);
46541 - fscache_stat(&fscache_n_op_pend);
46542 + fscache_stat_unchecked(&fscache_n_op_pend);
46543 fscache_start_operations(object);
46544 } else {
46545 ASSERTCMP(object->n_exclusive, ==, 0);
46546 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46547 object->n_ops++;
46548 atomic_inc(&op->usage);
46549 list_add_tail(&op->pend_link, &object->pending_ops);
46550 - fscache_stat(&fscache_n_op_pend);
46551 + fscache_stat_unchecked(&fscache_n_op_pend);
46552 ret = 0;
46553 } else if (object->state == FSCACHE_OBJECT_DYING ||
46554 object->state == FSCACHE_OBJECT_LC_DYING ||
46555 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46556 - fscache_stat(&fscache_n_op_rejected);
46557 + fscache_stat_unchecked(&fscache_n_op_rejected);
46558 ret = -ENOBUFS;
46559 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46560 fscache_report_unexpected_submission(object, op, ostate);
46561 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46562
46563 ret = -EBUSY;
46564 if (!list_empty(&op->pend_link)) {
46565 - fscache_stat(&fscache_n_op_cancelled);
46566 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46567 list_del_init(&op->pend_link);
46568 object->n_ops--;
46569 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46570 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46571 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46572 BUG();
46573
46574 - fscache_stat(&fscache_n_op_release);
46575 + fscache_stat_unchecked(&fscache_n_op_release);
46576
46577 if (op->release) {
46578 op->release(op);
46579 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46580 * lock, and defer it otherwise */
46581 if (!spin_trylock(&object->lock)) {
46582 _debug("defer put");
46583 - fscache_stat(&fscache_n_op_deferred_release);
46584 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46585
46586 cache = object->cache;
46587 spin_lock(&cache->op_gc_list_lock);
46588 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46589
46590 _debug("GC DEFERRED REL OBJ%x OP%x",
46591 object->debug_id, op->debug_id);
46592 - fscache_stat(&fscache_n_op_gc);
46593 + fscache_stat_unchecked(&fscache_n_op_gc);
46594
46595 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46596
46597 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46598 index 3f7a59b..cf196cc 100644
46599 --- a/fs/fscache/page.c
46600 +++ b/fs/fscache/page.c
46601 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46602 val = radix_tree_lookup(&cookie->stores, page->index);
46603 if (!val) {
46604 rcu_read_unlock();
46605 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46606 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46607 __fscache_uncache_page(cookie, page);
46608 return true;
46609 }
46610 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46611 spin_unlock(&cookie->stores_lock);
46612
46613 if (xpage) {
46614 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46615 - fscache_stat(&fscache_n_store_radix_deletes);
46616 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46617 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46618 ASSERTCMP(xpage, ==, page);
46619 } else {
46620 - fscache_stat(&fscache_n_store_vmscan_gone);
46621 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46622 }
46623
46624 wake_up_bit(&cookie->flags, 0);
46625 @@ -107,7 +107,7 @@ page_busy:
46626 /* we might want to wait here, but that could deadlock the allocator as
46627 * the work threads writing to the cache may all end up sleeping
46628 * on memory allocation */
46629 - fscache_stat(&fscache_n_store_vmscan_busy);
46630 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46631 return false;
46632 }
46633 EXPORT_SYMBOL(__fscache_maybe_release_page);
46634 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46635 FSCACHE_COOKIE_STORING_TAG);
46636 if (!radix_tree_tag_get(&cookie->stores, page->index,
46637 FSCACHE_COOKIE_PENDING_TAG)) {
46638 - fscache_stat(&fscache_n_store_radix_deletes);
46639 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46640 xpage = radix_tree_delete(&cookie->stores, page->index);
46641 }
46642 spin_unlock(&cookie->stores_lock);
46643 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46644
46645 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46646
46647 - fscache_stat(&fscache_n_attr_changed_calls);
46648 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46649
46650 if (fscache_object_is_active(object)) {
46651 fscache_stat(&fscache_n_cop_attr_changed);
46652 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46653
46654 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46655
46656 - fscache_stat(&fscache_n_attr_changed);
46657 + fscache_stat_unchecked(&fscache_n_attr_changed);
46658
46659 op = kzalloc(sizeof(*op), GFP_KERNEL);
46660 if (!op) {
46661 - fscache_stat(&fscache_n_attr_changed_nomem);
46662 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46663 _leave(" = -ENOMEM");
46664 return -ENOMEM;
46665 }
46666 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46667 if (fscache_submit_exclusive_op(object, op) < 0)
46668 goto nobufs;
46669 spin_unlock(&cookie->lock);
46670 - fscache_stat(&fscache_n_attr_changed_ok);
46671 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46672 fscache_put_operation(op);
46673 _leave(" = 0");
46674 return 0;
46675 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46676 nobufs:
46677 spin_unlock(&cookie->lock);
46678 kfree(op);
46679 - fscache_stat(&fscache_n_attr_changed_nobufs);
46680 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46681 _leave(" = %d", -ENOBUFS);
46682 return -ENOBUFS;
46683 }
46684 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46685 /* allocate a retrieval operation and attempt to submit it */
46686 op = kzalloc(sizeof(*op), GFP_NOIO);
46687 if (!op) {
46688 - fscache_stat(&fscache_n_retrievals_nomem);
46689 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46690 return NULL;
46691 }
46692
46693 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46694 return 0;
46695 }
46696
46697 - fscache_stat(&fscache_n_retrievals_wait);
46698 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46699
46700 jif = jiffies;
46701 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46702 fscache_wait_bit_interruptible,
46703 TASK_INTERRUPTIBLE) != 0) {
46704 - fscache_stat(&fscache_n_retrievals_intr);
46705 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46706 _leave(" = -ERESTARTSYS");
46707 return -ERESTARTSYS;
46708 }
46709 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46710 */
46711 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46712 struct fscache_retrieval *op,
46713 - atomic_t *stat_op_waits,
46714 - atomic_t *stat_object_dead)
46715 + atomic_unchecked_t *stat_op_waits,
46716 + atomic_unchecked_t *stat_object_dead)
46717 {
46718 int ret;
46719
46720 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46721 goto check_if_dead;
46722
46723 _debug(">>> WT");
46724 - fscache_stat(stat_op_waits);
46725 + fscache_stat_unchecked(stat_op_waits);
46726 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46727 fscache_wait_bit_interruptible,
46728 TASK_INTERRUPTIBLE) < 0) {
46729 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46730
46731 check_if_dead:
46732 if (unlikely(fscache_object_is_dead(object))) {
46733 - fscache_stat(stat_object_dead);
46734 + fscache_stat_unchecked(stat_object_dead);
46735 return -ENOBUFS;
46736 }
46737 return 0;
46738 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46739
46740 _enter("%p,%p,,,", cookie, page);
46741
46742 - fscache_stat(&fscache_n_retrievals);
46743 + fscache_stat_unchecked(&fscache_n_retrievals);
46744
46745 if (hlist_empty(&cookie->backing_objects))
46746 goto nobufs;
46747 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46748 goto nobufs_unlock;
46749 spin_unlock(&cookie->lock);
46750
46751 - fscache_stat(&fscache_n_retrieval_ops);
46752 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46753
46754 /* pin the netfs read context in case we need to do the actual netfs
46755 * read because we've encountered a cache read failure */
46756 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46757
46758 error:
46759 if (ret == -ENOMEM)
46760 - fscache_stat(&fscache_n_retrievals_nomem);
46761 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46762 else if (ret == -ERESTARTSYS)
46763 - fscache_stat(&fscache_n_retrievals_intr);
46764 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46765 else if (ret == -ENODATA)
46766 - fscache_stat(&fscache_n_retrievals_nodata);
46767 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46768 else if (ret < 0)
46769 - fscache_stat(&fscache_n_retrievals_nobufs);
46770 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46771 else
46772 - fscache_stat(&fscache_n_retrievals_ok);
46773 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46774
46775 fscache_put_retrieval(op);
46776 _leave(" = %d", ret);
46777 @@ -429,7 +429,7 @@ nobufs_unlock:
46778 spin_unlock(&cookie->lock);
46779 kfree(op);
46780 nobufs:
46781 - fscache_stat(&fscache_n_retrievals_nobufs);
46782 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46783 _leave(" = -ENOBUFS");
46784 return -ENOBUFS;
46785 }
46786 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46787
46788 _enter("%p,,%d,,,", cookie, *nr_pages);
46789
46790 - fscache_stat(&fscache_n_retrievals);
46791 + fscache_stat_unchecked(&fscache_n_retrievals);
46792
46793 if (hlist_empty(&cookie->backing_objects))
46794 goto nobufs;
46795 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46796 goto nobufs_unlock;
46797 spin_unlock(&cookie->lock);
46798
46799 - fscache_stat(&fscache_n_retrieval_ops);
46800 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46801
46802 /* pin the netfs read context in case we need to do the actual netfs
46803 * read because we've encountered a cache read failure */
46804 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46805
46806 error:
46807 if (ret == -ENOMEM)
46808 - fscache_stat(&fscache_n_retrievals_nomem);
46809 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46810 else if (ret == -ERESTARTSYS)
46811 - fscache_stat(&fscache_n_retrievals_intr);
46812 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46813 else if (ret == -ENODATA)
46814 - fscache_stat(&fscache_n_retrievals_nodata);
46815 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46816 else if (ret < 0)
46817 - fscache_stat(&fscache_n_retrievals_nobufs);
46818 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46819 else
46820 - fscache_stat(&fscache_n_retrievals_ok);
46821 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46822
46823 fscache_put_retrieval(op);
46824 _leave(" = %d", ret);
46825 @@ -545,7 +545,7 @@ nobufs_unlock:
46826 spin_unlock(&cookie->lock);
46827 kfree(op);
46828 nobufs:
46829 - fscache_stat(&fscache_n_retrievals_nobufs);
46830 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46831 _leave(" = -ENOBUFS");
46832 return -ENOBUFS;
46833 }
46834 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46835
46836 _enter("%p,%p,,,", cookie, page);
46837
46838 - fscache_stat(&fscache_n_allocs);
46839 + fscache_stat_unchecked(&fscache_n_allocs);
46840
46841 if (hlist_empty(&cookie->backing_objects))
46842 goto nobufs;
46843 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46844 goto nobufs_unlock;
46845 spin_unlock(&cookie->lock);
46846
46847 - fscache_stat(&fscache_n_alloc_ops);
46848 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46849
46850 ret = fscache_wait_for_retrieval_activation(
46851 object, op,
46852 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46853
46854 error:
46855 if (ret == -ERESTARTSYS)
46856 - fscache_stat(&fscache_n_allocs_intr);
46857 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46858 else if (ret < 0)
46859 - fscache_stat(&fscache_n_allocs_nobufs);
46860 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46861 else
46862 - fscache_stat(&fscache_n_allocs_ok);
46863 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46864
46865 fscache_put_retrieval(op);
46866 _leave(" = %d", ret);
46867 @@ -625,7 +625,7 @@ nobufs_unlock:
46868 spin_unlock(&cookie->lock);
46869 kfree(op);
46870 nobufs:
46871 - fscache_stat(&fscache_n_allocs_nobufs);
46872 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46873 _leave(" = -ENOBUFS");
46874 return -ENOBUFS;
46875 }
46876 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46877
46878 spin_lock(&cookie->stores_lock);
46879
46880 - fscache_stat(&fscache_n_store_calls);
46881 + fscache_stat_unchecked(&fscache_n_store_calls);
46882
46883 /* find a page to store */
46884 page = NULL;
46885 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46886 page = results[0];
46887 _debug("gang %d [%lx]", n, page->index);
46888 if (page->index > op->store_limit) {
46889 - fscache_stat(&fscache_n_store_pages_over_limit);
46890 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46891 goto superseded;
46892 }
46893
46894 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46895 spin_unlock(&cookie->stores_lock);
46896 spin_unlock(&object->lock);
46897
46898 - fscache_stat(&fscache_n_store_pages);
46899 + fscache_stat_unchecked(&fscache_n_store_pages);
46900 fscache_stat(&fscache_n_cop_write_page);
46901 ret = object->cache->ops->write_page(op, page);
46902 fscache_stat_d(&fscache_n_cop_write_page);
46903 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46904 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46905 ASSERT(PageFsCache(page));
46906
46907 - fscache_stat(&fscache_n_stores);
46908 + fscache_stat_unchecked(&fscache_n_stores);
46909
46910 op = kzalloc(sizeof(*op), GFP_NOIO);
46911 if (!op)
46912 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46913 spin_unlock(&cookie->stores_lock);
46914 spin_unlock(&object->lock);
46915
46916 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46917 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46918 op->store_limit = object->store_limit;
46919
46920 if (fscache_submit_op(object, &op->op) < 0)
46921 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46922
46923 spin_unlock(&cookie->lock);
46924 radix_tree_preload_end();
46925 - fscache_stat(&fscache_n_store_ops);
46926 - fscache_stat(&fscache_n_stores_ok);
46927 + fscache_stat_unchecked(&fscache_n_store_ops);
46928 + fscache_stat_unchecked(&fscache_n_stores_ok);
46929
46930 /* the work queue now carries its own ref on the object */
46931 fscache_put_operation(&op->op);
46932 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46933 return 0;
46934
46935 already_queued:
46936 - fscache_stat(&fscache_n_stores_again);
46937 + fscache_stat_unchecked(&fscache_n_stores_again);
46938 already_pending:
46939 spin_unlock(&cookie->stores_lock);
46940 spin_unlock(&object->lock);
46941 spin_unlock(&cookie->lock);
46942 radix_tree_preload_end();
46943 kfree(op);
46944 - fscache_stat(&fscache_n_stores_ok);
46945 + fscache_stat_unchecked(&fscache_n_stores_ok);
46946 _leave(" = 0");
46947 return 0;
46948
46949 @@ -851,14 +851,14 @@ nobufs:
46950 spin_unlock(&cookie->lock);
46951 radix_tree_preload_end();
46952 kfree(op);
46953 - fscache_stat(&fscache_n_stores_nobufs);
46954 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
46955 _leave(" = -ENOBUFS");
46956 return -ENOBUFS;
46957
46958 nomem_free:
46959 kfree(op);
46960 nomem:
46961 - fscache_stat(&fscache_n_stores_oom);
46962 + fscache_stat_unchecked(&fscache_n_stores_oom);
46963 _leave(" = -ENOMEM");
46964 return -ENOMEM;
46965 }
46966 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
46967 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46968 ASSERTCMP(page, !=, NULL);
46969
46970 - fscache_stat(&fscache_n_uncaches);
46971 + fscache_stat_unchecked(&fscache_n_uncaches);
46972
46973 /* cache withdrawal may beat us to it */
46974 if (!PageFsCache(page))
46975 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
46976 unsigned long loop;
46977
46978 #ifdef CONFIG_FSCACHE_STATS
46979 - atomic_add(pagevec->nr, &fscache_n_marks);
46980 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
46981 #endif
46982
46983 for (loop = 0; loop < pagevec->nr; loop++) {
46984 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
46985 index 4765190..2a067f2 100644
46986 --- a/fs/fscache/stats.c
46987 +++ b/fs/fscache/stats.c
46988 @@ -18,95 +18,95 @@
46989 /*
46990 * operation counters
46991 */
46992 -atomic_t fscache_n_op_pend;
46993 -atomic_t fscache_n_op_run;
46994 -atomic_t fscache_n_op_enqueue;
46995 -atomic_t fscache_n_op_requeue;
46996 -atomic_t fscache_n_op_deferred_release;
46997 -atomic_t fscache_n_op_release;
46998 -atomic_t fscache_n_op_gc;
46999 -atomic_t fscache_n_op_cancelled;
47000 -atomic_t fscache_n_op_rejected;
47001 +atomic_unchecked_t fscache_n_op_pend;
47002 +atomic_unchecked_t fscache_n_op_run;
47003 +atomic_unchecked_t fscache_n_op_enqueue;
47004 +atomic_unchecked_t fscache_n_op_requeue;
47005 +atomic_unchecked_t fscache_n_op_deferred_release;
47006 +atomic_unchecked_t fscache_n_op_release;
47007 +atomic_unchecked_t fscache_n_op_gc;
47008 +atomic_unchecked_t fscache_n_op_cancelled;
47009 +atomic_unchecked_t fscache_n_op_rejected;
47010
47011 -atomic_t fscache_n_attr_changed;
47012 -atomic_t fscache_n_attr_changed_ok;
47013 -atomic_t fscache_n_attr_changed_nobufs;
47014 -atomic_t fscache_n_attr_changed_nomem;
47015 -atomic_t fscache_n_attr_changed_calls;
47016 +atomic_unchecked_t fscache_n_attr_changed;
47017 +atomic_unchecked_t fscache_n_attr_changed_ok;
47018 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47019 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47020 +atomic_unchecked_t fscache_n_attr_changed_calls;
47021
47022 -atomic_t fscache_n_allocs;
47023 -atomic_t fscache_n_allocs_ok;
47024 -atomic_t fscache_n_allocs_wait;
47025 -atomic_t fscache_n_allocs_nobufs;
47026 -atomic_t fscache_n_allocs_intr;
47027 -atomic_t fscache_n_allocs_object_dead;
47028 -atomic_t fscache_n_alloc_ops;
47029 -atomic_t fscache_n_alloc_op_waits;
47030 +atomic_unchecked_t fscache_n_allocs;
47031 +atomic_unchecked_t fscache_n_allocs_ok;
47032 +atomic_unchecked_t fscache_n_allocs_wait;
47033 +atomic_unchecked_t fscache_n_allocs_nobufs;
47034 +atomic_unchecked_t fscache_n_allocs_intr;
47035 +atomic_unchecked_t fscache_n_allocs_object_dead;
47036 +atomic_unchecked_t fscache_n_alloc_ops;
47037 +atomic_unchecked_t fscache_n_alloc_op_waits;
47038
47039 -atomic_t fscache_n_retrievals;
47040 -atomic_t fscache_n_retrievals_ok;
47041 -atomic_t fscache_n_retrievals_wait;
47042 -atomic_t fscache_n_retrievals_nodata;
47043 -atomic_t fscache_n_retrievals_nobufs;
47044 -atomic_t fscache_n_retrievals_intr;
47045 -atomic_t fscache_n_retrievals_nomem;
47046 -atomic_t fscache_n_retrievals_object_dead;
47047 -atomic_t fscache_n_retrieval_ops;
47048 -atomic_t fscache_n_retrieval_op_waits;
47049 +atomic_unchecked_t fscache_n_retrievals;
47050 +atomic_unchecked_t fscache_n_retrievals_ok;
47051 +atomic_unchecked_t fscache_n_retrievals_wait;
47052 +atomic_unchecked_t fscache_n_retrievals_nodata;
47053 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47054 +atomic_unchecked_t fscache_n_retrievals_intr;
47055 +atomic_unchecked_t fscache_n_retrievals_nomem;
47056 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47057 +atomic_unchecked_t fscache_n_retrieval_ops;
47058 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47059
47060 -atomic_t fscache_n_stores;
47061 -atomic_t fscache_n_stores_ok;
47062 -atomic_t fscache_n_stores_again;
47063 -atomic_t fscache_n_stores_nobufs;
47064 -atomic_t fscache_n_stores_oom;
47065 -atomic_t fscache_n_store_ops;
47066 -atomic_t fscache_n_store_calls;
47067 -atomic_t fscache_n_store_pages;
47068 -atomic_t fscache_n_store_radix_deletes;
47069 -atomic_t fscache_n_store_pages_over_limit;
47070 +atomic_unchecked_t fscache_n_stores;
47071 +atomic_unchecked_t fscache_n_stores_ok;
47072 +atomic_unchecked_t fscache_n_stores_again;
47073 +atomic_unchecked_t fscache_n_stores_nobufs;
47074 +atomic_unchecked_t fscache_n_stores_oom;
47075 +atomic_unchecked_t fscache_n_store_ops;
47076 +atomic_unchecked_t fscache_n_store_calls;
47077 +atomic_unchecked_t fscache_n_store_pages;
47078 +atomic_unchecked_t fscache_n_store_radix_deletes;
47079 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47080
47081 -atomic_t fscache_n_store_vmscan_not_storing;
47082 -atomic_t fscache_n_store_vmscan_gone;
47083 -atomic_t fscache_n_store_vmscan_busy;
47084 -atomic_t fscache_n_store_vmscan_cancelled;
47085 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47086 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47087 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47088 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47089
47090 -atomic_t fscache_n_marks;
47091 -atomic_t fscache_n_uncaches;
47092 +atomic_unchecked_t fscache_n_marks;
47093 +atomic_unchecked_t fscache_n_uncaches;
47094
47095 -atomic_t fscache_n_acquires;
47096 -atomic_t fscache_n_acquires_null;
47097 -atomic_t fscache_n_acquires_no_cache;
47098 -atomic_t fscache_n_acquires_ok;
47099 -atomic_t fscache_n_acquires_nobufs;
47100 -atomic_t fscache_n_acquires_oom;
47101 +atomic_unchecked_t fscache_n_acquires;
47102 +atomic_unchecked_t fscache_n_acquires_null;
47103 +atomic_unchecked_t fscache_n_acquires_no_cache;
47104 +atomic_unchecked_t fscache_n_acquires_ok;
47105 +atomic_unchecked_t fscache_n_acquires_nobufs;
47106 +atomic_unchecked_t fscache_n_acquires_oom;
47107
47108 -atomic_t fscache_n_updates;
47109 -atomic_t fscache_n_updates_null;
47110 -atomic_t fscache_n_updates_run;
47111 +atomic_unchecked_t fscache_n_updates;
47112 +atomic_unchecked_t fscache_n_updates_null;
47113 +atomic_unchecked_t fscache_n_updates_run;
47114
47115 -atomic_t fscache_n_relinquishes;
47116 -atomic_t fscache_n_relinquishes_null;
47117 -atomic_t fscache_n_relinquishes_waitcrt;
47118 -atomic_t fscache_n_relinquishes_retire;
47119 +atomic_unchecked_t fscache_n_relinquishes;
47120 +atomic_unchecked_t fscache_n_relinquishes_null;
47121 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47122 +atomic_unchecked_t fscache_n_relinquishes_retire;
47123
47124 -atomic_t fscache_n_cookie_index;
47125 -atomic_t fscache_n_cookie_data;
47126 -atomic_t fscache_n_cookie_special;
47127 +atomic_unchecked_t fscache_n_cookie_index;
47128 +atomic_unchecked_t fscache_n_cookie_data;
47129 +atomic_unchecked_t fscache_n_cookie_special;
47130
47131 -atomic_t fscache_n_object_alloc;
47132 -atomic_t fscache_n_object_no_alloc;
47133 -atomic_t fscache_n_object_lookups;
47134 -atomic_t fscache_n_object_lookups_negative;
47135 -atomic_t fscache_n_object_lookups_positive;
47136 -atomic_t fscache_n_object_lookups_timed_out;
47137 -atomic_t fscache_n_object_created;
47138 -atomic_t fscache_n_object_avail;
47139 -atomic_t fscache_n_object_dead;
47140 +atomic_unchecked_t fscache_n_object_alloc;
47141 +atomic_unchecked_t fscache_n_object_no_alloc;
47142 +atomic_unchecked_t fscache_n_object_lookups;
47143 +atomic_unchecked_t fscache_n_object_lookups_negative;
47144 +atomic_unchecked_t fscache_n_object_lookups_positive;
47145 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47146 +atomic_unchecked_t fscache_n_object_created;
47147 +atomic_unchecked_t fscache_n_object_avail;
47148 +atomic_unchecked_t fscache_n_object_dead;
47149
47150 -atomic_t fscache_n_checkaux_none;
47151 -atomic_t fscache_n_checkaux_okay;
47152 -atomic_t fscache_n_checkaux_update;
47153 -atomic_t fscache_n_checkaux_obsolete;
47154 +atomic_unchecked_t fscache_n_checkaux_none;
47155 +atomic_unchecked_t fscache_n_checkaux_okay;
47156 +atomic_unchecked_t fscache_n_checkaux_update;
47157 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47158
47159 atomic_t fscache_n_cop_alloc_object;
47160 atomic_t fscache_n_cop_lookup_object;
47161 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47162 seq_puts(m, "FS-Cache statistics\n");
47163
47164 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47165 - atomic_read(&fscache_n_cookie_index),
47166 - atomic_read(&fscache_n_cookie_data),
47167 - atomic_read(&fscache_n_cookie_special));
47168 + atomic_read_unchecked(&fscache_n_cookie_index),
47169 + atomic_read_unchecked(&fscache_n_cookie_data),
47170 + atomic_read_unchecked(&fscache_n_cookie_special));
47171
47172 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47173 - atomic_read(&fscache_n_object_alloc),
47174 - atomic_read(&fscache_n_object_no_alloc),
47175 - atomic_read(&fscache_n_object_avail),
47176 - atomic_read(&fscache_n_object_dead));
47177 + atomic_read_unchecked(&fscache_n_object_alloc),
47178 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47179 + atomic_read_unchecked(&fscache_n_object_avail),
47180 + atomic_read_unchecked(&fscache_n_object_dead));
47181 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47182 - atomic_read(&fscache_n_checkaux_none),
47183 - atomic_read(&fscache_n_checkaux_okay),
47184 - atomic_read(&fscache_n_checkaux_update),
47185 - atomic_read(&fscache_n_checkaux_obsolete));
47186 + atomic_read_unchecked(&fscache_n_checkaux_none),
47187 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47188 + atomic_read_unchecked(&fscache_n_checkaux_update),
47189 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47190
47191 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47192 - atomic_read(&fscache_n_marks),
47193 - atomic_read(&fscache_n_uncaches));
47194 + atomic_read_unchecked(&fscache_n_marks),
47195 + atomic_read_unchecked(&fscache_n_uncaches));
47196
47197 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47198 " oom=%u\n",
47199 - atomic_read(&fscache_n_acquires),
47200 - atomic_read(&fscache_n_acquires_null),
47201 - atomic_read(&fscache_n_acquires_no_cache),
47202 - atomic_read(&fscache_n_acquires_ok),
47203 - atomic_read(&fscache_n_acquires_nobufs),
47204 - atomic_read(&fscache_n_acquires_oom));
47205 + atomic_read_unchecked(&fscache_n_acquires),
47206 + atomic_read_unchecked(&fscache_n_acquires_null),
47207 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47208 + atomic_read_unchecked(&fscache_n_acquires_ok),
47209 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47210 + atomic_read_unchecked(&fscache_n_acquires_oom));
47211
47212 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47213 - atomic_read(&fscache_n_object_lookups),
47214 - atomic_read(&fscache_n_object_lookups_negative),
47215 - atomic_read(&fscache_n_object_lookups_positive),
47216 - atomic_read(&fscache_n_object_created),
47217 - atomic_read(&fscache_n_object_lookups_timed_out));
47218 + atomic_read_unchecked(&fscache_n_object_lookups),
47219 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47220 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47221 + atomic_read_unchecked(&fscache_n_object_created),
47222 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47223
47224 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47225 - atomic_read(&fscache_n_updates),
47226 - atomic_read(&fscache_n_updates_null),
47227 - atomic_read(&fscache_n_updates_run));
47228 + atomic_read_unchecked(&fscache_n_updates),
47229 + atomic_read_unchecked(&fscache_n_updates_null),
47230 + atomic_read_unchecked(&fscache_n_updates_run));
47231
47232 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47233 - atomic_read(&fscache_n_relinquishes),
47234 - atomic_read(&fscache_n_relinquishes_null),
47235 - atomic_read(&fscache_n_relinquishes_waitcrt),
47236 - atomic_read(&fscache_n_relinquishes_retire));
47237 + atomic_read_unchecked(&fscache_n_relinquishes),
47238 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47239 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47240 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47241
47242 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47243 - atomic_read(&fscache_n_attr_changed),
47244 - atomic_read(&fscache_n_attr_changed_ok),
47245 - atomic_read(&fscache_n_attr_changed_nobufs),
47246 - atomic_read(&fscache_n_attr_changed_nomem),
47247 - atomic_read(&fscache_n_attr_changed_calls));
47248 + atomic_read_unchecked(&fscache_n_attr_changed),
47249 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47250 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47251 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47252 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47253
47254 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47255 - atomic_read(&fscache_n_allocs),
47256 - atomic_read(&fscache_n_allocs_ok),
47257 - atomic_read(&fscache_n_allocs_wait),
47258 - atomic_read(&fscache_n_allocs_nobufs),
47259 - atomic_read(&fscache_n_allocs_intr));
47260 + atomic_read_unchecked(&fscache_n_allocs),
47261 + atomic_read_unchecked(&fscache_n_allocs_ok),
47262 + atomic_read_unchecked(&fscache_n_allocs_wait),
47263 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47264 + atomic_read_unchecked(&fscache_n_allocs_intr));
47265 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47266 - atomic_read(&fscache_n_alloc_ops),
47267 - atomic_read(&fscache_n_alloc_op_waits),
47268 - atomic_read(&fscache_n_allocs_object_dead));
47269 + atomic_read_unchecked(&fscache_n_alloc_ops),
47270 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47271 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47272
47273 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47274 " int=%u oom=%u\n",
47275 - atomic_read(&fscache_n_retrievals),
47276 - atomic_read(&fscache_n_retrievals_ok),
47277 - atomic_read(&fscache_n_retrievals_wait),
47278 - atomic_read(&fscache_n_retrievals_nodata),
47279 - atomic_read(&fscache_n_retrievals_nobufs),
47280 - atomic_read(&fscache_n_retrievals_intr),
47281 - atomic_read(&fscache_n_retrievals_nomem));
47282 + atomic_read_unchecked(&fscache_n_retrievals),
47283 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47284 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47285 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47286 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47287 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47288 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47289 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47290 - atomic_read(&fscache_n_retrieval_ops),
47291 - atomic_read(&fscache_n_retrieval_op_waits),
47292 - atomic_read(&fscache_n_retrievals_object_dead));
47293 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47294 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47295 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47296
47297 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47298 - atomic_read(&fscache_n_stores),
47299 - atomic_read(&fscache_n_stores_ok),
47300 - atomic_read(&fscache_n_stores_again),
47301 - atomic_read(&fscache_n_stores_nobufs),
47302 - atomic_read(&fscache_n_stores_oom));
47303 + atomic_read_unchecked(&fscache_n_stores),
47304 + atomic_read_unchecked(&fscache_n_stores_ok),
47305 + atomic_read_unchecked(&fscache_n_stores_again),
47306 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47307 + atomic_read_unchecked(&fscache_n_stores_oom));
47308 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47309 - atomic_read(&fscache_n_store_ops),
47310 - atomic_read(&fscache_n_store_calls),
47311 - atomic_read(&fscache_n_store_pages),
47312 - atomic_read(&fscache_n_store_radix_deletes),
47313 - atomic_read(&fscache_n_store_pages_over_limit));
47314 + atomic_read_unchecked(&fscache_n_store_ops),
47315 + atomic_read_unchecked(&fscache_n_store_calls),
47316 + atomic_read_unchecked(&fscache_n_store_pages),
47317 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47318 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47319
47320 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47321 - atomic_read(&fscache_n_store_vmscan_not_storing),
47322 - atomic_read(&fscache_n_store_vmscan_gone),
47323 - atomic_read(&fscache_n_store_vmscan_busy),
47324 - atomic_read(&fscache_n_store_vmscan_cancelled));
47325 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47326 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47327 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47328 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47329
47330 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47331 - atomic_read(&fscache_n_op_pend),
47332 - atomic_read(&fscache_n_op_run),
47333 - atomic_read(&fscache_n_op_enqueue),
47334 - atomic_read(&fscache_n_op_cancelled),
47335 - atomic_read(&fscache_n_op_rejected));
47336 + atomic_read_unchecked(&fscache_n_op_pend),
47337 + atomic_read_unchecked(&fscache_n_op_run),
47338 + atomic_read_unchecked(&fscache_n_op_enqueue),
47339 + atomic_read_unchecked(&fscache_n_op_cancelled),
47340 + atomic_read_unchecked(&fscache_n_op_rejected));
47341 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47342 - atomic_read(&fscache_n_op_deferred_release),
47343 - atomic_read(&fscache_n_op_release),
47344 - atomic_read(&fscache_n_op_gc));
47345 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47346 + atomic_read_unchecked(&fscache_n_op_release),
47347 + atomic_read_unchecked(&fscache_n_op_gc));
47348
47349 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47350 atomic_read(&fscache_n_cop_alloc_object),
47351 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47352 index ee8d550..7189d8c 100644
47353 --- a/fs/fuse/cuse.c
47354 +++ b/fs/fuse/cuse.c
47355 @@ -585,10 +585,12 @@ static int __init cuse_init(void)
47356 INIT_LIST_HEAD(&cuse_conntbl[i]);
47357
47358 /* inherit and extend fuse_dev_operations */
47359 - cuse_channel_fops = fuse_dev_operations;
47360 - cuse_channel_fops.owner = THIS_MODULE;
47361 - cuse_channel_fops.open = cuse_channel_open;
47362 - cuse_channel_fops.release = cuse_channel_release;
47363 + pax_open_kernel();
47364 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47365 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47366 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47367 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47368 + pax_close_kernel();
47369
47370 cuse_class = class_create(THIS_MODULE, "cuse");
47371 if (IS_ERR(cuse_class))
47372 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47373 index f4246cf..b4aed1d 100644
47374 --- a/fs/fuse/dev.c
47375 +++ b/fs/fuse/dev.c
47376 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47377 ret = 0;
47378 pipe_lock(pipe);
47379
47380 - if (!pipe->readers) {
47381 + if (!atomic_read(&pipe->readers)) {
47382 send_sig(SIGPIPE, current, 0);
47383 if (!ret)
47384 ret = -EPIPE;
47385 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47386 index 324bc08..4fdd56e 100644
47387 --- a/fs/fuse/dir.c
47388 +++ b/fs/fuse/dir.c
47389 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
47390 return link;
47391 }
47392
47393 -static void free_link(char *link)
47394 +static void free_link(const char *link)
47395 {
47396 if (!IS_ERR(link))
47397 free_page((unsigned long) link);
47398 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47399 index 753af3d..f7b021a 100644
47400 --- a/fs/gfs2/inode.c
47401 +++ b/fs/gfs2/inode.c
47402 @@ -1498,7 +1498,7 @@ out:
47403
47404 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47405 {
47406 - char *s = nd_get_link(nd);
47407 + const char *s = nd_get_link(nd);
47408 if (!IS_ERR(s))
47409 kfree(s);
47410 }
47411 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47412 index 8349a89..51a0254 100644
47413 --- a/fs/hugetlbfs/inode.c
47414 +++ b/fs/hugetlbfs/inode.c
47415 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47416 .kill_sb = kill_litter_super,
47417 };
47418
47419 -static struct vfsmount *hugetlbfs_vfsmount;
47420 +struct vfsmount *hugetlbfs_vfsmount;
47421
47422 static int can_do_hugetlb_shm(void)
47423 {
47424 diff --git a/fs/inode.c b/fs/inode.c
47425 index ac8d904..9f45d40 100644
47426 --- a/fs/inode.c
47427 +++ b/fs/inode.c
47428 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47429
47430 #ifdef CONFIG_SMP
47431 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47432 - static atomic_t shared_last_ino;
47433 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47434 + static atomic_unchecked_t shared_last_ino;
47435 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47436
47437 res = next - LAST_INO_BATCH;
47438 }
47439 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47440 index 4a6cf28..d3a29d3 100644
47441 --- a/fs/jffs2/erase.c
47442 +++ b/fs/jffs2/erase.c
47443 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47444 struct jffs2_unknown_node marker = {
47445 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47446 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47447 - .totlen = cpu_to_je32(c->cleanmarker_size)
47448 + .totlen = cpu_to_je32(c->cleanmarker_size),
47449 + .hdr_crc = cpu_to_je32(0)
47450 };
47451
47452 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47453 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47454 index a6597d6..41b30ec 100644
47455 --- a/fs/jffs2/wbuf.c
47456 +++ b/fs/jffs2/wbuf.c
47457 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47458 {
47459 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47460 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47461 - .totlen = constant_cpu_to_je32(8)
47462 + .totlen = constant_cpu_to_je32(8),
47463 + .hdr_crc = constant_cpu_to_je32(0)
47464 };
47465
47466 /*
47467 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47468 index c55c745..f67ee56 100644
47469 --- a/fs/jfs/super.c
47470 +++ b/fs/jfs/super.c
47471 @@ -806,7 +806,7 @@ static int __init init_jfs_fs(void)
47472
47473 jfs_inode_cachep =
47474 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47475 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47476 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47477 init_once);
47478 if (jfs_inode_cachep == NULL)
47479 return -ENOMEM;
47480 diff --git a/fs/libfs.c b/fs/libfs.c
47481 index a74cb17..37fcbe4 100644
47482 --- a/fs/libfs.c
47483 +++ b/fs/libfs.c
47484 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47485
47486 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47487 struct dentry *next;
47488 + char d_name[sizeof(next->d_iname)];
47489 + const unsigned char *name;
47490 +
47491 next = list_entry(p, struct dentry, d_u.d_child);
47492 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47493 if (!simple_positive(next)) {
47494 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47495
47496 spin_unlock(&next->d_lock);
47497 spin_unlock(&dentry->d_lock);
47498 - if (filldir(dirent, next->d_name.name,
47499 + name = next->d_name.name;
47500 + if (name == next->d_iname) {
47501 + memcpy(d_name, name, next->d_name.len);
47502 + name = d_name;
47503 + }
47504 + if (filldir(dirent, name,
47505 next->d_name.len, filp->f_pos,
47506 next->d_inode->i_ino,
47507 dt_type(next->d_inode)) < 0)
47508 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47509 index 05d2912..760abfa 100644
47510 --- a/fs/lockd/clntproc.c
47511 +++ b/fs/lockd/clntproc.c
47512 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47513 /*
47514 * Cookie counter for NLM requests
47515 */
47516 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47517 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47518
47519 void nlmclnt_next_cookie(struct nlm_cookie *c)
47520 {
47521 - u32 cookie = atomic_inc_return(&nlm_cookie);
47522 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47523
47524 memcpy(c->data, &cookie, 4);
47525 c->len=4;
47526 diff --git a/fs/locks.c b/fs/locks.c
47527 index 7e81bfc..c3649aa 100644
47528 --- a/fs/locks.c
47529 +++ b/fs/locks.c
47530 @@ -2066,16 +2066,16 @@ void locks_remove_flock(struct file *filp)
47531 return;
47532
47533 if (filp->f_op && filp->f_op->flock) {
47534 - struct file_lock fl = {
47535 + struct file_lock flock = {
47536 .fl_pid = current->tgid,
47537 .fl_file = filp,
47538 .fl_flags = FL_FLOCK,
47539 .fl_type = F_UNLCK,
47540 .fl_end = OFFSET_MAX,
47541 };
47542 - filp->f_op->flock(filp, F_SETLKW, &fl);
47543 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47544 - fl.fl_ops->fl_release_private(&fl);
47545 + filp->f_op->flock(filp, F_SETLKW, &flock);
47546 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47547 + flock.fl_ops->fl_release_private(&flock);
47548 }
47549
47550 lock_flocks();
47551 diff --git a/fs/namei.c b/fs/namei.c
47552 index dd1ed1b..875e998 100644
47553 --- a/fs/namei.c
47554 +++ b/fs/namei.c
47555 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47556 if (ret != -EACCES)
47557 return ret;
47558
47559 +#ifdef CONFIG_GRKERNSEC
47560 + /* we'll block if we have to log due to a denied capability use */
47561 + if (mask & MAY_NOT_BLOCK)
47562 + return -ECHILD;
47563 +#endif
47564 +
47565 if (S_ISDIR(inode->i_mode)) {
47566 /* DACs are overridable for directories */
47567 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47568 - return 0;
47569 if (!(mask & MAY_WRITE))
47570 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47571 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47572 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47573 return 0;
47574 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47575 + return 0;
47576 return -EACCES;
47577 }
47578 /*
47579 + * Searching includes executable on directories, else just read.
47580 + */
47581 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47582 + if (mask == MAY_READ)
47583 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47584 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47585 + return 0;
47586 +
47587 + /*
47588 * Read/write DACs are always overridable.
47589 * Executable DACs are overridable when there is
47590 * at least one exec bit set.
47591 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47592 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47593 return 0;
47594
47595 - /*
47596 - * Searching includes executable on directories, else just read.
47597 - */
47598 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47599 - if (mask == MAY_READ)
47600 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47601 - return 0;
47602 -
47603 return -EACCES;
47604 }
47605
47606 @@ -772,7 +780,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47607 {
47608 struct dentry *dentry = link->dentry;
47609 int error;
47610 - char *s;
47611 + const char *s;
47612
47613 BUG_ON(nd->flags & LOOKUP_RCU);
47614
47615 @@ -793,6 +801,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47616 if (error)
47617 goto out_put_nd_path;
47618
47619 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47620 + dentry->d_inode, dentry, nd->path.mnt)) {
47621 + error = -EACCES;
47622 + goto out_put_nd_path;
47623 + }
47624 +
47625 nd->last_type = LAST_BIND;
47626 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47627 error = PTR_ERR(*p);
47628 @@ -1550,6 +1564,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47629 break;
47630 res = walk_component(nd, path, &nd->last,
47631 nd->last_type, LOOKUP_FOLLOW);
47632 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47633 + res = -EACCES;
47634 put_link(nd, &link, cookie);
47635 } while (res > 0);
47636
47637 @@ -1943,6 +1959,8 @@ static int path_lookupat(int dfd, const char *name,
47638 if (err)
47639 break;
47640 err = lookup_last(nd, &path);
47641 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47642 + err = -EACCES;
47643 put_link(nd, &link, cookie);
47644 }
47645 }
47646 @@ -1950,6 +1968,21 @@ static int path_lookupat(int dfd, const char *name,
47647 if (!err)
47648 err = complete_walk(nd);
47649
47650 + if (!(nd->flags & LOOKUP_PARENT)) {
47651 +#ifdef CONFIG_GRKERNSEC
47652 + if (flags & LOOKUP_RCU) {
47653 + if (!err)
47654 + path_put(&nd->path);
47655 + err = -ECHILD;
47656 + } else
47657 +#endif
47658 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47659 + if (!err)
47660 + path_put(&nd->path);
47661 + err = -ENOENT;
47662 + }
47663 + }
47664 +
47665 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47666 if (!nd->inode->i_op->lookup) {
47667 path_put(&nd->path);
47668 @@ -1977,6 +2010,15 @@ static int do_path_lookup(int dfd, const char *name,
47669 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47670
47671 if (likely(!retval)) {
47672 + if (*name != '/' && nd->path.dentry && nd->inode) {
47673 +#ifdef CONFIG_GRKERNSEC
47674 + if (flags & LOOKUP_RCU)
47675 + return -ECHILD;
47676 +#endif
47677 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47678 + return -ENOENT;
47679 + }
47680 +
47681 if (unlikely(!audit_dummy_context())) {
47682 if (nd->path.dentry && nd->inode)
47683 audit_inode(name, nd->path.dentry);
47684 @@ -2336,6 +2378,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47685 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47686 return -EPERM;
47687
47688 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47689 + return -EPERM;
47690 + if (gr_handle_rawio(inode))
47691 + return -EPERM;
47692 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47693 + return -EACCES;
47694 +
47695 return 0;
47696 }
47697
47698 @@ -2557,7 +2606,7 @@ looked_up:
47699 * cleared otherwise prior to returning.
47700 */
47701 static int lookup_open(struct nameidata *nd, struct path *path,
47702 - struct file *file,
47703 + struct path *link, struct file *file,
47704 const struct open_flags *op,
47705 bool got_write, int *opened)
47706 {
47707 @@ -2592,6 +2641,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47708 /* Negative dentry, just create the file */
47709 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
47710 umode_t mode = op->mode;
47711 +
47712 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47713 + error = -EACCES;
47714 + goto out_dput;
47715 + }
47716 +
47717 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
47718 + error = -EACCES;
47719 + goto out_dput;
47720 + }
47721 +
47722 if (!IS_POSIXACL(dir->d_inode))
47723 mode &= ~current_umask();
47724 /*
47725 @@ -2613,6 +2673,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
47726 nd->flags & LOOKUP_EXCL);
47727 if (error)
47728 goto out_dput;
47729 + else
47730 + gr_handle_create(dentry, nd->path.mnt);
47731 }
47732 out_no_open:
47733 path->dentry = dentry;
47734 @@ -2627,7 +2689,7 @@ out_dput:
47735 /*
47736 * Handle the last step of open()
47737 */
47738 -static int do_last(struct nameidata *nd, struct path *path,
47739 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
47740 struct file *file, const struct open_flags *op,
47741 int *opened, const char *pathname)
47742 {
47743 @@ -2656,16 +2718,44 @@ static int do_last(struct nameidata *nd, struct path *path,
47744 error = complete_walk(nd);
47745 if (error)
47746 return error;
47747 +#ifdef CONFIG_GRKERNSEC
47748 + if (nd->flags & LOOKUP_RCU) {
47749 + error = -ECHILD;
47750 + goto out;
47751 + }
47752 +#endif
47753 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47754 + error = -ENOENT;
47755 + goto out;
47756 + }
47757 audit_inode(pathname, nd->path.dentry);
47758 if (open_flag & O_CREAT) {
47759 error = -EISDIR;
47760 goto out;
47761 }
47762 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47763 + error = -EACCES;
47764 + goto out;
47765 + }
47766 goto finish_open;
47767 case LAST_BIND:
47768 error = complete_walk(nd);
47769 if (error)
47770 return error;
47771 +#ifdef CONFIG_GRKERNSEC
47772 + if (nd->flags & LOOKUP_RCU) {
47773 + error = -ECHILD;
47774 + goto out;
47775 + }
47776 +#endif
47777 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47778 + error = -ENOENT;
47779 + goto out;
47780 + }
47781 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47782 + error = -EACCES;
47783 + goto out;
47784 + }
47785 audit_inode(pathname, dir);
47786 goto finish_open;
47787 }
47788 @@ -2714,7 +2804,7 @@ retry_lookup:
47789 */
47790 }
47791 mutex_lock(&dir->d_inode->i_mutex);
47792 - error = lookup_open(nd, path, file, op, got_write, opened);
47793 + error = lookup_open(nd, path, link, file, op, got_write, opened);
47794 mutex_unlock(&dir->d_inode->i_mutex);
47795
47796 if (error <= 0) {
47797 @@ -2738,11 +2828,28 @@ retry_lookup:
47798 goto finish_open_created;
47799 }
47800
47801 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
47802 + error = -ENOENT;
47803 + goto exit_dput;
47804 + }
47805 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
47806 + error = -EACCES;
47807 + goto exit_dput;
47808 + }
47809 +
47810 /*
47811 * create/update audit record if it already exists.
47812 */
47813 - if (path->dentry->d_inode)
47814 + if (path->dentry->d_inode) {
47815 + /* only check if O_CREAT is specified, all other checks need to go
47816 + into may_open */
47817 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47818 + error = -EACCES;
47819 + goto exit_dput;
47820 + }
47821 +
47822 audit_inode(pathname, path->dentry);
47823 + }
47824
47825 /*
47826 * If atomic_open() acquired write access it is dropped now due to
47827 @@ -2783,6 +2890,11 @@ finish_lookup:
47828 }
47829 }
47830 BUG_ON(inode != path->dentry->d_inode);
47831 + /* if we're resolving a symlink to another symlink */
47832 + if (link && gr_handle_symlink_owner(link, inode)) {
47833 + error = -EACCES;
47834 + goto out;
47835 + }
47836 return 1;
47837 }
47838
47839 @@ -2792,7 +2904,6 @@ finish_lookup:
47840 save_parent.dentry = nd->path.dentry;
47841 save_parent.mnt = mntget(path->mnt);
47842 nd->path.dentry = path->dentry;
47843 -
47844 }
47845 nd->inode = inode;
47846 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47847 @@ -2801,6 +2912,22 @@ finish_lookup:
47848 path_put(&save_parent);
47849 return error;
47850 }
47851 +
47852 +#ifdef CONFIG_GRKERNSEC
47853 + if (nd->flags & LOOKUP_RCU) {
47854 + error = -ECHILD;
47855 + goto out;
47856 + }
47857 +#endif
47858 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47859 + error = -ENOENT;
47860 + goto out;
47861 + }
47862 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47863 + error = -EACCES;
47864 + goto out;
47865 + }
47866 +
47867 error = -EISDIR;
47868 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47869 goto out;
47870 @@ -2899,7 +3026,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47871 if (unlikely(error))
47872 goto out;
47873
47874 - error = do_last(nd, &path, file, op, &opened, pathname);
47875 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
47876 while (unlikely(error > 0)) { /* trailing symlink */
47877 struct path link = path;
47878 void *cookie;
47879 @@ -2917,7 +3044,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47880 error = follow_link(&link, nd, &cookie);
47881 if (unlikely(error))
47882 break;
47883 - error = do_last(nd, &path, file, op, &opened, pathname);
47884 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
47885 put_link(nd, &link, cookie);
47886 }
47887 out:
47888 @@ -3006,8 +3133,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47889 goto unlock;
47890
47891 error = -EEXIST;
47892 - if (dentry->d_inode)
47893 + if (dentry->d_inode) {
47894 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47895 + error = -ENOENT;
47896 + }
47897 goto fail;
47898 + }
47899 /*
47900 * Special case - lookup gave negative, but... we had foo/bar/
47901 * From the vfs_mknod() POV we just have a negative dentry -
47902 @@ -3058,6 +3189,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47903 }
47904 EXPORT_SYMBOL(user_path_create);
47905
47906 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47907 +{
47908 + char *tmp = getname(pathname);
47909 + struct dentry *res;
47910 + if (IS_ERR(tmp))
47911 + return ERR_CAST(tmp);
47912 + res = kern_path_create(dfd, tmp, path, is_dir);
47913 + if (IS_ERR(res))
47914 + putname(tmp);
47915 + else
47916 + *to = tmp;
47917 + return res;
47918 +}
47919 +
47920 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47921 {
47922 int error = may_create(dir, dentry);
47923 @@ -3119,6 +3264,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47924
47925 if (!IS_POSIXACL(path.dentry->d_inode))
47926 mode &= ~current_umask();
47927 +
47928 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47929 + error = -EPERM;
47930 + goto out;
47931 + }
47932 +
47933 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47934 + error = -EACCES;
47935 + goto out;
47936 + }
47937 +
47938 error = security_path_mknod(&path, dentry, mode, dev);
47939 if (error)
47940 goto out;
47941 @@ -3135,6 +3291,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47942 break;
47943 }
47944 out:
47945 + if (!error)
47946 + gr_handle_create(dentry, path.mnt);
47947 done_path_create(&path, dentry);
47948 return error;
47949 }
47950 @@ -3181,9 +3339,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
47951
47952 if (!IS_POSIXACL(path.dentry->d_inode))
47953 mode &= ~current_umask();
47954 +
47955 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
47956 + error = -EACCES;
47957 + goto out;
47958 + }
47959 +
47960 error = security_path_mkdir(&path, dentry, mode);
47961 if (!error)
47962 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
47963 + if (!error)
47964 + gr_handle_create(dentry, path.mnt);
47965 +out:
47966 done_path_create(&path, dentry);
47967 return error;
47968 }
47969 @@ -3260,6 +3427,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
47970 char * name;
47971 struct dentry *dentry;
47972 struct nameidata nd;
47973 + ino_t saved_ino = 0;
47974 + dev_t saved_dev = 0;
47975
47976 error = user_path_parent(dfd, pathname, &nd, &name);
47977 if (error)
47978 @@ -3291,10 +3460,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
47979 error = -ENOENT;
47980 goto exit3;
47981 }
47982 +
47983 + saved_ino = dentry->d_inode->i_ino;
47984 + saved_dev = gr_get_dev_from_dentry(dentry);
47985 +
47986 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
47987 + error = -EACCES;
47988 + goto exit3;
47989 + }
47990 +
47991 error = security_path_rmdir(&nd.path, dentry);
47992 if (error)
47993 goto exit3;
47994 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
47995 + if (!error && (saved_dev || saved_ino))
47996 + gr_handle_delete(saved_ino, saved_dev);
47997 exit3:
47998 dput(dentry);
47999 exit2:
48000 @@ -3356,6 +3536,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48001 struct dentry *dentry;
48002 struct nameidata nd;
48003 struct inode *inode = NULL;
48004 + ino_t saved_ino = 0;
48005 + dev_t saved_dev = 0;
48006
48007 error = user_path_parent(dfd, pathname, &nd, &name);
48008 if (error)
48009 @@ -3381,10 +3563,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48010 if (!inode)
48011 goto slashes;
48012 ihold(inode);
48013 +
48014 + if (inode->i_nlink <= 1) {
48015 + saved_ino = inode->i_ino;
48016 + saved_dev = gr_get_dev_from_dentry(dentry);
48017 + }
48018 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48019 + error = -EACCES;
48020 + goto exit2;
48021 + }
48022 +
48023 error = security_path_unlink(&nd.path, dentry);
48024 if (error)
48025 goto exit2;
48026 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48027 + if (!error && (saved_ino || saved_dev))
48028 + gr_handle_delete(saved_ino, saved_dev);
48029 exit2:
48030 dput(dentry);
48031 }
48032 @@ -3456,9 +3650,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48033 if (IS_ERR(dentry))
48034 goto out_putname;
48035
48036 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48037 + error = -EACCES;
48038 + goto out;
48039 + }
48040 +
48041 error = security_path_symlink(&path, dentry, from);
48042 if (!error)
48043 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48044 + if (!error)
48045 + gr_handle_create(dentry, path.mnt);
48046 +out:
48047 done_path_create(&path, dentry);
48048 out_putname:
48049 putname(from);
48050 @@ -3528,6 +3730,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48051 {
48052 struct dentry *new_dentry;
48053 struct path old_path, new_path;
48054 + char *to = NULL;
48055 int how = 0;
48056 int error;
48057
48058 @@ -3551,7 +3754,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48059 if (error)
48060 return error;
48061
48062 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48063 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48064 error = PTR_ERR(new_dentry);
48065 if (IS_ERR(new_dentry))
48066 goto out;
48067 @@ -3562,11 +3765,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48068 error = may_linkat(&old_path);
48069 if (unlikely(error))
48070 goto out_dput;
48071 +
48072 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48073 + old_path.dentry->d_inode,
48074 + old_path.dentry->d_inode->i_mode, to)) {
48075 + error = -EACCES;
48076 + goto out_dput;
48077 + }
48078 +
48079 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48080 + old_path.dentry, old_path.mnt, to)) {
48081 + error = -EACCES;
48082 + goto out_dput;
48083 + }
48084 +
48085 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48086 if (error)
48087 goto out_dput;
48088 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48089 + if (!error)
48090 + gr_handle_create(new_dentry, new_path.mnt);
48091 out_dput:
48092 + putname(to);
48093 done_path_create(&new_path, new_dentry);
48094 out:
48095 path_put(&old_path);
48096 @@ -3802,12 +4022,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48097 if (new_dentry == trap)
48098 goto exit5;
48099
48100 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48101 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48102 + to);
48103 + if (error)
48104 + goto exit5;
48105 +
48106 error = security_path_rename(&oldnd.path, old_dentry,
48107 &newnd.path, new_dentry);
48108 if (error)
48109 goto exit5;
48110 error = vfs_rename(old_dir->d_inode, old_dentry,
48111 new_dir->d_inode, new_dentry);
48112 + if (!error)
48113 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48114 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48115 exit5:
48116 dput(new_dentry);
48117 exit4:
48118 @@ -3832,6 +4061,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48119
48120 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48121 {
48122 + char tmpbuf[64];
48123 + const char *newlink;
48124 int len;
48125
48126 len = PTR_ERR(link);
48127 @@ -3841,7 +4072,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48128 len = strlen(link);
48129 if (len > (unsigned) buflen)
48130 len = buflen;
48131 - if (copy_to_user(buffer, link, len))
48132 +
48133 + if (len < sizeof(tmpbuf)) {
48134 + memcpy(tmpbuf, link, len);
48135 + newlink = tmpbuf;
48136 + } else
48137 + newlink = link;
48138 +
48139 + if (copy_to_user(buffer, newlink, len))
48140 len = -EFAULT;
48141 out:
48142 return len;
48143 diff --git a/fs/namespace.c b/fs/namespace.c
48144 index 7bdf790..eb79c4b 100644
48145 --- a/fs/namespace.c
48146 +++ b/fs/namespace.c
48147 @@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
48148 if (!(sb->s_flags & MS_RDONLY))
48149 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48150 up_write(&sb->s_umount);
48151 +
48152 + gr_log_remount(mnt->mnt_devname, retval);
48153 +
48154 return retval;
48155 }
48156
48157 @@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
48158 br_write_unlock(&vfsmount_lock);
48159 up_write(&namespace_sem);
48160 release_mounts(&umount_list);
48161 +
48162 + gr_log_unmount(mnt->mnt_devname, retval);
48163 +
48164 return retval;
48165 }
48166
48167 @@ -2244,6 +2250,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48168 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48169 MS_STRICTATIME);
48170
48171 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48172 + retval = -EPERM;
48173 + goto dput_out;
48174 + }
48175 +
48176 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48177 + retval = -EPERM;
48178 + goto dput_out;
48179 + }
48180 +
48181 if (flags & MS_REMOUNT)
48182 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48183 data_page);
48184 @@ -2258,6 +2274,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48185 dev_name, data_page);
48186 dput_out:
48187 path_put(&path);
48188 +
48189 + gr_log_mount(dev_name, dir_name, retval);
48190 +
48191 return retval;
48192 }
48193
48194 @@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48195 if (error)
48196 goto out2;
48197
48198 + if (gr_handle_chroot_pivot()) {
48199 + error = -EPERM;
48200 + goto out2;
48201 + }
48202 +
48203 get_fs_root(current->fs, &root);
48204 error = lock_mount(&old);
48205 if (error)
48206 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48207 index 9b47610..066975e 100644
48208 --- a/fs/nfs/inode.c
48209 +++ b/fs/nfs/inode.c
48210 @@ -1026,16 +1026,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48211 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48212 }
48213
48214 -static atomic_long_t nfs_attr_generation_counter;
48215 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48216
48217 static unsigned long nfs_read_attr_generation_counter(void)
48218 {
48219 - return atomic_long_read(&nfs_attr_generation_counter);
48220 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48221 }
48222
48223 unsigned long nfs_inc_attr_generation_counter(void)
48224 {
48225 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48226 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48227 }
48228
48229 void nfs_fattr_init(struct nfs_fattr *fattr)
48230 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48231 index a9269f1..5490437 100644
48232 --- a/fs/nfsd/vfs.c
48233 +++ b/fs/nfsd/vfs.c
48234 @@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48235 } else {
48236 oldfs = get_fs();
48237 set_fs(KERNEL_DS);
48238 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48239 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48240 set_fs(oldfs);
48241 }
48242
48243 @@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48244
48245 /* Write the data. */
48246 oldfs = get_fs(); set_fs(KERNEL_DS);
48247 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48248 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48249 set_fs(oldfs);
48250 if (host_err < 0)
48251 goto out_nfserr;
48252 @@ -1581,7 +1581,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48253 */
48254
48255 oldfs = get_fs(); set_fs(KERNEL_DS);
48256 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48257 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48258 set_fs(oldfs);
48259
48260 if (host_err < 0)
48261 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48262 index d438036..0ecadde 100644
48263 --- a/fs/notify/fanotify/fanotify_user.c
48264 +++ b/fs/notify/fanotify/fanotify_user.c
48265 @@ -274,7 +274,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48266 goto out_close_fd;
48267
48268 ret = -EFAULT;
48269 - if (copy_to_user(buf, &fanotify_event_metadata,
48270 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48271 + copy_to_user(buf, &fanotify_event_metadata,
48272 fanotify_event_metadata.event_len))
48273 goto out_kill_access_response;
48274
48275 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48276 index c887b13..0fdf472 100644
48277 --- a/fs/notify/notification.c
48278 +++ b/fs/notify/notification.c
48279 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48280 * get set to 0 so it will never get 'freed'
48281 */
48282 static struct fsnotify_event *q_overflow_event;
48283 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48284 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48285
48286 /**
48287 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48288 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48289 */
48290 u32 fsnotify_get_cookie(void)
48291 {
48292 - return atomic_inc_return(&fsnotify_sync_cookie);
48293 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48294 }
48295 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48296
48297 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48298 index 99e3610..02c1068 100644
48299 --- a/fs/ntfs/dir.c
48300 +++ b/fs/ntfs/dir.c
48301 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48302 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48303 ~(s64)(ndir->itype.index.block_size - 1)));
48304 /* Bounds checks. */
48305 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48306 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48307 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48308 "inode 0x%lx or driver bug.", vdir->i_ino);
48309 goto err_out;
48310 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48311 index 1ecf464..e1ff8bf 100644
48312 --- a/fs/ntfs/file.c
48313 +++ b/fs/ntfs/file.c
48314 @@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48315 #endif /* NTFS_RW */
48316 };
48317
48318 -const struct file_operations ntfs_empty_file_ops = {};
48319 +const struct file_operations ntfs_empty_file_ops __read_only;
48320
48321 -const struct inode_operations ntfs_empty_inode_ops = {};
48322 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48323 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48324 index a9f78c7..ed8a381 100644
48325 --- a/fs/ocfs2/localalloc.c
48326 +++ b/fs/ocfs2/localalloc.c
48327 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48328 goto bail;
48329 }
48330
48331 - atomic_inc(&osb->alloc_stats.moves);
48332 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48333
48334 bail:
48335 if (handle)
48336 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48337 index d355e6e..578d905 100644
48338 --- a/fs/ocfs2/ocfs2.h
48339 +++ b/fs/ocfs2/ocfs2.h
48340 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48341
48342 struct ocfs2_alloc_stats
48343 {
48344 - atomic_t moves;
48345 - atomic_t local_data;
48346 - atomic_t bitmap_data;
48347 - atomic_t bg_allocs;
48348 - atomic_t bg_extends;
48349 + atomic_unchecked_t moves;
48350 + atomic_unchecked_t local_data;
48351 + atomic_unchecked_t bitmap_data;
48352 + atomic_unchecked_t bg_allocs;
48353 + atomic_unchecked_t bg_extends;
48354 };
48355
48356 enum ocfs2_local_alloc_state
48357 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48358 index f169da4..9112253 100644
48359 --- a/fs/ocfs2/suballoc.c
48360 +++ b/fs/ocfs2/suballoc.c
48361 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48362 mlog_errno(status);
48363 goto bail;
48364 }
48365 - atomic_inc(&osb->alloc_stats.bg_extends);
48366 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48367
48368 /* You should never ask for this much metadata */
48369 BUG_ON(bits_wanted >
48370 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48371 mlog_errno(status);
48372 goto bail;
48373 }
48374 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48375 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48376
48377 *suballoc_loc = res.sr_bg_blkno;
48378 *suballoc_bit_start = res.sr_bit_offset;
48379 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48380 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48381 res->sr_bits);
48382
48383 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48384 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48385
48386 BUG_ON(res->sr_bits != 1);
48387
48388 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48389 mlog_errno(status);
48390 goto bail;
48391 }
48392 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48393 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48394
48395 BUG_ON(res.sr_bits != 1);
48396
48397 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48398 cluster_start,
48399 num_clusters);
48400 if (!status)
48401 - atomic_inc(&osb->alloc_stats.local_data);
48402 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48403 } else {
48404 if (min_clusters > (osb->bitmap_cpg - 1)) {
48405 /* The only paths asking for contiguousness
48406 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48407 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48408 res.sr_bg_blkno,
48409 res.sr_bit_offset);
48410 - atomic_inc(&osb->alloc_stats.bitmap_data);
48411 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48412 *num_clusters = res.sr_bits;
48413 }
48414 }
48415 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48416 index 68f4541..89cfe6a 100644
48417 --- a/fs/ocfs2/super.c
48418 +++ b/fs/ocfs2/super.c
48419 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48420 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48421 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48422 "Stats",
48423 - atomic_read(&osb->alloc_stats.bitmap_data),
48424 - atomic_read(&osb->alloc_stats.local_data),
48425 - atomic_read(&osb->alloc_stats.bg_allocs),
48426 - atomic_read(&osb->alloc_stats.moves),
48427 - atomic_read(&osb->alloc_stats.bg_extends));
48428 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48429 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48430 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48431 + atomic_read_unchecked(&osb->alloc_stats.moves),
48432 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48433
48434 out += snprintf(buf + out, len - out,
48435 "%10s => State: %u Descriptor: %llu Size: %u bits "
48436 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48437 spin_lock_init(&osb->osb_xattr_lock);
48438 ocfs2_init_steal_slots(osb);
48439
48440 - atomic_set(&osb->alloc_stats.moves, 0);
48441 - atomic_set(&osb->alloc_stats.local_data, 0);
48442 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48443 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48444 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48445 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48446 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48447 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48448 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48449 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48450
48451 /* Copy the blockcheck stats from the superblock probe */
48452 osb->osb_ecc_stats = *stats;
48453 diff --git a/fs/open.c b/fs/open.c
48454 index e1f2cdb..3bd5f39 100644
48455 --- a/fs/open.c
48456 +++ b/fs/open.c
48457 @@ -31,6 +31,8 @@
48458 #include <linux/ima.h>
48459 #include <linux/dnotify.h>
48460
48461 +#define CREATE_TRACE_POINTS
48462 +#include <trace/events/fs.h>
48463 #include "internal.h"
48464
48465 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48466 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48467 error = locks_verify_truncate(inode, NULL, length);
48468 if (!error)
48469 error = security_path_truncate(&path);
48470 +
48471 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48472 + error = -EACCES;
48473 +
48474 if (!error)
48475 error = do_truncate(path.dentry, length, 0, NULL);
48476
48477 @@ -364,6 +370,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48478 if (__mnt_is_readonly(path.mnt))
48479 res = -EROFS;
48480
48481 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48482 + res = -EACCES;
48483 +
48484 out_path_release:
48485 path_put(&path);
48486 out:
48487 @@ -390,6 +399,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48488 if (error)
48489 goto dput_and_out;
48490
48491 + gr_log_chdir(path.dentry, path.mnt);
48492 +
48493 set_fs_pwd(current->fs, &path);
48494
48495 dput_and_out:
48496 @@ -416,6 +427,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48497 goto out_putf;
48498
48499 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48500 +
48501 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48502 + error = -EPERM;
48503 +
48504 + if (!error)
48505 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48506 +
48507 if (!error)
48508 set_fs_pwd(current->fs, &file->f_path);
48509 out_putf:
48510 @@ -444,7 +462,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48511 if (error)
48512 goto dput_and_out;
48513
48514 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48515 + goto dput_and_out;
48516 +
48517 set_fs_root(current->fs, &path);
48518 +
48519 + gr_handle_chroot_chdir(&path);
48520 +
48521 error = 0;
48522 dput_and_out:
48523 path_put(&path);
48524 @@ -462,6 +486,16 @@ static int chmod_common(struct path *path, umode_t mode)
48525 if (error)
48526 return error;
48527 mutex_lock(&inode->i_mutex);
48528 +
48529 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48530 + error = -EACCES;
48531 + goto out_unlock;
48532 + }
48533 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48534 + error = -EACCES;
48535 + goto out_unlock;
48536 + }
48537 +
48538 error = security_path_chmod(path, mode);
48539 if (error)
48540 goto out_unlock;
48541 @@ -517,6 +551,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48542 uid = make_kuid(current_user_ns(), user);
48543 gid = make_kgid(current_user_ns(), group);
48544
48545 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48546 + return -EACCES;
48547 +
48548 newattrs.ia_valid = ATTR_CTIME;
48549 if (user != (uid_t) -1) {
48550 if (!uid_valid(uid))
48551 @@ -958,6 +995,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48552 } else {
48553 fsnotify_open(f);
48554 fd_install(fd, f);
48555 + trace_do_sys_open(tmp, flags, mode);
48556 }
48557 }
48558 putname(tmp);
48559 diff --git a/fs/pipe.c b/fs/pipe.c
48560 index 8d85d70..581036b 100644
48561 --- a/fs/pipe.c
48562 +++ b/fs/pipe.c
48563 @@ -438,9 +438,9 @@ redo:
48564 }
48565 if (bufs) /* More to do? */
48566 continue;
48567 - if (!pipe->writers)
48568 + if (!atomic_read(&pipe->writers))
48569 break;
48570 - if (!pipe->waiting_writers) {
48571 + if (!atomic_read(&pipe->waiting_writers)) {
48572 /* syscall merging: Usually we must not sleep
48573 * if O_NONBLOCK is set, or if we got some data.
48574 * But if a writer sleeps in kernel space, then
48575 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48576 mutex_lock(&inode->i_mutex);
48577 pipe = inode->i_pipe;
48578
48579 - if (!pipe->readers) {
48580 + if (!atomic_read(&pipe->readers)) {
48581 send_sig(SIGPIPE, current, 0);
48582 ret = -EPIPE;
48583 goto out;
48584 @@ -553,7 +553,7 @@ redo1:
48585 for (;;) {
48586 int bufs;
48587
48588 - if (!pipe->readers) {
48589 + if (!atomic_read(&pipe->readers)) {
48590 send_sig(SIGPIPE, current, 0);
48591 if (!ret)
48592 ret = -EPIPE;
48593 @@ -644,9 +644,9 @@ redo2:
48594 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48595 do_wakeup = 0;
48596 }
48597 - pipe->waiting_writers++;
48598 + atomic_inc(&pipe->waiting_writers);
48599 pipe_wait(pipe);
48600 - pipe->waiting_writers--;
48601 + atomic_dec(&pipe->waiting_writers);
48602 }
48603 out:
48604 mutex_unlock(&inode->i_mutex);
48605 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48606 mask = 0;
48607 if (filp->f_mode & FMODE_READ) {
48608 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48609 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48610 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48611 mask |= POLLHUP;
48612 }
48613
48614 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48615 * Most Unices do not set POLLERR for FIFOs but on Linux they
48616 * behave exactly like pipes for poll().
48617 */
48618 - if (!pipe->readers)
48619 + if (!atomic_read(&pipe->readers))
48620 mask |= POLLERR;
48621 }
48622
48623 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48624
48625 mutex_lock(&inode->i_mutex);
48626 pipe = inode->i_pipe;
48627 - pipe->readers -= decr;
48628 - pipe->writers -= decw;
48629 + atomic_sub(decr, &pipe->readers);
48630 + atomic_sub(decw, &pipe->writers);
48631
48632 - if (!pipe->readers && !pipe->writers) {
48633 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48634 free_pipe_info(inode);
48635 } else {
48636 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48637 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48638
48639 if (inode->i_pipe) {
48640 ret = 0;
48641 - inode->i_pipe->readers++;
48642 + atomic_inc(&inode->i_pipe->readers);
48643 }
48644
48645 mutex_unlock(&inode->i_mutex);
48646 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48647
48648 if (inode->i_pipe) {
48649 ret = 0;
48650 - inode->i_pipe->writers++;
48651 + atomic_inc(&inode->i_pipe->writers);
48652 }
48653
48654 mutex_unlock(&inode->i_mutex);
48655 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48656 if (inode->i_pipe) {
48657 ret = 0;
48658 if (filp->f_mode & FMODE_READ)
48659 - inode->i_pipe->readers++;
48660 + atomic_inc(&inode->i_pipe->readers);
48661 if (filp->f_mode & FMODE_WRITE)
48662 - inode->i_pipe->writers++;
48663 + atomic_inc(&inode->i_pipe->writers);
48664 }
48665
48666 mutex_unlock(&inode->i_mutex);
48667 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48668 inode->i_pipe = NULL;
48669 }
48670
48671 -static struct vfsmount *pipe_mnt __read_mostly;
48672 +struct vfsmount *pipe_mnt __read_mostly;
48673
48674 /*
48675 * pipefs_dname() is called from d_path().
48676 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48677 goto fail_iput;
48678 inode->i_pipe = pipe;
48679
48680 - pipe->readers = pipe->writers = 1;
48681 + atomic_set(&pipe->readers, 1);
48682 + atomic_set(&pipe->writers, 1);
48683 inode->i_fop = &rdwr_pipefifo_fops;
48684
48685 /*
48686 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48687 index 15af622..0e9f4467 100644
48688 --- a/fs/proc/Kconfig
48689 +++ b/fs/proc/Kconfig
48690 @@ -30,12 +30,12 @@ config PROC_FS
48691
48692 config PROC_KCORE
48693 bool "/proc/kcore support" if !ARM
48694 - depends on PROC_FS && MMU
48695 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48696
48697 config PROC_VMCORE
48698 bool "/proc/vmcore support"
48699 - depends on PROC_FS && CRASH_DUMP
48700 - default y
48701 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48702 + default n
48703 help
48704 Exports the dump image of crashed kernel in ELF format.
48705
48706 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48707 limited in memory.
48708
48709 config PROC_PAGE_MONITOR
48710 - default y
48711 - depends on PROC_FS && MMU
48712 + default n
48713 + depends on PROC_FS && MMU && !GRKERNSEC
48714 bool "Enable /proc page monitoring" if EXPERT
48715 help
48716 Various /proc files exist to monitor process memory utilization:
48717 diff --git a/fs/proc/array.c b/fs/proc/array.c
48718 index c1c207c..01ce725 100644
48719 --- a/fs/proc/array.c
48720 +++ b/fs/proc/array.c
48721 @@ -60,6 +60,7 @@
48722 #include <linux/tty.h>
48723 #include <linux/string.h>
48724 #include <linux/mman.h>
48725 +#include <linux/grsecurity.h>
48726 #include <linux/proc_fs.h>
48727 #include <linux/ioport.h>
48728 #include <linux/uaccess.h>
48729 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48730 seq_putc(m, '\n');
48731 }
48732
48733 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48734 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48735 +{
48736 + if (p->mm)
48737 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48738 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48739 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48740 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48741 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48742 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48743 + else
48744 + seq_printf(m, "PaX:\t-----\n");
48745 +}
48746 +#endif
48747 +
48748 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48749 struct pid *pid, struct task_struct *task)
48750 {
48751 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48752 task_cpus_allowed(m, task);
48753 cpuset_task_status_allowed(m, task);
48754 task_context_switch_counts(m, task);
48755 +
48756 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48757 + task_pax(m, task);
48758 +#endif
48759 +
48760 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48761 + task_grsec_rbac(m, task);
48762 +#endif
48763 +
48764 return 0;
48765 }
48766
48767 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48768 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48769 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48770 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48771 +#endif
48772 +
48773 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48774 struct pid *pid, struct task_struct *task, int whole)
48775 {
48776 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48777 char tcomm[sizeof(task->comm)];
48778 unsigned long flags;
48779
48780 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48781 + if (current->exec_id != m->exec_id) {
48782 + gr_log_badprocpid("stat");
48783 + return 0;
48784 + }
48785 +#endif
48786 +
48787 state = *get_task_state(task);
48788 vsize = eip = esp = 0;
48789 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48790 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48791 gtime = task->gtime;
48792 }
48793
48794 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48795 + if (PAX_RAND_FLAGS(mm)) {
48796 + eip = 0;
48797 + esp = 0;
48798 + wchan = 0;
48799 + }
48800 +#endif
48801 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48802 + wchan = 0;
48803 + eip =0;
48804 + esp =0;
48805 +#endif
48806 +
48807 /* scale priority and nice values from timeslices to -20..20 */
48808 /* to make it look like a "normal" Unix priority/nice value */
48809 priority = task_prio(task);
48810 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48811 seq_put_decimal_ull(m, ' ', vsize);
48812 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48813 seq_put_decimal_ull(m, ' ', rsslim);
48814 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48815 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48816 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48817 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48818 +#else
48819 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48820 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48821 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48822 +#endif
48823 seq_put_decimal_ull(m, ' ', esp);
48824 seq_put_decimal_ull(m, ' ', eip);
48825 /* The signal information here is obsolete.
48826 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48827 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48828 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48829
48830 - if (mm && permitted) {
48831 + if (mm && permitted
48832 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48833 + && !PAX_RAND_FLAGS(mm)
48834 +#endif
48835 + ) {
48836 seq_put_decimal_ull(m, ' ', mm->start_data);
48837 seq_put_decimal_ull(m, ' ', mm->end_data);
48838 seq_put_decimal_ull(m, ' ', mm->start_brk);
48839 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48840 struct pid *pid, struct task_struct *task)
48841 {
48842 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48843 - struct mm_struct *mm = get_task_mm(task);
48844 + struct mm_struct *mm;
48845
48846 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48847 + if (current->exec_id != m->exec_id) {
48848 + gr_log_badprocpid("statm");
48849 + return 0;
48850 + }
48851 +#endif
48852 + mm = get_task_mm(task);
48853 if (mm) {
48854 size = task_statm(mm, &shared, &text, &data, &resident);
48855 mmput(mm);
48856 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48857 return 0;
48858 }
48859
48860 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48861 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48862 +{
48863 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48864 +}
48865 +#endif
48866 +
48867 #ifdef CONFIG_CHECKPOINT_RESTORE
48868 static struct pid *
48869 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48870 diff --git a/fs/proc/base.c b/fs/proc/base.c
48871 index 1b6c84c..66b738b 100644
48872 --- a/fs/proc/base.c
48873 +++ b/fs/proc/base.c
48874 @@ -110,6 +110,14 @@ struct pid_entry {
48875 union proc_op op;
48876 };
48877
48878 +struct getdents_callback {
48879 + struct linux_dirent __user * current_dir;
48880 + struct linux_dirent __user * previous;
48881 + struct file * file;
48882 + int count;
48883 + int error;
48884 +};
48885 +
48886 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48887 .name = (NAME), \
48888 .len = sizeof(NAME) - 1, \
48889 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48890 if (!mm->arg_end)
48891 goto out_mm; /* Shh! No looking before we're done */
48892
48893 + if (gr_acl_handle_procpidmem(task))
48894 + goto out_mm;
48895 +
48896 len = mm->arg_end - mm->arg_start;
48897
48898 if (len > PAGE_SIZE)
48899 @@ -236,12 +247,28 @@ out:
48900 return res;
48901 }
48902
48903 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48904 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48905 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48906 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48907 +#endif
48908 +
48909 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48910 {
48911 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48912 int res = PTR_ERR(mm);
48913 if (mm && !IS_ERR(mm)) {
48914 unsigned int nwords = 0;
48915 +
48916 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48917 + /* allow if we're currently ptracing this task */
48918 + if (PAX_RAND_FLAGS(mm) &&
48919 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48920 + mmput(mm);
48921 + return 0;
48922 + }
48923 +#endif
48924 +
48925 do {
48926 nwords += 2;
48927 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48928 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48929 }
48930
48931
48932 -#ifdef CONFIG_KALLSYMS
48933 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48934 /*
48935 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48936 * Returns the resolved symbol. If that fails, simply return the address.
48937 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
48938 mutex_unlock(&task->signal->cred_guard_mutex);
48939 }
48940
48941 -#ifdef CONFIG_STACKTRACE
48942 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48943
48944 #define MAX_STACK_TRACE_DEPTH 64
48945
48946 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
48947 return count;
48948 }
48949
48950 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
48951 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48952 static int proc_pid_syscall(struct task_struct *task, char *buffer)
48953 {
48954 long nr;
48955 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
48956 /************************************************************************/
48957
48958 /* permission checks */
48959 -static int proc_fd_access_allowed(struct inode *inode)
48960 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
48961 {
48962 struct task_struct *task;
48963 int allowed = 0;
48964 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
48965 */
48966 task = get_proc_task(inode);
48967 if (task) {
48968 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48969 + if (log)
48970 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
48971 + else
48972 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48973 put_task_struct(task);
48974 }
48975 return allowed;
48976 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
48977 struct task_struct *task,
48978 int hide_pid_min)
48979 {
48980 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
48981 + return false;
48982 +
48983 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
48984 + rcu_read_lock();
48985 + {
48986 + const struct cred *tmpcred = current_cred();
48987 + const struct cred *cred = __task_cred(task);
48988 +
48989 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
48990 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
48991 + || in_group_p(grsec_proc_gid)
48992 +#endif
48993 + ) {
48994 + rcu_read_unlock();
48995 + return true;
48996 + }
48997 + }
48998 + rcu_read_unlock();
48999 +
49000 + if (!pid->hide_pid)
49001 + return false;
49002 +#endif
49003 +
49004 if (pid->hide_pid < hide_pid_min)
49005 return true;
49006 if (in_group_p(pid->pid_gid))
49007 return true;
49008 +
49009 return ptrace_may_access(task, PTRACE_MODE_READ);
49010 }
49011
49012 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49013 put_task_struct(task);
49014
49015 if (!has_perms) {
49016 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49017 + {
49018 +#else
49019 if (pid->hide_pid == 2) {
49020 +#endif
49021 /*
49022 * Let's make getdents(), stat(), and open()
49023 * consistent with each other. If a process
49024 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49025 if (!task)
49026 return -ESRCH;
49027
49028 + if (gr_acl_handle_procpidmem(task)) {
49029 + put_task_struct(task);
49030 + return -EPERM;
49031 + }
49032 +
49033 mm = mm_access(task, mode);
49034 put_task_struct(task);
49035
49036 @@ -697,6 +761,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49037
49038 file->private_data = mm;
49039
49040 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49041 + file->f_version = current->exec_id;
49042 +#endif
49043 +
49044 return 0;
49045 }
49046
49047 @@ -718,6 +786,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49048 ssize_t copied;
49049 char *page;
49050
49051 +#ifdef CONFIG_GRKERNSEC
49052 + if (write)
49053 + return -EPERM;
49054 +#endif
49055 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49056 + if (file->f_version != current->exec_id) {
49057 + gr_log_badprocpid("mem");
49058 + return 0;
49059 + }
49060 +#endif
49061 +
49062 if (!mm)
49063 return 0;
49064
49065 @@ -822,6 +901,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49066 if (!mm)
49067 return 0;
49068
49069 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49070 + if (file->f_version != current->exec_id) {
49071 + gr_log_badprocpid("environ");
49072 + return 0;
49073 + }
49074 +#endif
49075 +
49076 page = (char *)__get_free_page(GFP_TEMPORARY);
49077 if (!page)
49078 return -ENOMEM;
49079 @@ -1435,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49080 int error = -EACCES;
49081
49082 /* Are we allowed to snoop on the tasks file descriptors? */
49083 - if (!proc_fd_access_allowed(inode))
49084 + if (!proc_fd_access_allowed(inode, 0))
49085 goto out;
49086
49087 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49088 @@ -1479,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49089 struct path path;
49090
49091 /* Are we allowed to snoop on the tasks file descriptors? */
49092 - if (!proc_fd_access_allowed(inode))
49093 - goto out;
49094 + /* logging this is needed for learning on chromium to work properly,
49095 + but we don't want to flood the logs from 'ps' which does a readlink
49096 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49097 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49098 + */
49099 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49100 + if (!proc_fd_access_allowed(inode,0))
49101 + goto out;
49102 + } else {
49103 + if (!proc_fd_access_allowed(inode,1))
49104 + goto out;
49105 + }
49106
49107 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49108 if (error)
49109 @@ -1545,7 +1641,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49110 rcu_read_lock();
49111 cred = __task_cred(task);
49112 inode->i_uid = cred->euid;
49113 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49114 + inode->i_gid = grsec_proc_gid;
49115 +#else
49116 inode->i_gid = cred->egid;
49117 +#endif
49118 rcu_read_unlock();
49119 }
49120 security_task_to_inode(task, inode);
49121 @@ -1581,10 +1681,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49122 return -ENOENT;
49123 }
49124 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49125 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49126 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49127 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49128 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49129 +#endif
49130 task_dumpable(task)) {
49131 cred = __task_cred(task);
49132 stat->uid = cred->euid;
49133 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49134 + stat->gid = grsec_proc_gid;
49135 +#else
49136 stat->gid = cred->egid;
49137 +#endif
49138 }
49139 }
49140 rcu_read_unlock();
49141 @@ -1622,11 +1731,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
49142
49143 if (task) {
49144 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49145 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49146 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49147 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49148 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49149 +#endif
49150 task_dumpable(task)) {
49151 rcu_read_lock();
49152 cred = __task_cred(task);
49153 inode->i_uid = cred->euid;
49154 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49155 + inode->i_gid = grsec_proc_gid;
49156 +#else
49157 inode->i_gid = cred->egid;
49158 +#endif
49159 rcu_read_unlock();
49160 } else {
49161 inode->i_uid = GLOBAL_ROOT_UID;
49162 @@ -1744,7 +1862,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49163 int fd = proc_fd(inode);
49164
49165 if (task) {
49166 - files = get_files_struct(task);
49167 + if (!gr_acl_handle_procpidmem(task))
49168 + files = get_files_struct(task);
49169 put_task_struct(task);
49170 }
49171 if (files) {
49172 @@ -2343,11 +2462,21 @@ static const struct file_operations proc_map_files_operations = {
49173 */
49174 static int proc_fd_permission(struct inode *inode, int mask)
49175 {
49176 + struct task_struct *task;
49177 int rv = generic_permission(inode, mask);
49178 - if (rv == 0)
49179 - return 0;
49180 +
49181 if (task_pid(current) == proc_pid(inode))
49182 rv = 0;
49183 +
49184 + task = get_proc_task(inode);
49185 + if (task == NULL)
49186 + return rv;
49187 +
49188 + if (gr_acl_handle_procpidmem(task))
49189 + rv = -EACCES;
49190 +
49191 + put_task_struct(task);
49192 +
49193 return rv;
49194 }
49195
49196 @@ -2457,6 +2586,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49197 if (!task)
49198 goto out_no_task;
49199
49200 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49201 + goto out;
49202 +
49203 /*
49204 * Yes, it does not scale. And it should not. Don't add
49205 * new entries into /proc/<tgid>/ without very good reasons.
49206 @@ -2501,6 +2633,9 @@ static int proc_pident_readdir(struct file *filp,
49207 if (!task)
49208 goto out_no_task;
49209
49210 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49211 + goto out;
49212 +
49213 ret = 0;
49214 i = filp->f_pos;
49215 switch (i) {
49216 @@ -2771,7 +2906,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49217 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49218 void *cookie)
49219 {
49220 - char *s = nd_get_link(nd);
49221 + const char *s = nd_get_link(nd);
49222 if (!IS_ERR(s))
49223 __putname(s);
49224 }
49225 @@ -3040,7 +3175,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49226 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49227 #endif
49228 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49229 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49230 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49231 INF("syscall", S_IRUGO, proc_pid_syscall),
49232 #endif
49233 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49234 @@ -3065,10 +3200,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49235 #ifdef CONFIG_SECURITY
49236 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49237 #endif
49238 -#ifdef CONFIG_KALLSYMS
49239 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49240 INF("wchan", S_IRUGO, proc_pid_wchan),
49241 #endif
49242 -#ifdef CONFIG_STACKTRACE
49243 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49244 ONE("stack", S_IRUGO, proc_pid_stack),
49245 #endif
49246 #ifdef CONFIG_SCHEDSTATS
49247 @@ -3102,6 +3237,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49248 #ifdef CONFIG_HARDWALL
49249 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49250 #endif
49251 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49252 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49253 +#endif
49254 #ifdef CONFIG_USER_NS
49255 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49256 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49257 @@ -3233,7 +3371,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49258 if (!inode)
49259 goto out;
49260
49261 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49262 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49263 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49264 + inode->i_gid = grsec_proc_gid;
49265 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49266 +#else
49267 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49268 +#endif
49269 inode->i_op = &proc_tgid_base_inode_operations;
49270 inode->i_fop = &proc_tgid_base_operations;
49271 inode->i_flags|=S_IMMUTABLE;
49272 @@ -3275,7 +3420,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
49273 if (!task)
49274 goto out;
49275
49276 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49277 + goto out_put_task;
49278 +
49279 result = proc_pid_instantiate(dir, dentry, task, NULL);
49280 +out_put_task:
49281 put_task_struct(task);
49282 out:
49283 return result;
49284 @@ -3338,6 +3487,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49285 static int fake_filldir(void *buf, const char *name, int namelen,
49286 loff_t offset, u64 ino, unsigned d_type)
49287 {
49288 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49289 + __buf->error = -EINVAL;
49290 return 0;
49291 }
49292
49293 @@ -3404,7 +3555,7 @@ static const struct pid_entry tid_base_stuff[] = {
49294 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49295 #endif
49296 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49297 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49298 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49299 INF("syscall", S_IRUGO, proc_pid_syscall),
49300 #endif
49301 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49302 @@ -3431,10 +3582,10 @@ static const struct pid_entry tid_base_stuff[] = {
49303 #ifdef CONFIG_SECURITY
49304 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49305 #endif
49306 -#ifdef CONFIG_KALLSYMS
49307 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49308 INF("wchan", S_IRUGO, proc_pid_wchan),
49309 #endif
49310 -#ifdef CONFIG_STACKTRACE
49311 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49312 ONE("stack", S_IRUGO, proc_pid_stack),
49313 #endif
49314 #ifdef CONFIG_SCHEDSTATS
49315 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49316 index 82676e3..5f8518a 100644
49317 --- a/fs/proc/cmdline.c
49318 +++ b/fs/proc/cmdline.c
49319 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49320
49321 static int __init proc_cmdline_init(void)
49322 {
49323 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49324 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49325 +#else
49326 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49327 +#endif
49328 return 0;
49329 }
49330 module_init(proc_cmdline_init);
49331 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49332 index b143471..bb105e5 100644
49333 --- a/fs/proc/devices.c
49334 +++ b/fs/proc/devices.c
49335 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49336
49337 static int __init proc_devices_init(void)
49338 {
49339 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49340 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49341 +#else
49342 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49343 +#endif
49344 return 0;
49345 }
49346 module_init(proc_devices_init);
49347 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49348 index 7ac817b..c5c9eb0 100644
49349 --- a/fs/proc/inode.c
49350 +++ b/fs/proc/inode.c
49351 @@ -21,11 +21,17 @@
49352 #include <linux/seq_file.h>
49353 #include <linux/slab.h>
49354 #include <linux/mount.h>
49355 +#include <linux/grsecurity.h>
49356
49357 #include <asm/uaccess.h>
49358
49359 #include "internal.h"
49360
49361 +#ifdef CONFIG_PROC_SYSCTL
49362 +extern const struct inode_operations proc_sys_inode_operations;
49363 +extern const struct inode_operations proc_sys_dir_operations;
49364 +#endif
49365 +
49366 static void proc_evict_inode(struct inode *inode)
49367 {
49368 struct proc_dir_entry *de;
49369 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49370 ns_ops = PROC_I(inode)->ns_ops;
49371 if (ns_ops && ns_ops->put)
49372 ns_ops->put(PROC_I(inode)->ns);
49373 +
49374 +#ifdef CONFIG_PROC_SYSCTL
49375 + if (inode->i_op == &proc_sys_inode_operations ||
49376 + inode->i_op == &proc_sys_dir_operations)
49377 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49378 +#endif
49379 +
49380 }
49381
49382 static struct kmem_cache * proc_inode_cachep;
49383 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49384 if (de->mode) {
49385 inode->i_mode = de->mode;
49386 inode->i_uid = de->uid;
49387 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49388 + inode->i_gid = grsec_proc_gid;
49389 +#else
49390 inode->i_gid = de->gid;
49391 +#endif
49392 }
49393 if (de->size)
49394 inode->i_size = de->size;
49395 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49396 index e1167a1..bd24f20 100644
49397 --- a/fs/proc/internal.h
49398 +++ b/fs/proc/internal.h
49399 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49400 struct pid *pid, struct task_struct *task);
49401 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49402 struct pid *pid, struct task_struct *task);
49403 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49404 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49405 +#endif
49406 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49407
49408 extern const struct file_operations proc_tid_children_operations;
49409 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49410 index 86c67ee..cdca321 100644
49411 --- a/fs/proc/kcore.c
49412 +++ b/fs/proc/kcore.c
49413 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49414 * the addresses in the elf_phdr on our list.
49415 */
49416 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49417 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49418 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49419 + if (tsz > buflen)
49420 tsz = buflen;
49421 -
49422 +
49423 while (buflen) {
49424 struct kcore_list *m;
49425
49426 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49427 kfree(elf_buf);
49428 } else {
49429 if (kern_addr_valid(start)) {
49430 - unsigned long n;
49431 + char *elf_buf;
49432 + mm_segment_t oldfs;
49433
49434 - n = copy_to_user(buffer, (char *)start, tsz);
49435 - /*
49436 - * We cannot distinguish between fault on source
49437 - * and fault on destination. When this happens
49438 - * we clear too and hope it will trigger the
49439 - * EFAULT again.
49440 - */
49441 - if (n) {
49442 - if (clear_user(buffer + tsz - n,
49443 - n))
49444 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49445 + if (!elf_buf)
49446 + return -ENOMEM;
49447 + oldfs = get_fs();
49448 + set_fs(KERNEL_DS);
49449 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49450 + set_fs(oldfs);
49451 + if (copy_to_user(buffer, elf_buf, tsz)) {
49452 + kfree(elf_buf);
49453 return -EFAULT;
49454 + }
49455 }
49456 + set_fs(oldfs);
49457 + kfree(elf_buf);
49458 } else {
49459 if (clear_user(buffer, tsz))
49460 return -EFAULT;
49461 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49462
49463 static int open_kcore(struct inode *inode, struct file *filp)
49464 {
49465 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49466 + return -EPERM;
49467 +#endif
49468 if (!capable(CAP_SYS_RAWIO))
49469 return -EPERM;
49470 if (kcore_need_update)
49471 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49472 index 80e4645..53e5fcf 100644
49473 --- a/fs/proc/meminfo.c
49474 +++ b/fs/proc/meminfo.c
49475 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49476 vmi.used >> 10,
49477 vmi.largest_chunk >> 10
49478 #ifdef CONFIG_MEMORY_FAILURE
49479 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49480 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49481 #endif
49482 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49483 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49484 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49485 index b1822dd..df622cb 100644
49486 --- a/fs/proc/nommu.c
49487 +++ b/fs/proc/nommu.c
49488 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49489 if (len < 1)
49490 len = 1;
49491 seq_printf(m, "%*c", len, ' ');
49492 - seq_path(m, &file->f_path, "");
49493 + seq_path(m, &file->f_path, "\n\\");
49494 }
49495
49496 seq_putc(m, '\n');
49497 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49498 index fe72cd0..cb9b67d 100644
49499 --- a/fs/proc/proc_net.c
49500 +++ b/fs/proc/proc_net.c
49501 @@ -23,6 +23,7 @@
49502 #include <linux/nsproxy.h>
49503 #include <net/net_namespace.h>
49504 #include <linux/seq_file.h>
49505 +#include <linux/grsecurity.h>
49506
49507 #include "internal.h"
49508
49509 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49510 struct task_struct *task;
49511 struct nsproxy *ns;
49512 struct net *net = NULL;
49513 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49514 + const struct cred *cred = current_cred();
49515 +#endif
49516 +
49517 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49518 + if (cred->fsuid)
49519 + return net;
49520 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49521 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49522 + return net;
49523 +#endif
49524
49525 rcu_read_lock();
49526 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49527 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49528 index eb7cc91..7327a46 100644
49529 --- a/fs/proc/proc_sysctl.c
49530 +++ b/fs/proc/proc_sysctl.c
49531 @@ -12,11 +12,15 @@
49532 #include <linux/module.h>
49533 #include "internal.h"
49534
49535 +extern int gr_handle_chroot_sysctl(const int op);
49536 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49537 + const int op);
49538 +
49539 static const struct dentry_operations proc_sys_dentry_operations;
49540 static const struct file_operations proc_sys_file_operations;
49541 -static const struct inode_operations proc_sys_inode_operations;
49542 +const struct inode_operations proc_sys_inode_operations;
49543 static const struct file_operations proc_sys_dir_file_operations;
49544 -static const struct inode_operations proc_sys_dir_operations;
49545 +const struct inode_operations proc_sys_dir_operations;
49546
49547 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49548 {
49549 @@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49550
49551 err = NULL;
49552 d_set_d_op(dentry, &proc_sys_dentry_operations);
49553 +
49554 + gr_handle_proc_create(dentry, inode);
49555 +
49556 d_add(dentry, inode);
49557
49558 out:
49559 @@ -482,18 +489,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49560 struct inode *inode = filp->f_path.dentry->d_inode;
49561 struct ctl_table_header *head = grab_header(inode);
49562 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49563 + int op = write ? MAY_WRITE : MAY_READ;
49564 ssize_t error;
49565 size_t res;
49566
49567 if (IS_ERR(head))
49568 return PTR_ERR(head);
49569
49570 +
49571 /*
49572 * At this point we know that the sysctl was not unregistered
49573 * and won't be until we finish.
49574 */
49575 error = -EPERM;
49576 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49577 + if (sysctl_perm(head->root, table, op))
49578 goto out;
49579
49580 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49581 @@ -501,6 +510,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49582 if (!table->proc_handler)
49583 goto out;
49584
49585 +#ifdef CONFIG_GRKERNSEC
49586 + error = -EPERM;
49587 + if (gr_handle_chroot_sysctl(op))
49588 + goto out;
49589 + dget(filp->f_path.dentry);
49590 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49591 + dput(filp->f_path.dentry);
49592 + goto out;
49593 + }
49594 + dput(filp->f_path.dentry);
49595 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49596 + goto out;
49597 + if (write && !capable(CAP_SYS_ADMIN))
49598 + goto out;
49599 +#endif
49600 +
49601 /* careful: calling conventions are nasty here */
49602 res = count;
49603 error = table->proc_handler(table, write, buf, &res, ppos);
49604 @@ -598,6 +623,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49605 return -ENOMEM;
49606 } else {
49607 d_set_d_op(child, &proc_sys_dentry_operations);
49608 +
49609 + gr_handle_proc_create(child, inode);
49610 +
49611 d_add(child, inode);
49612 }
49613 } else {
49614 @@ -641,6 +669,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49615 if ((*pos)++ < file->f_pos)
49616 return 0;
49617
49618 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49619 + return 0;
49620 +
49621 if (unlikely(S_ISLNK(table->mode)))
49622 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49623 else
49624 @@ -758,6 +789,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49625 if (IS_ERR(head))
49626 return PTR_ERR(head);
49627
49628 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49629 + return -ENOENT;
49630 +
49631 generic_fillattr(inode, stat);
49632 if (table)
49633 stat->mode = (stat->mode & S_IFMT) | table->mode;
49634 @@ -780,13 +814,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49635 .llseek = generic_file_llseek,
49636 };
49637
49638 -static const struct inode_operations proc_sys_inode_operations = {
49639 +const struct inode_operations proc_sys_inode_operations = {
49640 .permission = proc_sys_permission,
49641 .setattr = proc_sys_setattr,
49642 .getattr = proc_sys_getattr,
49643 };
49644
49645 -static const struct inode_operations proc_sys_dir_operations = {
49646 +const struct inode_operations proc_sys_dir_operations = {
49647 .lookup = proc_sys_lookup,
49648 .permission = proc_sys_permission,
49649 .setattr = proc_sys_setattr,
49650 diff --git a/fs/proc/root.c b/fs/proc/root.c
49651 index 9a2d9fd..ddfc92a 100644
49652 --- a/fs/proc/root.c
49653 +++ b/fs/proc/root.c
49654 @@ -187,7 +187,15 @@ void __init proc_root_init(void)
49655 #ifdef CONFIG_PROC_DEVICETREE
49656 proc_device_tree_init();
49657 #endif
49658 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49659 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49660 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49661 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49662 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49663 +#endif
49664 +#else
49665 proc_mkdir("bus", NULL);
49666 +#endif
49667 proc_sys_init();
49668 }
49669
49670 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49671 index 4540b8f..1b9772f 100644
49672 --- a/fs/proc/task_mmu.c
49673 +++ b/fs/proc/task_mmu.c
49674 @@ -11,12 +11,19 @@
49675 #include <linux/rmap.h>
49676 #include <linux/swap.h>
49677 #include <linux/swapops.h>
49678 +#include <linux/grsecurity.h>
49679
49680 #include <asm/elf.h>
49681 #include <asm/uaccess.h>
49682 #include <asm/tlbflush.h>
49683 #include "internal.h"
49684
49685 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49686 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49687 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49688 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49689 +#endif
49690 +
49691 void task_mem(struct seq_file *m, struct mm_struct *mm)
49692 {
49693 unsigned long data, text, lib, swap;
49694 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49695 "VmExe:\t%8lu kB\n"
49696 "VmLib:\t%8lu kB\n"
49697 "VmPTE:\t%8lu kB\n"
49698 - "VmSwap:\t%8lu kB\n",
49699 - hiwater_vm << (PAGE_SHIFT-10),
49700 + "VmSwap:\t%8lu kB\n"
49701 +
49702 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49703 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49704 +#endif
49705 +
49706 + ,hiwater_vm << (PAGE_SHIFT-10),
49707 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49708 mm->locked_vm << (PAGE_SHIFT-10),
49709 mm->pinned_vm << (PAGE_SHIFT-10),
49710 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49711 data << (PAGE_SHIFT-10),
49712 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49713 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49714 - swap << (PAGE_SHIFT-10));
49715 + swap << (PAGE_SHIFT-10)
49716 +
49717 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49718 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49719 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49720 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49721 +#else
49722 + , mm->context.user_cs_base
49723 + , mm->context.user_cs_limit
49724 +#endif
49725 +#endif
49726 +
49727 + );
49728 }
49729
49730 unsigned long task_vsize(struct mm_struct *mm)
49731 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49732 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49733 }
49734
49735 - /* We don't show the stack guard page in /proc/maps */
49736 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49737 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49738 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49739 +#else
49740 start = vma->vm_start;
49741 - if (stack_guard_page_start(vma, start))
49742 - start += PAGE_SIZE;
49743 end = vma->vm_end;
49744 - if (stack_guard_page_end(vma, end))
49745 - end -= PAGE_SIZE;
49746 +#endif
49747
49748 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49749 start,
49750 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49751 flags & VM_WRITE ? 'w' : '-',
49752 flags & VM_EXEC ? 'x' : '-',
49753 flags & VM_MAYSHARE ? 's' : 'p',
49754 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49755 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49756 +#else
49757 pgoff,
49758 +#endif
49759 MAJOR(dev), MINOR(dev), ino, &len);
49760
49761 /*
49762 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49763 */
49764 if (file) {
49765 pad_len_spaces(m, len);
49766 - seq_path(m, &file->f_path, "\n");
49767 + seq_path(m, &file->f_path, "\n\\");
49768 goto done;
49769 }
49770
49771 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49772 * Thread stack in /proc/PID/task/TID/maps or
49773 * the main process stack.
49774 */
49775 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49776 - vma->vm_end >= mm->start_stack)) {
49777 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49778 + (vma->vm_start <= mm->start_stack &&
49779 + vma->vm_end >= mm->start_stack)) {
49780 name = "[stack]";
49781 } else {
49782 /* Thread stack in /proc/PID/maps */
49783 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49784 struct proc_maps_private *priv = m->private;
49785 struct task_struct *task = priv->task;
49786
49787 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49788 + if (current->exec_id != m->exec_id) {
49789 + gr_log_badprocpid("maps");
49790 + return 0;
49791 + }
49792 +#endif
49793 +
49794 show_map_vma(m, vma, is_pid);
49795
49796 if (m->count < m->size) /* vma is copied successfully */
49797 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49798 .private = &mss,
49799 };
49800
49801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49802 + if (current->exec_id != m->exec_id) {
49803 + gr_log_badprocpid("smaps");
49804 + return 0;
49805 + }
49806 +#endif
49807 memset(&mss, 0, sizeof mss);
49808 - mss.vma = vma;
49809 - /* mmap_sem is held in m_start */
49810 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49811 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49812 -
49813 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49814 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49815 +#endif
49816 + mss.vma = vma;
49817 + /* mmap_sem is held in m_start */
49818 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49819 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49820 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49821 + }
49822 +#endif
49823 show_map_vma(m, vma, is_pid);
49824
49825 seq_printf(m,
49826 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49827 "KernelPageSize: %8lu kB\n"
49828 "MMUPageSize: %8lu kB\n"
49829 "Locked: %8lu kB\n",
49830 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49831 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49832 +#else
49833 (vma->vm_end - vma->vm_start) >> 10,
49834 +#endif
49835 mss.resident >> 10,
49836 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49837 mss.shared_clean >> 10,
49838 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49839 int n;
49840 char buffer[50];
49841
49842 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49843 + if (current->exec_id != m->exec_id) {
49844 + gr_log_badprocpid("numa_maps");
49845 + return 0;
49846 + }
49847 +#endif
49848 +
49849 if (!mm)
49850 return 0;
49851
49852 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49853 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49854 mpol_cond_put(pol);
49855
49856 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49857 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49858 +#else
49859 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49860 +#endif
49861
49862 if (file) {
49863 seq_printf(m, " file=");
49864 - seq_path(m, &file->f_path, "\n\t= ");
49865 + seq_path(m, &file->f_path, "\n\t\\= ");
49866 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49867 seq_printf(m, " heap");
49868 } else {
49869 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49870 index 1ccfa53..0848f95 100644
49871 --- a/fs/proc/task_nommu.c
49872 +++ b/fs/proc/task_nommu.c
49873 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49874 else
49875 bytes += kobjsize(mm);
49876
49877 - if (current->fs && current->fs->users > 1)
49878 + if (current->fs && atomic_read(&current->fs->users) > 1)
49879 sbytes += kobjsize(current->fs);
49880 else
49881 bytes += kobjsize(current->fs);
49882 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49883
49884 if (file) {
49885 pad_len_spaces(m, len);
49886 - seq_path(m, &file->f_path, "");
49887 + seq_path(m, &file->f_path, "\n\\");
49888 } else if (mm) {
49889 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49890
49891 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49892 index d67908b..d13f6a6 100644
49893 --- a/fs/quota/netlink.c
49894 +++ b/fs/quota/netlink.c
49895 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49896 void quota_send_warning(short type, unsigned int id, dev_t dev,
49897 const char warntype)
49898 {
49899 - static atomic_t seq;
49900 + static atomic_unchecked_t seq;
49901 struct sk_buff *skb;
49902 void *msg_head;
49903 int ret;
49904 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
49905 "VFS: Not enough memory to send quota warning.\n");
49906 return;
49907 }
49908 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
49909 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
49910 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
49911 if (!msg_head) {
49912 printk(KERN_ERR
49913 diff --git a/fs/readdir.c b/fs/readdir.c
49914 index 39e3370..20d446d 100644
49915 --- a/fs/readdir.c
49916 +++ b/fs/readdir.c
49917 @@ -17,6 +17,7 @@
49918 #include <linux/security.h>
49919 #include <linux/syscalls.h>
49920 #include <linux/unistd.h>
49921 +#include <linux/namei.h>
49922
49923 #include <asm/uaccess.h>
49924
49925 @@ -67,6 +68,7 @@ struct old_linux_dirent {
49926
49927 struct readdir_callback {
49928 struct old_linux_dirent __user * dirent;
49929 + struct file * file;
49930 int result;
49931 };
49932
49933 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
49934 buf->result = -EOVERFLOW;
49935 return -EOVERFLOW;
49936 }
49937 +
49938 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49939 + return 0;
49940 +
49941 buf->result++;
49942 dirent = buf->dirent;
49943 if (!access_ok(VERIFY_WRITE, dirent,
49944 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
49945
49946 buf.result = 0;
49947 buf.dirent = dirent;
49948 + buf.file = file;
49949
49950 error = vfs_readdir(file, fillonedir, &buf);
49951 if (buf.result)
49952 @@ -141,6 +148,7 @@ struct linux_dirent {
49953 struct getdents_callback {
49954 struct linux_dirent __user * current_dir;
49955 struct linux_dirent __user * previous;
49956 + struct file * file;
49957 int count;
49958 int error;
49959 };
49960 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
49961 buf->error = -EOVERFLOW;
49962 return -EOVERFLOW;
49963 }
49964 +
49965 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49966 + return 0;
49967 +
49968 dirent = buf->previous;
49969 if (dirent) {
49970 if (__put_user(offset, &dirent->d_off))
49971 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49972 buf.previous = NULL;
49973 buf.count = count;
49974 buf.error = 0;
49975 + buf.file = file;
49976
49977 error = vfs_readdir(file, filldir, &buf);
49978 if (error >= 0)
49979 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
49980 struct getdents_callback64 {
49981 struct linux_dirent64 __user * current_dir;
49982 struct linux_dirent64 __user * previous;
49983 + struct file *file;
49984 int count;
49985 int error;
49986 };
49987 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
49988 buf->error = -EINVAL; /* only used if we fail.. */
49989 if (reclen > buf->count)
49990 return -EINVAL;
49991 +
49992 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49993 + return 0;
49994 +
49995 dirent = buf->previous;
49996 if (dirent) {
49997 if (__put_user(offset, &dirent->d_off))
49998 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
49999
50000 buf.current_dir = dirent;
50001 buf.previous = NULL;
50002 + buf.file = file;
50003 buf.count = count;
50004 buf.error = 0;
50005
50006 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50007 error = buf.error;
50008 lastdirent = buf.previous;
50009 if (lastdirent) {
50010 - typeof(lastdirent->d_off) d_off = file->f_pos;
50011 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50012 if (__put_user(d_off, &lastdirent->d_off))
50013 error = -EFAULT;
50014 else
50015 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50016 index 2b7882b..1c5ef48 100644
50017 --- a/fs/reiserfs/do_balan.c
50018 +++ b/fs/reiserfs/do_balan.c
50019 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50020 return;
50021 }
50022
50023 - atomic_inc(&(fs_generation(tb->tb_sb)));
50024 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50025 do_balance_starts(tb);
50026
50027 /* balance leaf returns 0 except if combining L R and S into
50028 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50029 index e60e870..f40ac16 100644
50030 --- a/fs/reiserfs/procfs.c
50031 +++ b/fs/reiserfs/procfs.c
50032 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50033 "SMALL_TAILS " : "NO_TAILS ",
50034 replay_only(sb) ? "REPLAY_ONLY " : "",
50035 convert_reiserfs(sb) ? "CONV " : "",
50036 - atomic_read(&r->s_generation_counter),
50037 + atomic_read_unchecked(&r->s_generation_counter),
50038 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50039 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50040 SF(s_good_search_by_key_reada), SF(s_bmaps),
50041 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50042 index 33215f5..c5d427a 100644
50043 --- a/fs/reiserfs/reiserfs.h
50044 +++ b/fs/reiserfs/reiserfs.h
50045 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50046 /* Comment? -Hans */
50047 wait_queue_head_t s_wait;
50048 /* To be obsoleted soon by per buffer seals.. -Hans */
50049 - atomic_t s_generation_counter; // increased by one every time the
50050 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50051 // tree gets re-balanced
50052 unsigned long s_properties; /* File system properties. Currently holds
50053 on-disk FS format */
50054 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50055 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50056
50057 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50058 -#define get_generation(s) atomic_read (&fs_generation(s))
50059 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50060 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50061 #define __fs_changed(gen,s) (gen != get_generation (s))
50062 #define fs_changed(gen,s) \
50063 diff --git a/fs/select.c b/fs/select.c
50064 index db14c78..3aae1bd 100644
50065 --- a/fs/select.c
50066 +++ b/fs/select.c
50067 @@ -20,6 +20,7 @@
50068 #include <linux/export.h>
50069 #include <linux/slab.h>
50070 #include <linux/poll.h>
50071 +#include <linux/security.h>
50072 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50073 #include <linux/file.h>
50074 #include <linux/fdtable.h>
50075 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50076 struct poll_list *walk = head;
50077 unsigned long todo = nfds;
50078
50079 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50080 if (nfds > rlimit(RLIMIT_NOFILE))
50081 return -EINVAL;
50082
50083 diff --git a/fs/seq_file.c b/fs/seq_file.c
50084 index 14cf9de..adc4d5b 100644
50085 --- a/fs/seq_file.c
50086 +++ b/fs/seq_file.c
50087 @@ -9,6 +9,7 @@
50088 #include <linux/export.h>
50089 #include <linux/seq_file.h>
50090 #include <linux/slab.h>
50091 +#include <linux/sched.h>
50092
50093 #include <asm/uaccess.h>
50094 #include <asm/page.h>
50095 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50096 memset(p, 0, sizeof(*p));
50097 mutex_init(&p->lock);
50098 p->op = op;
50099 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50100 + p->exec_id = current->exec_id;
50101 +#endif
50102
50103 /*
50104 * Wrappers around seq_open(e.g. swaps_open) need to be
50105 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50106 return 0;
50107 }
50108 if (!m->buf) {
50109 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50110 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50111 if (!m->buf)
50112 return -ENOMEM;
50113 }
50114 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50115 Eoverflow:
50116 m->op->stop(m, p);
50117 kfree(m->buf);
50118 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50119 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50120 return !m->buf ? -ENOMEM : -EAGAIN;
50121 }
50122
50123 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50124
50125 /* grab buffer if we didn't have one */
50126 if (!m->buf) {
50127 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50128 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50129 if (!m->buf)
50130 goto Enomem;
50131 }
50132 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50133 goto Fill;
50134 m->op->stop(m, p);
50135 kfree(m->buf);
50136 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50137 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50138 if (!m->buf)
50139 goto Enomem;
50140 m->count = 0;
50141 @@ -577,7 +581,7 @@ static void single_stop(struct seq_file *p, void *v)
50142 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50143 void *data)
50144 {
50145 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50146 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50147 int res = -ENOMEM;
50148
50149 if (op) {
50150 diff --git a/fs/splice.c b/fs/splice.c
50151 index 41514dd..6564a93 100644
50152 --- a/fs/splice.c
50153 +++ b/fs/splice.c
50154 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50155 pipe_lock(pipe);
50156
50157 for (;;) {
50158 - if (!pipe->readers) {
50159 + if (!atomic_read(&pipe->readers)) {
50160 send_sig(SIGPIPE, current, 0);
50161 if (!ret)
50162 ret = -EPIPE;
50163 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50164 do_wakeup = 0;
50165 }
50166
50167 - pipe->waiting_writers++;
50168 + atomic_inc(&pipe->waiting_writers);
50169 pipe_wait(pipe);
50170 - pipe->waiting_writers--;
50171 + atomic_dec(&pipe->waiting_writers);
50172 }
50173
50174 pipe_unlock(pipe);
50175 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50176 old_fs = get_fs();
50177 set_fs(get_ds());
50178 /* The cast to a user pointer is valid due to the set_fs() */
50179 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50180 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50181 set_fs(old_fs);
50182
50183 return res;
50184 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50185 old_fs = get_fs();
50186 set_fs(get_ds());
50187 /* The cast to a user pointer is valid due to the set_fs() */
50188 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50189 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50190 set_fs(old_fs);
50191
50192 return res;
50193 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50194 goto err;
50195
50196 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50197 - vec[i].iov_base = (void __user *) page_address(page);
50198 + vec[i].iov_base = (void __force_user *) page_address(page);
50199 vec[i].iov_len = this_len;
50200 spd.pages[i] = page;
50201 spd.nr_pages++;
50202 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50203 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50204 {
50205 while (!pipe->nrbufs) {
50206 - if (!pipe->writers)
50207 + if (!atomic_read(&pipe->writers))
50208 return 0;
50209
50210 - if (!pipe->waiting_writers && sd->num_spliced)
50211 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50212 return 0;
50213
50214 if (sd->flags & SPLICE_F_NONBLOCK)
50215 @@ -1190,7 +1190,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50216 * out of the pipe right after the splice_to_pipe(). So set
50217 * PIPE_READERS appropriately.
50218 */
50219 - pipe->readers = 1;
50220 + atomic_set(&pipe->readers, 1);
50221
50222 current->splice_pipe = pipe;
50223 }
50224 @@ -1743,9 +1743,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50225 ret = -ERESTARTSYS;
50226 break;
50227 }
50228 - if (!pipe->writers)
50229 + if (!atomic_read(&pipe->writers))
50230 break;
50231 - if (!pipe->waiting_writers) {
50232 + if (!atomic_read(&pipe->waiting_writers)) {
50233 if (flags & SPLICE_F_NONBLOCK) {
50234 ret = -EAGAIN;
50235 break;
50236 @@ -1777,7 +1777,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50237 pipe_lock(pipe);
50238
50239 while (pipe->nrbufs >= pipe->buffers) {
50240 - if (!pipe->readers) {
50241 + if (!atomic_read(&pipe->readers)) {
50242 send_sig(SIGPIPE, current, 0);
50243 ret = -EPIPE;
50244 break;
50245 @@ -1790,9 +1790,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50246 ret = -ERESTARTSYS;
50247 break;
50248 }
50249 - pipe->waiting_writers++;
50250 + atomic_inc(&pipe->waiting_writers);
50251 pipe_wait(pipe);
50252 - pipe->waiting_writers--;
50253 + atomic_dec(&pipe->waiting_writers);
50254 }
50255
50256 pipe_unlock(pipe);
50257 @@ -1828,14 +1828,14 @@ retry:
50258 pipe_double_lock(ipipe, opipe);
50259
50260 do {
50261 - if (!opipe->readers) {
50262 + if (!atomic_read(&opipe->readers)) {
50263 send_sig(SIGPIPE, current, 0);
50264 if (!ret)
50265 ret = -EPIPE;
50266 break;
50267 }
50268
50269 - if (!ipipe->nrbufs && !ipipe->writers)
50270 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50271 break;
50272
50273 /*
50274 @@ -1932,7 +1932,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50275 pipe_double_lock(ipipe, opipe);
50276
50277 do {
50278 - if (!opipe->readers) {
50279 + if (!atomic_read(&opipe->readers)) {
50280 send_sig(SIGPIPE, current, 0);
50281 if (!ret)
50282 ret = -EPIPE;
50283 @@ -1977,7 +1977,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50284 * return EAGAIN if we have the potential of some data in the
50285 * future, otherwise just return 0
50286 */
50287 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50288 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50289 ret = -EAGAIN;
50290
50291 pipe_unlock(ipipe);
50292 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50293 index 6b0bb00..75db2fe 100644
50294 --- a/fs/sysfs/dir.c
50295 +++ b/fs/sysfs/dir.c
50296 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50297 struct sysfs_dirent *sd;
50298 int rc;
50299
50300 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50301 + const char *parent_name = parent_sd->s_name;
50302 +
50303 + mode = S_IFDIR | S_IRWXU;
50304 +
50305 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50306 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50307 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50308 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50309 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50310 +#endif
50311 +
50312 /* allocate */
50313 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50314 if (!sd)
50315 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50316 index 00012e3..8392349 100644
50317 --- a/fs/sysfs/file.c
50318 +++ b/fs/sysfs/file.c
50319 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50320
50321 struct sysfs_open_dirent {
50322 atomic_t refcnt;
50323 - atomic_t event;
50324 + atomic_unchecked_t event;
50325 wait_queue_head_t poll;
50326 struct list_head buffers; /* goes through sysfs_buffer.list */
50327 };
50328 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50329 if (!sysfs_get_active(attr_sd))
50330 return -ENODEV;
50331
50332 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50333 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50334 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50335
50336 sysfs_put_active(attr_sd);
50337 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50338 return -ENOMEM;
50339
50340 atomic_set(&new_od->refcnt, 0);
50341 - atomic_set(&new_od->event, 1);
50342 + atomic_set_unchecked(&new_od->event, 1);
50343 init_waitqueue_head(&new_od->poll);
50344 INIT_LIST_HEAD(&new_od->buffers);
50345 goto retry;
50346 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50347
50348 sysfs_put_active(attr_sd);
50349
50350 - if (buffer->event != atomic_read(&od->event))
50351 + if (buffer->event != atomic_read_unchecked(&od->event))
50352 goto trigger;
50353
50354 return DEFAULT_POLLMASK;
50355 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50356
50357 od = sd->s_attr.open;
50358 if (od) {
50359 - atomic_inc(&od->event);
50360 + atomic_inc_unchecked(&od->event);
50361 wake_up_interruptible(&od->poll);
50362 }
50363
50364 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50365 index a7ac78f..02158e1 100644
50366 --- a/fs/sysfs/symlink.c
50367 +++ b/fs/sysfs/symlink.c
50368 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50369
50370 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50371 {
50372 - char *page = nd_get_link(nd);
50373 + const char *page = nd_get_link(nd);
50374 if (!IS_ERR(page))
50375 free_page((unsigned long)page);
50376 }
50377 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50378 index c175b4d..8f36a16 100644
50379 --- a/fs/udf/misc.c
50380 +++ b/fs/udf/misc.c
50381 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50382
50383 u8 udf_tag_checksum(const struct tag *t)
50384 {
50385 - u8 *data = (u8 *)t;
50386 + const u8 *data = (const u8 *)t;
50387 u8 checksum = 0;
50388 int i;
50389 for (i = 0; i < sizeof(struct tag); ++i)
50390 diff --git a/fs/utimes.c b/fs/utimes.c
50391 index fa4dbe4..e12d1b9 100644
50392 --- a/fs/utimes.c
50393 +++ b/fs/utimes.c
50394 @@ -1,6 +1,7 @@
50395 #include <linux/compiler.h>
50396 #include <linux/file.h>
50397 #include <linux/fs.h>
50398 +#include <linux/security.h>
50399 #include <linux/linkage.h>
50400 #include <linux/mount.h>
50401 #include <linux/namei.h>
50402 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50403 goto mnt_drop_write_and_out;
50404 }
50405 }
50406 +
50407 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50408 + error = -EACCES;
50409 + goto mnt_drop_write_and_out;
50410 + }
50411 +
50412 mutex_lock(&inode->i_mutex);
50413 error = notify_change(path->dentry, &newattrs);
50414 mutex_unlock(&inode->i_mutex);
50415 diff --git a/fs/xattr.c b/fs/xattr.c
50416 index 4d45b71..2ec08e10 100644
50417 --- a/fs/xattr.c
50418 +++ b/fs/xattr.c
50419 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50420 * Extended attribute SET operations
50421 */
50422 static long
50423 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50424 +setxattr(struct path *path, const char __user *name, const void __user *value,
50425 size_t size, int flags)
50426 {
50427 int error;
50428 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50429 }
50430 }
50431
50432 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50433 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50434 + error = -EACCES;
50435 + goto out;
50436 + }
50437 +
50438 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50439 out:
50440 if (vvalue)
50441 vfree(vvalue);
50442 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50443 return error;
50444 error = mnt_want_write(path.mnt);
50445 if (!error) {
50446 - error = setxattr(path.dentry, name, value, size, flags);
50447 + error = setxattr(&path, name, value, size, flags);
50448 mnt_drop_write(path.mnt);
50449 }
50450 path_put(&path);
50451 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50452 return error;
50453 error = mnt_want_write(path.mnt);
50454 if (!error) {
50455 - error = setxattr(path.dentry, name, value, size, flags);
50456 + error = setxattr(&path, name, value, size, flags);
50457 mnt_drop_write(path.mnt);
50458 }
50459 path_put(&path);
50460 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50461 {
50462 int fput_needed;
50463 struct file *f;
50464 - struct dentry *dentry;
50465 int error = -EBADF;
50466
50467 f = fget_light(fd, &fput_needed);
50468 if (!f)
50469 return error;
50470 - dentry = f->f_path.dentry;
50471 - audit_inode(NULL, dentry);
50472 + audit_inode(NULL, f->f_path.dentry);
50473 error = mnt_want_write_file(f);
50474 if (!error) {
50475 - error = setxattr(dentry, name, value, size, flags);
50476 + error = setxattr(&f->f_path, name, value, size, flags);
50477 mnt_drop_write_file(f);
50478 }
50479 fput_light(f, fput_needed);
50480 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50481 index 69d06b0..c0996e5 100644
50482 --- a/fs/xattr_acl.c
50483 +++ b/fs/xattr_acl.c
50484 @@ -17,8 +17,8 @@
50485 struct posix_acl *
50486 posix_acl_from_xattr(const void *value, size_t size)
50487 {
50488 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50489 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50490 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50491 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50492 int count;
50493 struct posix_acl *acl;
50494 struct posix_acl_entry *acl_e;
50495 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50496 index 848ffa7..1f249bf 100644
50497 --- a/fs/xfs/xfs_bmap.c
50498 +++ b/fs/xfs/xfs_bmap.c
50499 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50500 int nmap,
50501 int ret_nmap);
50502 #else
50503 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50504 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50505 #endif /* DEBUG */
50506
50507 STATIC int
50508 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50509 index 1b9fc3e..e1bdde0 100644
50510 --- a/fs/xfs/xfs_dir2_sf.c
50511 +++ b/fs/xfs/xfs_dir2_sf.c
50512 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50513 }
50514
50515 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50516 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50517 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50518 + char name[sfep->namelen];
50519 + memcpy(name, sfep->name, sfep->namelen);
50520 + if (filldir(dirent, name, sfep->namelen,
50521 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50522 + *offset = off & 0x7fffffff;
50523 + return 0;
50524 + }
50525 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50526 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50527 *offset = off & 0x7fffffff;
50528 return 0;
50529 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50530 index 0e0232c..fa5c3fe 100644
50531 --- a/fs/xfs/xfs_ioctl.c
50532 +++ b/fs/xfs/xfs_ioctl.c
50533 @@ -126,7 +126,7 @@ xfs_find_handle(
50534 }
50535
50536 error = -EFAULT;
50537 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50538 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50539 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50540 goto out_put;
50541
50542 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50543 index 4e00cf0..3374374 100644
50544 --- a/fs/xfs/xfs_iops.c
50545 +++ b/fs/xfs/xfs_iops.c
50546 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50547 struct nameidata *nd,
50548 void *p)
50549 {
50550 - char *s = nd_get_link(nd);
50551 + const char *s = nd_get_link(nd);
50552
50553 if (!IS_ERR(s))
50554 kfree(s);
50555 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50556 new file mode 100644
50557 index 0000000..d38b430
50558 --- /dev/null
50559 +++ b/grsecurity/Kconfig
50560 @@ -0,0 +1,947 @@
50561 +#
50562 +# grecurity configuration
50563 +#
50564 +menu "Memory Protections"
50565 +depends on GRKERNSEC
50566 +
50567 +config GRKERNSEC_KMEM
50568 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50569 + default y if GRKERNSEC_CONFIG_AUTO
50570 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50571 + help
50572 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50573 + be written to or read from to modify or leak the contents of the running
50574 + kernel. /dev/port will also not be allowed to be opened. If you have module
50575 + support disabled, enabling this will close up four ways that are
50576 + currently used to insert malicious code into the running kernel.
50577 + Even with all these features enabled, we still highly recommend that
50578 + you use the RBAC system, as it is still possible for an attacker to
50579 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50580 + If you are not using XFree86, you may be able to stop this additional
50581 + case by enabling the 'Disable privileged I/O' option. Though nothing
50582 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50583 + but only to video memory, which is the only writing we allow in this
50584 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50585 + not be allowed to mprotect it with PROT_WRITE later.
50586 + It is highly recommended that you say Y here if you meet all the
50587 + conditions above.
50588 +
50589 +config GRKERNSEC_VM86
50590 + bool "Restrict VM86 mode"
50591 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50592 + depends on X86_32
50593 +
50594 + help
50595 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50596 + make use of a special execution mode on 32bit x86 processors called
50597 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50598 + video cards and will still work with this option enabled. The purpose
50599 + of the option is to prevent exploitation of emulation errors in
50600 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50601 + Nearly all users should be able to enable this option.
50602 +
50603 +config GRKERNSEC_IO
50604 + bool "Disable privileged I/O"
50605 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50606 + depends on X86
50607 + select RTC_CLASS
50608 + select RTC_INTF_DEV
50609 + select RTC_DRV_CMOS
50610 +
50611 + help
50612 + If you say Y here, all ioperm and iopl calls will return an error.
50613 + Ioperm and iopl can be used to modify the running kernel.
50614 + Unfortunately, some programs need this access to operate properly,
50615 + the most notable of which are XFree86 and hwclock. hwclock can be
50616 + remedied by having RTC support in the kernel, so real-time
50617 + clock support is enabled if this option is enabled, to ensure
50618 + that hwclock operates correctly. XFree86 still will not
50619 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50620 + IF YOU USE XFree86. If you use XFree86 and you still want to
50621 + protect your kernel against modification, use the RBAC system.
50622 +
50623 +config GRKERNSEC_PROC_MEMMAP
50624 + bool "Harden ASLR against information leaks and entropy reduction"
50625 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50626 + depends on PAX_NOEXEC || PAX_ASLR
50627 + help
50628 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50629 + give no information about the addresses of its mappings if
50630 + PaX features that rely on random addresses are enabled on the task.
50631 + In addition to sanitizing this information and disabling other
50632 + dangerous sources of information, this option causes reads of sensitive
50633 + /proc/<pid> entries where the file descriptor was opened in a different
50634 + task than the one performing the read. Such attempts are logged.
50635 + This option also limits argv/env strings for suid/sgid binaries
50636 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50637 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50638 + binaries to prevent alternative mmap layouts from being abused.
50639 +
50640 + If you use PaX it is essential that you say Y here as it closes up
50641 + several holes that make full ASLR useless locally.
50642 +
50643 +config GRKERNSEC_BRUTE
50644 + bool "Deter exploit bruteforcing"
50645 + default y if GRKERNSEC_CONFIG_AUTO
50646 + help
50647 + If you say Y here, attempts to bruteforce exploits against forking
50648 + daemons such as apache or sshd, as well as against suid/sgid binaries
50649 + will be deterred. When a child of a forking daemon is killed by PaX
50650 + or crashes due to an illegal instruction or other suspicious signal,
50651 + the parent process will be delayed 30 seconds upon every subsequent
50652 + fork until the administrator is able to assess the situation and
50653 + restart the daemon.
50654 + In the suid/sgid case, the attempt is logged, the user has all their
50655 + processes terminated, and they are prevented from executing any further
50656 + processes for 15 minutes.
50657 + It is recommended that you also enable signal logging in the auditing
50658 + section so that logs are generated when a process triggers a suspicious
50659 + signal.
50660 + If the sysctl option is enabled, a sysctl option with name
50661 + "deter_bruteforce" is created.
50662 +
50663 +
50664 +config GRKERNSEC_MODHARDEN
50665 + bool "Harden module auto-loading"
50666 + default y if GRKERNSEC_CONFIG_AUTO
50667 + depends on MODULES
50668 + help
50669 + If you say Y here, module auto-loading in response to use of some
50670 + feature implemented by an unloaded module will be restricted to
50671 + root users. Enabling this option helps defend against attacks
50672 + by unprivileged users who abuse the auto-loading behavior to
50673 + cause a vulnerable module to load that is then exploited.
50674 +
50675 + If this option prevents a legitimate use of auto-loading for a
50676 + non-root user, the administrator can execute modprobe manually
50677 + with the exact name of the module mentioned in the alert log.
50678 + Alternatively, the administrator can add the module to the list
50679 + of modules loaded at boot by modifying init scripts.
50680 +
50681 + Modification of init scripts will most likely be needed on
50682 + Ubuntu servers with encrypted home directory support enabled,
50683 + as the first non-root user logging in will cause the ecb(aes),
50684 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50685 +
50686 +config GRKERNSEC_HIDESYM
50687 + bool "Hide kernel symbols"
50688 + default y if GRKERNSEC_CONFIG_AUTO
50689 + select PAX_USERCOPY_SLABS
50690 + help
50691 + If you say Y here, getting information on loaded modules, and
50692 + displaying all kernel symbols through a syscall will be restricted
50693 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50694 + /proc/kallsyms will be restricted to the root user. The RBAC
50695 + system can hide that entry even from root.
50696 +
50697 + This option also prevents leaking of kernel addresses through
50698 + several /proc entries.
50699 +
50700 + Note that this option is only effective provided the following
50701 + conditions are met:
50702 + 1) The kernel using grsecurity is not precompiled by some distribution
50703 + 2) You have also enabled GRKERNSEC_DMESG
50704 + 3) You are using the RBAC system and hiding other files such as your
50705 + kernel image and System.map. Alternatively, enabling this option
50706 + causes the permissions on /boot, /lib/modules, and the kernel
50707 + source directory to change at compile time to prevent
50708 + reading by non-root users.
50709 + If the above conditions are met, this option will aid in providing a
50710 + useful protection against local kernel exploitation of overflows
50711 + and arbitrary read/write vulnerabilities.
50712 +
50713 +config GRKERNSEC_KERN_LOCKOUT
50714 + bool "Active kernel exploit response"
50715 + default y if GRKERNSEC_CONFIG_AUTO
50716 + depends on X86 || ARM || PPC || SPARC
50717 + help
50718 + If you say Y here, when a PaX alert is triggered due to suspicious
50719 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50720 + or an OOPS occurs due to bad memory accesses, instead of just
50721 + terminating the offending process (and potentially allowing
50722 + a subsequent exploit from the same user), we will take one of two
50723 + actions:
50724 + If the user was root, we will panic the system
50725 + If the user was non-root, we will log the attempt, terminate
50726 + all processes owned by the user, then prevent them from creating
50727 + any new processes until the system is restarted
50728 + This deters repeated kernel exploitation/bruteforcing attempts
50729 + and is useful for later forensics.
50730 +
50731 +endmenu
50732 +menu "Role Based Access Control Options"
50733 +depends on GRKERNSEC
50734 +
50735 +config GRKERNSEC_RBAC_DEBUG
50736 + bool
50737 +
50738 +config GRKERNSEC_NO_RBAC
50739 + bool "Disable RBAC system"
50740 + help
50741 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50742 + preventing the RBAC system from being enabled. You should only say Y
50743 + here if you have no intention of using the RBAC system, so as to prevent
50744 + an attacker with root access from misusing the RBAC system to hide files
50745 + and processes when loadable module support and /dev/[k]mem have been
50746 + locked down.
50747 +
50748 +config GRKERNSEC_ACL_HIDEKERN
50749 + bool "Hide kernel processes"
50750 + help
50751 + If you say Y here, all kernel threads will be hidden to all
50752 + processes but those whose subject has the "view hidden processes"
50753 + flag.
50754 +
50755 +config GRKERNSEC_ACL_MAXTRIES
50756 + int "Maximum tries before password lockout"
50757 + default 3
50758 + help
50759 + This option enforces the maximum number of times a user can attempt
50760 + to authorize themselves with the grsecurity RBAC system before being
50761 + denied the ability to attempt authorization again for a specified time.
50762 + The lower the number, the harder it will be to brute-force a password.
50763 +
50764 +config GRKERNSEC_ACL_TIMEOUT
50765 + int "Time to wait after max password tries, in seconds"
50766 + default 30
50767 + help
50768 + This option specifies the time the user must wait after attempting to
50769 + authorize to the RBAC system with the maximum number of invalid
50770 + passwords. The higher the number, the harder it will be to brute-force
50771 + a password.
50772 +
50773 +endmenu
50774 +menu "Filesystem Protections"
50775 +depends on GRKERNSEC
50776 +
50777 +config GRKERNSEC_PROC
50778 + bool "Proc restrictions"
50779 + default y if GRKERNSEC_CONFIG_AUTO
50780 + help
50781 + If you say Y here, the permissions of the /proc filesystem
50782 + will be altered to enhance system security and privacy. You MUST
50783 + choose either a user only restriction or a user and group restriction.
50784 + Depending upon the option you choose, you can either restrict users to
50785 + see only the processes they themselves run, or choose a group that can
50786 + view all processes and files normally restricted to root if you choose
50787 + the "restrict to user only" option. NOTE: If you're running identd or
50788 + ntpd as a non-root user, you will have to run it as the group you
50789 + specify here.
50790 +
50791 +config GRKERNSEC_PROC_USER
50792 + bool "Restrict /proc to user only"
50793 + depends on GRKERNSEC_PROC
50794 + help
50795 + If you say Y here, non-root users will only be able to view their own
50796 + processes, and restricts them from viewing network-related information,
50797 + and viewing kernel symbol and module information.
50798 +
50799 +config GRKERNSEC_PROC_USERGROUP
50800 + bool "Allow special group"
50801 + default y if GRKERNSEC_CONFIG_AUTO
50802 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50803 + help
50804 + If you say Y here, you will be able to select a group that will be
50805 + able to view all processes and network-related information. If you've
50806 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50807 + remain hidden. This option is useful if you want to run identd as
50808 + a non-root user. The group you select may also be chosen at boot time
50809 + via "grsec_proc_gid=" on the kernel commandline.
50810 +
50811 +config GRKERNSEC_PROC_GID
50812 + int "GID for special group"
50813 + depends on GRKERNSEC_PROC_USERGROUP
50814 + default 1001
50815 +
50816 +config GRKERNSEC_PROC_ADD
50817 + bool "Additional restrictions"
50818 + default y if GRKERNSEC_CONFIG_AUTO
50819 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50820 + help
50821 + If you say Y here, additional restrictions will be placed on
50822 + /proc that keep normal users from viewing device information and
50823 + slabinfo information that could be useful for exploits.
50824 +
50825 +config GRKERNSEC_LINK
50826 + bool "Linking restrictions"
50827 + default y if GRKERNSEC_CONFIG_AUTO
50828 + help
50829 + If you say Y here, /tmp race exploits will be prevented, since users
50830 + will no longer be able to follow symlinks owned by other users in
50831 + world-writable +t directories (e.g. /tmp), unless the owner of the
50832 + symlink is the owner of the directory. users will also not be
50833 + able to hardlink to files they do not own. If the sysctl option is
50834 + enabled, a sysctl option with name "linking_restrictions" is created.
50835 +
50836 +config GRKERNSEC_SYMLINKOWN
50837 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50838 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50839 + help
50840 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50841 + that prevents it from being used as a security feature. As Apache
50842 + verifies the symlink by performing a stat() against the target of
50843 + the symlink before it is followed, an attacker can setup a symlink
50844 + to point to a same-owned file, then replace the symlink with one
50845 + that targets another user's file just after Apache "validates" the
50846 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50847 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50848 + will be in place for the group you specify. If the sysctl option
50849 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50850 + created.
50851 +
50852 +config GRKERNSEC_SYMLINKOWN_GID
50853 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50854 + depends on GRKERNSEC_SYMLINKOWN
50855 + default 1006
50856 + help
50857 + Setting this GID determines what group kernel-enforced
50858 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
50859 + is enabled, a sysctl option with name "symlinkown_gid" is created.
50860 +
50861 +config GRKERNSEC_FIFO
50862 + bool "FIFO restrictions"
50863 + default y if GRKERNSEC_CONFIG_AUTO
50864 + help
50865 + If you say Y here, users will not be able to write to FIFOs they don't
50866 + own in world-writable +t directories (e.g. /tmp), unless the owner of
50867 + the FIFO is the same owner of the directory it's held in. If the sysctl
50868 + option is enabled, a sysctl option with name "fifo_restrictions" is
50869 + created.
50870 +
50871 +config GRKERNSEC_SYSFS_RESTRICT
50872 + bool "Sysfs/debugfs restriction"
50873 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50874 + depends on SYSFS
50875 + help
50876 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
50877 + any filesystem normally mounted under it (e.g. debugfs) will be
50878 + mostly accessible only by root. These filesystems generally provide access
50879 + to hardware and debug information that isn't appropriate for unprivileged
50880 + users of the system. Sysfs and debugfs have also become a large source
50881 + of new vulnerabilities, ranging from infoleaks to local compromise.
50882 + There has been very little oversight with an eye toward security involved
50883 + in adding new exporters of information to these filesystems, so their
50884 + use is discouraged.
50885 + For reasons of compatibility, a few directories have been whitelisted
50886 + for access by non-root users:
50887 + /sys/fs/selinux
50888 + /sys/fs/fuse
50889 + /sys/devices/system/cpu
50890 +
50891 +config GRKERNSEC_ROFS
50892 + bool "Runtime read-only mount protection"
50893 + help
50894 + If you say Y here, a sysctl option with name "romount_protect" will
50895 + be created. By setting this option to 1 at runtime, filesystems
50896 + will be protected in the following ways:
50897 + * No new writable mounts will be allowed
50898 + * Existing read-only mounts won't be able to be remounted read/write
50899 + * Write operations will be denied on all block devices
50900 + This option acts independently of grsec_lock: once it is set to 1,
50901 + it cannot be turned off. Therefore, please be mindful of the resulting
50902 + behavior if this option is enabled in an init script on a read-only
50903 + filesystem. This feature is mainly intended for secure embedded systems.
50904 +
50905 +config GRKERNSEC_CHROOT
50906 + bool "Chroot jail restrictions"
50907 + default y if GRKERNSEC_CONFIG_AUTO
50908 + help
50909 + If you say Y here, you will be able to choose several options that will
50910 + make breaking out of a chrooted jail much more difficult. If you
50911 + encounter no software incompatibilities with the following options, it
50912 + is recommended that you enable each one.
50913 +
50914 +config GRKERNSEC_CHROOT_MOUNT
50915 + bool "Deny mounts"
50916 + default y if GRKERNSEC_CONFIG_AUTO
50917 + depends on GRKERNSEC_CHROOT
50918 + help
50919 + If you say Y here, processes inside a chroot will not be able to
50920 + mount or remount filesystems. If the sysctl option is enabled, a
50921 + sysctl option with name "chroot_deny_mount" is created.
50922 +
50923 +config GRKERNSEC_CHROOT_DOUBLE
50924 + bool "Deny double-chroots"
50925 + default y if GRKERNSEC_CONFIG_AUTO
50926 + depends on GRKERNSEC_CHROOT
50927 + help
50928 + If you say Y here, processes inside a chroot will not be able to chroot
50929 + again outside the chroot. This is a widely used method of breaking
50930 + out of a chroot jail and should not be allowed. If the sysctl
50931 + option is enabled, a sysctl option with name
50932 + "chroot_deny_chroot" is created.
50933 +
50934 +config GRKERNSEC_CHROOT_PIVOT
50935 + bool "Deny pivot_root in chroot"
50936 + default y if GRKERNSEC_CONFIG_AUTO
50937 + depends on GRKERNSEC_CHROOT
50938 + help
50939 + If you say Y here, processes inside a chroot will not be able to use
50940 + a function called pivot_root() that was introduced in Linux 2.3.41. It
50941 + works similar to chroot in that it changes the root filesystem. This
50942 + function could be misused in a chrooted process to attempt to break out
50943 + of the chroot, and therefore should not be allowed. If the sysctl
50944 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
50945 + created.
50946 +
50947 +config GRKERNSEC_CHROOT_CHDIR
50948 + bool "Enforce chdir(\"/\") on all chroots"
50949 + default y if GRKERNSEC_CONFIG_AUTO
50950 + depends on GRKERNSEC_CHROOT
50951 + help
50952 + If you say Y here, the current working directory of all newly-chrooted
50953 + applications will be set to the the root directory of the chroot.
50954 + The man page on chroot(2) states:
50955 + Note that this call does not change the current working
50956 + directory, so that `.' can be outside the tree rooted at
50957 + `/'. In particular, the super-user can escape from a
50958 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
50959 +
50960 + It is recommended that you say Y here, since it's not known to break
50961 + any software. If the sysctl option is enabled, a sysctl option with
50962 + name "chroot_enforce_chdir" is created.
50963 +
50964 +config GRKERNSEC_CHROOT_CHMOD
50965 + bool "Deny (f)chmod +s"
50966 + default y if GRKERNSEC_CONFIG_AUTO
50967 + depends on GRKERNSEC_CHROOT
50968 + help
50969 + If you say Y here, processes inside a chroot will not be able to chmod
50970 + or fchmod files to make them have suid or sgid bits. This protects
50971 + against another published method of breaking a chroot. If the sysctl
50972 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
50973 + created.
50974 +
50975 +config GRKERNSEC_CHROOT_FCHDIR
50976 + bool "Deny fchdir out of chroot"
50977 + default y if GRKERNSEC_CONFIG_AUTO
50978 + depends on GRKERNSEC_CHROOT
50979 + help
50980 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
50981 + to a file descriptor of the chrooting process that points to a directory
50982 + outside the filesystem will be stopped. If the sysctl option
50983 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
50984 +
50985 +config GRKERNSEC_CHROOT_MKNOD
50986 + bool "Deny mknod"
50987 + default y if GRKERNSEC_CONFIG_AUTO
50988 + depends on GRKERNSEC_CHROOT
50989 + help
50990 + If you say Y here, processes inside a chroot will not be allowed to
50991 + mknod. The problem with using mknod inside a chroot is that it
50992 + would allow an attacker to create a device entry that is the same
50993 + as one on the physical root of your system, which could range from
50994 + anything from the console device to a device for your harddrive (which
50995 + they could then use to wipe the drive or steal data). It is recommended
50996 + that you say Y here, unless you run into software incompatibilities.
50997 + If the sysctl option is enabled, a sysctl option with name
50998 + "chroot_deny_mknod" is created.
50999 +
51000 +config GRKERNSEC_CHROOT_SHMAT
51001 + bool "Deny shmat() out of chroot"
51002 + default y if GRKERNSEC_CONFIG_AUTO
51003 + depends on GRKERNSEC_CHROOT
51004 + help
51005 + If you say Y here, processes inside a chroot will not be able to attach
51006 + to shared memory segments that were created outside of the chroot jail.
51007 + It is recommended that you say Y here. If the sysctl option is enabled,
51008 + a sysctl option with name "chroot_deny_shmat" is created.
51009 +
51010 +config GRKERNSEC_CHROOT_UNIX
51011 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51012 + default y if GRKERNSEC_CONFIG_AUTO
51013 + depends on GRKERNSEC_CHROOT
51014 + help
51015 + If you say Y here, processes inside a chroot will not be able to
51016 + connect to abstract (meaning not belonging to a filesystem) Unix
51017 + domain sockets that were bound outside of a chroot. It is recommended
51018 + that you say Y here. If the sysctl option is enabled, a sysctl option
51019 + with name "chroot_deny_unix" is created.
51020 +
51021 +config GRKERNSEC_CHROOT_FINDTASK
51022 + bool "Protect outside processes"
51023 + default y if GRKERNSEC_CONFIG_AUTO
51024 + depends on GRKERNSEC_CHROOT
51025 + help
51026 + If you say Y here, processes inside a chroot will not be able to
51027 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51028 + getsid, or view any process outside of the chroot. If the sysctl
51029 + option is enabled, a sysctl option with name "chroot_findtask" is
51030 + created.
51031 +
51032 +config GRKERNSEC_CHROOT_NICE
51033 + bool "Restrict priority changes"
51034 + default y if GRKERNSEC_CONFIG_AUTO
51035 + depends on GRKERNSEC_CHROOT
51036 + help
51037 + If you say Y here, processes inside a chroot will not be able to raise
51038 + the priority of processes in the chroot, or alter the priority of
51039 + processes outside the chroot. This provides more security than simply
51040 + removing CAP_SYS_NICE from the process' capability set. If the
51041 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51042 + is created.
51043 +
51044 +config GRKERNSEC_CHROOT_SYSCTL
51045 + bool "Deny sysctl writes"
51046 + default y if GRKERNSEC_CONFIG_AUTO
51047 + depends on GRKERNSEC_CHROOT
51048 + help
51049 + If you say Y here, an attacker in a chroot will not be able to
51050 + write to sysctl entries, either by sysctl(2) or through a /proc
51051 + interface. It is strongly recommended that you say Y here. If the
51052 + sysctl option is enabled, a sysctl option with name
51053 + "chroot_deny_sysctl" is created.
51054 +
51055 +config GRKERNSEC_CHROOT_CAPS
51056 + bool "Capability restrictions"
51057 + default y if GRKERNSEC_CONFIG_AUTO
51058 + depends on GRKERNSEC_CHROOT
51059 + help
51060 + If you say Y here, the capabilities on all processes within a
51061 + chroot jail will be lowered to stop module insertion, raw i/o,
51062 + system and net admin tasks, rebooting the system, modifying immutable
51063 + files, modifying IPC owned by another, and changing the system time.
51064 + This is left an option because it can break some apps. Disable this
51065 + if your chrooted apps are having problems performing those kinds of
51066 + tasks. If the sysctl option is enabled, a sysctl option with
51067 + name "chroot_caps" is created.
51068 +
51069 +endmenu
51070 +menu "Kernel Auditing"
51071 +depends on GRKERNSEC
51072 +
51073 +config GRKERNSEC_AUDIT_GROUP
51074 + bool "Single group for auditing"
51075 + help
51076 + If you say Y here, the exec, chdir, and (un)mount logging features
51077 + will only operate on a group you specify. This option is recommended
51078 + if you only want to watch certain users instead of having a large
51079 + amount of logs from the entire system. If the sysctl option is enabled,
51080 + a sysctl option with name "audit_group" is created.
51081 +
51082 +config GRKERNSEC_AUDIT_GID
51083 + int "GID for auditing"
51084 + depends on GRKERNSEC_AUDIT_GROUP
51085 + default 1007
51086 +
51087 +config GRKERNSEC_EXECLOG
51088 + bool "Exec logging"
51089 + help
51090 + If you say Y here, all execve() calls will be logged (since the
51091 + other exec*() calls are frontends to execve(), all execution
51092 + will be logged). Useful for shell-servers that like to keep track
51093 + of their users. If the sysctl option is enabled, a sysctl option with
51094 + name "exec_logging" is created.
51095 + WARNING: This option when enabled will produce a LOT of logs, especially
51096 + on an active system.
51097 +
51098 +config GRKERNSEC_RESLOG
51099 + bool "Resource logging"
51100 + default y if GRKERNSEC_CONFIG_AUTO
51101 + help
51102 + If you say Y here, all attempts to overstep resource limits will
51103 + be logged with the resource name, the requested size, and the current
51104 + limit. It is highly recommended that you say Y here. If the sysctl
51105 + option is enabled, a sysctl option with name "resource_logging" is
51106 + created. If the RBAC system is enabled, the sysctl value is ignored.
51107 +
51108 +config GRKERNSEC_CHROOT_EXECLOG
51109 + bool "Log execs within chroot"
51110 + help
51111 + If you say Y here, all executions inside a chroot jail will be logged
51112 + to syslog. This can cause a large amount of logs if certain
51113 + applications (eg. djb's daemontools) are installed on the system, and
51114 + is therefore left as an option. If the sysctl option is enabled, a
51115 + sysctl option with name "chroot_execlog" is created.
51116 +
51117 +config GRKERNSEC_AUDIT_PTRACE
51118 + bool "Ptrace logging"
51119 + help
51120 + If you say Y here, all attempts to attach to a process via ptrace
51121 + will be logged. If the sysctl option is enabled, a sysctl option
51122 + with name "audit_ptrace" is created.
51123 +
51124 +config GRKERNSEC_AUDIT_CHDIR
51125 + bool "Chdir logging"
51126 + help
51127 + If you say Y here, all chdir() calls will be logged. If the sysctl
51128 + option is enabled, a sysctl option with name "audit_chdir" is created.
51129 +
51130 +config GRKERNSEC_AUDIT_MOUNT
51131 + bool "(Un)Mount logging"
51132 + help
51133 + If you say Y here, all mounts and unmounts will be logged. If the
51134 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51135 + created.
51136 +
51137 +config GRKERNSEC_SIGNAL
51138 + bool "Signal logging"
51139 + default y if GRKERNSEC_CONFIG_AUTO
51140 + help
51141 + If you say Y here, certain important signals will be logged, such as
51142 + SIGSEGV, which will as a result inform you of when a error in a program
51143 + occurred, which in some cases could mean a possible exploit attempt.
51144 + If the sysctl option is enabled, a sysctl option with name
51145 + "signal_logging" is created.
51146 +
51147 +config GRKERNSEC_FORKFAIL
51148 + bool "Fork failure logging"
51149 + help
51150 + If you say Y here, all failed fork() attempts will be logged.
51151 + This could suggest a fork bomb, or someone attempting to overstep
51152 + their process limit. If the sysctl option is enabled, a sysctl option
51153 + with name "forkfail_logging" is created.
51154 +
51155 +config GRKERNSEC_TIME
51156 + bool "Time change logging"
51157 + default y if GRKERNSEC_CONFIG_AUTO
51158 + help
51159 + If you say Y here, any changes of the system clock will be logged.
51160 + If the sysctl option is enabled, a sysctl option with name
51161 + "timechange_logging" is created.
51162 +
51163 +config GRKERNSEC_PROC_IPADDR
51164 + bool "/proc/<pid>/ipaddr support"
51165 + default y if GRKERNSEC_CONFIG_AUTO
51166 + help
51167 + If you say Y here, a new entry will be added to each /proc/<pid>
51168 + directory that contains the IP address of the person using the task.
51169 + The IP is carried across local TCP and AF_UNIX stream sockets.
51170 + This information can be useful for IDS/IPSes to perform remote response
51171 + to a local attack. The entry is readable by only the owner of the
51172 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51173 + the RBAC system), and thus does not create privacy concerns.
51174 +
51175 +config GRKERNSEC_RWXMAP_LOG
51176 + bool 'Denied RWX mmap/mprotect logging'
51177 + default y if GRKERNSEC_CONFIG_AUTO
51178 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51179 + help
51180 + If you say Y here, calls to mmap() and mprotect() with explicit
51181 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51182 + denied by the PAX_MPROTECT feature. If the sysctl option is
51183 + enabled, a sysctl option with name "rwxmap_logging" is created.
51184 +
51185 +config GRKERNSEC_AUDIT_TEXTREL
51186 + bool 'ELF text relocations logging (READ HELP)'
51187 + depends on PAX_MPROTECT
51188 + help
51189 + If you say Y here, text relocations will be logged with the filename
51190 + of the offending library or binary. The purpose of the feature is
51191 + to help Linux distribution developers get rid of libraries and
51192 + binaries that need text relocations which hinder the future progress
51193 + of PaX. Only Linux distribution developers should say Y here, and
51194 + never on a production machine, as this option creates an information
51195 + leak that could aid an attacker in defeating the randomization of
51196 + a single memory region. If the sysctl option is enabled, a sysctl
51197 + option with name "audit_textrel" is created.
51198 +
51199 +endmenu
51200 +
51201 +menu "Executable Protections"
51202 +depends on GRKERNSEC
51203 +
51204 +config GRKERNSEC_DMESG
51205 + bool "Dmesg(8) restriction"
51206 + default y if GRKERNSEC_CONFIG_AUTO
51207 + help
51208 + If you say Y here, non-root users will not be able to use dmesg(8)
51209 + to view up to the last 4kb of messages in the kernel's log buffer.
51210 + The kernel's log buffer often contains kernel addresses and other
51211 + identifying information useful to an attacker in fingerprinting a
51212 + system for a targeted exploit.
51213 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51214 + created.
51215 +
51216 +config GRKERNSEC_HARDEN_PTRACE
51217 + bool "Deter ptrace-based process snooping"
51218 + default y if GRKERNSEC_CONFIG_AUTO
51219 + help
51220 + If you say Y here, TTY sniffers and other malicious monitoring
51221 + programs implemented through ptrace will be defeated. If you
51222 + have been using the RBAC system, this option has already been
51223 + enabled for several years for all users, with the ability to make
51224 + fine-grained exceptions.
51225 +
51226 + This option only affects the ability of non-root users to ptrace
51227 + processes that are not a descendent of the ptracing process.
51228 + This means that strace ./binary and gdb ./binary will still work,
51229 + but attaching to arbitrary processes will not. If the sysctl
51230 + option is enabled, a sysctl option with name "harden_ptrace" is
51231 + created.
51232 +
51233 +config GRKERNSEC_PTRACE_READEXEC
51234 + bool "Require read access to ptrace sensitive binaries"
51235 + default y if GRKERNSEC_CONFIG_AUTO
51236 + help
51237 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51238 + binaries. This option is useful in environments that
51239 + remove the read bits (e.g. file mode 4711) from suid binaries to
51240 + prevent infoleaking of their contents. This option adds
51241 + consistency to the use of that file mode, as the binary could normally
51242 + be read out when run without privileges while ptracing.
51243 +
51244 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51245 + is created.
51246 +
51247 +config GRKERNSEC_SETXID
51248 + bool "Enforce consistent multithreaded privileges"
51249 + default y if GRKERNSEC_CONFIG_AUTO
51250 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51251 + help
51252 + If you say Y here, a change from a root uid to a non-root uid
51253 + in a multithreaded application will cause the resulting uids,
51254 + gids, supplementary groups, and capabilities in that thread
51255 + to be propagated to the other threads of the process. In most
51256 + cases this is unnecessary, as glibc will emulate this behavior
51257 + on behalf of the application. Other libcs do not act in the
51258 + same way, allowing the other threads of the process to continue
51259 + running with root privileges. If the sysctl option is enabled,
51260 + a sysctl option with name "consistent_setxid" is created.
51261 +
51262 +config GRKERNSEC_TPE
51263 + bool "Trusted Path Execution (TPE)"
51264 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51265 + help
51266 + If you say Y here, you will be able to choose a gid to add to the
51267 + supplementary groups of users you want to mark as "untrusted."
51268 + These users will not be able to execute any files that are not in
51269 + root-owned directories writable only by root. If the sysctl option
51270 + is enabled, a sysctl option with name "tpe" is created.
51271 +
51272 +config GRKERNSEC_TPE_ALL
51273 + bool "Partially restrict all non-root users"
51274 + depends on GRKERNSEC_TPE
51275 + help
51276 + If you say Y here, all non-root users will be covered under
51277 + a weaker TPE restriction. This is separate from, and in addition to,
51278 + the main TPE options that you have selected elsewhere. Thus, if a
51279 + "trusted" GID is chosen, this restriction applies to even that GID.
51280 + Under this restriction, all non-root users will only be allowed to
51281 + execute files in directories they own that are not group or
51282 + world-writable, or in directories owned by root and writable only by
51283 + root. If the sysctl option is enabled, a sysctl option with name
51284 + "tpe_restrict_all" is created.
51285 +
51286 +config GRKERNSEC_TPE_INVERT
51287 + bool "Invert GID option"
51288 + depends on GRKERNSEC_TPE
51289 + help
51290 + If you say Y here, the group you specify in the TPE configuration will
51291 + decide what group TPE restrictions will be *disabled* for. This
51292 + option is useful if you want TPE restrictions to be applied to most
51293 + users on the system. If the sysctl option is enabled, a sysctl option
51294 + with name "tpe_invert" is created. Unlike other sysctl options, this
51295 + entry will default to on for backward-compatibility.
51296 +
51297 +config GRKERNSEC_TPE_GID
51298 + int
51299 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51300 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51301 +
51302 +config GRKERNSEC_TPE_UNTRUSTED_GID
51303 + int "GID for TPE-untrusted users"
51304 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51305 + default 1005
51306 + help
51307 + Setting this GID determines what group TPE restrictions will be
51308 + *enabled* for. If the sysctl option is enabled, a sysctl option
51309 + with name "tpe_gid" is created.
51310 +
51311 +config GRKERNSEC_TPE_TRUSTED_GID
51312 + int "GID for TPE-trusted users"
51313 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51314 + default 1005
51315 + help
51316 + Setting this GID determines what group TPE restrictions will be
51317 + *disabled* for. If the sysctl option is enabled, a sysctl option
51318 + with name "tpe_gid" is created.
51319 +
51320 +endmenu
51321 +menu "Network Protections"
51322 +depends on GRKERNSEC
51323 +
51324 +config GRKERNSEC_RANDNET
51325 + bool "Larger entropy pools"
51326 + default y if GRKERNSEC_CONFIG_AUTO
51327 + help
51328 + If you say Y here, the entropy pools used for many features of Linux
51329 + and grsecurity will be doubled in size. Since several grsecurity
51330 + features use additional randomness, it is recommended that you say Y
51331 + here. Saying Y here has a similar effect as modifying
51332 + /proc/sys/kernel/random/poolsize.
51333 +
51334 +config GRKERNSEC_BLACKHOLE
51335 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51336 + default y if GRKERNSEC_CONFIG_AUTO
51337 + depends on NET
51338 + help
51339 + If you say Y here, neither TCP resets nor ICMP
51340 + destination-unreachable packets will be sent in response to packets
51341 + sent to ports for which no associated listening process exists.
51342 + This feature supports both IPV4 and IPV6 and exempts the
51343 + loopback interface from blackholing. Enabling this feature
51344 + makes a host more resilient to DoS attacks and reduces network
51345 + visibility against scanners.
51346 +
51347 + The blackhole feature as-implemented is equivalent to the FreeBSD
51348 + blackhole feature, as it prevents RST responses to all packets, not
51349 + just SYNs. Under most application behavior this causes no
51350 + problems, but applications (like haproxy) may not close certain
51351 + connections in a way that cleanly terminates them on the remote
51352 + end, leaving the remote host in LAST_ACK state. Because of this
51353 + side-effect and to prevent intentional LAST_ACK DoSes, this
51354 + feature also adds automatic mitigation against such attacks.
51355 + The mitigation drastically reduces the amount of time a socket
51356 + can spend in LAST_ACK state. If you're using haproxy and not
51357 + all servers it connects to have this option enabled, consider
51358 + disabling this feature on the haproxy host.
51359 +
51360 + If the sysctl option is enabled, two sysctl options with names
51361 + "ip_blackhole" and "lastack_retries" will be created.
51362 + While "ip_blackhole" takes the standard zero/non-zero on/off
51363 + toggle, "lastack_retries" uses the same kinds of values as
51364 + "tcp_retries1" and "tcp_retries2". The default value of 4
51365 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51366 + state.
51367 +
51368 +config GRKERNSEC_SOCKET
51369 + bool "Socket restrictions"
51370 + depends on NET
51371 + help
51372 + If you say Y here, you will be able to choose from several options.
51373 + If you assign a GID on your system and add it to the supplementary
51374 + groups of users you want to restrict socket access to, this patch
51375 + will perform up to three things, based on the option(s) you choose.
51376 +
51377 +config GRKERNSEC_SOCKET_ALL
51378 + bool "Deny any sockets to group"
51379 + depends on GRKERNSEC_SOCKET
51380 + help
51381 + If you say Y here, you will be able to choose a GID of whose users will
51382 + be unable to connect to other hosts from your machine or run server
51383 + applications from your machine. If the sysctl option is enabled, a
51384 + sysctl option with name "socket_all" is created.
51385 +
51386 +config GRKERNSEC_SOCKET_ALL_GID
51387 + int "GID to deny all sockets for"
51388 + depends on GRKERNSEC_SOCKET_ALL
51389 + default 1004
51390 + help
51391 + Here you can choose the GID to disable socket access for. Remember to
51392 + add the users you want socket access disabled for to the GID
51393 + specified here. If the sysctl option is enabled, a sysctl option
51394 + with name "socket_all_gid" is created.
51395 +
51396 +config GRKERNSEC_SOCKET_CLIENT
51397 + bool "Deny client sockets to group"
51398 + depends on GRKERNSEC_SOCKET
51399 + help
51400 + If you say Y here, you will be able to choose a GID of whose users will
51401 + be unable to connect to other hosts from your machine, but will be
51402 + able to run servers. If this option is enabled, all users in the group
51403 + you specify will have to use passive mode when initiating ftp transfers
51404 + from the shell on your machine. If the sysctl option is enabled, a
51405 + sysctl option with name "socket_client" is created.
51406 +
51407 +config GRKERNSEC_SOCKET_CLIENT_GID
51408 + int "GID to deny client sockets for"
51409 + depends on GRKERNSEC_SOCKET_CLIENT
51410 + default 1003
51411 + help
51412 + Here you can choose the GID to disable client socket access for.
51413 + Remember to add the users you want client socket access disabled for to
51414 + the GID specified here. If the sysctl option is enabled, a sysctl
51415 + option with name "socket_client_gid" is created.
51416 +
51417 +config GRKERNSEC_SOCKET_SERVER
51418 + bool "Deny server sockets to group"
51419 + depends on GRKERNSEC_SOCKET
51420 + help
51421 + If you say Y here, you will be able to choose a GID of whose users will
51422 + be unable to run server applications from your machine. If the sysctl
51423 + option is enabled, a sysctl option with name "socket_server" is created.
51424 +
51425 +config GRKERNSEC_SOCKET_SERVER_GID
51426 + int "GID to deny server sockets for"
51427 + depends on GRKERNSEC_SOCKET_SERVER
51428 + default 1002
51429 + help
51430 + Here you can choose the GID to disable server socket access for.
51431 + Remember to add the users you want server socket access disabled for to
51432 + the GID specified here. If the sysctl option is enabled, a sysctl
51433 + option with name "socket_server_gid" is created.
51434 +
51435 +endmenu
51436 +menu "Sysctl Support"
51437 +depends on GRKERNSEC && SYSCTL
51438 +
51439 +config GRKERNSEC_SYSCTL
51440 + bool "Sysctl support"
51441 + default y if GRKERNSEC_CONFIG_AUTO
51442 + help
51443 + If you say Y here, you will be able to change the options that
51444 + grsecurity runs with at bootup, without having to recompile your
51445 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51446 + to enable (1) or disable (0) various features. All the sysctl entries
51447 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51448 + All features enabled in the kernel configuration are disabled at boot
51449 + if you do not say Y to the "Turn on features by default" option.
51450 + All options should be set at startup, and the grsec_lock entry should
51451 + be set to a non-zero value after all the options are set.
51452 + *THIS IS EXTREMELY IMPORTANT*
51453 +
51454 +config GRKERNSEC_SYSCTL_DISTRO
51455 + bool "Extra sysctl support for distro makers (READ HELP)"
51456 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51457 + help
51458 + If you say Y here, additional sysctl options will be created
51459 + for features that affect processes running as root. Therefore,
51460 + it is critical when using this option that the grsec_lock entry be
51461 + enabled after boot. Only distros with prebuilt kernel packages
51462 + with this option enabled that can ensure grsec_lock is enabled
51463 + after boot should use this option.
51464 + *Failure to set grsec_lock after boot makes all grsec features
51465 + this option covers useless*
51466 +
51467 + Currently this option creates the following sysctl entries:
51468 + "Disable Privileged I/O": "disable_priv_io"
51469 +
51470 +config GRKERNSEC_SYSCTL_ON
51471 + bool "Turn on features by default"
51472 + default y if GRKERNSEC_CONFIG_AUTO
51473 + depends on GRKERNSEC_SYSCTL
51474 + help
51475 + If you say Y here, instead of having all features enabled in the
51476 + kernel configuration disabled at boot time, the features will be
51477 + enabled at boot time. It is recommended you say Y here unless
51478 + there is some reason you would want all sysctl-tunable features to
51479 + be disabled by default. As mentioned elsewhere, it is important
51480 + to enable the grsec_lock entry once you have finished modifying
51481 + the sysctl entries.
51482 +
51483 +endmenu
51484 +menu "Logging Options"
51485 +depends on GRKERNSEC
51486 +
51487 +config GRKERNSEC_FLOODTIME
51488 + int "Seconds in between log messages (minimum)"
51489 + default 10
51490 + help
51491 + This option allows you to enforce the number of seconds between
51492 + grsecurity log messages. The default should be suitable for most
51493 + people, however, if you choose to change it, choose a value small enough
51494 + to allow informative logs to be produced, but large enough to
51495 + prevent flooding.
51496 +
51497 +config GRKERNSEC_FLOODBURST
51498 + int "Number of messages in a burst (maximum)"
51499 + default 6
51500 + help
51501 + This option allows you to choose the maximum number of messages allowed
51502 + within the flood time interval you chose in a separate option. The
51503 + default should be suitable for most people, however if you find that
51504 + many of your logs are being interpreted as flooding, you may want to
51505 + raise this value.
51506 +
51507 +endmenu
51508 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51509 new file mode 100644
51510 index 0000000..1b9afa9
51511 --- /dev/null
51512 +++ b/grsecurity/Makefile
51513 @@ -0,0 +1,38 @@
51514 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51515 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51516 +# into an RBAC system
51517 +#
51518 +# All code in this directory and various hooks inserted throughout the kernel
51519 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51520 +# under the GPL v2 or higher
51521 +
51522 +KBUILD_CFLAGS += -Werror
51523 +
51524 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51525 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51526 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51527 +
51528 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51529 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51530 + gracl_learn.o grsec_log.o
51531 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51532 +
51533 +ifdef CONFIG_NET
51534 +obj-y += grsec_sock.o
51535 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51536 +endif
51537 +
51538 +ifndef CONFIG_GRKERNSEC
51539 +obj-y += grsec_disabled.o
51540 +endif
51541 +
51542 +ifdef CONFIG_GRKERNSEC_HIDESYM
51543 +extra-y := grsec_hidesym.o
51544 +$(obj)/grsec_hidesym.o:
51545 + @-chmod -f 500 /boot
51546 + @-chmod -f 500 /lib/modules
51547 + @-chmod -f 500 /lib64/modules
51548 + @-chmod -f 500 /lib32/modules
51549 + @-chmod -f 700 .
51550 + @echo ' grsec: protected kernel image paths'
51551 +endif
51552 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51553 new file mode 100644
51554 index 0000000..07cd799
51555 --- /dev/null
51556 +++ b/grsecurity/gracl.c
51557 @@ -0,0 +1,4017 @@
51558 +#include <linux/kernel.h>
51559 +#include <linux/module.h>
51560 +#include <linux/sched.h>
51561 +#include <linux/mm.h>
51562 +#include <linux/file.h>
51563 +#include <linux/fs.h>
51564 +#include <linux/namei.h>
51565 +#include <linux/mount.h>
51566 +#include <linux/tty.h>
51567 +#include <linux/proc_fs.h>
51568 +#include <linux/lglock.h>
51569 +#include <linux/slab.h>
51570 +#include <linux/vmalloc.h>
51571 +#include <linux/types.h>
51572 +#include <linux/sysctl.h>
51573 +#include <linux/netdevice.h>
51574 +#include <linux/ptrace.h>
51575 +#include <linux/gracl.h>
51576 +#include <linux/gralloc.h>
51577 +#include <linux/security.h>
51578 +#include <linux/grinternal.h>
51579 +#include <linux/pid_namespace.h>
51580 +#include <linux/stop_machine.h>
51581 +#include <linux/fdtable.h>
51582 +#include <linux/percpu.h>
51583 +#include <linux/lglock.h>
51584 +#include "../fs/mount.h"
51585 +
51586 +#include <asm/uaccess.h>
51587 +#include <asm/errno.h>
51588 +#include <asm/mman.h>
51589 +
51590 +extern struct lglock vfsmount_lock;
51591 +
51592 +static struct acl_role_db acl_role_set;
51593 +static struct name_db name_set;
51594 +static struct inodev_db inodev_set;
51595 +
51596 +/* for keeping track of userspace pointers used for subjects, so we
51597 + can share references in the kernel as well
51598 +*/
51599 +
51600 +static struct path real_root;
51601 +
51602 +static struct acl_subj_map_db subj_map_set;
51603 +
51604 +static struct acl_role_label *default_role;
51605 +
51606 +static struct acl_role_label *role_list;
51607 +
51608 +static u16 acl_sp_role_value;
51609 +
51610 +extern char *gr_shared_page[4];
51611 +static DEFINE_MUTEX(gr_dev_mutex);
51612 +DEFINE_RWLOCK(gr_inode_lock);
51613 +
51614 +struct gr_arg *gr_usermode;
51615 +
51616 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51617 +
51618 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51619 +extern void gr_clear_learn_entries(void);
51620 +
51621 +#ifdef CONFIG_GRKERNSEC_RESLOG
51622 +extern void gr_log_resource(const struct task_struct *task,
51623 + const int res, const unsigned long wanted, const int gt);
51624 +#endif
51625 +
51626 +unsigned char *gr_system_salt;
51627 +unsigned char *gr_system_sum;
51628 +
51629 +static struct sprole_pw **acl_special_roles = NULL;
51630 +static __u16 num_sprole_pws = 0;
51631 +
51632 +static struct acl_role_label *kernel_role = NULL;
51633 +
51634 +static unsigned int gr_auth_attempts = 0;
51635 +static unsigned long gr_auth_expires = 0UL;
51636 +
51637 +#ifdef CONFIG_NET
51638 +extern struct vfsmount *sock_mnt;
51639 +#endif
51640 +
51641 +extern struct vfsmount *pipe_mnt;
51642 +extern struct vfsmount *shm_mnt;
51643 +#ifdef CONFIG_HUGETLBFS
51644 +extern struct vfsmount *hugetlbfs_vfsmount;
51645 +#endif
51646 +
51647 +static struct acl_object_label *fakefs_obj_rw;
51648 +static struct acl_object_label *fakefs_obj_rwx;
51649 +
51650 +extern int gr_init_uidset(void);
51651 +extern void gr_free_uidset(void);
51652 +extern void gr_remove_uid(uid_t uid);
51653 +extern int gr_find_uid(uid_t uid);
51654 +
51655 +__inline__ int
51656 +gr_acl_is_enabled(void)
51657 +{
51658 + return (gr_status & GR_READY);
51659 +}
51660 +
51661 +#ifdef CONFIG_BTRFS_FS
51662 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51663 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51664 +#endif
51665 +
51666 +static inline dev_t __get_dev(const struct dentry *dentry)
51667 +{
51668 +#ifdef CONFIG_BTRFS_FS
51669 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51670 + return get_btrfs_dev_from_inode(dentry->d_inode);
51671 + else
51672 +#endif
51673 + return dentry->d_inode->i_sb->s_dev;
51674 +}
51675 +
51676 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51677 +{
51678 + return __get_dev(dentry);
51679 +}
51680 +
51681 +static char gr_task_roletype_to_char(struct task_struct *task)
51682 +{
51683 + switch (task->role->roletype &
51684 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51685 + GR_ROLE_SPECIAL)) {
51686 + case GR_ROLE_DEFAULT:
51687 + return 'D';
51688 + case GR_ROLE_USER:
51689 + return 'U';
51690 + case GR_ROLE_GROUP:
51691 + return 'G';
51692 + case GR_ROLE_SPECIAL:
51693 + return 'S';
51694 + }
51695 +
51696 + return 'X';
51697 +}
51698 +
51699 +char gr_roletype_to_char(void)
51700 +{
51701 + return gr_task_roletype_to_char(current);
51702 +}
51703 +
51704 +__inline__ int
51705 +gr_acl_tpe_check(void)
51706 +{
51707 + if (unlikely(!(gr_status & GR_READY)))
51708 + return 0;
51709 + if (current->role->roletype & GR_ROLE_TPE)
51710 + return 1;
51711 + else
51712 + return 0;
51713 +}
51714 +
51715 +int
51716 +gr_handle_rawio(const struct inode *inode)
51717 +{
51718 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51719 + if (inode && S_ISBLK(inode->i_mode) &&
51720 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51721 + !capable(CAP_SYS_RAWIO))
51722 + return 1;
51723 +#endif
51724 + return 0;
51725 +}
51726 +
51727 +static int
51728 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51729 +{
51730 + if (likely(lena != lenb))
51731 + return 0;
51732 +
51733 + return !memcmp(a, b, lena);
51734 +}
51735 +
51736 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51737 +{
51738 + *buflen -= namelen;
51739 + if (*buflen < 0)
51740 + return -ENAMETOOLONG;
51741 + *buffer -= namelen;
51742 + memcpy(*buffer, str, namelen);
51743 + return 0;
51744 +}
51745 +
51746 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51747 +{
51748 + return prepend(buffer, buflen, name->name, name->len);
51749 +}
51750 +
51751 +static int prepend_path(const struct path *path, struct path *root,
51752 + char **buffer, int *buflen)
51753 +{
51754 + struct dentry *dentry = path->dentry;
51755 + struct vfsmount *vfsmnt = path->mnt;
51756 + struct mount *mnt = real_mount(vfsmnt);
51757 + bool slash = false;
51758 + int error = 0;
51759 +
51760 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51761 + struct dentry * parent;
51762 +
51763 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51764 + /* Global root? */
51765 + if (!mnt_has_parent(mnt)) {
51766 + goto out;
51767 + }
51768 + dentry = mnt->mnt_mountpoint;
51769 + mnt = mnt->mnt_parent;
51770 + vfsmnt = &mnt->mnt;
51771 + continue;
51772 + }
51773 + parent = dentry->d_parent;
51774 + prefetch(parent);
51775 + spin_lock(&dentry->d_lock);
51776 + error = prepend_name(buffer, buflen, &dentry->d_name);
51777 + spin_unlock(&dentry->d_lock);
51778 + if (!error)
51779 + error = prepend(buffer, buflen, "/", 1);
51780 + if (error)
51781 + break;
51782 +
51783 + slash = true;
51784 + dentry = parent;
51785 + }
51786 +
51787 +out:
51788 + if (!error && !slash)
51789 + error = prepend(buffer, buflen, "/", 1);
51790 +
51791 + return error;
51792 +}
51793 +
51794 +/* this must be called with vfsmount_lock and rename_lock held */
51795 +
51796 +static char *__our_d_path(const struct path *path, struct path *root,
51797 + char *buf, int buflen)
51798 +{
51799 + char *res = buf + buflen;
51800 + int error;
51801 +
51802 + prepend(&res, &buflen, "\0", 1);
51803 + error = prepend_path(path, root, &res, &buflen);
51804 + if (error)
51805 + return ERR_PTR(error);
51806 +
51807 + return res;
51808 +}
51809 +
51810 +static char *
51811 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51812 +{
51813 + char *retval;
51814 +
51815 + retval = __our_d_path(path, root, buf, buflen);
51816 + if (unlikely(IS_ERR(retval)))
51817 + retval = strcpy(buf, "<path too long>");
51818 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51819 + retval[1] = '\0';
51820 +
51821 + return retval;
51822 +}
51823 +
51824 +static char *
51825 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51826 + char *buf, int buflen)
51827 +{
51828 + struct path path;
51829 + char *res;
51830 +
51831 + path.dentry = (struct dentry *)dentry;
51832 + path.mnt = (struct vfsmount *)vfsmnt;
51833 +
51834 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51835 + by the RBAC system */
51836 + res = gen_full_path(&path, &real_root, buf, buflen);
51837 +
51838 + return res;
51839 +}
51840 +
51841 +static char *
51842 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51843 + char *buf, int buflen)
51844 +{
51845 + char *res;
51846 + struct path path;
51847 + struct path root;
51848 + struct task_struct *reaper = init_pid_ns.child_reaper;
51849 +
51850 + path.dentry = (struct dentry *)dentry;
51851 + path.mnt = (struct vfsmount *)vfsmnt;
51852 +
51853 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51854 + get_fs_root(reaper->fs, &root);
51855 +
51856 + write_seqlock(&rename_lock);
51857 + br_read_lock(&vfsmount_lock);
51858 + res = gen_full_path(&path, &root, buf, buflen);
51859 + br_read_unlock(&vfsmount_lock);
51860 + write_sequnlock(&rename_lock);
51861 +
51862 + path_put(&root);
51863 + return res;
51864 +}
51865 +
51866 +static char *
51867 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51868 +{
51869 + char *ret;
51870 + write_seqlock(&rename_lock);
51871 + br_read_lock(&vfsmount_lock);
51872 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51873 + PAGE_SIZE);
51874 + br_read_unlock(&vfsmount_lock);
51875 + write_sequnlock(&rename_lock);
51876 + return ret;
51877 +}
51878 +
51879 +static char *
51880 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
51881 +{
51882 + char *ret;
51883 + char *buf;
51884 + int buflen;
51885 +
51886 + write_seqlock(&rename_lock);
51887 + br_read_lock(&vfsmount_lock);
51888 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
51889 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
51890 + buflen = (int)(ret - buf);
51891 + if (buflen >= 5)
51892 + prepend(&ret, &buflen, "/proc", 5);
51893 + else
51894 + ret = strcpy(buf, "<path too long>");
51895 + br_read_unlock(&vfsmount_lock);
51896 + write_sequnlock(&rename_lock);
51897 + return ret;
51898 +}
51899 +
51900 +char *
51901 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
51902 +{
51903 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
51904 + PAGE_SIZE);
51905 +}
51906 +
51907 +char *
51908 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
51909 +{
51910 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
51911 + PAGE_SIZE);
51912 +}
51913 +
51914 +char *
51915 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
51916 +{
51917 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
51918 + PAGE_SIZE);
51919 +}
51920 +
51921 +char *
51922 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
51923 +{
51924 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
51925 + PAGE_SIZE);
51926 +}
51927 +
51928 +char *
51929 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
51930 +{
51931 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
51932 + PAGE_SIZE);
51933 +}
51934 +
51935 +__inline__ __u32
51936 +to_gr_audit(const __u32 reqmode)
51937 +{
51938 + /* masks off auditable permission flags, then shifts them to create
51939 + auditing flags, and adds the special case of append auditing if
51940 + we're requesting write */
51941 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
51942 +}
51943 +
51944 +struct acl_subject_label *
51945 +lookup_subject_map(const struct acl_subject_label *userp)
51946 +{
51947 + unsigned int index = shash(userp, subj_map_set.s_size);
51948 + struct subject_map *match;
51949 +
51950 + match = subj_map_set.s_hash[index];
51951 +
51952 + while (match && match->user != userp)
51953 + match = match->next;
51954 +
51955 + if (match != NULL)
51956 + return match->kernel;
51957 + else
51958 + return NULL;
51959 +}
51960 +
51961 +static void
51962 +insert_subj_map_entry(struct subject_map *subjmap)
51963 +{
51964 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
51965 + struct subject_map **curr;
51966 +
51967 + subjmap->prev = NULL;
51968 +
51969 + curr = &subj_map_set.s_hash[index];
51970 + if (*curr != NULL)
51971 + (*curr)->prev = subjmap;
51972 +
51973 + subjmap->next = *curr;
51974 + *curr = subjmap;
51975 +
51976 + return;
51977 +}
51978 +
51979 +static struct acl_role_label *
51980 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
51981 + const gid_t gid)
51982 +{
51983 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
51984 + struct acl_role_label *match;
51985 + struct role_allowed_ip *ipp;
51986 + unsigned int x;
51987 + u32 curr_ip = task->signal->curr_ip;
51988 +
51989 + task->signal->saved_ip = curr_ip;
51990 +
51991 + match = acl_role_set.r_hash[index];
51992 +
51993 + while (match) {
51994 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
51995 + for (x = 0; x < match->domain_child_num; x++) {
51996 + if (match->domain_children[x] == uid)
51997 + goto found;
51998 + }
51999 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52000 + break;
52001 + match = match->next;
52002 + }
52003 +found:
52004 + if (match == NULL) {
52005 + try_group:
52006 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52007 + match = acl_role_set.r_hash[index];
52008 +
52009 + while (match) {
52010 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52011 + for (x = 0; x < match->domain_child_num; x++) {
52012 + if (match->domain_children[x] == gid)
52013 + goto found2;
52014 + }
52015 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52016 + break;
52017 + match = match->next;
52018 + }
52019 +found2:
52020 + if (match == NULL)
52021 + match = default_role;
52022 + if (match->allowed_ips == NULL)
52023 + return match;
52024 + else {
52025 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52026 + if (likely
52027 + ((ntohl(curr_ip) & ipp->netmask) ==
52028 + (ntohl(ipp->addr) & ipp->netmask)))
52029 + return match;
52030 + }
52031 + match = default_role;
52032 + }
52033 + } else if (match->allowed_ips == NULL) {
52034 + return match;
52035 + } else {
52036 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52037 + if (likely
52038 + ((ntohl(curr_ip) & ipp->netmask) ==
52039 + (ntohl(ipp->addr) & ipp->netmask)))
52040 + return match;
52041 + }
52042 + goto try_group;
52043 + }
52044 +
52045 + return match;
52046 +}
52047 +
52048 +struct acl_subject_label *
52049 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52050 + const struct acl_role_label *role)
52051 +{
52052 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52053 + struct acl_subject_label *match;
52054 +
52055 + match = role->subj_hash[index];
52056 +
52057 + while (match && (match->inode != ino || match->device != dev ||
52058 + (match->mode & GR_DELETED))) {
52059 + match = match->next;
52060 + }
52061 +
52062 + if (match && !(match->mode & GR_DELETED))
52063 + return match;
52064 + else
52065 + return NULL;
52066 +}
52067 +
52068 +struct acl_subject_label *
52069 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52070 + const struct acl_role_label *role)
52071 +{
52072 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52073 + struct acl_subject_label *match;
52074 +
52075 + match = role->subj_hash[index];
52076 +
52077 + while (match && (match->inode != ino || match->device != dev ||
52078 + !(match->mode & GR_DELETED))) {
52079 + match = match->next;
52080 + }
52081 +
52082 + if (match && (match->mode & GR_DELETED))
52083 + return match;
52084 + else
52085 + return NULL;
52086 +}
52087 +
52088 +static struct acl_object_label *
52089 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52090 + const struct acl_subject_label *subj)
52091 +{
52092 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52093 + struct acl_object_label *match;
52094 +
52095 + match = subj->obj_hash[index];
52096 +
52097 + while (match && (match->inode != ino || match->device != dev ||
52098 + (match->mode & GR_DELETED))) {
52099 + match = match->next;
52100 + }
52101 +
52102 + if (match && !(match->mode & GR_DELETED))
52103 + return match;
52104 + else
52105 + return NULL;
52106 +}
52107 +
52108 +static struct acl_object_label *
52109 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52110 + const struct acl_subject_label *subj)
52111 +{
52112 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52113 + struct acl_object_label *match;
52114 +
52115 + match = subj->obj_hash[index];
52116 +
52117 + while (match && (match->inode != ino || match->device != dev ||
52118 + !(match->mode & GR_DELETED))) {
52119 + match = match->next;
52120 + }
52121 +
52122 + if (match && (match->mode & GR_DELETED))
52123 + return match;
52124 +
52125 + match = subj->obj_hash[index];
52126 +
52127 + while (match && (match->inode != ino || match->device != dev ||
52128 + (match->mode & GR_DELETED))) {
52129 + match = match->next;
52130 + }
52131 +
52132 + if (match && !(match->mode & GR_DELETED))
52133 + return match;
52134 + else
52135 + return NULL;
52136 +}
52137 +
52138 +static struct name_entry *
52139 +lookup_name_entry(const char *name)
52140 +{
52141 + unsigned int len = strlen(name);
52142 + unsigned int key = full_name_hash(name, len);
52143 + unsigned int index = key % name_set.n_size;
52144 + struct name_entry *match;
52145 +
52146 + match = name_set.n_hash[index];
52147 +
52148 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52149 + match = match->next;
52150 +
52151 + return match;
52152 +}
52153 +
52154 +static struct name_entry *
52155 +lookup_name_entry_create(const char *name)
52156 +{
52157 + unsigned int len = strlen(name);
52158 + unsigned int key = full_name_hash(name, len);
52159 + unsigned int index = key % name_set.n_size;
52160 + struct name_entry *match;
52161 +
52162 + match = name_set.n_hash[index];
52163 +
52164 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52165 + !match->deleted))
52166 + match = match->next;
52167 +
52168 + if (match && match->deleted)
52169 + return match;
52170 +
52171 + match = name_set.n_hash[index];
52172 +
52173 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52174 + match->deleted))
52175 + match = match->next;
52176 +
52177 + if (match && !match->deleted)
52178 + return match;
52179 + else
52180 + return NULL;
52181 +}
52182 +
52183 +static struct inodev_entry *
52184 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52185 +{
52186 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52187 + struct inodev_entry *match;
52188 +
52189 + match = inodev_set.i_hash[index];
52190 +
52191 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52192 + match = match->next;
52193 +
52194 + return match;
52195 +}
52196 +
52197 +static void
52198 +insert_inodev_entry(struct inodev_entry *entry)
52199 +{
52200 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52201 + inodev_set.i_size);
52202 + struct inodev_entry **curr;
52203 +
52204 + entry->prev = NULL;
52205 +
52206 + curr = &inodev_set.i_hash[index];
52207 + if (*curr != NULL)
52208 + (*curr)->prev = entry;
52209 +
52210 + entry->next = *curr;
52211 + *curr = entry;
52212 +
52213 + return;
52214 +}
52215 +
52216 +static void
52217 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52218 +{
52219 + unsigned int index =
52220 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52221 + struct acl_role_label **curr;
52222 + struct acl_role_label *tmp, *tmp2;
52223 +
52224 + curr = &acl_role_set.r_hash[index];
52225 +
52226 + /* simple case, slot is empty, just set it to our role */
52227 + if (*curr == NULL) {
52228 + *curr = role;
52229 + } else {
52230 + /* example:
52231 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52232 + 2 -> 3
52233 + */
52234 + /* first check to see if we can already be reached via this slot */
52235 + tmp = *curr;
52236 + while (tmp && tmp != role)
52237 + tmp = tmp->next;
52238 + if (tmp == role) {
52239 + /* we don't need to add ourselves to this slot's chain */
52240 + return;
52241 + }
52242 + /* we need to add ourselves to this chain, two cases */
52243 + if (role->next == NULL) {
52244 + /* simple case, append the current chain to our role */
52245 + role->next = *curr;
52246 + *curr = role;
52247 + } else {
52248 + /* 1 -> 2 -> 3 -> 4
52249 + 2 -> 3 -> 4
52250 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52251 + */
52252 + /* trickier case: walk our role's chain until we find
52253 + the role for the start of the current slot's chain */
52254 + tmp = role;
52255 + tmp2 = *curr;
52256 + while (tmp->next && tmp->next != tmp2)
52257 + tmp = tmp->next;
52258 + if (tmp->next == tmp2) {
52259 + /* from example above, we found 3, so just
52260 + replace this slot's chain with ours */
52261 + *curr = role;
52262 + } else {
52263 + /* we didn't find a subset of our role's chain
52264 + in the current slot's chain, so append their
52265 + chain to ours, and set us as the first role in
52266 + the slot's chain
52267 +
52268 + we could fold this case with the case above,
52269 + but making it explicit for clarity
52270 + */
52271 + tmp->next = tmp2;
52272 + *curr = role;
52273 + }
52274 + }
52275 + }
52276 +
52277 + return;
52278 +}
52279 +
52280 +static void
52281 +insert_acl_role_label(struct acl_role_label *role)
52282 +{
52283 + int i;
52284 +
52285 + if (role_list == NULL) {
52286 + role_list = role;
52287 + role->prev = NULL;
52288 + } else {
52289 + role->prev = role_list;
52290 + role_list = role;
52291 + }
52292 +
52293 + /* used for hash chains */
52294 + role->next = NULL;
52295 +
52296 + if (role->roletype & GR_ROLE_DOMAIN) {
52297 + for (i = 0; i < role->domain_child_num; i++)
52298 + __insert_acl_role_label(role, role->domain_children[i]);
52299 + } else
52300 + __insert_acl_role_label(role, role->uidgid);
52301 +}
52302 +
52303 +static int
52304 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52305 +{
52306 + struct name_entry **curr, *nentry;
52307 + struct inodev_entry *ientry;
52308 + unsigned int len = strlen(name);
52309 + unsigned int key = full_name_hash(name, len);
52310 + unsigned int index = key % name_set.n_size;
52311 +
52312 + curr = &name_set.n_hash[index];
52313 +
52314 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52315 + curr = &((*curr)->next);
52316 +
52317 + if (*curr != NULL)
52318 + return 1;
52319 +
52320 + nentry = acl_alloc(sizeof (struct name_entry));
52321 + if (nentry == NULL)
52322 + return 0;
52323 + ientry = acl_alloc(sizeof (struct inodev_entry));
52324 + if (ientry == NULL)
52325 + return 0;
52326 + ientry->nentry = nentry;
52327 +
52328 + nentry->key = key;
52329 + nentry->name = name;
52330 + nentry->inode = inode;
52331 + nentry->device = device;
52332 + nentry->len = len;
52333 + nentry->deleted = deleted;
52334 +
52335 + nentry->prev = NULL;
52336 + curr = &name_set.n_hash[index];
52337 + if (*curr != NULL)
52338 + (*curr)->prev = nentry;
52339 + nentry->next = *curr;
52340 + *curr = nentry;
52341 +
52342 + /* insert us into the table searchable by inode/dev */
52343 + insert_inodev_entry(ientry);
52344 +
52345 + return 1;
52346 +}
52347 +
52348 +static void
52349 +insert_acl_obj_label(struct acl_object_label *obj,
52350 + struct acl_subject_label *subj)
52351 +{
52352 + unsigned int index =
52353 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52354 + struct acl_object_label **curr;
52355 +
52356 +
52357 + obj->prev = NULL;
52358 +
52359 + curr = &subj->obj_hash[index];
52360 + if (*curr != NULL)
52361 + (*curr)->prev = obj;
52362 +
52363 + obj->next = *curr;
52364 + *curr = obj;
52365 +
52366 + return;
52367 +}
52368 +
52369 +static void
52370 +insert_acl_subj_label(struct acl_subject_label *obj,
52371 + struct acl_role_label *role)
52372 +{
52373 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52374 + struct acl_subject_label **curr;
52375 +
52376 + obj->prev = NULL;
52377 +
52378 + curr = &role->subj_hash[index];
52379 + if (*curr != NULL)
52380 + (*curr)->prev = obj;
52381 +
52382 + obj->next = *curr;
52383 + *curr = obj;
52384 +
52385 + return;
52386 +}
52387 +
52388 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52389 +
52390 +static void *
52391 +create_table(__u32 * len, int elementsize)
52392 +{
52393 + unsigned int table_sizes[] = {
52394 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52395 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52396 + 4194301, 8388593, 16777213, 33554393, 67108859
52397 + };
52398 + void *newtable = NULL;
52399 + unsigned int pwr = 0;
52400 +
52401 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52402 + table_sizes[pwr] <= *len)
52403 + pwr++;
52404 +
52405 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52406 + return newtable;
52407 +
52408 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52409 + newtable =
52410 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52411 + else
52412 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52413 +
52414 + *len = table_sizes[pwr];
52415 +
52416 + return newtable;
52417 +}
52418 +
52419 +static int
52420 +init_variables(const struct gr_arg *arg)
52421 +{
52422 + struct task_struct *reaper = init_pid_ns.child_reaper;
52423 + unsigned int stacksize;
52424 +
52425 + subj_map_set.s_size = arg->role_db.num_subjects;
52426 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52427 + name_set.n_size = arg->role_db.num_objects;
52428 + inodev_set.i_size = arg->role_db.num_objects;
52429 +
52430 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52431 + !name_set.n_size || !inodev_set.i_size)
52432 + return 1;
52433 +
52434 + if (!gr_init_uidset())
52435 + return 1;
52436 +
52437 + /* set up the stack that holds allocation info */
52438 +
52439 + stacksize = arg->role_db.num_pointers + 5;
52440 +
52441 + if (!acl_alloc_stack_init(stacksize))
52442 + return 1;
52443 +
52444 + /* grab reference for the real root dentry and vfsmount */
52445 + get_fs_root(reaper->fs, &real_root);
52446 +
52447 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52448 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52449 +#endif
52450 +
52451 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52452 + if (fakefs_obj_rw == NULL)
52453 + return 1;
52454 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52455 +
52456 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52457 + if (fakefs_obj_rwx == NULL)
52458 + return 1;
52459 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52460 +
52461 + subj_map_set.s_hash =
52462 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52463 + acl_role_set.r_hash =
52464 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52465 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52466 + inodev_set.i_hash =
52467 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52468 +
52469 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52470 + !name_set.n_hash || !inodev_set.i_hash)
52471 + return 1;
52472 +
52473 + memset(subj_map_set.s_hash, 0,
52474 + sizeof(struct subject_map *) * subj_map_set.s_size);
52475 + memset(acl_role_set.r_hash, 0,
52476 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52477 + memset(name_set.n_hash, 0,
52478 + sizeof (struct name_entry *) * name_set.n_size);
52479 + memset(inodev_set.i_hash, 0,
52480 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52481 +
52482 + return 0;
52483 +}
52484 +
52485 +/* free information not needed after startup
52486 + currently contains user->kernel pointer mappings for subjects
52487 +*/
52488 +
52489 +static void
52490 +free_init_variables(void)
52491 +{
52492 + __u32 i;
52493 +
52494 + if (subj_map_set.s_hash) {
52495 + for (i = 0; i < subj_map_set.s_size; i++) {
52496 + if (subj_map_set.s_hash[i]) {
52497 + kfree(subj_map_set.s_hash[i]);
52498 + subj_map_set.s_hash[i] = NULL;
52499 + }
52500 + }
52501 +
52502 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52503 + PAGE_SIZE)
52504 + kfree(subj_map_set.s_hash);
52505 + else
52506 + vfree(subj_map_set.s_hash);
52507 + }
52508 +
52509 + return;
52510 +}
52511 +
52512 +static void
52513 +free_variables(void)
52514 +{
52515 + struct acl_subject_label *s;
52516 + struct acl_role_label *r;
52517 + struct task_struct *task, *task2;
52518 + unsigned int x;
52519 +
52520 + gr_clear_learn_entries();
52521 +
52522 + read_lock(&tasklist_lock);
52523 + do_each_thread(task2, task) {
52524 + task->acl_sp_role = 0;
52525 + task->acl_role_id = 0;
52526 + task->acl = NULL;
52527 + task->role = NULL;
52528 + } while_each_thread(task2, task);
52529 + read_unlock(&tasklist_lock);
52530 +
52531 + /* release the reference to the real root dentry and vfsmount */
52532 + path_put(&real_root);
52533 + memset(&real_root, 0, sizeof(real_root));
52534 +
52535 + /* free all object hash tables */
52536 +
52537 + FOR_EACH_ROLE_START(r)
52538 + if (r->subj_hash == NULL)
52539 + goto next_role;
52540 + FOR_EACH_SUBJECT_START(r, s, x)
52541 + if (s->obj_hash == NULL)
52542 + break;
52543 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52544 + kfree(s->obj_hash);
52545 + else
52546 + vfree(s->obj_hash);
52547 + FOR_EACH_SUBJECT_END(s, x)
52548 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52549 + if (s->obj_hash == NULL)
52550 + break;
52551 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52552 + kfree(s->obj_hash);
52553 + else
52554 + vfree(s->obj_hash);
52555 + FOR_EACH_NESTED_SUBJECT_END(s)
52556 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52557 + kfree(r->subj_hash);
52558 + else
52559 + vfree(r->subj_hash);
52560 + r->subj_hash = NULL;
52561 +next_role:
52562 + FOR_EACH_ROLE_END(r)
52563 +
52564 + acl_free_all();
52565 +
52566 + if (acl_role_set.r_hash) {
52567 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52568 + PAGE_SIZE)
52569 + kfree(acl_role_set.r_hash);
52570 + else
52571 + vfree(acl_role_set.r_hash);
52572 + }
52573 + if (name_set.n_hash) {
52574 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52575 + PAGE_SIZE)
52576 + kfree(name_set.n_hash);
52577 + else
52578 + vfree(name_set.n_hash);
52579 + }
52580 +
52581 + if (inodev_set.i_hash) {
52582 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52583 + PAGE_SIZE)
52584 + kfree(inodev_set.i_hash);
52585 + else
52586 + vfree(inodev_set.i_hash);
52587 + }
52588 +
52589 + gr_free_uidset();
52590 +
52591 + memset(&name_set, 0, sizeof (struct name_db));
52592 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52593 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52594 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52595 +
52596 + default_role = NULL;
52597 + kernel_role = NULL;
52598 + role_list = NULL;
52599 +
52600 + return;
52601 +}
52602 +
52603 +static __u32
52604 +count_user_objs(struct acl_object_label *userp)
52605 +{
52606 + struct acl_object_label o_tmp;
52607 + __u32 num = 0;
52608 +
52609 + while (userp) {
52610 + if (copy_from_user(&o_tmp, userp,
52611 + sizeof (struct acl_object_label)))
52612 + break;
52613 +
52614 + userp = o_tmp.prev;
52615 + num++;
52616 + }
52617 +
52618 + return num;
52619 +}
52620 +
52621 +static struct acl_subject_label *
52622 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52623 +
52624 +static int
52625 +copy_user_glob(struct acl_object_label *obj)
52626 +{
52627 + struct acl_object_label *g_tmp, **guser;
52628 + unsigned int len;
52629 + char *tmp;
52630 +
52631 + if (obj->globbed == NULL)
52632 + return 0;
52633 +
52634 + guser = &obj->globbed;
52635 + while (*guser) {
52636 + g_tmp = (struct acl_object_label *)
52637 + acl_alloc(sizeof (struct acl_object_label));
52638 + if (g_tmp == NULL)
52639 + return -ENOMEM;
52640 +
52641 + if (copy_from_user(g_tmp, *guser,
52642 + sizeof (struct acl_object_label)))
52643 + return -EFAULT;
52644 +
52645 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52646 +
52647 + if (!len || len >= PATH_MAX)
52648 + return -EINVAL;
52649 +
52650 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52651 + return -ENOMEM;
52652 +
52653 + if (copy_from_user(tmp, g_tmp->filename, len))
52654 + return -EFAULT;
52655 + tmp[len-1] = '\0';
52656 + g_tmp->filename = tmp;
52657 +
52658 + *guser = g_tmp;
52659 + guser = &(g_tmp->next);
52660 + }
52661 +
52662 + return 0;
52663 +}
52664 +
52665 +static int
52666 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52667 + struct acl_role_label *role)
52668 +{
52669 + struct acl_object_label *o_tmp;
52670 + unsigned int len;
52671 + int ret;
52672 + char *tmp;
52673 +
52674 + while (userp) {
52675 + if ((o_tmp = (struct acl_object_label *)
52676 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52677 + return -ENOMEM;
52678 +
52679 + if (copy_from_user(o_tmp, userp,
52680 + sizeof (struct acl_object_label)))
52681 + return -EFAULT;
52682 +
52683 + userp = o_tmp->prev;
52684 +
52685 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52686 +
52687 + if (!len || len >= PATH_MAX)
52688 + return -EINVAL;
52689 +
52690 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52691 + return -ENOMEM;
52692 +
52693 + if (copy_from_user(tmp, o_tmp->filename, len))
52694 + return -EFAULT;
52695 + tmp[len-1] = '\0';
52696 + o_tmp->filename = tmp;
52697 +
52698 + insert_acl_obj_label(o_tmp, subj);
52699 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52700 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52701 + return -ENOMEM;
52702 +
52703 + ret = copy_user_glob(o_tmp);
52704 + if (ret)
52705 + return ret;
52706 +
52707 + if (o_tmp->nested) {
52708 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52709 + if (IS_ERR(o_tmp->nested))
52710 + return PTR_ERR(o_tmp->nested);
52711 +
52712 + /* insert into nested subject list */
52713 + o_tmp->nested->next = role->hash->first;
52714 + role->hash->first = o_tmp->nested;
52715 + }
52716 + }
52717 +
52718 + return 0;
52719 +}
52720 +
52721 +static __u32
52722 +count_user_subjs(struct acl_subject_label *userp)
52723 +{
52724 + struct acl_subject_label s_tmp;
52725 + __u32 num = 0;
52726 +
52727 + while (userp) {
52728 + if (copy_from_user(&s_tmp, userp,
52729 + sizeof (struct acl_subject_label)))
52730 + break;
52731 +
52732 + userp = s_tmp.prev;
52733 + /* do not count nested subjects against this count, since
52734 + they are not included in the hash table, but are
52735 + attached to objects. We have already counted
52736 + the subjects in userspace for the allocation
52737 + stack
52738 + */
52739 + if (!(s_tmp.mode & GR_NESTED))
52740 + num++;
52741 + }
52742 +
52743 + return num;
52744 +}
52745 +
52746 +static int
52747 +copy_user_allowedips(struct acl_role_label *rolep)
52748 +{
52749 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52750 +
52751 + ruserip = rolep->allowed_ips;
52752 +
52753 + while (ruserip) {
52754 + rlast = rtmp;
52755 +
52756 + if ((rtmp = (struct role_allowed_ip *)
52757 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52758 + return -ENOMEM;
52759 +
52760 + if (copy_from_user(rtmp, ruserip,
52761 + sizeof (struct role_allowed_ip)))
52762 + return -EFAULT;
52763 +
52764 + ruserip = rtmp->prev;
52765 +
52766 + if (!rlast) {
52767 + rtmp->prev = NULL;
52768 + rolep->allowed_ips = rtmp;
52769 + } else {
52770 + rlast->next = rtmp;
52771 + rtmp->prev = rlast;
52772 + }
52773 +
52774 + if (!ruserip)
52775 + rtmp->next = NULL;
52776 + }
52777 +
52778 + return 0;
52779 +}
52780 +
52781 +static int
52782 +copy_user_transitions(struct acl_role_label *rolep)
52783 +{
52784 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52785 +
52786 + unsigned int len;
52787 + char *tmp;
52788 +
52789 + rusertp = rolep->transitions;
52790 +
52791 + while (rusertp) {
52792 + rlast = rtmp;
52793 +
52794 + if ((rtmp = (struct role_transition *)
52795 + acl_alloc(sizeof (struct role_transition))) == NULL)
52796 + return -ENOMEM;
52797 +
52798 + if (copy_from_user(rtmp, rusertp,
52799 + sizeof (struct role_transition)))
52800 + return -EFAULT;
52801 +
52802 + rusertp = rtmp->prev;
52803 +
52804 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52805 +
52806 + if (!len || len >= GR_SPROLE_LEN)
52807 + return -EINVAL;
52808 +
52809 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52810 + return -ENOMEM;
52811 +
52812 + if (copy_from_user(tmp, rtmp->rolename, len))
52813 + return -EFAULT;
52814 + tmp[len-1] = '\0';
52815 + rtmp->rolename = tmp;
52816 +
52817 + if (!rlast) {
52818 + rtmp->prev = NULL;
52819 + rolep->transitions = rtmp;
52820 + } else {
52821 + rlast->next = rtmp;
52822 + rtmp->prev = rlast;
52823 + }
52824 +
52825 + if (!rusertp)
52826 + rtmp->next = NULL;
52827 + }
52828 +
52829 + return 0;
52830 +}
52831 +
52832 +static struct acl_subject_label *
52833 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52834 +{
52835 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52836 + unsigned int len;
52837 + char *tmp;
52838 + __u32 num_objs;
52839 + struct acl_ip_label **i_tmp, *i_utmp2;
52840 + struct gr_hash_struct ghash;
52841 + struct subject_map *subjmap;
52842 + unsigned int i_num;
52843 + int err;
52844 +
52845 + s_tmp = lookup_subject_map(userp);
52846 +
52847 + /* we've already copied this subject into the kernel, just return
52848 + the reference to it, and don't copy it over again
52849 + */
52850 + if (s_tmp)
52851 + return(s_tmp);
52852 +
52853 + if ((s_tmp = (struct acl_subject_label *)
52854 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
52855 + return ERR_PTR(-ENOMEM);
52856 +
52857 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
52858 + if (subjmap == NULL)
52859 + return ERR_PTR(-ENOMEM);
52860 +
52861 + subjmap->user = userp;
52862 + subjmap->kernel = s_tmp;
52863 + insert_subj_map_entry(subjmap);
52864 +
52865 + if (copy_from_user(s_tmp, userp,
52866 + sizeof (struct acl_subject_label)))
52867 + return ERR_PTR(-EFAULT);
52868 +
52869 + len = strnlen_user(s_tmp->filename, PATH_MAX);
52870 +
52871 + if (!len || len >= PATH_MAX)
52872 + return ERR_PTR(-EINVAL);
52873 +
52874 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52875 + return ERR_PTR(-ENOMEM);
52876 +
52877 + if (copy_from_user(tmp, s_tmp->filename, len))
52878 + return ERR_PTR(-EFAULT);
52879 + tmp[len-1] = '\0';
52880 + s_tmp->filename = tmp;
52881 +
52882 + if (!strcmp(s_tmp->filename, "/"))
52883 + role->root_label = s_tmp;
52884 +
52885 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
52886 + return ERR_PTR(-EFAULT);
52887 +
52888 + /* copy user and group transition tables */
52889 +
52890 + if (s_tmp->user_trans_num) {
52891 + uid_t *uidlist;
52892 +
52893 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
52894 + if (uidlist == NULL)
52895 + return ERR_PTR(-ENOMEM);
52896 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
52897 + return ERR_PTR(-EFAULT);
52898 +
52899 + s_tmp->user_transitions = uidlist;
52900 + }
52901 +
52902 + if (s_tmp->group_trans_num) {
52903 + gid_t *gidlist;
52904 +
52905 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
52906 + if (gidlist == NULL)
52907 + return ERR_PTR(-ENOMEM);
52908 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
52909 + return ERR_PTR(-EFAULT);
52910 +
52911 + s_tmp->group_transitions = gidlist;
52912 + }
52913 +
52914 + /* set up object hash table */
52915 + num_objs = count_user_objs(ghash.first);
52916 +
52917 + s_tmp->obj_hash_size = num_objs;
52918 + s_tmp->obj_hash =
52919 + (struct acl_object_label **)
52920 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
52921 +
52922 + if (!s_tmp->obj_hash)
52923 + return ERR_PTR(-ENOMEM);
52924 +
52925 + memset(s_tmp->obj_hash, 0,
52926 + s_tmp->obj_hash_size *
52927 + sizeof (struct acl_object_label *));
52928 +
52929 + /* add in objects */
52930 + err = copy_user_objs(ghash.first, s_tmp, role);
52931 +
52932 + if (err)
52933 + return ERR_PTR(err);
52934 +
52935 + /* set pointer for parent subject */
52936 + if (s_tmp->parent_subject) {
52937 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
52938 +
52939 + if (IS_ERR(s_tmp2))
52940 + return s_tmp2;
52941 +
52942 + s_tmp->parent_subject = s_tmp2;
52943 + }
52944 +
52945 + /* add in ip acls */
52946 +
52947 + if (!s_tmp->ip_num) {
52948 + s_tmp->ips = NULL;
52949 + goto insert;
52950 + }
52951 +
52952 + i_tmp =
52953 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
52954 + sizeof (struct acl_ip_label *));
52955 +
52956 + if (!i_tmp)
52957 + return ERR_PTR(-ENOMEM);
52958 +
52959 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
52960 + *(i_tmp + i_num) =
52961 + (struct acl_ip_label *)
52962 + acl_alloc(sizeof (struct acl_ip_label));
52963 + if (!*(i_tmp + i_num))
52964 + return ERR_PTR(-ENOMEM);
52965 +
52966 + if (copy_from_user
52967 + (&i_utmp2, s_tmp->ips + i_num,
52968 + sizeof (struct acl_ip_label *)))
52969 + return ERR_PTR(-EFAULT);
52970 +
52971 + if (copy_from_user
52972 + (*(i_tmp + i_num), i_utmp2,
52973 + sizeof (struct acl_ip_label)))
52974 + return ERR_PTR(-EFAULT);
52975 +
52976 + if ((*(i_tmp + i_num))->iface == NULL)
52977 + continue;
52978 +
52979 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
52980 + if (!len || len >= IFNAMSIZ)
52981 + return ERR_PTR(-EINVAL);
52982 + tmp = acl_alloc(len);
52983 + if (tmp == NULL)
52984 + return ERR_PTR(-ENOMEM);
52985 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
52986 + return ERR_PTR(-EFAULT);
52987 + (*(i_tmp + i_num))->iface = tmp;
52988 + }
52989 +
52990 + s_tmp->ips = i_tmp;
52991 +
52992 +insert:
52993 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
52994 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
52995 + return ERR_PTR(-ENOMEM);
52996 +
52997 + return s_tmp;
52998 +}
52999 +
53000 +static int
53001 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53002 +{
53003 + struct acl_subject_label s_pre;
53004 + struct acl_subject_label * ret;
53005 + int err;
53006 +
53007 + while (userp) {
53008 + if (copy_from_user(&s_pre, userp,
53009 + sizeof (struct acl_subject_label)))
53010 + return -EFAULT;
53011 +
53012 + /* do not add nested subjects here, add
53013 + while parsing objects
53014 + */
53015 +
53016 + if (s_pre.mode & GR_NESTED) {
53017 + userp = s_pre.prev;
53018 + continue;
53019 + }
53020 +
53021 + ret = do_copy_user_subj(userp, role);
53022 +
53023 + err = PTR_ERR(ret);
53024 + if (IS_ERR(ret))
53025 + return err;
53026 +
53027 + insert_acl_subj_label(ret, role);
53028 +
53029 + userp = s_pre.prev;
53030 + }
53031 +
53032 + return 0;
53033 +}
53034 +
53035 +static int
53036 +copy_user_acl(struct gr_arg *arg)
53037 +{
53038 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53039 + struct sprole_pw *sptmp;
53040 + struct gr_hash_struct *ghash;
53041 + uid_t *domainlist;
53042 + unsigned int r_num;
53043 + unsigned int len;
53044 + char *tmp;
53045 + int err = 0;
53046 + __u16 i;
53047 + __u32 num_subjs;
53048 +
53049 + /* we need a default and kernel role */
53050 + if (arg->role_db.num_roles < 2)
53051 + return -EINVAL;
53052 +
53053 + /* copy special role authentication info from userspace */
53054 +
53055 + num_sprole_pws = arg->num_sprole_pws;
53056 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53057 +
53058 + if (!acl_special_roles && num_sprole_pws)
53059 + return -ENOMEM;
53060 +
53061 + for (i = 0; i < num_sprole_pws; i++) {
53062 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53063 + if (!sptmp)
53064 + return -ENOMEM;
53065 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53066 + sizeof (struct sprole_pw)))
53067 + return -EFAULT;
53068 +
53069 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53070 +
53071 + if (!len || len >= GR_SPROLE_LEN)
53072 + return -EINVAL;
53073 +
53074 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53075 + return -ENOMEM;
53076 +
53077 + if (copy_from_user(tmp, sptmp->rolename, len))
53078 + return -EFAULT;
53079 +
53080 + tmp[len-1] = '\0';
53081 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53082 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53083 +#endif
53084 + sptmp->rolename = tmp;
53085 + acl_special_roles[i] = sptmp;
53086 + }
53087 +
53088 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53089 +
53090 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53091 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53092 +
53093 + if (!r_tmp)
53094 + return -ENOMEM;
53095 +
53096 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53097 + sizeof (struct acl_role_label *)))
53098 + return -EFAULT;
53099 +
53100 + if (copy_from_user(r_tmp, r_utmp2,
53101 + sizeof (struct acl_role_label)))
53102 + return -EFAULT;
53103 +
53104 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53105 +
53106 + if (!len || len >= PATH_MAX)
53107 + return -EINVAL;
53108 +
53109 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53110 + return -ENOMEM;
53111 +
53112 + if (copy_from_user(tmp, r_tmp->rolename, len))
53113 + return -EFAULT;
53114 +
53115 + tmp[len-1] = '\0';
53116 + r_tmp->rolename = tmp;
53117 +
53118 + if (!strcmp(r_tmp->rolename, "default")
53119 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53120 + default_role = r_tmp;
53121 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53122 + kernel_role = r_tmp;
53123 + }
53124 +
53125 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53126 + return -ENOMEM;
53127 +
53128 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53129 + return -EFAULT;
53130 +
53131 + r_tmp->hash = ghash;
53132 +
53133 + num_subjs = count_user_subjs(r_tmp->hash->first);
53134 +
53135 + r_tmp->subj_hash_size = num_subjs;
53136 + r_tmp->subj_hash =
53137 + (struct acl_subject_label **)
53138 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53139 +
53140 + if (!r_tmp->subj_hash)
53141 + return -ENOMEM;
53142 +
53143 + err = copy_user_allowedips(r_tmp);
53144 + if (err)
53145 + return err;
53146 +
53147 + /* copy domain info */
53148 + if (r_tmp->domain_children != NULL) {
53149 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53150 + if (domainlist == NULL)
53151 + return -ENOMEM;
53152 +
53153 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53154 + return -EFAULT;
53155 +
53156 + r_tmp->domain_children = domainlist;
53157 + }
53158 +
53159 + err = copy_user_transitions(r_tmp);
53160 + if (err)
53161 + return err;
53162 +
53163 + memset(r_tmp->subj_hash, 0,
53164 + r_tmp->subj_hash_size *
53165 + sizeof (struct acl_subject_label *));
53166 +
53167 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
53168 +
53169 + if (err)
53170 + return err;
53171 +
53172 + /* set nested subject list to null */
53173 + r_tmp->hash->first = NULL;
53174 +
53175 + insert_acl_role_label(r_tmp);
53176 + }
53177 +
53178 + if (default_role == NULL || kernel_role == NULL)
53179 + return -EINVAL;
53180 +
53181 + return err;
53182 +}
53183 +
53184 +static int
53185 +gracl_init(struct gr_arg *args)
53186 +{
53187 + int error = 0;
53188 +
53189 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53190 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53191 +
53192 + if (init_variables(args)) {
53193 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53194 + error = -ENOMEM;
53195 + free_variables();
53196 + goto out;
53197 + }
53198 +
53199 + error = copy_user_acl(args);
53200 + free_init_variables();
53201 + if (error) {
53202 + free_variables();
53203 + goto out;
53204 + }
53205 +
53206 + if ((error = gr_set_acls(0))) {
53207 + free_variables();
53208 + goto out;
53209 + }
53210 +
53211 + pax_open_kernel();
53212 + gr_status |= GR_READY;
53213 + pax_close_kernel();
53214 +
53215 + out:
53216 + return error;
53217 +}
53218 +
53219 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53220 +
53221 +static int
53222 +glob_match(const char *p, const char *n)
53223 +{
53224 + char c;
53225 +
53226 + while ((c = *p++) != '\0') {
53227 + switch (c) {
53228 + case '?':
53229 + if (*n == '\0')
53230 + return 1;
53231 + else if (*n == '/')
53232 + return 1;
53233 + break;
53234 + case '\\':
53235 + if (*n != c)
53236 + return 1;
53237 + break;
53238 + case '*':
53239 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53240 + if (*n == '/')
53241 + return 1;
53242 + else if (c == '?') {
53243 + if (*n == '\0')
53244 + return 1;
53245 + else
53246 + ++n;
53247 + }
53248 + }
53249 + if (c == '\0') {
53250 + return 0;
53251 + } else {
53252 + const char *endp;
53253 +
53254 + if ((endp = strchr(n, '/')) == NULL)
53255 + endp = n + strlen(n);
53256 +
53257 + if (c == '[') {
53258 + for (--p; n < endp; ++n)
53259 + if (!glob_match(p, n))
53260 + return 0;
53261 + } else if (c == '/') {
53262 + while (*n != '\0' && *n != '/')
53263 + ++n;
53264 + if (*n == '/' && !glob_match(p, n + 1))
53265 + return 0;
53266 + } else {
53267 + for (--p; n < endp; ++n)
53268 + if (*n == c && !glob_match(p, n))
53269 + return 0;
53270 + }
53271 +
53272 + return 1;
53273 + }
53274 + case '[':
53275 + {
53276 + int not;
53277 + char cold;
53278 +
53279 + if (*n == '\0' || *n == '/')
53280 + return 1;
53281 +
53282 + not = (*p == '!' || *p == '^');
53283 + if (not)
53284 + ++p;
53285 +
53286 + c = *p++;
53287 + for (;;) {
53288 + unsigned char fn = (unsigned char)*n;
53289 +
53290 + if (c == '\0')
53291 + return 1;
53292 + else {
53293 + if (c == fn)
53294 + goto matched;
53295 + cold = c;
53296 + c = *p++;
53297 +
53298 + if (c == '-' && *p != ']') {
53299 + unsigned char cend = *p++;
53300 +
53301 + if (cend == '\0')
53302 + return 1;
53303 +
53304 + if (cold <= fn && fn <= cend)
53305 + goto matched;
53306 +
53307 + c = *p++;
53308 + }
53309 + }
53310 +
53311 + if (c == ']')
53312 + break;
53313 + }
53314 + if (!not)
53315 + return 1;
53316 + break;
53317 + matched:
53318 + while (c != ']') {
53319 + if (c == '\0')
53320 + return 1;
53321 +
53322 + c = *p++;
53323 + }
53324 + if (not)
53325 + return 1;
53326 + }
53327 + break;
53328 + default:
53329 + if (c != *n)
53330 + return 1;
53331 + }
53332 +
53333 + ++n;
53334 + }
53335 +
53336 + if (*n == '\0')
53337 + return 0;
53338 +
53339 + if (*n == '/')
53340 + return 0;
53341 +
53342 + return 1;
53343 +}
53344 +
53345 +static struct acl_object_label *
53346 +chk_glob_label(struct acl_object_label *globbed,
53347 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53348 +{
53349 + struct acl_object_label *tmp;
53350 +
53351 + if (*path == NULL)
53352 + *path = gr_to_filename_nolock(dentry, mnt);
53353 +
53354 + tmp = globbed;
53355 +
53356 + while (tmp) {
53357 + if (!glob_match(tmp->filename, *path))
53358 + return tmp;
53359 + tmp = tmp->next;
53360 + }
53361 +
53362 + return NULL;
53363 +}
53364 +
53365 +static struct acl_object_label *
53366 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53367 + const ino_t curr_ino, const dev_t curr_dev,
53368 + const struct acl_subject_label *subj, char **path, const int checkglob)
53369 +{
53370 + struct acl_subject_label *tmpsubj;
53371 + struct acl_object_label *retval;
53372 + struct acl_object_label *retval2;
53373 +
53374 + tmpsubj = (struct acl_subject_label *) subj;
53375 + read_lock(&gr_inode_lock);
53376 + do {
53377 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53378 + if (retval) {
53379 + if (checkglob && retval->globbed) {
53380 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53381 + if (retval2)
53382 + retval = retval2;
53383 + }
53384 + break;
53385 + }
53386 + } while ((tmpsubj = tmpsubj->parent_subject));
53387 + read_unlock(&gr_inode_lock);
53388 +
53389 + return retval;
53390 +}
53391 +
53392 +static __inline__ struct acl_object_label *
53393 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53394 + struct dentry *curr_dentry,
53395 + const struct acl_subject_label *subj, char **path, const int checkglob)
53396 +{
53397 + int newglob = checkglob;
53398 + ino_t inode;
53399 + dev_t device;
53400 +
53401 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53402 + as we don't want a / * rule to match instead of the / object
53403 + don't do this for create lookups that call this function though, since they're looking up
53404 + on the parent and thus need globbing checks on all paths
53405 + */
53406 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53407 + newglob = GR_NO_GLOB;
53408 +
53409 + spin_lock(&curr_dentry->d_lock);
53410 + inode = curr_dentry->d_inode->i_ino;
53411 + device = __get_dev(curr_dentry);
53412 + spin_unlock(&curr_dentry->d_lock);
53413 +
53414 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53415 +}
53416 +
53417 +static struct acl_object_label *
53418 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53419 + const struct acl_subject_label *subj, char *path, const int checkglob)
53420 +{
53421 + struct dentry *dentry = (struct dentry *) l_dentry;
53422 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53423 + struct mount *real_mnt = real_mount(mnt);
53424 + struct acl_object_label *retval;
53425 + struct dentry *parent;
53426 +
53427 + write_seqlock(&rename_lock);
53428 + br_read_lock(&vfsmount_lock);
53429 +
53430 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53431 +#ifdef CONFIG_NET
53432 + mnt == sock_mnt ||
53433 +#endif
53434 +#ifdef CONFIG_HUGETLBFS
53435 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53436 +#endif
53437 + /* ignore Eric Biederman */
53438 + IS_PRIVATE(l_dentry->d_inode))) {
53439 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53440 + goto out;
53441 + }
53442 +
53443 + for (;;) {
53444 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53445 + break;
53446 +
53447 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53448 + if (!mnt_has_parent(real_mnt))
53449 + break;
53450 +
53451 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53452 + if (retval != NULL)
53453 + goto out;
53454 +
53455 + dentry = real_mnt->mnt_mountpoint;
53456 + real_mnt = real_mnt->mnt_parent;
53457 + mnt = &real_mnt->mnt;
53458 + continue;
53459 + }
53460 +
53461 + parent = dentry->d_parent;
53462 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53463 + if (retval != NULL)
53464 + goto out;
53465 +
53466 + dentry = parent;
53467 + }
53468 +
53469 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53470 +
53471 + /* real_root is pinned so we don't have to hold a reference */
53472 + if (retval == NULL)
53473 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53474 +out:
53475 + br_read_unlock(&vfsmount_lock);
53476 + write_sequnlock(&rename_lock);
53477 +
53478 + BUG_ON(retval == NULL);
53479 +
53480 + return retval;
53481 +}
53482 +
53483 +static __inline__ struct acl_object_label *
53484 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53485 + const struct acl_subject_label *subj)
53486 +{
53487 + char *path = NULL;
53488 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53489 +}
53490 +
53491 +static __inline__ struct acl_object_label *
53492 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53493 + const struct acl_subject_label *subj)
53494 +{
53495 + char *path = NULL;
53496 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53497 +}
53498 +
53499 +static __inline__ struct acl_object_label *
53500 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53501 + const struct acl_subject_label *subj, char *path)
53502 +{
53503 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53504 +}
53505 +
53506 +static struct acl_subject_label *
53507 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53508 + const struct acl_role_label *role)
53509 +{
53510 + struct dentry *dentry = (struct dentry *) l_dentry;
53511 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53512 + struct mount *real_mnt = real_mount(mnt);
53513 + struct acl_subject_label *retval;
53514 + struct dentry *parent;
53515 +
53516 + write_seqlock(&rename_lock);
53517 + br_read_lock(&vfsmount_lock);
53518 +
53519 + for (;;) {
53520 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53521 + break;
53522 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53523 + if (!mnt_has_parent(real_mnt))
53524 + break;
53525 +
53526 + spin_lock(&dentry->d_lock);
53527 + read_lock(&gr_inode_lock);
53528 + retval =
53529 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53530 + __get_dev(dentry), role);
53531 + read_unlock(&gr_inode_lock);
53532 + spin_unlock(&dentry->d_lock);
53533 + if (retval != NULL)
53534 + goto out;
53535 +
53536 + dentry = real_mnt->mnt_mountpoint;
53537 + real_mnt = real_mnt->mnt_parent;
53538 + mnt = &real_mnt->mnt;
53539 + continue;
53540 + }
53541 +
53542 + spin_lock(&dentry->d_lock);
53543 + read_lock(&gr_inode_lock);
53544 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53545 + __get_dev(dentry), role);
53546 + read_unlock(&gr_inode_lock);
53547 + parent = dentry->d_parent;
53548 + spin_unlock(&dentry->d_lock);
53549 +
53550 + if (retval != NULL)
53551 + goto out;
53552 +
53553 + dentry = parent;
53554 + }
53555 +
53556 + spin_lock(&dentry->d_lock);
53557 + read_lock(&gr_inode_lock);
53558 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53559 + __get_dev(dentry), role);
53560 + read_unlock(&gr_inode_lock);
53561 + spin_unlock(&dentry->d_lock);
53562 +
53563 + if (unlikely(retval == NULL)) {
53564 + /* real_root is pinned, we don't need to hold a reference */
53565 + read_lock(&gr_inode_lock);
53566 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53567 + __get_dev(real_root.dentry), role);
53568 + read_unlock(&gr_inode_lock);
53569 + }
53570 +out:
53571 + br_read_unlock(&vfsmount_lock);
53572 + write_sequnlock(&rename_lock);
53573 +
53574 + BUG_ON(retval == NULL);
53575 +
53576 + return retval;
53577 +}
53578 +
53579 +static void
53580 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53581 +{
53582 + struct task_struct *task = current;
53583 + const struct cred *cred = current_cred();
53584 +
53585 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53586 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53587 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53588 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53589 +
53590 + return;
53591 +}
53592 +
53593 +static void
53594 +gr_log_learn_id_change(const char type, const unsigned int real,
53595 + const unsigned int effective, const unsigned int fs)
53596 +{
53597 + struct task_struct *task = current;
53598 + const struct cred *cred = current_cred();
53599 +
53600 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53601 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53602 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53603 + type, real, effective, fs, &task->signal->saved_ip);
53604 +
53605 + return;
53606 +}
53607 +
53608 +__u32
53609 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53610 + const struct vfsmount * mnt)
53611 +{
53612 + __u32 retval = mode;
53613 + struct acl_subject_label *curracl;
53614 + struct acl_object_label *currobj;
53615 +
53616 + if (unlikely(!(gr_status & GR_READY)))
53617 + return (mode & ~GR_AUDITS);
53618 +
53619 + curracl = current->acl;
53620 +
53621 + currobj = chk_obj_label(dentry, mnt, curracl);
53622 + retval = currobj->mode & mode;
53623 +
53624 + /* if we're opening a specified transfer file for writing
53625 + (e.g. /dev/initctl), then transfer our role to init
53626 + */
53627 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53628 + current->role->roletype & GR_ROLE_PERSIST)) {
53629 + struct task_struct *task = init_pid_ns.child_reaper;
53630 +
53631 + if (task->role != current->role) {
53632 + task->acl_sp_role = 0;
53633 + task->acl_role_id = current->acl_role_id;
53634 + task->role = current->role;
53635 + rcu_read_lock();
53636 + read_lock(&grsec_exec_file_lock);
53637 + gr_apply_subject_to_task(task);
53638 + read_unlock(&grsec_exec_file_lock);
53639 + rcu_read_unlock();
53640 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53641 + }
53642 + }
53643 +
53644 + if (unlikely
53645 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53646 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53647 + __u32 new_mode = mode;
53648 +
53649 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53650 +
53651 + retval = new_mode;
53652 +
53653 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53654 + new_mode |= GR_INHERIT;
53655 +
53656 + if (!(mode & GR_NOLEARN))
53657 + gr_log_learn(dentry, mnt, new_mode);
53658 + }
53659 +
53660 + return retval;
53661 +}
53662 +
53663 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53664 + const struct dentry *parent,
53665 + const struct vfsmount *mnt)
53666 +{
53667 + struct name_entry *match;
53668 + struct acl_object_label *matchpo;
53669 + struct acl_subject_label *curracl;
53670 + char *path;
53671 +
53672 + if (unlikely(!(gr_status & GR_READY)))
53673 + return NULL;
53674 +
53675 + preempt_disable();
53676 + path = gr_to_filename_rbac(new_dentry, mnt);
53677 + match = lookup_name_entry_create(path);
53678 +
53679 + curracl = current->acl;
53680 +
53681 + if (match) {
53682 + read_lock(&gr_inode_lock);
53683 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53684 + read_unlock(&gr_inode_lock);
53685 +
53686 + if (matchpo) {
53687 + preempt_enable();
53688 + return matchpo;
53689 + }
53690 + }
53691 +
53692 + // lookup parent
53693 +
53694 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53695 +
53696 + preempt_enable();
53697 + return matchpo;
53698 +}
53699 +
53700 +__u32
53701 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53702 + const struct vfsmount * mnt, const __u32 mode)
53703 +{
53704 + struct acl_object_label *matchpo;
53705 + __u32 retval;
53706 +
53707 + if (unlikely(!(gr_status & GR_READY)))
53708 + return (mode & ~GR_AUDITS);
53709 +
53710 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53711 +
53712 + retval = matchpo->mode & mode;
53713 +
53714 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53715 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53716 + __u32 new_mode = mode;
53717 +
53718 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53719 +
53720 + gr_log_learn(new_dentry, mnt, new_mode);
53721 + return new_mode;
53722 + }
53723 +
53724 + return retval;
53725 +}
53726 +
53727 +__u32
53728 +gr_check_link(const struct dentry * new_dentry,
53729 + const struct dentry * parent_dentry,
53730 + const struct vfsmount * parent_mnt,
53731 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53732 +{
53733 + struct acl_object_label *obj;
53734 + __u32 oldmode, newmode;
53735 + __u32 needmode;
53736 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53737 + GR_DELETE | GR_INHERIT;
53738 +
53739 + if (unlikely(!(gr_status & GR_READY)))
53740 + return (GR_CREATE | GR_LINK);
53741 +
53742 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53743 + oldmode = obj->mode;
53744 +
53745 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53746 + newmode = obj->mode;
53747 +
53748 + needmode = newmode & checkmodes;
53749 +
53750 + // old name for hardlink must have at least the permissions of the new name
53751 + if ((oldmode & needmode) != needmode)
53752 + goto bad;
53753 +
53754 + // if old name had restrictions/auditing, make sure the new name does as well
53755 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53756 +
53757 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53758 + if (is_privileged_binary(old_dentry))
53759 + needmode |= GR_SETID;
53760 +
53761 + if ((newmode & needmode) != needmode)
53762 + goto bad;
53763 +
53764 + // enforce minimum permissions
53765 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53766 + return newmode;
53767 +bad:
53768 + needmode = oldmode;
53769 + if (is_privileged_binary(old_dentry))
53770 + needmode |= GR_SETID;
53771 +
53772 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53773 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53774 + return (GR_CREATE | GR_LINK);
53775 + } else if (newmode & GR_SUPPRESS)
53776 + return GR_SUPPRESS;
53777 + else
53778 + return 0;
53779 +}
53780 +
53781 +int
53782 +gr_check_hidden_task(const struct task_struct *task)
53783 +{
53784 + if (unlikely(!(gr_status & GR_READY)))
53785 + return 0;
53786 +
53787 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53788 + return 1;
53789 +
53790 + return 0;
53791 +}
53792 +
53793 +int
53794 +gr_check_protected_task(const struct task_struct *task)
53795 +{
53796 + if (unlikely(!(gr_status & GR_READY) || !task))
53797 + return 0;
53798 +
53799 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53800 + task->acl != current->acl)
53801 + return 1;
53802 +
53803 + return 0;
53804 +}
53805 +
53806 +int
53807 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53808 +{
53809 + struct task_struct *p;
53810 + int ret = 0;
53811 +
53812 + if (unlikely(!(gr_status & GR_READY) || !pid))
53813 + return ret;
53814 +
53815 + read_lock(&tasklist_lock);
53816 + do_each_pid_task(pid, type, p) {
53817 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53818 + p->acl != current->acl) {
53819 + ret = 1;
53820 + goto out;
53821 + }
53822 + } while_each_pid_task(pid, type, p);
53823 +out:
53824 + read_unlock(&tasklist_lock);
53825 +
53826 + return ret;
53827 +}
53828 +
53829 +void
53830 +gr_copy_label(struct task_struct *tsk)
53831 +{
53832 + tsk->signal->used_accept = 0;
53833 + tsk->acl_sp_role = 0;
53834 + tsk->acl_role_id = current->acl_role_id;
53835 + tsk->acl = current->acl;
53836 + tsk->role = current->role;
53837 + tsk->signal->curr_ip = current->signal->curr_ip;
53838 + tsk->signal->saved_ip = current->signal->saved_ip;
53839 + if (current->exec_file)
53840 + get_file(current->exec_file);
53841 + tsk->exec_file = current->exec_file;
53842 + tsk->is_writable = current->is_writable;
53843 + if (unlikely(current->signal->used_accept)) {
53844 + current->signal->curr_ip = 0;
53845 + current->signal->saved_ip = 0;
53846 + }
53847 +
53848 + return;
53849 +}
53850 +
53851 +static void
53852 +gr_set_proc_res(struct task_struct *task)
53853 +{
53854 + struct acl_subject_label *proc;
53855 + unsigned short i;
53856 +
53857 + proc = task->acl;
53858 +
53859 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
53860 + return;
53861 +
53862 + for (i = 0; i < RLIM_NLIMITS; i++) {
53863 + if (!(proc->resmask & (1 << i)))
53864 + continue;
53865 +
53866 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
53867 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
53868 + }
53869 +
53870 + return;
53871 +}
53872 +
53873 +extern int __gr_process_user_ban(struct user_struct *user);
53874 +
53875 +int
53876 +gr_check_user_change(int real, int effective, int fs)
53877 +{
53878 + unsigned int i;
53879 + __u16 num;
53880 + uid_t *uidlist;
53881 + int curuid;
53882 + int realok = 0;
53883 + int effectiveok = 0;
53884 + int fsok = 0;
53885 +
53886 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
53887 + struct user_struct *user;
53888 +
53889 + if (real == -1)
53890 + goto skipit;
53891 +
53892 + user = find_user(real);
53893 + if (user == NULL)
53894 + goto skipit;
53895 +
53896 + if (__gr_process_user_ban(user)) {
53897 + /* for find_user */
53898 + free_uid(user);
53899 + return 1;
53900 + }
53901 +
53902 + /* for find_user */
53903 + free_uid(user);
53904 +
53905 +skipit:
53906 +#endif
53907 +
53908 + if (unlikely(!(gr_status & GR_READY)))
53909 + return 0;
53910 +
53911 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53912 + gr_log_learn_id_change('u', real, effective, fs);
53913 +
53914 + num = current->acl->user_trans_num;
53915 + uidlist = current->acl->user_transitions;
53916 +
53917 + if (uidlist == NULL)
53918 + return 0;
53919 +
53920 + if (real == -1)
53921 + realok = 1;
53922 + if (effective == -1)
53923 + effectiveok = 1;
53924 + if (fs == -1)
53925 + fsok = 1;
53926 +
53927 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
53928 + for (i = 0; i < num; i++) {
53929 + curuid = (int)uidlist[i];
53930 + if (real == curuid)
53931 + realok = 1;
53932 + if (effective == curuid)
53933 + effectiveok = 1;
53934 + if (fs == curuid)
53935 + fsok = 1;
53936 + }
53937 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
53938 + for (i = 0; i < num; i++) {
53939 + curuid = (int)uidlist[i];
53940 + if (real == curuid)
53941 + break;
53942 + if (effective == curuid)
53943 + break;
53944 + if (fs == curuid)
53945 + break;
53946 + }
53947 + /* not in deny list */
53948 + if (i == num) {
53949 + realok = 1;
53950 + effectiveok = 1;
53951 + fsok = 1;
53952 + }
53953 + }
53954 +
53955 + if (realok && effectiveok && fsok)
53956 + return 0;
53957 + else {
53958 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
53959 + return 1;
53960 + }
53961 +}
53962 +
53963 +int
53964 +gr_check_group_change(int real, int effective, int fs)
53965 +{
53966 + unsigned int i;
53967 + __u16 num;
53968 + gid_t *gidlist;
53969 + int curgid;
53970 + int realok = 0;
53971 + int effectiveok = 0;
53972 + int fsok = 0;
53973 +
53974 + if (unlikely(!(gr_status & GR_READY)))
53975 + return 0;
53976 +
53977 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
53978 + gr_log_learn_id_change('g', real, effective, fs);
53979 +
53980 + num = current->acl->group_trans_num;
53981 + gidlist = current->acl->group_transitions;
53982 +
53983 + if (gidlist == NULL)
53984 + return 0;
53985 +
53986 + if (real == -1)
53987 + realok = 1;
53988 + if (effective == -1)
53989 + effectiveok = 1;
53990 + if (fs == -1)
53991 + fsok = 1;
53992 +
53993 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
53994 + for (i = 0; i < num; i++) {
53995 + curgid = (int)gidlist[i];
53996 + if (real == curgid)
53997 + realok = 1;
53998 + if (effective == curgid)
53999 + effectiveok = 1;
54000 + if (fs == curgid)
54001 + fsok = 1;
54002 + }
54003 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54004 + for (i = 0; i < num; i++) {
54005 + curgid = (int)gidlist[i];
54006 + if (real == curgid)
54007 + break;
54008 + if (effective == curgid)
54009 + break;
54010 + if (fs == curgid)
54011 + break;
54012 + }
54013 + /* not in deny list */
54014 + if (i == num) {
54015 + realok = 1;
54016 + effectiveok = 1;
54017 + fsok = 1;
54018 + }
54019 + }
54020 +
54021 + if (realok && effectiveok && fsok)
54022 + return 0;
54023 + else {
54024 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54025 + return 1;
54026 + }
54027 +}
54028 +
54029 +extern int gr_acl_is_capable(const int cap);
54030 +
54031 +void
54032 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54033 +{
54034 + struct acl_role_label *role = task->role;
54035 + struct acl_subject_label *subj = NULL;
54036 + struct acl_object_label *obj;
54037 + struct file *filp;
54038 +
54039 + if (unlikely(!(gr_status & GR_READY)))
54040 + return;
54041 +
54042 + filp = task->exec_file;
54043 +
54044 + /* kernel process, we'll give them the kernel role */
54045 + if (unlikely(!filp)) {
54046 + task->role = kernel_role;
54047 + task->acl = kernel_role->root_label;
54048 + return;
54049 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54050 + role = lookup_acl_role_label(task, uid, gid);
54051 +
54052 + /* don't change the role if we're not a privileged process */
54053 + if (role && task->role != role &&
54054 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54055 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54056 + return;
54057 +
54058 + /* perform subject lookup in possibly new role
54059 + we can use this result below in the case where role == task->role
54060 + */
54061 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54062 +
54063 + /* if we changed uid/gid, but result in the same role
54064 + and are using inheritance, don't lose the inherited subject
54065 + if current subject is other than what normal lookup
54066 + would result in, we arrived via inheritance, don't
54067 + lose subject
54068 + */
54069 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54070 + (subj == task->acl)))
54071 + task->acl = subj;
54072 +
54073 + task->role = role;
54074 +
54075 + task->is_writable = 0;
54076 +
54077 + /* ignore additional mmap checks for processes that are writable
54078 + by the default ACL */
54079 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54080 + if (unlikely(obj->mode & GR_WRITE))
54081 + task->is_writable = 1;
54082 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54083 + if (unlikely(obj->mode & GR_WRITE))
54084 + task->is_writable = 1;
54085 +
54086 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54087 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54088 +#endif
54089 +
54090 + gr_set_proc_res(task);
54091 +
54092 + return;
54093 +}
54094 +
54095 +int
54096 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54097 + const int unsafe_flags)
54098 +{
54099 + struct task_struct *task = current;
54100 + struct acl_subject_label *newacl;
54101 + struct acl_object_label *obj;
54102 + __u32 retmode;
54103 +
54104 + if (unlikely(!(gr_status & GR_READY)))
54105 + return 0;
54106 +
54107 + newacl = chk_subj_label(dentry, mnt, task->role);
54108 +
54109 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54110 + did an exec
54111 + */
54112 + rcu_read_lock();
54113 + read_lock(&tasklist_lock);
54114 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54115 + (task->parent->acl->mode & GR_POVERRIDE))) {
54116 + read_unlock(&tasklist_lock);
54117 + rcu_read_unlock();
54118 + goto skip_check;
54119 + }
54120 + read_unlock(&tasklist_lock);
54121 + rcu_read_unlock();
54122 +
54123 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54124 + !(task->role->roletype & GR_ROLE_GOD) &&
54125 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54126 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54127 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54128 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54129 + else
54130 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54131 + return -EACCES;
54132 + }
54133 +
54134 +skip_check:
54135 +
54136 + obj = chk_obj_label(dentry, mnt, task->acl);
54137 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54138 +
54139 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54140 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54141 + if (obj->nested)
54142 + task->acl = obj->nested;
54143 + else
54144 + task->acl = newacl;
54145 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54146 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54147 +
54148 + task->is_writable = 0;
54149 +
54150 + /* ignore additional mmap checks for processes that are writable
54151 + by the default ACL */
54152 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54153 + if (unlikely(obj->mode & GR_WRITE))
54154 + task->is_writable = 1;
54155 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54156 + if (unlikely(obj->mode & GR_WRITE))
54157 + task->is_writable = 1;
54158 +
54159 + gr_set_proc_res(task);
54160 +
54161 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54162 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54163 +#endif
54164 + return 0;
54165 +}
54166 +
54167 +/* always called with valid inodev ptr */
54168 +static void
54169 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54170 +{
54171 + struct acl_object_label *matchpo;
54172 + struct acl_subject_label *matchps;
54173 + struct acl_subject_label *subj;
54174 + struct acl_role_label *role;
54175 + unsigned int x;
54176 +
54177 + FOR_EACH_ROLE_START(role)
54178 + FOR_EACH_SUBJECT_START(role, subj, x)
54179 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54180 + matchpo->mode |= GR_DELETED;
54181 + FOR_EACH_SUBJECT_END(subj,x)
54182 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54183 + if (subj->inode == ino && subj->device == dev)
54184 + subj->mode |= GR_DELETED;
54185 + FOR_EACH_NESTED_SUBJECT_END(subj)
54186 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54187 + matchps->mode |= GR_DELETED;
54188 + FOR_EACH_ROLE_END(role)
54189 +
54190 + inodev->nentry->deleted = 1;
54191 +
54192 + return;
54193 +}
54194 +
54195 +void
54196 +gr_handle_delete(const ino_t ino, const dev_t dev)
54197 +{
54198 + struct inodev_entry *inodev;
54199 +
54200 + if (unlikely(!(gr_status & GR_READY)))
54201 + return;
54202 +
54203 + write_lock(&gr_inode_lock);
54204 + inodev = lookup_inodev_entry(ino, dev);
54205 + if (inodev != NULL)
54206 + do_handle_delete(inodev, ino, dev);
54207 + write_unlock(&gr_inode_lock);
54208 +
54209 + return;
54210 +}
54211 +
54212 +static void
54213 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54214 + const ino_t newinode, const dev_t newdevice,
54215 + struct acl_subject_label *subj)
54216 +{
54217 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54218 + struct acl_object_label *match;
54219 +
54220 + match = subj->obj_hash[index];
54221 +
54222 + while (match && (match->inode != oldinode ||
54223 + match->device != olddevice ||
54224 + !(match->mode & GR_DELETED)))
54225 + match = match->next;
54226 +
54227 + if (match && (match->inode == oldinode)
54228 + && (match->device == olddevice)
54229 + && (match->mode & GR_DELETED)) {
54230 + if (match->prev == NULL) {
54231 + subj->obj_hash[index] = match->next;
54232 + if (match->next != NULL)
54233 + match->next->prev = NULL;
54234 + } else {
54235 + match->prev->next = match->next;
54236 + if (match->next != NULL)
54237 + match->next->prev = match->prev;
54238 + }
54239 + match->prev = NULL;
54240 + match->next = NULL;
54241 + match->inode = newinode;
54242 + match->device = newdevice;
54243 + match->mode &= ~GR_DELETED;
54244 +
54245 + insert_acl_obj_label(match, subj);
54246 + }
54247 +
54248 + return;
54249 +}
54250 +
54251 +static void
54252 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54253 + const ino_t newinode, const dev_t newdevice,
54254 + struct acl_role_label *role)
54255 +{
54256 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54257 + struct acl_subject_label *match;
54258 +
54259 + match = role->subj_hash[index];
54260 +
54261 + while (match && (match->inode != oldinode ||
54262 + match->device != olddevice ||
54263 + !(match->mode & GR_DELETED)))
54264 + match = match->next;
54265 +
54266 + if (match && (match->inode == oldinode)
54267 + && (match->device == olddevice)
54268 + && (match->mode & GR_DELETED)) {
54269 + if (match->prev == NULL) {
54270 + role->subj_hash[index] = match->next;
54271 + if (match->next != NULL)
54272 + match->next->prev = NULL;
54273 + } else {
54274 + match->prev->next = match->next;
54275 + if (match->next != NULL)
54276 + match->next->prev = match->prev;
54277 + }
54278 + match->prev = NULL;
54279 + match->next = NULL;
54280 + match->inode = newinode;
54281 + match->device = newdevice;
54282 + match->mode &= ~GR_DELETED;
54283 +
54284 + insert_acl_subj_label(match, role);
54285 + }
54286 +
54287 + return;
54288 +}
54289 +
54290 +static void
54291 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54292 + const ino_t newinode, const dev_t newdevice)
54293 +{
54294 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54295 + struct inodev_entry *match;
54296 +
54297 + match = inodev_set.i_hash[index];
54298 +
54299 + while (match && (match->nentry->inode != oldinode ||
54300 + match->nentry->device != olddevice || !match->nentry->deleted))
54301 + match = match->next;
54302 +
54303 + if (match && (match->nentry->inode == oldinode)
54304 + && (match->nentry->device == olddevice) &&
54305 + match->nentry->deleted) {
54306 + if (match->prev == NULL) {
54307 + inodev_set.i_hash[index] = match->next;
54308 + if (match->next != NULL)
54309 + match->next->prev = NULL;
54310 + } else {
54311 + match->prev->next = match->next;
54312 + if (match->next != NULL)
54313 + match->next->prev = match->prev;
54314 + }
54315 + match->prev = NULL;
54316 + match->next = NULL;
54317 + match->nentry->inode = newinode;
54318 + match->nentry->device = newdevice;
54319 + match->nentry->deleted = 0;
54320 +
54321 + insert_inodev_entry(match);
54322 + }
54323 +
54324 + return;
54325 +}
54326 +
54327 +static void
54328 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54329 +{
54330 + struct acl_subject_label *subj;
54331 + struct acl_role_label *role;
54332 + unsigned int x;
54333 +
54334 + FOR_EACH_ROLE_START(role)
54335 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54336 +
54337 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54338 + if ((subj->inode == ino) && (subj->device == dev)) {
54339 + subj->inode = ino;
54340 + subj->device = dev;
54341 + }
54342 + FOR_EACH_NESTED_SUBJECT_END(subj)
54343 + FOR_EACH_SUBJECT_START(role, subj, x)
54344 + update_acl_obj_label(matchn->inode, matchn->device,
54345 + ino, dev, subj);
54346 + FOR_EACH_SUBJECT_END(subj,x)
54347 + FOR_EACH_ROLE_END(role)
54348 +
54349 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54350 +
54351 + return;
54352 +}
54353 +
54354 +static void
54355 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54356 + const struct vfsmount *mnt)
54357 +{
54358 + ino_t ino = dentry->d_inode->i_ino;
54359 + dev_t dev = __get_dev(dentry);
54360 +
54361 + __do_handle_create(matchn, ino, dev);
54362 +
54363 + return;
54364 +}
54365 +
54366 +void
54367 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54368 +{
54369 + struct name_entry *matchn;
54370 +
54371 + if (unlikely(!(gr_status & GR_READY)))
54372 + return;
54373 +
54374 + preempt_disable();
54375 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54376 +
54377 + if (unlikely((unsigned long)matchn)) {
54378 + write_lock(&gr_inode_lock);
54379 + do_handle_create(matchn, dentry, mnt);
54380 + write_unlock(&gr_inode_lock);
54381 + }
54382 + preempt_enable();
54383 +
54384 + return;
54385 +}
54386 +
54387 +void
54388 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54389 +{
54390 + struct name_entry *matchn;
54391 +
54392 + if (unlikely(!(gr_status & GR_READY)))
54393 + return;
54394 +
54395 + preempt_disable();
54396 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54397 +
54398 + if (unlikely((unsigned long)matchn)) {
54399 + write_lock(&gr_inode_lock);
54400 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54401 + write_unlock(&gr_inode_lock);
54402 + }
54403 + preempt_enable();
54404 +
54405 + return;
54406 +}
54407 +
54408 +void
54409 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54410 + struct dentry *old_dentry,
54411 + struct dentry *new_dentry,
54412 + struct vfsmount *mnt, const __u8 replace)
54413 +{
54414 + struct name_entry *matchn;
54415 + struct inodev_entry *inodev;
54416 + struct inode *inode = new_dentry->d_inode;
54417 + ino_t old_ino = old_dentry->d_inode->i_ino;
54418 + dev_t old_dev = __get_dev(old_dentry);
54419 +
54420 + /* vfs_rename swaps the name and parent link for old_dentry and
54421 + new_dentry
54422 + at this point, old_dentry has the new name, parent link, and inode
54423 + for the renamed file
54424 + if a file is being replaced by a rename, new_dentry has the inode
54425 + and name for the replaced file
54426 + */
54427 +
54428 + if (unlikely(!(gr_status & GR_READY)))
54429 + return;
54430 +
54431 + preempt_disable();
54432 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54433 +
54434 + /* we wouldn't have to check d_inode if it weren't for
54435 + NFS silly-renaming
54436 + */
54437 +
54438 + write_lock(&gr_inode_lock);
54439 + if (unlikely(replace && inode)) {
54440 + ino_t new_ino = inode->i_ino;
54441 + dev_t new_dev = __get_dev(new_dentry);
54442 +
54443 + inodev = lookup_inodev_entry(new_ino, new_dev);
54444 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54445 + do_handle_delete(inodev, new_ino, new_dev);
54446 + }
54447 +
54448 + inodev = lookup_inodev_entry(old_ino, old_dev);
54449 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54450 + do_handle_delete(inodev, old_ino, old_dev);
54451 +
54452 + if (unlikely((unsigned long)matchn))
54453 + do_handle_create(matchn, old_dentry, mnt);
54454 +
54455 + write_unlock(&gr_inode_lock);
54456 + preempt_enable();
54457 +
54458 + return;
54459 +}
54460 +
54461 +static int
54462 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54463 + unsigned char **sum)
54464 +{
54465 + struct acl_role_label *r;
54466 + struct role_allowed_ip *ipp;
54467 + struct role_transition *trans;
54468 + unsigned int i;
54469 + int found = 0;
54470 + u32 curr_ip = current->signal->curr_ip;
54471 +
54472 + current->signal->saved_ip = curr_ip;
54473 +
54474 + /* check transition table */
54475 +
54476 + for (trans = current->role->transitions; trans; trans = trans->next) {
54477 + if (!strcmp(rolename, trans->rolename)) {
54478 + found = 1;
54479 + break;
54480 + }
54481 + }
54482 +
54483 + if (!found)
54484 + return 0;
54485 +
54486 + /* handle special roles that do not require authentication
54487 + and check ip */
54488 +
54489 + FOR_EACH_ROLE_START(r)
54490 + if (!strcmp(rolename, r->rolename) &&
54491 + (r->roletype & GR_ROLE_SPECIAL)) {
54492 + found = 0;
54493 + if (r->allowed_ips != NULL) {
54494 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54495 + if ((ntohl(curr_ip) & ipp->netmask) ==
54496 + (ntohl(ipp->addr) & ipp->netmask))
54497 + found = 1;
54498 + }
54499 + } else
54500 + found = 2;
54501 + if (!found)
54502 + return 0;
54503 +
54504 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54505 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54506 + *salt = NULL;
54507 + *sum = NULL;
54508 + return 1;
54509 + }
54510 + }
54511 + FOR_EACH_ROLE_END(r)
54512 +
54513 + for (i = 0; i < num_sprole_pws; i++) {
54514 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54515 + *salt = acl_special_roles[i]->salt;
54516 + *sum = acl_special_roles[i]->sum;
54517 + return 1;
54518 + }
54519 + }
54520 +
54521 + return 0;
54522 +}
54523 +
54524 +static void
54525 +assign_special_role(char *rolename)
54526 +{
54527 + struct acl_object_label *obj;
54528 + struct acl_role_label *r;
54529 + struct acl_role_label *assigned = NULL;
54530 + struct task_struct *tsk;
54531 + struct file *filp;
54532 +
54533 + FOR_EACH_ROLE_START(r)
54534 + if (!strcmp(rolename, r->rolename) &&
54535 + (r->roletype & GR_ROLE_SPECIAL)) {
54536 + assigned = r;
54537 + break;
54538 + }
54539 + FOR_EACH_ROLE_END(r)
54540 +
54541 + if (!assigned)
54542 + return;
54543 +
54544 + read_lock(&tasklist_lock);
54545 + read_lock(&grsec_exec_file_lock);
54546 +
54547 + tsk = current->real_parent;
54548 + if (tsk == NULL)
54549 + goto out_unlock;
54550 +
54551 + filp = tsk->exec_file;
54552 + if (filp == NULL)
54553 + goto out_unlock;
54554 +
54555 + tsk->is_writable = 0;
54556 +
54557 + tsk->acl_sp_role = 1;
54558 + tsk->acl_role_id = ++acl_sp_role_value;
54559 + tsk->role = assigned;
54560 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54561 +
54562 + /* ignore additional mmap checks for processes that are writable
54563 + by the default ACL */
54564 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54565 + if (unlikely(obj->mode & GR_WRITE))
54566 + tsk->is_writable = 1;
54567 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54568 + if (unlikely(obj->mode & GR_WRITE))
54569 + tsk->is_writable = 1;
54570 +
54571 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54572 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54573 +#endif
54574 +
54575 +out_unlock:
54576 + read_unlock(&grsec_exec_file_lock);
54577 + read_unlock(&tasklist_lock);
54578 + return;
54579 +}
54580 +
54581 +int gr_check_secure_terminal(struct task_struct *task)
54582 +{
54583 + struct task_struct *p, *p2, *p3;
54584 + struct files_struct *files;
54585 + struct fdtable *fdt;
54586 + struct file *our_file = NULL, *file;
54587 + int i;
54588 +
54589 + if (task->signal->tty == NULL)
54590 + return 1;
54591 +
54592 + files = get_files_struct(task);
54593 + if (files != NULL) {
54594 + rcu_read_lock();
54595 + fdt = files_fdtable(files);
54596 + for (i=0; i < fdt->max_fds; i++) {
54597 + file = fcheck_files(files, i);
54598 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54599 + get_file(file);
54600 + our_file = file;
54601 + }
54602 + }
54603 + rcu_read_unlock();
54604 + put_files_struct(files);
54605 + }
54606 +
54607 + if (our_file == NULL)
54608 + return 1;
54609 +
54610 + read_lock(&tasklist_lock);
54611 + do_each_thread(p2, p) {
54612 + files = get_files_struct(p);
54613 + if (files == NULL ||
54614 + (p->signal && p->signal->tty == task->signal->tty)) {
54615 + if (files != NULL)
54616 + put_files_struct(files);
54617 + continue;
54618 + }
54619 + rcu_read_lock();
54620 + fdt = files_fdtable(files);
54621 + for (i=0; i < fdt->max_fds; i++) {
54622 + file = fcheck_files(files, i);
54623 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54624 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54625 + p3 = task;
54626 + while (p3->pid > 0) {
54627 + if (p3 == p)
54628 + break;
54629 + p3 = p3->real_parent;
54630 + }
54631 + if (p3 == p)
54632 + break;
54633 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54634 + gr_handle_alertkill(p);
54635 + rcu_read_unlock();
54636 + put_files_struct(files);
54637 + read_unlock(&tasklist_lock);
54638 + fput(our_file);
54639 + return 0;
54640 + }
54641 + }
54642 + rcu_read_unlock();
54643 + put_files_struct(files);
54644 + } while_each_thread(p2, p);
54645 + read_unlock(&tasklist_lock);
54646 +
54647 + fput(our_file);
54648 + return 1;
54649 +}
54650 +
54651 +static int gr_rbac_disable(void *unused)
54652 +{
54653 + pax_open_kernel();
54654 + gr_status &= ~GR_READY;
54655 + pax_close_kernel();
54656 +
54657 + return 0;
54658 +}
54659 +
54660 +ssize_t
54661 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54662 +{
54663 + struct gr_arg_wrapper uwrap;
54664 + unsigned char *sprole_salt = NULL;
54665 + unsigned char *sprole_sum = NULL;
54666 + int error = sizeof (struct gr_arg_wrapper);
54667 + int error2 = 0;
54668 +
54669 + mutex_lock(&gr_dev_mutex);
54670 +
54671 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54672 + error = -EPERM;
54673 + goto out;
54674 + }
54675 +
54676 + if (count != sizeof (struct gr_arg_wrapper)) {
54677 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54678 + error = -EINVAL;
54679 + goto out;
54680 + }
54681 +
54682 +
54683 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54684 + gr_auth_expires = 0;
54685 + gr_auth_attempts = 0;
54686 + }
54687 +
54688 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54689 + error = -EFAULT;
54690 + goto out;
54691 + }
54692 +
54693 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54694 + error = -EINVAL;
54695 + goto out;
54696 + }
54697 +
54698 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54699 + error = -EFAULT;
54700 + goto out;
54701 + }
54702 +
54703 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54704 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54705 + time_after(gr_auth_expires, get_seconds())) {
54706 + error = -EBUSY;
54707 + goto out;
54708 + }
54709 +
54710 + /* if non-root trying to do anything other than use a special role,
54711 + do not attempt authentication, do not count towards authentication
54712 + locking
54713 + */
54714 +
54715 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54716 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54717 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54718 + error = -EPERM;
54719 + goto out;
54720 + }
54721 +
54722 + /* ensure pw and special role name are null terminated */
54723 +
54724 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54725 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54726 +
54727 + /* Okay.
54728 + * We have our enough of the argument structure..(we have yet
54729 + * to copy_from_user the tables themselves) . Copy the tables
54730 + * only if we need them, i.e. for loading operations. */
54731 +
54732 + switch (gr_usermode->mode) {
54733 + case GR_STATUS:
54734 + if (gr_status & GR_READY) {
54735 + error = 1;
54736 + if (!gr_check_secure_terminal(current))
54737 + error = 3;
54738 + } else
54739 + error = 2;
54740 + goto out;
54741 + case GR_SHUTDOWN:
54742 + if ((gr_status & GR_READY)
54743 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54744 + stop_machine(gr_rbac_disable, NULL, NULL);
54745 + free_variables();
54746 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54747 + memset(gr_system_salt, 0, GR_SALT_LEN);
54748 + memset(gr_system_sum, 0, GR_SHA_LEN);
54749 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54750 + } else if (gr_status & GR_READY) {
54751 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54752 + error = -EPERM;
54753 + } else {
54754 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54755 + error = -EAGAIN;
54756 + }
54757 + break;
54758 + case GR_ENABLE:
54759 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54760 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54761 + else {
54762 + if (gr_status & GR_READY)
54763 + error = -EAGAIN;
54764 + else
54765 + error = error2;
54766 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54767 + }
54768 + break;
54769 + case GR_RELOAD:
54770 + if (!(gr_status & GR_READY)) {
54771 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54772 + error = -EAGAIN;
54773 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54774 + stop_machine(gr_rbac_disable, NULL, NULL);
54775 + free_variables();
54776 + error2 = gracl_init(gr_usermode);
54777 + if (!error2)
54778 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54779 + else {
54780 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54781 + error = error2;
54782 + }
54783 + } else {
54784 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54785 + error = -EPERM;
54786 + }
54787 + break;
54788 + case GR_SEGVMOD:
54789 + if (unlikely(!(gr_status & GR_READY))) {
54790 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54791 + error = -EAGAIN;
54792 + break;
54793 + }
54794 +
54795 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54796 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54797 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54798 + struct acl_subject_label *segvacl;
54799 + segvacl =
54800 + lookup_acl_subj_label(gr_usermode->segv_inode,
54801 + gr_usermode->segv_device,
54802 + current->role);
54803 + if (segvacl) {
54804 + segvacl->crashes = 0;
54805 + segvacl->expires = 0;
54806 + }
54807 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54808 + gr_remove_uid(gr_usermode->segv_uid);
54809 + }
54810 + } else {
54811 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54812 + error = -EPERM;
54813 + }
54814 + break;
54815 + case GR_SPROLE:
54816 + case GR_SPROLEPAM:
54817 + if (unlikely(!(gr_status & GR_READY))) {
54818 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54819 + error = -EAGAIN;
54820 + break;
54821 + }
54822 +
54823 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54824 + current->role->expires = 0;
54825 + current->role->auth_attempts = 0;
54826 + }
54827 +
54828 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54829 + time_after(current->role->expires, get_seconds())) {
54830 + error = -EBUSY;
54831 + goto out;
54832 + }
54833 +
54834 + if (lookup_special_role_auth
54835 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54836 + && ((!sprole_salt && !sprole_sum)
54837 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54838 + char *p = "";
54839 + assign_special_role(gr_usermode->sp_role);
54840 + read_lock(&tasklist_lock);
54841 + if (current->real_parent)
54842 + p = current->real_parent->role->rolename;
54843 + read_unlock(&tasklist_lock);
54844 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54845 + p, acl_sp_role_value);
54846 + } else {
54847 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54848 + error = -EPERM;
54849 + if(!(current->role->auth_attempts++))
54850 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54851 +
54852 + goto out;
54853 + }
54854 + break;
54855 + case GR_UNSPROLE:
54856 + if (unlikely(!(gr_status & GR_READY))) {
54857 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
54858 + error = -EAGAIN;
54859 + break;
54860 + }
54861 +
54862 + if (current->role->roletype & GR_ROLE_SPECIAL) {
54863 + char *p = "";
54864 + int i = 0;
54865 +
54866 + read_lock(&tasklist_lock);
54867 + if (current->real_parent) {
54868 + p = current->real_parent->role->rolename;
54869 + i = current->real_parent->acl_role_id;
54870 + }
54871 + read_unlock(&tasklist_lock);
54872 +
54873 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
54874 + gr_set_acls(1);
54875 + } else {
54876 + error = -EPERM;
54877 + goto out;
54878 + }
54879 + break;
54880 + default:
54881 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
54882 + error = -EINVAL;
54883 + break;
54884 + }
54885 +
54886 + if (error != -EPERM)
54887 + goto out;
54888 +
54889 + if(!(gr_auth_attempts++))
54890 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54891 +
54892 + out:
54893 + mutex_unlock(&gr_dev_mutex);
54894 + return error;
54895 +}
54896 +
54897 +/* must be called with
54898 + rcu_read_lock();
54899 + read_lock(&tasklist_lock);
54900 + read_lock(&grsec_exec_file_lock);
54901 +*/
54902 +int gr_apply_subject_to_task(struct task_struct *task)
54903 +{
54904 + struct acl_object_label *obj;
54905 + char *tmpname;
54906 + struct acl_subject_label *tmpsubj;
54907 + struct file *filp;
54908 + struct name_entry *nmatch;
54909 +
54910 + filp = task->exec_file;
54911 + if (filp == NULL)
54912 + return 0;
54913 +
54914 + /* the following is to apply the correct subject
54915 + on binaries running when the RBAC system
54916 + is enabled, when the binaries have been
54917 + replaced or deleted since their execution
54918 + -----
54919 + when the RBAC system starts, the inode/dev
54920 + from exec_file will be one the RBAC system
54921 + is unaware of. It only knows the inode/dev
54922 + of the present file on disk, or the absence
54923 + of it.
54924 + */
54925 + preempt_disable();
54926 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
54927 +
54928 + nmatch = lookup_name_entry(tmpname);
54929 + preempt_enable();
54930 + tmpsubj = NULL;
54931 + if (nmatch) {
54932 + if (nmatch->deleted)
54933 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
54934 + else
54935 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
54936 + if (tmpsubj != NULL)
54937 + task->acl = tmpsubj;
54938 + }
54939 + if (tmpsubj == NULL)
54940 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
54941 + task->role);
54942 + if (task->acl) {
54943 + task->is_writable = 0;
54944 + /* ignore additional mmap checks for processes that are writable
54945 + by the default ACL */
54946 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54947 + if (unlikely(obj->mode & GR_WRITE))
54948 + task->is_writable = 1;
54949 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54950 + if (unlikely(obj->mode & GR_WRITE))
54951 + task->is_writable = 1;
54952 +
54953 + gr_set_proc_res(task);
54954 +
54955 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54956 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54957 +#endif
54958 + } else {
54959 + return 1;
54960 + }
54961 +
54962 + return 0;
54963 +}
54964 +
54965 +int
54966 +gr_set_acls(const int type)
54967 +{
54968 + struct task_struct *task, *task2;
54969 + struct acl_role_label *role = current->role;
54970 + __u16 acl_role_id = current->acl_role_id;
54971 + const struct cred *cred;
54972 + int ret;
54973 +
54974 + rcu_read_lock();
54975 + read_lock(&tasklist_lock);
54976 + read_lock(&grsec_exec_file_lock);
54977 + do_each_thread(task2, task) {
54978 + /* check to see if we're called from the exit handler,
54979 + if so, only replace ACLs that have inherited the admin
54980 + ACL */
54981 +
54982 + if (type && (task->role != role ||
54983 + task->acl_role_id != acl_role_id))
54984 + continue;
54985 +
54986 + task->acl_role_id = 0;
54987 + task->acl_sp_role = 0;
54988 +
54989 + if (task->exec_file) {
54990 + cred = __task_cred(task);
54991 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
54992 + ret = gr_apply_subject_to_task(task);
54993 + if (ret) {
54994 + read_unlock(&grsec_exec_file_lock);
54995 + read_unlock(&tasklist_lock);
54996 + rcu_read_unlock();
54997 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
54998 + return ret;
54999 + }
55000 + } else {
55001 + // it's a kernel process
55002 + task->role = kernel_role;
55003 + task->acl = kernel_role->root_label;
55004 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55005 + task->acl->mode &= ~GR_PROCFIND;
55006 +#endif
55007 + }
55008 + } while_each_thread(task2, task);
55009 + read_unlock(&grsec_exec_file_lock);
55010 + read_unlock(&tasklist_lock);
55011 + rcu_read_unlock();
55012 +
55013 + return 0;
55014 +}
55015 +
55016 +void
55017 +gr_learn_resource(const struct task_struct *task,
55018 + const int res, const unsigned long wanted, const int gt)
55019 +{
55020 + struct acl_subject_label *acl;
55021 + const struct cred *cred;
55022 +
55023 + if (unlikely((gr_status & GR_READY) &&
55024 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55025 + goto skip_reslog;
55026 +
55027 +#ifdef CONFIG_GRKERNSEC_RESLOG
55028 + gr_log_resource(task, res, wanted, gt);
55029 +#endif
55030 + skip_reslog:
55031 +
55032 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55033 + return;
55034 +
55035 + acl = task->acl;
55036 +
55037 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55038 + !(acl->resmask & (1 << (unsigned short) res))))
55039 + return;
55040 +
55041 + if (wanted >= acl->res[res].rlim_cur) {
55042 + unsigned long res_add;
55043 +
55044 + res_add = wanted;
55045 + switch (res) {
55046 + case RLIMIT_CPU:
55047 + res_add += GR_RLIM_CPU_BUMP;
55048 + break;
55049 + case RLIMIT_FSIZE:
55050 + res_add += GR_RLIM_FSIZE_BUMP;
55051 + break;
55052 + case RLIMIT_DATA:
55053 + res_add += GR_RLIM_DATA_BUMP;
55054 + break;
55055 + case RLIMIT_STACK:
55056 + res_add += GR_RLIM_STACK_BUMP;
55057 + break;
55058 + case RLIMIT_CORE:
55059 + res_add += GR_RLIM_CORE_BUMP;
55060 + break;
55061 + case RLIMIT_RSS:
55062 + res_add += GR_RLIM_RSS_BUMP;
55063 + break;
55064 + case RLIMIT_NPROC:
55065 + res_add += GR_RLIM_NPROC_BUMP;
55066 + break;
55067 + case RLIMIT_NOFILE:
55068 + res_add += GR_RLIM_NOFILE_BUMP;
55069 + break;
55070 + case RLIMIT_MEMLOCK:
55071 + res_add += GR_RLIM_MEMLOCK_BUMP;
55072 + break;
55073 + case RLIMIT_AS:
55074 + res_add += GR_RLIM_AS_BUMP;
55075 + break;
55076 + case RLIMIT_LOCKS:
55077 + res_add += GR_RLIM_LOCKS_BUMP;
55078 + break;
55079 + case RLIMIT_SIGPENDING:
55080 + res_add += GR_RLIM_SIGPENDING_BUMP;
55081 + break;
55082 + case RLIMIT_MSGQUEUE:
55083 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55084 + break;
55085 + case RLIMIT_NICE:
55086 + res_add += GR_RLIM_NICE_BUMP;
55087 + break;
55088 + case RLIMIT_RTPRIO:
55089 + res_add += GR_RLIM_RTPRIO_BUMP;
55090 + break;
55091 + case RLIMIT_RTTIME:
55092 + res_add += GR_RLIM_RTTIME_BUMP;
55093 + break;
55094 + }
55095 +
55096 + acl->res[res].rlim_cur = res_add;
55097 +
55098 + if (wanted > acl->res[res].rlim_max)
55099 + acl->res[res].rlim_max = res_add;
55100 +
55101 + /* only log the subject filename, since resource logging is supported for
55102 + single-subject learning only */
55103 + rcu_read_lock();
55104 + cred = __task_cred(task);
55105 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55106 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55107 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55108 + "", (unsigned long) res, &task->signal->saved_ip);
55109 + rcu_read_unlock();
55110 + }
55111 +
55112 + return;
55113 +}
55114 +
55115 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55116 +void
55117 +pax_set_initial_flags(struct linux_binprm *bprm)
55118 +{
55119 + struct task_struct *task = current;
55120 + struct acl_subject_label *proc;
55121 + unsigned long flags;
55122 +
55123 + if (unlikely(!(gr_status & GR_READY)))
55124 + return;
55125 +
55126 + flags = pax_get_flags(task);
55127 +
55128 + proc = task->acl;
55129 +
55130 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55131 + flags &= ~MF_PAX_PAGEEXEC;
55132 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55133 + flags &= ~MF_PAX_SEGMEXEC;
55134 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55135 + flags &= ~MF_PAX_RANDMMAP;
55136 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55137 + flags &= ~MF_PAX_EMUTRAMP;
55138 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55139 + flags &= ~MF_PAX_MPROTECT;
55140 +
55141 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55142 + flags |= MF_PAX_PAGEEXEC;
55143 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55144 + flags |= MF_PAX_SEGMEXEC;
55145 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55146 + flags |= MF_PAX_RANDMMAP;
55147 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55148 + flags |= MF_PAX_EMUTRAMP;
55149 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55150 + flags |= MF_PAX_MPROTECT;
55151 +
55152 + pax_set_flags(task, flags);
55153 +
55154 + return;
55155 +}
55156 +#endif
55157 +
55158 +int
55159 +gr_handle_proc_ptrace(struct task_struct *task)
55160 +{
55161 + struct file *filp;
55162 + struct task_struct *tmp = task;
55163 + struct task_struct *curtemp = current;
55164 + __u32 retmode;
55165 +
55166 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55167 + if (unlikely(!(gr_status & GR_READY)))
55168 + return 0;
55169 +#endif
55170 +
55171 + read_lock(&tasklist_lock);
55172 + read_lock(&grsec_exec_file_lock);
55173 + filp = task->exec_file;
55174 +
55175 + while (tmp->pid > 0) {
55176 + if (tmp == curtemp)
55177 + break;
55178 + tmp = tmp->real_parent;
55179 + }
55180 +
55181 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55182 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55183 + read_unlock(&grsec_exec_file_lock);
55184 + read_unlock(&tasklist_lock);
55185 + return 1;
55186 + }
55187 +
55188 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55189 + if (!(gr_status & GR_READY)) {
55190 + read_unlock(&grsec_exec_file_lock);
55191 + read_unlock(&tasklist_lock);
55192 + return 0;
55193 + }
55194 +#endif
55195 +
55196 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55197 + read_unlock(&grsec_exec_file_lock);
55198 + read_unlock(&tasklist_lock);
55199 +
55200 + if (retmode & GR_NOPTRACE)
55201 + return 1;
55202 +
55203 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55204 + && (current->acl != task->acl || (current->acl != current->role->root_label
55205 + && current->pid != task->pid)))
55206 + return 1;
55207 +
55208 + return 0;
55209 +}
55210 +
55211 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55212 +{
55213 + if (unlikely(!(gr_status & GR_READY)))
55214 + return;
55215 +
55216 + if (!(current->role->roletype & GR_ROLE_GOD))
55217 + return;
55218 +
55219 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55220 + p->role->rolename, gr_task_roletype_to_char(p),
55221 + p->acl->filename);
55222 +}
55223 +
55224 +int
55225 +gr_handle_ptrace(struct task_struct *task, const long request)
55226 +{
55227 + struct task_struct *tmp = task;
55228 + struct task_struct *curtemp = current;
55229 + __u32 retmode;
55230 +
55231 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55232 + if (unlikely(!(gr_status & GR_READY)))
55233 + return 0;
55234 +#endif
55235 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55236 + read_lock(&tasklist_lock);
55237 + while (tmp->pid > 0) {
55238 + if (tmp == curtemp)
55239 + break;
55240 + tmp = tmp->real_parent;
55241 + }
55242 +
55243 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55244 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55245 + read_unlock(&tasklist_lock);
55246 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55247 + return 1;
55248 + }
55249 + read_unlock(&tasklist_lock);
55250 + }
55251 +
55252 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55253 + if (!(gr_status & GR_READY))
55254 + return 0;
55255 +#endif
55256 +
55257 + read_lock(&grsec_exec_file_lock);
55258 + if (unlikely(!task->exec_file)) {
55259 + read_unlock(&grsec_exec_file_lock);
55260 + return 0;
55261 + }
55262 +
55263 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55264 + read_unlock(&grsec_exec_file_lock);
55265 +
55266 + if (retmode & GR_NOPTRACE) {
55267 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55268 + return 1;
55269 + }
55270 +
55271 + if (retmode & GR_PTRACERD) {
55272 + switch (request) {
55273 + case PTRACE_SEIZE:
55274 + case PTRACE_POKETEXT:
55275 + case PTRACE_POKEDATA:
55276 + case PTRACE_POKEUSR:
55277 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55278 + case PTRACE_SETREGS:
55279 + case PTRACE_SETFPREGS:
55280 +#endif
55281 +#ifdef CONFIG_X86
55282 + case PTRACE_SETFPXREGS:
55283 +#endif
55284 +#ifdef CONFIG_ALTIVEC
55285 + case PTRACE_SETVRREGS:
55286 +#endif
55287 + return 1;
55288 + default:
55289 + return 0;
55290 + }
55291 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55292 + !(current->role->roletype & GR_ROLE_GOD) &&
55293 + (current->acl != task->acl)) {
55294 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55295 + return 1;
55296 + }
55297 +
55298 + return 0;
55299 +}
55300 +
55301 +static int is_writable_mmap(const struct file *filp)
55302 +{
55303 + struct task_struct *task = current;
55304 + struct acl_object_label *obj, *obj2;
55305 +
55306 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55307 + !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))) {
55308 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55309 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55310 + task->role->root_label);
55311 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55312 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55313 + return 1;
55314 + }
55315 + }
55316 + return 0;
55317 +}
55318 +
55319 +int
55320 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55321 +{
55322 + __u32 mode;
55323 +
55324 + if (unlikely(!file || !(prot & PROT_EXEC)))
55325 + return 1;
55326 +
55327 + if (is_writable_mmap(file))
55328 + return 0;
55329 +
55330 + mode =
55331 + gr_search_file(file->f_path.dentry,
55332 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55333 + file->f_path.mnt);
55334 +
55335 + if (!gr_tpe_allow(file))
55336 + return 0;
55337 +
55338 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55339 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55340 + return 0;
55341 + } else if (unlikely(!(mode & GR_EXEC))) {
55342 + return 0;
55343 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55344 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55345 + return 1;
55346 + }
55347 +
55348 + return 1;
55349 +}
55350 +
55351 +int
55352 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55353 +{
55354 + __u32 mode;
55355 +
55356 + if (unlikely(!file || !(prot & PROT_EXEC)))
55357 + return 1;
55358 +
55359 + if (is_writable_mmap(file))
55360 + return 0;
55361 +
55362 + mode =
55363 + gr_search_file(file->f_path.dentry,
55364 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55365 + file->f_path.mnt);
55366 +
55367 + if (!gr_tpe_allow(file))
55368 + return 0;
55369 +
55370 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55371 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55372 + return 0;
55373 + } else if (unlikely(!(mode & GR_EXEC))) {
55374 + return 0;
55375 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55376 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55377 + return 1;
55378 + }
55379 +
55380 + return 1;
55381 +}
55382 +
55383 +void
55384 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55385 +{
55386 + unsigned long runtime;
55387 + unsigned long cputime;
55388 + unsigned int wday, cday;
55389 + __u8 whr, chr;
55390 + __u8 wmin, cmin;
55391 + __u8 wsec, csec;
55392 + struct timespec timeval;
55393 +
55394 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55395 + !(task->acl->mode & GR_PROCACCT)))
55396 + return;
55397 +
55398 + do_posix_clock_monotonic_gettime(&timeval);
55399 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55400 + wday = runtime / (3600 * 24);
55401 + runtime -= wday * (3600 * 24);
55402 + whr = runtime / 3600;
55403 + runtime -= whr * 3600;
55404 + wmin = runtime / 60;
55405 + runtime -= wmin * 60;
55406 + wsec = runtime;
55407 +
55408 + cputime = (task->utime + task->stime) / HZ;
55409 + cday = cputime / (3600 * 24);
55410 + cputime -= cday * (3600 * 24);
55411 + chr = cputime / 3600;
55412 + cputime -= chr * 3600;
55413 + cmin = cputime / 60;
55414 + cputime -= cmin * 60;
55415 + csec = cputime;
55416 +
55417 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55418 +
55419 + return;
55420 +}
55421 +
55422 +void gr_set_kernel_label(struct task_struct *task)
55423 +{
55424 + if (gr_status & GR_READY) {
55425 + task->role = kernel_role;
55426 + task->acl = kernel_role->root_label;
55427 + }
55428 + return;
55429 +}
55430 +
55431 +#ifdef CONFIG_TASKSTATS
55432 +int gr_is_taskstats_denied(int pid)
55433 +{
55434 + struct task_struct *task;
55435 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55436 + const struct cred *cred;
55437 +#endif
55438 + int ret = 0;
55439 +
55440 + /* restrict taskstats viewing to un-chrooted root users
55441 + who have the 'view' subject flag if the RBAC system is enabled
55442 + */
55443 +
55444 + rcu_read_lock();
55445 + read_lock(&tasklist_lock);
55446 + task = find_task_by_vpid(pid);
55447 + if (task) {
55448 +#ifdef CONFIG_GRKERNSEC_CHROOT
55449 + if (proc_is_chrooted(task))
55450 + ret = -EACCES;
55451 +#endif
55452 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55453 + cred = __task_cred(task);
55454 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55455 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55456 + ret = -EACCES;
55457 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55458 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55459 + ret = -EACCES;
55460 +#endif
55461 +#endif
55462 + if (gr_status & GR_READY) {
55463 + if (!(task->acl->mode & GR_VIEW))
55464 + ret = -EACCES;
55465 + }
55466 + } else
55467 + ret = -ENOENT;
55468 +
55469 + read_unlock(&tasklist_lock);
55470 + rcu_read_unlock();
55471 +
55472 + return ret;
55473 +}
55474 +#endif
55475 +
55476 +/* AUXV entries are filled via a descendant of search_binary_handler
55477 + after we've already applied the subject for the target
55478 +*/
55479 +int gr_acl_enable_at_secure(void)
55480 +{
55481 + if (unlikely(!(gr_status & GR_READY)))
55482 + return 0;
55483 +
55484 + if (current->acl->mode & GR_ATSECURE)
55485 + return 1;
55486 +
55487 + return 0;
55488 +}
55489 +
55490 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55491 +{
55492 + struct task_struct *task = current;
55493 + struct dentry *dentry = file->f_path.dentry;
55494 + struct vfsmount *mnt = file->f_path.mnt;
55495 + struct acl_object_label *obj, *tmp;
55496 + struct acl_subject_label *subj;
55497 + unsigned int bufsize;
55498 + int is_not_root;
55499 + char *path;
55500 + dev_t dev = __get_dev(dentry);
55501 +
55502 + if (unlikely(!(gr_status & GR_READY)))
55503 + return 1;
55504 +
55505 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55506 + return 1;
55507 +
55508 + /* ignore Eric Biederman */
55509 + if (IS_PRIVATE(dentry->d_inode))
55510 + return 1;
55511 +
55512 + subj = task->acl;
55513 + read_lock(&gr_inode_lock);
55514 + do {
55515 + obj = lookup_acl_obj_label(ino, dev, subj);
55516 + if (obj != NULL) {
55517 + read_unlock(&gr_inode_lock);
55518 + return (obj->mode & GR_FIND) ? 1 : 0;
55519 + }
55520 + } while ((subj = subj->parent_subject));
55521 + read_unlock(&gr_inode_lock);
55522 +
55523 + /* this is purely an optimization since we're looking for an object
55524 + for the directory we're doing a readdir on
55525 + if it's possible for any globbed object to match the entry we're
55526 + filling into the directory, then the object we find here will be
55527 + an anchor point with attached globbed objects
55528 + */
55529 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55530 + if (obj->globbed == NULL)
55531 + return (obj->mode & GR_FIND) ? 1 : 0;
55532 +
55533 + is_not_root = ((obj->filename[0] == '/') &&
55534 + (obj->filename[1] == '\0')) ? 0 : 1;
55535 + bufsize = PAGE_SIZE - namelen - is_not_root;
55536 +
55537 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55538 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55539 + return 1;
55540 +
55541 + preempt_disable();
55542 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55543 + bufsize);
55544 +
55545 + bufsize = strlen(path);
55546 +
55547 + /* if base is "/", don't append an additional slash */
55548 + if (is_not_root)
55549 + *(path + bufsize) = '/';
55550 + memcpy(path + bufsize + is_not_root, name, namelen);
55551 + *(path + bufsize + namelen + is_not_root) = '\0';
55552 +
55553 + tmp = obj->globbed;
55554 + while (tmp) {
55555 + if (!glob_match(tmp->filename, path)) {
55556 + preempt_enable();
55557 + return (tmp->mode & GR_FIND) ? 1 : 0;
55558 + }
55559 + tmp = tmp->next;
55560 + }
55561 + preempt_enable();
55562 + return (obj->mode & GR_FIND) ? 1 : 0;
55563 +}
55564 +
55565 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55566 +EXPORT_SYMBOL(gr_acl_is_enabled);
55567 +#endif
55568 +EXPORT_SYMBOL(gr_learn_resource);
55569 +EXPORT_SYMBOL(gr_set_kernel_label);
55570 +#ifdef CONFIG_SECURITY
55571 +EXPORT_SYMBOL(gr_check_user_change);
55572 +EXPORT_SYMBOL(gr_check_group_change);
55573 +#endif
55574 +
55575 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55576 new file mode 100644
55577 index 0000000..34fefda
55578 --- /dev/null
55579 +++ b/grsecurity/gracl_alloc.c
55580 @@ -0,0 +1,105 @@
55581 +#include <linux/kernel.h>
55582 +#include <linux/mm.h>
55583 +#include <linux/slab.h>
55584 +#include <linux/vmalloc.h>
55585 +#include <linux/gracl.h>
55586 +#include <linux/grsecurity.h>
55587 +
55588 +static unsigned long alloc_stack_next = 1;
55589 +static unsigned long alloc_stack_size = 1;
55590 +static void **alloc_stack;
55591 +
55592 +static __inline__ int
55593 +alloc_pop(void)
55594 +{
55595 + if (alloc_stack_next == 1)
55596 + return 0;
55597 +
55598 + kfree(alloc_stack[alloc_stack_next - 2]);
55599 +
55600 + alloc_stack_next--;
55601 +
55602 + return 1;
55603 +}
55604 +
55605 +static __inline__ int
55606 +alloc_push(void *buf)
55607 +{
55608 + if (alloc_stack_next >= alloc_stack_size)
55609 + return 1;
55610 +
55611 + alloc_stack[alloc_stack_next - 1] = buf;
55612 +
55613 + alloc_stack_next++;
55614 +
55615 + return 0;
55616 +}
55617 +
55618 +void *
55619 +acl_alloc(unsigned long len)
55620 +{
55621 + void *ret = NULL;
55622 +
55623 + if (!len || len > PAGE_SIZE)
55624 + goto out;
55625 +
55626 + ret = kmalloc(len, GFP_KERNEL);
55627 +
55628 + if (ret) {
55629 + if (alloc_push(ret)) {
55630 + kfree(ret);
55631 + ret = NULL;
55632 + }
55633 + }
55634 +
55635 +out:
55636 + return ret;
55637 +}
55638 +
55639 +void *
55640 +acl_alloc_num(unsigned long num, unsigned long len)
55641 +{
55642 + if (!len || (num > (PAGE_SIZE / len)))
55643 + return NULL;
55644 +
55645 + return acl_alloc(num * len);
55646 +}
55647 +
55648 +void
55649 +acl_free_all(void)
55650 +{
55651 + if (gr_acl_is_enabled() || !alloc_stack)
55652 + return;
55653 +
55654 + while (alloc_pop()) ;
55655 +
55656 + if (alloc_stack) {
55657 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55658 + kfree(alloc_stack);
55659 + else
55660 + vfree(alloc_stack);
55661 + }
55662 +
55663 + alloc_stack = NULL;
55664 + alloc_stack_size = 1;
55665 + alloc_stack_next = 1;
55666 +
55667 + return;
55668 +}
55669 +
55670 +int
55671 +acl_alloc_stack_init(unsigned long size)
55672 +{
55673 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55674 + alloc_stack =
55675 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55676 + else
55677 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55678 +
55679 + alloc_stack_size = size;
55680 +
55681 + if (!alloc_stack)
55682 + return 0;
55683 + else
55684 + return 1;
55685 +}
55686 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55687 new file mode 100644
55688 index 0000000..6d21049
55689 --- /dev/null
55690 +++ b/grsecurity/gracl_cap.c
55691 @@ -0,0 +1,110 @@
55692 +#include <linux/kernel.h>
55693 +#include <linux/module.h>
55694 +#include <linux/sched.h>
55695 +#include <linux/gracl.h>
55696 +#include <linux/grsecurity.h>
55697 +#include <linux/grinternal.h>
55698 +
55699 +extern const char *captab_log[];
55700 +extern int captab_log_entries;
55701 +
55702 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55703 +{
55704 + struct acl_subject_label *curracl;
55705 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55706 + kernel_cap_t cap_audit = __cap_empty_set;
55707 +
55708 + if (!gr_acl_is_enabled())
55709 + return 1;
55710 +
55711 + curracl = task->acl;
55712 +
55713 + cap_drop = curracl->cap_lower;
55714 + cap_mask = curracl->cap_mask;
55715 + cap_audit = curracl->cap_invert_audit;
55716 +
55717 + while ((curracl = curracl->parent_subject)) {
55718 + /* if the cap isn't specified in the current computed mask but is specified in the
55719 + current level subject, and is lowered in the current level subject, then add
55720 + it to the set of dropped capabilities
55721 + otherwise, add the current level subject's mask to the current computed mask
55722 + */
55723 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55724 + cap_raise(cap_mask, cap);
55725 + if (cap_raised(curracl->cap_lower, cap))
55726 + cap_raise(cap_drop, cap);
55727 + if (cap_raised(curracl->cap_invert_audit, cap))
55728 + cap_raise(cap_audit, cap);
55729 + }
55730 + }
55731 +
55732 + if (!cap_raised(cap_drop, cap)) {
55733 + if (cap_raised(cap_audit, cap))
55734 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55735 + return 1;
55736 + }
55737 +
55738 + curracl = task->acl;
55739 +
55740 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55741 + && cap_raised(cred->cap_effective, cap)) {
55742 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55743 + task->role->roletype, cred->uid,
55744 + cred->gid, task->exec_file ?
55745 + gr_to_filename(task->exec_file->f_path.dentry,
55746 + task->exec_file->f_path.mnt) : curracl->filename,
55747 + curracl->filename, 0UL,
55748 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55749 + return 1;
55750 + }
55751 +
55752 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55753 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55754 +
55755 + return 0;
55756 +}
55757 +
55758 +int
55759 +gr_acl_is_capable(const int cap)
55760 +{
55761 + return gr_task_acl_is_capable(current, current_cred(), cap);
55762 +}
55763 +
55764 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55765 +{
55766 + struct acl_subject_label *curracl;
55767 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55768 +
55769 + if (!gr_acl_is_enabled())
55770 + return 1;
55771 +
55772 + curracl = task->acl;
55773 +
55774 + cap_drop = curracl->cap_lower;
55775 + cap_mask = curracl->cap_mask;
55776 +
55777 + while ((curracl = curracl->parent_subject)) {
55778 + /* if the cap isn't specified in the current computed mask but is specified in the
55779 + current level subject, and is lowered in the current level subject, then add
55780 + it to the set of dropped capabilities
55781 + otherwise, add the current level subject's mask to the current computed mask
55782 + */
55783 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55784 + cap_raise(cap_mask, cap);
55785 + if (cap_raised(curracl->cap_lower, cap))
55786 + cap_raise(cap_drop, cap);
55787 + }
55788 + }
55789 +
55790 + if (!cap_raised(cap_drop, cap))
55791 + return 1;
55792 +
55793 + return 0;
55794 +}
55795 +
55796 +int
55797 +gr_acl_is_capable_nolog(const int cap)
55798 +{
55799 + return gr_task_acl_is_capable_nolog(current, cap);
55800 +}
55801 +
55802 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55803 new file mode 100644
55804 index 0000000..d28e241
55805 --- /dev/null
55806 +++ b/grsecurity/gracl_fs.c
55807 @@ -0,0 +1,437 @@
55808 +#include <linux/kernel.h>
55809 +#include <linux/sched.h>
55810 +#include <linux/types.h>
55811 +#include <linux/fs.h>
55812 +#include <linux/file.h>
55813 +#include <linux/stat.h>
55814 +#include <linux/grsecurity.h>
55815 +#include <linux/grinternal.h>
55816 +#include <linux/gracl.h>
55817 +
55818 +umode_t
55819 +gr_acl_umask(void)
55820 +{
55821 + if (unlikely(!gr_acl_is_enabled()))
55822 + return 0;
55823 +
55824 + return current->role->umask;
55825 +}
55826 +
55827 +__u32
55828 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55829 + const struct vfsmount * mnt)
55830 +{
55831 + __u32 mode;
55832 +
55833 + if (unlikely(!dentry->d_inode))
55834 + return GR_FIND;
55835 +
55836 + mode =
55837 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55838 +
55839 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55840 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55841 + return mode;
55842 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55843 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55844 + return 0;
55845 + } else if (unlikely(!(mode & GR_FIND)))
55846 + return 0;
55847 +
55848 + return GR_FIND;
55849 +}
55850 +
55851 +__u32
55852 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55853 + int acc_mode)
55854 +{
55855 + __u32 reqmode = GR_FIND;
55856 + __u32 mode;
55857 +
55858 + if (unlikely(!dentry->d_inode))
55859 + return reqmode;
55860 +
55861 + if (acc_mode & MAY_APPEND)
55862 + reqmode |= GR_APPEND;
55863 + else if (acc_mode & MAY_WRITE)
55864 + reqmode |= GR_WRITE;
55865 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
55866 + reqmode |= GR_READ;
55867 +
55868 + mode =
55869 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55870 + mnt);
55871 +
55872 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55873 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55874 + reqmode & GR_READ ? " reading" : "",
55875 + reqmode & GR_WRITE ? " writing" : reqmode &
55876 + GR_APPEND ? " appending" : "");
55877 + return reqmode;
55878 + } else
55879 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55880 + {
55881 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
55882 + reqmode & GR_READ ? " reading" : "",
55883 + reqmode & GR_WRITE ? " writing" : reqmode &
55884 + GR_APPEND ? " appending" : "");
55885 + return 0;
55886 + } else if (unlikely((mode & reqmode) != reqmode))
55887 + return 0;
55888 +
55889 + return reqmode;
55890 +}
55891 +
55892 +__u32
55893 +gr_acl_handle_creat(const struct dentry * dentry,
55894 + const struct dentry * p_dentry,
55895 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
55896 + const int imode)
55897 +{
55898 + __u32 reqmode = GR_WRITE | GR_CREATE;
55899 + __u32 mode;
55900 +
55901 + if (acc_mode & MAY_APPEND)
55902 + reqmode |= GR_APPEND;
55903 + // if a directory was required or the directory already exists, then
55904 + // don't count this open as a read
55905 + if ((acc_mode & MAY_READ) &&
55906 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
55907 + reqmode |= GR_READ;
55908 + if ((open_flags & O_CREAT) &&
55909 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
55910 + reqmode |= GR_SETID;
55911 +
55912 + mode =
55913 + gr_check_create(dentry, p_dentry, p_mnt,
55914 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
55915 +
55916 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55917 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55918 + reqmode & GR_READ ? " reading" : "",
55919 + reqmode & GR_WRITE ? " writing" : reqmode &
55920 + GR_APPEND ? " appending" : "");
55921 + return reqmode;
55922 + } else
55923 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55924 + {
55925 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
55926 + reqmode & GR_READ ? " reading" : "",
55927 + reqmode & GR_WRITE ? " writing" : reqmode &
55928 + GR_APPEND ? " appending" : "");
55929 + return 0;
55930 + } else if (unlikely((mode & reqmode) != reqmode))
55931 + return 0;
55932 +
55933 + return reqmode;
55934 +}
55935 +
55936 +__u32
55937 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
55938 + const int fmode)
55939 +{
55940 + __u32 mode, reqmode = GR_FIND;
55941 +
55942 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
55943 + reqmode |= GR_EXEC;
55944 + if (fmode & S_IWOTH)
55945 + reqmode |= GR_WRITE;
55946 + if (fmode & S_IROTH)
55947 + reqmode |= GR_READ;
55948 +
55949 + mode =
55950 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
55951 + mnt);
55952 +
55953 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
55954 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55955 + reqmode & GR_READ ? " reading" : "",
55956 + reqmode & GR_WRITE ? " writing" : "",
55957 + reqmode & GR_EXEC ? " executing" : "");
55958 + return reqmode;
55959 + } else
55960 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
55961 + {
55962 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
55963 + reqmode & GR_READ ? " reading" : "",
55964 + reqmode & GR_WRITE ? " writing" : "",
55965 + reqmode & GR_EXEC ? " executing" : "");
55966 + return 0;
55967 + } else if (unlikely((mode & reqmode) != reqmode))
55968 + return 0;
55969 +
55970 + return reqmode;
55971 +}
55972 +
55973 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
55974 +{
55975 + __u32 mode;
55976 +
55977 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
55978 +
55979 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
55980 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
55981 + return mode;
55982 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
55983 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
55984 + return 0;
55985 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
55986 + return 0;
55987 +
55988 + return (reqmode);
55989 +}
55990 +
55991 +__u32
55992 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
55993 +{
55994 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
55995 +}
55996 +
55997 +__u32
55998 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
55999 +{
56000 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56001 +}
56002 +
56003 +__u32
56004 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56005 +{
56006 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56007 +}
56008 +
56009 +__u32
56010 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56011 +{
56012 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56013 +}
56014 +
56015 +__u32
56016 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56017 + umode_t *modeptr)
56018 +{
56019 + umode_t mode;
56020 +
56021 + *modeptr &= ~gr_acl_umask();
56022 + mode = *modeptr;
56023 +
56024 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56025 + return 1;
56026 +
56027 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56028 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56029 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56030 + GR_CHMOD_ACL_MSG);
56031 + } else {
56032 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56033 + }
56034 +}
56035 +
56036 +__u32
56037 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56038 +{
56039 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56040 +}
56041 +
56042 +__u32
56043 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56044 +{
56045 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56046 +}
56047 +
56048 +__u32
56049 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56050 +{
56051 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56052 +}
56053 +
56054 +__u32
56055 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56056 +{
56057 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56058 + GR_UNIXCONNECT_ACL_MSG);
56059 +}
56060 +
56061 +/* hardlinks require at minimum create and link permission,
56062 + any additional privilege required is based on the
56063 + privilege of the file being linked to
56064 +*/
56065 +__u32
56066 +gr_acl_handle_link(const struct dentry * new_dentry,
56067 + const struct dentry * parent_dentry,
56068 + const struct vfsmount * parent_mnt,
56069 + const struct dentry * old_dentry,
56070 + const struct vfsmount * old_mnt, const char *to)
56071 +{
56072 + __u32 mode;
56073 + __u32 needmode = GR_CREATE | GR_LINK;
56074 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56075 +
56076 + mode =
56077 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56078 + old_mnt);
56079 +
56080 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56081 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56082 + return mode;
56083 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56084 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56085 + return 0;
56086 + } else if (unlikely((mode & needmode) != needmode))
56087 + return 0;
56088 +
56089 + return 1;
56090 +}
56091 +
56092 +__u32
56093 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56094 + const struct dentry * parent_dentry,
56095 + const struct vfsmount * parent_mnt, const char *from)
56096 +{
56097 + __u32 needmode = GR_WRITE | GR_CREATE;
56098 + __u32 mode;
56099 +
56100 + mode =
56101 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56102 + GR_CREATE | GR_AUDIT_CREATE |
56103 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56104 +
56105 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56106 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56107 + return mode;
56108 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56109 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56110 + return 0;
56111 + } else if (unlikely((mode & needmode) != needmode))
56112 + return 0;
56113 +
56114 + return (GR_WRITE | GR_CREATE);
56115 +}
56116 +
56117 +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)
56118 +{
56119 + __u32 mode;
56120 +
56121 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56122 +
56123 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56124 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56125 + return mode;
56126 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56127 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56128 + return 0;
56129 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56130 + return 0;
56131 +
56132 + return (reqmode);
56133 +}
56134 +
56135 +__u32
56136 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56137 + const struct dentry * parent_dentry,
56138 + const struct vfsmount * parent_mnt,
56139 + const int mode)
56140 +{
56141 + __u32 reqmode = GR_WRITE | GR_CREATE;
56142 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56143 + reqmode |= GR_SETID;
56144 +
56145 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56146 + reqmode, GR_MKNOD_ACL_MSG);
56147 +}
56148 +
56149 +__u32
56150 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56151 + const struct dentry *parent_dentry,
56152 + const struct vfsmount *parent_mnt)
56153 +{
56154 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56155 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56156 +}
56157 +
56158 +#define RENAME_CHECK_SUCCESS(old, new) \
56159 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56160 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56161 +
56162 +int
56163 +gr_acl_handle_rename(struct dentry *new_dentry,
56164 + struct dentry *parent_dentry,
56165 + const struct vfsmount *parent_mnt,
56166 + struct dentry *old_dentry,
56167 + struct inode *old_parent_inode,
56168 + struct vfsmount *old_mnt, const char *newname)
56169 +{
56170 + __u32 comp1, comp2;
56171 + int error = 0;
56172 +
56173 + if (unlikely(!gr_acl_is_enabled()))
56174 + return 0;
56175 +
56176 + if (!new_dentry->d_inode) {
56177 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56178 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56179 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56180 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56181 + GR_DELETE | GR_AUDIT_DELETE |
56182 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56183 + GR_SUPPRESS, old_mnt);
56184 + } else {
56185 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56186 + GR_CREATE | GR_DELETE |
56187 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56188 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56189 + GR_SUPPRESS, parent_mnt);
56190 + comp2 =
56191 + gr_search_file(old_dentry,
56192 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56193 + GR_DELETE | GR_AUDIT_DELETE |
56194 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56195 + }
56196 +
56197 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56198 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56199 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56200 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56201 + && !(comp2 & GR_SUPPRESS)) {
56202 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56203 + error = -EACCES;
56204 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56205 + error = -EACCES;
56206 +
56207 + return error;
56208 +}
56209 +
56210 +void
56211 +gr_acl_handle_exit(void)
56212 +{
56213 + u16 id;
56214 + char *rolename;
56215 + struct file *exec_file;
56216 +
56217 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56218 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56219 + id = current->acl_role_id;
56220 + rolename = current->role->rolename;
56221 + gr_set_acls(1);
56222 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56223 + }
56224 +
56225 + write_lock(&grsec_exec_file_lock);
56226 + exec_file = current->exec_file;
56227 + current->exec_file = NULL;
56228 + write_unlock(&grsec_exec_file_lock);
56229 +
56230 + if (exec_file)
56231 + fput(exec_file);
56232 +}
56233 +
56234 +int
56235 +gr_acl_handle_procpidmem(const struct task_struct *task)
56236 +{
56237 + if (unlikely(!gr_acl_is_enabled()))
56238 + return 0;
56239 +
56240 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56241 + return -EACCES;
56242 +
56243 + return 0;
56244 +}
56245 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56246 new file mode 100644
56247 index 0000000..58800a7
56248 --- /dev/null
56249 +++ b/grsecurity/gracl_ip.c
56250 @@ -0,0 +1,384 @@
56251 +#include <linux/kernel.h>
56252 +#include <asm/uaccess.h>
56253 +#include <asm/errno.h>
56254 +#include <net/sock.h>
56255 +#include <linux/file.h>
56256 +#include <linux/fs.h>
56257 +#include <linux/net.h>
56258 +#include <linux/in.h>
56259 +#include <linux/skbuff.h>
56260 +#include <linux/ip.h>
56261 +#include <linux/udp.h>
56262 +#include <linux/types.h>
56263 +#include <linux/sched.h>
56264 +#include <linux/netdevice.h>
56265 +#include <linux/inetdevice.h>
56266 +#include <linux/gracl.h>
56267 +#include <linux/grsecurity.h>
56268 +#include <linux/grinternal.h>
56269 +
56270 +#define GR_BIND 0x01
56271 +#define GR_CONNECT 0x02
56272 +#define GR_INVERT 0x04
56273 +#define GR_BINDOVERRIDE 0x08
56274 +#define GR_CONNECTOVERRIDE 0x10
56275 +#define GR_SOCK_FAMILY 0x20
56276 +
56277 +static const char * gr_protocols[IPPROTO_MAX] = {
56278 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56279 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56280 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56281 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56282 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56283 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56284 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56285 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56286 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56287 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56288 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56289 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56290 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56291 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56292 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56293 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56294 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56295 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56296 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56297 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56298 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56299 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56300 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56301 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56302 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56303 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56304 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56305 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56306 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56307 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56308 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56309 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56310 + };
56311 +
56312 +static const char * gr_socktypes[SOCK_MAX] = {
56313 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56314 + "unknown:7", "unknown:8", "unknown:9", "packet"
56315 + };
56316 +
56317 +static const char * gr_sockfamilies[AF_MAX+1] = {
56318 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56319 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56320 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56321 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56322 + };
56323 +
56324 +const char *
56325 +gr_proto_to_name(unsigned char proto)
56326 +{
56327 + return gr_protocols[proto];
56328 +}
56329 +
56330 +const char *
56331 +gr_socktype_to_name(unsigned char type)
56332 +{
56333 + return gr_socktypes[type];
56334 +}
56335 +
56336 +const char *
56337 +gr_sockfamily_to_name(unsigned char family)
56338 +{
56339 + return gr_sockfamilies[family];
56340 +}
56341 +
56342 +int
56343 +gr_search_socket(const int domain, const int type, const int protocol)
56344 +{
56345 + struct acl_subject_label *curr;
56346 + const struct cred *cred = current_cred();
56347 +
56348 + if (unlikely(!gr_acl_is_enabled()))
56349 + goto exit;
56350 +
56351 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56352 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56353 + goto exit; // let the kernel handle it
56354 +
56355 + curr = current->acl;
56356 +
56357 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56358 + /* the family is allowed, if this is PF_INET allow it only if
56359 + the extra sock type/protocol checks pass */
56360 + if (domain == PF_INET)
56361 + goto inet_check;
56362 + goto exit;
56363 + } else {
56364 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56365 + __u32 fakeip = 0;
56366 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56367 + current->role->roletype, cred->uid,
56368 + cred->gid, current->exec_file ?
56369 + gr_to_filename(current->exec_file->f_path.dentry,
56370 + current->exec_file->f_path.mnt) :
56371 + curr->filename, curr->filename,
56372 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56373 + &current->signal->saved_ip);
56374 + goto exit;
56375 + }
56376 + goto exit_fail;
56377 + }
56378 +
56379 +inet_check:
56380 + /* the rest of this checking is for IPv4 only */
56381 + if (!curr->ips)
56382 + goto exit;
56383 +
56384 + if ((curr->ip_type & (1 << type)) &&
56385 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56386 + goto exit;
56387 +
56388 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56389 + /* we don't place acls on raw sockets , and sometimes
56390 + dgram/ip sockets are opened for ioctl and not
56391 + bind/connect, so we'll fake a bind learn log */
56392 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56393 + __u32 fakeip = 0;
56394 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56395 + current->role->roletype, cred->uid,
56396 + cred->gid, current->exec_file ?
56397 + gr_to_filename(current->exec_file->f_path.dentry,
56398 + current->exec_file->f_path.mnt) :
56399 + curr->filename, curr->filename,
56400 + &fakeip, 0, type,
56401 + protocol, GR_CONNECT, &current->signal->saved_ip);
56402 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56403 + __u32 fakeip = 0;
56404 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56405 + current->role->roletype, cred->uid,
56406 + cred->gid, current->exec_file ?
56407 + gr_to_filename(current->exec_file->f_path.dentry,
56408 + current->exec_file->f_path.mnt) :
56409 + curr->filename, curr->filename,
56410 + &fakeip, 0, type,
56411 + protocol, GR_BIND, &current->signal->saved_ip);
56412 + }
56413 + /* we'll log when they use connect or bind */
56414 + goto exit;
56415 + }
56416 +
56417 +exit_fail:
56418 + if (domain == PF_INET)
56419 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56420 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56421 + else
56422 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56423 + gr_socktype_to_name(type), protocol);
56424 +
56425 + return 0;
56426 +exit:
56427 + return 1;
56428 +}
56429 +
56430 +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)
56431 +{
56432 + if ((ip->mode & mode) &&
56433 + (ip_port >= ip->low) &&
56434 + (ip_port <= ip->high) &&
56435 + ((ntohl(ip_addr) & our_netmask) ==
56436 + (ntohl(our_addr) & our_netmask))
56437 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56438 + && (ip->type & (1 << type))) {
56439 + if (ip->mode & GR_INVERT)
56440 + return 2; // specifically denied
56441 + else
56442 + return 1; // allowed
56443 + }
56444 +
56445 + return 0; // not specifically allowed, may continue parsing
56446 +}
56447 +
56448 +static int
56449 +gr_search_connectbind(const int full_mode, struct sock *sk,
56450 + struct sockaddr_in *addr, const int type)
56451 +{
56452 + char iface[IFNAMSIZ] = {0};
56453 + struct acl_subject_label *curr;
56454 + struct acl_ip_label *ip;
56455 + struct inet_sock *isk;
56456 + struct net_device *dev;
56457 + struct in_device *idev;
56458 + unsigned long i;
56459 + int ret;
56460 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56461 + __u32 ip_addr = 0;
56462 + __u32 our_addr;
56463 + __u32 our_netmask;
56464 + char *p;
56465 + __u16 ip_port = 0;
56466 + const struct cred *cred = current_cred();
56467 +
56468 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56469 + return 0;
56470 +
56471 + curr = current->acl;
56472 + isk = inet_sk(sk);
56473 +
56474 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56475 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56476 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56477 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56478 + struct sockaddr_in saddr;
56479 + int err;
56480 +
56481 + saddr.sin_family = AF_INET;
56482 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56483 + saddr.sin_port = isk->inet_sport;
56484 +
56485 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56486 + if (err)
56487 + return err;
56488 +
56489 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56490 + if (err)
56491 + return err;
56492 + }
56493 +
56494 + if (!curr->ips)
56495 + return 0;
56496 +
56497 + ip_addr = addr->sin_addr.s_addr;
56498 + ip_port = ntohs(addr->sin_port);
56499 +
56500 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56501 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56502 + current->role->roletype, cred->uid,
56503 + cred->gid, current->exec_file ?
56504 + gr_to_filename(current->exec_file->f_path.dentry,
56505 + current->exec_file->f_path.mnt) :
56506 + curr->filename, curr->filename,
56507 + &ip_addr, ip_port, type,
56508 + sk->sk_protocol, mode, &current->signal->saved_ip);
56509 + return 0;
56510 + }
56511 +
56512 + for (i = 0; i < curr->ip_num; i++) {
56513 + ip = *(curr->ips + i);
56514 + if (ip->iface != NULL) {
56515 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56516 + p = strchr(iface, ':');
56517 + if (p != NULL)
56518 + *p = '\0';
56519 + dev = dev_get_by_name(sock_net(sk), iface);
56520 + if (dev == NULL)
56521 + continue;
56522 + idev = in_dev_get(dev);
56523 + if (idev == NULL) {
56524 + dev_put(dev);
56525 + continue;
56526 + }
56527 + rcu_read_lock();
56528 + for_ifa(idev) {
56529 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56530 + our_addr = ifa->ifa_address;
56531 + our_netmask = 0xffffffff;
56532 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56533 + if (ret == 1) {
56534 + rcu_read_unlock();
56535 + in_dev_put(idev);
56536 + dev_put(dev);
56537 + return 0;
56538 + } else if (ret == 2) {
56539 + rcu_read_unlock();
56540 + in_dev_put(idev);
56541 + dev_put(dev);
56542 + goto denied;
56543 + }
56544 + }
56545 + } endfor_ifa(idev);
56546 + rcu_read_unlock();
56547 + in_dev_put(idev);
56548 + dev_put(dev);
56549 + } else {
56550 + our_addr = ip->addr;
56551 + our_netmask = ip->netmask;
56552 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56553 + if (ret == 1)
56554 + return 0;
56555 + else if (ret == 2)
56556 + goto denied;
56557 + }
56558 + }
56559 +
56560 +denied:
56561 + if (mode == GR_BIND)
56562 + 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));
56563 + else if (mode == GR_CONNECT)
56564 + 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));
56565 +
56566 + return -EACCES;
56567 +}
56568 +
56569 +int
56570 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56571 +{
56572 + /* always allow disconnection of dgram sockets with connect */
56573 + if (addr->sin_family == AF_UNSPEC)
56574 + return 0;
56575 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56576 +}
56577 +
56578 +int
56579 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56580 +{
56581 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56582 +}
56583 +
56584 +int gr_search_listen(struct socket *sock)
56585 +{
56586 + struct sock *sk = sock->sk;
56587 + struct sockaddr_in addr;
56588 +
56589 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56590 + addr.sin_port = inet_sk(sk)->inet_sport;
56591 +
56592 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56593 +}
56594 +
56595 +int gr_search_accept(struct socket *sock)
56596 +{
56597 + struct sock *sk = sock->sk;
56598 + struct sockaddr_in addr;
56599 +
56600 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56601 + addr.sin_port = inet_sk(sk)->inet_sport;
56602 +
56603 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56604 +}
56605 +
56606 +int
56607 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56608 +{
56609 + if (addr)
56610 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56611 + else {
56612 + struct sockaddr_in sin;
56613 + const struct inet_sock *inet = inet_sk(sk);
56614 +
56615 + sin.sin_addr.s_addr = inet->inet_daddr;
56616 + sin.sin_port = inet->inet_dport;
56617 +
56618 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56619 + }
56620 +}
56621 +
56622 +int
56623 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56624 +{
56625 + struct sockaddr_in sin;
56626 +
56627 + if (unlikely(skb->len < sizeof (struct udphdr)))
56628 + return 0; // skip this packet
56629 +
56630 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56631 + sin.sin_port = udp_hdr(skb)->source;
56632 +
56633 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56634 +}
56635 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56636 new file mode 100644
56637 index 0000000..25f54ef
56638 --- /dev/null
56639 +++ b/grsecurity/gracl_learn.c
56640 @@ -0,0 +1,207 @@
56641 +#include <linux/kernel.h>
56642 +#include <linux/mm.h>
56643 +#include <linux/sched.h>
56644 +#include <linux/poll.h>
56645 +#include <linux/string.h>
56646 +#include <linux/file.h>
56647 +#include <linux/types.h>
56648 +#include <linux/vmalloc.h>
56649 +#include <linux/grinternal.h>
56650 +
56651 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56652 + size_t count, loff_t *ppos);
56653 +extern int gr_acl_is_enabled(void);
56654 +
56655 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56656 +static int gr_learn_attached;
56657 +
56658 +/* use a 512k buffer */
56659 +#define LEARN_BUFFER_SIZE (512 * 1024)
56660 +
56661 +static DEFINE_SPINLOCK(gr_learn_lock);
56662 +static DEFINE_MUTEX(gr_learn_user_mutex);
56663 +
56664 +/* we need to maintain two buffers, so that the kernel context of grlearn
56665 + uses a semaphore around the userspace copying, and the other kernel contexts
56666 + use a spinlock when copying into the buffer, since they cannot sleep
56667 +*/
56668 +static char *learn_buffer;
56669 +static char *learn_buffer_user;
56670 +static int learn_buffer_len;
56671 +static int learn_buffer_user_len;
56672 +
56673 +static ssize_t
56674 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56675 +{
56676 + DECLARE_WAITQUEUE(wait, current);
56677 + ssize_t retval = 0;
56678 +
56679 + add_wait_queue(&learn_wait, &wait);
56680 + set_current_state(TASK_INTERRUPTIBLE);
56681 + do {
56682 + mutex_lock(&gr_learn_user_mutex);
56683 + spin_lock(&gr_learn_lock);
56684 + if (learn_buffer_len)
56685 + break;
56686 + spin_unlock(&gr_learn_lock);
56687 + mutex_unlock(&gr_learn_user_mutex);
56688 + if (file->f_flags & O_NONBLOCK) {
56689 + retval = -EAGAIN;
56690 + goto out;
56691 + }
56692 + if (signal_pending(current)) {
56693 + retval = -ERESTARTSYS;
56694 + goto out;
56695 + }
56696 +
56697 + schedule();
56698 + } while (1);
56699 +
56700 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56701 + learn_buffer_user_len = learn_buffer_len;
56702 + retval = learn_buffer_len;
56703 + learn_buffer_len = 0;
56704 +
56705 + spin_unlock(&gr_learn_lock);
56706 +
56707 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56708 + retval = -EFAULT;
56709 +
56710 + mutex_unlock(&gr_learn_user_mutex);
56711 +out:
56712 + set_current_state(TASK_RUNNING);
56713 + remove_wait_queue(&learn_wait, &wait);
56714 + return retval;
56715 +}
56716 +
56717 +static unsigned int
56718 +poll_learn(struct file * file, poll_table * wait)
56719 +{
56720 + poll_wait(file, &learn_wait, wait);
56721 +
56722 + if (learn_buffer_len)
56723 + return (POLLIN | POLLRDNORM);
56724 +
56725 + return 0;
56726 +}
56727 +
56728 +void
56729 +gr_clear_learn_entries(void)
56730 +{
56731 + char *tmp;
56732 +
56733 + mutex_lock(&gr_learn_user_mutex);
56734 + spin_lock(&gr_learn_lock);
56735 + tmp = learn_buffer;
56736 + learn_buffer = NULL;
56737 + spin_unlock(&gr_learn_lock);
56738 + if (tmp)
56739 + vfree(tmp);
56740 + if (learn_buffer_user != NULL) {
56741 + vfree(learn_buffer_user);
56742 + learn_buffer_user = NULL;
56743 + }
56744 + learn_buffer_len = 0;
56745 + mutex_unlock(&gr_learn_user_mutex);
56746 +
56747 + return;
56748 +}
56749 +
56750 +void
56751 +gr_add_learn_entry(const char *fmt, ...)
56752 +{
56753 + va_list args;
56754 + unsigned int len;
56755 +
56756 + if (!gr_learn_attached)
56757 + return;
56758 +
56759 + spin_lock(&gr_learn_lock);
56760 +
56761 + /* leave a gap at the end so we know when it's "full" but don't have to
56762 + compute the exact length of the string we're trying to append
56763 + */
56764 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56765 + spin_unlock(&gr_learn_lock);
56766 + wake_up_interruptible(&learn_wait);
56767 + return;
56768 + }
56769 + if (learn_buffer == NULL) {
56770 + spin_unlock(&gr_learn_lock);
56771 + return;
56772 + }
56773 +
56774 + va_start(args, fmt);
56775 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56776 + va_end(args);
56777 +
56778 + learn_buffer_len += len + 1;
56779 +
56780 + spin_unlock(&gr_learn_lock);
56781 + wake_up_interruptible(&learn_wait);
56782 +
56783 + return;
56784 +}
56785 +
56786 +static int
56787 +open_learn(struct inode *inode, struct file *file)
56788 +{
56789 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56790 + return -EBUSY;
56791 + if (file->f_mode & FMODE_READ) {
56792 + int retval = 0;
56793 + mutex_lock(&gr_learn_user_mutex);
56794 + if (learn_buffer == NULL)
56795 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56796 + if (learn_buffer_user == NULL)
56797 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56798 + if (learn_buffer == NULL) {
56799 + retval = -ENOMEM;
56800 + goto out_error;
56801 + }
56802 + if (learn_buffer_user == NULL) {
56803 + retval = -ENOMEM;
56804 + goto out_error;
56805 + }
56806 + learn_buffer_len = 0;
56807 + learn_buffer_user_len = 0;
56808 + gr_learn_attached = 1;
56809 +out_error:
56810 + mutex_unlock(&gr_learn_user_mutex);
56811 + return retval;
56812 + }
56813 + return 0;
56814 +}
56815 +
56816 +static int
56817 +close_learn(struct inode *inode, struct file *file)
56818 +{
56819 + if (file->f_mode & FMODE_READ) {
56820 + char *tmp = NULL;
56821 + mutex_lock(&gr_learn_user_mutex);
56822 + spin_lock(&gr_learn_lock);
56823 + tmp = learn_buffer;
56824 + learn_buffer = NULL;
56825 + spin_unlock(&gr_learn_lock);
56826 + if (tmp)
56827 + vfree(tmp);
56828 + if (learn_buffer_user != NULL) {
56829 + vfree(learn_buffer_user);
56830 + learn_buffer_user = NULL;
56831 + }
56832 + learn_buffer_len = 0;
56833 + learn_buffer_user_len = 0;
56834 + gr_learn_attached = 0;
56835 + mutex_unlock(&gr_learn_user_mutex);
56836 + }
56837 +
56838 + return 0;
56839 +}
56840 +
56841 +const struct file_operations grsec_fops = {
56842 + .read = read_learn,
56843 + .write = write_grsec_handler,
56844 + .open = open_learn,
56845 + .release = close_learn,
56846 + .poll = poll_learn,
56847 +};
56848 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56849 new file mode 100644
56850 index 0000000..39645c9
56851 --- /dev/null
56852 +++ b/grsecurity/gracl_res.c
56853 @@ -0,0 +1,68 @@
56854 +#include <linux/kernel.h>
56855 +#include <linux/sched.h>
56856 +#include <linux/gracl.h>
56857 +#include <linux/grinternal.h>
56858 +
56859 +static const char *restab_log[] = {
56860 + [RLIMIT_CPU] = "RLIMIT_CPU",
56861 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
56862 + [RLIMIT_DATA] = "RLIMIT_DATA",
56863 + [RLIMIT_STACK] = "RLIMIT_STACK",
56864 + [RLIMIT_CORE] = "RLIMIT_CORE",
56865 + [RLIMIT_RSS] = "RLIMIT_RSS",
56866 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
56867 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
56868 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
56869 + [RLIMIT_AS] = "RLIMIT_AS",
56870 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
56871 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
56872 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
56873 + [RLIMIT_NICE] = "RLIMIT_NICE",
56874 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
56875 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
56876 + [GR_CRASH_RES] = "RLIMIT_CRASH"
56877 +};
56878 +
56879 +void
56880 +gr_log_resource(const struct task_struct *task,
56881 + const int res, const unsigned long wanted, const int gt)
56882 +{
56883 + const struct cred *cred;
56884 + unsigned long rlim;
56885 +
56886 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
56887 + return;
56888 +
56889 + // not yet supported resource
56890 + if (unlikely(!restab_log[res]))
56891 + return;
56892 +
56893 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
56894 + rlim = task_rlimit_max(task, res);
56895 + else
56896 + rlim = task_rlimit(task, res);
56897 +
56898 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
56899 + return;
56900 +
56901 + rcu_read_lock();
56902 + cred = __task_cred(task);
56903 +
56904 + if (res == RLIMIT_NPROC &&
56905 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
56906 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
56907 + goto out_rcu_unlock;
56908 + else if (res == RLIMIT_MEMLOCK &&
56909 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
56910 + goto out_rcu_unlock;
56911 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
56912 + goto out_rcu_unlock;
56913 + rcu_read_unlock();
56914 +
56915 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
56916 +
56917 + return;
56918 +out_rcu_unlock:
56919 + rcu_read_unlock();
56920 + return;
56921 +}
56922 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
56923 new file mode 100644
56924 index 0000000..25197e9
56925 --- /dev/null
56926 +++ b/grsecurity/gracl_segv.c
56927 @@ -0,0 +1,299 @@
56928 +#include <linux/kernel.h>
56929 +#include <linux/mm.h>
56930 +#include <asm/uaccess.h>
56931 +#include <asm/errno.h>
56932 +#include <asm/mman.h>
56933 +#include <net/sock.h>
56934 +#include <linux/file.h>
56935 +#include <linux/fs.h>
56936 +#include <linux/net.h>
56937 +#include <linux/in.h>
56938 +#include <linux/slab.h>
56939 +#include <linux/types.h>
56940 +#include <linux/sched.h>
56941 +#include <linux/timer.h>
56942 +#include <linux/gracl.h>
56943 +#include <linux/grsecurity.h>
56944 +#include <linux/grinternal.h>
56945 +
56946 +static struct crash_uid *uid_set;
56947 +static unsigned short uid_used;
56948 +static DEFINE_SPINLOCK(gr_uid_lock);
56949 +extern rwlock_t gr_inode_lock;
56950 +extern struct acl_subject_label *
56951 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
56952 + struct acl_role_label *role);
56953 +
56954 +#ifdef CONFIG_BTRFS_FS
56955 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56956 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56957 +#endif
56958 +
56959 +static inline dev_t __get_dev(const struct dentry *dentry)
56960 +{
56961 +#ifdef CONFIG_BTRFS_FS
56962 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56963 + return get_btrfs_dev_from_inode(dentry->d_inode);
56964 + else
56965 +#endif
56966 + return dentry->d_inode->i_sb->s_dev;
56967 +}
56968 +
56969 +int
56970 +gr_init_uidset(void)
56971 +{
56972 + uid_set =
56973 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
56974 + uid_used = 0;
56975 +
56976 + return uid_set ? 1 : 0;
56977 +}
56978 +
56979 +void
56980 +gr_free_uidset(void)
56981 +{
56982 + if (uid_set)
56983 + kfree(uid_set);
56984 +
56985 + return;
56986 +}
56987 +
56988 +int
56989 +gr_find_uid(const uid_t uid)
56990 +{
56991 + struct crash_uid *tmp = uid_set;
56992 + uid_t buid;
56993 + int low = 0, high = uid_used - 1, mid;
56994 +
56995 + while (high >= low) {
56996 + mid = (low + high) >> 1;
56997 + buid = tmp[mid].uid;
56998 + if (buid == uid)
56999 + return mid;
57000 + if (buid > uid)
57001 + high = mid - 1;
57002 + if (buid < uid)
57003 + low = mid + 1;
57004 + }
57005 +
57006 + return -1;
57007 +}
57008 +
57009 +static __inline__ void
57010 +gr_insertsort(void)
57011 +{
57012 + unsigned short i, j;
57013 + struct crash_uid index;
57014 +
57015 + for (i = 1; i < uid_used; i++) {
57016 + index = uid_set[i];
57017 + j = i;
57018 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57019 + uid_set[j] = uid_set[j - 1];
57020 + j--;
57021 + }
57022 + uid_set[j] = index;
57023 + }
57024 +
57025 + return;
57026 +}
57027 +
57028 +static __inline__ void
57029 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57030 +{
57031 + int loc;
57032 +
57033 + if (uid_used == GR_UIDTABLE_MAX)
57034 + return;
57035 +
57036 + loc = gr_find_uid(uid);
57037 +
57038 + if (loc >= 0) {
57039 + uid_set[loc].expires = expires;
57040 + return;
57041 + }
57042 +
57043 + uid_set[uid_used].uid = uid;
57044 + uid_set[uid_used].expires = expires;
57045 + uid_used++;
57046 +
57047 + gr_insertsort();
57048 +
57049 + return;
57050 +}
57051 +
57052 +void
57053 +gr_remove_uid(const unsigned short loc)
57054 +{
57055 + unsigned short i;
57056 +
57057 + for (i = loc + 1; i < uid_used; i++)
57058 + uid_set[i - 1] = uid_set[i];
57059 +
57060 + uid_used--;
57061 +
57062 + return;
57063 +}
57064 +
57065 +int
57066 +gr_check_crash_uid(const uid_t uid)
57067 +{
57068 + int loc;
57069 + int ret = 0;
57070 +
57071 + if (unlikely(!gr_acl_is_enabled()))
57072 + return 0;
57073 +
57074 + spin_lock(&gr_uid_lock);
57075 + loc = gr_find_uid(uid);
57076 +
57077 + if (loc < 0)
57078 + goto out_unlock;
57079 +
57080 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57081 + gr_remove_uid(loc);
57082 + else
57083 + ret = 1;
57084 +
57085 +out_unlock:
57086 + spin_unlock(&gr_uid_lock);
57087 + return ret;
57088 +}
57089 +
57090 +static __inline__ int
57091 +proc_is_setxid(const struct cred *cred)
57092 +{
57093 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57094 + !uid_eq(cred->uid, cred->fsuid))
57095 + return 1;
57096 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57097 + !uid_eq(cred->gid, cred->fsgid))
57098 + return 1;
57099 +
57100 + return 0;
57101 +}
57102 +
57103 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57104 +
57105 +void
57106 +gr_handle_crash(struct task_struct *task, const int sig)
57107 +{
57108 + struct acl_subject_label *curr;
57109 + struct task_struct *tsk, *tsk2;
57110 + const struct cred *cred;
57111 + const struct cred *cred2;
57112 +
57113 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57114 + return;
57115 +
57116 + if (unlikely(!gr_acl_is_enabled()))
57117 + return;
57118 +
57119 + curr = task->acl;
57120 +
57121 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57122 + return;
57123 +
57124 + if (time_before_eq(curr->expires, get_seconds())) {
57125 + curr->expires = 0;
57126 + curr->crashes = 0;
57127 + }
57128 +
57129 + curr->crashes++;
57130 +
57131 + if (!curr->expires)
57132 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57133 +
57134 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57135 + time_after(curr->expires, get_seconds())) {
57136 + rcu_read_lock();
57137 + cred = __task_cred(task);
57138 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57139 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57140 + spin_lock(&gr_uid_lock);
57141 + gr_insert_uid(cred->uid, curr->expires);
57142 + spin_unlock(&gr_uid_lock);
57143 + curr->expires = 0;
57144 + curr->crashes = 0;
57145 + read_lock(&tasklist_lock);
57146 + do_each_thread(tsk2, tsk) {
57147 + cred2 = __task_cred(tsk);
57148 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57149 + gr_fake_force_sig(SIGKILL, tsk);
57150 + } while_each_thread(tsk2, tsk);
57151 + read_unlock(&tasklist_lock);
57152 + } else {
57153 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57154 + read_lock(&tasklist_lock);
57155 + read_lock(&grsec_exec_file_lock);
57156 + do_each_thread(tsk2, tsk) {
57157 + if (likely(tsk != task)) {
57158 + // if this thread has the same subject as the one that triggered
57159 + // RES_CRASH and it's the same binary, kill it
57160 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57161 + gr_fake_force_sig(SIGKILL, tsk);
57162 + }
57163 + } while_each_thread(tsk2, tsk);
57164 + read_unlock(&grsec_exec_file_lock);
57165 + read_unlock(&tasklist_lock);
57166 + }
57167 + rcu_read_unlock();
57168 + }
57169 +
57170 + return;
57171 +}
57172 +
57173 +int
57174 +gr_check_crash_exec(const struct file *filp)
57175 +{
57176 + struct acl_subject_label *curr;
57177 +
57178 + if (unlikely(!gr_acl_is_enabled()))
57179 + return 0;
57180 +
57181 + read_lock(&gr_inode_lock);
57182 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57183 + __get_dev(filp->f_path.dentry),
57184 + current->role);
57185 + read_unlock(&gr_inode_lock);
57186 +
57187 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57188 + (!curr->crashes && !curr->expires))
57189 + return 0;
57190 +
57191 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57192 + time_after(curr->expires, get_seconds()))
57193 + return 1;
57194 + else if (time_before_eq(curr->expires, get_seconds())) {
57195 + curr->crashes = 0;
57196 + curr->expires = 0;
57197 + }
57198 +
57199 + return 0;
57200 +}
57201 +
57202 +void
57203 +gr_handle_alertkill(struct task_struct *task)
57204 +{
57205 + struct acl_subject_label *curracl;
57206 + __u32 curr_ip;
57207 + struct task_struct *p, *p2;
57208 +
57209 + if (unlikely(!gr_acl_is_enabled()))
57210 + return;
57211 +
57212 + curracl = task->acl;
57213 + curr_ip = task->signal->curr_ip;
57214 +
57215 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57216 + read_lock(&tasklist_lock);
57217 + do_each_thread(p2, p) {
57218 + if (p->signal->curr_ip == curr_ip)
57219 + gr_fake_force_sig(SIGKILL, p);
57220 + } while_each_thread(p2, p);
57221 + read_unlock(&tasklist_lock);
57222 + } else if (curracl->mode & GR_KILLPROC)
57223 + gr_fake_force_sig(SIGKILL, task);
57224 +
57225 + return;
57226 +}
57227 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57228 new file mode 100644
57229 index 0000000..9d83a69
57230 --- /dev/null
57231 +++ b/grsecurity/gracl_shm.c
57232 @@ -0,0 +1,40 @@
57233 +#include <linux/kernel.h>
57234 +#include <linux/mm.h>
57235 +#include <linux/sched.h>
57236 +#include <linux/file.h>
57237 +#include <linux/ipc.h>
57238 +#include <linux/gracl.h>
57239 +#include <linux/grsecurity.h>
57240 +#include <linux/grinternal.h>
57241 +
57242 +int
57243 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57244 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57245 +{
57246 + struct task_struct *task;
57247 +
57248 + if (!gr_acl_is_enabled())
57249 + return 1;
57250 +
57251 + rcu_read_lock();
57252 + read_lock(&tasklist_lock);
57253 +
57254 + task = find_task_by_vpid(shm_cprid);
57255 +
57256 + if (unlikely(!task))
57257 + task = find_task_by_vpid(shm_lapid);
57258 +
57259 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57260 + (task->pid == shm_lapid)) &&
57261 + (task->acl->mode & GR_PROTSHM) &&
57262 + (task->acl != current->acl))) {
57263 + read_unlock(&tasklist_lock);
57264 + rcu_read_unlock();
57265 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57266 + return 0;
57267 + }
57268 + read_unlock(&tasklist_lock);
57269 + rcu_read_unlock();
57270 +
57271 + return 1;
57272 +}
57273 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57274 new file mode 100644
57275 index 0000000..bc0be01
57276 --- /dev/null
57277 +++ b/grsecurity/grsec_chdir.c
57278 @@ -0,0 +1,19 @@
57279 +#include <linux/kernel.h>
57280 +#include <linux/sched.h>
57281 +#include <linux/fs.h>
57282 +#include <linux/file.h>
57283 +#include <linux/grsecurity.h>
57284 +#include <linux/grinternal.h>
57285 +
57286 +void
57287 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57288 +{
57289 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57290 + if ((grsec_enable_chdir && grsec_enable_group &&
57291 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57292 + !grsec_enable_group)) {
57293 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57294 + }
57295 +#endif
57296 + return;
57297 +}
57298 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57299 new file mode 100644
57300 index 0000000..9807ee2
57301 --- /dev/null
57302 +++ b/grsecurity/grsec_chroot.c
57303 @@ -0,0 +1,368 @@
57304 +#include <linux/kernel.h>
57305 +#include <linux/module.h>
57306 +#include <linux/sched.h>
57307 +#include <linux/file.h>
57308 +#include <linux/fs.h>
57309 +#include <linux/mount.h>
57310 +#include <linux/types.h>
57311 +#include "../fs/mount.h"
57312 +#include <linux/grsecurity.h>
57313 +#include <linux/grinternal.h>
57314 +
57315 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57316 +{
57317 +#ifdef CONFIG_GRKERNSEC
57318 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57319 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57320 + task->gr_is_chrooted = 1;
57321 + else
57322 + task->gr_is_chrooted = 0;
57323 +
57324 + task->gr_chroot_dentry = path->dentry;
57325 +#endif
57326 + return;
57327 +}
57328 +
57329 +void gr_clear_chroot_entries(struct task_struct *task)
57330 +{
57331 +#ifdef CONFIG_GRKERNSEC
57332 + task->gr_is_chrooted = 0;
57333 + task->gr_chroot_dentry = NULL;
57334 +#endif
57335 + return;
57336 +}
57337 +
57338 +int
57339 +gr_handle_chroot_unix(const pid_t pid)
57340 +{
57341 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57342 + struct task_struct *p;
57343 +
57344 + if (unlikely(!grsec_enable_chroot_unix))
57345 + return 1;
57346 +
57347 + if (likely(!proc_is_chrooted(current)))
57348 + return 1;
57349 +
57350 + rcu_read_lock();
57351 + read_lock(&tasklist_lock);
57352 + p = find_task_by_vpid_unrestricted(pid);
57353 + if (unlikely(p && !have_same_root(current, p))) {
57354 + read_unlock(&tasklist_lock);
57355 + rcu_read_unlock();
57356 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57357 + return 0;
57358 + }
57359 + read_unlock(&tasklist_lock);
57360 + rcu_read_unlock();
57361 +#endif
57362 + return 1;
57363 +}
57364 +
57365 +int
57366 +gr_handle_chroot_nice(void)
57367 +{
57368 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57369 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57370 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57371 + return -EPERM;
57372 + }
57373 +#endif
57374 + return 0;
57375 +}
57376 +
57377 +int
57378 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57379 +{
57380 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57381 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57382 + && proc_is_chrooted(current)) {
57383 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57384 + return -EACCES;
57385 + }
57386 +#endif
57387 + return 0;
57388 +}
57389 +
57390 +int
57391 +gr_handle_chroot_rawio(const struct inode *inode)
57392 +{
57393 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57394 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57395 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57396 + return 1;
57397 +#endif
57398 + return 0;
57399 +}
57400 +
57401 +int
57402 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57403 +{
57404 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57405 + struct task_struct *p;
57406 + int ret = 0;
57407 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57408 + return ret;
57409 +
57410 + read_lock(&tasklist_lock);
57411 + do_each_pid_task(pid, type, p) {
57412 + if (!have_same_root(current, p)) {
57413 + ret = 1;
57414 + goto out;
57415 + }
57416 + } while_each_pid_task(pid, type, p);
57417 +out:
57418 + read_unlock(&tasklist_lock);
57419 + return ret;
57420 +#endif
57421 + return 0;
57422 +}
57423 +
57424 +int
57425 +gr_pid_is_chrooted(struct task_struct *p)
57426 +{
57427 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57428 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57429 + return 0;
57430 +
57431 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57432 + !have_same_root(current, p)) {
57433 + return 1;
57434 + }
57435 +#endif
57436 + return 0;
57437 +}
57438 +
57439 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57440 +
57441 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57442 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57443 +{
57444 + struct path path, currentroot;
57445 + int ret = 0;
57446 +
57447 + path.dentry = (struct dentry *)u_dentry;
57448 + path.mnt = (struct vfsmount *)u_mnt;
57449 + get_fs_root(current->fs, &currentroot);
57450 + if (path_is_under(&path, &currentroot))
57451 + ret = 1;
57452 + path_put(&currentroot);
57453 +
57454 + return ret;
57455 +}
57456 +#endif
57457 +
57458 +int
57459 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57460 +{
57461 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57462 + if (!grsec_enable_chroot_fchdir)
57463 + return 1;
57464 +
57465 + if (!proc_is_chrooted(current))
57466 + return 1;
57467 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57468 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57469 + return 0;
57470 + }
57471 +#endif
57472 + return 1;
57473 +}
57474 +
57475 +int
57476 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57477 + const time_t shm_createtime)
57478 +{
57479 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57480 + struct task_struct *p;
57481 + time_t starttime;
57482 +
57483 + if (unlikely(!grsec_enable_chroot_shmat))
57484 + return 1;
57485 +
57486 + if (likely(!proc_is_chrooted(current)))
57487 + return 1;
57488 +
57489 + rcu_read_lock();
57490 + read_lock(&tasklist_lock);
57491 +
57492 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57493 + starttime = p->start_time.tv_sec;
57494 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57495 + if (have_same_root(current, p)) {
57496 + goto allow;
57497 + } else {
57498 + read_unlock(&tasklist_lock);
57499 + rcu_read_unlock();
57500 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57501 + return 0;
57502 + }
57503 + }
57504 + /* creator exited, pid reuse, fall through to next check */
57505 + }
57506 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57507 + if (unlikely(!have_same_root(current, p))) {
57508 + read_unlock(&tasklist_lock);
57509 + rcu_read_unlock();
57510 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57511 + return 0;
57512 + }
57513 + }
57514 +
57515 +allow:
57516 + read_unlock(&tasklist_lock);
57517 + rcu_read_unlock();
57518 +#endif
57519 + return 1;
57520 +}
57521 +
57522 +void
57523 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57524 +{
57525 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57526 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57527 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57528 +#endif
57529 + return;
57530 +}
57531 +
57532 +int
57533 +gr_handle_chroot_mknod(const struct dentry *dentry,
57534 + const struct vfsmount *mnt, const int mode)
57535 +{
57536 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57537 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57538 + proc_is_chrooted(current)) {
57539 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57540 + return -EPERM;
57541 + }
57542 +#endif
57543 + return 0;
57544 +}
57545 +
57546 +int
57547 +gr_handle_chroot_mount(const struct dentry *dentry,
57548 + const struct vfsmount *mnt, const char *dev_name)
57549 +{
57550 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57551 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57552 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57553 + return -EPERM;
57554 + }
57555 +#endif
57556 + return 0;
57557 +}
57558 +
57559 +int
57560 +gr_handle_chroot_pivot(void)
57561 +{
57562 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57563 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57564 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57565 + return -EPERM;
57566 + }
57567 +#endif
57568 + return 0;
57569 +}
57570 +
57571 +int
57572 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57573 +{
57574 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57575 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57576 + !gr_is_outside_chroot(dentry, mnt)) {
57577 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57578 + return -EPERM;
57579 + }
57580 +#endif
57581 + return 0;
57582 +}
57583 +
57584 +extern const char *captab_log[];
57585 +extern int captab_log_entries;
57586 +
57587 +int
57588 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57589 +{
57590 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57591 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57592 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57593 + if (cap_raised(chroot_caps, cap)) {
57594 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57595 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57596 + }
57597 + return 0;
57598 + }
57599 + }
57600 +#endif
57601 + return 1;
57602 +}
57603 +
57604 +int
57605 +gr_chroot_is_capable(const int cap)
57606 +{
57607 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57608 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57609 +#endif
57610 + return 1;
57611 +}
57612 +
57613 +int
57614 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57615 +{
57616 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57617 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57618 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57619 + if (cap_raised(chroot_caps, cap)) {
57620 + return 0;
57621 + }
57622 + }
57623 +#endif
57624 + return 1;
57625 +}
57626 +
57627 +int
57628 +gr_chroot_is_capable_nolog(const int cap)
57629 +{
57630 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57631 + return gr_task_chroot_is_capable_nolog(current, cap);
57632 +#endif
57633 + return 1;
57634 +}
57635 +
57636 +int
57637 +gr_handle_chroot_sysctl(const int op)
57638 +{
57639 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57640 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57641 + proc_is_chrooted(current))
57642 + return -EACCES;
57643 +#endif
57644 + return 0;
57645 +}
57646 +
57647 +void
57648 +gr_handle_chroot_chdir(struct path *path)
57649 +{
57650 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57651 + if (grsec_enable_chroot_chdir)
57652 + set_fs_pwd(current->fs, path);
57653 +#endif
57654 + return;
57655 +}
57656 +
57657 +int
57658 +gr_handle_chroot_chmod(const struct dentry *dentry,
57659 + const struct vfsmount *mnt, const int mode)
57660 +{
57661 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57662 + /* allow chmod +s on directories, but not files */
57663 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57664 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57665 + proc_is_chrooted(current)) {
57666 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57667 + return -EPERM;
57668 + }
57669 +#endif
57670 + return 0;
57671 +}
57672 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57673 new file mode 100644
57674 index 0000000..213ad8b
57675 --- /dev/null
57676 +++ b/grsecurity/grsec_disabled.c
57677 @@ -0,0 +1,437 @@
57678 +#include <linux/kernel.h>
57679 +#include <linux/module.h>
57680 +#include <linux/sched.h>
57681 +#include <linux/file.h>
57682 +#include <linux/fs.h>
57683 +#include <linux/kdev_t.h>
57684 +#include <linux/net.h>
57685 +#include <linux/in.h>
57686 +#include <linux/ip.h>
57687 +#include <linux/skbuff.h>
57688 +#include <linux/sysctl.h>
57689 +
57690 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57691 +void
57692 +pax_set_initial_flags(struct linux_binprm *bprm)
57693 +{
57694 + return;
57695 +}
57696 +#endif
57697 +
57698 +#ifdef CONFIG_SYSCTL
57699 +__u32
57700 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57701 +{
57702 + return 0;
57703 +}
57704 +#endif
57705 +
57706 +#ifdef CONFIG_TASKSTATS
57707 +int gr_is_taskstats_denied(int pid)
57708 +{
57709 + return 0;
57710 +}
57711 +#endif
57712 +
57713 +int
57714 +gr_acl_is_enabled(void)
57715 +{
57716 + return 0;
57717 +}
57718 +
57719 +void
57720 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57721 +{
57722 + return;
57723 +}
57724 +
57725 +int
57726 +gr_handle_rawio(const struct inode *inode)
57727 +{
57728 + return 0;
57729 +}
57730 +
57731 +void
57732 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57733 +{
57734 + return;
57735 +}
57736 +
57737 +int
57738 +gr_handle_ptrace(struct task_struct *task, const long request)
57739 +{
57740 + return 0;
57741 +}
57742 +
57743 +int
57744 +gr_handle_proc_ptrace(struct task_struct *task)
57745 +{
57746 + return 0;
57747 +}
57748 +
57749 +void
57750 +gr_learn_resource(const struct task_struct *task,
57751 + const int res, const unsigned long wanted, const int gt)
57752 +{
57753 + return;
57754 +}
57755 +
57756 +int
57757 +gr_set_acls(const int type)
57758 +{
57759 + return 0;
57760 +}
57761 +
57762 +int
57763 +gr_check_hidden_task(const struct task_struct *tsk)
57764 +{
57765 + return 0;
57766 +}
57767 +
57768 +int
57769 +gr_check_protected_task(const struct task_struct *task)
57770 +{
57771 + return 0;
57772 +}
57773 +
57774 +int
57775 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57776 +{
57777 + return 0;
57778 +}
57779 +
57780 +void
57781 +gr_copy_label(struct task_struct *tsk)
57782 +{
57783 + return;
57784 +}
57785 +
57786 +void
57787 +gr_set_pax_flags(struct task_struct *task)
57788 +{
57789 + return;
57790 +}
57791 +
57792 +int
57793 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57794 + const int unsafe_share)
57795 +{
57796 + return 0;
57797 +}
57798 +
57799 +void
57800 +gr_handle_delete(const ino_t ino, const dev_t dev)
57801 +{
57802 + return;
57803 +}
57804 +
57805 +void
57806 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57807 +{
57808 + return;
57809 +}
57810 +
57811 +void
57812 +gr_handle_crash(struct task_struct *task, const int sig)
57813 +{
57814 + return;
57815 +}
57816 +
57817 +int
57818 +gr_check_crash_exec(const struct file *filp)
57819 +{
57820 + return 0;
57821 +}
57822 +
57823 +int
57824 +gr_check_crash_uid(const uid_t uid)
57825 +{
57826 + return 0;
57827 +}
57828 +
57829 +void
57830 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57831 + struct dentry *old_dentry,
57832 + struct dentry *new_dentry,
57833 + struct vfsmount *mnt, const __u8 replace)
57834 +{
57835 + return;
57836 +}
57837 +
57838 +int
57839 +gr_search_socket(const int family, const int type, const int protocol)
57840 +{
57841 + return 1;
57842 +}
57843 +
57844 +int
57845 +gr_search_connectbind(const int mode, const struct socket *sock,
57846 + const struct sockaddr_in *addr)
57847 +{
57848 + return 0;
57849 +}
57850 +
57851 +void
57852 +gr_handle_alertkill(struct task_struct *task)
57853 +{
57854 + return;
57855 +}
57856 +
57857 +__u32
57858 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
57859 +{
57860 + return 1;
57861 +}
57862 +
57863 +__u32
57864 +gr_acl_handle_hidden_file(const struct dentry * dentry,
57865 + const struct vfsmount * mnt)
57866 +{
57867 + return 1;
57868 +}
57869 +
57870 +__u32
57871 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57872 + int acc_mode)
57873 +{
57874 + return 1;
57875 +}
57876 +
57877 +__u32
57878 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57879 +{
57880 + return 1;
57881 +}
57882 +
57883 +__u32
57884 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
57885 +{
57886 + return 1;
57887 +}
57888 +
57889 +int
57890 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
57891 + unsigned int *vm_flags)
57892 +{
57893 + return 1;
57894 +}
57895 +
57896 +__u32
57897 +gr_acl_handle_truncate(const struct dentry * dentry,
57898 + const struct vfsmount * mnt)
57899 +{
57900 + return 1;
57901 +}
57902 +
57903 +__u32
57904 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
57905 +{
57906 + return 1;
57907 +}
57908 +
57909 +__u32
57910 +gr_acl_handle_access(const struct dentry * dentry,
57911 + const struct vfsmount * mnt, const int fmode)
57912 +{
57913 + return 1;
57914 +}
57915 +
57916 +__u32
57917 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
57918 + umode_t *mode)
57919 +{
57920 + return 1;
57921 +}
57922 +
57923 +__u32
57924 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
57925 +{
57926 + return 1;
57927 +}
57928 +
57929 +__u32
57930 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
57931 +{
57932 + return 1;
57933 +}
57934 +
57935 +void
57936 +grsecurity_init(void)
57937 +{
57938 + return;
57939 +}
57940 +
57941 +umode_t gr_acl_umask(void)
57942 +{
57943 + return 0;
57944 +}
57945 +
57946 +__u32
57947 +gr_acl_handle_mknod(const struct dentry * new_dentry,
57948 + const struct dentry * parent_dentry,
57949 + const struct vfsmount * parent_mnt,
57950 + const int mode)
57951 +{
57952 + return 1;
57953 +}
57954 +
57955 +__u32
57956 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
57957 + const struct dentry * parent_dentry,
57958 + const struct vfsmount * parent_mnt)
57959 +{
57960 + return 1;
57961 +}
57962 +
57963 +__u32
57964 +gr_acl_handle_symlink(const struct dentry * new_dentry,
57965 + const struct dentry * parent_dentry,
57966 + const struct vfsmount * parent_mnt, const char *from)
57967 +{
57968 + return 1;
57969 +}
57970 +
57971 +__u32
57972 +gr_acl_handle_link(const struct dentry * new_dentry,
57973 + const struct dentry * parent_dentry,
57974 + const struct vfsmount * parent_mnt,
57975 + const struct dentry * old_dentry,
57976 + const struct vfsmount * old_mnt, const char *to)
57977 +{
57978 + return 1;
57979 +}
57980 +
57981 +int
57982 +gr_acl_handle_rename(const struct dentry *new_dentry,
57983 + const struct dentry *parent_dentry,
57984 + const struct vfsmount *parent_mnt,
57985 + const struct dentry *old_dentry,
57986 + const struct inode *old_parent_inode,
57987 + const struct vfsmount *old_mnt, const char *newname)
57988 +{
57989 + return 0;
57990 +}
57991 +
57992 +int
57993 +gr_acl_handle_filldir(const struct file *file, const char *name,
57994 + const int namelen, const ino_t ino)
57995 +{
57996 + return 1;
57997 +}
57998 +
57999 +int
58000 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58001 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58002 +{
58003 + return 1;
58004 +}
58005 +
58006 +int
58007 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58008 +{
58009 + return 0;
58010 +}
58011 +
58012 +int
58013 +gr_search_accept(const struct socket *sock)
58014 +{
58015 + return 0;
58016 +}
58017 +
58018 +int
58019 +gr_search_listen(const struct socket *sock)
58020 +{
58021 + return 0;
58022 +}
58023 +
58024 +int
58025 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58026 +{
58027 + return 0;
58028 +}
58029 +
58030 +__u32
58031 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58032 +{
58033 + return 1;
58034 +}
58035 +
58036 +__u32
58037 +gr_acl_handle_creat(const struct dentry * dentry,
58038 + const struct dentry * p_dentry,
58039 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58040 + const int imode)
58041 +{
58042 + return 1;
58043 +}
58044 +
58045 +void
58046 +gr_acl_handle_exit(void)
58047 +{
58048 + return;
58049 +}
58050 +
58051 +int
58052 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58053 +{
58054 + return 1;
58055 +}
58056 +
58057 +void
58058 +gr_set_role_label(const uid_t uid, const gid_t gid)
58059 +{
58060 + return;
58061 +}
58062 +
58063 +int
58064 +gr_acl_handle_procpidmem(const struct task_struct *task)
58065 +{
58066 + return 0;
58067 +}
58068 +
58069 +int
58070 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58071 +{
58072 + return 0;
58073 +}
58074 +
58075 +int
58076 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58077 +{
58078 + return 0;
58079 +}
58080 +
58081 +void
58082 +gr_set_kernel_label(struct task_struct *task)
58083 +{
58084 + return;
58085 +}
58086 +
58087 +int
58088 +gr_check_user_change(int real, int effective, int fs)
58089 +{
58090 + return 0;
58091 +}
58092 +
58093 +int
58094 +gr_check_group_change(int real, int effective, int fs)
58095 +{
58096 + return 0;
58097 +}
58098 +
58099 +int gr_acl_enable_at_secure(void)
58100 +{
58101 + return 0;
58102 +}
58103 +
58104 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58105 +{
58106 + return dentry->d_inode->i_sb->s_dev;
58107 +}
58108 +
58109 +EXPORT_SYMBOL(gr_learn_resource);
58110 +EXPORT_SYMBOL(gr_set_kernel_label);
58111 +#ifdef CONFIG_SECURITY
58112 +EXPORT_SYMBOL(gr_check_user_change);
58113 +EXPORT_SYMBOL(gr_check_group_change);
58114 +#endif
58115 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58116 new file mode 100644
58117 index 0000000..abfa971
58118 --- /dev/null
58119 +++ b/grsecurity/grsec_exec.c
58120 @@ -0,0 +1,174 @@
58121 +#include <linux/kernel.h>
58122 +#include <linux/sched.h>
58123 +#include <linux/file.h>
58124 +#include <linux/binfmts.h>
58125 +#include <linux/fs.h>
58126 +#include <linux/types.h>
58127 +#include <linux/grdefs.h>
58128 +#include <linux/grsecurity.h>
58129 +#include <linux/grinternal.h>
58130 +#include <linux/capability.h>
58131 +#include <linux/module.h>
58132 +
58133 +#include <asm/uaccess.h>
58134 +
58135 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58136 +static char gr_exec_arg_buf[132];
58137 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58138 +#endif
58139 +
58140 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58141 +
58142 +void
58143 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58144 +{
58145 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58146 + char *grarg = gr_exec_arg_buf;
58147 + unsigned int i, x, execlen = 0;
58148 + char c;
58149 +
58150 + if (!((grsec_enable_execlog && grsec_enable_group &&
58151 + in_group_p(grsec_audit_gid))
58152 + || (grsec_enable_execlog && !grsec_enable_group)))
58153 + return;
58154 +
58155 + mutex_lock(&gr_exec_arg_mutex);
58156 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58157 +
58158 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58159 + const char __user *p;
58160 + unsigned int len;
58161 +
58162 + p = get_user_arg_ptr(argv, i);
58163 + if (IS_ERR(p))
58164 + goto log;
58165 +
58166 + len = strnlen_user(p, 128 - execlen);
58167 + if (len > 128 - execlen)
58168 + len = 128 - execlen;
58169 + else if (len > 0)
58170 + len--;
58171 + if (copy_from_user(grarg + execlen, p, len))
58172 + goto log;
58173 +
58174 + /* rewrite unprintable characters */
58175 + for (x = 0; x < len; x++) {
58176 + c = *(grarg + execlen + x);
58177 + if (c < 32 || c > 126)
58178 + *(grarg + execlen + x) = ' ';
58179 + }
58180 +
58181 + execlen += len;
58182 + *(grarg + execlen) = ' ';
58183 + *(grarg + execlen + 1) = '\0';
58184 + execlen++;
58185 + }
58186 +
58187 + log:
58188 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58189 + bprm->file->f_path.mnt, grarg);
58190 + mutex_unlock(&gr_exec_arg_mutex);
58191 +#endif
58192 + return;
58193 +}
58194 +
58195 +#ifdef CONFIG_GRKERNSEC
58196 +extern int gr_acl_is_capable(const int cap);
58197 +extern int gr_acl_is_capable_nolog(const int cap);
58198 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58199 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58200 +extern int gr_chroot_is_capable(const int cap);
58201 +extern int gr_chroot_is_capable_nolog(const int cap);
58202 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58203 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58204 +#endif
58205 +
58206 +const char *captab_log[] = {
58207 + "CAP_CHOWN",
58208 + "CAP_DAC_OVERRIDE",
58209 + "CAP_DAC_READ_SEARCH",
58210 + "CAP_FOWNER",
58211 + "CAP_FSETID",
58212 + "CAP_KILL",
58213 + "CAP_SETGID",
58214 + "CAP_SETUID",
58215 + "CAP_SETPCAP",
58216 + "CAP_LINUX_IMMUTABLE",
58217 + "CAP_NET_BIND_SERVICE",
58218 + "CAP_NET_BROADCAST",
58219 + "CAP_NET_ADMIN",
58220 + "CAP_NET_RAW",
58221 + "CAP_IPC_LOCK",
58222 + "CAP_IPC_OWNER",
58223 + "CAP_SYS_MODULE",
58224 + "CAP_SYS_RAWIO",
58225 + "CAP_SYS_CHROOT",
58226 + "CAP_SYS_PTRACE",
58227 + "CAP_SYS_PACCT",
58228 + "CAP_SYS_ADMIN",
58229 + "CAP_SYS_BOOT",
58230 + "CAP_SYS_NICE",
58231 + "CAP_SYS_RESOURCE",
58232 + "CAP_SYS_TIME",
58233 + "CAP_SYS_TTY_CONFIG",
58234 + "CAP_MKNOD",
58235 + "CAP_LEASE",
58236 + "CAP_AUDIT_WRITE",
58237 + "CAP_AUDIT_CONTROL",
58238 + "CAP_SETFCAP",
58239 + "CAP_MAC_OVERRIDE",
58240 + "CAP_MAC_ADMIN",
58241 + "CAP_SYSLOG",
58242 + "CAP_WAKE_ALARM"
58243 +};
58244 +
58245 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58246 +
58247 +int gr_is_capable(const int cap)
58248 +{
58249 +#ifdef CONFIG_GRKERNSEC
58250 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58251 + return 1;
58252 + return 0;
58253 +#else
58254 + return 1;
58255 +#endif
58256 +}
58257 +
58258 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58259 +{
58260 +#ifdef CONFIG_GRKERNSEC
58261 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58262 + return 1;
58263 + return 0;
58264 +#else
58265 + return 1;
58266 +#endif
58267 +}
58268 +
58269 +int gr_is_capable_nolog(const int cap)
58270 +{
58271 +#ifdef CONFIG_GRKERNSEC
58272 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58273 + return 1;
58274 + return 0;
58275 +#else
58276 + return 1;
58277 +#endif
58278 +}
58279 +
58280 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58281 +{
58282 +#ifdef CONFIG_GRKERNSEC
58283 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58284 + return 1;
58285 + return 0;
58286 +#else
58287 + return 1;
58288 +#endif
58289 +}
58290 +
58291 +EXPORT_SYMBOL(gr_is_capable);
58292 +EXPORT_SYMBOL(gr_is_capable_nolog);
58293 +EXPORT_SYMBOL(gr_task_is_capable);
58294 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58295 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58296 new file mode 100644
58297 index 0000000..d3ee748
58298 --- /dev/null
58299 +++ b/grsecurity/grsec_fifo.c
58300 @@ -0,0 +1,24 @@
58301 +#include <linux/kernel.h>
58302 +#include <linux/sched.h>
58303 +#include <linux/fs.h>
58304 +#include <linux/file.h>
58305 +#include <linux/grinternal.h>
58306 +
58307 +int
58308 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58309 + const struct dentry *dir, const int flag, const int acc_mode)
58310 +{
58311 +#ifdef CONFIG_GRKERNSEC_FIFO
58312 + const struct cred *cred = current_cred();
58313 +
58314 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58315 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58316 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58317 + (cred->fsuid != dentry->d_inode->i_uid)) {
58318 + if (!inode_permission(dentry->d_inode, acc_mode))
58319 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58320 + return -EACCES;
58321 + }
58322 +#endif
58323 + return 0;
58324 +}
58325 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58326 new file mode 100644
58327 index 0000000..8ca18bf
58328 --- /dev/null
58329 +++ b/grsecurity/grsec_fork.c
58330 @@ -0,0 +1,23 @@
58331 +#include <linux/kernel.h>
58332 +#include <linux/sched.h>
58333 +#include <linux/grsecurity.h>
58334 +#include <linux/grinternal.h>
58335 +#include <linux/errno.h>
58336 +
58337 +void
58338 +gr_log_forkfail(const int retval)
58339 +{
58340 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58341 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58342 + switch (retval) {
58343 + case -EAGAIN:
58344 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58345 + break;
58346 + case -ENOMEM:
58347 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58348 + break;
58349 + }
58350 + }
58351 +#endif
58352 + return;
58353 +}
58354 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58355 new file mode 100644
58356 index 0000000..05a6015
58357 --- /dev/null
58358 +++ b/grsecurity/grsec_init.c
58359 @@ -0,0 +1,283 @@
58360 +#include <linux/kernel.h>
58361 +#include <linux/sched.h>
58362 +#include <linux/mm.h>
58363 +#include <linux/gracl.h>
58364 +#include <linux/slab.h>
58365 +#include <linux/vmalloc.h>
58366 +#include <linux/percpu.h>
58367 +#include <linux/module.h>
58368 +
58369 +int grsec_enable_ptrace_readexec;
58370 +int grsec_enable_setxid;
58371 +int grsec_enable_symlinkown;
58372 +int grsec_symlinkown_gid;
58373 +int grsec_enable_brute;
58374 +int grsec_enable_link;
58375 +int grsec_enable_dmesg;
58376 +int grsec_enable_harden_ptrace;
58377 +int grsec_enable_fifo;
58378 +int grsec_enable_execlog;
58379 +int grsec_enable_signal;
58380 +int grsec_enable_forkfail;
58381 +int grsec_enable_audit_ptrace;
58382 +int grsec_enable_time;
58383 +int grsec_enable_audit_textrel;
58384 +int grsec_enable_group;
58385 +int grsec_audit_gid;
58386 +int grsec_enable_chdir;
58387 +int grsec_enable_mount;
58388 +int grsec_enable_rofs;
58389 +int grsec_enable_chroot_findtask;
58390 +int grsec_enable_chroot_mount;
58391 +int grsec_enable_chroot_shmat;
58392 +int grsec_enable_chroot_fchdir;
58393 +int grsec_enable_chroot_double;
58394 +int grsec_enable_chroot_pivot;
58395 +int grsec_enable_chroot_chdir;
58396 +int grsec_enable_chroot_chmod;
58397 +int grsec_enable_chroot_mknod;
58398 +int grsec_enable_chroot_nice;
58399 +int grsec_enable_chroot_execlog;
58400 +int grsec_enable_chroot_caps;
58401 +int grsec_enable_chroot_sysctl;
58402 +int grsec_enable_chroot_unix;
58403 +int grsec_enable_tpe;
58404 +int grsec_tpe_gid;
58405 +int grsec_enable_blackhole;
58406 +#ifdef CONFIG_IPV6_MODULE
58407 +EXPORT_SYMBOL(grsec_enable_blackhole);
58408 +#endif
58409 +int grsec_lastack_retries;
58410 +int grsec_enable_tpe_all;
58411 +int grsec_enable_tpe_invert;
58412 +int grsec_enable_socket_all;
58413 +int grsec_socket_all_gid;
58414 +int grsec_enable_socket_client;
58415 +int grsec_socket_client_gid;
58416 +int grsec_enable_socket_server;
58417 +int grsec_socket_server_gid;
58418 +int grsec_resource_logging;
58419 +int grsec_disable_privio;
58420 +int grsec_enable_log_rwxmaps;
58421 +int grsec_lock;
58422 +
58423 +DEFINE_SPINLOCK(grsec_alert_lock);
58424 +unsigned long grsec_alert_wtime = 0;
58425 +unsigned long grsec_alert_fyet = 0;
58426 +
58427 +DEFINE_SPINLOCK(grsec_audit_lock);
58428 +
58429 +DEFINE_RWLOCK(grsec_exec_file_lock);
58430 +
58431 +char *gr_shared_page[4];
58432 +
58433 +char *gr_alert_log_fmt;
58434 +char *gr_audit_log_fmt;
58435 +char *gr_alert_log_buf;
58436 +char *gr_audit_log_buf;
58437 +
58438 +extern struct gr_arg *gr_usermode;
58439 +extern unsigned char *gr_system_salt;
58440 +extern unsigned char *gr_system_sum;
58441 +
58442 +void __init
58443 +grsecurity_init(void)
58444 +{
58445 + int j;
58446 + /* create the per-cpu shared pages */
58447 +
58448 +#ifdef CONFIG_X86
58449 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58450 +#endif
58451 +
58452 + for (j = 0; j < 4; j++) {
58453 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58454 + if (gr_shared_page[j] == NULL) {
58455 + panic("Unable to allocate grsecurity shared page");
58456 + return;
58457 + }
58458 + }
58459 +
58460 + /* allocate log buffers */
58461 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58462 + if (!gr_alert_log_fmt) {
58463 + panic("Unable to allocate grsecurity alert log format buffer");
58464 + return;
58465 + }
58466 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58467 + if (!gr_audit_log_fmt) {
58468 + panic("Unable to allocate grsecurity audit log format buffer");
58469 + return;
58470 + }
58471 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58472 + if (!gr_alert_log_buf) {
58473 + panic("Unable to allocate grsecurity alert log buffer");
58474 + return;
58475 + }
58476 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58477 + if (!gr_audit_log_buf) {
58478 + panic("Unable to allocate grsecurity audit log buffer");
58479 + return;
58480 + }
58481 +
58482 + /* allocate memory for authentication structure */
58483 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58484 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58485 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58486 +
58487 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58488 + panic("Unable to allocate grsecurity authentication structure");
58489 + return;
58490 + }
58491 +
58492 +
58493 +#ifdef CONFIG_GRKERNSEC_IO
58494 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58495 + grsec_disable_privio = 1;
58496 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58497 + grsec_disable_privio = 1;
58498 +#else
58499 + grsec_disable_privio = 0;
58500 +#endif
58501 +#endif
58502 +
58503 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58504 + /* for backward compatibility, tpe_invert always defaults to on if
58505 + enabled in the kernel
58506 + */
58507 + grsec_enable_tpe_invert = 1;
58508 +#endif
58509 +
58510 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58511 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58512 + grsec_lock = 1;
58513 +#endif
58514 +
58515 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58516 + grsec_enable_audit_textrel = 1;
58517 +#endif
58518 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58519 + grsec_enable_log_rwxmaps = 1;
58520 +#endif
58521 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58522 + grsec_enable_group = 1;
58523 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58524 +#endif
58525 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58526 + grsec_enable_ptrace_readexec = 1;
58527 +#endif
58528 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58529 + grsec_enable_chdir = 1;
58530 +#endif
58531 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58532 + grsec_enable_harden_ptrace = 1;
58533 +#endif
58534 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58535 + grsec_enable_mount = 1;
58536 +#endif
58537 +#ifdef CONFIG_GRKERNSEC_LINK
58538 + grsec_enable_link = 1;
58539 +#endif
58540 +#ifdef CONFIG_GRKERNSEC_BRUTE
58541 + grsec_enable_brute = 1;
58542 +#endif
58543 +#ifdef CONFIG_GRKERNSEC_DMESG
58544 + grsec_enable_dmesg = 1;
58545 +#endif
58546 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58547 + grsec_enable_blackhole = 1;
58548 + grsec_lastack_retries = 4;
58549 +#endif
58550 +#ifdef CONFIG_GRKERNSEC_FIFO
58551 + grsec_enable_fifo = 1;
58552 +#endif
58553 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58554 + grsec_enable_execlog = 1;
58555 +#endif
58556 +#ifdef CONFIG_GRKERNSEC_SETXID
58557 + grsec_enable_setxid = 1;
58558 +#endif
58559 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58560 + grsec_enable_signal = 1;
58561 +#endif
58562 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58563 + grsec_enable_forkfail = 1;
58564 +#endif
58565 +#ifdef CONFIG_GRKERNSEC_TIME
58566 + grsec_enable_time = 1;
58567 +#endif
58568 +#ifdef CONFIG_GRKERNSEC_RESLOG
58569 + grsec_resource_logging = 1;
58570 +#endif
58571 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58572 + grsec_enable_chroot_findtask = 1;
58573 +#endif
58574 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58575 + grsec_enable_chroot_unix = 1;
58576 +#endif
58577 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58578 + grsec_enable_chroot_mount = 1;
58579 +#endif
58580 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58581 + grsec_enable_chroot_fchdir = 1;
58582 +#endif
58583 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58584 + grsec_enable_chroot_shmat = 1;
58585 +#endif
58586 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58587 + grsec_enable_audit_ptrace = 1;
58588 +#endif
58589 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58590 + grsec_enable_chroot_double = 1;
58591 +#endif
58592 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58593 + grsec_enable_chroot_pivot = 1;
58594 +#endif
58595 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58596 + grsec_enable_chroot_chdir = 1;
58597 +#endif
58598 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58599 + grsec_enable_chroot_chmod = 1;
58600 +#endif
58601 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58602 + grsec_enable_chroot_mknod = 1;
58603 +#endif
58604 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58605 + grsec_enable_chroot_nice = 1;
58606 +#endif
58607 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58608 + grsec_enable_chroot_execlog = 1;
58609 +#endif
58610 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58611 + grsec_enable_chroot_caps = 1;
58612 +#endif
58613 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58614 + grsec_enable_chroot_sysctl = 1;
58615 +#endif
58616 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58617 + grsec_enable_symlinkown = 1;
58618 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58619 +#endif
58620 +#ifdef CONFIG_GRKERNSEC_TPE
58621 + grsec_enable_tpe = 1;
58622 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58623 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58624 + grsec_enable_tpe_all = 1;
58625 +#endif
58626 +#endif
58627 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58628 + grsec_enable_socket_all = 1;
58629 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58630 +#endif
58631 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58632 + grsec_enable_socket_client = 1;
58633 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58634 +#endif
58635 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58636 + grsec_enable_socket_server = 1;
58637 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58638 +#endif
58639 +#endif
58640 +
58641 + return;
58642 +}
58643 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58644 new file mode 100644
58645 index 0000000..589481f
58646 --- /dev/null
58647 +++ b/grsecurity/grsec_link.c
58648 @@ -0,0 +1,58 @@
58649 +#include <linux/kernel.h>
58650 +#include <linux/sched.h>
58651 +#include <linux/fs.h>
58652 +#include <linux/file.h>
58653 +#include <linux/grinternal.h>
58654 +
58655 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58656 +{
58657 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58658 + const struct inode *link_inode = link->dentry->d_inode;
58659 +
58660 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58661 + /* ignore root-owned links, e.g. /proc/self */
58662 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58663 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58664 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58665 + return 1;
58666 + }
58667 +#endif
58668 + return 0;
58669 +}
58670 +
58671 +int
58672 +gr_handle_follow_link(const struct inode *parent,
58673 + const struct inode *inode,
58674 + const struct dentry *dentry, const struct vfsmount *mnt)
58675 +{
58676 +#ifdef CONFIG_GRKERNSEC_LINK
58677 + const struct cred *cred = current_cred();
58678 +
58679 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58680 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58681 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58682 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58683 + return -EACCES;
58684 + }
58685 +#endif
58686 + return 0;
58687 +}
58688 +
58689 +int
58690 +gr_handle_hardlink(const struct dentry *dentry,
58691 + const struct vfsmount *mnt,
58692 + struct inode *inode, const int mode, const char *to)
58693 +{
58694 +#ifdef CONFIG_GRKERNSEC_LINK
58695 + const struct cred *cred = current_cred();
58696 +
58697 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58698 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58699 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58700 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58701 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58702 + return -EPERM;
58703 + }
58704 +#endif
58705 + return 0;
58706 +}
58707 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58708 new file mode 100644
58709 index 0000000..a45d2e9
58710 --- /dev/null
58711 +++ b/grsecurity/grsec_log.c
58712 @@ -0,0 +1,322 @@
58713 +#include <linux/kernel.h>
58714 +#include <linux/sched.h>
58715 +#include <linux/file.h>
58716 +#include <linux/tty.h>
58717 +#include <linux/fs.h>
58718 +#include <linux/grinternal.h>
58719 +
58720 +#ifdef CONFIG_TREE_PREEMPT_RCU
58721 +#define DISABLE_PREEMPT() preempt_disable()
58722 +#define ENABLE_PREEMPT() preempt_enable()
58723 +#else
58724 +#define DISABLE_PREEMPT()
58725 +#define ENABLE_PREEMPT()
58726 +#endif
58727 +
58728 +#define BEGIN_LOCKS(x) \
58729 + DISABLE_PREEMPT(); \
58730 + rcu_read_lock(); \
58731 + read_lock(&tasklist_lock); \
58732 + read_lock(&grsec_exec_file_lock); \
58733 + if (x != GR_DO_AUDIT) \
58734 + spin_lock(&grsec_alert_lock); \
58735 + else \
58736 + spin_lock(&grsec_audit_lock)
58737 +
58738 +#define END_LOCKS(x) \
58739 + if (x != GR_DO_AUDIT) \
58740 + spin_unlock(&grsec_alert_lock); \
58741 + else \
58742 + spin_unlock(&grsec_audit_lock); \
58743 + read_unlock(&grsec_exec_file_lock); \
58744 + read_unlock(&tasklist_lock); \
58745 + rcu_read_unlock(); \
58746 + ENABLE_PREEMPT(); \
58747 + if (x == GR_DONT_AUDIT) \
58748 + gr_handle_alertkill(current)
58749 +
58750 +enum {
58751 + FLOODING,
58752 + NO_FLOODING
58753 +};
58754 +
58755 +extern char *gr_alert_log_fmt;
58756 +extern char *gr_audit_log_fmt;
58757 +extern char *gr_alert_log_buf;
58758 +extern char *gr_audit_log_buf;
58759 +
58760 +static int gr_log_start(int audit)
58761 +{
58762 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58763 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58764 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58765 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58766 + unsigned long curr_secs = get_seconds();
58767 +
58768 + if (audit == GR_DO_AUDIT)
58769 + goto set_fmt;
58770 +
58771 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58772 + grsec_alert_wtime = curr_secs;
58773 + grsec_alert_fyet = 0;
58774 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58775 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58776 + grsec_alert_fyet++;
58777 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58778 + grsec_alert_wtime = curr_secs;
58779 + grsec_alert_fyet++;
58780 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58781 + return FLOODING;
58782 + }
58783 + else return FLOODING;
58784 +
58785 +set_fmt:
58786 +#endif
58787 + memset(buf, 0, PAGE_SIZE);
58788 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58789 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58790 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58791 + } else if (current->signal->curr_ip) {
58792 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58793 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58794 + } else if (gr_acl_is_enabled()) {
58795 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58796 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58797 + } else {
58798 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58799 + strcpy(buf, fmt);
58800 + }
58801 +
58802 + return NO_FLOODING;
58803 +}
58804 +
58805 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58806 + __attribute__ ((format (printf, 2, 0)));
58807 +
58808 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58809 +{
58810 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58811 + unsigned int len = strlen(buf);
58812 +
58813 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58814 +
58815 + return;
58816 +}
58817 +
58818 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58819 + __attribute__ ((format (printf, 2, 3)));
58820 +
58821 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58822 +{
58823 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58824 + unsigned int len = strlen(buf);
58825 + va_list ap;
58826 +
58827 + va_start(ap, msg);
58828 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58829 + va_end(ap);
58830 +
58831 + return;
58832 +}
58833 +
58834 +static void gr_log_end(int audit, int append_default)
58835 +{
58836 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58837 +
58838 + if (append_default) {
58839 + unsigned int len = strlen(buf);
58840 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58841 + }
58842 +
58843 + printk("%s\n", buf);
58844 +
58845 + return;
58846 +}
58847 +
58848 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58849 +{
58850 + int logtype;
58851 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58852 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58853 + void *voidptr = NULL;
58854 + int num1 = 0, num2 = 0;
58855 + unsigned long ulong1 = 0, ulong2 = 0;
58856 + struct dentry *dentry = NULL;
58857 + struct vfsmount *mnt = NULL;
58858 + struct file *file = NULL;
58859 + struct task_struct *task = NULL;
58860 + const struct cred *cred, *pcred;
58861 + va_list ap;
58862 +
58863 + BEGIN_LOCKS(audit);
58864 + logtype = gr_log_start(audit);
58865 + if (logtype == FLOODING) {
58866 + END_LOCKS(audit);
58867 + return;
58868 + }
58869 + va_start(ap, argtypes);
58870 + switch (argtypes) {
58871 + case GR_TTYSNIFF:
58872 + task = va_arg(ap, struct task_struct *);
58873 + 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);
58874 + break;
58875 + case GR_SYSCTL_HIDDEN:
58876 + str1 = va_arg(ap, char *);
58877 + gr_log_middle_varargs(audit, msg, result, str1);
58878 + break;
58879 + case GR_RBAC:
58880 + dentry = va_arg(ap, struct dentry *);
58881 + mnt = va_arg(ap, struct vfsmount *);
58882 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
58883 + break;
58884 + case GR_RBAC_STR:
58885 + dentry = va_arg(ap, struct dentry *);
58886 + mnt = va_arg(ap, struct vfsmount *);
58887 + str1 = va_arg(ap, char *);
58888 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
58889 + break;
58890 + case GR_STR_RBAC:
58891 + str1 = va_arg(ap, char *);
58892 + dentry = va_arg(ap, struct dentry *);
58893 + mnt = va_arg(ap, struct vfsmount *);
58894 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
58895 + break;
58896 + case GR_RBAC_MODE2:
58897 + dentry = va_arg(ap, struct dentry *);
58898 + mnt = va_arg(ap, struct vfsmount *);
58899 + str1 = va_arg(ap, char *);
58900 + str2 = va_arg(ap, char *);
58901 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
58902 + break;
58903 + case GR_RBAC_MODE3:
58904 + dentry = va_arg(ap, struct dentry *);
58905 + mnt = va_arg(ap, struct vfsmount *);
58906 + str1 = va_arg(ap, char *);
58907 + str2 = va_arg(ap, char *);
58908 + str3 = va_arg(ap, char *);
58909 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
58910 + break;
58911 + case GR_FILENAME:
58912 + dentry = va_arg(ap, struct dentry *);
58913 + mnt = va_arg(ap, struct vfsmount *);
58914 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
58915 + break;
58916 + case GR_STR_FILENAME:
58917 + str1 = va_arg(ap, char *);
58918 + dentry = va_arg(ap, struct dentry *);
58919 + mnt = va_arg(ap, struct vfsmount *);
58920 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
58921 + break;
58922 + case GR_FILENAME_STR:
58923 + dentry = va_arg(ap, struct dentry *);
58924 + mnt = va_arg(ap, struct vfsmount *);
58925 + str1 = va_arg(ap, char *);
58926 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
58927 + break;
58928 + case GR_FILENAME_TWO_INT:
58929 + dentry = va_arg(ap, struct dentry *);
58930 + mnt = va_arg(ap, struct vfsmount *);
58931 + num1 = va_arg(ap, int);
58932 + num2 = va_arg(ap, int);
58933 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
58934 + break;
58935 + case GR_FILENAME_TWO_INT_STR:
58936 + dentry = va_arg(ap, struct dentry *);
58937 + mnt = va_arg(ap, struct vfsmount *);
58938 + num1 = va_arg(ap, int);
58939 + num2 = va_arg(ap, int);
58940 + str1 = va_arg(ap, char *);
58941 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
58942 + break;
58943 + case GR_TEXTREL:
58944 + file = va_arg(ap, struct file *);
58945 + ulong1 = va_arg(ap, unsigned long);
58946 + ulong2 = va_arg(ap, unsigned long);
58947 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
58948 + break;
58949 + case GR_PTRACE:
58950 + task = va_arg(ap, struct task_struct *);
58951 + 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);
58952 + break;
58953 + case GR_RESOURCE:
58954 + task = va_arg(ap, struct task_struct *);
58955 + cred = __task_cred(task);
58956 + pcred = __task_cred(task->real_parent);
58957 + ulong1 = va_arg(ap, unsigned long);
58958 + str1 = va_arg(ap, char *);
58959 + ulong2 = va_arg(ap, unsigned long);
58960 + 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);
58961 + break;
58962 + case GR_CAP:
58963 + task = va_arg(ap, struct task_struct *);
58964 + cred = __task_cred(task);
58965 + pcred = __task_cred(task->real_parent);
58966 + str1 = va_arg(ap, char *);
58967 + 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);
58968 + break;
58969 + case GR_SIG:
58970 + str1 = va_arg(ap, char *);
58971 + voidptr = va_arg(ap, void *);
58972 + gr_log_middle_varargs(audit, msg, str1, voidptr);
58973 + break;
58974 + case GR_SIG2:
58975 + task = va_arg(ap, struct task_struct *);
58976 + cred = __task_cred(task);
58977 + pcred = __task_cred(task->real_parent);
58978 + num1 = va_arg(ap, int);
58979 + 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);
58980 + break;
58981 + case GR_CRASH1:
58982 + task = va_arg(ap, struct task_struct *);
58983 + cred = __task_cred(task);
58984 + pcred = __task_cred(task->real_parent);
58985 + ulong1 = va_arg(ap, unsigned long);
58986 + 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);
58987 + break;
58988 + case GR_CRASH2:
58989 + task = va_arg(ap, struct task_struct *);
58990 + cred = __task_cred(task);
58991 + pcred = __task_cred(task->real_parent);
58992 + ulong1 = va_arg(ap, unsigned long);
58993 + 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);
58994 + break;
58995 + case GR_RWXMAP:
58996 + file = va_arg(ap, struct file *);
58997 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
58998 + break;
58999 + case GR_PSACCT:
59000 + {
59001 + unsigned int wday, cday;
59002 + __u8 whr, chr;
59003 + __u8 wmin, cmin;
59004 + __u8 wsec, csec;
59005 + char cur_tty[64] = { 0 };
59006 + char parent_tty[64] = { 0 };
59007 +
59008 + task = va_arg(ap, struct task_struct *);
59009 + wday = va_arg(ap, unsigned int);
59010 + cday = va_arg(ap, unsigned int);
59011 + whr = va_arg(ap, int);
59012 + chr = va_arg(ap, int);
59013 + wmin = va_arg(ap, int);
59014 + cmin = va_arg(ap, int);
59015 + wsec = va_arg(ap, int);
59016 + csec = va_arg(ap, int);
59017 + ulong1 = va_arg(ap, unsigned long);
59018 + cred = __task_cred(task);
59019 + pcred = __task_cred(task->real_parent);
59020 +
59021 + 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);
59022 + }
59023 + break;
59024 + default:
59025 + gr_log_middle(audit, msg, ap);
59026 + }
59027 + va_end(ap);
59028 + // these don't need DEFAULTSECARGS printed on the end
59029 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59030 + gr_log_end(audit, 0);
59031 + else
59032 + gr_log_end(audit, 1);
59033 + END_LOCKS(audit);
59034 +}
59035 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59036 new file mode 100644
59037 index 0000000..f536303
59038 --- /dev/null
59039 +++ b/grsecurity/grsec_mem.c
59040 @@ -0,0 +1,40 @@
59041 +#include <linux/kernel.h>
59042 +#include <linux/sched.h>
59043 +#include <linux/mm.h>
59044 +#include <linux/mman.h>
59045 +#include <linux/grinternal.h>
59046 +
59047 +void
59048 +gr_handle_ioperm(void)
59049 +{
59050 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59051 + return;
59052 +}
59053 +
59054 +void
59055 +gr_handle_iopl(void)
59056 +{
59057 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59058 + return;
59059 +}
59060 +
59061 +void
59062 +gr_handle_mem_readwrite(u64 from, u64 to)
59063 +{
59064 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59065 + return;
59066 +}
59067 +
59068 +void
59069 +gr_handle_vm86(void)
59070 +{
59071 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59072 + return;
59073 +}
59074 +
59075 +void
59076 +gr_log_badprocpid(const char *entry)
59077 +{
59078 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59079 + return;
59080 +}
59081 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59082 new file mode 100644
59083 index 0000000..2131422
59084 --- /dev/null
59085 +++ b/grsecurity/grsec_mount.c
59086 @@ -0,0 +1,62 @@
59087 +#include <linux/kernel.h>
59088 +#include <linux/sched.h>
59089 +#include <linux/mount.h>
59090 +#include <linux/grsecurity.h>
59091 +#include <linux/grinternal.h>
59092 +
59093 +void
59094 +gr_log_remount(const char *devname, const int retval)
59095 +{
59096 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59097 + if (grsec_enable_mount && (retval >= 0))
59098 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59099 +#endif
59100 + return;
59101 +}
59102 +
59103 +void
59104 +gr_log_unmount(const char *devname, const int retval)
59105 +{
59106 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59107 + if (grsec_enable_mount && (retval >= 0))
59108 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59109 +#endif
59110 + return;
59111 +}
59112 +
59113 +void
59114 +gr_log_mount(const char *from, const char *to, const int retval)
59115 +{
59116 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59117 + if (grsec_enable_mount && (retval >= 0))
59118 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59119 +#endif
59120 + return;
59121 +}
59122 +
59123 +int
59124 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59125 +{
59126 +#ifdef CONFIG_GRKERNSEC_ROFS
59127 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59128 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59129 + return -EPERM;
59130 + } else
59131 + return 0;
59132 +#endif
59133 + return 0;
59134 +}
59135 +
59136 +int
59137 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59138 +{
59139 +#ifdef CONFIG_GRKERNSEC_ROFS
59140 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59141 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59142 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59143 + return -EPERM;
59144 + } else
59145 + return 0;
59146 +#endif
59147 + return 0;
59148 +}
59149 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59150 new file mode 100644
59151 index 0000000..a3b12a0
59152 --- /dev/null
59153 +++ b/grsecurity/grsec_pax.c
59154 @@ -0,0 +1,36 @@
59155 +#include <linux/kernel.h>
59156 +#include <linux/sched.h>
59157 +#include <linux/mm.h>
59158 +#include <linux/file.h>
59159 +#include <linux/grinternal.h>
59160 +#include <linux/grsecurity.h>
59161 +
59162 +void
59163 +gr_log_textrel(struct vm_area_struct * vma)
59164 +{
59165 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59166 + if (grsec_enable_audit_textrel)
59167 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59168 +#endif
59169 + return;
59170 +}
59171 +
59172 +void
59173 +gr_log_rwxmmap(struct file *file)
59174 +{
59175 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59176 + if (grsec_enable_log_rwxmaps)
59177 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59178 +#endif
59179 + return;
59180 +}
59181 +
59182 +void
59183 +gr_log_rwxmprotect(struct file *file)
59184 +{
59185 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59186 + if (grsec_enable_log_rwxmaps)
59187 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59188 +#endif
59189 + return;
59190 +}
59191 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59192 new file mode 100644
59193 index 0000000..f7f29aa
59194 --- /dev/null
59195 +++ b/grsecurity/grsec_ptrace.c
59196 @@ -0,0 +1,30 @@
59197 +#include <linux/kernel.h>
59198 +#include <linux/sched.h>
59199 +#include <linux/grinternal.h>
59200 +#include <linux/security.h>
59201 +
59202 +void
59203 +gr_audit_ptrace(struct task_struct *task)
59204 +{
59205 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59206 + if (grsec_enable_audit_ptrace)
59207 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59208 +#endif
59209 + return;
59210 +}
59211 +
59212 +int
59213 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59214 +{
59215 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59216 + const struct dentry *dentry = file->f_path.dentry;
59217 + const struct vfsmount *mnt = file->f_path.mnt;
59218 +
59219 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59220 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59221 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59222 + return -EACCES;
59223 + }
59224 +#endif
59225 + return 0;
59226 +}
59227 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59228 new file mode 100644
59229 index 0000000..b4ac94c
59230 --- /dev/null
59231 +++ b/grsecurity/grsec_sig.c
59232 @@ -0,0 +1,209 @@
59233 +#include <linux/kernel.h>
59234 +#include <linux/sched.h>
59235 +#include <linux/delay.h>
59236 +#include <linux/grsecurity.h>
59237 +#include <linux/grinternal.h>
59238 +#include <linux/hardirq.h>
59239 +
59240 +char *signames[] = {
59241 + [SIGSEGV] = "Segmentation fault",
59242 + [SIGILL] = "Illegal instruction",
59243 + [SIGABRT] = "Abort",
59244 + [SIGBUS] = "Invalid alignment/Bus error"
59245 +};
59246 +
59247 +void
59248 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59249 +{
59250 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59251 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59252 + (sig == SIGABRT) || (sig == SIGBUS))) {
59253 + if (t->pid == current->pid) {
59254 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59255 + } else {
59256 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59257 + }
59258 + }
59259 +#endif
59260 + return;
59261 +}
59262 +
59263 +int
59264 +gr_handle_signal(const struct task_struct *p, const int sig)
59265 +{
59266 +#ifdef CONFIG_GRKERNSEC
59267 + /* ignore the 0 signal for protected task checks */
59268 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59269 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59270 + return -EPERM;
59271 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59272 + return -EPERM;
59273 + }
59274 +#endif
59275 + return 0;
59276 +}
59277 +
59278 +#ifdef CONFIG_GRKERNSEC
59279 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59280 +
59281 +int gr_fake_force_sig(int sig, struct task_struct *t)
59282 +{
59283 + unsigned long int flags;
59284 + int ret, blocked, ignored;
59285 + struct k_sigaction *action;
59286 +
59287 + spin_lock_irqsave(&t->sighand->siglock, flags);
59288 + action = &t->sighand->action[sig-1];
59289 + ignored = action->sa.sa_handler == SIG_IGN;
59290 + blocked = sigismember(&t->blocked, sig);
59291 + if (blocked || ignored) {
59292 + action->sa.sa_handler = SIG_DFL;
59293 + if (blocked) {
59294 + sigdelset(&t->blocked, sig);
59295 + recalc_sigpending_and_wake(t);
59296 + }
59297 + }
59298 + if (action->sa.sa_handler == SIG_DFL)
59299 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59300 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59301 +
59302 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59303 +
59304 + return ret;
59305 +}
59306 +#endif
59307 +
59308 +#ifdef CONFIG_GRKERNSEC_BRUTE
59309 +#define GR_USER_BAN_TIME (15 * 60)
59310 +
59311 +static int __get_dumpable(unsigned long mm_flags)
59312 +{
59313 + int ret;
59314 +
59315 + ret = mm_flags & MMF_DUMPABLE_MASK;
59316 + return (ret >= 2) ? 2 : ret;
59317 +}
59318 +#endif
59319 +
59320 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59321 +{
59322 +#ifdef CONFIG_GRKERNSEC_BRUTE
59323 + kuid_t uid = GLOBAL_ROOT_UID;
59324 +
59325 + if (!grsec_enable_brute)
59326 + return;
59327 +
59328 + rcu_read_lock();
59329 + read_lock(&tasklist_lock);
59330 + read_lock(&grsec_exec_file_lock);
59331 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59332 + p->real_parent->brute = 1;
59333 + else {
59334 + const struct cred *cred = __task_cred(p), *cred2;
59335 + struct task_struct *tsk, *tsk2;
59336 +
59337 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59338 + struct user_struct *user;
59339 +
59340 + uid = cred->uid;
59341 +
59342 + /* this is put upon execution past expiration */
59343 + user = find_user(uid);
59344 + if (user == NULL)
59345 + goto unlock;
59346 + user->banned = 1;
59347 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59348 + if (user->ban_expires == ~0UL)
59349 + user->ban_expires--;
59350 +
59351 + do_each_thread(tsk2, tsk) {
59352 + cred2 = __task_cred(tsk);
59353 + if (tsk != p && uid_eq(cred2->uid, uid))
59354 + gr_fake_force_sig(SIGKILL, tsk);
59355 + } while_each_thread(tsk2, tsk);
59356 + }
59357 + }
59358 +unlock:
59359 + read_unlock(&grsec_exec_file_lock);
59360 + read_unlock(&tasklist_lock);
59361 + rcu_read_unlock();
59362 +
59363 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59364 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59365 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59366 +
59367 +#endif
59368 + return;
59369 +}
59370 +
59371 +void gr_handle_brute_check(void)
59372 +{
59373 +#ifdef CONFIG_GRKERNSEC_BRUTE
59374 + if (current->brute)
59375 + msleep(30 * 1000);
59376 +#endif
59377 + return;
59378 +}
59379 +
59380 +void gr_handle_kernel_exploit(void)
59381 +{
59382 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59383 + const struct cred *cred;
59384 + struct task_struct *tsk, *tsk2;
59385 + struct user_struct *user;
59386 + kuid_t uid;
59387 +
59388 + if (in_irq() || in_serving_softirq() || in_nmi())
59389 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59390 +
59391 + uid = current_uid();
59392 +
59393 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59394 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59395 + else {
59396 + /* kill all the processes of this user, hold a reference
59397 + to their creds struct, and prevent them from creating
59398 + another process until system reset
59399 + */
59400 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59401 + from_kuid_munged(&init_user_ns, uid));
59402 + /* we intentionally leak this ref */
59403 + user = get_uid(current->cred->user);
59404 + if (user) {
59405 + user->banned = 1;
59406 + user->ban_expires = ~0UL;
59407 + }
59408 +
59409 + read_lock(&tasklist_lock);
59410 + do_each_thread(tsk2, tsk) {
59411 + cred = __task_cred(tsk);
59412 + if (uid_eq(cred->uid, uid))
59413 + gr_fake_force_sig(SIGKILL, tsk);
59414 + } while_each_thread(tsk2, tsk);
59415 + read_unlock(&tasklist_lock);
59416 + }
59417 +#endif
59418 +}
59419 +
59420 +int __gr_process_user_ban(struct user_struct *user)
59421 +{
59422 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59423 + if (unlikely(user->banned)) {
59424 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59425 + user->banned = 0;
59426 + user->ban_expires = 0;
59427 + free_uid(user);
59428 + } else
59429 + return -EPERM;
59430 + }
59431 +#endif
59432 + return 0;
59433 +}
59434 +
59435 +int gr_process_user_ban(void)
59436 +{
59437 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59438 + return __gr_process_user_ban(current->cred->user);
59439 +#endif
59440 + return 0;
59441 +}
59442 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59443 new file mode 100644
59444 index 0000000..4030d57
59445 --- /dev/null
59446 +++ b/grsecurity/grsec_sock.c
59447 @@ -0,0 +1,244 @@
59448 +#include <linux/kernel.h>
59449 +#include <linux/module.h>
59450 +#include <linux/sched.h>
59451 +#include <linux/file.h>
59452 +#include <linux/net.h>
59453 +#include <linux/in.h>
59454 +#include <linux/ip.h>
59455 +#include <net/sock.h>
59456 +#include <net/inet_sock.h>
59457 +#include <linux/grsecurity.h>
59458 +#include <linux/grinternal.h>
59459 +#include <linux/gracl.h>
59460 +
59461 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59462 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59463 +
59464 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59465 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59466 +
59467 +#ifdef CONFIG_UNIX_MODULE
59468 +EXPORT_SYMBOL(gr_acl_handle_unix);
59469 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59470 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59471 +EXPORT_SYMBOL(gr_handle_create);
59472 +#endif
59473 +
59474 +#ifdef CONFIG_GRKERNSEC
59475 +#define gr_conn_table_size 32749
59476 +struct conn_table_entry {
59477 + struct conn_table_entry *next;
59478 + struct signal_struct *sig;
59479 +};
59480 +
59481 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59482 +DEFINE_SPINLOCK(gr_conn_table_lock);
59483 +
59484 +extern const char * gr_socktype_to_name(unsigned char type);
59485 +extern const char * gr_proto_to_name(unsigned char proto);
59486 +extern const char * gr_sockfamily_to_name(unsigned char family);
59487 +
59488 +static __inline__ int
59489 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59490 +{
59491 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59492 +}
59493 +
59494 +static __inline__ int
59495 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59496 + __u16 sport, __u16 dport)
59497 +{
59498 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59499 + sig->gr_sport == sport && sig->gr_dport == dport))
59500 + return 1;
59501 + else
59502 + return 0;
59503 +}
59504 +
59505 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59506 +{
59507 + struct conn_table_entry **match;
59508 + unsigned int index;
59509 +
59510 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59511 + sig->gr_sport, sig->gr_dport,
59512 + gr_conn_table_size);
59513 +
59514 + newent->sig = sig;
59515 +
59516 + match = &gr_conn_table[index];
59517 + newent->next = *match;
59518 + *match = newent;
59519 +
59520 + return;
59521 +}
59522 +
59523 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59524 +{
59525 + struct conn_table_entry *match, *last = NULL;
59526 + unsigned int index;
59527 +
59528 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59529 + sig->gr_sport, sig->gr_dport,
59530 + gr_conn_table_size);
59531 +
59532 + match = gr_conn_table[index];
59533 + while (match && !conn_match(match->sig,
59534 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59535 + sig->gr_dport)) {
59536 + last = match;
59537 + match = match->next;
59538 + }
59539 +
59540 + if (match) {
59541 + if (last)
59542 + last->next = match->next;
59543 + else
59544 + gr_conn_table[index] = NULL;
59545 + kfree(match);
59546 + }
59547 +
59548 + return;
59549 +}
59550 +
59551 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59552 + __u16 sport, __u16 dport)
59553 +{
59554 + struct conn_table_entry *match;
59555 + unsigned int index;
59556 +
59557 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59558 +
59559 + match = gr_conn_table[index];
59560 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59561 + match = match->next;
59562 +
59563 + if (match)
59564 + return match->sig;
59565 + else
59566 + return NULL;
59567 +}
59568 +
59569 +#endif
59570 +
59571 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59572 +{
59573 +#ifdef CONFIG_GRKERNSEC
59574 + struct signal_struct *sig = task->signal;
59575 + struct conn_table_entry *newent;
59576 +
59577 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59578 + if (newent == NULL)
59579 + return;
59580 + /* no bh lock needed since we are called with bh disabled */
59581 + spin_lock(&gr_conn_table_lock);
59582 + gr_del_task_from_ip_table_nolock(sig);
59583 + sig->gr_saddr = inet->inet_rcv_saddr;
59584 + sig->gr_daddr = inet->inet_daddr;
59585 + sig->gr_sport = inet->inet_sport;
59586 + sig->gr_dport = inet->inet_dport;
59587 + gr_add_to_task_ip_table_nolock(sig, newent);
59588 + spin_unlock(&gr_conn_table_lock);
59589 +#endif
59590 + return;
59591 +}
59592 +
59593 +void gr_del_task_from_ip_table(struct task_struct *task)
59594 +{
59595 +#ifdef CONFIG_GRKERNSEC
59596 + spin_lock_bh(&gr_conn_table_lock);
59597 + gr_del_task_from_ip_table_nolock(task->signal);
59598 + spin_unlock_bh(&gr_conn_table_lock);
59599 +#endif
59600 + return;
59601 +}
59602 +
59603 +void
59604 +gr_attach_curr_ip(const struct sock *sk)
59605 +{
59606 +#ifdef CONFIG_GRKERNSEC
59607 + struct signal_struct *p, *set;
59608 + const struct inet_sock *inet = inet_sk(sk);
59609 +
59610 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59611 + return;
59612 +
59613 + set = current->signal;
59614 +
59615 + spin_lock_bh(&gr_conn_table_lock);
59616 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59617 + inet->inet_dport, inet->inet_sport);
59618 + if (unlikely(p != NULL)) {
59619 + set->curr_ip = p->curr_ip;
59620 + set->used_accept = 1;
59621 + gr_del_task_from_ip_table_nolock(p);
59622 + spin_unlock_bh(&gr_conn_table_lock);
59623 + return;
59624 + }
59625 + spin_unlock_bh(&gr_conn_table_lock);
59626 +
59627 + set->curr_ip = inet->inet_daddr;
59628 + set->used_accept = 1;
59629 +#endif
59630 + return;
59631 +}
59632 +
59633 +int
59634 +gr_handle_sock_all(const int family, const int type, const int protocol)
59635 +{
59636 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59637 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59638 + (family != AF_UNIX)) {
59639 + if (family == AF_INET)
59640 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59641 + else
59642 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59643 + return -EACCES;
59644 + }
59645 +#endif
59646 + return 0;
59647 +}
59648 +
59649 +int
59650 +gr_handle_sock_server(const struct sockaddr *sck)
59651 +{
59652 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59653 + if (grsec_enable_socket_server &&
59654 + in_group_p(grsec_socket_server_gid) &&
59655 + sck && (sck->sa_family != AF_UNIX) &&
59656 + (sck->sa_family != AF_LOCAL)) {
59657 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59658 + return -EACCES;
59659 + }
59660 +#endif
59661 + return 0;
59662 +}
59663 +
59664 +int
59665 +gr_handle_sock_server_other(const struct sock *sck)
59666 +{
59667 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59668 + if (grsec_enable_socket_server &&
59669 + in_group_p(grsec_socket_server_gid) &&
59670 + sck && (sck->sk_family != AF_UNIX) &&
59671 + (sck->sk_family != AF_LOCAL)) {
59672 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59673 + return -EACCES;
59674 + }
59675 +#endif
59676 + return 0;
59677 +}
59678 +
59679 +int
59680 +gr_handle_sock_client(const struct sockaddr *sck)
59681 +{
59682 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59683 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59684 + sck && (sck->sa_family != AF_UNIX) &&
59685 + (sck->sa_family != AF_LOCAL)) {
59686 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59687 + return -EACCES;
59688 + }
59689 +#endif
59690 + return 0;
59691 +}
59692 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59693 new file mode 100644
59694 index 0000000..f55ef0f
59695 --- /dev/null
59696 +++ b/grsecurity/grsec_sysctl.c
59697 @@ -0,0 +1,469 @@
59698 +#include <linux/kernel.h>
59699 +#include <linux/sched.h>
59700 +#include <linux/sysctl.h>
59701 +#include <linux/grsecurity.h>
59702 +#include <linux/grinternal.h>
59703 +
59704 +int
59705 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59706 +{
59707 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59708 + if (dirname == NULL || name == NULL)
59709 + return 0;
59710 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59711 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59712 + return -EACCES;
59713 + }
59714 +#endif
59715 + return 0;
59716 +}
59717 +
59718 +#ifdef CONFIG_GRKERNSEC_ROFS
59719 +static int __maybe_unused one = 1;
59720 +#endif
59721 +
59722 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59723 +struct ctl_table grsecurity_table[] = {
59724 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59725 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59726 +#ifdef CONFIG_GRKERNSEC_IO
59727 + {
59728 + .procname = "disable_priv_io",
59729 + .data = &grsec_disable_privio,
59730 + .maxlen = sizeof(int),
59731 + .mode = 0600,
59732 + .proc_handler = &proc_dointvec,
59733 + },
59734 +#endif
59735 +#endif
59736 +#ifdef CONFIG_GRKERNSEC_LINK
59737 + {
59738 + .procname = "linking_restrictions",
59739 + .data = &grsec_enable_link,
59740 + .maxlen = sizeof(int),
59741 + .mode = 0600,
59742 + .proc_handler = &proc_dointvec,
59743 + },
59744 +#endif
59745 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59746 + {
59747 + .procname = "enforce_symlinksifowner",
59748 + .data = &grsec_enable_symlinkown,
59749 + .maxlen = sizeof(int),
59750 + .mode = 0600,
59751 + .proc_handler = &proc_dointvec,
59752 + },
59753 + {
59754 + .procname = "symlinkown_gid",
59755 + .data = &grsec_symlinkown_gid,
59756 + .maxlen = sizeof(int),
59757 + .mode = 0600,
59758 + .proc_handler = &proc_dointvec,
59759 + },
59760 +#endif
59761 +#ifdef CONFIG_GRKERNSEC_BRUTE
59762 + {
59763 + .procname = "deter_bruteforce",
59764 + .data = &grsec_enable_brute,
59765 + .maxlen = sizeof(int),
59766 + .mode = 0600,
59767 + .proc_handler = &proc_dointvec,
59768 + },
59769 +#endif
59770 +#ifdef CONFIG_GRKERNSEC_FIFO
59771 + {
59772 + .procname = "fifo_restrictions",
59773 + .data = &grsec_enable_fifo,
59774 + .maxlen = sizeof(int),
59775 + .mode = 0600,
59776 + .proc_handler = &proc_dointvec,
59777 + },
59778 +#endif
59779 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59780 + {
59781 + .procname = "ptrace_readexec",
59782 + .data = &grsec_enable_ptrace_readexec,
59783 + .maxlen = sizeof(int),
59784 + .mode = 0600,
59785 + .proc_handler = &proc_dointvec,
59786 + },
59787 +#endif
59788 +#ifdef CONFIG_GRKERNSEC_SETXID
59789 + {
59790 + .procname = "consistent_setxid",
59791 + .data = &grsec_enable_setxid,
59792 + .maxlen = sizeof(int),
59793 + .mode = 0600,
59794 + .proc_handler = &proc_dointvec,
59795 + },
59796 +#endif
59797 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59798 + {
59799 + .procname = "ip_blackhole",
59800 + .data = &grsec_enable_blackhole,
59801 + .maxlen = sizeof(int),
59802 + .mode = 0600,
59803 + .proc_handler = &proc_dointvec,
59804 + },
59805 + {
59806 + .procname = "lastack_retries",
59807 + .data = &grsec_lastack_retries,
59808 + .maxlen = sizeof(int),
59809 + .mode = 0600,
59810 + .proc_handler = &proc_dointvec,
59811 + },
59812 +#endif
59813 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59814 + {
59815 + .procname = "exec_logging",
59816 + .data = &grsec_enable_execlog,
59817 + .maxlen = sizeof(int),
59818 + .mode = 0600,
59819 + .proc_handler = &proc_dointvec,
59820 + },
59821 +#endif
59822 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59823 + {
59824 + .procname = "rwxmap_logging",
59825 + .data = &grsec_enable_log_rwxmaps,
59826 + .maxlen = sizeof(int),
59827 + .mode = 0600,
59828 + .proc_handler = &proc_dointvec,
59829 + },
59830 +#endif
59831 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59832 + {
59833 + .procname = "signal_logging",
59834 + .data = &grsec_enable_signal,
59835 + .maxlen = sizeof(int),
59836 + .mode = 0600,
59837 + .proc_handler = &proc_dointvec,
59838 + },
59839 +#endif
59840 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59841 + {
59842 + .procname = "forkfail_logging",
59843 + .data = &grsec_enable_forkfail,
59844 + .maxlen = sizeof(int),
59845 + .mode = 0600,
59846 + .proc_handler = &proc_dointvec,
59847 + },
59848 +#endif
59849 +#ifdef CONFIG_GRKERNSEC_TIME
59850 + {
59851 + .procname = "timechange_logging",
59852 + .data = &grsec_enable_time,
59853 + .maxlen = sizeof(int),
59854 + .mode = 0600,
59855 + .proc_handler = &proc_dointvec,
59856 + },
59857 +#endif
59858 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59859 + {
59860 + .procname = "chroot_deny_shmat",
59861 + .data = &grsec_enable_chroot_shmat,
59862 + .maxlen = sizeof(int),
59863 + .mode = 0600,
59864 + .proc_handler = &proc_dointvec,
59865 + },
59866 +#endif
59867 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59868 + {
59869 + .procname = "chroot_deny_unix",
59870 + .data = &grsec_enable_chroot_unix,
59871 + .maxlen = sizeof(int),
59872 + .mode = 0600,
59873 + .proc_handler = &proc_dointvec,
59874 + },
59875 +#endif
59876 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59877 + {
59878 + .procname = "chroot_deny_mount",
59879 + .data = &grsec_enable_chroot_mount,
59880 + .maxlen = sizeof(int),
59881 + .mode = 0600,
59882 + .proc_handler = &proc_dointvec,
59883 + },
59884 +#endif
59885 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59886 + {
59887 + .procname = "chroot_deny_fchdir",
59888 + .data = &grsec_enable_chroot_fchdir,
59889 + .maxlen = sizeof(int),
59890 + .mode = 0600,
59891 + .proc_handler = &proc_dointvec,
59892 + },
59893 +#endif
59894 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59895 + {
59896 + .procname = "chroot_deny_chroot",
59897 + .data = &grsec_enable_chroot_double,
59898 + .maxlen = sizeof(int),
59899 + .mode = 0600,
59900 + .proc_handler = &proc_dointvec,
59901 + },
59902 +#endif
59903 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59904 + {
59905 + .procname = "chroot_deny_pivot",
59906 + .data = &grsec_enable_chroot_pivot,
59907 + .maxlen = sizeof(int),
59908 + .mode = 0600,
59909 + .proc_handler = &proc_dointvec,
59910 + },
59911 +#endif
59912 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59913 + {
59914 + .procname = "chroot_enforce_chdir",
59915 + .data = &grsec_enable_chroot_chdir,
59916 + .maxlen = sizeof(int),
59917 + .mode = 0600,
59918 + .proc_handler = &proc_dointvec,
59919 + },
59920 +#endif
59921 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59922 + {
59923 + .procname = "chroot_deny_chmod",
59924 + .data = &grsec_enable_chroot_chmod,
59925 + .maxlen = sizeof(int),
59926 + .mode = 0600,
59927 + .proc_handler = &proc_dointvec,
59928 + },
59929 +#endif
59930 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59931 + {
59932 + .procname = "chroot_deny_mknod",
59933 + .data = &grsec_enable_chroot_mknod,
59934 + .maxlen = sizeof(int),
59935 + .mode = 0600,
59936 + .proc_handler = &proc_dointvec,
59937 + },
59938 +#endif
59939 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59940 + {
59941 + .procname = "chroot_restrict_nice",
59942 + .data = &grsec_enable_chroot_nice,
59943 + .maxlen = sizeof(int),
59944 + .mode = 0600,
59945 + .proc_handler = &proc_dointvec,
59946 + },
59947 +#endif
59948 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59949 + {
59950 + .procname = "chroot_execlog",
59951 + .data = &grsec_enable_chroot_execlog,
59952 + .maxlen = sizeof(int),
59953 + .mode = 0600,
59954 + .proc_handler = &proc_dointvec,
59955 + },
59956 +#endif
59957 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59958 + {
59959 + .procname = "chroot_caps",
59960 + .data = &grsec_enable_chroot_caps,
59961 + .maxlen = sizeof(int),
59962 + .mode = 0600,
59963 + .proc_handler = &proc_dointvec,
59964 + },
59965 +#endif
59966 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59967 + {
59968 + .procname = "chroot_deny_sysctl",
59969 + .data = &grsec_enable_chroot_sysctl,
59970 + .maxlen = sizeof(int),
59971 + .mode = 0600,
59972 + .proc_handler = &proc_dointvec,
59973 + },
59974 +#endif
59975 +#ifdef CONFIG_GRKERNSEC_TPE
59976 + {
59977 + .procname = "tpe",
59978 + .data = &grsec_enable_tpe,
59979 + .maxlen = sizeof(int),
59980 + .mode = 0600,
59981 + .proc_handler = &proc_dointvec,
59982 + },
59983 + {
59984 + .procname = "tpe_gid",
59985 + .data = &grsec_tpe_gid,
59986 + .maxlen = sizeof(int),
59987 + .mode = 0600,
59988 + .proc_handler = &proc_dointvec,
59989 + },
59990 +#endif
59991 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
59992 + {
59993 + .procname = "tpe_invert",
59994 + .data = &grsec_enable_tpe_invert,
59995 + .maxlen = sizeof(int),
59996 + .mode = 0600,
59997 + .proc_handler = &proc_dointvec,
59998 + },
59999 +#endif
60000 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60001 + {
60002 + .procname = "tpe_restrict_all",
60003 + .data = &grsec_enable_tpe_all,
60004 + .maxlen = sizeof(int),
60005 + .mode = 0600,
60006 + .proc_handler = &proc_dointvec,
60007 + },
60008 +#endif
60009 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60010 + {
60011 + .procname = "socket_all",
60012 + .data = &grsec_enable_socket_all,
60013 + .maxlen = sizeof(int),
60014 + .mode = 0600,
60015 + .proc_handler = &proc_dointvec,
60016 + },
60017 + {
60018 + .procname = "socket_all_gid",
60019 + .data = &grsec_socket_all_gid,
60020 + .maxlen = sizeof(int),
60021 + .mode = 0600,
60022 + .proc_handler = &proc_dointvec,
60023 + },
60024 +#endif
60025 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60026 + {
60027 + .procname = "socket_client",
60028 + .data = &grsec_enable_socket_client,
60029 + .maxlen = sizeof(int),
60030 + .mode = 0600,
60031 + .proc_handler = &proc_dointvec,
60032 + },
60033 + {
60034 + .procname = "socket_client_gid",
60035 + .data = &grsec_socket_client_gid,
60036 + .maxlen = sizeof(int),
60037 + .mode = 0600,
60038 + .proc_handler = &proc_dointvec,
60039 + },
60040 +#endif
60041 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60042 + {
60043 + .procname = "socket_server",
60044 + .data = &grsec_enable_socket_server,
60045 + .maxlen = sizeof(int),
60046 + .mode = 0600,
60047 + .proc_handler = &proc_dointvec,
60048 + },
60049 + {
60050 + .procname = "socket_server_gid",
60051 + .data = &grsec_socket_server_gid,
60052 + .maxlen = sizeof(int),
60053 + .mode = 0600,
60054 + .proc_handler = &proc_dointvec,
60055 + },
60056 +#endif
60057 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60058 + {
60059 + .procname = "audit_group",
60060 + .data = &grsec_enable_group,
60061 + .maxlen = sizeof(int),
60062 + .mode = 0600,
60063 + .proc_handler = &proc_dointvec,
60064 + },
60065 + {
60066 + .procname = "audit_gid",
60067 + .data = &grsec_audit_gid,
60068 + .maxlen = sizeof(int),
60069 + .mode = 0600,
60070 + .proc_handler = &proc_dointvec,
60071 + },
60072 +#endif
60073 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60074 + {
60075 + .procname = "audit_chdir",
60076 + .data = &grsec_enable_chdir,
60077 + .maxlen = sizeof(int),
60078 + .mode = 0600,
60079 + .proc_handler = &proc_dointvec,
60080 + },
60081 +#endif
60082 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60083 + {
60084 + .procname = "audit_mount",
60085 + .data = &grsec_enable_mount,
60086 + .maxlen = sizeof(int),
60087 + .mode = 0600,
60088 + .proc_handler = &proc_dointvec,
60089 + },
60090 +#endif
60091 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60092 + {
60093 + .procname = "audit_textrel",
60094 + .data = &grsec_enable_audit_textrel,
60095 + .maxlen = sizeof(int),
60096 + .mode = 0600,
60097 + .proc_handler = &proc_dointvec,
60098 + },
60099 +#endif
60100 +#ifdef CONFIG_GRKERNSEC_DMESG
60101 + {
60102 + .procname = "dmesg",
60103 + .data = &grsec_enable_dmesg,
60104 + .maxlen = sizeof(int),
60105 + .mode = 0600,
60106 + .proc_handler = &proc_dointvec,
60107 + },
60108 +#endif
60109 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60110 + {
60111 + .procname = "chroot_findtask",
60112 + .data = &grsec_enable_chroot_findtask,
60113 + .maxlen = sizeof(int),
60114 + .mode = 0600,
60115 + .proc_handler = &proc_dointvec,
60116 + },
60117 +#endif
60118 +#ifdef CONFIG_GRKERNSEC_RESLOG
60119 + {
60120 + .procname = "resource_logging",
60121 + .data = &grsec_resource_logging,
60122 + .maxlen = sizeof(int),
60123 + .mode = 0600,
60124 + .proc_handler = &proc_dointvec,
60125 + },
60126 +#endif
60127 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60128 + {
60129 + .procname = "audit_ptrace",
60130 + .data = &grsec_enable_audit_ptrace,
60131 + .maxlen = sizeof(int),
60132 + .mode = 0600,
60133 + .proc_handler = &proc_dointvec,
60134 + },
60135 +#endif
60136 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60137 + {
60138 + .procname = "harden_ptrace",
60139 + .data = &grsec_enable_harden_ptrace,
60140 + .maxlen = sizeof(int),
60141 + .mode = 0600,
60142 + .proc_handler = &proc_dointvec,
60143 + },
60144 +#endif
60145 + {
60146 + .procname = "grsec_lock",
60147 + .data = &grsec_lock,
60148 + .maxlen = sizeof(int),
60149 + .mode = 0600,
60150 + .proc_handler = &proc_dointvec,
60151 + },
60152 +#endif
60153 +#ifdef CONFIG_GRKERNSEC_ROFS
60154 + {
60155 + .procname = "romount_protect",
60156 + .data = &grsec_enable_rofs,
60157 + .maxlen = sizeof(int),
60158 + .mode = 0600,
60159 + .proc_handler = &proc_dointvec_minmax,
60160 + .extra1 = &one,
60161 + .extra2 = &one,
60162 + },
60163 +#endif
60164 + { }
60165 +};
60166 +#endif
60167 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60168 new file mode 100644
60169 index 0000000..0dc13c3
60170 --- /dev/null
60171 +++ b/grsecurity/grsec_time.c
60172 @@ -0,0 +1,16 @@
60173 +#include <linux/kernel.h>
60174 +#include <linux/sched.h>
60175 +#include <linux/grinternal.h>
60176 +#include <linux/module.h>
60177 +
60178 +void
60179 +gr_log_timechange(void)
60180 +{
60181 +#ifdef CONFIG_GRKERNSEC_TIME
60182 + if (grsec_enable_time)
60183 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60184 +#endif
60185 + return;
60186 +}
60187 +
60188 +EXPORT_SYMBOL(gr_log_timechange);
60189 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60190 new file mode 100644
60191 index 0000000..07e0dc0
60192 --- /dev/null
60193 +++ b/grsecurity/grsec_tpe.c
60194 @@ -0,0 +1,73 @@
60195 +#include <linux/kernel.h>
60196 +#include <linux/sched.h>
60197 +#include <linux/file.h>
60198 +#include <linux/fs.h>
60199 +#include <linux/grinternal.h>
60200 +
60201 +extern int gr_acl_tpe_check(void);
60202 +
60203 +int
60204 +gr_tpe_allow(const struct file *file)
60205 +{
60206 +#ifdef CONFIG_GRKERNSEC
60207 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60208 + const struct cred *cred = current_cred();
60209 + char *msg = NULL;
60210 + char *msg2 = NULL;
60211 +
60212 + // never restrict root
60213 + if (!cred->uid)
60214 + return 1;
60215 +
60216 + if (grsec_enable_tpe) {
60217 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60218 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60219 + msg = "not being in trusted group";
60220 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60221 + msg = "being in untrusted group";
60222 +#else
60223 + if (in_group_p(grsec_tpe_gid))
60224 + msg = "being in untrusted group";
60225 +#endif
60226 + }
60227 + if (!msg && gr_acl_tpe_check())
60228 + msg = "being in untrusted role";
60229 +
60230 + // not in any affected group/role
60231 + if (!msg)
60232 + goto next_check;
60233 +
60234 + if (inode->i_uid)
60235 + msg2 = "file in non-root-owned directory";
60236 + else if (inode->i_mode & S_IWOTH)
60237 + msg2 = "file in world-writable directory";
60238 + else if (inode->i_mode & S_IWGRP)
60239 + msg2 = "file in group-writable directory";
60240 +
60241 + if (msg && msg2) {
60242 + char fullmsg[70] = {0};
60243 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60244 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60245 + return 0;
60246 + }
60247 + msg = NULL;
60248 +next_check:
60249 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60250 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60251 + return 1;
60252 +
60253 + if (inode->i_uid && (inode->i_uid != cred->uid))
60254 + msg = "directory not owned by user";
60255 + else if (inode->i_mode & S_IWOTH)
60256 + msg = "file in world-writable directory";
60257 + else if (inode->i_mode & S_IWGRP)
60258 + msg = "file in group-writable directory";
60259 +
60260 + if (msg) {
60261 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60262 + return 0;
60263 + }
60264 +#endif
60265 +#endif
60266 + return 1;
60267 +}
60268 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60269 new file mode 100644
60270 index 0000000..9f7b1ac
60271 --- /dev/null
60272 +++ b/grsecurity/grsum.c
60273 @@ -0,0 +1,61 @@
60274 +#include <linux/err.h>
60275 +#include <linux/kernel.h>
60276 +#include <linux/sched.h>
60277 +#include <linux/mm.h>
60278 +#include <linux/scatterlist.h>
60279 +#include <linux/crypto.h>
60280 +#include <linux/gracl.h>
60281 +
60282 +
60283 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60284 +#error "crypto and sha256 must be built into the kernel"
60285 +#endif
60286 +
60287 +int
60288 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60289 +{
60290 + char *p;
60291 + struct crypto_hash *tfm;
60292 + struct hash_desc desc;
60293 + struct scatterlist sg;
60294 + unsigned char temp_sum[GR_SHA_LEN];
60295 + volatile int retval = 0;
60296 + volatile int dummy = 0;
60297 + unsigned int i;
60298 +
60299 + sg_init_table(&sg, 1);
60300 +
60301 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60302 + if (IS_ERR(tfm)) {
60303 + /* should never happen, since sha256 should be built in */
60304 + return 1;
60305 + }
60306 +
60307 + desc.tfm = tfm;
60308 + desc.flags = 0;
60309 +
60310 + crypto_hash_init(&desc);
60311 +
60312 + p = salt;
60313 + sg_set_buf(&sg, p, GR_SALT_LEN);
60314 + crypto_hash_update(&desc, &sg, sg.length);
60315 +
60316 + p = entry->pw;
60317 + sg_set_buf(&sg, p, strlen(p));
60318 +
60319 + crypto_hash_update(&desc, &sg, sg.length);
60320 +
60321 + crypto_hash_final(&desc, temp_sum);
60322 +
60323 + memset(entry->pw, 0, GR_PW_LEN);
60324 +
60325 + for (i = 0; i < GR_SHA_LEN; i++)
60326 + if (sum[i] != temp_sum[i])
60327 + retval = 1;
60328 + else
60329 + dummy = 1; // waste a cycle
60330 +
60331 + crypto_free_hash(tfm);
60332 +
60333 + return retval;
60334 +}
60335 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60336 index bde976e..a1cc32a 100644
60337 --- a/include/acpi/acpi_bus.h
60338 +++ b/include/acpi/acpi_bus.h
60339 @@ -136,7 +136,7 @@ struct acpi_device_ops {
60340 acpi_op_bind bind;
60341 acpi_op_unbind unbind;
60342 acpi_op_notify notify;
60343 -};
60344 +} __no_const;
60345
60346 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60347
60348 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60349 index 77ff547..181834f 100644
60350 --- a/include/asm-generic/4level-fixup.h
60351 +++ b/include/asm-generic/4level-fixup.h
60352 @@ -13,8 +13,10 @@
60353 #define pmd_alloc(mm, pud, address) \
60354 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60355 NULL: pmd_offset(pud, address))
60356 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60357
60358 #define pud_alloc(mm, pgd, address) (pgd)
60359 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60360 #define pud_offset(pgd, start) (pgd)
60361 #define pud_none(pud) 0
60362 #define pud_bad(pud) 0
60363 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60364 index b7babf0..3ba8aee 100644
60365 --- a/include/asm-generic/atomic-long.h
60366 +++ b/include/asm-generic/atomic-long.h
60367 @@ -22,6 +22,12 @@
60368
60369 typedef atomic64_t atomic_long_t;
60370
60371 +#ifdef CONFIG_PAX_REFCOUNT
60372 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60373 +#else
60374 +typedef atomic64_t atomic_long_unchecked_t;
60375 +#endif
60376 +
60377 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60378
60379 static inline long atomic_long_read(atomic_long_t *l)
60380 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60381 return (long)atomic64_read(v);
60382 }
60383
60384 +#ifdef CONFIG_PAX_REFCOUNT
60385 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60386 +{
60387 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60388 +
60389 + return (long)atomic64_read_unchecked(v);
60390 +}
60391 +#endif
60392 +
60393 static inline void atomic_long_set(atomic_long_t *l, long i)
60394 {
60395 atomic64_t *v = (atomic64_t *)l;
60396 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60397 atomic64_set(v, i);
60398 }
60399
60400 +#ifdef CONFIG_PAX_REFCOUNT
60401 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60402 +{
60403 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60404 +
60405 + atomic64_set_unchecked(v, i);
60406 +}
60407 +#endif
60408 +
60409 static inline void atomic_long_inc(atomic_long_t *l)
60410 {
60411 atomic64_t *v = (atomic64_t *)l;
60412 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60413 atomic64_inc(v);
60414 }
60415
60416 +#ifdef CONFIG_PAX_REFCOUNT
60417 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60418 +{
60419 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60420 +
60421 + atomic64_inc_unchecked(v);
60422 +}
60423 +#endif
60424 +
60425 static inline void atomic_long_dec(atomic_long_t *l)
60426 {
60427 atomic64_t *v = (atomic64_t *)l;
60428 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60429 atomic64_dec(v);
60430 }
60431
60432 +#ifdef CONFIG_PAX_REFCOUNT
60433 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60434 +{
60435 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60436 +
60437 + atomic64_dec_unchecked(v);
60438 +}
60439 +#endif
60440 +
60441 static inline void atomic_long_add(long i, atomic_long_t *l)
60442 {
60443 atomic64_t *v = (atomic64_t *)l;
60444 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60445 atomic64_add(i, v);
60446 }
60447
60448 +#ifdef CONFIG_PAX_REFCOUNT
60449 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60450 +{
60451 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60452 +
60453 + atomic64_add_unchecked(i, v);
60454 +}
60455 +#endif
60456 +
60457 static inline void atomic_long_sub(long i, atomic_long_t *l)
60458 {
60459 atomic64_t *v = (atomic64_t *)l;
60460 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60461 atomic64_sub(i, v);
60462 }
60463
60464 +#ifdef CONFIG_PAX_REFCOUNT
60465 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60466 +{
60467 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60468 +
60469 + atomic64_sub_unchecked(i, v);
60470 +}
60471 +#endif
60472 +
60473 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60474 {
60475 atomic64_t *v = (atomic64_t *)l;
60476 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60477 return (long)atomic64_inc_return(v);
60478 }
60479
60480 +#ifdef CONFIG_PAX_REFCOUNT
60481 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60482 +{
60483 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60484 +
60485 + return (long)atomic64_inc_return_unchecked(v);
60486 +}
60487 +#endif
60488 +
60489 static inline long atomic_long_dec_return(atomic_long_t *l)
60490 {
60491 atomic64_t *v = (atomic64_t *)l;
60492 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60493
60494 typedef atomic_t atomic_long_t;
60495
60496 +#ifdef CONFIG_PAX_REFCOUNT
60497 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60498 +#else
60499 +typedef atomic_t atomic_long_unchecked_t;
60500 +#endif
60501 +
60502 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60503 static inline long atomic_long_read(atomic_long_t *l)
60504 {
60505 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60506 return (long)atomic_read(v);
60507 }
60508
60509 +#ifdef CONFIG_PAX_REFCOUNT
60510 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60511 +{
60512 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60513 +
60514 + return (long)atomic_read_unchecked(v);
60515 +}
60516 +#endif
60517 +
60518 static inline void atomic_long_set(atomic_long_t *l, long i)
60519 {
60520 atomic_t *v = (atomic_t *)l;
60521 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60522 atomic_set(v, i);
60523 }
60524
60525 +#ifdef CONFIG_PAX_REFCOUNT
60526 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60527 +{
60528 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60529 +
60530 + atomic_set_unchecked(v, i);
60531 +}
60532 +#endif
60533 +
60534 static inline void atomic_long_inc(atomic_long_t *l)
60535 {
60536 atomic_t *v = (atomic_t *)l;
60537 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60538 atomic_inc(v);
60539 }
60540
60541 +#ifdef CONFIG_PAX_REFCOUNT
60542 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60543 +{
60544 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60545 +
60546 + atomic_inc_unchecked(v);
60547 +}
60548 +#endif
60549 +
60550 static inline void atomic_long_dec(atomic_long_t *l)
60551 {
60552 atomic_t *v = (atomic_t *)l;
60553 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60554 atomic_dec(v);
60555 }
60556
60557 +#ifdef CONFIG_PAX_REFCOUNT
60558 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60559 +{
60560 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60561 +
60562 + atomic_dec_unchecked(v);
60563 +}
60564 +#endif
60565 +
60566 static inline void atomic_long_add(long i, atomic_long_t *l)
60567 {
60568 atomic_t *v = (atomic_t *)l;
60569 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60570 atomic_add(i, v);
60571 }
60572
60573 +#ifdef CONFIG_PAX_REFCOUNT
60574 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60575 +{
60576 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60577 +
60578 + atomic_add_unchecked(i, v);
60579 +}
60580 +#endif
60581 +
60582 static inline void atomic_long_sub(long i, atomic_long_t *l)
60583 {
60584 atomic_t *v = (atomic_t *)l;
60585 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60586 atomic_sub(i, v);
60587 }
60588
60589 +#ifdef CONFIG_PAX_REFCOUNT
60590 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60591 +{
60592 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60593 +
60594 + atomic_sub_unchecked(i, v);
60595 +}
60596 +#endif
60597 +
60598 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60599 {
60600 atomic_t *v = (atomic_t *)l;
60601 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60602 return (long)atomic_inc_return(v);
60603 }
60604
60605 +#ifdef CONFIG_PAX_REFCOUNT
60606 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60607 +{
60608 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60609 +
60610 + return (long)atomic_inc_return_unchecked(v);
60611 +}
60612 +#endif
60613 +
60614 static inline long atomic_long_dec_return(atomic_long_t *l)
60615 {
60616 atomic_t *v = (atomic_t *)l;
60617 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60618
60619 #endif /* BITS_PER_LONG == 64 */
60620
60621 +#ifdef CONFIG_PAX_REFCOUNT
60622 +static inline void pax_refcount_needs_these_functions(void)
60623 +{
60624 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60625 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60626 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60627 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60628 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60629 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60630 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60631 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60632 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60633 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60634 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60635 +#ifdef CONFIG_X86
60636 + atomic_clear_mask_unchecked(0, NULL);
60637 + atomic_set_mask_unchecked(0, NULL);
60638 +#endif
60639 +
60640 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60641 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60642 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60643 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60644 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60645 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60646 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60647 +}
60648 +#else
60649 +#define atomic_read_unchecked(v) atomic_read(v)
60650 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60651 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60652 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60653 +#define atomic_inc_unchecked(v) atomic_inc(v)
60654 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60655 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60656 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60657 +#define atomic_dec_unchecked(v) atomic_dec(v)
60658 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60659 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60660 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60661 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60662 +
60663 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60664 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60665 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60666 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60667 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60668 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60669 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60670 +#endif
60671 +
60672 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60673 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60674 index 1ced641..c896ee8 100644
60675 --- a/include/asm-generic/atomic.h
60676 +++ b/include/asm-generic/atomic.h
60677 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60678 * Atomically clears the bits set in @mask from @v
60679 */
60680 #ifndef atomic_clear_mask
60681 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60682 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60683 {
60684 unsigned long flags;
60685
60686 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60687 index b18ce4f..2ee2843 100644
60688 --- a/include/asm-generic/atomic64.h
60689 +++ b/include/asm-generic/atomic64.h
60690 @@ -16,6 +16,8 @@ typedef struct {
60691 long long counter;
60692 } atomic64_t;
60693
60694 +typedef atomic64_t atomic64_unchecked_t;
60695 +
60696 #define ATOMIC64_INIT(i) { (i) }
60697
60698 extern long long atomic64_read(const atomic64_t *v);
60699 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60700 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60701 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60702
60703 +#define atomic64_read_unchecked(v) atomic64_read(v)
60704 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60705 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60706 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60707 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60708 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60709 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60710 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60711 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60712 +
60713 #endif /* _ASM_GENERIC_ATOMIC64_H */
60714 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60715 index 1bfcfe5..e04c5c9 100644
60716 --- a/include/asm-generic/cache.h
60717 +++ b/include/asm-generic/cache.h
60718 @@ -6,7 +6,7 @@
60719 * cache lines need to provide their own cache.h.
60720 */
60721
60722 -#define L1_CACHE_SHIFT 5
60723 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60724 +#define L1_CACHE_SHIFT 5UL
60725 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60726
60727 #endif /* __ASM_GENERIC_CACHE_H */
60728 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60729 index 0d68a1e..b74a761 100644
60730 --- a/include/asm-generic/emergency-restart.h
60731 +++ b/include/asm-generic/emergency-restart.h
60732 @@ -1,7 +1,7 @@
60733 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60734 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60735
60736 -static inline void machine_emergency_restart(void)
60737 +static inline __noreturn void machine_emergency_restart(void)
60738 {
60739 machine_restart(NULL);
60740 }
60741 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60742 index 90f99c7..00ce236 100644
60743 --- a/include/asm-generic/kmap_types.h
60744 +++ b/include/asm-generic/kmap_types.h
60745 @@ -2,9 +2,9 @@
60746 #define _ASM_GENERIC_KMAP_TYPES_H
60747
60748 #ifdef __WITH_KM_FENCE
60749 -# define KM_TYPE_NR 41
60750 +# define KM_TYPE_NR 42
60751 #else
60752 -# define KM_TYPE_NR 20
60753 +# define KM_TYPE_NR 21
60754 #endif
60755
60756 #endif
60757 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60758 index 9ceb03b..2efbcbd 100644
60759 --- a/include/asm-generic/local.h
60760 +++ b/include/asm-generic/local.h
60761 @@ -39,6 +39,7 @@ typedef struct
60762 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60763 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60764 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60765 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60766
60767 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60768 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60769 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60770 index 725612b..9cc513a 100644
60771 --- a/include/asm-generic/pgtable-nopmd.h
60772 +++ b/include/asm-generic/pgtable-nopmd.h
60773 @@ -1,14 +1,19 @@
60774 #ifndef _PGTABLE_NOPMD_H
60775 #define _PGTABLE_NOPMD_H
60776
60777 -#ifndef __ASSEMBLY__
60778 -
60779 #include <asm-generic/pgtable-nopud.h>
60780
60781 -struct mm_struct;
60782 -
60783 #define __PAGETABLE_PMD_FOLDED
60784
60785 +#define PMD_SHIFT PUD_SHIFT
60786 +#define PTRS_PER_PMD 1
60787 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60788 +#define PMD_MASK (~(PMD_SIZE-1))
60789 +
60790 +#ifndef __ASSEMBLY__
60791 +
60792 +struct mm_struct;
60793 +
60794 /*
60795 * Having the pmd type consist of a pud gets the size right, and allows
60796 * us to conceptually access the pud entry that this pmd is folded into
60797 @@ -16,11 +21,6 @@ struct mm_struct;
60798 */
60799 typedef struct { pud_t pud; } pmd_t;
60800
60801 -#define PMD_SHIFT PUD_SHIFT
60802 -#define PTRS_PER_PMD 1
60803 -#define PMD_SIZE (1UL << PMD_SHIFT)
60804 -#define PMD_MASK (~(PMD_SIZE-1))
60805 -
60806 /*
60807 * The "pud_xxx()" functions here are trivial for a folded two-level
60808 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60809 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60810 index 810431d..0ec4804f 100644
60811 --- a/include/asm-generic/pgtable-nopud.h
60812 +++ b/include/asm-generic/pgtable-nopud.h
60813 @@ -1,10 +1,15 @@
60814 #ifndef _PGTABLE_NOPUD_H
60815 #define _PGTABLE_NOPUD_H
60816
60817 -#ifndef __ASSEMBLY__
60818 -
60819 #define __PAGETABLE_PUD_FOLDED
60820
60821 +#define PUD_SHIFT PGDIR_SHIFT
60822 +#define PTRS_PER_PUD 1
60823 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60824 +#define PUD_MASK (~(PUD_SIZE-1))
60825 +
60826 +#ifndef __ASSEMBLY__
60827 +
60828 /*
60829 * Having the pud type consist of a pgd gets the size right, and allows
60830 * us to conceptually access the pgd entry that this pud is folded into
60831 @@ -12,11 +17,6 @@
60832 */
60833 typedef struct { pgd_t pgd; } pud_t;
60834
60835 -#define PUD_SHIFT PGDIR_SHIFT
60836 -#define PTRS_PER_PUD 1
60837 -#define PUD_SIZE (1UL << PUD_SHIFT)
60838 -#define PUD_MASK (~(PUD_SIZE-1))
60839 -
60840 /*
60841 * The "pgd_xxx()" functions here are trivial for a folded two-level
60842 * setup: the pud is never bad, and a pud always exists (as it's folded
60843 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60844 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60845
60846 #define pgd_populate(mm, pgd, pud) do { } while (0)
60847 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60848 /*
60849 * (puds are folded into pgds so this doesn't get actually called,
60850 * but the define is needed for a generic inline function.)
60851 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60852 index ff4947b..f48183f 100644
60853 --- a/include/asm-generic/pgtable.h
60854 +++ b/include/asm-generic/pgtable.h
60855 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
60856 #endif
60857 }
60858
60859 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
60860 +static inline unsigned long pax_open_kernel(void) { return 0; }
60861 +#endif
60862 +
60863 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
60864 +static inline unsigned long pax_close_kernel(void) { return 0; }
60865 +#endif
60866 +
60867 #endif /* CONFIG_MMU */
60868
60869 #endif /* !__ASSEMBLY__ */
60870 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
60871 index 4e2e1cc..12c266b 100644
60872 --- a/include/asm-generic/vmlinux.lds.h
60873 +++ b/include/asm-generic/vmlinux.lds.h
60874 @@ -218,6 +218,7 @@
60875 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
60876 VMLINUX_SYMBOL(__start_rodata) = .; \
60877 *(.rodata) *(.rodata.*) \
60878 + *(.data..read_only) \
60879 *(__vermagic) /* Kernel version magic */ \
60880 . = ALIGN(8); \
60881 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
60882 @@ -716,17 +717,18 @@
60883 * section in the linker script will go there too. @phdr should have
60884 * a leading colon.
60885 *
60886 - * Note that this macros defines __per_cpu_load as an absolute symbol.
60887 + * Note that this macros defines per_cpu_load as an absolute symbol.
60888 * If there is no need to put the percpu section at a predetermined
60889 * address, use PERCPU_SECTION.
60890 */
60891 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
60892 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
60893 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
60894 + per_cpu_load = .; \
60895 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
60896 - LOAD_OFFSET) { \
60897 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
60898 PERCPU_INPUT(cacheline) \
60899 } phdr \
60900 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
60901 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
60902
60903 /**
60904 * PERCPU_SECTION - define output section for percpu area, simple version
60905 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
60906 index d6b67bb..a272c29 100644
60907 --- a/include/drm/drmP.h
60908 +++ b/include/drm/drmP.h
60909 @@ -72,6 +72,7 @@
60910 #include <linux/workqueue.h>
60911 #include <linux/poll.h>
60912 #include <asm/pgalloc.h>
60913 +#include <asm/local.h>
60914 #include "drm.h"
60915
60916 #include <linux/idr.h>
60917 @@ -1067,7 +1068,7 @@ struct drm_device {
60918
60919 /** \name Usage Counters */
60920 /*@{ */
60921 - int open_count; /**< Outstanding files open */
60922 + local_t open_count; /**< Outstanding files open */
60923 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
60924 atomic_t vma_count; /**< Outstanding vma areas open */
60925 int buf_use; /**< Buffers in use -- cannot alloc */
60926 @@ -1078,7 +1079,7 @@ struct drm_device {
60927 /*@{ */
60928 unsigned long counters;
60929 enum drm_stat_type types[15];
60930 - atomic_t counts[15];
60931 + atomic_unchecked_t counts[15];
60932 /*@} */
60933
60934 struct list_head filelist;
60935 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
60936 index e01cc80..319855d 100644
60937 --- a/include/drm/drm_crtc_helper.h
60938 +++ b/include/drm/drm_crtc_helper.h
60939 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
60940
60941 /* disable crtc when not in use - more explicit than dpms off */
60942 void (*disable)(struct drm_crtc *crtc);
60943 -};
60944 +} __no_const;
60945
60946 /**
60947 * drm_encoder_helper_funcs - helper operations for encoders
60948 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
60949 struct drm_connector *connector);
60950 /* disable encoder when not in use - more explicit than dpms off */
60951 void (*disable)(struct drm_encoder *encoder);
60952 -};
60953 +} __no_const;
60954
60955 /**
60956 * drm_connector_helper_funcs - helper operations for connectors
60957 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
60958 index d6d1da4..fdd1ac5 100644
60959 --- a/include/drm/ttm/ttm_memory.h
60960 +++ b/include/drm/ttm/ttm_memory.h
60961 @@ -48,7 +48,7 @@
60962
60963 struct ttm_mem_shrink {
60964 int (*do_shrink) (struct ttm_mem_shrink *);
60965 -};
60966 +} __no_const;
60967
60968 /**
60969 * struct ttm_mem_global - Global memory accounting structure.
60970 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
60971 index e86dfca..40cc55f 100644
60972 --- a/include/linux/a.out.h
60973 +++ b/include/linux/a.out.h
60974 @@ -39,6 +39,14 @@ enum machine_type {
60975 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
60976 };
60977
60978 +/* Constants for the N_FLAGS field */
60979 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
60980 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
60981 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
60982 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
60983 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
60984 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
60985 +
60986 #if !defined (N_MAGIC)
60987 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
60988 #endif
60989 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
60990 index 06fd4bb..1caec0d 100644
60991 --- a/include/linux/atmdev.h
60992 +++ b/include/linux/atmdev.h
60993 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
60994 #endif
60995
60996 struct k_atm_aal_stats {
60997 -#define __HANDLE_ITEM(i) atomic_t i
60998 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
60999 __AAL_STAT_ITEMS
61000 #undef __HANDLE_ITEM
61001 };
61002 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61003 index 366422b..1fa7f84 100644
61004 --- a/include/linux/binfmts.h
61005 +++ b/include/linux/binfmts.h
61006 @@ -89,6 +89,7 @@ struct linux_binfmt {
61007 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61008 int (*load_shlib)(struct file *);
61009 int (*core_dump)(struct coredump_params *cprm);
61010 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61011 unsigned long min_coredump; /* minimal dump size */
61012 };
61013
61014 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61015 index 4a2ab7c..a2de7a8 100644
61016 --- a/include/linux/blkdev.h
61017 +++ b/include/linux/blkdev.h
61018 @@ -1420,7 +1420,7 @@ struct block_device_operations {
61019 /* this callback is with swap_lock and sometimes page table lock held */
61020 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61021 struct module *owner;
61022 -};
61023 +} __do_const;
61024
61025 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61026 unsigned long);
61027 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61028 index 4d1a074..88f929a 100644
61029 --- a/include/linux/blktrace_api.h
61030 +++ b/include/linux/blktrace_api.h
61031 @@ -162,7 +162,7 @@ struct blk_trace {
61032 struct dentry *dir;
61033 struct dentry *dropped_file;
61034 struct dentry *msg_file;
61035 - atomic_t dropped;
61036 + atomic_unchecked_t dropped;
61037 };
61038
61039 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61040 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61041 index 83195fb..0b0f77d 100644
61042 --- a/include/linux/byteorder/little_endian.h
61043 +++ b/include/linux/byteorder/little_endian.h
61044 @@ -42,51 +42,51 @@
61045
61046 static inline __le64 __cpu_to_le64p(const __u64 *p)
61047 {
61048 - return (__force __le64)*p;
61049 + return (__force const __le64)*p;
61050 }
61051 static inline __u64 __le64_to_cpup(const __le64 *p)
61052 {
61053 - return (__force __u64)*p;
61054 + return (__force const __u64)*p;
61055 }
61056 static inline __le32 __cpu_to_le32p(const __u32 *p)
61057 {
61058 - return (__force __le32)*p;
61059 + return (__force const __le32)*p;
61060 }
61061 static inline __u32 __le32_to_cpup(const __le32 *p)
61062 {
61063 - return (__force __u32)*p;
61064 + return (__force const __u32)*p;
61065 }
61066 static inline __le16 __cpu_to_le16p(const __u16 *p)
61067 {
61068 - return (__force __le16)*p;
61069 + return (__force const __le16)*p;
61070 }
61071 static inline __u16 __le16_to_cpup(const __le16 *p)
61072 {
61073 - return (__force __u16)*p;
61074 + return (__force const __u16)*p;
61075 }
61076 static inline __be64 __cpu_to_be64p(const __u64 *p)
61077 {
61078 - return (__force __be64)__swab64p(p);
61079 + return (__force const __be64)__swab64p(p);
61080 }
61081 static inline __u64 __be64_to_cpup(const __be64 *p)
61082 {
61083 - return __swab64p((__u64 *)p);
61084 + return __swab64p((const __u64 *)p);
61085 }
61086 static inline __be32 __cpu_to_be32p(const __u32 *p)
61087 {
61088 - return (__force __be32)__swab32p(p);
61089 + return (__force const __be32)__swab32p(p);
61090 }
61091 static inline __u32 __be32_to_cpup(const __be32 *p)
61092 {
61093 - return __swab32p((__u32 *)p);
61094 + return __swab32p((const __u32 *)p);
61095 }
61096 static inline __be16 __cpu_to_be16p(const __u16 *p)
61097 {
61098 - return (__force __be16)__swab16p(p);
61099 + return (__force const __be16)__swab16p(p);
61100 }
61101 static inline __u16 __be16_to_cpup(const __be16 *p)
61102 {
61103 - return __swab16p((__u16 *)p);
61104 + return __swab16p((const __u16 *)p);
61105 }
61106 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61107 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61108 diff --git a/include/linux/cache.h b/include/linux/cache.h
61109 index 4c57065..4307975 100644
61110 --- a/include/linux/cache.h
61111 +++ b/include/linux/cache.h
61112 @@ -16,6 +16,10 @@
61113 #define __read_mostly
61114 #endif
61115
61116 +#ifndef __read_only
61117 +#define __read_only __read_mostly
61118 +#endif
61119 +
61120 #ifndef ____cacheline_aligned
61121 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61122 #endif
61123 diff --git a/include/linux/capability.h b/include/linux/capability.h
61124 index d10b7ed..0288b79 100644
61125 --- a/include/linux/capability.h
61126 +++ b/include/linux/capability.h
61127 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61128 extern bool ns_capable(struct user_namespace *ns, int cap);
61129 extern bool nsown_capable(int cap);
61130 extern bool inode_capable(const struct inode *inode, int cap);
61131 +extern bool capable_nolog(int cap);
61132 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61133 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61134
61135 /* audit system wants to get cap info from files as well */
61136 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61137
61138 +extern int is_privileged_binary(const struct dentry *dentry);
61139 +
61140 #endif /* __KERNEL__ */
61141
61142 #endif /* !_LINUX_CAPABILITY_H */
61143 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61144 index 42e55de..1cd0e66 100644
61145 --- a/include/linux/cleancache.h
61146 +++ b/include/linux/cleancache.h
61147 @@ -31,7 +31,7 @@ struct cleancache_ops {
61148 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61149 void (*invalidate_inode)(int, struct cleancache_filekey);
61150 void (*invalidate_fs)(int);
61151 -};
61152 +} __no_const;
61153
61154 extern struct cleancache_ops
61155 cleancache_register_ops(struct cleancache_ops *ops);
61156 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61157 index 77335fa..6cbe7dd 100644
61158 --- a/include/linux/clk-provider.h
61159 +++ b/include/linux/clk-provider.h
61160 @@ -111,6 +111,7 @@ struct clk_ops {
61161 unsigned long);
61162 void (*init)(struct clk_hw *hw);
61163 };
61164 +typedef struct clk_ops __no_const clk_ops_no_const;
61165
61166 /**
61167 * struct clk_init_data - holds init data that's common to all clocks and is
61168 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61169 index 934bc34..1b47129 100644
61170 --- a/include/linux/compiler-gcc4.h
61171 +++ b/include/linux/compiler-gcc4.h
61172 @@ -32,6 +32,21 @@
61173 #define __linktime_error(message) __attribute__((__error__(message)))
61174
61175 #if __GNUC_MINOR__ >= 5
61176 +
61177 +#ifdef CONSTIFY_PLUGIN
61178 +#define __no_const __attribute__((no_const))
61179 +#define __do_const __attribute__((do_const))
61180 +#endif
61181 +
61182 +#ifdef SIZE_OVERFLOW_PLUGIN
61183 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61184 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61185 +#endif
61186 +
61187 +#ifdef LATENT_ENTROPY_PLUGIN
61188 +#define __latent_entropy __attribute__((latent_entropy))
61189 +#endif
61190 +
61191 /*
61192 * Mark a position in code as unreachable. This can be used to
61193 * suppress control flow warnings after asm blocks that transfer
61194 @@ -47,6 +62,11 @@
61195 #define __noclone __attribute__((__noclone__))
61196
61197 #endif
61198 +
61199 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61200 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61201 +#define __bos0(ptr) __bos((ptr), 0)
61202 +#define __bos1(ptr) __bos((ptr), 1)
61203 #endif
61204
61205 #if __GNUC_MINOR__ >= 6
61206 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61207 index f430e41..38be90f 100644
61208 --- a/include/linux/compiler.h
61209 +++ b/include/linux/compiler.h
61210 @@ -5,31 +5,62 @@
61211
61212 #ifdef __CHECKER__
61213 # define __user __attribute__((noderef, address_space(1)))
61214 +# define __force_user __force __user
61215 # define __kernel __attribute__((address_space(0)))
61216 +# define __force_kernel __force __kernel
61217 # define __safe __attribute__((safe))
61218 # define __force __attribute__((force))
61219 # define __nocast __attribute__((nocast))
61220 # define __iomem __attribute__((noderef, address_space(2)))
61221 +# define __force_iomem __force __iomem
61222 # define __acquires(x) __attribute__((context(x,0,1)))
61223 # define __releases(x) __attribute__((context(x,1,0)))
61224 # define __acquire(x) __context__(x,1)
61225 # define __release(x) __context__(x,-1)
61226 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61227 # define __percpu __attribute__((noderef, address_space(3)))
61228 +# define __force_percpu __force __percpu
61229 #ifdef CONFIG_SPARSE_RCU_POINTER
61230 # define __rcu __attribute__((noderef, address_space(4)))
61231 +# define __force_rcu __force __rcu
61232 #else
61233 # define __rcu
61234 +# define __force_rcu
61235 #endif
61236 extern void __chk_user_ptr(const volatile void __user *);
61237 extern void __chk_io_ptr(const volatile void __iomem *);
61238 +#elif defined(CHECKER_PLUGIN)
61239 +//# define __user
61240 +//# define __force_user
61241 +//# define __kernel
61242 +//# define __force_kernel
61243 +# define __safe
61244 +# define __force
61245 +# define __nocast
61246 +# define __iomem
61247 +# define __force_iomem
61248 +# define __chk_user_ptr(x) (void)0
61249 +# define __chk_io_ptr(x) (void)0
61250 +# define __builtin_warning(x, y...) (1)
61251 +# define __acquires(x)
61252 +# define __releases(x)
61253 +# define __acquire(x) (void)0
61254 +# define __release(x) (void)0
61255 +# define __cond_lock(x,c) (c)
61256 +# define __percpu
61257 +# define __force_percpu
61258 +# define __rcu
61259 +# define __force_rcu
61260 #else
61261 # define __user
61262 +# define __force_user
61263 # define __kernel
61264 +# define __force_kernel
61265 # define __safe
61266 # define __force
61267 # define __nocast
61268 # define __iomem
61269 +# define __force_iomem
61270 # define __chk_user_ptr(x) (void)0
61271 # define __chk_io_ptr(x) (void)0
61272 # define __builtin_warning(x, y...) (1)
61273 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61274 # define __release(x) (void)0
61275 # define __cond_lock(x,c) (c)
61276 # define __percpu
61277 +# define __force_percpu
61278 # define __rcu
61279 +# define __force_rcu
61280 #endif
61281
61282 #ifdef __KERNEL__
61283 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61284 # define __attribute_const__ /* unimplemented */
61285 #endif
61286
61287 +#ifndef __no_const
61288 +# define __no_const
61289 +#endif
61290 +
61291 +#ifndef __do_const
61292 +# define __do_const
61293 +#endif
61294 +
61295 +#ifndef __size_overflow
61296 +# define __size_overflow(...)
61297 +#endif
61298 +
61299 +#ifndef __intentional_overflow
61300 +# define __intentional_overflow(...)
61301 +#endif
61302 +
61303 +#ifndef __latent_entropy
61304 +# define __latent_entropy
61305 +#endif
61306 +
61307 /*
61308 * Tell gcc if a function is cold. The compiler will assume any path
61309 * directly leading to the call is unlikely.
61310 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61311 #define __cold
61312 #endif
61313
61314 +#ifndef __alloc_size
61315 +#define __alloc_size(...)
61316 +#endif
61317 +
61318 +#ifndef __bos
61319 +#define __bos(ptr, arg)
61320 +#endif
61321 +
61322 +#ifndef __bos0
61323 +#define __bos0(ptr)
61324 +#endif
61325 +
61326 +#ifndef __bos1
61327 +#define __bos1(ptr)
61328 +#endif
61329 +
61330 /* Simple shorthand for a section definition */
61331 #ifndef __section
61332 # define __section(S) __attribute__ ((__section__(#S)))
61333 @@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61334 * use is to mediate communication between process-level code and irq/NMI
61335 * handlers, all running on the same CPU.
61336 */
61337 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61338 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61339 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61340
61341 #endif /* __LINUX_COMPILER_H */
61342 diff --git a/include/linux/cred.h b/include/linux/cred.h
61343 index ebbed2c..908cc2c 100644
61344 --- a/include/linux/cred.h
61345 +++ b/include/linux/cred.h
61346 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61347 static inline void validate_process_creds(void)
61348 {
61349 }
61350 +static inline void validate_task_creds(struct task_struct *task)
61351 +{
61352 +}
61353 #endif
61354
61355 /**
61356 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61357 index b92eadf..b4ecdc1 100644
61358 --- a/include/linux/crypto.h
61359 +++ b/include/linux/crypto.h
61360 @@ -373,7 +373,7 @@ struct cipher_tfm {
61361 const u8 *key, unsigned int keylen);
61362 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61363 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61364 -};
61365 +} __no_const;
61366
61367 struct hash_tfm {
61368 int (*init)(struct hash_desc *desc);
61369 @@ -394,13 +394,13 @@ struct compress_tfm {
61370 int (*cot_decompress)(struct crypto_tfm *tfm,
61371 const u8 *src, unsigned int slen,
61372 u8 *dst, unsigned int *dlen);
61373 -};
61374 +} __no_const;
61375
61376 struct rng_tfm {
61377 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61378 unsigned int dlen);
61379 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61380 -};
61381 +} __no_const;
61382
61383 #define crt_ablkcipher crt_u.ablkcipher
61384 #define crt_aead crt_u.aead
61385 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61386 index 7925bf0..d5143d2 100644
61387 --- a/include/linux/decompress/mm.h
61388 +++ b/include/linux/decompress/mm.h
61389 @@ -77,7 +77,7 @@ static void free(void *where)
61390 * warnings when not needed (indeed large_malloc / large_free are not
61391 * needed by inflate */
61392
61393 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61394 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61395 #define free(a) kfree(a)
61396
61397 #define large_malloc(a) vmalloc(a)
61398 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61399 index 94af418..b1ca7a2 100644
61400 --- a/include/linux/dma-mapping.h
61401 +++ b/include/linux/dma-mapping.h
61402 @@ -54,7 +54,7 @@ struct dma_map_ops {
61403 u64 (*get_required_mask)(struct device *dev);
61404 #endif
61405 int is_phys;
61406 -};
61407 +} __do_const;
61408
61409 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61410
61411 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61412 index 9c02a45..89fdd73 100644
61413 --- a/include/linux/dmaengine.h
61414 +++ b/include/linux/dmaengine.h
61415 @@ -1017,9 +1017,9 @@ struct dma_pinned_list {
61416 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61417 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61418
61419 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61420 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61421 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61422 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61423 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61424 struct dma_pinned_list *pinned_list, struct page *page,
61425 unsigned int offset, size_t len);
61426
61427 diff --git a/include/linux/efi.h b/include/linux/efi.h
61428 index ec45ccd..9923c32 100644
61429 --- a/include/linux/efi.h
61430 +++ b/include/linux/efi.h
61431 @@ -635,7 +635,7 @@ struct efivar_operations {
61432 efi_get_variable_t *get_variable;
61433 efi_get_next_variable_t *get_next_variable;
61434 efi_set_variable_t *set_variable;
61435 -};
61436 +} __no_const;
61437
61438 struct efivars {
61439 /*
61440 diff --git a/include/linux/elf.h b/include/linux/elf.h
61441 index 999b4f5..57753b4 100644
61442 --- a/include/linux/elf.h
61443 +++ b/include/linux/elf.h
61444 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61445 #define PT_GNU_EH_FRAME 0x6474e550
61446
61447 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61448 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61449 +
61450 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61451 +
61452 +/* Constants for the e_flags field */
61453 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61454 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61455 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61456 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61457 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61458 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61459
61460 /*
61461 * Extended Numbering
61462 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61463 #define DT_DEBUG 21
61464 #define DT_TEXTREL 22
61465 #define DT_JMPREL 23
61466 +#define DT_FLAGS 30
61467 + #define DF_TEXTREL 0x00000004
61468 #define DT_ENCODING 32
61469 #define OLD_DT_LOOS 0x60000000
61470 #define DT_LOOS 0x6000000d
61471 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61472 #define PF_W 0x2
61473 #define PF_X 0x1
61474
61475 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61476 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61477 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61478 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61479 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61480 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61481 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61482 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61483 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61484 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61485 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61486 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61487 +
61488 typedef struct elf32_phdr{
61489 Elf32_Word p_type;
61490 Elf32_Off p_offset;
61491 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61492 #define EI_OSABI 7
61493 #define EI_PAD 8
61494
61495 +#define EI_PAX 14
61496 +
61497 #define ELFMAG0 0x7f /* EI_MAG */
61498 #define ELFMAG1 'E'
61499 #define ELFMAG2 'L'
61500 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61501 #define elf_note elf32_note
61502 #define elf_addr_t Elf32_Off
61503 #define Elf_Half Elf32_Half
61504 +#define elf_dyn Elf32_Dyn
61505
61506 #else
61507
61508 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61509 #define elf_note elf64_note
61510 #define elf_addr_t Elf64_Off
61511 #define Elf_Half Elf64_Half
61512 +#define elf_dyn Elf64_Dyn
61513
61514 #endif
61515
61516 diff --git a/include/linux/filter.h b/include/linux/filter.h
61517 index 82b0135..917914d 100644
61518 --- a/include/linux/filter.h
61519 +++ b/include/linux/filter.h
61520 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61521
61522 struct sk_buff;
61523 struct sock;
61524 +struct bpf_jit_work;
61525
61526 struct sk_filter
61527 {
61528 @@ -153,6 +154,9 @@ struct sk_filter
61529 unsigned int len; /* Number of filter blocks */
61530 unsigned int (*bpf_func)(const struct sk_buff *skb,
61531 const struct sock_filter *filter);
61532 +#ifdef CONFIG_BPF_JIT
61533 + struct bpf_jit_work *work;
61534 +#endif
61535 struct rcu_head rcu;
61536 struct sock_filter insns[0];
61537 };
61538 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61539 index db04ec5..f6ed627 100644
61540 --- a/include/linux/firewire.h
61541 +++ b/include/linux/firewire.h
61542 @@ -430,7 +430,7 @@ struct fw_iso_context {
61543 union {
61544 fw_iso_callback_t sc;
61545 fw_iso_mc_callback_t mc;
61546 - } callback;
61547 + } __no_const callback;
61548 void *callback_data;
61549 };
61550
61551 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61552 index 0e4e2ee..4ff4312 100644
61553 --- a/include/linux/frontswap.h
61554 +++ b/include/linux/frontswap.h
61555 @@ -11,7 +11,7 @@ struct frontswap_ops {
61556 int (*load)(unsigned, pgoff_t, struct page *);
61557 void (*invalidate_page)(unsigned, pgoff_t);
61558 void (*invalidate_area)(unsigned);
61559 -};
61560 +} __no_const;
61561
61562 extern bool frontswap_enabled;
61563 extern struct frontswap_ops
61564 diff --git a/include/linux/fs.h b/include/linux/fs.h
61565 index aa11047..7d046d0 100644
61566 --- a/include/linux/fs.h
61567 +++ b/include/linux/fs.h
61568 @@ -1802,7 +1802,8 @@ struct file_operations {
61569 int (*setlease)(struct file *, long, struct file_lock **);
61570 long (*fallocate)(struct file *file, int mode, loff_t offset,
61571 loff_t len);
61572 -};
61573 +} __do_const;
61574 +typedef struct file_operations __no_const file_operations_no_const;
61575
61576 struct inode_operations {
61577 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
61578 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61579 index 003dc0f..3c4ea97 100644
61580 --- a/include/linux/fs_struct.h
61581 +++ b/include/linux/fs_struct.h
61582 @@ -6,7 +6,7 @@
61583 #include <linux/seqlock.h>
61584
61585 struct fs_struct {
61586 - int users;
61587 + atomic_t users;
61588 spinlock_t lock;
61589 seqcount_t seq;
61590 int umask;
61591 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61592 index ce31408..b1ad003 100644
61593 --- a/include/linux/fscache-cache.h
61594 +++ b/include/linux/fscache-cache.h
61595 @@ -102,7 +102,7 @@ struct fscache_operation {
61596 fscache_operation_release_t release;
61597 };
61598
61599 -extern atomic_t fscache_op_debug_id;
61600 +extern atomic_unchecked_t fscache_op_debug_id;
61601 extern void fscache_op_work_func(struct work_struct *work);
61602
61603 extern void fscache_enqueue_operation(struct fscache_operation *);
61604 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61605 {
61606 INIT_WORK(&op->work, fscache_op_work_func);
61607 atomic_set(&op->usage, 1);
61608 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61609 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61610 op->processor = processor;
61611 op->release = release;
61612 INIT_LIST_HEAD(&op->pend_link);
61613 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61614 index a6dfe69..569586df 100644
61615 --- a/include/linux/fsnotify.h
61616 +++ b/include/linux/fsnotify.h
61617 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61618 */
61619 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61620 {
61621 - return kstrdup(name, GFP_KERNEL);
61622 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61623 }
61624
61625 /*
61626 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61627 index 63d966d..cdcb717 100644
61628 --- a/include/linux/fsnotify_backend.h
61629 +++ b/include/linux/fsnotify_backend.h
61630 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61631 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61632 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61633 };
61634 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61635
61636 /*
61637 * A group is a "thing" that wants to receive notification about filesystem
61638 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61639 index 642928c..e6c83a7 100644
61640 --- a/include/linux/ftrace_event.h
61641 +++ b/include/linux/ftrace_event.h
61642 @@ -97,7 +97,7 @@ struct trace_event_functions {
61643 trace_print_func raw;
61644 trace_print_func hex;
61645 trace_print_func binary;
61646 -};
61647 +} __no_const;
61648
61649 struct trace_event {
61650 struct hlist_node node;
61651 @@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61652 extern int trace_add_event_call(struct ftrace_event_call *call);
61653 extern void trace_remove_event_call(struct ftrace_event_call *call);
61654
61655 -#define is_signed_type(type) (((type)(-1)) < 0)
61656 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61657
61658 int trace_set_clr_event(const char *system, const char *event, int set);
61659
61660 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61661 index 4f440b3..342233a 100644
61662 --- a/include/linux/genhd.h
61663 +++ b/include/linux/genhd.h
61664 @@ -190,7 +190,7 @@ struct gendisk {
61665 struct kobject *slave_dir;
61666
61667 struct timer_rand_state *random;
61668 - atomic_t sync_io; /* RAID */
61669 + atomic_unchecked_t sync_io; /* RAID */
61670 struct disk_events *ev;
61671 #ifdef CONFIG_BLK_DEV_INTEGRITY
61672 struct blk_integrity *integrity;
61673 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61674 index 4883f39..26688a8 100644
61675 --- a/include/linux/gfp.h
61676 +++ b/include/linux/gfp.h
61677 @@ -39,6 +39,12 @@ struct vm_area_struct;
61678 #define ___GFP_OTHER_NODE 0x800000u
61679 #define ___GFP_WRITE 0x1000000u
61680
61681 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61682 +#define ___GFP_USERCOPY 0x2000000u
61683 +#else
61684 +#define ___GFP_USERCOPY 0
61685 +#endif
61686 +
61687 /*
61688 * GFP bitmasks..
61689 *
61690 @@ -93,6 +99,7 @@ struct vm_area_struct;
61691 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61692 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61693 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61694 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61695
61696 /*
61697 * This may seem redundant, but it's a way of annotating false positives vs.
61698 @@ -100,7 +107,7 @@ struct vm_area_struct;
61699 */
61700 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61701
61702 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61703 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61704 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61705
61706 /* This equals 0, but use constants in case they ever change */
61707 @@ -154,6 +161,8 @@ struct vm_area_struct;
61708 /* 4GB DMA on some platforms */
61709 #define GFP_DMA32 __GFP_DMA32
61710
61711 +#define GFP_USERCOPY __GFP_USERCOPY
61712 +
61713 /* Convert GFP flags to their corresponding migrate type */
61714 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61715 {
61716 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61717 new file mode 100644
61718 index 0000000..c938b1f
61719 --- /dev/null
61720 +++ b/include/linux/gracl.h
61721 @@ -0,0 +1,319 @@
61722 +#ifndef GR_ACL_H
61723 +#define GR_ACL_H
61724 +
61725 +#include <linux/grdefs.h>
61726 +#include <linux/resource.h>
61727 +#include <linux/capability.h>
61728 +#include <linux/dcache.h>
61729 +#include <asm/resource.h>
61730 +
61731 +/* Major status information */
61732 +
61733 +#define GR_VERSION "grsecurity 2.9.1"
61734 +#define GRSECURITY_VERSION 0x2901
61735 +
61736 +enum {
61737 + GR_SHUTDOWN = 0,
61738 + GR_ENABLE = 1,
61739 + GR_SPROLE = 2,
61740 + GR_RELOAD = 3,
61741 + GR_SEGVMOD = 4,
61742 + GR_STATUS = 5,
61743 + GR_UNSPROLE = 6,
61744 + GR_PASSSET = 7,
61745 + GR_SPROLEPAM = 8,
61746 +};
61747 +
61748 +/* Password setup definitions
61749 + * kernel/grhash.c */
61750 +enum {
61751 + GR_PW_LEN = 128,
61752 + GR_SALT_LEN = 16,
61753 + GR_SHA_LEN = 32,
61754 +};
61755 +
61756 +enum {
61757 + GR_SPROLE_LEN = 64,
61758 +};
61759 +
61760 +enum {
61761 + GR_NO_GLOB = 0,
61762 + GR_REG_GLOB,
61763 + GR_CREATE_GLOB
61764 +};
61765 +
61766 +#define GR_NLIMITS 32
61767 +
61768 +/* Begin Data Structures */
61769 +
61770 +struct sprole_pw {
61771 + unsigned char *rolename;
61772 + unsigned char salt[GR_SALT_LEN];
61773 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61774 +};
61775 +
61776 +struct name_entry {
61777 + __u32 key;
61778 + ino_t inode;
61779 + dev_t device;
61780 + char *name;
61781 + __u16 len;
61782 + __u8 deleted;
61783 + struct name_entry *prev;
61784 + struct name_entry *next;
61785 +};
61786 +
61787 +struct inodev_entry {
61788 + struct name_entry *nentry;
61789 + struct inodev_entry *prev;
61790 + struct inodev_entry *next;
61791 +};
61792 +
61793 +struct acl_role_db {
61794 + struct acl_role_label **r_hash;
61795 + __u32 r_size;
61796 +};
61797 +
61798 +struct inodev_db {
61799 + struct inodev_entry **i_hash;
61800 + __u32 i_size;
61801 +};
61802 +
61803 +struct name_db {
61804 + struct name_entry **n_hash;
61805 + __u32 n_size;
61806 +};
61807 +
61808 +struct crash_uid {
61809 + uid_t uid;
61810 + unsigned long expires;
61811 +};
61812 +
61813 +struct gr_hash_struct {
61814 + void **table;
61815 + void **nametable;
61816 + void *first;
61817 + __u32 table_size;
61818 + __u32 used_size;
61819 + int type;
61820 +};
61821 +
61822 +/* Userspace Grsecurity ACL data structures */
61823 +
61824 +struct acl_subject_label {
61825 + char *filename;
61826 + ino_t inode;
61827 + dev_t device;
61828 + __u32 mode;
61829 + kernel_cap_t cap_mask;
61830 + kernel_cap_t cap_lower;
61831 + kernel_cap_t cap_invert_audit;
61832 +
61833 + struct rlimit res[GR_NLIMITS];
61834 + __u32 resmask;
61835 +
61836 + __u8 user_trans_type;
61837 + __u8 group_trans_type;
61838 + uid_t *user_transitions;
61839 + gid_t *group_transitions;
61840 + __u16 user_trans_num;
61841 + __u16 group_trans_num;
61842 +
61843 + __u32 sock_families[2];
61844 + __u32 ip_proto[8];
61845 + __u32 ip_type;
61846 + struct acl_ip_label **ips;
61847 + __u32 ip_num;
61848 + __u32 inaddr_any_override;
61849 +
61850 + __u32 crashes;
61851 + unsigned long expires;
61852 +
61853 + struct acl_subject_label *parent_subject;
61854 + struct gr_hash_struct *hash;
61855 + struct acl_subject_label *prev;
61856 + struct acl_subject_label *next;
61857 +
61858 + struct acl_object_label **obj_hash;
61859 + __u32 obj_hash_size;
61860 + __u16 pax_flags;
61861 +};
61862 +
61863 +struct role_allowed_ip {
61864 + __u32 addr;
61865 + __u32 netmask;
61866 +
61867 + struct role_allowed_ip *prev;
61868 + struct role_allowed_ip *next;
61869 +};
61870 +
61871 +struct role_transition {
61872 + char *rolename;
61873 +
61874 + struct role_transition *prev;
61875 + struct role_transition *next;
61876 +};
61877 +
61878 +struct acl_role_label {
61879 + char *rolename;
61880 + uid_t uidgid;
61881 + __u16 roletype;
61882 +
61883 + __u16 auth_attempts;
61884 + unsigned long expires;
61885 +
61886 + struct acl_subject_label *root_label;
61887 + struct gr_hash_struct *hash;
61888 +
61889 + struct acl_role_label *prev;
61890 + struct acl_role_label *next;
61891 +
61892 + struct role_transition *transitions;
61893 + struct role_allowed_ip *allowed_ips;
61894 + uid_t *domain_children;
61895 + __u16 domain_child_num;
61896 +
61897 + umode_t umask;
61898 +
61899 + struct acl_subject_label **subj_hash;
61900 + __u32 subj_hash_size;
61901 +};
61902 +
61903 +struct user_acl_role_db {
61904 + struct acl_role_label **r_table;
61905 + __u32 num_pointers; /* Number of allocations to track */
61906 + __u32 num_roles; /* Number of roles */
61907 + __u32 num_domain_children; /* Number of domain children */
61908 + __u32 num_subjects; /* Number of subjects */
61909 + __u32 num_objects; /* Number of objects */
61910 +};
61911 +
61912 +struct acl_object_label {
61913 + char *filename;
61914 + ino_t inode;
61915 + dev_t device;
61916 + __u32 mode;
61917 +
61918 + struct acl_subject_label *nested;
61919 + struct acl_object_label *globbed;
61920 +
61921 + /* next two structures not used */
61922 +
61923 + struct acl_object_label *prev;
61924 + struct acl_object_label *next;
61925 +};
61926 +
61927 +struct acl_ip_label {
61928 + char *iface;
61929 + __u32 addr;
61930 + __u32 netmask;
61931 + __u16 low, high;
61932 + __u8 mode;
61933 + __u32 type;
61934 + __u32 proto[8];
61935 +
61936 + /* next two structures not used */
61937 +
61938 + struct acl_ip_label *prev;
61939 + struct acl_ip_label *next;
61940 +};
61941 +
61942 +struct gr_arg {
61943 + struct user_acl_role_db role_db;
61944 + unsigned char pw[GR_PW_LEN];
61945 + unsigned char salt[GR_SALT_LEN];
61946 + unsigned char sum[GR_SHA_LEN];
61947 + unsigned char sp_role[GR_SPROLE_LEN];
61948 + struct sprole_pw *sprole_pws;
61949 + dev_t segv_device;
61950 + ino_t segv_inode;
61951 + uid_t segv_uid;
61952 + __u16 num_sprole_pws;
61953 + __u16 mode;
61954 +};
61955 +
61956 +struct gr_arg_wrapper {
61957 + struct gr_arg *arg;
61958 + __u32 version;
61959 + __u32 size;
61960 +};
61961 +
61962 +struct subject_map {
61963 + struct acl_subject_label *user;
61964 + struct acl_subject_label *kernel;
61965 + struct subject_map *prev;
61966 + struct subject_map *next;
61967 +};
61968 +
61969 +struct acl_subj_map_db {
61970 + struct subject_map **s_hash;
61971 + __u32 s_size;
61972 +};
61973 +
61974 +/* End Data Structures Section */
61975 +
61976 +/* Hash functions generated by empirical testing by Brad Spengler
61977 + Makes good use of the low bits of the inode. Generally 0-1 times
61978 + in loop for successful match. 0-3 for unsuccessful match.
61979 + Shift/add algorithm with modulus of table size and an XOR*/
61980 +
61981 +static __inline__ unsigned int
61982 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
61983 +{
61984 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
61985 +}
61986 +
61987 + static __inline__ unsigned int
61988 +shash(const struct acl_subject_label *userp, const unsigned int sz)
61989 +{
61990 + return ((const unsigned long)userp % sz);
61991 +}
61992 +
61993 +static __inline__ unsigned int
61994 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
61995 +{
61996 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
61997 +}
61998 +
61999 +static __inline__ unsigned int
62000 +nhash(const char *name, const __u16 len, const unsigned int sz)
62001 +{
62002 + return full_name_hash((const unsigned char *)name, len) % sz;
62003 +}
62004 +
62005 +#define FOR_EACH_ROLE_START(role) \
62006 + role = role_list; \
62007 + while (role) {
62008 +
62009 +#define FOR_EACH_ROLE_END(role) \
62010 + role = role->prev; \
62011 + }
62012 +
62013 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62014 + subj = NULL; \
62015 + iter = 0; \
62016 + while (iter < role->subj_hash_size) { \
62017 + if (subj == NULL) \
62018 + subj = role->subj_hash[iter]; \
62019 + if (subj == NULL) { \
62020 + iter++; \
62021 + continue; \
62022 + }
62023 +
62024 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62025 + subj = subj->next; \
62026 + if (subj == NULL) \
62027 + iter++; \
62028 + }
62029 +
62030 +
62031 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62032 + subj = role->hash->first; \
62033 + while (subj != NULL) {
62034 +
62035 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62036 + subj = subj->next; \
62037 + }
62038 +
62039 +#endif
62040 +
62041 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62042 new file mode 100644
62043 index 0000000..323ecf2
62044 --- /dev/null
62045 +++ b/include/linux/gralloc.h
62046 @@ -0,0 +1,9 @@
62047 +#ifndef __GRALLOC_H
62048 +#define __GRALLOC_H
62049 +
62050 +void acl_free_all(void);
62051 +int acl_alloc_stack_init(unsigned long size);
62052 +void *acl_alloc(unsigned long len);
62053 +void *acl_alloc_num(unsigned long num, unsigned long len);
62054 +
62055 +#endif
62056 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62057 new file mode 100644
62058 index 0000000..b30e9bc
62059 --- /dev/null
62060 +++ b/include/linux/grdefs.h
62061 @@ -0,0 +1,140 @@
62062 +#ifndef GRDEFS_H
62063 +#define GRDEFS_H
62064 +
62065 +/* Begin grsecurity status declarations */
62066 +
62067 +enum {
62068 + GR_READY = 0x01,
62069 + GR_STATUS_INIT = 0x00 // disabled state
62070 +};
62071 +
62072 +/* Begin ACL declarations */
62073 +
62074 +/* Role flags */
62075 +
62076 +enum {
62077 + GR_ROLE_USER = 0x0001,
62078 + GR_ROLE_GROUP = 0x0002,
62079 + GR_ROLE_DEFAULT = 0x0004,
62080 + GR_ROLE_SPECIAL = 0x0008,
62081 + GR_ROLE_AUTH = 0x0010,
62082 + GR_ROLE_NOPW = 0x0020,
62083 + GR_ROLE_GOD = 0x0040,
62084 + GR_ROLE_LEARN = 0x0080,
62085 + GR_ROLE_TPE = 0x0100,
62086 + GR_ROLE_DOMAIN = 0x0200,
62087 + GR_ROLE_PAM = 0x0400,
62088 + GR_ROLE_PERSIST = 0x0800
62089 +};
62090 +
62091 +/* ACL Subject and Object mode flags */
62092 +enum {
62093 + GR_DELETED = 0x80000000
62094 +};
62095 +
62096 +/* ACL Object-only mode flags */
62097 +enum {
62098 + GR_READ = 0x00000001,
62099 + GR_APPEND = 0x00000002,
62100 + GR_WRITE = 0x00000004,
62101 + GR_EXEC = 0x00000008,
62102 + GR_FIND = 0x00000010,
62103 + GR_INHERIT = 0x00000020,
62104 + GR_SETID = 0x00000040,
62105 + GR_CREATE = 0x00000080,
62106 + GR_DELETE = 0x00000100,
62107 + GR_LINK = 0x00000200,
62108 + GR_AUDIT_READ = 0x00000400,
62109 + GR_AUDIT_APPEND = 0x00000800,
62110 + GR_AUDIT_WRITE = 0x00001000,
62111 + GR_AUDIT_EXEC = 0x00002000,
62112 + GR_AUDIT_FIND = 0x00004000,
62113 + GR_AUDIT_INHERIT= 0x00008000,
62114 + GR_AUDIT_SETID = 0x00010000,
62115 + GR_AUDIT_CREATE = 0x00020000,
62116 + GR_AUDIT_DELETE = 0x00040000,
62117 + GR_AUDIT_LINK = 0x00080000,
62118 + GR_PTRACERD = 0x00100000,
62119 + GR_NOPTRACE = 0x00200000,
62120 + GR_SUPPRESS = 0x00400000,
62121 + GR_NOLEARN = 0x00800000,
62122 + GR_INIT_TRANSFER= 0x01000000
62123 +};
62124 +
62125 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62126 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62127 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62128 +
62129 +/* ACL subject-only mode flags */
62130 +enum {
62131 + GR_KILL = 0x00000001,
62132 + GR_VIEW = 0x00000002,
62133 + GR_PROTECTED = 0x00000004,
62134 + GR_LEARN = 0x00000008,
62135 + GR_OVERRIDE = 0x00000010,
62136 + /* just a placeholder, this mode is only used in userspace */
62137 + GR_DUMMY = 0x00000020,
62138 + GR_PROTSHM = 0x00000040,
62139 + GR_KILLPROC = 0x00000080,
62140 + GR_KILLIPPROC = 0x00000100,
62141 + /* just a placeholder, this mode is only used in userspace */
62142 + GR_NOTROJAN = 0x00000200,
62143 + GR_PROTPROCFD = 0x00000400,
62144 + GR_PROCACCT = 0x00000800,
62145 + GR_RELAXPTRACE = 0x00001000,
62146 + GR_NESTED = 0x00002000,
62147 + GR_INHERITLEARN = 0x00004000,
62148 + GR_PROCFIND = 0x00008000,
62149 + GR_POVERRIDE = 0x00010000,
62150 + GR_KERNELAUTH = 0x00020000,
62151 + GR_ATSECURE = 0x00040000,
62152 + GR_SHMEXEC = 0x00080000
62153 +};
62154 +
62155 +enum {
62156 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62157 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62158 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62159 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62160 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62161 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62162 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62163 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62164 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62165 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62166 +};
62167 +
62168 +enum {
62169 + GR_ID_USER = 0x01,
62170 + GR_ID_GROUP = 0x02,
62171 +};
62172 +
62173 +enum {
62174 + GR_ID_ALLOW = 0x01,
62175 + GR_ID_DENY = 0x02,
62176 +};
62177 +
62178 +#define GR_CRASH_RES 31
62179 +#define GR_UIDTABLE_MAX 500
62180 +
62181 +/* begin resource learning section */
62182 +enum {
62183 + GR_RLIM_CPU_BUMP = 60,
62184 + GR_RLIM_FSIZE_BUMP = 50000,
62185 + GR_RLIM_DATA_BUMP = 10000,
62186 + GR_RLIM_STACK_BUMP = 1000,
62187 + GR_RLIM_CORE_BUMP = 10000,
62188 + GR_RLIM_RSS_BUMP = 500000,
62189 + GR_RLIM_NPROC_BUMP = 1,
62190 + GR_RLIM_NOFILE_BUMP = 5,
62191 + GR_RLIM_MEMLOCK_BUMP = 50000,
62192 + GR_RLIM_AS_BUMP = 500000,
62193 + GR_RLIM_LOCKS_BUMP = 2,
62194 + GR_RLIM_SIGPENDING_BUMP = 5,
62195 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62196 + GR_RLIM_NICE_BUMP = 1,
62197 + GR_RLIM_RTPRIO_BUMP = 1,
62198 + GR_RLIM_RTTIME_BUMP = 1000000
62199 +};
62200 +
62201 +#endif
62202 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62203 new file mode 100644
62204 index 0000000..c9292f7
62205 --- /dev/null
62206 +++ b/include/linux/grinternal.h
62207 @@ -0,0 +1,223 @@
62208 +#ifndef __GRINTERNAL_H
62209 +#define __GRINTERNAL_H
62210 +
62211 +#ifdef CONFIG_GRKERNSEC
62212 +
62213 +#include <linux/fs.h>
62214 +#include <linux/mnt_namespace.h>
62215 +#include <linux/nsproxy.h>
62216 +#include <linux/gracl.h>
62217 +#include <linux/grdefs.h>
62218 +#include <linux/grmsg.h>
62219 +
62220 +void gr_add_learn_entry(const char *fmt, ...)
62221 + __attribute__ ((format (printf, 1, 2)));
62222 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62223 + const struct vfsmount *mnt);
62224 +__u32 gr_check_create(const struct dentry *new_dentry,
62225 + const struct dentry *parent,
62226 + const struct vfsmount *mnt, const __u32 mode);
62227 +int gr_check_protected_task(const struct task_struct *task);
62228 +__u32 to_gr_audit(const __u32 reqmode);
62229 +int gr_set_acls(const int type);
62230 +int gr_apply_subject_to_task(struct task_struct *task);
62231 +int gr_acl_is_enabled(void);
62232 +char gr_roletype_to_char(void);
62233 +
62234 +void gr_handle_alertkill(struct task_struct *task);
62235 +char *gr_to_filename(const struct dentry *dentry,
62236 + const struct vfsmount *mnt);
62237 +char *gr_to_filename1(const struct dentry *dentry,
62238 + const struct vfsmount *mnt);
62239 +char *gr_to_filename2(const struct dentry *dentry,
62240 + const struct vfsmount *mnt);
62241 +char *gr_to_filename3(const struct dentry *dentry,
62242 + const struct vfsmount *mnt);
62243 +
62244 +extern int grsec_enable_ptrace_readexec;
62245 +extern int grsec_enable_harden_ptrace;
62246 +extern int grsec_enable_link;
62247 +extern int grsec_enable_fifo;
62248 +extern int grsec_enable_execve;
62249 +extern int grsec_enable_shm;
62250 +extern int grsec_enable_execlog;
62251 +extern int grsec_enable_signal;
62252 +extern int grsec_enable_audit_ptrace;
62253 +extern int grsec_enable_forkfail;
62254 +extern int grsec_enable_time;
62255 +extern int grsec_enable_rofs;
62256 +extern int grsec_enable_chroot_shmat;
62257 +extern int grsec_enable_chroot_mount;
62258 +extern int grsec_enable_chroot_double;
62259 +extern int grsec_enable_chroot_pivot;
62260 +extern int grsec_enable_chroot_chdir;
62261 +extern int grsec_enable_chroot_chmod;
62262 +extern int grsec_enable_chroot_mknod;
62263 +extern int grsec_enable_chroot_fchdir;
62264 +extern int grsec_enable_chroot_nice;
62265 +extern int grsec_enable_chroot_execlog;
62266 +extern int grsec_enable_chroot_caps;
62267 +extern int grsec_enable_chroot_sysctl;
62268 +extern int grsec_enable_chroot_unix;
62269 +extern int grsec_enable_symlinkown;
62270 +extern int grsec_symlinkown_gid;
62271 +extern int grsec_enable_tpe;
62272 +extern int grsec_tpe_gid;
62273 +extern int grsec_enable_tpe_all;
62274 +extern int grsec_enable_tpe_invert;
62275 +extern int grsec_enable_socket_all;
62276 +extern int grsec_socket_all_gid;
62277 +extern int grsec_enable_socket_client;
62278 +extern int grsec_socket_client_gid;
62279 +extern int grsec_enable_socket_server;
62280 +extern int grsec_socket_server_gid;
62281 +extern int grsec_audit_gid;
62282 +extern int grsec_enable_group;
62283 +extern int grsec_enable_audit_textrel;
62284 +extern int grsec_enable_log_rwxmaps;
62285 +extern int grsec_enable_mount;
62286 +extern int grsec_enable_chdir;
62287 +extern int grsec_resource_logging;
62288 +extern int grsec_enable_blackhole;
62289 +extern int grsec_lastack_retries;
62290 +extern int grsec_enable_brute;
62291 +extern int grsec_lock;
62292 +
62293 +extern spinlock_t grsec_alert_lock;
62294 +extern unsigned long grsec_alert_wtime;
62295 +extern unsigned long grsec_alert_fyet;
62296 +
62297 +extern spinlock_t grsec_audit_lock;
62298 +
62299 +extern rwlock_t grsec_exec_file_lock;
62300 +
62301 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62302 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62303 + (tsk)->exec_file->f_vfsmnt) : "/")
62304 +
62305 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62306 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62307 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62308 +
62309 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62310 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62311 + (tsk)->exec_file->f_vfsmnt) : "/")
62312 +
62313 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62314 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62315 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62316 +
62317 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62318 +
62319 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62320 +
62321 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62322 + (task)->pid, (cred)->uid, \
62323 + (cred)->euid, (cred)->gid, (cred)->egid, \
62324 + gr_parent_task_fullpath(task), \
62325 + (task)->real_parent->comm, (task)->real_parent->pid, \
62326 + (pcred)->uid, (pcred)->euid, \
62327 + (pcred)->gid, (pcred)->egid
62328 +
62329 +#define GR_CHROOT_CAPS {{ \
62330 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62331 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62332 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62333 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62334 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62335 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62336 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62337 +
62338 +#define security_learn(normal_msg,args...) \
62339 +({ \
62340 + read_lock(&grsec_exec_file_lock); \
62341 + gr_add_learn_entry(normal_msg "\n", ## args); \
62342 + read_unlock(&grsec_exec_file_lock); \
62343 +})
62344 +
62345 +enum {
62346 + GR_DO_AUDIT,
62347 + GR_DONT_AUDIT,
62348 + /* used for non-audit messages that we shouldn't kill the task on */
62349 + GR_DONT_AUDIT_GOOD
62350 +};
62351 +
62352 +enum {
62353 + GR_TTYSNIFF,
62354 + GR_RBAC,
62355 + GR_RBAC_STR,
62356 + GR_STR_RBAC,
62357 + GR_RBAC_MODE2,
62358 + GR_RBAC_MODE3,
62359 + GR_FILENAME,
62360 + GR_SYSCTL_HIDDEN,
62361 + GR_NOARGS,
62362 + GR_ONE_INT,
62363 + GR_ONE_INT_TWO_STR,
62364 + GR_ONE_STR,
62365 + GR_STR_INT,
62366 + GR_TWO_STR_INT,
62367 + GR_TWO_INT,
62368 + GR_TWO_U64,
62369 + GR_THREE_INT,
62370 + GR_FIVE_INT_TWO_STR,
62371 + GR_TWO_STR,
62372 + GR_THREE_STR,
62373 + GR_FOUR_STR,
62374 + GR_STR_FILENAME,
62375 + GR_FILENAME_STR,
62376 + GR_FILENAME_TWO_INT,
62377 + GR_FILENAME_TWO_INT_STR,
62378 + GR_TEXTREL,
62379 + GR_PTRACE,
62380 + GR_RESOURCE,
62381 + GR_CAP,
62382 + GR_SIG,
62383 + GR_SIG2,
62384 + GR_CRASH1,
62385 + GR_CRASH2,
62386 + GR_PSACCT,
62387 + GR_RWXMAP
62388 +};
62389 +
62390 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62391 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62392 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62393 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62394 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62395 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62396 +#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)
62397 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62398 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62399 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62400 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62401 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62402 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62403 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62404 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62405 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62406 +#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)
62407 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62408 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62409 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62410 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62411 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62412 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62413 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62414 +#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)
62415 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62416 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62417 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62418 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62419 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62420 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62421 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62422 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62423 +#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)
62424 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62425 +
62426 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62427 +
62428 +#endif
62429 +
62430 +#endif
62431 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62432 new file mode 100644
62433 index 0000000..54f4e85
62434 --- /dev/null
62435 +++ b/include/linux/grmsg.h
62436 @@ -0,0 +1,110 @@
62437 +#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"
62438 +#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"
62439 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62440 +#define GR_STOPMOD_MSG "denied modification of module state by "
62441 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62442 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62443 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62444 +#define GR_IOPL_MSG "denied use of iopl() by "
62445 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62446 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62447 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62448 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62449 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62450 +#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"
62451 +#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"
62452 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62453 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62454 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62455 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62456 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62457 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62458 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62459 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62460 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62461 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62462 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62463 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62464 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62465 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62466 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62467 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62468 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62469 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62470 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62471 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62472 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62473 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62474 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62475 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62476 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62477 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62478 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62479 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62480 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62481 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62482 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62483 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62484 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62485 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62486 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62487 +#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"
62488 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62489 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62490 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62491 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62492 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62493 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62494 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62495 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62496 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62497 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62498 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62499 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62500 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62501 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62502 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62503 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62504 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62505 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62506 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62507 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62508 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62509 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62510 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62511 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62512 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62513 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62514 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62515 +#define GR_TIME_MSG "time set by "
62516 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62517 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62518 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62519 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62520 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62521 +#define GR_BIND_MSG "denied bind() by "
62522 +#define GR_CONNECT_MSG "denied connect() by "
62523 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62524 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62525 +#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"
62526 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62527 +#define GR_CAP_ACL_MSG "use of %s denied for "
62528 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62529 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62530 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62531 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62532 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62533 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62534 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62535 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62536 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62537 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62538 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62539 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62540 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62541 +#define GR_VM86_MSG "denied use of vm86 by "
62542 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62543 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62544 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62545 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62546 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62547 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62548 new file mode 100644
62549 index 0000000..f9b9a21
62550 --- /dev/null
62551 +++ b/include/linux/grsecurity.h
62552 @@ -0,0 +1,238 @@
62553 +#ifndef GR_SECURITY_H
62554 +#define GR_SECURITY_H
62555 +#include <linux/fs.h>
62556 +#include <linux/fs_struct.h>
62557 +#include <linux/binfmts.h>
62558 +#include <linux/gracl.h>
62559 +
62560 +/* notify of brain-dead configs */
62561 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62562 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62563 +#endif
62564 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62565 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62566 +#endif
62567 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62568 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62569 +#endif
62570 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62571 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62572 +#endif
62573 +
62574 +#include <linux/compat.h>
62575 +
62576 +struct user_arg_ptr {
62577 +#ifdef CONFIG_COMPAT
62578 + bool is_compat;
62579 +#endif
62580 + union {
62581 + const char __user *const __user *native;
62582 +#ifdef CONFIG_COMPAT
62583 + compat_uptr_t __user *compat;
62584 +#endif
62585 + } ptr;
62586 +};
62587 +
62588 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62589 +void gr_handle_brute_check(void);
62590 +void gr_handle_kernel_exploit(void);
62591 +int gr_process_user_ban(void);
62592 +
62593 +char gr_roletype_to_char(void);
62594 +
62595 +int gr_acl_enable_at_secure(void);
62596 +
62597 +int gr_check_user_change(int real, int effective, int fs);
62598 +int gr_check_group_change(int real, int effective, int fs);
62599 +
62600 +void gr_del_task_from_ip_table(struct task_struct *p);
62601 +
62602 +int gr_pid_is_chrooted(struct task_struct *p);
62603 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62604 +int gr_handle_chroot_nice(void);
62605 +int gr_handle_chroot_sysctl(const int op);
62606 +int gr_handle_chroot_setpriority(struct task_struct *p,
62607 + const int niceval);
62608 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62609 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62610 + const struct vfsmount *mnt);
62611 +void gr_handle_chroot_chdir(struct path *path);
62612 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62613 + const struct vfsmount *mnt, const int mode);
62614 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62615 + const struct vfsmount *mnt, const int mode);
62616 +int gr_handle_chroot_mount(const struct dentry *dentry,
62617 + const struct vfsmount *mnt,
62618 + const char *dev_name);
62619 +int gr_handle_chroot_pivot(void);
62620 +int gr_handle_chroot_unix(const pid_t pid);
62621 +
62622 +int gr_handle_rawio(const struct inode *inode);
62623 +
62624 +void gr_handle_ioperm(void);
62625 +void gr_handle_iopl(void);
62626 +
62627 +umode_t gr_acl_umask(void);
62628 +
62629 +int gr_tpe_allow(const struct file *file);
62630 +
62631 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62632 +void gr_clear_chroot_entries(struct task_struct *task);
62633 +
62634 +void gr_log_forkfail(const int retval);
62635 +void gr_log_timechange(void);
62636 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62637 +void gr_log_chdir(const struct dentry *dentry,
62638 + const struct vfsmount *mnt);
62639 +void gr_log_chroot_exec(const struct dentry *dentry,
62640 + const struct vfsmount *mnt);
62641 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62642 +void gr_log_remount(const char *devname, const int retval);
62643 +void gr_log_unmount(const char *devname, const int retval);
62644 +void gr_log_mount(const char *from, const char *to, const int retval);
62645 +void gr_log_textrel(struct vm_area_struct *vma);
62646 +void gr_log_rwxmmap(struct file *file);
62647 +void gr_log_rwxmprotect(struct file *file);
62648 +
62649 +int gr_handle_follow_link(const struct inode *parent,
62650 + const struct inode *inode,
62651 + const struct dentry *dentry,
62652 + const struct vfsmount *mnt);
62653 +int gr_handle_fifo(const struct dentry *dentry,
62654 + const struct vfsmount *mnt,
62655 + const struct dentry *dir, const int flag,
62656 + const int acc_mode);
62657 +int gr_handle_hardlink(const struct dentry *dentry,
62658 + const struct vfsmount *mnt,
62659 + struct inode *inode,
62660 + const int mode, const char *to);
62661 +
62662 +int gr_is_capable(const int cap);
62663 +int gr_is_capable_nolog(const int cap);
62664 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62665 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62666 +
62667 +void gr_learn_resource(const struct task_struct *task, const int limit,
62668 + const unsigned long wanted, const int gt);
62669 +void gr_copy_label(struct task_struct *tsk);
62670 +void gr_handle_crash(struct task_struct *task, const int sig);
62671 +int gr_handle_signal(const struct task_struct *p, const int sig);
62672 +int gr_check_crash_uid(const uid_t uid);
62673 +int gr_check_protected_task(const struct task_struct *task);
62674 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62675 +int gr_acl_handle_mmap(const struct file *file,
62676 + const unsigned long prot);
62677 +int gr_acl_handle_mprotect(const struct file *file,
62678 + const unsigned long prot);
62679 +int gr_check_hidden_task(const struct task_struct *tsk);
62680 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62681 + const struct vfsmount *mnt);
62682 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62683 + const struct vfsmount *mnt);
62684 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62685 + const struct vfsmount *mnt, const int fmode);
62686 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62687 + const struct vfsmount *mnt, umode_t *mode);
62688 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62689 + const struct vfsmount *mnt);
62690 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62691 + const struct vfsmount *mnt);
62692 +int gr_handle_ptrace(struct task_struct *task, const long request);
62693 +int gr_handle_proc_ptrace(struct task_struct *task);
62694 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62695 + const struct vfsmount *mnt);
62696 +int gr_check_crash_exec(const struct file *filp);
62697 +int gr_acl_is_enabled(void);
62698 +void gr_set_kernel_label(struct task_struct *task);
62699 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62700 + const gid_t gid);
62701 +int gr_set_proc_label(const struct dentry *dentry,
62702 + const struct vfsmount *mnt,
62703 + const int unsafe_flags);
62704 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62705 + const struct vfsmount *mnt);
62706 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62707 + const struct vfsmount *mnt, int acc_mode);
62708 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62709 + const struct dentry *p_dentry,
62710 + const struct vfsmount *p_mnt,
62711 + int open_flags, int acc_mode, const int imode);
62712 +void gr_handle_create(const struct dentry *dentry,
62713 + const struct vfsmount *mnt);
62714 +void gr_handle_proc_create(const struct dentry *dentry,
62715 + const struct inode *inode);
62716 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62717 + const struct dentry *parent_dentry,
62718 + const struct vfsmount *parent_mnt,
62719 + const int mode);
62720 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62721 + const struct dentry *parent_dentry,
62722 + const struct vfsmount *parent_mnt);
62723 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62724 + const struct vfsmount *mnt);
62725 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62726 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62727 + const struct vfsmount *mnt);
62728 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62729 + const struct dentry *parent_dentry,
62730 + const struct vfsmount *parent_mnt,
62731 + const char *from);
62732 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62733 + const struct dentry *parent_dentry,
62734 + const struct vfsmount *parent_mnt,
62735 + const struct dentry *old_dentry,
62736 + const struct vfsmount *old_mnt, const char *to);
62737 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62738 +int gr_acl_handle_rename(struct dentry *new_dentry,
62739 + struct dentry *parent_dentry,
62740 + const struct vfsmount *parent_mnt,
62741 + struct dentry *old_dentry,
62742 + struct inode *old_parent_inode,
62743 + struct vfsmount *old_mnt, const char *newname);
62744 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62745 + struct dentry *old_dentry,
62746 + struct dentry *new_dentry,
62747 + struct vfsmount *mnt, const __u8 replace);
62748 +__u32 gr_check_link(const struct dentry *new_dentry,
62749 + const struct dentry *parent_dentry,
62750 + const struct vfsmount *parent_mnt,
62751 + const struct dentry *old_dentry,
62752 + const struct vfsmount *old_mnt);
62753 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62754 + const unsigned int namelen, const ino_t ino);
62755 +
62756 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62757 + const struct vfsmount *mnt);
62758 +void gr_acl_handle_exit(void);
62759 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62760 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62761 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62762 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62763 +void gr_audit_ptrace(struct task_struct *task);
62764 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62765 +
62766 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62767 +
62768 +#ifdef CONFIG_GRKERNSEC
62769 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62770 +void gr_handle_vm86(void);
62771 +void gr_handle_mem_readwrite(u64 from, u64 to);
62772 +
62773 +void gr_log_badprocpid(const char *entry);
62774 +
62775 +extern int grsec_enable_dmesg;
62776 +extern int grsec_disable_privio;
62777 +
62778 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62779 +extern int grsec_proc_gid;
62780 +#endif
62781 +
62782 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62783 +extern int grsec_enable_chroot_findtask;
62784 +#endif
62785 +#ifdef CONFIG_GRKERNSEC_SETXID
62786 +extern int grsec_enable_setxid;
62787 +#endif
62788 +#endif
62789 +
62790 +#endif
62791 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62792 new file mode 100644
62793 index 0000000..e7ffaaf
62794 --- /dev/null
62795 +++ b/include/linux/grsock.h
62796 @@ -0,0 +1,19 @@
62797 +#ifndef __GRSOCK_H
62798 +#define __GRSOCK_H
62799 +
62800 +extern void gr_attach_curr_ip(const struct sock *sk);
62801 +extern int gr_handle_sock_all(const int family, const int type,
62802 + const int protocol);
62803 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62804 +extern int gr_handle_sock_server_other(const struct sock *sck);
62805 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62806 +extern int gr_search_connect(struct socket * sock,
62807 + struct sockaddr_in * addr);
62808 +extern int gr_search_bind(struct socket * sock,
62809 + struct sockaddr_in * addr);
62810 +extern int gr_search_listen(struct socket * sock);
62811 +extern int gr_search_accept(struct socket * sock);
62812 +extern int gr_search_socket(const int domain, const int type,
62813 + const int protocol);
62814 +
62815 +#endif
62816 diff --git a/include/linux/hid.h b/include/linux/hid.h
62817 index 42970de..5db3c92 100644
62818 --- a/include/linux/hid.h
62819 +++ b/include/linux/hid.h
62820 @@ -705,7 +705,7 @@ struct hid_ll_driver {
62821 unsigned int code, int value);
62822
62823 int (*parse)(struct hid_device *hdev);
62824 -};
62825 +} __no_const;
62826
62827 #define PM_HINT_FULLON 1<<5
62828 #define PM_HINT_NORMAL 1<<1
62829 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62830 index ef788b5..ac41b7b 100644
62831 --- a/include/linux/highmem.h
62832 +++ b/include/linux/highmem.h
62833 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
62834 kunmap_atomic(kaddr);
62835 }
62836
62837 +static inline void sanitize_highpage(struct page *page)
62838 +{
62839 + void *kaddr;
62840 + unsigned long flags;
62841 +
62842 + local_irq_save(flags);
62843 + kaddr = kmap_atomic(page);
62844 + clear_page(kaddr);
62845 + kunmap_atomic(kaddr);
62846 + local_irq_restore(flags);
62847 +}
62848 +
62849 static inline void zero_user_segments(struct page *page,
62850 unsigned start1, unsigned end1,
62851 unsigned start2, unsigned end2)
62852 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62853 index 5970266..1c48c3b 100644
62854 --- a/include/linux/i2c.h
62855 +++ b/include/linux/i2c.h
62856 @@ -369,6 +369,7 @@ struct i2c_algorithm {
62857 /* To determine what the adapter supports */
62858 u32 (*functionality) (struct i2c_adapter *);
62859 };
62860 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
62861
62862 /*
62863 * i2c_adapter is the structure used to identify a physical i2c bus along
62864 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
62865 index d23c3c2..eb63c81 100644
62866 --- a/include/linux/i2o.h
62867 +++ b/include/linux/i2o.h
62868 @@ -565,7 +565,7 @@ struct i2o_controller {
62869 struct i2o_device *exec; /* Executive */
62870 #if BITS_PER_LONG == 64
62871 spinlock_t context_list_lock; /* lock for context_list */
62872 - atomic_t context_list_counter; /* needed for unique contexts */
62873 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
62874 struct list_head context_list; /* list of context id's
62875 and pointers */
62876 #endif
62877 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
62878 index aa2e167..84024ce 100644
62879 --- a/include/linux/if_team.h
62880 +++ b/include/linux/if_team.h
62881 @@ -109,6 +109,7 @@ struct team_mode_ops {
62882 void (*port_enabled)(struct team *team, struct team_port *port);
62883 void (*port_disabled)(struct team *team, struct team_port *port);
62884 };
62885 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
62886
62887 enum team_option_type {
62888 TEAM_OPTION_TYPE_U32,
62889 @@ -181,7 +182,7 @@ struct team {
62890 struct list_head option_inst_list; /* list of option instances */
62891
62892 const struct team_mode *mode;
62893 - struct team_mode_ops ops;
62894 + team_mode_ops_no_const ops;
62895 long mode_priv[TEAM_MODE_PRIV_LONGS];
62896 };
62897
62898 diff --git a/include/linux/init.h b/include/linux/init.h
62899 index 5e664f6..0a1225c 100644
62900 --- a/include/linux/init.h
62901 +++ b/include/linux/init.h
62902 @@ -39,9 +39,15 @@
62903 * Also note, that this data cannot be "const".
62904 */
62905
62906 +#ifdef MODULE
62907 +#define add_latent_entropy
62908 +#else
62909 +#define add_latent_entropy __latent_entropy
62910 +#endif
62911 +
62912 /* These are for everybody (although not all archs will actually
62913 discard it in modules) */
62914 -#define __init __section(.init.text) __cold notrace
62915 +#define __init __section(.init.text) __cold notrace add_latent_entropy
62916 #define __initdata __section(.init.data)
62917 #define __initconst __section(.init.rodata)
62918 #define __exitdata __section(.exit.data)
62919 @@ -83,7 +89,7 @@
62920 #define __exit __section(.exit.text) __exitused __cold notrace
62921
62922 /* Used for HOTPLUG */
62923 -#define __devinit __section(.devinit.text) __cold notrace
62924 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
62925 #define __devinitdata __section(.devinit.data)
62926 #define __devinitconst __section(.devinit.rodata)
62927 #define __devexit __section(.devexit.text) __exitused __cold notrace
62928 @@ -91,7 +97,7 @@
62929 #define __devexitconst __section(.devexit.rodata)
62930
62931 /* Used for HOTPLUG_CPU */
62932 -#define __cpuinit __section(.cpuinit.text) __cold notrace
62933 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
62934 #define __cpuinitdata __section(.cpuinit.data)
62935 #define __cpuinitconst __section(.cpuinit.rodata)
62936 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
62937 @@ -99,7 +105,7 @@
62938 #define __cpuexitconst __section(.cpuexit.rodata)
62939
62940 /* Used for MEMORY_HOTPLUG */
62941 -#define __meminit __section(.meminit.text) __cold notrace
62942 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
62943 #define __meminitdata __section(.meminit.data)
62944 #define __meminitconst __section(.meminit.rodata)
62945 #define __memexit __section(.memexit.text) __exitused __cold notrace
62946 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
62947 index 89f1cb1..7986c0f 100644
62948 --- a/include/linux/init_task.h
62949 +++ b/include/linux/init_task.h
62950 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
62951
62952 #define INIT_TASK_COMM "swapper"
62953
62954 +#ifdef CONFIG_X86
62955 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
62956 +#else
62957 +#define INIT_TASK_THREAD_INFO
62958 +#endif
62959 +
62960 /*
62961 * INIT_TASK is used to set up the first task table, touch at
62962 * your own risk!. Base=0, limit=0x1fffff (=2MB)
62963 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
62964 RCU_POINTER_INITIALIZER(cred, &init_cred), \
62965 .comm = INIT_TASK_COMM, \
62966 .thread = INIT_THREAD, \
62967 + INIT_TASK_THREAD_INFO \
62968 .fs = &init_fs, \
62969 .files = &init_files, \
62970 .signal = &init_signals, \
62971 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
62972 index 78e2ada..745564d 100644
62973 --- a/include/linux/intel-iommu.h
62974 +++ b/include/linux/intel-iommu.h
62975 @@ -296,7 +296,7 @@ struct iommu_flush {
62976 u8 fm, u64 type);
62977 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
62978 unsigned int size_order, u64 type);
62979 -};
62980 +} __no_const;
62981
62982 enum {
62983 SR_DMAR_FECTL_REG,
62984 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
62985 index c5f856a..d29c117 100644
62986 --- a/include/linux/interrupt.h
62987 +++ b/include/linux/interrupt.h
62988 @@ -433,7 +433,7 @@ enum
62989 /* map softirq index to softirq name. update 'softirq_to_name' in
62990 * kernel/softirq.c when adding a new softirq.
62991 */
62992 -extern char *softirq_to_name[NR_SOFTIRQS];
62993 +extern const char * const softirq_to_name[NR_SOFTIRQS];
62994
62995 /* softirq mask and active fields moved to irq_cpustat_t in
62996 * asm/hardirq.h to get better cache usage. KAO
62997 @@ -441,12 +441,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
62998
62999 struct softirq_action
63000 {
63001 - void (*action)(struct softirq_action *);
63002 + void (*action)(void);
63003 };
63004
63005 asmlinkage void do_softirq(void);
63006 asmlinkage void __do_softirq(void);
63007 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63008 +extern void open_softirq(int nr, void (*action)(void));
63009 extern void softirq_init(void);
63010 extern void __raise_softirq_irqoff(unsigned int nr);
63011
63012 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63013 index 6883e19..06992b1 100644
63014 --- a/include/linux/kallsyms.h
63015 +++ b/include/linux/kallsyms.h
63016 @@ -15,7 +15,8 @@
63017
63018 struct module;
63019
63020 -#ifdef CONFIG_KALLSYMS
63021 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63022 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63023 /* Lookup the address for a symbol. Returns 0 if not found. */
63024 unsigned long kallsyms_lookup_name(const char *name);
63025
63026 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63027 /* Stupid that this does nothing, but I didn't create this mess. */
63028 #define __print_symbol(fmt, addr)
63029 #endif /*CONFIG_KALLSYMS*/
63030 +#else /* when included by kallsyms.c, vsnprintf.c, or
63031 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63032 +extern void __print_symbol(const char *fmt, unsigned long address);
63033 +extern int sprint_backtrace(char *buffer, unsigned long address);
63034 +extern int sprint_symbol(char *buffer, unsigned long address);
63035 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63036 +const char *kallsyms_lookup(unsigned long addr,
63037 + unsigned long *symbolsize,
63038 + unsigned long *offset,
63039 + char **modname, char *namebuf);
63040 +#endif
63041
63042 /* This macro allows us to keep printk typechecking */
63043 static __printf(1, 2)
63044 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63045 index c4d2fc1..5df9c19 100644
63046 --- a/include/linux/kgdb.h
63047 +++ b/include/linux/kgdb.h
63048 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63049 extern int kgdb_io_module_registered;
63050
63051 extern atomic_t kgdb_setting_breakpoint;
63052 -extern atomic_t kgdb_cpu_doing_single_step;
63053 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63054
63055 extern struct task_struct *kgdb_usethread;
63056 extern struct task_struct *kgdb_contthread;
63057 @@ -252,7 +252,7 @@ struct kgdb_arch {
63058 void (*disable_hw_break)(struct pt_regs *regs);
63059 void (*remove_all_hw_break)(void);
63060 void (*correct_hw_break)(void);
63061 -};
63062 +} __do_const;
63063
63064 /**
63065 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63066 @@ -277,7 +277,7 @@ struct kgdb_io {
63067 void (*pre_exception) (void);
63068 void (*post_exception) (void);
63069 int is_console;
63070 -};
63071 +} __do_const;
63072
63073 extern struct kgdb_arch arch_kgdb_ops;
63074
63075 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63076 index 5398d58..5883a34 100644
63077 --- a/include/linux/kmod.h
63078 +++ b/include/linux/kmod.h
63079 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63080 * usually useless though. */
63081 extern __printf(2, 3)
63082 int __request_module(bool wait, const char *name, ...);
63083 +extern __printf(3, 4)
63084 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63085 #define request_module(mod...) __request_module(true, mod)
63086 #define request_module_nowait(mod...) __request_module(false, mod)
63087 #define try_then_request_module(x, mod...) \
63088 diff --git a/include/linux/kref.h b/include/linux/kref.h
63089 index 65af688..0592677 100644
63090 --- a/include/linux/kref.h
63091 +++ b/include/linux/kref.h
63092 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
63093 static inline int kref_sub(struct kref *kref, unsigned int count,
63094 void (*release)(struct kref *kref))
63095 {
63096 - WARN_ON(release == NULL);
63097 + BUG_ON(release == NULL);
63098
63099 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63100 release(kref);
63101 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63102 index b70b48b..0d7153b 100644
63103 --- a/include/linux/kvm_host.h
63104 +++ b/include/linux/kvm_host.h
63105 @@ -351,7 +351,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63106 void vcpu_load(struct kvm_vcpu *vcpu);
63107 void vcpu_put(struct kvm_vcpu *vcpu);
63108
63109 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63110 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63111 struct module *module);
63112 void kvm_exit(void);
63113
63114 @@ -517,7 +517,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63115 struct kvm_guest_debug *dbg);
63116 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63117
63118 -int kvm_arch_init(void *opaque);
63119 +int kvm_arch_init(const void *opaque);
63120 void kvm_arch_exit(void);
63121
63122 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63123 diff --git a/include/linux/libata.h b/include/linux/libata.h
63124 index 64f90e1..32b945b 100644
63125 --- a/include/linux/libata.h
63126 +++ b/include/linux/libata.h
63127 @@ -909,7 +909,7 @@ struct ata_port_operations {
63128 * fields must be pointers.
63129 */
63130 const struct ata_port_operations *inherits;
63131 -};
63132 +} __do_const;
63133
63134 struct ata_port_info {
63135 unsigned long flags;
63136 diff --git a/include/linux/memory.h b/include/linux/memory.h
63137 index ff9a9f8..c715deb 100644
63138 --- a/include/linux/memory.h
63139 +++ b/include/linux/memory.h
63140 @@ -143,7 +143,7 @@ struct memory_accessor {
63141 size_t count);
63142 ssize_t (*write)(struct memory_accessor *, const char *buf,
63143 off_t offset, size_t count);
63144 -};
63145 +} __no_const;
63146
63147 /*
63148 * Kernel text modification mutex, used for code patching. Users of this lock
63149 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63150 index 1318ca6..7521340 100644
63151 --- a/include/linux/mfd/abx500.h
63152 +++ b/include/linux/mfd/abx500.h
63153 @@ -452,6 +452,7 @@ struct abx500_ops {
63154 int (*event_registers_startup_state_get) (struct device *, u8 *);
63155 int (*startup_irq_enabled) (struct device *, unsigned int);
63156 };
63157 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63158
63159 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63160 void abx500_remove_ops(struct device *dev);
63161 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63162 index 9b07725..3d55001 100644
63163 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63164 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63165 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63166 int (*enable) (struct ux500_charger *, int, int, int);
63167 int (*kick_wd) (struct ux500_charger *);
63168 int (*update_curr) (struct ux500_charger *, int);
63169 -};
63170 +} __no_const;
63171
63172 /**
63173 * struct ux500_charger - power supply ux500 charger sub class
63174 diff --git a/include/linux/mm.h b/include/linux/mm.h
63175 index 311be90..5f1638c 100644
63176 --- a/include/linux/mm.h
63177 +++ b/include/linux/mm.h
63178 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63179
63180 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63181 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63182 +
63183 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63184 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63185 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63186 +#else
63187 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63188 +#endif
63189 +
63190 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63191 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63192
63193 @@ -1038,34 +1045,6 @@ int set_page_dirty(struct page *page);
63194 int set_page_dirty_lock(struct page *page);
63195 int clear_page_dirty_for_io(struct page *page);
63196
63197 -/* Is the vma a continuation of the stack vma above it? */
63198 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63199 -{
63200 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63201 -}
63202 -
63203 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63204 - unsigned long addr)
63205 -{
63206 - return (vma->vm_flags & VM_GROWSDOWN) &&
63207 - (vma->vm_start == addr) &&
63208 - !vma_growsdown(vma->vm_prev, addr);
63209 -}
63210 -
63211 -/* Is the vma a continuation of the stack vma below it? */
63212 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63213 -{
63214 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63215 -}
63216 -
63217 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63218 - unsigned long addr)
63219 -{
63220 - return (vma->vm_flags & VM_GROWSUP) &&
63221 - (vma->vm_end == addr) &&
63222 - !vma_growsup(vma->vm_next, addr);
63223 -}
63224 -
63225 extern pid_t
63226 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63227
63228 @@ -1164,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63229 }
63230 #endif
63231
63232 +#ifdef CONFIG_MMU
63233 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63234 +#else
63235 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63236 +{
63237 + return __pgprot(0);
63238 +}
63239 +#endif
63240 +
63241 int vma_wants_writenotify(struct vm_area_struct *vma);
63242
63243 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63244 @@ -1182,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63245 {
63246 return 0;
63247 }
63248 +
63249 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63250 + unsigned long address)
63251 +{
63252 + return 0;
63253 +}
63254 #else
63255 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63256 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63257 #endif
63258
63259 #ifdef __PAGETABLE_PMD_FOLDED
63260 @@ -1192,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63261 {
63262 return 0;
63263 }
63264 +
63265 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63266 + unsigned long address)
63267 +{
63268 + return 0;
63269 +}
63270 #else
63271 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63272 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63273 #endif
63274
63275 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63276 @@ -1211,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63277 NULL: pud_offset(pgd, address);
63278 }
63279
63280 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63281 +{
63282 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63283 + NULL: pud_offset(pgd, address);
63284 +}
63285 +
63286 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63287 {
63288 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63289 NULL: pmd_offset(pud, address);
63290 }
63291 +
63292 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63293 +{
63294 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63295 + NULL: pmd_offset(pud, address);
63296 +}
63297 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63298
63299 #if USE_SPLIT_PTLOCKS
63300 @@ -1426,6 +1440,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63301 unsigned long, unsigned long,
63302 unsigned long, unsigned long);
63303 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63304 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63305
63306 /* These take the mm semaphore themselves */
63307 extern unsigned long vm_brk(unsigned long, unsigned long);
63308 @@ -1489,6 +1504,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63309 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63310 struct vm_area_struct **pprev);
63311
63312 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63313 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63314 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63315 +
63316 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63317 NULL if none. Assume start_addr < end_addr. */
63318 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63319 @@ -1517,15 +1536,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63320 return vma;
63321 }
63322
63323 -#ifdef CONFIG_MMU
63324 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63325 -#else
63326 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63327 -{
63328 - return __pgprot(0);
63329 -}
63330 -#endif
63331 -
63332 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63333 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63334 unsigned long pfn, unsigned long size, pgprot_t);
63335 @@ -1631,7 +1641,7 @@ extern int unpoison_memory(unsigned long pfn);
63336 extern int sysctl_memory_failure_early_kill;
63337 extern int sysctl_memory_failure_recovery;
63338 extern void shake_page(struct page *p, int access);
63339 -extern atomic_long_t mce_bad_pages;
63340 +extern atomic_long_unchecked_t mce_bad_pages;
63341 extern int soft_offline_page(struct page *page, int flags);
63342
63343 extern void dump_page(struct page *page);
63344 @@ -1662,5 +1672,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63345 static inline bool page_is_guard(struct page *page) { return false; }
63346 #endif /* CONFIG_DEBUG_PAGEALLOC */
63347
63348 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63349 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63350 +#else
63351 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63352 +#endif
63353 +
63354 #endif /* __KERNEL__ */
63355 #endif /* _LINUX_MM_H */
63356 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63357 index bf78672..debc693 100644
63358 --- a/include/linux/mm_types.h
63359 +++ b/include/linux/mm_types.h
63360 @@ -279,6 +279,8 @@ struct vm_area_struct {
63361 #ifdef CONFIG_NUMA
63362 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63363 #endif
63364 +
63365 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63366 };
63367
63368 struct core_thread {
63369 @@ -353,7 +355,7 @@ struct mm_struct {
63370 unsigned long def_flags;
63371 unsigned long nr_ptes; /* Page table pages */
63372 unsigned long start_code, end_code, start_data, end_data;
63373 - unsigned long start_brk, brk, start_stack;
63374 + unsigned long brk_gap, start_brk, brk, start_stack;
63375 unsigned long arg_start, arg_end, env_start, env_end;
63376
63377 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63378 @@ -405,6 +407,24 @@ struct mm_struct {
63379 struct cpumask cpumask_allocation;
63380 #endif
63381 struct uprobes_state uprobes_state;
63382 +
63383 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63384 + unsigned long pax_flags;
63385 +#endif
63386 +
63387 +#ifdef CONFIG_PAX_DLRESOLVE
63388 + unsigned long call_dl_resolve;
63389 +#endif
63390 +
63391 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63392 + unsigned long call_syscall;
63393 +#endif
63394 +
63395 +#ifdef CONFIG_PAX_ASLR
63396 + unsigned long delta_mmap; /* randomized offset */
63397 + unsigned long delta_stack; /* randomized offset */
63398 +#endif
63399 +
63400 };
63401
63402 static inline void mm_init_cpumask(struct mm_struct *mm)
63403 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63404 index 1d1b1e1..2a13c78 100644
63405 --- a/include/linux/mmu_notifier.h
63406 +++ b/include/linux/mmu_notifier.h
63407 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63408 */
63409 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63410 ({ \
63411 - pte_t __pte; \
63412 + pte_t ___pte; \
63413 struct vm_area_struct *___vma = __vma; \
63414 unsigned long ___address = __address; \
63415 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63416 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63417 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63418 - __pte; \
63419 + ___pte; \
63420 })
63421
63422 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63423 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63424 index 2daa54f..bfdf2f5 100644
63425 --- a/include/linux/mmzone.h
63426 +++ b/include/linux/mmzone.h
63427 @@ -414,7 +414,7 @@ struct zone {
63428 unsigned long flags; /* zone flags, see below */
63429
63430 /* Zone statistics */
63431 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63432 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63433
63434 /*
63435 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63436 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63437 index 6955045..ebdb7cd 100644
63438 --- a/include/linux/mod_devicetable.h
63439 +++ b/include/linux/mod_devicetable.h
63440 @@ -12,7 +12,7 @@
63441 typedef unsigned long kernel_ulong_t;
63442 #endif
63443
63444 -#define PCI_ANY_ID (~0)
63445 +#define PCI_ANY_ID ((__u16)~0)
63446
63447 struct pci_device_id {
63448 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63449 @@ -139,7 +139,7 @@ struct usb_device_id {
63450 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63451 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
63452
63453 -#define HID_ANY_ID (~0)
63454 +#define HID_ANY_ID (~0U)
63455 #define HID_BUS_ANY 0xffff
63456 #define HID_GROUP_ANY 0x0000
63457
63458 diff --git a/include/linux/module.h b/include/linux/module.h
63459 index fbcafe2..e5d9587 100644
63460 --- a/include/linux/module.h
63461 +++ b/include/linux/module.h
63462 @@ -17,6 +17,7 @@
63463 #include <linux/moduleparam.h>
63464 #include <linux/tracepoint.h>
63465 #include <linux/export.h>
63466 +#include <linux/fs.h>
63467
63468 #include <linux/percpu.h>
63469 #include <asm/module.h>
63470 @@ -273,19 +274,16 @@ struct module
63471 int (*init)(void);
63472
63473 /* If this is non-NULL, vfree after init() returns */
63474 - void *module_init;
63475 + void *module_init_rx, *module_init_rw;
63476
63477 /* Here is the actual code + data, vfree'd on unload. */
63478 - void *module_core;
63479 + void *module_core_rx, *module_core_rw;
63480
63481 /* Here are the sizes of the init and core sections */
63482 - unsigned int init_size, core_size;
63483 + unsigned int init_size_rw, core_size_rw;
63484
63485 /* The size of the executable code in each section. */
63486 - unsigned int init_text_size, core_text_size;
63487 -
63488 - /* Size of RO sections of the module (text+rodata) */
63489 - unsigned int init_ro_size, core_ro_size;
63490 + unsigned int init_size_rx, core_size_rx;
63491
63492 /* Arch-specific module values */
63493 struct mod_arch_specific arch;
63494 @@ -341,6 +339,10 @@ struct module
63495 #ifdef CONFIG_EVENT_TRACING
63496 struct ftrace_event_call **trace_events;
63497 unsigned int num_trace_events;
63498 + struct file_operations trace_id;
63499 + struct file_operations trace_enable;
63500 + struct file_operations trace_format;
63501 + struct file_operations trace_filter;
63502 #endif
63503 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63504 unsigned int num_ftrace_callsites;
63505 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63506 bool is_module_percpu_address(unsigned long addr);
63507 bool is_module_text_address(unsigned long addr);
63508
63509 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63510 +{
63511 +
63512 +#ifdef CONFIG_PAX_KERNEXEC
63513 + if (ktla_ktva(addr) >= (unsigned long)start &&
63514 + ktla_ktva(addr) < (unsigned long)start + size)
63515 + return 1;
63516 +#endif
63517 +
63518 + return ((void *)addr >= start && (void *)addr < start + size);
63519 +}
63520 +
63521 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63522 +{
63523 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63524 +}
63525 +
63526 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63527 +{
63528 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63529 +}
63530 +
63531 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63532 +{
63533 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63534 +}
63535 +
63536 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63537 +{
63538 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63539 +}
63540 +
63541 static inline int within_module_core(unsigned long addr, struct module *mod)
63542 {
63543 - return (unsigned long)mod->module_core <= addr &&
63544 - addr < (unsigned long)mod->module_core + mod->core_size;
63545 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63546 }
63547
63548 static inline int within_module_init(unsigned long addr, struct module *mod)
63549 {
63550 - return (unsigned long)mod->module_init <= addr &&
63551 - addr < (unsigned long)mod->module_init + mod->init_size;
63552 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63553 }
63554
63555 /* Search for module by name: must hold module_mutex. */
63556 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63557 index b2be02e..72d2f78 100644
63558 --- a/include/linux/moduleloader.h
63559 +++ b/include/linux/moduleloader.h
63560 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63561
63562 /* Allocator used for allocating struct module, core sections and init
63563 sections. Returns NULL on failure. */
63564 -void *module_alloc(unsigned long size);
63565 +void *module_alloc(unsigned long size) __size_overflow(1);
63566 +
63567 +#ifdef CONFIG_PAX_KERNEXEC
63568 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63569 +#else
63570 +#define module_alloc_exec(x) module_alloc(x)
63571 +#endif
63572
63573 /* Free memory returned from module_alloc. */
63574 void module_free(struct module *mod, void *module_region);
63575
63576 +#ifdef CONFIG_PAX_KERNEXEC
63577 +void module_free_exec(struct module *mod, void *module_region);
63578 +#else
63579 +#define module_free_exec(x, y) module_free((x), (y))
63580 +#endif
63581 +
63582 /* Apply the given relocation to the (simplified) ELF. Return -error
63583 or 0. */
63584 int apply_relocate(Elf_Shdr *sechdrs,
63585 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63586 index d6a5806..7c13347 100644
63587 --- a/include/linux/moduleparam.h
63588 +++ b/include/linux/moduleparam.h
63589 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63590 * @len is usually just sizeof(string).
63591 */
63592 #define module_param_string(name, string, len, perm) \
63593 - static const struct kparam_string __param_string_##name \
63594 + static const struct kparam_string __param_string_##name __used \
63595 = { len, string }; \
63596 __module_param_call(MODULE_PARAM_PREFIX, name, \
63597 &param_ops_string, \
63598 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63599 */
63600 #define module_param_array_named(name, array, type, nump, perm) \
63601 param_check_##type(name, &(array)[0]); \
63602 - static const struct kparam_array __param_arr_##name \
63603 + static const struct kparam_array __param_arr_##name __used \
63604 = { .max = ARRAY_SIZE(array), .num = nump, \
63605 .ops = &param_ops_##type, \
63606 .elemsize = sizeof(array[0]), .elem = array }; \
63607 diff --git a/include/linux/namei.h b/include/linux/namei.h
63608 index 4bf19d8..5268cea 100644
63609 --- a/include/linux/namei.h
63610 +++ b/include/linux/namei.h
63611 @@ -18,7 +18,7 @@ struct nameidata {
63612 unsigned seq;
63613 int last_type;
63614 unsigned depth;
63615 - char *saved_names[MAX_NESTED_LINKS + 1];
63616 + const char *saved_names[MAX_NESTED_LINKS + 1];
63617 };
63618
63619 /*
63620 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
63621
63622 extern void nd_jump_link(struct nameidata *nd, struct path *path);
63623
63624 -static inline void nd_set_link(struct nameidata *nd, char *path)
63625 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63626 {
63627 nd->saved_names[nd->depth] = path;
63628 }
63629
63630 -static inline char *nd_get_link(struct nameidata *nd)
63631 +static inline const char *nd_get_link(const struct nameidata *nd)
63632 {
63633 return nd->saved_names[nd->depth];
63634 }
63635 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63636 index 59dc05f3..c905a34 100644
63637 --- a/include/linux/netdevice.h
63638 +++ b/include/linux/netdevice.h
63639 @@ -1027,6 +1027,7 @@ struct net_device_ops {
63640 struct net_device *dev,
63641 int idx);
63642 };
63643 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63644
63645 /*
63646 * The DEVICE structure.
63647 @@ -1087,7 +1088,7 @@ struct net_device {
63648 int iflink;
63649
63650 struct net_device_stats stats;
63651 - atomic_long_t rx_dropped; /* dropped packets by core network
63652 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63653 * Do not use this in drivers.
63654 */
63655
63656 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63657 new file mode 100644
63658 index 0000000..33f4af8
63659 --- /dev/null
63660 +++ b/include/linux/netfilter/xt_gradm.h
63661 @@ -0,0 +1,9 @@
63662 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63663 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63664 +
63665 +struct xt_gradm_mtinfo {
63666 + __u16 flags;
63667 + __u16 invflags;
63668 +};
63669 +
63670 +#endif
63671 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63672 index c65a18a..0c05f3a 100644
63673 --- a/include/linux/of_pdt.h
63674 +++ b/include/linux/of_pdt.h
63675 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63676
63677 /* return 0 on success; fill in 'len' with number of bytes in path */
63678 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63679 -};
63680 +} __no_const;
63681
63682 extern void *prom_early_alloc(unsigned long size);
63683
63684 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63685 index a4c5624..79d6d88 100644
63686 --- a/include/linux/oprofile.h
63687 +++ b/include/linux/oprofile.h
63688 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63689 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63690 char const * name, ulong * val);
63691
63692 -/** Create a file for read-only access to an atomic_t. */
63693 +/** Create a file for read-only access to an atomic_unchecked_t. */
63694 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63695 - char const * name, atomic_t * val);
63696 + char const * name, atomic_unchecked_t * val);
63697
63698 /** create a directory */
63699 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63700 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63701 index bdb4161..f373d41 100644
63702 --- a/include/linux/perf_event.h
63703 +++ b/include/linux/perf_event.h
63704 @@ -882,8 +882,8 @@ struct perf_event {
63705
63706 enum perf_event_active_state state;
63707 unsigned int attach_state;
63708 - local64_t count;
63709 - atomic64_t child_count;
63710 + local64_t count; /* PaX: fix it one day */
63711 + atomic64_unchecked_t child_count;
63712
63713 /*
63714 * These are the total time in nanoseconds that the event
63715 @@ -934,8 +934,8 @@ struct perf_event {
63716 * These accumulate total time (in nanoseconds) that children
63717 * events have been enabled and running, respectively.
63718 */
63719 - atomic64_t child_total_time_enabled;
63720 - atomic64_t child_total_time_running;
63721 + atomic64_unchecked_t child_total_time_enabled;
63722 + atomic64_unchecked_t child_total_time_running;
63723
63724 /*
63725 * Protect attach/detach and child_list:
63726 diff --git a/include/linux/personality.h b/include/linux/personality.h
63727 index 8fc7dd1a..c19d89e 100644
63728 --- a/include/linux/personality.h
63729 +++ b/include/linux/personality.h
63730 @@ -44,6 +44,7 @@ enum {
63731 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63732 ADDR_NO_RANDOMIZE | \
63733 ADDR_COMPAT_LAYOUT | \
63734 + ADDR_LIMIT_3GB | \
63735 MMAP_PAGE_ZERO)
63736
63737 /*
63738 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63739 index ad1a427..6419649 100644
63740 --- a/include/linux/pipe_fs_i.h
63741 +++ b/include/linux/pipe_fs_i.h
63742 @@ -45,9 +45,9 @@ struct pipe_buffer {
63743 struct pipe_inode_info {
63744 wait_queue_head_t wait;
63745 unsigned int nrbufs, curbuf, buffers;
63746 - unsigned int readers;
63747 - unsigned int writers;
63748 - unsigned int waiting_writers;
63749 + atomic_t readers;
63750 + atomic_t writers;
63751 + atomic_t waiting_writers;
63752 unsigned int r_counter;
63753 unsigned int w_counter;
63754 struct page *tmp_page;
63755 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63756 index f271860..6b3bec5 100644
63757 --- a/include/linux/pm_runtime.h
63758 +++ b/include/linux/pm_runtime.h
63759 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63760
63761 static inline void pm_runtime_mark_last_busy(struct device *dev)
63762 {
63763 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63764 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63765 }
63766
63767 #else /* !CONFIG_PM_RUNTIME */
63768 diff --git a/include/linux/poison.h b/include/linux/poison.h
63769 index 2110a81..13a11bb 100644
63770 --- a/include/linux/poison.h
63771 +++ b/include/linux/poison.h
63772 @@ -19,8 +19,8 @@
63773 * under normal circumstances, used to verify that nobody uses
63774 * non-initialized list entries.
63775 */
63776 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63777 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63778 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63779 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63780
63781 /********** include/linux/timer.h **********/
63782 /*
63783 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63784 index 5a710b9..0b0dab9 100644
63785 --- a/include/linux/preempt.h
63786 +++ b/include/linux/preempt.h
63787 @@ -126,7 +126,7 @@ struct preempt_ops {
63788 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63789 void (*sched_out)(struct preempt_notifier *notifier,
63790 struct task_struct *next);
63791 -};
63792 +} __no_const;
63793
63794 /**
63795 * preempt_notifier - key for installing preemption notifiers
63796 diff --git a/include/linux/printk.h b/include/linux/printk.h
63797 index 9afc01e..92c32e8 100644
63798 --- a/include/linux/printk.h
63799 +++ b/include/linux/printk.h
63800 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
63801 extern int printk_needs_cpu(int cpu);
63802 extern void printk_tick(void);
63803
63804 +extern int kptr_restrict;
63805 +
63806 #ifdef CONFIG_PRINTK
63807 asmlinkage __printf(5, 0)
63808 int vprintk_emit(int facility, int level,
63809 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63810
63811 extern int printk_delay_msec;
63812 extern int dmesg_restrict;
63813 -extern int kptr_restrict;
63814
63815 void log_buf_kexec_setup(void);
63816 void __init setup_log_buf(int early);
63817 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63818 index 3fd2e87..d93a721 100644
63819 --- a/include/linux/proc_fs.h
63820 +++ b/include/linux/proc_fs.h
63821 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63822 return proc_create_data(name, mode, parent, proc_fops, NULL);
63823 }
63824
63825 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63826 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63827 +{
63828 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63829 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63830 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63831 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63832 +#else
63833 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63834 +#endif
63835 +}
63836 +
63837 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63838 umode_t mode, struct proc_dir_entry *base,
63839 read_proc_t *read_proc, void * data)
63840 @@ -258,7 +270,7 @@ union proc_op {
63841 int (*proc_show)(struct seq_file *m,
63842 struct pid_namespace *ns, struct pid *pid,
63843 struct task_struct *task);
63844 -};
63845 +} __no_const;
63846
63847 struct ctl_table_header;
63848 struct ctl_table;
63849 diff --git a/include/linux/random.h b/include/linux/random.h
63850 index ac621ce..c1215f3 100644
63851 --- a/include/linux/random.h
63852 +++ b/include/linux/random.h
63853 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
63854 unsigned int value);
63855 extern void add_interrupt_randomness(int irq, int irq_flags);
63856
63857 +#ifdef CONFIG_PAX_LATENT_ENTROPY
63858 +extern void transfer_latent_entropy(void);
63859 +#endif
63860 +
63861 extern void get_random_bytes(void *buf, int nbytes);
63862 extern void get_random_bytes_arch(void *buf, int nbytes);
63863 void generate_random_uuid(unsigned char uuid_out[16]);
63864 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
63865
63866 u32 prandom32(struct rnd_state *);
63867
63868 +static inline unsigned long pax_get_random_long(void)
63869 +{
63870 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
63871 +}
63872 +
63873 /*
63874 * Handle minimum values for seeds
63875 */
63876 static inline u32 __seed(u32 x, u32 m)
63877 {
63878 - return (x < m) ? x + m : x;
63879 + return (x <= m) ? x + m + 1 : x;
63880 }
63881
63882 /**
63883 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
63884 index e0879a7..a12f962 100644
63885 --- a/include/linux/reboot.h
63886 +++ b/include/linux/reboot.h
63887 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
63888 * Architecture-specific implementations of sys_reboot commands.
63889 */
63890
63891 -extern void machine_restart(char *cmd);
63892 -extern void machine_halt(void);
63893 -extern void machine_power_off(void);
63894 +extern void machine_restart(char *cmd) __noreturn;
63895 +extern void machine_halt(void) __noreturn;
63896 +extern void machine_power_off(void) __noreturn;
63897
63898 extern void machine_shutdown(void);
63899 struct pt_regs;
63900 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
63901 */
63902
63903 extern void kernel_restart_prepare(char *cmd);
63904 -extern void kernel_restart(char *cmd);
63905 -extern void kernel_halt(void);
63906 -extern void kernel_power_off(void);
63907 +extern void kernel_restart(char *cmd) __noreturn;
63908 +extern void kernel_halt(void) __noreturn;
63909 +extern void kernel_power_off(void) __noreturn;
63910
63911 extern int C_A_D; /* for sysctl */
63912 void ctrl_alt_del(void);
63913 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
63914 * Emergency restart, callable from an interrupt handler.
63915 */
63916
63917 -extern void emergency_restart(void);
63918 +extern void emergency_restart(void) __noreturn;
63919 #include <asm/emergency-restart.h>
63920
63921 #endif
63922 diff --git a/include/linux/relay.h b/include/linux/relay.h
63923 index 91cacc3..b55ff74 100644
63924 --- a/include/linux/relay.h
63925 +++ b/include/linux/relay.h
63926 @@ -160,7 +160,7 @@ struct rchan_callbacks
63927 * The callback should return 0 if successful, negative if not.
63928 */
63929 int (*remove_buf_file)(struct dentry *dentry);
63930 -};
63931 +} __no_const;
63932
63933 /*
63934 * CONFIG_RELAY kernel API, kernel/relay.c
63935 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
63936 index 6fdf027..ff72610 100644
63937 --- a/include/linux/rfkill.h
63938 +++ b/include/linux/rfkill.h
63939 @@ -147,6 +147,7 @@ struct rfkill_ops {
63940 void (*query)(struct rfkill *rfkill, void *data);
63941 int (*set_block)(void *data, bool blocked);
63942 };
63943 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
63944
63945 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
63946 /**
63947 diff --git a/include/linux/rio.h b/include/linux/rio.h
63948 index a90ebad..fd87b5d 100644
63949 --- a/include/linux/rio.h
63950 +++ b/include/linux/rio.h
63951 @@ -321,7 +321,7 @@ struct rio_ops {
63952 int mbox, void *buffer, size_t len);
63953 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
63954 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
63955 -};
63956 +} __no_const;
63957
63958 #define RIO_RESOURCE_MEM 0x00000100
63959 #define RIO_RESOURCE_DOORBELL 0x00000200
63960 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
63961 index 3fce545..b4fed6e 100644
63962 --- a/include/linux/rmap.h
63963 +++ b/include/linux/rmap.h
63964 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
63965 void anon_vma_init(void); /* create anon_vma_cachep */
63966 int anon_vma_prepare(struct vm_area_struct *);
63967 void unlink_anon_vmas(struct vm_area_struct *);
63968 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
63969 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
63970 void anon_vma_moveto_tail(struct vm_area_struct *);
63971 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
63972 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
63973
63974 static inline void anon_vma_merge(struct vm_area_struct *vma,
63975 struct vm_area_struct *next)
63976 diff --git a/include/linux/sched.h b/include/linux/sched.h
63977 index 23bddac..5976055 100644
63978 --- a/include/linux/sched.h
63979 +++ b/include/linux/sched.h
63980 @@ -101,6 +101,7 @@ struct bio_list;
63981 struct fs_struct;
63982 struct perf_event_context;
63983 struct blk_plug;
63984 +struct linux_binprm;
63985
63986 /*
63987 * List of flags we want to share for kernel threads,
63988 @@ -384,10 +385,13 @@ struct user_namespace;
63989 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
63990
63991 extern int sysctl_max_map_count;
63992 +extern unsigned long sysctl_heap_stack_gap;
63993
63994 #include <linux/aio.h>
63995
63996 #ifdef CONFIG_MMU
63997 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
63998 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
63999 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64000 extern unsigned long
64001 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64002 @@ -651,6 +655,17 @@ struct signal_struct {
64003 #ifdef CONFIG_TASKSTATS
64004 struct taskstats *stats;
64005 #endif
64006 +
64007 +#ifdef CONFIG_GRKERNSEC
64008 + u32 curr_ip;
64009 + u32 saved_ip;
64010 + u32 gr_saddr;
64011 + u32 gr_daddr;
64012 + u16 gr_sport;
64013 + u16 gr_dport;
64014 + u8 used_accept:1;
64015 +#endif
64016 +
64017 #ifdef CONFIG_AUDIT
64018 unsigned audit_tty;
64019 struct tty_audit_buf *tty_audit_buf;
64020 @@ -734,6 +749,11 @@ struct user_struct {
64021 struct key *session_keyring; /* UID's default session keyring */
64022 #endif
64023
64024 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64025 + unsigned int banned;
64026 + unsigned long ban_expires;
64027 +#endif
64028 +
64029 /* Hash table maintenance information */
64030 struct hlist_node uidhash_node;
64031 kuid_t uid;
64032 @@ -1356,8 +1376,8 @@ struct task_struct {
64033 struct list_head thread_group;
64034
64035 struct completion *vfork_done; /* for vfork() */
64036 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64037 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64038 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64039 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64040
64041 cputime_t utime, stime, utimescaled, stimescaled;
64042 cputime_t gtime;
64043 @@ -1373,11 +1393,6 @@ struct task_struct {
64044 struct task_cputime cputime_expires;
64045 struct list_head cpu_timers[3];
64046
64047 -/* process credentials */
64048 - const struct cred __rcu *real_cred; /* objective and real subjective task
64049 - * credentials (COW) */
64050 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64051 - * credentials (COW) */
64052 char comm[TASK_COMM_LEN]; /* executable name excluding path
64053 - access with [gs]et_task_comm (which lock
64054 it with task_lock())
64055 @@ -1394,6 +1409,10 @@ struct task_struct {
64056 #endif
64057 /* CPU-specific state of this task */
64058 struct thread_struct thread;
64059 +/* thread_info moved to task_struct */
64060 +#ifdef CONFIG_X86
64061 + struct thread_info tinfo;
64062 +#endif
64063 /* filesystem information */
64064 struct fs_struct *fs;
64065 /* open file information */
64066 @@ -1467,6 +1486,10 @@ struct task_struct {
64067 gfp_t lockdep_reclaim_gfp;
64068 #endif
64069
64070 +/* process credentials */
64071 + const struct cred __rcu *real_cred; /* objective and real subjective task
64072 + * credentials (COW) */
64073 +
64074 /* journalling filesystem info */
64075 void *journal_info;
64076
64077 @@ -1505,6 +1528,10 @@ struct task_struct {
64078 /* cg_list protected by css_set_lock and tsk->alloc_lock */
64079 struct list_head cg_list;
64080 #endif
64081 +
64082 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64083 + * credentials (COW) */
64084 +
64085 #ifdef CONFIG_FUTEX
64086 struct robust_list_head __user *robust_list;
64087 #ifdef CONFIG_COMPAT
64088 @@ -1589,8 +1616,74 @@ struct task_struct {
64089 #ifdef CONFIG_UPROBES
64090 struct uprobe_task *utask;
64091 #endif
64092 +
64093 +#ifdef CONFIG_GRKERNSEC
64094 + /* grsecurity */
64095 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64096 + u64 exec_id;
64097 +#endif
64098 +#ifdef CONFIG_GRKERNSEC_SETXID
64099 + const struct cred *delayed_cred;
64100 +#endif
64101 + struct dentry *gr_chroot_dentry;
64102 + struct acl_subject_label *acl;
64103 + struct acl_role_label *role;
64104 + struct file *exec_file;
64105 + u16 acl_role_id;
64106 + /* is this the task that authenticated to the special role */
64107 + u8 acl_sp_role;
64108 + u8 is_writable;
64109 + u8 brute;
64110 + u8 gr_is_chrooted;
64111 +#endif
64112 +
64113 };
64114
64115 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64116 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64117 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64118 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64119 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64120 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64121 +
64122 +#ifdef CONFIG_PAX_SOFTMODE
64123 +extern int pax_softmode;
64124 +#endif
64125 +
64126 +extern int pax_check_flags(unsigned long *);
64127 +
64128 +/* if tsk != current then task_lock must be held on it */
64129 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64130 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64131 +{
64132 + if (likely(tsk->mm))
64133 + return tsk->mm->pax_flags;
64134 + else
64135 + return 0UL;
64136 +}
64137 +
64138 +/* if tsk != current then task_lock must be held on it */
64139 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64140 +{
64141 + if (likely(tsk->mm)) {
64142 + tsk->mm->pax_flags = flags;
64143 + return 0;
64144 + }
64145 + return -EINVAL;
64146 +}
64147 +#endif
64148 +
64149 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64150 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64151 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64152 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64153 +#endif
64154 +
64155 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64156 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64157 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64158 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64159 +
64160 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64161 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64162
64163 @@ -2125,7 +2218,9 @@ void yield(void);
64164 extern struct exec_domain default_exec_domain;
64165
64166 union thread_union {
64167 +#ifndef CONFIG_X86
64168 struct thread_info thread_info;
64169 +#endif
64170 unsigned long stack[THREAD_SIZE/sizeof(long)];
64171 };
64172
64173 @@ -2158,6 +2253,7 @@ extern struct pid_namespace init_pid_ns;
64174 */
64175
64176 extern struct task_struct *find_task_by_vpid(pid_t nr);
64177 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64178 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64179 struct pid_namespace *ns);
64180
64181 @@ -2314,7 +2410,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64182 extern void exit_itimers(struct signal_struct *);
64183 extern void flush_itimer_signals(void);
64184
64185 -extern void do_group_exit(int);
64186 +extern __noreturn void do_group_exit(int);
64187
64188 extern void daemonize(const char *, ...);
64189 extern int allow_signal(int);
64190 @@ -2515,9 +2611,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64191
64192 #endif
64193
64194 -static inline int object_is_on_stack(void *obj)
64195 +static inline int object_starts_on_stack(void *obj)
64196 {
64197 - void *stack = task_stack_page(current);
64198 + const void *stack = task_stack_page(current);
64199
64200 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64201 }
64202 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64203 index 899fbb4..1cb4138 100644
64204 --- a/include/linux/screen_info.h
64205 +++ b/include/linux/screen_info.h
64206 @@ -43,7 +43,8 @@ struct screen_info {
64207 __u16 pages; /* 0x32 */
64208 __u16 vesa_attributes; /* 0x34 */
64209 __u32 capabilities; /* 0x36 */
64210 - __u8 _reserved[6]; /* 0x3a */
64211 + __u16 vesapm_size; /* 0x3a */
64212 + __u8 _reserved[4]; /* 0x3c */
64213 } __attribute__((packed));
64214
64215 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64216 diff --git a/include/linux/security.h b/include/linux/security.h
64217 index d143b8e..9f27b95 100644
64218 --- a/include/linux/security.h
64219 +++ b/include/linux/security.h
64220 @@ -26,6 +26,7 @@
64221 #include <linux/capability.h>
64222 #include <linux/slab.h>
64223 #include <linux/err.h>
64224 +#include <linux/grsecurity.h>
64225
64226 struct linux_binprm;
64227 struct cred;
64228 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64229 index 83c44ee..e8a9eba 100644
64230 --- a/include/linux/seq_file.h
64231 +++ b/include/linux/seq_file.h
64232 @@ -25,6 +25,9 @@ struct seq_file {
64233 struct mutex lock;
64234 const struct seq_operations *op;
64235 int poll_event;
64236 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64237 + u64 exec_id;
64238 +#endif
64239 void *private;
64240 };
64241
64242 @@ -34,6 +37,7 @@ struct seq_operations {
64243 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64244 int (*show) (struct seq_file *m, void *v);
64245 };
64246 +typedef struct seq_operations __no_const seq_operations_no_const;
64247
64248 #define SEQ_SKIP 1
64249
64250 diff --git a/include/linux/shm.h b/include/linux/shm.h
64251 index edd0868..f98feee 100644
64252 --- a/include/linux/shm.h
64253 +++ b/include/linux/shm.h
64254 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64255
64256 /* The task created the shm object. NULL if the task is dead. */
64257 struct task_struct *shm_creator;
64258 +#ifdef CONFIG_GRKERNSEC
64259 + time_t shm_createtime;
64260 + pid_t shm_lapid;
64261 +#endif
64262 };
64263
64264 /* shm_mode upper byte flags */
64265 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64266 index 7632c87..8fd660f 100644
64267 --- a/include/linux/skbuff.h
64268 +++ b/include/linux/skbuff.h
64269 @@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64270 extern struct sk_buff *__alloc_skb(unsigned int size,
64271 gfp_t priority, int flags, int node);
64272 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64273 -static inline struct sk_buff *alloc_skb(unsigned int size,
64274 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64275 gfp_t priority)
64276 {
64277 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64278 @@ -690,7 +690,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64279 */
64280 static inline int skb_queue_empty(const struct sk_buff_head *list)
64281 {
64282 - return list->next == (struct sk_buff *)list;
64283 + return list->next == (const struct sk_buff *)list;
64284 }
64285
64286 /**
64287 @@ -703,7 +703,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64288 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64289 const struct sk_buff *skb)
64290 {
64291 - return skb->next == (struct sk_buff *)list;
64292 + return skb->next == (const struct sk_buff *)list;
64293 }
64294
64295 /**
64296 @@ -716,7 +716,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64297 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64298 const struct sk_buff *skb)
64299 {
64300 - return skb->prev == (struct sk_buff *)list;
64301 + return skb->prev == (const struct sk_buff *)list;
64302 }
64303
64304 /**
64305 @@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64306 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64307 */
64308 #ifndef NET_SKB_PAD
64309 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64310 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64311 #endif
64312
64313 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64314 @@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64315 int noblock, int *err);
64316 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64317 struct poll_table_struct *wait);
64318 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64319 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64320 int offset, struct iovec *to,
64321 int size);
64322 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64323 diff --git a/include/linux/slab.h b/include/linux/slab.h
64324 index 0dd2dfa..2b8677c 100644
64325 --- a/include/linux/slab.h
64326 +++ b/include/linux/slab.h
64327 @@ -11,12 +11,20 @@
64328
64329 #include <linux/gfp.h>
64330 #include <linux/types.h>
64331 +#include <linux/err.h>
64332
64333 /*
64334 * Flags to pass to kmem_cache_create().
64335 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64336 */
64337 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64338 +
64339 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64340 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64341 +#else
64342 +#define SLAB_USERCOPY 0x00000000UL
64343 +#endif
64344 +
64345 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64346 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64347 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64348 @@ -87,10 +95,13 @@
64349 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64350 * Both make kfree a no-op.
64351 */
64352 -#define ZERO_SIZE_PTR ((void *)16)
64353 +#define ZERO_SIZE_PTR \
64354 +({ \
64355 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64356 + (void *)(-MAX_ERRNO-1L); \
64357 +})
64358
64359 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64360 - (unsigned long)ZERO_SIZE_PTR)
64361 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64362
64363 /*
64364 * Common fields provided in kmem_cache by all slab allocators
64365 @@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64366 void kfree(const void *);
64367 void kzfree(const void *);
64368 size_t ksize(const void *);
64369 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64370 +bool is_usercopy_object(const void *ptr);
64371
64372 /*
64373 * Allocator specific definitions. These are mainly used to establish optimized
64374 @@ -322,7 +335,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64375 */
64376 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64377 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64378 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64379 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64380 #define kmalloc_track_caller(size, flags) \
64381 __kmalloc_track_caller(size, flags, _RET_IP_)
64382 #else
64383 @@ -341,7 +354,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64384 */
64385 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64386 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64387 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64388 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64389 #define kmalloc_node_track_caller(size, flags, node) \
64390 __kmalloc_node_track_caller(size, flags, node, \
64391 _RET_IP_)
64392 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64393 index 0c634fa..8616300 100644
64394 --- a/include/linux/slab_def.h
64395 +++ b/include/linux/slab_def.h
64396 @@ -69,10 +69,10 @@ struct kmem_cache {
64397 unsigned long node_allocs;
64398 unsigned long node_frees;
64399 unsigned long node_overflow;
64400 - atomic_t allochit;
64401 - atomic_t allocmiss;
64402 - atomic_t freehit;
64403 - atomic_t freemiss;
64404 + atomic_unchecked_t allochit;
64405 + atomic_unchecked_t allocmiss;
64406 + atomic_unchecked_t freehit;
64407 + atomic_unchecked_t freemiss;
64408
64409 /*
64410 * If debugging is enabled, then the allocator can add additional
64411 @@ -105,11 +105,16 @@ struct cache_sizes {
64412 #ifdef CONFIG_ZONE_DMA
64413 struct kmem_cache *cs_dmacachep;
64414 #endif
64415 +
64416 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64417 + struct kmem_cache *cs_usercopycachep;
64418 +#endif
64419 +
64420 };
64421 extern struct cache_sizes malloc_sizes[];
64422
64423 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64424 -void *__kmalloc(size_t size, gfp_t flags);
64425 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64426
64427 #ifdef CONFIG_TRACING
64428 extern void *kmem_cache_alloc_trace(size_t size,
64429 @@ -152,6 +157,13 @@ found:
64430 cachep = malloc_sizes[i].cs_dmacachep;
64431 else
64432 #endif
64433 +
64434 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64435 + if (flags & GFP_USERCOPY)
64436 + cachep = malloc_sizes[i].cs_usercopycachep;
64437 + else
64438 +#endif
64439 +
64440 cachep = malloc_sizes[i].cs_cachep;
64441
64442 ret = kmem_cache_alloc_trace(size, cachep, flags);
64443 @@ -162,7 +174,7 @@ found:
64444 }
64445
64446 #ifdef CONFIG_NUMA
64447 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64448 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64449 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64450
64451 #ifdef CONFIG_TRACING
64452 @@ -205,6 +217,13 @@ found:
64453 cachep = malloc_sizes[i].cs_dmacachep;
64454 else
64455 #endif
64456 +
64457 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64458 + if (flags & GFP_USERCOPY)
64459 + cachep = malloc_sizes[i].cs_usercopycachep;
64460 + else
64461 +#endif
64462 +
64463 cachep = malloc_sizes[i].cs_cachep;
64464
64465 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64466 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64467 index 0ec00b3..22b4715 100644
64468 --- a/include/linux/slob_def.h
64469 +++ b/include/linux/slob_def.h
64470 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64471 return kmem_cache_alloc_node(cachep, flags, -1);
64472 }
64473
64474 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64475 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64476
64477 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64478 {
64479 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64480 return __kmalloc_node(size, flags, -1);
64481 }
64482
64483 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64484 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64485 {
64486 return kmalloc(size, flags);
64487 }
64488 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64489 index df448ad..b99e7f6 100644
64490 --- a/include/linux/slub_def.h
64491 +++ b/include/linux/slub_def.h
64492 @@ -91,7 +91,7 @@ struct kmem_cache {
64493 struct kmem_cache_order_objects max;
64494 struct kmem_cache_order_objects min;
64495 gfp_t allocflags; /* gfp flags to use on each alloc */
64496 - int refcount; /* Refcount for slab cache destroy */
64497 + atomic_t refcount; /* Refcount for slab cache destroy */
64498 void (*ctor)(void *);
64499 int inuse; /* Offset to metadata */
64500 int align; /* Alignment */
64501 @@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64502 * Sorry that the following has to be that ugly but some versions of GCC
64503 * have trouble with constant propagation and loops.
64504 */
64505 -static __always_inline int kmalloc_index(size_t size)
64506 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64507 {
64508 if (!size)
64509 return 0;
64510 @@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64511 }
64512
64513 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64514 -void *__kmalloc(size_t size, gfp_t flags);
64515 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64516
64517 static __always_inline void *
64518 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64519 @@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64520 }
64521 #endif
64522
64523 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64524 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64525 {
64526 unsigned int order = get_order(size);
64527 return kmalloc_order_trace(size, flags, order);
64528 @@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64529 }
64530
64531 #ifdef CONFIG_NUMA
64532 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64533 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64534 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64535
64536 #ifdef CONFIG_TRACING
64537 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64538 index de8832d..0147b46 100644
64539 --- a/include/linux/sonet.h
64540 +++ b/include/linux/sonet.h
64541 @@ -61,7 +61,7 @@ struct sonet_stats {
64542 #include <linux/atomic.h>
64543
64544 struct k_sonet_stats {
64545 -#define __HANDLE_ITEM(i) atomic_t i
64546 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64547 __SONET_ITEMS
64548 #undef __HANDLE_ITEM
64549 };
64550 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64551 index 523547e..2cb7140 100644
64552 --- a/include/linux/sunrpc/clnt.h
64553 +++ b/include/linux/sunrpc/clnt.h
64554 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64555 {
64556 switch (sap->sa_family) {
64557 case AF_INET:
64558 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64559 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64560 case AF_INET6:
64561 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64562 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64563 }
64564 return 0;
64565 }
64566 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64567 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64568 const struct sockaddr *src)
64569 {
64570 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64571 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64572 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64573
64574 dsin->sin_family = ssin->sin_family;
64575 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64576 if (sa->sa_family != AF_INET6)
64577 return 0;
64578
64579 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64580 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64581 }
64582
64583 #endif /* __KERNEL__ */
64584 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64585 index dc0c3cc..8503fb6 100644
64586 --- a/include/linux/sunrpc/sched.h
64587 +++ b/include/linux/sunrpc/sched.h
64588 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64589 void (*rpc_count_stats)(struct rpc_task *, void *);
64590 void (*rpc_release)(void *);
64591 };
64592 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64593
64594 struct rpc_task_setup {
64595 struct rpc_task *task;
64596 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64597 index 0b8e3e6..33e0a01 100644
64598 --- a/include/linux/sunrpc/svc_rdma.h
64599 +++ b/include/linux/sunrpc/svc_rdma.h
64600 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64601 extern unsigned int svcrdma_max_requests;
64602 extern unsigned int svcrdma_max_req_size;
64603
64604 -extern atomic_t rdma_stat_recv;
64605 -extern atomic_t rdma_stat_read;
64606 -extern atomic_t rdma_stat_write;
64607 -extern atomic_t rdma_stat_sq_starve;
64608 -extern atomic_t rdma_stat_rq_starve;
64609 -extern atomic_t rdma_stat_rq_poll;
64610 -extern atomic_t rdma_stat_rq_prod;
64611 -extern atomic_t rdma_stat_sq_poll;
64612 -extern atomic_t rdma_stat_sq_prod;
64613 +extern atomic_unchecked_t rdma_stat_recv;
64614 +extern atomic_unchecked_t rdma_stat_read;
64615 +extern atomic_unchecked_t rdma_stat_write;
64616 +extern atomic_unchecked_t rdma_stat_sq_starve;
64617 +extern atomic_unchecked_t rdma_stat_rq_starve;
64618 +extern atomic_unchecked_t rdma_stat_rq_poll;
64619 +extern atomic_unchecked_t rdma_stat_rq_prod;
64620 +extern atomic_unchecked_t rdma_stat_sq_poll;
64621 +extern atomic_unchecked_t rdma_stat_sq_prod;
64622
64623 #define RPCRDMA_VERSION 1
64624
64625 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64626 index c34b4c8..a65b67d 100644
64627 --- a/include/linux/sysctl.h
64628 +++ b/include/linux/sysctl.h
64629 @@ -155,7 +155,11 @@ enum
64630 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64631 };
64632
64633 -
64634 +#ifdef CONFIG_PAX_SOFTMODE
64635 +enum {
64636 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64637 +};
64638 +#endif
64639
64640 /* CTL_VM names: */
64641 enum
64642 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64643
64644 extern int proc_dostring(struct ctl_table *, int,
64645 void __user *, size_t *, loff_t *);
64646 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64647 + void __user *, size_t *, loff_t *);
64648 extern int proc_dointvec(struct ctl_table *, int,
64649 void __user *, size_t *, loff_t *);
64650 extern int proc_dointvec_minmax(struct ctl_table *, int,
64651 diff --git a/include/linux/tty.h b/include/linux/tty.h
64652 index 9f47ab5..73da944 100644
64653 --- a/include/linux/tty.h
64654 +++ b/include/linux/tty.h
64655 @@ -225,7 +225,7 @@ struct tty_port {
64656 const struct tty_port_operations *ops; /* Port operations */
64657 spinlock_t lock; /* Lock protecting tty field */
64658 int blocked_open; /* Waiting to open */
64659 - int count; /* Usage count */
64660 + atomic_t count; /* Usage count */
64661 wait_queue_head_t open_wait; /* Open waiters */
64662 wait_queue_head_t close_wait; /* Close waiters */
64663 wait_queue_head_t delta_msr_wait; /* Modem status change */
64664 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64665 struct tty_struct *tty, struct file *filp);
64666 static inline int tty_port_users(struct tty_port *port)
64667 {
64668 - return port->count + port->blocked_open;
64669 + return atomic_read(&port->count) + port->blocked_open;
64670 }
64671
64672 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64673 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64674 index fb79dd8d..07d4773 100644
64675 --- a/include/linux/tty_ldisc.h
64676 +++ b/include/linux/tty_ldisc.h
64677 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64678
64679 struct module *owner;
64680
64681 - int refcount;
64682 + atomic_t refcount;
64683 };
64684
64685 struct tty_ldisc {
64686 diff --git a/include/linux/types.h b/include/linux/types.h
64687 index bf0dd75..a1f23aaa 100644
64688 --- a/include/linux/types.h
64689 +++ b/include/linux/types.h
64690 @@ -220,10 +220,26 @@ typedef struct {
64691 int counter;
64692 } atomic_t;
64693
64694 +#ifdef CONFIG_PAX_REFCOUNT
64695 +typedef struct {
64696 + int counter;
64697 +} atomic_unchecked_t;
64698 +#else
64699 +typedef atomic_t atomic_unchecked_t;
64700 +#endif
64701 +
64702 #ifdef CONFIG_64BIT
64703 typedef struct {
64704 long counter;
64705 } atomic64_t;
64706 +
64707 +#ifdef CONFIG_PAX_REFCOUNT
64708 +typedef struct {
64709 + long counter;
64710 +} atomic64_unchecked_t;
64711 +#else
64712 +typedef atomic64_t atomic64_unchecked_t;
64713 +#endif
64714 #endif
64715
64716 struct list_head {
64717 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64718 index 5ca0951..ab496a5 100644
64719 --- a/include/linux/uaccess.h
64720 +++ b/include/linux/uaccess.h
64721 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64722 long ret; \
64723 mm_segment_t old_fs = get_fs(); \
64724 \
64725 - set_fs(KERNEL_DS); \
64726 pagefault_disable(); \
64727 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64728 - pagefault_enable(); \
64729 + set_fs(KERNEL_DS); \
64730 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64731 set_fs(old_fs); \
64732 + pagefault_enable(); \
64733 ret; \
64734 })
64735
64736 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64737 index 99c1b4d..bb94261 100644
64738 --- a/include/linux/unaligned/access_ok.h
64739 +++ b/include/linux/unaligned/access_ok.h
64740 @@ -6,32 +6,32 @@
64741
64742 static inline u16 get_unaligned_le16(const void *p)
64743 {
64744 - return le16_to_cpup((__le16 *)p);
64745 + return le16_to_cpup((const __le16 *)p);
64746 }
64747
64748 static inline u32 get_unaligned_le32(const void *p)
64749 {
64750 - return le32_to_cpup((__le32 *)p);
64751 + return le32_to_cpup((const __le32 *)p);
64752 }
64753
64754 static inline u64 get_unaligned_le64(const void *p)
64755 {
64756 - return le64_to_cpup((__le64 *)p);
64757 + return le64_to_cpup((const __le64 *)p);
64758 }
64759
64760 static inline u16 get_unaligned_be16(const void *p)
64761 {
64762 - return be16_to_cpup((__be16 *)p);
64763 + return be16_to_cpup((const __be16 *)p);
64764 }
64765
64766 static inline u32 get_unaligned_be32(const void *p)
64767 {
64768 - return be32_to_cpup((__be32 *)p);
64769 + return be32_to_cpup((const __be32 *)p);
64770 }
64771
64772 static inline u64 get_unaligned_be64(const void *p)
64773 {
64774 - return be64_to_cpup((__be64 *)p);
64775 + return be64_to_cpup((const __be64 *)p);
64776 }
64777
64778 static inline void put_unaligned_le16(u16 val, void *p)
64779 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64780 index c5d36c6..8478c90 100644
64781 --- a/include/linux/usb/renesas_usbhs.h
64782 +++ b/include/linux/usb/renesas_usbhs.h
64783 @@ -39,7 +39,7 @@ enum {
64784 */
64785 struct renesas_usbhs_driver_callback {
64786 int (*notify_hotplug)(struct platform_device *pdev);
64787 -};
64788 +} __no_const;
64789
64790 /*
64791 * callback functions for platform
64792 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64793 * VBUS control is needed for Host
64794 */
64795 int (*set_vbus)(struct platform_device *pdev, int enable);
64796 -};
64797 +} __no_const;
64798
64799 /*
64800 * parameters for renesas usbhs
64801 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64802 index 6f8fbcf..8259001 100644
64803 --- a/include/linux/vermagic.h
64804 +++ b/include/linux/vermagic.h
64805 @@ -25,9 +25,35 @@
64806 #define MODULE_ARCH_VERMAGIC ""
64807 #endif
64808
64809 +#ifdef CONFIG_PAX_REFCOUNT
64810 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64811 +#else
64812 +#define MODULE_PAX_REFCOUNT ""
64813 +#endif
64814 +
64815 +#ifdef CONSTIFY_PLUGIN
64816 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64817 +#else
64818 +#define MODULE_CONSTIFY_PLUGIN ""
64819 +#endif
64820 +
64821 +#ifdef STACKLEAK_PLUGIN
64822 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64823 +#else
64824 +#define MODULE_STACKLEAK_PLUGIN ""
64825 +#endif
64826 +
64827 +#ifdef CONFIG_GRKERNSEC
64828 +#define MODULE_GRSEC "GRSEC "
64829 +#else
64830 +#define MODULE_GRSEC ""
64831 +#endif
64832 +
64833 #define VERMAGIC_STRING \
64834 UTS_RELEASE " " \
64835 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64836 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64837 - MODULE_ARCH_VERMAGIC
64838 + MODULE_ARCH_VERMAGIC \
64839 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64840 + MODULE_GRSEC
64841
64842 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
64843 index 6071e91..ca6a489 100644
64844 --- a/include/linux/vmalloc.h
64845 +++ b/include/linux/vmalloc.h
64846 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
64847 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
64848 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
64849 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
64850 +
64851 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
64852 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
64853 +#endif
64854 +
64855 /* bits [20..32] reserved for arch specific ioremap internals */
64856
64857 /*
64858 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
64859 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
64860 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
64861 unsigned long start, unsigned long end, gfp_t gfp_mask,
64862 - pgprot_t prot, int node, const void *caller);
64863 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
64864 extern void vfree(const void *addr);
64865
64866 extern void *vmap(struct page **pages, unsigned int count,
64867 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
64868 extern void free_vm_area(struct vm_struct *area);
64869
64870 /* for /dev/kmem */
64871 -extern long vread(char *buf, char *addr, unsigned long count);
64872 -extern long vwrite(char *buf, char *addr, unsigned long count);
64873 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
64874 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
64875
64876 /*
64877 * Internals. Dont't use..
64878 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
64879 index ad2cfd5..74c94ad 100644
64880 --- a/include/linux/vmstat.h
64881 +++ b/include/linux/vmstat.h
64882 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
64883 /*
64884 * Zone based page accounting with per cpu differentials.
64885 */
64886 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64887 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
64888
64889 static inline void zone_page_state_add(long x, struct zone *zone,
64890 enum zone_stat_item item)
64891 {
64892 - atomic_long_add(x, &zone->vm_stat[item]);
64893 - atomic_long_add(x, &vm_stat[item]);
64894 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
64895 + atomic_long_add_unchecked(x, &vm_stat[item]);
64896 }
64897
64898 static inline unsigned long global_page_state(enum zone_stat_item item)
64899 {
64900 - long x = atomic_long_read(&vm_stat[item]);
64901 + long x = atomic_long_read_unchecked(&vm_stat[item]);
64902 #ifdef CONFIG_SMP
64903 if (x < 0)
64904 x = 0;
64905 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
64906 static inline unsigned long zone_page_state(struct zone *zone,
64907 enum zone_stat_item item)
64908 {
64909 - long x = atomic_long_read(&zone->vm_stat[item]);
64910 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64911 #ifdef CONFIG_SMP
64912 if (x < 0)
64913 x = 0;
64914 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
64915 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
64916 enum zone_stat_item item)
64917 {
64918 - long x = atomic_long_read(&zone->vm_stat[item]);
64919 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
64920
64921 #ifdef CONFIG_SMP
64922 int cpu;
64923 @@ -216,8 +216,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
64924
64925 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
64926 {
64927 - atomic_long_inc(&zone->vm_stat[item]);
64928 - atomic_long_inc(&vm_stat[item]);
64929 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
64930 + atomic_long_inc_unchecked(&vm_stat[item]);
64931 }
64932
64933 static inline void __inc_zone_page_state(struct page *page,
64934 @@ -228,8 +228,8 @@ static inline void __inc_zone_page_state(struct page *page,
64935
64936 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
64937 {
64938 - atomic_long_dec(&zone->vm_stat[item]);
64939 - atomic_long_dec(&vm_stat[item]);
64940 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
64941 + atomic_long_dec_unchecked(&vm_stat[item]);
64942 }
64943
64944 static inline void __dec_zone_page_state(struct page *page,
64945 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
64946 index e5d1220..ef6e406 100644
64947 --- a/include/linux/xattr.h
64948 +++ b/include/linux/xattr.h
64949 @@ -57,6 +57,11 @@
64950 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
64951 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
64952
64953 +/* User namespace */
64954 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
64955 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
64956 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
64957 +
64958 #ifdef __KERNEL__
64959
64960 #include <linux/types.h>
64961 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
64962 index 944ecdf..a3994fc 100644
64963 --- a/include/media/saa7146_vv.h
64964 +++ b/include/media/saa7146_vv.h
64965 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
64966 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
64967
64968 /* the extension can override this */
64969 - struct v4l2_ioctl_ops vid_ops;
64970 - struct v4l2_ioctl_ops vbi_ops;
64971 + v4l2_ioctl_ops_no_const vid_ops;
64972 + v4l2_ioctl_ops_no_const vbi_ops;
64973 /* pointer to the saa7146 core ops */
64974 const struct v4l2_ioctl_ops *core_ops;
64975
64976 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
64977 index 5c416cd..20021aa 100644
64978 --- a/include/media/v4l2-dev.h
64979 +++ b/include/media/v4l2-dev.h
64980 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
64981 int (*mmap) (struct file *, struct vm_area_struct *);
64982 int (*open) (struct file *);
64983 int (*release) (struct file *);
64984 -};
64985 +} __do_const;
64986 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
64987
64988 /*
64989 * Newer version of video_device, handled by videodev2.c
64990 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
64991 index e614c9c..20602b7 100644
64992 --- a/include/media/v4l2-ioctl.h
64993 +++ b/include/media/v4l2-ioctl.h
64994 @@ -289,7 +289,7 @@ struct v4l2_ioctl_ops {
64995 long (*vidioc_default) (struct file *file, void *fh,
64996 bool valid_prio, int cmd, void *arg);
64997 };
64998 -
64999 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65000
65001 /* v4l debugging and diagnostics */
65002
65003 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65004 index bcb9cc3..f4ec722e 100644
65005 --- a/include/net/caif/caif_hsi.h
65006 +++ b/include/net/caif/caif_hsi.h
65007 @@ -98,7 +98,7 @@ struct cfhsi_cb_ops {
65008 void (*rx_done_cb) (struct cfhsi_cb_ops *drv);
65009 void (*wake_up_cb) (struct cfhsi_cb_ops *drv);
65010 void (*wake_down_cb) (struct cfhsi_cb_ops *drv);
65011 -};
65012 +} __no_const;
65013
65014 /* Structure implemented by HSI device. */
65015 struct cfhsi_ops {
65016 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65017 index 9e5425b..8136ffc 100644
65018 --- a/include/net/caif/cfctrl.h
65019 +++ b/include/net/caif/cfctrl.h
65020 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65021 void (*radioset_rsp)(void);
65022 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65023 struct cflayer *client_layer);
65024 -};
65025 +} __no_const;
65026
65027 /* Link Setup Parameters for CAIF-Links. */
65028 struct cfctrl_link_param {
65029 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65030 struct cfctrl {
65031 struct cfsrvl serv;
65032 struct cfctrl_rsp res;
65033 - atomic_t req_seq_no;
65034 - atomic_t rsp_seq_no;
65035 + atomic_unchecked_t req_seq_no;
65036 + atomic_unchecked_t rsp_seq_no;
65037 struct list_head list;
65038 /* Protects from simultaneous access to first_req list */
65039 spinlock_t info_list_lock;
65040 diff --git a/include/net/flow.h b/include/net/flow.h
65041 index e1dd508..2873851 100644
65042 --- a/include/net/flow.h
65043 +++ b/include/net/flow.h
65044 @@ -220,6 +220,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65045
65046 extern void flow_cache_flush(void);
65047 extern void flow_cache_flush_deferred(void);
65048 -extern atomic_t flow_cache_genid;
65049 +extern atomic_unchecked_t flow_cache_genid;
65050
65051 #endif
65052 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65053 index 53f464d..ba76aaa 100644
65054 --- a/include/net/inetpeer.h
65055 +++ b/include/net/inetpeer.h
65056 @@ -47,8 +47,8 @@ struct inet_peer {
65057 */
65058 union {
65059 struct {
65060 - atomic_t rid; /* Frag reception counter */
65061 - atomic_t ip_id_count; /* IP ID for the next packet */
65062 + atomic_unchecked_t rid; /* Frag reception counter */
65063 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65064 };
65065 struct rcu_head rcu;
65066 struct inet_peer *gc_next;
65067 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65068 more++;
65069 inet_peer_refcheck(p);
65070 do {
65071 - old = atomic_read(&p->ip_id_count);
65072 + old = atomic_read_unchecked(&p->ip_id_count);
65073 new = old + more;
65074 if (!new)
65075 new = 1;
65076 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65077 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65078 return new;
65079 }
65080
65081 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65082 index 9497be1..5a4fafe 100644
65083 --- a/include/net/ip_fib.h
65084 +++ b/include/net/ip_fib.h
65085 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65086
65087 #define FIB_RES_SADDR(net, res) \
65088 ((FIB_RES_NH(res).nh_saddr_genid == \
65089 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65090 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65091 FIB_RES_NH(res).nh_saddr : \
65092 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65093 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65094 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65095 index 95374d1..2300e36 100644
65096 --- a/include/net/ip_vs.h
65097 +++ b/include/net/ip_vs.h
65098 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65099 struct ip_vs_conn *control; /* Master control connection */
65100 atomic_t n_control; /* Number of controlled ones */
65101 struct ip_vs_dest *dest; /* real server */
65102 - atomic_t in_pkts; /* incoming packet counter */
65103 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65104
65105 /* packet transmitter for different forwarding methods. If it
65106 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65107 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65108 __be16 port; /* port number of the server */
65109 union nf_inet_addr addr; /* IP address of the server */
65110 volatile unsigned int flags; /* dest status flags */
65111 - atomic_t conn_flags; /* flags to copy to conn */
65112 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65113 atomic_t weight; /* server weight */
65114
65115 atomic_t refcnt; /* reference counter */
65116 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65117 index 69b610a..fe3962c 100644
65118 --- a/include/net/irda/ircomm_core.h
65119 +++ b/include/net/irda/ircomm_core.h
65120 @@ -51,7 +51,7 @@ typedef struct {
65121 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65122 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65123 struct ircomm_info *);
65124 -} call_t;
65125 +} __no_const call_t;
65126
65127 struct ircomm_cb {
65128 irda_queue_t queue;
65129 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65130 index 59ba38bc..d515662 100644
65131 --- a/include/net/irda/ircomm_tty.h
65132 +++ b/include/net/irda/ircomm_tty.h
65133 @@ -35,6 +35,7 @@
65134 #include <linux/termios.h>
65135 #include <linux/timer.h>
65136 #include <linux/tty.h> /* struct tty_struct */
65137 +#include <asm/local.h>
65138
65139 #include <net/irda/irias_object.h>
65140 #include <net/irda/ircomm_core.h>
65141 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65142 unsigned short close_delay;
65143 unsigned short closing_wait; /* time to wait before closing */
65144
65145 - int open_count;
65146 - int blocked_open; /* # of blocked opens */
65147 + local_t open_count;
65148 + local_t blocked_open; /* # of blocked opens */
65149
65150 /* Protect concurent access to :
65151 * o self->open_count
65152 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65153 index cc7c197..9f2da2a 100644
65154 --- a/include/net/iucv/af_iucv.h
65155 +++ b/include/net/iucv/af_iucv.h
65156 @@ -141,7 +141,7 @@ struct iucv_sock {
65157 struct iucv_sock_list {
65158 struct hlist_head head;
65159 rwlock_t lock;
65160 - atomic_t autobind_name;
65161 + atomic_unchecked_t autobind_name;
65162 };
65163
65164 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65165 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65166 index 344d898..2ae1302 100644
65167 --- a/include/net/neighbour.h
65168 +++ b/include/net/neighbour.h
65169 @@ -123,7 +123,7 @@ struct neigh_ops {
65170 void (*error_report)(struct neighbour *, struct sk_buff *);
65171 int (*output)(struct neighbour *, struct sk_buff *);
65172 int (*connected_output)(struct neighbour *, struct sk_buff *);
65173 -};
65174 +} __do_const;
65175
65176 struct pneigh_entry {
65177 struct pneigh_entry *next;
65178 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
65179 index fd87963..312a11f 100644
65180 --- a/include/net/net_namespace.h
65181 +++ b/include/net/net_namespace.h
65182 @@ -102,7 +102,7 @@ struct net {
65183 #endif
65184 struct netns_ipvs *ipvs;
65185 struct sock *diag_nlsk;
65186 - atomic_t rt_genid;
65187 + atomic_unchecked_t rt_genid;
65188 };
65189
65190
65191 @@ -303,12 +303,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
65192
65193 static inline int rt_genid(struct net *net)
65194 {
65195 - return atomic_read(&net->rt_genid);
65196 + return atomic_read_unchecked(&net->rt_genid);
65197 }
65198
65199 static inline void rt_genid_bump(struct net *net)
65200 {
65201 - atomic_inc(&net->rt_genid);
65202 + atomic_inc_unchecked(&net->rt_genid);
65203 }
65204
65205 #endif /* __NET_NET_NAMESPACE_H */
65206 diff --git a/include/net/netdma.h b/include/net/netdma.h
65207 index 8ba8ce2..99b7fff 100644
65208 --- a/include/net/netdma.h
65209 +++ b/include/net/netdma.h
65210 @@ -24,7 +24,7 @@
65211 #include <linux/dmaengine.h>
65212 #include <linux/skbuff.h>
65213
65214 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65215 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65216 struct sk_buff *skb, int offset, struct iovec *to,
65217 size_t len, struct dma_pinned_list *pinned_list);
65218
65219 diff --git a/include/net/netlink.h b/include/net/netlink.h
65220 index 785f37a..c81dc0c 100644
65221 --- a/include/net/netlink.h
65222 +++ b/include/net/netlink.h
65223 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65224 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65225 {
65226 if (mark)
65227 - skb_trim(skb, (unsigned char *) mark - skb->data);
65228 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65229 }
65230
65231 /**
65232 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65233 index eb24dbc..567d6ed 100644
65234 --- a/include/net/netns/ipv4.h
65235 +++ b/include/net/netns/ipv4.h
65236 @@ -65,7 +65,7 @@ struct netns_ipv4 {
65237 unsigned int sysctl_ping_group_range[2];
65238 long sysctl_tcp_mem[3];
65239
65240 - atomic_t dev_addr_genid;
65241 + atomic_unchecked_t dev_addr_genid;
65242
65243 #ifdef CONFIG_IP_MROUTE
65244 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65245 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65246 index ff49964..1411fee 100644
65247 --- a/include/net/sctp/sctp.h
65248 +++ b/include/net/sctp/sctp.h
65249 @@ -320,9 +320,9 @@ do { \
65250
65251 #else /* SCTP_DEBUG */
65252
65253 -#define SCTP_DEBUG_PRINTK(whatever...)
65254 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65255 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65256 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65257 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65258 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65259 #define SCTP_ENABLE_DEBUG
65260 #define SCTP_DISABLE_DEBUG
65261 #define SCTP_ASSERT(expr, str, func)
65262 diff --git a/include/net/sock.h b/include/net/sock.h
65263 index adb7da2..1100002 100644
65264 --- a/include/net/sock.h
65265 +++ b/include/net/sock.h
65266 @@ -305,7 +305,7 @@ struct sock {
65267 #ifdef CONFIG_RPS
65268 __u32 sk_rxhash;
65269 #endif
65270 - atomic_t sk_drops;
65271 + atomic_unchecked_t sk_drops;
65272 int sk_rcvbuf;
65273
65274 struct sk_filter __rcu *sk_filter;
65275 @@ -1764,7 +1764,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65276 }
65277
65278 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65279 - char __user *from, char *to,
65280 + char __user *from, unsigned char *to,
65281 int copy, int offset)
65282 {
65283 if (skb->ip_summed == CHECKSUM_NONE) {
65284 @@ -2023,7 +2023,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65285 }
65286 }
65287
65288 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65289 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65290
65291 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65292 {
65293 diff --git a/include/net/tcp.h b/include/net/tcp.h
65294 index 1f000ff..e5a8dfb 100644
65295 --- a/include/net/tcp.h
65296 +++ b/include/net/tcp.h
65297 @@ -508,7 +508,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65298 extern void tcp_xmit_retransmit_queue(struct sock *);
65299 extern void tcp_simple_retransmit(struct sock *);
65300 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65301 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65302 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65303
65304 extern void tcp_send_probe0(struct sock *);
65305 extern void tcp_send_partial(struct sock *);
65306 @@ -677,8 +677,8 @@ struct tcp_skb_cb {
65307 struct inet6_skb_parm h6;
65308 #endif
65309 } header; /* For incoming frames */
65310 - __u32 seq; /* Starting sequence number */
65311 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65312 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65313 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65314 __u32 when; /* used to compute rtt's */
65315 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65316
65317 @@ -692,7 +692,7 @@ struct tcp_skb_cb {
65318
65319 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65320 /* 1 byte hole */
65321 - __u32 ack_seq; /* Sequence number ACK'd */
65322 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65323 };
65324
65325 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65326 @@ -1502,7 +1502,7 @@ struct tcp_seq_afinfo {
65327 char *name;
65328 sa_family_t family;
65329 const struct file_operations *seq_fops;
65330 - struct seq_operations seq_ops;
65331 + seq_operations_no_const seq_ops;
65332 };
65333
65334 struct tcp_iter_state {
65335 diff --git a/include/net/udp.h b/include/net/udp.h
65336 index 065f379..b661b40 100644
65337 --- a/include/net/udp.h
65338 +++ b/include/net/udp.h
65339 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65340 sa_family_t family;
65341 struct udp_table *udp_table;
65342 const struct file_operations *seq_fops;
65343 - struct seq_operations seq_ops;
65344 + seq_operations_no_const seq_ops;
65345 };
65346
65347 struct udp_iter_state {
65348 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65349 index 639dd13..15b206c 100644
65350 --- a/include/net/xfrm.h
65351 +++ b/include/net/xfrm.h
65352 @@ -514,7 +514,7 @@ struct xfrm_policy {
65353 struct timer_list timer;
65354
65355 struct flow_cache_object flo;
65356 - atomic_t genid;
65357 + atomic_unchecked_t genid;
65358 u32 priority;
65359 u32 index;
65360 struct xfrm_mark mark;
65361 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65362 index 1a046b1..ee0bef0 100644
65363 --- a/include/rdma/iw_cm.h
65364 +++ b/include/rdma/iw_cm.h
65365 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65366 int backlog);
65367
65368 int (*destroy_listen)(struct iw_cm_id *cm_id);
65369 -};
65370 +} __no_const;
65371
65372 /**
65373 * iw_create_cm_id - Create an IW CM identifier.
65374 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65375 index 399162b..b337f1a 100644
65376 --- a/include/scsi/libfc.h
65377 +++ b/include/scsi/libfc.h
65378 @@ -762,6 +762,7 @@ struct libfc_function_template {
65379 */
65380 void (*disc_stop_final) (struct fc_lport *);
65381 };
65382 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65383
65384 /**
65385 * struct fc_disc - Discovery context
65386 @@ -866,7 +867,7 @@ struct fc_lport {
65387 struct fc_vport *vport;
65388
65389 /* Operational Information */
65390 - struct libfc_function_template tt;
65391 + libfc_function_template_no_const tt;
65392 u8 link_up;
65393 u8 qfull;
65394 enum fc_lport_state state;
65395 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65396 index 9895f69..f1418f0 100644
65397 --- a/include/scsi/scsi_device.h
65398 +++ b/include/scsi/scsi_device.h
65399 @@ -166,9 +166,9 @@ struct scsi_device {
65400 unsigned int max_device_blocked; /* what device_blocked counts down from */
65401 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65402
65403 - atomic_t iorequest_cnt;
65404 - atomic_t iodone_cnt;
65405 - atomic_t ioerr_cnt;
65406 + atomic_unchecked_t iorequest_cnt;
65407 + atomic_unchecked_t iodone_cnt;
65408 + atomic_unchecked_t ioerr_cnt;
65409
65410 struct device sdev_gendev,
65411 sdev_dev;
65412 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65413 index b797e8f..8e2c3aa 100644
65414 --- a/include/scsi/scsi_transport_fc.h
65415 +++ b/include/scsi/scsi_transport_fc.h
65416 @@ -751,7 +751,8 @@ struct fc_function_template {
65417 unsigned long show_host_system_hostname:1;
65418
65419 unsigned long disable_target_scan:1;
65420 -};
65421 +} __do_const;
65422 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65423
65424
65425 /**
65426 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65427 index 030b87c..98a6954 100644
65428 --- a/include/sound/ak4xxx-adda.h
65429 +++ b/include/sound/ak4xxx-adda.h
65430 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65431 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65432 unsigned char val);
65433 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65434 -};
65435 +} __no_const;
65436
65437 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65438
65439 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65440 index 8c05e47..2b5df97 100644
65441 --- a/include/sound/hwdep.h
65442 +++ b/include/sound/hwdep.h
65443 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65444 struct snd_hwdep_dsp_status *status);
65445 int (*dsp_load)(struct snd_hwdep *hw,
65446 struct snd_hwdep_dsp_image *image);
65447 -};
65448 +} __no_const;
65449
65450 struct snd_hwdep {
65451 struct snd_card *card;
65452 diff --git a/include/sound/info.h b/include/sound/info.h
65453 index 9ca1a49..aba1728 100644
65454 --- a/include/sound/info.h
65455 +++ b/include/sound/info.h
65456 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65457 struct snd_info_buffer *buffer);
65458 void (*write)(struct snd_info_entry *entry,
65459 struct snd_info_buffer *buffer);
65460 -};
65461 +} __no_const;
65462
65463 struct snd_info_entry_ops {
65464 int (*open)(struct snd_info_entry *entry,
65465 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65466 index cdca2ab..10bbe05 100644
65467 --- a/include/sound/pcm.h
65468 +++ b/include/sound/pcm.h
65469 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65470 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65471 int (*ack)(struct snd_pcm_substream *substream);
65472 };
65473 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65474
65475 /*
65476 *
65477 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65478 index af1b49e..a5d55a5 100644
65479 --- a/include/sound/sb16_csp.h
65480 +++ b/include/sound/sb16_csp.h
65481 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65482 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65483 int (*csp_stop) (struct snd_sb_csp * p);
65484 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65485 -};
65486 +} __no_const;
65487
65488 /*
65489 * CSP private data
65490 diff --git a/include/sound/soc.h b/include/sound/soc.h
65491 index e063380..e8077d5 100644
65492 --- a/include/sound/soc.h
65493 +++ b/include/sound/soc.h
65494 @@ -801,7 +801,7 @@ struct snd_soc_platform_driver {
65495 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65496 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65497 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65498 -};
65499 +} __do_const;
65500
65501 struct snd_soc_platform {
65502 const char *name;
65503 @@ -1016,7 +1016,7 @@ struct snd_soc_pcm_runtime {
65504 struct snd_soc_dai_link *dai_link;
65505 struct mutex pcm_mutex;
65506 enum snd_soc_pcm_subclass pcm_subclass;
65507 - struct snd_pcm_ops ops;
65508 + snd_pcm_ops_no_const ops;
65509
65510 unsigned int dev_registered:1;
65511
65512 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65513 index fe8590c..aaed363 100644
65514 --- a/include/sound/tea575x-tuner.h
65515 +++ b/include/sound/tea575x-tuner.h
65516 @@ -48,7 +48,7 @@ struct snd_tea575x_ops {
65517
65518 struct snd_tea575x {
65519 struct v4l2_device *v4l2_dev;
65520 - struct v4l2_file_operations fops;
65521 + v4l2_file_operations_no_const fops;
65522 struct video_device vd; /* video device */
65523 int radio_nr; /* radio_nr */
65524 bool tea5759; /* 5759 chip is present */
65525 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65526 index 5be8937..a8e46e9 100644
65527 --- a/include/target/target_core_base.h
65528 +++ b/include/target/target_core_base.h
65529 @@ -434,7 +434,7 @@ struct t10_reservation_ops {
65530 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65531 int (*t10_pr_register)(struct se_cmd *);
65532 int (*t10_pr_clear)(struct se_cmd *);
65533 -};
65534 +} __no_const;
65535
65536 struct t10_reservation {
65537 /* Reservation effects all target ports */
65538 @@ -758,7 +758,7 @@ struct se_device {
65539 spinlock_t stats_lock;
65540 /* Active commands on this virtual SE device */
65541 atomic_t simple_cmds;
65542 - atomic_t dev_ordered_id;
65543 + atomic_unchecked_t dev_ordered_id;
65544 atomic_t dev_ordered_sync;
65545 atomic_t dev_qf_count;
65546 struct se_obj dev_obj;
65547 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65548 new file mode 100644
65549 index 0000000..2efe49d
65550 --- /dev/null
65551 +++ b/include/trace/events/fs.h
65552 @@ -0,0 +1,53 @@
65553 +#undef TRACE_SYSTEM
65554 +#define TRACE_SYSTEM fs
65555 +
65556 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65557 +#define _TRACE_FS_H
65558 +
65559 +#include <linux/fs.h>
65560 +#include <linux/tracepoint.h>
65561 +
65562 +TRACE_EVENT(do_sys_open,
65563 +
65564 + TP_PROTO(char *filename, int flags, int mode),
65565 +
65566 + TP_ARGS(filename, flags, mode),
65567 +
65568 + TP_STRUCT__entry(
65569 + __string( filename, filename )
65570 + __field( int, flags )
65571 + __field( int, mode )
65572 + ),
65573 +
65574 + TP_fast_assign(
65575 + __assign_str(filename, filename);
65576 + __entry->flags = flags;
65577 + __entry->mode = mode;
65578 + ),
65579 +
65580 + TP_printk("\"%s\" %x %o",
65581 + __get_str(filename), __entry->flags, __entry->mode)
65582 +);
65583 +
65584 +TRACE_EVENT(open_exec,
65585 +
65586 + TP_PROTO(const char *filename),
65587 +
65588 + TP_ARGS(filename),
65589 +
65590 + TP_STRUCT__entry(
65591 + __string( filename, filename )
65592 + ),
65593 +
65594 + TP_fast_assign(
65595 + __assign_str(filename, filename);
65596 + ),
65597 +
65598 + TP_printk("\"%s\"",
65599 + __get_str(filename))
65600 +);
65601 +
65602 +#endif /* _TRACE_FS_H */
65603 +
65604 +/* This part must be outside protection */
65605 +#include <trace/define_trace.h>
65606 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65607 index 1c09820..7f5ec79 100644
65608 --- a/include/trace/events/irq.h
65609 +++ b/include/trace/events/irq.h
65610 @@ -36,7 +36,7 @@ struct softirq_action;
65611 */
65612 TRACE_EVENT(irq_handler_entry,
65613
65614 - TP_PROTO(int irq, struct irqaction *action),
65615 + TP_PROTO(int irq, const struct irqaction *action),
65616
65617 TP_ARGS(irq, action),
65618
65619 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65620 */
65621 TRACE_EVENT(irq_handler_exit,
65622
65623 - TP_PROTO(int irq, struct irqaction *action, int ret),
65624 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65625
65626 TP_ARGS(irq, action, ret),
65627
65628 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65629 index f9466fa..f4e2b81 100644
65630 --- a/include/video/udlfb.h
65631 +++ b/include/video/udlfb.h
65632 @@ -53,10 +53,10 @@ struct dlfb_data {
65633 u32 pseudo_palette[256];
65634 int blank_mode; /*one of FB_BLANK_ */
65635 /* blit-only rendering path metrics, exposed through sysfs */
65636 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65637 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65638 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65639 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65640 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65641 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65642 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65643 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65644 };
65645
65646 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65647 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65648 index 0993a22..32ba2fe 100644
65649 --- a/include/video/uvesafb.h
65650 +++ b/include/video/uvesafb.h
65651 @@ -177,6 +177,7 @@ struct uvesafb_par {
65652 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65653 u8 pmi_setpal; /* PMI for palette changes */
65654 u16 *pmi_base; /* protected mode interface location */
65655 + u8 *pmi_code; /* protected mode code location */
65656 void *pmi_start;
65657 void *pmi_pal;
65658 u8 *vbe_state_orig; /*
65659 diff --git a/init/Kconfig b/init/Kconfig
65660 index af6c7f8..5c188f8 100644
65661 --- a/init/Kconfig
65662 +++ b/init/Kconfig
65663 @@ -850,6 +850,7 @@ endif # CGROUPS
65664
65665 config CHECKPOINT_RESTORE
65666 bool "Checkpoint/restore support" if EXPERT
65667 + depends on !GRKERNSEC
65668 default n
65669 help
65670 Enables additional kernel features in a sake of checkpoint/restore.
65671 @@ -1029,6 +1030,7 @@ config UIDGID_CONVERTED
65672 # Security modules
65673 depends on SECURITY_TOMOYO = n
65674 depends on SECURITY_APPARMOR = n
65675 + depends on GRKERNSEC = n
65676
65677 config UIDGID_STRICT_TYPE_CHECKS
65678 bool "Require conversions between uid/gids and their internal representation"
65679 @@ -1416,7 +1418,7 @@ config SLUB_DEBUG
65680
65681 config COMPAT_BRK
65682 bool "Disable heap randomization"
65683 - default y
65684 + default n
65685 help
65686 Randomizing heap placement makes heap exploits harder, but it
65687 also breaks ancient binaries (including anything libc5 based).
65688 @@ -1599,7 +1601,7 @@ config INIT_ALL_POSSIBLE
65689 config STOP_MACHINE
65690 bool
65691 default y
65692 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65693 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65694 help
65695 Need stop_machine() primitive.
65696
65697 diff --git a/init/Makefile b/init/Makefile
65698 index 7bc47ee..6da2dc7 100644
65699 --- a/init/Makefile
65700 +++ b/init/Makefile
65701 @@ -2,6 +2,9 @@
65702 # Makefile for the linux kernel.
65703 #
65704
65705 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65706 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65707 +
65708 obj-y := main.o version.o mounts.o
65709 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65710 obj-y += noinitramfs.o
65711 diff --git a/init/do_mounts.c b/init/do_mounts.c
65712 index d3f0aee..c9322f5 100644
65713 --- a/init/do_mounts.c
65714 +++ b/init/do_mounts.c
65715 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65716 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65717 {
65718 struct super_block *s;
65719 - int err = sys_mount(name, "/root", fs, flags, data);
65720 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65721 if (err)
65722 return err;
65723
65724 - sys_chdir("/root");
65725 + sys_chdir((const char __force_user *)"/root");
65726 s = current->fs->pwd.dentry->d_sb;
65727 ROOT_DEV = s->s_dev;
65728 printk(KERN_INFO
65729 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65730 va_start(args, fmt);
65731 vsprintf(buf, fmt, args);
65732 va_end(args);
65733 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65734 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65735 if (fd >= 0) {
65736 sys_ioctl(fd, FDEJECT, 0);
65737 sys_close(fd);
65738 }
65739 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65740 - fd = sys_open("/dev/console", O_RDWR, 0);
65741 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65742 if (fd >= 0) {
65743 sys_ioctl(fd, TCGETS, (long)&termios);
65744 termios.c_lflag &= ~ICANON;
65745 sys_ioctl(fd, TCSETSF, (long)&termios);
65746 - sys_read(fd, &c, 1);
65747 + sys_read(fd, (char __user *)&c, 1);
65748 termios.c_lflag |= ICANON;
65749 sys_ioctl(fd, TCSETSF, (long)&termios);
65750 sys_close(fd);
65751 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65752 mount_root();
65753 out:
65754 devtmpfs_mount("dev");
65755 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65756 - sys_chroot(".");
65757 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65758 + sys_chroot((const char __force_user *)".");
65759 }
65760 diff --git a/init/do_mounts.h b/init/do_mounts.h
65761 index f5b978a..69dbfe8 100644
65762 --- a/init/do_mounts.h
65763 +++ b/init/do_mounts.h
65764 @@ -15,15 +15,15 @@ extern int root_mountflags;
65765
65766 static inline int create_dev(char *name, dev_t dev)
65767 {
65768 - sys_unlink(name);
65769 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65770 + sys_unlink((char __force_user *)name);
65771 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65772 }
65773
65774 #if BITS_PER_LONG == 32
65775 static inline u32 bstat(char *name)
65776 {
65777 struct stat64 stat;
65778 - if (sys_stat64(name, &stat) != 0)
65779 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65780 return 0;
65781 if (!S_ISBLK(stat.st_mode))
65782 return 0;
65783 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65784 static inline u32 bstat(char *name)
65785 {
65786 struct stat stat;
65787 - if (sys_newstat(name, &stat) != 0)
65788 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65789 return 0;
65790 if (!S_ISBLK(stat.st_mode))
65791 return 0;
65792 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65793 index 135959a2..28a3f43 100644
65794 --- a/init/do_mounts_initrd.c
65795 +++ b/init/do_mounts_initrd.c
65796 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65797 create_dev("/dev/root.old", Root_RAM0);
65798 /* mount initrd on rootfs' /root */
65799 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65800 - sys_mkdir("/old", 0700);
65801 - root_fd = sys_open("/", 0, 0);
65802 - old_fd = sys_open("/old", 0, 0);
65803 + sys_mkdir((const char __force_user *)"/old", 0700);
65804 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65805 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65806 /* move initrd over / and chdir/chroot in initrd root */
65807 - sys_chdir("/root");
65808 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65809 - sys_chroot(".");
65810 + sys_chdir((const char __force_user *)"/root");
65811 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65812 + sys_chroot((const char __force_user *)".");
65813
65814 /*
65815 * In case that a resume from disk is carried out by linuxrc or one of
65816 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65817
65818 /* move initrd to rootfs' /old */
65819 sys_fchdir(old_fd);
65820 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65821 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65822 /* switch root and cwd back to / of rootfs */
65823 sys_fchdir(root_fd);
65824 - sys_chroot(".");
65825 + sys_chroot((const char __force_user *)".");
65826 sys_close(old_fd);
65827 sys_close(root_fd);
65828
65829 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65830 - sys_chdir("/old");
65831 + sys_chdir((const char __force_user *)"/old");
65832 return;
65833 }
65834
65835 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65836 mount_root();
65837
65838 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65839 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65840 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
65841 if (!error)
65842 printk("okay\n");
65843 else {
65844 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
65845 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
65846 if (error == -ENOENT)
65847 printk("/initrd does not exist. Ignored.\n");
65848 else
65849 printk("failed\n");
65850 printk(KERN_NOTICE "Unmounting old root\n");
65851 - sys_umount("/old", MNT_DETACH);
65852 + sys_umount((char __force_user *)"/old", MNT_DETACH);
65853 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
65854 if (fd < 0) {
65855 error = fd;
65856 @@ -125,11 +125,11 @@ int __init initrd_load(void)
65857 * mounted in the normal path.
65858 */
65859 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
65860 - sys_unlink("/initrd.image");
65861 + sys_unlink((const char __force_user *)"/initrd.image");
65862 handle_initrd();
65863 return 1;
65864 }
65865 }
65866 - sys_unlink("/initrd.image");
65867 + sys_unlink((const char __force_user *)"/initrd.image");
65868 return 0;
65869 }
65870 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
65871 index 8cb6db5..d729f50 100644
65872 --- a/init/do_mounts_md.c
65873 +++ b/init/do_mounts_md.c
65874 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
65875 partitioned ? "_d" : "", minor,
65876 md_setup_args[ent].device_names);
65877
65878 - fd = sys_open(name, 0, 0);
65879 + fd = sys_open((char __force_user *)name, 0, 0);
65880 if (fd < 0) {
65881 printk(KERN_ERR "md: open failed - cannot start "
65882 "array %s\n", name);
65883 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
65884 * array without it
65885 */
65886 sys_close(fd);
65887 - fd = sys_open(name, 0, 0);
65888 + fd = sys_open((char __force_user *)name, 0, 0);
65889 sys_ioctl(fd, BLKRRPART, 0);
65890 }
65891 sys_close(fd);
65892 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
65893
65894 wait_for_device_probe();
65895
65896 - fd = sys_open("/dev/md0", 0, 0);
65897 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
65898 if (fd >= 0) {
65899 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
65900 sys_close(fd);
65901 diff --git a/init/init_task.c b/init/init_task.c
65902 index 8b2f399..f0797c9 100644
65903 --- a/init/init_task.c
65904 +++ b/init/init_task.c
65905 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
65906 * Initial thread structure. Alignment of this is handled by a special
65907 * linker map entry.
65908 */
65909 +#ifdef CONFIG_X86
65910 +union thread_union init_thread_union __init_task_data;
65911 +#else
65912 union thread_union init_thread_union __init_task_data =
65913 { INIT_THREAD_INFO(init_task) };
65914 +#endif
65915 diff --git a/init/initramfs.c b/init/initramfs.c
65916 index 84c6bf1..8899338 100644
65917 --- a/init/initramfs.c
65918 +++ b/init/initramfs.c
65919 @@ -84,7 +84,7 @@ static void __init free_hash(void)
65920 }
65921 }
65922
65923 -static long __init do_utime(char *filename, time_t mtime)
65924 +static long __init do_utime(char __force_user *filename, time_t mtime)
65925 {
65926 struct timespec t[2];
65927
65928 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
65929 struct dir_entry *de, *tmp;
65930 list_for_each_entry_safe(de, tmp, &dir_list, list) {
65931 list_del(&de->list);
65932 - do_utime(de->name, de->mtime);
65933 + do_utime((char __force_user *)de->name, de->mtime);
65934 kfree(de->name);
65935 kfree(de);
65936 }
65937 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
65938 if (nlink >= 2) {
65939 char *old = find_link(major, minor, ino, mode, collected);
65940 if (old)
65941 - return (sys_link(old, collected) < 0) ? -1 : 1;
65942 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
65943 }
65944 return 0;
65945 }
65946 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
65947 {
65948 struct stat st;
65949
65950 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
65951 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
65952 if (S_ISDIR(st.st_mode))
65953 - sys_rmdir(path);
65954 + sys_rmdir((char __force_user *)path);
65955 else
65956 - sys_unlink(path);
65957 + sys_unlink((char __force_user *)path);
65958 }
65959 }
65960
65961 @@ -315,7 +315,7 @@ static int __init do_name(void)
65962 int openflags = O_WRONLY|O_CREAT;
65963 if (ml != 1)
65964 openflags |= O_TRUNC;
65965 - wfd = sys_open(collected, openflags, mode);
65966 + wfd = sys_open((char __force_user *)collected, openflags, mode);
65967
65968 if (wfd >= 0) {
65969 sys_fchown(wfd, uid, gid);
65970 @@ -327,17 +327,17 @@ static int __init do_name(void)
65971 }
65972 }
65973 } else if (S_ISDIR(mode)) {
65974 - sys_mkdir(collected, mode);
65975 - sys_chown(collected, uid, gid);
65976 - sys_chmod(collected, mode);
65977 + sys_mkdir((char __force_user *)collected, mode);
65978 + sys_chown((char __force_user *)collected, uid, gid);
65979 + sys_chmod((char __force_user *)collected, mode);
65980 dir_add(collected, mtime);
65981 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
65982 S_ISFIFO(mode) || S_ISSOCK(mode)) {
65983 if (maybe_link() == 0) {
65984 - sys_mknod(collected, mode, rdev);
65985 - sys_chown(collected, uid, gid);
65986 - sys_chmod(collected, mode);
65987 - do_utime(collected, mtime);
65988 + sys_mknod((char __force_user *)collected, mode, rdev);
65989 + sys_chown((char __force_user *)collected, uid, gid);
65990 + sys_chmod((char __force_user *)collected, mode);
65991 + do_utime((char __force_user *)collected, mtime);
65992 }
65993 }
65994 return 0;
65995 @@ -346,15 +346,15 @@ static int __init do_name(void)
65996 static int __init do_copy(void)
65997 {
65998 if (count >= body_len) {
65999 - sys_write(wfd, victim, body_len);
66000 + sys_write(wfd, (char __force_user *)victim, body_len);
66001 sys_close(wfd);
66002 - do_utime(vcollected, mtime);
66003 + do_utime((char __force_user *)vcollected, mtime);
66004 kfree(vcollected);
66005 eat(body_len);
66006 state = SkipIt;
66007 return 0;
66008 } else {
66009 - sys_write(wfd, victim, count);
66010 + sys_write(wfd, (char __force_user *)victim, count);
66011 body_len -= count;
66012 eat(count);
66013 return 1;
66014 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66015 {
66016 collected[N_ALIGN(name_len) + body_len] = '\0';
66017 clean_path(collected, 0);
66018 - sys_symlink(collected + N_ALIGN(name_len), collected);
66019 - sys_lchown(collected, uid, gid);
66020 - do_utime(collected, mtime);
66021 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66022 + sys_lchown((char __force_user *)collected, uid, gid);
66023 + do_utime((char __force_user *)collected, mtime);
66024 state = SkipIt;
66025 next_state = Reset;
66026 return 0;
66027 diff --git a/init/main.c b/init/main.c
66028 index b286730..9ff6135 100644
66029 --- a/init/main.c
66030 +++ b/init/main.c
66031 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
66032 extern void tc_init(void);
66033 #endif
66034
66035 +extern void grsecurity_init(void);
66036 +
66037 /*
66038 * Debug helper: via this flag we know that we are in 'early bootup code'
66039 * where only the boot processor is running with IRQ disabled. This means
66040 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
66041
66042 __setup("reset_devices", set_reset_devices);
66043
66044 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66045 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66046 +static int __init setup_grsec_proc_gid(char *str)
66047 +{
66048 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
66049 + return 1;
66050 +}
66051 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66052 +#endif
66053 +
66054 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66055 +extern char pax_enter_kernel_user[];
66056 +extern char pax_exit_kernel_user[];
66057 +extern pgdval_t clone_pgd_mask;
66058 +#endif
66059 +
66060 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66061 +static int __init setup_pax_nouderef(char *str)
66062 +{
66063 +#ifdef CONFIG_X86_32
66064 + unsigned int cpu;
66065 + struct desc_struct *gdt;
66066 +
66067 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66068 + gdt = get_cpu_gdt_table(cpu);
66069 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66070 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66071 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66072 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66073 + }
66074 + loadsegment(ds, __KERNEL_DS);
66075 + loadsegment(es, __KERNEL_DS);
66076 + loadsegment(ss, __KERNEL_DS);
66077 +#else
66078 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66079 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66080 + clone_pgd_mask = ~(pgdval_t)0UL;
66081 +#endif
66082 +
66083 + return 0;
66084 +}
66085 +early_param("pax_nouderef", setup_pax_nouderef);
66086 +#endif
66087 +
66088 +#ifdef CONFIG_PAX_SOFTMODE
66089 +int pax_softmode;
66090 +
66091 +static int __init setup_pax_softmode(char *str)
66092 +{
66093 + get_option(&str, &pax_softmode);
66094 + return 1;
66095 +}
66096 +__setup("pax_softmode=", setup_pax_softmode);
66097 +#endif
66098 +
66099 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66100 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66101 static const char *panic_later, *panic_param;
66102 @@ -675,6 +732,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66103 {
66104 int count = preempt_count();
66105 int ret;
66106 + const char *msg1 = "", *msg2 = "";
66107
66108 if (initcall_debug)
66109 ret = do_one_initcall_debug(fn);
66110 @@ -687,15 +745,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66111 sprintf(msgbuf, "error code %d ", ret);
66112
66113 if (preempt_count() != count) {
66114 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66115 + msg1 = " preemption imbalance";
66116 preempt_count() = count;
66117 }
66118 if (irqs_disabled()) {
66119 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66120 + msg2 = " disabled interrupts";
66121 local_irq_enable();
66122 }
66123 - if (msgbuf[0]) {
66124 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66125 + if (msgbuf[0] || *msg1 || *msg2) {
66126 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66127 }
66128
66129 return ret;
66130 @@ -749,8 +807,14 @@ static void __init do_initcall_level(int level)
66131 level, level,
66132 &repair_env_string);
66133
66134 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66135 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66136 do_one_initcall(*fn);
66137 +
66138 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66139 + transfer_latent_entropy();
66140 +#endif
66141 +
66142 + }
66143 }
66144
66145 static void __init do_initcalls(void)
66146 @@ -784,8 +848,14 @@ static void __init do_pre_smp_initcalls(void)
66147 {
66148 initcall_t *fn;
66149
66150 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66151 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66152 do_one_initcall(*fn);
66153 +
66154 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66155 + transfer_latent_entropy();
66156 +#endif
66157 +
66158 + }
66159 }
66160
66161 static void run_init_process(const char *init_filename)
66162 @@ -867,7 +937,7 @@ static int __init kernel_init(void * unused)
66163 do_basic_setup();
66164
66165 /* Open the /dev/console on the rootfs, this should never fail */
66166 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66167 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66168 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66169
66170 (void) sys_dup(0);
66171 @@ -880,11 +950,13 @@ static int __init kernel_init(void * unused)
66172 if (!ramdisk_execute_command)
66173 ramdisk_execute_command = "/init";
66174
66175 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66176 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66177 ramdisk_execute_command = NULL;
66178 prepare_namespace();
66179 }
66180
66181 + grsecurity_init();
66182 +
66183 /*
66184 * Ok, we have completed the initial bootup, and
66185 * we're essentially up and running. Get rid of the
66186 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66187 index 9a08acc..e65ebe7 100644
66188 --- a/ipc/mqueue.c
66189 +++ b/ipc/mqueue.c
66190 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66191 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66192 info->attr.mq_msgsize);
66193
66194 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66195 spin_lock(&mq_lock);
66196 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66197 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66198 diff --git a/ipc/msg.c b/ipc/msg.c
66199 index 7385de2..a8180e08 100644
66200 --- a/ipc/msg.c
66201 +++ b/ipc/msg.c
66202 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66203 return security_msg_queue_associate(msq, msgflg);
66204 }
66205
66206 +static struct ipc_ops msg_ops = {
66207 + .getnew = newque,
66208 + .associate = msg_security,
66209 + .more_checks = NULL
66210 +};
66211 +
66212 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66213 {
66214 struct ipc_namespace *ns;
66215 - struct ipc_ops msg_ops;
66216 struct ipc_params msg_params;
66217
66218 ns = current->nsproxy->ipc_ns;
66219
66220 - msg_ops.getnew = newque;
66221 - msg_ops.associate = msg_security;
66222 - msg_ops.more_checks = NULL;
66223 -
66224 msg_params.key = key;
66225 msg_params.flg = msgflg;
66226
66227 diff --git a/ipc/sem.c b/ipc/sem.c
66228 index 5215a81..cfc0cac 100644
66229 --- a/ipc/sem.c
66230 +++ b/ipc/sem.c
66231 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66232 return 0;
66233 }
66234
66235 +static struct ipc_ops sem_ops = {
66236 + .getnew = newary,
66237 + .associate = sem_security,
66238 + .more_checks = sem_more_checks
66239 +};
66240 +
66241 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66242 {
66243 struct ipc_namespace *ns;
66244 - struct ipc_ops sem_ops;
66245 struct ipc_params sem_params;
66246
66247 ns = current->nsproxy->ipc_ns;
66248 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66249 if (nsems < 0 || nsems > ns->sc_semmsl)
66250 return -EINVAL;
66251
66252 - sem_ops.getnew = newary;
66253 - sem_ops.associate = sem_security;
66254 - sem_ops.more_checks = sem_more_checks;
66255 -
66256 sem_params.key = key;
66257 sem_params.flg = semflg;
66258 sem_params.u.nsems = nsems;
66259 diff --git a/ipc/shm.c b/ipc/shm.c
66260 index 00faa05..7040960 100644
66261 --- a/ipc/shm.c
66262 +++ b/ipc/shm.c
66263 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66264 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66265 #endif
66266
66267 +#ifdef CONFIG_GRKERNSEC
66268 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66269 + const time_t shm_createtime, const uid_t cuid,
66270 + const int shmid);
66271 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66272 + const time_t shm_createtime);
66273 +#endif
66274 +
66275 void shm_init_ns(struct ipc_namespace *ns)
66276 {
66277 ns->shm_ctlmax = SHMMAX;
66278 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66279 shp->shm_lprid = 0;
66280 shp->shm_atim = shp->shm_dtim = 0;
66281 shp->shm_ctim = get_seconds();
66282 +#ifdef CONFIG_GRKERNSEC
66283 + {
66284 + struct timespec timeval;
66285 + do_posix_clock_monotonic_gettime(&timeval);
66286 +
66287 + shp->shm_createtime = timeval.tv_sec;
66288 + }
66289 +#endif
66290 shp->shm_segsz = size;
66291 shp->shm_nattch = 0;
66292 shp->shm_file = file;
66293 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66294 return 0;
66295 }
66296
66297 +static struct ipc_ops shm_ops = {
66298 + .getnew = newseg,
66299 + .associate = shm_security,
66300 + .more_checks = shm_more_checks
66301 +};
66302 +
66303 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66304 {
66305 struct ipc_namespace *ns;
66306 - struct ipc_ops shm_ops;
66307 struct ipc_params shm_params;
66308
66309 ns = current->nsproxy->ipc_ns;
66310
66311 - shm_ops.getnew = newseg;
66312 - shm_ops.associate = shm_security;
66313 - shm_ops.more_checks = shm_more_checks;
66314 -
66315 shm_params.key = key;
66316 shm_params.flg = shmflg;
66317 shm_params.u.size = size;
66318 @@ -1001,6 +1018,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66319 f_mode = FMODE_READ | FMODE_WRITE;
66320 }
66321 if (shmflg & SHM_EXEC) {
66322 +
66323 +#ifdef CONFIG_PAX_MPROTECT
66324 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66325 + goto out;
66326 +#endif
66327 +
66328 prot |= PROT_EXEC;
66329 acc_mode |= S_IXUGO;
66330 }
66331 @@ -1024,9 +1047,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
66332 if (err)
66333 goto out_unlock;
66334
66335 +#ifdef CONFIG_GRKERNSEC
66336 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66337 + shp->shm_perm.cuid, shmid) ||
66338 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66339 + err = -EACCES;
66340 + goto out_unlock;
66341 + }
66342 +#endif
66343 +
66344 path = shp->shm_file->f_path;
66345 path_get(&path);
66346 shp->shm_nattch++;
66347 +#ifdef CONFIG_GRKERNSEC
66348 + shp->shm_lapid = current->pid;
66349 +#endif
66350 size = i_size_read(path.dentry->d_inode);
66351 shm_unlock(shp);
66352
66353 diff --git a/kernel/acct.c b/kernel/acct.c
66354 index 02e6167..54824f7 100644
66355 --- a/kernel/acct.c
66356 +++ b/kernel/acct.c
66357 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66358 */
66359 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66360 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66361 - file->f_op->write(file, (char *)&ac,
66362 + file->f_op->write(file, (char __force_user *)&ac,
66363 sizeof(acct_t), &file->f_pos);
66364 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66365 set_fs(fs);
66366 diff --git a/kernel/audit.c b/kernel/audit.c
66367 index ea3b7b6..c260d34 100644
66368 --- a/kernel/audit.c
66369 +++ b/kernel/audit.c
66370 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66371 3) suppressed due to audit_rate_limit
66372 4) suppressed due to audit_backlog_limit
66373 */
66374 -static atomic_t audit_lost = ATOMIC_INIT(0);
66375 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66376
66377 /* The netlink socket. */
66378 static struct sock *audit_sock;
66379 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66380 unsigned long now;
66381 int print;
66382
66383 - atomic_inc(&audit_lost);
66384 + atomic_inc_unchecked(&audit_lost);
66385
66386 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66387
66388 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66389 printk(KERN_WARNING
66390 "audit: audit_lost=%d audit_rate_limit=%d "
66391 "audit_backlog_limit=%d\n",
66392 - atomic_read(&audit_lost),
66393 + atomic_read_unchecked(&audit_lost),
66394 audit_rate_limit,
66395 audit_backlog_limit);
66396 audit_panic(message);
66397 @@ -690,7 +690,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66398 status_set.pid = audit_pid;
66399 status_set.rate_limit = audit_rate_limit;
66400 status_set.backlog_limit = audit_backlog_limit;
66401 - status_set.lost = atomic_read(&audit_lost);
66402 + status_set.lost = atomic_read_unchecked(&audit_lost);
66403 status_set.backlog = skb_queue_len(&audit_skb_queue);
66404 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66405 &status_set, sizeof(status_set));
66406 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66407 index 4b96415..d8c16ee 100644
66408 --- a/kernel/auditsc.c
66409 +++ b/kernel/auditsc.c
66410 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66411 }
66412
66413 /* global counter which is incremented every time something logs in */
66414 -static atomic_t session_id = ATOMIC_INIT(0);
66415 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66416
66417 /**
66418 * audit_set_loginuid - set current task's audit_context loginuid
66419 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66420 return -EPERM;
66421 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66422
66423 - sessionid = atomic_inc_return(&session_id);
66424 + sessionid = atomic_inc_return_unchecked(&session_id);
66425 if (context && context->in_syscall) {
66426 struct audit_buffer *ab;
66427
66428 diff --git a/kernel/capability.c b/kernel/capability.c
66429 index 493d972..ea17248 100644
66430 --- a/kernel/capability.c
66431 +++ b/kernel/capability.c
66432 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66433 * before modification is attempted and the application
66434 * fails.
66435 */
66436 + if (tocopy > ARRAY_SIZE(kdata))
66437 + return -EFAULT;
66438 +
66439 if (copy_to_user(dataptr, kdata, tocopy
66440 * sizeof(struct __user_cap_data_struct))) {
66441 return -EFAULT;
66442 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66443 int ret;
66444
66445 rcu_read_lock();
66446 - ret = security_capable(__task_cred(t), ns, cap);
66447 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66448 + gr_task_is_capable(t, __task_cred(t), cap);
66449 rcu_read_unlock();
66450
66451 - return (ret == 0);
66452 + return ret;
66453 }
66454
66455 /**
66456 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66457 int ret;
66458
66459 rcu_read_lock();
66460 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66461 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66462 rcu_read_unlock();
66463
66464 - return (ret == 0);
66465 + return ret;
66466 }
66467
66468 /**
66469 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66470 BUG();
66471 }
66472
66473 - if (security_capable(current_cred(), ns, cap) == 0) {
66474 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66475 current->flags |= PF_SUPERPRIV;
66476 return true;
66477 }
66478 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66479 }
66480 EXPORT_SYMBOL(ns_capable);
66481
66482 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66483 +{
66484 + if (unlikely(!cap_valid(cap))) {
66485 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66486 + BUG();
66487 + }
66488 +
66489 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66490 + current->flags |= PF_SUPERPRIV;
66491 + return true;
66492 + }
66493 + return false;
66494 +}
66495 +EXPORT_SYMBOL(ns_capable_nolog);
66496 +
66497 /**
66498 * capable - Determine if the current task has a superior capability in effect
66499 * @cap: The capability to be tested for
66500 @@ -408,6 +427,12 @@ bool capable(int cap)
66501 }
66502 EXPORT_SYMBOL(capable);
66503
66504 +bool capable_nolog(int cap)
66505 +{
66506 + return ns_capable_nolog(&init_user_ns, cap);
66507 +}
66508 +EXPORT_SYMBOL(capable_nolog);
66509 +
66510 /**
66511 * nsown_capable - Check superior capability to one's own user_ns
66512 * @cap: The capability in question
66513 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66514
66515 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66516 }
66517 +
66518 +bool inode_capable_nolog(const struct inode *inode, int cap)
66519 +{
66520 + struct user_namespace *ns = current_user_ns();
66521 +
66522 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66523 +}
66524 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
66525 index 7981850..370878f 100644
66526 --- a/kernel/cgroup.c
66527 +++ b/kernel/cgroup.c
66528 @@ -5411,7 +5411,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
66529 struct css_set *cg = link->cg;
66530 struct task_struct *task;
66531 int count = 0;
66532 - seq_printf(seq, "css_set %p\n", cg);
66533 + seq_printf(seq, "css_set %pK\n", cg);
66534 list_for_each_entry(task, &cg->tasks, cg_list) {
66535 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
66536 seq_puts(seq, " ...\n");
66537 diff --git a/kernel/compat.c b/kernel/compat.c
66538 index c28a306..b4d0cf3 100644
66539 --- a/kernel/compat.c
66540 +++ b/kernel/compat.c
66541 @@ -13,6 +13,7 @@
66542
66543 #include <linux/linkage.h>
66544 #include <linux/compat.h>
66545 +#include <linux/module.h>
66546 #include <linux/errno.h>
66547 #include <linux/time.h>
66548 #include <linux/signal.h>
66549 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66550 mm_segment_t oldfs;
66551 long ret;
66552
66553 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66554 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66555 oldfs = get_fs();
66556 set_fs(KERNEL_DS);
66557 ret = hrtimer_nanosleep_restart(restart);
66558 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66559 oldfs = get_fs();
66560 set_fs(KERNEL_DS);
66561 ret = hrtimer_nanosleep(&tu,
66562 - rmtp ? (struct timespec __user *)&rmt : NULL,
66563 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66564 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66565 set_fs(oldfs);
66566
66567 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66568 mm_segment_t old_fs = get_fs();
66569
66570 set_fs(KERNEL_DS);
66571 - ret = sys_sigpending((old_sigset_t __user *) &s);
66572 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66573 set_fs(old_fs);
66574 if (ret == 0)
66575 ret = put_user(s, set);
66576 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66577 mm_segment_t old_fs = get_fs();
66578
66579 set_fs(KERNEL_DS);
66580 - ret = sys_old_getrlimit(resource, &r);
66581 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66582 set_fs(old_fs);
66583
66584 if (!ret) {
66585 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66586 mm_segment_t old_fs = get_fs();
66587
66588 set_fs(KERNEL_DS);
66589 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66590 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66591 set_fs(old_fs);
66592
66593 if (ret)
66594 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66595 set_fs (KERNEL_DS);
66596 ret = sys_wait4(pid,
66597 (stat_addr ?
66598 - (unsigned int __user *) &status : NULL),
66599 - options, (struct rusage __user *) &r);
66600 + (unsigned int __force_user *) &status : NULL),
66601 + options, (struct rusage __force_user *) &r);
66602 set_fs (old_fs);
66603
66604 if (ret > 0) {
66605 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66606 memset(&info, 0, sizeof(info));
66607
66608 set_fs(KERNEL_DS);
66609 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66610 - uru ? (struct rusage __user *)&ru : NULL);
66611 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66612 + uru ? (struct rusage __force_user *)&ru : NULL);
66613 set_fs(old_fs);
66614
66615 if ((ret < 0) || (info.si_signo == 0))
66616 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66617 oldfs = get_fs();
66618 set_fs(KERNEL_DS);
66619 err = sys_timer_settime(timer_id, flags,
66620 - (struct itimerspec __user *) &newts,
66621 - (struct itimerspec __user *) &oldts);
66622 + (struct itimerspec __force_user *) &newts,
66623 + (struct itimerspec __force_user *) &oldts);
66624 set_fs(oldfs);
66625 if (!err && old && put_compat_itimerspec(old, &oldts))
66626 return -EFAULT;
66627 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66628 oldfs = get_fs();
66629 set_fs(KERNEL_DS);
66630 err = sys_timer_gettime(timer_id,
66631 - (struct itimerspec __user *) &ts);
66632 + (struct itimerspec __force_user *) &ts);
66633 set_fs(oldfs);
66634 if (!err && put_compat_itimerspec(setting, &ts))
66635 return -EFAULT;
66636 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66637 oldfs = get_fs();
66638 set_fs(KERNEL_DS);
66639 err = sys_clock_settime(which_clock,
66640 - (struct timespec __user *) &ts);
66641 + (struct timespec __force_user *) &ts);
66642 set_fs(oldfs);
66643 return err;
66644 }
66645 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66646 oldfs = get_fs();
66647 set_fs(KERNEL_DS);
66648 err = sys_clock_gettime(which_clock,
66649 - (struct timespec __user *) &ts);
66650 + (struct timespec __force_user *) &ts);
66651 set_fs(oldfs);
66652 if (!err && put_compat_timespec(&ts, tp))
66653 return -EFAULT;
66654 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66655
66656 oldfs = get_fs();
66657 set_fs(KERNEL_DS);
66658 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66659 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66660 set_fs(oldfs);
66661
66662 err = compat_put_timex(utp, &txc);
66663 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66664 oldfs = get_fs();
66665 set_fs(KERNEL_DS);
66666 err = sys_clock_getres(which_clock,
66667 - (struct timespec __user *) &ts);
66668 + (struct timespec __force_user *) &ts);
66669 set_fs(oldfs);
66670 if (!err && tp && put_compat_timespec(&ts, tp))
66671 return -EFAULT;
66672 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66673 long err;
66674 mm_segment_t oldfs;
66675 struct timespec tu;
66676 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66677 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66678
66679 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66680 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66681 oldfs = get_fs();
66682 set_fs(KERNEL_DS);
66683 err = clock_nanosleep_restart(restart);
66684 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66685 oldfs = get_fs();
66686 set_fs(KERNEL_DS);
66687 err = sys_clock_nanosleep(which_clock, flags,
66688 - (struct timespec __user *) &in,
66689 - (struct timespec __user *) &out);
66690 + (struct timespec __force_user *) &in,
66691 + (struct timespec __force_user *) &out);
66692 set_fs(oldfs);
66693
66694 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66695 diff --git a/kernel/configs.c b/kernel/configs.c
66696 index 42e8fa0..9e7406b 100644
66697 --- a/kernel/configs.c
66698 +++ b/kernel/configs.c
66699 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66700 struct proc_dir_entry *entry;
66701
66702 /* create the current config file */
66703 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66704 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66705 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66706 + &ikconfig_file_ops);
66707 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66708 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66709 + &ikconfig_file_ops);
66710 +#endif
66711 +#else
66712 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66713 &ikconfig_file_ops);
66714 +#endif
66715 +
66716 if (!entry)
66717 return -ENOMEM;
66718
66719 diff --git a/kernel/cred.c b/kernel/cred.c
66720 index de728ac..e3c267c 100644
66721 --- a/kernel/cred.c
66722 +++ b/kernel/cred.c
66723 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66724 validate_creds(cred);
66725 alter_cred_subscribers(cred, -1);
66726 put_cred(cred);
66727 +
66728 +#ifdef CONFIG_GRKERNSEC_SETXID
66729 + cred = (struct cred *) tsk->delayed_cred;
66730 + if (cred != NULL) {
66731 + tsk->delayed_cred = NULL;
66732 + validate_creds(cred);
66733 + alter_cred_subscribers(cred, -1);
66734 + put_cred(cred);
66735 + }
66736 +#endif
66737 }
66738
66739 /**
66740 @@ -469,7 +479,7 @@ error_put:
66741 * Always returns 0 thus allowing this function to be tail-called at the end
66742 * of, say, sys_setgid().
66743 */
66744 -int commit_creds(struct cred *new)
66745 +static int __commit_creds(struct cred *new)
66746 {
66747 struct task_struct *task = current;
66748 const struct cred *old = task->real_cred;
66749 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66750
66751 get_cred(new); /* we will require a ref for the subj creds too */
66752
66753 + gr_set_role_label(task, new->uid, new->gid);
66754 +
66755 /* dumpability changes */
66756 if (!uid_eq(old->euid, new->euid) ||
66757 !gid_eq(old->egid, new->egid) ||
66758 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66759 put_cred(old);
66760 return 0;
66761 }
66762 +#ifdef CONFIG_GRKERNSEC_SETXID
66763 +extern int set_user(struct cred *new);
66764 +
66765 +void gr_delayed_cred_worker(void)
66766 +{
66767 + const struct cred *new = current->delayed_cred;
66768 + struct cred *ncred;
66769 +
66770 + current->delayed_cred = NULL;
66771 +
66772 + if (current_uid() && new != NULL) {
66773 + // from doing get_cred on it when queueing this
66774 + put_cred(new);
66775 + return;
66776 + } else if (new == NULL)
66777 + return;
66778 +
66779 + ncred = prepare_creds();
66780 + if (!ncred)
66781 + goto die;
66782 + // uids
66783 + ncred->uid = new->uid;
66784 + ncred->euid = new->euid;
66785 + ncred->suid = new->suid;
66786 + ncred->fsuid = new->fsuid;
66787 + // gids
66788 + ncred->gid = new->gid;
66789 + ncred->egid = new->egid;
66790 + ncred->sgid = new->sgid;
66791 + ncred->fsgid = new->fsgid;
66792 + // groups
66793 + if (set_groups(ncred, new->group_info) < 0) {
66794 + abort_creds(ncred);
66795 + goto die;
66796 + }
66797 + // caps
66798 + ncred->securebits = new->securebits;
66799 + ncred->cap_inheritable = new->cap_inheritable;
66800 + ncred->cap_permitted = new->cap_permitted;
66801 + ncred->cap_effective = new->cap_effective;
66802 + ncred->cap_bset = new->cap_bset;
66803 +
66804 + if (set_user(ncred)) {
66805 + abort_creds(ncred);
66806 + goto die;
66807 + }
66808 +
66809 + // from doing get_cred on it when queueing this
66810 + put_cred(new);
66811 +
66812 + __commit_creds(ncred);
66813 + return;
66814 +die:
66815 + // from doing get_cred on it when queueing this
66816 + put_cred(new);
66817 + do_group_exit(SIGKILL);
66818 +}
66819 +#endif
66820 +
66821 +int commit_creds(struct cred *new)
66822 +{
66823 +#ifdef CONFIG_GRKERNSEC_SETXID
66824 + int ret;
66825 + int schedule_it = 0;
66826 + struct task_struct *t;
66827 +
66828 + /* we won't get called with tasklist_lock held for writing
66829 + and interrupts disabled as the cred struct in that case is
66830 + init_cred
66831 + */
66832 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66833 + !current_uid() && new->uid) {
66834 + schedule_it = 1;
66835 + }
66836 + ret = __commit_creds(new);
66837 + if (schedule_it) {
66838 + rcu_read_lock();
66839 + read_lock(&tasklist_lock);
66840 + for (t = next_thread(current); t != current;
66841 + t = next_thread(t)) {
66842 + if (t->delayed_cred == NULL) {
66843 + t->delayed_cred = get_cred(new);
66844 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66845 + set_tsk_need_resched(t);
66846 + }
66847 + }
66848 + read_unlock(&tasklist_lock);
66849 + rcu_read_unlock();
66850 + }
66851 + return ret;
66852 +#else
66853 + return __commit_creds(new);
66854 +#endif
66855 +}
66856 +
66857 EXPORT_SYMBOL(commit_creds);
66858
66859 /**
66860 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
66861 index 0557f24..1a00d9a 100644
66862 --- a/kernel/debug/debug_core.c
66863 +++ b/kernel/debug/debug_core.c
66864 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
66865 */
66866 static atomic_t masters_in_kgdb;
66867 static atomic_t slaves_in_kgdb;
66868 -static atomic_t kgdb_break_tasklet_var;
66869 +static atomic_unchecked_t kgdb_break_tasklet_var;
66870 atomic_t kgdb_setting_breakpoint;
66871
66872 struct task_struct *kgdb_usethread;
66873 @@ -132,7 +132,7 @@ int kgdb_single_step;
66874 static pid_t kgdb_sstep_pid;
66875
66876 /* to keep track of the CPU which is doing the single stepping*/
66877 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66878 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
66879
66880 /*
66881 * If you are debugging a problem where roundup (the collection of
66882 @@ -540,7 +540,7 @@ return_normal:
66883 * kernel will only try for the value of sstep_tries before
66884 * giving up and continuing on.
66885 */
66886 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
66887 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
66888 (kgdb_info[cpu].task &&
66889 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
66890 atomic_set(&kgdb_active, -1);
66891 @@ -634,8 +634,8 @@ cpu_master_loop:
66892 }
66893
66894 kgdb_restore:
66895 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
66896 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
66897 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
66898 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
66899 if (kgdb_info[sstep_cpu].task)
66900 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
66901 else
66902 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
66903 static void kgdb_tasklet_bpt(unsigned long ing)
66904 {
66905 kgdb_breakpoint();
66906 - atomic_set(&kgdb_break_tasklet_var, 0);
66907 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
66908 }
66909
66910 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
66911
66912 void kgdb_schedule_breakpoint(void)
66913 {
66914 - if (atomic_read(&kgdb_break_tasklet_var) ||
66915 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
66916 atomic_read(&kgdb_active) != -1 ||
66917 atomic_read(&kgdb_setting_breakpoint))
66918 return;
66919 - atomic_inc(&kgdb_break_tasklet_var);
66920 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
66921 tasklet_schedule(&kgdb_tasklet_breakpoint);
66922 }
66923 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
66924 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
66925 index 31df170..bc98840 100644
66926 --- a/kernel/debug/kdb/kdb_main.c
66927 +++ b/kernel/debug/kdb/kdb_main.c
66928 @@ -1971,7 +1971,7 @@ static int kdb_lsmod(int argc, const char **argv)
66929 list_for_each_entry(mod, kdb_modules, list) {
66930
66931 kdb_printf("%-20s%8u 0x%p ", mod->name,
66932 - mod->core_size, (void *)mod);
66933 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
66934 #ifdef CONFIG_MODULE_UNLOAD
66935 kdb_printf("%4ld ", module_refcount(mod));
66936 #endif
66937 @@ -1981,7 +1981,7 @@ static int kdb_lsmod(int argc, const char **argv)
66938 kdb_printf(" (Loading)");
66939 else
66940 kdb_printf(" (Live)");
66941 - kdb_printf(" 0x%p", mod->module_core);
66942 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
66943
66944 #ifdef CONFIG_MODULE_UNLOAD
66945 {
66946 diff --git a/kernel/events/core.c b/kernel/events/core.c
66947 index 7fee567..8affa2c 100644
66948 --- a/kernel/events/core.c
66949 +++ b/kernel/events/core.c
66950 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
66951 return 0;
66952 }
66953
66954 -static atomic64_t perf_event_id;
66955 +static atomic64_unchecked_t perf_event_id;
66956
66957 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
66958 enum event_type_t event_type);
66959 @@ -2665,7 +2665,7 @@ static void __perf_event_read(void *info)
66960
66961 static inline u64 perf_event_count(struct perf_event *event)
66962 {
66963 - return local64_read(&event->count) + atomic64_read(&event->child_count);
66964 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
66965 }
66966
66967 static u64 perf_event_read(struct perf_event *event)
66968 @@ -2995,9 +2995,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
66969 mutex_lock(&event->child_mutex);
66970 total += perf_event_read(event);
66971 *enabled += event->total_time_enabled +
66972 - atomic64_read(&event->child_total_time_enabled);
66973 + atomic64_read_unchecked(&event->child_total_time_enabled);
66974 *running += event->total_time_running +
66975 - atomic64_read(&event->child_total_time_running);
66976 + atomic64_read_unchecked(&event->child_total_time_running);
66977
66978 list_for_each_entry(child, &event->child_list, child_list) {
66979 total += perf_event_read(child);
66980 @@ -3406,10 +3406,10 @@ void perf_event_update_userpage(struct perf_event *event)
66981 userpg->offset -= local64_read(&event->hw.prev_count);
66982
66983 userpg->time_enabled = enabled +
66984 - atomic64_read(&event->child_total_time_enabled);
66985 + atomic64_read_unchecked(&event->child_total_time_enabled);
66986
66987 userpg->time_running = running +
66988 - atomic64_read(&event->child_total_time_running);
66989 + atomic64_read_unchecked(&event->child_total_time_running);
66990
66991 arch_perf_update_userpage(userpg, now);
66992
66993 @@ -3842,11 +3842,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
66994 values[n++] = perf_event_count(event);
66995 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
66996 values[n++] = enabled +
66997 - atomic64_read(&event->child_total_time_enabled);
66998 + atomic64_read_unchecked(&event->child_total_time_enabled);
66999 }
67000 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67001 values[n++] = running +
67002 - atomic64_read(&event->child_total_time_running);
67003 + atomic64_read_unchecked(&event->child_total_time_running);
67004 }
67005 if (read_format & PERF_FORMAT_ID)
67006 values[n++] = primary_event_id(event);
67007 @@ -4524,12 +4524,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67008 * need to add enough zero bytes after the string to handle
67009 * the 64bit alignment we do later.
67010 */
67011 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67012 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67013 if (!buf) {
67014 name = strncpy(tmp, "//enomem", sizeof(tmp));
67015 goto got_name;
67016 }
67017 - name = d_path(&file->f_path, buf, PATH_MAX);
67018 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67019 if (IS_ERR(name)) {
67020 name = strncpy(tmp, "//toolong", sizeof(tmp));
67021 goto got_name;
67022 @@ -5968,7 +5968,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67023 event->parent = parent_event;
67024
67025 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67026 - event->id = atomic64_inc_return(&perf_event_id);
67027 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67028
67029 event->state = PERF_EVENT_STATE_INACTIVE;
67030
67031 @@ -6567,10 +6567,10 @@ static void sync_child_event(struct perf_event *child_event,
67032 /*
67033 * Add back the child's count to the parent's count:
67034 */
67035 - atomic64_add(child_val, &parent_event->child_count);
67036 - atomic64_add(child_event->total_time_enabled,
67037 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67038 + atomic64_add_unchecked(child_event->total_time_enabled,
67039 &parent_event->child_total_time_enabled);
67040 - atomic64_add(child_event->total_time_running,
67041 + atomic64_add_unchecked(child_event->total_time_running,
67042 &parent_event->child_total_time_running);
67043
67044 /*
67045 diff --git a/kernel/exit.c b/kernel/exit.c
67046 index f65345f9..9c28dab 100644
67047 --- a/kernel/exit.c
67048 +++ b/kernel/exit.c
67049 @@ -59,6 +59,10 @@
67050 #include <asm/pgtable.h>
67051 #include <asm/mmu_context.h>
67052
67053 +#ifdef CONFIG_GRKERNSEC
67054 +extern rwlock_t grsec_exec_file_lock;
67055 +#endif
67056 +
67057 static void exit_mm(struct task_struct * tsk);
67058
67059 static void __unhash_process(struct task_struct *p, bool group_dead)
67060 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67061 struct task_struct *leader;
67062 int zap_leader;
67063 repeat:
67064 +#ifdef CONFIG_NET
67065 + gr_del_task_from_ip_table(p);
67066 +#endif
67067 +
67068 /* don't need to get the RCU readlock here - the process is dead and
67069 * can't be modifying its own credentials. But shut RCU-lockdep up */
67070 rcu_read_lock();
67071 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67072 * know it'll be handled, so that they don't get converted to
67073 * SIGKILL or just silently dropped.
67074 */
67075 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67076 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67077 recalc_sigpending();
67078 spin_unlock_irq(&current->sighand->siglock);
67079 return 0;
67080 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67081 vsnprintf(current->comm, sizeof(current->comm), name, args);
67082 va_end(args);
67083
67084 +#ifdef CONFIG_GRKERNSEC
67085 + write_lock(&grsec_exec_file_lock);
67086 + if (current->exec_file) {
67087 + fput(current->exec_file);
67088 + current->exec_file = NULL;
67089 + }
67090 + write_unlock(&grsec_exec_file_lock);
67091 +#endif
67092 +
67093 + gr_set_kernel_label(current);
67094 +
67095 /*
67096 * If we were started as result of loading a module, close all of the
67097 * user space pages. We don't need them, and if we didn't close them
67098 @@ -907,6 +926,8 @@ void do_exit(long code)
67099 struct task_struct *tsk = current;
67100 int group_dead;
67101
67102 + set_fs(USER_DS);
67103 +
67104 profile_task_exit(tsk);
67105
67106 WARN_ON(blk_needs_flush_plug(tsk));
67107 @@ -923,7 +944,6 @@ void do_exit(long code)
67108 * mm_release()->clear_child_tid() from writing to a user-controlled
67109 * kernel address.
67110 */
67111 - set_fs(USER_DS);
67112
67113 ptrace_event(PTRACE_EVENT_EXIT, code);
67114
67115 @@ -982,6 +1002,9 @@ void do_exit(long code)
67116 tsk->exit_code = code;
67117 taskstats_exit(tsk, group_dead);
67118
67119 + gr_acl_handle_psacct(tsk, code);
67120 + gr_acl_handle_exit();
67121 +
67122 exit_mm(tsk);
67123
67124 if (group_dead)
67125 @@ -1099,7 +1122,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67126 * Take down every thread in the group. This is called by fatal signals
67127 * as well as by sys_exit_group (below).
67128 */
67129 -void
67130 +__noreturn void
67131 do_group_exit(int exit_code)
67132 {
67133 struct signal_struct *sig = current->signal;
67134 diff --git a/kernel/fork.c b/kernel/fork.c
67135 index 2c8857e..288c9c7 100644
67136 --- a/kernel/fork.c
67137 +++ b/kernel/fork.c
67138 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67139 *stackend = STACK_END_MAGIC; /* for overflow detection */
67140
67141 #ifdef CONFIG_CC_STACKPROTECTOR
67142 - tsk->stack_canary = get_random_int();
67143 + tsk->stack_canary = pax_get_random_long();
67144 #endif
67145
67146 /*
67147 @@ -343,13 +343,78 @@ free_tsk:
67148 }
67149
67150 #ifdef CONFIG_MMU
67151 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67152 +{
67153 + struct vm_area_struct *tmp;
67154 + unsigned long charge;
67155 + struct mempolicy *pol;
67156 + struct file *file;
67157 +
67158 + charge = 0;
67159 + if (mpnt->vm_flags & VM_ACCOUNT) {
67160 + unsigned long len = vma_pages(mpnt);
67161 +
67162 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67163 + goto fail_nomem;
67164 + charge = len;
67165 + }
67166 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67167 + if (!tmp)
67168 + goto fail_nomem;
67169 + *tmp = *mpnt;
67170 + tmp->vm_mm = mm;
67171 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67172 + pol = mpol_dup(vma_policy(mpnt));
67173 + if (IS_ERR(pol))
67174 + goto fail_nomem_policy;
67175 + vma_set_policy(tmp, pol);
67176 + if (anon_vma_fork(tmp, mpnt))
67177 + goto fail_nomem_anon_vma_fork;
67178 + tmp->vm_flags &= ~VM_LOCKED;
67179 + tmp->vm_next = tmp->vm_prev = NULL;
67180 + tmp->vm_mirror = NULL;
67181 + file = tmp->vm_file;
67182 + if (file) {
67183 + struct inode *inode = file->f_path.dentry->d_inode;
67184 + struct address_space *mapping = file->f_mapping;
67185 +
67186 + get_file(file);
67187 + if (tmp->vm_flags & VM_DENYWRITE)
67188 + atomic_dec(&inode->i_writecount);
67189 + mutex_lock(&mapping->i_mmap_mutex);
67190 + if (tmp->vm_flags & VM_SHARED)
67191 + mapping->i_mmap_writable++;
67192 + flush_dcache_mmap_lock(mapping);
67193 + /* insert tmp into the share list, just after mpnt */
67194 + vma_prio_tree_add(tmp, mpnt);
67195 + flush_dcache_mmap_unlock(mapping);
67196 + mutex_unlock(&mapping->i_mmap_mutex);
67197 + }
67198 +
67199 + /*
67200 + * Clear hugetlb-related page reserves for children. This only
67201 + * affects MAP_PRIVATE mappings. Faults generated by the child
67202 + * are not guaranteed to succeed, even if read-only
67203 + */
67204 + if (is_vm_hugetlb_page(tmp))
67205 + reset_vma_resv_huge_pages(tmp);
67206 +
67207 + return tmp;
67208 +
67209 +fail_nomem_anon_vma_fork:
67210 + mpol_put(pol);
67211 +fail_nomem_policy:
67212 + kmem_cache_free(vm_area_cachep, tmp);
67213 +fail_nomem:
67214 + vm_unacct_memory(charge);
67215 + return NULL;
67216 +}
67217 +
67218 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67219 {
67220 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67221 struct rb_node **rb_link, *rb_parent;
67222 int retval;
67223 - unsigned long charge;
67224 - struct mempolicy *pol;
67225
67226 down_write(&oldmm->mmap_sem);
67227 flush_cache_dup_mm(oldmm);
67228 @@ -361,8 +426,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67229 mm->locked_vm = 0;
67230 mm->mmap = NULL;
67231 mm->mmap_cache = NULL;
67232 - mm->free_area_cache = oldmm->mmap_base;
67233 - mm->cached_hole_size = ~0UL;
67234 + mm->free_area_cache = oldmm->free_area_cache;
67235 + mm->cached_hole_size = oldmm->cached_hole_size;
67236 mm->map_count = 0;
67237 cpumask_clear(mm_cpumask(mm));
67238 mm->mm_rb = RB_ROOT;
67239 @@ -378,52 +443,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67240
67241 prev = NULL;
67242 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67243 - struct file *file;
67244 -
67245 if (mpnt->vm_flags & VM_DONTCOPY) {
67246 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
67247 -vma_pages(mpnt));
67248 continue;
67249 }
67250 - charge = 0;
67251 - if (mpnt->vm_flags & VM_ACCOUNT) {
67252 - unsigned long len = vma_pages(mpnt);
67253 -
67254 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67255 - goto fail_nomem;
67256 - charge = len;
67257 - }
67258 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67259 - if (!tmp)
67260 - goto fail_nomem;
67261 - *tmp = *mpnt;
67262 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67263 - pol = mpol_dup(vma_policy(mpnt));
67264 - retval = PTR_ERR(pol);
67265 - if (IS_ERR(pol))
67266 - goto fail_nomem_policy;
67267 - vma_set_policy(tmp, pol);
67268 - tmp->vm_mm = mm;
67269 - if (anon_vma_fork(tmp, mpnt))
67270 - goto fail_nomem_anon_vma_fork;
67271 - tmp->vm_flags &= ~VM_LOCKED;
67272 - tmp->vm_next = tmp->vm_prev = NULL;
67273 - file = tmp->vm_file;
67274 - if (file) {
67275 - struct inode *inode = file->f_path.dentry->d_inode;
67276 - struct address_space *mapping = file->f_mapping;
67277 -
67278 - get_file(file);
67279 - if (tmp->vm_flags & VM_DENYWRITE)
67280 - atomic_dec(&inode->i_writecount);
67281 - mutex_lock(&mapping->i_mmap_mutex);
67282 - if (tmp->vm_flags & VM_SHARED)
67283 - mapping->i_mmap_writable++;
67284 - flush_dcache_mmap_lock(mapping);
67285 - /* insert tmp into the share list, just after mpnt */
67286 - vma_prio_tree_add(tmp, mpnt);
67287 - flush_dcache_mmap_unlock(mapping);
67288 - mutex_unlock(&mapping->i_mmap_mutex);
67289 + tmp = dup_vma(mm, oldmm, mpnt);
67290 + if (!tmp) {
67291 + retval = -ENOMEM;
67292 + goto out;
67293 }
67294
67295 /*
67296 @@ -455,9 +483,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67297 if (retval)
67298 goto out;
67299
67300 - if (file)
67301 + if (tmp->vm_file)
67302 uprobe_mmap(tmp);
67303 }
67304 +
67305 +#ifdef CONFIG_PAX_SEGMEXEC
67306 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67307 + struct vm_area_struct *mpnt_m;
67308 +
67309 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67310 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67311 +
67312 + if (!mpnt->vm_mirror)
67313 + continue;
67314 +
67315 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67316 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67317 + mpnt->vm_mirror = mpnt_m;
67318 + } else {
67319 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67320 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67321 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67322 + mpnt->vm_mirror->vm_mirror = mpnt;
67323 + }
67324 + }
67325 + BUG_ON(mpnt_m);
67326 + }
67327 +#endif
67328 +
67329 /* a new mm has just been created */
67330 arch_dup_mmap(oldmm, mm);
67331 retval = 0;
67332 @@ -466,14 +519,6 @@ out:
67333 flush_tlb_mm(oldmm);
67334 up_write(&oldmm->mmap_sem);
67335 return retval;
67336 -fail_nomem_anon_vma_fork:
67337 - mpol_put(pol);
67338 -fail_nomem_policy:
67339 - kmem_cache_free(vm_area_cachep, tmp);
67340 -fail_nomem:
67341 - retval = -ENOMEM;
67342 - vm_unacct_memory(charge);
67343 - goto out;
67344 }
67345
67346 static inline int mm_alloc_pgd(struct mm_struct *mm)
67347 @@ -710,8 +755,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67348 return ERR_PTR(err);
67349
67350 mm = get_task_mm(task);
67351 - if (mm && mm != current->mm &&
67352 - !ptrace_may_access(task, mode)) {
67353 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67354 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67355 mmput(mm);
67356 mm = ERR_PTR(-EACCES);
67357 }
67358 @@ -932,13 +977,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67359 spin_unlock(&fs->lock);
67360 return -EAGAIN;
67361 }
67362 - fs->users++;
67363 + atomic_inc(&fs->users);
67364 spin_unlock(&fs->lock);
67365 return 0;
67366 }
67367 tsk->fs = copy_fs_struct(fs);
67368 if (!tsk->fs)
67369 return -ENOMEM;
67370 + /* Carry through gr_chroot_dentry and is_chrooted instead
67371 + of recomputing it here. Already copied when the task struct
67372 + is duplicated. This allows pivot_root to not be treated as
67373 + a chroot
67374 + */
67375 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
67376 +
67377 return 0;
67378 }
67379
67380 @@ -1205,6 +1257,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67381 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67382 #endif
67383 retval = -EAGAIN;
67384 +
67385 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67386 +
67387 if (atomic_read(&p->real_cred->user->processes) >=
67388 task_rlimit(p, RLIMIT_NPROC)) {
67389 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67390 @@ -1427,6 +1482,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67391 /* Need tasklist lock for parent etc handling! */
67392 write_lock_irq(&tasklist_lock);
67393
67394 + /* synchronizes with gr_set_acls() */
67395 + gr_copy_label(p);
67396 +
67397 /* CLONE_PARENT re-uses the old parent */
67398 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67399 p->real_parent = current->real_parent;
67400 @@ -1537,6 +1595,8 @@ bad_fork_cleanup_count:
67401 bad_fork_free:
67402 free_task(p);
67403 fork_out:
67404 + gr_log_forkfail(retval);
67405 +
67406 return ERR_PTR(retval);
67407 }
67408
67409 @@ -1637,6 +1697,8 @@ long do_fork(unsigned long clone_flags,
67410 if (clone_flags & CLONE_PARENT_SETTID)
67411 put_user(nr, parent_tidptr);
67412
67413 + gr_handle_brute_check();
67414 +
67415 if (clone_flags & CLONE_VFORK) {
67416 p->vfork_done = &vfork;
67417 init_completion(&vfork);
67418 @@ -1735,7 +1797,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67419 return 0;
67420
67421 /* don't need lock here; in the worst case we'll do useless copy */
67422 - if (fs->users == 1)
67423 + if (atomic_read(&fs->users) == 1)
67424 return 0;
67425
67426 *new_fsp = copy_fs_struct(fs);
67427 @@ -1824,7 +1886,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67428 fs = current->fs;
67429 spin_lock(&fs->lock);
67430 current->fs = new_fs;
67431 - if (--fs->users)
67432 + gr_set_chroot_entries(current, &current->fs->root);
67433 + if (atomic_dec_return(&fs->users))
67434 new_fs = NULL;
67435 else
67436 new_fs = fs;
67437 diff --git a/kernel/futex.c b/kernel/futex.c
67438 index 3717e7b..473c750 100644
67439 --- a/kernel/futex.c
67440 +++ b/kernel/futex.c
67441 @@ -54,6 +54,7 @@
67442 #include <linux/mount.h>
67443 #include <linux/pagemap.h>
67444 #include <linux/syscalls.h>
67445 +#include <linux/ptrace.h>
67446 #include <linux/signal.h>
67447 #include <linux/export.h>
67448 #include <linux/magic.h>
67449 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67450 struct page *page, *page_head;
67451 int err, ro = 0;
67452
67453 +#ifdef CONFIG_PAX_SEGMEXEC
67454 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67455 + return -EFAULT;
67456 +#endif
67457 +
67458 /*
67459 * The futex address must be "naturally" aligned.
67460 */
67461 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67462 {
67463 u32 curval;
67464 int i;
67465 + mm_segment_t oldfs;
67466
67467 /*
67468 * This will fail and we want it. Some arch implementations do
67469 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67470 * implementation, the non-functional ones will return
67471 * -ENOSYS.
67472 */
67473 + oldfs = get_fs();
67474 + set_fs(USER_DS);
67475 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67476 futex_cmpxchg_enabled = 1;
67477 + set_fs(oldfs);
67478
67479 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67480 plist_head_init(&futex_queues[i].chain);
67481 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67482 index 9b22d03..6295b62 100644
67483 --- a/kernel/gcov/base.c
67484 +++ b/kernel/gcov/base.c
67485 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67486 }
67487
67488 #ifdef CONFIG_MODULES
67489 -static inline int within(void *addr, void *start, unsigned long size)
67490 -{
67491 - return ((addr >= start) && (addr < start + size));
67492 -}
67493 -
67494 /* Update list and generate events when modules are unloaded. */
67495 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67496 void *data)
67497 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67498 prev = NULL;
67499 /* Remove entries located in module from linked list. */
67500 for (info = gcov_info_head; info; info = info->next) {
67501 - if (within(info, mod->module_core, mod->core_size)) {
67502 + if (within_module_core_rw((unsigned long)info, mod)) {
67503 if (prev)
67504 prev->next = info->next;
67505 else
67506 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67507 index 6db7a5e..25b6648 100644
67508 --- a/kernel/hrtimer.c
67509 +++ b/kernel/hrtimer.c
67510 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67511 local_irq_restore(flags);
67512 }
67513
67514 -static void run_hrtimer_softirq(struct softirq_action *h)
67515 +static void run_hrtimer_softirq(void)
67516 {
67517 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67518
67519 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67520 index 4304919..408c4c0 100644
67521 --- a/kernel/jump_label.c
67522 +++ b/kernel/jump_label.c
67523 @@ -13,6 +13,7 @@
67524 #include <linux/sort.h>
67525 #include <linux/err.h>
67526 #include <linux/static_key.h>
67527 +#include <linux/mm.h>
67528
67529 #ifdef HAVE_JUMP_LABEL
67530
67531 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67532
67533 size = (((unsigned long)stop - (unsigned long)start)
67534 / sizeof(struct jump_entry));
67535 + pax_open_kernel();
67536 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67537 + pax_close_kernel();
67538 }
67539
67540 static void jump_label_update(struct static_key *key, int enable);
67541 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67542 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67543 struct jump_entry *iter;
67544
67545 + pax_open_kernel();
67546 for (iter = iter_start; iter < iter_stop; iter++) {
67547 if (within_module_init(iter->code, mod))
67548 iter->code = 0;
67549 }
67550 + pax_close_kernel();
67551 }
67552
67553 static int
67554 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67555 index 2169fee..45c017a 100644
67556 --- a/kernel/kallsyms.c
67557 +++ b/kernel/kallsyms.c
67558 @@ -11,6 +11,9 @@
67559 * Changed the compression method from stem compression to "table lookup"
67560 * compression (see scripts/kallsyms.c for a more complete description)
67561 */
67562 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67563 +#define __INCLUDED_BY_HIDESYM 1
67564 +#endif
67565 #include <linux/kallsyms.h>
67566 #include <linux/module.h>
67567 #include <linux/init.h>
67568 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67569
67570 static inline int is_kernel_inittext(unsigned long addr)
67571 {
67572 + if (system_state != SYSTEM_BOOTING)
67573 + return 0;
67574 +
67575 if (addr >= (unsigned long)_sinittext
67576 && addr <= (unsigned long)_einittext)
67577 return 1;
67578 return 0;
67579 }
67580
67581 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67582 +#ifdef CONFIG_MODULES
67583 +static inline int is_module_text(unsigned long addr)
67584 +{
67585 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67586 + return 1;
67587 +
67588 + addr = ktla_ktva(addr);
67589 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67590 +}
67591 +#else
67592 +static inline int is_module_text(unsigned long addr)
67593 +{
67594 + return 0;
67595 +}
67596 +#endif
67597 +#endif
67598 +
67599 static inline int is_kernel_text(unsigned long addr)
67600 {
67601 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67602 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67603
67604 static inline int is_kernel(unsigned long addr)
67605 {
67606 +
67607 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67608 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67609 + return 1;
67610 +
67611 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67612 +#else
67613 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67614 +#endif
67615 +
67616 return 1;
67617 return in_gate_area_no_mm(addr);
67618 }
67619
67620 static int is_ksym_addr(unsigned long addr)
67621 {
67622 +
67623 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67624 + if (is_module_text(addr))
67625 + return 0;
67626 +#endif
67627 +
67628 if (all_var)
67629 return is_kernel(addr);
67630
67631 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67632
67633 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67634 {
67635 - iter->name[0] = '\0';
67636 iter->nameoff = get_symbol_offset(new_pos);
67637 iter->pos = new_pos;
67638 }
67639 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67640 {
67641 struct kallsym_iter *iter = m->private;
67642
67643 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67644 + if (current_uid())
67645 + return 0;
67646 +#endif
67647 +
67648 /* Some debugging symbols have no name. Ignore them. */
67649 if (!iter->name[0])
67650 return 0;
67651 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67652 */
67653 type = iter->exported ? toupper(iter->type) :
67654 tolower(iter->type);
67655 +
67656 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67657 type, iter->name, iter->module_name);
67658 } else
67659 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67660 struct kallsym_iter *iter;
67661 int ret;
67662
67663 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67664 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67665 if (!iter)
67666 return -ENOMEM;
67667 reset_iter(iter, 0);
67668 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
67669 index 30b7b22..c726387 100644
67670 --- a/kernel/kcmp.c
67671 +++ b/kernel/kcmp.c
67672 @@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
67673 struct task_struct *task1, *task2;
67674 int ret;
67675
67676 +#ifdef CONFIG_GRKERNSEC
67677 + return -ENOSYS;
67678 +#endif
67679 +
67680 rcu_read_lock();
67681
67682 /*
67683 diff --git a/kernel/kexec.c b/kernel/kexec.c
67684 index 0668d58..591b6fc 100644
67685 --- a/kernel/kexec.c
67686 +++ b/kernel/kexec.c
67687 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67688 unsigned long flags)
67689 {
67690 struct compat_kexec_segment in;
67691 - struct kexec_segment out, __user *ksegments;
67692 + struct kexec_segment out;
67693 + struct kexec_segment __user *ksegments;
67694 unsigned long i, result;
67695
67696 /* Don't allow clients that don't understand the native
67697 diff --git a/kernel/kmod.c b/kernel/kmod.c
67698 index 6f99aea..eb6e3a0 100644
67699 --- a/kernel/kmod.c
67700 +++ b/kernel/kmod.c
67701 @@ -73,7 +73,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67702 kfree(info->argv);
67703 }
67704
67705 -static int call_modprobe(char *module_name, int wait)
67706 +static int call_modprobe(char *module_name, char *module_param, int wait)
67707 {
67708 static char *envp[] = {
67709 "HOME=/",
67710 @@ -82,7 +82,7 @@ static int call_modprobe(char *module_name, int wait)
67711 NULL
67712 };
67713
67714 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67715 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67716 if (!argv)
67717 goto out;
67718
67719 @@ -94,7 +94,8 @@ static int call_modprobe(char *module_name, int wait)
67720 argv[1] = "-q";
67721 argv[2] = "--";
67722 argv[3] = module_name; /* check free_modprobe_argv() */
67723 - argv[4] = NULL;
67724 + argv[4] = module_param;
67725 + argv[5] = NULL;
67726
67727 return call_usermodehelper_fns(modprobe_path, argv, envp,
67728 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67729 @@ -119,9 +120,8 @@ out:
67730 * If module auto-loading support is disabled then this function
67731 * becomes a no-operation.
67732 */
67733 -int __request_module(bool wait, const char *fmt, ...)
67734 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67735 {
67736 - va_list args;
67737 char module_name[MODULE_NAME_LEN];
67738 unsigned int max_modprobes;
67739 int ret;
67740 @@ -129,9 +129,7 @@ int __request_module(bool wait, const char *fmt, ...)
67741 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67742 static int kmod_loop_msg;
67743
67744 - va_start(args, fmt);
67745 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67746 - va_end(args);
67747 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67748 if (ret >= MODULE_NAME_LEN)
67749 return -ENAMETOOLONG;
67750
67751 @@ -139,6 +137,20 @@ int __request_module(bool wait, const char *fmt, ...)
67752 if (ret)
67753 return ret;
67754
67755 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67756 + if (!current_uid()) {
67757 + /* hack to workaround consolekit/udisks stupidity */
67758 + read_lock(&tasklist_lock);
67759 + if (!strcmp(current->comm, "mount") &&
67760 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67761 + read_unlock(&tasklist_lock);
67762 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67763 + return -EPERM;
67764 + }
67765 + read_unlock(&tasklist_lock);
67766 + }
67767 +#endif
67768 +
67769 /* If modprobe needs a service that is in a module, we get a recursive
67770 * loop. Limit the number of running kmod threads to max_threads/2 or
67771 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67772 @@ -167,11 +179,52 @@ int __request_module(bool wait, const char *fmt, ...)
67773
67774 trace_module_request(module_name, wait, _RET_IP_);
67775
67776 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67777 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67778
67779 atomic_dec(&kmod_concurrent);
67780 return ret;
67781 }
67782 +
67783 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67784 +{
67785 + va_list args;
67786 + int ret;
67787 +
67788 + va_start(args, fmt);
67789 + ret = ____request_module(wait, module_param, fmt, args);
67790 + va_end(args);
67791 +
67792 + return ret;
67793 +}
67794 +
67795 +int __request_module(bool wait, const char *fmt, ...)
67796 +{
67797 + va_list args;
67798 + int ret;
67799 +
67800 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67801 + if (current_uid()) {
67802 + char module_param[MODULE_NAME_LEN];
67803 +
67804 + memset(module_param, 0, sizeof(module_param));
67805 +
67806 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67807 +
67808 + va_start(args, fmt);
67809 + ret = ____request_module(wait, module_param, fmt, args);
67810 + va_end(args);
67811 +
67812 + return ret;
67813 + }
67814 +#endif
67815 +
67816 + va_start(args, fmt);
67817 + ret = ____request_module(wait, NULL, fmt, args);
67818 + va_end(args);
67819 +
67820 + return ret;
67821 +}
67822 +
67823 EXPORT_SYMBOL(__request_module);
67824 #endif /* CONFIG_MODULES */
67825
67826 @@ -280,7 +333,7 @@ static int wait_for_helper(void *data)
67827 *
67828 * Thus the __user pointer cast is valid here.
67829 */
67830 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67831 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67832
67833 /*
67834 * If ret is 0, either ____call_usermodehelper failed and the
67835 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67836 index c62b854..6fc810d 100644
67837 --- a/kernel/kprobes.c
67838 +++ b/kernel/kprobes.c
67839 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67840 * kernel image and loaded module images reside. This is required
67841 * so x86_64 can correctly handle the %rip-relative fixups.
67842 */
67843 - kip->insns = module_alloc(PAGE_SIZE);
67844 + kip->insns = module_alloc_exec(PAGE_SIZE);
67845 if (!kip->insns) {
67846 kfree(kip);
67847 return NULL;
67848 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67849 */
67850 if (!list_is_singular(&kip->list)) {
67851 list_del(&kip->list);
67852 - module_free(NULL, kip->insns);
67853 + module_free_exec(NULL, kip->insns);
67854 kfree(kip);
67855 }
67856 return 1;
67857 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67858 {
67859 int i, err = 0;
67860 unsigned long offset = 0, size = 0;
67861 - char *modname, namebuf[128];
67862 + char *modname, namebuf[KSYM_NAME_LEN];
67863 const char *symbol_name;
67864 void *addr;
67865 struct kprobe_blackpoint *kb;
67866 @@ -2040,11 +2040,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
67867 kprobe_type = "k";
67868
67869 if (sym)
67870 - seq_printf(pi, "%p %s %s+0x%x %s ",
67871 + seq_printf(pi, "%pK %s %s+0x%x %s ",
67872 p->addr, kprobe_type, sym, offset,
67873 (modname ? modname : " "));
67874 else
67875 - seq_printf(pi, "%p %s %p ",
67876 + seq_printf(pi, "%pK %s %pK ",
67877 p->addr, kprobe_type, p->addr);
67878
67879 if (!pp)
67880 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
67881 const char *sym = NULL;
67882 unsigned int i = *(loff_t *) v;
67883 unsigned long offset = 0;
67884 - char *modname, namebuf[128];
67885 + char *modname, namebuf[KSYM_NAME_LEN];
67886
67887 head = &kprobe_table[i];
67888 preempt_disable();
67889 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
67890 index 4e316e1..5501eef 100644
67891 --- a/kernel/ksysfs.c
67892 +++ b/kernel/ksysfs.c
67893 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
67894 {
67895 if (count+1 > UEVENT_HELPER_PATH_LEN)
67896 return -ENOENT;
67897 + if (!capable(CAP_SYS_ADMIN))
67898 + return -EPERM;
67899 memcpy(uevent_helper, buf, count);
67900 uevent_helper[count] = '\0';
67901 if (count && uevent_helper[count-1] == '\n')
67902 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
67903 index ea9ee45..67ebc8f 100644
67904 --- a/kernel/lockdep.c
67905 +++ b/kernel/lockdep.c
67906 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
67907 end = (unsigned long) &_end,
67908 addr = (unsigned long) obj;
67909
67910 +#ifdef CONFIG_PAX_KERNEXEC
67911 + start = ktla_ktva(start);
67912 +#endif
67913 +
67914 /*
67915 * static variable?
67916 */
67917 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
67918 if (!static_obj(lock->key)) {
67919 debug_locks_off();
67920 printk("INFO: trying to register non-static key.\n");
67921 + printk("lock:%pS key:%pS.\n", lock, lock->key);
67922 printk("the code is fine but needs lockdep annotation.\n");
67923 printk("turning off the locking correctness validator.\n");
67924 dump_stack();
67925 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
67926 if (!class)
67927 return 0;
67928 }
67929 - atomic_inc((atomic_t *)&class->ops);
67930 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
67931 if (very_verbose(class)) {
67932 printk("\nacquire class [%p] %s", class->key, class->name);
67933 if (class->name_version > 1)
67934 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
67935 index 91c32a0..7b88d63 100644
67936 --- a/kernel/lockdep_proc.c
67937 +++ b/kernel/lockdep_proc.c
67938 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
67939
67940 static void print_name(struct seq_file *m, struct lock_class *class)
67941 {
67942 - char str[128];
67943 + char str[KSYM_NAME_LEN];
67944 const char *name = class->name;
67945
67946 if (!name) {
67947 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
67948 return 0;
67949 }
67950
67951 - seq_printf(m, "%p", class->key);
67952 + seq_printf(m, "%pK", class->key);
67953 #ifdef CONFIG_DEBUG_LOCKDEP
67954 seq_printf(m, " OPS:%8ld", class->ops);
67955 #endif
67956 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
67957
67958 list_for_each_entry(entry, &class->locks_after, entry) {
67959 if (entry->distance == 1) {
67960 - seq_printf(m, " -> [%p] ", entry->class->key);
67961 + seq_printf(m, " -> [%pK] ", entry->class->key);
67962 print_name(m, entry->class);
67963 seq_puts(m, "\n");
67964 }
67965 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
67966 if (!class->key)
67967 continue;
67968
67969 - seq_printf(m, "[%p] ", class->key);
67970 + seq_printf(m, "[%pK] ", class->key);
67971 print_name(m, class);
67972 seq_puts(m, "\n");
67973 }
67974 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67975 if (!i)
67976 seq_line(m, '-', 40-namelen, namelen);
67977
67978 - snprintf(ip, sizeof(ip), "[<%p>]",
67979 + snprintf(ip, sizeof(ip), "[<%pK>]",
67980 (void *)class->contention_point[i]);
67981 seq_printf(m, "%40s %14lu %29s %pS\n",
67982 name, stats->contention_point[i],
67983 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
67984 if (!i)
67985 seq_line(m, '-', 40-namelen, namelen);
67986
67987 - snprintf(ip, sizeof(ip), "[<%p>]",
67988 + snprintf(ip, sizeof(ip), "[<%pK>]",
67989 (void *)class->contending_point[i]);
67990 seq_printf(m, "%40s %14lu %29s %pS\n",
67991 name, stats->contending_point[i],
67992 diff --git a/kernel/module.c b/kernel/module.c
67993 index 4edbd9c..165e780 100644
67994 --- a/kernel/module.c
67995 +++ b/kernel/module.c
67996 @@ -58,6 +58,7 @@
67997 #include <linux/jump_label.h>
67998 #include <linux/pfn.h>
67999 #include <linux/bsearch.h>
68000 +#include <linux/grsecurity.h>
68001
68002 #define CREATE_TRACE_POINTS
68003 #include <trace/events/module.h>
68004 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68005
68006 /* Bounds of module allocation, for speeding __module_address.
68007 * Protected by module_mutex. */
68008 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68009 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68010 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68011
68012 int register_module_notifier(struct notifier_block * nb)
68013 {
68014 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68015 return true;
68016
68017 list_for_each_entry_rcu(mod, &modules, list) {
68018 - struct symsearch arr[] = {
68019 + struct symsearch modarr[] = {
68020 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68021 NOT_GPL_ONLY, false },
68022 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68023 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68024 #endif
68025 };
68026
68027 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68028 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68029 return true;
68030 }
68031 return false;
68032 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68033 static int percpu_modalloc(struct module *mod,
68034 unsigned long size, unsigned long align)
68035 {
68036 - if (align > PAGE_SIZE) {
68037 + if (align-1 >= PAGE_SIZE) {
68038 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68039 mod->name, align, PAGE_SIZE);
68040 align = PAGE_SIZE;
68041 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68042 static ssize_t show_coresize(struct module_attribute *mattr,
68043 struct module_kobject *mk, char *buffer)
68044 {
68045 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68046 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68047 }
68048
68049 static struct module_attribute modinfo_coresize =
68050 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68051 static ssize_t show_initsize(struct module_attribute *mattr,
68052 struct module_kobject *mk, char *buffer)
68053 {
68054 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68055 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68056 }
68057
68058 static struct module_attribute modinfo_initsize =
68059 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68060 */
68061 #ifdef CONFIG_SYSFS
68062
68063 -#ifdef CONFIG_KALLSYMS
68064 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68065 static inline bool sect_empty(const Elf_Shdr *sect)
68066 {
68067 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68068 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68069
68070 static void unset_module_core_ro_nx(struct module *mod)
68071 {
68072 - set_page_attributes(mod->module_core + mod->core_text_size,
68073 - mod->module_core + mod->core_size,
68074 + set_page_attributes(mod->module_core_rw,
68075 + mod->module_core_rw + mod->core_size_rw,
68076 set_memory_x);
68077 - set_page_attributes(mod->module_core,
68078 - mod->module_core + mod->core_ro_size,
68079 + set_page_attributes(mod->module_core_rx,
68080 + mod->module_core_rx + mod->core_size_rx,
68081 set_memory_rw);
68082 }
68083
68084 static void unset_module_init_ro_nx(struct module *mod)
68085 {
68086 - set_page_attributes(mod->module_init + mod->init_text_size,
68087 - mod->module_init + mod->init_size,
68088 + set_page_attributes(mod->module_init_rw,
68089 + mod->module_init_rw + mod->init_size_rw,
68090 set_memory_x);
68091 - set_page_attributes(mod->module_init,
68092 - mod->module_init + mod->init_ro_size,
68093 + set_page_attributes(mod->module_init_rx,
68094 + mod->module_init_rx + mod->init_size_rx,
68095 set_memory_rw);
68096 }
68097
68098 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68099
68100 mutex_lock(&module_mutex);
68101 list_for_each_entry_rcu(mod, &modules, list) {
68102 - if ((mod->module_core) && (mod->core_text_size)) {
68103 - set_page_attributes(mod->module_core,
68104 - mod->module_core + mod->core_text_size,
68105 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68106 + set_page_attributes(mod->module_core_rx,
68107 + mod->module_core_rx + mod->core_size_rx,
68108 set_memory_rw);
68109 }
68110 - if ((mod->module_init) && (mod->init_text_size)) {
68111 - set_page_attributes(mod->module_init,
68112 - mod->module_init + mod->init_text_size,
68113 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68114 + set_page_attributes(mod->module_init_rx,
68115 + mod->module_init_rx + mod->init_size_rx,
68116 set_memory_rw);
68117 }
68118 }
68119 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68120
68121 mutex_lock(&module_mutex);
68122 list_for_each_entry_rcu(mod, &modules, list) {
68123 - if ((mod->module_core) && (mod->core_text_size)) {
68124 - set_page_attributes(mod->module_core,
68125 - mod->module_core + mod->core_text_size,
68126 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68127 + set_page_attributes(mod->module_core_rx,
68128 + mod->module_core_rx + mod->core_size_rx,
68129 set_memory_ro);
68130 }
68131 - if ((mod->module_init) && (mod->init_text_size)) {
68132 - set_page_attributes(mod->module_init,
68133 - mod->module_init + mod->init_text_size,
68134 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68135 + set_page_attributes(mod->module_init_rx,
68136 + mod->module_init_rx + mod->init_size_rx,
68137 set_memory_ro);
68138 }
68139 }
68140 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68141
68142 /* This may be NULL, but that's OK */
68143 unset_module_init_ro_nx(mod);
68144 - module_free(mod, mod->module_init);
68145 + module_free(mod, mod->module_init_rw);
68146 + module_free_exec(mod, mod->module_init_rx);
68147 kfree(mod->args);
68148 percpu_modfree(mod);
68149
68150 /* Free lock-classes: */
68151 - lockdep_free_key_range(mod->module_core, mod->core_size);
68152 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68153 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68154
68155 /* Finally, free the core (containing the module structure) */
68156 unset_module_core_ro_nx(mod);
68157 - module_free(mod, mod->module_core);
68158 + module_free_exec(mod, mod->module_core_rx);
68159 + module_free(mod, mod->module_core_rw);
68160
68161 #ifdef CONFIG_MPU
68162 update_protections(current->mm);
68163 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68164 int ret = 0;
68165 const struct kernel_symbol *ksym;
68166
68167 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68168 + int is_fs_load = 0;
68169 + int register_filesystem_found = 0;
68170 + char *p;
68171 +
68172 + p = strstr(mod->args, "grsec_modharden_fs");
68173 + if (p) {
68174 + char *endptr = p + strlen("grsec_modharden_fs");
68175 + /* copy \0 as well */
68176 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68177 + is_fs_load = 1;
68178 + }
68179 +#endif
68180 +
68181 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68182 const char *name = info->strtab + sym[i].st_name;
68183
68184 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68185 + /* it's a real shame this will never get ripped and copied
68186 + upstream! ;(
68187 + */
68188 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68189 + register_filesystem_found = 1;
68190 +#endif
68191 +
68192 switch (sym[i].st_shndx) {
68193 case SHN_COMMON:
68194 /* We compiled with -fno-common. These are not
68195 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68196 ksym = resolve_symbol_wait(mod, info, name);
68197 /* Ok if resolved. */
68198 if (ksym && !IS_ERR(ksym)) {
68199 + pax_open_kernel();
68200 sym[i].st_value = ksym->value;
68201 + pax_close_kernel();
68202 break;
68203 }
68204
68205 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68206 secbase = (unsigned long)mod_percpu(mod);
68207 else
68208 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68209 + pax_open_kernel();
68210 sym[i].st_value += secbase;
68211 + pax_close_kernel();
68212 break;
68213 }
68214 }
68215
68216 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68217 + if (is_fs_load && !register_filesystem_found) {
68218 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68219 + ret = -EPERM;
68220 + }
68221 +#endif
68222 +
68223 return ret;
68224 }
68225
68226 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68227 || s->sh_entsize != ~0UL
68228 || strstarts(sname, ".init"))
68229 continue;
68230 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68231 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68232 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68233 + else
68234 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68235 pr_debug("\t%s\n", sname);
68236 }
68237 - switch (m) {
68238 - case 0: /* executable */
68239 - mod->core_size = debug_align(mod->core_size);
68240 - mod->core_text_size = mod->core_size;
68241 - break;
68242 - case 1: /* RO: text and ro-data */
68243 - mod->core_size = debug_align(mod->core_size);
68244 - mod->core_ro_size = mod->core_size;
68245 - break;
68246 - case 3: /* whole core */
68247 - mod->core_size = debug_align(mod->core_size);
68248 - break;
68249 - }
68250 }
68251
68252 pr_debug("Init section allocation order:\n");
68253 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68254 || s->sh_entsize != ~0UL
68255 || !strstarts(sname, ".init"))
68256 continue;
68257 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68258 - | INIT_OFFSET_MASK);
68259 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68260 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68261 + else
68262 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68263 + s->sh_entsize |= INIT_OFFSET_MASK;
68264 pr_debug("\t%s\n", sname);
68265 }
68266 - switch (m) {
68267 - case 0: /* executable */
68268 - mod->init_size = debug_align(mod->init_size);
68269 - mod->init_text_size = mod->init_size;
68270 - break;
68271 - case 1: /* RO: text and ro-data */
68272 - mod->init_size = debug_align(mod->init_size);
68273 - mod->init_ro_size = mod->init_size;
68274 - break;
68275 - case 3: /* whole init */
68276 - mod->init_size = debug_align(mod->init_size);
68277 - break;
68278 - }
68279 }
68280 }
68281
68282 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68283
68284 /* Put symbol section at end of init part of module. */
68285 symsect->sh_flags |= SHF_ALLOC;
68286 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68287 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68288 info->index.sym) | INIT_OFFSET_MASK;
68289 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68290
68291 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68292 }
68293
68294 /* Append room for core symbols at end of core part. */
68295 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68296 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68297 - mod->core_size += strtab_size;
68298 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68299 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68300 + mod->core_size_rx += strtab_size;
68301
68302 /* Put string table section at end of init part of module. */
68303 strsect->sh_flags |= SHF_ALLOC;
68304 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68305 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68306 info->index.str) | INIT_OFFSET_MASK;
68307 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68308 }
68309 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68310 /* Make sure we get permanent strtab: don't use info->strtab. */
68311 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68312
68313 + pax_open_kernel();
68314 +
68315 /* Set types up while we still have access to sections. */
68316 for (i = 0; i < mod->num_symtab; i++)
68317 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68318
68319 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68320 - mod->core_strtab = s = mod->module_core + info->stroffs;
68321 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68322 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68323 src = mod->symtab;
68324 *dst = *src;
68325 *s++ = 0;
68326 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68327 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68328 }
68329 mod->core_num_syms = ndst;
68330 +
68331 + pax_close_kernel();
68332 }
68333 #else
68334 static inline void layout_symtab(struct module *mod, struct load_info *info)
68335 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68336 return size == 0 ? NULL : vmalloc_exec(size);
68337 }
68338
68339 -static void *module_alloc_update_bounds(unsigned long size)
68340 +static void *module_alloc_update_bounds_rw(unsigned long size)
68341 {
68342 void *ret = module_alloc(size);
68343
68344 if (ret) {
68345 mutex_lock(&module_mutex);
68346 /* Update module bounds. */
68347 - if ((unsigned long)ret < module_addr_min)
68348 - module_addr_min = (unsigned long)ret;
68349 - if ((unsigned long)ret + size > module_addr_max)
68350 - module_addr_max = (unsigned long)ret + size;
68351 + if ((unsigned long)ret < module_addr_min_rw)
68352 + module_addr_min_rw = (unsigned long)ret;
68353 + if ((unsigned long)ret + size > module_addr_max_rw)
68354 + module_addr_max_rw = (unsigned long)ret + size;
68355 + mutex_unlock(&module_mutex);
68356 + }
68357 + return ret;
68358 +}
68359 +
68360 +static void *module_alloc_update_bounds_rx(unsigned long size)
68361 +{
68362 + void *ret = module_alloc_exec(size);
68363 +
68364 + if (ret) {
68365 + mutex_lock(&module_mutex);
68366 + /* Update module bounds. */
68367 + if ((unsigned long)ret < module_addr_min_rx)
68368 + module_addr_min_rx = (unsigned long)ret;
68369 + if ((unsigned long)ret + size > module_addr_max_rx)
68370 + module_addr_max_rx = (unsigned long)ret + size;
68371 mutex_unlock(&module_mutex);
68372 }
68373 return ret;
68374 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68375 static int check_modinfo(struct module *mod, struct load_info *info)
68376 {
68377 const char *modmagic = get_modinfo(info, "vermagic");
68378 + const char *license = get_modinfo(info, "license");
68379 int err;
68380
68381 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68382 + if (!license || !license_is_gpl_compatible(license))
68383 + return -ENOEXEC;
68384 +#endif
68385 +
68386 /* This is allowed: modprobe --force will invalidate it. */
68387 if (!modmagic) {
68388 err = try_to_force_load(mod, "bad vermagic");
68389 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68390 }
68391
68392 /* Set up license info based on the info section */
68393 - set_license(mod, get_modinfo(info, "license"));
68394 + set_license(mod, license);
68395
68396 return 0;
68397 }
68398 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68399 void *ptr;
68400
68401 /* Do the allocs. */
68402 - ptr = module_alloc_update_bounds(mod->core_size);
68403 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68404 /*
68405 * The pointer to this block is stored in the module structure
68406 * which is inside the block. Just mark it as not being a
68407 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68408 if (!ptr)
68409 return -ENOMEM;
68410
68411 - memset(ptr, 0, mod->core_size);
68412 - mod->module_core = ptr;
68413 + memset(ptr, 0, mod->core_size_rw);
68414 + mod->module_core_rw = ptr;
68415
68416 - ptr = module_alloc_update_bounds(mod->init_size);
68417 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68418 /*
68419 * The pointer to this block is stored in the module structure
68420 * which is inside the block. This block doesn't need to be
68421 * scanned as it contains data and code that will be freed
68422 * after the module is initialized.
68423 */
68424 - kmemleak_ignore(ptr);
68425 - if (!ptr && mod->init_size) {
68426 - module_free(mod, mod->module_core);
68427 + kmemleak_not_leak(ptr);
68428 + if (!ptr && mod->init_size_rw) {
68429 + module_free(mod, mod->module_core_rw);
68430 return -ENOMEM;
68431 }
68432 - memset(ptr, 0, mod->init_size);
68433 - mod->module_init = ptr;
68434 + memset(ptr, 0, mod->init_size_rw);
68435 + mod->module_init_rw = ptr;
68436 +
68437 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68438 + kmemleak_not_leak(ptr);
68439 + if (!ptr) {
68440 + module_free(mod, mod->module_init_rw);
68441 + module_free(mod, mod->module_core_rw);
68442 + return -ENOMEM;
68443 + }
68444 +
68445 + pax_open_kernel();
68446 + memset(ptr, 0, mod->core_size_rx);
68447 + pax_close_kernel();
68448 + mod->module_core_rx = ptr;
68449 +
68450 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68451 + kmemleak_not_leak(ptr);
68452 + if (!ptr && mod->init_size_rx) {
68453 + module_free_exec(mod, mod->module_core_rx);
68454 + module_free(mod, mod->module_init_rw);
68455 + module_free(mod, mod->module_core_rw);
68456 + return -ENOMEM;
68457 + }
68458 +
68459 + pax_open_kernel();
68460 + memset(ptr, 0, mod->init_size_rx);
68461 + pax_close_kernel();
68462 + mod->module_init_rx = ptr;
68463
68464 /* Transfer each section which specifies SHF_ALLOC */
68465 pr_debug("final section addresses:\n");
68466 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68467 if (!(shdr->sh_flags & SHF_ALLOC))
68468 continue;
68469
68470 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68471 - dest = mod->module_init
68472 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68473 - else
68474 - dest = mod->module_core + shdr->sh_entsize;
68475 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68476 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68477 + dest = mod->module_init_rw
68478 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68479 + else
68480 + dest = mod->module_init_rx
68481 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68482 + } else {
68483 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68484 + dest = mod->module_core_rw + shdr->sh_entsize;
68485 + else
68486 + dest = mod->module_core_rx + shdr->sh_entsize;
68487 + }
68488 +
68489 + if (shdr->sh_type != SHT_NOBITS) {
68490 +
68491 +#ifdef CONFIG_PAX_KERNEXEC
68492 +#ifdef CONFIG_X86_64
68493 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68494 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68495 +#endif
68496 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68497 + pax_open_kernel();
68498 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68499 + pax_close_kernel();
68500 + } else
68501 +#endif
68502
68503 - if (shdr->sh_type != SHT_NOBITS)
68504 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68505 + }
68506 /* Update sh_addr to point to copy in image. */
68507 - shdr->sh_addr = (unsigned long)dest;
68508 +
68509 +#ifdef CONFIG_PAX_KERNEXEC
68510 + if (shdr->sh_flags & SHF_EXECINSTR)
68511 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68512 + else
68513 +#endif
68514 +
68515 + shdr->sh_addr = (unsigned long)dest;
68516 pr_debug("\t0x%lx %s\n",
68517 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68518 }
68519 @@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
68520 * Do it before processing of module parameters, so the module
68521 * can provide parameter accessor functions of its own.
68522 */
68523 - if (mod->module_init)
68524 - flush_icache_range((unsigned long)mod->module_init,
68525 - (unsigned long)mod->module_init
68526 - + mod->init_size);
68527 - flush_icache_range((unsigned long)mod->module_core,
68528 - (unsigned long)mod->module_core + mod->core_size);
68529 + if (mod->module_init_rx)
68530 + flush_icache_range((unsigned long)mod->module_init_rx,
68531 + (unsigned long)mod->module_init_rx
68532 + + mod->init_size_rx);
68533 + flush_icache_range((unsigned long)mod->module_core_rx,
68534 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68535
68536 set_fs(old_fs);
68537 }
68538 @@ -2834,8 +2934,10 @@ out:
68539 static void module_deallocate(struct module *mod, struct load_info *info)
68540 {
68541 percpu_modfree(mod);
68542 - module_free(mod, mod->module_init);
68543 - module_free(mod, mod->module_core);
68544 + module_free_exec(mod, mod->module_init_rx);
68545 + module_free_exec(mod, mod->module_core_rx);
68546 + module_free(mod, mod->module_init_rw);
68547 + module_free(mod, mod->module_core_rw);
68548 }
68549
68550 int __weak module_finalize(const Elf_Ehdr *hdr,
68551 @@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68552 static int post_relocation(struct module *mod, const struct load_info *info)
68553 {
68554 /* Sort exception table now relocations are done. */
68555 + pax_open_kernel();
68556 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68557 + pax_close_kernel();
68558
68559 /* Copy relocated percpu area over. */
68560 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68561 @@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
68562 if (err)
68563 goto free_unload;
68564
68565 + /* Now copy in args */
68566 + mod->args = strndup_user(uargs, ~0UL >> 1);
68567 + if (IS_ERR(mod->args)) {
68568 + err = PTR_ERR(mod->args);
68569 + goto free_unload;
68570 + }
68571 +
68572 /* Set up MODINFO_ATTR fields */
68573 setup_modinfo(mod, &info);
68574
68575 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68576 + {
68577 + char *p, *p2;
68578 +
68579 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68580 + 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);
68581 + err = -EPERM;
68582 + goto free_modinfo;
68583 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68584 + p += strlen("grsec_modharden_normal");
68585 + p2 = strstr(p, "_");
68586 + if (p2) {
68587 + *p2 = '\0';
68588 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68589 + *p2 = '_';
68590 + }
68591 + err = -EPERM;
68592 + goto free_modinfo;
68593 + }
68594 + }
68595 +#endif
68596 +
68597 /* Fix up syms, so that st_value is a pointer to location. */
68598 err = simplify_symbols(mod, &info);
68599 if (err < 0)
68600 @@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68601
68602 flush_module_icache(mod);
68603
68604 - /* Now copy in args */
68605 - mod->args = strndup_user(uargs, ~0UL >> 1);
68606 - if (IS_ERR(mod->args)) {
68607 - err = PTR_ERR(mod->args);
68608 - goto free_arch_cleanup;
68609 - }
68610 -
68611 /* Mark state as coming so strong_try_module_get() ignores us. */
68612 mod->state = MODULE_STATE_COMING;
68613
68614 @@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68615 unlock:
68616 mutex_unlock(&module_mutex);
68617 synchronize_sched();
68618 - kfree(mod->args);
68619 - free_arch_cleanup:
68620 module_arch_cleanup(mod);
68621 free_modinfo:
68622 free_modinfo(mod);
68623 + kfree(mod->args);
68624 free_unload:
68625 module_unload_free(mod);
68626 free_module:
68627 @@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68628 MODULE_STATE_COMING, mod);
68629
68630 /* Set RO and NX regions for core */
68631 - set_section_ro_nx(mod->module_core,
68632 - mod->core_text_size,
68633 - mod->core_ro_size,
68634 - mod->core_size);
68635 + set_section_ro_nx(mod->module_core_rx,
68636 + mod->core_size_rx,
68637 + mod->core_size_rx,
68638 + mod->core_size_rx);
68639
68640 /* Set RO and NX regions for init */
68641 - set_section_ro_nx(mod->module_init,
68642 - mod->init_text_size,
68643 - mod->init_ro_size,
68644 - mod->init_size);
68645 + set_section_ro_nx(mod->module_init_rx,
68646 + mod->init_size_rx,
68647 + mod->init_size_rx,
68648 + mod->init_size_rx);
68649
68650 do_mod_ctors(mod);
68651 /* Start the module */
68652 @@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68653 mod->strtab = mod->core_strtab;
68654 #endif
68655 unset_module_init_ro_nx(mod);
68656 - module_free(mod, mod->module_init);
68657 - mod->module_init = NULL;
68658 - mod->init_size = 0;
68659 - mod->init_ro_size = 0;
68660 - mod->init_text_size = 0;
68661 + module_free(mod, mod->module_init_rw);
68662 + module_free_exec(mod, mod->module_init_rx);
68663 + mod->module_init_rw = NULL;
68664 + mod->module_init_rx = NULL;
68665 + mod->init_size_rw = 0;
68666 + mod->init_size_rx = 0;
68667 mutex_unlock(&module_mutex);
68668
68669 return 0;
68670 @@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68671 unsigned long nextval;
68672
68673 /* At worse, next value is at end of module */
68674 - if (within_module_init(addr, mod))
68675 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68676 + if (within_module_init_rx(addr, mod))
68677 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68678 + else if (within_module_init_rw(addr, mod))
68679 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68680 + else if (within_module_core_rx(addr, mod))
68681 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68682 + else if (within_module_core_rw(addr, mod))
68683 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68684 else
68685 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68686 + return NULL;
68687
68688 /* Scan for closest preceding symbol, and next symbol. (ELF
68689 starts real symbols at 1). */
68690 @@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68691 char buf[8];
68692
68693 seq_printf(m, "%s %u",
68694 - mod->name, mod->init_size + mod->core_size);
68695 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68696 print_unload_info(m, mod);
68697
68698 /* Informative for users. */
68699 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68700 mod->state == MODULE_STATE_COMING ? "Loading":
68701 "Live");
68702 /* Used by oprofile and other similar tools. */
68703 - seq_printf(m, " 0x%pK", mod->module_core);
68704 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68705
68706 /* Taints info */
68707 if (mod->taints)
68708 @@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68709
68710 static int __init proc_modules_init(void)
68711 {
68712 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68713 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68714 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68715 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68716 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68717 +#else
68718 proc_create("modules", 0, NULL, &proc_modules_operations);
68719 +#endif
68720 +#else
68721 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68722 +#endif
68723 return 0;
68724 }
68725 module_init(proc_modules_init);
68726 @@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68727 {
68728 struct module *mod;
68729
68730 - if (addr < module_addr_min || addr > module_addr_max)
68731 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68732 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68733 return NULL;
68734
68735 list_for_each_entry_rcu(mod, &modules, list)
68736 - if (within_module_core(addr, mod)
68737 - || within_module_init(addr, mod))
68738 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68739 return mod;
68740 return NULL;
68741 }
68742 @@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68743 */
68744 struct module *__module_text_address(unsigned long addr)
68745 {
68746 - struct module *mod = __module_address(addr);
68747 + struct module *mod;
68748 +
68749 +#ifdef CONFIG_X86_32
68750 + addr = ktla_ktva(addr);
68751 +#endif
68752 +
68753 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68754 + return NULL;
68755 +
68756 + mod = __module_address(addr);
68757 +
68758 if (mod) {
68759 /* Make sure it's within the text section. */
68760 - if (!within(addr, mod->module_init, mod->init_text_size)
68761 - && !within(addr, mod->module_core, mod->core_text_size))
68762 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68763 mod = NULL;
68764 }
68765 return mod;
68766 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68767 index 7e3443f..b2a1e6b 100644
68768 --- a/kernel/mutex-debug.c
68769 +++ b/kernel/mutex-debug.c
68770 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68771 }
68772
68773 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68774 - struct thread_info *ti)
68775 + struct task_struct *task)
68776 {
68777 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68778
68779 /* Mark the current thread as blocked on the lock: */
68780 - ti->task->blocked_on = waiter;
68781 + task->blocked_on = waiter;
68782 }
68783
68784 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68785 - struct thread_info *ti)
68786 + struct task_struct *task)
68787 {
68788 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68789 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68790 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68791 - ti->task->blocked_on = NULL;
68792 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68793 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68794 + task->blocked_on = NULL;
68795
68796 list_del_init(&waiter->list);
68797 waiter->task = NULL;
68798 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68799 index 0799fd3..d06ae3b 100644
68800 --- a/kernel/mutex-debug.h
68801 +++ b/kernel/mutex-debug.h
68802 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68803 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68804 extern void debug_mutex_add_waiter(struct mutex *lock,
68805 struct mutex_waiter *waiter,
68806 - struct thread_info *ti);
68807 + struct task_struct *task);
68808 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68809 - struct thread_info *ti);
68810 + struct task_struct *task);
68811 extern void debug_mutex_unlock(struct mutex *lock);
68812 extern void debug_mutex_init(struct mutex *lock, const char *name,
68813 struct lock_class_key *key);
68814 diff --git a/kernel/mutex.c b/kernel/mutex.c
68815 index a307cc9..27fd2e9 100644
68816 --- a/kernel/mutex.c
68817 +++ b/kernel/mutex.c
68818 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68819 spin_lock_mutex(&lock->wait_lock, flags);
68820
68821 debug_mutex_lock_common(lock, &waiter);
68822 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68823 + debug_mutex_add_waiter(lock, &waiter, task);
68824
68825 /* add waiting tasks to the end of the waitqueue (FIFO): */
68826 list_add_tail(&waiter.list, &lock->wait_list);
68827 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68828 * TASK_UNINTERRUPTIBLE case.)
68829 */
68830 if (unlikely(signal_pending_state(state, task))) {
68831 - mutex_remove_waiter(lock, &waiter,
68832 - task_thread_info(task));
68833 + mutex_remove_waiter(lock, &waiter, task);
68834 mutex_release(&lock->dep_map, 1, ip);
68835 spin_unlock_mutex(&lock->wait_lock, flags);
68836
68837 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68838 done:
68839 lock_acquired(&lock->dep_map, ip);
68840 /* got the lock - rejoice! */
68841 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68842 + mutex_remove_waiter(lock, &waiter, task);
68843 mutex_set_owner(lock);
68844
68845 /* set it to 0 if there are no waiters left: */
68846 diff --git a/kernel/panic.c b/kernel/panic.c
68847 index e1b2822..5edc1d9 100644
68848 --- a/kernel/panic.c
68849 +++ b/kernel/panic.c
68850 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68851 const char *board;
68852
68853 printk(KERN_WARNING "------------[ cut here ]------------\n");
68854 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68855 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68856 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68857 if (board)
68858 printk(KERN_WARNING "Hardware name: %s\n", board);
68859 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68860 */
68861 void __stack_chk_fail(void)
68862 {
68863 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68864 + dump_stack();
68865 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68866 __builtin_return_address(0));
68867 }
68868 EXPORT_SYMBOL(__stack_chk_fail);
68869 diff --git a/kernel/pid.c b/kernel/pid.c
68870 index e86b291a..e8b0fb5 100644
68871 --- a/kernel/pid.c
68872 +++ b/kernel/pid.c
68873 @@ -33,6 +33,7 @@
68874 #include <linux/rculist.h>
68875 #include <linux/bootmem.h>
68876 #include <linux/hash.h>
68877 +#include <linux/security.h>
68878 #include <linux/pid_namespace.h>
68879 #include <linux/init_task.h>
68880 #include <linux/syscalls.h>
68881 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68882
68883 int pid_max = PID_MAX_DEFAULT;
68884
68885 -#define RESERVED_PIDS 300
68886 +#define RESERVED_PIDS 500
68887
68888 int pid_max_min = RESERVED_PIDS + 1;
68889 int pid_max_max = PID_MAX_LIMIT;
68890 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68891 */
68892 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68893 {
68894 + struct task_struct *task;
68895 +
68896 rcu_lockdep_assert(rcu_read_lock_held(),
68897 "find_task_by_pid_ns() needs rcu_read_lock()"
68898 " protection");
68899 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68900 +
68901 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68902 +
68903 + if (gr_pid_is_chrooted(task))
68904 + return NULL;
68905 +
68906 + return task;
68907 }
68908
68909 struct task_struct *find_task_by_vpid(pid_t vnr)
68910 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
68911 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
68912 }
68913
68914 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
68915 +{
68916 + rcu_lockdep_assert(rcu_read_lock_held(),
68917 + "find_task_by_pid_ns() needs rcu_read_lock()"
68918 + " protection");
68919 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
68920 +}
68921 +
68922 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
68923 {
68924 struct pid *pid;
68925 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
68926 index 125cb67..a4d1c30 100644
68927 --- a/kernel/posix-cpu-timers.c
68928 +++ b/kernel/posix-cpu-timers.c
68929 @@ -6,6 +6,7 @@
68930 #include <linux/posix-timers.h>
68931 #include <linux/errno.h>
68932 #include <linux/math64.h>
68933 +#include <linux/security.h>
68934 #include <asm/uaccess.h>
68935 #include <linux/kernel_stat.h>
68936 #include <trace/events/timer.h>
68937 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
68938
68939 static __init int init_posix_cpu_timers(void)
68940 {
68941 - struct k_clock process = {
68942 + static struct k_clock process = {
68943 .clock_getres = process_cpu_clock_getres,
68944 .clock_get = process_cpu_clock_get,
68945 .timer_create = process_cpu_timer_create,
68946 .nsleep = process_cpu_nsleep,
68947 .nsleep_restart = process_cpu_nsleep_restart,
68948 };
68949 - struct k_clock thread = {
68950 + static struct k_clock thread = {
68951 .clock_getres = thread_cpu_clock_getres,
68952 .clock_get = thread_cpu_clock_get,
68953 .timer_create = thread_cpu_timer_create,
68954 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
68955 index 69185ae..cc2847a 100644
68956 --- a/kernel/posix-timers.c
68957 +++ b/kernel/posix-timers.c
68958 @@ -43,6 +43,7 @@
68959 #include <linux/idr.h>
68960 #include <linux/posix-clock.h>
68961 #include <linux/posix-timers.h>
68962 +#include <linux/grsecurity.h>
68963 #include <linux/syscalls.h>
68964 #include <linux/wait.h>
68965 #include <linux/workqueue.h>
68966 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
68967 * which we beg off on and pass to do_sys_settimeofday().
68968 */
68969
68970 -static struct k_clock posix_clocks[MAX_CLOCKS];
68971 +static struct k_clock *posix_clocks[MAX_CLOCKS];
68972
68973 /*
68974 * These ones are defined below.
68975 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
68976 */
68977 static __init int init_posix_timers(void)
68978 {
68979 - struct k_clock clock_realtime = {
68980 + static struct k_clock clock_realtime = {
68981 .clock_getres = hrtimer_get_res,
68982 .clock_get = posix_clock_realtime_get,
68983 .clock_set = posix_clock_realtime_set,
68984 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
68985 .timer_get = common_timer_get,
68986 .timer_del = common_timer_del,
68987 };
68988 - struct k_clock clock_monotonic = {
68989 + static struct k_clock clock_monotonic = {
68990 .clock_getres = hrtimer_get_res,
68991 .clock_get = posix_ktime_get_ts,
68992 .nsleep = common_nsleep,
68993 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
68994 .timer_get = common_timer_get,
68995 .timer_del = common_timer_del,
68996 };
68997 - struct k_clock clock_monotonic_raw = {
68998 + static struct k_clock clock_monotonic_raw = {
68999 .clock_getres = hrtimer_get_res,
69000 .clock_get = posix_get_monotonic_raw,
69001 };
69002 - struct k_clock clock_realtime_coarse = {
69003 + static struct k_clock clock_realtime_coarse = {
69004 .clock_getres = posix_get_coarse_res,
69005 .clock_get = posix_get_realtime_coarse,
69006 };
69007 - struct k_clock clock_monotonic_coarse = {
69008 + static struct k_clock clock_monotonic_coarse = {
69009 .clock_getres = posix_get_coarse_res,
69010 .clock_get = posix_get_monotonic_coarse,
69011 };
69012 - struct k_clock clock_boottime = {
69013 + static struct k_clock clock_boottime = {
69014 .clock_getres = hrtimer_get_res,
69015 .clock_get = posix_get_boottime,
69016 .nsleep = common_nsleep,
69017 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69018 return;
69019 }
69020
69021 - posix_clocks[clock_id] = *new_clock;
69022 + posix_clocks[clock_id] = new_clock;
69023 }
69024 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69025
69026 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69027 return (id & CLOCKFD_MASK) == CLOCKFD ?
69028 &clock_posix_dynamic : &clock_posix_cpu;
69029
69030 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69031 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69032 return NULL;
69033 - return &posix_clocks[id];
69034 + return posix_clocks[id];
69035 }
69036
69037 static int common_timer_create(struct k_itimer *new_timer)
69038 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69039 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69040 return -EFAULT;
69041
69042 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69043 + have their clock_set fptr set to a nosettime dummy function
69044 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69045 + call common_clock_set, which calls do_sys_settimeofday, which
69046 + we hook
69047 + */
69048 +
69049 return kc->clock_set(which_clock, &new_tp);
69050 }
69051
69052 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69053 index d523593..68197a4 100644
69054 --- a/kernel/power/poweroff.c
69055 +++ b/kernel/power/poweroff.c
69056 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69057 .enable_mask = SYSRQ_ENABLE_BOOT,
69058 };
69059
69060 -static int pm_sysrq_init(void)
69061 +static int __init pm_sysrq_init(void)
69062 {
69063 register_sysrq_key('o', &sysrq_poweroff_op);
69064 return 0;
69065 diff --git a/kernel/power/process.c b/kernel/power/process.c
69066 index 19db29f..33b52b6 100644
69067 --- a/kernel/power/process.c
69068 +++ b/kernel/power/process.c
69069 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69070 u64 elapsed_csecs64;
69071 unsigned int elapsed_csecs;
69072 bool wakeup = false;
69073 + bool timedout = false;
69074
69075 do_gettimeofday(&start);
69076
69077 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69078
69079 while (true) {
69080 todo = 0;
69081 + if (time_after(jiffies, end_time))
69082 + timedout = true;
69083 read_lock(&tasklist_lock);
69084 do_each_thread(g, p) {
69085 if (p == current || !freeze_task(p))
69086 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69087 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69088 * transition can't race with task state testing here.
69089 */
69090 - if (!task_is_stopped_or_traced(p) &&
69091 - !freezer_should_skip(p))
69092 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69093 todo++;
69094 + if (timedout) {
69095 + printk(KERN_ERR "Task refusing to freeze:\n");
69096 + sched_show_task(p);
69097 + }
69098 + }
69099 } while_each_thread(g, p);
69100 read_unlock(&tasklist_lock);
69101
69102 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69103 todo += wq_busy;
69104 }
69105
69106 - if (!todo || time_after(jiffies, end_time))
69107 + if (!todo || timedout)
69108 break;
69109
69110 if (pm_wakeup_pending()) {
69111 diff --git a/kernel/printk.c b/kernel/printk.c
69112 index 66a2ea3..10f3a01 100644
69113 --- a/kernel/printk.c
69114 +++ b/kernel/printk.c
69115 @@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
69116 if (from_file && type != SYSLOG_ACTION_OPEN)
69117 return 0;
69118
69119 +#ifdef CONFIG_GRKERNSEC_DMESG
69120 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69121 + return -EPERM;
69122 +#endif
69123 +
69124 if (syslog_action_restricted(type)) {
69125 if (capable(CAP_SYSLOG))
69126 return 0;
69127 diff --git a/kernel/profile.c b/kernel/profile.c
69128 index 76b8e77..a2930e8 100644
69129 --- a/kernel/profile.c
69130 +++ b/kernel/profile.c
69131 @@ -39,7 +39,7 @@ struct profile_hit {
69132 /* Oprofile timer tick hook */
69133 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69134
69135 -static atomic_t *prof_buffer;
69136 +static atomic_unchecked_t *prof_buffer;
69137 static unsigned long prof_len, prof_shift;
69138
69139 int prof_on __read_mostly;
69140 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69141 hits[i].pc = 0;
69142 continue;
69143 }
69144 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69145 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69146 hits[i].hits = hits[i].pc = 0;
69147 }
69148 }
69149 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69150 * Add the current hit(s) and flush the write-queue out
69151 * to the global buffer:
69152 */
69153 - atomic_add(nr_hits, &prof_buffer[pc]);
69154 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69155 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69156 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69157 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69158 hits[i].pc = hits[i].hits = 0;
69159 }
69160 out:
69161 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69162 {
69163 unsigned long pc;
69164 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69165 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69166 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69167 }
69168 #endif /* !CONFIG_SMP */
69169
69170 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69171 return -EFAULT;
69172 buf++; p++; count--; read++;
69173 }
69174 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69175 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69176 if (copy_to_user(buf, (void *)pnt, count))
69177 return -EFAULT;
69178 read += count;
69179 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69180 }
69181 #endif
69182 profile_discard_flip_buffers();
69183 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69184 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69185 return count;
69186 }
69187
69188 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69189 index a232bb5..2a65ef9 100644
69190 --- a/kernel/ptrace.c
69191 +++ b/kernel/ptrace.c
69192 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69193
69194 if (seize)
69195 flags |= PT_SEIZED;
69196 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69197 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69198 flags |= PT_PTRACE_CAP;
69199 task->ptrace = flags;
69200
69201 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69202 break;
69203 return -EIO;
69204 }
69205 - if (copy_to_user(dst, buf, retval))
69206 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69207 return -EFAULT;
69208 copied += retval;
69209 src += retval;
69210 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69211 bool seized = child->ptrace & PT_SEIZED;
69212 int ret = -EIO;
69213 siginfo_t siginfo, *si;
69214 - void __user *datavp = (void __user *) data;
69215 + void __user *datavp = (__force void __user *) data;
69216 unsigned long __user *datalp = datavp;
69217 unsigned long flags;
69218
69219 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69220 goto out;
69221 }
69222
69223 + if (gr_handle_ptrace(child, request)) {
69224 + ret = -EPERM;
69225 + goto out_put_task_struct;
69226 + }
69227 +
69228 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69229 ret = ptrace_attach(child, request, addr, data);
69230 /*
69231 * Some architectures need to do book-keeping after
69232 * a ptrace attach.
69233 */
69234 - if (!ret)
69235 + if (!ret) {
69236 arch_ptrace_attach(child);
69237 + gr_audit_ptrace(child);
69238 + }
69239 goto out_put_task_struct;
69240 }
69241
69242 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69243 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69244 if (copied != sizeof(tmp))
69245 return -EIO;
69246 - return put_user(tmp, (unsigned long __user *)data);
69247 + return put_user(tmp, (__force unsigned long __user *)data);
69248 }
69249
69250 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69251 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69252 goto out;
69253 }
69254
69255 + if (gr_handle_ptrace(child, request)) {
69256 + ret = -EPERM;
69257 + goto out_put_task_struct;
69258 + }
69259 +
69260 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69261 ret = ptrace_attach(child, request, addr, data);
69262 /*
69263 * Some architectures need to do book-keeping after
69264 * a ptrace attach.
69265 */
69266 - if (!ret)
69267 + if (!ret) {
69268 arch_ptrace_attach(child);
69269 + gr_audit_ptrace(child);
69270 + }
69271 goto out_put_task_struct;
69272 }
69273
69274 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69275 index 547b1fe..65e874e 100644
69276 --- a/kernel/rcutiny.c
69277 +++ b/kernel/rcutiny.c
69278 @@ -46,7 +46,7 @@
69279 struct rcu_ctrlblk;
69280 static void invoke_rcu_callbacks(void);
69281 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69282 -static void rcu_process_callbacks(struct softirq_action *unused);
69283 +static void rcu_process_callbacks(void);
69284 static void __call_rcu(struct rcu_head *head,
69285 void (*func)(struct rcu_head *rcu),
69286 struct rcu_ctrlblk *rcp);
69287 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69288 rcu_is_callbacks_kthread()));
69289 }
69290
69291 -static void rcu_process_callbacks(struct softirq_action *unused)
69292 +static void rcu_process_callbacks(void)
69293 {
69294 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69295 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69296 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69297 index 918fd1e..85089bb 100644
69298 --- a/kernel/rcutiny_plugin.h
69299 +++ b/kernel/rcutiny_plugin.h
69300 @@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
69301 have_rcu_kthread_work = morework;
69302 local_irq_restore(flags);
69303 if (work)
69304 - rcu_process_callbacks(NULL);
69305 + rcu_process_callbacks();
69306 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69307 }
69308
69309 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69310 index 25b1503..1988a74 100644
69311 --- a/kernel/rcutorture.c
69312 +++ b/kernel/rcutorture.c
69313 @@ -162,12 +162,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69314 { 0 };
69315 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69316 { 0 };
69317 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69318 -static atomic_t n_rcu_torture_alloc;
69319 -static atomic_t n_rcu_torture_alloc_fail;
69320 -static atomic_t n_rcu_torture_free;
69321 -static atomic_t n_rcu_torture_mberror;
69322 -static atomic_t n_rcu_torture_error;
69323 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69324 +static atomic_unchecked_t n_rcu_torture_alloc;
69325 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69326 +static atomic_unchecked_t n_rcu_torture_free;
69327 +static atomic_unchecked_t n_rcu_torture_mberror;
69328 +static atomic_unchecked_t n_rcu_torture_error;
69329 static long n_rcu_torture_barrier_error;
69330 static long n_rcu_torture_boost_ktrerror;
69331 static long n_rcu_torture_boost_rterror;
69332 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69333
69334 spin_lock_bh(&rcu_torture_lock);
69335 if (list_empty(&rcu_torture_freelist)) {
69336 - atomic_inc(&n_rcu_torture_alloc_fail);
69337 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69338 spin_unlock_bh(&rcu_torture_lock);
69339 return NULL;
69340 }
69341 - atomic_inc(&n_rcu_torture_alloc);
69342 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69343 p = rcu_torture_freelist.next;
69344 list_del_init(p);
69345 spin_unlock_bh(&rcu_torture_lock);
69346 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69347 static void
69348 rcu_torture_free(struct rcu_torture *p)
69349 {
69350 - atomic_inc(&n_rcu_torture_free);
69351 + atomic_inc_unchecked(&n_rcu_torture_free);
69352 spin_lock_bh(&rcu_torture_lock);
69353 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69354 spin_unlock_bh(&rcu_torture_lock);
69355 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69356 i = rp->rtort_pipe_count;
69357 if (i > RCU_TORTURE_PIPE_LEN)
69358 i = RCU_TORTURE_PIPE_LEN;
69359 - atomic_inc(&rcu_torture_wcount[i]);
69360 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69361 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69362 rp->rtort_mbtest = 0;
69363 rcu_torture_free(rp);
69364 @@ -452,7 +452,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69365 i = rp->rtort_pipe_count;
69366 if (i > RCU_TORTURE_PIPE_LEN)
69367 i = RCU_TORTURE_PIPE_LEN;
69368 - atomic_inc(&rcu_torture_wcount[i]);
69369 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69370 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69371 rp->rtort_mbtest = 0;
69372 list_del(&rp->rtort_free);
69373 @@ -995,7 +995,7 @@ rcu_torture_writer(void *arg)
69374 i = old_rp->rtort_pipe_count;
69375 if (i > RCU_TORTURE_PIPE_LEN)
69376 i = RCU_TORTURE_PIPE_LEN;
69377 - atomic_inc(&rcu_torture_wcount[i]);
69378 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69379 old_rp->rtort_pipe_count++;
69380 cur_ops->deferred_free(old_rp);
69381 }
69382 @@ -1080,7 +1080,7 @@ static void rcu_torture_timer(unsigned long unused)
69383 }
69384 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69385 if (p->rtort_mbtest == 0)
69386 - atomic_inc(&n_rcu_torture_mberror);
69387 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69388 spin_lock(&rand_lock);
69389 cur_ops->read_delay(&rand);
69390 n_rcu_torture_timers++;
69391 @@ -1144,7 +1144,7 @@ rcu_torture_reader(void *arg)
69392 }
69393 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69394 if (p->rtort_mbtest == 0)
69395 - atomic_inc(&n_rcu_torture_mberror);
69396 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69397 cur_ops->read_delay(&rand);
69398 preempt_disable();
69399 pipe_count = p->rtort_pipe_count;
69400 @@ -1203,11 +1203,11 @@ rcu_torture_printk(char *page)
69401 rcu_torture_current,
69402 rcu_torture_current_version,
69403 list_empty(&rcu_torture_freelist),
69404 - atomic_read(&n_rcu_torture_alloc),
69405 - atomic_read(&n_rcu_torture_alloc_fail),
69406 - atomic_read(&n_rcu_torture_free));
69407 + atomic_read_unchecked(&n_rcu_torture_alloc),
69408 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69409 + atomic_read_unchecked(&n_rcu_torture_free));
69410 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
69411 - atomic_read(&n_rcu_torture_mberror),
69412 + atomic_read_unchecked(&n_rcu_torture_mberror),
69413 n_rcu_torture_boost_ktrerror,
69414 n_rcu_torture_boost_rterror);
69415 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
69416 @@ -1224,14 +1224,14 @@ rcu_torture_printk(char *page)
69417 n_barrier_attempts,
69418 n_rcu_torture_barrier_error);
69419 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69420 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69421 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69422 n_rcu_torture_barrier_error != 0 ||
69423 n_rcu_torture_boost_ktrerror != 0 ||
69424 n_rcu_torture_boost_rterror != 0 ||
69425 n_rcu_torture_boost_failure != 0 ||
69426 i > 1) {
69427 cnt += sprintf(&page[cnt], "!!! ");
69428 - atomic_inc(&n_rcu_torture_error);
69429 + atomic_inc_unchecked(&n_rcu_torture_error);
69430 WARN_ON_ONCE(1);
69431 }
69432 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69433 @@ -1245,7 +1245,7 @@ rcu_torture_printk(char *page)
69434 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69435 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69436 cnt += sprintf(&page[cnt], " %d",
69437 - atomic_read(&rcu_torture_wcount[i]));
69438 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69439 }
69440 cnt += sprintf(&page[cnt], "\n");
69441 if (cur_ops->stats)
69442 @@ -1905,7 +1905,7 @@ rcu_torture_cleanup(void)
69443
69444 if (cur_ops->cleanup)
69445 cur_ops->cleanup();
69446 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69447 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69448 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69449 else if (n_online_successes != n_online_attempts ||
69450 n_offline_successes != n_offline_attempts)
69451 @@ -1974,18 +1974,18 @@ rcu_torture_init(void)
69452
69453 rcu_torture_current = NULL;
69454 rcu_torture_current_version = 0;
69455 - atomic_set(&n_rcu_torture_alloc, 0);
69456 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69457 - atomic_set(&n_rcu_torture_free, 0);
69458 - atomic_set(&n_rcu_torture_mberror, 0);
69459 - atomic_set(&n_rcu_torture_error, 0);
69460 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69461 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69462 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69463 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69464 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69465 n_rcu_torture_barrier_error = 0;
69466 n_rcu_torture_boost_ktrerror = 0;
69467 n_rcu_torture_boost_rterror = 0;
69468 n_rcu_torture_boost_failure = 0;
69469 n_rcu_torture_boosts = 0;
69470 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69471 - atomic_set(&rcu_torture_wcount[i], 0);
69472 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69473 for_each_possible_cpu(cpu) {
69474 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69475 per_cpu(rcu_torture_count, cpu)[i] = 0;
69476 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69477 index f7bcd9e..8973e14 100644
69478 --- a/kernel/rcutree.c
69479 +++ b/kernel/rcutree.c
69480 @@ -369,9 +369,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69481 rcu_prepare_for_idle(smp_processor_id());
69482 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69483 smp_mb__before_atomic_inc(); /* See above. */
69484 - atomic_inc(&rdtp->dynticks);
69485 + atomic_inc_unchecked(&rdtp->dynticks);
69486 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69487 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69488 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69489
69490 /*
69491 * The idle task is not permitted to enter the idle loop while
69492 @@ -460,10 +460,10 @@ void rcu_irq_exit(void)
69493 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69494 {
69495 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69496 - atomic_inc(&rdtp->dynticks);
69497 + atomic_inc_unchecked(&rdtp->dynticks);
69498 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69499 smp_mb__after_atomic_inc(); /* See above. */
69500 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69501 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69502 rcu_cleanup_after_idle(smp_processor_id());
69503 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69504 if (!is_idle_task(current)) {
69505 @@ -557,14 +557,14 @@ void rcu_nmi_enter(void)
69506 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69507
69508 if (rdtp->dynticks_nmi_nesting == 0 &&
69509 - (atomic_read(&rdtp->dynticks) & 0x1))
69510 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69511 return;
69512 rdtp->dynticks_nmi_nesting++;
69513 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69514 - atomic_inc(&rdtp->dynticks);
69515 + atomic_inc_unchecked(&rdtp->dynticks);
69516 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69517 smp_mb__after_atomic_inc(); /* See above. */
69518 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69519 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69520 }
69521
69522 /**
69523 @@ -583,9 +583,9 @@ void rcu_nmi_exit(void)
69524 return;
69525 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69526 smp_mb__before_atomic_inc(); /* See above. */
69527 - atomic_inc(&rdtp->dynticks);
69528 + atomic_inc_unchecked(&rdtp->dynticks);
69529 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69530 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69531 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69532 }
69533
69534 /**
69535 @@ -599,7 +599,7 @@ int rcu_is_cpu_idle(void)
69536 int ret;
69537
69538 preempt_disable();
69539 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69540 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69541 preempt_enable();
69542 return ret;
69543 }
69544 @@ -667,7 +667,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69545 */
69546 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69547 {
69548 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69549 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69550 return (rdp->dynticks_snap & 0x1) == 0;
69551 }
69552
69553 @@ -682,7 +682,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69554 unsigned int curr;
69555 unsigned int snap;
69556
69557 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69558 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69559 snap = (unsigned int)rdp->dynticks_snap;
69560
69561 /*
69562 @@ -712,10 +712,10 @@ static int jiffies_till_stall_check(void)
69563 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69564 */
69565 if (till_stall_check < 3) {
69566 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69567 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69568 till_stall_check = 3;
69569 } else if (till_stall_check > 300) {
69570 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69571 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69572 till_stall_check = 300;
69573 }
69574 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69575 @@ -1351,7 +1351,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
69576 rsp->qlen += rdp->qlen;
69577 rdp->n_cbs_orphaned += rdp->qlen;
69578 rdp->qlen_lazy = 0;
69579 - ACCESS_ONCE(rdp->qlen) = 0;
69580 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69581 }
69582
69583 /*
69584 @@ -1604,7 +1604,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
69585 }
69586 smp_mb(); /* List handling before counting for rcu_barrier(). */
69587 rdp->qlen_lazy -= count_lazy;
69588 - ACCESS_ONCE(rdp->qlen) -= count;
69589 + ACCESS_ONCE_RW(rdp->qlen) -= count;
69590 rdp->n_cbs_invoked += count;
69591
69592 /* Reinstate batch limit if we have worked down the excess. */
69593 @@ -1836,7 +1836,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
69594 /*
69595 * Do RCU core processing for the current CPU.
69596 */
69597 -static void rcu_process_callbacks(struct softirq_action *unused)
69598 +static void rcu_process_callbacks(void)
69599 {
69600 struct rcu_state *rsp;
69601
69602 @@ -1943,7 +1943,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
69603 rdp = this_cpu_ptr(rsp->rda);
69604
69605 /* Add the callback to our list. */
69606 - ACCESS_ONCE(rdp->qlen)++;
69607 + ACCESS_ONCE_RW(rdp->qlen)++;
69608 if (lazy)
69609 rdp->qlen_lazy++;
69610 else
69611 @@ -2057,8 +2057,8 @@ void synchronize_rcu_bh(void)
69612 }
69613 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69614
69615 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69616 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69617 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69618 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69619
69620 static int synchronize_sched_expedited_cpu_stop(void *data)
69621 {
69622 @@ -2119,7 +2119,7 @@ void synchronize_sched_expedited(void)
69623 int firstsnap, s, snap, trycount = 0;
69624
69625 /* Note that atomic_inc_return() implies full memory barrier. */
69626 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69627 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69628 get_online_cpus();
69629 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69630
69631 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69632 }
69633
69634 /* Check to see if someone else did our work for us. */
69635 - s = atomic_read(&sync_sched_expedited_done);
69636 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69637 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69638 smp_mb(); /* ensure test happens before caller kfree */
69639 return;
69640 @@ -2156,7 +2156,7 @@ void synchronize_sched_expedited(void)
69641 * grace period works for us.
69642 */
69643 get_online_cpus();
69644 - snap = atomic_read(&sync_sched_expedited_started);
69645 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69646 smp_mb(); /* ensure read is before try_stop_cpus(). */
69647 }
69648
69649 @@ -2167,12 +2167,12 @@ void synchronize_sched_expedited(void)
69650 * than we did beat us to the punch.
69651 */
69652 do {
69653 - s = atomic_read(&sync_sched_expedited_done);
69654 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69655 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69656 smp_mb(); /* ensure test happens before caller kfree */
69657 break;
69658 }
69659 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69660 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69661
69662 put_online_cpus();
69663 }
69664 @@ -2366,7 +2366,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69665 * ACCESS_ONCE() to prevent the compiler from speculating
69666 * the increment to precede the early-exit check.
69667 */
69668 - ACCESS_ONCE(rsp->n_barrier_done)++;
69669 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69670 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
69671 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
69672 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
69673 @@ -2448,7 +2448,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
69674
69675 /* Increment ->n_barrier_done to prevent duplicate work. */
69676 smp_mb(); /* Keep increment after above mechanism. */
69677 - ACCESS_ONCE(rsp->n_barrier_done)++;
69678 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
69679 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
69680 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
69681 smp_mb(); /* Keep increment before caller's subsequent code. */
69682 @@ -2495,10 +2495,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69683 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
69684 init_callback_list(rdp);
69685 rdp->qlen_lazy = 0;
69686 - ACCESS_ONCE(rdp->qlen) = 0;
69687 + ACCESS_ONCE_RW(rdp->qlen) = 0;
69688 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69689 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69690 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69691 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69692 rdp->cpu = cpu;
69693 rdp->rsp = rsp;
69694 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69695 @@ -2526,8 +2526,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69696 rdp->n_force_qs_snap = rsp->n_force_qs;
69697 rdp->blimit = blimit;
69698 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69699 - atomic_set(&rdp->dynticks->dynticks,
69700 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69701 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69702 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69703 rcu_prepare_for_idle_init(cpu);
69704 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69705
69706 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69707 index 4d29169..d104a3c 100644
69708 --- a/kernel/rcutree.h
69709 +++ b/kernel/rcutree.h
69710 @@ -86,7 +86,7 @@ struct rcu_dynticks {
69711 long long dynticks_nesting; /* Track irq/process nesting level. */
69712 /* Process level is worth LLONG_MAX/2. */
69713 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69714 - atomic_t dynticks; /* Even value for idle, else odd. */
69715 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69716 #ifdef CONFIG_RCU_FAST_NO_HZ
69717 int dyntick_drain; /* Prepare-for-idle state variable. */
69718 unsigned long dyntick_holdoff;
69719 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69720 index 7f3244c..417d606 100644
69721 --- a/kernel/rcutree_plugin.h
69722 +++ b/kernel/rcutree_plugin.h
69723 @@ -843,7 +843,7 @@ void synchronize_rcu_expedited(void)
69724
69725 /* Clean up and exit. */
69726 smp_mb(); /* ensure expedited GP seen before counter increment. */
69727 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69728 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69729 unlock_mb_ret:
69730 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69731 mb_ret:
69732 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69733 index abffb48..cbfa6d3 100644
69734 --- a/kernel/rcutree_trace.c
69735 +++ b/kernel/rcutree_trace.c
69736 @@ -93,7 +93,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69737 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69738 rdp->qs_pending);
69739 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69740 - atomic_read(&rdp->dynticks->dynticks),
69741 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69742 rdp->dynticks->dynticks_nesting,
69743 rdp->dynticks->dynticks_nmi_nesting,
69744 rdp->dynticks_fqs);
69745 @@ -157,7 +157,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69746 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69747 rdp->qs_pending);
69748 seq_printf(m, ",%d,%llx,%d,%lu",
69749 - atomic_read(&rdp->dynticks->dynticks),
69750 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69751 rdp->dynticks->dynticks_nesting,
69752 rdp->dynticks->dynticks_nmi_nesting,
69753 rdp->dynticks_fqs);
69754 diff --git a/kernel/resource.c b/kernel/resource.c
69755 index 34d4588..10baa6a 100644
69756 --- a/kernel/resource.c
69757 +++ b/kernel/resource.c
69758 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
69759
69760 static int __init ioresources_init(void)
69761 {
69762 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69763 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69764 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69765 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69766 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69767 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69768 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69769 +#endif
69770 +#else
69771 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69772 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69773 +#endif
69774 return 0;
69775 }
69776 __initcall(ioresources_init);
69777 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69778 index 98ec494..4241d6d 100644
69779 --- a/kernel/rtmutex-tester.c
69780 +++ b/kernel/rtmutex-tester.c
69781 @@ -20,7 +20,7 @@
69782 #define MAX_RT_TEST_MUTEXES 8
69783
69784 static spinlock_t rttest_lock;
69785 -static atomic_t rttest_event;
69786 +static atomic_unchecked_t rttest_event;
69787
69788 struct test_thread_data {
69789 int opcode;
69790 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69791
69792 case RTTEST_LOCKCONT:
69793 td->mutexes[td->opdata] = 1;
69794 - td->event = atomic_add_return(1, &rttest_event);
69795 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69796 return 0;
69797
69798 case RTTEST_RESET:
69799 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69800 return 0;
69801
69802 case RTTEST_RESETEVENT:
69803 - atomic_set(&rttest_event, 0);
69804 + atomic_set_unchecked(&rttest_event, 0);
69805 return 0;
69806
69807 default:
69808 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69809 return ret;
69810
69811 td->mutexes[id] = 1;
69812 - td->event = atomic_add_return(1, &rttest_event);
69813 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69814 rt_mutex_lock(&mutexes[id]);
69815 - td->event = atomic_add_return(1, &rttest_event);
69816 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69817 td->mutexes[id] = 4;
69818 return 0;
69819
69820 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69821 return ret;
69822
69823 td->mutexes[id] = 1;
69824 - td->event = atomic_add_return(1, &rttest_event);
69825 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69826 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69827 - td->event = atomic_add_return(1, &rttest_event);
69828 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69829 td->mutexes[id] = ret ? 0 : 4;
69830 return ret ? -EINTR : 0;
69831
69832 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69833 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69834 return ret;
69835
69836 - td->event = atomic_add_return(1, &rttest_event);
69837 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69838 rt_mutex_unlock(&mutexes[id]);
69839 - td->event = atomic_add_return(1, &rttest_event);
69840 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69841 td->mutexes[id] = 0;
69842 return 0;
69843
69844 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69845 break;
69846
69847 td->mutexes[dat] = 2;
69848 - td->event = atomic_add_return(1, &rttest_event);
69849 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69850 break;
69851
69852 default:
69853 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69854 return;
69855
69856 td->mutexes[dat] = 3;
69857 - td->event = atomic_add_return(1, &rttest_event);
69858 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69859 break;
69860
69861 case RTTEST_LOCKNOWAIT:
69862 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69863 return;
69864
69865 td->mutexes[dat] = 1;
69866 - td->event = atomic_add_return(1, &rttest_event);
69867 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69868 return;
69869
69870 default:
69871 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69872 index 0984a21..939f183 100644
69873 --- a/kernel/sched/auto_group.c
69874 +++ b/kernel/sched/auto_group.c
69875 @@ -11,7 +11,7 @@
69876
69877 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69878 static struct autogroup autogroup_default;
69879 -static atomic_t autogroup_seq_nr;
69880 +static atomic_unchecked_t autogroup_seq_nr;
69881
69882 void __init autogroup_init(struct task_struct *init_task)
69883 {
69884 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69885
69886 kref_init(&ag->kref);
69887 init_rwsem(&ag->lock);
69888 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69889 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69890 ag->tg = tg;
69891 #ifdef CONFIG_RT_GROUP_SCHED
69892 /*
69893 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69894 index 1a48cdb..d3949ff 100644
69895 --- a/kernel/sched/core.c
69896 +++ b/kernel/sched/core.c
69897 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69898 /* convert nice value [19,-20] to rlimit style value [1,40] */
69899 int nice_rlim = 20 - nice;
69900
69901 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69902 +
69903 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69904 capable(CAP_SYS_NICE));
69905 }
69906 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69907 if (nice > 19)
69908 nice = 19;
69909
69910 - if (increment < 0 && !can_nice(current, nice))
69911 + if (increment < 0 && (!can_nice(current, nice) ||
69912 + gr_handle_chroot_nice()))
69913 return -EPERM;
69914
69915 retval = security_task_setnice(current, nice);
69916 @@ -4290,6 +4293,7 @@ recheck:
69917 unsigned long rlim_rtprio =
69918 task_rlimit(p, RLIMIT_RTPRIO);
69919
69920 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69921 /* can't set/change the rt policy */
69922 if (policy != p->policy && !rlim_rtprio)
69923 return -EPERM;
69924 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69925 index 96e2b18..bb31eec 100644
69926 --- a/kernel/sched/fair.c
69927 +++ b/kernel/sched/fair.c
69928 @@ -4923,7 +4923,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69929 * run_rebalance_domains is triggered when needed from the scheduler tick.
69930 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69931 */
69932 -static void run_rebalance_domains(struct softirq_action *h)
69933 +static void run_rebalance_domains(void)
69934 {
69935 int this_cpu = smp_processor_id();
69936 struct rq *this_rq = cpu_rq(this_cpu);
69937 diff --git a/kernel/signal.c b/kernel/signal.c
69938 index be4f856..453401c 100644
69939 --- a/kernel/signal.c
69940 +++ b/kernel/signal.c
69941 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
69942
69943 int print_fatal_signals __read_mostly;
69944
69945 -static void __user *sig_handler(struct task_struct *t, int sig)
69946 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
69947 {
69948 return t->sighand->action[sig - 1].sa.sa_handler;
69949 }
69950
69951 -static int sig_handler_ignored(void __user *handler, int sig)
69952 +static int sig_handler_ignored(__sighandler_t handler, int sig)
69953 {
69954 /* Is it explicitly or implicitly ignored? */
69955 return handler == SIG_IGN ||
69956 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
69957
69958 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
69959 {
69960 - void __user *handler;
69961 + __sighandler_t handler;
69962
69963 handler = sig_handler(t, sig);
69964
69965 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
69966 atomic_inc(&user->sigpending);
69967 rcu_read_unlock();
69968
69969 + if (!override_rlimit)
69970 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
69971 +
69972 if (override_rlimit ||
69973 atomic_read(&user->sigpending) <=
69974 task_rlimit(t, RLIMIT_SIGPENDING)) {
69975 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
69976
69977 int unhandled_signal(struct task_struct *tsk, int sig)
69978 {
69979 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
69980 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
69981 if (is_global_init(tsk))
69982 return 1;
69983 if (handler != SIG_IGN && handler != SIG_DFL)
69984 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
69985 }
69986 }
69987
69988 + /* allow glibc communication via tgkill to other threads in our
69989 + thread group */
69990 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
69991 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
69992 + && gr_handle_signal(t, sig))
69993 + return -EPERM;
69994 +
69995 return security_task_kill(t, info, sig, 0);
69996 }
69997
69998 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
69999 return send_signal(sig, info, p, 1);
70000 }
70001
70002 -static int
70003 +int
70004 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70005 {
70006 return send_signal(sig, info, t, 0);
70007 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70008 unsigned long int flags;
70009 int ret, blocked, ignored;
70010 struct k_sigaction *action;
70011 + int is_unhandled = 0;
70012
70013 spin_lock_irqsave(&t->sighand->siglock, flags);
70014 action = &t->sighand->action[sig-1];
70015 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70016 }
70017 if (action->sa.sa_handler == SIG_DFL)
70018 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70019 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70020 + is_unhandled = 1;
70021 ret = specific_send_sig_info(sig, info, t);
70022 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70023
70024 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70025 + normal operation */
70026 + if (is_unhandled) {
70027 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70028 + gr_handle_crash(t, sig);
70029 + }
70030 +
70031 return ret;
70032 }
70033
70034 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70035 ret = check_kill_permission(sig, info, p);
70036 rcu_read_unlock();
70037
70038 - if (!ret && sig)
70039 + if (!ret && sig) {
70040 ret = do_send_sig_info(sig, info, p, true);
70041 + if (!ret)
70042 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70043 + }
70044
70045 return ret;
70046 }
70047 @@ -2873,7 +2896,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70048 int error = -ESRCH;
70049
70050 rcu_read_lock();
70051 - p = find_task_by_vpid(pid);
70052 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70053 + /* allow glibc communication via tgkill to other threads in our
70054 + thread group */
70055 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70056 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70057 + p = find_task_by_vpid_unrestricted(pid);
70058 + else
70059 +#endif
70060 + p = find_task_by_vpid(pid);
70061 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70062 error = check_kill_permission(sig, info, p);
70063 /*
70064 diff --git a/kernel/softirq.c b/kernel/softirq.c
70065 index b73e681..645ab62 100644
70066 --- a/kernel/softirq.c
70067 +++ b/kernel/softirq.c
70068 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70069
70070 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70071
70072 -char *softirq_to_name[NR_SOFTIRQS] = {
70073 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70074 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70075 "TASKLET", "SCHED", "HRTIMER", "RCU"
70076 };
70077 @@ -243,7 +243,7 @@ restart:
70078 kstat_incr_softirqs_this_cpu(vec_nr);
70079
70080 trace_softirq_entry(vec_nr);
70081 - h->action(h);
70082 + h->action();
70083 trace_softirq_exit(vec_nr);
70084 if (unlikely(prev_count != preempt_count())) {
70085 printk(KERN_ERR "huh, entered softirq %u %s %p"
70086 @@ -390,9 +390,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70087 or_softirq_pending(1UL << nr);
70088 }
70089
70090 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70091 +void open_softirq(int nr, void (*action)(void))
70092 {
70093 - softirq_vec[nr].action = action;
70094 + pax_open_kernel();
70095 + *(void **)&softirq_vec[nr].action = action;
70096 + pax_close_kernel();
70097 }
70098
70099 /*
70100 @@ -446,7 +448,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70101
70102 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70103
70104 -static void tasklet_action(struct softirq_action *a)
70105 +static void tasklet_action(void)
70106 {
70107 struct tasklet_struct *list;
70108
70109 @@ -481,7 +483,7 @@ static void tasklet_action(struct softirq_action *a)
70110 }
70111 }
70112
70113 -static void tasklet_hi_action(struct softirq_action *a)
70114 +static void tasklet_hi_action(void)
70115 {
70116 struct tasklet_struct *list;
70117
70118 diff --git a/kernel/srcu.c b/kernel/srcu.c
70119 index 2095be3..9a5b89d 100644
70120 --- a/kernel/srcu.c
70121 +++ b/kernel/srcu.c
70122 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70123 preempt_disable();
70124 idx = rcu_dereference_index_check(sp->completed,
70125 rcu_read_lock_sched_held()) & 0x1;
70126 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70127 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70128 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70129 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70130 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70131 preempt_enable();
70132 return idx;
70133 }
70134 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70135 {
70136 preempt_disable();
70137 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70138 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70139 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70140 preempt_enable();
70141 }
70142 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70143 diff --git a/kernel/sys.c b/kernel/sys.c
70144 index 6fab59a..4ad079b 100644
70145 --- a/kernel/sys.c
70146 +++ b/kernel/sys.c
70147 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70148 error = -EACCES;
70149 goto out;
70150 }
70151 +
70152 + if (gr_handle_chroot_setpriority(p, niceval)) {
70153 + error = -EACCES;
70154 + goto out;
70155 + }
70156 +
70157 no_nice = security_task_setnice(p, niceval);
70158 if (no_nice) {
70159 error = no_nice;
70160 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70161 goto error;
70162 }
70163
70164 + if (gr_check_group_change(new->gid, new->egid, -1))
70165 + goto error;
70166 +
70167 if (rgid != (gid_t) -1 ||
70168 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70169 new->sgid = new->egid;
70170 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70171 old = current_cred();
70172
70173 retval = -EPERM;
70174 +
70175 + if (gr_check_group_change(kgid, kgid, kgid))
70176 + goto error;
70177 +
70178 if (nsown_capable(CAP_SETGID))
70179 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70180 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70181 @@ -647,7 +660,7 @@ error:
70182 /*
70183 * change the user struct in a credentials set to match the new UID
70184 */
70185 -static int set_user(struct cred *new)
70186 +int set_user(struct cred *new)
70187 {
70188 struct user_struct *new_user;
70189
70190 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70191 goto error;
70192 }
70193
70194 + if (gr_check_user_change(new->uid, new->euid, -1))
70195 + goto error;
70196 +
70197 if (!uid_eq(new->uid, old->uid)) {
70198 retval = set_user(new);
70199 if (retval < 0)
70200 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70201 old = current_cred();
70202
70203 retval = -EPERM;
70204 +
70205 + if (gr_check_crash_uid(kuid))
70206 + goto error;
70207 + if (gr_check_user_change(kuid, kuid, kuid))
70208 + goto error;
70209 +
70210 if (nsown_capable(CAP_SETUID)) {
70211 new->suid = new->uid = kuid;
70212 if (!uid_eq(kuid, old->uid)) {
70213 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70214 goto error;
70215 }
70216
70217 + if (gr_check_user_change(kruid, keuid, -1))
70218 + goto error;
70219 +
70220 if (ruid != (uid_t) -1) {
70221 new->uid = kruid;
70222 if (!uid_eq(kruid, old->uid)) {
70223 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70224 goto error;
70225 }
70226
70227 + if (gr_check_group_change(krgid, kegid, -1))
70228 + goto error;
70229 +
70230 if (rgid != (gid_t) -1)
70231 new->gid = krgid;
70232 if (egid != (gid_t) -1)
70233 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70234 if (!uid_valid(kuid))
70235 return old_fsuid;
70236
70237 + if (gr_check_user_change(-1, -1, kuid))
70238 + goto error;
70239 +
70240 new = prepare_creds();
70241 if (!new)
70242 return old_fsuid;
70243 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70244 }
70245 }
70246
70247 +error:
70248 abort_creds(new);
70249 return old_fsuid;
70250
70251 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70252 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70253 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70254 nsown_capable(CAP_SETGID)) {
70255 + if (gr_check_group_change(-1, -1, kgid))
70256 + goto error;
70257 +
70258 if (!gid_eq(kgid, old->fsgid)) {
70259 new->fsgid = kgid;
70260 goto change_okay;
70261 }
70262 }
70263
70264 +error:
70265 abort_creds(new);
70266 return old_fsgid;
70267
70268 @@ -1265,13 +1301,13 @@ DECLARE_RWSEM(uts_sem);
70269 * Work around broken programs that cannot handle "Linux 3.0".
70270 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
70271 */
70272 -static int override_release(char __user *release, int len)
70273 +static int override_release(char __user *release, size_t len)
70274 {
70275 int ret = 0;
70276 - char buf[65];
70277
70278 if (current->personality & UNAME26) {
70279 - char *rest = UTS_RELEASE;
70280 + char buf[65] = { 0 };
70281 + const char *rest = UTS_RELEASE;
70282 int ndots = 0;
70283 unsigned v;
70284
70285 @@ -1283,7 +1319,10 @@ static int override_release(char __user *release, int len)
70286 rest++;
70287 }
70288 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
70289 + if (sizeof buf < len)
70290 + len = sizeof buf;
70291 snprintf(buf, len, "2.6.%u%s", v, rest);
70292 + buf[len - 1] = 0;
70293 ret = copy_to_user(release, buf, len);
70294 }
70295 return ret;
70296 @@ -1338,19 +1377,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70297 return -EFAULT;
70298
70299 down_read(&uts_sem);
70300 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70301 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70302 __OLD_UTS_LEN);
70303 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70304 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70305 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70306 __OLD_UTS_LEN);
70307 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70308 - error |= __copy_to_user(&name->release, &utsname()->release,
70309 + error |= __copy_to_user(name->release, &utsname()->release,
70310 __OLD_UTS_LEN);
70311 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70312 - error |= __copy_to_user(&name->version, &utsname()->version,
70313 + error |= __copy_to_user(name->version, &utsname()->version,
70314 __OLD_UTS_LEN);
70315 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70316 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70317 + error |= __copy_to_user(name->machine, &utsname()->machine,
70318 __OLD_UTS_LEN);
70319 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70320 up_read(&uts_sem);
70321 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70322 error = get_dumpable(me->mm);
70323 break;
70324 case PR_SET_DUMPABLE:
70325 - if (arg2 < 0 || arg2 > 1) {
70326 + if (arg2 > 1) {
70327 error = -EINVAL;
70328 break;
70329 }
70330 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70331 index 87174ef..68cbb82 100644
70332 --- a/kernel/sysctl.c
70333 +++ b/kernel/sysctl.c
70334 @@ -92,7 +92,6 @@
70335
70336
70337 #if defined(CONFIG_SYSCTL)
70338 -
70339 /* External variables not in a header file. */
70340 extern int sysctl_overcommit_memory;
70341 extern int sysctl_overcommit_ratio;
70342 @@ -170,10 +169,8 @@ static int proc_taint(struct ctl_table *table, int write,
70343 void __user *buffer, size_t *lenp, loff_t *ppos);
70344 #endif
70345
70346 -#ifdef CONFIG_PRINTK
70347 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70348 void __user *buffer, size_t *lenp, loff_t *ppos);
70349 -#endif
70350
70351 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70352 void __user *buffer, size_t *lenp, loff_t *ppos);
70353 @@ -202,6 +199,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70354
70355 #endif
70356
70357 +extern struct ctl_table grsecurity_table[];
70358 +
70359 static struct ctl_table kern_table[];
70360 static struct ctl_table vm_table[];
70361 static struct ctl_table fs_table[];
70362 @@ -216,6 +215,20 @@ extern struct ctl_table epoll_table[];
70363 int sysctl_legacy_va_layout;
70364 #endif
70365
70366 +#ifdef CONFIG_PAX_SOFTMODE
70367 +static ctl_table pax_table[] = {
70368 + {
70369 + .procname = "softmode",
70370 + .data = &pax_softmode,
70371 + .maxlen = sizeof(unsigned int),
70372 + .mode = 0600,
70373 + .proc_handler = &proc_dointvec,
70374 + },
70375 +
70376 + { }
70377 +};
70378 +#endif
70379 +
70380 /* The default sysctl tables: */
70381
70382 static struct ctl_table sysctl_base_table[] = {
70383 @@ -262,6 +275,22 @@ static int max_extfrag_threshold = 1000;
70384 #endif
70385
70386 static struct ctl_table kern_table[] = {
70387 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70388 + {
70389 + .procname = "grsecurity",
70390 + .mode = 0500,
70391 + .child = grsecurity_table,
70392 + },
70393 +#endif
70394 +
70395 +#ifdef CONFIG_PAX_SOFTMODE
70396 + {
70397 + .procname = "pax",
70398 + .mode = 0500,
70399 + .child = pax_table,
70400 + },
70401 +#endif
70402 +
70403 {
70404 .procname = "sched_child_runs_first",
70405 .data = &sysctl_sched_child_runs_first,
70406 @@ -546,7 +575,7 @@ static struct ctl_table kern_table[] = {
70407 .data = &modprobe_path,
70408 .maxlen = KMOD_PATH_LEN,
70409 .mode = 0644,
70410 - .proc_handler = proc_dostring,
70411 + .proc_handler = proc_dostring_modpriv,
70412 },
70413 {
70414 .procname = "modules_disabled",
70415 @@ -713,16 +742,20 @@ static struct ctl_table kern_table[] = {
70416 .extra1 = &zero,
70417 .extra2 = &one,
70418 },
70419 +#endif
70420 {
70421 .procname = "kptr_restrict",
70422 .data = &kptr_restrict,
70423 .maxlen = sizeof(int),
70424 .mode = 0644,
70425 .proc_handler = proc_dointvec_minmax_sysadmin,
70426 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70427 + .extra1 = &two,
70428 +#else
70429 .extra1 = &zero,
70430 +#endif
70431 .extra2 = &two,
70432 },
70433 -#endif
70434 {
70435 .procname = "ngroups_max",
70436 .data = &ngroups_max,
70437 @@ -1219,6 +1252,13 @@ static struct ctl_table vm_table[] = {
70438 .proc_handler = proc_dointvec_minmax,
70439 .extra1 = &zero,
70440 },
70441 + {
70442 + .procname = "heap_stack_gap",
70443 + .data = &sysctl_heap_stack_gap,
70444 + .maxlen = sizeof(sysctl_heap_stack_gap),
70445 + .mode = 0644,
70446 + .proc_handler = proc_doulongvec_minmax,
70447 + },
70448 #else
70449 {
70450 .procname = "nr_trim_pages",
70451 @@ -1670,6 +1710,16 @@ int proc_dostring(struct ctl_table *table, int write,
70452 buffer, lenp, ppos);
70453 }
70454
70455 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70456 + void __user *buffer, size_t *lenp, loff_t *ppos)
70457 +{
70458 + if (write && !capable(CAP_SYS_MODULE))
70459 + return -EPERM;
70460 +
70461 + return _proc_do_string(table->data, table->maxlen, write,
70462 + buffer, lenp, ppos);
70463 +}
70464 +
70465 static size_t proc_skip_spaces(char **buf)
70466 {
70467 size_t ret;
70468 @@ -1775,6 +1825,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70469 len = strlen(tmp);
70470 if (len > *size)
70471 len = *size;
70472 + if (len > sizeof(tmp))
70473 + len = sizeof(tmp);
70474 if (copy_to_user(*buf, tmp, len))
70475 return -EFAULT;
70476 *size -= len;
70477 @@ -1967,7 +2019,6 @@ static int proc_taint(struct ctl_table *table, int write,
70478 return err;
70479 }
70480
70481 -#ifdef CONFIG_PRINTK
70482 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70483 void __user *buffer, size_t *lenp, loff_t *ppos)
70484 {
70485 @@ -1976,7 +2027,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70486
70487 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70488 }
70489 -#endif
70490
70491 struct do_proc_dointvec_minmax_conv_param {
70492 int *min;
70493 @@ -2119,8 +2169,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70494 *i = val;
70495 } else {
70496 val = convdiv * (*i) / convmul;
70497 - if (!first)
70498 + if (!first) {
70499 err = proc_put_char(&buffer, &left, '\t');
70500 + if (err)
70501 + break;
70502 + }
70503 err = proc_put_long(&buffer, &left, val, false);
70504 if (err)
70505 break;
70506 @@ -2512,6 +2565,12 @@ int proc_dostring(struct ctl_table *table, int write,
70507 return -ENOSYS;
70508 }
70509
70510 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70511 + void __user *buffer, size_t *lenp, loff_t *ppos)
70512 +{
70513 + return -ENOSYS;
70514 +}
70515 +
70516 int proc_dointvec(struct ctl_table *table, int write,
70517 void __user *buffer, size_t *lenp, loff_t *ppos)
70518 {
70519 @@ -2568,5 +2627,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70520 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70521 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70522 EXPORT_SYMBOL(proc_dostring);
70523 +EXPORT_SYMBOL(proc_dostring_modpriv);
70524 EXPORT_SYMBOL(proc_doulongvec_minmax);
70525 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70526 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70527 index 65bdcf1..21eb831 100644
70528 --- a/kernel/sysctl_binary.c
70529 +++ b/kernel/sysctl_binary.c
70530 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70531 int i;
70532
70533 set_fs(KERNEL_DS);
70534 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70535 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70536 set_fs(old_fs);
70537 if (result < 0)
70538 goto out_kfree;
70539 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70540 }
70541
70542 set_fs(KERNEL_DS);
70543 - result = vfs_write(file, buffer, str - buffer, &pos);
70544 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70545 set_fs(old_fs);
70546 if (result < 0)
70547 goto out_kfree;
70548 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70549 int i;
70550
70551 set_fs(KERNEL_DS);
70552 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70553 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70554 set_fs(old_fs);
70555 if (result < 0)
70556 goto out_kfree;
70557 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70558 }
70559
70560 set_fs(KERNEL_DS);
70561 - result = vfs_write(file, buffer, str - buffer, &pos);
70562 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70563 set_fs(old_fs);
70564 if (result < 0)
70565 goto out_kfree;
70566 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70567 int i;
70568
70569 set_fs(KERNEL_DS);
70570 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70571 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70572 set_fs(old_fs);
70573 if (result < 0)
70574 goto out;
70575 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70576 __le16 dnaddr;
70577
70578 set_fs(KERNEL_DS);
70579 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70580 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70581 set_fs(old_fs);
70582 if (result < 0)
70583 goto out;
70584 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70585 le16_to_cpu(dnaddr) & 0x3ff);
70586
70587 set_fs(KERNEL_DS);
70588 - result = vfs_write(file, buf, len, &pos);
70589 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70590 set_fs(old_fs);
70591 if (result < 0)
70592 goto out;
70593 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70594 index d0a3279..db0ad99 100644
70595 --- a/kernel/taskstats.c
70596 +++ b/kernel/taskstats.c
70597 @@ -27,9 +27,12 @@
70598 #include <linux/cgroup.h>
70599 #include <linux/fs.h>
70600 #include <linux/file.h>
70601 +#include <linux/grsecurity.h>
70602 #include <net/genetlink.h>
70603 #include <linux/atomic.h>
70604
70605 +extern int gr_is_taskstats_denied(int pid);
70606 +
70607 /*
70608 * Maximum length of a cpumask that can be specified in
70609 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70610 @@ -561,6 +564,9 @@ err:
70611
70612 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70613 {
70614 + if (gr_is_taskstats_denied(current->pid))
70615 + return -EACCES;
70616 +
70617 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70618 return cmd_attr_register_cpumask(info);
70619 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70620 diff --git a/kernel/time.c b/kernel/time.c
70621 index ba744cf..267b7c5 100644
70622 --- a/kernel/time.c
70623 +++ b/kernel/time.c
70624 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70625 return error;
70626
70627 if (tz) {
70628 + /* we log in do_settimeofday called below, so don't log twice
70629 + */
70630 + if (!tv)
70631 + gr_log_timechange();
70632 +
70633 sys_tz = *tz;
70634 update_vsyscall_tz();
70635 if (firsttime) {
70636 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70637 index aa27d39..34d221c 100644
70638 --- a/kernel/time/alarmtimer.c
70639 +++ b/kernel/time/alarmtimer.c
70640 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70641 struct platform_device *pdev;
70642 int error = 0;
70643 int i;
70644 - struct k_clock alarm_clock = {
70645 + static struct k_clock alarm_clock = {
70646 .clock_getres = alarm_clock_getres,
70647 .clock_get = alarm_clock_get,
70648 .timer_create = alarm_timer_create,
70649 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70650 index f113755..ec24223 100644
70651 --- a/kernel/time/tick-broadcast.c
70652 +++ b/kernel/time/tick-broadcast.c
70653 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70654 * then clear the broadcast bit.
70655 */
70656 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70657 - int cpu = smp_processor_id();
70658 + cpu = smp_processor_id();
70659
70660 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70661 tick_broadcast_clear_oneshot(cpu);
70662 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70663 index d3b91e7..2a4be68 100644
70664 --- a/kernel/time/timekeeping.c
70665 +++ b/kernel/time/timekeeping.c
70666 @@ -14,6 +14,7 @@
70667 #include <linux/init.h>
70668 #include <linux/mm.h>
70669 #include <linux/sched.h>
70670 +#include <linux/grsecurity.h>
70671 #include <linux/syscore_ops.h>
70672 #include <linux/clocksource.h>
70673 #include <linux/jiffies.h>
70674 @@ -434,6 +435,8 @@ int do_settimeofday(const struct timespec *tv)
70675 if (!timespec_valid_strict(tv))
70676 return -EINVAL;
70677
70678 + gr_log_timechange();
70679 +
70680 write_seqlock_irqsave(&tk->lock, flags);
70681
70682 timekeeping_forward_now(tk);
70683 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70684 index af5a7e9..715611a 100644
70685 --- a/kernel/time/timer_list.c
70686 +++ b/kernel/time/timer_list.c
70687 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70688
70689 static void print_name_offset(struct seq_file *m, void *sym)
70690 {
70691 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70692 + SEQ_printf(m, "<%p>", NULL);
70693 +#else
70694 char symname[KSYM_NAME_LEN];
70695
70696 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70697 SEQ_printf(m, "<%pK>", sym);
70698 else
70699 SEQ_printf(m, "%s", symname);
70700 +#endif
70701 }
70702
70703 static void
70704 @@ -112,7 +116,11 @@ next_one:
70705 static void
70706 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70707 {
70708 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70709 + SEQ_printf(m, " .base: %p\n", NULL);
70710 +#else
70711 SEQ_printf(m, " .base: %pK\n", base);
70712 +#endif
70713 SEQ_printf(m, " .index: %d\n",
70714 base->index);
70715 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70716 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70717 {
70718 struct proc_dir_entry *pe;
70719
70720 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70721 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70722 +#else
70723 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70724 +#endif
70725 if (!pe)
70726 return -ENOMEM;
70727 return 0;
70728 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70729 index 0b537f2..40d6c20 100644
70730 --- a/kernel/time/timer_stats.c
70731 +++ b/kernel/time/timer_stats.c
70732 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70733 static unsigned long nr_entries;
70734 static struct entry entries[MAX_ENTRIES];
70735
70736 -static atomic_t overflow_count;
70737 +static atomic_unchecked_t overflow_count;
70738
70739 /*
70740 * The entries are in a hash-table, for fast lookup:
70741 @@ -140,7 +140,7 @@ static void reset_entries(void)
70742 nr_entries = 0;
70743 memset(entries, 0, sizeof(entries));
70744 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70745 - atomic_set(&overflow_count, 0);
70746 + atomic_set_unchecked(&overflow_count, 0);
70747 }
70748
70749 static struct entry *alloc_entry(void)
70750 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70751 if (likely(entry))
70752 entry->count++;
70753 else
70754 - atomic_inc(&overflow_count);
70755 + atomic_inc_unchecked(&overflow_count);
70756
70757 out_unlock:
70758 raw_spin_unlock_irqrestore(lock, flags);
70759 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70760
70761 static void print_name_offset(struct seq_file *m, unsigned long addr)
70762 {
70763 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70764 + seq_printf(m, "<%p>", NULL);
70765 +#else
70766 char symname[KSYM_NAME_LEN];
70767
70768 if (lookup_symbol_name(addr, symname) < 0)
70769 - seq_printf(m, "<%p>", (void *)addr);
70770 + seq_printf(m, "<%pK>", (void *)addr);
70771 else
70772 seq_printf(m, "%s", symname);
70773 +#endif
70774 }
70775
70776 static int tstats_show(struct seq_file *m, void *v)
70777 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70778
70779 seq_puts(m, "Timer Stats Version: v0.2\n");
70780 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70781 - if (atomic_read(&overflow_count))
70782 + if (atomic_read_unchecked(&overflow_count))
70783 seq_printf(m, "Overflow: %d entries\n",
70784 - atomic_read(&overflow_count));
70785 + atomic_read_unchecked(&overflow_count));
70786
70787 for (i = 0; i < nr_entries; i++) {
70788 entry = entries + i;
70789 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70790 {
70791 struct proc_dir_entry *pe;
70792
70793 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70794 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70795 +#else
70796 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70797 +#endif
70798 if (!pe)
70799 return -ENOMEM;
70800 return 0;
70801 diff --git a/kernel/timer.c b/kernel/timer.c
70802 index 8c5e7b9..968d02c 100644
70803 --- a/kernel/timer.c
70804 +++ b/kernel/timer.c
70805 @@ -1375,7 +1375,7 @@ void update_process_times(int user_tick)
70806 /*
70807 * This function runs timers and the timer-tq in bottom half context.
70808 */
70809 -static void run_timer_softirq(struct softirq_action *h)
70810 +static void run_timer_softirq(void)
70811 {
70812 struct tvec_base *base = __this_cpu_read(tvec_bases);
70813
70814 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70815 index c0bd030..62a1927 100644
70816 --- a/kernel/trace/blktrace.c
70817 +++ b/kernel/trace/blktrace.c
70818 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70819 struct blk_trace *bt = filp->private_data;
70820 char buf[16];
70821
70822 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70823 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70824
70825 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70826 }
70827 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70828 return 1;
70829
70830 bt = buf->chan->private_data;
70831 - atomic_inc(&bt->dropped);
70832 + atomic_inc_unchecked(&bt->dropped);
70833 return 0;
70834 }
70835
70836 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70837
70838 bt->dir = dir;
70839 bt->dev = dev;
70840 - atomic_set(&bt->dropped, 0);
70841 + atomic_set_unchecked(&bt->dropped, 0);
70842
70843 ret = -EIO;
70844 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70845 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
70846 index b4f20fb..483c5fa 100644
70847 --- a/kernel/trace/ftrace.c
70848 +++ b/kernel/trace/ftrace.c
70849 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
70850 if (unlikely(ftrace_disabled))
70851 return 0;
70852
70853 + ret = ftrace_arch_code_modify_prepare();
70854 + FTRACE_WARN_ON(ret);
70855 + if (ret)
70856 + return 0;
70857 +
70858 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
70859 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
70860 if (ret) {
70861 ftrace_bug(ret, ip);
70862 - return 0;
70863 }
70864 - return 1;
70865 + return ret ? 0 : 1;
70866 }
70867
70868 /*
70869 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
70870
70871 int
70872 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
70873 - void *data)
70874 + void *data)
70875 {
70876 struct ftrace_func_probe *entry;
70877 struct ftrace_page *pg;
70878 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
70879 if (!count)
70880 return 0;
70881
70882 + pax_open_kernel();
70883 sort(start, count, sizeof(*start),
70884 ftrace_cmp_ips, ftrace_swap_ips);
70885 + pax_close_kernel();
70886
70887 start_pg = ftrace_allocate_pages(count);
70888 if (!start_pg)
70889 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
70890 index 5c38c81..88012af 100644
70891 --- a/kernel/trace/trace.c
70892 +++ b/kernel/trace/trace.c
70893 @@ -4437,10 +4437,9 @@ static const struct file_operations tracing_dyn_info_fops = {
70894 };
70895 #endif
70896
70897 -static struct dentry *d_tracer;
70898 -
70899 struct dentry *tracing_init_dentry(void)
70900 {
70901 + static struct dentry *d_tracer;
70902 static int once;
70903
70904 if (d_tracer)
70905 @@ -4460,10 +4459,9 @@ struct dentry *tracing_init_dentry(void)
70906 return d_tracer;
70907 }
70908
70909 -static struct dentry *d_percpu;
70910 -
70911 struct dentry *tracing_dentry_percpu(void)
70912 {
70913 + static struct dentry *d_percpu;
70914 static int once;
70915 struct dentry *d_tracer;
70916
70917 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
70918 index 29111da..d190fe2 100644
70919 --- a/kernel/trace/trace_events.c
70920 +++ b/kernel/trace/trace_events.c
70921 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
70922 struct ftrace_module_file_ops {
70923 struct list_head list;
70924 struct module *mod;
70925 - struct file_operations id;
70926 - struct file_operations enable;
70927 - struct file_operations format;
70928 - struct file_operations filter;
70929 };
70930
70931 static struct ftrace_module_file_ops *
70932 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
70933
70934 file_ops->mod = mod;
70935
70936 - file_ops->id = ftrace_event_id_fops;
70937 - file_ops->id.owner = mod;
70938 -
70939 - file_ops->enable = ftrace_enable_fops;
70940 - file_ops->enable.owner = mod;
70941 -
70942 - file_ops->filter = ftrace_event_filter_fops;
70943 - file_ops->filter.owner = mod;
70944 -
70945 - file_ops->format = ftrace_event_format_fops;
70946 - file_ops->format.owner = mod;
70947 + pax_open_kernel();
70948 + *(void **)&mod->trace_id.owner = mod;
70949 + *(void **)&mod->trace_enable.owner = mod;
70950 + *(void **)&mod->trace_filter.owner = mod;
70951 + *(void **)&mod->trace_format.owner = mod;
70952 + pax_close_kernel();
70953
70954 list_add(&file_ops->list, &ftrace_module_file_list);
70955
70956 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
70957
70958 for_each_event(call, start, end) {
70959 __trace_add_event_call(*call, mod,
70960 - &file_ops->id, &file_ops->enable,
70961 - &file_ops->filter, &file_ops->format);
70962 + &mod->trace_id, &mod->trace_enable,
70963 + &mod->trace_filter, &mod->trace_format);
70964 }
70965 }
70966
70967 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
70968 index fd3c8aa..5f324a6 100644
70969 --- a/kernel/trace/trace_mmiotrace.c
70970 +++ b/kernel/trace/trace_mmiotrace.c
70971 @@ -24,7 +24,7 @@ struct header_iter {
70972 static struct trace_array *mmio_trace_array;
70973 static bool overrun_detected;
70974 static unsigned long prev_overruns;
70975 -static atomic_t dropped_count;
70976 +static atomic_unchecked_t dropped_count;
70977
70978 static void mmio_reset_data(struct trace_array *tr)
70979 {
70980 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
70981
70982 static unsigned long count_overruns(struct trace_iterator *iter)
70983 {
70984 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
70985 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
70986 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
70987
70988 if (over > prev_overruns)
70989 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
70990 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
70991 sizeof(*entry), 0, pc);
70992 if (!event) {
70993 - atomic_inc(&dropped_count);
70994 + atomic_inc_unchecked(&dropped_count);
70995 return;
70996 }
70997 entry = ring_buffer_event_data(event);
70998 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
70999 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71000 sizeof(*entry), 0, pc);
71001 if (!event) {
71002 - atomic_inc(&dropped_count);
71003 + atomic_inc_unchecked(&dropped_count);
71004 return;
71005 }
71006 entry = ring_buffer_event_data(event);
71007 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71008 index 123b189..97b81f5 100644
71009 --- a/kernel/trace/trace_output.c
71010 +++ b/kernel/trace/trace_output.c
71011 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71012
71013 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71014 if (!IS_ERR(p)) {
71015 - p = mangle_path(s->buffer + s->len, p, "\n");
71016 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71017 if (p) {
71018 s->len = p - s->buffer;
71019 return 1;
71020 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71021 index d4545f4..a9010a1 100644
71022 --- a/kernel/trace/trace_stack.c
71023 +++ b/kernel/trace/trace_stack.c
71024 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71025 return;
71026
71027 /* we do not handle interrupt stacks yet */
71028 - if (!object_is_on_stack(&this_size))
71029 + if (!object_starts_on_stack(&this_size))
71030 return;
71031
71032 local_irq_save(flags);
71033 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71034 index 872bd6d..31601a2 100644
71035 --- a/kernel/workqueue.c
71036 +++ b/kernel/workqueue.c
71037 @@ -1422,7 +1422,7 @@ retry:
71038 /* morph UNBOUND to REBIND atomically */
71039 worker_flags &= ~WORKER_UNBOUND;
71040 worker_flags |= WORKER_REBIND;
71041 - ACCESS_ONCE(worker->flags) = worker_flags;
71042 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71043
71044 idle_rebind.cnt++;
71045 worker->idle_rebind = &idle_rebind;
71046 @@ -1448,7 +1448,7 @@ retry:
71047 /* morph UNBOUND to REBIND atomically */
71048 worker_flags &= ~WORKER_UNBOUND;
71049 worker_flags |= WORKER_REBIND;
71050 - ACCESS_ONCE(worker->flags) = worker_flags;
71051 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71052
71053 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71054 work_data_bits(rebind_work)))
71055 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71056 index 2403a63..5c4be4c 100644
71057 --- a/lib/Kconfig.debug
71058 +++ b/lib/Kconfig.debug
71059 @@ -1252,6 +1252,7 @@ config LATENCYTOP
71060 depends on DEBUG_KERNEL
71061 depends on STACKTRACE_SUPPORT
71062 depends on PROC_FS
71063 + depends on !GRKERNSEC_HIDESYM
71064 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71065 select KALLSYMS
71066 select KALLSYMS_ALL
71067 @@ -1267,7 +1268,7 @@ source kernel/trace/Kconfig
71068
71069 config PROVIDE_OHCI1394_DMA_INIT
71070 bool "Remote debugging over FireWire early on boot"
71071 - depends on PCI && X86
71072 + depends on PCI && X86 && !GRKERNSEC
71073 help
71074 If you want to debug problems which hang or crash the kernel early
71075 on boot and the crashing machine has a FireWire port, you can use
71076 @@ -1296,7 +1297,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71077
71078 config FIREWIRE_OHCI_REMOTE_DMA
71079 bool "Remote debugging over FireWire with firewire-ohci"
71080 - depends on FIREWIRE_OHCI
71081 + depends on FIREWIRE_OHCI && !GRKERNSEC
71082 help
71083 This option lets you use the FireWire bus for remote debugging
71084 with help of the firewire-ohci driver. It enables unfiltered
71085 diff --git a/lib/bitmap.c b/lib/bitmap.c
71086 index 06fdfa1..97c5c7d 100644
71087 --- a/lib/bitmap.c
71088 +++ b/lib/bitmap.c
71089 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71090 {
71091 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71092 u32 chunk;
71093 - const char __user __force *ubuf = (const char __user __force *)buf;
71094 + const char __user *ubuf = (const char __force_user *)buf;
71095
71096 bitmap_zero(maskp, nmaskbits);
71097
71098 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71099 {
71100 if (!access_ok(VERIFY_READ, ubuf, ulen))
71101 return -EFAULT;
71102 - return __bitmap_parse((const char __force *)ubuf,
71103 + return __bitmap_parse((const char __force_kernel *)ubuf,
71104 ulen, 1, maskp, nmaskbits);
71105
71106 }
71107 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71108 {
71109 unsigned a, b;
71110 int c, old_c, totaldigits;
71111 - const char __user __force *ubuf = (const char __user __force *)buf;
71112 + const char __user *ubuf = (const char __force_user *)buf;
71113 int exp_digit, in_range;
71114
71115 totaldigits = c = 0;
71116 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71117 {
71118 if (!access_ok(VERIFY_READ, ubuf, ulen))
71119 return -EFAULT;
71120 - return __bitmap_parselist((const char __force *)ubuf,
71121 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71122 ulen, 1, maskp, nmaskbits);
71123 }
71124 EXPORT_SYMBOL(bitmap_parselist_user);
71125 diff --git a/lib/bug.c b/lib/bug.c
71126 index a28c141..2bd3d95 100644
71127 --- a/lib/bug.c
71128 +++ b/lib/bug.c
71129 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71130 return BUG_TRAP_TYPE_NONE;
71131
71132 bug = find_bug(bugaddr);
71133 + if (!bug)
71134 + return BUG_TRAP_TYPE_NONE;
71135
71136 file = NULL;
71137 line = 0;
71138 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71139 index d11808c..dc2d6f8 100644
71140 --- a/lib/debugobjects.c
71141 +++ b/lib/debugobjects.c
71142 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71143 if (limit > 4)
71144 return;
71145
71146 - is_on_stack = object_is_on_stack(addr);
71147 + is_on_stack = object_starts_on_stack(addr);
71148 if (is_on_stack == onstack)
71149 return;
71150
71151 diff --git a/lib/devres.c b/lib/devres.c
71152 index 80b9c76..9e32279 100644
71153 --- a/lib/devres.c
71154 +++ b/lib/devres.c
71155 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71156 void devm_iounmap(struct device *dev, void __iomem *addr)
71157 {
71158 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71159 - (void *)addr));
71160 + (void __force *)addr));
71161 iounmap(addr);
71162 }
71163 EXPORT_SYMBOL(devm_iounmap);
71164 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71165 {
71166 ioport_unmap(addr);
71167 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71168 - devm_ioport_map_match, (void *)addr));
71169 + devm_ioport_map_match, (void __force *)addr));
71170 }
71171 EXPORT_SYMBOL(devm_ioport_unmap);
71172
71173 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71174 index 66ce414..6f0a0dd 100644
71175 --- a/lib/dma-debug.c
71176 +++ b/lib/dma-debug.c
71177 @@ -924,7 +924,7 @@ out:
71178
71179 static void check_for_stack(struct device *dev, void *addr)
71180 {
71181 - if (object_is_on_stack(addr))
71182 + if (object_starts_on_stack(addr))
71183 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71184 "stack [addr=%p]\n", addr);
71185 }
71186 diff --git a/lib/inflate.c b/lib/inflate.c
71187 index 013a761..c28f3fc 100644
71188 --- a/lib/inflate.c
71189 +++ b/lib/inflate.c
71190 @@ -269,7 +269,7 @@ static void free(void *where)
71191 malloc_ptr = free_mem_ptr;
71192 }
71193 #else
71194 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71195 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71196 #define free(a) kfree(a)
71197 #endif
71198
71199 diff --git a/lib/ioremap.c b/lib/ioremap.c
71200 index 0c9216c..863bd89 100644
71201 --- a/lib/ioremap.c
71202 +++ b/lib/ioremap.c
71203 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71204 unsigned long next;
71205
71206 phys_addr -= addr;
71207 - pmd = pmd_alloc(&init_mm, pud, addr);
71208 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71209 if (!pmd)
71210 return -ENOMEM;
71211 do {
71212 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71213 unsigned long next;
71214
71215 phys_addr -= addr;
71216 - pud = pud_alloc(&init_mm, pgd, addr);
71217 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71218 if (!pud)
71219 return -ENOMEM;
71220 do {
71221 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71222 index bd2bea9..6b3c95e 100644
71223 --- a/lib/is_single_threaded.c
71224 +++ b/lib/is_single_threaded.c
71225 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71226 struct task_struct *p, *t;
71227 bool ret;
71228
71229 + if (!mm)
71230 + return true;
71231 +
71232 if (atomic_read(&task->signal->live) != 1)
71233 return false;
71234
71235 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71236 index e796429..6e38f9f 100644
71237 --- a/lib/radix-tree.c
71238 +++ b/lib/radix-tree.c
71239 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71240 int nr;
71241 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71242 };
71243 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71244 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71245
71246 static inline void *ptr_to_indirect(void *ptr)
71247 {
71248 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71249 index 0e33754..50a0e63 100644
71250 --- a/lib/vsprintf.c
71251 +++ b/lib/vsprintf.c
71252 @@ -16,6 +16,9 @@
71253 * - scnprintf and vscnprintf
71254 */
71255
71256 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71257 +#define __INCLUDED_BY_HIDESYM 1
71258 +#endif
71259 #include <stdarg.h>
71260 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71261 #include <linux/types.h>
71262 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71263 char sym[KSYM_SYMBOL_LEN];
71264 if (ext == 'B')
71265 sprint_backtrace(sym, value);
71266 - else if (ext != 'f' && ext != 's')
71267 + else if (ext != 'f' && ext != 's' && ext != 'a')
71268 sprint_symbol(sym, value);
71269 else
71270 sprint_symbol_no_offset(sym, value);
71271 @@ -969,7 +972,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71272 return number(buf, end, *(const netdev_features_t *)addr, spec);
71273 }
71274
71275 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71276 +int kptr_restrict __read_mostly = 2;
71277 +#else
71278 int kptr_restrict __read_mostly;
71279 +#endif
71280
71281 /*
71282 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71283 @@ -983,6 +990,8 @@ int kptr_restrict __read_mostly;
71284 * - 'S' For symbolic direct pointers with offset
71285 * - 's' For symbolic direct pointers without offset
71286 * - 'B' For backtraced symbolic direct pointers with offset
71287 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71288 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71289 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71290 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71291 * - 'M' For a 6-byte MAC address, it prints the address in the
71292 @@ -1038,12 +1047,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71293
71294 if (!ptr && *fmt != 'K') {
71295 /*
71296 - * Print (null) with the same width as a pointer so it makes
71297 + * Print (nil) with the same width as a pointer so it makes
71298 * tabular output look nice.
71299 */
71300 if (spec.field_width == -1)
71301 spec.field_width = default_width;
71302 - return string(buf, end, "(null)", spec);
71303 + return string(buf, end, "(nil)", spec);
71304 }
71305
71306 switch (*fmt) {
71307 @@ -1053,6 +1062,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71308 /* Fallthrough */
71309 case 'S':
71310 case 's':
71311 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71312 + break;
71313 +#else
71314 + return symbol_string(buf, end, ptr, spec, *fmt);
71315 +#endif
71316 + case 'A':
71317 + case 'a':
71318 case 'B':
71319 return symbol_string(buf, end, ptr, spec, *fmt);
71320 case 'R':
71321 @@ -1093,6 +1109,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71322 va_end(va);
71323 return buf;
71324 }
71325 + case 'P':
71326 + break;
71327 case 'K':
71328 /*
71329 * %pK cannot be used in IRQ context because its test
71330 @@ -1116,6 +1134,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71331 }
71332 break;
71333 }
71334 +
71335 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71336 + /* 'P' = approved pointers to copy to userland,
71337 + as in the /proc/kallsyms case, as we make it display nothing
71338 + for non-root users, and the real contents for root users
71339 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71340 + above
71341 + */
71342 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71343 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71344 + dump_stack();
71345 + ptr = NULL;
71346 + }
71347 +#endif
71348 +
71349 spec.flags |= SMALL;
71350 if (spec.field_width == -1) {
71351 spec.field_width = default_width;
71352 @@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71353 typeof(type) value; \
71354 if (sizeof(type) == 8) { \
71355 args = PTR_ALIGN(args, sizeof(u32)); \
71356 - *(u32 *)&value = *(u32 *)args; \
71357 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71358 + *(u32 *)&value = *(const u32 *)args; \
71359 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71360 } else { \
71361 args = PTR_ALIGN(args, sizeof(type)); \
71362 - value = *(typeof(type) *)args; \
71363 + value = *(const typeof(type) *)args; \
71364 } \
71365 args += sizeof(type); \
71366 value; \
71367 @@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71368 case FORMAT_TYPE_STR: {
71369 const char *str_arg = args;
71370 args += strlen(str_arg) + 1;
71371 - str = string(str, end, (char *)str_arg, spec);
71372 + str = string(str, end, str_arg, spec);
71373 break;
71374 }
71375
71376 diff --git a/localversion-grsec b/localversion-grsec
71377 new file mode 100644
71378 index 0000000..7cd6065
71379 --- /dev/null
71380 +++ b/localversion-grsec
71381 @@ -0,0 +1 @@
71382 +-grsec
71383 diff --git a/mm/Kconfig b/mm/Kconfig
71384 index d5c8019..f513038 100644
71385 --- a/mm/Kconfig
71386 +++ b/mm/Kconfig
71387 @@ -251,10 +251,10 @@ config KSM
71388 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71389
71390 config DEFAULT_MMAP_MIN_ADDR
71391 - int "Low address space to protect from user allocation"
71392 + int "Low address space to protect from user allocation"
71393 depends on MMU
71394 - default 4096
71395 - help
71396 + default 65536
71397 + help
71398 This is the portion of low virtual memory which should be protected
71399 from userspace allocation. Keeping a user from writing to low pages
71400 can help reduce the impact of kernel NULL pointer bugs.
71401 @@ -285,7 +285,7 @@ config MEMORY_FAILURE
71402
71403 config HWPOISON_INJECT
71404 tristate "HWPoison pages injector"
71405 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71406 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71407 select PROC_PAGE_MONITOR
71408
71409 config NOMMU_INITIAL_TRIM_EXCESS
71410 diff --git a/mm/filemap.c b/mm/filemap.c
71411 index 3843445..4fe6833 100644
71412 --- a/mm/filemap.c
71413 +++ b/mm/filemap.c
71414 @@ -1746,7 +1746,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71415 struct address_space *mapping = file->f_mapping;
71416
71417 if (!mapping->a_ops->readpage)
71418 - return -ENOEXEC;
71419 + return -ENODEV;
71420 file_accessed(file);
71421 vma->vm_ops = &generic_file_vm_ops;
71422 vma->vm_flags |= VM_CAN_NONLINEAR;
71423 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71424 *pos = i_size_read(inode);
71425
71426 if (limit != RLIM_INFINITY) {
71427 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71428 if (*pos >= limit) {
71429 send_sig(SIGXFSZ, current, 0);
71430 return -EFBIG;
71431 diff --git a/mm/fremap.c b/mm/fremap.c
71432 index 9ed4fd4..c42648d 100644
71433 --- a/mm/fremap.c
71434 +++ b/mm/fremap.c
71435 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71436 retry:
71437 vma = find_vma(mm, start);
71438
71439 +#ifdef CONFIG_PAX_SEGMEXEC
71440 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71441 + goto out;
71442 +#endif
71443 +
71444 /*
71445 * Make sure the vma is shared, that it supports prefaulting,
71446 * and that the remapped range is valid and fully within
71447 diff --git a/mm/highmem.c b/mm/highmem.c
71448 index d517cd1..006a1c5 100644
71449 --- a/mm/highmem.c
71450 +++ b/mm/highmem.c
71451 @@ -137,9 +137,10 @@ static void flush_all_zero_pkmaps(void)
71452 * So no dangers, even with speculative execution.
71453 */
71454 page = pte_page(pkmap_page_table[i]);
71455 + pax_open_kernel();
71456 pte_clear(&init_mm, (unsigned long)page_address(page),
71457 &pkmap_page_table[i]);
71458 -
71459 + pax_close_kernel();
71460 set_page_address(page, NULL);
71461 need_flush = 1;
71462 }
71463 @@ -198,9 +199,11 @@ start:
71464 }
71465 }
71466 vaddr = PKMAP_ADDR(last_pkmap_nr);
71467 +
71468 + pax_open_kernel();
71469 set_pte_at(&init_mm, vaddr,
71470 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71471 -
71472 + pax_close_kernel();
71473 pkmap_count[last_pkmap_nr] = 1;
71474 set_page_address(page, (void *)vaddr);
71475
71476 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71477 index 141dbb6..ebff057 100644
71478 --- a/mm/huge_memory.c
71479 +++ b/mm/huge_memory.c
71480 @@ -735,7 +735,7 @@ out:
71481 * run pte_offset_map on the pmd, if an huge pmd could
71482 * materialize from under us from a different thread.
71483 */
71484 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71485 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71486 return VM_FAULT_OOM;
71487 /* if an huge pmd materialized from under us just retry later */
71488 if (unlikely(pmd_trans_huge(*pmd)))
71489 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71490 index 3adceaf..dccfea3 100644
71491 --- a/mm/hugetlb.c
71492 +++ b/mm/hugetlb.c
71493 @@ -2512,6 +2512,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71494 return 1;
71495 }
71496
71497 +#ifdef CONFIG_PAX_SEGMEXEC
71498 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71499 +{
71500 + struct mm_struct *mm = vma->vm_mm;
71501 + struct vm_area_struct *vma_m;
71502 + unsigned long address_m;
71503 + pte_t *ptep_m;
71504 +
71505 + vma_m = pax_find_mirror_vma(vma);
71506 + if (!vma_m)
71507 + return;
71508 +
71509 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71510 + address_m = address + SEGMEXEC_TASK_SIZE;
71511 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71512 + get_page(page_m);
71513 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71514 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71515 +}
71516 +#endif
71517 +
71518 /*
71519 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71520 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71521 @@ -2628,6 +2649,11 @@ retry_avoidcopy:
71522 make_huge_pte(vma, new_page, 1));
71523 page_remove_rmap(old_page);
71524 hugepage_add_new_anon_rmap(new_page, vma, address);
71525 +
71526 +#ifdef CONFIG_PAX_SEGMEXEC
71527 + pax_mirror_huge_pte(vma, address, new_page);
71528 +#endif
71529 +
71530 /* Make the old page be freed below */
71531 new_page = old_page;
71532 mmu_notifier_invalidate_range_end(mm,
71533 @@ -2786,6 +2812,10 @@ retry:
71534 && (vma->vm_flags & VM_SHARED)));
71535 set_huge_pte_at(mm, address, ptep, new_pte);
71536
71537 +#ifdef CONFIG_PAX_SEGMEXEC
71538 + pax_mirror_huge_pte(vma, address, page);
71539 +#endif
71540 +
71541 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71542 /* Optimization, do the COW without a second fault */
71543 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71544 @@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71545 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71546 struct hstate *h = hstate_vma(vma);
71547
71548 +#ifdef CONFIG_PAX_SEGMEXEC
71549 + struct vm_area_struct *vma_m;
71550 +#endif
71551 +
71552 address &= huge_page_mask(h);
71553
71554 ptep = huge_pte_offset(mm, address);
71555 @@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71556 VM_FAULT_SET_HINDEX(hstate_index(h));
71557 }
71558
71559 +#ifdef CONFIG_PAX_SEGMEXEC
71560 + vma_m = pax_find_mirror_vma(vma);
71561 + if (vma_m) {
71562 + unsigned long address_m;
71563 +
71564 + if (vma->vm_start > vma_m->vm_start) {
71565 + address_m = address;
71566 + address -= SEGMEXEC_TASK_SIZE;
71567 + vma = vma_m;
71568 + h = hstate_vma(vma);
71569 + } else
71570 + address_m = address + SEGMEXEC_TASK_SIZE;
71571 +
71572 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71573 + return VM_FAULT_OOM;
71574 + address_m &= HPAGE_MASK;
71575 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71576 + }
71577 +#endif
71578 +
71579 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71580 if (!ptep)
71581 return VM_FAULT_OOM;
71582 diff --git a/mm/internal.h b/mm/internal.h
71583 index b8c91b3..93e95a3 100644
71584 --- a/mm/internal.h
71585 +++ b/mm/internal.h
71586 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71587 * in mm/page_alloc.c
71588 */
71589 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71590 +extern void free_compound_page(struct page *page);
71591 extern void prep_compound_page(struct page *page, unsigned long order);
71592 #ifdef CONFIG_MEMORY_FAILURE
71593 extern bool is_free_buddy_page(struct page *page);
71594 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71595 index 45eb621..6ccd8ea 100644
71596 --- a/mm/kmemleak.c
71597 +++ b/mm/kmemleak.c
71598 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71599
71600 for (i = 0; i < object->trace_len; i++) {
71601 void *ptr = (void *)object->trace[i];
71602 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71603 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71604 }
71605 }
71606
71607 diff --git a/mm/maccess.c b/mm/maccess.c
71608 index d53adf9..03a24bf 100644
71609 --- a/mm/maccess.c
71610 +++ b/mm/maccess.c
71611 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71612 set_fs(KERNEL_DS);
71613 pagefault_disable();
71614 ret = __copy_from_user_inatomic(dst,
71615 - (__force const void __user *)src, size);
71616 + (const void __force_user *)src, size);
71617 pagefault_enable();
71618 set_fs(old_fs);
71619
71620 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71621
71622 set_fs(KERNEL_DS);
71623 pagefault_disable();
71624 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71625 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71626 pagefault_enable();
71627 set_fs(old_fs);
71628
71629 diff --git a/mm/madvise.c b/mm/madvise.c
71630 index 14d260f..b2a80fd 100644
71631 --- a/mm/madvise.c
71632 +++ b/mm/madvise.c
71633 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71634 pgoff_t pgoff;
71635 unsigned long new_flags = vma->vm_flags;
71636
71637 +#ifdef CONFIG_PAX_SEGMEXEC
71638 + struct vm_area_struct *vma_m;
71639 +#endif
71640 +
71641 switch (behavior) {
71642 case MADV_NORMAL:
71643 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71644 @@ -119,6 +123,13 @@ success:
71645 /*
71646 * vm_flags is protected by the mmap_sem held in write mode.
71647 */
71648 +
71649 +#ifdef CONFIG_PAX_SEGMEXEC
71650 + vma_m = pax_find_mirror_vma(vma);
71651 + if (vma_m)
71652 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71653 +#endif
71654 +
71655 vma->vm_flags = new_flags;
71656
71657 out:
71658 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71659 struct vm_area_struct ** prev,
71660 unsigned long start, unsigned long end)
71661 {
71662 +
71663 +#ifdef CONFIG_PAX_SEGMEXEC
71664 + struct vm_area_struct *vma_m;
71665 +#endif
71666 +
71667 *prev = vma;
71668 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71669 return -EINVAL;
71670 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71671 zap_page_range(vma, start, end - start, &details);
71672 } else
71673 zap_page_range(vma, start, end - start, NULL);
71674 +
71675 +#ifdef CONFIG_PAX_SEGMEXEC
71676 + vma_m = pax_find_mirror_vma(vma);
71677 + if (vma_m) {
71678 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71679 + struct zap_details details = {
71680 + .nonlinear_vma = vma_m,
71681 + .last_index = ULONG_MAX,
71682 + };
71683 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71684 + } else
71685 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71686 + }
71687 +#endif
71688 +
71689 return 0;
71690 }
71691
71692 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71693 if (end < start)
71694 goto out;
71695
71696 +#ifdef CONFIG_PAX_SEGMEXEC
71697 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71698 + if (end > SEGMEXEC_TASK_SIZE)
71699 + goto out;
71700 + } else
71701 +#endif
71702 +
71703 + if (end > TASK_SIZE)
71704 + goto out;
71705 +
71706 error = 0;
71707 if (end == start)
71708 goto out;
71709 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71710 index a6e2141..eaf5aad 100644
71711 --- a/mm/memory-failure.c
71712 +++ b/mm/memory-failure.c
71713 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71714
71715 int sysctl_memory_failure_recovery __read_mostly = 1;
71716
71717 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71718 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71719
71720 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71721
71722 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71723 pfn, t->comm, t->pid);
71724 si.si_signo = SIGBUS;
71725 si.si_errno = 0;
71726 - si.si_addr = (void *)addr;
71727 + si.si_addr = (void __user *)addr;
71728 #ifdef __ARCH_SI_TRAPNO
71729 si.si_trapno = trapno;
71730 #endif
71731 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71732 }
71733
71734 nr_pages = 1 << compound_trans_order(hpage);
71735 - atomic_long_add(nr_pages, &mce_bad_pages);
71736 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71737
71738 /*
71739 * We need/can do nothing about count=0 pages.
71740 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71741 if (!PageHWPoison(hpage)
71742 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71743 || (p != hpage && TestSetPageHWPoison(hpage))) {
71744 - atomic_long_sub(nr_pages, &mce_bad_pages);
71745 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71746 return 0;
71747 }
71748 set_page_hwpoison_huge_page(hpage);
71749 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71750 }
71751 if (hwpoison_filter(p)) {
71752 if (TestClearPageHWPoison(p))
71753 - atomic_long_sub(nr_pages, &mce_bad_pages);
71754 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71755 unlock_page(hpage);
71756 put_page(hpage);
71757 return 0;
71758 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71759 return 0;
71760 }
71761 if (TestClearPageHWPoison(p))
71762 - atomic_long_sub(nr_pages, &mce_bad_pages);
71763 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71764 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71765 return 0;
71766 }
71767 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71768 */
71769 if (TestClearPageHWPoison(page)) {
71770 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71771 - atomic_long_sub(nr_pages, &mce_bad_pages);
71772 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71773 freeit = 1;
71774 if (PageHuge(page))
71775 clear_page_hwpoison_huge_page(page);
71776 @@ -1440,7 +1440,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71777 }
71778 done:
71779 if (!PageHWPoison(hpage))
71780 - atomic_long_add(1 << compound_trans_order(hpage),
71781 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
71782 &mce_bad_pages);
71783 set_page_hwpoison_huge_page(hpage);
71784 dequeue_hwpoisoned_huge_page(hpage);
71785 @@ -1572,7 +1572,7 @@ int soft_offline_page(struct page *page, int flags)
71786 return ret;
71787
71788 done:
71789 - atomic_long_add(1, &mce_bad_pages);
71790 + atomic_long_add_unchecked(1, &mce_bad_pages);
71791 SetPageHWPoison(page);
71792 /* keep elevated page count for bad page */
71793 return ret;
71794 diff --git a/mm/memory.c b/mm/memory.c
71795 index 5736170..8e04800 100644
71796 --- a/mm/memory.c
71797 +++ b/mm/memory.c
71798 @@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71799 free_pte_range(tlb, pmd, addr);
71800 } while (pmd++, addr = next, addr != end);
71801
71802 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71803 start &= PUD_MASK;
71804 if (start < floor)
71805 return;
71806 @@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71807 pmd = pmd_offset(pud, start);
71808 pud_clear(pud);
71809 pmd_free_tlb(tlb, pmd, start);
71810 +#endif
71811 +
71812 }
71813
71814 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71815 @@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71816 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71817 } while (pud++, addr = next, addr != end);
71818
71819 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71820 start &= PGDIR_MASK;
71821 if (start < floor)
71822 return;
71823 @@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71824 pud = pud_offset(pgd, start);
71825 pgd_clear(pgd);
71826 pud_free_tlb(tlb, pud, start);
71827 +#endif
71828 +
71829 }
71830
71831 /*
71832 @@ -1614,12 +1620,6 @@ no_page_table:
71833 return page;
71834 }
71835
71836 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71837 -{
71838 - return stack_guard_page_start(vma, addr) ||
71839 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71840 -}
71841 -
71842 /**
71843 * __get_user_pages() - pin user pages in memory
71844 * @tsk: task_struct of target task
71845 @@ -1692,10 +1692,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71846 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71847 i = 0;
71848
71849 - do {
71850 + while (nr_pages) {
71851 struct vm_area_struct *vma;
71852
71853 - vma = find_extend_vma(mm, start);
71854 + vma = find_vma(mm, start);
71855 if (!vma && in_gate_area(mm, start)) {
71856 unsigned long pg = start & PAGE_MASK;
71857 pgd_t *pgd;
71858 @@ -1743,7 +1743,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71859 goto next_page;
71860 }
71861
71862 - if (!vma ||
71863 + if (!vma || start < vma->vm_start ||
71864 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
71865 !(vm_flags & vma->vm_flags))
71866 return i ? : -EFAULT;
71867 @@ -1770,11 +1770,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71868 int ret;
71869 unsigned int fault_flags = 0;
71870
71871 - /* For mlock, just skip the stack guard page. */
71872 - if (foll_flags & FOLL_MLOCK) {
71873 - if (stack_guard_page(vma, start))
71874 - goto next_page;
71875 - }
71876 if (foll_flags & FOLL_WRITE)
71877 fault_flags |= FAULT_FLAG_WRITE;
71878 if (nonblocking)
71879 @@ -1848,7 +1843,7 @@ next_page:
71880 start += PAGE_SIZE;
71881 nr_pages--;
71882 } while (nr_pages && start < vma->vm_end);
71883 - } while (nr_pages);
71884 + }
71885 return i;
71886 }
71887 EXPORT_SYMBOL(__get_user_pages);
71888 @@ -2055,6 +2050,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
71889 page_add_file_rmap(page);
71890 set_pte_at(mm, addr, pte, mk_pte(page, prot));
71891
71892 +#ifdef CONFIG_PAX_SEGMEXEC
71893 + pax_mirror_file_pte(vma, addr, page, ptl);
71894 +#endif
71895 +
71896 retval = 0;
71897 pte_unmap_unlock(pte, ptl);
71898 return retval;
71899 @@ -2089,10 +2088,22 @@ out:
71900 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
71901 struct page *page)
71902 {
71903 +
71904 +#ifdef CONFIG_PAX_SEGMEXEC
71905 + struct vm_area_struct *vma_m;
71906 +#endif
71907 +
71908 if (addr < vma->vm_start || addr >= vma->vm_end)
71909 return -EFAULT;
71910 if (!page_count(page))
71911 return -EINVAL;
71912 +
71913 +#ifdef CONFIG_PAX_SEGMEXEC
71914 + vma_m = pax_find_mirror_vma(vma);
71915 + if (vma_m)
71916 + vma_m->vm_flags |= VM_INSERTPAGE;
71917 +#endif
71918 +
71919 vma->vm_flags |= VM_INSERTPAGE;
71920 return insert_page(vma, addr, page, vma->vm_page_prot);
71921 }
71922 @@ -2178,6 +2189,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
71923 unsigned long pfn)
71924 {
71925 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
71926 + BUG_ON(vma->vm_mirror);
71927
71928 if (addr < vma->vm_start || addr >= vma->vm_end)
71929 return -EFAULT;
71930 @@ -2385,7 +2397,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
71931
71932 BUG_ON(pud_huge(*pud));
71933
71934 - pmd = pmd_alloc(mm, pud, addr);
71935 + pmd = (mm == &init_mm) ?
71936 + pmd_alloc_kernel(mm, pud, addr) :
71937 + pmd_alloc(mm, pud, addr);
71938 if (!pmd)
71939 return -ENOMEM;
71940 do {
71941 @@ -2405,7 +2419,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
71942 unsigned long next;
71943 int err;
71944
71945 - pud = pud_alloc(mm, pgd, addr);
71946 + pud = (mm == &init_mm) ?
71947 + pud_alloc_kernel(mm, pgd, addr) :
71948 + pud_alloc(mm, pgd, addr);
71949 if (!pud)
71950 return -ENOMEM;
71951 do {
71952 @@ -2493,6 +2509,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
71953 copy_user_highpage(dst, src, va, vma);
71954 }
71955
71956 +#ifdef CONFIG_PAX_SEGMEXEC
71957 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
71958 +{
71959 + struct mm_struct *mm = vma->vm_mm;
71960 + spinlock_t *ptl;
71961 + pte_t *pte, entry;
71962 +
71963 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
71964 + entry = *pte;
71965 + if (!pte_present(entry)) {
71966 + if (!pte_none(entry)) {
71967 + BUG_ON(pte_file(entry));
71968 + free_swap_and_cache(pte_to_swp_entry(entry));
71969 + pte_clear_not_present_full(mm, address, pte, 0);
71970 + }
71971 + } else {
71972 + struct page *page;
71973 +
71974 + flush_cache_page(vma, address, pte_pfn(entry));
71975 + entry = ptep_clear_flush(vma, address, pte);
71976 + BUG_ON(pte_dirty(entry));
71977 + page = vm_normal_page(vma, address, entry);
71978 + if (page) {
71979 + update_hiwater_rss(mm);
71980 + if (PageAnon(page))
71981 + dec_mm_counter_fast(mm, MM_ANONPAGES);
71982 + else
71983 + dec_mm_counter_fast(mm, MM_FILEPAGES);
71984 + page_remove_rmap(page);
71985 + page_cache_release(page);
71986 + }
71987 + }
71988 + pte_unmap_unlock(pte, ptl);
71989 +}
71990 +
71991 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
71992 + *
71993 + * the ptl of the lower mapped page is held on entry and is not released on exit
71994 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
71995 + */
71996 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
71997 +{
71998 + struct mm_struct *mm = vma->vm_mm;
71999 + unsigned long address_m;
72000 + spinlock_t *ptl_m;
72001 + struct vm_area_struct *vma_m;
72002 + pmd_t *pmd_m;
72003 + pte_t *pte_m, entry_m;
72004 +
72005 + BUG_ON(!page_m || !PageAnon(page_m));
72006 +
72007 + vma_m = pax_find_mirror_vma(vma);
72008 + if (!vma_m)
72009 + return;
72010 +
72011 + BUG_ON(!PageLocked(page_m));
72012 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72013 + address_m = address + SEGMEXEC_TASK_SIZE;
72014 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72015 + pte_m = pte_offset_map(pmd_m, address_m);
72016 + ptl_m = pte_lockptr(mm, pmd_m);
72017 + if (ptl != ptl_m) {
72018 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72019 + if (!pte_none(*pte_m))
72020 + goto out;
72021 + }
72022 +
72023 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72024 + page_cache_get(page_m);
72025 + page_add_anon_rmap(page_m, vma_m, address_m);
72026 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72027 + set_pte_at(mm, address_m, pte_m, entry_m);
72028 + update_mmu_cache(vma_m, address_m, entry_m);
72029 +out:
72030 + if (ptl != ptl_m)
72031 + spin_unlock(ptl_m);
72032 + pte_unmap(pte_m);
72033 + unlock_page(page_m);
72034 +}
72035 +
72036 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72037 +{
72038 + struct mm_struct *mm = vma->vm_mm;
72039 + unsigned long address_m;
72040 + spinlock_t *ptl_m;
72041 + struct vm_area_struct *vma_m;
72042 + pmd_t *pmd_m;
72043 + pte_t *pte_m, entry_m;
72044 +
72045 + BUG_ON(!page_m || PageAnon(page_m));
72046 +
72047 + vma_m = pax_find_mirror_vma(vma);
72048 + if (!vma_m)
72049 + return;
72050 +
72051 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72052 + address_m = address + SEGMEXEC_TASK_SIZE;
72053 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72054 + pte_m = pte_offset_map(pmd_m, address_m);
72055 + ptl_m = pte_lockptr(mm, pmd_m);
72056 + if (ptl != ptl_m) {
72057 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72058 + if (!pte_none(*pte_m))
72059 + goto out;
72060 + }
72061 +
72062 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72063 + page_cache_get(page_m);
72064 + page_add_file_rmap(page_m);
72065 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72066 + set_pte_at(mm, address_m, pte_m, entry_m);
72067 + update_mmu_cache(vma_m, address_m, entry_m);
72068 +out:
72069 + if (ptl != ptl_m)
72070 + spin_unlock(ptl_m);
72071 + pte_unmap(pte_m);
72072 +}
72073 +
72074 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72075 +{
72076 + struct mm_struct *mm = vma->vm_mm;
72077 + unsigned long address_m;
72078 + spinlock_t *ptl_m;
72079 + struct vm_area_struct *vma_m;
72080 + pmd_t *pmd_m;
72081 + pte_t *pte_m, entry_m;
72082 +
72083 + vma_m = pax_find_mirror_vma(vma);
72084 + if (!vma_m)
72085 + return;
72086 +
72087 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72088 + address_m = address + SEGMEXEC_TASK_SIZE;
72089 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72090 + pte_m = pte_offset_map(pmd_m, address_m);
72091 + ptl_m = pte_lockptr(mm, pmd_m);
72092 + if (ptl != ptl_m) {
72093 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72094 + if (!pte_none(*pte_m))
72095 + goto out;
72096 + }
72097 +
72098 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72099 + set_pte_at(mm, address_m, pte_m, entry_m);
72100 +out:
72101 + if (ptl != ptl_m)
72102 + spin_unlock(ptl_m);
72103 + pte_unmap(pte_m);
72104 +}
72105 +
72106 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72107 +{
72108 + struct page *page_m;
72109 + pte_t entry;
72110 +
72111 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72112 + goto out;
72113 +
72114 + entry = *pte;
72115 + page_m = vm_normal_page(vma, address, entry);
72116 + if (!page_m)
72117 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72118 + else if (PageAnon(page_m)) {
72119 + if (pax_find_mirror_vma(vma)) {
72120 + pte_unmap_unlock(pte, ptl);
72121 + lock_page(page_m);
72122 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72123 + if (pte_same(entry, *pte))
72124 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72125 + else
72126 + unlock_page(page_m);
72127 + }
72128 + } else
72129 + pax_mirror_file_pte(vma, address, page_m, ptl);
72130 +
72131 +out:
72132 + pte_unmap_unlock(pte, ptl);
72133 +}
72134 +#endif
72135 +
72136 /*
72137 * This routine handles present pages, when users try to write
72138 * to a shared page. It is done by copying the page to a new address
72139 @@ -2703,6 +2899,12 @@ gotten:
72140 */
72141 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72142 if (likely(pte_same(*page_table, orig_pte))) {
72143 +
72144 +#ifdef CONFIG_PAX_SEGMEXEC
72145 + if (pax_find_mirror_vma(vma))
72146 + BUG_ON(!trylock_page(new_page));
72147 +#endif
72148 +
72149 if (old_page) {
72150 if (!PageAnon(old_page)) {
72151 dec_mm_counter_fast(mm, MM_FILEPAGES);
72152 @@ -2754,6 +2956,10 @@ gotten:
72153 page_remove_rmap(old_page);
72154 }
72155
72156 +#ifdef CONFIG_PAX_SEGMEXEC
72157 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72158 +#endif
72159 +
72160 /* Free the old page.. */
72161 new_page = old_page;
72162 ret |= VM_FAULT_WRITE;
72163 @@ -3033,6 +3239,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72164 swap_free(entry);
72165 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72166 try_to_free_swap(page);
72167 +
72168 +#ifdef CONFIG_PAX_SEGMEXEC
72169 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72170 +#endif
72171 +
72172 unlock_page(page);
72173 if (swapcache) {
72174 /*
72175 @@ -3056,6 +3267,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72176
72177 /* No need to invalidate - it was non-present before */
72178 update_mmu_cache(vma, address, page_table);
72179 +
72180 +#ifdef CONFIG_PAX_SEGMEXEC
72181 + pax_mirror_anon_pte(vma, address, page, ptl);
72182 +#endif
72183 +
72184 unlock:
72185 pte_unmap_unlock(page_table, ptl);
72186 out:
72187 @@ -3075,40 +3291,6 @@ out_release:
72188 }
72189
72190 /*
72191 - * This is like a special single-page "expand_{down|up}wards()",
72192 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72193 - * doesn't hit another vma.
72194 - */
72195 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72196 -{
72197 - address &= PAGE_MASK;
72198 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72199 - struct vm_area_struct *prev = vma->vm_prev;
72200 -
72201 - /*
72202 - * Is there a mapping abutting this one below?
72203 - *
72204 - * That's only ok if it's the same stack mapping
72205 - * that has gotten split..
72206 - */
72207 - if (prev && prev->vm_end == address)
72208 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72209 -
72210 - expand_downwards(vma, address - PAGE_SIZE);
72211 - }
72212 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72213 - struct vm_area_struct *next = vma->vm_next;
72214 -
72215 - /* As VM_GROWSDOWN but s/below/above/ */
72216 - if (next && next->vm_start == address + PAGE_SIZE)
72217 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72218 -
72219 - expand_upwards(vma, address + PAGE_SIZE);
72220 - }
72221 - return 0;
72222 -}
72223 -
72224 -/*
72225 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72226 * but allow concurrent faults), and pte mapped but not yet locked.
72227 * We return with mmap_sem still held, but pte unmapped and unlocked.
72228 @@ -3117,27 +3299,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72229 unsigned long address, pte_t *page_table, pmd_t *pmd,
72230 unsigned int flags)
72231 {
72232 - struct page *page;
72233 + struct page *page = NULL;
72234 spinlock_t *ptl;
72235 pte_t entry;
72236
72237 - pte_unmap(page_table);
72238 -
72239 - /* Check if we need to add a guard page to the stack */
72240 - if (check_stack_guard_page(vma, address) < 0)
72241 - return VM_FAULT_SIGBUS;
72242 -
72243 - /* Use the zero-page for reads */
72244 if (!(flags & FAULT_FLAG_WRITE)) {
72245 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72246 vma->vm_page_prot));
72247 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72248 + ptl = pte_lockptr(mm, pmd);
72249 + spin_lock(ptl);
72250 if (!pte_none(*page_table))
72251 goto unlock;
72252 goto setpte;
72253 }
72254
72255 /* Allocate our own private page. */
72256 + pte_unmap(page_table);
72257 +
72258 if (unlikely(anon_vma_prepare(vma)))
72259 goto oom;
72260 page = alloc_zeroed_user_highpage_movable(vma, address);
72261 @@ -3156,6 +3334,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72262 if (!pte_none(*page_table))
72263 goto release;
72264
72265 +#ifdef CONFIG_PAX_SEGMEXEC
72266 + if (pax_find_mirror_vma(vma))
72267 + BUG_ON(!trylock_page(page));
72268 +#endif
72269 +
72270 inc_mm_counter_fast(mm, MM_ANONPAGES);
72271 page_add_new_anon_rmap(page, vma, address);
72272 setpte:
72273 @@ -3163,6 +3346,12 @@ setpte:
72274
72275 /* No need to invalidate - it was non-present before */
72276 update_mmu_cache(vma, address, page_table);
72277 +
72278 +#ifdef CONFIG_PAX_SEGMEXEC
72279 + if (page)
72280 + pax_mirror_anon_pte(vma, address, page, ptl);
72281 +#endif
72282 +
72283 unlock:
72284 pte_unmap_unlock(page_table, ptl);
72285 return 0;
72286 @@ -3306,6 +3495,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72287 */
72288 /* Only go through if we didn't race with anybody else... */
72289 if (likely(pte_same(*page_table, orig_pte))) {
72290 +
72291 +#ifdef CONFIG_PAX_SEGMEXEC
72292 + if (anon && pax_find_mirror_vma(vma))
72293 + BUG_ON(!trylock_page(page));
72294 +#endif
72295 +
72296 flush_icache_page(vma, page);
72297 entry = mk_pte(page, vma->vm_page_prot);
72298 if (flags & FAULT_FLAG_WRITE)
72299 @@ -3325,6 +3520,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72300
72301 /* no need to invalidate: a not-present page won't be cached */
72302 update_mmu_cache(vma, address, page_table);
72303 +
72304 +#ifdef CONFIG_PAX_SEGMEXEC
72305 + if (anon)
72306 + pax_mirror_anon_pte(vma, address, page, ptl);
72307 + else
72308 + pax_mirror_file_pte(vma, address, page, ptl);
72309 +#endif
72310 +
72311 } else {
72312 if (cow_page)
72313 mem_cgroup_uncharge_page(cow_page);
72314 @@ -3479,6 +3682,12 @@ int handle_pte_fault(struct mm_struct *mm,
72315 if (flags & FAULT_FLAG_WRITE)
72316 flush_tlb_fix_spurious_fault(vma, address);
72317 }
72318 +
72319 +#ifdef CONFIG_PAX_SEGMEXEC
72320 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72321 + return 0;
72322 +#endif
72323 +
72324 unlock:
72325 pte_unmap_unlock(pte, ptl);
72326 return 0;
72327 @@ -3495,6 +3704,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72328 pmd_t *pmd;
72329 pte_t *pte;
72330
72331 +#ifdef CONFIG_PAX_SEGMEXEC
72332 + struct vm_area_struct *vma_m;
72333 +#endif
72334 +
72335 __set_current_state(TASK_RUNNING);
72336
72337 count_vm_event(PGFAULT);
72338 @@ -3506,6 +3719,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72339 if (unlikely(is_vm_hugetlb_page(vma)))
72340 return hugetlb_fault(mm, vma, address, flags);
72341
72342 +#ifdef CONFIG_PAX_SEGMEXEC
72343 + vma_m = pax_find_mirror_vma(vma);
72344 + if (vma_m) {
72345 + unsigned long address_m;
72346 + pgd_t *pgd_m;
72347 + pud_t *pud_m;
72348 + pmd_t *pmd_m;
72349 +
72350 + if (vma->vm_start > vma_m->vm_start) {
72351 + address_m = address;
72352 + address -= SEGMEXEC_TASK_SIZE;
72353 + vma = vma_m;
72354 + } else
72355 + address_m = address + SEGMEXEC_TASK_SIZE;
72356 +
72357 + pgd_m = pgd_offset(mm, address_m);
72358 + pud_m = pud_alloc(mm, pgd_m, address_m);
72359 + if (!pud_m)
72360 + return VM_FAULT_OOM;
72361 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72362 + if (!pmd_m)
72363 + return VM_FAULT_OOM;
72364 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72365 + return VM_FAULT_OOM;
72366 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72367 + }
72368 +#endif
72369 +
72370 retry:
72371 pgd = pgd_offset(mm, address);
72372 pud = pud_alloc(mm, pgd, address);
72373 @@ -3547,7 +3788,7 @@ retry:
72374 * run pte_offset_map on the pmd, if an huge pmd could
72375 * materialize from under us from a different thread.
72376 */
72377 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72378 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72379 return VM_FAULT_OOM;
72380 /* if an huge pmd materialized from under us just retry later */
72381 if (unlikely(pmd_trans_huge(*pmd)))
72382 @@ -3584,6 +3825,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72383 spin_unlock(&mm->page_table_lock);
72384 return 0;
72385 }
72386 +
72387 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72388 +{
72389 + pud_t *new = pud_alloc_one(mm, address);
72390 + if (!new)
72391 + return -ENOMEM;
72392 +
72393 + smp_wmb(); /* See comment in __pte_alloc */
72394 +
72395 + spin_lock(&mm->page_table_lock);
72396 + if (pgd_present(*pgd)) /* Another has populated it */
72397 + pud_free(mm, new);
72398 + else
72399 + pgd_populate_kernel(mm, pgd, new);
72400 + spin_unlock(&mm->page_table_lock);
72401 + return 0;
72402 +}
72403 #endif /* __PAGETABLE_PUD_FOLDED */
72404
72405 #ifndef __PAGETABLE_PMD_FOLDED
72406 @@ -3614,6 +3872,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72407 spin_unlock(&mm->page_table_lock);
72408 return 0;
72409 }
72410 +
72411 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72412 +{
72413 + pmd_t *new = pmd_alloc_one(mm, address);
72414 + if (!new)
72415 + return -ENOMEM;
72416 +
72417 + smp_wmb(); /* See comment in __pte_alloc */
72418 +
72419 + spin_lock(&mm->page_table_lock);
72420 +#ifndef __ARCH_HAS_4LEVEL_HACK
72421 + if (pud_present(*pud)) /* Another has populated it */
72422 + pmd_free(mm, new);
72423 + else
72424 + pud_populate_kernel(mm, pud, new);
72425 +#else
72426 + if (pgd_present(*pud)) /* Another has populated it */
72427 + pmd_free(mm, new);
72428 + else
72429 + pgd_populate_kernel(mm, pud, new);
72430 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72431 + spin_unlock(&mm->page_table_lock);
72432 + return 0;
72433 +}
72434 #endif /* __PAGETABLE_PMD_FOLDED */
72435
72436 int make_pages_present(unsigned long addr, unsigned long end)
72437 @@ -3651,7 +3933,7 @@ static int __init gate_vma_init(void)
72438 gate_vma.vm_start = FIXADDR_USER_START;
72439 gate_vma.vm_end = FIXADDR_USER_END;
72440 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72441 - gate_vma.vm_page_prot = __P101;
72442 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72443
72444 return 0;
72445 }
72446 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72447 index 3d64b36..dbab433 100644
72448 --- a/mm/mempolicy.c
72449 +++ b/mm/mempolicy.c
72450 @@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72451 unsigned long vmstart;
72452 unsigned long vmend;
72453
72454 +#ifdef CONFIG_PAX_SEGMEXEC
72455 + struct vm_area_struct *vma_m;
72456 +#endif
72457 +
72458 vma = find_vma(mm, start);
72459 if (!vma || vma->vm_start > start)
72460 return -EFAULT;
72461 @@ -691,9 +695,18 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72462 if (err)
72463 goto out;
72464 }
72465 +
72466 err = vma_replace_policy(vma, new_pol);
72467 if (err)
72468 goto out;
72469 +
72470 +#ifdef CONFIG_PAX_SEGMEXEC
72471 + vma_m = pax_find_mirror_vma(vma);
72472 + err = vma_replace_policy(vma_m, new_pol);
72473 + if (err)
72474 + goto out;
72475 +#endif
72476 +
72477 }
72478
72479 out:
72480 @@ -1147,6 +1160,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72481
72482 if (end < start)
72483 return -EINVAL;
72484 +
72485 +#ifdef CONFIG_PAX_SEGMEXEC
72486 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72487 + if (end > SEGMEXEC_TASK_SIZE)
72488 + return -EINVAL;
72489 + } else
72490 +#endif
72491 +
72492 + if (end > TASK_SIZE)
72493 + return -EINVAL;
72494 +
72495 if (end == start)
72496 return 0;
72497
72498 @@ -1370,8 +1394,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72499 */
72500 tcred = __task_cred(task);
72501 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72502 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72503 - !capable(CAP_SYS_NICE)) {
72504 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72505 rcu_read_unlock();
72506 err = -EPERM;
72507 goto out_put;
72508 @@ -1402,6 +1425,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72509 goto out;
72510 }
72511
72512 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72513 + if (mm != current->mm &&
72514 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72515 + mmput(mm);
72516 + err = -EPERM;
72517 + goto out;
72518 + }
72519 +#endif
72520 +
72521 err = do_migrate_pages(mm, old, new,
72522 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72523
72524 diff --git a/mm/migrate.c b/mm/migrate.c
72525 index 77ed2d7..317d528 100644
72526 --- a/mm/migrate.c
72527 +++ b/mm/migrate.c
72528 @@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
72529 */
72530 tcred = __task_cred(task);
72531 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72532 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72533 - !capable(CAP_SYS_NICE)) {
72534 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72535 rcu_read_unlock();
72536 err = -EPERM;
72537 goto out;
72538 diff --git a/mm/mlock.c b/mm/mlock.c
72539 index ef726e8..cd7f1ec 100644
72540 --- a/mm/mlock.c
72541 +++ b/mm/mlock.c
72542 @@ -13,6 +13,7 @@
72543 #include <linux/pagemap.h>
72544 #include <linux/mempolicy.h>
72545 #include <linux/syscalls.h>
72546 +#include <linux/security.h>
72547 #include <linux/sched.h>
72548 #include <linux/export.h>
72549 #include <linux/rmap.h>
72550 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72551 {
72552 unsigned long nstart, end, tmp;
72553 struct vm_area_struct * vma, * prev;
72554 - int error;
72555 + int error = 0;
72556
72557 VM_BUG_ON(start & ~PAGE_MASK);
72558 VM_BUG_ON(len != PAGE_ALIGN(len));
72559 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72560 return -EINVAL;
72561 if (end == start)
72562 return 0;
72563 + if (end > TASK_SIZE)
72564 + return -EINVAL;
72565 +
72566 vma = find_vma(current->mm, start);
72567 if (!vma || vma->vm_start > start)
72568 return -ENOMEM;
72569 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72570 for (nstart = start ; ; ) {
72571 vm_flags_t newflags;
72572
72573 +#ifdef CONFIG_PAX_SEGMEXEC
72574 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72575 + break;
72576 +#endif
72577 +
72578 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72579
72580 newflags = vma->vm_flags | VM_LOCKED;
72581 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72582 lock_limit >>= PAGE_SHIFT;
72583
72584 /* check against resource limits */
72585 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72586 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72587 error = do_mlock(start, len, 1);
72588 up_write(&current->mm->mmap_sem);
72589 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72590 static int do_mlockall(int flags)
72591 {
72592 struct vm_area_struct * vma, * prev = NULL;
72593 - unsigned int def_flags = 0;
72594
72595 if (flags & MCL_FUTURE)
72596 - def_flags = VM_LOCKED;
72597 - current->mm->def_flags = def_flags;
72598 + current->mm->def_flags |= VM_LOCKED;
72599 + else
72600 + current->mm->def_flags &= ~VM_LOCKED;
72601 if (flags == MCL_FUTURE)
72602 goto out;
72603
72604 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72605 vm_flags_t newflags;
72606
72607 +#ifdef CONFIG_PAX_SEGMEXEC
72608 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72609 + break;
72610 +#endif
72611 +
72612 + BUG_ON(vma->vm_end > TASK_SIZE);
72613 newflags = vma->vm_flags | VM_LOCKED;
72614 if (!(flags & MCL_CURRENT))
72615 newflags &= ~VM_LOCKED;
72616 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72617 lock_limit >>= PAGE_SHIFT;
72618
72619 ret = -ENOMEM;
72620 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72621 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72622 capable(CAP_IPC_LOCK))
72623 ret = do_mlockall(flags);
72624 diff --git a/mm/mmap.c b/mm/mmap.c
72625 index ae18a48..86cf99e 100644
72626 --- a/mm/mmap.c
72627 +++ b/mm/mmap.c
72628 @@ -47,6 +47,16 @@
72629 #define arch_rebalance_pgtables(addr, len) (addr)
72630 #endif
72631
72632 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72633 +{
72634 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72635 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72636 + up_read(&mm->mmap_sem);
72637 + BUG();
72638 + }
72639 +#endif
72640 +}
72641 +
72642 static void unmap_region(struct mm_struct *mm,
72643 struct vm_area_struct *vma, struct vm_area_struct *prev,
72644 unsigned long start, unsigned long end);
72645 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72646 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72647 *
72648 */
72649 -pgprot_t protection_map[16] = {
72650 +pgprot_t protection_map[16] __read_only = {
72651 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72652 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72653 };
72654
72655 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72656 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72657 {
72658 - return __pgprot(pgprot_val(protection_map[vm_flags &
72659 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72660 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72661 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72662 +
72663 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72664 + if (!(__supported_pte_mask & _PAGE_NX) &&
72665 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72666 + (vm_flags & (VM_READ | VM_WRITE)))
72667 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72668 +#endif
72669 +
72670 + return prot;
72671 }
72672 EXPORT_SYMBOL(vm_get_page_prot);
72673
72674 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72675 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72676 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72677 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72678 /*
72679 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72680 * other variables. It can be updated by several CPUs frequently.
72681 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72682 struct vm_area_struct *next = vma->vm_next;
72683
72684 might_sleep();
72685 + BUG_ON(vma->vm_mirror);
72686 if (vma->vm_ops && vma->vm_ops->close)
72687 vma->vm_ops->close(vma);
72688 if (vma->vm_file) {
72689 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72690 * not page aligned -Ram Gupta
72691 */
72692 rlim = rlimit(RLIMIT_DATA);
72693 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72694 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72695 (mm->end_data - mm->start_data) > rlim)
72696 goto out;
72697 @@ -708,6 +730,12 @@ static int
72698 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72699 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72700 {
72701 +
72702 +#ifdef CONFIG_PAX_SEGMEXEC
72703 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72704 + return 0;
72705 +#endif
72706 +
72707 if (is_mergeable_vma(vma, file, vm_flags) &&
72708 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72709 if (vma->vm_pgoff == vm_pgoff)
72710 @@ -727,6 +755,12 @@ static int
72711 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72712 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72713 {
72714 +
72715 +#ifdef CONFIG_PAX_SEGMEXEC
72716 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72717 + return 0;
72718 +#endif
72719 +
72720 if (is_mergeable_vma(vma, file, vm_flags) &&
72721 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72722 pgoff_t vm_pglen;
72723 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72724 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72725 struct vm_area_struct *prev, unsigned long addr,
72726 unsigned long end, unsigned long vm_flags,
72727 - struct anon_vma *anon_vma, struct file *file,
72728 + struct anon_vma *anon_vma, struct file *file,
72729 pgoff_t pgoff, struct mempolicy *policy)
72730 {
72731 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72732 struct vm_area_struct *area, *next;
72733 int err;
72734
72735 +#ifdef CONFIG_PAX_SEGMEXEC
72736 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72737 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72738 +
72739 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72740 +#endif
72741 +
72742 /*
72743 * We later require that vma->vm_flags == vm_flags,
72744 * so this tests vma->vm_flags & VM_SPECIAL, too.
72745 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72746 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72747 next = next->vm_next;
72748
72749 +#ifdef CONFIG_PAX_SEGMEXEC
72750 + if (prev)
72751 + prev_m = pax_find_mirror_vma(prev);
72752 + if (area)
72753 + area_m = pax_find_mirror_vma(area);
72754 + if (next)
72755 + next_m = pax_find_mirror_vma(next);
72756 +#endif
72757 +
72758 /*
72759 * Can it merge with the predecessor?
72760 */
72761 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72762 /* cases 1, 6 */
72763 err = vma_adjust(prev, prev->vm_start,
72764 next->vm_end, prev->vm_pgoff, NULL);
72765 - } else /* cases 2, 5, 7 */
72766 +
72767 +#ifdef CONFIG_PAX_SEGMEXEC
72768 + if (!err && prev_m)
72769 + err = vma_adjust(prev_m, prev_m->vm_start,
72770 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72771 +#endif
72772 +
72773 + } else { /* cases 2, 5, 7 */
72774 err = vma_adjust(prev, prev->vm_start,
72775 end, prev->vm_pgoff, NULL);
72776 +
72777 +#ifdef CONFIG_PAX_SEGMEXEC
72778 + if (!err && prev_m)
72779 + err = vma_adjust(prev_m, prev_m->vm_start,
72780 + end_m, prev_m->vm_pgoff, NULL);
72781 +#endif
72782 +
72783 + }
72784 if (err)
72785 return NULL;
72786 khugepaged_enter_vma_merge(prev);
72787 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72788 mpol_equal(policy, vma_policy(next)) &&
72789 can_vma_merge_before(next, vm_flags,
72790 anon_vma, file, pgoff+pglen)) {
72791 - if (prev && addr < prev->vm_end) /* case 4 */
72792 + if (prev && addr < prev->vm_end) { /* case 4 */
72793 err = vma_adjust(prev, prev->vm_start,
72794 addr, prev->vm_pgoff, NULL);
72795 - else /* cases 3, 8 */
72796 +
72797 +#ifdef CONFIG_PAX_SEGMEXEC
72798 + if (!err && prev_m)
72799 + err = vma_adjust(prev_m, prev_m->vm_start,
72800 + addr_m, prev_m->vm_pgoff, NULL);
72801 +#endif
72802 +
72803 + } else { /* cases 3, 8 */
72804 err = vma_adjust(area, addr, next->vm_end,
72805 next->vm_pgoff - pglen, NULL);
72806 +
72807 +#ifdef CONFIG_PAX_SEGMEXEC
72808 + if (!err && area_m)
72809 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72810 + next_m->vm_pgoff - pglen, NULL);
72811 +#endif
72812 +
72813 + }
72814 if (err)
72815 return NULL;
72816 khugepaged_enter_vma_merge(area);
72817 @@ -940,16 +1020,13 @@ none:
72818 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72819 struct file *file, long pages)
72820 {
72821 - const unsigned long stack_flags
72822 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72823 -
72824 mm->total_vm += pages;
72825
72826 if (file) {
72827 mm->shared_vm += pages;
72828 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72829 mm->exec_vm += pages;
72830 - } else if (flags & stack_flags)
72831 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72832 mm->stack_vm += pages;
72833 if (flags & (VM_RESERVED|VM_IO))
72834 mm->reserved_vm += pages;
72835 @@ -987,7 +1064,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72836 * (the exception is when the underlying filesystem is noexec
72837 * mounted, in which case we dont add PROT_EXEC.)
72838 */
72839 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72840 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72841 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72842 prot |= PROT_EXEC;
72843
72844 @@ -1013,7 +1090,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72845 /* Obtain the address to map to. we verify (or select) it and ensure
72846 * that it represents a valid section of the address space.
72847 */
72848 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72849 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72850 if (addr & ~PAGE_MASK)
72851 return addr;
72852
72853 @@ -1024,6 +1101,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72854 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72855 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72856
72857 +#ifdef CONFIG_PAX_MPROTECT
72858 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72859 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72860 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72861 + gr_log_rwxmmap(file);
72862 +
72863 +#ifdef CONFIG_PAX_EMUPLT
72864 + vm_flags &= ~VM_EXEC;
72865 +#else
72866 + return -EPERM;
72867 +#endif
72868 +
72869 + }
72870 +
72871 + if (!(vm_flags & VM_EXEC))
72872 + vm_flags &= ~VM_MAYEXEC;
72873 +#else
72874 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
72875 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
72876 +#endif
72877 + else
72878 + vm_flags &= ~VM_MAYWRITE;
72879 + }
72880 +#endif
72881 +
72882 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72883 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
72884 + vm_flags &= ~VM_PAGEEXEC;
72885 +#endif
72886 +
72887 if (flags & MAP_LOCKED)
72888 if (!can_do_mlock())
72889 return -EPERM;
72890 @@ -1035,6 +1142,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72891 locked += mm->locked_vm;
72892 lock_limit = rlimit(RLIMIT_MEMLOCK);
72893 lock_limit >>= PAGE_SHIFT;
72894 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
72895 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
72896 return -EAGAIN;
72897 }
72898 @@ -1101,6 +1209,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72899 }
72900 }
72901
72902 + if (!gr_acl_handle_mmap(file, prot))
72903 + return -EACCES;
72904 +
72905 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
72906 }
72907
72908 @@ -1177,7 +1288,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
72909 vm_flags_t vm_flags = vma->vm_flags;
72910
72911 /* If it was private or non-writable, the write bit is already clear */
72912 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
72913 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
72914 return 0;
72915
72916 /* The backer wishes to know when pages are first written to? */
72917 @@ -1226,14 +1337,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
72918 unsigned long charged = 0;
72919 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
72920
72921 +#ifdef CONFIG_PAX_SEGMEXEC
72922 + struct vm_area_struct *vma_m = NULL;
72923 +#endif
72924 +
72925 + /*
72926 + * mm->mmap_sem is required to protect against another thread
72927 + * changing the mappings in case we sleep.
72928 + */
72929 + verify_mm_writelocked(mm);
72930 +
72931 /* Clear old maps */
72932 error = -ENOMEM;
72933 -munmap_back:
72934 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72935 if (vma && vma->vm_start < addr + len) {
72936 if (do_munmap(mm, addr, len))
72937 return -ENOMEM;
72938 - goto munmap_back;
72939 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
72940 + BUG_ON(vma && vma->vm_start < addr + len);
72941 }
72942
72943 /* Check against address space limit. */
72944 @@ -1282,6 +1403,16 @@ munmap_back:
72945 goto unacct_error;
72946 }
72947
72948 +#ifdef CONFIG_PAX_SEGMEXEC
72949 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
72950 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
72951 + if (!vma_m) {
72952 + error = -ENOMEM;
72953 + goto free_vma;
72954 + }
72955 + }
72956 +#endif
72957 +
72958 vma->vm_mm = mm;
72959 vma->vm_start = addr;
72960 vma->vm_end = addr + len;
72961 @@ -1306,6 +1437,19 @@ munmap_back:
72962 error = file->f_op->mmap(file, vma);
72963 if (error)
72964 goto unmap_and_free_vma;
72965 +
72966 +#ifdef CONFIG_PAX_SEGMEXEC
72967 + if (vma_m && (vm_flags & VM_EXECUTABLE))
72968 + added_exe_file_vma(mm);
72969 +#endif
72970 +
72971 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72972 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
72973 + vma->vm_flags |= VM_PAGEEXEC;
72974 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
72975 + }
72976 +#endif
72977 +
72978 if (vm_flags & VM_EXECUTABLE)
72979 added_exe_file_vma(mm);
72980
72981 @@ -1343,6 +1487,11 @@ munmap_back:
72982 vma_link(mm, vma, prev, rb_link, rb_parent);
72983 file = vma->vm_file;
72984
72985 +#ifdef CONFIG_PAX_SEGMEXEC
72986 + if (vma_m)
72987 + BUG_ON(pax_mirror_vma(vma_m, vma));
72988 +#endif
72989 +
72990 /* Once vma denies write, undo our temporary denial count */
72991 if (correct_wcount)
72992 atomic_inc(&inode->i_writecount);
72993 @@ -1350,6 +1499,7 @@ out:
72994 perf_event_mmap(vma);
72995
72996 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
72997 + track_exec_limit(mm, addr, addr + len, vm_flags);
72998 if (vm_flags & VM_LOCKED) {
72999 if (!mlock_vma_pages_range(vma, addr, addr + len))
73000 mm->locked_vm += (len >> PAGE_SHIFT);
73001 @@ -1371,6 +1521,12 @@ unmap_and_free_vma:
73002 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73003 charged = 0;
73004 free_vma:
73005 +
73006 +#ifdef CONFIG_PAX_SEGMEXEC
73007 + if (vma_m)
73008 + kmem_cache_free(vm_area_cachep, vma_m);
73009 +#endif
73010 +
73011 kmem_cache_free(vm_area_cachep, vma);
73012 unacct_error:
73013 if (charged)
73014 @@ -1378,6 +1534,44 @@ unacct_error:
73015 return error;
73016 }
73017
73018 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73019 +{
73020 + if (!vma) {
73021 +#ifdef CONFIG_STACK_GROWSUP
73022 + if (addr > sysctl_heap_stack_gap)
73023 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73024 + else
73025 + vma = find_vma(current->mm, 0);
73026 + if (vma && (vma->vm_flags & VM_GROWSUP))
73027 + return false;
73028 +#endif
73029 + return true;
73030 + }
73031 +
73032 + if (addr + len > vma->vm_start)
73033 + return false;
73034 +
73035 + if (vma->vm_flags & VM_GROWSDOWN)
73036 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73037 +#ifdef CONFIG_STACK_GROWSUP
73038 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73039 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73040 +#endif
73041 +
73042 + return true;
73043 +}
73044 +
73045 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73046 +{
73047 + if (vma->vm_start < len)
73048 + return -ENOMEM;
73049 + if (!(vma->vm_flags & VM_GROWSDOWN))
73050 + return vma->vm_start - len;
73051 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73052 + return vma->vm_start - len - sysctl_heap_stack_gap;
73053 + return -ENOMEM;
73054 +}
73055 +
73056 /* Get an address range which is currently unmapped.
73057 * For shmat() with addr=0.
73058 *
73059 @@ -1404,18 +1598,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73060 if (flags & MAP_FIXED)
73061 return addr;
73062
73063 +#ifdef CONFIG_PAX_RANDMMAP
73064 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73065 +#endif
73066 +
73067 if (addr) {
73068 addr = PAGE_ALIGN(addr);
73069 - vma = find_vma(mm, addr);
73070 - if (TASK_SIZE - len >= addr &&
73071 - (!vma || addr + len <= vma->vm_start))
73072 - return addr;
73073 + if (TASK_SIZE - len >= addr) {
73074 + vma = find_vma(mm, addr);
73075 + if (check_heap_stack_gap(vma, addr, len))
73076 + return addr;
73077 + }
73078 }
73079 if (len > mm->cached_hole_size) {
73080 - start_addr = addr = mm->free_area_cache;
73081 + start_addr = addr = mm->free_area_cache;
73082 } else {
73083 - start_addr = addr = TASK_UNMAPPED_BASE;
73084 - mm->cached_hole_size = 0;
73085 + start_addr = addr = mm->mmap_base;
73086 + mm->cached_hole_size = 0;
73087 }
73088
73089 full_search:
73090 @@ -1426,34 +1625,40 @@ full_search:
73091 * Start a new search - just in case we missed
73092 * some holes.
73093 */
73094 - if (start_addr != TASK_UNMAPPED_BASE) {
73095 - addr = TASK_UNMAPPED_BASE;
73096 - start_addr = addr;
73097 + if (start_addr != mm->mmap_base) {
73098 + start_addr = addr = mm->mmap_base;
73099 mm->cached_hole_size = 0;
73100 goto full_search;
73101 }
73102 return -ENOMEM;
73103 }
73104 - if (!vma || addr + len <= vma->vm_start) {
73105 - /*
73106 - * Remember the place where we stopped the search:
73107 - */
73108 - mm->free_area_cache = addr + len;
73109 - return addr;
73110 - }
73111 + if (check_heap_stack_gap(vma, addr, len))
73112 + break;
73113 if (addr + mm->cached_hole_size < vma->vm_start)
73114 mm->cached_hole_size = vma->vm_start - addr;
73115 addr = vma->vm_end;
73116 }
73117 +
73118 + /*
73119 + * Remember the place where we stopped the search:
73120 + */
73121 + mm->free_area_cache = addr + len;
73122 + return addr;
73123 }
73124 #endif
73125
73126 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73127 {
73128 +
73129 +#ifdef CONFIG_PAX_SEGMEXEC
73130 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73131 + return;
73132 +#endif
73133 +
73134 /*
73135 * Is this a new hole at the lowest possible address?
73136 */
73137 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73138 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73139 mm->free_area_cache = addr;
73140 }
73141
73142 @@ -1469,7 +1674,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73143 {
73144 struct vm_area_struct *vma;
73145 struct mm_struct *mm = current->mm;
73146 - unsigned long addr = addr0, start_addr;
73147 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73148
73149 /* requested length too big for entire address space */
73150 if (len > TASK_SIZE)
73151 @@ -1478,13 +1683,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73152 if (flags & MAP_FIXED)
73153 return addr;
73154
73155 +#ifdef CONFIG_PAX_RANDMMAP
73156 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73157 +#endif
73158 +
73159 /* requesting a specific address */
73160 if (addr) {
73161 addr = PAGE_ALIGN(addr);
73162 - vma = find_vma(mm, addr);
73163 - if (TASK_SIZE - len >= addr &&
73164 - (!vma || addr + len <= vma->vm_start))
73165 - return addr;
73166 + if (TASK_SIZE - len >= addr) {
73167 + vma = find_vma(mm, addr);
73168 + if (check_heap_stack_gap(vma, addr, len))
73169 + return addr;
73170 + }
73171 }
73172
73173 /* check if free_area_cache is useful for us */
73174 @@ -1508,7 +1718,7 @@ try_again:
73175 * return with success:
73176 */
73177 vma = find_vma(mm, addr);
73178 - if (!vma || addr+len <= vma->vm_start)
73179 + if (check_heap_stack_gap(vma, addr, len))
73180 /* remember the address as a hint for next time */
73181 return (mm->free_area_cache = addr);
73182
73183 @@ -1517,8 +1727,8 @@ try_again:
73184 mm->cached_hole_size = vma->vm_start - addr;
73185
73186 /* try just below the current vma->vm_start */
73187 - addr = vma->vm_start-len;
73188 - } while (len < vma->vm_start);
73189 + addr = skip_heap_stack_gap(vma, len);
73190 + } while (!IS_ERR_VALUE(addr));
73191
73192 fail:
73193 /*
73194 @@ -1541,13 +1751,21 @@ fail:
73195 * can happen with large stack limits and large mmap()
73196 * allocations.
73197 */
73198 + mm->mmap_base = TASK_UNMAPPED_BASE;
73199 +
73200 +#ifdef CONFIG_PAX_RANDMMAP
73201 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73202 + mm->mmap_base += mm->delta_mmap;
73203 +#endif
73204 +
73205 + mm->free_area_cache = mm->mmap_base;
73206 mm->cached_hole_size = ~0UL;
73207 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73208 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73209 /*
73210 * Restore the topdown base:
73211 */
73212 - mm->free_area_cache = mm->mmap_base;
73213 + mm->mmap_base = base;
73214 + mm->free_area_cache = base;
73215 mm->cached_hole_size = ~0UL;
73216
73217 return addr;
73218 @@ -1556,6 +1774,12 @@ fail:
73219
73220 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73221 {
73222 +
73223 +#ifdef CONFIG_PAX_SEGMEXEC
73224 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73225 + return;
73226 +#endif
73227 +
73228 /*
73229 * Is this a new hole at the highest possible address?
73230 */
73231 @@ -1563,8 +1787,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73232 mm->free_area_cache = addr;
73233
73234 /* dont allow allocations above current base */
73235 - if (mm->free_area_cache > mm->mmap_base)
73236 + if (mm->free_area_cache > mm->mmap_base) {
73237 mm->free_area_cache = mm->mmap_base;
73238 + mm->cached_hole_size = ~0UL;
73239 + }
73240 }
73241
73242 unsigned long
73243 @@ -1663,6 +1889,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73244 return vma;
73245 }
73246
73247 +#ifdef CONFIG_PAX_SEGMEXEC
73248 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73249 +{
73250 + struct vm_area_struct *vma_m;
73251 +
73252 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73253 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73254 + BUG_ON(vma->vm_mirror);
73255 + return NULL;
73256 + }
73257 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73258 + vma_m = vma->vm_mirror;
73259 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73260 + BUG_ON(vma->vm_file != vma_m->vm_file);
73261 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73262 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73263 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73264 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73265 + return vma_m;
73266 +}
73267 +#endif
73268 +
73269 /*
73270 * Verify that the stack growth is acceptable and
73271 * update accounting. This is shared with both the
73272 @@ -1679,6 +1927,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73273 return -ENOMEM;
73274
73275 /* Stack limit test */
73276 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73277 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73278 return -ENOMEM;
73279
73280 @@ -1689,6 +1938,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73281 locked = mm->locked_vm + grow;
73282 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73283 limit >>= PAGE_SHIFT;
73284 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73285 if (locked > limit && !capable(CAP_IPC_LOCK))
73286 return -ENOMEM;
73287 }
73288 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73289 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73290 * vma is the last one with address > vma->vm_end. Have to extend vma.
73291 */
73292 +#ifndef CONFIG_IA64
73293 +static
73294 +#endif
73295 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73296 {
73297 int error;
73298 + bool locknext;
73299
73300 if (!(vma->vm_flags & VM_GROWSUP))
73301 return -EFAULT;
73302
73303 + /* Also guard against wrapping around to address 0. */
73304 + if (address < PAGE_ALIGN(address+1))
73305 + address = PAGE_ALIGN(address+1);
73306 + else
73307 + return -ENOMEM;
73308 +
73309 /*
73310 * We must make sure the anon_vma is allocated
73311 * so that the anon_vma locking is not a noop.
73312 */
73313 if (unlikely(anon_vma_prepare(vma)))
73314 return -ENOMEM;
73315 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73316 + if (locknext && anon_vma_prepare(vma->vm_next))
73317 + return -ENOMEM;
73318 vma_lock_anon_vma(vma);
73319 + if (locknext)
73320 + vma_lock_anon_vma(vma->vm_next);
73321
73322 /*
73323 * vma->vm_start/vm_end cannot change under us because the caller
73324 * is required to hold the mmap_sem in read mode. We need the
73325 - * anon_vma lock to serialize against concurrent expand_stacks.
73326 - * Also guard against wrapping around to address 0.
73327 + * anon_vma locks to serialize against concurrent expand_stacks
73328 + * and expand_upwards.
73329 */
73330 - if (address < PAGE_ALIGN(address+4))
73331 - address = PAGE_ALIGN(address+4);
73332 - else {
73333 - vma_unlock_anon_vma(vma);
73334 - return -ENOMEM;
73335 - }
73336 error = 0;
73337
73338 /* Somebody else might have raced and expanded it already */
73339 - if (address > vma->vm_end) {
73340 + 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)
73341 + error = -ENOMEM;
73342 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73343 unsigned long size, grow;
73344
73345 size = address - vma->vm_start;
73346 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73347 }
73348 }
73349 }
73350 + if (locknext)
73351 + vma_unlock_anon_vma(vma->vm_next);
73352 vma_unlock_anon_vma(vma);
73353 khugepaged_enter_vma_merge(vma);
73354 return error;
73355 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73356 unsigned long address)
73357 {
73358 int error;
73359 + bool lockprev = false;
73360 + struct vm_area_struct *prev;
73361
73362 /*
73363 * We must make sure the anon_vma is allocated
73364 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73365 if (error)
73366 return error;
73367
73368 + prev = vma->vm_prev;
73369 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73370 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73371 +#endif
73372 + if (lockprev && anon_vma_prepare(prev))
73373 + return -ENOMEM;
73374 + if (lockprev)
73375 + vma_lock_anon_vma(prev);
73376 +
73377 vma_lock_anon_vma(vma);
73378
73379 /*
73380 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73381 */
73382
73383 /* Somebody else might have raced and expanded it already */
73384 - if (address < vma->vm_start) {
73385 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73386 + error = -ENOMEM;
73387 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73388 unsigned long size, grow;
73389
73390 +#ifdef CONFIG_PAX_SEGMEXEC
73391 + struct vm_area_struct *vma_m;
73392 +
73393 + vma_m = pax_find_mirror_vma(vma);
73394 +#endif
73395 +
73396 size = vma->vm_end - address;
73397 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73398
73399 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73400 if (!error) {
73401 vma->vm_start = address;
73402 vma->vm_pgoff -= grow;
73403 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73404 +
73405 +#ifdef CONFIG_PAX_SEGMEXEC
73406 + if (vma_m) {
73407 + vma_m->vm_start -= grow << PAGE_SHIFT;
73408 + vma_m->vm_pgoff -= grow;
73409 + }
73410 +#endif
73411 +
73412 perf_event_mmap(vma);
73413 }
73414 }
73415 }
73416 vma_unlock_anon_vma(vma);
73417 + if (lockprev)
73418 + vma_unlock_anon_vma(prev);
73419 khugepaged_enter_vma_merge(vma);
73420 return error;
73421 }
73422 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73423 do {
73424 long nrpages = vma_pages(vma);
73425
73426 +#ifdef CONFIG_PAX_SEGMEXEC
73427 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73428 + vma = remove_vma(vma);
73429 + continue;
73430 + }
73431 +#endif
73432 +
73433 if (vma->vm_flags & VM_ACCOUNT)
73434 nr_accounted += nrpages;
73435 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
73436 @@ -1931,6 +2231,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73437 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73438 vma->vm_prev = NULL;
73439 do {
73440 +
73441 +#ifdef CONFIG_PAX_SEGMEXEC
73442 + if (vma->vm_mirror) {
73443 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73444 + vma->vm_mirror->vm_mirror = NULL;
73445 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73446 + vma->vm_mirror = NULL;
73447 + }
73448 +#endif
73449 +
73450 rb_erase(&vma->vm_rb, &mm->mm_rb);
73451 mm->map_count--;
73452 tail_vma = vma;
73453 @@ -1959,14 +2269,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73454 struct vm_area_struct *new;
73455 int err = -ENOMEM;
73456
73457 +#ifdef CONFIG_PAX_SEGMEXEC
73458 + struct vm_area_struct *vma_m, *new_m = NULL;
73459 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73460 +#endif
73461 +
73462 if (is_vm_hugetlb_page(vma) && (addr &
73463 ~(huge_page_mask(hstate_vma(vma)))))
73464 return -EINVAL;
73465
73466 +#ifdef CONFIG_PAX_SEGMEXEC
73467 + vma_m = pax_find_mirror_vma(vma);
73468 +#endif
73469 +
73470 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73471 if (!new)
73472 goto out_err;
73473
73474 +#ifdef CONFIG_PAX_SEGMEXEC
73475 + if (vma_m) {
73476 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73477 + if (!new_m) {
73478 + kmem_cache_free(vm_area_cachep, new);
73479 + goto out_err;
73480 + }
73481 + }
73482 +#endif
73483 +
73484 /* most fields are the same, copy all, and then fixup */
73485 *new = *vma;
73486
73487 @@ -1979,6 +2308,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73488 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73489 }
73490
73491 +#ifdef CONFIG_PAX_SEGMEXEC
73492 + if (vma_m) {
73493 + *new_m = *vma_m;
73494 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73495 + new_m->vm_mirror = new;
73496 + new->vm_mirror = new_m;
73497 +
73498 + if (new_below)
73499 + new_m->vm_end = addr_m;
73500 + else {
73501 + new_m->vm_start = addr_m;
73502 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73503 + }
73504 + }
73505 +#endif
73506 +
73507 pol = mpol_dup(vma_policy(vma));
73508 if (IS_ERR(pol)) {
73509 err = PTR_ERR(pol);
73510 @@ -2004,6 +2349,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73511 else
73512 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73513
73514 +#ifdef CONFIG_PAX_SEGMEXEC
73515 + if (!err && vma_m) {
73516 + if (anon_vma_clone(new_m, vma_m))
73517 + goto out_free_mpol;
73518 +
73519 + mpol_get(pol);
73520 + vma_set_policy(new_m, pol);
73521 +
73522 + if (new_m->vm_file) {
73523 + get_file(new_m->vm_file);
73524 + if (vma_m->vm_flags & VM_EXECUTABLE)
73525 + added_exe_file_vma(mm);
73526 + }
73527 +
73528 + if (new_m->vm_ops && new_m->vm_ops->open)
73529 + new_m->vm_ops->open(new_m);
73530 +
73531 + if (new_below)
73532 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73533 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73534 + else
73535 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73536 +
73537 + if (err) {
73538 + if (new_m->vm_ops && new_m->vm_ops->close)
73539 + new_m->vm_ops->close(new_m);
73540 + if (new_m->vm_file) {
73541 + if (vma_m->vm_flags & VM_EXECUTABLE)
73542 + removed_exe_file_vma(mm);
73543 + fput(new_m->vm_file);
73544 + }
73545 + mpol_put(pol);
73546 + }
73547 + }
73548 +#endif
73549 +
73550 /* Success. */
73551 if (!err)
73552 return 0;
73553 @@ -2016,10 +2397,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73554 removed_exe_file_vma(mm);
73555 fput(new->vm_file);
73556 }
73557 - unlink_anon_vmas(new);
73558 out_free_mpol:
73559 mpol_put(pol);
73560 out_free_vma:
73561 +
73562 +#ifdef CONFIG_PAX_SEGMEXEC
73563 + if (new_m) {
73564 + unlink_anon_vmas(new_m);
73565 + kmem_cache_free(vm_area_cachep, new_m);
73566 + }
73567 +#endif
73568 +
73569 + unlink_anon_vmas(new);
73570 kmem_cache_free(vm_area_cachep, new);
73571 out_err:
73572 return err;
73573 @@ -2032,6 +2421,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73574 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73575 unsigned long addr, int new_below)
73576 {
73577 +
73578 +#ifdef CONFIG_PAX_SEGMEXEC
73579 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73580 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73581 + if (mm->map_count >= sysctl_max_map_count-1)
73582 + return -ENOMEM;
73583 + } else
73584 +#endif
73585 +
73586 if (mm->map_count >= sysctl_max_map_count)
73587 return -ENOMEM;
73588
73589 @@ -2043,11 +2441,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73590 * work. This now handles partial unmappings.
73591 * Jeremy Fitzhardinge <jeremy@goop.org>
73592 */
73593 +#ifdef CONFIG_PAX_SEGMEXEC
73594 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73595 {
73596 + int ret = __do_munmap(mm, start, len);
73597 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73598 + return ret;
73599 +
73600 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73601 +}
73602 +
73603 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73604 +#else
73605 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73606 +#endif
73607 +{
73608 unsigned long end;
73609 struct vm_area_struct *vma, *prev, *last;
73610
73611 + /*
73612 + * mm->mmap_sem is required to protect against another thread
73613 + * changing the mappings in case we sleep.
73614 + */
73615 + verify_mm_writelocked(mm);
73616 +
73617 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73618 return -EINVAL;
73619
73620 @@ -2122,6 +2539,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73621 /* Fix up all other VM information */
73622 remove_vma_list(mm, vma);
73623
73624 + track_exec_limit(mm, start, end, 0UL);
73625 +
73626 return 0;
73627 }
73628
73629 @@ -2130,6 +2549,13 @@ int vm_munmap(unsigned long start, size_t len)
73630 int ret;
73631 struct mm_struct *mm = current->mm;
73632
73633 +
73634 +#ifdef CONFIG_PAX_SEGMEXEC
73635 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73636 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73637 + return -EINVAL;
73638 +#endif
73639 +
73640 down_write(&mm->mmap_sem);
73641 ret = do_munmap(mm, start, len);
73642 up_write(&mm->mmap_sem);
73643 @@ -2143,16 +2569,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73644 return vm_munmap(addr, len);
73645 }
73646
73647 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73648 -{
73649 -#ifdef CONFIG_DEBUG_VM
73650 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73651 - WARN_ON(1);
73652 - up_read(&mm->mmap_sem);
73653 - }
73654 -#endif
73655 -}
73656 -
73657 /*
73658 * this is really a simplified "do_mmap". it only handles
73659 * anonymous maps. eventually we may be able to do some
73660 @@ -2166,6 +2582,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73661 struct rb_node ** rb_link, * rb_parent;
73662 pgoff_t pgoff = addr >> PAGE_SHIFT;
73663 int error;
73664 + unsigned long charged;
73665
73666 len = PAGE_ALIGN(len);
73667 if (!len)
73668 @@ -2173,16 +2590,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73669
73670 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73671
73672 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73673 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73674 + flags &= ~VM_EXEC;
73675 +
73676 +#ifdef CONFIG_PAX_MPROTECT
73677 + if (mm->pax_flags & MF_PAX_MPROTECT)
73678 + flags &= ~VM_MAYEXEC;
73679 +#endif
73680 +
73681 + }
73682 +#endif
73683 +
73684 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73685 if (error & ~PAGE_MASK)
73686 return error;
73687
73688 + charged = len >> PAGE_SHIFT;
73689 +
73690 /*
73691 * mlock MCL_FUTURE?
73692 */
73693 if (mm->def_flags & VM_LOCKED) {
73694 unsigned long locked, lock_limit;
73695 - locked = len >> PAGE_SHIFT;
73696 + locked = charged;
73697 locked += mm->locked_vm;
73698 lock_limit = rlimit(RLIMIT_MEMLOCK);
73699 lock_limit >>= PAGE_SHIFT;
73700 @@ -2199,22 +2630,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73701 /*
73702 * Clear old maps. this also does some error checking for us
73703 */
73704 - munmap_back:
73705 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73706 if (vma && vma->vm_start < addr + len) {
73707 if (do_munmap(mm, addr, len))
73708 return -ENOMEM;
73709 - goto munmap_back;
73710 - }
73711 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73712 + BUG_ON(vma && vma->vm_start < addr + len);
73713 + }
73714
73715 /* Check against address space limits *after* clearing old maps... */
73716 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73717 + if (!may_expand_vm(mm, charged))
73718 return -ENOMEM;
73719
73720 if (mm->map_count > sysctl_max_map_count)
73721 return -ENOMEM;
73722
73723 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73724 + if (security_vm_enough_memory_mm(mm, charged))
73725 return -ENOMEM;
73726
73727 /* Can we just expand an old private anonymous mapping? */
73728 @@ -2228,7 +2659,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73729 */
73730 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73731 if (!vma) {
73732 - vm_unacct_memory(len >> PAGE_SHIFT);
73733 + vm_unacct_memory(charged);
73734 return -ENOMEM;
73735 }
73736
73737 @@ -2242,11 +2673,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73738 vma_link(mm, vma, prev, rb_link, rb_parent);
73739 out:
73740 perf_event_mmap(vma);
73741 - mm->total_vm += len >> PAGE_SHIFT;
73742 + mm->total_vm += charged;
73743 if (flags & VM_LOCKED) {
73744 if (!mlock_vma_pages_range(vma, addr, addr + len))
73745 - mm->locked_vm += (len >> PAGE_SHIFT);
73746 + mm->locked_vm += charged;
73747 }
73748 + track_exec_limit(mm, addr, addr + len, flags);
73749 return addr;
73750 }
73751
73752 @@ -2304,6 +2736,7 @@ void exit_mmap(struct mm_struct *mm)
73753 while (vma) {
73754 if (vma->vm_flags & VM_ACCOUNT)
73755 nr_accounted += vma_pages(vma);
73756 + vma->vm_mirror = NULL;
73757 vma = remove_vma(vma);
73758 }
73759 vm_unacct_memory(nr_accounted);
73760 @@ -2320,6 +2753,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73761 struct vm_area_struct * __vma, * prev;
73762 struct rb_node ** rb_link, * rb_parent;
73763
73764 +#ifdef CONFIG_PAX_SEGMEXEC
73765 + struct vm_area_struct *vma_m = NULL;
73766 +#endif
73767 +
73768 + if (security_mmap_addr(vma->vm_start))
73769 + return -EPERM;
73770 +
73771 /*
73772 * The vm_pgoff of a purely anonymous vma should be irrelevant
73773 * until its first write fault, when page's anon_vma and index
73774 @@ -2343,7 +2783,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73775 security_vm_enough_memory_mm(mm, vma_pages(vma)))
73776 return -ENOMEM;
73777
73778 +#ifdef CONFIG_PAX_SEGMEXEC
73779 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73780 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73781 + if (!vma_m)
73782 + return -ENOMEM;
73783 + }
73784 +#endif
73785 +
73786 vma_link(mm, vma, prev, rb_link, rb_parent);
73787 +
73788 +#ifdef CONFIG_PAX_SEGMEXEC
73789 + if (vma_m)
73790 + BUG_ON(pax_mirror_vma(vma_m, vma));
73791 +#endif
73792 +
73793 return 0;
73794 }
73795
73796 @@ -2362,6 +2816,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73797 struct mempolicy *pol;
73798 bool faulted_in_anon_vma = true;
73799
73800 + BUG_ON(vma->vm_mirror);
73801 +
73802 /*
73803 * If anonymous vma has not yet been faulted, update new pgoff
73804 * to match new location, to increase its chance of merging.
73805 @@ -2430,6 +2886,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73806 return NULL;
73807 }
73808
73809 +#ifdef CONFIG_PAX_SEGMEXEC
73810 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73811 +{
73812 + struct vm_area_struct *prev_m;
73813 + struct rb_node **rb_link_m, *rb_parent_m;
73814 + struct mempolicy *pol_m;
73815 +
73816 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73817 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73818 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73819 + *vma_m = *vma;
73820 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73821 + if (anon_vma_clone(vma_m, vma))
73822 + return -ENOMEM;
73823 + pol_m = vma_policy(vma_m);
73824 + mpol_get(pol_m);
73825 + vma_set_policy(vma_m, pol_m);
73826 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73827 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73828 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73829 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73830 + if (vma_m->vm_file)
73831 + get_file(vma_m->vm_file);
73832 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73833 + vma_m->vm_ops->open(vma_m);
73834 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73835 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73836 + vma_m->vm_mirror = vma;
73837 + vma->vm_mirror = vma_m;
73838 + return 0;
73839 +}
73840 +#endif
73841 +
73842 /*
73843 * Return true if the calling process may expand its vm space by the passed
73844 * number of pages
73845 @@ -2441,6 +2930,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73846
73847 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73848
73849 +#ifdef CONFIG_PAX_RANDMMAP
73850 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73851 + cur -= mm->brk_gap;
73852 +#endif
73853 +
73854 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73855 if (cur + npages > lim)
73856 return 0;
73857 return 1;
73858 @@ -2511,6 +3006,22 @@ int install_special_mapping(struct mm_struct *mm,
73859 vma->vm_start = addr;
73860 vma->vm_end = addr + len;
73861
73862 +#ifdef CONFIG_PAX_MPROTECT
73863 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73864 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73865 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73866 + return -EPERM;
73867 + if (!(vm_flags & VM_EXEC))
73868 + vm_flags &= ~VM_MAYEXEC;
73869 +#else
73870 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73871 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73872 +#endif
73873 + else
73874 + vm_flags &= ~VM_MAYWRITE;
73875 + }
73876 +#endif
73877 +
73878 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
73879 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73880
73881 diff --git a/mm/mprotect.c b/mm/mprotect.c
73882 index a409926..8b32e6d 100644
73883 --- a/mm/mprotect.c
73884 +++ b/mm/mprotect.c
73885 @@ -23,10 +23,17 @@
73886 #include <linux/mmu_notifier.h>
73887 #include <linux/migrate.h>
73888 #include <linux/perf_event.h>
73889 +
73890 +#ifdef CONFIG_PAX_MPROTECT
73891 +#include <linux/elf.h>
73892 +#include <linux/binfmts.h>
73893 +#endif
73894 +
73895 #include <asm/uaccess.h>
73896 #include <asm/pgtable.h>
73897 #include <asm/cacheflush.h>
73898 #include <asm/tlbflush.h>
73899 +#include <asm/mmu_context.h>
73900
73901 #ifndef pgprot_modify
73902 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
73903 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
73904 flush_tlb_range(vma, start, end);
73905 }
73906
73907 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
73908 +/* called while holding the mmap semaphor for writing except stack expansion */
73909 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
73910 +{
73911 + unsigned long oldlimit, newlimit = 0UL;
73912 +
73913 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
73914 + return;
73915 +
73916 + spin_lock(&mm->page_table_lock);
73917 + oldlimit = mm->context.user_cs_limit;
73918 + if ((prot & VM_EXEC) && oldlimit < end)
73919 + /* USER_CS limit moved up */
73920 + newlimit = end;
73921 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
73922 + /* USER_CS limit moved down */
73923 + newlimit = start;
73924 +
73925 + if (newlimit) {
73926 + mm->context.user_cs_limit = newlimit;
73927 +
73928 +#ifdef CONFIG_SMP
73929 + wmb();
73930 + cpus_clear(mm->context.cpu_user_cs_mask);
73931 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
73932 +#endif
73933 +
73934 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
73935 + }
73936 + spin_unlock(&mm->page_table_lock);
73937 + if (newlimit == end) {
73938 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
73939 +
73940 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
73941 + if (is_vm_hugetlb_page(vma))
73942 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
73943 + else
73944 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
73945 + }
73946 +}
73947 +#endif
73948 +
73949 int
73950 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73951 unsigned long start, unsigned long end, unsigned long newflags)
73952 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73953 int error;
73954 int dirty_accountable = 0;
73955
73956 +#ifdef CONFIG_PAX_SEGMEXEC
73957 + struct vm_area_struct *vma_m = NULL;
73958 + unsigned long start_m, end_m;
73959 +
73960 + start_m = start + SEGMEXEC_TASK_SIZE;
73961 + end_m = end + SEGMEXEC_TASK_SIZE;
73962 +#endif
73963 +
73964 if (newflags == oldflags) {
73965 *pprev = vma;
73966 return 0;
73967 }
73968
73969 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
73970 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
73971 +
73972 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
73973 + return -ENOMEM;
73974 +
73975 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
73976 + return -ENOMEM;
73977 + }
73978 +
73979 /*
73980 * If we make a private mapping writable we increase our commit;
73981 * but (without finer accounting) cannot reduce our commit if we
73982 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
73983 }
73984 }
73985
73986 +#ifdef CONFIG_PAX_SEGMEXEC
73987 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
73988 + if (start != vma->vm_start) {
73989 + error = split_vma(mm, vma, start, 1);
73990 + if (error)
73991 + goto fail;
73992 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
73993 + *pprev = (*pprev)->vm_next;
73994 + }
73995 +
73996 + if (end != vma->vm_end) {
73997 + error = split_vma(mm, vma, end, 0);
73998 + if (error)
73999 + goto fail;
74000 + }
74001 +
74002 + if (pax_find_mirror_vma(vma)) {
74003 + error = __do_munmap(mm, start_m, end_m - start_m);
74004 + if (error)
74005 + goto fail;
74006 + } else {
74007 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74008 + if (!vma_m) {
74009 + error = -ENOMEM;
74010 + goto fail;
74011 + }
74012 + vma->vm_flags = newflags;
74013 + error = pax_mirror_vma(vma_m, vma);
74014 + if (error) {
74015 + vma->vm_flags = oldflags;
74016 + goto fail;
74017 + }
74018 + }
74019 + }
74020 +#endif
74021 +
74022 /*
74023 * First try to merge with previous and/or next vma.
74024 */
74025 @@ -204,9 +307,21 @@ success:
74026 * vm_flags and vm_page_prot are protected by the mmap_sem
74027 * held in write mode.
74028 */
74029 +
74030 +#ifdef CONFIG_PAX_SEGMEXEC
74031 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74032 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74033 +#endif
74034 +
74035 vma->vm_flags = newflags;
74036 +
74037 +#ifdef CONFIG_PAX_MPROTECT
74038 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74039 + mm->binfmt->handle_mprotect(vma, newflags);
74040 +#endif
74041 +
74042 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74043 - vm_get_page_prot(newflags));
74044 + vm_get_page_prot(vma->vm_flags));
74045
74046 if (vma_wants_writenotify(vma)) {
74047 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74048 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74049 end = start + len;
74050 if (end <= start)
74051 return -ENOMEM;
74052 +
74053 +#ifdef CONFIG_PAX_SEGMEXEC
74054 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74055 + if (end > SEGMEXEC_TASK_SIZE)
74056 + return -EINVAL;
74057 + } else
74058 +#endif
74059 +
74060 + if (end > TASK_SIZE)
74061 + return -EINVAL;
74062 +
74063 if (!arch_validate_prot(prot))
74064 return -EINVAL;
74065
74066 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74067 /*
74068 * Does the application expect PROT_READ to imply PROT_EXEC:
74069 */
74070 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74071 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74072 prot |= PROT_EXEC;
74073
74074 vm_flags = calc_vm_prot_bits(prot);
74075 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74076 if (start > vma->vm_start)
74077 prev = vma;
74078
74079 +#ifdef CONFIG_PAX_MPROTECT
74080 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74081 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74082 +#endif
74083 +
74084 for (nstart = start ; ; ) {
74085 unsigned long newflags;
74086
74087 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74088
74089 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74090 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74091 + if (prot & (PROT_WRITE | PROT_EXEC))
74092 + gr_log_rwxmprotect(vma->vm_file);
74093 +
74094 + error = -EACCES;
74095 + goto out;
74096 + }
74097 +
74098 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74099 error = -EACCES;
74100 goto out;
74101 }
74102 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74103 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74104 if (error)
74105 goto out;
74106 +
74107 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74108 +
74109 nstart = tmp;
74110
74111 if (nstart < prev->vm_end)
74112 diff --git a/mm/mremap.c b/mm/mremap.c
74113 index cc06d0e..40b5d18 100644
74114 --- a/mm/mremap.c
74115 +++ b/mm/mremap.c
74116 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74117 continue;
74118 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74119 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74120 +
74121 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74122 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74123 + pte = pte_exprotect(pte);
74124 +#endif
74125 +
74126 set_pte_at(mm, new_addr, new_pte, pte);
74127 }
74128
74129 @@ -298,6 +304,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74130 if (is_vm_hugetlb_page(vma))
74131 goto Einval;
74132
74133 +#ifdef CONFIG_PAX_SEGMEXEC
74134 + if (pax_find_mirror_vma(vma))
74135 + goto Einval;
74136 +#endif
74137 +
74138 /* We can't remap across vm area boundaries */
74139 if (old_len > vma->vm_end - addr)
74140 goto Efault;
74141 @@ -354,20 +365,25 @@ static unsigned long mremap_to(unsigned long addr,
74142 unsigned long ret = -EINVAL;
74143 unsigned long charged = 0;
74144 unsigned long map_flags;
74145 + unsigned long pax_task_size = TASK_SIZE;
74146
74147 if (new_addr & ~PAGE_MASK)
74148 goto out;
74149
74150 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74151 +#ifdef CONFIG_PAX_SEGMEXEC
74152 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74153 + pax_task_size = SEGMEXEC_TASK_SIZE;
74154 +#endif
74155 +
74156 + pax_task_size -= PAGE_SIZE;
74157 +
74158 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74159 goto out;
74160
74161 /* Check if the location we're moving into overlaps the
74162 * old location at all, and fail if it does.
74163 */
74164 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74165 - goto out;
74166 -
74167 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74168 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74169 goto out;
74170
74171 ret = do_munmap(mm, new_addr, new_len);
74172 @@ -435,6 +451,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74173 struct vm_area_struct *vma;
74174 unsigned long ret = -EINVAL;
74175 unsigned long charged = 0;
74176 + unsigned long pax_task_size = TASK_SIZE;
74177
74178 down_write(&current->mm->mmap_sem);
74179
74180 @@ -455,6 +472,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74181 if (!new_len)
74182 goto out;
74183
74184 +#ifdef CONFIG_PAX_SEGMEXEC
74185 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74186 + pax_task_size = SEGMEXEC_TASK_SIZE;
74187 +#endif
74188 +
74189 + pax_task_size -= PAGE_SIZE;
74190 +
74191 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74192 + old_len > pax_task_size || addr > pax_task_size-old_len)
74193 + goto out;
74194 +
74195 if (flags & MREMAP_FIXED) {
74196 if (flags & MREMAP_MAYMOVE)
74197 ret = mremap_to(addr, old_len, new_addr, new_len);
74198 @@ -503,6 +531,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74199 addr + new_len);
74200 }
74201 ret = addr;
74202 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74203 goto out;
74204 }
74205 }
74206 @@ -526,7 +555,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74207 goto out;
74208 }
74209
74210 + map_flags = vma->vm_flags;
74211 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74212 + if (!(ret & ~PAGE_MASK)) {
74213 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74214 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74215 + }
74216 }
74217 out:
74218 if (ret & ~PAGE_MASK)
74219 diff --git a/mm/nommu.c b/mm/nommu.c
74220 index d4b0c10..ed421b5 100644
74221 --- a/mm/nommu.c
74222 +++ b/mm/nommu.c
74223 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74224 int sysctl_overcommit_ratio = 50; /* default is 50% */
74225 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74226 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74227 -int heap_stack_gap = 0;
74228
74229 atomic_long_t mmap_pages_allocated;
74230
74231 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74232 EXPORT_SYMBOL(find_vma);
74233
74234 /*
74235 - * find a VMA
74236 - * - we don't extend stack VMAs under NOMMU conditions
74237 - */
74238 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74239 -{
74240 - return find_vma(mm, addr);
74241 -}
74242 -
74243 -/*
74244 * expand a stack to a given address
74245 * - not supported under NOMMU conditions
74246 */
74247 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74248
74249 /* most fields are the same, copy all, and then fixup */
74250 *new = *vma;
74251 + INIT_LIST_HEAD(&new->anon_vma_chain);
74252 *region = *vma->vm_region;
74253 new->vm_region = region;
74254
74255 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74256 index c13ea75..081ab2c 100644
74257 --- a/mm/page_alloc.c
74258 +++ b/mm/page_alloc.c
74259 @@ -340,7 +340,7 @@ out:
74260 * This usage means that zero-order pages may not be compound.
74261 */
74262
74263 -static void free_compound_page(struct page *page)
74264 +void free_compound_page(struct page *page)
74265 {
74266 __free_pages_ok(page, compound_order(page));
74267 }
74268 @@ -697,6 +697,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74269 int i;
74270 int bad = 0;
74271
74272 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74273 + unsigned long index = 1UL << order;
74274 +#endif
74275 +
74276 trace_mm_page_free(page, order);
74277 kmemcheck_free_shadow(page, order);
74278
74279 @@ -712,6 +716,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74280 debug_check_no_obj_freed(page_address(page),
74281 PAGE_SIZE << order);
74282 }
74283 +
74284 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74285 + for (; index; --index)
74286 + sanitize_highpage(page + index - 1);
74287 +#endif
74288 +
74289 arch_free_page(page, order);
74290 kernel_map_pages(page, 1 << order, 0);
74291
74292 @@ -853,8 +863,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74293 arch_alloc_page(page, order);
74294 kernel_map_pages(page, 1 << order, 1);
74295
74296 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74297 if (gfp_flags & __GFP_ZERO)
74298 prep_zero_page(page, order, gfp_flags);
74299 +#endif
74300
74301 if (order && (gfp_flags & __GFP_COMP))
74302 prep_compound_page(page, order);
74303 @@ -3648,7 +3660,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74304 unsigned long pfn;
74305
74306 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74307 +#ifdef CONFIG_X86_32
74308 + /* boot failures in VMware 8 on 32bit vanilla since
74309 + this change */
74310 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74311 +#else
74312 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74313 +#endif
74314 return 1;
74315 }
74316 return 0;
74317 diff --git a/mm/percpu.c b/mm/percpu.c
74318 index bb4be74..a43ea85 100644
74319 --- a/mm/percpu.c
74320 +++ b/mm/percpu.c
74321 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74322 static unsigned int pcpu_high_unit_cpu __read_mostly;
74323
74324 /* the address of the first chunk which starts with the kernel static area */
74325 -void *pcpu_base_addr __read_mostly;
74326 +void *pcpu_base_addr __read_only;
74327 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74328
74329 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74330 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74331 index 926b466..b23df53 100644
74332 --- a/mm/process_vm_access.c
74333 +++ b/mm/process_vm_access.c
74334 @@ -13,6 +13,7 @@
74335 #include <linux/uio.h>
74336 #include <linux/sched.h>
74337 #include <linux/highmem.h>
74338 +#include <linux/security.h>
74339 #include <linux/ptrace.h>
74340 #include <linux/slab.h>
74341 #include <linux/syscalls.h>
74342 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74343 size_t iov_l_curr_offset = 0;
74344 ssize_t iov_len;
74345
74346 + return -ENOSYS; // PaX: until properly audited
74347 +
74348 /*
74349 * Work out how many pages of struct pages we're going to need
74350 * when eventually calling get_user_pages
74351 */
74352 for (i = 0; i < riovcnt; i++) {
74353 iov_len = rvec[i].iov_len;
74354 - if (iov_len > 0) {
74355 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74356 - + iov_len)
74357 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74358 - / PAGE_SIZE + 1;
74359 - nr_pages = max(nr_pages, nr_pages_iov);
74360 - }
74361 + if (iov_len <= 0)
74362 + continue;
74363 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74364 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74365 + nr_pages = max(nr_pages, nr_pages_iov);
74366 }
74367
74368 if (nr_pages == 0)
74369 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74370 goto free_proc_pages;
74371 }
74372
74373 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74374 + rc = -EPERM;
74375 + goto put_task_struct;
74376 + }
74377 +
74378 mm = mm_access(task, PTRACE_MODE_ATTACH);
74379 if (!mm || IS_ERR(mm)) {
74380 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74381 diff --git a/mm/rmap.c b/mm/rmap.c
74382 index 0f3b7cd..c5652b6 100644
74383 --- a/mm/rmap.c
74384 +++ b/mm/rmap.c
74385 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74386 struct anon_vma *anon_vma = vma->anon_vma;
74387 struct anon_vma_chain *avc;
74388
74389 +#ifdef CONFIG_PAX_SEGMEXEC
74390 + struct anon_vma_chain *avc_m = NULL;
74391 +#endif
74392 +
74393 might_sleep();
74394 if (unlikely(!anon_vma)) {
74395 struct mm_struct *mm = vma->vm_mm;
74396 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74397 if (!avc)
74398 goto out_enomem;
74399
74400 +#ifdef CONFIG_PAX_SEGMEXEC
74401 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74402 + if (!avc_m)
74403 + goto out_enomem_free_avc;
74404 +#endif
74405 +
74406 anon_vma = find_mergeable_anon_vma(vma);
74407 allocated = NULL;
74408 if (!anon_vma) {
74409 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74410 /* page_table_lock to protect against threads */
74411 spin_lock(&mm->page_table_lock);
74412 if (likely(!vma->anon_vma)) {
74413 +
74414 +#ifdef CONFIG_PAX_SEGMEXEC
74415 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74416 +
74417 + if (vma_m) {
74418 + BUG_ON(vma_m->anon_vma);
74419 + vma_m->anon_vma = anon_vma;
74420 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74421 + avc_m = NULL;
74422 + }
74423 +#endif
74424 +
74425 vma->anon_vma = anon_vma;
74426 anon_vma_chain_link(vma, avc, anon_vma);
74427 allocated = NULL;
74428 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74429
74430 if (unlikely(allocated))
74431 put_anon_vma(allocated);
74432 +
74433 +#ifdef CONFIG_PAX_SEGMEXEC
74434 + if (unlikely(avc_m))
74435 + anon_vma_chain_free(avc_m);
74436 +#endif
74437 +
74438 if (unlikely(avc))
74439 anon_vma_chain_free(avc);
74440 }
74441 return 0;
74442
74443 out_enomem_free_avc:
74444 +
74445 +#ifdef CONFIG_PAX_SEGMEXEC
74446 + if (avc_m)
74447 + anon_vma_chain_free(avc_m);
74448 +#endif
74449 +
74450 anon_vma_chain_free(avc);
74451 out_enomem:
74452 return -ENOMEM;
74453 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74454 * Attach the anon_vmas from src to dst.
74455 * Returns 0 on success, -ENOMEM on failure.
74456 */
74457 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74458 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74459 {
74460 struct anon_vma_chain *avc, *pavc;
74461 struct anon_vma *root = NULL;
74462 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74463 * the corresponding VMA in the parent process is attached to.
74464 * Returns 0 on success, non-zero on failure.
74465 */
74466 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74467 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74468 {
74469 struct anon_vma_chain *avc;
74470 struct anon_vma *anon_vma;
74471 diff --git a/mm/shmem.c b/mm/shmem.c
74472 index d4e184e..9953cdd 100644
74473 --- a/mm/shmem.c
74474 +++ b/mm/shmem.c
74475 @@ -31,7 +31,7 @@
74476 #include <linux/export.h>
74477 #include <linux/swap.h>
74478
74479 -static struct vfsmount *shm_mnt;
74480 +struct vfsmount *shm_mnt;
74481
74482 #ifdef CONFIG_SHMEM
74483 /*
74484 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74485 #define BOGO_DIRENT_SIZE 20
74486
74487 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74488 -#define SHORT_SYMLINK_LEN 128
74489 +#define SHORT_SYMLINK_LEN 64
74490
74491 struct shmem_xattr {
74492 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74493 @@ -2592,8 +2592,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74494 int err = -ENOMEM;
74495
74496 /* Round up to L1_CACHE_BYTES to resist false sharing */
74497 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74498 - L1_CACHE_BYTES), GFP_KERNEL);
74499 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74500 if (!sbinfo)
74501 return -ENOMEM;
74502
74503 diff --git a/mm/slab.c b/mm/slab.c
74504 index d066037..5bb78d9 100644
74505 --- a/mm/slab.c
74506 +++ b/mm/slab.c
74507 @@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
74508
74509 /* Legal flag mask for kmem_cache_create(). */
74510 #if DEBUG
74511 -# define CREATE_MASK (SLAB_RED_ZONE | \
74512 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74513 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74514 SLAB_CACHE_DMA | \
74515 SLAB_STORE_USER | \
74516 @@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
74517 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74518 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74519 #else
74520 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74521 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74522 SLAB_CACHE_DMA | \
74523 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74524 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74525 @@ -322,7 +322,7 @@ struct kmem_list3 {
74526 * Need this for bootstrapping a per node allocator.
74527 */
74528 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74529 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74530 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74531 #define CACHE_CACHE 0
74532 #define SIZE_AC MAX_NUMNODES
74533 #define SIZE_L3 (2 * MAX_NUMNODES)
74534 @@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74535 if ((x)->max_freeable < i) \
74536 (x)->max_freeable = i; \
74537 } while (0)
74538 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74539 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74540 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74541 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74542 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74543 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74544 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74545 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74546 #else
74547 #define STATS_INC_ACTIVE(x) do { } while (0)
74548 #define STATS_DEC_ACTIVE(x) do { } while (0)
74549 @@ -549,7 +549,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74550 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74551 */
74552 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74553 - const struct slab *slab, void *obj)
74554 + const struct slab *slab, const void *obj)
74555 {
74556 u32 offset = (obj - slab->s_mem);
74557 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74558 @@ -570,12 +570,13 @@ EXPORT_SYMBOL(malloc_sizes);
74559 struct cache_names {
74560 char *name;
74561 char *name_dma;
74562 + char *name_usercopy;
74563 };
74564
74565 static struct cache_names __initdata cache_names[] = {
74566 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74567 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74568 #include <linux/kmalloc_sizes.h>
74569 - {NULL,}
74570 + {NULL}
74571 #undef CACHE
74572 };
74573
74574 @@ -736,6 +737,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74575 if (unlikely(gfpflags & GFP_DMA))
74576 return csizep->cs_dmacachep;
74577 #endif
74578 +
74579 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74580 + if (unlikely(gfpflags & GFP_USERCOPY))
74581 + return csizep->cs_usercopycachep;
74582 +#endif
74583 +
74584 return csizep->cs_cachep;
74585 }
74586
74587 @@ -1684,7 +1691,7 @@ void __init kmem_cache_init(void)
74588 sizes[INDEX_AC].cs_cachep = __kmem_cache_create(names[INDEX_AC].name,
74589 sizes[INDEX_AC].cs_size,
74590 ARCH_KMALLOC_MINALIGN,
74591 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74592 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74593 NULL);
74594
74595 if (INDEX_AC != INDEX_L3) {
74596 @@ -1692,7 +1699,7 @@ void __init kmem_cache_init(void)
74597 __kmem_cache_create(names[INDEX_L3].name,
74598 sizes[INDEX_L3].cs_size,
74599 ARCH_KMALLOC_MINALIGN,
74600 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74601 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74602 NULL);
74603 }
74604
74605 @@ -1710,7 +1717,7 @@ void __init kmem_cache_init(void)
74606 sizes->cs_cachep = __kmem_cache_create(names->name,
74607 sizes->cs_size,
74608 ARCH_KMALLOC_MINALIGN,
74609 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74610 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74611 NULL);
74612 }
74613 #ifdef CONFIG_ZONE_DMA
74614 @@ -1722,6 +1729,16 @@ void __init kmem_cache_init(void)
74615 SLAB_PANIC,
74616 NULL);
74617 #endif
74618 +
74619 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74620 + sizes->cs_usercopycachep = kmem_cache_create(
74621 + names->name_usercopy,
74622 + sizes->cs_size,
74623 + ARCH_KMALLOC_MINALIGN,
74624 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74625 + NULL);
74626 +#endif
74627 +
74628 sizes++;
74629 names++;
74630 }
74631 @@ -4467,10 +4484,10 @@ static int s_show(struct seq_file *m, void *p)
74632 }
74633 /* cpu stats */
74634 {
74635 - unsigned long allochit = atomic_read(&cachep->allochit);
74636 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74637 - unsigned long freehit = atomic_read(&cachep->freehit);
74638 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74639 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74640 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74641 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74642 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74643
74644 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74645 allochit, allocmiss, freehit, freemiss);
74646 @@ -4729,13 +4746,71 @@ static int __init slab_proc_init(void)
74647 {
74648 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74649 #ifdef CONFIG_DEBUG_SLAB_LEAK
74650 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74651 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74652 #endif
74653 return 0;
74654 }
74655 module_init(slab_proc_init);
74656 #endif
74657
74658 +bool is_usercopy_object(const void *ptr)
74659 +{
74660 + struct page *page;
74661 + struct kmem_cache *cachep;
74662 +
74663 + if (ZERO_OR_NULL_PTR(ptr))
74664 + return false;
74665 +
74666 + if (!slab_is_available())
74667 + return false;
74668 +
74669 + if (!virt_addr_valid(ptr))
74670 + return false;
74671 +
74672 + page = virt_to_head_page(ptr);
74673 +
74674 + if (!PageSlab(page))
74675 + return false;
74676 +
74677 + cachep = page_get_cache(page);
74678 + return cachep->flags & SLAB_USERCOPY;
74679 +}
74680 +
74681 +#ifdef CONFIG_PAX_USERCOPY
74682 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74683 +{
74684 + struct page *page;
74685 + struct kmem_cache *cachep;
74686 + struct slab *slabp;
74687 + unsigned int objnr;
74688 + unsigned long offset;
74689 +
74690 + if (ZERO_OR_NULL_PTR(ptr))
74691 + return "<null>";
74692 +
74693 + if (!virt_addr_valid(ptr))
74694 + return NULL;
74695 +
74696 + page = virt_to_head_page(ptr);
74697 +
74698 + if (!PageSlab(page))
74699 + return NULL;
74700 +
74701 + cachep = page_get_cache(page);
74702 + if (!(cachep->flags & SLAB_USERCOPY))
74703 + return cachep->name;
74704 +
74705 + slabp = page->slab_page;
74706 + objnr = obj_to_index(cachep, slabp, ptr);
74707 + BUG_ON(objnr >= cachep->num);
74708 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74709 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
74710 + return NULL;
74711 +
74712 + return cachep->name;
74713 +}
74714 +#endif
74715 +
74716 /**
74717 * ksize - get the actual amount of memory allocated for a given object
74718 * @objp: Pointer to the object
74719 diff --git a/mm/slob.c b/mm/slob.c
74720 index 45d4ca7..88943c1 100644
74721 --- a/mm/slob.c
74722 +++ b/mm/slob.c
74723 @@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74724 /*
74725 * Return the size of a slob block.
74726 */
74727 -static slobidx_t slob_units(slob_t *s)
74728 +static slobidx_t slob_units(const slob_t *s)
74729 {
74730 if (s->units > 0)
74731 return s->units;
74732 @@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
74733 /*
74734 * Return the next free slob block pointer after this one.
74735 */
74736 -static slob_t *slob_next(slob_t *s)
74737 +static slob_t *slob_next(const slob_t *s)
74738 {
74739 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74740 slobidx_t next;
74741 @@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
74742 /*
74743 * Returns true if s is the last free block in its page.
74744 */
74745 -static int slob_last(slob_t *s)
74746 +static int slob_last(const slob_t *s)
74747 {
74748 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74749 }
74750
74751 -static void *slob_new_pages(gfp_t gfp, int order, int node)
74752 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
74753 {
74754 - void *page;
74755 + struct page *page;
74756
74757 #ifdef CONFIG_NUMA
74758 if (node != -1)
74759 @@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74760 if (!page)
74761 return NULL;
74762
74763 - return page_address(page);
74764 + __SetPageSlab(page);
74765 + return page;
74766 }
74767
74768 -static void slob_free_pages(void *b, int order)
74769 +static void slob_free_pages(struct page *sp, int order)
74770 {
74771 if (current->reclaim_state)
74772 current->reclaim_state->reclaimed_slab += 1 << order;
74773 - free_pages((unsigned long)b, order);
74774 + __ClearPageSlab(sp);
74775 + reset_page_mapcount(sp);
74776 + sp->private = 0;
74777 + __free_pages(sp, order);
74778 }
74779
74780 /*
74781 @@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74782
74783 /* Not enough space: must allocate a new page */
74784 if (!b) {
74785 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74786 - if (!b)
74787 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
74788 + if (!sp)
74789 return NULL;
74790 - sp = virt_to_page(b);
74791 - __SetPageSlab(sp);
74792 + b = page_address(sp);
74793
74794 spin_lock_irqsave(&slob_lock, flags);
74795 sp->units = SLOB_UNITS(PAGE_SIZE);
74796 sp->freelist = b;
74797 + sp->private = 0;
74798 INIT_LIST_HEAD(&sp->list);
74799 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74800 set_slob_page_free(sp, slob_list);
74801 @@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
74802 if (slob_page_free(sp))
74803 clear_slob_page_free(sp);
74804 spin_unlock_irqrestore(&slob_lock, flags);
74805 - __ClearPageSlab(sp);
74806 - reset_page_mapcount(sp);
74807 - slob_free_pages(b, 0);
74808 + slob_free_pages(sp, 0);
74809 return;
74810 }
74811
74812 @@ -425,11 +427,10 @@ out:
74813 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74814 */
74815
74816 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74817 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74818 {
74819 - unsigned int *m;
74820 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74821 - void *ret;
74822 + slob_t *m;
74823 + void *ret = NULL;
74824
74825 gfp &= gfp_allowed_mask;
74826
74827 @@ -443,20 +444,23 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74828
74829 if (!m)
74830 return NULL;
74831 - *m = size;
74832 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74833 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74834 + m[0].units = size;
74835 + m[1].units = align;
74836 ret = (void *)m + align;
74837
74838 trace_kmalloc_node(_RET_IP_, ret,
74839 size, size + align, gfp, node);
74840 } else {
74841 unsigned int order = get_order(size);
74842 + struct page *page;
74843
74844 if (likely(order))
74845 gfp |= __GFP_COMP;
74846 - ret = slob_new_pages(gfp, order, node);
74847 - if (ret) {
74848 - struct page *page;
74849 - page = virt_to_page(ret);
74850 + page = slob_new_pages(gfp, order, node);
74851 + if (page) {
74852 + ret = page_address(page);
74853 page->private = size;
74854 }
74855
74856 @@ -464,7 +468,16 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74857 size, PAGE_SIZE << order, gfp, node);
74858 }
74859
74860 - kmemleak_alloc(ret, size, 1, gfp);
74861 + return ret;
74862 +}
74863 +
74864 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74865 +{
74866 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74867 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74868 +
74869 + if (!ZERO_OR_NULL_PTR(ret))
74870 + kmemleak_alloc(ret, size, 1, gfp);
74871 return ret;
74872 }
74873 EXPORT_SYMBOL(__kmalloc_node);
74874 @@ -480,15 +493,91 @@ void kfree(const void *block)
74875 kmemleak_free(block);
74876
74877 sp = virt_to_page(block);
74878 - if (PageSlab(sp)) {
74879 + VM_BUG_ON(!PageSlab(sp));
74880 + if (!sp->private) {
74881 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74882 - unsigned int *m = (unsigned int *)(block - align);
74883 - slob_free(m, *m + align);
74884 - } else
74885 + slob_t *m = (slob_t *)(block - align);
74886 + slob_free(m, m[0].units + align);
74887 + } else {
74888 + __ClearPageSlab(sp);
74889 + reset_page_mapcount(sp);
74890 + sp->private = 0;
74891 put_page(sp);
74892 + }
74893 }
74894 EXPORT_SYMBOL(kfree);
74895
74896 +bool is_usercopy_object(const void *ptr)
74897 +{
74898 + if (!slab_is_available())
74899 + return false;
74900 +
74901 + // PAX: TODO
74902 +
74903 + return false;
74904 +}
74905 +
74906 +#ifdef CONFIG_PAX_USERCOPY
74907 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74908 +{
74909 + struct page *page;
74910 + const slob_t *free;
74911 + const void *base;
74912 + unsigned long flags;
74913 +
74914 + if (ZERO_OR_NULL_PTR(ptr))
74915 + return "<null>";
74916 +
74917 + if (!virt_addr_valid(ptr))
74918 + return NULL;
74919 +
74920 + page = virt_to_head_page(ptr);
74921 + if (!PageSlab(page))
74922 + return NULL;
74923 +
74924 + if (page->private) {
74925 + base = page;
74926 + if (base <= ptr && n <= page->private - (ptr - base))
74927 + return NULL;
74928 + return "<slob>";
74929 + }
74930 +
74931 + /* some tricky double walking to find the chunk */
74932 + spin_lock_irqsave(&slob_lock, flags);
74933 + base = (void *)((unsigned long)ptr & PAGE_MASK);
74934 + free = page->freelist;
74935 +
74936 + while (!slob_last(free) && (void *)free <= ptr) {
74937 + base = free + slob_units(free);
74938 + free = slob_next(free);
74939 + }
74940 +
74941 + while (base < (void *)free) {
74942 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
74943 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
74944 + int offset;
74945 +
74946 + if (ptr < base + align)
74947 + break;
74948 +
74949 + offset = ptr - base - align;
74950 + if (offset >= m) {
74951 + base += size;
74952 + continue;
74953 + }
74954 +
74955 + if (n > m - offset)
74956 + break;
74957 +
74958 + spin_unlock_irqrestore(&slob_lock, flags);
74959 + return NULL;
74960 + }
74961 +
74962 + spin_unlock_irqrestore(&slob_lock, flags);
74963 + return "<slob>";
74964 +}
74965 +#endif
74966 +
74967 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
74968 size_t ksize(const void *block)
74969 {
74970 @@ -499,10 +588,11 @@ size_t ksize(const void *block)
74971 return 0;
74972
74973 sp = virt_to_page(block);
74974 - if (PageSlab(sp)) {
74975 + VM_BUG_ON(!PageSlab(sp));
74976 + if (!sp->private) {
74977 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74978 - unsigned int *m = (unsigned int *)(block - align);
74979 - return SLOB_UNITS(*m) * SLOB_UNIT;
74980 + slob_t *m = (slob_t *)(block - align);
74981 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
74982 } else
74983 return sp->private;
74984 }
74985 @@ -513,8 +603,13 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
74986 {
74987 struct kmem_cache *c;
74988
74989 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74990 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
74991 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
74992 +#else
74993 c = slob_alloc(sizeof(struct kmem_cache),
74994 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
74995 +#endif
74996
74997 if (c) {
74998 c->name = name;
74999 @@ -549,23 +644,33 @@ EXPORT_SYMBOL(kmem_cache_destroy);
75000
75001 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75002 {
75003 - void *b;
75004 + void *b = NULL;
75005
75006 flags &= gfp_allowed_mask;
75007
75008 lockdep_trace_alloc(flags);
75009
75010 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75011 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75012 +#else
75013 if (c->size < PAGE_SIZE) {
75014 b = slob_alloc(c->size, flags, c->align, node);
75015 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75016 SLOB_UNITS(c->size) * SLOB_UNIT,
75017 flags, node);
75018 } else {
75019 - b = slob_new_pages(flags, get_order(c->size), node);
75020 + struct page *sp;
75021 +
75022 + sp = slob_new_pages(flags, get_order(c->size), node);
75023 + if (sp) {
75024 + b = page_address(sp);
75025 + sp->private = c->size;
75026 + }
75027 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75028 PAGE_SIZE << get_order(c->size),
75029 flags, node);
75030 }
75031 +#endif
75032
75033 if (c->ctor)
75034 c->ctor(b);
75035 @@ -577,10 +682,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75036
75037 static void __kmem_cache_free(void *b, int size)
75038 {
75039 - if (size < PAGE_SIZE)
75040 + struct page *sp;
75041 +
75042 + sp = virt_to_page(b);
75043 + BUG_ON(!PageSlab(sp));
75044 + if (!sp->private)
75045 slob_free(b, size);
75046 else
75047 - slob_free_pages(b, get_order(size));
75048 + slob_free_pages(sp, get_order(size));
75049 }
75050
75051 static void kmem_rcu_free(struct rcu_head *head)
75052 @@ -593,17 +702,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75053
75054 void kmem_cache_free(struct kmem_cache *c, void *b)
75055 {
75056 + int size = c->size;
75057 +
75058 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75059 + if (size + c->align < PAGE_SIZE) {
75060 + size += c->align;
75061 + b -= c->align;
75062 + }
75063 +#endif
75064 +
75065 kmemleak_free_recursive(b, c->flags);
75066 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75067 struct slob_rcu *slob_rcu;
75068 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75069 - slob_rcu->size = c->size;
75070 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75071 + slob_rcu->size = size;
75072 call_rcu(&slob_rcu->head, kmem_rcu_free);
75073 } else {
75074 - __kmem_cache_free(b, c->size);
75075 + __kmem_cache_free(b, size);
75076 }
75077
75078 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75079 + trace_kfree(_RET_IP_, b);
75080 +#else
75081 trace_kmem_cache_free(_RET_IP_, b);
75082 +#endif
75083 +
75084 }
75085 EXPORT_SYMBOL(kmem_cache_free);
75086
75087 diff --git a/mm/slub.c b/mm/slub.c
75088 index 2fdd96f..1e2f893 100644
75089 --- a/mm/slub.c
75090 +++ b/mm/slub.c
75091 @@ -201,7 +201,7 @@ struct track {
75092
75093 enum track_item { TRACK_ALLOC, TRACK_FREE };
75094
75095 -#ifdef CONFIG_SYSFS
75096 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75097 static int sysfs_slab_add(struct kmem_cache *);
75098 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75099 static void sysfs_slab_remove(struct kmem_cache *);
75100 @@ -525,7 +525,7 @@ static void print_track(const char *s, struct track *t)
75101 if (!t->addr)
75102 return;
75103
75104 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75105 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75106 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75107 #ifdef CONFIG_STACKTRACE
75108 {
75109 @@ -2612,6 +2612,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75110
75111 page = virt_to_head_page(x);
75112
75113 + BUG_ON(!PageSlab(page));
75114 +
75115 slab_free(s, page, x, _RET_IP_);
75116
75117 trace_kmem_cache_free(_RET_IP_, x);
75118 @@ -2645,7 +2647,7 @@ static int slub_min_objects;
75119 * Merge control. If this is set then no merging of slab caches will occur.
75120 * (Could be removed. This was introduced to pacify the merge skeptics.)
75121 */
75122 -static int slub_nomerge;
75123 +static int slub_nomerge = 1;
75124
75125 /*
75126 * Calculate the order of allocation given an slab object size.
75127 @@ -3098,7 +3100,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75128 else
75129 s->cpu_partial = 30;
75130
75131 - s->refcount = 1;
75132 + atomic_set(&s->refcount, 1);
75133 #ifdef CONFIG_NUMA
75134 s->remote_node_defrag_ratio = 1000;
75135 #endif
75136 @@ -3202,8 +3204,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75137 void kmem_cache_destroy(struct kmem_cache *s)
75138 {
75139 mutex_lock(&slab_mutex);
75140 - s->refcount--;
75141 - if (!s->refcount) {
75142 + if (atomic_dec_and_test(&s->refcount)) {
75143 list_del(&s->list);
75144 mutex_unlock(&slab_mutex);
75145 if (kmem_cache_close(s)) {
75146 @@ -3232,6 +3233,10 @@ static struct kmem_cache *kmem_cache;
75147 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75148 #endif
75149
75150 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75151 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75152 +#endif
75153 +
75154 static int __init setup_slub_min_order(char *str)
75155 {
75156 get_option(&str, &slub_min_order);
75157 @@ -3346,6 +3351,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75158 return kmalloc_dma_caches[index];
75159
75160 #endif
75161 +
75162 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75163 + if (flags & SLAB_USERCOPY)
75164 + return kmalloc_usercopy_caches[index];
75165 +
75166 +#endif
75167 +
75168 return kmalloc_caches[index];
75169 }
75170
75171 @@ -3414,6 +3426,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75172 EXPORT_SYMBOL(__kmalloc_node);
75173 #endif
75174
75175 +bool is_usercopy_object(const void *ptr)
75176 +{
75177 + struct page *page;
75178 + struct kmem_cache *s;
75179 +
75180 + if (ZERO_OR_NULL_PTR(ptr))
75181 + return false;
75182 +
75183 + if (!slab_is_available())
75184 + return false;
75185 +
75186 + if (!virt_addr_valid(ptr))
75187 + return false;
75188 +
75189 + page = virt_to_head_page(ptr);
75190 +
75191 + if (!PageSlab(page))
75192 + return false;
75193 +
75194 + s = page->slab;
75195 + return s->flags & SLAB_USERCOPY;
75196 +}
75197 +
75198 +#ifdef CONFIG_PAX_USERCOPY
75199 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75200 +{
75201 + struct page *page;
75202 + struct kmem_cache *s;
75203 + unsigned long offset;
75204 +
75205 + if (ZERO_OR_NULL_PTR(ptr))
75206 + return "<null>";
75207 +
75208 + if (!virt_addr_valid(ptr))
75209 + return NULL;
75210 +
75211 + page = virt_to_head_page(ptr);
75212 +
75213 + if (!PageSlab(page))
75214 + return NULL;
75215 +
75216 + s = page->slab;
75217 + if (!(s->flags & SLAB_USERCOPY))
75218 + return s->name;
75219 +
75220 + offset = (ptr - page_address(page)) % s->size;
75221 + if (offset <= s->object_size && n <= s->object_size - offset)
75222 + return NULL;
75223 +
75224 + return s->name;
75225 +}
75226 +#endif
75227 +
75228 size_t ksize(const void *object)
75229 {
75230 struct page *page;
75231 @@ -3688,7 +3753,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75232 int node;
75233
75234 list_add(&s->list, &slab_caches);
75235 - s->refcount = -1;
75236 + atomic_set(&s->refcount, -1);
75237
75238 for_each_node_state(node, N_NORMAL_MEMORY) {
75239 struct kmem_cache_node *n = get_node(s, node);
75240 @@ -3808,17 +3873,17 @@ void __init kmem_cache_init(void)
75241
75242 /* Caches that are not of the two-to-the-power-of size */
75243 if (KMALLOC_MIN_SIZE <= 32) {
75244 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75245 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75246 caches++;
75247 }
75248
75249 if (KMALLOC_MIN_SIZE <= 64) {
75250 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75251 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75252 caches++;
75253 }
75254
75255 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75256 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75257 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75258 caches++;
75259 }
75260
75261 @@ -3860,6 +3925,22 @@ void __init kmem_cache_init(void)
75262 }
75263 }
75264 #endif
75265 +
75266 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75267 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75268 + struct kmem_cache *s = kmalloc_caches[i];
75269 +
75270 + if (s && s->size) {
75271 + char *name = kasprintf(GFP_NOWAIT,
75272 + "usercopy-kmalloc-%d", s->object_size);
75273 +
75274 + BUG_ON(!name);
75275 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75276 + s->object_size, SLAB_USERCOPY);
75277 + }
75278 + }
75279 +#endif
75280 +
75281 printk(KERN_INFO
75282 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75283 " CPUs=%d, Nodes=%d\n",
75284 @@ -3886,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75285 /*
75286 * We may have set a slab to be unmergeable during bootstrap.
75287 */
75288 - if (s->refcount < 0)
75289 + if (atomic_read(&s->refcount) < 0)
75290 return 1;
75291
75292 return 0;
75293 @@ -3941,7 +4022,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75294
75295 s = find_mergeable(size, align, flags, name, ctor);
75296 if (s) {
75297 - s->refcount++;
75298 + atomic_inc(&s->refcount);
75299 /*
75300 * Adjust the object sizes so that we clear
75301 * the complete object on kzalloc.
75302 @@ -3950,7 +4031,7 @@ struct kmem_cache *__kmem_cache_create(const char *name, size_t size,
75303 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75304
75305 if (sysfs_slab_alias(s, name)) {
75306 - s->refcount--;
75307 + atomic_dec(&s->refcount);
75308 return NULL;
75309 }
75310 return s;
75311 @@ -4072,7 +4153,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75312 }
75313 #endif
75314
75315 -#ifdef CONFIG_SYSFS
75316 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75317 static int count_inuse(struct page *page)
75318 {
75319 return page->inuse;
75320 @@ -4459,12 +4540,12 @@ static void resiliency_test(void)
75321 validate_slab_cache(kmalloc_caches[9]);
75322 }
75323 #else
75324 -#ifdef CONFIG_SYSFS
75325 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75326 static void resiliency_test(void) {};
75327 #endif
75328 #endif
75329
75330 -#ifdef CONFIG_SYSFS
75331 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75332 enum slab_stat_type {
75333 SL_ALL, /* All slabs */
75334 SL_PARTIAL, /* Only partially allocated slabs */
75335 @@ -4708,7 +4789,7 @@ SLAB_ATTR_RO(ctor);
75336
75337 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75338 {
75339 - return sprintf(buf, "%d\n", s->refcount - 1);
75340 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75341 }
75342 SLAB_ATTR_RO(aliases);
75343
75344 @@ -5279,6 +5360,7 @@ static char *create_unique_id(struct kmem_cache *s)
75345 return name;
75346 }
75347
75348 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75349 static int sysfs_slab_add(struct kmem_cache *s)
75350 {
75351 int err;
75352 @@ -5341,6 +5423,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75353 kobject_del(&s->kobj);
75354 kobject_put(&s->kobj);
75355 }
75356 +#endif
75357
75358 /*
75359 * Need to buffer aliases during bootup until sysfs becomes
75360 @@ -5354,6 +5437,7 @@ struct saved_alias {
75361
75362 static struct saved_alias *alias_list;
75363
75364 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75365 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75366 {
75367 struct saved_alias *al;
75368 @@ -5376,6 +5460,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75369 alias_list = al;
75370 return 0;
75371 }
75372 +#endif
75373
75374 static int __init slab_sysfs_init(void)
75375 {
75376 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75377 index 1b7e22a..3fcd4f3 100644
75378 --- a/mm/sparse-vmemmap.c
75379 +++ b/mm/sparse-vmemmap.c
75380 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75381 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75382 if (!p)
75383 return NULL;
75384 - pud_populate(&init_mm, pud, p);
75385 + pud_populate_kernel(&init_mm, pud, p);
75386 }
75387 return pud;
75388 }
75389 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75390 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75391 if (!p)
75392 return NULL;
75393 - pgd_populate(&init_mm, pgd, p);
75394 + pgd_populate_kernel(&init_mm, pgd, p);
75395 }
75396 return pgd;
75397 }
75398 diff --git a/mm/swap.c b/mm/swap.c
75399 index 7782588..228c784 100644
75400 --- a/mm/swap.c
75401 +++ b/mm/swap.c
75402 @@ -30,6 +30,7 @@
75403 #include <linux/backing-dev.h>
75404 #include <linux/memcontrol.h>
75405 #include <linux/gfp.h>
75406 +#include <linux/hugetlb.h>
75407
75408 #include "internal.h"
75409
75410 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75411
75412 __page_cache_release(page);
75413 dtor = get_compound_page_dtor(page);
75414 + if (!PageHuge(page))
75415 + BUG_ON(dtor != free_compound_page);
75416 (*dtor)(page);
75417 }
75418
75419 diff --git a/mm/swapfile.c b/mm/swapfile.c
75420 index 14e254c..a6af32c 100644
75421 --- a/mm/swapfile.c
75422 +++ b/mm/swapfile.c
75423 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
75424
75425 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75426 /* Activity counter to indicate that a swapon or swapoff has occurred */
75427 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75428 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75429
75430 static inline unsigned char swap_count(unsigned char ent)
75431 {
75432 @@ -1603,7 +1603,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75433 }
75434 filp_close(swap_file, NULL);
75435 err = 0;
75436 - atomic_inc(&proc_poll_event);
75437 + atomic_inc_unchecked(&proc_poll_event);
75438 wake_up_interruptible(&proc_poll_wait);
75439
75440 out_dput:
75441 @@ -1619,8 +1619,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75442
75443 poll_wait(file, &proc_poll_wait, wait);
75444
75445 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75446 - seq->poll_event = atomic_read(&proc_poll_event);
75447 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75448 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75449 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75450 }
75451
75452 @@ -1718,7 +1718,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75453 return ret;
75454
75455 seq = file->private_data;
75456 - seq->poll_event = atomic_read(&proc_poll_event);
75457 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75458 return 0;
75459 }
75460
75461 @@ -2060,7 +2060,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75462 (frontswap_map) ? "FS" : "");
75463
75464 mutex_unlock(&swapon_mutex);
75465 - atomic_inc(&proc_poll_event);
75466 + atomic_inc_unchecked(&proc_poll_event);
75467 wake_up_interruptible(&proc_poll_wait);
75468
75469 if (S_ISREG(inode->i_mode))
75470 diff --git a/mm/util.c b/mm/util.c
75471 index 8c7265a..c96d884 100644
75472 --- a/mm/util.c
75473 +++ b/mm/util.c
75474 @@ -285,6 +285,12 @@ done:
75475 void arch_pick_mmap_layout(struct mm_struct *mm)
75476 {
75477 mm->mmap_base = TASK_UNMAPPED_BASE;
75478 +
75479 +#ifdef CONFIG_PAX_RANDMMAP
75480 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75481 + mm->mmap_base += mm->delta_mmap;
75482 +#endif
75483 +
75484 mm->get_unmapped_area = arch_get_unmapped_area;
75485 mm->unmap_area = arch_unmap_area;
75486 }
75487 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75488 index 2bb90b1..ed47e53 100644
75489 --- a/mm/vmalloc.c
75490 +++ b/mm/vmalloc.c
75491 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75492
75493 pte = pte_offset_kernel(pmd, addr);
75494 do {
75495 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75496 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75497 +
75498 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75499 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75500 + BUG_ON(!pte_exec(*pte));
75501 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75502 + continue;
75503 + }
75504 +#endif
75505 +
75506 + {
75507 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75508 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75509 + }
75510 } while (pte++, addr += PAGE_SIZE, addr != end);
75511 }
75512
75513 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75514 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75515 {
75516 pte_t *pte;
75517 + int ret = -ENOMEM;
75518
75519 /*
75520 * nr is a running index into the array which helps higher level
75521 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75522 pte = pte_alloc_kernel(pmd, addr);
75523 if (!pte)
75524 return -ENOMEM;
75525 +
75526 + pax_open_kernel();
75527 do {
75528 struct page *page = pages[*nr];
75529
75530 - if (WARN_ON(!pte_none(*pte)))
75531 - return -EBUSY;
75532 - if (WARN_ON(!page))
75533 - return -ENOMEM;
75534 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75535 + if (pgprot_val(prot) & _PAGE_NX)
75536 +#endif
75537 +
75538 + if (WARN_ON(!pte_none(*pte))) {
75539 + ret = -EBUSY;
75540 + goto out;
75541 + }
75542 + if (WARN_ON(!page)) {
75543 + ret = -ENOMEM;
75544 + goto out;
75545 + }
75546 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75547 (*nr)++;
75548 } while (pte++, addr += PAGE_SIZE, addr != end);
75549 - return 0;
75550 + ret = 0;
75551 +out:
75552 + pax_close_kernel();
75553 + return ret;
75554 }
75555
75556 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75557 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75558 pmd_t *pmd;
75559 unsigned long next;
75560
75561 - pmd = pmd_alloc(&init_mm, pud, addr);
75562 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75563 if (!pmd)
75564 return -ENOMEM;
75565 do {
75566 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75567 pud_t *pud;
75568 unsigned long next;
75569
75570 - pud = pud_alloc(&init_mm, pgd, addr);
75571 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75572 if (!pud)
75573 return -ENOMEM;
75574 do {
75575 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75576 * and fall back on vmalloc() if that fails. Others
75577 * just put it in the vmalloc space.
75578 */
75579 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75580 +#ifdef CONFIG_MODULES
75581 +#ifdef MODULES_VADDR
75582 unsigned long addr = (unsigned long)x;
75583 if (addr >= MODULES_VADDR && addr < MODULES_END)
75584 return 1;
75585 #endif
75586 +
75587 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75588 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75589 + return 1;
75590 +#endif
75591 +
75592 +#endif
75593 +
75594 return is_vmalloc_addr(x);
75595 }
75596
75597 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75598
75599 if (!pgd_none(*pgd)) {
75600 pud_t *pud = pud_offset(pgd, addr);
75601 +#ifdef CONFIG_X86
75602 + if (!pud_large(*pud))
75603 +#endif
75604 if (!pud_none(*pud)) {
75605 pmd_t *pmd = pmd_offset(pud, addr);
75606 +#ifdef CONFIG_X86
75607 + if (!pmd_large(*pmd))
75608 +#endif
75609 if (!pmd_none(*pmd)) {
75610 pte_t *ptep, pte;
75611
75612 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75613 * Allocate a region of KVA of the specified size and alignment, within the
75614 * vstart and vend.
75615 */
75616 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75617 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75618 unsigned long align,
75619 unsigned long vstart, unsigned long vend,
75620 int node, gfp_t gfp_mask)
75621 @@ -1328,6 +1368,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75622 struct vm_struct *area;
75623
75624 BUG_ON(in_interrupt());
75625 +
75626 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75627 + if (flags & VM_KERNEXEC) {
75628 + if (start != VMALLOC_START || end != VMALLOC_END)
75629 + return NULL;
75630 + start = (unsigned long)MODULES_EXEC_VADDR;
75631 + end = (unsigned long)MODULES_EXEC_END;
75632 + }
75633 +#endif
75634 +
75635 if (flags & VM_IOREMAP) {
75636 int bit = fls(size);
75637
75638 @@ -1568,6 +1618,11 @@ void *vmap(struct page **pages, unsigned int count,
75639 if (count > totalram_pages)
75640 return NULL;
75641
75642 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75643 + if (!(pgprot_val(prot) & _PAGE_NX))
75644 + flags |= VM_KERNEXEC;
75645 +#endif
75646 +
75647 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75648 __builtin_return_address(0));
75649 if (!area)
75650 @@ -1669,6 +1724,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75651 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75652 goto fail;
75653
75654 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75655 + if (!(pgprot_val(prot) & _PAGE_NX))
75656 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75657 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75658 + else
75659 +#endif
75660 +
75661 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75662 start, end, node, gfp_mask, caller);
75663 if (!area)
75664 @@ -1842,10 +1904,9 @@ EXPORT_SYMBOL(vzalloc_node);
75665 * For tight control over page level allocator and protection flags
75666 * use __vmalloc() instead.
75667 */
75668 -
75669 void *vmalloc_exec(unsigned long size)
75670 {
75671 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75672 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75673 -1, __builtin_return_address(0));
75674 }
75675
75676 @@ -2136,6 +2197,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75677 unsigned long uaddr = vma->vm_start;
75678 unsigned long usize = vma->vm_end - vma->vm_start;
75679
75680 + BUG_ON(vma->vm_mirror);
75681 +
75682 if ((PAGE_SIZE-1) & (unsigned long)addr)
75683 return -EINVAL;
75684
75685 @@ -2572,7 +2635,7 @@ static int s_show(struct seq_file *m, void *p)
75686 {
75687 struct vm_struct *v = p;
75688
75689 - seq_printf(m, "0x%p-0x%p %7ld",
75690 + seq_printf(m, "0x%pK-0x%pK %7ld",
75691 v->addr, v->addr + v->size, v->size);
75692
75693 if (v->caller)
75694 diff --git a/mm/vmstat.c b/mm/vmstat.c
75695 index df7a674..8b4a4f3 100644
75696 --- a/mm/vmstat.c
75697 +++ b/mm/vmstat.c
75698 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75699 *
75700 * vm_stat contains the global counters
75701 */
75702 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75703 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75704 EXPORT_SYMBOL(vm_stat);
75705
75706 #ifdef CONFIG_SMP
75707 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75708 v = p->vm_stat_diff[i];
75709 p->vm_stat_diff[i] = 0;
75710 local_irq_restore(flags);
75711 - atomic_long_add(v, &zone->vm_stat[i]);
75712 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75713 global_diff[i] += v;
75714 #ifdef CONFIG_NUMA
75715 /* 3 seconds idle till flush */
75716 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75717
75718 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75719 if (global_diff[i])
75720 - atomic_long_add(global_diff[i], &vm_stat[i]);
75721 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75722 }
75723
75724 #endif
75725 @@ -1212,10 +1212,20 @@ static int __init setup_vmstat(void)
75726 start_cpu_timer(cpu);
75727 #endif
75728 #ifdef CONFIG_PROC_FS
75729 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75730 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75731 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75732 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75733 + {
75734 + mode_t gr_mode = S_IRUGO;
75735 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75736 + gr_mode = S_IRUSR;
75737 +#endif
75738 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75739 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75740 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75741 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75742 +#else
75743 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75744 +#endif
75745 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75746 + }
75747 #endif
75748 return 0;
75749 }
75750 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75751 index 9096bcb..43ed7bb 100644
75752 --- a/net/8021q/vlan.c
75753 +++ b/net/8021q/vlan.c
75754 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75755 err = -EPERM;
75756 if (!capable(CAP_NET_ADMIN))
75757 break;
75758 - if ((args.u.name_type >= 0) &&
75759 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75760 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75761 struct vlan_net *vn;
75762
75763 vn = net_generic(net, vlan_net_id);
75764 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75765 index 6449bae..8c1f454 100644
75766 --- a/net/9p/trans_fd.c
75767 +++ b/net/9p/trans_fd.c
75768 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75769 oldfs = get_fs();
75770 set_fs(get_ds());
75771 /* The cast to a user pointer is valid due to the set_fs() */
75772 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75773 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75774 set_fs(oldfs);
75775
75776 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75777 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75778 index 876fbe8..8bbea9f 100644
75779 --- a/net/atm/atm_misc.c
75780 +++ b/net/atm/atm_misc.c
75781 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75782 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75783 return 1;
75784 atm_return(vcc, truesize);
75785 - atomic_inc(&vcc->stats->rx_drop);
75786 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75787 return 0;
75788 }
75789 EXPORT_SYMBOL(atm_charge);
75790 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75791 }
75792 }
75793 atm_return(vcc, guess);
75794 - atomic_inc(&vcc->stats->rx_drop);
75795 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75796 return NULL;
75797 }
75798 EXPORT_SYMBOL(atm_alloc_charge);
75799 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75800
75801 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75802 {
75803 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75804 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75805 __SONET_ITEMS
75806 #undef __HANDLE_ITEM
75807 }
75808 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75809
75810 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75811 {
75812 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75813 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75814 __SONET_ITEMS
75815 #undef __HANDLE_ITEM
75816 }
75817 diff --git a/net/atm/lec.h b/net/atm/lec.h
75818 index a86aff9..3a0d6f6 100644
75819 --- a/net/atm/lec.h
75820 +++ b/net/atm/lec.h
75821 @@ -48,7 +48,7 @@ struct lane2_ops {
75822 const u8 *tlvs, u32 sizeoftlvs);
75823 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75824 const u8 *tlvs, u32 sizeoftlvs);
75825 -};
75826 +} __no_const;
75827
75828 /*
75829 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75830 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75831 index 0919a88..a23d54e 100644
75832 --- a/net/atm/mpc.h
75833 +++ b/net/atm/mpc.h
75834 @@ -33,7 +33,7 @@ struct mpoa_client {
75835 struct mpc_parameters parameters; /* parameters for this client */
75836
75837 const struct net_device_ops *old_ops;
75838 - struct net_device_ops new_ops;
75839 + net_device_ops_no_const new_ops;
75840 };
75841
75842
75843 diff --git a/net/atm/proc.c b/net/atm/proc.c
75844 index 0d020de..011c7bb 100644
75845 --- a/net/atm/proc.c
75846 +++ b/net/atm/proc.c
75847 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75848 const struct k_atm_aal_stats *stats)
75849 {
75850 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75851 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75852 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75853 - atomic_read(&stats->rx_drop));
75854 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75855 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75856 + atomic_read_unchecked(&stats->rx_drop));
75857 }
75858
75859 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75860 diff --git a/net/atm/resources.c b/net/atm/resources.c
75861 index 23f45ce..c748f1a 100644
75862 --- a/net/atm/resources.c
75863 +++ b/net/atm/resources.c
75864 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75865 static void copy_aal_stats(struct k_atm_aal_stats *from,
75866 struct atm_aal_stats *to)
75867 {
75868 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75869 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75870 __AAL_STAT_ITEMS
75871 #undef __HANDLE_ITEM
75872 }
75873 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75874 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75875 struct atm_aal_stats *to)
75876 {
75877 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75878 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75879 __AAL_STAT_ITEMS
75880 #undef __HANDLE_ITEM
75881 }
75882 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75883 index 469daab..9fc7f8d 100644
75884 --- a/net/batman-adv/bat_iv_ogm.c
75885 +++ b/net/batman-adv/bat_iv_ogm.c
75886 @@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
75887
75888 /* randomize initial seqno to avoid collision */
75889 get_random_bytes(&random_seqno, sizeof(random_seqno));
75890 - atomic_set(&hard_iface->seqno, random_seqno);
75891 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
75892
75893 hard_iface->packet_len = BATADV_OGM_HLEN;
75894 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
75895 @@ -191,7 +191,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
75896 "Sending own" :
75897 "Forwarding"));
75898 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
75899 - "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75900 + "%s %spacket (originator %pM, s_uncheckedeqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
75901 fwd_str, (packet_num > 0 ? "aggregated " : ""),
75902 batadv_ogm_packet->orig,
75903 ntohl(batadv_ogm_packet->seqno),
75904 @@ -600,8 +600,8 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
75905
75906 /* change sequence number to network order */
75907 batadv_ogm_packet->seqno =
75908 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
75909 - atomic_inc(&hard_iface->seqno);
75910 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
75911 + atomic_inc_unchecked(&hard_iface->seqno);
75912
75913 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
75914 batadv_ogm_packet->tt_crc = htons(bat_priv->tt_crc);
75915 @@ -1001,7 +1001,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
75916 return;
75917
75918 /* could be changed by schedule_own_packet() */
75919 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
75920 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
75921
75922 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
75923 has_directlink_flag = 1;
75924 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
75925 index 282bf6e..4b2603d 100644
75926 --- a/net/batman-adv/hard-interface.c
75927 +++ b/net/batman-adv/hard-interface.c
75928 @@ -320,7 +320,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
75929 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
75930 dev_add_pack(&hard_iface->batman_adv_ptype);
75931
75932 - atomic_set(&hard_iface->frag_seqno, 1);
75933 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
75934 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
75935 hard_iface->net_dev->name);
75936
75937 @@ -443,7 +443,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
75938 /* This can't be called via a bat_priv callback because
75939 * we have no bat_priv yet.
75940 */
75941 - atomic_set(&hard_iface->seqno, 1);
75942 + atomic_set_unchecked(&hard_iface->seqno, 1);
75943 hard_iface->packet_buff = NULL;
75944
75945 return hard_iface;
75946 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
75947 index 21c5357..768be1a 100644
75948 --- a/net/batman-adv/soft-interface.c
75949 +++ b/net/batman-adv/soft-interface.c
75950 @@ -227,7 +227,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
75951
75952 /* set broadcast sequence number */
75953 bcast_packet->seqno =
75954 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
75955 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
75956
75957 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
75958
75959 @@ -407,7 +407,7 @@ struct net_device *batadv_softif_create(const char *name)
75960 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
75961
75962 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
75963 - atomic_set(&bat_priv->bcast_seqno, 1);
75964 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
75965 atomic_set(&bat_priv->ttvn, 0);
75966 atomic_set(&bat_priv->tt_local_changes, 0);
75967 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
75968 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
75969 index 12635fd..d99d837 100644
75970 --- a/net/batman-adv/types.h
75971 +++ b/net/batman-adv/types.h
75972 @@ -33,8 +33,8 @@ struct batadv_hard_iface {
75973 int16_t if_num;
75974 char if_status;
75975 struct net_device *net_dev;
75976 - atomic_t seqno;
75977 - atomic_t frag_seqno;
75978 + atomic_unchecked_t seqno;
75979 + atomic_unchecked_t frag_seqno;
75980 unsigned char *packet_buff;
75981 int packet_len;
75982 struct kobject *hardif_obj;
75983 @@ -176,7 +176,7 @@ struct batadv_priv {
75984 atomic_t orig_interval; /* uint */
75985 atomic_t hop_penalty; /* uint */
75986 atomic_t log_level; /* uint */
75987 - atomic_t bcast_seqno;
75988 + atomic_unchecked_t bcast_seqno;
75989 atomic_t bcast_queue_left;
75990 atomic_t batman_queue_left;
75991 atomic_t ttvn; /* translation table version number */
75992 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
75993 index 0016464..0ef3e53 100644
75994 --- a/net/batman-adv/unicast.c
75995 +++ b/net/batman-adv/unicast.c
75996 @@ -269,7 +269,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
75997 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
75998 frag2->flags = large_tail;
75999
76000 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76001 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76002 frag1->seqno = htons(seqno - 1);
76003 frag2->seqno = htons(seqno);
76004
76005 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76006 index d5ace1e..231c4bf 100644
76007 --- a/net/bluetooth/hci_sock.c
76008 +++ b/net/bluetooth/hci_sock.c
76009 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
76010 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76011 }
76012
76013 - len = min_t(unsigned int, len, sizeof(uf));
76014 + len = min((size_t)len, sizeof(uf));
76015 if (copy_from_user(&uf, optval, len)) {
76016 err = -EFAULT;
76017 break;
76018 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76019 index 38c00f1..e9d566e 100644
76020 --- a/net/bluetooth/l2cap_core.c
76021 +++ b/net/bluetooth/l2cap_core.c
76022 @@ -3165,8 +3165,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76023 break;
76024
76025 case L2CAP_CONF_RFC:
76026 - if (olen == sizeof(rfc))
76027 - memcpy(&rfc, (void *)val, olen);
76028 + if (olen != sizeof(rfc))
76029 + break;
76030 +
76031 + memcpy(&rfc, (void *)val, olen);
76032
76033 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76034 rfc.mode != chan->mode)
76035 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76036 index 34bbe1c..451c19b 100644
76037 --- a/net/bluetooth/l2cap_sock.c
76038 +++ b/net/bluetooth/l2cap_sock.c
76039 @@ -467,7 +467,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76040 struct sock *sk = sock->sk;
76041 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76042 struct l2cap_options opts;
76043 - int len, err = 0;
76044 + int err = 0;
76045 + size_t len = optlen;
76046 u32 opt;
76047
76048 BT_DBG("sk %p", sk);
76049 @@ -489,7 +490,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76050 opts.max_tx = chan->max_tx;
76051 opts.txwin_size = chan->tx_win;
76052
76053 - len = min_t(unsigned int, sizeof(opts), optlen);
76054 + len = min(sizeof(opts), len);
76055 if (copy_from_user((char *) &opts, optval, len)) {
76056 err = -EFAULT;
76057 break;
76058 @@ -567,7 +568,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76059 struct bt_security sec;
76060 struct bt_power pwr;
76061 struct l2cap_conn *conn;
76062 - int len, err = 0;
76063 + int err = 0;
76064 + size_t len = optlen;
76065 u32 opt;
76066
76067 BT_DBG("sk %p", sk);
76068 @@ -590,7 +592,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76069
76070 sec.level = BT_SECURITY_LOW;
76071
76072 - len = min_t(unsigned int, sizeof(sec), optlen);
76073 + len = min(sizeof(sec), len);
76074 if (copy_from_user((char *) &sec, optval, len)) {
76075 err = -EFAULT;
76076 break;
76077 @@ -687,7 +689,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76078
76079 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76080
76081 - len = min_t(unsigned int, sizeof(pwr), optlen);
76082 + len = min(sizeof(pwr), len);
76083 if (copy_from_user((char *) &pwr, optval, len)) {
76084 err = -EFAULT;
76085 break;
76086 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76087 index 1a17850..65a3129 100644
76088 --- a/net/bluetooth/rfcomm/sock.c
76089 +++ b/net/bluetooth/rfcomm/sock.c
76090 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76091 struct sock *sk = sock->sk;
76092 struct bt_security sec;
76093 int err = 0;
76094 - size_t len;
76095 + size_t len = optlen;
76096 u32 opt;
76097
76098 BT_DBG("sk %p", sk);
76099 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76100
76101 sec.level = BT_SECURITY_LOW;
76102
76103 - len = min_t(unsigned int, sizeof(sec), optlen);
76104 + len = min(sizeof(sec), len);
76105 if (copy_from_user((char *) &sec, optval, len)) {
76106 err = -EFAULT;
76107 break;
76108 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76109 index 56f1823..da44330 100644
76110 --- a/net/bluetooth/rfcomm/tty.c
76111 +++ b/net/bluetooth/rfcomm/tty.c
76112 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76113 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76114
76115 spin_lock_irqsave(&dev->port.lock, flags);
76116 - if (dev->port.count > 0) {
76117 + if (atomic_read(&dev->port.count) > 0) {
76118 spin_unlock_irqrestore(&dev->port.lock, flags);
76119 return;
76120 }
76121 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76122 return -ENODEV;
76123
76124 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76125 - dev->channel, dev->port.count);
76126 + dev->channel, atomic_read(&dev->port.count));
76127
76128 spin_lock_irqsave(&dev->port.lock, flags);
76129 - if (++dev->port.count > 1) {
76130 + if (atomic_inc_return(&dev->port.count) > 1) {
76131 spin_unlock_irqrestore(&dev->port.lock, flags);
76132 return 0;
76133 }
76134 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76135 return;
76136
76137 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76138 - dev->port.count);
76139 + atomic_read(&dev->port.count));
76140
76141 spin_lock_irqsave(&dev->port.lock, flags);
76142 - if (!--dev->port.count) {
76143 + if (!atomic_dec_return(&dev->port.count)) {
76144 spin_unlock_irqrestore(&dev->port.lock, flags);
76145 if (dev->tty_dev->parent)
76146 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76147 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76148 index 5fe2ff3..121d696 100644
76149 --- a/net/bridge/netfilter/ebtables.c
76150 +++ b/net/bridge/netfilter/ebtables.c
76151 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76152 tmp.valid_hooks = t->table->valid_hooks;
76153 }
76154 mutex_unlock(&ebt_mutex);
76155 - if (copy_to_user(user, &tmp, *len) != 0){
76156 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76157 BUGPRINT("c2u Didn't work\n");
76158 ret = -EFAULT;
76159 break;
76160 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76161 goto out;
76162 tmp.valid_hooks = t->valid_hooks;
76163
76164 - if (copy_to_user(user, &tmp, *len) != 0) {
76165 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76166 ret = -EFAULT;
76167 break;
76168 }
76169 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76170 tmp.entries_size = t->table->entries_size;
76171 tmp.valid_hooks = t->table->valid_hooks;
76172
76173 - if (copy_to_user(user, &tmp, *len) != 0) {
76174 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76175 ret = -EFAULT;
76176 break;
76177 }
76178 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76179 index 44f270f..1f5602d 100644
76180 --- a/net/caif/cfctrl.c
76181 +++ b/net/caif/cfctrl.c
76182 @@ -10,6 +10,7 @@
76183 #include <linux/spinlock.h>
76184 #include <linux/slab.h>
76185 #include <linux/pkt_sched.h>
76186 +#include <linux/sched.h>
76187 #include <net/caif/caif_layer.h>
76188 #include <net/caif/cfpkt.h>
76189 #include <net/caif/cfctrl.h>
76190 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76191 memset(&dev_info, 0, sizeof(dev_info));
76192 dev_info.id = 0xff;
76193 cfsrvl_init(&this->serv, 0, &dev_info, false);
76194 - atomic_set(&this->req_seq_no, 1);
76195 - atomic_set(&this->rsp_seq_no, 1);
76196 + atomic_set_unchecked(&this->req_seq_no, 1);
76197 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76198 this->serv.layer.receive = cfctrl_recv;
76199 sprintf(this->serv.layer.name, "ctrl");
76200 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76201 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76202 struct cfctrl_request_info *req)
76203 {
76204 spin_lock_bh(&ctrl->info_list_lock);
76205 - atomic_inc(&ctrl->req_seq_no);
76206 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76207 + atomic_inc_unchecked(&ctrl->req_seq_no);
76208 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76209 list_add_tail(&req->list, &ctrl->list);
76210 spin_unlock_bh(&ctrl->info_list_lock);
76211 }
76212 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76213 if (p != first)
76214 pr_warn("Requests are not received in order\n");
76215
76216 - atomic_set(&ctrl->rsp_seq_no,
76217 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76218 p->sequence_no);
76219 list_del(&p->list);
76220 goto out;
76221 diff --git a/net/can/gw.c b/net/can/gw.c
76222 index b54d5e6..91c3b25 100644
76223 --- a/net/can/gw.c
76224 +++ b/net/can/gw.c
76225 @@ -96,7 +96,7 @@ struct cf_mod {
76226 struct {
76227 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76228 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76229 - } csumfunc;
76230 + } __no_const csumfunc;
76231 };
76232
76233
76234 diff --git a/net/compat.c b/net/compat.c
76235 index 74ed1d7..3695bd9 100644
76236 --- a/net/compat.c
76237 +++ b/net/compat.c
76238 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76239 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76240 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76241 return -EFAULT;
76242 - kmsg->msg_name = compat_ptr(tmp1);
76243 - kmsg->msg_iov = compat_ptr(tmp2);
76244 - kmsg->msg_control = compat_ptr(tmp3);
76245 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76246 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76247 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76248 return 0;
76249 }
76250
76251 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76252
76253 if (kern_msg->msg_namelen) {
76254 if (mode == VERIFY_READ) {
76255 - int err = move_addr_to_kernel(kern_msg->msg_name,
76256 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76257 kern_msg->msg_namelen,
76258 kern_address);
76259 if (err < 0)
76260 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76261 kern_msg->msg_name = NULL;
76262
76263 tot_len = iov_from_user_compat_to_kern(kern_iov,
76264 - (struct compat_iovec __user *)kern_msg->msg_iov,
76265 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76266 kern_msg->msg_iovlen);
76267 if (tot_len >= 0)
76268 kern_msg->msg_iov = kern_iov;
76269 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76270
76271 #define CMSG_COMPAT_FIRSTHDR(msg) \
76272 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76273 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76274 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76275 (struct compat_cmsghdr __user *)NULL)
76276
76277 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76278 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76279 (ucmlen) <= (unsigned long) \
76280 ((mhdr)->msg_controllen - \
76281 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76282 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76283
76284 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76285 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76286 {
76287 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76288 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76289 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76290 msg->msg_controllen)
76291 return NULL;
76292 return (struct compat_cmsghdr __user *)ptr;
76293 @@ -219,7 +219,7 @@ Efault:
76294
76295 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76296 {
76297 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76298 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76299 struct compat_cmsghdr cmhdr;
76300 struct compat_timeval ctv;
76301 struct compat_timespec cts[3];
76302 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76303
76304 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76305 {
76306 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76307 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76308 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76309 int fdnum = scm->fp->count;
76310 struct file **fp = scm->fp->fp;
76311 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76312 return -EFAULT;
76313 old_fs = get_fs();
76314 set_fs(KERNEL_DS);
76315 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76316 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76317 set_fs(old_fs);
76318
76319 return err;
76320 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76321 len = sizeof(ktime);
76322 old_fs = get_fs();
76323 set_fs(KERNEL_DS);
76324 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76325 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76326 set_fs(old_fs);
76327
76328 if (!err) {
76329 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76330 case MCAST_JOIN_GROUP:
76331 case MCAST_LEAVE_GROUP:
76332 {
76333 - struct compat_group_req __user *gr32 = (void *)optval;
76334 + struct compat_group_req __user *gr32 = (void __user *)optval;
76335 struct group_req __user *kgr =
76336 compat_alloc_user_space(sizeof(struct group_req));
76337 u32 interface;
76338 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76339 case MCAST_BLOCK_SOURCE:
76340 case MCAST_UNBLOCK_SOURCE:
76341 {
76342 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76343 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76344 struct group_source_req __user *kgsr = compat_alloc_user_space(
76345 sizeof(struct group_source_req));
76346 u32 interface;
76347 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76348 }
76349 case MCAST_MSFILTER:
76350 {
76351 - struct compat_group_filter __user *gf32 = (void *)optval;
76352 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76353 struct group_filter __user *kgf;
76354 u32 interface, fmode, numsrc;
76355
76356 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76357 char __user *optval, int __user *optlen,
76358 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76359 {
76360 - struct compat_group_filter __user *gf32 = (void *)optval;
76361 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76362 struct group_filter __user *kgf;
76363 int __user *koptlen;
76364 u32 interface, fmode, numsrc;
76365 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76366
76367 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76368 return -EINVAL;
76369 - if (copy_from_user(a, args, nas[call]))
76370 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76371 return -EFAULT;
76372 a0 = a[0];
76373 a1 = a[1];
76374 diff --git a/net/core/datagram.c b/net/core/datagram.c
76375 index 0337e2b..47914a0 100644
76376 --- a/net/core/datagram.c
76377 +++ b/net/core/datagram.c
76378 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76379 }
76380
76381 kfree_skb(skb);
76382 - atomic_inc(&sk->sk_drops);
76383 + atomic_inc_unchecked(&sk->sk_drops);
76384 sk_mem_reclaim_partial(sk);
76385
76386 return err;
76387 diff --git a/net/core/dev.c b/net/core/dev.c
76388 index 89e33a5..16d9d25 100644
76389 --- a/net/core/dev.c
76390 +++ b/net/core/dev.c
76391 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76392 if (no_module && capable(CAP_NET_ADMIN))
76393 no_module = request_module("netdev-%s", name);
76394 if (no_module && capable(CAP_SYS_MODULE)) {
76395 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76396 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76397 +#else
76398 if (!request_module("%s", name))
76399 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76400 name);
76401 +#endif
76402 }
76403 }
76404 EXPORT_SYMBOL(dev_load);
76405 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76406 {
76407 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76408 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76409 - atomic_long_inc(&dev->rx_dropped);
76410 + atomic_long_inc_unchecked(&dev->rx_dropped);
76411 kfree_skb(skb);
76412 return NET_RX_DROP;
76413 }
76414 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76415 nf_reset(skb);
76416
76417 if (unlikely(!is_skb_forwardable(dev, skb))) {
76418 - atomic_long_inc(&dev->rx_dropped);
76419 + atomic_long_inc_unchecked(&dev->rx_dropped);
76420 kfree_skb(skb);
76421 return NET_RX_DROP;
76422 }
76423 @@ -2071,7 +2075,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76424
76425 struct dev_gso_cb {
76426 void (*destructor)(struct sk_buff *skb);
76427 -};
76428 +} __no_const;
76429
76430 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76431
76432 @@ -2928,7 +2932,7 @@ enqueue:
76433
76434 local_irq_restore(flags);
76435
76436 - atomic_long_inc(&skb->dev->rx_dropped);
76437 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76438 kfree_skb(skb);
76439 return NET_RX_DROP;
76440 }
76441 @@ -3000,7 +3004,7 @@ int netif_rx_ni(struct sk_buff *skb)
76442 }
76443 EXPORT_SYMBOL(netif_rx_ni);
76444
76445 -static void net_tx_action(struct softirq_action *h)
76446 +static void net_tx_action(void)
76447 {
76448 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76449
76450 @@ -3328,7 +3332,7 @@ ncls:
76451 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76452 } else {
76453 drop:
76454 - atomic_long_inc(&skb->dev->rx_dropped);
76455 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76456 kfree_skb(skb);
76457 /* Jamal, now you will not able to escape explaining
76458 * me how you were going to use this. :-)
76459 @@ -3895,7 +3899,7 @@ void netif_napi_del(struct napi_struct *napi)
76460 }
76461 EXPORT_SYMBOL(netif_napi_del);
76462
76463 -static void net_rx_action(struct softirq_action *h)
76464 +static void net_rx_action(void)
76465 {
76466 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76467 unsigned long time_limit = jiffies + 2;
76468 @@ -4365,8 +4369,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76469 else
76470 seq_printf(seq, "%04x", ntohs(pt->type));
76471
76472 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76473 + seq_printf(seq, " %-8s %p\n",
76474 + pt->dev ? pt->dev->name : "", NULL);
76475 +#else
76476 seq_printf(seq, " %-8s %pF\n",
76477 pt->dev ? pt->dev->name : "", pt->func);
76478 +#endif
76479 }
76480
76481 return 0;
76482 @@ -5919,7 +5928,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76483 } else {
76484 netdev_stats_to_stats64(storage, &dev->stats);
76485 }
76486 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76487 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76488 return storage;
76489 }
76490 EXPORT_SYMBOL(dev_get_stats);
76491 diff --git a/net/core/flow.c b/net/core/flow.c
76492 index e318c7e..168b1d0 100644
76493 --- a/net/core/flow.c
76494 +++ b/net/core/flow.c
76495 @@ -61,7 +61,7 @@ struct flow_cache {
76496 struct timer_list rnd_timer;
76497 };
76498
76499 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76500 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76501 EXPORT_SYMBOL(flow_cache_genid);
76502 static struct flow_cache flow_cache_global;
76503 static struct kmem_cache *flow_cachep __read_mostly;
76504 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76505
76506 static int flow_entry_valid(struct flow_cache_entry *fle)
76507 {
76508 - if (atomic_read(&flow_cache_genid) != fle->genid)
76509 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76510 return 0;
76511 if (fle->object && !fle->object->ops->check(fle->object))
76512 return 0;
76513 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76514 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76515 fcp->hash_count++;
76516 }
76517 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76518 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76519 flo = fle->object;
76520 if (!flo)
76521 goto ret_object;
76522 @@ -280,7 +280,7 @@ nocache:
76523 }
76524 flo = resolver(net, key, family, dir, flo, ctx);
76525 if (fle) {
76526 - fle->genid = atomic_read(&flow_cache_genid);
76527 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76528 if (!IS_ERR(flo))
76529 fle->object = flo;
76530 else
76531 diff --git a/net/core/iovec.c b/net/core/iovec.c
76532 index 7e7aeb0..2a998cb 100644
76533 --- a/net/core/iovec.c
76534 +++ b/net/core/iovec.c
76535 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76536 if (m->msg_namelen) {
76537 if (mode == VERIFY_READ) {
76538 void __user *namep;
76539 - namep = (void __user __force *) m->msg_name;
76540 + namep = (void __force_user *) m->msg_name;
76541 err = move_addr_to_kernel(namep, m->msg_namelen,
76542 address);
76543 if (err < 0)
76544 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76545 }
76546
76547 size = m->msg_iovlen * sizeof(struct iovec);
76548 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76549 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76550 return -EFAULT;
76551
76552 m->msg_iov = iov;
76553 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76554 index 2c5a0a0..a45f90c 100644
76555 --- a/net/core/rtnetlink.c
76556 +++ b/net/core/rtnetlink.c
76557 @@ -58,7 +58,7 @@ struct rtnl_link {
76558 rtnl_doit_func doit;
76559 rtnl_dumpit_func dumpit;
76560 rtnl_calcit_func calcit;
76561 -};
76562 +} __no_const;
76563
76564 static DEFINE_MUTEX(rtnl_mutex);
76565
76566 diff --git a/net/core/scm.c b/net/core/scm.c
76567 index 040cebe..5b1e312 100644
76568 --- a/net/core/scm.c
76569 +++ b/net/core/scm.c
76570 @@ -203,7 +203,7 @@ EXPORT_SYMBOL(__scm_send);
76571 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76572 {
76573 struct cmsghdr __user *cm
76574 - = (__force struct cmsghdr __user *)msg->msg_control;
76575 + = (struct cmsghdr __force_user *)msg->msg_control;
76576 struct cmsghdr cmhdr;
76577 int cmlen = CMSG_LEN(len);
76578 int err;
76579 @@ -226,7 +226,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76580 err = -EFAULT;
76581 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76582 goto out;
76583 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76584 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76585 goto out;
76586 cmlen = CMSG_SPACE(len);
76587 if (msg->msg_controllen < cmlen)
76588 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(put_cmsg);
76589 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76590 {
76591 struct cmsghdr __user *cm
76592 - = (__force struct cmsghdr __user*)msg->msg_control;
76593 + = (struct cmsghdr __force_user *)msg->msg_control;
76594
76595 int fdmax = 0;
76596 int fdnum = scm->fp->count;
76597 @@ -262,7 +262,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76598 if (fdnum < fdmax)
76599 fdmax = fdnum;
76600
76601 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76602 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76603 i++, cmfptr++)
76604 {
76605 struct socket *sock;
76606 diff --git a/net/core/sock.c b/net/core/sock.c
76607 index a6000fb..d4aee72 100644
76608 --- a/net/core/sock.c
76609 +++ b/net/core/sock.c
76610 @@ -399,7 +399,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76611 struct sk_buff_head *list = &sk->sk_receive_queue;
76612
76613 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76614 - atomic_inc(&sk->sk_drops);
76615 + atomic_inc_unchecked(&sk->sk_drops);
76616 trace_sock_rcvqueue_full(sk, skb);
76617 return -ENOMEM;
76618 }
76619 @@ -409,7 +409,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76620 return err;
76621
76622 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
76623 - atomic_inc(&sk->sk_drops);
76624 + atomic_inc_unchecked(&sk->sk_drops);
76625 return -ENOBUFS;
76626 }
76627
76628 @@ -429,7 +429,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76629 skb_dst_force(skb);
76630
76631 spin_lock_irqsave(&list->lock, flags);
76632 - skb->dropcount = atomic_read(&sk->sk_drops);
76633 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76634 __skb_queue_tail(list, skb);
76635 spin_unlock_irqrestore(&list->lock, flags);
76636
76637 @@ -449,7 +449,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76638 skb->dev = NULL;
76639
76640 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76641 - atomic_inc(&sk->sk_drops);
76642 + atomic_inc_unchecked(&sk->sk_drops);
76643 goto discard_and_relse;
76644 }
76645 if (nested)
76646 @@ -467,7 +467,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76647 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76648 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76649 bh_unlock_sock(sk);
76650 - atomic_inc(&sk->sk_drops);
76651 + atomic_inc_unchecked(&sk->sk_drops);
76652 goto discard_and_relse;
76653 }
76654
76655 @@ -886,12 +886,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76656 struct timeval tm;
76657 } v;
76658
76659 - int lv = sizeof(int);
76660 - int len;
76661 + unsigned int lv = sizeof(int);
76662 + unsigned int len;
76663
76664 if (get_user(len, optlen))
76665 return -EFAULT;
76666 - if (len < 0)
76667 + if (len > INT_MAX)
76668 return -EINVAL;
76669
76670 memset(&v, 0, sizeof(v));
76671 @@ -1039,11 +1039,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76672
76673 case SO_PEERNAME:
76674 {
76675 - char address[128];
76676 + char address[_K_SS_MAXSIZE];
76677
76678 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76679 return -ENOTCONN;
76680 - if (lv < len)
76681 + if (lv < len || sizeof address < len)
76682 return -EINVAL;
76683 if (copy_to_user(optval, address, len))
76684 return -EFAULT;
76685 @@ -1091,7 +1091,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76686
76687 if (len > lv)
76688 len = lv;
76689 - if (copy_to_user(optval, &v, len))
76690 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76691 return -EFAULT;
76692 lenout:
76693 if (put_user(len, optlen))
76694 @@ -2193,7 +2193,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76695 */
76696 smp_wmb();
76697 atomic_set(&sk->sk_refcnt, 1);
76698 - atomic_set(&sk->sk_drops, 0);
76699 + atomic_set_unchecked(&sk->sk_drops, 0);
76700 }
76701 EXPORT_SYMBOL(sock_init_data);
76702
76703 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76704 index 9d8755e..26de8bc 100644
76705 --- a/net/core/sock_diag.c
76706 +++ b/net/core/sock_diag.c
76707 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76708
76709 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76710 {
76711 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76712 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76713 cookie[1] != INET_DIAG_NOCOOKIE) &&
76714 ((u32)(unsigned long)sk != cookie[0] ||
76715 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76716 return -ESTALE;
76717 else
76718 +#endif
76719 return 0;
76720 }
76721 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76722
76723 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76724 {
76725 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76726 + cookie[0] = 0;
76727 + cookie[1] = 0;
76728 +#else
76729 cookie[0] = (u32)(unsigned long)sk;
76730 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76731 +#endif
76732 }
76733 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76734
76735 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76736 index a55eecc..dd8428c 100644
76737 --- a/net/decnet/sysctl_net_decnet.c
76738 +++ b/net/decnet/sysctl_net_decnet.c
76739 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76740
76741 if (len > *lenp) len = *lenp;
76742
76743 - if (copy_to_user(buffer, addr, len))
76744 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76745 return -EFAULT;
76746
76747 *lenp = len;
76748 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76749
76750 if (len > *lenp) len = *lenp;
76751
76752 - if (copy_to_user(buffer, devname, len))
76753 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76754 return -EFAULT;
76755
76756 *lenp = len;
76757 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76758 index 8e2b475..7263d89 100644
76759 --- a/net/ipv4/fib_frontend.c
76760 +++ b/net/ipv4/fib_frontend.c
76761 @@ -1019,12 +1019,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76762 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76763 fib_sync_up(dev);
76764 #endif
76765 - atomic_inc(&net->ipv4.dev_addr_genid);
76766 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76767 rt_cache_flush(dev_net(dev));
76768 break;
76769 case NETDEV_DOWN:
76770 fib_del_ifaddr(ifa, NULL);
76771 - atomic_inc(&net->ipv4.dev_addr_genid);
76772 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76773 if (ifa->ifa_dev->ifa_list == NULL) {
76774 /* Last address was deleted from this interface.
76775 * Disable IP.
76776 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76777 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76778 fib_sync_up(dev);
76779 #endif
76780 - atomic_inc(&net->ipv4.dev_addr_genid);
76781 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76782 rt_cache_flush(dev_net(dev));
76783 break;
76784 case NETDEV_DOWN:
76785 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76786 index a747100..c5c8de1 100644
76787 --- a/net/ipv4/fib_semantics.c
76788 +++ b/net/ipv4/fib_semantics.c
76789 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76790 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76791 nh->nh_gw,
76792 nh->nh_parent->fib_scope);
76793 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76794 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76795
76796 return nh->nh_saddr;
76797 }
76798 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76799 index 7880af9..70f92a3 100644
76800 --- a/net/ipv4/inet_hashtables.c
76801 +++ b/net/ipv4/inet_hashtables.c
76802 @@ -18,12 +18,15 @@
76803 #include <linux/sched.h>
76804 #include <linux/slab.h>
76805 #include <linux/wait.h>
76806 +#include <linux/security.h>
76807
76808 #include <net/inet_connection_sock.h>
76809 #include <net/inet_hashtables.h>
76810 #include <net/secure_seq.h>
76811 #include <net/ip.h>
76812
76813 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76814 +
76815 /*
76816 * Allocate and initialize a new local port bind bucket.
76817 * The bindhash mutex for snum's hash chain must be held here.
76818 @@ -530,6 +533,8 @@ ok:
76819 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76820 spin_unlock(&head->lock);
76821
76822 + gr_update_task_in_ip_table(current, inet_sk(sk));
76823 +
76824 if (tw) {
76825 inet_twsk_deschedule(tw, death_row);
76826 while (twrefcnt) {
76827 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76828 index c7527f6..d8bba61 100644
76829 --- a/net/ipv4/inetpeer.c
76830 +++ b/net/ipv4/inetpeer.c
76831 @@ -503,8 +503,8 @@ relookup:
76832 if (p) {
76833 p->daddr = *daddr;
76834 atomic_set(&p->refcnt, 1);
76835 - atomic_set(&p->rid, 0);
76836 - atomic_set(&p->ip_id_count,
76837 + atomic_set_unchecked(&p->rid, 0);
76838 + atomic_set_unchecked(&p->ip_id_count,
76839 (daddr->family == AF_INET) ?
76840 secure_ip_id(daddr->addr.a4) :
76841 secure_ipv6_id(daddr->addr.a6));
76842 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76843 index 8d07c97..d0812ef 100644
76844 --- a/net/ipv4/ip_fragment.c
76845 +++ b/net/ipv4/ip_fragment.c
76846 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76847 return 0;
76848
76849 start = qp->rid;
76850 - end = atomic_inc_return(&peer->rid);
76851 + end = atomic_inc_return_unchecked(&peer->rid);
76852 qp->rid = end;
76853
76854 rc = qp->q.fragments && (end - start) > max;
76855 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76856 index 5eea4a8..49819c2 100644
76857 --- a/net/ipv4/ip_sockglue.c
76858 +++ b/net/ipv4/ip_sockglue.c
76859 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76860 len = min_t(unsigned int, len, opt->optlen);
76861 if (put_user(len, optlen))
76862 return -EFAULT;
76863 - if (copy_to_user(optval, opt->__data, len))
76864 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
76865 + copy_to_user(optval, opt->__data, len))
76866 return -EFAULT;
76867 return 0;
76868 }
76869 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
76870 if (sk->sk_type != SOCK_STREAM)
76871 return -ENOPROTOOPT;
76872
76873 - msg.msg_control = optval;
76874 + msg.msg_control = (void __force_kernel *)optval;
76875 msg.msg_controllen = len;
76876 msg.msg_flags = flags;
76877
76878 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
76879 index 67e8a6b..386764d 100644
76880 --- a/net/ipv4/ipconfig.c
76881 +++ b/net/ipv4/ipconfig.c
76882 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
76883
76884 mm_segment_t oldfs = get_fs();
76885 set_fs(get_ds());
76886 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76887 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76888 set_fs(oldfs);
76889 return res;
76890 }
76891 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
76892
76893 mm_segment_t oldfs = get_fs();
76894 set_fs(get_ds());
76895 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
76896 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
76897 set_fs(oldfs);
76898 return res;
76899 }
76900 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
76901
76902 mm_segment_t oldfs = get_fs();
76903 set_fs(get_ds());
76904 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
76905 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
76906 set_fs(oldfs);
76907 return res;
76908 }
76909 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
76910 index 97e61ea..cac1bbb 100644
76911 --- a/net/ipv4/netfilter/arp_tables.c
76912 +++ b/net/ipv4/netfilter/arp_tables.c
76913 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
76914 #endif
76915
76916 static int get_info(struct net *net, void __user *user,
76917 - const int *len, int compat)
76918 + int len, int compat)
76919 {
76920 char name[XT_TABLE_MAXNAMELEN];
76921 struct xt_table *t;
76922 int ret;
76923
76924 - if (*len != sizeof(struct arpt_getinfo)) {
76925 - duprintf("length %u != %Zu\n", *len,
76926 + if (len != sizeof(struct arpt_getinfo)) {
76927 + duprintf("length %u != %Zu\n", len,
76928 sizeof(struct arpt_getinfo));
76929 return -EINVAL;
76930 }
76931 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
76932 info.size = private->size;
76933 strcpy(info.name, name);
76934
76935 - if (copy_to_user(user, &info, *len) != 0)
76936 + if (copy_to_user(user, &info, len) != 0)
76937 ret = -EFAULT;
76938 else
76939 ret = 0;
76940 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
76941
76942 switch (cmd) {
76943 case ARPT_SO_GET_INFO:
76944 - ret = get_info(sock_net(sk), user, len, 1);
76945 + ret = get_info(sock_net(sk), user, *len, 1);
76946 break;
76947 case ARPT_SO_GET_ENTRIES:
76948 ret = compat_get_entries(sock_net(sk), user, len);
76949 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
76950
76951 switch (cmd) {
76952 case ARPT_SO_GET_INFO:
76953 - ret = get_info(sock_net(sk), user, len, 0);
76954 + ret = get_info(sock_net(sk), user, *len, 0);
76955 break;
76956
76957 case ARPT_SO_GET_ENTRIES:
76958 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
76959 index 170b1fd..6105b91 100644
76960 --- a/net/ipv4/netfilter/ip_tables.c
76961 +++ b/net/ipv4/netfilter/ip_tables.c
76962 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
76963 #endif
76964
76965 static int get_info(struct net *net, void __user *user,
76966 - const int *len, int compat)
76967 + int len, int compat)
76968 {
76969 char name[XT_TABLE_MAXNAMELEN];
76970 struct xt_table *t;
76971 int ret;
76972
76973 - if (*len != sizeof(struct ipt_getinfo)) {
76974 - duprintf("length %u != %zu\n", *len,
76975 + if (len != sizeof(struct ipt_getinfo)) {
76976 + duprintf("length %u != %zu\n", len,
76977 sizeof(struct ipt_getinfo));
76978 return -EINVAL;
76979 }
76980 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
76981 info.size = private->size;
76982 strcpy(info.name, name);
76983
76984 - if (copy_to_user(user, &info, *len) != 0)
76985 + if (copy_to_user(user, &info, len) != 0)
76986 ret = -EFAULT;
76987 else
76988 ret = 0;
76989 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76990
76991 switch (cmd) {
76992 case IPT_SO_GET_INFO:
76993 - ret = get_info(sock_net(sk), user, len, 1);
76994 + ret = get_info(sock_net(sk), user, *len, 1);
76995 break;
76996 case IPT_SO_GET_ENTRIES:
76997 ret = compat_get_entries(sock_net(sk), user, len);
76998 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76999
77000 switch (cmd) {
77001 case IPT_SO_GET_INFO:
77002 - ret = get_info(sock_net(sk), user, len, 0);
77003 + ret = get_info(sock_net(sk), user, *len, 0);
77004 break;
77005
77006 case IPT_SO_GET_ENTRIES:
77007 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77008 index 6232d47..6b88607 100644
77009 --- a/net/ipv4/ping.c
77010 +++ b/net/ipv4/ping.c
77011 @@ -847,7 +847,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77012 sk_rmem_alloc_get(sp),
77013 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77014 atomic_read(&sp->sk_refcnt), sp,
77015 - atomic_read(&sp->sk_drops), len);
77016 + atomic_read_unchecked(&sp->sk_drops), len);
77017 }
77018
77019 static int ping_seq_show(struct seq_file *seq, void *v)
77020 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77021 index d23c657..cb69cc2 100644
77022 --- a/net/ipv4/raw.c
77023 +++ b/net/ipv4/raw.c
77024 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77025 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77026 {
77027 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77028 - atomic_inc(&sk->sk_drops);
77029 + atomic_inc_unchecked(&sk->sk_drops);
77030 kfree_skb(skb);
77031 return NET_RX_DROP;
77032 }
77033 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
77034
77035 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77036 {
77037 + struct icmp_filter filter;
77038 +
77039 if (optlen > sizeof(struct icmp_filter))
77040 optlen = sizeof(struct icmp_filter);
77041 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77042 + if (copy_from_user(&filter, optval, optlen))
77043 return -EFAULT;
77044 + raw_sk(sk)->filter = filter;
77045 return 0;
77046 }
77047
77048 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77049 {
77050 int len, ret = -EFAULT;
77051 + struct icmp_filter filter;
77052
77053 if (get_user(len, optlen))
77054 goto out;
77055 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77056 if (len > sizeof(struct icmp_filter))
77057 len = sizeof(struct icmp_filter);
77058 ret = -EFAULT;
77059 - if (put_user(len, optlen) ||
77060 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77061 + filter = raw_sk(sk)->filter;
77062 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77063 goto out;
77064 ret = 0;
77065 out: return ret;
77066 @@ -995,7 +999,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77067 sk_wmem_alloc_get(sp),
77068 sk_rmem_alloc_get(sp),
77069 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77070 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77071 + atomic_read(&sp->sk_refcnt),
77072 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77073 + NULL,
77074 +#else
77075 + sp,
77076 +#endif
77077 + atomic_read_unchecked(&sp->sk_drops));
77078 }
77079
77080 static int raw_seq_show(struct seq_file *seq, void *v)
77081 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77082 index fd9af60..dca4e54 100644
77083 --- a/net/ipv4/route.c
77084 +++ b/net/ipv4/route.c
77085 @@ -2501,7 +2501,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
77086
77087 static __net_init int rt_genid_init(struct net *net)
77088 {
77089 - atomic_set(&net->rt_genid, 0);
77090 + atomic_set_unchecked(&net->rt_genid, 0);
77091 get_random_bytes(&net->ipv4.dev_addr_genid,
77092 sizeof(net->ipv4.dev_addr_genid));
77093 return 0;
77094 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77095 index d377f48..c2211ed 100644
77096 --- a/net/ipv4/tcp_input.c
77097 +++ b/net/ipv4/tcp_input.c
77098 @@ -4728,7 +4728,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77099 * simplifies code)
77100 */
77101 static void
77102 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77103 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77104 struct sk_buff *head, struct sk_buff *tail,
77105 u32 start, u32 end)
77106 {
77107 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77108 index 00a748d..e6d546b 100644
77109 --- a/net/ipv4/tcp_ipv4.c
77110 +++ b/net/ipv4/tcp_ipv4.c
77111 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77112 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77113
77114
77115 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77116 +extern int grsec_enable_blackhole;
77117 +#endif
77118 +
77119 #ifdef CONFIG_TCP_MD5SIG
77120 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77121 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77122 @@ -1663,6 +1667,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77123 return 0;
77124
77125 reset:
77126 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77127 + if (!grsec_enable_blackhole)
77128 +#endif
77129 tcp_v4_send_reset(rsk, skb);
77130 discard:
77131 kfree_skb(skb);
77132 @@ -1763,12 +1770,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77133 TCP_SKB_CB(skb)->sacked = 0;
77134
77135 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77136 - if (!sk)
77137 + if (!sk) {
77138 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77139 + ret = 1;
77140 +#endif
77141 goto no_tcp_socket;
77142 -
77143 + }
77144 process:
77145 - if (sk->sk_state == TCP_TIME_WAIT)
77146 + if (sk->sk_state == TCP_TIME_WAIT) {
77147 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77148 + ret = 2;
77149 +#endif
77150 goto do_time_wait;
77151 + }
77152
77153 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77154 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77155 @@ -1819,6 +1833,10 @@ no_tcp_socket:
77156 bad_packet:
77157 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77158 } else {
77159 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77160 + if (!grsec_enable_blackhole || (ret == 1 &&
77161 + (skb->dev->flags & IFF_LOOPBACK)))
77162 +#endif
77163 tcp_v4_send_reset(NULL, skb);
77164 }
77165
77166 @@ -2414,7 +2432,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77167 0, /* non standard timer */
77168 0, /* open_requests have no inode */
77169 atomic_read(&sk->sk_refcnt),
77170 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77171 + NULL,
77172 +#else
77173 req,
77174 +#endif
77175 len);
77176 }
77177
77178 @@ -2464,7 +2486,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77179 sock_i_uid(sk),
77180 icsk->icsk_probes_out,
77181 sock_i_ino(sk),
77182 - atomic_read(&sk->sk_refcnt), sk,
77183 + atomic_read(&sk->sk_refcnt),
77184 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77185 + NULL,
77186 +#else
77187 + sk,
77188 +#endif
77189 jiffies_to_clock_t(icsk->icsk_rto),
77190 jiffies_to_clock_t(icsk->icsk_ack.ato),
77191 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77192 @@ -2492,7 +2519,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77193 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77194 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77195 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77196 - atomic_read(&tw->tw_refcnt), tw, len);
77197 + atomic_read(&tw->tw_refcnt),
77198 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77199 + NULL,
77200 +#else
77201 + tw,
77202 +#endif
77203 + len);
77204 }
77205
77206 #define TMPSZ 150
77207 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77208 index 6ff7f10..38de56e 100644
77209 --- a/net/ipv4/tcp_minisocks.c
77210 +++ b/net/ipv4/tcp_minisocks.c
77211 @@ -27,6 +27,10 @@
77212 #include <net/inet_common.h>
77213 #include <net/xfrm.h>
77214
77215 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77216 +extern int grsec_enable_blackhole;
77217 +#endif
77218 +
77219 int sysctl_tcp_syncookies __read_mostly = 1;
77220 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77221
77222 @@ -707,6 +711,10 @@ listen_overflow:
77223
77224 embryonic_reset:
77225 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77226 +
77227 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77228 + if (!grsec_enable_blackhole)
77229 +#endif
77230 if (!(flg & TCP_FLAG_RST))
77231 req->rsk_ops->send_reset(sk, skb);
77232
77233 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77234 index 4526fe6..1a34e43 100644
77235 --- a/net/ipv4/tcp_probe.c
77236 +++ b/net/ipv4/tcp_probe.c
77237 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77238 if (cnt + width >= len)
77239 break;
77240
77241 - if (copy_to_user(buf + cnt, tbuf, width))
77242 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77243 return -EFAULT;
77244 cnt += width;
77245 }
77246 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77247 index b774a03..3873efe 100644
77248 --- a/net/ipv4/tcp_timer.c
77249 +++ b/net/ipv4/tcp_timer.c
77250 @@ -22,6 +22,10 @@
77251 #include <linux/gfp.h>
77252 #include <net/tcp.h>
77253
77254 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77255 +extern int grsec_lastack_retries;
77256 +#endif
77257 +
77258 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77259 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77260 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77261 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
77262 }
77263 }
77264
77265 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77266 + if ((sk->sk_state == TCP_LAST_ACK) &&
77267 + (grsec_lastack_retries > 0) &&
77268 + (grsec_lastack_retries < retry_until))
77269 + retry_until = grsec_lastack_retries;
77270 +#endif
77271 +
77272 if (retransmits_timed_out(sk, retry_until,
77273 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77274 /* Has it gone just too far? */
77275 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77276 index 2814f66..fa2b223 100644
77277 --- a/net/ipv4/udp.c
77278 +++ b/net/ipv4/udp.c
77279 @@ -87,6 +87,7 @@
77280 #include <linux/types.h>
77281 #include <linux/fcntl.h>
77282 #include <linux/module.h>
77283 +#include <linux/security.h>
77284 #include <linux/socket.h>
77285 #include <linux/sockios.h>
77286 #include <linux/igmp.h>
77287 @@ -111,6 +112,10 @@
77288 #include <trace/events/skb.h>
77289 #include "udp_impl.h"
77290
77291 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77292 +extern int grsec_enable_blackhole;
77293 +#endif
77294 +
77295 struct udp_table udp_table __read_mostly;
77296 EXPORT_SYMBOL(udp_table);
77297
77298 @@ -569,6 +574,9 @@ found:
77299 return s;
77300 }
77301
77302 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77303 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77304 +
77305 /*
77306 * This routine is called by the ICMP module when it gets some
77307 * sort of error condition. If err < 0 then the socket should
77308 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77309 dport = usin->sin_port;
77310 if (dport == 0)
77311 return -EINVAL;
77312 +
77313 + err = gr_search_udp_sendmsg(sk, usin);
77314 + if (err)
77315 + return err;
77316 } else {
77317 if (sk->sk_state != TCP_ESTABLISHED)
77318 return -EDESTADDRREQ;
77319 +
77320 + err = gr_search_udp_sendmsg(sk, NULL);
77321 + if (err)
77322 + return err;
77323 +
77324 daddr = inet->inet_daddr;
77325 dport = inet->inet_dport;
77326 /* Open fast path for connected socket.
77327 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
77328 udp_lib_checksum_complete(skb)) {
77329 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77330 IS_UDPLITE(sk));
77331 - atomic_inc(&sk->sk_drops);
77332 + atomic_inc_unchecked(&sk->sk_drops);
77333 __skb_unlink(skb, rcvq);
77334 __skb_queue_tail(&list_kill, skb);
77335 }
77336 @@ -1194,6 +1211,10 @@ try_again:
77337 if (!skb)
77338 goto out;
77339
77340 + err = gr_search_udp_recvmsg(sk, skb);
77341 + if (err)
77342 + goto out_free;
77343 +
77344 ulen = skb->len - sizeof(struct udphdr);
77345 copied = len;
77346 if (copied > ulen)
77347 @@ -1227,7 +1248,7 @@ try_again:
77348 if (unlikely(err)) {
77349 trace_kfree_skb(skb, udp_recvmsg);
77350 if (!peeked) {
77351 - atomic_inc(&sk->sk_drops);
77352 + atomic_inc_unchecked(&sk->sk_drops);
77353 UDP_INC_STATS_USER(sock_net(sk),
77354 UDP_MIB_INERRORS, is_udplite);
77355 }
77356 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77357
77358 drop:
77359 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77360 - atomic_inc(&sk->sk_drops);
77361 + atomic_inc_unchecked(&sk->sk_drops);
77362 kfree_skb(skb);
77363 return -1;
77364 }
77365 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77366 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77367
77368 if (!skb1) {
77369 - atomic_inc(&sk->sk_drops);
77370 + atomic_inc_unchecked(&sk->sk_drops);
77371 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77372 IS_UDPLITE(sk));
77373 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77374 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77375 goto csum_error;
77376
77377 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77378 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77379 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77380 +#endif
77381 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77382
77383 /*
77384 @@ -2116,8 +2140,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77385 sk_wmem_alloc_get(sp),
77386 sk_rmem_alloc_get(sp),
77387 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77388 - atomic_read(&sp->sk_refcnt), sp,
77389 - atomic_read(&sp->sk_drops), len);
77390 + atomic_read(&sp->sk_refcnt),
77391 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77392 + NULL,
77393 +#else
77394 + sp,
77395 +#endif
77396 + atomic_read_unchecked(&sp->sk_drops), len);
77397 }
77398
77399 int udp4_seq_show(struct seq_file *seq, void *v)
77400 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77401 index ea3e9af..b60262e 100644
77402 --- a/net/ipv6/addrconf.c
77403 +++ b/net/ipv6/addrconf.c
77404 @@ -2144,7 +2144,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77405 p.iph.ihl = 5;
77406 p.iph.protocol = IPPROTO_IPV6;
77407 p.iph.ttl = 64;
77408 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77409 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77410
77411 if (ops->ndo_do_ioctl) {
77412 mm_segment_t oldfs = get_fs();
77413 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77414 index ba6d13d..6899122 100644
77415 --- a/net/ipv6/ipv6_sockglue.c
77416 +++ b/net/ipv6/ipv6_sockglue.c
77417 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77418 if (sk->sk_type != SOCK_STREAM)
77419 return -ENOPROTOOPT;
77420
77421 - msg.msg_control = optval;
77422 + msg.msg_control = (void __force_kernel *)optval;
77423 msg.msg_controllen = len;
77424 msg.msg_flags = flags;
77425
77426 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77427 index d7cb045..8c0ded6 100644
77428 --- a/net/ipv6/netfilter/ip6_tables.c
77429 +++ b/net/ipv6/netfilter/ip6_tables.c
77430 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77431 #endif
77432
77433 static int get_info(struct net *net, void __user *user,
77434 - const int *len, int compat)
77435 + int len, int compat)
77436 {
77437 char name[XT_TABLE_MAXNAMELEN];
77438 struct xt_table *t;
77439 int ret;
77440
77441 - if (*len != sizeof(struct ip6t_getinfo)) {
77442 - duprintf("length %u != %zu\n", *len,
77443 + if (len != sizeof(struct ip6t_getinfo)) {
77444 + duprintf("length %u != %zu\n", len,
77445 sizeof(struct ip6t_getinfo));
77446 return -EINVAL;
77447 }
77448 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77449 info.size = private->size;
77450 strcpy(info.name, name);
77451
77452 - if (copy_to_user(user, &info, *len) != 0)
77453 + if (copy_to_user(user, &info, len) != 0)
77454 ret = -EFAULT;
77455 else
77456 ret = 0;
77457 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77458
77459 switch (cmd) {
77460 case IP6T_SO_GET_INFO:
77461 - ret = get_info(sock_net(sk), user, len, 1);
77462 + ret = get_info(sock_net(sk), user, *len, 1);
77463 break;
77464 case IP6T_SO_GET_ENTRIES:
77465 ret = compat_get_entries(sock_net(sk), user, len);
77466 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77467
77468 switch (cmd) {
77469 case IP6T_SO_GET_INFO:
77470 - ret = get_info(sock_net(sk), user, len, 0);
77471 + ret = get_info(sock_net(sk), user, *len, 0);
77472 break;
77473
77474 case IP6T_SO_GET_ENTRIES:
77475 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77476 index 4a5f78b..3f22ebe 100644
77477 --- a/net/ipv6/raw.c
77478 +++ b/net/ipv6/raw.c
77479 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77480 {
77481 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77482 skb_checksum_complete(skb)) {
77483 - atomic_inc(&sk->sk_drops);
77484 + atomic_inc_unchecked(&sk->sk_drops);
77485 kfree_skb(skb);
77486 return NET_RX_DROP;
77487 }
77488 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77489 struct raw6_sock *rp = raw6_sk(sk);
77490
77491 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77492 - atomic_inc(&sk->sk_drops);
77493 + atomic_inc_unchecked(&sk->sk_drops);
77494 kfree_skb(skb);
77495 return NET_RX_DROP;
77496 }
77497 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77498
77499 if (inet->hdrincl) {
77500 if (skb_checksum_complete(skb)) {
77501 - atomic_inc(&sk->sk_drops);
77502 + atomic_inc_unchecked(&sk->sk_drops);
77503 kfree_skb(skb);
77504 return NET_RX_DROP;
77505 }
77506 @@ -604,7 +604,7 @@ out:
77507 return err;
77508 }
77509
77510 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77511 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77512 struct flowi6 *fl6, struct dst_entry **dstp,
77513 unsigned int flags)
77514 {
77515 @@ -916,12 +916,15 @@ do_confirm:
77516 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77517 char __user *optval, int optlen)
77518 {
77519 + struct icmp6_filter filter;
77520 +
77521 switch (optname) {
77522 case ICMPV6_FILTER:
77523 if (optlen > sizeof(struct icmp6_filter))
77524 optlen = sizeof(struct icmp6_filter);
77525 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77526 + if (copy_from_user(&filter, optval, optlen))
77527 return -EFAULT;
77528 + raw6_sk(sk)->filter = filter;
77529 return 0;
77530 default:
77531 return -ENOPROTOOPT;
77532 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77533 char __user *optval, int __user *optlen)
77534 {
77535 int len;
77536 + struct icmp6_filter filter;
77537
77538 switch (optname) {
77539 case ICMPV6_FILTER:
77540 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77541 len = sizeof(struct icmp6_filter);
77542 if (put_user(len, optlen))
77543 return -EFAULT;
77544 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77545 + filter = raw6_sk(sk)->filter;
77546 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77547 return -EFAULT;
77548 return 0;
77549 default:
77550 @@ -1252,7 +1257,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77551 0, 0L, 0,
77552 sock_i_uid(sp), 0,
77553 sock_i_ino(sp),
77554 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77555 + atomic_read(&sp->sk_refcnt),
77556 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77557 + NULL,
77558 +#else
77559 + sp,
77560 +#endif
77561 + atomic_read_unchecked(&sp->sk_drops));
77562 }
77563
77564 static int raw6_seq_show(struct seq_file *seq, void *v)
77565 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77566 index acd32e3..f73f8f7 100644
77567 --- a/net/ipv6/tcp_ipv6.c
77568 +++ b/net/ipv6/tcp_ipv6.c
77569 @@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
77570 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
77571 }
77572
77573 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77574 +extern int grsec_enable_blackhole;
77575 +#endif
77576 +
77577 static void tcp_v6_hash(struct sock *sk)
77578 {
77579 if (sk->sk_state != TCP_CLOSE) {
77580 @@ -1510,6 +1514,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77581 return 0;
77582
77583 reset:
77584 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77585 + if (!grsec_enable_blackhole)
77586 +#endif
77587 tcp_v6_send_reset(sk, skb);
77588 discard:
77589 if (opt_skb)
77590 @@ -1591,12 +1598,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77591 TCP_SKB_CB(skb)->sacked = 0;
77592
77593 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77594 - if (!sk)
77595 + if (!sk) {
77596 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77597 + ret = 1;
77598 +#endif
77599 goto no_tcp_socket;
77600 + }
77601
77602 process:
77603 - if (sk->sk_state == TCP_TIME_WAIT)
77604 + if (sk->sk_state == TCP_TIME_WAIT) {
77605 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77606 + ret = 2;
77607 +#endif
77608 goto do_time_wait;
77609 + }
77610
77611 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77612 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77613 @@ -1645,6 +1660,10 @@ no_tcp_socket:
77614 bad_packet:
77615 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77616 } else {
77617 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77618 + if (!grsec_enable_blackhole || (ret == 1 &&
77619 + (skb->dev->flags & IFF_LOOPBACK)))
77620 +#endif
77621 tcp_v6_send_reset(NULL, skb);
77622 }
77623
77624 @@ -1856,7 +1875,13 @@ static void get_openreq6(struct seq_file *seq,
77625 uid,
77626 0, /* non standard timer */
77627 0, /* open_requests have no inode */
77628 - 0, req);
77629 + 0,
77630 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77631 + NULL
77632 +#else
77633 + req
77634 +#endif
77635 + );
77636 }
77637
77638 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77639 @@ -1906,7 +1931,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77640 sock_i_uid(sp),
77641 icsk->icsk_probes_out,
77642 sock_i_ino(sp),
77643 - atomic_read(&sp->sk_refcnt), sp,
77644 + atomic_read(&sp->sk_refcnt),
77645 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77646 + NULL,
77647 +#else
77648 + sp,
77649 +#endif
77650 jiffies_to_clock_t(icsk->icsk_rto),
77651 jiffies_to_clock_t(icsk->icsk_ack.ato),
77652 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77653 @@ -1941,7 +1971,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77654 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77655 tw->tw_substate, 0, 0,
77656 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77657 - atomic_read(&tw->tw_refcnt), tw);
77658 + atomic_read(&tw->tw_refcnt),
77659 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77660 + NULL
77661 +#else
77662 + tw
77663 +#endif
77664 + );
77665 }
77666
77667 static int tcp6_seq_show(struct seq_file *seq, void *v)
77668 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77669 index 07e2bfe..328dae8 100644
77670 --- a/net/ipv6/udp.c
77671 +++ b/net/ipv6/udp.c
77672 @@ -51,6 +51,10 @@
77673 #include <trace/events/skb.h>
77674 #include "udp_impl.h"
77675
77676 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77677 +extern int grsec_enable_blackhole;
77678 +#endif
77679 +
77680 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77681 {
77682 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77683 @@ -395,7 +399,7 @@ try_again:
77684 if (unlikely(err)) {
77685 trace_kfree_skb(skb, udpv6_recvmsg);
77686 if (!peeked) {
77687 - atomic_inc(&sk->sk_drops);
77688 + atomic_inc_unchecked(&sk->sk_drops);
77689 if (is_udp4)
77690 UDP_INC_STATS_USER(sock_net(sk),
77691 UDP_MIB_INERRORS,
77692 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77693 return rc;
77694 drop:
77695 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77696 - atomic_inc(&sk->sk_drops);
77697 + atomic_inc_unchecked(&sk->sk_drops);
77698 kfree_skb(skb);
77699 return -1;
77700 }
77701 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77702 if (likely(skb1 == NULL))
77703 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77704 if (!skb1) {
77705 - atomic_inc(&sk->sk_drops);
77706 + atomic_inc_unchecked(&sk->sk_drops);
77707 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77708 IS_UDPLITE(sk));
77709 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77710 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77711 goto discard;
77712
77713 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77714 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77715 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77716 +#endif
77717 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77718
77719 kfree_skb(skb);
77720 @@ -1471,8 +1478,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77721 0, 0L, 0,
77722 sock_i_uid(sp), 0,
77723 sock_i_ino(sp),
77724 - atomic_read(&sp->sk_refcnt), sp,
77725 - atomic_read(&sp->sk_drops));
77726 + atomic_read(&sp->sk_refcnt),
77727 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77728 + NULL,
77729 +#else
77730 + sp,
77731 +#endif
77732 + atomic_read_unchecked(&sp->sk_drops));
77733 }
77734
77735 int udp6_seq_show(struct seq_file *seq, void *v)
77736 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77737 index 6b9d5a0..4dffaf1 100644
77738 --- a/net/irda/ircomm/ircomm_tty.c
77739 +++ b/net/irda/ircomm/ircomm_tty.c
77740 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77741 add_wait_queue(&self->open_wait, &wait);
77742
77743 IRDA_DEBUG(2, "%s(%d):block_til_ready before block 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 /* As far as I can see, we protect open_count - Jean II */
77748 spin_lock_irqsave(&self->spinlock, flags);
77749 if (!tty_hung_up_p(filp)) {
77750 extra_count = 1;
77751 - self->open_count--;
77752 + local_dec(&self->open_count);
77753 }
77754 spin_unlock_irqrestore(&self->spinlock, flags);
77755 - self->blocked_open++;
77756 + local_inc(&self->blocked_open);
77757
77758 while (1) {
77759 if (tty->termios->c_cflag & CBAUD) {
77760 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77761 }
77762
77763 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77764 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77765 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77766
77767 schedule();
77768 }
77769 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77770 if (extra_count) {
77771 /* ++ is not atomic, so this should be protected - Jean II */
77772 spin_lock_irqsave(&self->spinlock, flags);
77773 - self->open_count++;
77774 + local_inc(&self->open_count);
77775 spin_unlock_irqrestore(&self->spinlock, flags);
77776 }
77777 - self->blocked_open--;
77778 + local_dec(&self->blocked_open);
77779
77780 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77781 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77782 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77783
77784 if (!retval)
77785 self->flags |= ASYNC_NORMAL_ACTIVE;
77786 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77787 }
77788 /* ++ is not atomic, so this should be protected - Jean II */
77789 spin_lock_irqsave(&self->spinlock, flags);
77790 - self->open_count++;
77791 + local_inc(&self->open_count);
77792
77793 tty->driver_data = self;
77794 self->tty = tty;
77795 spin_unlock_irqrestore(&self->spinlock, flags);
77796
77797 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77798 - self->line, self->open_count);
77799 + self->line, local_read(&self->open_count));
77800
77801 /* Not really used by us, but lets do it anyway */
77802 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77803 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77804 return;
77805 }
77806
77807 - if ((tty->count == 1) && (self->open_count != 1)) {
77808 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77809 /*
77810 * Uh, oh. tty->count is 1, which means that the tty
77811 * structure will be freed. state->count should always
77812 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77813 */
77814 IRDA_DEBUG(0, "%s(), bad serial port count; "
77815 "tty->count is 1, state->count is %d\n", __func__ ,
77816 - self->open_count);
77817 - self->open_count = 1;
77818 + local_read(&self->open_count));
77819 + local_set(&self->open_count, 1);
77820 }
77821
77822 - if (--self->open_count < 0) {
77823 + if (local_dec_return(&self->open_count) < 0) {
77824 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
77825 - __func__, self->line, self->open_count);
77826 - self->open_count = 0;
77827 + __func__, self->line, local_read(&self->open_count));
77828 + local_set(&self->open_count, 0);
77829 }
77830 - if (self->open_count) {
77831 + if (local_read(&self->open_count)) {
77832 spin_unlock_irqrestore(&self->spinlock, flags);
77833
77834 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
77835 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77836 tty->closing = 0;
77837 self->tty = NULL;
77838
77839 - if (self->blocked_open) {
77840 + if (local_read(&self->blocked_open)) {
77841 if (self->close_delay)
77842 schedule_timeout_interruptible(self->close_delay);
77843 wake_up_interruptible(&self->open_wait);
77844 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
77845 spin_lock_irqsave(&self->spinlock, flags);
77846 self->flags &= ~ASYNC_NORMAL_ACTIVE;
77847 self->tty = NULL;
77848 - self->open_count = 0;
77849 + local_set(&self->open_count, 0);
77850 spin_unlock_irqrestore(&self->spinlock, flags);
77851
77852 wake_up_interruptible(&self->open_wait);
77853 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
77854 seq_putc(m, '\n');
77855
77856 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
77857 - seq_printf(m, "Open count: %d\n", self->open_count);
77858 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
77859 seq_printf(m, "Max data size: %d\n", self->max_data_size);
77860 seq_printf(m, "Max header size: %d\n", self->max_header_size);
77861
77862 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
77863 index cd6f7a9..e63fe89 100644
77864 --- a/net/iucv/af_iucv.c
77865 +++ b/net/iucv/af_iucv.c
77866 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
77867
77868 write_lock_bh(&iucv_sk_list.lock);
77869
77870 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
77871 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77872 while (__iucv_get_sock_by_name(name)) {
77873 sprintf(name, "%08x",
77874 - atomic_inc_return(&iucv_sk_list.autobind_name));
77875 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
77876 }
77877
77878 write_unlock_bh(&iucv_sk_list.lock);
77879 diff --git a/net/key/af_key.c b/net/key/af_key.c
77880 index 34e4185..8823368 100644
77881 --- a/net/key/af_key.c
77882 +++ b/net/key/af_key.c
77883 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
77884 static u32 get_acqseq(void)
77885 {
77886 u32 res;
77887 - static atomic_t acqseq;
77888 + static atomic_unchecked_t acqseq;
77889
77890 do {
77891 - res = atomic_inc_return(&acqseq);
77892 + res = atomic_inc_return_unchecked(&acqseq);
77893 } while (!res);
77894 return res;
77895 }
77896 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
77897 index bb61f77..3788d63 100644
77898 --- a/net/mac80211/ieee80211_i.h
77899 +++ b/net/mac80211/ieee80211_i.h
77900 @@ -28,6 +28,7 @@
77901 #include <net/ieee80211_radiotap.h>
77902 #include <net/cfg80211.h>
77903 #include <net/mac80211.h>
77904 +#include <asm/local.h>
77905 #include "key.h"
77906 #include "sta_info.h"
77907 #include "debug.h"
77908 @@ -840,7 +841,7 @@ struct ieee80211_local {
77909 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
77910 spinlock_t queue_stop_reason_lock;
77911
77912 - int open_count;
77913 + local_t open_count;
77914 int monitors, cooked_mntrs;
77915 /* number of interfaces with corresponding FIF_ flags */
77916 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
77917 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
77918 index bfb57dc..77c4b81 100644
77919 --- a/net/mac80211/iface.c
77920 +++ b/net/mac80211/iface.c
77921 @@ -454,7 +454,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77922 break;
77923 }
77924
77925 - if (local->open_count == 0) {
77926 + if (local_read(&local->open_count) == 0) {
77927 res = drv_start(local);
77928 if (res)
77929 goto err_del_bss;
77930 @@ -497,7 +497,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77931 break;
77932 }
77933
77934 - if (local->monitors == 0 && local->open_count == 0) {
77935 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
77936 res = ieee80211_add_virtual_monitor(local);
77937 if (res)
77938 goto err_stop;
77939 @@ -594,7 +594,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77940 mutex_unlock(&local->mtx);
77941
77942 if (coming_up)
77943 - local->open_count++;
77944 + local_inc(&local->open_count);
77945
77946 if (hw_reconf_flags)
77947 ieee80211_hw_config(local, hw_reconf_flags);
77948 @@ -607,7 +607,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
77949 err_del_interface:
77950 drv_remove_interface(local, sdata);
77951 err_stop:
77952 - if (!local->open_count)
77953 + if (!local_read(&local->open_count))
77954 drv_stop(local);
77955 err_del_bss:
77956 sdata->bss = NULL;
77957 @@ -736,7 +736,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77958 }
77959
77960 if (going_down)
77961 - local->open_count--;
77962 + local_dec(&local->open_count);
77963
77964 switch (sdata->vif.type) {
77965 case NL80211_IFTYPE_AP_VLAN:
77966 @@ -796,7 +796,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77967
77968 ieee80211_recalc_ps(local, -1);
77969
77970 - if (local->open_count == 0) {
77971 + if (local_read(&local->open_count) == 0) {
77972 if (local->ops->napi_poll)
77973 napi_disable(&local->napi);
77974 ieee80211_clear_tx_pending(local);
77975 @@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
77976 }
77977 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
77978
77979 - if (local->monitors == local->open_count && local->monitors > 0)
77980 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
77981 ieee80211_add_virtual_monitor(local);
77982 }
77983
77984 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
77985 index c26e231..8916637 100644
77986 --- a/net/mac80211/main.c
77987 +++ b/net/mac80211/main.c
77988 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
77989 local->hw.conf.power_level = power;
77990 }
77991
77992 - if (changed && local->open_count) {
77993 + if (changed && local_read(&local->open_count)) {
77994 ret = drv_config(local, changed);
77995 /*
77996 * Goal:
77997 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
77998 index 5c572e7..ecf75ce 100644
77999 --- a/net/mac80211/pm.c
78000 +++ b/net/mac80211/pm.c
78001 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78002 struct ieee80211_sub_if_data *sdata;
78003 struct sta_info *sta;
78004
78005 - if (!local->open_count)
78006 + if (!local_read(&local->open_count))
78007 goto suspend;
78008
78009 ieee80211_scan_cancel(local);
78010 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78011 cancel_work_sync(&local->dynamic_ps_enable_work);
78012 del_timer_sync(&local->dynamic_ps_timer);
78013
78014 - local->wowlan = wowlan && local->open_count;
78015 + local->wowlan = wowlan && local_read(&local->open_count);
78016 if (local->wowlan) {
78017 int err = drv_suspend(local, wowlan);
78018 if (err < 0) {
78019 @@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78020 drv_remove_interface(local, sdata);
78021
78022 /* stop hardware - this must stop RX */
78023 - if (local->open_count)
78024 + if (local_read(&local->open_count))
78025 ieee80211_stop_device(local);
78026
78027 suspend:
78028 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78029 index 3313c11..bec9f17 100644
78030 --- a/net/mac80211/rate.c
78031 +++ b/net/mac80211/rate.c
78032 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78033
78034 ASSERT_RTNL();
78035
78036 - if (local->open_count)
78037 + if (local_read(&local->open_count))
78038 return -EBUSY;
78039
78040 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78041 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78042 index c97a065..ff61928 100644
78043 --- a/net/mac80211/rc80211_pid_debugfs.c
78044 +++ b/net/mac80211/rc80211_pid_debugfs.c
78045 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78046
78047 spin_unlock_irqrestore(&events->lock, status);
78048
78049 - if (copy_to_user(buf, pb, p))
78050 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78051 return -EFAULT;
78052
78053 return p;
78054 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78055 index 39b82fe..5469ef4 100644
78056 --- a/net/mac80211/util.c
78057 +++ b/net/mac80211/util.c
78058 @@ -1251,7 +1251,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78059 }
78060 #endif
78061 /* everything else happens only if HW was up & running */
78062 - if (!local->open_count)
78063 + if (!local_read(&local->open_count))
78064 goto wake_up;
78065
78066 /*
78067 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78068 index c19b214..471fad1 100644
78069 --- a/net/netfilter/Kconfig
78070 +++ b/net/netfilter/Kconfig
78071 @@ -872,6 +872,16 @@ config NETFILTER_XT_MATCH_ESP
78072
78073 To compile it as a module, choose M here. If unsure, say N.
78074
78075 +config NETFILTER_XT_MATCH_GRADM
78076 + tristate '"gradm" match support'
78077 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78078 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78079 + ---help---
78080 + The gradm match allows to match on grsecurity RBAC being enabled.
78081 + It is useful when iptables rules are applied early on bootup to
78082 + prevent connections to the machine (except from a trusted host)
78083 + while the RBAC system is disabled.
78084 +
78085 config NETFILTER_XT_MATCH_HASHLIMIT
78086 tristate '"hashlimit" match support'
78087 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78088 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78089 index 1c5160f..145ae21 100644
78090 --- a/net/netfilter/Makefile
78091 +++ b/net/netfilter/Makefile
78092 @@ -90,6 +90,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78093 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78094 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78095 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78096 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78097 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78098 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78099 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78100 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78101 index 1548df9..98ad9b4 100644
78102 --- a/net/netfilter/ipvs/ip_vs_conn.c
78103 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78104 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78105 /* Increase the refcnt counter of the dest */
78106 atomic_inc(&dest->refcnt);
78107
78108 - conn_flags = atomic_read(&dest->conn_flags);
78109 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78110 if (cp->protocol != IPPROTO_UDP)
78111 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78112 flags = cp->flags;
78113 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78114 atomic_set(&cp->refcnt, 1);
78115
78116 atomic_set(&cp->n_control, 0);
78117 - atomic_set(&cp->in_pkts, 0);
78118 + atomic_set_unchecked(&cp->in_pkts, 0);
78119
78120 atomic_inc(&ipvs->conn_count);
78121 if (flags & IP_VS_CONN_F_NO_CPORT)
78122 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78123
78124 /* Don't drop the entry if its number of incoming packets is not
78125 located in [0, 8] */
78126 - i = atomic_read(&cp->in_pkts);
78127 + i = atomic_read_unchecked(&cp->in_pkts);
78128 if (i > 8 || i < 0) return 0;
78129
78130 if (!todrop_rate[i]) return 0;
78131 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78132 index b54ecce..fc5f6cf 100644
78133 --- a/net/netfilter/ipvs/ip_vs_core.c
78134 +++ b/net/netfilter/ipvs/ip_vs_core.c
78135 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78136 ret = cp->packet_xmit(skb, cp, pd->pp);
78137 /* do not touch skb anymore */
78138
78139 - atomic_inc(&cp->in_pkts);
78140 + atomic_inc_unchecked(&cp->in_pkts);
78141 ip_vs_conn_put(cp);
78142 return ret;
78143 }
78144 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78145 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78146 pkts = sysctl_sync_threshold(ipvs);
78147 else
78148 - pkts = atomic_add_return(1, &cp->in_pkts);
78149 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78150
78151 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78152 ip_vs_sync_conn(net, cp, pkts);
78153 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78154 index f51013c..c99ee52 100644
78155 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78156 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78157 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78158 ip_vs_rs_hash(ipvs, dest);
78159 write_unlock_bh(&ipvs->rs_lock);
78160 }
78161 - atomic_set(&dest->conn_flags, conn_flags);
78162 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78163
78164 /* bind the service */
78165 if (!dest->svc) {
78166 @@ -2076,7 +2076,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78167 " %-7s %-6d %-10d %-10d\n",
78168 &dest->addr.in6,
78169 ntohs(dest->port),
78170 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78171 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78172 atomic_read(&dest->weight),
78173 atomic_read(&dest->activeconns),
78174 atomic_read(&dest->inactconns));
78175 @@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78176 "%-7s %-6d %-10d %-10d\n",
78177 ntohl(dest->addr.ip),
78178 ntohs(dest->port),
78179 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78180 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78181 atomic_read(&dest->weight),
78182 atomic_read(&dest->activeconns),
78183 atomic_read(&dest->inactconns));
78184 @@ -2557,7 +2557,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78185
78186 entry.addr = dest->addr.ip;
78187 entry.port = dest->port;
78188 - entry.conn_flags = atomic_read(&dest->conn_flags);
78189 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78190 entry.weight = atomic_read(&dest->weight);
78191 entry.u_threshold = dest->u_threshold;
78192 entry.l_threshold = dest->l_threshold;
78193 @@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78194 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78195 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78196 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78197 - (atomic_read(&dest->conn_flags) &
78198 + (atomic_read_unchecked(&dest->conn_flags) &
78199 IP_VS_CONN_F_FWD_MASK)) ||
78200 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78201 atomic_read(&dest->weight)) ||
78202 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78203 index effa10c..9058928 100644
78204 --- a/net/netfilter/ipvs/ip_vs_sync.c
78205 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78206 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78207 cp = cp->control;
78208 if (cp) {
78209 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78210 - pkts = atomic_add_return(1, &cp->in_pkts);
78211 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78212 else
78213 pkts = sysctl_sync_threshold(ipvs);
78214 ip_vs_sync_conn(net, cp->control, pkts);
78215 @@ -758,7 +758,7 @@ control:
78216 if (!cp)
78217 return;
78218 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78219 - pkts = atomic_add_return(1, &cp->in_pkts);
78220 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78221 else
78222 pkts = sysctl_sync_threshold(ipvs);
78223 goto sloop;
78224 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78225
78226 if (opt)
78227 memcpy(&cp->in_seq, opt, sizeof(*opt));
78228 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78229 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78230 cp->state = state;
78231 cp->old_state = cp->state;
78232 /*
78233 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78234 index 65b616a..760a66b 100644
78235 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78236 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78237 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78238 else
78239 rc = NF_ACCEPT;
78240 /* do not touch skb anymore */
78241 - atomic_inc(&cp->in_pkts);
78242 + atomic_inc_unchecked(&cp->in_pkts);
78243 goto out;
78244 }
78245
78246 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78247 else
78248 rc = NF_ACCEPT;
78249 /* do not touch skb anymore */
78250 - atomic_inc(&cp->in_pkts);
78251 + atomic_inc_unchecked(&cp->in_pkts);
78252 goto out;
78253 }
78254
78255 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78256 index 2ceec64..a5b8a61 100644
78257 --- a/net/netfilter/nf_conntrack_core.c
78258 +++ b/net/netfilter/nf_conntrack_core.c
78259 @@ -1529,6 +1529,10 @@ err_extend:
78260 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78261 #define DYING_NULLS_VAL ((1<<30)+1)
78262
78263 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78264 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78265 +#endif
78266 +
78267 static int nf_conntrack_init_net(struct net *net)
78268 {
78269 int ret;
78270 @@ -1542,7 +1546,11 @@ static int nf_conntrack_init_net(struct net *net)
78271 goto err_stat;
78272 }
78273
78274 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78275 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78276 +#else
78277 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78278 +#endif
78279 if (!net->ct.slabname) {
78280 ret = -ENOMEM;
78281 goto err_slabname;
78282 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78283 index 5cfb5be..217c6d8 100644
78284 --- a/net/netfilter/nfnetlink_log.c
78285 +++ b/net/netfilter/nfnetlink_log.c
78286 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78287 };
78288
78289 static DEFINE_SPINLOCK(instances_lock);
78290 -static atomic_t global_seq;
78291 +static atomic_unchecked_t global_seq;
78292
78293 #define INSTANCE_BUCKETS 16
78294 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78295 @@ -523,7 +523,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78296 /* global sequence number */
78297 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78298 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78299 - htonl(atomic_inc_return(&global_seq))))
78300 + htonl(atomic_inc_return_unchecked(&global_seq))))
78301 goto nla_put_failure;
78302
78303 if (data_len) {
78304 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78305 new file mode 100644
78306 index 0000000..6905327
78307 --- /dev/null
78308 +++ b/net/netfilter/xt_gradm.c
78309 @@ -0,0 +1,51 @@
78310 +/*
78311 + * gradm match for netfilter
78312 + * Copyright © Zbigniew Krzystolik, 2010
78313 + *
78314 + * This program is free software; you can redistribute it and/or modify
78315 + * it under the terms of the GNU General Public License; either version
78316 + * 2 or 3 as published by the Free Software Foundation.
78317 + */
78318 +#include <linux/module.h>
78319 +#include <linux/moduleparam.h>
78320 +#include <linux/skbuff.h>
78321 +#include <linux/netfilter/x_tables.h>
78322 +#include <linux/grsecurity.h>
78323 +#include <linux/netfilter/xt_gradm.h>
78324 +
78325 +static bool
78326 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78327 +{
78328 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78329 + bool retval = false;
78330 + if (gr_acl_is_enabled())
78331 + retval = true;
78332 + return retval ^ info->invflags;
78333 +}
78334 +
78335 +static struct xt_match gradm_mt_reg __read_mostly = {
78336 + .name = "gradm",
78337 + .revision = 0,
78338 + .family = NFPROTO_UNSPEC,
78339 + .match = gradm_mt,
78340 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78341 + .me = THIS_MODULE,
78342 +};
78343 +
78344 +static int __init gradm_mt_init(void)
78345 +{
78346 + return xt_register_match(&gradm_mt_reg);
78347 +}
78348 +
78349 +static void __exit gradm_mt_exit(void)
78350 +{
78351 + xt_unregister_match(&gradm_mt_reg);
78352 +}
78353 +
78354 +module_init(gradm_mt_init);
78355 +module_exit(gradm_mt_exit);
78356 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78357 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78358 +MODULE_LICENSE("GPL");
78359 +MODULE_ALIAS("ipt_gradm");
78360 +MODULE_ALIAS("ip6t_gradm");
78361 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78362 index 4fe4fb4..87a89e5 100644
78363 --- a/net/netfilter/xt_statistic.c
78364 +++ b/net/netfilter/xt_statistic.c
78365 @@ -19,7 +19,7 @@
78366 #include <linux/module.h>
78367
78368 struct xt_statistic_priv {
78369 - atomic_t count;
78370 + atomic_unchecked_t count;
78371 } ____cacheline_aligned_in_smp;
78372
78373 MODULE_LICENSE("GPL");
78374 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78375 break;
78376 case XT_STATISTIC_MODE_NTH:
78377 do {
78378 - oval = atomic_read(&info->master->count);
78379 + oval = atomic_read_unchecked(&info->master->count);
78380 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78381 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78382 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78383 if (nval == 0)
78384 ret = !ret;
78385 break;
78386 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78387 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78388 if (info->master == NULL)
78389 return -ENOMEM;
78390 - atomic_set(&info->master->count, info->u.nth.count);
78391 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78392
78393 return 0;
78394 }
78395 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78396 index 5270238..5d37fbc 100644
78397 --- a/net/netlink/af_netlink.c
78398 +++ b/net/netlink/af_netlink.c
78399 @@ -767,7 +767,7 @@ static void netlink_overrun(struct sock *sk)
78400 sk->sk_error_report(sk);
78401 }
78402 }
78403 - atomic_inc(&sk->sk_drops);
78404 + atomic_inc_unchecked(&sk->sk_drops);
78405 }
78406
78407 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78408 @@ -2046,7 +2046,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78409 sk_wmem_alloc_get(s),
78410 nlk->cb,
78411 atomic_read(&s->sk_refcnt),
78412 - atomic_read(&s->sk_drops),
78413 + atomic_read_unchecked(&s->sk_drops),
78414 sock_i_ino(s)
78415 );
78416
78417 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78418 index 7261eb8..44e8ac6 100644
78419 --- a/net/netrom/af_netrom.c
78420 +++ b/net/netrom/af_netrom.c
78421 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78422 struct sock *sk = sock->sk;
78423 struct nr_sock *nr = nr_sk(sk);
78424
78425 + memset(sax, 0, sizeof(*sax));
78426 lock_sock(sk);
78427 if (peer != 0) {
78428 if (sk->sk_state != TCP_ESTABLISHED) {
78429 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78430 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78431 } else {
78432 sax->fsa_ax25.sax25_family = AF_NETROM;
78433 - sax->fsa_ax25.sax25_ndigis = 0;
78434 sax->fsa_ax25.sax25_call = nr->source_addr;
78435 *uaddr_len = sizeof(struct sockaddr_ax25);
78436 }
78437 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78438 index c5c9e2a..4814ab1 100644
78439 --- a/net/packet/af_packet.c
78440 +++ b/net/packet/af_packet.c
78441 @@ -1689,7 +1689,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78442
78443 spin_lock(&sk->sk_receive_queue.lock);
78444 po->stats.tp_packets++;
78445 - skb->dropcount = atomic_read(&sk->sk_drops);
78446 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78447 __skb_queue_tail(&sk->sk_receive_queue, skb);
78448 spin_unlock(&sk->sk_receive_queue.lock);
78449 sk->sk_data_ready(sk, skb->len);
78450 @@ -1698,7 +1698,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78451 drop_n_acct:
78452 spin_lock(&sk->sk_receive_queue.lock);
78453 po->stats.tp_drops++;
78454 - atomic_inc(&sk->sk_drops);
78455 + atomic_inc_unchecked(&sk->sk_drops);
78456 spin_unlock(&sk->sk_receive_queue.lock);
78457
78458 drop_n_restore:
78459 @@ -2642,6 +2642,7 @@ out:
78460
78461 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78462 {
78463 + struct sock_extended_err ee;
78464 struct sock_exterr_skb *serr;
78465 struct sk_buff *skb, *skb2;
78466 int copied, err;
78467 @@ -2663,8 +2664,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78468 sock_recv_timestamp(msg, sk, skb);
78469
78470 serr = SKB_EXT_ERR(skb);
78471 + ee = serr->ee;
78472 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78473 - sizeof(serr->ee), &serr->ee);
78474 + sizeof ee, &ee);
78475
78476 msg->msg_flags |= MSG_ERRQUEUE;
78477 err = copied;
78478 @@ -3276,7 +3278,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78479 case PACKET_HDRLEN:
78480 if (len > sizeof(int))
78481 len = sizeof(int);
78482 - if (copy_from_user(&val, optval, len))
78483 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78484 return -EFAULT;
78485 switch (val) {
78486 case TPACKET_V1:
78487 @@ -3315,7 +3317,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78488 len = lv;
78489 if (put_user(len, optlen))
78490 return -EFAULT;
78491 - if (copy_to_user(optval, data, len))
78492 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78493 return -EFAULT;
78494 return 0;
78495 }
78496 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78497 index 5a940db..f0b9c12 100644
78498 --- a/net/phonet/af_phonet.c
78499 +++ b/net/phonet/af_phonet.c
78500 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78501 {
78502 struct phonet_protocol *pp;
78503
78504 - if (protocol >= PHONET_NPROTO)
78505 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78506 return NULL;
78507
78508 rcu_read_lock();
78509 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78510 {
78511 int err = 0;
78512
78513 - if (protocol >= PHONET_NPROTO)
78514 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78515 return -EINVAL;
78516
78517 err = proto_register(pp->prot, 1);
78518 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78519 index 576f22c..bc7a71b 100644
78520 --- a/net/phonet/pep.c
78521 +++ b/net/phonet/pep.c
78522 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78523
78524 case PNS_PEP_CTRL_REQ:
78525 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78526 - atomic_inc(&sk->sk_drops);
78527 + atomic_inc_unchecked(&sk->sk_drops);
78528 break;
78529 }
78530 __skb_pull(skb, 4);
78531 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78532 }
78533
78534 if (pn->rx_credits == 0) {
78535 - atomic_inc(&sk->sk_drops);
78536 + atomic_inc_unchecked(&sk->sk_drops);
78537 err = -ENOBUFS;
78538 break;
78539 }
78540 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78541 }
78542
78543 if (pn->rx_credits == 0) {
78544 - atomic_inc(&sk->sk_drops);
78545 + atomic_inc_unchecked(&sk->sk_drops);
78546 err = NET_RX_DROP;
78547 break;
78548 }
78549 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78550 index 0acc943..c727611 100644
78551 --- a/net/phonet/socket.c
78552 +++ b/net/phonet/socket.c
78553 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78554 pn->resource, sk->sk_state,
78555 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78556 sock_i_uid(sk), sock_i_ino(sk),
78557 - atomic_read(&sk->sk_refcnt), sk,
78558 - atomic_read(&sk->sk_drops), &len);
78559 + atomic_read(&sk->sk_refcnt),
78560 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78561 + NULL,
78562 +#else
78563 + sk,
78564 +#endif
78565 + atomic_read_unchecked(&sk->sk_drops), &len);
78566 }
78567 seq_printf(seq, "%*s\n", 127 - len, "");
78568 return 0;
78569 diff --git a/net/rds/cong.c b/net/rds/cong.c
78570 index e5b65ac..f3b6fb7 100644
78571 --- a/net/rds/cong.c
78572 +++ b/net/rds/cong.c
78573 @@ -78,7 +78,7 @@
78574 * finds that the saved generation number is smaller than the global generation
78575 * number, it wakes up the process.
78576 */
78577 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78578 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78579
78580 /*
78581 * Congestion monitoring
78582 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78583 rdsdebug("waking map %p for %pI4\n",
78584 map, &map->m_addr);
78585 rds_stats_inc(s_cong_update_received);
78586 - atomic_inc(&rds_cong_generation);
78587 + atomic_inc_unchecked(&rds_cong_generation);
78588 if (waitqueue_active(&map->m_waitq))
78589 wake_up(&map->m_waitq);
78590 if (waitqueue_active(&rds_poll_waitq))
78591 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78592
78593 int rds_cong_updated_since(unsigned long *recent)
78594 {
78595 - unsigned long gen = atomic_read(&rds_cong_generation);
78596 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78597
78598 if (likely(*recent == gen))
78599 return 0;
78600 diff --git a/net/rds/ib.h b/net/rds/ib.h
78601 index 8d2b3d5..227ec5b 100644
78602 --- a/net/rds/ib.h
78603 +++ b/net/rds/ib.h
78604 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78605 /* sending acks */
78606 unsigned long i_ack_flags;
78607 #ifdef KERNEL_HAS_ATOMIC64
78608 - atomic64_t i_ack_next; /* next ACK to send */
78609 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78610 #else
78611 spinlock_t i_ack_lock; /* protect i_ack_next */
78612 u64 i_ack_next; /* next ACK to send */
78613 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78614 index a1e1162..265e129 100644
78615 --- a/net/rds/ib_cm.c
78616 +++ b/net/rds/ib_cm.c
78617 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78618 /* Clear the ACK state */
78619 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78620 #ifdef KERNEL_HAS_ATOMIC64
78621 - atomic64_set(&ic->i_ack_next, 0);
78622 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78623 #else
78624 ic->i_ack_next = 0;
78625 #endif
78626 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78627 index 8d19491..05a3e65 100644
78628 --- a/net/rds/ib_recv.c
78629 +++ b/net/rds/ib_recv.c
78630 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78631 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78632 int ack_required)
78633 {
78634 - atomic64_set(&ic->i_ack_next, seq);
78635 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78636 if (ack_required) {
78637 smp_mb__before_clear_bit();
78638 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78639 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78640 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78641 smp_mb__after_clear_bit();
78642
78643 - return atomic64_read(&ic->i_ack_next);
78644 + return atomic64_read_unchecked(&ic->i_ack_next);
78645 }
78646 #endif
78647
78648 diff --git a/net/rds/iw.h b/net/rds/iw.h
78649 index 04ce3b1..48119a6 100644
78650 --- a/net/rds/iw.h
78651 +++ b/net/rds/iw.h
78652 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78653 /* sending acks */
78654 unsigned long i_ack_flags;
78655 #ifdef KERNEL_HAS_ATOMIC64
78656 - atomic64_t i_ack_next; /* next ACK to send */
78657 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78658 #else
78659 spinlock_t i_ack_lock; /* protect i_ack_next */
78660 u64 i_ack_next; /* next ACK to send */
78661 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78662 index a91e1db..cf3053f 100644
78663 --- a/net/rds/iw_cm.c
78664 +++ b/net/rds/iw_cm.c
78665 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78666 /* Clear the ACK state */
78667 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78668 #ifdef KERNEL_HAS_ATOMIC64
78669 - atomic64_set(&ic->i_ack_next, 0);
78670 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78671 #else
78672 ic->i_ack_next = 0;
78673 #endif
78674 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78675 index 4503335..db566b4 100644
78676 --- a/net/rds/iw_recv.c
78677 +++ b/net/rds/iw_recv.c
78678 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78679 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78680 int ack_required)
78681 {
78682 - atomic64_set(&ic->i_ack_next, seq);
78683 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78684 if (ack_required) {
78685 smp_mb__before_clear_bit();
78686 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78687 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78688 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78689 smp_mb__after_clear_bit();
78690
78691 - return atomic64_read(&ic->i_ack_next);
78692 + return atomic64_read_unchecked(&ic->i_ack_next);
78693 }
78694 #endif
78695
78696 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78697 index edac9ef..16bcb98 100644
78698 --- a/net/rds/tcp.c
78699 +++ b/net/rds/tcp.c
78700 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78701 int val = 1;
78702
78703 set_fs(KERNEL_DS);
78704 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78705 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78706 sizeof(val));
78707 set_fs(oldfs);
78708 }
78709 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78710 index 1b4fd68..2234175 100644
78711 --- a/net/rds/tcp_send.c
78712 +++ b/net/rds/tcp_send.c
78713 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78714
78715 oldfs = get_fs();
78716 set_fs(KERNEL_DS);
78717 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78718 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78719 sizeof(val));
78720 set_fs(oldfs);
78721 }
78722 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78723 index 05996d0..5a1dfe0 100644
78724 --- a/net/rxrpc/af_rxrpc.c
78725 +++ b/net/rxrpc/af_rxrpc.c
78726 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78727 __be32 rxrpc_epoch;
78728
78729 /* current debugging ID */
78730 -atomic_t rxrpc_debug_id;
78731 +atomic_unchecked_t rxrpc_debug_id;
78732
78733 /* count of skbs currently in use */
78734 atomic_t rxrpc_n_skbs;
78735 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78736 index e4d9cbc..b229649 100644
78737 --- a/net/rxrpc/ar-ack.c
78738 +++ b/net/rxrpc/ar-ack.c
78739 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78740
78741 _enter("{%d,%d,%d,%d},",
78742 call->acks_hard, call->acks_unacked,
78743 - atomic_read(&call->sequence),
78744 + atomic_read_unchecked(&call->sequence),
78745 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78746
78747 stop = 0;
78748 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78749
78750 /* each Tx packet has a new serial number */
78751 sp->hdr.serial =
78752 - htonl(atomic_inc_return(&call->conn->serial));
78753 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78754
78755 hdr = (struct rxrpc_header *) txb->head;
78756 hdr->serial = sp->hdr.serial;
78757 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78758 */
78759 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78760 {
78761 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78762 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78763 }
78764
78765 /*
78766 @@ -629,7 +629,7 @@ process_further:
78767
78768 latest = ntohl(sp->hdr.serial);
78769 hard = ntohl(ack.firstPacket);
78770 - tx = atomic_read(&call->sequence);
78771 + tx = atomic_read_unchecked(&call->sequence);
78772
78773 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78774 latest,
78775 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
78776 goto maybe_reschedule;
78777
78778 send_ACK_with_skew:
78779 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
78780 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
78781 ntohl(ack.serial));
78782 send_ACK:
78783 mtu = call->conn->trans->peer->if_mtu;
78784 @@ -1173,7 +1173,7 @@ send_ACK:
78785 ackinfo.rxMTU = htonl(5692);
78786 ackinfo.jumbo_max = htonl(4);
78787
78788 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78789 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78790 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
78791 ntohl(hdr.serial),
78792 ntohs(ack.maxSkew),
78793 @@ -1191,7 +1191,7 @@ send_ACK:
78794 send_message:
78795 _debug("send message");
78796
78797 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
78798 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
78799 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
78800 send_message_2:
78801
78802 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
78803 index a3bbb36..3341fb9 100644
78804 --- a/net/rxrpc/ar-call.c
78805 +++ b/net/rxrpc/ar-call.c
78806 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
78807 spin_lock_init(&call->lock);
78808 rwlock_init(&call->state_lock);
78809 atomic_set(&call->usage, 1);
78810 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
78811 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78812 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
78813
78814 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
78815 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
78816 index 4106ca9..a338d7a 100644
78817 --- a/net/rxrpc/ar-connection.c
78818 +++ b/net/rxrpc/ar-connection.c
78819 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
78820 rwlock_init(&conn->lock);
78821 spin_lock_init(&conn->state_lock);
78822 atomic_set(&conn->usage, 1);
78823 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
78824 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78825 conn->avail_calls = RXRPC_MAXCALLS;
78826 conn->size_align = 4;
78827 conn->header_size = sizeof(struct rxrpc_header);
78828 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
78829 index e7ed43a..6afa140 100644
78830 --- a/net/rxrpc/ar-connevent.c
78831 +++ b/net/rxrpc/ar-connevent.c
78832 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
78833
78834 len = iov[0].iov_len + iov[1].iov_len;
78835
78836 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78837 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78838 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
78839
78840 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78841 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
78842 index 529572f..c758ca7 100644
78843 --- a/net/rxrpc/ar-input.c
78844 +++ b/net/rxrpc/ar-input.c
78845 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
78846 /* track the latest serial number on this connection for ACK packet
78847 * information */
78848 serial = ntohl(sp->hdr.serial);
78849 - hi_serial = atomic_read(&call->conn->hi_serial);
78850 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
78851 while (serial > hi_serial)
78852 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
78853 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
78854 serial);
78855
78856 /* request ACK generation for any ACK or DATA packet that requests
78857 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
78858 index a693aca..81e7293 100644
78859 --- a/net/rxrpc/ar-internal.h
78860 +++ b/net/rxrpc/ar-internal.h
78861 @@ -272,8 +272,8 @@ struct rxrpc_connection {
78862 int error; /* error code for local abort */
78863 int debug_id; /* debug ID for printks */
78864 unsigned int call_counter; /* call ID counter */
78865 - atomic_t serial; /* packet serial number counter */
78866 - atomic_t hi_serial; /* highest serial number received */
78867 + atomic_unchecked_t serial; /* packet serial number counter */
78868 + atomic_unchecked_t hi_serial; /* highest serial number received */
78869 u8 avail_calls; /* number of calls available */
78870 u8 size_align; /* data size alignment (for security) */
78871 u8 header_size; /* rxrpc + security header size */
78872 @@ -346,7 +346,7 @@ struct rxrpc_call {
78873 spinlock_t lock;
78874 rwlock_t state_lock; /* lock for state transition */
78875 atomic_t usage;
78876 - atomic_t sequence; /* Tx data packet sequence counter */
78877 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
78878 u32 abort_code; /* local/remote abort code */
78879 enum { /* current state of call */
78880 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
78881 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
78882 */
78883 extern atomic_t rxrpc_n_skbs;
78884 extern __be32 rxrpc_epoch;
78885 -extern atomic_t rxrpc_debug_id;
78886 +extern atomic_unchecked_t rxrpc_debug_id;
78887 extern struct workqueue_struct *rxrpc_workqueue;
78888
78889 /*
78890 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
78891 index 87f7135..74d3703 100644
78892 --- a/net/rxrpc/ar-local.c
78893 +++ b/net/rxrpc/ar-local.c
78894 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
78895 spin_lock_init(&local->lock);
78896 rwlock_init(&local->services_lock);
78897 atomic_set(&local->usage, 1);
78898 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
78899 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78900 memcpy(&local->srx, srx, sizeof(*srx));
78901 }
78902
78903 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
78904 index e1ac183..b43e10e 100644
78905 --- a/net/rxrpc/ar-output.c
78906 +++ b/net/rxrpc/ar-output.c
78907 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
78908 sp->hdr.cid = call->cid;
78909 sp->hdr.callNumber = call->call_id;
78910 sp->hdr.seq =
78911 - htonl(atomic_inc_return(&call->sequence));
78912 + htonl(atomic_inc_return_unchecked(&call->sequence));
78913 sp->hdr.serial =
78914 - htonl(atomic_inc_return(&conn->serial));
78915 + htonl(atomic_inc_return_unchecked(&conn->serial));
78916 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
78917 sp->hdr.userStatus = 0;
78918 sp->hdr.securityIndex = conn->security_ix;
78919 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
78920 index bebaa43..2644591 100644
78921 --- a/net/rxrpc/ar-peer.c
78922 +++ b/net/rxrpc/ar-peer.c
78923 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
78924 INIT_LIST_HEAD(&peer->error_targets);
78925 spin_lock_init(&peer->lock);
78926 atomic_set(&peer->usage, 1);
78927 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
78928 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78929 memcpy(&peer->srx, srx, sizeof(*srx));
78930
78931 rxrpc_assess_MTU_size(peer);
78932 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
78933 index 38047f7..9f48511 100644
78934 --- a/net/rxrpc/ar-proc.c
78935 +++ b/net/rxrpc/ar-proc.c
78936 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
78937 atomic_read(&conn->usage),
78938 rxrpc_conn_states[conn->state],
78939 key_serial(conn->key),
78940 - atomic_read(&conn->serial),
78941 - atomic_read(&conn->hi_serial));
78942 + atomic_read_unchecked(&conn->serial),
78943 + atomic_read_unchecked(&conn->hi_serial));
78944
78945 return 0;
78946 }
78947 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
78948 index 92df566..87ec1bf 100644
78949 --- a/net/rxrpc/ar-transport.c
78950 +++ b/net/rxrpc/ar-transport.c
78951 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
78952 spin_lock_init(&trans->client_lock);
78953 rwlock_init(&trans->conn_lock);
78954 atomic_set(&trans->usage, 1);
78955 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
78956 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
78957
78958 if (peer->srx.transport.family == AF_INET) {
78959 switch (peer->srx.transport_type) {
78960 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
78961 index f226709..0e735a8 100644
78962 --- a/net/rxrpc/rxkad.c
78963 +++ b/net/rxrpc/rxkad.c
78964 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
78965
78966 len = iov[0].iov_len + iov[1].iov_len;
78967
78968 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
78969 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78970 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
78971
78972 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
78973 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
78974
78975 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
78976
78977 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
78978 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
78979 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
78980
78981 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
78982 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
78983 index 1e2eee8..ce3967e 100644
78984 --- a/net/sctp/proc.c
78985 +++ b/net/sctp/proc.c
78986 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
78987 seq_printf(seq,
78988 "%8pK %8pK %-3d %-3d %-2d %-4d "
78989 "%4d %8d %8d %7d %5lu %-5d %5d ",
78990 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
78991 + assoc, sk,
78992 + sctp_sk(sk)->type, sk->sk_state,
78993 assoc->state, hash,
78994 assoc->assoc_id,
78995 assoc->sndbuf_used,
78996 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
78997 index 5e25981..dbda919 100644
78998 --- a/net/sctp/socket.c
78999 +++ b/net/sctp/socket.c
79000 @@ -4630,6 +4630,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79001 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79002 if (space_left < addrlen)
79003 return -ENOMEM;
79004 + if (addrlen > sizeof(temp) || addrlen < 0)
79005 + return -EFAULT;
79006 if (copy_to_user(to, &temp, addrlen))
79007 return -EFAULT;
79008 to += addrlen;
79009 diff --git a/net/socket.c b/net/socket.c
79010 index edc3c4a..4b4e4a8 100644
79011 --- a/net/socket.c
79012 +++ b/net/socket.c
79013 @@ -88,6 +88,7 @@
79014 #include <linux/nsproxy.h>
79015 #include <linux/magic.h>
79016 #include <linux/slab.h>
79017 +#include <linux/in.h>
79018
79019 #include <asm/uaccess.h>
79020 #include <asm/unistd.h>
79021 @@ -105,6 +106,8 @@
79022 #include <linux/sockios.h>
79023 #include <linux/atalk.h>
79024
79025 +#include <linux/grsock.h>
79026 +
79027 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79028 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79029 unsigned long nr_segs, loff_t pos);
79030 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79031 &sockfs_dentry_operations, SOCKFS_MAGIC);
79032 }
79033
79034 -static struct vfsmount *sock_mnt __read_mostly;
79035 +struct vfsmount *sock_mnt __read_mostly;
79036
79037 static struct file_system_type sock_fs_type = {
79038 .name = "sockfs",
79039 @@ -1209,6 +1212,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79040 return -EAFNOSUPPORT;
79041 if (type < 0 || type >= SOCK_MAX)
79042 return -EINVAL;
79043 + if (protocol < 0)
79044 + return -EINVAL;
79045
79046 /* Compatibility.
79047
79048 @@ -1340,6 +1345,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79049 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79050 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79051
79052 + if(!gr_search_socket(family, type, protocol)) {
79053 + retval = -EACCES;
79054 + goto out;
79055 + }
79056 +
79057 + if (gr_handle_sock_all(family, type, protocol)) {
79058 + retval = -EACCES;
79059 + goto out;
79060 + }
79061 +
79062 retval = sock_create(family, type, protocol, &sock);
79063 if (retval < 0)
79064 goto out;
79065 @@ -1452,6 +1467,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79066 if (sock) {
79067 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79068 if (err >= 0) {
79069 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79070 + err = -EACCES;
79071 + goto error;
79072 + }
79073 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79074 + if (err)
79075 + goto error;
79076 +
79077 err = security_socket_bind(sock,
79078 (struct sockaddr *)&address,
79079 addrlen);
79080 @@ -1460,6 +1483,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79081 (struct sockaddr *)
79082 &address, addrlen);
79083 }
79084 +error:
79085 fput_light(sock->file, fput_needed);
79086 }
79087 return err;
79088 @@ -1483,10 +1507,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79089 if ((unsigned int)backlog > somaxconn)
79090 backlog = somaxconn;
79091
79092 + if (gr_handle_sock_server_other(sock->sk)) {
79093 + err = -EPERM;
79094 + goto error;
79095 + }
79096 +
79097 + err = gr_search_listen(sock);
79098 + if (err)
79099 + goto error;
79100 +
79101 err = security_socket_listen(sock, backlog);
79102 if (!err)
79103 err = sock->ops->listen(sock, backlog);
79104
79105 +error:
79106 fput_light(sock->file, fput_needed);
79107 }
79108 return err;
79109 @@ -1530,6 +1564,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79110 newsock->type = sock->type;
79111 newsock->ops = sock->ops;
79112
79113 + if (gr_handle_sock_server_other(sock->sk)) {
79114 + err = -EPERM;
79115 + sock_release(newsock);
79116 + goto out_put;
79117 + }
79118 +
79119 + err = gr_search_accept(sock);
79120 + if (err) {
79121 + sock_release(newsock);
79122 + goto out_put;
79123 + }
79124 +
79125 /*
79126 * We don't need try_module_get here, as the listening socket (sock)
79127 * has the protocol module (sock->ops->owner) held.
79128 @@ -1568,6 +1614,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79129 fd_install(newfd, newfile);
79130 err = newfd;
79131
79132 + gr_attach_curr_ip(newsock->sk);
79133 +
79134 out_put:
79135 fput_light(sock->file, fput_needed);
79136 out:
79137 @@ -1600,6 +1648,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79138 int, addrlen)
79139 {
79140 struct socket *sock;
79141 + struct sockaddr *sck;
79142 struct sockaddr_storage address;
79143 int err, fput_needed;
79144
79145 @@ -1610,6 +1659,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79146 if (err < 0)
79147 goto out_put;
79148
79149 + sck = (struct sockaddr *)&address;
79150 +
79151 + if (gr_handle_sock_client(sck)) {
79152 + err = -EACCES;
79153 + goto out_put;
79154 + }
79155 +
79156 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79157 + if (err)
79158 + goto out_put;
79159 +
79160 err =
79161 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79162 if (err)
79163 @@ -1964,7 +2024,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79164 * checking falls down on this.
79165 */
79166 if (copy_from_user(ctl_buf,
79167 - (void __user __force *)msg_sys->msg_control,
79168 + (void __force_user *)msg_sys->msg_control,
79169 ctl_len))
79170 goto out_freectl;
79171 msg_sys->msg_control = ctl_buf;
79172 @@ -2132,7 +2192,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79173 * kernel msghdr to use the kernel address space)
79174 */
79175
79176 - uaddr = (__force void __user *)msg_sys->msg_name;
79177 + uaddr = (void __force_user *)msg_sys->msg_name;
79178 uaddr_len = COMPAT_NAMELEN(msg);
79179 if (MSG_CMSG_COMPAT & flags) {
79180 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79181 @@ -2761,7 +2821,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79182 }
79183
79184 ifr = compat_alloc_user_space(buf_size);
79185 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79186 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79187
79188 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79189 return -EFAULT;
79190 @@ -2785,12 +2845,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79191 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79192
79193 if (copy_in_user(rxnfc, compat_rxnfc,
79194 - (void *)(&rxnfc->fs.m_ext + 1) -
79195 - (void *)rxnfc) ||
79196 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79197 + (void __user *)rxnfc) ||
79198 copy_in_user(&rxnfc->fs.ring_cookie,
79199 &compat_rxnfc->fs.ring_cookie,
79200 - (void *)(&rxnfc->fs.location + 1) -
79201 - (void *)&rxnfc->fs.ring_cookie) ||
79202 + (void __user *)(&rxnfc->fs.location + 1) -
79203 + (void __user *)&rxnfc->fs.ring_cookie) ||
79204 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79205 sizeof(rxnfc->rule_cnt)))
79206 return -EFAULT;
79207 @@ -2802,12 +2862,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79208
79209 if (convert_out) {
79210 if (copy_in_user(compat_rxnfc, rxnfc,
79211 - (const void *)(&rxnfc->fs.m_ext + 1) -
79212 - (const void *)rxnfc) ||
79213 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79214 + (const void __user *)rxnfc) ||
79215 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79216 &rxnfc->fs.ring_cookie,
79217 - (const void *)(&rxnfc->fs.location + 1) -
79218 - (const void *)&rxnfc->fs.ring_cookie) ||
79219 + (const void __user *)(&rxnfc->fs.location + 1) -
79220 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79221 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79222 sizeof(rxnfc->rule_cnt)))
79223 return -EFAULT;
79224 @@ -2877,7 +2937,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79225 old_fs = get_fs();
79226 set_fs(KERNEL_DS);
79227 err = dev_ioctl(net, cmd,
79228 - (struct ifreq __user __force *) &kifr);
79229 + (struct ifreq __force_user *) &kifr);
79230 set_fs(old_fs);
79231
79232 return err;
79233 @@ -2986,7 +3046,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79234
79235 old_fs = get_fs();
79236 set_fs(KERNEL_DS);
79237 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79238 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79239 set_fs(old_fs);
79240
79241 if (cmd == SIOCGIFMAP && !err) {
79242 @@ -3091,7 +3151,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79243 ret |= __get_user(rtdev, &(ur4->rt_dev));
79244 if (rtdev) {
79245 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79246 - r4.rt_dev = (char __user __force *)devname;
79247 + r4.rt_dev = (char __force_user *)devname;
79248 devname[15] = 0;
79249 } else
79250 r4.rt_dev = NULL;
79251 @@ -3317,8 +3377,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79252 int __user *uoptlen;
79253 int err;
79254
79255 - uoptval = (char __user __force *) optval;
79256 - uoptlen = (int __user __force *) optlen;
79257 + uoptval = (char __force_user *) optval;
79258 + uoptlen = (int __force_user *) optlen;
79259
79260 set_fs(KERNEL_DS);
79261 if (level == SOL_SOCKET)
79262 @@ -3338,7 +3398,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79263 char __user *uoptval;
79264 int err;
79265
79266 - uoptval = (char __user __force *) optval;
79267 + uoptval = (char __force_user *) optval;
79268
79269 set_fs(KERNEL_DS);
79270 if (level == SOL_SOCKET)
79271 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79272 index 128494e..775d0e0 100644
79273 --- a/net/sunrpc/sched.c
79274 +++ b/net/sunrpc/sched.c
79275 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79276 #ifdef RPC_DEBUG
79277 static void rpc_task_set_debuginfo(struct rpc_task *task)
79278 {
79279 - static atomic_t rpc_pid;
79280 + static atomic_unchecked_t rpc_pid;
79281
79282 - task->tk_pid = atomic_inc_return(&rpc_pid);
79283 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79284 }
79285 #else
79286 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79287 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79288 index 8343737..677025e 100644
79289 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79290 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79291 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79292 static unsigned int min_max_inline = 4096;
79293 static unsigned int max_max_inline = 65536;
79294
79295 -atomic_t rdma_stat_recv;
79296 -atomic_t rdma_stat_read;
79297 -atomic_t rdma_stat_write;
79298 -atomic_t rdma_stat_sq_starve;
79299 -atomic_t rdma_stat_rq_starve;
79300 -atomic_t rdma_stat_rq_poll;
79301 -atomic_t rdma_stat_rq_prod;
79302 -atomic_t rdma_stat_sq_poll;
79303 -atomic_t rdma_stat_sq_prod;
79304 +atomic_unchecked_t rdma_stat_recv;
79305 +atomic_unchecked_t rdma_stat_read;
79306 +atomic_unchecked_t rdma_stat_write;
79307 +atomic_unchecked_t rdma_stat_sq_starve;
79308 +atomic_unchecked_t rdma_stat_rq_starve;
79309 +atomic_unchecked_t rdma_stat_rq_poll;
79310 +atomic_unchecked_t rdma_stat_rq_prod;
79311 +atomic_unchecked_t rdma_stat_sq_poll;
79312 +atomic_unchecked_t rdma_stat_sq_prod;
79313
79314 /* Temporary NFS request map and context caches */
79315 struct kmem_cache *svc_rdma_map_cachep;
79316 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79317 len -= *ppos;
79318 if (len > *lenp)
79319 len = *lenp;
79320 - if (len && copy_to_user(buffer, str_buf, len))
79321 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79322 return -EFAULT;
79323 *lenp = len;
79324 *ppos += len;
79325 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79326 {
79327 .procname = "rdma_stat_read",
79328 .data = &rdma_stat_read,
79329 - .maxlen = sizeof(atomic_t),
79330 + .maxlen = sizeof(atomic_unchecked_t),
79331 .mode = 0644,
79332 .proc_handler = read_reset_stat,
79333 },
79334 {
79335 .procname = "rdma_stat_recv",
79336 .data = &rdma_stat_recv,
79337 - .maxlen = sizeof(atomic_t),
79338 + .maxlen = sizeof(atomic_unchecked_t),
79339 .mode = 0644,
79340 .proc_handler = read_reset_stat,
79341 },
79342 {
79343 .procname = "rdma_stat_write",
79344 .data = &rdma_stat_write,
79345 - .maxlen = sizeof(atomic_t),
79346 + .maxlen = sizeof(atomic_unchecked_t),
79347 .mode = 0644,
79348 .proc_handler = read_reset_stat,
79349 },
79350 {
79351 .procname = "rdma_stat_sq_starve",
79352 .data = &rdma_stat_sq_starve,
79353 - .maxlen = sizeof(atomic_t),
79354 + .maxlen = sizeof(atomic_unchecked_t),
79355 .mode = 0644,
79356 .proc_handler = read_reset_stat,
79357 },
79358 {
79359 .procname = "rdma_stat_rq_starve",
79360 .data = &rdma_stat_rq_starve,
79361 - .maxlen = sizeof(atomic_t),
79362 + .maxlen = sizeof(atomic_unchecked_t),
79363 .mode = 0644,
79364 .proc_handler = read_reset_stat,
79365 },
79366 {
79367 .procname = "rdma_stat_rq_poll",
79368 .data = &rdma_stat_rq_poll,
79369 - .maxlen = sizeof(atomic_t),
79370 + .maxlen = sizeof(atomic_unchecked_t),
79371 .mode = 0644,
79372 .proc_handler = read_reset_stat,
79373 },
79374 {
79375 .procname = "rdma_stat_rq_prod",
79376 .data = &rdma_stat_rq_prod,
79377 - .maxlen = sizeof(atomic_t),
79378 + .maxlen = sizeof(atomic_unchecked_t),
79379 .mode = 0644,
79380 .proc_handler = read_reset_stat,
79381 },
79382 {
79383 .procname = "rdma_stat_sq_poll",
79384 .data = &rdma_stat_sq_poll,
79385 - .maxlen = sizeof(atomic_t),
79386 + .maxlen = sizeof(atomic_unchecked_t),
79387 .mode = 0644,
79388 .proc_handler = read_reset_stat,
79389 },
79390 {
79391 .procname = "rdma_stat_sq_prod",
79392 .data = &rdma_stat_sq_prod,
79393 - .maxlen = sizeof(atomic_t),
79394 + .maxlen = sizeof(atomic_unchecked_t),
79395 .mode = 0644,
79396 .proc_handler = read_reset_stat,
79397 },
79398 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79399 index 41cb63b..c4a1489 100644
79400 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79401 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79402 @@ -501,7 +501,7 @@ next_sge:
79403 svc_rdma_put_context(ctxt, 0);
79404 goto out;
79405 }
79406 - atomic_inc(&rdma_stat_read);
79407 + atomic_inc_unchecked(&rdma_stat_read);
79408
79409 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79410 chl_map->ch[ch_no].count -= read_wr.num_sge;
79411 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79412 dto_q);
79413 list_del_init(&ctxt->dto_q);
79414 } else {
79415 - atomic_inc(&rdma_stat_rq_starve);
79416 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79417 clear_bit(XPT_DATA, &xprt->xpt_flags);
79418 ctxt = NULL;
79419 }
79420 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79421 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79422 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79423 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79424 - atomic_inc(&rdma_stat_recv);
79425 + atomic_inc_unchecked(&rdma_stat_recv);
79426
79427 /* Build up the XDR from the receive buffers. */
79428 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79429 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79430 index 42eb7ba..c887c45 100644
79431 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79432 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79433 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79434 write_wr.wr.rdma.remote_addr = to;
79435
79436 /* Post It */
79437 - atomic_inc(&rdma_stat_write);
79438 + atomic_inc_unchecked(&rdma_stat_write);
79439 if (svc_rdma_send(xprt, &write_wr))
79440 goto err;
79441 return 0;
79442 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79443 index 73b428b..5f3f8f3 100644
79444 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79445 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79446 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79447 return;
79448
79449 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79450 - atomic_inc(&rdma_stat_rq_poll);
79451 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79452
79453 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79454 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79455 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79456 }
79457
79458 if (ctxt)
79459 - atomic_inc(&rdma_stat_rq_prod);
79460 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79461
79462 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79463 /*
79464 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79465 return;
79466
79467 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79468 - atomic_inc(&rdma_stat_sq_poll);
79469 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79470 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79471 if (wc.status != IB_WC_SUCCESS)
79472 /* Close the transport */
79473 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79474 }
79475
79476 if (ctxt)
79477 - atomic_inc(&rdma_stat_sq_prod);
79478 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79479 }
79480
79481 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79482 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79483 spin_lock_bh(&xprt->sc_lock);
79484 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79485 spin_unlock_bh(&xprt->sc_lock);
79486 - atomic_inc(&rdma_stat_sq_starve);
79487 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79488
79489 /* See if we can opportunistically reap SQ WR to make room */
79490 sq_cq_reap(xprt);
79491 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79492 index e3a6e37..be2ea77 100644
79493 --- a/net/sysctl_net.c
79494 +++ b/net/sysctl_net.c
79495 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79496 struct ctl_table *table)
79497 {
79498 /* Allow network administrator to have same access as root. */
79499 - if (capable(CAP_NET_ADMIN)) {
79500 + if (capable_nolog(CAP_NET_ADMIN)) {
79501 int mode = (table->mode >> 6) & 7;
79502 return (mode << 6) | (mode << 3) | mode;
79503 }
79504 diff --git a/net/tipc/link.c b/net/tipc/link.c
79505 index 1c1e615..113e0ae 100644
79506 --- a/net/tipc/link.c
79507 +++ b/net/tipc/link.c
79508 @@ -1171,7 +1171,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79509 struct tipc_msg fragm_hdr;
79510 struct sk_buff *buf, *buf_chain, *prev;
79511 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79512 - const unchar *sect_crs;
79513 + const unchar __user *sect_crs;
79514 int curr_sect;
79515 u32 fragm_no;
79516
79517 @@ -1212,7 +1212,7 @@ again:
79518
79519 if (!sect_rest) {
79520 sect_rest = msg_sect[++curr_sect].iov_len;
79521 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79522 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79523 }
79524
79525 if (sect_rest < fragm_rest)
79526 @@ -1231,7 +1231,7 @@ error:
79527 }
79528 } else
79529 skb_copy_to_linear_data_offset(buf, fragm_crs,
79530 - sect_crs, sz);
79531 + (const void __force_kernel *)sect_crs, sz);
79532 sect_crs += sz;
79533 sect_rest -= sz;
79534 fragm_crs += sz;
79535 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79536 index f2db8a8..9245aa4 100644
79537 --- a/net/tipc/msg.c
79538 +++ b/net/tipc/msg.c
79539 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79540 msg_sect[cnt].iov_len);
79541 else
79542 skb_copy_to_linear_data_offset(*buf, pos,
79543 - msg_sect[cnt].iov_base,
79544 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79545 msg_sect[cnt].iov_len);
79546 pos += msg_sect[cnt].iov_len;
79547 }
79548 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79549 index 5ed5965..90abe34 100644
79550 --- a/net/tipc/subscr.c
79551 +++ b/net/tipc/subscr.c
79552 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79553 {
79554 struct iovec msg_sect;
79555
79556 - msg_sect.iov_base = (void *)&sub->evt;
79557 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79558 msg_sect.iov_len = sizeof(struct tipc_event);
79559
79560 sub->evt.event = htohl(event, sub->swap);
79561 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79562 index c5ee4ff..e905948 100644
79563 --- a/net/unix/af_unix.c
79564 +++ b/net/unix/af_unix.c
79565 @@ -789,6 +789,12 @@ static struct sock *unix_find_other(struct net *net,
79566 err = -ECONNREFUSED;
79567 if (!S_ISSOCK(inode->i_mode))
79568 goto put_fail;
79569 +
79570 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79571 + err = -EACCES;
79572 + goto put_fail;
79573 + }
79574 +
79575 u = unix_find_socket_byinode(inode);
79576 if (!u)
79577 goto put_fail;
79578 @@ -809,6 +815,13 @@ static struct sock *unix_find_other(struct net *net,
79579 if (u) {
79580 struct dentry *dentry;
79581 dentry = unix_sk(u)->path.dentry;
79582 +
79583 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79584 + err = -EPERM;
79585 + sock_put(u);
79586 + goto fail;
79587 + }
79588 +
79589 if (dentry)
79590 touch_atime(&unix_sk(u)->path);
79591 } else
79592 @@ -842,12 +855,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
79593 */
79594 err = security_path_mknod(&path, dentry, mode, 0);
79595 if (!err) {
79596 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79597 + err = -EACCES;
79598 + goto out;
79599 + }
79600 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79601 if (!err) {
79602 res->mnt = mntget(path.mnt);
79603 res->dentry = dget(dentry);
79604 + gr_handle_create(dentry, path.mnt);
79605 }
79606 }
79607 +out:
79608 done_path_create(&path, dentry);
79609 return err;
79610 }
79611 diff --git a/net/wireless/core.h b/net/wireless/core.h
79612 index bc7430b..35349de 100644
79613 --- a/net/wireless/core.h
79614 +++ b/net/wireless/core.h
79615 @@ -28,7 +28,7 @@ struct cfg80211_registered_device {
79616 struct mutex mtx;
79617
79618 /* rfkill support */
79619 - struct rfkill_ops rfkill_ops;
79620 + rfkill_ops_no_const rfkill_ops;
79621 struct rfkill *rfkill;
79622 struct work_struct rfkill_sync;
79623
79624 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79625 index b0eb7aa..7d73e82 100644
79626 --- a/net/wireless/wext-core.c
79627 +++ b/net/wireless/wext-core.c
79628 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79629 */
79630
79631 /* Support for very large requests */
79632 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79633 - (user_length > descr->max_tokens)) {
79634 + if (user_length > descr->max_tokens) {
79635 /* Allow userspace to GET more than max so
79636 * we can support any size GET requests.
79637 * There is still a limit : -ENOMEM.
79638 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79639 }
79640 }
79641
79642 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79643 - /*
79644 - * If this is a GET, but not NOMAX, it means that the extra
79645 - * data is not bounded by userspace, but by max_tokens. Thus
79646 - * set the length to max_tokens. This matches the extra data
79647 - * allocation.
79648 - * The driver should fill it with the number of tokens it
79649 - * provided, and it may check iwp->length rather than having
79650 - * knowledge of max_tokens. If the driver doesn't change the
79651 - * iwp->length, this ioctl just copies back max_token tokens
79652 - * filled with zeroes. Hopefully the driver isn't claiming
79653 - * them to be valid data.
79654 - */
79655 - iwp->length = descr->max_tokens;
79656 - }
79657 -
79658 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79659
79660 iwp->length += essid_compat;
79661 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79662 index 387848e..a6667a2 100644
79663 --- a/net/xfrm/xfrm_policy.c
79664 +++ b/net/xfrm/xfrm_policy.c
79665 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79666 {
79667 policy->walk.dead = 1;
79668
79669 - atomic_inc(&policy->genid);
79670 + atomic_inc_unchecked(&policy->genid);
79671
79672 if (del_timer(&policy->timer))
79673 xfrm_pol_put(policy);
79674 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79675 hlist_add_head(&policy->bydst, chain);
79676 xfrm_pol_hold(policy);
79677 net->xfrm.policy_count[dir]++;
79678 - atomic_inc(&flow_cache_genid);
79679 + atomic_inc_unchecked(&flow_cache_genid);
79680 rt_genid_bump(net);
79681 if (delpol)
79682 __xfrm_policy_unlink(delpol, dir);
79683 @@ -1533,7 +1533,7 @@ free_dst:
79684 goto out;
79685 }
79686
79687 -static int inline
79688 +static inline int
79689 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79690 {
79691 if (!*target) {
79692 @@ -1545,7 +1545,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79693 return 0;
79694 }
79695
79696 -static int inline
79697 +static inline int
79698 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79699 {
79700 #ifdef CONFIG_XFRM_SUB_POLICY
79701 @@ -1557,7 +1557,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79702 #endif
79703 }
79704
79705 -static int inline
79706 +static inline int
79707 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79708 {
79709 #ifdef CONFIG_XFRM_SUB_POLICY
79710 @@ -1651,7 +1651,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79711
79712 xdst->num_pols = num_pols;
79713 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79714 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79715 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79716
79717 return xdst;
79718 }
79719 @@ -2352,7 +2352,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79720 if (xdst->xfrm_genid != dst->xfrm->genid)
79721 return 0;
79722 if (xdst->num_pols > 0 &&
79723 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79724 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79725 return 0;
79726
79727 mtu = dst_mtu(dst->child);
79728 @@ -2891,7 +2891,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79729 sizeof(pol->xfrm_vec[i].saddr));
79730 pol->xfrm_vec[i].encap_family = mp->new_family;
79731 /* flush bundles */
79732 - atomic_inc(&pol->genid);
79733 + atomic_inc_unchecked(&pol->genid);
79734 }
79735 }
79736
79737 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
79738 index ff1720d..ed8475e 100644
79739 --- a/scripts/Makefile.build
79740 +++ b/scripts/Makefile.build
79741 @@ -111,7 +111,7 @@ endif
79742 endif
79743
79744 # Do not include host rules unless needed
79745 -ifneq ($(hostprogs-y)$(hostprogs-m),)
79746 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
79747 include scripts/Makefile.host
79748 endif
79749
79750 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
79751 index 686cb0d..9d653bf 100644
79752 --- a/scripts/Makefile.clean
79753 +++ b/scripts/Makefile.clean
79754 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
79755 __clean-files := $(extra-y) $(always) \
79756 $(targets) $(clean-files) \
79757 $(host-progs) \
79758 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
79759 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
79760 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
79761
79762 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
79763
79764 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
79765 index 1ac414f..38575f7 100644
79766 --- a/scripts/Makefile.host
79767 +++ b/scripts/Makefile.host
79768 @@ -31,6 +31,8 @@
79769 # Note: Shared libraries consisting of C++ files are not supported
79770
79771 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
79772 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
79773 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
79774
79775 # C code
79776 # Executables compiled from a single .c file
79777 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
79778 # Shared libaries (only .c supported)
79779 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
79780 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
79781 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
79782 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
79783 # Remove .so files from "xxx-objs"
79784 host-cobjs := $(filter-out %.so,$(host-cobjs))
79785 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
79786
79787 -#Object (.o) files used by the shared libaries
79788 +# Object (.o) files used by the shared libaries
79789 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
79790 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
79791
79792 # output directory for programs/.o files
79793 # hostprogs-y := tools/build may have been specified. Retrieve directory
79794 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
79795 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
79796 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
79797 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
79798 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
79799 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
79800 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
79801 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
79802
79803 obj-dirs += $(host-objdirs)
79804 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
79805 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
79806 $(call if_changed_dep,host-cshobjs)
79807
79808 +# Compile .c file, create position independent .o file
79809 +# host-cxxshobjs -> .o
79810 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
79811 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
79812 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
79813 + $(call if_changed_dep,host-cxxshobjs)
79814 +
79815 # Link a shared library, based on position independent .o files
79816 # *.o -> .so shared library (host-cshlib)
79817 quiet_cmd_host-cshlib = HOSTLLD -shared $@
79818 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
79819 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
79820 $(call if_changed,host-cshlib)
79821
79822 +# Link a shared library, based on position independent .o files
79823 +# *.o -> .so shared library (host-cxxshlib)
79824 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
79825 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
79826 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
79827 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
79828 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
79829 + $(call if_changed,host-cxxshlib)
79830 +
79831 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
79832 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
79833 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
79834
79835 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
79836 index cb1f50c..cef2a7c 100644
79837 --- a/scripts/basic/fixdep.c
79838 +++ b/scripts/basic/fixdep.c
79839 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
79840 /*
79841 * Lookup a value in the configuration string.
79842 */
79843 -static int is_defined_config(const char *name, int len, unsigned int hash)
79844 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
79845 {
79846 struct item *aux;
79847
79848 @@ -211,10 +211,10 @@ static void clear_config(void)
79849 /*
79850 * Record the use of a CONFIG_* word.
79851 */
79852 -static void use_config(const char *m, int slen)
79853 +static void use_config(const char *m, unsigned int slen)
79854 {
79855 unsigned int hash = strhash(m, slen);
79856 - int c, i;
79857 + unsigned int c, i;
79858
79859 if (is_defined_config(m, slen, hash))
79860 return;
79861 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
79862
79863 static void parse_config_file(const char *map, size_t len)
79864 {
79865 - const int *end = (const int *) (map + len);
79866 + const unsigned int *end = (const unsigned int *) (map + len);
79867 /* start at +1, so that p can never be < map */
79868 - const int *m = (const int *) map + 1;
79869 + const unsigned int *m = (const unsigned int *) map + 1;
79870 const char *p, *q;
79871
79872 for (; m < end; m++) {
79873 @@ -406,7 +406,7 @@ static void print_deps(void)
79874 static void traps(void)
79875 {
79876 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
79877 - int *p = (int *)test;
79878 + unsigned int *p = (unsigned int *)test;
79879
79880 if (*p != INT_CONF) {
79881 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
79882 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
79883 new file mode 100644
79884 index 0000000..008ac1a
79885 --- /dev/null
79886 +++ b/scripts/gcc-plugin.sh
79887 @@ -0,0 +1,17 @@
79888 +#!/bin/bash
79889 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
79890 +#include "gcc-plugin.h"
79891 +#include "tree.h"
79892 +#include "tm.h"
79893 +#include "rtl.h"
79894 +#ifdef ENABLE_BUILD_WITH_CXX
79895 +#warning $2
79896 +#else
79897 +#warning $1
79898 +#endif
79899 +EOF`
79900 +if [ $? -eq 0 ]
79901 +then
79902 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
79903 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
79904 +fi
79905 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
79906 index b3d907e..a4782ab 100644
79907 --- a/scripts/link-vmlinux.sh
79908 +++ b/scripts/link-vmlinux.sh
79909 @@ -152,7 +152,7 @@ else
79910 fi;
79911
79912 # final build of init/
79913 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
79914 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
79915
79916 kallsymso=""
79917 kallsyms_vmlinux=""
79918 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
79919 index 7ed6864..b6e90e6 100644
79920 --- a/scripts/mod/file2alias.c
79921 +++ b/scripts/mod/file2alias.c
79922 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
79923 unsigned long size, unsigned long id_size,
79924 void *symval)
79925 {
79926 - int i;
79927 + unsigned int i;
79928
79929 if (size % id_size || size < id_size) {
79930 if (cross_build != 0)
79931 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
79932 /* USB is special because the bcdDevice can be matched against a numeric range */
79933 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
79934 static void do_usb_entry(struct usb_device_id *id,
79935 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
79936 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
79937 unsigned char range_lo, unsigned char range_hi,
79938 unsigned char max, struct module *mod)
79939 {
79940 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
79941 {
79942 unsigned int devlo, devhi;
79943 unsigned char chi, clo, max;
79944 - int ndigits;
79945 + unsigned int ndigits;
79946
79947 id->match_flags = TO_NATIVE(id->match_flags);
79948 id->idVendor = TO_NATIVE(id->idVendor);
79949 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
79950 for (i = 0; i < count; i++) {
79951 const char *id = (char *)devs[i].id;
79952 char acpi_id[sizeof(devs[0].id)];
79953 - int j;
79954 + unsigned int j;
79955
79956 buf_printf(&mod->dev_table_buf,
79957 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79958 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79959
79960 for (j = 0; j < PNP_MAX_DEVICES; j++) {
79961 const char *id = (char *)card->devs[j].id;
79962 - int i2, j2;
79963 + unsigned int i2, j2;
79964 int dup = 0;
79965
79966 if (!id[0])
79967 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
79968 /* add an individual alias for every device entry */
79969 if (!dup) {
79970 char acpi_id[sizeof(card->devs[0].id)];
79971 - int k;
79972 + unsigned int k;
79973
79974 buf_printf(&mod->dev_table_buf,
79975 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
79976 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
79977 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
79978 char *alias)
79979 {
79980 - int i, j;
79981 + unsigned int i, j;
79982
79983 sprintf(alias, "dmi*");
79984
79985 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
79986 index 68e9f5e..ac7759b 100644
79987 --- a/scripts/mod/modpost.c
79988 +++ b/scripts/mod/modpost.c
79989 @@ -930,6 +930,7 @@ enum mismatch {
79990 ANY_INIT_TO_ANY_EXIT,
79991 ANY_EXIT_TO_ANY_INIT,
79992 EXPORT_TO_INIT_EXIT,
79993 + DATA_TO_TEXT
79994 };
79995
79996 struct sectioncheck {
79997 @@ -1044,6 +1045,12 @@ const struct sectioncheck sectioncheck[] = {
79998 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
79999 .mismatch = EXPORT_TO_INIT_EXIT,
80000 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80001 +},
80002 +/* Do not reference code from writable data */
80003 +{
80004 + .fromsec = { DATA_SECTIONS, NULL },
80005 + .tosec = { TEXT_SECTIONS, NULL },
80006 + .mismatch = DATA_TO_TEXT
80007 }
80008 };
80009
80010 @@ -1166,10 +1173,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80011 continue;
80012 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80013 continue;
80014 - if (sym->st_value == addr)
80015 - return sym;
80016 /* Find a symbol nearby - addr are maybe negative */
80017 d = sym->st_value - addr;
80018 + if (d == 0)
80019 + return sym;
80020 if (d < 0)
80021 d = addr - sym->st_value;
80022 if (d < distance) {
80023 @@ -1448,6 +1455,14 @@ static void report_sec_mismatch(const char *modname,
80024 tosym, prl_to, prl_to, tosym);
80025 free(prl_to);
80026 break;
80027 + case DATA_TO_TEXT:
80028 +#if 0
80029 + fprintf(stderr,
80030 + "The %s %s:%s references\n"
80031 + "the %s %s:%s%s\n",
80032 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80033 +#endif
80034 + break;
80035 }
80036 fprintf(stderr, "\n");
80037 }
80038 @@ -1682,7 +1697,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80039 static void check_sec_ref(struct module *mod, const char *modname,
80040 struct elf_info *elf)
80041 {
80042 - int i;
80043 + unsigned int i;
80044 Elf_Shdr *sechdrs = elf->sechdrs;
80045
80046 /* Walk through all sections */
80047 @@ -1780,7 +1795,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80048 va_end(ap);
80049 }
80050
80051 -void buf_write(struct buffer *buf, const char *s, int len)
80052 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80053 {
80054 if (buf->size - buf->pos < len) {
80055 buf->size += len + SZ;
80056 @@ -1998,7 +2013,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80057 if (fstat(fileno(file), &st) < 0)
80058 goto close_write;
80059
80060 - if (st.st_size != b->pos)
80061 + if (st.st_size != (off_t)b->pos)
80062 goto close_write;
80063
80064 tmp = NOFAIL(malloc(b->pos));
80065 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80066 index 51207e4..f7d603d 100644
80067 --- a/scripts/mod/modpost.h
80068 +++ b/scripts/mod/modpost.h
80069 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80070
80071 struct buffer {
80072 char *p;
80073 - int pos;
80074 - int size;
80075 + unsigned int pos;
80076 + unsigned int size;
80077 };
80078
80079 void __attribute__((format(printf, 2, 3)))
80080 buf_printf(struct buffer *buf, const char *fmt, ...);
80081
80082 void
80083 -buf_write(struct buffer *buf, const char *s, int len);
80084 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80085
80086 struct module {
80087 struct module *next;
80088 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80089 index 9dfcd6d..099068e 100644
80090 --- a/scripts/mod/sumversion.c
80091 +++ b/scripts/mod/sumversion.c
80092 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80093 goto out;
80094 }
80095
80096 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80097 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80098 warn("writing sum in %s failed: %s\n",
80099 filename, strerror(errno));
80100 goto out;
80101 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80102 index 5c11312..72742b5 100644
80103 --- a/scripts/pnmtologo.c
80104 +++ b/scripts/pnmtologo.c
80105 @@ -237,14 +237,14 @@ static void write_header(void)
80106 fprintf(out, " * Linux logo %s\n", logoname);
80107 fputs(" */\n\n", out);
80108 fputs("#include <linux/linux_logo.h>\n\n", out);
80109 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80110 + fprintf(out, "static unsigned char %s_data[] = {\n",
80111 logoname);
80112 }
80113
80114 static void write_footer(void)
80115 {
80116 fputs("\n};\n\n", out);
80117 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80118 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80119 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80120 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80121 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80122 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80123 fputs("\n};\n\n", out);
80124
80125 /* write logo clut */
80126 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80127 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80128 logoname);
80129 write_hex_cnt = 0;
80130 for (i = 0; i < logo_clutsize; i++) {
80131 diff --git a/security/Kconfig b/security/Kconfig
80132 index e9c6ac7..e7feb0d 100644
80133 --- a/security/Kconfig
80134 +++ b/security/Kconfig
80135 @@ -4,6 +4,896 @@
80136
80137 menu "Security options"
80138
80139 +menu "Grsecurity"
80140 +
80141 + config ARCH_TRACK_EXEC_LIMIT
80142 + bool
80143 +
80144 + config PAX_KERNEXEC_PLUGIN
80145 + bool
80146 +
80147 + config PAX_PER_CPU_PGD
80148 + bool
80149 +
80150 + config TASK_SIZE_MAX_SHIFT
80151 + int
80152 + depends on X86_64
80153 + default 47 if !PAX_PER_CPU_PGD
80154 + default 42 if PAX_PER_CPU_PGD
80155 +
80156 + config PAX_ENABLE_PAE
80157 + bool
80158 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80159 +
80160 + config PAX_USERCOPY_SLABS
80161 + bool
80162 +
80163 +config GRKERNSEC
80164 + bool "Grsecurity"
80165 + select CRYPTO
80166 + select CRYPTO_SHA256
80167 + select PROC_FS
80168 + select STOP_MACHINE
80169 + help
80170 + If you say Y here, you will be able to configure many features
80171 + that will enhance the security of your system. It is highly
80172 + recommended that you say Y here and read through the help
80173 + for each option so that you fully understand the features and
80174 + can evaluate their usefulness for your machine.
80175 +
80176 +choice
80177 + prompt "Configuration Method"
80178 + depends on GRKERNSEC
80179 + default GRKERNSEC_CONFIG_CUSTOM
80180 + help
80181 +
80182 +config GRKERNSEC_CONFIG_AUTO
80183 + bool "Automatic"
80184 + help
80185 + If you choose this configuration method, you'll be able to answer a small
80186 + number of simple questions about how you plan to use this kernel.
80187 + The settings of grsecurity and PaX will be automatically configured for
80188 + the highest commonly-used settings within the provided constraints.
80189 +
80190 + If you require additional configuration, custom changes can still be made
80191 + from the "custom configuration" menu.
80192 +
80193 +config GRKERNSEC_CONFIG_CUSTOM
80194 + bool "Custom"
80195 + help
80196 + If you choose this configuration method, you'll be able to configure all
80197 + grsecurity and PaX settings manually. Via this method, no options are
80198 + automatically enabled.
80199 +
80200 +endchoice
80201 +
80202 +choice
80203 + prompt "Usage Type"
80204 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80205 + default GRKERNSEC_CONFIG_SERVER
80206 + help
80207 +
80208 +config GRKERNSEC_CONFIG_SERVER
80209 + bool "Server"
80210 + help
80211 + Choose this option if you plan to use this kernel on a server.
80212 +
80213 +config GRKERNSEC_CONFIG_DESKTOP
80214 + bool "Desktop"
80215 + help
80216 + Choose this option if you plan to use this kernel on a desktop.
80217 +
80218 +endchoice
80219 +
80220 +choice
80221 + prompt "Virtualization Type"
80222 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80223 + default GRKERNSEC_CONFIG_VIRT_NONE
80224 + help
80225 +
80226 +config GRKERNSEC_CONFIG_VIRT_NONE
80227 + bool "None"
80228 + help
80229 + Choose this option if this kernel will be run on bare metal.
80230 +
80231 +config GRKERNSEC_CONFIG_VIRT_GUEST
80232 + bool "Guest"
80233 + help
80234 + Choose this option if this kernel will be run as a VM guest.
80235 +
80236 +config GRKERNSEC_CONFIG_VIRT_HOST
80237 + bool "Host"
80238 + help
80239 + Choose this option if this kernel will be run as a VM host.
80240 +
80241 +endchoice
80242 +
80243 +choice
80244 + prompt "Virtualization Hardware"
80245 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80246 + help
80247 +
80248 +config GRKERNSEC_CONFIG_VIRT_EPT
80249 + bool "EPT/RVI Processor Support"
80250 + depends on X86
80251 + help
80252 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80253 + hardware virtualization. This allows for additional kernel hardening protections
80254 + to operate without additional performance impact.
80255 +
80256 + To see if your Intel processor supports EPT, see:
80257 + http://ark.intel.com/Products/VirtualizationTechnology
80258 + (Most Core i3/5/7 support EPT)
80259 +
80260 + To see if your AMD processor supports RVI, see:
80261 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80262 +
80263 +config GRKERNSEC_CONFIG_VIRT_SOFT
80264 + bool "First-gen/No Hardware Virtualization"
80265 + help
80266 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80267 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80268 +
80269 +endchoice
80270 +
80271 +choice
80272 + prompt "Virtualization Software"
80273 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80274 + help
80275 +
80276 +config GRKERNSEC_CONFIG_VIRT_XEN
80277 + bool "Xen"
80278 + help
80279 + Choose this option if this kernel is running as a Xen guest or host.
80280 +
80281 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80282 + bool "VMWare"
80283 + help
80284 + Choose this option if this kernel is running as a VMWare guest or host.
80285 +
80286 +config GRKERNSEC_CONFIG_VIRT_KVM
80287 + bool "KVM"
80288 + help
80289 + Choose this option if this kernel is running as a KVM guest or host.
80290 +
80291 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80292 + bool "VirtualBox"
80293 + help
80294 + Choose this option if this kernel is running as a VirtualBox guest or host.
80295 +
80296 +endchoice
80297 +
80298 +choice
80299 + prompt "Required Priorities"
80300 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80301 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80302 + help
80303 +
80304 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80305 + bool "Performance"
80306 + help
80307 + Choose this option if performance is of highest priority for this deployment
80308 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80309 + and freed memory sanitizing will be disabled.
80310 +
80311 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80312 + bool "Security"
80313 + help
80314 + Choose this option if security is of highest priority for this deployment of
80315 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80316 + be enabled for this kernel. In a worst-case scenario, these features can
80317 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80318 +
80319 +endchoice
80320 +
80321 +menu "Default Special Groups"
80322 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80323 +
80324 +config GRKERNSEC_PROC_GID
80325 + int "GID exempted from /proc restrictions"
80326 + default 1001
80327 + help
80328 + Setting this GID determines which group will be exempted from
80329 + grsecurity's /proc restrictions, allowing users of the specified
80330 + group to view network statistics and the existence of other users'
80331 + processes on the system. This GID may also be chosen at boot time
80332 + via "grsec_proc_gid=" on the kernel commandline.
80333 +
80334 +config GRKERNSEC_TPE_UNTRUSTED_GID
80335 + int "GID for TPE-untrusted users"
80336 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80337 + default 1005
80338 + help
80339 + Setting this GID determines which group untrusted users should
80340 + be added to. These users will be placed under grsecurity's Trusted Path
80341 + Execution mechanism, preventing them from executing their own binaries.
80342 + The users will only be able to execute binaries in directories owned and
80343 + writable only by the root user. If the sysctl option is enabled, a sysctl
80344 + option with name "tpe_gid" is created.
80345 +
80346 +config GRKERNSEC_TPE_TRUSTED_GID
80347 + int "GID for TPE-trusted users"
80348 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80349 + default 1005
80350 + help
80351 + Setting this GID determines what group TPE restrictions will be
80352 + *disabled* for. If the sysctl option is enabled, a sysctl option
80353 + with name "tpe_gid" is created.
80354 +
80355 +config GRKERNSEC_SYMLINKOWN_GID
80356 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80357 + depends on GRKERNSEC_CONFIG_SERVER
80358 + default 1006
80359 + help
80360 + Setting this GID determines what group kernel-enforced
80361 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80362 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80363 +
80364 +
80365 +endmenu
80366 +
80367 +menu "Customize Configuration"
80368 +depends on GRKERNSEC
80369 +
80370 +menu "PaX"
80371 +
80372 +config PAX
80373 + bool "Enable various PaX features"
80374 + default y if GRKERNSEC_CONFIG_AUTO
80375 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80376 + help
80377 + This allows you to enable various PaX features. PaX adds
80378 + intrusion prevention mechanisms to the kernel that reduce
80379 + the risks posed by exploitable memory corruption bugs.
80380 +
80381 +menu "PaX Control"
80382 + depends on PAX
80383 +
80384 +config PAX_SOFTMODE
80385 + bool 'Support soft mode'
80386 + help
80387 + Enabling this option will allow you to run PaX in soft mode, that
80388 + is, PaX features will not be enforced by default, only on executables
80389 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80390 + support as they are the only way to mark executables for soft mode use.
80391 +
80392 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80393 + line option on boot. Furthermore you can control various PaX features
80394 + at runtime via the entries in /proc/sys/kernel/pax.
80395 +
80396 +config PAX_EI_PAX
80397 + bool 'Use legacy ELF header marking'
80398 + default y if GRKERNSEC_CONFIG_AUTO
80399 + help
80400 + Enabling this option will allow you to control PaX features on
80401 + a per executable basis via the 'chpax' utility available at
80402 + http://pax.grsecurity.net/. The control flags will be read from
80403 + an otherwise reserved part of the ELF header. This marking has
80404 + numerous drawbacks (no support for soft-mode, toolchain does not
80405 + know about the non-standard use of the ELF header) therefore it
80406 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80407 + support.
80408 +
80409 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80410 + support as well, they will override the legacy EI_PAX marks.
80411 +
80412 + If you enable none of the marking options then all applications
80413 + will run with PaX enabled on them by default.
80414 +
80415 +config PAX_PT_PAX_FLAGS
80416 + bool 'Use ELF program header marking'
80417 + default y if GRKERNSEC_CONFIG_AUTO
80418 + help
80419 + Enabling this option will allow you to control PaX features on
80420 + a per executable basis via the 'paxctl' utility available at
80421 + http://pax.grsecurity.net/. The control flags will be read from
80422 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80423 + has the benefits of supporting both soft mode and being fully
80424 + integrated into the toolchain (the binutils patch is available
80425 + from http://pax.grsecurity.net).
80426 +
80427 + Note that if you enable the legacy EI_PAX marking support as well,
80428 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80429 +
80430 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80431 + must make sure that the marks are the same if a binary has both marks.
80432 +
80433 + If you enable none of the marking options then all applications
80434 + will run with PaX enabled on them by default.
80435 +
80436 +config PAX_XATTR_PAX_FLAGS
80437 + bool 'Use filesystem extended attributes marking'
80438 + default y if GRKERNSEC_CONFIG_AUTO
80439 + select CIFS_XATTR if CIFS
80440 + select EXT2_FS_XATTR if EXT2_FS
80441 + select EXT3_FS_XATTR if EXT3_FS
80442 + select EXT4_FS_XATTR if EXT4_FS
80443 + select JFFS2_FS_XATTR if JFFS2_FS
80444 + select REISERFS_FS_XATTR if REISERFS_FS
80445 + select SQUASHFS_XATTR if SQUASHFS
80446 + select TMPFS_XATTR if TMPFS
80447 + select UBIFS_FS_XATTR if UBIFS_FS
80448 + help
80449 + Enabling this option will allow you to control PaX features on
80450 + a per executable basis via the 'setfattr' utility. The control
80451 + flags will be read from the user.pax.flags extended attribute of
80452 + the file. This marking has the benefit of supporting binary-only
80453 + applications that self-check themselves (e.g., skype) and would
80454 + not tolerate chpax/paxctl changes. The main drawback is that
80455 + extended attributes are not supported by some filesystems (e.g.,
80456 + isofs, udf, vfat) so copying files through such filesystems will
80457 + lose the extended attributes and these PaX markings.
80458 +
80459 + Note that if you enable the legacy EI_PAX marking support as well,
80460 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80461 +
80462 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80463 + must make sure that the marks are the same if a binary has both marks.
80464 +
80465 + If you enable none of the marking options then all applications
80466 + will run with PaX enabled on them by default.
80467 +
80468 +choice
80469 + prompt 'MAC system integration'
80470 + default PAX_HAVE_ACL_FLAGS
80471 + help
80472 + Mandatory Access Control systems have the option of controlling
80473 + PaX flags on a per executable basis, choose the method supported
80474 + by your particular system.
80475 +
80476 + - "none": if your MAC system does not interact with PaX,
80477 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80478 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80479 +
80480 + NOTE: this option is for developers/integrators only.
80481 +
80482 + config PAX_NO_ACL_FLAGS
80483 + bool 'none'
80484 +
80485 + config PAX_HAVE_ACL_FLAGS
80486 + bool 'direct'
80487 +
80488 + config PAX_HOOK_ACL_FLAGS
80489 + bool 'hook'
80490 +endchoice
80491 +
80492 +endmenu
80493 +
80494 +menu "Non-executable pages"
80495 + depends on PAX
80496 +
80497 +config PAX_NOEXEC
80498 + bool "Enforce non-executable pages"
80499 + default y if GRKERNSEC_CONFIG_AUTO
80500 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80501 + help
80502 + By design some architectures do not allow for protecting memory
80503 + pages against execution or even if they do, Linux does not make
80504 + use of this feature. In practice this means that if a page is
80505 + readable (such as the stack or heap) it is also executable.
80506 +
80507 + There is a well known exploit technique that makes use of this
80508 + fact and a common programming mistake where an attacker can
80509 + introduce code of his choice somewhere in the attacked program's
80510 + memory (typically the stack or the heap) and then execute it.
80511 +
80512 + If the attacked program was running with different (typically
80513 + higher) privileges than that of the attacker, then he can elevate
80514 + his own privilege level (e.g. get a root shell, write to files for
80515 + which he does not have write access to, etc).
80516 +
80517 + Enabling this option will let you choose from various features
80518 + that prevent the injection and execution of 'foreign' code in
80519 + a program.
80520 +
80521 + This will also break programs that rely on the old behaviour and
80522 + expect that dynamically allocated memory via the malloc() family
80523 + of functions is executable (which it is not). Notable examples
80524 + are the XFree86 4.x server, the java runtime and wine.
80525 +
80526 +config PAX_PAGEEXEC
80527 + bool "Paging based non-executable pages"
80528 + default y if GRKERNSEC_CONFIG_AUTO
80529 + 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)
80530 + select S390_SWITCH_AMODE if S390
80531 + select S390_EXEC_PROTECT if S390
80532 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80533 + help
80534 + This implementation is based on the paging feature of the CPU.
80535 + On i386 without hardware non-executable bit support there is a
80536 + variable but usually low performance impact, however on Intel's
80537 + P4 core based CPUs it is very high so you should not enable this
80538 + for kernels meant to be used on such CPUs.
80539 +
80540 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80541 + with hardware non-executable bit support there is no performance
80542 + impact, on ppc the impact is negligible.
80543 +
80544 + Note that several architectures require various emulations due to
80545 + badly designed userland ABIs, this will cause a performance impact
80546 + but will disappear as soon as userland is fixed. For example, ppc
80547 + userland MUST have been built with secure-plt by a recent toolchain.
80548 +
80549 +config PAX_SEGMEXEC
80550 + bool "Segmentation based non-executable pages"
80551 + default y if GRKERNSEC_CONFIG_AUTO
80552 + depends on PAX_NOEXEC && X86_32
80553 + help
80554 + This implementation is based on the segmentation feature of the
80555 + CPU and has a very small performance impact, however applications
80556 + will be limited to a 1.5 GB address space instead of the normal
80557 + 3 GB.
80558 +
80559 +config PAX_EMUTRAMP
80560 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80561 + default y if PARISC
80562 + help
80563 + There are some programs and libraries that for one reason or
80564 + another attempt to execute special small code snippets from
80565 + non-executable memory pages. Most notable examples are the
80566 + signal handler return code generated by the kernel itself and
80567 + the GCC trampolines.
80568 +
80569 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80570 + such programs will no longer work under your kernel.
80571 +
80572 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80573 + utilities to enable trampoline emulation for the affected programs
80574 + yet still have the protection provided by the non-executable pages.
80575 +
80576 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80577 + your system will not even boot.
80578 +
80579 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80580 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80581 + for the affected files.
80582 +
80583 + NOTE: enabling this feature *may* open up a loophole in the
80584 + protection provided by non-executable pages that an attacker
80585 + could abuse. Therefore the best solution is to not have any
80586 + files on your system that would require this option. This can
80587 + be achieved by not using libc5 (which relies on the kernel
80588 + signal handler return code) and not using or rewriting programs
80589 + that make use of the nested function implementation of GCC.
80590 + Skilled users can just fix GCC itself so that it implements
80591 + nested function calls in a way that does not interfere with PaX.
80592 +
80593 +config PAX_EMUSIGRT
80594 + bool "Automatically emulate sigreturn trampolines"
80595 + depends on PAX_EMUTRAMP && PARISC
80596 + default y
80597 + help
80598 + Enabling this option will have the kernel automatically detect
80599 + and emulate signal return trampolines executing on the stack
80600 + that would otherwise lead to task termination.
80601 +
80602 + This solution is intended as a temporary one for users with
80603 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
80604 + Modula-3 runtime, etc) or executables linked to such, basically
80605 + everything that does not specify its own SA_RESTORER function in
80606 + normal executable memory like glibc 2.1+ does.
80607 +
80608 + On parisc you MUST enable this option, otherwise your system will
80609 + not even boot.
80610 +
80611 + NOTE: this feature cannot be disabled on a per executable basis
80612 + and since it *does* open up a loophole in the protection provided
80613 + by non-executable pages, the best solution is to not have any
80614 + files on your system that would require this option.
80615 +
80616 +config PAX_MPROTECT
80617 + bool "Restrict mprotect()"
80618 + default y if GRKERNSEC_CONFIG_AUTO
80619 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
80620 + help
80621 + Enabling this option will prevent programs from
80622 + - changing the executable status of memory pages that were
80623 + not originally created as executable,
80624 + - making read-only executable pages writable again,
80625 + - creating executable pages from anonymous memory,
80626 + - making read-only-after-relocations (RELRO) data pages writable again.
80627 +
80628 + You should say Y here to complete the protection provided by
80629 + the enforcement of non-executable pages.
80630 +
80631 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80632 + this feature on a per file basis.
80633 +
80634 +config PAX_MPROTECT_COMPAT
80635 + bool "Use legacy/compat protection demoting (read help)"
80636 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80637 + depends on PAX_MPROTECT
80638 + help
80639 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
80640 + by sending the proper error code to the application. For some broken
80641 + userland, this can cause problems with Python or other applications. The
80642 + current implementation however allows for applications like clamav to
80643 + detect if JIT compilation/execution is allowed and to fall back gracefully
80644 + to an interpreter-based mode if it does not. While we encourage everyone
80645 + to use the current implementation as-is and push upstream to fix broken
80646 + userland (note that the RWX logging option can assist with this), in some
80647 + environments this may not be possible. Having to disable MPROTECT
80648 + completely on certain binaries reduces the security benefit of PaX,
80649 + so this option is provided for those environments to revert to the old
80650 + behavior.
80651 +
80652 +config PAX_ELFRELOCS
80653 + bool "Allow ELF text relocations (read help)"
80654 + depends on PAX_MPROTECT
80655 + default n
80656 + help
80657 + Non-executable pages and mprotect() restrictions are effective
80658 + in preventing the introduction of new executable code into an
80659 + attacked task's address space. There remain only two venues
80660 + for this kind of attack: if the attacker can execute already
80661 + existing code in the attacked task then he can either have it
80662 + create and mmap() a file containing his code or have it mmap()
80663 + an already existing ELF library that does not have position
80664 + independent code in it and use mprotect() on it to make it
80665 + writable and copy his code there. While protecting against
80666 + the former approach is beyond PaX, the latter can be prevented
80667 + by having only PIC ELF libraries on one's system (which do not
80668 + need to relocate their code). If you are sure this is your case,
80669 + as is the case with all modern Linux distributions, then leave
80670 + this option disabled. You should say 'n' here.
80671 +
80672 +config PAX_ETEXECRELOCS
80673 + bool "Allow ELF ET_EXEC text relocations"
80674 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
80675 + select PAX_ELFRELOCS
80676 + default y
80677 + help
80678 + On some architectures there are incorrectly created applications
80679 + that require text relocations and would not work without enabling
80680 + this option. If you are an alpha, ia64 or parisc user, you should
80681 + enable this option and disable it once you have made sure that
80682 + none of your applications need it.
80683 +
80684 +config PAX_EMUPLT
80685 + bool "Automatically emulate ELF PLT"
80686 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
80687 + default y
80688 + help
80689 + Enabling this option will have the kernel automatically detect
80690 + and emulate the Procedure Linkage Table entries in ELF files.
80691 + On some architectures such entries are in writable memory, and
80692 + become non-executable leading to task termination. Therefore
80693 + it is mandatory that you enable this option on alpha, parisc,
80694 + sparc and sparc64, otherwise your system would not even boot.
80695 +
80696 + NOTE: this feature *does* open up a loophole in the protection
80697 + provided by the non-executable pages, therefore the proper
80698 + solution is to modify the toolchain to produce a PLT that does
80699 + not need to be writable.
80700 +
80701 +config PAX_DLRESOLVE
80702 + bool 'Emulate old glibc resolver stub'
80703 + depends on PAX_EMUPLT && SPARC
80704 + default n
80705 + help
80706 + This option is needed if userland has an old glibc (before 2.4)
80707 + that puts a 'save' instruction into the runtime generated resolver
80708 + stub that needs special emulation.
80709 +
80710 +config PAX_KERNEXEC
80711 + bool "Enforce non-executable kernel pages"
80712 + 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))
80713 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
80714 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
80715 + select PAX_KERNEXEC_PLUGIN if X86_64
80716 + help
80717 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
80718 + that is, enabling this option will make it harder to inject
80719 + and execute 'foreign' code in kernel memory itself.
80720 +
80721 +choice
80722 + prompt "Return Address Instrumentation Method"
80723 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
80724 + depends on PAX_KERNEXEC_PLUGIN
80725 + help
80726 + Select the method used to instrument function pointer dereferences.
80727 + Note that binary modules cannot be instrumented by this approach.
80728 +
80729 + Note that the implementation requires a gcc with plugin support,
80730 + i.e., gcc 4.5 or newer. You may need to install the supporting
80731 + headers explicitly in addition to the normal gcc package.
80732 +
80733 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
80734 + bool "bts"
80735 + help
80736 + This method is compatible with binary only modules but has
80737 + a higher runtime overhead.
80738 +
80739 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
80740 + bool "or"
80741 + depends on !PARAVIRT
80742 + help
80743 + This method is incompatible with binary only modules but has
80744 + a lower runtime overhead.
80745 +endchoice
80746 +
80747 +config PAX_KERNEXEC_PLUGIN_METHOD
80748 + string
80749 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
80750 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
80751 + default ""
80752 +
80753 +config PAX_KERNEXEC_MODULE_TEXT
80754 + int "Minimum amount of memory reserved for module code"
80755 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
80756 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
80757 + depends on PAX_KERNEXEC && X86_32 && MODULES
80758 + help
80759 + Due to implementation details the kernel must reserve a fixed
80760 + amount of memory for module code at compile time that cannot be
80761 + changed at runtime. Here you can specify the minimum amount
80762 + in MB that will be reserved. Due to the same implementation
80763 + details this size will always be rounded up to the next 2/4 MB
80764 + boundary (depends on PAE) so the actually available memory for
80765 + module code will usually be more than this minimum.
80766 +
80767 + The default 4 MB should be enough for most users but if you have
80768 + an excessive number of modules (e.g., most distribution configs
80769 + compile many drivers as modules) or use huge modules such as
80770 + nvidia's kernel driver, you will need to adjust this amount.
80771 + A good rule of thumb is to look at your currently loaded kernel
80772 + modules and add up their sizes.
80773 +
80774 +endmenu
80775 +
80776 +menu "Address Space Layout Randomization"
80777 + depends on PAX
80778 +
80779 +config PAX_ASLR
80780 + bool "Address Space Layout Randomization"
80781 + default y if GRKERNSEC_CONFIG_AUTO
80782 + help
80783 + Many if not most exploit techniques rely on the knowledge of
80784 + certain addresses in the attacked program. The following options
80785 + will allow the kernel to apply a certain amount of randomization
80786 + to specific parts of the program thereby forcing an attacker to
80787 + guess them in most cases. Any failed guess will most likely crash
80788 + the attacked program which allows the kernel to detect such attempts
80789 + and react on them. PaX itself provides no reaction mechanisms,
80790 + instead it is strongly encouraged that you make use of Nergal's
80791 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
80792 + (http://www.grsecurity.net/) built-in crash detection features or
80793 + develop one yourself.
80794 +
80795 + By saying Y here you can choose to randomize the following areas:
80796 + - top of the task's kernel stack
80797 + - top of the task's userland stack
80798 + - base address for mmap() requests that do not specify one
80799 + (this includes all libraries)
80800 + - base address of the main executable
80801 +
80802 + It is strongly recommended to say Y here as address space layout
80803 + randomization has negligible impact on performance yet it provides
80804 + a very effective protection.
80805 +
80806 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
80807 + this feature on a per file basis.
80808 +
80809 +config PAX_RANDKSTACK
80810 + bool "Randomize kernel stack base"
80811 + default y if GRKERNSEC_CONFIG_AUTO
80812 + depends on X86_TSC && X86
80813 + help
80814 + By saying Y here the kernel will randomize every task's kernel
80815 + stack on every system call. This will not only force an attacker
80816 + to guess it but also prevent him from making use of possible
80817 + leaked information about it.
80818 +
80819 + Since the kernel stack is a rather scarce resource, randomization
80820 + may cause unexpected stack overflows, therefore you should very
80821 + carefully test your system. Note that once enabled in the kernel
80822 + configuration, this feature cannot be disabled on a per file basis.
80823 +
80824 +config PAX_RANDUSTACK
80825 + bool "Randomize user stack base"
80826 + default y if GRKERNSEC_CONFIG_AUTO
80827 + depends on PAX_ASLR
80828 + help
80829 + By saying Y here the kernel will randomize every task's userland
80830 + stack. The randomization is done in two steps where the second
80831 + one may apply a big amount of shift to the top of the stack and
80832 + cause problems for programs that want to use lots of memory (more
80833 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
80834 + For this reason the second step can be controlled by 'chpax' or
80835 + 'paxctl' on a per file basis.
80836 +
80837 +config PAX_RANDMMAP
80838 + bool "Randomize mmap() base"
80839 + default y if GRKERNSEC_CONFIG_AUTO
80840 + depends on PAX_ASLR
80841 + help
80842 + By saying Y here the kernel will use a randomized base address for
80843 + mmap() requests that do not specify one themselves. As a result
80844 + all dynamically loaded libraries will appear at random addresses
80845 + and therefore be harder to exploit by a technique where an attacker
80846 + attempts to execute library code for his purposes (e.g. spawn a
80847 + shell from an exploited program that is running at an elevated
80848 + privilege level).
80849 +
80850 + Furthermore, if a program is relinked as a dynamic ELF file, its
80851 + base address will be randomized as well, completing the full
80852 + randomization of the address space layout. Attacking such programs
80853 + becomes a guess game. You can find an example of doing this at
80854 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
80855 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
80856 +
80857 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
80858 + feature on a per file basis.
80859 +
80860 +endmenu
80861 +
80862 +menu "Miscellaneous hardening features"
80863 +
80864 +config PAX_MEMORY_SANITIZE
80865 + bool "Sanitize all freed memory"
80866 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80867 + depends on !HIBERNATION
80868 + help
80869 + By saying Y here the kernel will erase memory pages as soon as they
80870 + are freed. This in turn reduces the lifetime of data stored in the
80871 + pages, making it less likely that sensitive information such as
80872 + passwords, cryptographic secrets, etc stay in memory for too long.
80873 +
80874 + This is especially useful for programs whose runtime is short, long
80875 + lived processes and the kernel itself benefit from this as long as
80876 + they operate on whole memory pages and ensure timely freeing of pages
80877 + that may hold sensitive information.
80878 +
80879 + The tradeoff is performance impact, on a single CPU system kernel
80880 + compilation sees a 3% slowdown, other systems and workloads may vary
80881 + and you are advised to test this feature on your expected workload
80882 + before deploying it.
80883 +
80884 + Note that this feature does not protect data stored in live pages,
80885 + e.g., process memory swapped to disk may stay there for a long time.
80886 +
80887 +config PAX_MEMORY_STACKLEAK
80888 + bool "Sanitize kernel stack"
80889 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
80890 + depends on X86
80891 + help
80892 + By saying Y here the kernel will erase the kernel stack before it
80893 + returns from a system call. This in turn reduces the information
80894 + that a kernel stack leak bug can reveal.
80895 +
80896 + Note that such a bug can still leak information that was put on
80897 + the stack by the current system call (the one eventually triggering
80898 + the bug) but traces of earlier system calls on the kernel stack
80899 + cannot leak anymore.
80900 +
80901 + The tradeoff is performance impact: on a single CPU system kernel
80902 + compilation sees a 1% slowdown, other systems and workloads may vary
80903 + and you are advised to test this feature on your expected workload
80904 + before deploying it.
80905 +
80906 + Note that the full feature requires a gcc with plugin support,
80907 + i.e., gcc 4.5 or newer. You may need to install the supporting
80908 + headers explicitly in addition to the normal gcc package. Using
80909 + older gcc versions means that functions with large enough stack
80910 + frames may leave uninitialized memory behind that may be exposed
80911 + to a later syscall leaking the stack.
80912 +
80913 +config PAX_MEMORY_UDEREF
80914 + bool "Prevent invalid userland pointer dereference"
80915 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
80916 + depends on X86 && !UML_X86 && !XEN
80917 + select PAX_PER_CPU_PGD if X86_64
80918 + help
80919 + By saying Y here the kernel will be prevented from dereferencing
80920 + userland pointers in contexts where the kernel expects only kernel
80921 + pointers. This is both a useful runtime debugging feature and a
80922 + security measure that prevents exploiting a class of kernel bugs.
80923 +
80924 + The tradeoff is that some virtualization solutions may experience
80925 + a huge slowdown and therefore you should not enable this feature
80926 + for kernels meant to run in such environments. Whether a given VM
80927 + solution is affected or not is best determined by simply trying it
80928 + out, the performance impact will be obvious right on boot as this
80929 + mechanism engages from very early on. A good rule of thumb is that
80930 + VMs running on CPUs without hardware virtualization support (i.e.,
80931 + the majority of IA-32 CPUs) will likely experience the slowdown.
80932 +
80933 +config PAX_REFCOUNT
80934 + bool "Prevent various kernel object reference counter overflows"
80935 + default y if GRKERNSEC_CONFIG_AUTO
80936 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
80937 + help
80938 + By saying Y here the kernel will detect and prevent overflowing
80939 + various (but not all) kinds of object reference counters. Such
80940 + overflows can normally occur due to bugs only and are often, if
80941 + not always, exploitable.
80942 +
80943 + The tradeoff is that data structures protected by an overflowed
80944 + refcount will never be freed and therefore will leak memory. Note
80945 + that this leak also happens even without this protection but in
80946 + that case the overflow can eventually trigger the freeing of the
80947 + data structure while it is still being used elsewhere, resulting
80948 + in the exploitable situation that this feature prevents.
80949 +
80950 + Since this has a negligible performance impact, you should enable
80951 + this feature.
80952 +
80953 +config PAX_USERCOPY
80954 + bool "Harden heap object copies between kernel and userland"
80955 + default y if GRKERNSEC_CONFIG_AUTO
80956 + depends on X86 || PPC || SPARC || ARM
80957 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
80958 + select PAX_USERCOPY_SLABS
80959 + help
80960 + By saying Y here the kernel will enforce the size of heap objects
80961 + when they are copied in either direction between the kernel and
80962 + userland, even if only a part of the heap object is copied.
80963 +
80964 + Specifically, this checking prevents information leaking from the
80965 + kernel heap during kernel to userland copies (if the kernel heap
80966 + object is otherwise fully initialized) and prevents kernel heap
80967 + overflows during userland to kernel copies.
80968 +
80969 + Note that the current implementation provides the strictest bounds
80970 + checks for the SLUB allocator.
80971 +
80972 + Enabling this option also enables per-slab cache protection against
80973 + data in a given cache being copied into/out of via userland
80974 + accessors. Though the whitelist of regions will be reduced over
80975 + time, it notably protects important data structures like task structs.
80976 +
80977 + If frame pointers are enabled on x86, this option will also restrict
80978 + copies into and out of the kernel stack to local variables within a
80979 + single frame.
80980 +
80981 + Since this has a negligible performance impact, you should enable
80982 + this feature.
80983 +
80984 +config PAX_SIZE_OVERFLOW
80985 + bool "Prevent various integer overflows in function size parameters"
80986 + default y if GRKERNSEC_CONFIG_AUTO
80987 + depends on X86
80988 + help
80989 + By saying Y here the kernel recomputes expressions of function
80990 + arguments marked by a size_overflow attribute with double integer
80991 + precision (DImode/TImode for 32/64 bit integer types).
80992 +
80993 + The recomputed argument is checked against TYPE_MAX and an event
80994 + is logged on overflow and the triggering process is killed.
80995 +
80996 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
80997 +
80998 + Note that the implementation requires a gcc with plugin support,
80999 + i.e., gcc 4.5 or newer. You may need to install the supporting
81000 + headers explicitly in addition to the normal gcc package.
81001 +
81002 +config PAX_LATENT_ENTROPY
81003 + bool "Generate some entropy during boot"
81004 + default y if GRKERNSEC_CONFIG_AUTO
81005 + help
81006 + By saying Y here the kernel will instrument early boot code to
81007 + extract some entropy from both original and artificially created
81008 + program state. This will help especially embedded systems where
81009 + there is little 'natural' source of entropy normally. The cost
81010 + is some slowdown of the boot process.
81011 +
81012 + Note that the implementation requires a gcc with plugin support,
81013 + i.e., gcc 4.5 or newer. You may need to install the supporting
81014 + headers explicitly in addition to the normal gcc package.
81015 +
81016 + Note that entropy extracted this way is not cryptographically
81017 + secure!
81018 +
81019 +endmenu
81020 +
81021 +endmenu
81022 +
81023 +source grsecurity/Kconfig
81024 +
81025 +endmenu
81026 +
81027 +endmenu
81028 +
81029 source security/keys/Kconfig
81030
81031 config SECURITY_DMESG_RESTRICT
81032 @@ -103,7 +993,7 @@ config INTEL_TXT
81033 config LSM_MMAP_MIN_ADDR
81034 int "Low address space for LSM to protect from user allocation"
81035 depends on SECURITY && SECURITY_SELINUX
81036 - default 32768 if ARM
81037 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81038 default 65536
81039 help
81040 This is the portion of low virtual memory which should be protected
81041 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81042 index 8ea39aa..8569ac5 100644
81043 --- a/security/apparmor/lsm.c
81044 +++ b/security/apparmor/lsm.c
81045 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81046 return error;
81047 }
81048
81049 -static struct security_operations apparmor_ops = {
81050 +static struct security_operations apparmor_ops __read_only = {
81051 .name = "apparmor",
81052
81053 .ptrace_access_check = apparmor_ptrace_access_check,
81054 diff --git a/security/commoncap.c b/security/commoncap.c
81055 index 6dbae46..d5611fd 100644
81056 --- a/security/commoncap.c
81057 +++ b/security/commoncap.c
81058 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81059 return 0;
81060 }
81061
81062 +/* returns:
81063 + 1 for suid privilege
81064 + 2 for sgid privilege
81065 + 3 for fscap privilege
81066 +*/
81067 +int is_privileged_binary(const struct dentry *dentry)
81068 +{
81069 + struct cpu_vfs_cap_data capdata;
81070 + struct inode *inode = dentry->d_inode;
81071 +
81072 + if (!inode || S_ISDIR(inode->i_mode))
81073 + return 0;
81074 +
81075 + if (inode->i_mode & S_ISUID)
81076 + return 1;
81077 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81078 + return 2;
81079 +
81080 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81081 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81082 + return 3;
81083 + }
81084 +
81085 + return 0;
81086 +}
81087 +
81088 /*
81089 * Attempt to get the on-exec apply capability sets for an executable file from
81090 * its xattrs and, if present, apply them to the proposed credentials being
81091 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81092 const struct cred *cred = current_cred();
81093 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81094
81095 + if (gr_acl_enable_at_secure())
81096 + return 1;
81097 +
81098 if (!uid_eq(cred->uid, root_uid)) {
81099 if (bprm->cap_effective)
81100 return 1;
81101 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81102 index e7c99fd..5b2fa24 100644
81103 --- a/security/integrity/ima/ima.h
81104 +++ b/security/integrity/ima/ima.h
81105 @@ -95,8 +95,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81106 extern spinlock_t ima_queue_lock;
81107
81108 struct ima_h_table {
81109 - atomic_long_t len; /* number of stored measurements in the list */
81110 - atomic_long_t violations;
81111 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81112 + atomic_long_unchecked_t violations;
81113 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81114 };
81115 extern struct ima_h_table ima_htable;
81116 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81117 index 032ff03..c428a74 100644
81118 --- a/security/integrity/ima/ima_api.c
81119 +++ b/security/integrity/ima/ima_api.c
81120 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81121 int result;
81122
81123 /* can overflow, only indicator */
81124 - atomic_long_inc(&ima_htable.violations);
81125 + atomic_long_inc_unchecked(&ima_htable.violations);
81126
81127 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81128 if (!entry) {
81129 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81130 index 38477c9..87a60c7 100644
81131 --- a/security/integrity/ima/ima_fs.c
81132 +++ b/security/integrity/ima/ima_fs.c
81133 @@ -28,12 +28,12 @@
81134 static int valid_policy = 1;
81135 #define TMPBUFLEN 12
81136 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81137 - loff_t *ppos, atomic_long_t *val)
81138 + loff_t *ppos, atomic_long_unchecked_t *val)
81139 {
81140 char tmpbuf[TMPBUFLEN];
81141 ssize_t len;
81142
81143 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81144 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81145 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81146 }
81147
81148 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81149 index 55a6271..ad829c3 100644
81150 --- a/security/integrity/ima/ima_queue.c
81151 +++ b/security/integrity/ima/ima_queue.c
81152 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81153 INIT_LIST_HEAD(&qe->later);
81154 list_add_tail_rcu(&qe->later, &ima_measurements);
81155
81156 - atomic_long_inc(&ima_htable.len);
81157 + atomic_long_inc_unchecked(&ima_htable.len);
81158 key = ima_hash_key(entry->digest);
81159 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81160 return 0;
81161 diff --git a/security/keys/compat.c b/security/keys/compat.c
81162 index 1c26176..64a1ba2 100644
81163 --- a/security/keys/compat.c
81164 +++ b/security/keys/compat.c
81165 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
81166 if (ret == 0)
81167 goto no_payload_free;
81168
81169 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81170 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81171
81172 if (iov != iovstack)
81173 kfree(iov);
81174 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81175 index 3364fbf..1f10f31 100644
81176 --- a/security/keys/keyctl.c
81177 +++ b/security/keys/keyctl.c
81178 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81179 /*
81180 * Copy the iovec data from userspace
81181 */
81182 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81183 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81184 unsigned ioc)
81185 {
81186 for (; ioc > 0; ioc--) {
81187 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81188 * If successful, 0 will be returned.
81189 */
81190 long keyctl_instantiate_key_common(key_serial_t id,
81191 - const struct iovec *payload_iov,
81192 + const struct iovec __user *payload_iov,
81193 unsigned ioc,
81194 size_t plen,
81195 key_serial_t ringid)
81196 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81197 [0].iov_len = plen
81198 };
81199
81200 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81201 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81202 }
81203
81204 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81205 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81206 if (ret == 0)
81207 goto no_payload_free;
81208
81209 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81210 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81211
81212 if (iov != iovstack)
81213 kfree(iov);
81214 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81215 index 81e7852..2b2ecc3 100644
81216 --- a/security/keys/keyring.c
81217 +++ b/security/keys/keyring.c
81218 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81219 ret = -EFAULT;
81220
81221 for (loop = 0; loop < klist->nkeys; loop++) {
81222 + key_serial_t serial;
81223 key = rcu_deref_link_locked(klist, loop,
81224 keyring);
81225 + serial = key->serial;
81226
81227 tmp = sizeof(key_serial_t);
81228 if (tmp > buflen)
81229 tmp = buflen;
81230
81231 - if (copy_to_user(buffer,
81232 - &key->serial,
81233 - tmp) != 0)
81234 + if (copy_to_user(buffer, &serial, tmp))
81235 goto error;
81236
81237 buflen -= tmp;
81238 diff --git a/security/min_addr.c b/security/min_addr.c
81239 index f728728..6457a0c 100644
81240 --- a/security/min_addr.c
81241 +++ b/security/min_addr.c
81242 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81243 */
81244 static void update_mmap_min_addr(void)
81245 {
81246 +#ifndef SPARC
81247 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81248 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81249 mmap_min_addr = dac_mmap_min_addr;
81250 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81251 #else
81252 mmap_min_addr = dac_mmap_min_addr;
81253 #endif
81254 +#endif
81255 }
81256
81257 /*
81258 diff --git a/security/security.c b/security/security.c
81259 index 860aeb3..45765c0 100644
81260 --- a/security/security.c
81261 +++ b/security/security.c
81262 @@ -20,6 +20,7 @@
81263 #include <linux/ima.h>
81264 #include <linux/evm.h>
81265 #include <linux/fsnotify.h>
81266 +#include <linux/mm.h>
81267 #include <linux/mman.h>
81268 #include <linux/mount.h>
81269 #include <linux/personality.h>
81270 @@ -32,8 +33,8 @@
81271 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81272 CONFIG_DEFAULT_SECURITY;
81273
81274 -static struct security_operations *security_ops;
81275 -static struct security_operations default_security_ops = {
81276 +static struct security_operations *security_ops __read_only;
81277 +static struct security_operations default_security_ops __read_only = {
81278 .name = "default",
81279 };
81280
81281 @@ -74,7 +75,9 @@ int __init security_init(void)
81282
81283 void reset_security_ops(void)
81284 {
81285 + pax_open_kernel();
81286 security_ops = &default_security_ops;
81287 + pax_close_kernel();
81288 }
81289
81290 /* Save user chosen LSM */
81291 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81292 index 6c77f63..7496c76 100644
81293 --- a/security/selinux/hooks.c
81294 +++ b/security/selinux/hooks.c
81295 @@ -95,8 +95,6 @@
81296
81297 #define NUM_SEL_MNT_OPTS 5
81298
81299 -extern struct security_operations *security_ops;
81300 -
81301 /* SECMARK reference count */
81302 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81303
81304 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81305
81306 #endif
81307
81308 -static struct security_operations selinux_ops = {
81309 +static struct security_operations selinux_ops __read_only = {
81310 .name = "selinux",
81311
81312 .ptrace_access_check = selinux_ptrace_access_check,
81313 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81314 index 65f67cb..3f141ef 100644
81315 --- a/security/selinux/include/xfrm.h
81316 +++ b/security/selinux/include/xfrm.h
81317 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81318
81319 static inline void selinux_xfrm_notify_policyload(void)
81320 {
81321 - atomic_inc(&flow_cache_genid);
81322 + atomic_inc_unchecked(&flow_cache_genid);
81323 rt_genid_bump(&init_net);
81324 }
81325 #else
81326 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81327 index 8221514..5c4775f 100644
81328 --- a/security/smack/smack_lsm.c
81329 +++ b/security/smack/smack_lsm.c
81330 @@ -3429,7 +3429,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81331 return 0;
81332 }
81333
81334 -struct security_operations smack_ops = {
81335 +struct security_operations smack_ops __read_only = {
81336 .name = "smack",
81337
81338 .ptrace_access_check = smack_ptrace_access_check,
81339 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81340 index c2d04a5..e6a1aeb 100644
81341 --- a/security/tomoyo/tomoyo.c
81342 +++ b/security/tomoyo/tomoyo.c
81343 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81344 * tomoyo_security_ops is a "struct security_operations" which is used for
81345 * registering TOMOYO.
81346 */
81347 -static struct security_operations tomoyo_security_ops = {
81348 +static struct security_operations tomoyo_security_ops __read_only = {
81349 .name = "tomoyo",
81350 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81351 .cred_prepare = tomoyo_cred_prepare,
81352 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81353 index 51d6709..1f3dbe2 100644
81354 --- a/security/yama/Kconfig
81355 +++ b/security/yama/Kconfig
81356 @@ -1,6 +1,6 @@
81357 config SECURITY_YAMA
81358 bool "Yama support"
81359 - depends on SECURITY
81360 + depends on SECURITY && !GRKERNSEC
81361 select SECURITYFS
81362 select SECURITY_PATH
81363 default n
81364 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81365 index 4cedc69..e59d8a3 100644
81366 --- a/sound/aoa/codecs/onyx.c
81367 +++ b/sound/aoa/codecs/onyx.c
81368 @@ -54,7 +54,7 @@ struct onyx {
81369 spdif_locked:1,
81370 analog_locked:1,
81371 original_mute:2;
81372 - int open_count;
81373 + local_t open_count;
81374 struct codec_info *codec_info;
81375
81376 /* mutex serializes concurrent access to the device
81377 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81378 struct onyx *onyx = cii->codec_data;
81379
81380 mutex_lock(&onyx->mutex);
81381 - onyx->open_count++;
81382 + local_inc(&onyx->open_count);
81383 mutex_unlock(&onyx->mutex);
81384
81385 return 0;
81386 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81387 struct onyx *onyx = cii->codec_data;
81388
81389 mutex_lock(&onyx->mutex);
81390 - onyx->open_count--;
81391 - if (!onyx->open_count)
81392 + if (local_dec_and_test(&onyx->open_count))
81393 onyx->spdif_locked = onyx->analog_locked = 0;
81394 mutex_unlock(&onyx->mutex);
81395
81396 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81397 index ffd2025..df062c9 100644
81398 --- a/sound/aoa/codecs/onyx.h
81399 +++ b/sound/aoa/codecs/onyx.h
81400 @@ -11,6 +11,7 @@
81401 #include <linux/i2c.h>
81402 #include <asm/pmac_low_i2c.h>
81403 #include <asm/prom.h>
81404 +#include <asm/local.h>
81405
81406 /* PCM3052 register definitions */
81407
81408 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81409 index 08fde00..0bf641a 100644
81410 --- a/sound/core/oss/pcm_oss.c
81411 +++ b/sound/core/oss/pcm_oss.c
81412 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81413 if (in_kernel) {
81414 mm_segment_t fs;
81415 fs = snd_enter_user();
81416 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81417 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81418 snd_leave_user(fs);
81419 } else {
81420 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81421 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81422 }
81423 if (ret != -EPIPE && ret != -ESTRPIPE)
81424 break;
81425 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81426 if (in_kernel) {
81427 mm_segment_t fs;
81428 fs = snd_enter_user();
81429 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81430 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81431 snd_leave_user(fs);
81432 } else {
81433 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81434 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81435 }
81436 if (ret == -EPIPE) {
81437 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81438 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81439 struct snd_pcm_plugin_channel *channels;
81440 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81441 if (!in_kernel) {
81442 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81443 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81444 return -EFAULT;
81445 buf = runtime->oss.buffer;
81446 }
81447 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81448 }
81449 } else {
81450 tmp = snd_pcm_oss_write2(substream,
81451 - (const char __force *)buf,
81452 + (const char __force_kernel *)buf,
81453 runtime->oss.period_bytes, 0);
81454 if (tmp <= 0)
81455 goto err;
81456 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81457 struct snd_pcm_runtime *runtime = substream->runtime;
81458 snd_pcm_sframes_t frames, frames1;
81459 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81460 - char __user *final_dst = (char __force __user *)buf;
81461 + char __user *final_dst = (char __force_user *)buf;
81462 if (runtime->oss.plugin_first) {
81463 struct snd_pcm_plugin_channel *channels;
81464 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81465 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81466 xfer += tmp;
81467 runtime->oss.buffer_used -= tmp;
81468 } else {
81469 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81470 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81471 runtime->oss.period_bytes, 0);
81472 if (tmp <= 0)
81473 goto err;
81474 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81475 size1);
81476 size1 /= runtime->channels; /* frames */
81477 fs = snd_enter_user();
81478 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81479 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81480 snd_leave_user(fs);
81481 }
81482 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81483 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81484 index 91cdf94..4085161 100644
81485 --- a/sound/core/pcm_compat.c
81486 +++ b/sound/core/pcm_compat.c
81487 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81488 int err;
81489
81490 fs = snd_enter_user();
81491 - err = snd_pcm_delay(substream, &delay);
81492 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81493 snd_leave_user(fs);
81494 if (err < 0)
81495 return err;
81496 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81497 index 53b5ada..2db94c8 100644
81498 --- a/sound/core/pcm_native.c
81499 +++ b/sound/core/pcm_native.c
81500 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81501 switch (substream->stream) {
81502 case SNDRV_PCM_STREAM_PLAYBACK:
81503 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81504 - (void __user *)arg);
81505 + (void __force_user *)arg);
81506 break;
81507 case SNDRV_PCM_STREAM_CAPTURE:
81508 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81509 - (void __user *)arg);
81510 + (void __force_user *)arg);
81511 break;
81512 default:
81513 result = -EINVAL;
81514 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81515 index 5cf8d65..912a79c 100644
81516 --- a/sound/core/seq/seq_device.c
81517 +++ b/sound/core/seq/seq_device.c
81518 @@ -64,7 +64,7 @@ struct ops_list {
81519 int argsize; /* argument size */
81520
81521 /* operators */
81522 - struct snd_seq_dev_ops ops;
81523 + struct snd_seq_dev_ops *ops;
81524
81525 /* registred devices */
81526 struct list_head dev_list; /* list of devices */
81527 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81528
81529 mutex_lock(&ops->reg_mutex);
81530 /* copy driver operators */
81531 - ops->ops = *entry;
81532 + ops->ops = entry;
81533 ops->driver |= DRIVER_LOADED;
81534 ops->argsize = argsize;
81535
81536 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81537 dev->name, ops->id, ops->argsize, dev->argsize);
81538 return -EINVAL;
81539 }
81540 - if (ops->ops.init_device(dev) >= 0) {
81541 + if (ops->ops->init_device(dev) >= 0) {
81542 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81543 ops->num_init_devices++;
81544 } else {
81545 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81546 dev->name, ops->id, ops->argsize, dev->argsize);
81547 return -EINVAL;
81548 }
81549 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81550 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81551 dev->status = SNDRV_SEQ_DEVICE_FREE;
81552 dev->driver_data = NULL;
81553 ops->num_init_devices--;
81554 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81555 index 2d5514b..3afae9c 100644
81556 --- a/sound/drivers/mts64.c
81557 +++ b/sound/drivers/mts64.c
81558 @@ -29,6 +29,7 @@
81559 #include <sound/initval.h>
81560 #include <sound/rawmidi.h>
81561 #include <sound/control.h>
81562 +#include <asm/local.h>
81563
81564 #define CARD_NAME "Miditerminal 4140"
81565 #define DRIVER_NAME "MTS64"
81566 @@ -67,7 +68,7 @@ struct mts64 {
81567 struct pardevice *pardev;
81568 int pardev_claimed;
81569
81570 - int open_count;
81571 + local_t open_count;
81572 int current_midi_output_port;
81573 int current_midi_input_port;
81574 u8 mode[MTS64_NUM_INPUT_PORTS];
81575 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81576 {
81577 struct mts64 *mts = substream->rmidi->private_data;
81578
81579 - if (mts->open_count == 0) {
81580 + if (local_read(&mts->open_count) == 0) {
81581 /* We don't need a spinlock here, because this is just called
81582 if the device has not been opened before.
81583 So there aren't any IRQs from the device */
81584 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81585
81586 msleep(50);
81587 }
81588 - ++(mts->open_count);
81589 + local_inc(&mts->open_count);
81590
81591 return 0;
81592 }
81593 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81594 struct mts64 *mts = substream->rmidi->private_data;
81595 unsigned long flags;
81596
81597 - --(mts->open_count);
81598 - if (mts->open_count == 0) {
81599 + if (local_dec_return(&mts->open_count) == 0) {
81600 /* We need the spinlock_irqsave here because we can still
81601 have IRQs at this point */
81602 spin_lock_irqsave(&mts->lock, flags);
81603 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
81604
81605 msleep(500);
81606
81607 - } else if (mts->open_count < 0)
81608 - mts->open_count = 0;
81609 + } else if (local_read(&mts->open_count) < 0)
81610 + local_set(&mts->open_count, 0);
81611
81612 return 0;
81613 }
81614 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
81615 index b953fb4..1999c01 100644
81616 --- a/sound/drivers/opl4/opl4_lib.c
81617 +++ b/sound/drivers/opl4/opl4_lib.c
81618 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
81619 MODULE_DESCRIPTION("OPL4 driver");
81620 MODULE_LICENSE("GPL");
81621
81622 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
81623 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
81624 {
81625 int timeout = 10;
81626 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
81627 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
81628 index 8364855..59f2e2b 100644
81629 --- a/sound/drivers/portman2x4.c
81630 +++ b/sound/drivers/portman2x4.c
81631 @@ -48,6 +48,7 @@
81632 #include <sound/initval.h>
81633 #include <sound/rawmidi.h>
81634 #include <sound/control.h>
81635 +#include <asm/local.h>
81636
81637 #define CARD_NAME "Portman 2x4"
81638 #define DRIVER_NAME "portman"
81639 @@ -85,7 +86,7 @@ struct portman {
81640 struct pardevice *pardev;
81641 int pardev_claimed;
81642
81643 - int open_count;
81644 + local_t open_count;
81645 int mode[PORTMAN_NUM_INPUT_PORTS];
81646 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
81647 };
81648 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
81649 index ea995af..f1bfa37 100644
81650 --- a/sound/firewire/amdtp.c
81651 +++ b/sound/firewire/amdtp.c
81652 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
81653 ptr = s->pcm_buffer_pointer + data_blocks;
81654 if (ptr >= pcm->runtime->buffer_size)
81655 ptr -= pcm->runtime->buffer_size;
81656 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
81657 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
81658
81659 s->pcm_period_pointer += data_blocks;
81660 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
81661 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
81662 */
81663 void amdtp_out_stream_update(struct amdtp_out_stream *s)
81664 {
81665 - ACCESS_ONCE(s->source_node_id_field) =
81666 + ACCESS_ONCE_RW(s->source_node_id_field) =
81667 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
81668 }
81669 EXPORT_SYMBOL(amdtp_out_stream_update);
81670 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
81671 index b680c5e..061b7a0 100644
81672 --- a/sound/firewire/amdtp.h
81673 +++ b/sound/firewire/amdtp.h
81674 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
81675 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
81676 struct snd_pcm_substream *pcm)
81677 {
81678 - ACCESS_ONCE(s->pcm) = pcm;
81679 + ACCESS_ONCE_RW(s->pcm) = pcm;
81680 }
81681
81682 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
81683 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
81684 index d428ffe..751ef78 100644
81685 --- a/sound/firewire/isight.c
81686 +++ b/sound/firewire/isight.c
81687 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
81688 ptr += count;
81689 if (ptr >= runtime->buffer_size)
81690 ptr -= runtime->buffer_size;
81691 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
81692 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
81693
81694 isight->period_counter += count;
81695 if (isight->period_counter >= runtime->period_size) {
81696 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
81697 if (err < 0)
81698 return err;
81699
81700 - ACCESS_ONCE(isight->pcm_active) = true;
81701 + ACCESS_ONCE_RW(isight->pcm_active) = true;
81702
81703 return 0;
81704 }
81705 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
81706 {
81707 struct isight *isight = substream->private_data;
81708
81709 - ACCESS_ONCE(isight->pcm_active) = false;
81710 + ACCESS_ONCE_RW(isight->pcm_active) = false;
81711
81712 mutex_lock(&isight->mutex);
81713 isight_stop_streaming(isight);
81714 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
81715
81716 switch (cmd) {
81717 case SNDRV_PCM_TRIGGER_START:
81718 - ACCESS_ONCE(isight->pcm_running) = true;
81719 + ACCESS_ONCE_RW(isight->pcm_running) = true;
81720 break;
81721 case SNDRV_PCM_TRIGGER_STOP:
81722 - ACCESS_ONCE(isight->pcm_running) = false;
81723 + ACCESS_ONCE_RW(isight->pcm_running) = false;
81724 break;
81725 default:
81726 return -EINVAL;
81727 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
81728 index 7bd5e33..1fcab12 100644
81729 --- a/sound/isa/cmi8330.c
81730 +++ b/sound/isa/cmi8330.c
81731 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
81732
81733 struct snd_pcm *pcm;
81734 struct snd_cmi8330_stream {
81735 - struct snd_pcm_ops ops;
81736 + snd_pcm_ops_no_const ops;
81737 snd_pcm_open_callback_t open;
81738 void *private_data; /* sb or wss */
81739 } streams[2];
81740 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
81741 index b2b3c01..e1c1e1f 100644
81742 --- a/sound/oss/sb_audio.c
81743 +++ b/sound/oss/sb_audio.c
81744 @@ -903,7 +903,7 @@ sb16_copy_from_user(int dev,
81745 buf16 = (signed short *)(localbuf + localoffs);
81746 while (c)
81747 {
81748 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81749 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
81750 if (copy_from_user(lbuf8,
81751 userbuf+useroffs + p,
81752 locallen))
81753 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
81754 index 7d8803a..559f8d0 100644
81755 --- a/sound/oss/swarm_cs4297a.c
81756 +++ b/sound/oss/swarm_cs4297a.c
81757 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
81758 {
81759 struct cs4297a_state *s;
81760 u32 pwr, id;
81761 - mm_segment_t fs;
81762 int rval;
81763 #ifndef CONFIG_BCM_CS4297A_CSWARM
81764 u64 cfg;
81765 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
81766 if (!rval) {
81767 char *sb1250_duart_present;
81768
81769 +#if 0
81770 + mm_segment_t fs;
81771 fs = get_fs();
81772 set_fs(KERNEL_DS);
81773 -#if 0
81774 val = SOUND_MASK_LINE;
81775 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
81776 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
81777 val = initvol[i].vol;
81778 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
81779 }
81780 + set_fs(fs);
81781 // cs4297a_write_ac97(s, 0x18, 0x0808);
81782 #else
81783 // cs4297a_write_ac97(s, 0x5e, 0x180);
81784 cs4297a_write_ac97(s, 0x02, 0x0808);
81785 cs4297a_write_ac97(s, 0x18, 0x0808);
81786 #endif
81787 - set_fs(fs);
81788
81789 list_add(&s->list, &cs4297a_devs);
81790
81791 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
81792 index e5a7e19..4049063 100644
81793 --- a/sound/pci/hda/hda_codec.h
81794 +++ b/sound/pci/hda/hda_codec.h
81795 @@ -614,7 +614,7 @@ struct hda_bus_ops {
81796 /* notify power-up/down from codec to controller */
81797 void (*pm_notify)(struct hda_bus *bus);
81798 #endif
81799 -};
81800 +} __no_const;
81801
81802 /* template to pass to the bus constructor */
81803 struct hda_bus_template {
81804 @@ -714,6 +714,7 @@ struct hda_codec_ops {
81805 #endif
81806 void (*reboot_notify)(struct hda_codec *codec);
81807 };
81808 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
81809
81810 /* record for amp information cache */
81811 struct hda_cache_head {
81812 @@ -744,7 +745,7 @@ struct hda_pcm_ops {
81813 struct snd_pcm_substream *substream);
81814 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
81815 struct snd_pcm_substream *substream);
81816 -};
81817 +} __no_const;
81818
81819 /* PCM information for each substream */
81820 struct hda_pcm_stream {
81821 @@ -802,7 +803,7 @@ struct hda_codec {
81822 const char *modelname; /* model name for preset */
81823
81824 /* set by patch */
81825 - struct hda_codec_ops patch_ops;
81826 + hda_codec_ops_no_const patch_ops;
81827
81828 /* PCM to create, set by patch_ops.build_pcms callback */
81829 unsigned int num_pcms;
81830 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
81831 index 0da778a..bc38b84 100644
81832 --- a/sound/pci/ice1712/ice1712.h
81833 +++ b/sound/pci/ice1712/ice1712.h
81834 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
81835 unsigned int mask_flags; /* total mask bits */
81836 struct snd_akm4xxx_ops {
81837 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
81838 - } ops;
81839 + } __no_const ops;
81840 };
81841
81842 struct snd_ice1712_spdif {
81843 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
81844 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81845 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81846 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
81847 - } ops;
81848 + } __no_const ops;
81849 };
81850
81851
81852 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
81853 index bddc405..2c0733c 100644
81854 --- a/sound/pci/ymfpci/ymfpci.h
81855 +++ b/sound/pci/ymfpci/ymfpci.h
81856 @@ -358,7 +358,7 @@ struct snd_ymfpci {
81857 spinlock_t reg_lock;
81858 spinlock_t voice_lock;
81859 wait_queue_head_t interrupt_sleep;
81860 - atomic_t interrupt_sleep_count;
81861 + atomic_unchecked_t interrupt_sleep_count;
81862 struct snd_info_entry *proc_entry;
81863 const struct firmware *dsp_microcode;
81864 const struct firmware *controller_microcode;
81865 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
81866 index 62b2363..ee77972 100644
81867 --- a/sound/pci/ymfpci/ymfpci_main.c
81868 +++ b/sound/pci/ymfpci/ymfpci_main.c
81869 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
81870 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
81871 break;
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 __end:
81880 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
81881 continue;
81882 init_waitqueue_entry(&wait, current);
81883 add_wait_queue(&chip->interrupt_sleep, &wait);
81884 - atomic_inc(&chip->interrupt_sleep_count);
81885 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
81886 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
81887 remove_wait_queue(&chip->interrupt_sleep, &wait);
81888 }
81889 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
81890 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
81891 spin_unlock(&chip->reg_lock);
81892
81893 - if (atomic_read(&chip->interrupt_sleep_count)) {
81894 - atomic_set(&chip->interrupt_sleep_count, 0);
81895 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
81896 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81897 wake_up(&chip->interrupt_sleep);
81898 }
81899 }
81900 @@ -2402,7 +2402,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
81901 spin_lock_init(&chip->reg_lock);
81902 spin_lock_init(&chip->voice_lock);
81903 init_waitqueue_head(&chip->interrupt_sleep);
81904 - atomic_set(&chip->interrupt_sleep_count, 0);
81905 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
81906 chip->card = card;
81907 chip->pci = pci;
81908 chip->irq = -1;
81909 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
81910 new file mode 100644
81911 index 0000000..50f2f2f
81912 --- /dev/null
81913 +++ b/tools/gcc/.gitignore
81914 @@ -0,0 +1 @@
81915 +size_overflow_hash.h
81916 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
81917 new file mode 100644
81918 index 0000000..1d09b7e
81919 --- /dev/null
81920 +++ b/tools/gcc/Makefile
81921 @@ -0,0 +1,43 @@
81922 +#CC := gcc
81923 +#PLUGIN_SOURCE_FILES := pax_plugin.c
81924 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
81925 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
81926 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
81927 +
81928 +ifeq ($(PLUGINCC),$(HOSTCC))
81929 +HOSTLIBS := hostlibs
81930 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
81931 +else
81932 +HOSTLIBS := hostcxxlibs
81933 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
81934 +endif
81935 +
81936 +$(HOSTLIBS)-y := constify_plugin.so
81937 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
81938 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
81939 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
81940 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
81941 +$(HOSTLIBS)-y += colorize_plugin.so
81942 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
81943 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
81944 +
81945 +always := $($(HOSTLIBS)-y)
81946 +
81947 +constify_plugin-objs := constify_plugin.o
81948 +stackleak_plugin-objs := stackleak_plugin.o
81949 +kallocstat_plugin-objs := kallocstat_plugin.o
81950 +kernexec_plugin-objs := kernexec_plugin.o
81951 +checker_plugin-objs := checker_plugin.o
81952 +colorize_plugin-objs := colorize_plugin.o
81953 +size_overflow_plugin-objs := size_overflow_plugin.o
81954 +latent_entropy_plugin-objs := latent_entropy_plugin.o
81955 +
81956 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
81957 +
81958 +quiet_cmd_build_size_overflow_hash = GENHASH $@
81959 + cmd_build_size_overflow_hash = \
81960 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
81961 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
81962 + $(call if_changed,build_size_overflow_hash)
81963 +
81964 +targets += size_overflow_hash.h
81965 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
81966 new file mode 100644
81967 index 0000000..d41b5af
81968 --- /dev/null
81969 +++ b/tools/gcc/checker_plugin.c
81970 @@ -0,0 +1,171 @@
81971 +/*
81972 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
81973 + * Licensed under the GPL v2
81974 + *
81975 + * Note: the choice of the license means that the compilation process is
81976 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
81977 + * but for the kernel it doesn't matter since it doesn't link against
81978 + * any of the gcc libraries
81979 + *
81980 + * gcc plugin to implement various sparse (source code checker) features
81981 + *
81982 + * TODO:
81983 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
81984 + *
81985 + * BUGS:
81986 + * - none known
81987 + */
81988 +#include "gcc-plugin.h"
81989 +#include "config.h"
81990 +#include "system.h"
81991 +#include "coretypes.h"
81992 +#include "tree.h"
81993 +#include "tree-pass.h"
81994 +#include "flags.h"
81995 +#include "intl.h"
81996 +#include "toplev.h"
81997 +#include "plugin.h"
81998 +//#include "expr.h" where are you...
81999 +#include "diagnostic.h"
82000 +#include "plugin-version.h"
82001 +#include "tm.h"
82002 +#include "function.h"
82003 +#include "basic-block.h"
82004 +#include "gimple.h"
82005 +#include "rtl.h"
82006 +#include "emit-rtl.h"
82007 +#include "tree-flow.h"
82008 +#include "target.h"
82009 +
82010 +extern void c_register_addr_space (const char *str, addr_space_t as);
82011 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82012 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82013 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82014 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82015 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82016 +
82017 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82018 +extern rtx emit_move_insn(rtx x, rtx y);
82019 +
82020 +int plugin_is_GPL_compatible;
82021 +
82022 +static struct plugin_info checker_plugin_info = {
82023 + .version = "201111150100",
82024 +};
82025 +
82026 +#define ADDR_SPACE_KERNEL 0
82027 +#define ADDR_SPACE_FORCE_KERNEL 1
82028 +#define ADDR_SPACE_USER 2
82029 +#define ADDR_SPACE_FORCE_USER 3
82030 +#define ADDR_SPACE_IOMEM 0
82031 +#define ADDR_SPACE_FORCE_IOMEM 0
82032 +#define ADDR_SPACE_PERCPU 0
82033 +#define ADDR_SPACE_FORCE_PERCPU 0
82034 +#define ADDR_SPACE_RCU 0
82035 +#define ADDR_SPACE_FORCE_RCU 0
82036 +
82037 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82038 +{
82039 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82040 +}
82041 +
82042 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82043 +{
82044 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82045 +}
82046 +
82047 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82048 +{
82049 + return default_addr_space_valid_pointer_mode(mode, as);
82050 +}
82051 +
82052 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82053 +{
82054 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82055 +}
82056 +
82057 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82058 +{
82059 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82060 +}
82061 +
82062 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82063 +{
82064 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82065 + return true;
82066 +
82067 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82068 + return true;
82069 +
82070 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82071 + return true;
82072 +
82073 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82074 + return true;
82075 +
82076 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82077 + return true;
82078 +
82079 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82080 + return true;
82081 +
82082 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82083 + return true;
82084 +
82085 + return subset == superset;
82086 +}
82087 +
82088 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82089 +{
82090 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82091 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82092 +
82093 + return op;
82094 +}
82095 +
82096 +static void register_checker_address_spaces(void *event_data, void *data)
82097 +{
82098 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82099 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82100 + c_register_addr_space("__user", ADDR_SPACE_USER);
82101 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82102 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82103 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82104 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82105 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82106 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82107 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82108 +
82109 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82110 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82111 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82112 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82113 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82114 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82115 + targetm.addr_space.convert = checker_addr_space_convert;
82116 +}
82117 +
82118 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82119 +{
82120 + const char * const plugin_name = plugin_info->base_name;
82121 + const int argc = plugin_info->argc;
82122 + const struct plugin_argument * const argv = plugin_info->argv;
82123 + int i;
82124 +
82125 + if (!plugin_default_version_check(version, &gcc_version)) {
82126 + error(G_("incompatible gcc/plugin versions"));
82127 + return 1;
82128 + }
82129 +
82130 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82131 +
82132 + for (i = 0; i < argc; ++i)
82133 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82134 +
82135 + if (TARGET_64BIT == 0)
82136 + return 0;
82137 +
82138 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82139 +
82140 + return 0;
82141 +}
82142 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82143 new file mode 100644
82144 index 0000000..846aeb0
82145 --- /dev/null
82146 +++ b/tools/gcc/colorize_plugin.c
82147 @@ -0,0 +1,148 @@
82148 +/*
82149 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82150 + * Licensed under the GPL v2
82151 + *
82152 + * Note: the choice of the license means that the compilation process is
82153 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82154 + * but for the kernel it doesn't matter since it doesn't link against
82155 + * any of the gcc libraries
82156 + *
82157 + * gcc plugin to colorize diagnostic output
82158 + *
82159 + */
82160 +
82161 +#include "gcc-plugin.h"
82162 +#include "config.h"
82163 +#include "system.h"
82164 +#include "coretypes.h"
82165 +#include "tree.h"
82166 +#include "tree-pass.h"
82167 +#include "flags.h"
82168 +#include "intl.h"
82169 +#include "toplev.h"
82170 +#include "plugin.h"
82171 +#include "diagnostic.h"
82172 +#include "plugin-version.h"
82173 +#include "tm.h"
82174 +
82175 +int plugin_is_GPL_compatible;
82176 +
82177 +static struct plugin_info colorize_plugin_info = {
82178 + .version = "201203092200",
82179 + .help = NULL,
82180 +};
82181 +
82182 +#define GREEN "\033[32m\033[2m"
82183 +#define LIGHTGREEN "\033[32m\033[1m"
82184 +#define YELLOW "\033[33m\033[2m"
82185 +#define LIGHTYELLOW "\033[33m\033[1m"
82186 +#define RED "\033[31m\033[2m"
82187 +#define LIGHTRED "\033[31m\033[1m"
82188 +#define BLUE "\033[34m\033[2m"
82189 +#define LIGHTBLUE "\033[34m\033[1m"
82190 +#define BRIGHT "\033[m\033[1m"
82191 +#define NORMAL "\033[m"
82192 +
82193 +static diagnostic_starter_fn old_starter;
82194 +static diagnostic_finalizer_fn old_finalizer;
82195 +
82196 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82197 +{
82198 + const char *color;
82199 + char *newprefix;
82200 +
82201 + switch (diagnostic->kind) {
82202 + case DK_NOTE:
82203 + color = LIGHTBLUE;
82204 + break;
82205 +
82206 + case DK_PEDWARN:
82207 + case DK_WARNING:
82208 + color = LIGHTYELLOW;
82209 + break;
82210 +
82211 + case DK_ERROR:
82212 + case DK_FATAL:
82213 + case DK_ICE:
82214 + case DK_PERMERROR:
82215 + case DK_SORRY:
82216 + color = LIGHTRED;
82217 + break;
82218 +
82219 + default:
82220 + color = NORMAL;
82221 + }
82222 +
82223 + old_starter(context, diagnostic);
82224 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82225 + return;
82226 + pp_destroy_prefix(context->printer);
82227 + pp_set_prefix(context->printer, newprefix);
82228 +}
82229 +
82230 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82231 +{
82232 + old_finalizer(context, diagnostic);
82233 +}
82234 +
82235 +static void colorize_arm(void)
82236 +{
82237 + old_starter = diagnostic_starter(global_dc);
82238 + old_finalizer = diagnostic_finalizer(global_dc);
82239 +
82240 + diagnostic_starter(global_dc) = start_colorize;
82241 + diagnostic_finalizer(global_dc) = finalize_colorize;
82242 +}
82243 +
82244 +static unsigned int execute_colorize_rearm(void)
82245 +{
82246 + if (diagnostic_starter(global_dc) == start_colorize)
82247 + return 0;
82248 +
82249 + colorize_arm();
82250 + return 0;
82251 +}
82252 +
82253 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82254 + .pass = {
82255 + .type = SIMPLE_IPA_PASS,
82256 + .name = "colorize_rearm",
82257 + .gate = NULL,
82258 + .execute = execute_colorize_rearm,
82259 + .sub = NULL,
82260 + .next = NULL,
82261 + .static_pass_number = 0,
82262 + .tv_id = TV_NONE,
82263 + .properties_required = 0,
82264 + .properties_provided = 0,
82265 + .properties_destroyed = 0,
82266 + .todo_flags_start = 0,
82267 + .todo_flags_finish = 0
82268 + }
82269 +};
82270 +
82271 +static void colorize_start_unit(void *gcc_data, void *user_data)
82272 +{
82273 + colorize_arm();
82274 +}
82275 +
82276 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82277 +{
82278 + const char * const plugin_name = plugin_info->base_name;
82279 + struct register_pass_info colorize_rearm_pass_info = {
82280 + .pass = &pass_ipa_colorize_rearm.pass,
82281 + .reference_pass_name = "*free_lang_data",
82282 + .ref_pass_instance_number = 1,
82283 + .pos_op = PASS_POS_INSERT_AFTER
82284 + };
82285 +
82286 + if (!plugin_default_version_check(version, &gcc_version)) {
82287 + error(G_("incompatible gcc/plugin versions"));
82288 + return 1;
82289 + }
82290 +
82291 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82292 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82293 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82294 + return 0;
82295 +}
82296 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82297 new file mode 100644
82298 index 0000000..92ed719
82299 --- /dev/null
82300 +++ b/tools/gcc/constify_plugin.c
82301 @@ -0,0 +1,331 @@
82302 +/*
82303 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82304 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82305 + * Licensed under the GPL v2, or (at your option) v3
82306 + *
82307 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82308 + *
82309 + * Homepage:
82310 + * http://www.grsecurity.net/~ephox/const_plugin/
82311 + *
82312 + * Usage:
82313 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82314 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82315 + */
82316 +
82317 +#include "gcc-plugin.h"
82318 +#include "config.h"
82319 +#include "system.h"
82320 +#include "coretypes.h"
82321 +#include "tree.h"
82322 +#include "tree-pass.h"
82323 +#include "flags.h"
82324 +#include "intl.h"
82325 +#include "toplev.h"
82326 +#include "plugin.h"
82327 +#include "diagnostic.h"
82328 +#include "plugin-version.h"
82329 +#include "tm.h"
82330 +#include "function.h"
82331 +#include "basic-block.h"
82332 +#include "gimple.h"
82333 +#include "rtl.h"
82334 +#include "emit-rtl.h"
82335 +#include "tree-flow.h"
82336 +
82337 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82338 +
82339 +int plugin_is_GPL_compatible;
82340 +
82341 +static struct plugin_info const_plugin_info = {
82342 + .version = "201205300030",
82343 + .help = "no-constify\tturn off constification\n",
82344 +};
82345 +
82346 +static void deconstify_tree(tree node);
82347 +
82348 +static void deconstify_type(tree type)
82349 +{
82350 + tree field;
82351 +
82352 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82353 + tree type = TREE_TYPE(field);
82354 +
82355 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82356 + continue;
82357 + if (!TYPE_READONLY(type))
82358 + continue;
82359 +
82360 + deconstify_tree(field);
82361 + }
82362 + TYPE_READONLY(type) = 0;
82363 + C_TYPE_FIELDS_READONLY(type) = 0;
82364 +}
82365 +
82366 +static void deconstify_tree(tree node)
82367 +{
82368 + tree old_type, new_type, field;
82369 +
82370 + old_type = TREE_TYPE(node);
82371 +
82372 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82373 +
82374 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82375 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82376 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82377 + DECL_FIELD_CONTEXT(field) = new_type;
82378 +
82379 + deconstify_type(new_type);
82380 +
82381 + TREE_READONLY(node) = 0;
82382 + TREE_TYPE(node) = new_type;
82383 +}
82384 +
82385 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82386 +{
82387 + tree type;
82388 +
82389 + *no_add_attrs = true;
82390 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82391 + error("%qE attribute does not apply to functions", name);
82392 + return NULL_TREE;
82393 + }
82394 +
82395 + if (TREE_CODE(*node) == VAR_DECL) {
82396 + error("%qE attribute does not apply to variables", name);
82397 + return NULL_TREE;
82398 + }
82399 +
82400 + if (TYPE_P(*node)) {
82401 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82402 + *no_add_attrs = false;
82403 + else
82404 + error("%qE attribute applies to struct and union types only", name);
82405 + return NULL_TREE;
82406 + }
82407 +
82408 + type = TREE_TYPE(*node);
82409 +
82410 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82411 + error("%qE attribute applies to struct and union types only", name);
82412 + return NULL_TREE;
82413 + }
82414 +
82415 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82416 + error("%qE attribute is already applied to the type", name);
82417 + return NULL_TREE;
82418 + }
82419 +
82420 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82421 + error("%qE attribute used on type that is not constified", name);
82422 + return NULL_TREE;
82423 + }
82424 +
82425 + if (TREE_CODE(*node) == TYPE_DECL) {
82426 + deconstify_tree(*node);
82427 + return NULL_TREE;
82428 + }
82429 +
82430 + return NULL_TREE;
82431 +}
82432 +
82433 +static void constify_type(tree type)
82434 +{
82435 + TYPE_READONLY(type) = 1;
82436 + C_TYPE_FIELDS_READONLY(type) = 1;
82437 +}
82438 +
82439 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82440 +{
82441 + *no_add_attrs = true;
82442 + if (!TYPE_P(*node)) {
82443 + error("%qE attribute applies to types only", name);
82444 + return NULL_TREE;
82445 + }
82446 +
82447 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82448 + error("%qE attribute applies to struct and union types only", name);
82449 + return NULL_TREE;
82450 + }
82451 +
82452 + *no_add_attrs = false;
82453 + constify_type(*node);
82454 + return NULL_TREE;
82455 +}
82456 +
82457 +static struct attribute_spec no_const_attr = {
82458 + .name = "no_const",
82459 + .min_length = 0,
82460 + .max_length = 0,
82461 + .decl_required = false,
82462 + .type_required = false,
82463 + .function_type_required = false,
82464 + .handler = handle_no_const_attribute,
82465 +#if BUILDING_GCC_VERSION >= 4007
82466 + .affects_type_identity = true
82467 +#endif
82468 +};
82469 +
82470 +static struct attribute_spec do_const_attr = {
82471 + .name = "do_const",
82472 + .min_length = 0,
82473 + .max_length = 0,
82474 + .decl_required = false,
82475 + .type_required = false,
82476 + .function_type_required = false,
82477 + .handler = handle_do_const_attribute,
82478 +#if BUILDING_GCC_VERSION >= 4007
82479 + .affects_type_identity = true
82480 +#endif
82481 +};
82482 +
82483 +static void register_attributes(void *event_data, void *data)
82484 +{
82485 + register_attribute(&no_const_attr);
82486 + register_attribute(&do_const_attr);
82487 +}
82488 +
82489 +static bool is_fptr(tree field)
82490 +{
82491 + tree ptr = TREE_TYPE(field);
82492 +
82493 + if (TREE_CODE(ptr) != POINTER_TYPE)
82494 + return false;
82495 +
82496 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82497 +}
82498 +
82499 +static bool walk_struct(tree node)
82500 +{
82501 + tree field;
82502 +
82503 + if (TYPE_FIELDS(node) == NULL_TREE)
82504 + return false;
82505 +
82506 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82507 + gcc_assert(!TYPE_READONLY(node));
82508 + deconstify_type(node);
82509 + return false;
82510 + }
82511 +
82512 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82513 + tree type = TREE_TYPE(field);
82514 + enum tree_code code = TREE_CODE(type);
82515 +
82516 + if (node == type)
82517 + return false;
82518 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82519 + if (!(walk_struct(type)))
82520 + return false;
82521 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82522 + return false;
82523 + }
82524 + return true;
82525 +}
82526 +
82527 +static void finish_type(void *event_data, void *data)
82528 +{
82529 + tree type = (tree)event_data;
82530 +
82531 + if (type == NULL_TREE || type == error_mark_node)
82532 + return;
82533 +
82534 + if (TYPE_READONLY(type))
82535 + return;
82536 +
82537 + if (walk_struct(type))
82538 + constify_type(type);
82539 +}
82540 +
82541 +static unsigned int check_local_variables(void);
82542 +
82543 +struct gimple_opt_pass pass_local_variable = {
82544 + {
82545 + .type = GIMPLE_PASS,
82546 + .name = "check_local_variables",
82547 + .gate = NULL,
82548 + .execute = check_local_variables,
82549 + .sub = NULL,
82550 + .next = NULL,
82551 + .static_pass_number = 0,
82552 + .tv_id = TV_NONE,
82553 + .properties_required = 0,
82554 + .properties_provided = 0,
82555 + .properties_destroyed = 0,
82556 + .todo_flags_start = 0,
82557 + .todo_flags_finish = 0
82558 + }
82559 +};
82560 +
82561 +static unsigned int check_local_variables(void)
82562 +{
82563 + tree var;
82564 + referenced_var_iterator rvi;
82565 +
82566 +#if BUILDING_GCC_VERSION == 4005
82567 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82568 +#else
82569 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82570 +#endif
82571 + tree type = TREE_TYPE(var);
82572 +
82573 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82574 + continue;
82575 +
82576 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82577 + continue;
82578 +
82579 + if (!TYPE_READONLY(type))
82580 + continue;
82581 +
82582 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82583 +// continue;
82584 +
82585 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82586 +// continue;
82587 +
82588 + if (walk_struct(type)) {
82589 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82590 + return 1;
82591 + }
82592 + }
82593 + return 0;
82594 +}
82595 +
82596 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82597 +{
82598 + const char * const plugin_name = plugin_info->base_name;
82599 + const int argc = plugin_info->argc;
82600 + const struct plugin_argument * const argv = plugin_info->argv;
82601 + int i;
82602 + bool constify = true;
82603 +
82604 + struct register_pass_info local_variable_pass_info = {
82605 + .pass = &pass_local_variable.pass,
82606 + .reference_pass_name = "*referenced_vars",
82607 + .ref_pass_instance_number = 1,
82608 + .pos_op = PASS_POS_INSERT_AFTER
82609 + };
82610 +
82611 + if (!plugin_default_version_check(version, &gcc_version)) {
82612 + error(G_("incompatible gcc/plugin versions"));
82613 + return 1;
82614 + }
82615 +
82616 + for (i = 0; i < argc; ++i) {
82617 + if (!(strcmp(argv[i].key, "no-constify"))) {
82618 + constify = false;
82619 + continue;
82620 + }
82621 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82622 + }
82623 +
82624 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
82625 + if (constify) {
82626 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
82627 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
82628 + }
82629 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
82630 +
82631 + return 0;
82632 +}
82633 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
82634 new file mode 100644
82635 index 0000000..02c6bec
82636 --- /dev/null
82637 +++ b/tools/gcc/generate_size_overflow_hash.sh
82638 @@ -0,0 +1,94 @@
82639 +#!/bin/bash
82640 +
82641 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
82642 +
82643 +header1="size_overflow_hash.h"
82644 +database="size_overflow_hash.data"
82645 +n=65536
82646 +
82647 +usage() {
82648 +cat <<EOF
82649 +usage: $0 options
82650 +OPTIONS:
82651 + -h|--help help
82652 + -o header file
82653 + -d database file
82654 + -n hash array size
82655 +EOF
82656 + return 0
82657 +}
82658 +
82659 +while true
82660 +do
82661 + case "$1" in
82662 + -h|--help) usage && exit 0;;
82663 + -n) n=$2; shift 2;;
82664 + -o) header1="$2"; shift 2;;
82665 + -d) database="$2"; shift 2;;
82666 + --) shift 1; break ;;
82667 + *) break ;;
82668 + esac
82669 +done
82670 +
82671 +create_defines() {
82672 + for i in `seq 1 32`
82673 + do
82674 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
82675 + done
82676 + echo >> "$header1"
82677 +}
82678 +
82679 +create_structs () {
82680 + rm -f "$header1"
82681 +
82682 + create_defines
82683 +
82684 + cat "$database" | while read data
82685 + do
82686 + data_array=($data)
82687 + struct_hash_name="${data_array[0]}"
82688 + funcn="${data_array[1]}"
82689 + params="${data_array[2]}"
82690 + next="${data_array[5]}"
82691 +
82692 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
82693 +
82694 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
82695 + echo -en "\t.param\t= " >> "$header1"
82696 + line=
82697 + for param_num in ${params//-/ };
82698 + do
82699 + line="${line}PARAM"$param_num"|"
82700 + done
82701 +
82702 + echo -e "${line%?},\n};\n" >> "$header1"
82703 + done
82704 +}
82705 +
82706 +create_headers () {
82707 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
82708 +}
82709 +
82710 +create_array_elements () {
82711 + index=0
82712 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
82713 + do
82714 + data_array=($data)
82715 + i="${data_array[3]}"
82716 + hash="${data_array[4]}"
82717 + while [[ $index -lt $i ]]
82718 + do
82719 + echo -e "\t["$index"]\t= NULL," >> "$header1"
82720 + index=$(($index + 1))
82721 + done
82722 + index=$(($index + 1))
82723 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
82724 + done
82725 + echo '};' >> $header1
82726 +}
82727 +
82728 +create_structs
82729 +create_headers
82730 +create_array_elements
82731 +
82732 +exit 0
82733 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
82734 new file mode 100644
82735 index 0000000..a86e422
82736 --- /dev/null
82737 +++ b/tools/gcc/kallocstat_plugin.c
82738 @@ -0,0 +1,167 @@
82739 +/*
82740 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82741 + * Licensed under the GPL v2
82742 + *
82743 + * Note: the choice of the license means that the compilation process is
82744 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82745 + * but for the kernel it doesn't matter since it doesn't link against
82746 + * any of the gcc libraries
82747 + *
82748 + * gcc plugin to find the distribution of k*alloc sizes
82749 + *
82750 + * TODO:
82751 + *
82752 + * BUGS:
82753 + * - none known
82754 + */
82755 +#include "gcc-plugin.h"
82756 +#include "config.h"
82757 +#include "system.h"
82758 +#include "coretypes.h"
82759 +#include "tree.h"
82760 +#include "tree-pass.h"
82761 +#include "flags.h"
82762 +#include "intl.h"
82763 +#include "toplev.h"
82764 +#include "plugin.h"
82765 +//#include "expr.h" where are you...
82766 +#include "diagnostic.h"
82767 +#include "plugin-version.h"
82768 +#include "tm.h"
82769 +#include "function.h"
82770 +#include "basic-block.h"
82771 +#include "gimple.h"
82772 +#include "rtl.h"
82773 +#include "emit-rtl.h"
82774 +
82775 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82776 +
82777 +int plugin_is_GPL_compatible;
82778 +
82779 +static const char * const kalloc_functions[] = {
82780 + "__kmalloc",
82781 + "kmalloc",
82782 + "kmalloc_large",
82783 + "kmalloc_node",
82784 + "kmalloc_order",
82785 + "kmalloc_order_trace",
82786 + "kmalloc_slab",
82787 + "kzalloc",
82788 + "kzalloc_node",
82789 +};
82790 +
82791 +static struct plugin_info kallocstat_plugin_info = {
82792 + .version = "201111150100",
82793 +};
82794 +
82795 +static unsigned int execute_kallocstat(void);
82796 +
82797 +static struct gimple_opt_pass kallocstat_pass = {
82798 + .pass = {
82799 + .type = GIMPLE_PASS,
82800 + .name = "kallocstat",
82801 + .gate = NULL,
82802 + .execute = execute_kallocstat,
82803 + .sub = NULL,
82804 + .next = NULL,
82805 + .static_pass_number = 0,
82806 + .tv_id = TV_NONE,
82807 + .properties_required = 0,
82808 + .properties_provided = 0,
82809 + .properties_destroyed = 0,
82810 + .todo_flags_start = 0,
82811 + .todo_flags_finish = 0
82812 + }
82813 +};
82814 +
82815 +static bool is_kalloc(const char *fnname)
82816 +{
82817 + size_t i;
82818 +
82819 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
82820 + if (!strcmp(fnname, kalloc_functions[i]))
82821 + return true;
82822 + return false;
82823 +}
82824 +
82825 +static unsigned int execute_kallocstat(void)
82826 +{
82827 + basic_block bb;
82828 +
82829 + // 1. loop through BBs and GIMPLE statements
82830 + FOR_EACH_BB(bb) {
82831 + gimple_stmt_iterator gsi;
82832 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
82833 + // gimple match:
82834 + tree fndecl, size;
82835 + gimple call_stmt;
82836 + const char *fnname;
82837 +
82838 + // is it a call
82839 + call_stmt = gsi_stmt(gsi);
82840 + if (!is_gimple_call(call_stmt))
82841 + continue;
82842 + fndecl = gimple_call_fndecl(call_stmt);
82843 + if (fndecl == NULL_TREE)
82844 + continue;
82845 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
82846 + continue;
82847 +
82848 + // is it a call to k*alloc
82849 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
82850 + if (!is_kalloc(fnname))
82851 + continue;
82852 +
82853 + // is the size arg the result of a simple const assignment
82854 + size = gimple_call_arg(call_stmt, 0);
82855 + while (true) {
82856 + gimple def_stmt;
82857 + expanded_location xloc;
82858 + size_t size_val;
82859 +
82860 + if (TREE_CODE(size) != SSA_NAME)
82861 + break;
82862 + def_stmt = SSA_NAME_DEF_STMT(size);
82863 + if (!def_stmt || !is_gimple_assign(def_stmt))
82864 + break;
82865 + if (gimple_num_ops(def_stmt) != 2)
82866 + break;
82867 + size = gimple_assign_rhs1(def_stmt);
82868 + if (!TREE_CONSTANT(size))
82869 + continue;
82870 + xloc = expand_location(gimple_location(def_stmt));
82871 + if (!xloc.file)
82872 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
82873 + size_val = TREE_INT_CST_LOW(size);
82874 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
82875 + break;
82876 + }
82877 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
82878 +//debug_tree(gimple_call_fn(call_stmt));
82879 +//print_node(stderr, "pax", fndecl, 4);
82880 + }
82881 + }
82882 +
82883 + return 0;
82884 +}
82885 +
82886 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82887 +{
82888 + const char * const plugin_name = plugin_info->base_name;
82889 + struct register_pass_info kallocstat_pass_info = {
82890 + .pass = &kallocstat_pass.pass,
82891 + .reference_pass_name = "ssa",
82892 + .ref_pass_instance_number = 1,
82893 + .pos_op = PASS_POS_INSERT_AFTER
82894 + };
82895 +
82896 + if (!plugin_default_version_check(version, &gcc_version)) {
82897 + error(G_("incompatible gcc/plugin versions"));
82898 + return 1;
82899 + }
82900 +
82901 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
82902 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
82903 +
82904 + return 0;
82905 +}
82906 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
82907 new file mode 100644
82908 index 0000000..98011fa
82909 --- /dev/null
82910 +++ b/tools/gcc/kernexec_plugin.c
82911 @@ -0,0 +1,427 @@
82912 +/*
82913 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82914 + * Licensed under the GPL v2
82915 + *
82916 + * Note: the choice of the license means that the compilation process is
82917 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82918 + * but for the kernel it doesn't matter since it doesn't link against
82919 + * any of the gcc libraries
82920 + *
82921 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
82922 + *
82923 + * TODO:
82924 + *
82925 + * BUGS:
82926 + * - none known
82927 + */
82928 +#include "gcc-plugin.h"
82929 +#include "config.h"
82930 +#include "system.h"
82931 +#include "coretypes.h"
82932 +#include "tree.h"
82933 +#include "tree-pass.h"
82934 +#include "flags.h"
82935 +#include "intl.h"
82936 +#include "toplev.h"
82937 +#include "plugin.h"
82938 +//#include "expr.h" where are you...
82939 +#include "diagnostic.h"
82940 +#include "plugin-version.h"
82941 +#include "tm.h"
82942 +#include "function.h"
82943 +#include "basic-block.h"
82944 +#include "gimple.h"
82945 +#include "rtl.h"
82946 +#include "emit-rtl.h"
82947 +#include "tree-flow.h"
82948 +
82949 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82950 +extern rtx emit_move_insn(rtx x, rtx y);
82951 +
82952 +int plugin_is_GPL_compatible;
82953 +
82954 +static struct plugin_info kernexec_plugin_info = {
82955 + .version = "201111291120",
82956 + .help = "method=[bts|or]\tinstrumentation method\n"
82957 +};
82958 +
82959 +static unsigned int execute_kernexec_reload(void);
82960 +static unsigned int execute_kernexec_fptr(void);
82961 +static unsigned int execute_kernexec_retaddr(void);
82962 +static bool kernexec_cmodel_check(void);
82963 +
82964 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
82965 +static void (*kernexec_instrument_retaddr)(rtx);
82966 +
82967 +static struct gimple_opt_pass kernexec_reload_pass = {
82968 + .pass = {
82969 + .type = GIMPLE_PASS,
82970 + .name = "kernexec_reload",
82971 + .gate = kernexec_cmodel_check,
82972 + .execute = execute_kernexec_reload,
82973 + .sub = NULL,
82974 + .next = NULL,
82975 + .static_pass_number = 0,
82976 + .tv_id = TV_NONE,
82977 + .properties_required = 0,
82978 + .properties_provided = 0,
82979 + .properties_destroyed = 0,
82980 + .todo_flags_start = 0,
82981 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
82982 + }
82983 +};
82984 +
82985 +static struct gimple_opt_pass kernexec_fptr_pass = {
82986 + .pass = {
82987 + .type = GIMPLE_PASS,
82988 + .name = "kernexec_fptr",
82989 + .gate = kernexec_cmodel_check,
82990 + .execute = execute_kernexec_fptr,
82991 + .sub = NULL,
82992 + .next = NULL,
82993 + .static_pass_number = 0,
82994 + .tv_id = TV_NONE,
82995 + .properties_required = 0,
82996 + .properties_provided = 0,
82997 + .properties_destroyed = 0,
82998 + .todo_flags_start = 0,
82999 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83000 + }
83001 +};
83002 +
83003 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83004 + .pass = {
83005 + .type = RTL_PASS,
83006 + .name = "kernexec_retaddr",
83007 + .gate = kernexec_cmodel_check,
83008 + .execute = execute_kernexec_retaddr,
83009 + .sub = NULL,
83010 + .next = NULL,
83011 + .static_pass_number = 0,
83012 + .tv_id = TV_NONE,
83013 + .properties_required = 0,
83014 + .properties_provided = 0,
83015 + .properties_destroyed = 0,
83016 + .todo_flags_start = 0,
83017 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83018 + }
83019 +};
83020 +
83021 +static bool kernexec_cmodel_check(void)
83022 +{
83023 + tree section;
83024 +
83025 + if (ix86_cmodel != CM_KERNEL)
83026 + return false;
83027 +
83028 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83029 + if (!section || !TREE_VALUE(section))
83030 + return true;
83031 +
83032 + section = TREE_VALUE(TREE_VALUE(section));
83033 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83034 + return true;
83035 +
83036 + return false;
83037 +}
83038 +
83039 +/*
83040 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83041 + */
83042 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83043 +{
83044 + gimple asm_movabs_stmt;
83045 +
83046 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83047 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83048 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83049 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83050 + update_stmt(asm_movabs_stmt);
83051 +}
83052 +
83053 +/*
83054 + * find all asm() stmts that clobber r10 and add a reload of r10
83055 + */
83056 +static unsigned int execute_kernexec_reload(void)
83057 +{
83058 + basic_block bb;
83059 +
83060 + // 1. loop through BBs and GIMPLE statements
83061 + FOR_EACH_BB(bb) {
83062 + gimple_stmt_iterator gsi;
83063 +
83064 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83065 + // gimple match: __asm__ ("" : : : "r10");
83066 + gimple asm_stmt;
83067 + size_t nclobbers;
83068 +
83069 + // is it an asm ...
83070 + asm_stmt = gsi_stmt(gsi);
83071 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83072 + continue;
83073 +
83074 + // ... clobbering r10
83075 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83076 + while (nclobbers--) {
83077 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83078 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83079 + continue;
83080 + kernexec_reload_fptr_mask(&gsi);
83081 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83082 + break;
83083 + }
83084 + }
83085 + }
83086 +
83087 + return 0;
83088 +}
83089 +
83090 +/*
83091 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83092 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83093 + */
83094 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83095 +{
83096 + gimple assign_intptr, assign_new_fptr, call_stmt;
83097 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83098 +
83099 + call_stmt = gsi_stmt(*gsi);
83100 + old_fptr = gimple_call_fn(call_stmt);
83101 +
83102 + // create temporary unsigned long variable used for bitops and cast fptr to it
83103 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83104 + add_referenced_var(intptr);
83105 + mark_sym_for_renaming(intptr);
83106 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83107 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83108 + update_stmt(assign_intptr);
83109 +
83110 + // apply logical or to temporary unsigned long and bitmask
83111 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83112 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83113 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83114 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83115 + update_stmt(assign_intptr);
83116 +
83117 + // cast temporary unsigned long back to a temporary fptr variable
83118 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83119 + add_referenced_var(new_fptr);
83120 + mark_sym_for_renaming(new_fptr);
83121 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83122 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83123 + update_stmt(assign_new_fptr);
83124 +
83125 + // replace call stmt fn with the new fptr
83126 + gimple_call_set_fn(call_stmt, new_fptr);
83127 + update_stmt(call_stmt);
83128 +}
83129 +
83130 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83131 +{
83132 + gimple asm_or_stmt, call_stmt;
83133 + tree old_fptr, new_fptr, input, output;
83134 + VEC(tree, gc) *inputs = NULL;
83135 + VEC(tree, gc) *outputs = NULL;
83136 +
83137 + call_stmt = gsi_stmt(*gsi);
83138 + old_fptr = gimple_call_fn(call_stmt);
83139 +
83140 + // create temporary fptr variable
83141 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83142 + add_referenced_var(new_fptr);
83143 + mark_sym_for_renaming(new_fptr);
83144 +
83145 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83146 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83147 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83148 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83149 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83150 + VEC_safe_push(tree, gc, inputs, input);
83151 + VEC_safe_push(tree, gc, outputs, output);
83152 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83153 + gimple_asm_set_volatile(asm_or_stmt, true);
83154 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83155 + update_stmt(asm_or_stmt);
83156 +
83157 + // replace call stmt fn with the new fptr
83158 + gimple_call_set_fn(call_stmt, new_fptr);
83159 + update_stmt(call_stmt);
83160 +}
83161 +
83162 +/*
83163 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83164 + */
83165 +static unsigned int execute_kernexec_fptr(void)
83166 +{
83167 + basic_block bb;
83168 +
83169 + // 1. loop through BBs and GIMPLE statements
83170 + FOR_EACH_BB(bb) {
83171 + gimple_stmt_iterator gsi;
83172 +
83173 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83174 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83175 + tree fn;
83176 + gimple call_stmt;
83177 +
83178 + // is it a call ...
83179 + call_stmt = gsi_stmt(gsi);
83180 + if (!is_gimple_call(call_stmt))
83181 + continue;
83182 + fn = gimple_call_fn(call_stmt);
83183 + if (TREE_CODE(fn) == ADDR_EXPR)
83184 + continue;
83185 + if (TREE_CODE(fn) != SSA_NAME)
83186 + gcc_unreachable();
83187 +
83188 + // ... through a function pointer
83189 + fn = SSA_NAME_VAR(fn);
83190 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83191 + continue;
83192 + fn = TREE_TYPE(fn);
83193 + if (TREE_CODE(fn) != POINTER_TYPE)
83194 + continue;
83195 + fn = TREE_TYPE(fn);
83196 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83197 + continue;
83198 +
83199 + kernexec_instrument_fptr(&gsi);
83200 +
83201 +//debug_tree(gimple_call_fn(call_stmt));
83202 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83203 + }
83204 + }
83205 +
83206 + return 0;
83207 +}
83208 +
83209 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83210 +static void kernexec_instrument_retaddr_bts(rtx insn)
83211 +{
83212 + rtx btsq;
83213 + rtvec argvec, constraintvec, labelvec;
83214 + int line;
83215 +
83216 + // create asm volatile("btsq $63,(%%rsp)":::)
83217 + argvec = rtvec_alloc(0);
83218 + constraintvec = rtvec_alloc(0);
83219 + labelvec = rtvec_alloc(0);
83220 + line = expand_location(RTL_LOCATION(insn)).line;
83221 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83222 + MEM_VOLATILE_P(btsq) = 1;
83223 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83224 + emit_insn_before(btsq, insn);
83225 +}
83226 +
83227 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83228 +static void kernexec_instrument_retaddr_or(rtx insn)
83229 +{
83230 + rtx orq;
83231 + rtvec argvec, constraintvec, labelvec;
83232 + int line;
83233 +
83234 + // create asm volatile("orq %%r10,(%%rsp)":::)
83235 + argvec = rtvec_alloc(0);
83236 + constraintvec = rtvec_alloc(0);
83237 + labelvec = rtvec_alloc(0);
83238 + line = expand_location(RTL_LOCATION(insn)).line;
83239 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83240 + MEM_VOLATILE_P(orq) = 1;
83241 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83242 + emit_insn_before(orq, insn);
83243 +}
83244 +
83245 +/*
83246 + * find all asm level function returns and forcibly set the highest bit of the return address
83247 + */
83248 +static unsigned int execute_kernexec_retaddr(void)
83249 +{
83250 + rtx insn;
83251 +
83252 + // 1. find function returns
83253 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83254 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83255 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83256 + rtx body;
83257 +
83258 + // is it a retn
83259 + if (!JUMP_P(insn))
83260 + continue;
83261 + body = PATTERN(insn);
83262 + if (GET_CODE(body) == PARALLEL)
83263 + body = XVECEXP(body, 0, 0);
83264 + if (GET_CODE(body) != RETURN)
83265 + continue;
83266 + kernexec_instrument_retaddr(insn);
83267 + }
83268 +
83269 +// print_simple_rtl(stderr, get_insns());
83270 +// print_rtl(stderr, get_insns());
83271 +
83272 + return 0;
83273 +}
83274 +
83275 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83276 +{
83277 + const char * const plugin_name = plugin_info->base_name;
83278 + const int argc = plugin_info->argc;
83279 + const struct plugin_argument * const argv = plugin_info->argv;
83280 + int i;
83281 + struct register_pass_info kernexec_reload_pass_info = {
83282 + .pass = &kernexec_reload_pass.pass,
83283 + .reference_pass_name = "ssa",
83284 + .ref_pass_instance_number = 1,
83285 + .pos_op = PASS_POS_INSERT_AFTER
83286 + };
83287 + struct register_pass_info kernexec_fptr_pass_info = {
83288 + .pass = &kernexec_fptr_pass.pass,
83289 + .reference_pass_name = "ssa",
83290 + .ref_pass_instance_number = 1,
83291 + .pos_op = PASS_POS_INSERT_AFTER
83292 + };
83293 + struct register_pass_info kernexec_retaddr_pass_info = {
83294 + .pass = &kernexec_retaddr_pass.pass,
83295 + .reference_pass_name = "pro_and_epilogue",
83296 + .ref_pass_instance_number = 1,
83297 + .pos_op = PASS_POS_INSERT_AFTER
83298 + };
83299 +
83300 + if (!plugin_default_version_check(version, &gcc_version)) {
83301 + error(G_("incompatible gcc/plugin versions"));
83302 + return 1;
83303 + }
83304 +
83305 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83306 +
83307 + if (TARGET_64BIT == 0)
83308 + return 0;
83309 +
83310 + for (i = 0; i < argc; ++i) {
83311 + if (!strcmp(argv[i].key, "method")) {
83312 + if (!argv[i].value) {
83313 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83314 + continue;
83315 + }
83316 + if (!strcmp(argv[i].value, "bts")) {
83317 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83318 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83319 + } else if (!strcmp(argv[i].value, "or")) {
83320 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83321 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83322 + fix_register("r10", 1, 1);
83323 + } else
83324 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83325 + continue;
83326 + }
83327 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83328 + }
83329 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83330 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83331 +
83332 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83333 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83334 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83335 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83336 +
83337 + return 0;
83338 +}
83339 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83340 new file mode 100644
83341 index 0000000..b8008f7
83342 --- /dev/null
83343 +++ b/tools/gcc/latent_entropy_plugin.c
83344 @@ -0,0 +1,295 @@
83345 +/*
83346 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83347 + * Licensed under the GPL v2
83348 + *
83349 + * Note: the choice of the license means that the compilation process is
83350 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83351 + * but for the kernel it doesn't matter since it doesn't link against
83352 + * any of the gcc libraries
83353 + *
83354 + * gcc plugin to help generate a little bit of entropy from program state,
83355 + * used during boot in the kernel
83356 + *
83357 + * TODO:
83358 + * - add ipa pass to identify not explicitly marked candidate functions
83359 + * - mix in more program state (function arguments/return values, loop variables, etc)
83360 + * - more instrumentation control via attribute parameters
83361 + *
83362 + * BUGS:
83363 + * - LTO needs -flto-partition=none for now
83364 + */
83365 +#include "gcc-plugin.h"
83366 +#include "config.h"
83367 +#include "system.h"
83368 +#include "coretypes.h"
83369 +#include "tree.h"
83370 +#include "tree-pass.h"
83371 +#include "flags.h"
83372 +#include "intl.h"
83373 +#include "toplev.h"
83374 +#include "plugin.h"
83375 +//#include "expr.h" where are you...
83376 +#include "diagnostic.h"
83377 +#include "plugin-version.h"
83378 +#include "tm.h"
83379 +#include "function.h"
83380 +#include "basic-block.h"
83381 +#include "gimple.h"
83382 +#include "rtl.h"
83383 +#include "emit-rtl.h"
83384 +#include "tree-flow.h"
83385 +
83386 +int plugin_is_GPL_compatible;
83387 +
83388 +static tree latent_entropy_decl;
83389 +
83390 +static struct plugin_info latent_entropy_plugin_info = {
83391 + .version = "201207271820",
83392 + .help = NULL
83393 +};
83394 +
83395 +static unsigned int execute_latent_entropy(void);
83396 +static bool gate_latent_entropy(void);
83397 +
83398 +static struct gimple_opt_pass latent_entropy_pass = {
83399 + .pass = {
83400 + .type = GIMPLE_PASS,
83401 + .name = "latent_entropy",
83402 + .gate = gate_latent_entropy,
83403 + .execute = execute_latent_entropy,
83404 + .sub = NULL,
83405 + .next = NULL,
83406 + .static_pass_number = 0,
83407 + .tv_id = TV_NONE,
83408 + .properties_required = PROP_gimple_leh | PROP_cfg,
83409 + .properties_provided = 0,
83410 + .properties_destroyed = 0,
83411 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83412 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83413 + }
83414 +};
83415 +
83416 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83417 +{
83418 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83419 + *no_add_attrs = true;
83420 + error("%qE attribute only applies to functions", name);
83421 + }
83422 + return NULL_TREE;
83423 +}
83424 +
83425 +static struct attribute_spec latent_entropy_attr = {
83426 + .name = "latent_entropy",
83427 + .min_length = 0,
83428 + .max_length = 0,
83429 + .decl_required = true,
83430 + .type_required = false,
83431 + .function_type_required = false,
83432 + .handler = handle_latent_entropy_attribute,
83433 +#if BUILDING_GCC_VERSION >= 4007
83434 + .affects_type_identity = false
83435 +#endif
83436 +};
83437 +
83438 +static void register_attributes(void *event_data, void *data)
83439 +{
83440 + register_attribute(&latent_entropy_attr);
83441 +}
83442 +
83443 +static bool gate_latent_entropy(void)
83444 +{
83445 + tree latent_entropy_attr;
83446 +
83447 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83448 + return latent_entropy_attr != NULL_TREE;
83449 +}
83450 +
83451 +static unsigned HOST_WIDE_INT seed;
83452 +static unsigned HOST_WIDE_INT get_random_const(void)
83453 +{
83454 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83455 + return seed;
83456 +}
83457 +
83458 +static enum tree_code get_op(tree *rhs)
83459 +{
83460 + static enum tree_code op;
83461 + unsigned HOST_WIDE_INT random_const;
83462 +
83463 + random_const = get_random_const();
83464 +
83465 + switch (op) {
83466 + case BIT_XOR_EXPR:
83467 + op = PLUS_EXPR;
83468 + break;
83469 +
83470 + case PLUS_EXPR:
83471 + if (rhs) {
83472 + op = LROTATE_EXPR;
83473 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83474 + break;
83475 + }
83476 +
83477 + case LROTATE_EXPR:
83478 + default:
83479 + op = BIT_XOR_EXPR;
83480 + break;
83481 + }
83482 + if (rhs)
83483 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83484 + return op;
83485 +}
83486 +
83487 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83488 +{
83489 + gimple_stmt_iterator gsi;
83490 + gimple assign;
83491 + tree addxorrol, rhs;
83492 + enum tree_code op;
83493 +
83494 + op = get_op(&rhs);
83495 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83496 + assign = gimple_build_assign(local_entropy, addxorrol);
83497 + find_referenced_vars_in(assign);
83498 +//debug_bb(bb);
83499 + gsi = gsi_after_labels(bb);
83500 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83501 + update_stmt(assign);
83502 +}
83503 +
83504 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83505 +{
83506 + gimple_stmt_iterator gsi;
83507 + gimple assign;
83508 + tree addxorrol, temp;
83509 +
83510 + // 1. create temporary copy of latent_entropy
83511 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83512 + add_referenced_var(temp);
83513 + mark_sym_for_renaming(temp);
83514 +
83515 + // 2. read...
83516 + assign = gimple_build_assign(temp, latent_entropy_decl);
83517 + find_referenced_vars_in(assign);
83518 + gsi = gsi_after_labels(bb);
83519 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83520 + update_stmt(assign);
83521 +
83522 + // 3. ...modify...
83523 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83524 + assign = gimple_build_assign(temp, addxorrol);
83525 + find_referenced_vars_in(assign);
83526 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83527 + update_stmt(assign);
83528 +
83529 + // 4. ...write latent_entropy
83530 + assign = gimple_build_assign(latent_entropy_decl, temp);
83531 + find_referenced_vars_in(assign);
83532 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83533 + update_stmt(assign);
83534 +}
83535 +
83536 +static unsigned int execute_latent_entropy(void)
83537 +{
83538 + basic_block bb;
83539 + gimple assign;
83540 + gimple_stmt_iterator gsi;
83541 + tree local_entropy;
83542 +
83543 + if (!latent_entropy_decl) {
83544 + struct varpool_node *node;
83545 +
83546 + for (node = varpool_nodes; node; node = node->next) {
83547 + tree var = node->decl;
83548 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83549 + continue;
83550 + latent_entropy_decl = var;
83551 +// debug_tree(var);
83552 + break;
83553 + }
83554 + if (!latent_entropy_decl) {
83555 +// debug_tree(current_function_decl);
83556 + return 0;
83557 + }
83558 + }
83559 +
83560 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83561 +
83562 + // 1. create local entropy variable
83563 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83564 + add_referenced_var(local_entropy);
83565 + mark_sym_for_renaming(local_entropy);
83566 +
83567 + // 2. initialize local entropy variable
83568 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83569 + if (dom_info_available_p(CDI_DOMINATORS))
83570 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83571 + gsi = gsi_start_bb(bb);
83572 +
83573 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83574 +// gimple_set_location(assign, loc);
83575 + find_referenced_vars_in(assign);
83576 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83577 + update_stmt(assign);
83578 + bb = bb->next_bb;
83579 +
83580 + // 3. instrument each BB with an operation on the local entropy variable
83581 + while (bb != EXIT_BLOCK_PTR) {
83582 + perturb_local_entropy(bb, local_entropy);
83583 + bb = bb->next_bb;
83584 + };
83585 +
83586 + // 4. mix local entropy into the global entropy variable
83587 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83588 + return 0;
83589 +}
83590 +
83591 +static void start_unit_callback(void *gcc_data, void *user_data)
83592 +{
83593 +#if BUILDING_GCC_VERSION >= 4007
83594 + seed = get_random_seed(false);
83595 +#else
83596 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83597 + seed *= seed;
83598 +#endif
83599 +
83600 + if (in_lto_p)
83601 + return;
83602 +
83603 + // extern u64 latent_entropy
83604 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83605 +
83606 + TREE_STATIC(latent_entropy_decl) = 1;
83607 + TREE_PUBLIC(latent_entropy_decl) = 1;
83608 + TREE_USED(latent_entropy_decl) = 1;
83609 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
83610 + DECL_EXTERNAL(latent_entropy_decl) = 1;
83611 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
83612 + DECL_INITIAL(latent_entropy_decl) = NULL;
83613 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
83614 +// varpool_finalize_decl(latent_entropy_decl);
83615 +// varpool_mark_needed_node(latent_entropy_decl);
83616 +}
83617 +
83618 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83619 +{
83620 + const char * const plugin_name = plugin_info->base_name;
83621 + struct register_pass_info latent_entropy_pass_info = {
83622 + .pass = &latent_entropy_pass.pass,
83623 + .reference_pass_name = "optimized",
83624 + .ref_pass_instance_number = 1,
83625 + .pos_op = PASS_POS_INSERT_BEFORE
83626 + };
83627 +
83628 + if (!plugin_default_version_check(version, &gcc_version)) {
83629 + error(G_("incompatible gcc/plugin versions"));
83630 + return 1;
83631 + }
83632 +
83633 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
83634 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
83635 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
83636 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83637 +
83638 + return 0;
83639 +}
83640 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
83641 new file mode 100644
83642 index 0000000..9332f17
83643 --- /dev/null
83644 +++ b/tools/gcc/size_overflow_hash.data
83645 @@ -0,0 +1,3597 @@
83646 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
83647 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
83648 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
83649 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
83650 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
83651 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
83652 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
83653 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
83654 +_000009_hash kmalloc 1 60432 _003302_hash NULL nohasharray
83655 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
83656 +_000012_hash __kmalloc_reserve 1 17080 _000012_hash NULL
83657 +_000013_hash kmalloc_slab 1 11917 _000013_hash NULL
83658 +_000014_hash kmemdup 2 64015 _000014_hash NULL
83659 +_000015_hash __krealloc 2 14857 _000340_hash NULL nohasharray
83660 +_000016_hash memdup_user 2 59590 _000016_hash NULL
83661 +_000017_hash module_alloc 1 63630 _000017_hash NULL
83662 +_000018_hash read_default_ldt 2 14302 _000018_hash NULL
83663 +_000019_hash read_kcore 3 63488 _000019_hash NULL
83664 +_000020_hash read_ldt 2 47570 _000020_hash NULL
83665 +_000021_hash read_zero 3 19366 _000021_hash NULL
83666 +_000022_hash __vmalloc_node 1 39308 _000022_hash NULL
83667 +_000023_hash aac_convert_sgraw2 4 51598 _000023_hash NULL
83668 +_000024_hash aa_simple_write_to_buffer 4-3 49683 _000024_hash NULL
83669 +_000025_hash ablkcipher_copy_iv 3 64140 _000025_hash NULL
83670 +_000026_hash ablkcipher_next_slow 3-4 47274 _000026_hash NULL
83671 +_000028_hash acpi_battery_write_alarm 3 1240 _000028_hash NULL
83672 +_000029_hash acpi_os_allocate 1 14892 _000029_hash NULL
83673 +_000030_hash acpi_system_write_wakeup_device 3 34853 _000030_hash NULL
83674 +_000031_hash adu_write 3 30487 _000031_hash NULL
83675 +_000032_hash aer_inject_write 3 52399 _000032_hash NULL
83676 +_000033_hash afs_alloc_flat_call 2-3 36399 _000033_hash NULL
83677 +_000035_hash afs_proc_cells_write 3 61139 _000035_hash NULL
83678 +_000036_hash afs_proc_rootcell_write 3 15822 _000036_hash NULL
83679 +_000037_hash agp_3_5_isochronous_node_enable 3 49465 _000037_hash NULL
83680 +_000038_hash agp_alloc_page_array 1 22554 _000038_hash NULL
83681 +_000039_hash ah_alloc_tmp 2-3 54378 _000039_hash NULL
83682 +_000041_hash ahash_setkey_unaligned 3 33521 _000041_hash NULL
83683 +_000042_hash alg_setkey 3 31485 _000042_hash NULL
83684 +_000043_hash aligned_kmalloc 1 3628 _000043_hash NULL
83685 +_000044_hash alloc_context 1 3194 _000044_hash NULL
83686 +_000045_hash alloc_ep_req 2 54860 _000045_hash NULL
83687 +_000046_hash alloc_fdmem 1 27083 _000046_hash NULL
83688 +_000047_hash alloc_flex_gd 1 57259 _000047_hash NULL
83689 +_000048_hash alloc_sglist 1-3-2 22960 _000048_hash NULL
83690 +_000049_hash __alloc_skb 1 23940 _000049_hash NULL
83691 +_000050_hash aoedev_flush 2 44398 _000050_hash NULL
83692 +_000051_hash append_to_buffer 3 63550 _000051_hash NULL
83693 +_000052_hash asix_read_cmd 5 13245 _000052_hash NULL
83694 +_000053_hash asix_write_cmd 5 58192 _000053_hash NULL
83695 +_000054_hash at76_set_card_command 4 4471 _000054_hash NULL
83696 +_000055_hash ath6kl_add_bss_if_needed 6 24317 _000055_hash NULL
83697 +_000056_hash ath6kl_debug_roam_tbl_event 3 5224 _000056_hash NULL
83698 +_000057_hash ath6kl_mgmt_powersave_ap 6 13791 _000057_hash NULL
83699 +_000058_hash ath6kl_send_go_probe_resp 3 21113 _000058_hash NULL
83700 +_000059_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000059_hash NULL
83701 +_000060_hash ath6kl_set_assoc_req_ies 3 43185 _000060_hash NULL
83702 +_000061_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000061_hash NULL
83703 +_000062_hash ath6kl_wmi_send_action_cmd 7 58860 _000062_hash NULL
83704 +_000063_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000063_hash NULL
83705 +_000064_hash attach_hdlc_protocol 3 19986 _000064_hash NULL
83706 +_000065_hash audio_write 4 54261 _001782_hash NULL nohasharray
83707 +_000066_hash audit_unpack_string 3 13748 _000066_hash NULL
83708 +_000067_hash ax25_setsockopt 5 42740 _000067_hash NULL
83709 +_000068_hash b43_debugfs_write 3 34838 _000068_hash NULL
83710 +_000069_hash b43legacy_debugfs_write 3 28556 _000069_hash NULL
83711 +_000070_hash batadv_hash_new 1 40491 _000070_hash NULL
83712 +_000071_hash batadv_orig_node_add_if 2 18433 _000071_hash NULL
83713 +_000072_hash batadv_orig_node_del_if 2 4 _000072_hash NULL
83714 +_000073_hash batadv_tt_changes_fill_buff 4 40323 _000073_hash NULL
83715 +_000074_hash batadv_tt_realloc_packet_buff 4 49960 _000074_hash NULL
83716 +_000075_hash bch_alloc 1 4593 _000075_hash NULL
83717 +_000076_hash befs_nls2utf 3 17163 _000076_hash NULL
83718 +_000077_hash befs_utf2nls 3 25628 _000077_hash NULL
83719 +_000078_hash bfad_debugfs_write_regrd 3 15218 _000078_hash NULL
83720 +_000079_hash bfad_debugfs_write_regwr 3 61841 _000079_hash NULL
83721 +_000080_hash bio_alloc_map_data 1-2 50782 _000080_hash NULL
83722 +_000082_hash bio_kmalloc 2 54672 _000082_hash NULL
83723 +_000083_hash bitmap_storage_alloc 2 55077 _000083_hash NULL
83724 +_000084_hash blkcipher_copy_iv 3 24075 _000084_hash NULL
83725 +_000085_hash blkcipher_next_slow 3-4 52733 _000085_hash NULL
83726 +_000087_hash bl_pipe_downcall 3 34264 _000087_hash NULL
83727 +_000088_hash bnad_debugfs_write_regrd 3 6706 _000088_hash NULL
83728 +_000089_hash bnad_debugfs_write_regwr 3 57500 _000089_hash NULL
83729 +_000090_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000090_hash NULL
83730 +_000092_hash bnx2fc_process_unsol_compl 2 15576 _000092_hash NULL
83731 +_000093_hash bnx2_nvram_write 2-4 7790 _000093_hash NULL
83732 +_000095_hash btmrvl_gpiogap_write 3 35053 _000095_hash NULL
83733 +_000096_hash btmrvl_hscfgcmd_write 3 27143 _000096_hash NULL
83734 +_000097_hash btmrvl_hscmd_write 3 27089 _000097_hash NULL
83735 +_000098_hash btmrvl_hsmode_write 3 42252 _000098_hash NULL
83736 +_000099_hash btmrvl_pscmd_write 3 29504 _000099_hash NULL
83737 +_000100_hash btmrvl_psmode_write 3 3703 _000100_hash NULL
83738 +_000101_hash btrfs_alloc_delayed_item 1 11678 _000101_hash NULL
83739 +_000102_hash c4iw_id_table_alloc 3 48163 _000102_hash NULL
83740 +_000103_hash cache_do_downcall 3 6926 _000103_hash NULL
83741 +_000104_hash cachefiles_cook_key 2 33274 _000104_hash NULL
83742 +_000105_hash cachefiles_daemon_write 3 43535 _000105_hash NULL
83743 +_000106_hash capi_write 3 35104 _003607_hash NULL nohasharray
83744 +_000107_hash carl9170_debugfs_write 3 50857 _000107_hash NULL
83745 +_000108_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000108_hash NULL
83746 +_000110_hash cciss_proc_write 3 10259 _000110_hash NULL
83747 +_000111_hash cdrom_read_cdda_old 4 27664 _000111_hash NULL
83748 +_000112_hash ceph_alloc_page_vector 1 18710 _000112_hash NULL
83749 +_000113_hash ceph_buffer_new 1 35974 _000113_hash NULL
83750 +_000114_hash ceph_copy_user_to_page_vector 3-4 656 _000114_hash NULL
83751 +_000116_hash ceph_get_direct_page_vector 2 41917 _000116_hash NULL
83752 +_000117_hash ceph_msg_new 2 5846 _000117_hash NULL
83753 +_000118_hash ceph_setxattr 4 18913 _000118_hash NULL
83754 +_000119_hash cfi_read_pri 3 24366 _000119_hash NULL
83755 +_000120_hash cgroup_write_string 5 10900 _000120_hash NULL
83756 +_000121_hash cgroup_write_X64 5 54514 _000121_hash NULL
83757 +_000122_hash change_xattr 5 61390 _000122_hash NULL
83758 +_000123_hash check_load_and_stores 2 2143 _000123_hash NULL
83759 +_000124_hash cifs_idmap_key_instantiate 3 54503 _000124_hash NULL
83760 +_000125_hash cifs_security_flags_proc_write 3 5484 _000125_hash NULL
83761 +_000126_hash cifs_setxattr 4 23957 _000126_hash NULL
83762 +_000127_hash cifs_spnego_key_instantiate 3 23588 _000127_hash NULL
83763 +_000128_hash cld_pipe_downcall 3 15058 _000128_hash NULL
83764 +_000129_hash clear_refs_write 3 61904 _000129_hash NULL
83765 +_000130_hash clusterip_proc_write 3 44729 _000130_hash NULL
83766 +_000131_hash cm4040_write 3 58079 _000131_hash NULL
83767 +_000132_hash cm_copy_private_data 2 3649 _000132_hash NULL
83768 +_000133_hash cmm_write 3 2896 _000133_hash NULL
83769 +_000134_hash cm_write 3 36858 _000134_hash NULL
83770 +_000135_hash coda_psdev_write 3 1711 _000135_hash NULL
83771 +_000136_hash codec_reg_read_file 3 36280 _000136_hash NULL
83772 +_000137_hash command_file_write 3 31318 _000137_hash NULL
83773 +_000138_hash command_write 3 58841 _000138_hash NULL
83774 +_000139_hash comm_write 3 44537 _001714_hash NULL nohasharray
83775 +_000140_hash concat_writev 3 21451 _000140_hash NULL
83776 +_000141_hash copy_and_check 3 19089 _000141_hash NULL
83777 +_000142_hash copy_from_user_toio 3 31966 _000142_hash NULL
83778 +_000143_hash copy_items 6 50140 _000143_hash NULL
83779 +_000144_hash copy_macs 4 45534 _000144_hash NULL
83780 +_000145_hash __copy_to_user 3 17551 _000145_hash NULL
83781 +_000146_hash copy_vm86_regs_from_user 3 45340 _000146_hash NULL
83782 +_000147_hash core_sys_select 1 47494 _000147_hash NULL
83783 +_000148_hash cosa_write 3 1774 _000148_hash NULL
83784 +_000149_hash cp210x_set_config 4 46447 _000149_hash NULL
83785 +_000150_hash create_entry 2 33479 _000150_hash NULL
83786 +_000151_hash create_queues 2-3 9088 _000151_hash NULL
83787 +_000153_hash create_xattr 5 54106 _000153_hash NULL
83788 +_000154_hash create_xattr_datum 5 33356 _003443_hash NULL nohasharray
83789 +_000155_hash csum_partial_copy_fromiovecend 3-4 9957 _000155_hash NULL
83790 +_000157_hash ctrl_out 3-5 8712 _000157_hash NULL
83791 +_000159_hash cxacru_cm_get_array 4 4412 _000159_hash NULL
83792 +_000160_hash cxgbi_alloc_big_mem 1 4707 _000160_hash NULL
83793 +_000161_hash dac960_user_command_proc_write 3 3071 _000161_hash NULL
83794 +_000162_hash datablob_format 2 39571 _002490_hash NULL nohasharray
83795 +_000163_hash dccp_feat_clone_sp_val 3 11942 _000163_hash NULL
83796 +_000164_hash dccp_setsockopt_ccid 4 30701 _000164_hash NULL
83797 +_000165_hash dccp_setsockopt_cscov 2 37766 _000165_hash NULL
83798 +_000166_hash dccp_setsockopt_service 4 65336 _000166_hash NULL
83799 +_000167_hash ddebug_proc_write 3 18055 _000167_hash NULL
83800 +_000168_hash dev_config 3 8506 _000168_hash NULL
83801 +_000169_hash device_write 3 45156 _000169_hash NULL
83802 +_000170_hash devm_kzalloc 2 4966 _000170_hash NULL
83803 +_000171_hash devres_alloc 2 551 _000171_hash NULL
83804 +_000172_hash dfs_file_write 3 41196 _000172_hash NULL
83805 +_000173_hash direct_entry 3 38836 _000173_hash NULL
83806 +_000174_hash dispatch_ioctl 2 32357 _000174_hash NULL
83807 +_000175_hash dispatch_proc_write 3 44320 _000175_hash NULL
83808 +_000176_hash diva_os_copy_from_user 4 7792 _000176_hash NULL
83809 +_000177_hash dlm_alloc_pagevec 1 54296 _000177_hash NULL
83810 +_000178_hash dlmfs_file_read 3 28385 _000178_hash NULL
83811 +_000179_hash dlmfs_file_write 3 6892 _000179_hash NULL
83812 +_000180_hash dm_read 3 15674 _000180_hash NULL
83813 +_000181_hash dm_write 3 2513 _000181_hash NULL
83814 +_000182_hash __dn_setsockopt 5 13060 _000182_hash NULL
83815 +_000183_hash dns_query 3 9676 _000183_hash NULL
83816 +_000184_hash dns_resolver_instantiate 3 63314 _000184_hash NULL
83817 +_000185_hash do_add_counters 3 3992 _000185_hash NULL
83818 +_000186_hash __do_config_autodelink 3 58763 _000186_hash NULL
83819 +_000187_hash do_ip_setsockopt 5 41852 _000187_hash NULL
83820 +_000188_hash do_ipv6_setsockopt 5 18215 _000188_hash NULL
83821 +_000189_hash do_ip_vs_set_ctl 4 48641 _000189_hash NULL
83822 +_000190_hash do_kimage_alloc 3 64827 _000190_hash NULL
83823 +_000191_hash do_register_entry 4 29478 _000191_hash NULL
83824 +_000192_hash do_tty_write 5 44896 _000192_hash NULL
83825 +_000193_hash do_update_counters 4 2259 _000193_hash NULL
83826 +_000194_hash dsp_write 2 46218 _000194_hash NULL
83827 +_000195_hash dup_to_netobj 3 26363 _000195_hash NULL
83828 +_000196_hash dwc3_link_state_write 3 12641 _000196_hash NULL
83829 +_000197_hash dwc3_mode_write 3 51997 _000197_hash NULL
83830 +_000198_hash dwc3_testmode_write 3 30516 _000198_hash NULL
83831 +_000199_hash ecryptfs_copy_filename 4 11868 _000199_hash NULL
83832 +_000200_hash ecryptfs_miscdev_write 3 26847 _000200_hash NULL
83833 +_000201_hash ecryptfs_send_miscdev 2 64816 _000201_hash NULL
83834 +_000202_hash efx_tsoh_heap_alloc 2 58545 _000202_hash NULL
83835 +_000203_hash emi26_writememory 4 57908 _000203_hash NULL
83836 +_000204_hash emi62_writememory 4 29731 _000204_hash NULL
83837 +_000205_hash encrypted_instantiate 3 3168 _000205_hash NULL
83838 +_000206_hash encrypted_update 3 13414 _000206_hash NULL
83839 +_000207_hash ep0_write 3 14536 _001422_hash NULL nohasharray
83840 +_000208_hash ep_read 3 58813 _000208_hash NULL
83841 +_000209_hash ep_write 3 59008 _000209_hash NULL
83842 +_000210_hash erst_dbg_write 3 46715 _000210_hash NULL
83843 +_000211_hash esp_alloc_tmp 2-3 40558 _000211_hash NULL
83844 +_000213_hash evdev_do_ioctl 2 24459 _000213_hash NULL
83845 +_000214_hash exofs_read_lookup_dev_table 3 17733 _000214_hash NULL
83846 +_000215_hash ext4_kvmalloc 1 14796 _000215_hash NULL
83847 +_000216_hash ezusb_writememory 4 45976 _000216_hash NULL
83848 +_000217_hash fanotify_write 3 64623 _000217_hash NULL
83849 +_000218_hash fd_copyin 3 56247 _000218_hash NULL
83850 +_000219_hash ffs_epfile_io 3 64886 _000219_hash NULL
83851 +_000220_hash ffs_prepare_buffer 2 59892 _000220_hash NULL
83852 +_000221_hash f_hidg_write 3 7932 _000221_hash NULL
83853 +_000222_hash file_read_actor 4 1401 _000222_hash NULL
83854 +_000223_hash fill_write_buffer 3 3142 _000223_hash NULL
83855 +_000224_hash __find_xattr 6 2117 _002425_hash NULL nohasharray
83856 +_000225_hash fl_create 5 56435 _000225_hash NULL
83857 +_000226_hash fs_path_ensure_buf 2 59445 _000226_hash NULL
83858 +_000227_hash ftdi_elan_write 3 57309 _000227_hash NULL
83859 +_000228_hash fw_iso_buffer_alloc 2 13704 _000228_hash NULL
83860 +_000229_hash garmin_write_bulk 3 58191 _000229_hash NULL
83861 +_000230_hash garp_attr_create 3 3883 _000230_hash NULL
83862 +_000231_hash get_arg 3 5694 _000231_hash NULL
83863 +_000232_hash getdqbuf 1 62908 _000232_hash NULL
83864 +_000233_hash get_fdb_entries 3 41916 _000233_hash NULL
83865 +_000234_hash get_fd_set 1 3866 _000234_hash NULL
83866 +_000235_hash get_indirect_ea 4 51869 _000235_hash NULL
83867 +_000236_hash get_registers 3 26187 _000236_hash NULL
83868 +_000237_hash get_scq 2 10897 _000237_hash NULL
83869 +_000238_hash get_server_iovec 2 16804 _000238_hash NULL
83870 +_000239_hash get_ucode_user 3 38202 _000239_hash NULL
83871 +_000240_hash get_user_cpu_mask 2 14861 _000240_hash NULL
83872 +_000241_hash gfs2_alloc_sort_buffer 1 18275 _000241_hash NULL
83873 +_000242_hash gfs2_glock_nq_m 1 20347 _000242_hash NULL
83874 +_000243_hash gigaset_initcs 2 43753 _000243_hash NULL
83875 +_000244_hash gigaset_initdriver 2 1060 _000244_hash NULL
83876 +_000245_hash groups_alloc 1 7614 _000245_hash NULL
83877 +_000246_hash gs_alloc_req 2 58883 _000246_hash NULL
83878 +_000247_hash gs_buf_alloc 2 25067 _000247_hash NULL
83879 +_000248_hash gsm_data_alloc 3 42437 _000248_hash NULL
83880 +_000249_hash gss_pipe_downcall 3 23182 _000249_hash NULL
83881 +_000250_hash handle_request 9 10024 _000250_hash NULL
83882 +_000251_hash hashtab_create 3 33769 _000251_hash NULL
83883 +_000252_hash hcd_buffer_alloc 2 27495 _000252_hash NULL
83884 +_000253_hash hci_sock_setsockopt 5 28993 _000253_hash NULL
83885 +_000254_hash heap_init 2 49617 _000254_hash NULL
83886 +_000255_hash hest_ghes_dev_register 1 46766 _000255_hash NULL
83887 +_000256_hash hidg_alloc_ep_req 2 10159 _000256_hash NULL
83888 +_000257_hash hid_parse_report 3 51737 _000257_hash NULL
83889 +_000258_hash hidraw_get_report 3 45609 _000258_hash NULL
83890 +_000259_hash hidraw_report_event 3 20503 _000259_hash NULL
83891 +_000260_hash hidraw_send_report 3 23449 _000260_hash NULL
83892 +_000261_hash hpfs_translate_name 3 41497 _000261_hash NULL
83893 +_000262_hash hysdn_conf_write 3 52145 _000262_hash NULL
83894 +_000263_hash __i2400mu_send_barker 3 23652 _000263_hash NULL
83895 +_000264_hash i2cdev_read 3 1206 _000264_hash NULL
83896 +_000265_hash i2cdev_write 3 23310 _000265_hash NULL
83897 +_000266_hash i2o_parm_field_get 5 34477 _000266_hash NULL
83898 +_000267_hash i2o_parm_table_get 6 61635 _000267_hash NULL
83899 +_000268_hash ib_copy_from_udata 3 59502 _000268_hash NULL
83900 +_000269_hash ib_ucm_alloc_data 3 36885 _000269_hash NULL
83901 +_000270_hash ib_umad_write 3 47993 _000270_hash NULL
83902 +_000271_hash ib_uverbs_unmarshall_recv 5 12251 _000271_hash NULL
83903 +_000272_hash icn_writecmd 2 38629 _000272_hash NULL
83904 +_000273_hash ide_driver_proc_write 3 32493 _000273_hash NULL
83905 +_000274_hash ide_settings_proc_write 3 35110 _000274_hash NULL
83906 +_000275_hash idetape_chrdev_write 3 53976 _000275_hash NULL
83907 +_000276_hash idmap_pipe_downcall 3 14591 _000276_hash NULL
83908 +_000277_hash ieee80211_build_probe_req 7-5 27660 _000277_hash NULL
83909 +_000278_hash ieee80211_if_write 3 34894 _000278_hash NULL
83910 +_000279_hash if_write 3 51756 _000279_hash NULL
83911 +_000280_hash ilo_write 3 64378 _000280_hash NULL
83912 +_000281_hash ima_write_policy 3 40548 _000281_hash NULL
83913 +_000282_hash init_data_container 1 60709 _000282_hash NULL
83914 +_000283_hash init_send_hfcd 1 34586 _000283_hash NULL
83915 +_000284_hash insert_dent 7 65034 _000284_hash NULL
83916 +_000285_hash interpret_user_input 2 19393 _000285_hash NULL
83917 +_000286_hash int_proc_write 3 39542 _000286_hash NULL
83918 +_000287_hash ioctl_private_iw_point 7 1273 _000287_hash NULL
83919 +_000288_hash iov_iter_copy_from_user 4 31942 _000288_hash NULL
83920 +_000289_hash iov_iter_copy_from_user_atomic 4 56368 _000289_hash NULL
83921 +_000290_hash iowarrior_write 3 18604 _000290_hash NULL
83922 +_000291_hash ipc_alloc 1 1192 _000291_hash NULL
83923 +_000292_hash ipc_rcu_alloc 1 21208 _000292_hash NULL
83924 +_000293_hash ip_options_get_from_user 4 64958 _000293_hash NULL
83925 +_000294_hash ipv6_renew_option 3 38813 _000294_hash NULL
83926 +_000295_hash ip_vs_conn_fill_param_sync 6 29771 _001898_hash NULL nohasharray
83927 +_000296_hash ip_vs_create_timeout_table 2 64478 _000296_hash NULL
83928 +_000297_hash ipw_queue_tx_init 3 49161 _000297_hash NULL
83929 +_000298_hash irda_setsockopt 5 19824 _000298_hash NULL
83930 +_000299_hash irias_new_octseq_value 2 13596 _003821_hash NULL nohasharray
83931 +_000300_hash irnet_ctrl_write 3 24139 _000300_hash NULL
83932 +_000301_hash isdn_add_channels 3 40905 _000301_hash NULL
83933 +_000302_hash isdn_ppp_fill_rq 2 41428 _000302_hash NULL
83934 +_000303_hash isdn_ppp_write 4 29109 _000303_hash NULL
83935 +_000304_hash isdn_read 3 50021 _000304_hash NULL
83936 +_000305_hash isdn_v110_open 3 2418 _000305_hash NULL
83937 +_000306_hash isdn_writebuf_stub 4 52383 _000306_hash NULL
83938 +_000307_hash islpci_mgt_transmit 5 34133 _000307_hash NULL
83939 +_000308_hash iso_callback 3 43208 _000308_hash NULL
83940 +_000309_hash iso_packets_buffer_init 3-4 29061 _000309_hash NULL
83941 +_000310_hash it821x_firmware_command 3 8628 _000310_hash NULL
83942 +_000311_hash iwch_alloc_fastreg_pbl 2 40153 _000311_hash NULL
83943 +_000312_hash iwl_calib_set 3 34400 _003754_hash NULL nohasharray
83944 +_000313_hash jbd2_journal_init_revoke_table 1 36336 _000313_hash NULL
83945 +_000314_hash jffs2_alloc_full_dirent 1 60179 _001158_hash NULL nohasharray
83946 +_000315_hash journal_init_revoke_table 1 56331 _000315_hash NULL
83947 +_000316_hash kcalloc 1-2 27770 _000316_hash NULL
83948 +_000318_hash keyctl_instantiate_key_common 4 47889 _000318_hash NULL
83949 +_000319_hash keyctl_update_key 3 26061 _000319_hash NULL
83950 +_000320_hash __kfifo_alloc 2-3 22173 _000320_hash NULL
83951 +_000322_hash kfifo_copy_from_user 3 5091 _000322_hash NULL
83952 +_000323_hash kmalloc_node 1 50163 _003818_hash NULL nohasharray
83953 +_000324_hash kmalloc_parameter 1 65279 _000324_hash NULL
83954 +_000325_hash kmem_alloc 1 31920 _000325_hash NULL
83955 +_000326_hash kobj_map 2-3 9566 _000326_hash NULL
83956 +_000328_hash kone_receive 4 4690 _000328_hash NULL
83957 +_000329_hash kone_send 4 63435 _000329_hash NULL
83958 +_000330_hash krealloc 2 14908 _000330_hash NULL
83959 +_000331_hash kvmalloc 1 32646 _000331_hash NULL
83960 +_000332_hash kvm_read_guest_atomic 4 10765 _000332_hash NULL
83961 +_000333_hash kvm_read_guest_cached 4 39666 _000333_hash NULL
83962 +_000334_hash kvm_read_guest_page 5 18074 _000334_hash NULL
83963 +_000335_hash kzalloc 1 54740 _000335_hash NULL
83964 +_000336_hash l2cap_sock_setsockopt 5 50207 _000336_hash NULL
83965 +_000337_hash l2cap_sock_setsockopt_old 4 29346 _000337_hash NULL
83966 +_000338_hash lane2_associate_req 4 45398 _000338_hash NULL
83967 +_000339_hash lbs_debugfs_write 3 48413 _000339_hash NULL
83968 +_000340_hash lcd_write 3 14857 _000340_hash &_000015_hash
83969 +_000341_hash ldm_frag_add 2 5611 _000341_hash NULL
83970 +_000342_hash __lgread 4 31668 _000342_hash NULL
83971 +_000343_hash libipw_alloc_txb 1-3-2 27579 _000343_hash NULL
83972 +_000344_hash link_send_sections_long 4 46556 _000344_hash NULL
83973 +_000345_hash listxattr 3 12769 _000345_hash NULL
83974 +_000346_hash load_msg 2 95 _000346_hash NULL
83975 +_000347_hash lpfc_debugfs_dif_err_write 3 17424 _000347_hash NULL
83976 +_000348_hash lp_write 3 9511 _000348_hash NULL
83977 +_000349_hash mb_cache_create 2 17307 _000349_hash NULL
83978 +_000350_hash mce_write 3 26201 _000350_hash NULL
83979 +_000351_hash mcs7830_get_reg 3 33308 _000351_hash NULL
83980 +_000352_hash mcs7830_set_reg 3 31413 _000352_hash NULL
83981 +_000353_hash memcpy_fromiovec 3 55247 _000353_hash NULL
83982 +_000354_hash memcpy_fromiovecend 3-4 2707 _000354_hash NULL
83983 +_000356_hash mempool_resize 2 47983 _002039_hash NULL nohasharray
83984 +_000357_hash mem_rw 3 22085 _000357_hash NULL
83985 +_000358_hash mgmt_control 3 7349 _000358_hash NULL
83986 +_000359_hash mgmt_pending_add 5 46976 _000359_hash NULL
83987 +_000360_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000360_hash NULL
83988 +_000361_hash mmc_alloc_sg 1 21504 _000361_hash NULL
83989 +_000362_hash mmc_send_bus_test 4 18285 _000362_hash NULL
83990 +_000363_hash mmc_send_cxd_data 5 38655 _000363_hash NULL
83991 +_000364_hash module_alloc_update_bounds 1 47205 _000364_hash NULL
83992 +_000365_hash move_addr_to_kernel 2 32673 _000365_hash NULL
83993 +_000366_hash mpi_alloc_limb_space 1 23190 _000366_hash NULL
83994 +_000367_hash mpi_resize 2 44674 _000367_hash NULL
83995 +_000368_hash mptctl_getiocinfo 2 28545 _000368_hash NULL
83996 +_000369_hash mtdchar_readoob 4 31200 _000369_hash NULL
83997 +_000370_hash mtdchar_write 3 56831 _002122_hash NULL nohasharray
83998 +_000371_hash mtdchar_writeoob 4 3393 _000371_hash NULL
83999 +_000372_hash mtd_device_parse_register 5 5024 _000372_hash NULL
84000 +_000373_hash mtf_test_write 3 18844 _000373_hash NULL
84001 +_000374_hash mthca_alloc_icm_table 3-4 38268 _002459_hash NULL nohasharray
84002 +_000376_hash mthca_alloc_init 2 21754 _000376_hash NULL
84003 +_000377_hash mthca_array_init 2 39987 _000377_hash NULL
84004 +_000378_hash mthca_buf_alloc 2 35861 _000378_hash NULL
84005 +_000379_hash mtrr_write 3 59622 _000379_hash NULL
84006 +_000380_hash musb_test_mode_write 3 33518 _000380_hash NULL
84007 +_000381_hash mwifiex_get_common_rates 3 17131 _000381_hash NULL
84008 +_000382_hash __mxt_write_reg 3 57326 _000382_hash NULL
84009 +_000383_hash nand_bch_init 2-3 16280 _001439_hash NULL nohasharray
84010 +_000385_hash ncp_file_write 3 3813 _000385_hash NULL
84011 +_000386_hash ncp__vol2io 5 4804 _000386_hash NULL
84012 +_000387_hash nes_alloc_fast_reg_page_list 2 33523 _000387_hash NULL
84013 +_000388_hash nfc_targets_found 3 29886 _000388_hash NULL
84014 +_000389_hash __nf_ct_ext_add_length 3 12364 _000389_hash NULL
84015 +_000390_hash nfs4_acl_new 1 49806 _000390_hash NULL
84016 +_000391_hash nfs4_write_cached_acl 4 15070 _000391_hash NULL
84017 +_000392_hash nfsd_symlink 6 63442 _000392_hash NULL
84018 +_000393_hash nfs_idmap_get_desc 2-4 42990 _000393_hash NULL
84019 +_000395_hash nfs_readdir_make_qstr 3 12509 _000395_hash NULL
84020 +_000396_hash note_last_dentry 3 12285 _000396_hash NULL
84021 +_000397_hash ntfs_copy_from_user 3-5 15072 _000397_hash NULL
84022 +_000399_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000399_hash NULL
84023 +_000401_hash ntfs_ucstonls 3-5 23097 _000401_hash NULL
84024 +_000403_hash nvme_alloc_iod 1 56027 _000403_hash NULL
84025 +_000404_hash nvram_write 3 3894 _000404_hash NULL
84026 +_000405_hash o2hb_debug_create 4 18744 _000405_hash NULL
84027 +_000406_hash o2net_send_message_vec 4 879 _002013_hash NULL nohasharray
84028 +_000407_hash ocfs2_control_cfu 2 37750 _000407_hash NULL
84029 +_000408_hash oom_adjust_write 3 41116 _000408_hash NULL
84030 +_000409_hash oom_score_adj_write 3 42594 _000409_hash NULL
84031 +_000410_hash oprofilefs_ulong_from_user 3 57251 _000410_hash NULL
84032 +_000411_hash opticon_write 4 60775 _000411_hash NULL
84033 +_000412_hash p9_check_zc_errors 4 15534 _000412_hash NULL
84034 +_000413_hash packet_buffer_init 2 1607 _000413_hash NULL
84035 +_000414_hash packet_setsockopt 5 17662 _000414_hash NULL
84036 +_000415_hash parse_command 2 37079 _000415_hash NULL
84037 +_000416_hash pcbit_writecmd 2 12332 _000416_hash NULL
84038 +_000417_hash pcmcia_replace_cis 3 57066 _000417_hash NULL
84039 +_000418_hash pgctrl_write 3 50453 _000418_hash NULL
84040 +_000419_hash pg_write 3 40766 _000419_hash NULL
84041 +_000420_hash pidlist_allocate 1 64404 _000420_hash NULL
84042 +_000421_hash pipe_iov_copy_from_user 3 23102 _000421_hash NULL
84043 +_000422_hash pipe_iov_copy_to_user 3 3447 _000422_hash NULL
84044 +_000423_hash pkt_add 3 39897 _000423_hash NULL
84045 +_000424_hash pktgen_if_write 3 55628 _000424_hash NULL
84046 +_000425_hash platform_device_add_data 3 310 _000425_hash NULL
84047 +_000426_hash platform_device_add_resources 3 13289 _000426_hash NULL
84048 +_000427_hash pmcraid_copy_sglist 3 38431 _000427_hash NULL
84049 +_000428_hash pm_qos_power_write 3 52513 _000428_hash NULL
84050 +_000429_hash pnpbios_proc_write 3 19758 _000429_hash NULL
84051 +_000430_hash pool_allocate 3 42012 _000430_hash NULL
84052 +_000431_hash posix_acl_alloc 1 48063 _000431_hash NULL
84053 +_000432_hash ppp_cp_parse_cr 4 5214 _000432_hash NULL
84054 +_000433_hash ppp_write 3 34034 _000433_hash NULL
84055 +_000434_hash pp_read 3 33210 _000434_hash NULL
84056 +_000435_hash pp_write 3 39554 _000435_hash NULL
84057 +_000436_hash printer_req_alloc 2 62687 _000436_hash NULL
84058 +_000437_hash printer_write 3 60276 _000437_hash NULL
84059 +_000438_hash prism2_info_scanresults 3 59729 _000438_hash NULL
84060 +_000439_hash prism2_set_genericelement 3 29277 _000439_hash NULL
84061 +_000440_hash __probe_kernel_read 3 61119 _000440_hash NULL
84062 +_000441_hash __probe_kernel_write 3 29842 _000441_hash NULL
84063 +_000442_hash proc_coredump_filter_write 3 25625 _000442_hash NULL
84064 +_000443_hash _proc_do_string 2 6376 _000443_hash NULL
84065 +_000444_hash process_vm_rw_pages 5-6 15954 _000444_hash NULL
84066 +_000446_hash proc_loginuid_write 3 63648 _000446_hash NULL
84067 +_000447_hash proc_pid_attr_write 3 63845 _000447_hash NULL
84068 +_000448_hash proc_scsi_devinfo_write 3 32064 _000448_hash NULL
84069 +_000449_hash proc_scsi_write 3 29142 _000449_hash NULL
84070 +_000450_hash proc_scsi_write_proc 3 267 _000450_hash NULL
84071 +_000451_hash pskb_expand_head 2-3 42881 _000451_hash NULL
84072 +_000453_hash pstore_mkfile 5 50830 _000453_hash NULL
84073 +_000454_hash pti_char_write 3 60960 _000454_hash NULL
84074 +_000455_hash ptrace_writedata 4 45021 _000455_hash NULL
84075 +_000456_hash pt_write 3 40159 _000456_hash NULL
84076 +_000457_hash qdisc_class_hash_alloc 1 18262 _000457_hash NULL
84077 +_000458_hash r3964_write 4 57662 _000458_hash NULL
84078 +_000459_hash raw_seticmpfilter 3 6888 _000459_hash NULL
84079 +_000460_hash raw_setsockopt 5 45800 _000460_hash NULL
84080 +_000461_hash rawv6_seticmpfilter 5 12137 _000461_hash NULL
84081 +_000462_hash ray_cs_essid_proc_write 3 17875 _000462_hash NULL
84082 +_000463_hash rbd_add 3 16366 _000463_hash NULL
84083 +_000464_hash rbd_snap_add 4 19678 _000464_hash NULL
84084 +_000465_hash rdma_set_ib_paths 3 45592 _000465_hash NULL
84085 +_000466_hash rds_page_copy_user 4 35691 _000466_hash NULL
84086 +_000467_hash read 3 9397 _000467_hash NULL
84087 +_000468_hash read_buf 2 20469 _000468_hash NULL
84088 +_000469_hash read_cis_cache 4 29735 _000469_hash NULL
84089 +_000470_hash realloc_buffer 2 25816 _000470_hash NULL
84090 +_000471_hash receive_DataRequest 3 9904 _000471_hash NULL
84091 +_000472_hash recent_mt_proc_write 3 8206 _000472_hash NULL
84092 +_000473_hash regmap_access_read_file 3 37223 _000473_hash NULL
84093 +_000474_hash regmap_bulk_write 4 59049 _000474_hash NULL
84094 +_000475_hash regmap_map_read_file 3 37685 _000475_hash NULL
84095 +_000476_hash regset_tls_set 4 18459 _000476_hash NULL
84096 +_000477_hash reiserfs_add_entry 4 23062 _002792_hash NULL nohasharray
84097 +_000478_hash remote_settings_file_write 3 22987 _000478_hash NULL
84098 +_000479_hash request_key_auth_new 3 38092 _000479_hash NULL
84099 +_000480_hash restore_i387_fxsave 2 17528 _000480_hash NULL
84100 +_000481_hash revalidate 2 19043 _000481_hash NULL
84101 +_000482_hash rfcomm_sock_setsockopt 5 18254 _000482_hash NULL
84102 +_000483_hash rndis_add_response 2 58544 _000483_hash NULL
84103 +_000484_hash rndis_set_oid 4 6547 _000484_hash NULL
84104 +_000485_hash rngapi_reset 3 34366 _002137_hash NULL nohasharray
84105 +_000486_hash roccat_common2_receive 4 50369 _000486_hash NULL
84106 +_000487_hash roccat_common2_send 4 2422 _000487_hash NULL
84107 +_000488_hash rpc_malloc 2 43573 _000488_hash NULL
84108 +_000489_hash rt2x00debug_write_bbp 3 8212 _000489_hash NULL
84109 +_000490_hash rt2x00debug_write_csr 3 64753 _000490_hash NULL
84110 +_000491_hash rt2x00debug_write_eeprom 3 23091 _000491_hash NULL
84111 +_000492_hash rt2x00debug_write_rf 3 38195 _000492_hash NULL
84112 +_000493_hash rt2x00debug_write_rfcsr 3 41473 _000493_hash NULL
84113 +_000494_hash rts51x_read_mem 4 26577 _002730_hash NULL nohasharray
84114 +_000495_hash rts51x_read_status 4 11830 _000495_hash NULL
84115 +_000496_hash rts51x_write_mem 4 17598 _000496_hash NULL
84116 +_000497_hash rw_copy_check_uvector 3 45748 _003716_hash NULL nohasharray
84117 +_000498_hash rxrpc_request_key 3 27235 _000498_hash NULL
84118 +_000499_hash rxrpc_server_keyring 3 16431 _000499_hash NULL
84119 +_000500_hash savemem 3 58129 _000500_hash NULL
84120 +_000501_hash sb16_copy_from_user 10-7-6 55836 _000501_hash NULL
84121 +_000504_hash sched_autogroup_write 3 10984 _000504_hash NULL
84122 +_000505_hash scsi_mode_select 6 37330 _000505_hash NULL
84123 +_000506_hash scsi_tgt_copy_sense 3 26933 _000506_hash NULL
84124 +_000507_hash sctp_auth_create_key 1 51641 _000507_hash NULL
84125 +_000508_hash sctp_getsockopt_delayed_ack 2 9232 _000508_hash NULL
84126 +_000509_hash sctp_getsockopt_local_addrs 2 25178 _000509_hash NULL
84127 +_000510_hash sctp_make_abort_user 3 29654 _000510_hash NULL
84128 +_000511_hash sctp_setsockopt_active_key 3 43755 _000511_hash NULL
84129 +_000512_hash sctp_setsockopt_adaptation_layer 3 26935 _003246_hash NULL nohasharray
84130 +_000513_hash sctp_setsockopt_associnfo 3 51684 _000513_hash NULL
84131 +_000514_hash sctp_setsockopt_auth_chunk 3 30843 _000514_hash NULL
84132 +_000515_hash sctp_setsockopt_auth_key 3 3793 _000515_hash NULL
84133 +_000516_hash sctp_setsockopt_autoclose 3 5775 _000516_hash NULL
84134 +_000517_hash sctp_setsockopt_bindx 3 49870 _000517_hash NULL
84135 +_000518_hash __sctp_setsockopt_connectx 3 46949 _000518_hash NULL
84136 +_000519_hash sctp_setsockopt_context 3 31091 _000519_hash NULL
84137 +_000520_hash sctp_setsockopt_default_send_param 3 49578 _000520_hash NULL
84138 +_000521_hash sctp_setsockopt_delayed_ack 3 40129 _000521_hash NULL
84139 +_000522_hash sctp_setsockopt_del_key 3 42304 _002709_hash NULL nohasharray
84140 +_000523_hash sctp_setsockopt_events 3 18862 _000523_hash NULL
84141 +_000524_hash sctp_setsockopt_hmac_ident 3 11687 _000524_hash NULL
84142 +_000525_hash sctp_setsockopt_initmsg 3 1383 _000525_hash NULL
84143 +_000526_hash sctp_setsockopt_maxburst 3 28041 _000526_hash NULL
84144 +_000527_hash sctp_setsockopt_maxseg 3 11829 _000527_hash NULL
84145 +_000528_hash sctp_setsockopt_peer_addr_params 3 734 _000528_hash NULL
84146 +_000529_hash sctp_setsockopt_peer_primary_addr 3 13440 _000529_hash NULL
84147 +_000530_hash sctp_setsockopt_rtoinfo 3 30941 _000530_hash NULL
84148 +_000531_hash security_context_to_sid_core 2 29248 _000531_hash NULL
84149 +_000532_hash sel_commit_bools_write 3 46077 _000532_hash NULL
84150 +_000533_hash sel_write_avc_cache_threshold 3 2256 _000533_hash NULL
84151 +_000534_hash sel_write_bool 3 46996 _000534_hash NULL
84152 +_000535_hash sel_write_checkreqprot 3 60774 _000535_hash NULL
84153 +_000536_hash sel_write_disable 3 10511 _000536_hash NULL
84154 +_000537_hash sel_write_enforce 3 48998 _000537_hash NULL
84155 +_000538_hash sel_write_load 3 63830 _000538_hash NULL
84156 +_000539_hash send_bulk_static_data 3 61932 _000539_hash NULL
84157 +_000540_hash set_aoe_iflist 2 42737 _000540_hash NULL
84158 +_000541_hash setkey_unaligned 3 39474 _000541_hash NULL
84159 +_000542_hash set_registers 3 53582 _000542_hash NULL
84160 +_000543_hash setsockopt 5 54539 _000543_hash NULL
84161 +_000544_hash setup_req 3 5848 _000544_hash NULL
84162 +_000545_hash setxattr 4 37006 _000545_hash NULL
84163 +_000546_hash sfq_alloc 1 2861 _000546_hash NULL
84164 +_000547_hash sg_kmalloc 1 50240 _000547_hash NULL
84165 +_000548_hash sgl_map_user_pages 2 30610 _000548_hash NULL
84166 +_000549_hash shash_setkey_unaligned 3 8620 _000549_hash NULL
84167 +_000550_hash shmem_xattr_alloc 2 61190 _000550_hash NULL
84168 +_000551_hash sierra_setup_urb 5 46029 _000551_hash NULL
84169 +_000552_hash simple_transaction_get 3 50633 _000552_hash NULL
84170 +_000553_hash simple_write_to_buffer 2-5 3122 _000553_hash NULL
84171 +_000555_hash sisusb_send_bulk_msg 3 17864 _000555_hash NULL
84172 +_000556_hash skb_add_data 3 48363 _000556_hash NULL
84173 +_000557_hash skb_do_copy_data_nocache 5 12465 _000557_hash NULL
84174 +_000558_hash sl_alloc_bufs 2 50380 _000558_hash NULL
84175 +_000559_hash sl_realloc_bufs 2 64086 _000559_hash NULL
84176 +_000560_hash smk_set_cipso 3 20379 _000560_hash NULL
84177 +_000561_hash smk_write_ambient 3 45691 _000561_hash NULL
84178 +_000562_hash smk_write_direct 3 46363 _000562_hash NULL
84179 +_000563_hash smk_write_doi 3 49621 _000563_hash NULL
84180 +_000564_hash smk_write_logging 3 2618 _000564_hash NULL
84181 +_000565_hash smk_write_mapped 3 13519 _000565_hash NULL
84182 +_000566_hash smk_write_netlbladdr 3 42525 _000566_hash NULL
84183 +_000567_hash smk_write_onlycap 3 14400 _000567_hash NULL
84184 +_000568_hash smk_write_rules_list 3 18565 _000568_hash NULL
84185 +_000569_hash snd_ctl_elem_user_tlv 3 11695 _000569_hash NULL
84186 +_000570_hash snd_emu10k1_fx8010_read 5 9605 _000570_hash NULL
84187 +_000571_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000571_hash NULL
84188 +_000573_hash snd_gus_dram_poke 4 18525 _000573_hash NULL
84189 +_000574_hash snd_hdsp_playback_copy 5 20676 _000574_hash NULL
84190 +_000575_hash snd_info_entry_write 3 63474 _000575_hash NULL
84191 +_000576_hash snd_korg1212_copy_from 6 36169 _000576_hash NULL
84192 +_000577_hash snd_mem_proc_write 3 9786 _000577_hash NULL
84193 +_000578_hash snd_midi_channel_init_set 1 30092 _000578_hash NULL
84194 +_000579_hash snd_midi_event_new 1 9893 _000764_hash NULL nohasharray
84195 +_000580_hash snd_opl4_mem_proc_write 5 9670 _000580_hash NULL
84196 +_000581_hash snd_pcm_aio_read 3 13900 _000581_hash NULL
84197 +_000582_hash snd_pcm_aio_write 3 28738 _000582_hash NULL
84198 +_000583_hash snd_pcm_oss_write1 3 10872 _000583_hash NULL
84199 +_000584_hash snd_pcm_oss_write2 3 27332 _000584_hash NULL
84200 +_000585_hash snd_rawmidi_kernel_write1 4 56847 _000585_hash NULL
84201 +_000586_hash snd_rme9652_playback_copy 5 20970 _000586_hash NULL
84202 +_000587_hash snd_sb_csp_load_user 3 45190 _000587_hash NULL
84203 +_000588_hash snd_usb_ctl_msg 8 8436 _000588_hash NULL
84204 +_000589_hash sock_bindtodevice 3 50942 _000589_hash NULL
84205 +_000590_hash sock_kmalloc 2 62205 _000590_hash NULL
84206 +_000591_hash spidev_ioctl 2 12846 _000591_hash NULL
84207 +_000592_hash spidev_write 3 44510 _000592_hash NULL
84208 +_000593_hash squashfs_read_table 3 16945 _000593_hash NULL
84209 +_000594_hash srpt_alloc_ioctx 2-3 51042 _000594_hash NULL
84210 +_000596_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000596_hash NULL
84211 +_000597_hash st5481_setup_isocpipes 6-4 61340 _000597_hash NULL
84212 +_000598_hash sta_agg_status_write 3 45164 _000598_hash NULL
84213 +_000599_hash svc_setsockopt 5 36876 _000599_hash NULL
84214 +_000600_hash sys_add_key 4 61288 _000600_hash NULL
84215 +_000601_hash sys_modify_ldt 3 18824 _000601_hash NULL
84216 +_000602_hash sys_semtimedop 3 4486 _000602_hash NULL
84217 +_000603_hash sys_setdomainname 2 4373 _000603_hash NULL
84218 +_000604_hash sys_sethostname 2 42962 _000604_hash NULL
84219 +_000605_hash tomoyo_write_self 3 45161 _000605_hash NULL
84220 +_000606_hash tower_write 3 8580 _000606_hash NULL
84221 +_000607_hash tpm_write 3 50798 _000607_hash NULL
84222 +_000608_hash trusted_instantiate 3 4710 _000608_hash NULL
84223 +_000609_hash trusted_update 3 12664 _000609_hash NULL
84224 +_000610_hash tty_buffer_alloc 2 45437 _000610_hash NULL
84225 +_000611_hash __tun_chr_ioctl 4 22300 _000611_hash NULL
84226 +_000612_hash ubi_more_leb_change_data 4 63534 _000612_hash NULL
84227 +_000613_hash ubi_more_update_data 4 39189 _000613_hash NULL
84228 +_000614_hash ubi_resize_volume 2 50172 _000614_hash NULL
84229 +_000615_hash udf_alloc_i_data 2 35786 _000615_hash NULL
84230 +_000616_hash uea_idma_write 3 64139 _000616_hash NULL
84231 +_000617_hash uea_request 4 47613 _000617_hash NULL
84232 +_000618_hash uea_send_modem_cmd 3 3888 _000618_hash NULL
84233 +_000619_hash uio_write 3 43202 _000619_hash NULL
84234 +_000620_hash um_idi_write 3 18293 _000620_hash NULL
84235 +_000621_hash us122l_ctl_msg 8 13330 _000621_hash NULL
84236 +_000622_hash usb_alloc_urb 1 43436 _000622_hash NULL
84237 +_000623_hash usblp_new_writeurb 2 22894 _000623_hash NULL
84238 +_000624_hash usblp_write 3 23178 _000624_hash NULL
84239 +_000625_hash usbtest_alloc_urb 3-5 34446 _000625_hash NULL
84240 +_000627_hash usbtmc_write 3 64340 _000627_hash NULL
84241 +_000628_hash user_instantiate 3 26131 _000628_hash NULL
84242 +_000629_hash user_update 3 41332 _000629_hash NULL
84243 +_000630_hash uwb_rc_cmd_done 4 35892 _000630_hash NULL
84244 +_000631_hash uwb_rc_neh_grok_event 3 55799 _000631_hash NULL
84245 +_000632_hash v9fs_alloc_rdir_buf 2 42150 _000632_hash NULL
84246 +_000633_hash vc_do_resize 3-4 48842 _000633_hash NULL
84247 +_000635_hash vcs_write 3 3910 _000635_hash NULL
84248 +_000636_hash vga_arb_write 3 36112 _000636_hash NULL
84249 +_000637_hash vga_switcheroo_debugfs_write 3 33984 _000637_hash NULL
84250 +_000638_hash vhci_get_user 3 45039 _000638_hash NULL
84251 +_000639_hash video_proc_write 3 6724 _000639_hash NULL
84252 +_000640_hash vlsi_alloc_ring 3-4 57003 _000640_hash NULL
84253 +_000642_hash __vmalloc 1 61168 _000642_hash NULL
84254 +_000643_hash vmalloc_32 1 1135 _000643_hash NULL
84255 +_000644_hash vmalloc_32_user 1 37519 _000644_hash NULL
84256 +_000645_hash vmalloc_exec 1 36132 _000645_hash NULL
84257 +_000646_hash vmalloc_node 1 58700 _000646_hash NULL
84258 +_000647_hash __vmalloc_node_flags 1 30352 _000647_hash NULL
84259 +_000648_hash vmalloc_user 1 32308 _000648_hash NULL
84260 +_000649_hash vol_cdev_direct_write 3 20751 _000649_hash NULL
84261 +_000650_hash vp_request_msix_vectors 2 28849 _000650_hash NULL
84262 +_000651_hash vring_add_indirect 3-4 20737 _000651_hash NULL
84263 +_000653_hash vring_new_virtqueue 1 9671 _000653_hash NULL
84264 +_000654_hash vxge_os_dma_malloc 2 46184 _000654_hash NULL
84265 +_000655_hash vxge_os_dma_malloc_async 3 56348 _000655_hash NULL
84266 +_000656_hash wdm_write 3 53735 _000656_hash NULL
84267 +_000657_hash wiimote_hid_send 3 48528 _000657_hash NULL
84268 +_000658_hash wlc_phy_loadsampletable_nphy 3 64367 _000658_hash NULL
84269 +_000659_hash write 3 62671 _000659_hash NULL
84270 +_000660_hash write_flush 3 50803 _000660_hash NULL
84271 +_000661_hash write_rio 3 54837 _000661_hash NULL
84272 +_000662_hash x25_asy_change_mtu 2 26928 _000662_hash NULL
84273 +_000663_hash xdi_copy_from_user 4 8395 _000663_hash NULL
84274 +_000664_hash xfrm_dst_alloc_copy 3 3034 _000664_hash NULL
84275 +_000665_hash xfrm_user_policy 4 62573 _000665_hash NULL
84276 +_000666_hash xfs_attrmulti_attr_set 4 59346 _000666_hash NULL
84277 +_000667_hash xfs_handle_to_dentry 3 12135 _000667_hash NULL
84278 +_000668_hash xip_file_read 3 58592 _000668_hash NULL
84279 +_000669_hash __xip_file_write 3-4 2733 _000669_hash NULL
84280 +_000671_hash xprt_rdma_allocate 2 31372 _000671_hash NULL
84281 +_000672_hash zd_usb_iowrite16v_async 3 23984 _000672_hash NULL
84282 +_000673_hash zd_usb_read_fw 4 22049 _000673_hash NULL
84283 +_000674_hash zerocopy_sg_from_iovec 3 11828 _000674_hash NULL
84284 +_000675_hash __a2mp_build 3 60987 _000675_hash NULL
84285 +_000677_hash acpi_ex_allocate_name_string 2-1 7685 _001169_hash NULL nohasharray
84286 +_000678_hash acpi_os_allocate_zeroed 1 37422 _000678_hash NULL
84287 +_000679_hash acpi_ut_initialize_buffer 2 47143 _002830_hash NULL nohasharray
84288 +_000680_hash ad7879_spi_xfer 3 36311 _000680_hash NULL
84289 +_000681_hash add_new_gdb 3 27643 _000681_hash NULL
84290 +_000682_hash add_numbered_child 5 14273 _000682_hash NULL
84291 +_000683_hash add_res_range 4 21310 _000683_hash NULL
84292 +_000684_hash addtgt 3 54703 _000684_hash NULL
84293 +_000685_hash add_uuid 4 49831 _000685_hash NULL
84294 +_000686_hash afs_cell_alloc 2 24052 _000686_hash NULL
84295 +_000687_hash aggr_recv_addba_req_evt 4 38037 _000687_hash NULL
84296 +_000688_hash agp_create_memory 1 1075 _000688_hash NULL
84297 +_000689_hash agp_create_user_memory 1 62955 _000689_hash NULL
84298 +_000690_hash alg_setsockopt 5 20985 _000690_hash NULL
84299 +_000691_hash alloc_async 1 14208 _000691_hash NULL
84300 +_000692_hash ___alloc_bootmem_nopanic 1 53626 _000692_hash NULL
84301 +_000693_hash alloc_buf 1 34532 _000693_hash NULL
84302 +_000694_hash alloc_chunk 1 49575 _000694_hash NULL
84303 +_000695_hash alloc_context 1 41283 _000695_hash NULL
84304 +_000696_hash alloc_ctrl_packet 1 44667 _000696_hash NULL
84305 +_000697_hash alloc_data_packet 1 46698 _000697_hash NULL
84306 +_000698_hash alloc_dca_provider 2 59670 _000698_hash NULL
84307 +_000699_hash __alloc_dev_table 2 54343 _000699_hash NULL
84308 +_000700_hash alloc_ep 1 17269 _000700_hash NULL
84309 +_000701_hash __alloc_extent_buffer 3 15093 _000701_hash NULL
84310 +_000702_hash alloc_group_attrs 2 9194 _000727_hash NULL nohasharray
84311 +_000703_hash alloc_large_system_hash 2 22391 _000703_hash NULL
84312 +_000704_hash alloc_netdev_mqs 1 30030 _000704_hash NULL
84313 +_000705_hash __alloc_objio_seg 1 7203 _000705_hash NULL
84314 +_000706_hash alloc_ring 2-4 15345 _000706_hash NULL
84315 +_000707_hash alloc_ring 2-4 39151 _000707_hash NULL
84316 +_000710_hash alloc_session 1-2 64171 _000710_hash NULL
84317 +_000714_hash alloc_skb 1 55439 _000714_hash NULL
84318 +_000715_hash alloc_skb_fclone 1 3467 _000715_hash NULL
84319 +_000716_hash alloc_smp_req 1 51337 _000716_hash NULL
84320 +_000717_hash alloc_smp_resp 1 3566 _000717_hash NULL
84321 +_000718_hash alloc_ts_config 1 45775 _000718_hash NULL
84322 +_000719_hash alloc_upcall 2 62186 _000719_hash NULL
84323 +_000720_hash altera_drscan 2 48698 _000720_hash NULL
84324 +_000721_hash altera_irscan 2 62396 _000721_hash NULL
84325 +_000722_hash altera_set_dr_post 2 54291 _000722_hash NULL
84326 +_000723_hash altera_set_dr_pre 2 64862 _000723_hash NULL
84327 +_000724_hash altera_set_ir_post 2 20948 _000724_hash NULL
84328 +_000725_hash altera_set_ir_pre 2 54103 _000725_hash NULL
84329 +_000726_hash altera_swap_dr 2 50090 _000726_hash NULL
84330 +_000727_hash altera_swap_ir 2 9194 _000727_hash &_000702_hash
84331 +_000728_hash amd_create_gatt_pages 1 20537 _000728_hash NULL
84332 +_000729_hash aoechr_write 3 62883 _003674_hash NULL nohasharray
84333 +_000730_hash applesmc_create_nodes 2 49392 _000730_hash NULL
84334 +_000731_hash array_zalloc 1-2 7519 _000731_hash NULL
84335 +_000733_hash arvo_sysfs_read 6 31617 _000733_hash NULL
84336 +_000734_hash arvo_sysfs_write 6 3311 _000734_hash NULL
84337 +_000735_hash asd_store_update_bios 4 10165 _000735_hash NULL
84338 +_000736_hash ata_host_alloc 2 46094 _000736_hash NULL
84339 +_000737_hash atalk_sendmsg 4 21677 _000737_hash NULL
84340 +_000738_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000738_hash NULL
84341 +_000739_hash ath6kl_mgmt_tx 9 21153 _000739_hash NULL
84342 +_000740_hash ath6kl_wmi_proc_events_vif 5 42549 _003190_hash NULL nohasharray
84343 +_000741_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000741_hash NULL
84344 +_000742_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000742_hash NULL
84345 +_000743_hash ath_descdma_setup 5 12257 _000743_hash NULL
84346 +_000744_hash ath_rx_edma_init 2 65483 _000744_hash NULL
84347 +_000745_hash ati_create_gatt_pages 1 4722 _003275_hash NULL nohasharray
84348 +_000746_hash audit_expand 2 2098 _000746_hash NULL
84349 +_000747_hash audit_init_entry 1 38644 _000747_hash NULL
84350 +_000748_hash ax25_sendmsg 4 62770 _000748_hash NULL
84351 +_000749_hash b1_alloc_card 1 36155 _000749_hash NULL
84352 +_000750_hash b43_nphy_load_samples 3 36481 _000750_hash NULL
84353 +_000751_hash batadv_orig_hash_add_if 2 10033 _000751_hash NULL
84354 +_000752_hash batadv_orig_hash_del_if 2 48972 _000752_hash NULL
84355 +_000753_hash batadv_tt_append_diff 4 20588 _000753_hash NULL
84356 +_000754_hash batadv_tt_commit_changes 4 2008 _000754_hash NULL
84357 +_000755_hash batadv_tt_prepare_packet_buff 4 1280 _000755_hash NULL
84358 +_000756_hash bio_copy_user_iov 4 37660 _000756_hash NULL
84359 +_000757_hash __bio_map_kern 3 47379 _000757_hash NULL
84360 +_000758_hash bitmap_resize 2 33054 _000758_hash NULL
84361 +_000759_hash blk_check_plugged 3 50736 _000759_hash NULL
84362 +_000760_hash blk_register_region 1-2 51424 _000760_hash NULL
84363 +_000762_hash bm_entry_write 3 28338 _000762_hash NULL
84364 +_000763_hash bm_realloc_pages 2 9431 _000763_hash NULL
84365 +_000764_hash bm_register_write 3 9893 _000764_hash &_000579_hash
84366 +_000765_hash bm_status_write 3 12964 _000765_hash NULL
84367 +_000766_hash br_mdb_rehash 2 42643 _000766_hash NULL
84368 +_000767_hash btmrvl_sdio_host_to_card 3 12152 _000767_hash NULL
84369 +_000768_hash btrfs_copy_from_user 1-3 43806 _000768_hash NULL
84370 +_000770_hash btrfs_insert_delayed_dir_index 4 63720 _000770_hash NULL
84371 +_000771_hash __btrfs_map_block 3 49839 _000771_hash NULL
84372 +_000772_hash c4iw_init_resource 2-3 30393 _000772_hash NULL
84373 +_000774_hash cache_downcall 3 13666 _000774_hash NULL
84374 +_000775_hash cache_slow_downcall 2 8570 _000775_hash NULL
84375 +_000776_hash caif_seqpkt_sendmsg 4 22961 _000776_hash NULL
84376 +_000777_hash caif_stream_sendmsg 4 9110 _000777_hash NULL
84377 +_000778_hash carl9170_cmd_buf 3 950 _000778_hash NULL
84378 +_000779_hash cdev_add 2-3 38176 _000779_hash NULL
84379 +_000781_hash cdrom_read_cdda 4 50478 _000781_hash NULL
84380 +_000782_hash ceph_dns_resolve_name 2 62488 _000782_hash NULL
84381 +_000783_hash ceph_msgpool_get 2 54258 _000783_hash NULL
84382 +_000784_hash cfg80211_connect_result 4-6 56515 _000784_hash NULL
84383 +_000786_hash cfg80211_disconnected 4 57 _000786_hash NULL
84384 +_000787_hash cfg80211_inform_bss 8 19332 _000787_hash NULL
84385 +_000788_hash cfg80211_inform_bss_frame 4 41078 _000788_hash NULL
84386 +_000789_hash cfg80211_mlme_register_mgmt 5 19852 _000789_hash NULL
84387 +_000790_hash cfg80211_roamed_bss 4-6 50198 _000790_hash NULL
84388 +_000792_hash cgroup_file_write 3 52417 _000792_hash NULL
84389 +_000793_hash cifs_readdata_alloc 1 26360 _000793_hash NULL
84390 +_000794_hash cifs_readv_from_socket 3 19109 _000794_hash NULL
84391 +_000795_hash cifs_writedata_alloc 1 32880 _003097_hash NULL nohasharray
84392 +_000796_hash cnic_alloc_dma 3 34641 _000796_hash NULL
84393 +_000797_hash cnic_init_id_tbl 2 41354 _000797_hash NULL
84394 +_000798_hash configfs_write_file 3 61621 _000798_hash NULL
84395 +_000799_hash construct_key 3 11329 _000799_hash NULL
84396 +_000800_hash context_alloc 3 24645 _000800_hash NULL
84397 +_000801_hash copy_to_user 3 57835 _000801_hash NULL
84398 +_000802_hash cp210x_get_config 4 56229 _000802_hash NULL
84399 +_000803_hash create_attr_set 1 22861 _000803_hash NULL
84400 +_000804_hash create_bounce_buffer 3 39155 _000804_hash NULL
84401 +_000805_hash create_gpadl_header 2 19064 _000805_hash NULL
84402 +_000806_hash _create_sg_bios 4 31244 _000806_hash NULL
84403 +_000807_hash cryptd_alloc_instance 2-3 18048 _000807_hash NULL
84404 +_000809_hash crypto_ahash_setkey 3 55134 _000809_hash NULL
84405 +_000810_hash crypto_alloc_instance2 3 25277 _000810_hash NULL
84406 +_000811_hash crypto_shash_setkey 3 60483 _000811_hash NULL
84407 +_000812_hash cxgb_alloc_mem 1 24007 _000812_hash NULL
84408 +_000813_hash cxgbi_device_portmap_create 3 25747 _000813_hash NULL
84409 +_000814_hash cxgbi_device_register 1-2 36746 _000814_hash NULL
84410 +_000816_hash __cxio_init_resource_fifo 3 23447 _000816_hash NULL
84411 +_000817_hash dccp_sendmsg 4 56058 _000817_hash NULL
84412 +_000818_hash ddp_make_gl 1 12179 _000818_hash NULL
84413 +_000819_hash depth_write 3 3021 _000819_hash NULL
84414 +_000820_hash dev_irnet_write 3 11398 _000820_hash NULL
84415 +_000821_hash dev_set_alias 3 50084 _000821_hash NULL
84416 +_000822_hash dev_write 3 7708 _000822_hash NULL
84417 +_000823_hash dfs_global_file_write 3 6112 _000823_hash NULL
84418 +_000824_hash dgram_sendmsg 4 45679 _000824_hash NULL
84419 +_000825_hash disconnect 4 32521 _000825_hash NULL
84420 +_000826_hash dma_attach 6-7 50831 _000826_hash NULL
84421 +_000828_hash dma_declare_coherent_memory 4-2 14244 _000828_hash NULL
84422 +_000829_hash dn_sendmsg 4 38390 _000829_hash NULL
84423 +_000830_hash dn_setsockopt 5 314 _000830_hash NULL
84424 +_000831_hash do_arpt_set_ctl 4 51053 _000831_hash NULL
84425 +_000832_hash do_dccp_setsockopt 5 54377 _003195_hash NULL nohasharray
84426 +_000833_hash do_ip6t_set_ctl 4 60040 _000833_hash NULL
84427 +_000834_hash do_ipt_set_ctl 4 56238 _000834_hash NULL
84428 +_000835_hash do_jffs2_setxattr 5 25910 _000835_hash NULL
84429 +_000836_hash do_msgsnd 4 1387 _000836_hash NULL
84430 +_000837_hash do_pselect 1 62061 _000837_hash NULL
84431 +_000838_hash do_raw_setsockopt 5 55215 _000838_hash NULL
84432 +_000839_hash do_readv_writev 4 51849 _000839_hash NULL
84433 +_000840_hash do_sync 1 9604 _000840_hash NULL
84434 +_000841_hash dup_array 3 33551 _000841_hash NULL
84435 +_000842_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000842_hash NULL
84436 +_000843_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000843_hash NULL
84437 +_000844_hash ecryptfs_send_message_locked 2 31801 _000844_hash NULL
84438 +_000845_hash edac_device_alloc_ctl_info 1 5941 _000845_hash NULL
84439 +_000846_hash edac_mc_alloc 4 3611 _000846_hash NULL
84440 +_000847_hash edac_pci_alloc_ctl_info 1 63388 _000847_hash NULL
84441 +_000848_hash efivar_create_sysfs_entry 2 19485 _000848_hash NULL
84442 +_000849_hash enable_write 3 30456 _000849_hash NULL
84443 +_000850_hash enclosure_register 3 57412 _000850_hash NULL
84444 +_000851_hash enlarge_skb 2 44248 _002839_hash NULL nohasharray
84445 +_000852_hash evdev_ioctl_handler 2 21705 _000852_hash NULL
84446 +_000853_hash ext4_kvzalloc 1 47605 _000853_hash NULL
84447 +_000854_hash extend_netdev_table 2 21453 _000854_hash NULL
84448 +_000855_hash fcoe_ctlr_device_add 3 1793 _000855_hash NULL
84449 +_000856_hash fd_do_readv 3 51297 _000856_hash NULL
84450 +_000857_hash fd_do_writev 3 29329 _000857_hash NULL
84451 +_000858_hash __feat_register_sp 6 64712 _000858_hash NULL
84452 +_000859_hash __ffs_ep0_read_events 3 48868 _000859_hash NULL
84453 +_000860_hash ffs_ep0_write 3 9438 _000860_hash NULL
84454 +_000861_hash ffs_epfile_read 3 18775 _000861_hash NULL
84455 +_000862_hash ffs_epfile_write 3 48014 _000862_hash NULL
84456 +_000863_hash fib_info_hash_alloc 1 9075 _000863_hash NULL
84457 +_000864_hash fillonedir 3 41746 _000864_hash NULL
84458 +_000865_hash fs_devrw_entry 3 11924 _000865_hash NULL
84459 +_000866_hash fs_path_prepare_for_add 2 61854 _000866_hash NULL
84460 +_000867_hash fuse_fill_write_pages 4 53682 _000867_hash NULL
84461 +_000868_hash fw_device_op_ioctl 2 11595 _000868_hash NULL
84462 +_000869_hash fw_iso_buffer_init 3 54582 _000869_hash NULL
84463 +_000870_hash fw_node_create 2 9559 _000870_hash NULL
84464 +_000871_hash garmin_read_process 3 27509 _000871_hash NULL
84465 +_000872_hash garp_request_join 4 7471 _000872_hash NULL
84466 +_000873_hash generic_perform_write 3 54832 _000873_hash NULL
84467 +_000874_hash gen_pool_add_virt 4 39913 _000874_hash NULL
84468 +_000875_hash get_derived_key 4 61100 _000875_hash NULL
84469 +_000876_hash get_new_cssid 2 51665 _000876_hash NULL
84470 +_000877_hash getxattr 4 24398 _003758_hash NULL nohasharray
84471 +_000878_hash gsm_control_reply 4 53333 _000878_hash NULL
84472 +_000879_hash hcd_alloc_coherent 5 55862 _000879_hash NULL
84473 +_000880_hash hci_sock_sendmsg 4 37420 _000880_hash NULL
84474 +_000881_hash hidraw_ioctl 2 63658 _000881_hash NULL
84475 +_000882_hash hidraw_write 3 31536 _000882_hash NULL
84476 +_000883_hash hid_register_field 2-3 4874 _000883_hash NULL
84477 +_000885_hash hid_report_raw_event 4 2762 _000885_hash NULL
84478 +_000886_hash hpi_alloc_control_cache 1 35351 _000886_hash NULL
84479 +_000887_hash hugetlbfs_read_actor 2-5-4 34547 _000887_hash NULL
84480 +_000890_hash hvc_alloc 4 12579 _000890_hash NULL
84481 +_000891_hash __hwahc_dev_set_key 5 46328 _000891_hash NULL
84482 +_000892_hash i2400m_zrealloc_2x 3 54166 _001549_hash NULL nohasharray
84483 +_000893_hash ib_alloc_device 1 26483 _000893_hash NULL
84484 +_000894_hash ib_create_send_mad 5 1196 _000894_hash NULL
84485 +_000895_hash ibmasm_new_command 2 25714 _000895_hash NULL
84486 +_000896_hash ib_send_cm_drep 3 50186 _000896_hash NULL
84487 +_000897_hash ib_send_cm_mra 4 60202 _003063_hash NULL nohasharray
84488 +_000898_hash ib_send_cm_rtu 3 63138 _000898_hash NULL
84489 +_000899_hash ide_core_cp_entry 3 22636 _000899_hash NULL
84490 +_000900_hash ieee80211_if_write_smps 3 35550 _000900_hash NULL
84491 +_000901_hash ieee80211_if_write_tkip_mic_test 3 58748 _000901_hash NULL
84492 +_000902_hash ieee80211_if_write_tsf 3 36077 _000902_hash NULL
84493 +_000903_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _000903_hash NULL
84494 +_000904_hash ieee80211_if_write_uapsd_queues 3 51526 _000904_hash NULL
84495 +_000905_hash ieee80211_key_alloc 3 19065 _000905_hash NULL
84496 +_000906_hash ieee80211_send_probe_req 6-4 6924 _000906_hash NULL
84497 +_000907_hash ieee80211_skb_resize 3 50211 _000907_hash NULL
84498 +_000908_hash if_spi_host_to_card 4 62890 _000908_hash NULL
84499 +_000909_hash if_writecmd 2 815 _000909_hash NULL
84500 +_000910_hash init_bch 1-2 64130 _000910_hash NULL
84501 +_000912_hash init_ipath 1 48187 _000912_hash NULL
84502 +_000913_hash init_list_set 2-3 39188 _000913_hash NULL
84503 +_000915_hash init_q 4 132 _000915_hash NULL
84504 +_000916_hash init_state 2 60165 _000916_hash NULL
84505 +_000917_hash init_tag_map 3 57515 _000917_hash NULL
84506 +_000918_hash input_ff_create 2 21240 _000918_hash NULL
84507 +_000919_hash input_mt_init_slots 2 31183 _000919_hash NULL
84508 +_000920_hash interfaces 2 38859 _000920_hash NULL
84509 +_000921_hash int_hardware_entry 3 36833 _000921_hash NULL
84510 +_000922_hash int_hw_irq_en 3 46776 _000922_hash NULL
84511 +_000923_hash int_tasklet_entry 3 52500 _000923_hash NULL
84512 +_000924_hash ioat2_alloc_ring 2 11172 _000924_hash NULL
84513 +_000925_hash ip_generic_getfrag 3-4 12187 _000925_hash NULL
84514 +_000927_hash ip_options_get_alloc 1 7448 _000927_hash NULL
84515 +_000928_hash ipr_alloc_ucode_buffer 1 40199 _000928_hash NULL
84516 +_000929_hash ip_set_alloc 1 57953 _000929_hash NULL
84517 +_000930_hash ip_setsockopt 5 33487 _000930_hash NULL
84518 +_000931_hash ipv6_flowlabel_opt 3 58135 _001179_hash NULL nohasharray
84519 +_000932_hash ipv6_renew_options 5 28867 _000932_hash NULL
84520 +_000933_hash ipv6_setsockopt 5 29871 _000933_hash NULL
84521 +_000934_hash ipxrtr_route_packet 4 54036 _000934_hash NULL
84522 +_000935_hash irda_sendmsg 4 4388 _000935_hash NULL
84523 +_000936_hash irda_sendmsg_dgram 4 38563 _000936_hash NULL
84524 +_000937_hash irda_sendmsg_ultra 4 42047 _000937_hash NULL
84525 +_000938_hash irias_add_octseq_attrib 4 29983 _000938_hash NULL
84526 +_000939_hash irq_alloc_generic_chip 2 26650 _000939_hash NULL
84527 +_000940_hash iscsi_alloc_session 3 49390 _000940_hash NULL
84528 +_000941_hash iscsi_create_conn 2 50425 _000941_hash NULL
84529 +_000942_hash iscsi_create_endpoint 1 15193 _000942_hash NULL
84530 +_000943_hash iscsi_create_iface 5 38510 _000943_hash NULL
84531 +_000944_hash iscsi_decode_text_input 4 58292 _000944_hash NULL
84532 +_000945_hash iscsi_pool_init 2-4 54913 _000945_hash NULL
84533 +_000947_hash iscsit_dump_data_payload 2 38683 _000947_hash NULL
84534 +_000948_hash isdn_write 3 45863 _000948_hash NULL
84535 +_000949_hash isku_receive 4 54130 _000949_hash NULL
84536 +_000950_hash islpci_mgt_transaction 5 23610 _000950_hash NULL
84537 +_000951_hash iso_alloc_urb 4-5 45206 _000951_hash NULL
84538 +_000952_hash iso_sched_alloc 1 13377 _003325_hash NULL nohasharray
84539 +_000953_hash iwl_trans_txq_alloc 3 36147 _000953_hash NULL
84540 +_000954_hash ixgbe_alloc_q_vector 4-6 24439 _000954_hash NULL
84541 +_000956_hash jbd2_journal_init_revoke 2 51088 _000956_hash NULL
84542 +_000957_hash jffs2_write_dirent 5 37311 _000957_hash NULL
84543 +_000958_hash journal_init_revoke 2 56933 _000958_hash NULL
84544 +_000959_hash keyctl_instantiate_key 3 41855 _000959_hash NULL
84545 +_000960_hash keyctl_instantiate_key_iov 3 16969 _000960_hash NULL
84546 +_000961_hash __kfifo_from_user 3 20399 _000961_hash NULL
84547 +_000962_hash kimage_crash_alloc 3 3233 _000962_hash NULL
84548 +_000963_hash kimage_normal_alloc 3 31140 _000963_hash NULL
84549 +_000964_hash kmem_realloc 2 37489 _000964_hash NULL
84550 +_000965_hash kmem_zalloc 1 11510 _000965_hash NULL
84551 +_000966_hash koneplus_sysfs_read 6 42792 _000966_hash NULL
84552 +_000967_hash kvm_kvzalloc 1 52894 _000967_hash NULL
84553 +_000968_hash kvm_read_guest_page_mmu 6 37611 _000968_hash NULL
84554 +_000969_hash kvm_set_irq_routing 3 48704 _000969_hash NULL
84555 +_000970_hash kvm_write_guest_cached 4 11106 _000970_hash NULL
84556 +_000971_hash kvm_write_guest_page 5 63555 _002812_hash NULL nohasharray
84557 +_000972_hash kzalloc_node 1 24352 _000972_hash NULL
84558 +_000973_hash l2cap_skbuff_fromiovec 3-4 35003 _000973_hash NULL
84559 +_000975_hash l2tp_ip_sendmsg 4 50411 _000975_hash NULL
84560 +_000976_hash l2tp_session_create 1 25286 _000976_hash NULL
84561 +_000977_hash lc_create 3 48662 _000977_hash NULL
84562 +_000978_hash leaf_dealloc 3 29566 _000978_hash NULL
84563 +_000979_hash linear_conf 2 23485 _003837_hash NULL nohasharray
84564 +_000980_hash llc_ui_sendmsg 4 24987 _000980_hash NULL
84565 +_000981_hash load_module 2 60056 _003010_hash NULL nohasharray
84566 +_000982_hash lpfc_sli4_queue_alloc 3 62646 _000982_hash NULL
84567 +_000983_hash mdiobus_alloc_size 1 52259 _000983_hash NULL
84568 +_000984_hash mempool_create_node 1 3191 _000984_hash NULL
84569 +_000985_hash mem_read 3 57631 _000985_hash NULL
84570 +_000986_hash memstick_alloc_host 1 142 _000986_hash NULL
84571 +_000987_hash mem_swapout_entry 3 32586 _000987_hash NULL
84572 +_000988_hash mem_write 3 22232 _000988_hash NULL
84573 +_000989_hash mesh_table_alloc 1 22305 _000989_hash NULL
84574 +_000990_hash mfd_add_devices 4 16668 _000990_hash NULL
84575 +_000991_hash mISDN_sock_sendmsg 4 41035 _000991_hash NULL
84576 +_000992_hash mlx4_init_icm_table 4-5 2151 _000992_hash NULL
84577 +_000994_hash mmc_alloc_host 1 48097 _000994_hash NULL
84578 +_000995_hash mmc_test_alloc_mem 2-3 28102 _000995_hash NULL
84579 +_000997_hash mon_bin_ioctl 3 2771 _000997_hash NULL
84580 +_000998_hash mpi_alloc 1 18094 _000998_hash NULL
84581 +_000999_hash mpihelp_mul_karatsuba_case 5-3 23918 _003061_hash NULL nohasharray
84582 +_001000_hash __mptctl_ioctl 2 15875 _001000_hash NULL
84583 +_001001_hash mtd_concat_create 2 14416 _001001_hash NULL
84584 +_001002_hash mthca_alloc_cq_buf 3 46512 _001002_hash NULL
84585 +_001003_hash mvumi_alloc_mem_resource 3 47750 _001003_hash NULL
84586 +_001004_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _001004_hash NULL
84587 +_001005_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _001005_hash NULL
84588 +_001007_hash mwl8k_cmd_set_beacon 4 23110 _001007_hash NULL
84589 +_001008_hash neigh_hash_alloc 1 17595 _001008_hash NULL
84590 +_001009_hash __netdev_alloc_skb 2 18595 _001009_hash NULL
84591 +_001010_hash __netlink_change_ngroups 2 46156 _001010_hash NULL
84592 +_001011_hash netlink_sendmsg 4 33708 _001236_hash NULL nohasharray
84593 +_001012_hash netxen_alloc_sds_rings 2 13417 _001012_hash NULL
84594 +_001013_hash new_bind_ctl 2 35324 _001013_hash NULL
84595 +_001014_hash new_dir 3 31919 _001014_hash NULL
84596 +_001015_hash new_tape_buffer 2 32866 _001015_hash NULL
84597 +_001016_hash nfc_llcp_build_tlv 3 19536 _001016_hash NULL
84598 +_001017_hash nfc_llcp_send_i_frame 3 59130 _001017_hash NULL
84599 +_001018_hash nf_ct_ext_create 3 51232 _001018_hash NULL
84600 +_001019_hash nfs4_alloc_pages 1 48426 _001019_hash NULL
84601 +_001020_hash nfs4_alloc_slots 1 2454 _003345_hash NULL nohasharray
84602 +_001021_hash nfsctl_transaction_write 3 64800 _001021_hash NULL
84603 +_001022_hash nfs_fscache_get_super_cookie 3 44355 _001850_hash NULL nohasharray
84604 +_001023_hash nfs_idmap_request_key 3 30208 _001023_hash NULL
84605 +_001024_hash nfs_pgarray_set 2 1085 _001024_hash NULL
84606 +_001025_hash nl_pid_hash_zalloc 1 23314 _001025_hash NULL
84607 +_001026_hash nr_sendmsg 4 53656 _001026_hash NULL
84608 +_001027_hash nsm_create_handle 4 38060 _001027_hash NULL
84609 +_001028_hash ntfs_copy_from_user_iovec 3-6 49829 _001028_hash NULL
84610 +_001030_hash ntfs_file_buffered_write 4-6 41442 _001030_hash NULL
84611 +_001032_hash __ntfs_malloc 1 34022 _001032_hash NULL
84612 +_001033_hash nvme_alloc_queue 3 46865 _001033_hash NULL
84613 +_001034_hash nvme_map_user_pages 3-4 41093 _001639_hash NULL nohasharray
84614 +_001036_hash ocfs2_acl_from_xattr 2 21604 _001036_hash NULL
84615 +_001037_hash ocfs2_control_message 3 19564 _001037_hash NULL
84616 +_001038_hash _ore_get_io_state 3-5-4 2166 _001038_hash NULL
84617 +_001041_hash orinoco_set_key 5-7 17878 _001041_hash NULL
84618 +_001043_hash osdmap_set_max_osd 2 57630 _002267_hash NULL nohasharray
84619 +_001044_hash _osd_realloc_seg 3 54352 _001044_hash NULL
84620 +_001045_hash osst_execute 7-6 17607 _001045_hash NULL
84621 +_001046_hash osst_write 3 31581 _001046_hash NULL
84622 +_001047_hash otp_read 2-5-4 10594 _001047_hash NULL
84623 +_001050_hash ovs_vport_alloc 1 33475 _001050_hash NULL
84624 +_001051_hash p54_parse_rssical 3 64493 _001051_hash NULL
84625 +_001052_hash p9_client_zc_rpc 7 14345 _001052_hash NULL
84626 +_001053_hash packet_sendmsg_spkt 4 28885 _001053_hash NULL
84627 +_001054_hash pair_device 4 61175 _003161_hash NULL nohasharray
84628 +_001055_hash pccard_store_cis 6 18176 _001055_hash NULL
84629 +_001056_hash pci_add_cap_save_buffer 3 3426 _001056_hash NULL
84630 +_001057_hash pcnet32_realloc_rx_ring 3 36598 _001057_hash NULL
84631 +_001058_hash pcnet32_realloc_tx_ring 3 38428 _001058_hash NULL
84632 +_001059_hash pcpu_mem_zalloc 1 22948 _001059_hash NULL
84633 +_001060_hash pep_sendmsg 4 62524 _001060_hash NULL
84634 +_001061_hash pfkey_sendmsg 4 47394 _001061_hash NULL
84635 +_001062_hash pidlist_resize 2 496 _001062_hash NULL
84636 +_001063_hash pin_code_reply 4 46510 _001063_hash NULL
84637 +_001064_hash ping_getfrag 3-4 8360 _001064_hash NULL
84638 +_001066_hash pipe_set_size 2 5204 _001066_hash NULL
84639 +_001067_hash pkt_bio_alloc 1 48284 _001067_hash NULL
84640 +_001068_hash platform_create_bundle 4-6 12785 _001068_hash NULL
84641 +_001070_hash pm8001_store_update_fw 4 55716 _001070_hash NULL
84642 +_001071_hash pmcraid_alloc_sglist 1 9864 _001071_hash NULL
84643 +_001072_hash pn533_dep_link_up 5 22154 _001072_hash NULL
84644 +_001073_hash pn533_init_target_frame 3 65438 _001073_hash NULL
84645 +_001074_hash pnp_alloc 1 24869 _001538_hash NULL nohasharray
84646 +_001075_hash pn_sendmsg 4 12640 _001075_hash NULL
84647 +_001076_hash pppoe_sendmsg 4 48039 _001076_hash NULL
84648 +_001077_hash pppol2tp_sendmsg 4 56420 _001077_hash NULL
84649 +_001078_hash prism2_info_hostscanresults 3 39657 _001078_hash NULL
84650 +_001079_hash process_vm_rw 3-5 47533 _001079_hash NULL
84651 +_001081_hash process_vm_rw_single_vec 1-2 26213 _001081_hash NULL
84652 +_001083_hash proc_write 3 51003 _001083_hash NULL
84653 +_001084_hash profile_load 3 58267 _001084_hash NULL
84654 +_001085_hash profile_remove 3 8556 _001085_hash NULL
84655 +_001086_hash profile_replace 3 14652 _001086_hash NULL
84656 +_001087_hash pscsi_get_bio 1 56103 _001087_hash NULL
84657 +_001088_hash __pskb_copy 2 9038 _001088_hash NULL
84658 +_001089_hash __pskb_pull_tail 2 60287 _001089_hash NULL
84659 +_001090_hash qla4xxx_alloc_work 2 44813 _001090_hash NULL
84660 +_001091_hash qlcnic_alloc_msix_entries 2 46160 _001091_hash NULL
84661 +_001092_hash qlcnic_alloc_sds_rings 2 26795 _001092_hash NULL
84662 +_001093_hash queue_received_packet 5 9657 _001093_hash NULL
84663 +_001094_hash raw_send_hdrinc 4 58803 _001094_hash NULL
84664 +_001095_hash raw_sendmsg 4 23078 _003316_hash NULL nohasharray
84665 +_001096_hash rawsock_sendmsg 4 60010 _001096_hash NULL
84666 +_001097_hash rawv6_send_hdrinc 3 35425 _001097_hash NULL
84667 +_001098_hash rawv6_setsockopt 5 56165 _001098_hash NULL
84668 +_001099_hash rb_alloc 1 3102 _001099_hash NULL
84669 +_001100_hash rbd_alloc_coll 1 33678 _001100_hash NULL
84670 +_001101_hash rbd_create_rw_ops 1 55297 _001101_hash NULL
84671 +_001102_hash rds_ib_inc_copy_to_user 3 55007 _001102_hash NULL
84672 +_001103_hash rds_iw_inc_copy_to_user 3 29214 _001103_hash NULL
84673 +_001104_hash rds_message_alloc 1 10517 _001104_hash NULL
84674 +_001105_hash rds_message_copy_from_user 3 45510 _001105_hash NULL
84675 +_001106_hash rds_message_inc_copy_to_user 3 26540 _001106_hash NULL
84676 +_001107_hash regcache_rbtree_insert_to_block 5 58009 _001107_hash NULL
84677 +_001108_hash _regmap_raw_write 4 42652 _001108_hash NULL
84678 +_001109_hash regmap_register_patch 3 21681 _001109_hash NULL
84679 +_001110_hash relay_alloc_page_array 1 52735 _001110_hash NULL
84680 +_001111_hash remove_uuid 4 64505 _001111_hash NULL
84681 +_001112_hash reshape_ring 2 29147 _001112_hash NULL
84682 +_001113_hash RESIZE_IF_NEEDED 2 56286 _001113_hash NULL
84683 +_001114_hash resize_info_buffer 2 62889 _001114_hash NULL
84684 +_001115_hash resize_stripes 2 61650 _001115_hash NULL
84685 +_001116_hash rfcomm_sock_sendmsg 4 37661 _003661_hash NULL nohasharray
84686 +_001117_hash roccat_common2_send_with_status 4 50343 _001117_hash NULL
84687 +_001118_hash rose_sendmsg 4 20249 _001118_hash NULL
84688 +_001119_hash rsc_mgr_init 3 16299 _001119_hash NULL
84689 +_001120_hash rxrpc_send_data 5 21553 _001120_hash NULL
84690 +_001121_hash rxrpc_setsockopt 5 50286 _001121_hash NULL
84691 +_001122_hash savu_sysfs_read 6 49473 _001122_hash NULL
84692 +_001124_hash sco_send_frame 3 41815 _001124_hash NULL
84693 +_001125_hash scsi_dispatch_cmd_entry 3 49848 _001125_hash NULL
84694 +_001126_hash scsi_host_alloc 2 63041 _001126_hash NULL
84695 +_001127_hash scsi_tgt_kspace_exec 8 9522 _001127_hash NULL
84696 +_001128_hash sctp_sendmsg 4 61919 _001128_hash NULL
84697 +_001129_hash sctp_setsockopt 5 44788 _001129_hash NULL
84698 +_001130_hash sctp_setsockopt_connectx 3 6073 _001130_hash NULL
84699 +_001131_hash sctp_setsockopt_connectx_old 3 22631 _001131_hash NULL
84700 +_001132_hash sctp_tsnmap_grow 2 32784 _001132_hash NULL
84701 +_001133_hash sctp_tsnmap_init 2 36446 _001133_hash NULL
84702 +_001134_hash sctp_user_addto_chunk 2-3 62047 _001134_hash NULL
84703 +_001136_hash security_context_to_sid 2 19839 _001136_hash NULL
84704 +_001137_hash security_context_to_sid_default 2 3492 _003841_hash NULL nohasharray
84705 +_001138_hash security_context_to_sid_force 2 20724 _001138_hash NULL
84706 +_001139_hash self_check_write 5 50856 _001139_hash NULL
84707 +_001140_hash selinux_transaction_write 3 59038 _001140_hash NULL
84708 +_001141_hash sel_write_access 3 51704 _001141_hash NULL
84709 +_001142_hash sel_write_create 3 11353 _001142_hash NULL
84710 +_001143_hash sel_write_member 3 28800 _001143_hash NULL
84711 +_001144_hash sel_write_relabel 3 55195 _001144_hash NULL
84712 +_001145_hash sel_write_user 3 45060 _001145_hash NULL
84713 +_001146_hash __seq_open_private 3 40715 _001146_hash NULL
84714 +_001147_hash serverworks_create_gatt_pages 1 46582 _001147_hash NULL
84715 +_001148_hash set_connectable 4 56458 _001148_hash NULL
84716 +_001149_hash set_dev_class 4 39645 _001921_hash NULL nohasharray
84717 +_001150_hash set_discoverable 4 48141 _001150_hash NULL
84718 +_001151_hash set_fd_set 1 35249 _001151_hash NULL
84719 +_001152_hash setkey 3 14987 _001152_hash NULL
84720 +_001153_hash set_le 4 30581 _001153_hash NULL
84721 +_001154_hash set_link_security 4 4502 _001154_hash NULL
84722 +_001155_hash set_local_name 4 55757 _001155_hash NULL
84723 +_001156_hash set_powered 4 12129 _001156_hash NULL
84724 +_001157_hash set_ssp 4 62411 _001157_hash NULL
84725 +_001158_hash sg_build_sgat 3 60179 _001158_hash &_000314_hash
84726 +_001159_hash sg_read_oxfer 3 51724 _001159_hash NULL
84727 +_001160_hash shmem_xattr_set 4 11843 _001160_hash NULL
84728 +_001161_hash simple_alloc_urb 3 60420 _001161_hash NULL
84729 +_001162_hash sisusb_send_bridge_packet 2 11649 _001162_hash NULL
84730 +_001163_hash sisusb_send_packet 2 20891 _001163_hash NULL
84731 +_001164_hash sisusb_write_mem_bulk 4 29678 _001164_hash NULL
84732 +_001165_hash skb_add_data_nocache 4 4682 _001165_hash NULL
84733 +_001166_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001166_hash NULL
84734 +_001169_hash skb_copy_expand 2-3 7685 _001169_hash &_000677_hash
84735 +_001171_hash skb_copy_to_page_nocache 6 58624 _001171_hash NULL
84736 +_001172_hash __skb_cow 2 39254 _001172_hash NULL
84737 +_001173_hash skb_cow_data 2 11565 _001173_hash NULL
84738 +_001174_hash skb_pad 2 17302 _001174_hash NULL
84739 +_001175_hash skb_realloc_headroom 2 19516 _001175_hash NULL
84740 +_001176_hash sk_chk_filter 2 42095 _001176_hash NULL
84741 +_001177_hash skcipher_sendmsg 4 30290 _001177_hash NULL
84742 +_001178_hash sl_change_mtu 2 7396 _001178_hash NULL
84743 +_001179_hash slhc_init 1-2 58135 _001179_hash &_000931_hash
84744 +_001181_hash sm501_create_subdev 3-4 48668 _001245_hash NULL nohasharray
84745 +_001183_hash smk_user_access 3 24440 _001183_hash NULL
84746 +_001184_hash smk_write_cipso2 3 1021 _001184_hash NULL
84747 +_001185_hash smk_write_cipso 3 17989 _001185_hash NULL
84748 +_001186_hash smk_write_load2 3 52155 _001186_hash NULL
84749 +_001187_hash smk_write_load 3 26829 _001187_hash NULL
84750 +_001188_hash smk_write_load_self2 3 591 _001188_hash NULL
84751 +_001189_hash smk_write_load_self 3 7958 _001189_hash NULL
84752 +_001190_hash snapshot_write 3 28351 _001190_hash NULL
84753 +_001191_hash snd_ac97_pcm_assign 2 30218 _001191_hash NULL
84754 +_001192_hash snd_card_create 4 64418 _001529_hash NULL nohasharray
84755 +_001193_hash snd_emux_create_port 3 42533 _001193_hash NULL
84756 +_001194_hash snd_gus_dram_write 4 38784 _001194_hash NULL
84757 +_001195_hash snd_midi_channel_alloc_set 1 28153 _001195_hash NULL
84758 +_001196_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001196_hash NULL
84759 +_001197_hash snd_pcm_oss_sync1 2 45298 _001197_hash NULL
84760 +_001198_hash snd_pcm_oss_write 3 38108 _001198_hash NULL
84761 +_001199_hash snd_pcm_plugin_build 5 25505 _001199_hash NULL
84762 +_001200_hash snd_rawmidi_kernel_write 3 25106 _001200_hash NULL
84763 +_001201_hash snd_rawmidi_write 3 28008 _001201_hash NULL
84764 +_001202_hash snd_rme32_playback_copy 5 43732 _001202_hash NULL
84765 +_001203_hash snd_rme96_playback_copy 5 13111 _001203_hash NULL
84766 +_001204_hash snd_seq_device_new 4 31753 _001204_hash NULL
84767 +_001205_hash snd_seq_oss_readq_new 2 14283 _001205_hash NULL
84768 +_001206_hash snd_vx_create 4 40948 _001206_hash NULL
84769 +_001207_hash sock_setsockopt 5 50088 _001207_hash NULL
84770 +_001208_hash sound_write 3 5102 _001208_hash NULL
84771 +_001209_hash _sp2d_alloc 1-3-2 16944 _001209_hash NULL
84772 +_001212_hash spi_alloc_master 2 45223 _001212_hash NULL
84773 +_001213_hash spidev_message 3 5518 _001213_hash NULL
84774 +_001214_hash spi_register_board_info 2 35651 _001214_hash NULL
84775 +_001215_hash squashfs_cache_init 2 41656 _001215_hash NULL
84776 +_001216_hash squashfs_read_data 6 59440 _001216_hash NULL
84777 +_001217_hash squashfs_read_fragment_index_table 4 2506 _001217_hash NULL
84778 +_001218_hash squashfs_read_id_index_table 4 61961 _001218_hash NULL
84779 +_001219_hash squashfs_read_inode_lookup_table 4 64739 _001219_hash NULL
84780 +_001220_hash srp_alloc_iu 2 44227 _001220_hash NULL
84781 +_001221_hash srp_iu_pool_alloc 2 17920 _001221_hash NULL
84782 +_001222_hash srp_ring_alloc 2 26760 _001222_hash NULL
84783 +_001226_hash start_isoc_chain 2 565 _001226_hash NULL
84784 +_001227_hash st_write 3 16874 _001227_hash NULL
84785 +_001228_hash svc_pool_map_alloc_arrays 2 47181 _001228_hash NULL
84786 +_001229_hash symtab_init 2 61050 _001229_hash NULL
84787 +_001230_hash sys_bind 3 10799 _001230_hash NULL
84788 +_001231_hash sys_connect 3 15291 _003816_hash NULL nohasharray
84789 +_001232_hash sys_flistxattr 3 41407 _001232_hash NULL
84790 +_001233_hash sys_fsetxattr 4 49736 _001233_hash NULL
84791 +_001234_hash sysfs_write_file 3 57116 _001234_hash NULL
84792 +_001235_hash sys_ipc 3 4889 _001235_hash NULL
84793 +_001236_hash sys_keyctl 4 33708 _001236_hash &_001011_hash
84794 +_001237_hash sys_listxattr 3 27833 _001237_hash NULL
84795 +_001238_hash sys_llistxattr 3 4532 _001238_hash NULL
84796 +_001239_hash sys_lsetxattr 4 61177 _001239_hash NULL
84797 +_001240_hash sys_mq_timedsend 3 57661 _001240_hash NULL
84798 +_001241_hash sys_sched_setaffinity 2 32046 _001241_hash NULL
84799 +_001242_hash sys_select 1 38827 _001242_hash NULL
84800 +_001243_hash sys_semop 3 39457 _001243_hash NULL
84801 +_001244_hash sys_sendto 6 20809 _001244_hash NULL
84802 +_001245_hash sys_setgroups 1 48668 _001245_hash &_001181_hash
84803 +_001246_hash sys_setgroups16 1 48882 _001246_hash NULL
84804 +_001247_hash sys_setxattr 4 37880 _001247_hash NULL
84805 +_001248_hash t4_alloc_mem 1 32342 _001248_hash NULL
84806 +_001249_hash tcf_hash_create 4 54360 _001249_hash NULL
84807 +_001250_hash tcp_send_rcvq 3 11316 _001250_hash NULL
84808 +_001251_hash __team_options_register 3 63941 _001251_hash NULL
84809 +_001252_hash test_unaligned_bulk 3 52333 _001252_hash NULL
84810 +_001253_hash tifm_alloc_adapter 1 10903 _001253_hash NULL
84811 +_001254_hash timeout_write 3 50991 _001254_hash NULL
84812 +_001255_hash timeradd_entry 3 49850 _001255_hash NULL
84813 +_001256_hash tipc_link_send_sections_fast 4 37920 _001256_hash NULL
84814 +_001257_hash tipc_subseq_alloc 1 5957 _001257_hash NULL
84815 +_001258_hash tnode_alloc 1 49407 _001258_hash NULL
84816 +_001259_hash tomoyo_commit_ok 2 20167 _001259_hash NULL
84817 +_001260_hash tomoyo_scan_bprm 2-4 15642 _003488_hash NULL nohasharray
84818 +_001262_hash tps6586x_writes 3 58689 _001262_hash NULL
84819 +_001263_hash tty_buffer_find 2 2443 _001263_hash NULL
84820 +_001264_hash tty_write 3 5494 _001264_hash NULL
84821 +_001265_hash ubifs_setxattr 4 59650 _001477_hash NULL nohasharray
84822 +_001266_hash ubi_self_check_all_ff 4 41959 _001266_hash NULL
84823 +_001267_hash udf_sb_alloc_partition_maps 2 62313 _001267_hash NULL
84824 +_001268_hash udplite_getfrag 3-4 14479 _001268_hash NULL
84825 +_001270_hash ulong_write_file 3 26485 _001270_hash NULL
84826 +_001271_hash unix_stream_sendmsg 4 61455 _001271_hash NULL
84827 +_001272_hash unlink_queued 3-4 645 _001272_hash NULL
84828 +_001273_hash update_pmkid 4 2481 _001273_hash NULL
84829 +_001274_hash usb_alloc_coherent 2 65444 _001274_hash NULL
84830 +_001275_hash vc_resize 2-3 3585 _001275_hash NULL
84831 +_001277_hash vhci_write 3 2224 _001277_hash NULL
84832 +_001278_hash __vhost_add_used_n 3 26554 _001278_hash NULL
84833 +_001279_hash virtqueue_add_buf 3-4 59470 _001279_hash NULL
84834 +_001281_hash vmalloc 1 15464 _001281_hash NULL
84835 +_001282_hash vol_cdev_write 3 40915 _001282_hash NULL
84836 +_001283_hash vxge_device_register 4 7752 _001283_hash NULL
84837 +_001284_hash __vxge_hw_blockpool_malloc 2 5786 _001284_hash NULL
84838 +_001285_hash __vxge_hw_channel_allocate 3 55462 _001285_hash NULL
84839 +_001286_hash vzalloc 1 47421 _001286_hash NULL
84840 +_001287_hash vzalloc_node 1 23424 _001287_hash NULL
84841 +_001288_hash wa_nep_queue 2 8858 _001288_hash NULL
84842 +_001289_hash __wa_xfer_setup_segs 2 56725 _001289_hash NULL
84843 +_001290_hash wiphy_new 2 2482 _001290_hash NULL
84844 +_001291_hash wm8350_block_write 3 19727 _001291_hash NULL
84845 +_001292_hash wpan_phy_alloc 1 48056 _001292_hash NULL
84846 +_001293_hash write_flush_pipefs 3 2021 _001293_hash NULL
84847 +_001294_hash write_flush_procfs 3 44011 _001294_hash NULL
84848 +_001295_hash wusb_ccm_mac 7 32199 _001295_hash NULL
84849 +_001296_hash x25_sendmsg 4 12487 _001296_hash NULL
84850 +_001297_hash xfrm_hash_alloc 1 10997 _001297_hash NULL
84851 +_001298_hash _xfs_buf_get_pages 2 46811 _001298_hash NULL
84852 +_001299_hash xfs_da_grow_inode_int 3 21785 _001299_hash NULL
84853 +_001300_hash xfs_dir_cilookup_result 3 64288 _003160_hash NULL nohasharray
84854 +_001301_hash xfs_idata_realloc 2 26199 _001301_hash NULL
84855 +_001302_hash xfs_iext_add_indirect_multi 3 32400 _001302_hash NULL
84856 +_001303_hash xfs_iext_inline_to_direct 2 12384 _001303_hash NULL
84857 +_001304_hash xfs_iformat_local 4 49472 _001304_hash NULL
84858 +_001305_hash xfs_iroot_realloc 2 46826 _001305_hash NULL
84859 +_001306_hash xhci_alloc_stream_info 3 63902 _001306_hash NULL
84860 +_001307_hash xlog_recover_add_to_trans 4 62839 _001307_hash NULL
84861 +_001308_hash xprt_alloc 2 1475 _001308_hash NULL
84862 +_001309_hash xt_alloc_table_info 1 57903 _001309_hash NULL
84863 +_001310_hash _zd_iowrite32v_async_locked 3 39034 _001310_hash NULL
84864 +_001311_hash zd_usb_iowrite16v 3 49744 _001311_hash NULL
84865 +_001312_hash a2mp_send 4 41615 _001312_hash NULL
84866 +_001313_hash acpi_ds_build_internal_package_obj 3 58271 _001313_hash NULL
84867 +_001314_hash acpi_system_read_event 3 55362 _001314_hash NULL
84868 +_001315_hash acpi_ut_create_buffer_object 1 42030 _001315_hash NULL
84869 +_001316_hash acpi_ut_create_package_object 1 17594 _001316_hash NULL
84870 +_001317_hash acpi_ut_create_string_object 1 15360 _001317_hash NULL
84871 +_001318_hash ad7879_spi_multi_read 3 8218 _001318_hash NULL
84872 +_001319_hash add_child 4 45201 _001319_hash NULL
84873 +_001320_hash add_port 2 54941 _001320_hash NULL
84874 +_001321_hash adu_read 3 24177 _001321_hash NULL
84875 +_001322_hash afs_cell_create 2 27346 _001322_hash NULL
84876 +_001323_hash agp_allocate_memory 2 58761 _001323_hash NULL
84877 +_001324_hash agp_generic_alloc_user 1 9470 _001324_hash NULL
84878 +_001325_hash alc_auto_create_extra_outs 2 18975 _001325_hash NULL
84879 +_001326_hash alloc_agpphysmem_i8xx 1 39427 _001326_hash NULL
84880 +_001327_hash allocate_cnodes 1 5329 _001327_hash NULL
84881 +_001328_hash ___alloc_bootmem 1 11410 _001328_hash NULL
84882 +_001329_hash __alloc_bootmem_low_node 2 25726 _001662_hash NULL nohasharray
84883 +_001330_hash __alloc_bootmem_node 2 1992 _001330_hash NULL
84884 +_001331_hash __alloc_bootmem_node_nopanic 2 6432 _001331_hash NULL
84885 +_001332_hash __alloc_bootmem_nopanic 1 65397 _001332_hash NULL
84886 +_001333_hash alloc_candev 1-2 7776 _001333_hash NULL
84887 +_001335_hash _alloc_cdb_cont 2 23609 _001335_hash NULL
84888 +_001336_hash alloc_dummy_extent_buffer 2 56374 _001336_hash NULL
84889 +_001337_hash ____alloc_ei_netdev 1 51475 _001337_hash NULL
84890 +_001338_hash alloc_etherdev_mqs 1 36450 _001338_hash NULL
84891 +_001339_hash alloc_extent_buffer 3 52824 _001339_hash NULL
84892 +_001340_hash alloc_fcdev 1 18780 _001340_hash NULL
84893 +_001341_hash alloc_fddidev 1 15382 _001341_hash NULL
84894 +_001342_hash _alloc_get_attr_desc 2 470 _001342_hash NULL
84895 +_001343_hash alloc_hippi_dev 1 51320 _001343_hash NULL
84896 +_001344_hash alloc_irdadev 1 19140 _001344_hash NULL
84897 +_001345_hash alloc_ldt 2 21972 _001345_hash NULL
84898 +_001346_hash alloc_ltalkdev 1 38071 _001346_hash NULL
84899 +_001347_hash alloc_one_pg_vec_page 1 10747 _001347_hash NULL
84900 +_001348_hash alloc_orinocodev 1 21371 _001348_hash NULL
84901 +_001349_hash alloc_ring 2-4 18278 _001349_hash NULL
84902 +_001351_hash _alloc_set_attr_list 4 48991 _001351_hash NULL
84903 +_001353_hash alloc_tx 2 32143 _001353_hash NULL
84904 +_001354_hash alloc_wr 1-2 24635 _001354_hash NULL
84905 +_001356_hash async_setkey 3 35521 _001356_hash NULL
84906 +_001357_hash ata_host_alloc_pinfo 3 17325 _001357_hash NULL
84907 +_001360_hash ath6kl_connect_event 7-9-8 14267 _001360_hash NULL
84908 +_001361_hash ath6kl_fwlog_block_read 3 49836 _001361_hash NULL
84909 +_001362_hash ath6kl_fwlog_read 3 32101 _001362_hash NULL
84910 +_001363_hash ath9k_wmi_cmd 4 327 _001363_hash NULL
84911 +_001364_hash ath_rx_init 2 43564 _001364_hash NULL
84912 +_001365_hash ath_tx_init 2 60515 _001365_hash NULL
84913 +_001366_hash atm_alloc_charge 2 19517 _001914_hash NULL nohasharray
84914 +_001367_hash atm_get_addr 3 31221 _001367_hash NULL
84915 +_001368_hash audit_log_n_hex 3 45617 _001368_hash NULL
84916 +_001369_hash audit_log_n_string 3 31705 _001369_hash NULL
84917 +_001370_hash ax25_output 2 22736 _001370_hash NULL
84918 +_001371_hash bcsp_prepare_pkt 3 12961 _001371_hash NULL
84919 +_001372_hash bdx_rxdb_create 1 46525 _001372_hash NULL
84920 +_001373_hash bdx_tx_db_init 2 41719 _001373_hash NULL
84921 +_001374_hash bio_map_kern 3 64751 _001374_hash NULL
84922 +_001375_hash bits_to_user 2-3 47733 _001375_hash NULL
84923 +_001377_hash __blk_queue_init_tags 2 9778 _001377_hash NULL
84924 +_001378_hash blk_queue_resize_tags 2 28670 _001378_hash NULL
84925 +_001379_hash blk_rq_map_user_iov 5 16772 _001379_hash NULL
84926 +_001380_hash bm_init 2 13529 _001380_hash NULL
84927 +_001381_hash brcmf_alloc_wdev 1 60347 _001381_hash NULL
84928 +_001382_hash __btrfs_buffered_write 3 35311 _002735_hash NULL nohasharray
84929 +_001383_hash btrfs_insert_dir_item 4 59304 _001383_hash NULL
84930 +_001384_hash btrfs_map_block 3 64379 _001384_hash NULL
84931 +_001385_hash bt_skb_alloc 1 6404 _001385_hash NULL
84932 +_001386_hash c4_add_card 3 54968 _001386_hash NULL
84933 +_001387_hash cache_read 3 24790 _001387_hash NULL
84934 +_001388_hash cache_write 3 13589 _001388_hash NULL
84935 +_001389_hash calc_hmac 3 32010 _001389_hash NULL
84936 +_001390_hash capinc_tty_write 3 28539 _001390_hash NULL
84937 +_001391_hash ccid_getsockopt_builtin_ccids 2 53634 _001391_hash NULL
84938 +_001392_hash ceph_copy_page_vector_to_user 3-4 31270 _001392_hash NULL
84939 +_001394_hash ceph_parse_server_name 2 60318 _001394_hash NULL
84940 +_001395_hash ceph_read_dir 3 17005 _001395_hash NULL
84941 +_001396_hash cfg80211_roamed 5-7 32632 _001396_hash NULL
84942 +_001398_hash cfpkt_add_body 3 44630 _001398_hash NULL
84943 +_001399_hash cfpkt_create_pfx 1-2 23594 _001399_hash NULL
84944 +_001401_hash cmd_complete 6 51629 _001401_hash NULL
84945 +_001402_hash cmtp_add_msgpart 4 9252 _001402_hash NULL
84946 +_001403_hash cmtp_send_interopmsg 7 376 _001403_hash NULL
84947 +_001404_hash coda_psdev_read 3 35029 _001404_hash NULL
84948 +_001405_hash construct_key_and_link 4 8321 _001405_hash NULL
84949 +_001406_hash copy_counters_to_user 5 17027 _001406_hash NULL
84950 +_001407_hash copy_entries_to_user 1 52367 _001407_hash NULL
84951 +_001408_hash copy_from_buf 2-4 27308 _001408_hash NULL
84952 +_001410_hash copy_oldmem_page 3-1 26164 _001410_hash NULL
84953 +_001411_hash copy_to_user_fromio 3 57432 _001411_hash NULL
84954 +_001412_hash cryptd_hash_setkey 3 42781 _001412_hash NULL
84955 +_001413_hash crypto_authenc_esn_setkey 3 6985 _001413_hash NULL
84956 +_001414_hash crypto_authenc_setkey 3 80 _001414_hash NULL
84957 +_001415_hash cxgb3_get_cpl_reply_skb 2 10620 _001415_hash NULL
84958 +_001416_hash cxgbi_ddp_reserve 4 30091 _001416_hash NULL
84959 +_001417_hash cxio_init_resource_fifo 3 28764 _001417_hash NULL
84960 +_001418_hash cxio_init_resource_fifo_random 3 47151 _001418_hash NULL
84961 +_001419_hash datablob_hmac_append 3 40038 _001419_hash NULL
84962 +_001420_hash datablob_hmac_verify 4 24786 _001420_hash NULL
84963 +_001421_hash dataflash_read_fact_otp 3-2 33204 _001421_hash NULL
84964 +_001422_hash dataflash_read_user_otp 3-2 14536 _001422_hash &_000207_hash
84965 +_001423_hash dccp_feat_register_sp 5 17914 _001423_hash NULL
84966 +_001424_hash dccp_setsockopt 5 60367 _001424_hash NULL
84967 +_001425_hash __dev_alloc_skb 1 28681 _001425_hash NULL
84968 +_001426_hash disk_expand_part_tbl 2 30561 _001426_hash NULL
84969 +_001427_hash diva_os_alloc_message_buffer 1 64568 _001427_hash NULL
84970 +_001428_hash diva_os_copy_to_user 4 48508 _001428_hash NULL
84971 +_001429_hash diva_os_malloc 2 16406 _001429_hash NULL
84972 +_001430_hash dmam_declare_coherent_memory 4-2 43679 _001430_hash NULL
84973 +_001431_hash dm_vcalloc 1-2 16814 _001431_hash NULL
84974 +_001433_hash dn_alloc_skb 2 6631 _001433_hash NULL
84975 +_001434_hash do_proc_readlink 3 14096 _001434_hash NULL
84976 +_001435_hash do_readlink 2 43518 _001435_hash NULL
84977 +_001436_hash __do_replace 5 37227 _001436_hash NULL
84978 +_001437_hash do_sigpending 2 9766 _001437_hash NULL
84979 +_001438_hash drbd_bm_resize 2 20522 _001438_hash NULL
84980 +_001439_hash drbd_setsockopt 5 16280 _001439_hash &_000383_hash
84981 +_001440_hash dump_midi 3 51040 _001440_hash NULL
84982 +_001441_hash ecryptfs_filldir 3 6622 _001441_hash NULL
84983 +_001442_hash ecryptfs_send_message 2 18322 _001442_hash NULL
84984 +_001443_hash ep0_read 3 38095 _001443_hash NULL
84985 +_001444_hash evdev_ioctl 2 22371 _001444_hash NULL
84986 +_001445_hash ext4_add_new_descs 3 19509 _001445_hash NULL
84987 +_001446_hash fat_ioctl_filldir 3 36621 _001446_hash NULL
84988 +_001447_hash _fc_frame_alloc 1 43568 _001447_hash NULL
84989 +_001448_hash fc_host_post_vendor_event 3 30903 _001448_hash NULL
84990 +_001449_hash fd_copyout 3 59323 _001449_hash NULL
84991 +_001450_hash f_hidg_read 3 6238 _001450_hash NULL
84992 +_001451_hash filldir 3 55137 _001451_hash NULL
84993 +_001452_hash filldir64 3 46469 _001452_hash NULL
84994 +_001453_hash find_skb 2 20431 _001453_hash NULL
84995 +_001454_hash from_buffer 3 18625 _001454_hash NULL
84996 +_001455_hash fsm_init 2 16134 _001455_hash NULL
84997 +_001456_hash fs_path_add 3 15648 _001456_hash NULL
84998 +_001457_hash fs_path_add_from_extent_buffer 4 27702 _001457_hash NULL
84999 +_001458_hash fuse_perform_write 4 18457 _001458_hash NULL
85000 +_001459_hash gem_alloc_skb 2 51715 _001459_hash NULL
85001 +_001460_hash generic_file_buffered_write 4 25464 _001460_hash NULL
85002 +_001461_hash gen_pool_add 3 21776 _001461_hash NULL
85003 +_001462_hash get_packet 3 41914 _001462_hash NULL
85004 +_001463_hash get_packet 3 5747 _001463_hash NULL
85005 +_001464_hash get_packet_pg 4 28023 _001464_hash NULL
85006 +_001465_hash get_skb 2 63008 _001465_hash NULL
85007 +_001466_hash get_subdir 3 62581 _001466_hash NULL
85008 +_001467_hash gsm_control_message 4 18209 _001467_hash NULL
85009 +_001468_hash gsm_control_modem 3 55303 _001468_hash NULL
85010 +_001469_hash gsm_control_rls 3 3353 _001469_hash NULL
85011 +_001470_hash handle_received_packet 3 22457 _001470_hash NULL
85012 +_001471_hash hash_setkey 3 48310 _001471_hash NULL
85013 +_001472_hash hdlcdrv_register 2 6792 _001472_hash NULL
85014 +_001473_hash hiddev_ioctl 2 36816 _001473_hash NULL
85015 +_001474_hash hid_input_report 4 32458 _001474_hash NULL
85016 +_001475_hash hidp_queue_report 3 1881 _001475_hash NULL
85017 +_001476_hash __hidp_send_ctrl_message 4 28303 _001476_hash NULL
85018 +_001477_hash hidraw_read 3 59650 _001477_hash &_001265_hash
85019 +_001478_hash HiSax_readstatus 2 15752 _001478_hash NULL
85020 +_001480_hash __hwahc_op_set_gtk 4 42038 _001480_hash NULL
85021 +_001481_hash __hwahc_op_set_ptk 5 36510 _001481_hash NULL
85022 +_001482_hash hycapi_rx_capipkt 3 11602 _001482_hash NULL
85023 +_001483_hash i2400m_net_rx 5 27170 _001483_hash NULL
85024 +_001484_hash ib_copy_to_udata 3 27525 _001484_hash NULL
85025 +_001485_hash idetape_chrdev_read 3 2097 _001485_hash NULL
85026 +_001486_hash ieee80211_alloc_hw 1 43829 _001486_hash NULL
85027 +_001487_hash ieee80211_bss_info_update 4 13991 _001487_hash NULL
85028 +_001488_hash igmpv3_newpack 2 35912 _001488_hash NULL
85029 +_001489_hash ilo_read 3 32531 _001489_hash NULL
85030 +_001490_hash init_map_ipmac 3-4 63896 _001490_hash NULL
85031 +_001492_hash init_tid_tabs 2-4-3 13252 _001492_hash NULL
85032 +_001495_hash iowarrior_read 3 53483 _001495_hash NULL
85033 +_001496_hash ip_options_get 4 56538 _001496_hash NULL
85034 +_001497_hash ipv6_getsockopt_sticky 5 56711 _001497_hash NULL
85035 +_001498_hash ipwireless_send_packet 4 8328 _001498_hash NULL
85036 +_001499_hash ipx_sendmsg 4 1362 _001499_hash NULL
85037 +_001500_hash irq_domain_add_linear 2 29236 _001500_hash NULL
85038 +_001501_hash iscsi_conn_setup 2 35159 _001501_hash NULL
85039 +_001502_hash iscsi_create_session 3 51647 _001502_hash NULL
85040 +_001503_hash iscsi_host_alloc 2 36671 _001503_hash NULL
85041 +_001504_hash iscsi_if_send_reply 7 52219 _001504_hash NULL
85042 +_001505_hash iscsi_offload_mesg 5 58425 _001505_hash NULL
85043 +_001506_hash iscsi_ping_comp_event 5 38263 _001506_hash NULL
85044 +_001507_hash iscsi_post_host_event 4 13473 _001507_hash NULL
85045 +_001508_hash iscsi_recv_pdu 4 16755 _001508_hash NULL
85046 +_001509_hash iscsi_session_setup 4-5 196 _001509_hash NULL
85047 +_001511_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _003122_hash NULL nohasharray
85048 +_001512_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _001951_hash NULL nohasharray
85049 +_001513_hash isdn_ppp_ccp_xmit_reset 6 63297 _001513_hash NULL
85050 +_001514_hash isdn_ppp_read 4 50356 _001514_hash NULL
85051 +_001515_hash isdn_ppp_skb_push 2 5236 _001515_hash NULL
85052 +_001516_hash isku_sysfs_read 6 58806 _001516_hash NULL
85053 +_001517_hash isku_sysfs_write 6 49767 _001517_hash NULL
85054 +_001520_hash jbd2_alloc 1 41359 _001520_hash NULL
85055 +_001521_hash jffs2_do_link 6 42048 _001521_hash NULL
85056 +_001522_hash jffs2_do_unlink 4 62020 _001522_hash NULL
85057 +_001523_hash jffs2_security_setxattr 4 62107 _001523_hash NULL
85058 +_001524_hash jffs2_trusted_setxattr 4 17048 _001524_hash NULL
85059 +_001525_hash jffs2_user_setxattr 4 10182 _001525_hash NULL
85060 +_001526_hash joydev_ioctl_common 2 49359 _001526_hash NULL
85061 +_001527_hash kernel_setsockopt 5 35913 _001527_hash NULL
85062 +_001528_hash keyctl_describe_key 3 36853 _001528_hash NULL
85063 +_001529_hash keyctl_get_security 3 64418 _001529_hash &_001192_hash
85064 +_001530_hash keyring_read 3 13438 _001530_hash NULL
85065 +_001531_hash kfifo_copy_to_user 3 20646 _001531_hash NULL
85066 +_001532_hash kmem_zalloc_large 1 56128 _001532_hash NULL
85067 +_001533_hash kmp_init 2 41373 _001533_hash NULL
85068 +_001534_hash koneplus_sysfs_write 6 35993 _001534_hash NULL
85069 +_001535_hash kvm_clear_guest_page 4 2308 _001535_hash NULL
85070 +_001536_hash kvm_read_nested_guest_page 5 13337 _001536_hash NULL
85071 +_001537_hash _l2_alloc_skb 1 11883 _001537_hash NULL
85072 +_001538_hash l2cap_create_basic_pdu 3 24869 _001538_hash &_001074_hash
85073 +_001539_hash l2cap_create_connless_pdu 3 37327 _001539_hash NULL
85074 +_001540_hash l2cap_create_iframe_pdu 3 40055 _001540_hash NULL
85075 +_001541_hash l3_alloc_skb 1 32289 _001541_hash NULL
85076 +_001542_hash __lgwrite 4 57669 _001542_hash NULL
85077 +_001543_hash libfc_host_alloc 2 7917 _001543_hash NULL
85078 +_001544_hash llc_alloc_frame 4 64366 _001544_hash NULL
85079 +_001545_hash llcp_sock_sendmsg 4 1092 _001545_hash NULL
85080 +_001546_hash mac_drv_rx_init 2 48898 _001546_hash NULL
85081 +_001547_hash macvtap_get_user 4 28185 _001547_hash NULL
85082 +_001548_hash mdc800_device_read 3 22896 _001548_hash NULL
85083 +_001549_hash memcpy_toiovec 3 54166 _001549_hash &_000892_hash
85084 +_001550_hash memcpy_toiovecend 3-4 19736 _001550_hash NULL
85085 +_001552_hash mempool_create 1 29437 _001552_hash NULL
85086 +_001553_hash mgmt_event 4 12810 _001553_hash NULL
85087 +_001554_hash mgt_set_varlen 4 60916 _001554_hash NULL
85088 +_001555_hash mI_alloc_skb 1 24770 _001555_hash NULL
85089 +_001556_hash mlx4_en_create_rx_ring 3 62498 _001556_hash NULL
85090 +_001557_hash mlx4_en_create_tx_ring 4 48501 _001557_hash NULL
85091 +_001558_hash mlx4_init_cmpt_table 3 11569 _001558_hash NULL
85092 +_001559_hash mon_bin_get_event 4 52863 _001559_hash NULL
85093 +_001560_hash mousedev_read 3 47123 _001560_hash NULL
85094 +_001561_hash move_addr_to_user 2 2868 _001561_hash NULL
85095 +_001562_hash mpihelp_mul 5-3 27805 _001562_hash NULL
85096 +_001564_hash mpi_set_buffer 3 65294 _001564_hash NULL
85097 +_001565_hash mptctl_ioctl 2 12355 _001565_hash NULL
85098 +_001566_hash msnd_fifo_alloc 2 23179 _001566_hash NULL
85099 +_001567_hash mtdswap_init 2 55719 _001567_hash NULL
85100 +_001568_hash mthca_alloc_resize_buf 3 60394 _001568_hash NULL
85101 +_001569_hash mthca_init_cq 2 60011 _001569_hash NULL
85102 +_001570_hash nci_skb_alloc 2 49757 _001570_hash NULL
85103 +_001571_hash neigh_hash_grow 2 17283 _001571_hash NULL
85104 +_001572_hash netdev_alloc_skb 2 62437 _001572_hash NULL
85105 +_001573_hash __netdev_alloc_skb_ip_align 2 55067 _001573_hash NULL
85106 +_001574_hash netlink_change_ngroups 2 16457 _001574_hash NULL
85107 +_001575_hash new_skb 1 21148 _001575_hash NULL
85108 +_001576_hash nfc_alloc_recv_skb 1 10244 _001576_hash NULL
85109 +_001577_hash nfcwilink_skb_alloc 1 16167 _001577_hash NULL
85110 +_001578_hash __nf_nat_mangle_tcp_packet 5-7 8190 _001578_hash NULL
85111 +_001580_hash nf_nat_mangle_udp_packet 5-7 13321 _001580_hash NULL
85112 +_001582_hash nfqnl_mangle 4-2 36226 _001582_hash NULL
85113 +_001583_hash nfs4_realloc_slot_table 2 22859 _001583_hash NULL
85114 +_001584_hash nfs_idmap_get_key 2 39616 _001584_hash NULL
85115 +_001585_hash nfs_readdata_alloc 2 65015 _001585_hash NULL
85116 +_001586_hash nfs_writedata_alloc 2 12133 _001586_hash NULL
85117 +_001587_hash nfulnl_alloc_skb 2 65207 _001587_hash NULL
85118 +_001588_hash ni65_alloc_mem 3 10664 _001588_hash NULL
85119 +_001589_hash nsm_get_handle 4 52089 _001589_hash NULL
85120 +_001590_hash ntfs_malloc_nofs 1 49572 _001590_hash NULL
85121 +_001591_hash ntfs_malloc_nofs_nofail 1 63631 _001591_hash NULL
85122 +_001592_hash nvme_create_queue 3 170 _001592_hash NULL
85123 +_001593_hash ocfs2_control_write 3 54737 _001593_hash NULL
85124 +_001595_hash orinoco_add_extscan_result 3 18207 _001595_hash NULL
85125 +_001596_hash osd_req_read_sg_kern 5 6378 _001596_hash NULL
85126 +_001597_hash osd_req_write_sg_kern 5 10514 _001597_hash NULL
85127 +_001599_hash override_release 2 52032 _001599_hash NULL
85128 +_001600_hash p9_client_read 5 19750 _001600_hash NULL
85129 +_001601_hash packet_snd 3 13634 _001601_hash NULL
85130 +_001602_hash pcbit_stat 2 27364 _001602_hash NULL
85131 +_001603_hash pcpu_extend_area_map 2 12589 _001603_hash NULL
85132 +_001604_hash pep_alloc_skb 3 46303 _001604_hash NULL
85133 +_001605_hash pg_read 3 17276 _001605_hash NULL
85134 +_001606_hash picolcd_debug_eeprom_read 3 14549 _001606_hash NULL
85135 +_001607_hash pkt_alloc_packet_data 1 37928 _001607_hash NULL
85136 +_001608_hash pmcraid_build_passthrough_ioadls 2 62034 _001608_hash NULL
85137 +_001609_hash pn_raw_send 2 54330 _001609_hash NULL
85138 +_001610_hash posix_clock_register 2 5662 _001610_hash NULL
85139 +_001611_hash printer_read 3 54851 _001611_hash NULL
85140 +_001612_hash __proc_file_read 3 54978 _001612_hash NULL
85141 +_001613_hash pskb_may_pull 2 22546 _001613_hash NULL
85142 +_001614_hash __pskb_pull 2 42602 _001614_hash NULL
85143 +_001615_hash ptp_read 4 63251 _001615_hash NULL
85144 +_001616_hash pt_read 3 49136 _001616_hash NULL
85145 +_001617_hash put_cmsg 4 36589 _001617_hash NULL
85146 +_001618_hash px_raw_event 4 49371 _001618_hash NULL
85147 +_001619_hash qla4xxx_post_aen_work 3 46953 _001619_hash NULL
85148 +_001620_hash qla4xxx_post_ping_evt_work 4 8074 _001819_hash NULL nohasharray
85149 +_001621_hash raid5_resize 2 63306 _001621_hash NULL
85150 +_001622_hash rawv6_sendmsg 4 20080 _001622_hash NULL
85151 +_001623_hash rds_message_map_pages 2 31487 _001623_hash NULL
85152 +_001624_hash rds_sendmsg 4 40976 _001624_hash NULL
85153 +_001625_hash read_flush 3 43851 _001625_hash NULL
85154 +_001626_hash read_profile 3 27859 _001626_hash NULL
85155 +_001627_hash read_vmcore 3 26501 _001627_hash NULL
85156 +_001628_hash redirected_tty_write 3 65297 _001628_hash NULL
85157 +_001629_hash refill_pool 2 19477 _001629_hash NULL
85158 +_001630_hash __register_chrdev 2-3 54223 _001630_hash NULL
85159 +_001632_hash regmap_raw_write 4 53803 _001632_hash NULL
85160 +_001633_hash reiserfs_allocate_list_bitmaps 3 21732 _001633_hash NULL
85161 +_001634_hash reiserfs_resize 2 34377 _001634_hash NULL
85162 +_001635_hash request_key_auth_read 3 24109 _001635_hash NULL
85163 +_001636_hash rfcomm_wmalloc 2 58090 _001636_hash NULL
85164 +_001637_hash rfkill_fop_read 3 54711 _001637_hash NULL
85165 +_001638_hash rng_dev_read 3 41581 _001638_hash NULL
85166 +_001639_hash roccat_read 3 41093 _001639_hash &_001034_hash
85167 +_001640_hash rx 4 57944 _001640_hash NULL
85168 +_001641_hash rxrpc_client_sendmsg 5 23236 _001641_hash NULL
85169 +_001642_hash rxrpc_kernel_send_data 3 60083 _001642_hash NULL
85170 +_001643_hash rxrpc_server_sendmsg 4 37331 _001643_hash NULL
85171 +_001644_hash savu_sysfs_write 6 42273 _001644_hash NULL
85172 +_001645_hash sco_sock_sendmsg 4 62542 _001645_hash NULL
85173 +_001646_hash scsi_nl_send_vendor_msg 5 16394 _001646_hash NULL
85174 +_001647_hash scsi_register 2 49094 _001647_hash NULL
85175 +_001648_hash sctp_datamsg_from_user 4 55342 _001648_hash NULL
85176 +_001649_hash sctp_getsockopt_events 2 3607 _001649_hash NULL
85177 +_001650_hash sctp_getsockopt_maxburst 2 42941 _001650_hash NULL
85178 +_001651_hash sctp_getsockopt_maxseg 2 10737 _001651_hash NULL
85179 +_001652_hash sctp_make_chunk 4 12986 _001652_hash NULL
85180 +_001653_hash sctpprobe_read 3 17741 _001653_hash NULL
85181 +_001654_hash sctp_tsnmap_mark 2 35929 _001654_hash NULL
85182 +_001655_hash sctp_ulpevent_new 1 33377 _001655_hash NULL
85183 +_001656_hash sdhci_alloc_host 2 7509 _001656_hash NULL
85184 +_001657_hash selinux_inode_post_setxattr 4 26037 _001657_hash NULL
85185 +_001658_hash selinux_inode_setsecurity 4 18148 _001658_hash NULL
85186 +_001659_hash selinux_inode_setxattr 4 10708 _001659_hash NULL
85187 +_001660_hash selinux_secctx_to_secid 2 63744 _001660_hash NULL
85188 +_001661_hash selinux_setprocattr 4 55611 _001661_hash NULL
85189 +_001662_hash sel_write_context 3 25726 _001662_hash &_001329_hash
85190 +_001663_hash send_command 4 10832 _001663_hash NULL
85191 +_001664_hash seq_copy_in_user 3 18543 _001664_hash NULL
85192 +_001665_hash seq_open_net 4 8968 _001779_hash NULL nohasharray
85193 +_001666_hash seq_open_private 3 61589 _001666_hash NULL
85194 +_001667_hash set_arg 3 42824 _001667_hash NULL
85195 +_001668_hash sg_read 3 25799 _001668_hash NULL
85196 +_001669_hash shash_async_setkey 3 10720 _003506_hash NULL nohasharray
85197 +_001670_hash shash_compat_setkey 3 12267 _001670_hash NULL
85198 +_001671_hash shmem_setxattr 4 55867 _001671_hash NULL
85199 +_001672_hash simple_read_from_buffer 2-5 55957 _001672_hash NULL
85200 +_001674_hash sisusb_clear_vram 2-3 57466 _001674_hash NULL
85201 +_001676_hash sisusbcon_do_font_op 9 52271 _001676_hash NULL
85202 +_001677_hash sisusb_copy_memory 4 35016 _001677_hash NULL
85203 +_001678_hash sisusb_write 3 44834 _001678_hash NULL
85204 +_001680_hash skb_cow 2 26138 _001680_hash NULL
85205 +_001681_hash skb_cow_head 2 52495 _001681_hash NULL
85206 +_001682_hash skb_make_writable 2 24783 _001682_hash NULL
85207 +_001683_hash skb_padto 2 50759 _001683_hash NULL
85208 +_001684_hash sk_stream_alloc_skb 2 57622 _001684_hash NULL
85209 +_001685_hash smk_write_access2 3 19170 _001685_hash NULL
85210 +_001686_hash smk_write_access 3 49561 _001686_hash NULL
85211 +_001687_hash snd_es1938_capture_copy 5 25930 _001687_hash NULL
85212 +_001688_hash snd_gus_dram_peek 4 9062 _001688_hash NULL
85213 +_001689_hash snd_hdsp_capture_copy 5 4011 _001689_hash NULL
85214 +_001690_hash snd_korg1212_copy_to 6 92 _001690_hash NULL
85215 +_001691_hash snd_opl4_mem_proc_read 5 63774 _001691_hash NULL
85216 +_001692_hash snd_pcm_oss_read1 3 63771 _001692_hash NULL
85217 +_001693_hash snd_pcm_plugin_alloc 2 12580 _001693_hash NULL
85218 +_001694_hash snd_rawmidi_kernel_read1 4 36740 _001694_hash NULL
85219 +_001695_hash snd_rme9652_capture_copy 5 10287 _001695_hash NULL
85220 +_001696_hash sock_alloc_send_pskb 2 21246 _001696_hash NULL
85221 +_001697_hash sock_rmalloc 2 59740 _002491_hash NULL nohasharray
85222 +_001698_hash sock_wmalloc 2 16472 _001698_hash NULL
85223 +_001699_hash solos_param_store 4 34755 _001699_hash NULL
85224 +_001702_hash srp_target_alloc 3 37288 _001702_hash NULL
85225 +_001703_hash store_ifalias 4 35088 _001703_hash NULL
85226 +_001704_hash store_msg 3 56417 _001704_hash NULL
85227 +_001705_hash str_to_user 2 11411 _001705_hash NULL
85228 +_001706_hash subbuf_read_actor 3 2071 _001706_hash NULL
85229 +_001707_hash sys_fgetxattr 4 25166 _001707_hash NULL
85230 +_001708_hash sys_gethostname 2 49698 _001708_hash NULL
85231 +_001709_hash sys_getxattr 4 37418 _001709_hash NULL
85232 +_001710_hash sys_init_module 2 36047 _001710_hash NULL
85233 +_001711_hash sys_kexec_load 2 14222 _001711_hash NULL
85234 +_001712_hash sys_lgetxattr 4 45531 _001712_hash NULL
85235 +_001713_hash syslog_print 2 307 _001713_hash NULL
85236 +_001714_hash sys_msgsnd 3 44537 _001714_hash &_000139_hash
85237 +_001715_hash sys_process_vm_readv 3-5 19090 _003104_hash NULL nohasharray
85238 +_001717_hash sys_process_vm_writev 3-5 4928 _001717_hash NULL
85239 +_001719_hash sys_pselect6 1 57449 _001719_hash NULL
85240 +_001720_hash sys_sched_getaffinity 2 60033 _001720_hash NULL
85241 +_001721_hash sys_setsockopt 5 35320 _001721_hash NULL
85242 +_001722_hash t3_init_l2t 1 8261 _001722_hash NULL
85243 +_001723_hash t4vf_pktgl_to_skb 2 39005 _001723_hash NULL
85244 +_001724_hash tcp_collapse 5-6 63294 _001724_hash NULL
85245 +_001726_hash tcp_sendmsg 4 30296 _001726_hash NULL
85246 +_001727_hash team_options_register 3 20091 _001727_hash NULL
85247 +_001728_hash tipc_buf_acquire 1 60437 _001728_hash NULL
85248 +_001729_hash tipc_cfg_reply_alloc 1 27606 _001729_hash NULL
85249 +_001730_hash tipc_send2name 6 16809 _001730_hash NULL
85250 +_001731_hash tipc_send2port 5 63935 _001731_hash NULL
85251 +_001732_hash tipc_send 4 51238 _001732_hash NULL
85252 +_001733_hash tnode_new 3 44757 _002769_hash NULL nohasharray
85253 +_001734_hash tomoyo_read_self 3 33539 _001734_hash NULL
85254 +_001735_hash tomoyo_update_domain 2 5498 _001735_hash NULL
85255 +_001736_hash tomoyo_update_policy 2 40458 _001736_hash NULL
85256 +_001737_hash tpm_read 3 50344 _001737_hash NULL
85257 +_001738_hash TSS_rawhmac 3 17486 _001738_hash NULL
85258 +_001739_hash __tty_buffer_request_room 2 27700 _001739_hash NULL
85259 +_001740_hash tun_get_user 4 39099 _001740_hash NULL
85260 +_001741_hash ubi_dump_flash 4 46381 _001741_hash NULL
85261 +_001742_hash ubi_io_write 4-5 15870 _003453_hash NULL nohasharray
85262 +_001744_hash udp_setsockopt 5 25985 _001744_hash NULL
85263 +_001745_hash udpv6_setsockopt 5 18487 _001745_hash NULL
85264 +_001746_hash uio_read 3 49300 _001746_hash NULL
85265 +_001747_hash ulog_alloc_skb 1 23427 _001747_hash NULL
85266 +_001748_hash unix_dgram_sendmsg 4 45699 _001748_hash NULL
85267 +_001749_hash unlink1 3 63059 _001749_hash NULL
85268 +_001751_hash usbdev_read 3 45114 _001751_hash NULL
85269 +_001752_hash usblp_ioctl 2 30203 _001752_hash NULL
85270 +_001753_hash usblp_read 3 57342 _003832_hash NULL nohasharray
85271 +_001754_hash usbtmc_read 3 32377 _001754_hash NULL
85272 +_001755_hash _usb_writeN_sync 4 31682 _001755_hash NULL
85273 +_001756_hash user_read 3 51881 _001756_hash NULL
85274 +_001757_hash vcs_read 3 8017 _001757_hash NULL
85275 +_001758_hash vdma_mem_alloc 1 6171 _001758_hash NULL
85276 +_001759_hash venus_create 4 20555 _001759_hash NULL
85277 +_001760_hash venus_link 5 32165 _001760_hash NULL
85278 +_001761_hash venus_lookup 4 8121 _001761_hash NULL
85279 +_001762_hash venus_mkdir 4 8967 _001762_hash NULL
85280 +_001763_hash venus_remove 4 59781 _001763_hash NULL
85281 +_001764_hash venus_rename 4-5 17707 _003784_hash NULL nohasharray
85282 +_001766_hash venus_rmdir 4 45564 _001766_hash NULL
85283 +_001767_hash venus_symlink 4-6 23570 _001767_hash NULL
85284 +_001769_hash vfs_readlink 3 54368 _001769_hash NULL
85285 +_001770_hash vfs_readv 3 38011 _001770_hash NULL
85286 +_001771_hash vfs_writev 3 25278 _001771_hash NULL
85287 +_001772_hash vga_arb_read 3 4886 _001772_hash NULL
85288 +_001773_hash vgacon_adjust_height 2 28124 _001773_hash NULL
85289 +_001774_hash vhci_put_user 4 12604 _001774_hash NULL
85290 +_001775_hash vhost_add_used_n 3 10760 _001775_hash NULL
85291 +_001776_hash virtnet_send_command 5-6 61993 _001776_hash NULL
85292 +_001778_hash vmbus_establish_gpadl 3 4495 _001778_hash NULL
85293 +_001779_hash vol_cdev_read 3 8968 _001779_hash &_001665_hash
85294 +_001780_hash wdm_read 3 6549 _001780_hash NULL
85295 +_001781_hash write_adapter_mem 3 3234 _001781_hash NULL
85296 +_001782_hash wusb_prf 7 54261 _001782_hash &_000065_hash
85297 +_001783_hash xdi_copy_to_user 4 48900 _001783_hash NULL
85298 +_001784_hash xfs_buf_associate_memory 3 17915 _001784_hash NULL
85299 +_001785_hash xfs_buf_get_maps 2 4581 _001785_hash NULL
85300 +_001786_hash xfs_buf_get_uncached 2 51477 _001786_hash NULL
85301 +_001787_hash xfs_buf_item_get_format 2 189 _001787_hash NULL
85302 +_001788_hash xfs_buf_map_from_irec 5 2368 _002641_hash NULL nohasharray
85303 +_001789_hash xfs_dir2_block_to_sf 3 37868 _001789_hash NULL
85304 +_001790_hash xfs_dir2_leaf_getdents 3 23841 _001790_hash NULL
85305 +_001791_hash xfs_dir2_sf_addname_hard 3 54254 _001791_hash NULL
85306 +_001792_hash xfs_efd_init 3 5463 _001792_hash NULL
85307 +_001793_hash xfs_efi_init 2 5476 _001793_hash NULL
85308 +_001794_hash xfs_iext_realloc_direct 2 20521 _001794_hash NULL
85309 +_001795_hash xfs_iext_realloc_indirect 2 59211 _001795_hash NULL
85310 +_001796_hash xfs_inumbers_fmt 3 12817 _001796_hash NULL
85311 +_001797_hash xhci_alloc_streams 5 37586 _001797_hash NULL
85312 +_001798_hash xlog_recover_add_to_cont_trans 4 44102 _001798_hash NULL
85313 +_001799_hash xz_dec_lzma2_create 2 36353 _002713_hash NULL nohasharray
85314 +_001800_hash _zd_iowrite32v_locked 3 44725 _001800_hash NULL
85315 +_001801_hash a2mp_chan_alloc_skb_cb 2 27159 _001801_hash NULL
85316 +_001802_hash aat2870_reg_read_file 3 12221 _001802_hash NULL
85317 +_001803_hash add_partition 2 55588 _001803_hash NULL
85318 +_001804_hash add_sctp_bind_addr 3 12269 _001804_hash NULL
85319 +_001805_hash _add_sg_continuation_descriptor 3 54721 _001805_hash NULL
85320 +_001806_hash afs_cell_lookup 2 8482 _001806_hash NULL
85321 +_001807_hash afs_send_simple_reply 3 63940 _001807_hash NULL
85322 +_001808_hash agp_allocate_memory_wrap 1 16576 _001808_hash NULL
85323 +_001809_hash __alloc_bootmem 1 31498 _001809_hash NULL
85324 +_001810_hash __alloc_bootmem_low 1 43423 _003425_hash NULL nohasharray
85325 +_001811_hash __alloc_bootmem_node_high 2 65076 _001811_hash NULL
85326 +_001812_hash alloc_cc770dev 1 48186 _001812_hash NULL
85327 +_001813_hash __alloc_ei_netdev 1 29338 _001813_hash NULL
85328 +_001814_hash __alloc_eip_netdev 1 51549 _001814_hash NULL
85329 +_001815_hash alloc_libipw 1 22708 _001815_hash NULL
85330 +_001816_hash _alloc_mISDN_skb 3 52232 _001816_hash NULL
85331 +_001817_hash alloc_pg_vec 2 8533 _001817_hash NULL
85332 +_001818_hash alloc_sja1000dev 1 17868 _001818_hash NULL
85333 +_001819_hash alloc_targets 2 8074 _001819_hash &_001620_hash
85334 +_001822_hash ath6kl_disconnect_timeout_read 3 3650 _001822_hash NULL
85335 +_001823_hash ath6kl_endpoint_stats_read 3 41554 _001823_hash NULL
85336 +_001824_hash ath6kl_fwlog_mask_read 3 2050 _001824_hash NULL
85337 +_001825_hash ath6kl_keepalive_read 3 44303 _001825_hash NULL
85338 +_001826_hash ath6kl_listen_int_read 3 10355 _001826_hash NULL
85339 +_001827_hash ath6kl_lrssi_roam_read 3 61022 _001827_hash NULL
85340 +_001828_hash ath6kl_regdump_read 3 14393 _001828_hash NULL
85341 +_001829_hash ath6kl_regread_read 3 25884 _001829_hash NULL
85342 +_001830_hash ath6kl_regwrite_read 3 48747 _001830_hash NULL
85343 +_001831_hash ath6kl_roam_table_read 3 26166 _001831_hash NULL
85344 +_001832_hash ath9k_debugfs_read_buf 3 25316 _001832_hash NULL
85345 +_001833_hash ath9k_multi_regread 4 65056 _001833_hash NULL
85346 +_001834_hash ath_rxbuf_alloc 2 24745 _001834_hash NULL
85347 +_001835_hash atk_debugfs_ggrp_read 3 29522 _001835_hash NULL
85348 +_001836_hash audit_log_n_untrustedstring 3 9548 _001836_hash NULL
85349 +_001837_hash ax25_send_frame 2 19964 _001837_hash NULL
85350 +_001838_hash b43_debugfs_read 3 24425 _001838_hash NULL
85351 +_001839_hash b43legacy_debugfs_read 3 2473 _001839_hash NULL
85352 +_001840_hash batadv_bla_is_backbone_gw 3 58488 _001840_hash NULL
85353 +_001841_hash batadv_check_management_packet 3 52993 _001841_hash NULL
85354 +_001842_hash batadv_check_unicast_packet 2 10866 _001842_hash NULL
85355 +_001843_hash batadv_interface_rx 4 8568 _001843_hash NULL
85356 +_001844_hash batadv_skb_head_push 2 11360 _001844_hash NULL
85357 +_001845_hash bchannel_get_rxbuf 2 37213 _001845_hash NULL
85358 +_001846_hash bcm_recvmsg 4 43992 _001846_hash NULL
85359 +_001847_hash bfad_debugfs_read 3 13119 _001847_hash NULL
85360 +_001848_hash bfad_debugfs_read_regrd 3 57830 _001848_hash NULL
85361 +_001849_hash blk_init_tags 1 30592 _001849_hash NULL
85362 +_001850_hash blk_queue_init_tags 2 44355 _001850_hash &_001022_hash
85363 +_001851_hash blk_rq_map_kern 4 47004 _001851_hash NULL
85364 +_001852_hash bm_entry_read 3 10976 _001852_hash NULL
85365 +_001853_hash bm_status_read 3 19583 _001853_hash NULL
85366 +_001854_hash bnad_debugfs_read 3 50665 _001854_hash NULL
85367 +_001855_hash bnad_debugfs_read_regrd 3 51308 _001855_hash NULL
85368 +_001856_hash bnx2i_send_nl_mesg 4 53353 _001856_hash NULL
85369 +_001857_hash brcmf_debugfs_sdio_counter_read 3 58369 _001857_hash NULL
85370 +_001858_hash brcmf_sdio_assert_info 4 52653 _001858_hash NULL
85371 +_001859_hash brcmf_sdio_dump_console 4 37455 _001859_hash NULL
85372 +_001860_hash brcmf_sdio_trap_info 4 48510 _001860_hash NULL
85373 +_001861_hash btmrvl_curpsmode_read 3 46939 _001861_hash NULL
85374 +_001862_hash btmrvl_gpiogap_read 3 4718 _001862_hash NULL
85375 +_001863_hash btmrvl_hscfgcmd_read 3 56303 _001863_hash NULL
85376 +_001864_hash btmrvl_hscmd_read 3 1614 _001864_hash NULL
85377 +_001865_hash btmrvl_hsmode_read 3 1647 _001865_hash NULL
85378 +_001866_hash btmrvl_hsstate_read 3 920 _001866_hash NULL
85379 +_001867_hash btmrvl_pscmd_read 3 24308 _001867_hash NULL
85380 +_001868_hash btmrvl_psmode_read 3 22395 _001868_hash NULL
85381 +_001869_hash btmrvl_psstate_read 3 50683 _001869_hash NULL
85382 +_001870_hash btmrvl_txdnldready_read 3 413 _001870_hash NULL
85383 +_001871_hash btrfs_add_link 5 9973 _001871_hash NULL
85384 +_001872_hash __btrfs_direct_write 4 22273 _001872_hash NULL
85385 +_001873_hash btrfs_discard_extent 2 38547 _001873_hash NULL
85386 +_001874_hash btrfs_file_aio_write 4 21520 _001874_hash NULL
85387 +_001875_hash btrfs_find_create_tree_block 3 55812 _001875_hash NULL
85388 +_001876_hash btrfsic_map_block 2 56751 _001876_hash NULL
85389 +_001877_hash cache_read_pipefs 3 47615 _001877_hash NULL
85390 +_001878_hash cache_read_procfs 3 52882 _001878_hash NULL
85391 +_001879_hash cache_write_pipefs 3 48270 _001879_hash NULL
85392 +_001880_hash cache_write_procfs 3 22491 _001880_hash NULL
85393 +_001881_hash caif_stream_recvmsg 4 13173 _001881_hash NULL
85394 +_001882_hash carl9170_alloc 1 27 _001882_hash NULL
85395 +_001883_hash carl9170_debugfs_read 3 47738 _001883_hash NULL
85396 +_001884_hash ceph_msgpool_init 4 34599 _001884_hash NULL
85397 +_001885_hash cfpkt_add_trail 3 27260 _001885_hash NULL
85398 +_001886_hash cfpkt_create 1 18197 _001886_hash NULL
85399 +_001887_hash cfpkt_pad_trail 2 55511 _003606_hash NULL nohasharray
85400 +_001888_hash cfpkt_split 2 47541 _001888_hash NULL
85401 +_001889_hash cgroup_read_s64 5 19570 _001889_hash NULL
85402 +_001890_hash cgroup_read_u64 5 45532 _001890_hash NULL
85403 +_001891_hash channel_type_read 3 47308 _001891_hash NULL
85404 +_001892_hash check_header 2 56930 _001892_hash NULL
85405 +_001893_hash codec_list_read_file 3 24910 _001893_hash NULL
85406 +_001894_hash configfs_read_file 3 1683 _001894_hash NULL
85407 +_001895_hash console_store 4 36007 _001895_hash NULL
85408 +_001896_hash cpuset_common_file_read 5 8800 _001896_hash NULL
85409 +_001897_hash create_subvol 4 30836 _001897_hash NULL
85410 +_001898_hash cxio_hal_init_resource 2-7-6 29771 _001898_hash &_000295_hash
85411 +_001901_hash cxio_hal_init_rhdl_resource 1 25104 _001901_hash NULL
85412 +_001902_hash dai_list_read_file 3 25421 _001902_hash NULL
85413 +_001903_hash dapm_bias_read_file 3 64715 _001903_hash NULL
85414 +_001904_hash dapm_widget_power_read_file 3 59950 _001983_hash NULL nohasharray
85415 +_001907_hash dbgfs_frame 3 45917 _001907_hash NULL
85416 +_001908_hash dbgfs_state 3 38894 _001908_hash NULL
85417 +_001909_hash dccp_manip_pkt 2 30229 _001909_hash NULL
85418 +_001910_hash ddp_ppod_write_idata 5 25610 _001910_hash NULL
85419 +_001911_hash debugfs_read 3 62535 _001911_hash NULL
85420 +_001912_hash debug_output 3 18575 _001912_hash NULL
85421 +_001913_hash debug_read 3 19322 _001913_hash NULL
85422 +_001914_hash dev_alloc_skb 1 19517 _001914_hash &_001366_hash
85423 +_001915_hash dfs_file_read 3 18116 _001915_hash NULL
85424 +_001916_hash diva_alloc_dma_map 2 23798 _001916_hash NULL
85425 +_001917_hash diva_xdi_write 4 63975 _001917_hash NULL
85426 +_001918_hash dma_memcpy_pg_to_iovec 6 1725 _001918_hash NULL
85427 +_001919_hash dma_memcpy_to_iovec 5 12173 _001919_hash NULL
85428 +_001920_hash dma_show_regs 3 35266 _001920_hash NULL
85429 +_001921_hash dm_exception_table_init 2 39645 _001921_hash &_001149_hash
85430 +_001922_hash dn_nsp_do_disc 2-6 49474 _001922_hash NULL
85431 +_001924_hash dn_recvmsg 4 17213 _001924_hash NULL
85432 +_001925_hash dns_resolver_read 3 54658 _001925_hash NULL
85433 +_001926_hash do_msgrcv 4 5590 _001926_hash NULL
85434 +_001927_hash do_syslog 3 56807 _001927_hash NULL
85435 +_001928_hash dpcm_state_read_file 3 65489 _001928_hash NULL
85436 +_001929_hash dsp_cmx_send_member 2 15625 _001929_hash NULL
85437 +_001930_hash fallback_on_nodma_alloc 2 35332 _001930_hash NULL
85438 +_001931_hash fc_frame_alloc 2 1596 _001931_hash NULL
85439 +_001932_hash fc_frame_alloc_fill 2 59394 _001932_hash NULL
85440 +_001933_hash filter_read 3 61692 _001933_hash NULL
85441 +_001934_hash __finish_unordered_dir 4 33198 _001934_hash NULL
85442 +_001935_hash format_devstat_counter 3 32550 _001935_hash NULL
85443 +_001936_hash fragmentation_threshold_read 3 61718 _001936_hash NULL
85444 +_001937_hash fuse_conn_limit_read 3 20084 _001937_hash NULL
85445 +_001938_hash fuse_conn_waiting_read 3 49762 _001938_hash NULL
85446 +_001939_hash fuse_file_aio_write 4 46399 _001939_hash NULL
85447 +_001940_hash generic_readlink 3 32654 _001940_hash NULL
85448 +_001941_hash gre_manip_pkt 2 38785 _001941_hash NULL
85449 +_001942_hash handle_eviocgbit 3 44193 _001942_hash NULL
85450 +_001943_hash handle_response 5 55951 _001943_hash NULL
85451 +_001944_hash handle_response_icmp 7 39574 _001944_hash NULL
85452 +_001945_hash hash_recvmsg 4 50924 _001945_hash NULL
85453 +_001946_hash hci_send_cmd 3 43810 _001946_hash NULL
85454 +_001947_hash hci_si_event 3 1404 _001947_hash NULL
85455 +_001948_hash help 4 14971 _001948_hash NULL
85456 +_001949_hash hfcpci_empty_bfifo 4 62323 _001949_hash NULL
85457 +_001950_hash hidp_send_ctrl_message 4 43702 _001950_hash NULL
85458 +_001951_hash ht40allow_map_read 3 55209 _001951_hash &_001512_hash
85459 +_001952_hash hwflags_read 3 52318 _001952_hash NULL
85460 +_001953_hash hysdn_conf_read 3 42324 _001953_hash NULL
85461 +_001954_hash hysdn_sched_rx 3 60533 _001954_hash NULL
85462 +_001955_hash i2400m_rx_stats_read 3 57706 _001955_hash NULL
85463 +_001956_hash i2400m_tx_stats_read 3 28527 _001956_hash NULL
85464 +_001957_hash icmp_manip_pkt 2 48801 _001957_hash NULL
85465 +_001958_hash idmouse_read 3 63374 _001958_hash NULL
85466 +_001959_hash ieee80211_if_read 3 6785 _001959_hash NULL
85467 +_001960_hash ieee80211_rx_bss_info 3 61630 _001960_hash NULL
85468 +_001961_hash ikconfig_read_current 3 1658 _001961_hash NULL
85469 +_001962_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001962_hash NULL
85470 +_001963_hash il3945_ucode_general_stats_read 3 46111 _001963_hash NULL
85471 +_001964_hash il3945_ucode_rx_stats_read 3 3048 _001964_hash NULL
85472 +_001965_hash il3945_ucode_tx_stats_read 3 36016 _001965_hash NULL
85473 +_001966_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001966_hash NULL
85474 +_001967_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001967_hash NULL
85475 +_001968_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001968_hash NULL
85476 +_001969_hash il4965_ucode_general_stats_read 3 56277 _001969_hash NULL
85477 +_001970_hash il4965_ucode_rx_stats_read 3 61948 _001970_hash NULL
85478 +_001971_hash il4965_ucode_tx_stats_read 3 12064 _001971_hash NULL
85479 +_001972_hash il_dbgfs_chain_noise_read 3 38044 _001972_hash NULL
85480 +_001973_hash il_dbgfs_channels_read 3 25005 _001973_hash NULL
85481 +_001974_hash il_dbgfs_disable_ht40_read 3 42386 _001974_hash NULL
85482 +_001975_hash il_dbgfs_fh_reg_read 3 40993 _001975_hash NULL
85483 +_001976_hash il_dbgfs_force_reset_read 3 57517 _001976_hash NULL
85484 +_001977_hash il_dbgfs_interrupt_read 3 3351 _001977_hash NULL
85485 +_001978_hash il_dbgfs_missed_beacon_read 3 59956 _001978_hash NULL
85486 +_001979_hash il_dbgfs_nvm_read 3 12288 _001979_hash NULL
85487 +_001980_hash il_dbgfs_power_save_status_read 3 43165 _001980_hash NULL
85488 +_001981_hash il_dbgfs_qos_read 3 33615 _001981_hash NULL
85489 +_001982_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001982_hash NULL
85490 +_001983_hash il_dbgfs_rxon_flags_read 3 59950 _001983_hash &_001904_hash
85491 +_001984_hash il_dbgfs_rx_queue_read 3 11221 _001984_hash NULL
85492 +_001985_hash il_dbgfs_rx_stats_read 3 15243 _001985_hash NULL
85493 +_001986_hash il_dbgfs_sensitivity_read 3 2370 _001986_hash NULL
85494 +_001987_hash il_dbgfs_sram_read 3 62296 _001987_hash NULL
85495 +_001988_hash il_dbgfs_stations_read 3 21532 _001988_hash NULL
85496 +_001989_hash il_dbgfs_status_read 3 58388 _001989_hash NULL
85497 +_001990_hash il_dbgfs_tx_queue_read 3 55668 _001990_hash NULL
85498 +_001991_hash il_dbgfs_tx_stats_read 3 32913 _001991_hash NULL
85499 +_001992_hash ima_show_htable_value 2 57136 _001992_hash NULL
85500 +_001994_hash intel_fake_agp_alloc_by_type 1 1 _001994_hash NULL
85501 +_001995_hash ip4ip6_err 5 36772 _001995_hash NULL
85502 +_001996_hash ip6_append_data 4-5 36490 _003601_hash NULL nohasharray
85503 +_001997_hash ip6ip6_err 5 18308 _001997_hash NULL
85504 +_001998_hash __ip_append_data 7-8 36191 _001998_hash NULL
85505 +_001999_hash ip_vs_icmp_xmit 4 59624 _001999_hash NULL
85506 +_002000_hash ip_vs_icmp_xmit_v6 4 20464 _002000_hash NULL
85507 +_002001_hash ipw_write 3 59807 _002001_hash NULL
85508 +_002002_hash irda_recvmsg_stream 4 35280 _002002_hash NULL
85509 +_002003_hash irq_domain_add_simple 2 46734 _002003_hash NULL
85510 +_002004_hash __iscsi_complete_pdu 4 10726 _002004_hash NULL
85511 +_002005_hash iscsi_nop_out_rsp 4 51117 _002005_hash NULL
85512 +_002006_hash iscsi_tcp_conn_setup 2 16376 _002006_hash NULL
85513 +_002007_hash iwl_dbgfs_bt_traffic_read 3 35534 _002007_hash NULL
85514 +_002008_hash iwl_dbgfs_calib_disabled_read 3 22649 _002008_hash NULL
85515 +_002009_hash iwl_dbgfs_chain_noise_read 3 46355 _002009_hash NULL
85516 +_002010_hash iwl_dbgfs_channels_read 3 6784 _002010_hash NULL
85517 +_002011_hash iwl_dbgfs_current_sleep_command_read 3 2081 _002011_hash NULL
85518 +_002012_hash iwl_dbgfs_disable_ht40_read 3 35761 _002012_hash NULL
85519 +_002013_hash iwl_dbgfs_fh_reg_read 3 879 _002013_hash &_000406_hash
85520 +_002014_hash iwl_dbgfs_interrupt_read 3 23574 _002014_hash NULL
85521 +_002015_hash iwl_dbgfs_log_event_read 3 2107 _002015_hash NULL
85522 +_002016_hash iwl_dbgfs_missed_beacon_read 3 50584 _002016_hash NULL
85523 +_002017_hash iwl_dbgfs_nvm_read 3 23845 _002017_hash NULL
85524 +_002018_hash iwl_dbgfs_plcp_delta_read 3 55407 _002018_hash NULL
85525 +_002019_hash iwl_dbgfs_power_save_status_read 3 54392 _002019_hash NULL
85526 +_002020_hash iwl_dbgfs_protection_mode_read 3 13943 _002020_hash NULL
85527 +_002021_hash iwl_dbgfs_qos_read 3 11753 _002021_hash NULL
85528 +_002022_hash iwl_dbgfs_reply_tx_error_read 3 19205 _002022_hash NULL
85529 +_002023_hash iwl_dbgfs_rf_reset_read 3 26512 _002023_hash NULL
85530 +_002024_hash iwl_dbgfs_rx_handlers_read 3 18708 _002024_hash NULL
85531 +_002025_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _002025_hash NULL
85532 +_002026_hash iwl_dbgfs_rxon_flags_read 3 20795 _002026_hash NULL
85533 +_002027_hash iwl_dbgfs_rx_queue_read 3 19943 _002027_hash NULL
85534 +_002028_hash iwl_dbgfs_sensitivity_read 3 63116 _002731_hash NULL nohasharray
85535 +_002029_hash iwl_dbgfs_sleep_level_override_read 3 3038 _002029_hash NULL
85536 +_002030_hash iwl_dbgfs_sram_read 3 44505 _002030_hash NULL
85537 +_002031_hash iwl_dbgfs_stations_read 3 9309 _002031_hash NULL
85538 +_002032_hash iwl_dbgfs_status_read 3 5171 _002032_hash NULL
85539 +_002033_hash iwl_dbgfs_temperature_read 3 29224 _002033_hash NULL
85540 +_002034_hash iwl_dbgfs_thermal_throttling_read 3 38779 _002034_hash NULL
85541 +_002035_hash iwl_dbgfs_tx_queue_read 3 4635 _002035_hash NULL
85542 +_002036_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _002036_hash NULL
85543 +_002037_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _002037_hash NULL
85544 +_002038_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _002038_hash NULL
85545 +_002039_hash iwl_dbgfs_ucode_tracing_read 3 47983 _002039_hash &_000356_hash
85546 +_002040_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _002040_hash NULL
85547 +_002041_hash iwl_dbgfs_wowlan_sram_read 3 540 _002041_hash NULL
85548 +_002042_hash joydev_ioctl 2 33343 _002042_hash NULL
85549 +_002043_hash kernel_readv 3 35617 _002043_hash NULL
85550 +_002044_hash key_algorithm_read 3 57946 _002044_hash NULL
85551 +_002045_hash key_icverrors_read 3 20895 _002045_hash NULL
85552 +_002046_hash key_key_read 3 3241 _002046_hash NULL
85553 +_002047_hash key_replays_read 3 62746 _002047_hash NULL
85554 +_002048_hash key_rx_spec_read 3 12736 _002048_hash NULL
85555 +_002049_hash key_tx_spec_read 3 4862 _002049_hash NULL
85556 +_002050_hash __kfifo_to_user 3 36555 _002568_hash NULL nohasharray
85557 +_002051_hash __kfifo_to_user_r 3 39123 _002051_hash NULL
85558 +_002052_hash kmem_zalloc_greedy 2-3 65268 _002052_hash NULL
85559 +_002054_hash l1oip_socket_recv 6 56537 _002054_hash NULL
85560 +_002055_hash l2cap_build_cmd 4 48676 _002055_hash NULL
85561 +_002056_hash l2cap_chan_send 3 49995 _002056_hash NULL
85562 +_002057_hash l2cap_segment_sdu 4 48772 _002057_hash NULL
85563 +_002058_hash l2down_create 4 21755 _002058_hash NULL
85564 +_002059_hash l2tp_xmit_skb 3 42672 _002059_hash NULL
85565 +_002060_hash l2up_create 3 6430 _002060_hash NULL
85566 +_002061_hash lbs_debugfs_read 3 30721 _002061_hash NULL
85567 +_002062_hash lbs_dev_info 3 51023 _002062_hash NULL
85568 +_002063_hash lbs_host_sleep_read 3 31013 _002063_hash NULL
85569 +_002064_hash lbs_rdbbp_read 3 45805 _002064_hash NULL
85570 +_002065_hash lbs_rdmac_read 3 418 _002065_hash NULL
85571 +_002066_hash lbs_rdrf_read 3 41431 _002066_hash NULL
85572 +_002067_hash lbs_sleepparams_read 3 10840 _002067_hash NULL
85573 +_002068_hash lbs_threshold_read 5 21046 _002068_hash NULL
85574 +_002069_hash ldisc_receive 4 41516 _002069_hash NULL
85575 +_002070_hash libfc_vport_create 2 4415 _002070_hash NULL
85576 +_002073_hash lkdtm_debugfs_read 3 45752 _002073_hash NULL
85577 +_002074_hash llcp_sock_recvmsg 4 13556 _002074_hash NULL
85578 +_002075_hash long_retry_limit_read 3 59766 _002075_hash NULL
85579 +_002076_hash lpfc_debugfs_dif_err_read 3 36303 _002076_hash NULL
85580 +_002077_hash lpfc_debugfs_read 3 16566 _002077_hash NULL
85581 +_002078_hash lpfc_idiag_baracc_read 3 58466 _002972_hash NULL nohasharray
85582 +_002079_hash lpfc_idiag_ctlacc_read 3 33943 _002079_hash NULL
85583 +_002080_hash lpfc_idiag_drbacc_read 3 15948 _002080_hash NULL
85584 +_002081_hash lpfc_idiag_extacc_read 3 48301 _002081_hash NULL
85585 +_002082_hash lpfc_idiag_mbxacc_read 3 28061 _002082_hash NULL
85586 +_002083_hash lpfc_idiag_pcicfg_read 3 50334 _002083_hash NULL
85587 +_002084_hash lpfc_idiag_queacc_read 3 13950 _002084_hash NULL
85588 +_002085_hash lpfc_idiag_queinfo_read 3 55662 _002085_hash NULL
85589 +_002086_hash lro_gen_skb 6 2644 _002086_hash NULL
85590 +_002087_hash mac80211_format_buffer 2 41010 _002087_hash NULL
85591 +_002088_hash macvtap_alloc_skb 2-4-3 50629 _002088_hash NULL
85592 +_002091_hash macvtap_put_user 4 55609 _002091_hash NULL
85593 +_002092_hash macvtap_sendmsg 4 30629 _002092_hash NULL
85594 +_002093_hash mangle_packet 6-8 27864 _002093_hash NULL
85595 +_002095_hash manip_pkt 3 7741 _002095_hash NULL
85596 +_002096_hash mempool_create_kmalloc_pool 1 41650 _002096_hash NULL
85597 +_002097_hash mempool_create_page_pool 1 30189 _002097_hash NULL
85598 +_002098_hash mempool_create_slab_pool 1 62907 _002098_hash NULL
85599 +_002099_hash mgmt_device_found 10 14146 _002099_hash NULL
85600 +_002100_hash minstrel_stats_read 3 17290 _002100_hash NULL
85601 +_002101_hash mmc_ext_csd_read 3 13205 _002101_hash NULL
85602 +_002102_hash mon_bin_read 3 6841 _002102_hash NULL
85603 +_002103_hash mon_stat_read 3 25238 _002103_hash NULL
85604 +_002105_hash mqueue_read_file 3 6228 _002105_hash NULL
85605 +_002106_hash mwifiex_debug_read 3 53074 _002106_hash NULL
85606 +_002107_hash mwifiex_getlog_read 3 54269 _002107_hash NULL
85607 +_002108_hash mwifiex_info_read 3 53447 _002108_hash NULL
85608 +_002109_hash mwifiex_rdeeprom_read 3 51429 _002109_hash NULL
85609 +_002110_hash mwifiex_regrdwr_read 3 34472 _002110_hash NULL
85610 +_002111_hash named_prepare_buf 2 24532 _002111_hash NULL
85611 +_002112_hash nci_send_cmd 3 58206 _002112_hash NULL
85612 +_002113_hash netdev_alloc_skb_ip_align 2 40811 _002113_hash NULL
85613 +_002114_hash netpoll_send_udp 3 58955 _002114_hash NULL
85614 +_002115_hash nfcwilink_send_bts_cmd 3 10802 _002115_hash NULL
85615 +_002116_hash nf_nat_mangle_tcp_packet 5-7 8643 _002116_hash NULL
85616 +_002119_hash nfsd_vfs_read 6 62605 _002616_hash NULL nohasharray
85617 +_002120_hash nfsd_vfs_write 6 54577 _002120_hash NULL
85618 +_002121_hash nfs_idmap_lookup_id 2 10660 _002121_hash NULL
85619 +_002122_hash ntfs_rl_realloc 3 56831 _002122_hash &_000370_hash
85620 +_002123_hash ntfs_rl_realloc_nofail 3 32173 _002123_hash NULL
85621 +_002124_hash o2hb_debug_read 3 37851 _002124_hash NULL
85622 +_002125_hash o2net_debug_read 3 52105 _002125_hash NULL
85623 +_002126_hash ocfs2_control_read 3 56405 _002126_hash NULL
85624 +_002127_hash ocfs2_debug_read 3 14507 _002127_hash NULL
85625 +_002128_hash oom_adjust_read 3 25127 _002128_hash NULL
85626 +_002129_hash oom_score_adj_read 3 39921 _002426_hash NULL nohasharray
85627 +_002130_hash oprofilefs_str_to_user 3 42182 _002130_hash NULL
85628 +_002131_hash oprofilefs_ulong_to_user 3 11582 _002131_hash NULL
85629 +_002132_hash osd_req_add_get_attr_list 3 49278 _002132_hash NULL
85630 +_002133_hash _osd_req_list_objects 6 4204 _002133_hash NULL
85631 +_002134_hash osd_req_read_kern 5 59990 _002134_hash NULL
85632 +_002135_hash osd_req_write_kern 5 53486 _002135_hash NULL
85633 +_002136_hash osst_read 3 40237 _002136_hash NULL
85634 +_002137_hash p54_alloc_skb 3 34366 _002137_hash &_000485_hash
85635 +_002138_hash p54_init_common 1 23850 _002138_hash NULL
85636 +_002139_hash packet_alloc_skb 2-5-4 62602 _002139_hash NULL
85637 +_002142_hash packet_sendmsg 4 24954 _002142_hash NULL
85638 +_002143_hash page_readlink 3 23346 _002143_hash NULL
85639 +_002144_hash pcf50633_write_block 3 2124 _002144_hash NULL
85640 +_002145_hash pcpu_alloc_alloc_info 1-2 45813 _002145_hash NULL
85641 +_002147_hash pep_indicate 5 38611 _002147_hash NULL
85642 +_002148_hash pep_reply 5 50582 _002148_hash NULL
85643 +_002149_hash pipe_handler_request 5 50774 _003582_hash NULL nohasharray
85644 +_002150_hash platform_list_read_file 3 34734 _002150_hash NULL
85645 +_002151_hash pm860x_bulk_write 3 43875 _002151_hash NULL
85646 +_002152_hash pm_qos_power_read 3 55891 _002152_hash NULL
85647 +_002153_hash port_show_regs 3 5904 _002153_hash NULL
85648 +_002154_hash proc_coredump_filter_read 3 39153 _002154_hash NULL
85649 +_002155_hash proc_fdinfo_read 3 62043 _002155_hash NULL
85650 +_002156_hash proc_file_read 3 53905 _002156_hash NULL
85651 +_002157_hash proc_info_read 3 63344 _002157_hash NULL
85652 +_002158_hash proc_loginuid_read 3 15631 _002158_hash NULL
85653 +_002159_hash proc_pid_attr_read 3 10173 _002159_hash NULL
85654 +_002160_hash proc_pid_readlink 3 52186 _002160_hash NULL
85655 +_002161_hash proc_read 3 43614 _002161_hash NULL
85656 +_002162_hash proc_self_readlink 3 38094 _002162_hash NULL
85657 +_002163_hash proc_sessionid_read 3 6911 _002299_hash NULL nohasharray
85658 +_002164_hash provide_user_output 3 41105 _002164_hash NULL
85659 +_002165_hash pskb_network_may_pull 2 35336 _002165_hash NULL
85660 +_002166_hash pskb_pull 2 65005 _002166_hash NULL
85661 +_002167_hash pstore_file_read 3 57288 _002167_hash NULL
85662 +_002168_hash ql_process_mac_rx_page 4 15543 _002168_hash NULL
85663 +_002169_hash ql_process_mac_rx_skb 4 6689 _002169_hash NULL
85664 +_002170_hash queues_read 3 24877 _002170_hash NULL
85665 +_002171_hash raw_recvmsg 4 17277 _002171_hash NULL
85666 +_002172_hash rcname_read 3 25919 _002172_hash NULL
85667 +_002173_hash read_4k_modal_eeprom 3 30212 _002173_hash NULL
85668 +_002174_hash read_9287_modal_eeprom 3 59327 _002174_hash NULL
85669 +_002175_hash reada_find_extent 2 63486 _002175_hash NULL
85670 +_002176_hash read_def_modal_eeprom 3 14041 _002176_hash NULL
85671 +_002177_hash read_enabled_file_bool 3 37744 _002177_hash NULL
85672 +_002178_hash read_file_ani 3 23161 _002178_hash NULL
85673 +_002179_hash read_file_antenna 3 13574 _002179_hash NULL
85674 +_002180_hash read_file_base_eeprom 3 42168 _002180_hash NULL
85675 +_002181_hash read_file_beacon 3 32595 _002181_hash NULL
85676 +_002182_hash read_file_blob 3 57406 _002182_hash NULL
85677 +_002183_hash read_file_bool 3 4180 _002183_hash NULL
85678 +_002184_hash read_file_credit_dist_stats 3 54367 _002184_hash NULL
85679 +_002185_hash read_file_debug 3 58256 _002185_hash NULL
85680 +_002186_hash read_file_disable_ani 3 6536 _002186_hash NULL
85681 +_002187_hash read_file_dma 3 9530 _002187_hash NULL
85682 +_002188_hash read_file_dump_nfcal 3 18766 _002188_hash NULL
85683 +_002189_hash read_file_frameerrors 3 64001 _002189_hash NULL
85684 +_002190_hash read_file_interrupt 3 61742 _002197_hash NULL nohasharray
85685 +_002191_hash read_file_misc 3 9948 _002191_hash NULL
85686 +_002192_hash read_file_modal_eeprom 3 39909 _002192_hash NULL
85687 +_002193_hash read_file_queue 3 40895 _002193_hash NULL
85688 +_002194_hash read_file_rcstat 3 22854 _002194_hash NULL
85689 +_002195_hash read_file_recv 3 48232 _002195_hash NULL
85690 +_002196_hash read_file_regidx 3 33370 _002196_hash NULL
85691 +_002197_hash read_file_regval 3 61742 _002197_hash &_002190_hash
85692 +_002198_hash read_file_reset 3 52310 _002198_hash NULL
85693 +_002199_hash read_file_rx_chainmask 3 41605 _002199_hash NULL
85694 +_002200_hash read_file_slot 3 50111 _002200_hash NULL
85695 +_002201_hash read_file_stations 3 35795 _002201_hash NULL
85696 +_002202_hash read_file_tgt_int_stats 3 20697 _002202_hash NULL
85697 +_002203_hash read_file_tgt_rx_stats 3 33944 _002203_hash NULL
85698 +_002204_hash read_file_tgt_stats 3 8959 _002204_hash NULL
85699 +_002205_hash read_file_tgt_tx_stats 3 51847 _002205_hash NULL
85700 +_002206_hash read_file_tx_chainmask 3 3829 _002206_hash NULL
85701 +_002207_hash read_file_war_stats 3 292 _002207_hash NULL
85702 +_002208_hash read_file_xmit 3 21487 _002208_hash NULL
85703 +_002209_hash read_flush_pipefs 3 20171 _002209_hash NULL
85704 +_002210_hash read_flush_procfs 3 27642 _002210_hash NULL
85705 +_002211_hash read_from_oldmem 2 3337 _002211_hash NULL
85706 +_002212_hash read_oldmem 3 55658 _002212_hash NULL
85707 +_002213_hash receive_packet 2 12367 _002213_hash NULL
85708 +_002214_hash regmap_name_read_file 3 39379 _002214_hash NULL
85709 +_002215_hash repair_io_failure 4 4815 _002215_hash NULL
85710 +_002216_hash request_key_and_link 4 42693 _002216_hash NULL
85711 +_002217_hash res_counter_read 4 33499 _002217_hash NULL
85712 +_002218_hash rfcomm_tty_write 3 51603 _002218_hash NULL
85713 +_002219_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _002219_hash NULL
85714 +_002220_hash rs_sta_dbgfs_scale_table_read 3 40262 _002220_hash NULL
85715 +_002221_hash rs_sta_dbgfs_stats_table_read 3 56573 _002221_hash NULL
85716 +_002222_hash rts_threshold_read 3 44384 _002222_hash NULL
85717 +_002223_hash rxrpc_sendmsg 4 29049 _002223_hash NULL
85718 +_002224_hash scrub_setup_recheck_block 3-4 56245 _002224_hash NULL
85719 +_002226_hash scsi_adjust_queue_depth 3 12802 _002226_hash NULL
85720 +_002227_hash sctp_make_abort 3 34459 _002227_hash NULL
85721 +_002228_hash sctp_make_asconf 3 4078 _002228_hash NULL
85722 +_002229_hash sctp_make_asconf_ack 3 31726 _002229_hash NULL
85723 +_002230_hash sctp_make_datafrag_empty 3 34737 _002230_hash NULL
85724 +_002231_hash sctp_make_fwdtsn 3 53265 _002231_hash NULL
85725 +_002232_hash sctp_make_heartbeat_ack 4 34411 _002232_hash NULL
85726 +_002233_hash sctp_make_init 4 58401 _002233_hash NULL
85727 +_002234_hash sctp_make_init_ack 4 3335 _002234_hash NULL
85728 +_002235_hash sctp_make_op_error_space 3 5528 _002235_hash NULL
85729 +_002236_hash sctp_manip_pkt 2 40620 _002236_hash NULL
85730 +_002237_hash selinux_inode_notifysecctx 3 36896 _002237_hash NULL
85731 +_002238_hash sel_read_avc_cache_threshold 3 33942 _002238_hash NULL
85732 +_002239_hash sel_read_avc_hash_stats 3 1984 _002239_hash NULL
85733 +_002240_hash sel_read_bool 3 24236 _002240_hash NULL
85734 +_002241_hash sel_read_checkreqprot 3 33068 _002241_hash NULL
85735 +_002242_hash sel_read_class 3 12669 _002960_hash NULL nohasharray
85736 +_002243_hash sel_read_enforce 3 2828 _002243_hash NULL
85737 +_002244_hash sel_read_handle_status 3 56139 _002244_hash NULL
85738 +_002245_hash sel_read_handle_unknown 3 57933 _002245_hash NULL
85739 +_002246_hash sel_read_initcon 3 32362 _002246_hash NULL
85740 +_002247_hash sel_read_mls 3 25369 _002247_hash NULL
85741 +_002248_hash sel_read_perm 3 42302 _002248_hash NULL
85742 +_002249_hash sel_read_policy 3 55947 _002249_hash NULL
85743 +_002250_hash sel_read_policycap 3 28544 _002250_hash NULL
85744 +_002251_hash sel_read_policyvers 3 55 _002827_hash NULL nohasharray
85745 +_002252_hash send_mpa_reject 3 7135 _002252_hash NULL
85746 +_002253_hash send_mpa_reply 3 32372 _002253_hash NULL
85747 +_002254_hash send_msg 4 37323 _002254_hash NULL
85748 +_002255_hash send_packet 4 52960 _002255_hash NULL
85749 +_002256_hash set_rxd_buffer_pointer 8 9950 _002256_hash NULL
85750 +_002257_hash sge_rx 3 50594 _002257_hash NULL
85751 +_002258_hash short_retry_limit_read 3 4687 _002258_hash NULL
85752 +_002259_hash simple_attr_read 3 24738 _002259_hash NULL
85753 +_002260_hash simple_transaction_read 3 17076 _002260_hash NULL
85754 +_002261_hash sisusbcon_bmove 5-7-6 21873 _002261_hash NULL
85755 +_002264_hash sisusbcon_clear 3-5-4 64329 _002264_hash NULL
85756 +_002267_hash sisusbcon_putcs 3 57630 _002267_hash &_001043_hash
85757 +_002268_hash sisusbcon_scroll 5-3-2 31315 _002268_hash NULL
85758 +_002269_hash sisusbcon_scroll_area 3-4 25899 _002269_hash NULL
85759 +_002271_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002271_hash NULL
85760 +_002274_hash skb_copy_datagram_iovec 2-4 5806 _002274_hash NULL
85761 +_002276_hash skb_gro_header_slow 2 34958 _002276_hash NULL
85762 +_002277_hash smk_read_ambient 3 61220 _002277_hash NULL
85763 +_002278_hash smk_read_direct 3 15803 _002278_hash NULL
85764 +_002279_hash smk_read_doi 3 30813 _002279_hash NULL
85765 +_002280_hash smk_read_logging 3 37804 _002280_hash NULL
85766 +_002281_hash smk_read_mapped 3 7562 _002281_hash NULL
85767 +_002282_hash smk_read_onlycap 3 3855 _002282_hash NULL
85768 +_002283_hash smp_build_cmd 3 45853 _002283_hash NULL
85769 +_002284_hash snapshot_read 3 22601 _002284_hash NULL
85770 +_002285_hash snd_cs4281_BA0_read 5 6847 _002285_hash NULL
85771 +_002286_hash snd_cs4281_BA1_read 5 20323 _002286_hash NULL
85772 +_002287_hash snd_cs46xx_io_read 5 45734 _002287_hash NULL
85773 +_002288_hash snd_gus_dram_read 4 56686 _002288_hash NULL
85774 +_002289_hash snd_mixart_BA0_read 5 45069 _002289_hash NULL
85775 +_002290_hash snd_mixart_BA1_read 5 5082 _002290_hash NULL
85776 +_002291_hash snd_pcm_oss_read 3 28317 _002291_hash NULL
85777 +_002292_hash snd_pcm_plug_alloc 2 42339 _002292_hash NULL
85778 +_002293_hash snd_rawmidi_kernel_read 3 4328 _002293_hash NULL
85779 +_002294_hash snd_rawmidi_read 3 56337 _002294_hash NULL
85780 +_002295_hash snd_rme32_capture_copy 5 39653 _002295_hash NULL
85781 +_002296_hash snd_rme96_capture_copy 5 58484 _002296_hash NULL
85782 +_002297_hash snd_soc_hw_bulk_write_raw 4 14245 _002297_hash NULL
85783 +_002298_hash sock_alloc_send_skb 2 23720 _002298_hash NULL
85784 +_002299_hash spi_show_regs 3 6911 _002299_hash &_002163_hash
85785 +_002300_hash sta_agg_status_read 3 14058 _002300_hash NULL
85786 +_002301_hash sta_connected_time_read 3 17435 _002301_hash NULL
85787 +_002302_hash sta_flags_read 3 56710 _002302_hash NULL
85788 +_002303_hash sta_ht_capa_read 3 10366 _002303_hash NULL
85789 +_002304_hash sta_last_seq_ctrl_read 3 19106 _002304_hash NULL
85790 +_002305_hash sta_num_ps_buf_frames_read 3 1488 _002305_hash NULL
85791 +_002306_hash st_read 3 51251 _002306_hash NULL
85792 +_002307_hash supply_map_read_file 3 10608 _002307_hash NULL
85793 +_002308_hash sysfs_read_file 3 42113 _002308_hash NULL
85794 +_002309_hash sys_preadv 3 17100 _002309_hash NULL
85795 +_002310_hash sys_pwritev 3 41722 _002310_hash NULL
85796 +_002311_hash sys_readv 3 50664 _002311_hash NULL
85797 +_002312_hash sys_rt_sigpending 2 24961 _002312_hash NULL
85798 +_002313_hash sys_writev 3 28384 _002313_hash NULL
85799 +_002314_hash tcf_csum_skb_nextlayer 3 64025 _002314_hash NULL
85800 +_002315_hash tcp_fragment 3 20436 _002315_hash NULL
85801 +_002316_hash tcp_manip_pkt 2 14202 _002316_hash NULL
85802 +_002317_hash teiup_create 3 43201 _002317_hash NULL
85803 +_002318_hash test_iso_queue 5 62534 _002318_hash NULL
85804 +_002319_hash tg3_run_loopback 2 30093 _002319_hash NULL
85805 +_002320_hash tipc_msg_build 4 12326 _002320_hash NULL
85806 +_002321_hash TSS_authhmac 3 12839 _002321_hash NULL
85807 +_002322_hash TSS_checkhmac1 5 31429 _002322_hash NULL
85808 +_002323_hash TSS_checkhmac2 5-7 40520 _002323_hash NULL
85809 +_002325_hash tty_audit_log 8 47280 _002325_hash NULL
85810 +_002326_hash tty_buffer_request_room 2 23228 _002326_hash NULL
85811 +_002327_hash tty_insert_flip_string_fixed_flag 4 37428 _002327_hash NULL
85812 +_002328_hash tty_insert_flip_string_flags 4 30969 _002328_hash NULL
85813 +_002329_hash tty_prepare_flip_string 3 39955 _002329_hash NULL
85814 +_002330_hash tty_prepare_flip_string_flags 4 59240 _002330_hash NULL
85815 +_002331_hash tun_alloc_skb 2-4-3 41216 _002331_hash NULL
85816 +_002334_hash tun_sendmsg 4 10337 _002334_hash NULL
85817 +_002335_hash u32_array_read 3 2219 _002335_hash NULL
85818 +_002336_hash ubi_io_write_data 4-5 40305 _002336_hash NULL
85819 +_002338_hash udplite_manip_pkt 2 62433 _002338_hash NULL
85820 +_002339_hash udp_manip_pkt 2 50770 _002339_hash NULL
85821 +_002340_hash uhci_debug_read 3 5911 _002340_hash NULL
85822 +_002341_hash um_idi_read 3 850 _002341_hash NULL
85823 +_002342_hash unix_seqpacket_sendmsg 4 27893 _002342_hash NULL
85824 +_002343_hash unix_stream_recvmsg 4 35210 _002343_hash NULL
85825 +_002344_hash unlink_simple 3 47506 _002344_hash NULL
85826 +_002345_hash use_pool 2 64607 _002345_hash NULL
85827 +_002346_hash v9fs_fid_readn 4 60544 _002346_hash NULL
85828 +_002347_hash v9fs_file_read 3 40858 _002347_hash NULL
85829 +_002348_hash vhci_read 3 47878 _002348_hash NULL
85830 +_002349_hash vhost_add_used_and_signal_n 4 8038 _002349_hash NULL
85831 +_002350_hash vmbus_open 2-3 12154 _002350_hash NULL
85832 +_002352_hash vxge_rx_alloc 3 52024 _002352_hash NULL
85833 +_002353_hash waiters_read 3 40902 _002353_hash NULL
85834 +_002354_hash wm8994_bulk_write 3 13615 _002354_hash NULL
85835 +_002355_hash write_pbl 4 59583 _002355_hash NULL
85836 +_002356_hash wusb_prf_256 7 29203 _002356_hash NULL
85837 +_002357_hash wusb_prf_64 7 51065 _002357_hash NULL
85838 +_002358_hash _xfs_buf_alloc 3 38058 _002358_hash NULL
85839 +_002359_hash xfs_buf_read_uncached 3 42844 _002359_hash NULL
85840 +_002360_hash xfs_file_buffered_aio_write 4 11492 _002360_hash NULL
85841 +_002361_hash xfs_iext_add 3 41422 _002361_hash NULL
85842 +_002362_hash xfs_iext_remove_direct 3 40744 _002362_hash NULL
85843 +_002363_hash xfs_readdir 3 41200 _002363_hash NULL
85844 +_002364_hash xfs_trans_get_efd 3 51148 _002364_hash NULL
85845 +_002365_hash xfs_trans_get_efi 2 7898 _002365_hash NULL
85846 +_002366_hash xlog_bread_offset 3 60030 _002366_hash NULL
85847 +_002367_hash xlog_get_bp 2 23229 _002367_hash NULL
85848 +_002368_hash xz_dec_init 2 29029 _002368_hash NULL
85849 +_002369_hash aac_change_queue_depth 2 825 _002369_hash NULL
85850 +_002370_hash add_rx_skb 3 8257 _002370_hash NULL
85851 +_002371_hash afs_extract_data 5 50261 _002371_hash NULL
85852 +_002372_hash arcmsr_adjust_disk_queue_depth 2 16756 _002372_hash NULL
85853 +_002373_hash atalk_recvmsg 4 22053 _002373_hash NULL
85854 +_002374_hash ath6kl_buf_alloc 1 57304 _002374_hash NULL
85855 +_002376_hash atomic_read_file 3 16227 _002376_hash NULL
85856 +_002377_hash ax25_recvmsg 4 64441 _002377_hash NULL
85857 +_002378_hash batadv_add_packet 3 12136 _002378_hash NULL
85858 +_002379_hash batadv_iv_ogm_aggregate_new 2 54761 _002379_hash NULL
85859 +_002380_hash batadv_tt_response_fill_table 1 39236 _002380_hash NULL
85860 +_002381_hash beiscsi_process_async_pdu 7 39834 _002381_hash NULL
85861 +_002382_hash bioset_create 1 5580 _002382_hash NULL
85862 +_002383_hash bioset_integrity_create 2 62708 _002383_hash NULL
85863 +_002384_hash biovec_create_pools 2 9575 _002384_hash NULL
85864 +_002385_hash bnx2fc_process_l2_frame_compl 3 65072 _002385_hash NULL
85865 +_002386_hash brcmf_sdbrcm_died_dump 3 15841 _002386_hash NULL
85866 +_002387_hash brcmu_pkt_buf_get_skb 1 5556 _002387_hash NULL
85867 +_002388_hash br_send_bpdu 3 29669 _002388_hash NULL
85868 +_002389_hash btrfs_error_discard_extent 2 50444 _002389_hash NULL
85869 +_002390_hash __btrfs_free_reserved_extent 2 31207 _002390_hash NULL
85870 +_002391_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _002391_hash NULL
85871 +_002392_hash btrfsic_create_link_to_next_block 4 58246 _002392_hash NULL
85872 +_002393_hash btrfs_init_new_buffer 4 55761 _002393_hash NULL
85873 +_002394_hash btrfs_mksubvol 3 58240 _002394_hash NULL
85874 +_002395_hash bt_skb_send_alloc 2 6581 _002395_hash NULL
85875 +_002396_hash bt_sock_recvmsg 4 12316 _002396_hash NULL
85876 +_002397_hash bt_sock_stream_recvmsg 4 52518 _002397_hash NULL
85877 +_002398_hash c4iw_reject_cr 3 28174 _002398_hash NULL
85878 +_002399_hash caif_seqpkt_recvmsg 4 32241 _002399_hash NULL
85879 +_002400_hash carl9170_rx_copy_data 2 21656 _002400_hash NULL
85880 +_002401_hash cfpkt_append 3 61206 _002401_hash NULL
85881 +_002402_hash cfpkt_setlen 2 49343 _002402_hash NULL
85882 +_002403_hash cgroup_file_read 3 28804 _002403_hash NULL
85883 +_002404_hash cosa_net_setup_rx 2 38594 _002404_hash NULL
85884 +_002405_hash cpu_type_read 3 36540 _002405_hash NULL
85885 +_002406_hash cxgb4_pktgl_to_skb 2 61899 _002406_hash NULL
85886 +_002408_hash dccp_recvmsg 4 16056 _002408_hash NULL
85887 +_002409_hash ddp_clear_map 4 46152 _002409_hash NULL
85888 +_002410_hash ddp_set_map 4 751 _002410_hash NULL
85889 +_002411_hash depth_read 3 31112 _002411_hash NULL
85890 +_002412_hash dfs_global_file_read 3 7787 _002412_hash NULL
85891 +_002413_hash dgram_recvmsg 4 23104 _002413_hash NULL
85892 +_002414_hash diva_init_dma_map 3 58336 _002414_hash NULL
85893 +_002415_hash divas_write 3 63901 _002415_hash NULL
85894 +_002416_hash dma_push_rx 2 39973 _002416_hash NULL
85895 +_002417_hash dma_skb_copy_datagram_iovec 3-5 21516 _002417_hash NULL
85896 +_002419_hash dm_table_create 3 35687 _002419_hash NULL
85897 +_002420_hash dn_alloc_send_pskb 2 4465 _002420_hash NULL
85898 +_002421_hash dn_nsp_return_disc 2 60296 _002421_hash NULL
85899 +_002422_hash dn_nsp_send_disc 2 23469 _002422_hash NULL
85900 +_002423_hash dsp_tone_hw_message 3 17678 _002423_hash NULL
85901 +_002424_hash e1000_check_copybreak 3 62448 _002424_hash NULL
85902 +_002425_hash enable_read 3 2117 _002425_hash &_000224_hash
85903 +_002426_hash exofs_read_kern 6 39921 _002426_hash &_002129_hash
85904 +_002427_hash fast_rx_path 3 59214 _002427_hash NULL
85905 +_002428_hash fc_change_queue_depth 2 36841 _002428_hash NULL
85906 +_002429_hash fc_fcp_frame_alloc 2 12624 _002429_hash NULL
85907 +_002430_hash fcoe_ctlr_send_keep_alive 3 15308 _002430_hash NULL
85908 +_002431_hash frequency_read 3 64031 _003698_hash NULL nohasharray
85909 +_002432_hash ftdi_process_packet 5 45005 _002432_hash NULL
85910 +_002433_hash fuse_conn_congestion_threshold_read 3 51028 _002433_hash NULL
85911 +_002434_hash fuse_conn_max_background_read 3 10855 _002434_hash NULL
85912 +_002435_hash fwnet_incoming_packet 3 40380 _002435_hash NULL
85913 +_002436_hash fwnet_pd_new 4 39947 _003402_hash NULL nohasharray
85914 +_002437_hash get_alua_req 3 4166 _002437_hash NULL
85915 +_002438_hash get_rdac_req 3 45882 _002438_hash NULL
85916 +_002439_hash got_frame 2 16028 _002439_hash NULL
85917 +_002440_hash gsm_mux_rx_netchar 3 33336 _002440_hash NULL
85918 +_002441_hash hci_sock_recvmsg 4 7072 _002441_hash NULL
85919 +_002442_hash hdlcdev_rx 3 997 _002442_hash NULL
85920 +_002443_hash hdlc_empty_fifo 2 18397 _002443_hash NULL
85921 +_002444_hash hfc_empty_fifo 2 57972 _002444_hash NULL
85922 +_002445_hash hfcpci_empty_fifo 4 2427 _002445_hash NULL
85923 +_002446_hash hfcsusb_rx_frame 3 52745 _002446_hash NULL
85924 +_002447_hash hidp_output_raw_report 3 5629 _002447_hash NULL
85925 +_002448_hash hpsa_change_queue_depth 2 15449 _002448_hash NULL
85926 +_002449_hash hptiop_adjust_disk_queue_depth 2 20122 _002449_hash NULL
85927 +_002450_hash hscx_empty_fifo 2 13360 _002450_hash NULL
85928 +_002451_hash hysdn_rx_netpkt 3 16136 _002451_hash NULL
85929 +_002452_hash i2o_pool_alloc 4 55485 _002452_hash NULL
85930 +_002453_hash ide_queue_pc_tail 5 11673 _002453_hash NULL
85931 +_002454_hash ide_raw_taskfile 4 42355 _002454_hash NULL
85932 +_002455_hash idetape_queue_rw_tail 3 29562 _002455_hash NULL
85933 +_002456_hash ieee80211_amsdu_to_8023s 5 15561 _002456_hash NULL
85934 +_002457_hash ieee80211_fragment 4 33112 _002457_hash NULL
85935 +_002458_hash ieee80211_if_read_aid 3 9705 _002458_hash NULL
85936 +_002459_hash ieee80211_if_read_auto_open_plinks 3 38268 _002459_hash &_000374_hash
85937 +_002460_hash ieee80211_if_read_ave_beacon 3 64924 _002460_hash NULL
85938 +_002461_hash ieee80211_if_read_bssid 3 35161 _002461_hash NULL
85939 +_002462_hash ieee80211_if_read_channel_type 3 23884 _002462_hash NULL
85940 +_002463_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002463_hash NULL
85941 +_002464_hash ieee80211_if_read_dot11MeshForwarding 3 13940 _002464_hash NULL
85942 +_002465_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002465_hash NULL
85943 +_002466_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002466_hash NULL
85944 +_002467_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002467_hash NULL
85945 +_002468_hash ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 _002468_hash NULL
85946 +_002469_hash ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 _002469_hash NULL
85947 +_002470_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002470_hash NULL
85948 +_002471_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002471_hash NULL
85949 +_002472_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002472_hash NULL
85950 +_002473_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002473_hash NULL
85951 +_002474_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002474_hash NULL
85952 +_002475_hash ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 _002475_hash NULL
85953 +_002476_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002476_hash NULL
85954 +_002477_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002477_hash NULL
85955 +_002478_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002478_hash NULL
85956 +_002479_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002479_hash NULL
85957 +_002480_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002480_hash NULL
85958 +_002481_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002481_hash NULL
85959 +_002482_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002482_hash NULL
85960 +_002483_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002483_hash NULL
85961 +_002484_hash ieee80211_if_read_drop_unencrypted 3 37053 _002484_hash NULL
85962 +_002485_hash ieee80211_if_read_dtim_count 3 38419 _002485_hash NULL
85963 +_002486_hash ieee80211_if_read_element_ttl 3 18869 _002486_hash NULL
85964 +_002487_hash ieee80211_if_read_estab_plinks 3 32533 _002487_hash NULL
85965 +_002488_hash ieee80211_if_read_flags 3 57470 _002919_hash NULL nohasharray
85966 +_002489_hash ieee80211_if_read_fwded_frames 3 36520 _002489_hash NULL
85967 +_002490_hash ieee80211_if_read_fwded_mcast 3 39571 _002490_hash &_000162_hash
85968 +_002491_hash ieee80211_if_read_fwded_unicast 3 59740 _002491_hash &_001697_hash
85969 +_002492_hash ieee80211_if_read_ht_opmode 3 29044 _002492_hash NULL
85970 +_002493_hash ieee80211_if_read_last_beacon 3 31257 _002493_hash NULL
85971 +_002494_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002494_hash NULL
85972 +_002495_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002495_hash NULL
85973 +_002496_hash ieee80211_if_read_num_mcast_sta 3 12419 _002496_hash NULL
85974 +_002497_hash ieee80211_if_read_num_sta_ps 3 34722 _002497_hash NULL
85975 +_002498_hash ieee80211_if_read_path_refresh_time 3 25545 _002498_hash NULL
85976 +_002499_hash ieee80211_if_read_peer 3 45233 _002499_hash NULL
85977 +_002500_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002500_hash NULL
85978 +_002501_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002501_hash NULL
85979 +_002502_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002502_hash NULL
85980 +_002503_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002503_hash NULL
85981 +_002504_hash ieee80211_if_read_rssi_threshold 3 49260 _002504_hash NULL
85982 +_002505_hash ieee80211_if_read_smps 3 27416 _002505_hash NULL
85983 +_002506_hash ieee80211_if_read_state 3 9813 _002707_hash NULL nohasharray
85984 +_002507_hash ieee80211_if_read_tkip_mic_test 3 19565 _002507_hash NULL
85985 +_002508_hash ieee80211_if_read_tsf 3 16420 _002508_hash NULL
85986 +_002509_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002509_hash NULL
85987 +_002510_hash ieee80211_if_read_uapsd_queues 3 55150 _002510_hash NULL
85988 +_002511_hash ieee80211_mgmt_tx 9 46860 _002511_hash NULL
85989 +_002512_hash ieee80211_probereq_get 4-6 29069 _002512_hash NULL
85990 +_002514_hash ieee80211_rx_mgmt_beacon 3 24430 _002514_hash NULL
85991 +_002515_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002515_hash NULL
85992 +_002516_hash ieee80211_send_auth 5 24121 _002516_hash NULL
85993 +_002517_hash ieee80211_set_probe_resp 3 10077 _002517_hash NULL
85994 +_002518_hash ieee80211_tdls_mgmt 8 9581 _002518_hash NULL
85995 +_002519_hash ima_show_htable_violations 3 10619 _002519_hash NULL
85996 +_002520_hash ima_show_measurements_count 3 23536 _002520_hash NULL
85997 +_002521_hash insert_one_name 7 61668 _002521_hash NULL
85998 +_002522_hash ip6_ufo_append_data 5-7-6 4780 _002522_hash NULL
85999 +_002525_hash ip_append_data 5-6 16942 _002525_hash NULL
86000 +_002526_hash ip_make_skb 5-6 13129 _002526_hash NULL
86001 +_002527_hash ip_nat_sdp_port 6 52938 _002527_hash NULL
86002 +_002528_hash ip_nat_sip_expect 7 45693 _002528_hash NULL
86003 +_002529_hash ipr_change_queue_depth 2 6431 _002529_hash NULL
86004 +_002530_hash ip_recv_error 3 23109 _002530_hash NULL
86005 +_002531_hash ip_ufo_append_data 6-8-7 12775 _002531_hash NULL
86006 +_002534_hash ipv6_recv_error 3 56347 _002534_hash NULL
86007 +_002535_hash ipv6_recv_rxpmtu 3 7142 _002535_hash NULL
86008 +_002536_hash ipw_packet_received_skb 2 1230 _002536_hash NULL
86009 +_002537_hash ipx_recvmsg 4 44366 _002537_hash NULL
86010 +_002538_hash irda_recvmsg_dgram 4 32631 _002538_hash NULL
86011 +_002539_hash iscsi_change_queue_depth 2 23416 _002539_hash NULL
86012 +_002540_hash iscsi_complete_pdu 4 48372 _002540_hash NULL
86013 +_002541_hash iwch_reject_cr 3 23901 _002541_hash NULL
86014 +_002542_hash ixgb_check_copybreak 3 5847 _002542_hash NULL
86015 +_002543_hash key_conf_hw_key_idx_read 3 25003 _002543_hash NULL
86016 +_002544_hash key_conf_keyidx_read 3 42443 _002544_hash NULL
86017 +_002545_hash key_conf_keylen_read 3 49758 _002545_hash NULL
86018 +_002546_hash key_flags_read 3 25931 _002546_hash NULL
86019 +_002547_hash key_ifindex_read 3 31411 _002547_hash NULL
86020 +_002548_hash key_tx_rx_count_read 3 44742 _002548_hash NULL
86021 +_002549_hash kmsg_read 3 46514 _002549_hash NULL
86022 +_002550_hash l1oip_socket_parse 4 4507 _002550_hash NULL
86023 +_002551_hash l2cap_send_cmd 4 14548 _002551_hash NULL
86024 +_002552_hash l2cap_sock_sendmsg 4 63427 _002552_hash NULL
86025 +_002553_hash l2tp_ip6_recvmsg 4 62874 _002553_hash NULL
86026 +_002554_hash l2tp_ip6_sendmsg 4 7461 _002554_hash NULL
86027 +_002555_hash l2tp_ip_recvmsg 4 22681 _002555_hash NULL
86028 +_002556_hash lbs_bcnmiss_read 3 8678 _002556_hash NULL
86029 +_002557_hash lbs_failcount_read 3 31063 _002557_hash NULL
86030 +_002558_hash lbs_highrssi_read 3 64089 _002558_hash NULL
86031 +_002559_hash lbs_highsnr_read 3 5931 _002559_hash NULL
86032 +_002560_hash lbs_lowrssi_read 3 32242 _002560_hash NULL
86033 +_002561_hash lbs_lowsnr_read 3 29571 _002561_hash NULL
86034 +_002563_hash llc_ui_recvmsg 4 3826 _002563_hash NULL
86035 +_002564_hash lowpan_fragment_xmit 3-4 22095 _002564_hash NULL
86036 +_002566_hash lpfc_change_queue_depth 2 25905 _002566_hash NULL
86037 +_002568_hash macvtap_do_read 4 36555 _002568_hash &_002050_hash
86038 +_002569_hash mangle_sdp_packet 9 36279 _002569_hash NULL
86039 +_002570_hash map_addr 6 4666 _002570_hash NULL
86040 +_002571_hash mcs_unwrap_fir 3 25733 _002571_hash NULL
86041 +_002572_hash mcs_unwrap_mir 3 9455 _002572_hash NULL
86042 +_002573_hash megaraid_change_queue_depth 2 64815 _002573_hash NULL
86043 +_002574_hash megasas_change_queue_depth 2 32747 _002574_hash NULL
86044 +_002575_hash mld_newpack 2 50950 _002575_hash NULL
86045 +_002576_hash mptscsih_change_queue_depth 2 26036 _002576_hash NULL
86046 +_002577_hash named_distribute 4 48544 _002577_hash NULL
86047 +_002578_hash NCR_700_change_queue_depth 2 31742 _002578_hash NULL
86048 +_002579_hash netlink_recvmsg 4 61600 _002579_hash NULL
86049 +_002580_hash nfc_alloc_send_skb 4 3167 _002580_hash NULL
86050 +_002581_hash nf_nat_ftp 5 47948 _002581_hash NULL
86051 +_002582_hash nfsctl_transaction_read 3 48250 _002582_hash NULL
86052 +_002583_hash nfsd_read 5 19568 _002583_hash NULL
86053 +_002584_hash nfsd_read_file 6 62241 _002584_hash NULL
86054 +_002585_hash nfsd_write 6 54809 _002585_hash NULL
86055 +_002586_hash nfs_map_group_to_gid 3 15892 _002586_hash NULL
86056 +_002587_hash nfs_map_name_to_uid 3 51132 _002587_hash NULL
86057 +_002588_hash nr_recvmsg 4 12649 _002588_hash NULL
86058 +_002589_hash ntfs_rl_append 2-4 6037 _002589_hash NULL
86059 +_002591_hash ntfs_rl_insert 2-4 4931 _002591_hash NULL
86060 +_002593_hash ntfs_rl_replace 2-4 14136 _002593_hash NULL
86061 +_002595_hash ntfs_rl_split 2-4 52328 _002595_hash NULL
86062 +_002597_hash osd_req_list_collection_objects 5 36664 _002597_hash NULL
86063 +_002598_hash osd_req_list_partition_objects 5 56464 _002598_hash NULL
86064 +_002599_hash osd_req_read_sg 5 47905 _002599_hash NULL
86065 +_002600_hash osd_req_write_sg 5 50908 _002600_hash NULL
86066 +_002602_hash p54_download_eeprom 4 43842 _002602_hash NULL
86067 +_002604_hash packet_recv_error 3 16669 _002604_hash NULL
86068 +_002605_hash packet_recvmsg 4 47700 _002605_hash NULL
86069 +_002606_hash pep_recvmsg 4 19402 _002606_hash NULL
86070 +_002607_hash pfkey_recvmsg 4 53604 _002607_hash NULL
86071 +_002608_hash ping_recvmsg 4 25597 _002608_hash NULL
86072 +_002609_hash pmcraid_change_queue_depth 2 9116 _002609_hash NULL
86073 +_002610_hash pn_recvmsg 4 30887 _002610_hash NULL
86074 +_002611_hash pointer_size_read 3 51863 _002611_hash NULL
86075 +_002612_hash power_read 3 15939 _002612_hash NULL
86076 +_002613_hash pppoe_recvmsg 4 15073 _002613_hash NULL
86077 +_002614_hash pppol2tp_recvmsg 4 57742 _002993_hash NULL nohasharray
86078 +_002615_hash ppp_tx_cp 5 62044 _002615_hash NULL
86079 +_002616_hash prism2_send_mgmt 4 62605 _002616_hash &_002119_hash
86080 +_002617_hash prism2_sta_send_mgmt 5 43916 _002617_hash NULL
86081 +_002618_hash prison_create 1 43623 _002618_hash NULL
86082 +_002619_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002619_hash NULL
86083 +_002620_hash qla2x00_change_queue_depth 2 24742 _002620_hash NULL
86084 +_002621_hash _queue_data 4 54983 _002621_hash NULL
86085 +_002622_hash raw_recvmsg 4 52529 _002622_hash NULL
86086 +_002623_hash rawsock_recvmsg 4 12144 _002623_hash NULL
86087 +_002624_hash rawv6_recvmsg 4 30265 _002624_hash NULL
86088 +_002625_hash rds_tcp_data_recv 3 53476 _002625_hash NULL
86089 +_002626_hash reada_add_block 2 54247 _002626_hash NULL
86090 +_002627_hash readahead_tree_block 3 36285 _002627_hash NULL
86091 +_002628_hash reada_tree_block_flagged 3 18402 _002628_hash NULL
86092 +_002629_hash read_dma 3 55086 _002629_hash NULL
86093 +_002630_hash read_fifo 3 826 _002630_hash NULL
86094 +_002631_hash read_tree_block 3 841 _002631_hash NULL
86095 +_002632_hash receive_copy 3 12216 _002632_hash NULL
86096 +_002633_hash recover_peb 6-7 29238 _002633_hash NULL
86097 +_002635_hash recv_msg 4 48709 _002635_hash NULL
86098 +_002636_hash recv_stream 4 30138 _002636_hash NULL
86099 +_002637_hash _req_append_segment 2 41031 _002637_hash NULL
86100 +_002638_hash request_key_async 4 6990 _002638_hash NULL
86101 +_002639_hash request_key_async_with_auxdata 4 46624 _002639_hash NULL
86102 +_002640_hash request_key_with_auxdata 4 24515 _002640_hash NULL
86103 +_002641_hash rose_recvmsg 4 2368 _002641_hash &_001788_hash
86104 +_002642_hash rtl8169_try_rx_copy 3 705 _002642_hash NULL
86105 +_002643_hash _rtl92s_firmware_downloadcode 3 14021 _002643_hash NULL
86106 +_002644_hash rx_data 4 60442 _002644_hash NULL
86107 +_002645_hash rxrpc_recvmsg 4 26233 _002645_hash NULL
86108 +_002646_hash sas_change_queue_depth 2 18555 _002646_hash NULL
86109 +_002647_hash scsi_activate_tcq 2 42640 _002647_hash NULL
86110 +_002648_hash scsi_deactivate_tcq 2 47086 _002648_hash NULL
86111 +_002649_hash scsi_execute 5 33596 _002649_hash NULL
86112 +_002650_hash _scsih_adjust_queue_depth 2 1083 _002650_hash NULL
86113 +_002651_hash scsi_init_shared_tag_map 2 59812 _002651_hash NULL
86114 +_002652_hash scsi_track_queue_full 2 44239 _002652_hash NULL
86115 +_002653_hash sctp_abort_pkt_new 5 55218 _002653_hash NULL
86116 +_002654_hash sctp_make_abort_violation 4 27959 _002654_hash NULL
86117 +_002655_hash sctp_make_op_error 5-6 7057 _002655_hash NULL
86118 +_002657_hash sctp_recvmsg 4 23265 _002657_hash NULL
86119 +_002658_hash send_stream 4 3397 _002658_hash NULL
86120 +_002659_hash sis190_try_rx_copy 3 57069 _002659_hash NULL
86121 +_002664_hash skb_copy_and_csum_datagram_iovec 2 24466 _002664_hash NULL
86122 +_002666_hash skge_rx_get 3 40598 _002666_hash NULL
86123 +_002667_hash smp_send_cmd 3 512 _002667_hash NULL
86124 +_002668_hash snd_gf1_mem_proc_dump 5 16926 _003499_hash NULL nohasharray
86125 +_002669_hash sta_dev_read 3 14782 _002669_hash NULL
86126 +_002670_hash sta_inactive_ms_read 3 25690 _002670_hash NULL
86127 +_002671_hash sta_last_signal_read 3 31818 _002671_hash NULL
86128 +_002672_hash stats_dot11ACKFailureCount_read 3 45558 _002672_hash NULL
86129 +_002673_hash stats_dot11FCSErrorCount_read 3 28154 _002673_hash NULL
86130 +_002674_hash stats_dot11RTSFailureCount_read 3 43948 _002674_hash NULL
86131 +_002675_hash stats_dot11RTSSuccessCount_read 3 33065 _002675_hash NULL
86132 +_002676_hash storvsc_connect_to_vsp 2 22 _002676_hash NULL
86133 +_002677_hash sys_msgrcv 3 959 _002677_hash NULL
86134 +_002678_hash sys_syslog 3 10746 _002678_hash NULL
86135 +_002679_hash tcf_csum_ipv4_icmp 3 9258 _002679_hash NULL
86136 +_002680_hash tcf_csum_ipv4_igmp 3 60446 _002680_hash NULL
86137 +_002681_hash tcf_csum_ipv4_tcp 4 39713 _002681_hash NULL
86138 +_002682_hash tcf_csum_ipv4_udp 4 30777 _002682_hash NULL
86139 +_002683_hash tcf_csum_ipv6_icmp 4 11738 _002683_hash NULL
86140 +_002684_hash tcf_csum_ipv6_tcp 4 54877 _002684_hash NULL
86141 +_002685_hash tcf_csum_ipv6_udp 4 25241 _002685_hash NULL
86142 +_002686_hash tcm_loop_change_queue_depth 2 42454 _002686_hash NULL
86143 +_002687_hash tcp_copy_to_iovec 3 28344 _002687_hash NULL
86144 +_002688_hash tcp_mark_head_lost 2 35895 _002688_hash NULL
86145 +_002689_hash tcp_match_skb_to_sack 4 23568 _002689_hash NULL
86146 +_002690_hash timeout_read 3 47915 _002690_hash NULL
86147 +_002691_hash tipc_multicast 5 49144 _002691_hash NULL
86148 +_002692_hash tipc_port_recv_sections 4 42890 _002692_hash NULL
86149 +_002693_hash tipc_port_reject_sections 5 55229 _002693_hash NULL
86150 +_002694_hash total_ps_buffered_read 3 16365 _002694_hash NULL
86151 +_002695_hash tso_fragment 3 29050 _002695_hash NULL
86152 +_002696_hash tty_insert_flip_string 3 34042 _002696_hash NULL
86153 +_002698_hash tun_put_user 4 59849 _002698_hash NULL
86154 +_002699_hash twa_change_queue_depth 2 48808 _002699_hash NULL
86155 +_002700_hash tw_change_queue_depth 2 11116 _002700_hash NULL
86156 +_002701_hash twl_change_queue_depth 2 41342 _002701_hash NULL
86157 +_002702_hash ubi_eba_atomic_leb_change 5 60379 _002702_hash NULL
86158 +_002703_hash ubi_eba_write_leb 5-6 36029 _002703_hash NULL
86159 +_002705_hash ubi_eba_write_leb_st 5 44343 _002705_hash NULL
86160 +_002706_hash udp_recvmsg 4 42558 _002706_hash NULL
86161 +_002707_hash udpv6_recvmsg 4 9813 _002707_hash &_002506_hash
86162 +_002708_hash udpv6_sendmsg 4 22316 _002708_hash NULL
86163 +_002709_hash ulong_read_file 3 42304 _002709_hash &_000522_hash
86164 +_002710_hash unix_dgram_recvmsg 4 14952 _002710_hash NULL
86165 +_002711_hash user_power_read 3 39414 _002711_hash NULL
86166 +_002712_hash v9fs_direct_read 3 45546 _002712_hash NULL
86167 +_002713_hash v9fs_file_readn 4 36353 _002713_hash &_001799_hash
86168 +_002714_hash vcc_recvmsg 4 37198 _002714_hash NULL
86169 +_002715_hash velocity_rx_copy 2 34583 _002715_hash NULL
86170 +_002716_hash W6692_empty_Bfifo 2 47804 _002716_hash NULL
86171 +_002717_hash wep_iv_read 3 54744 _002717_hash NULL
86172 +_002718_hash x25_recvmsg 4 42777 _002718_hash NULL
86173 +_002719_hash xfs_buf_get_map 3 24522 _002719_hash NULL
86174 +_002720_hash xfs_file_aio_write 4 33234 _002720_hash NULL
86175 +_002721_hash xfs_iext_insert 3 18667 _002741_hash NULL nohasharray
86176 +_002722_hash xfs_iext_remove 3 50909 _002722_hash NULL
86177 +_002723_hash xlog_do_recovery_pass 3 21618 _002723_hash NULL
86178 +_002724_hash xlog_find_verify_log_record 2 18870 _002724_hash NULL
86179 +_002725_hash zd_mac_rx 3 38296 _002725_hash NULL
86180 +_002726_hash aircable_process_packet 5 46639 _002726_hash NULL
86181 +_002727_hash ath6kl_wmi_get_new_buf 1 52304 _002727_hash NULL
86182 +_002728_hash batadv_iv_ogm_queue_add 3 46319 _002728_hash NULL
86183 +_002729_hash batadv_receive_client_update_packet 3 41578 _002729_hash NULL
86184 +_002730_hash batadv_receive_server_sync_packet 3 26577 _002730_hash &_000494_hash
86185 +_002731_hash brcmf_alloc_pkt_and_read 2 63116 _002731_hash &_002028_hash
86186 +_002732_hash brcmf_sdcard_recv_buf 6 38179 _002732_hash NULL
86187 +_002733_hash brcmf_sdcard_rwdata 5 65041 _002733_hash NULL
86188 +_002734_hash brcmf_sdcard_send_buf 6 7713 _002734_hash NULL
86189 +_002735_hash brcmf_sdio_forensic_read 3 35311 _002735_hash &_001382_hash
86190 +_002736_hash btrfs_alloc_free_block 3 8986 _002736_hash NULL
86191 +_002737_hash btrfs_free_and_pin_reserved_extent 2 53016 _002737_hash NULL
86192 +_002738_hash btrfs_free_reserved_extent 2 9867 _002738_hash NULL
86193 +_002739_hash carl9170_handle_mpdu 3 11056 _002739_hash NULL
86194 +_002740_hash do_trimming 3 26952 _002740_hash NULL
86195 +_002741_hash edge_tty_recv 4 18667 _002741_hash &_002721_hash
86196 +_002742_hash fwnet_receive_packet 9 50537 _002742_hash NULL
86197 +_002743_hash gigaset_if_receive 3 4861 _002743_hash NULL
86198 +_002744_hash gsm_dlci_data 3 14155 _002744_hash NULL
86199 +_002745_hash handle_rx_packet 3 58993 _002745_hash NULL
86200 +_002746_hash HDLC_irq 2 8709 _002746_hash NULL
86201 +_002747_hash hdlc_rpr_irq 2 10240 _002747_hash NULL
86202 +_002749_hash ifx_spi_insert_flip_string 3 51752 _002749_hash NULL
86203 +_002753_hash ip_nat_sdp_media 8 23386 _002753_hash NULL
86204 +_002754_hash ip_send_unicast_reply 6 38714 _002754_hash NULL
86205 +_002756_hash ipwireless_network_packet_received 4 51277 _002756_hash NULL
86206 +_002757_hash ipwireless_tty_received 3 49154 _002757_hash NULL
86207 +_002758_hash iscsi_iser_recv 4 41948 _002758_hash NULL
86208 +_002759_hash l2cap_bredr_sig_cmd 3 49065 _002759_hash NULL
86209 +_002760_hash l2cap_sock_alloc_skb_cb 2 33532 _002760_hash NULL
86210 +_002761_hash l2cap_sock_recvmsg 4 59886 _002761_hash NULL
86211 +_002762_hash llcp_allocate_pdu 3 19866 _002762_hash NULL
86212 +_002763_hash macvtap_recvmsg 4 63949 _002763_hash NULL
86213 +_002764_hash osd_req_list_dev_partitions 4 60027 _002764_hash NULL
86214 +_002765_hash osd_req_list_partition_collections 5 38223 _002765_hash NULL
86215 +_002766_hash osst_do_scsi 4 44410 _002766_hash NULL
86216 +_002767_hash ping_sendmsg 4 3782 _002767_hash NULL
86217 +_002768_hash ppp_cp_event 6 2965 _002768_hash NULL
86218 +_002769_hash pty_write 3 44757 _002769_hash &_001733_hash
86219 +_002770_hash push_rx 3 28939 _002770_hash NULL
86220 +_002772_hash qla2x00_handle_queue_full 2 24365 _002772_hash NULL
86221 +_002773_hash qla4xxx_change_queue_depth 2 1268 _002773_hash NULL
86222 +_002774_hash rfcomm_sock_recvmsg 4 22227 _002774_hash NULL
86223 +_002775_hash scsi_execute_req 5 42088 _002775_hash NULL
86224 +_002776_hash _scsih_change_queue_depth 2 26230 _002776_hash NULL
86225 +_002777_hash sctp_sf_abort_violation 6 38380 _002777_hash NULL
86226 +_002778_hash send_to_tty 3 45141 _002778_hash NULL
86227 +_002780_hash sky2_receive 2 13407 _002780_hash NULL
86228 +_002781_hash spi_execute 5 28736 _002781_hash NULL
86229 +_002782_hash submit_inquiry 3 42108 _002782_hash NULL
86230 +_002783_hash tcp_dma_try_early_copy 3 4457 _002783_hash NULL
86231 +_002784_hash tcp_sacktag_walk 6 49703 _002784_hash NULL
86232 +_002785_hash tcp_write_xmit 2 64602 _002785_hash NULL
86233 +_002786_hash ti_recv 4 22027 _002786_hash NULL
86234 +_002787_hash tun_do_read 4 50800 _002787_hash NULL
86235 +_002788_hash ubi_leb_change 4 10289 _002788_hash NULL
86236 +_002789_hash ubi_leb_write 4-5 5478 _002789_hash NULL
86237 +_002791_hash udp_sendmsg 4 4492 _002791_hash NULL
86238 +_002792_hash unix_seqpacket_recvmsg 4 23062 _002792_hash &_000477_hash
86239 +_002793_hash v9fs_cached_file_read 3 2514 _002793_hash NULL
86240 +_002794_hash write_leb 5 36957 _002794_hash NULL
86241 +_002795_hash xfs_buf_read_map 3 40226 _002795_hash NULL
86242 +_002796_hash xfs_trans_get_buf_map 4 2927 _002796_hash NULL
86243 +_002797_hash xlog_do_log_recovery 3 17550 _002797_hash NULL
86244 +_002798_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _002798_hash NULL
86245 +_002799_hash ath6kl_wmi_beginscan_cmd 8 25462 _002799_hash NULL
86246 +_002800_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _002800_hash NULL
86247 +_002801_hash ath6kl_wmi_set_appie_cmd 5 39266 _002801_hash NULL
86248 +_002802_hash ath6kl_wmi_set_ie_cmd 6 37260 _002802_hash NULL
86249 +_002803_hash ath6kl_wmi_startscan_cmd 8 33674 _002803_hash NULL
86250 +_002804_hash ath6kl_wmi_test_cmd 3 27312 _002804_hash NULL
86251 +_002805_hash brcmf_sdbrcm_membytes 3-5 37324 _002805_hash NULL
86252 +_002807_hash brcmf_sdbrcm_read_control 3 22721 _002807_hash NULL
86253 +_002808_hash brcmf_tx_frame 3 20978 _002808_hash NULL
86254 +_002809_hash __carl9170_rx 3 56784 _002809_hash NULL
86255 +_002810_hash ch_do_scsi 4 31171 _002810_hash NULL
86256 +_002811_hash dbg_leb_change 4 23555 _002811_hash NULL
86257 +_002812_hash dbg_leb_write 4-5 63555 _002812_hash &_000971_hash
86258 +_002814_hash gluebi_write 3 27905 _002814_hash NULL
86259 +_002815_hash hdlc_irq_one 2 3944 _002815_hash NULL
86260 +_002819_hash iser_rcv_completion 2 8048 _002819_hash NULL
86261 +_002820_hash lock_loop 1 61681 _002820_hash NULL
86262 +_002821_hash process_rcvd_data 3 6679 _002821_hash NULL
86263 +_002822_hash brcmf_sdbrcm_bus_txctl 3 42492 _002822_hash NULL
86264 +_002823_hash carl9170_rx 3 13272 _002823_hash NULL
86265 +_002824_hash carl9170_rx_stream 3 1334 _002824_hash NULL
86266 +_002826_hash mpt_lan_receive_post_turbo 2 13592 _002826_hash NULL
86267 +_002827_hash padzero 1 55 _002827_hash &_002251_hash
86268 +_002828_hash scsi_mode_sense 5 16835 _002828_hash NULL
86269 +_002829_hash scsi_vpd_inquiry 4 30040 _002829_hash NULL
86270 +_002830_hash ses_recv_diag 4 47143 _002830_hash &_000679_hash
86271 +_002831_hash ses_send_diag 4 64527 _002831_hash NULL
86272 +_002832_hash tcp_push_one 2 48816 _002832_hash NULL
86273 +_002833_hash __tcp_push_pending_frames 2 48148 _002833_hash NULL
86274 +_002834_hash trim_bitmaps 3 24158 _002834_hash NULL
86275 +_002835_hash tun_recvmsg 4 48463 _002835_hash NULL
86276 +_002836_hash ubifs_leb_change 4 17789 _002836_hash NULL
86277 +_002837_hash ubifs_leb_write 4-5 22679 _002837_hash NULL
86278 +_002839_hash xfs_buf_readahead_map 3 44248 _002839_hash &_000851_hash
86279 +_002840_hash xfs_trans_read_buf_map 5 37487 _002840_hash NULL
86280 +_002841_hash xlog_do_recover 3 59789 _002841_hash NULL
86281 +_002842_hash btrfs_trim_block_group 3 28963 _002842_hash NULL
86282 +_002843_hash do_write_orph_node 2 64343 _002843_hash NULL
86283 +_002844_hash fix_unclean_leb 3 23188 _002844_hash NULL
86284 +_002845_hash fixup_leb 3 43256 _002845_hash NULL
86285 +_002846_hash recover_head 3 17904 _002846_hash NULL
86286 +_002847_hash scsi_get_vpd_page 4 51951 _002847_hash NULL
86287 +_002848_hash sd_do_mode_sense 5 11507 _002848_hash NULL
86288 +_002849_hash tcp_push 3 10680 _002849_hash NULL
86289 +_002850_hash ubifs_wbuf_write_nolock 3 64946 _002850_hash NULL
86290 +_002851_hash ubifs_write_node 3-5 11258 _002851_hash NULL
86291 +_002852_hash ubifs_recover_leb 3 60639 _002852_hash NULL
86292 +_002853_hash write_head 4 30481 _002853_hash NULL
86293 +_002854_hash write_node 4 33121 _002854_hash NULL
86294 +_002855_hash ubifs_recover_log_leb 3 12079 _002855_hash NULL
86295 +_002856_hash replay_log_leb 3 18704 _002856_hash NULL
86296 +_002857_hash alloc_cpu_rmap 1 65363 _002857_hash NULL
86297 +_002858_hash alloc_ebda_hpc 1-2 50046 _002858_hash NULL
86298 +_002860_hash alloc_sched_domains 1 28972 _002860_hash NULL
86299 +_002861_hash amthi_read 4 45831 _002861_hash NULL
86300 +_002862_hash bcm_char_read 3 31750 _002862_hash NULL
86301 +_002863_hash BcmCopySection 5 2035 _002863_hash NULL
86302 +_002864_hash buffer_from_user 3 51826 _002864_hash NULL
86303 +_002865_hash buffer_to_user 3 35439 _002865_hash NULL
86304 +_002866_hash card_send_command 3 40757 _002866_hash NULL
86305 +_002867_hash chd_dec_fetch_cdata 3 50926 _002867_hash NULL
86306 +_002868_hash copy_nodes_to_user 2 63807 _002868_hash NULL
86307 +_002869_hash create_log 2 8225 _002869_hash NULL
86308 +_002870_hash crystalhd_create_dio_pool 2 3427 _002870_hash NULL
86309 +_002871_hash crystalhd_user_data 3 18407 _002871_hash NULL
86310 +_002872_hash do_pages_stat 2 4437 _002872_hash NULL
86311 +_002873_hash do_read_log_to_user 4 3236 _002873_hash NULL
86312 +_002874_hash do_write_log_from_user 3 39362 _002874_hash NULL
86313 +_002875_hash evm_read_key 3 54674 _002875_hash NULL
86314 +_002876_hash evm_write_key 3 27715 _002876_hash NULL
86315 +_002877_hash fir16_create 3 5574 _002877_hash NULL
86316 +_002878_hash get_nodes 3 39012 _002878_hash NULL
86317 +_002879_hash __iio_allocate_kfifo 2-3 55738 _002879_hash NULL
86318 +_002881_hash __iio_allocate_sw_ring_buffer 3 4843 _002881_hash NULL
86319 +_002882_hash iio_debugfs_read_reg 3 60908 _002882_hash NULL
86320 +_002883_hash iio_debugfs_write_reg 3 22742 _002883_hash NULL
86321 +_002884_hash iio_device_alloc 1 41440 _002884_hash NULL
86322 +_002885_hash iio_event_chrdev_read 3 54757 _002885_hash NULL
86323 +_002886_hash iio_read_first_n_kfifo 2 57910 _002886_hash NULL
86324 +_002887_hash iio_read_first_n_sw_rb 2 51911 _002887_hash NULL
86325 +_002888_hash ioapic_setup_resources 1 35255 _002888_hash NULL
86326 +_002889_hash keymap_store 4 45406 _002889_hash NULL
86327 +_002890_hash line6_alloc_sysex_buffer 4 28225 _002890_hash NULL
86328 +_002891_hash line6_dumpreq_initbuf 3 53123 _002891_hash NULL
86329 +_002892_hash line6_midibuf_init 2 52425 _002892_hash NULL
86330 +_002893_hash _malloc 1 54077 _002893_hash NULL
86331 +_002894_hash mei_read 3 6507 _002894_hash NULL
86332 +_002895_hash mei_write 3 4005 _002895_hash NULL
86333 +_002896_hash msg_set 3 51725 _002896_hash NULL
86334 +_002897_hash newpart 6 47485 _002897_hash NULL
86335 +_002898_hash OS_kmalloc 1 36909 _002898_hash NULL
86336 +_002899_hash OS_mem_token_alloc 1 14276 _002899_hash NULL
86337 +_002900_hash packet_came 3 18072 _002900_hash NULL
86338 +_002901_hash pcpu_alloc_bootmem 2 62074 _002901_hash NULL
86339 +_002902_hash pcpu_build_alloc_info 1-3-2 41443 _002902_hash NULL
86340 +_002905_hash pcpu_get_vm_areas 3 50085 _002905_hash NULL
86341 +_002906_hash resource_from_user 3 30341 _002906_hash NULL
86342 +_002907_hash rtsx_read_cfg_seq 3-5 48139 _002907_hash NULL
86343 +_002909_hash rtsx_write_cfg_seq 3-5 27485 _002909_hash NULL
86344 +_002911_hash sca3000_read_data 4 57064 _002911_hash NULL
86345 +_002912_hash sca3000_read_first_n_hw_rb 2 11479 _002912_hash NULL
86346 +_002913_hash send_midi_async 3 57463 _002913_hash NULL
86347 +_002914_hash sep_create_dcb_dmatables_context 6 37551 _002914_hash NULL
86348 +_002915_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002915_hash NULL
86349 +_002916_hash sep_create_msgarea_context 4 33829 _002916_hash NULL
86350 +_002917_hash sep_lli_table_secure_dma 2-3 64042 _002917_hash NULL
86351 +_002919_hash sep_lock_user_pages 2-3 57470 _002919_hash &_002488_hash
86352 +_002921_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002921_hash NULL
86353 +_002923_hash sep_read 3 17161 _002923_hash NULL
86354 +_002924_hash TransmitTcb 4 12989 _002924_hash NULL
86355 +_002925_hash ValidateDSDParamsChecksum 3 63654 _002925_hash NULL
86356 +_002926_hash Wb35Reg_BurstWrite 4 62327 _002926_hash NULL
86357 +_002927_hash alloc_irq_cpu_rmap 1 28459 _002927_hash NULL
86358 +_002928_hash InterfaceTransmitPacket 3 42058 _002928_hash NULL
86359 +_002929_hash line6_dumpreq_init 3 34473 _002929_hash NULL
86360 +_002931_hash pcpu_embed_first_chunk 1-3-2 24224 _002931_hash NULL
86361 +_002933_hash pcpu_fc_alloc 2 11818 _002933_hash NULL
86362 +_002934_hash pcpu_page_first_chunk 1 20712 _002934_hash NULL
86363 +_002935_hash pod_alloc_sysex_buffer 3 31651 _002935_hash NULL
86364 +_002936_hash r8712_usbctrl_vendorreq 6 48489 _002936_hash NULL
86365 +_002937_hash r871x_set_wpa_ie 3 7000 _002937_hash NULL
86366 +_002938_hash sep_prepare_input_dma_table 2-3 2009 _002938_hash NULL
86367 +_002940_hash sep_prepare_input_output_dma_table 2-4-3 63429 _002940_hash NULL
86368 +_002943_hash sys_get_mempolicy 3 30379 _002943_hash NULL
86369 +_002944_hash sys_mbind 5 7990 _002944_hash NULL
86370 +_002945_hash sys_migrate_pages 2 39825 _002945_hash NULL
86371 +_002946_hash sys_move_pages 2 42626 _002946_hash NULL
86372 +_002947_hash sys_set_mempolicy 3 32608 _002947_hash NULL
86373 +_002948_hash variax_alloc_sysex_buffer 3 15237 _002948_hash NULL
86374 +_002949_hash vme_user_read 3 55338 _002949_hash NULL
86375 +_002950_hash vme_user_write 3 15587 _002950_hash NULL
86376 +_002954_hash variax_set_raw2 4 32374 _002954_hash NULL
86377 +_002955_hash copy_in_user 3 57502 _002955_hash NULL
86378 +_002956_hash __earlyonly_bootmem_alloc 2 23824 _002956_hash NULL
86379 +_002957_hash rfc4106_set_key 3 54519 _002957_hash NULL
86380 +_002958_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _002958_hash NULL
86381 +_002959_hash sparse_early_usemaps_alloc_node 4 9269 _002959_hash NULL
86382 +_002960_hash sparse_mem_maps_populate_node 4 12669 _002960_hash &_002242_hash
86383 +_002961_hash vmemmap_alloc_block 1 43245 _002961_hash NULL
86384 +_002962_hash sparse_early_mem_maps_alloc_node 4 36971 _002962_hash NULL
86385 +_002963_hash vmemmap_alloc_block_buf 1 61126 _002963_hash NULL
86386 +_002964_hash alloc_mr 1 45935 _002964_hash NULL
86387 +_002965_hash atomic_counters_read 3 48827 _002965_hash NULL
86388 +_002966_hash atomic_stats_read 3 36228 _002966_hash NULL
86389 +_002967_hash capabilities_read 3 58457 _002967_hash NULL
86390 +_002968_hash compat_core_sys_select 1 65285 _002968_hash NULL
86391 +_002969_hash compat_dccp_setsockopt 5 51263 _002969_hash NULL
86392 +_002970_hash compat_do_arpt_set_ctl 4 12184 _002970_hash NULL
86393 +_002971_hash compat_do_ip6t_set_ctl 4 3184 _002971_hash NULL
86394 +_002972_hash compat_do_ipt_set_ctl 4 58466 _002972_hash &_002078_hash
86395 +_002973_hash compat_filldir 3 32999 _002973_hash NULL
86396 +_002974_hash compat_filldir64 3 35354 _002974_hash NULL
86397 +_002975_hash compat_fillonedir 3 15620 _002975_hash NULL
86398 +_002976_hash compat_ip_setsockopt 5 13870 _003094_hash NULL nohasharray
86399 +_002977_hash compat_ipv6_setsockopt 5 20468 _002977_hash NULL
86400 +_002978_hash compat_mpctl_ioctl 2 45671 _002978_hash NULL
86401 +_002979_hash compat_raw_setsockopt 5 30634 _002979_hash NULL
86402 +_002980_hash compat_rawv6_setsockopt 5 4967 _002980_hash NULL
86403 +_002981_hash compat_rw_copy_check_uvector 3 22001 _003263_hash NULL nohasharray
86404 +_002982_hash compat_sock_setsockopt 5 23 _002982_hash NULL
86405 +_002983_hash compat_sys_get_mempolicy 3 31109 _002983_hash NULL
86406 +_002984_hash compat_sys_kexec_load 2 35674 _002984_hash NULL
86407 +_002985_hash compat_sys_keyctl 4 9639 _002985_hash NULL
86408 +_002986_hash compat_sys_mbind 5 36256 _002986_hash NULL
86409 +_002987_hash compat_sys_migrate_pages 2 3157 _002987_hash NULL
86410 +_002988_hash compat_sys_move_pages 2 5861 _002988_hash NULL
86411 +_002989_hash compat_sys_mq_timedsend 3 31060 _002989_hash NULL
86412 +_002990_hash compat_sys_msgrcv 2 7482 _002990_hash NULL
86413 +_002991_hash compat_sys_msgsnd 2 10738 _002991_hash NULL
86414 +_002992_hash compat_sys_semtimedop 3 3606 _002992_hash NULL
86415 +_002993_hash compat_sys_set_mempolicy 3 57742 _002993_hash &_002614_hash
86416 +_002994_hash __copy_in_user 3 34790 _002994_hash NULL
86417 +_002995_hash dev_counters_read 3 19216 _002995_hash NULL
86418 +_002996_hash dev_names_read 3 38509 _002996_hash NULL
86419 +_002997_hash driver_names_read 3 60399 _002997_hash NULL
86420 +_002998_hash driver_stats_read 3 8944 _002998_hash NULL
86421 +_002999_hash evdev_ioctl_compat 2 13851 _002999_hash NULL
86422 +_003000_hash evtchn_read 3 3569 _003000_hash NULL
86423 +_003001_hash evtchn_write 3 43278 _003001_hash NULL
86424 +_003002_hash fat_compat_ioctl_filldir 3 36328 _003002_hash NULL
86425 +_003003_hash flash_read 3 57843 _003003_hash NULL
86426 +_003004_hash flash_write 3 62354 _003004_hash NULL
86427 +_003005_hash fw_device_op_compat_ioctl 2 42804 _003005_hash NULL
86428 +_003006_hash gather_array 3 56641 _003006_hash NULL
86429 +_003007_hash ghash_async_setkey 3 60001 _003007_hash NULL
86430 +_003008_hash gntdev_alloc_map 2 35145 _003008_hash NULL
86431 +_003009_hash gnttab_map 2 56439 _003009_hash NULL
86432 +_003010_hash gru_alloc_gts 2-3 60056 _003010_hash &_000981_hash
86433 +_003012_hash hiddev_compat_ioctl 2 41255 _003012_hash NULL
86434 +_003013_hash init_cdev 1 8274 _003013_hash NULL
86435 +_003014_hash init_per_cpu 1 17880 _003014_hash NULL
86436 +_003015_hash ipath_create_cq 2 45586 _003015_hash NULL
86437 +_003016_hash ipath_get_base_info 3 7043 _003016_hash NULL
86438 +_003017_hash ipath_init_qp_table 2 25167 _003017_hash NULL
86439 +_003018_hash ipath_resize_cq 2 712 _003018_hash NULL
86440 +_003019_hash joydev_compat_ioctl 2 8765 _003019_hash NULL
86441 +_003020_hash mon_bin_compat_ioctl 3 50234 _003020_hash NULL
86442 +_003021_hash options_write 3 47243 _003021_hash NULL
86443 +_003022_hash portcntrs_1_read 3 47253 _003022_hash NULL
86444 +_003023_hash portcntrs_2_read 3 56586 _003023_hash NULL
86445 +_003024_hash portnames_read 3 41958 _003024_hash NULL
86446 +_003025_hash ptc_proc_write 3 12076 _003025_hash NULL
86447 +_003026_hash put_cmsg_compat 4 35937 _003026_hash NULL
86448 +_003027_hash qib_alloc_devdata 2 51819 _003027_hash NULL
86449 +_003028_hash qib_alloc_fast_reg_page_list 2 10507 _003028_hash NULL
86450 +_003029_hash qib_cdev_init 1 34778 _003029_hash NULL
86451 +_003030_hash qib_create_cq 2 27497 _003030_hash NULL
86452 +_003031_hash qib_diag_write 3 62133 _003031_hash NULL
86453 +_003032_hash qib_get_base_info 3 11369 _003032_hash NULL
86454 +_003033_hash qib_resize_cq 2 53090 _003033_hash NULL
86455 +_003034_hash qsfp_1_read 3 21915 _003034_hash NULL
86456 +_003035_hash qsfp_2_read 3 31491 _003035_hash NULL
86457 +_003036_hash queue_reply 3 22416 _003036_hash NULL
86458 +_003037_hash spidev_compat_ioctl 2 63778 _003037_hash NULL
86459 +_003038_hash split 2 11691 _003038_hash NULL
86460 +_003039_hash stats_read_ul 3 32751 _003039_hash NULL
86461 +_003040_hash sys32_ipc 3 7238 _003040_hash NULL
86462 +_003041_hash sys32_rt_sigpending 2 25814 _003041_hash NULL
86463 +_003042_hash tunables_read 3 36385 _003042_hash NULL
86464 +_003043_hash tunables_write 3 59563 _003043_hash NULL
86465 +_003044_hash xenbus_file_write 3 6282 _003044_hash NULL
86466 +_003045_hash xlbd_reserve_minors 1-2 18365 _003045_hash NULL
86467 +_003047_hash xpc_kmalloc_cacheline_aligned 1 42895 _003047_hash NULL
86468 +_003048_hash xpc_kzalloc_cacheline_aligned 1 65433 _003048_hash NULL
86469 +_003049_hash xsd_read 3 15653 _003049_hash NULL
86470 +_003050_hash compat_do_readv_writev 4 49102 _003050_hash NULL
86471 +_003051_hash compat_keyctl_instantiate_key_iov 3 57431 _003088_hash NULL nohasharray
86472 +_003052_hash compat_process_vm_rw 3-5 22254 _003052_hash NULL
86473 +_003054_hash compat_sys_select 1 16131 _003054_hash NULL
86474 +_003055_hash compat_sys_setsockopt 5 3326 _003055_hash NULL
86475 +_003056_hash compat_udp_setsockopt 5 38840 _003056_hash NULL
86476 +_003057_hash compat_udpv6_setsockopt 5 42981 _003057_hash NULL
86477 +_003058_hash do_compat_pselect 1 10398 _003058_hash NULL
86478 +_003059_hash gnttab_expand 1 15817 _003059_hash NULL
86479 +_003060_hash ipath_cdev_init 1 37752 _003060_hash NULL
86480 +_003061_hash ipath_reg_phys_mr 3 23918 _003061_hash &_000999_hash
86481 +_003062_hash qib_alloc_fast_reg_mr 2 12526 _003062_hash NULL
86482 +_003063_hash qib_reg_phys_mr 3 60202 _003063_hash &_000897_hash
86483 +_003064_hash compat_readv 3 30273 _003064_hash NULL
86484 +_003065_hash compat_sys_process_vm_readv 3-5 15374 _003065_hash NULL
86485 +_003067_hash compat_sys_process_vm_writev 3-5 41194 _003067_hash NULL
86486 +_003069_hash compat_sys_pselect6 1 14105 _003069_hash NULL
86487 +_003070_hash compat_writev 3 60063 _003070_hash NULL
86488 +_003071_hash get_free_entries 1 46030 _003071_hash NULL
86489 +_003072_hash compat_sys_preadv64 3 24283 _003072_hash NULL
86490 +_003073_hash compat_sys_pwritev64 3 51151 _003073_hash NULL
86491 +_003074_hash compat_sys_readv 3 20911 _003074_hash NULL
86492 +_003075_hash compat_sys_writev 3 5784 _003075_hash NULL
86493 +_003076_hash gnttab_alloc_grant_references 1 18240 _003076_hash NULL
86494 +_003077_hash compat_sys_preadv 3 583 _003077_hash NULL
86495 +_003078_hash compat_sys_pwritev 3 17886 _003078_hash NULL
86496 +_003079_hash aes_decrypt_fail_read 3 54815 _003079_hash NULL
86497 +_003080_hash aes_decrypt_interrupt_read 3 19910 _003080_hash NULL
86498 +_003081_hash aes_decrypt_packets_read 3 10155 _003081_hash NULL
86499 +_003082_hash aes_encrypt_fail_read 3 32562 _003082_hash NULL
86500 +_003083_hash aes_encrypt_interrupt_read 3 39919 _003083_hash NULL
86501 +_003084_hash aes_encrypt_packets_read 3 48666 _003084_hash NULL
86502 +_003085_hash agp_remap 2 30665 _003085_hash NULL
86503 +_003086_hash alloc_apertures 1 56561 _003086_hash NULL
86504 +_003087_hash allocate_probes 1 40204 _003087_hash NULL
86505 +_003088_hash alloc_ftrace_hash 1 57431 _003088_hash &_003051_hash
86506 +_003089_hash alloc_page_cgroup 1 2919 _003089_hash NULL
86507 +_003090_hash __alloc_preds 2 9492 _003090_hash NULL
86508 +_003091_hash __alloc_pred_stack 2 26687 _003091_hash NULL
86509 +_003092_hash alloc_sched_domains 1 47756 _003092_hash NULL
86510 +_003093_hash alloc_trace_probe 6 38720 _003093_hash NULL
86511 +_003094_hash alloc_trace_uprobe 3 13870 _003094_hash &_002976_hash
86512 +_003095_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003095_hash NULL
86513 +_003096_hash ath6kl_usb_post_recv_transfers 2 32892 _003096_hash NULL
86514 +_003097_hash ath6kl_usb_submit_ctrl_in 6 32880 _003097_hash &_000795_hash
86515 +_003098_hash ath6kl_usb_submit_ctrl_out 6 9978 _003098_hash NULL
86516 +_003099_hash av7110_ipack_init 2 46655 _003099_hash NULL
86517 +_003100_hash av7110_vbi_write 3 34384 _003100_hash NULL
86518 +_003101_hash bin_uuid 3 28999 _003101_hash NULL
86519 +_003102_hash blk_dropped_read 3 4168 _003102_hash NULL
86520 +_003103_hash blk_msg_write 3 13655 _003103_hash NULL
86521 +_003104_hash brcmf_usbdev_qinit 2 19090 _003104_hash &_001715_hash
86522 +_003105_hash brcmf_usb_dl_cmd 4 53130 _003105_hash NULL
86523 +_003106_hash ci_ll_init 3 12930 _003106_hash NULL
86524 +_003107_hash ci_ll_write 4 3740 _003107_hash NULL
86525 +_003108_hash conf_read 3 55786 _003108_hash NULL
86526 +_003109_hash __copy_from_user_inatomic_nocache 3 49921 _003109_hash NULL
86527 +_003110_hash cx24116_writeregN 4 41975 _003110_hash NULL
86528 +_003111_hash cyttsp_probe 4 1940 _003111_hash NULL
86529 +_003112_hash dccpprobe_read 3 52549 _003112_hash NULL
86530 +_003113_hash ddb_input_read 3 9743 _003113_hash NULL
86531 +_003114_hash ddb_output_write 3 31902 _003114_hash NULL
86532 +_003115_hash __devres_alloc 2 25598 _003115_hash NULL
86533 +_003116_hash dma_rx_errors_read 3 52045 _003116_hash NULL
86534 +_003117_hash dma_rx_requested_read 3 65354 _003117_hash NULL
86535 +_003118_hash dma_tx_errors_read 3 46060 _003118_hash NULL
86536 +_003119_hash dma_tx_requested_read 3 16110 _003203_hash NULL nohasharray
86537 +_003120_hash do_dmabuf_dirty_sou 7 3017 _003120_hash NULL
86538 +_003121_hash do_surface_dirty_sou 7 39678 _003121_hash NULL
86539 +_003122_hash driver_state_read 3 17194 _003122_hash &_001511_hash
86540 +_003123_hash drm_agp_bind_pages 3 56748 _003123_hash NULL
86541 +_003124_hash drm_buffer_alloc 2 44405 _003124_hash NULL
86542 +_003125_hash drm_calloc_large 1-2 65421 _003125_hash NULL
86543 +_003127_hash drm_fb_helper_init 3-4 19044 _003127_hash NULL
86544 +_003129_hash drm_ht_create 2 18853 _003129_hash NULL
86545 +_003130_hash drm_ioctl 2 42813 _003130_hash NULL
86546 +_003131_hash drm_malloc_ab 1-2 16831 _003131_hash NULL
86547 +_003133_hash drm_mode_crtc_set_gamma_size 2 31881 _003133_hash NULL
86548 +_003134_hash drm_plane_init 6 28731 _003134_hash NULL
86549 +_003135_hash drm_property_create 4 51239 _003135_hash NULL
86550 +_003136_hash drm_property_create_blob 2 7414 _003136_hash NULL
86551 +_003137_hash drm_vblank_init 2 11362 _003137_hash NULL
86552 +_003138_hash drm_vmalloc_dma 1 14550 _003138_hash NULL
86553 +_003139_hash dvb_aplay 3 56296 _003139_hash NULL
86554 +_003140_hash dvb_ca_en50221_init 4 45718 _003140_hash NULL
86555 +_003141_hash dvb_ca_en50221_io_write 3 43533 _003141_hash NULL
86556 +_003142_hash dvb_dmxdev_set_buffer_size 2 55643 _003142_hash NULL
86557 +_003143_hash dvbdmx_write 3 19423 _003143_hash NULL
86558 +_003144_hash dvb_dvr_set_buffer_size 2 9840 _003144_hash NULL
86559 +_003145_hash dvb_net_sec 3 37884 _003145_hash NULL
86560 +_003146_hash dvb_play 3 50814 _003146_hash NULL
86561 +_003147_hash dvb_ringbuffer_pkt_read_user 2-5-3 4303 _003147_hash NULL
86562 +_003150_hash dvb_ringbuffer_read_user 3 56702 _003150_hash NULL
86563 +_003151_hash dvb_usercopy 2 14036 _003151_hash NULL
86564 +_003152_hash dw210x_op_rw 6 39915 _003152_hash NULL
86565 +_003153_hash edt_ft5x06_debugfs_raw_data_read 3 28002 _003153_hash NULL
86566 +_003154_hash em_canid_change 3 14150 _003154_hash NULL
86567 +_003155_hash event_calibration_read 3 21083 _003155_hash NULL
86568 +_003156_hash event_enable_read 3 7074 _003156_hash NULL
86569 +_003157_hash event_filter_read 3 23494 _003157_hash NULL
86570 +_003158_hash event_filter_write 3 56609 _003158_hash NULL
86571 +_003159_hash event_heart_beat_read 3 48961 _003159_hash NULL
86572 +_003160_hash event_id_read 3 64288 _003160_hash &_001300_hash
86573 +_003161_hash event_oom_late_read 3 61175 _003161_hash &_001054_hash
86574 +_003162_hash event_phy_transmit_error_read 3 10471 _003162_hash NULL
86575 +_003163_hash event_rx_mem_empty_read 3 40363 _003163_hash NULL
86576 +_003164_hash event_rx_mismatch_read 3 38518 _003164_hash NULL
86577 +_003165_hash event_rx_pool_read 3 25792 _003165_hash NULL
86578 +_003166_hash event_tx_stuck_read 3 19305 _003166_hash NULL
86579 +_003167_hash excessive_retries_read 3 60425 _003167_hash NULL
86580 +_003168_hash flexcop_device_kmalloc 1 54793 _003168_hash NULL
86581 +_003169_hash fm_send_cmd 5 39639 _003169_hash NULL
86582 +_003170_hash __fprog_create 2 41263 _003170_hash NULL
86583 +_003171_hash fq_codel_zalloc 1 15378 _003171_hash NULL
86584 +_003172_hash ftrace_pid_write 3 39710 _003172_hash NULL
86585 +_003173_hash ftrace_profile_read 3 21327 _003173_hash NULL
86586 +_003174_hash fw_stats_raw_read 3 1369 _003174_hash NULL
86587 +_003175_hash get_info 3 55681 _003175_hash NULL
86588 +_003176_hash __get_vm_area_node 1 55305 _003176_hash NULL
86589 +_003177_hash gpio_power_read 3 36059 _003177_hash NULL
86590 +_003178_hash h5_prepare_pkt 4 12085 _003178_hash NULL
86591 +_003179_hash hsc_msg_alloc 1 60990 _003179_hash NULL
86592 +_003180_hash hsc_write 3 55875 _003180_hash NULL
86593 +_003181_hash hsi_alloc_controller 1 41802 _003181_hash NULL
86594 +_003182_hash hsi_register_board_info 2 13820 _003182_hash NULL
86595 +_003183_hash hugetlb_cgroup_read 5 49259 _003183_hash NULL
86596 +_003184_hash i915_cache_sharing_read 3 24775 _003184_hash NULL
86597 +_003185_hash i915_cache_sharing_write 3 57961 _003185_hash NULL
86598 +_003186_hash i915_max_freq_read 3 20581 _003186_hash NULL
86599 +_003187_hash i915_max_freq_write 3 11350 _003187_hash NULL
86600 +_003188_hash i915_min_freq_read 3 38470 _003188_hash NULL
86601 +_003189_hash i915_min_freq_write 3 10981 _003189_hash NULL
86602 +_003190_hash i915_ring_stop_read 3 42549 _003190_hash &_000740_hash
86603 +_003191_hash i915_ring_stop_write 3 59010 _003191_hash NULL
86604 +_003192_hash i915_wedged_read 3 35474 _003192_hash NULL
86605 +_003193_hash i915_wedged_write 3 47771 _003193_hash NULL
86606 +_003194_hash ieee802154_alloc_device 1 13767 _003194_hash NULL
86607 +_003195_hash intel_sdvo_write_cmd 4 54377 _003195_hash &_000832_hash
86608 +_003196_hash isr_cmd_cmplt_read 3 53439 _003196_hash NULL
86609 +_003197_hash isr_commands_read 3 41398 _003197_hash NULL
86610 +_003198_hash isr_decrypt_done_read 3 49490 _003198_hash NULL
86611 +_003199_hash isr_dma0_done_read 3 8574 _003199_hash NULL
86612 +_003200_hash isr_dma1_done_read 3 48159 _003200_hash NULL
86613 +_003201_hash isr_fiqs_read 3 34687 _003201_hash NULL
86614 +_003202_hash isr_host_acknowledges_read 3 54136 _003202_hash NULL
86615 +_003203_hash isr_hw_pm_mode_changes_read 3 16110 _003203_hash &_003119_hash
86616 +_003204_hash isr_irqs_read 3 9181 _003204_hash NULL
86617 +_003205_hash isr_low_rssi_read 3 64789 _003205_hash NULL
86618 +_003206_hash isr_pci_pm_read 3 30271 _003206_hash NULL
86619 +_003207_hash isr_rx_headers_read 3 38325 _003207_hash NULL
86620 +_003208_hash isr_rx_mem_overflow_read 3 43025 _003208_hash NULL
86621 +_003209_hash isr_rx_procs_read 3 31804 _003209_hash NULL
86622 +_003210_hash isr_rx_rdys_read 3 35283 _003210_hash NULL
86623 +_003211_hash isr_tx_exch_complete_read 3 16103 _003211_hash NULL
86624 +_003212_hash isr_tx_procs_read 3 23084 _003212_hash NULL
86625 +_003213_hash isr_wakeups_read 3 49607 _003213_hash NULL
86626 +_003214_hash LoadBitmap 2 19658 _003214_hash NULL
86627 +_003215_hash mem_cgroup_read 5 22461 _003215_hash NULL
86628 +_003216_hash mic_calc_failure_read 3 59700 _003216_hash NULL
86629 +_003217_hash mic_rx_pkts_read 3 27972 _003217_hash NULL
86630 +_003218_hash __module_alloc 1 50004 _003218_hash NULL
86631 +_003219_hash module_alloc_update_bounds_rw 1 63233 _003219_hash NULL
86632 +_003220_hash module_alloc_update_bounds_rx 1 58634 _003220_hash NULL
86633 +_003221_hash mwifiex_usb_submit_rx_urb 2 54558 _003221_hash NULL
86634 +_003222_hash nfc_hci_hcp_message_tx 6 14534 _003222_hash NULL
86635 +_003223_hash nfc_hci_set_param 5 40697 _003223_hash NULL
86636 +_003224_hash nfc_shdlc_alloc_skb 2 12741 _003224_hash NULL
86637 +_003225_hash opera1_xilinx_rw 5 31453 _003225_hash NULL
86638 +_003226_hash persistent_ram_vmap 1-2 709 _003226_hash NULL
86639 +_003228_hash prctl_set_mm 3 64538 _003228_hash NULL
86640 +_003229_hash probe_kernel_write 3 17481 _003229_hash NULL
86641 +_003230_hash proc_fault_inject_read 3 36802 _003230_hash NULL
86642 +_003231_hash proc_fault_inject_write 3 21058 _003231_hash NULL
86643 +_003232_hash ps_pspoll_max_apturn_read 3 6699 _003232_hash NULL
86644 +_003233_hash ps_pspoll_timeouts_read 3 11776 _003233_hash NULL
86645 +_003234_hash ps_pspoll_utilization_read 3 5361 _003234_hash NULL
86646 +_003235_hash ps_upsd_max_apturn_read 3 19918 _003235_hash NULL
86647 +_003236_hash ps_upsd_max_sptime_read 3 63362 _003236_hash NULL
86648 +_003237_hash ps_upsd_timeouts_read 3 28924 _003237_hash NULL
86649 +_003238_hash ps_upsd_utilization_read 3 51669 _003238_hash NULL
86650 +_003239_hash ptp_filter_init 2 36780 _003239_hash NULL
86651 +_003240_hash pwr_disable_ps_read 3 13176 _003240_hash NULL
86652 +_003241_hash pwr_elp_enter_read 3 5324 _003241_hash NULL
86653 +_003242_hash pwr_enable_ps_read 3 17686 _003242_hash NULL
86654 +_003243_hash pwr_fix_tsf_ps_read 3 26627 _003243_hash NULL
86655 +_003244_hash pwr_missing_bcns_read 3 25824 _003244_hash NULL
86656 +_003245_hash pwr_power_save_off_read 3 18355 _003245_hash NULL
86657 +_003246_hash pwr_ps_enter_read 3 26935 _003246_hash &_000512_hash
86658 +_003247_hash pwr_rcvd_awake_beacons_read 3 50505 _003247_hash NULL
86659 +_003248_hash pwr_rcvd_beacons_read 3 52836 _003248_hash NULL
86660 +_003249_hash pwr_tx_without_ps_read 3 48423 _003249_hash NULL
86661 +_003250_hash pwr_tx_with_ps_read 3 60851 _003250_hash NULL
86662 +_003251_hash pwr_wake_on_host_read 3 26321 _003251_hash NULL
86663 +_003252_hash pwr_wake_on_timer_exp_read 3 22640 _003252_hash NULL
86664 +_003253_hash rb_simple_read 3 45972 _003253_hash NULL
86665 +_003254_hash read_file_dfs 3 43145 _003254_hash NULL
86666 +_003255_hash retry_count_read 3 52129 _003255_hash NULL
86667 +_003256_hash rx_dropped_read 3 44799 _003256_hash NULL
86668 +_003257_hash rx_fcs_err_read 3 62844 _003257_hash NULL
86669 +_003258_hash rx_hdr_overflow_read 3 64407 _003258_hash NULL
86670 +_003259_hash rx_hw_stuck_read 3 57179 _003259_hash NULL
86671 +_003260_hash rx_out_of_mem_read 3 10157 _003260_hash NULL
86672 +_003261_hash rx_path_reset_read 3 23801 _003261_hash NULL
86673 +_003262_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _003262_hash NULL
86674 +_003263_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003263_hash &_002981_hash
86675 +_003264_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _003264_hash NULL
86676 +_003265_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _003265_hash NULL
86677 +_003266_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _003266_hash NULL
86678 +_003267_hash rx_reset_counter_read 3 58001 _003267_hash NULL
86679 +_003268_hash rx_xfr_hint_trig_read 3 40283 _003268_hash NULL
86680 +_003269_hash saa7146_vmalloc_build_pgtable 2 19780 _003269_hash NULL
86681 +_003270_hash sched_feat_write 3 55202 _003270_hash NULL
86682 +_003271_hash sd_alloc_ctl_entry 1 29708 _003271_hash NULL
86683 +_003272_hash shmem_pread_fast 3 34147 _003272_hash NULL
86684 +_003273_hash shmem_pread_slow 3 3198 _003273_hash NULL
86685 +_003274_hash shmem_pwrite_slow 3 31741 _003274_hash NULL
86686 +_003275_hash show_header 3 4722 _003275_hash &_000745_hash
86687 +_003276_hash stack_max_size_read 3 1445 _003276_hash NULL
86688 +_003277_hash subsystem_filter_read 3 62310 _003277_hash NULL
86689 +_003278_hash subsystem_filter_write 3 13022 _003278_hash NULL
86690 +_003279_hash swap_cgroup_swapon 2 13614 _003279_hash NULL
86691 +_003280_hash system_enable_read 3 25815 _003280_hash NULL
86692 +_003281_hash tda10048_writeregbulk 4 11050 _003281_hash NULL
86693 +_003282_hash tlbflush_read_file 3 64661 _003282_hash NULL
86694 +_003283_hash trace_options_core_read 3 47390 _003283_hash NULL
86695 +_003284_hash trace_options_read 3 11419 _003284_hash NULL
86696 +_003285_hash trace_parser_get_init 2 31379 _003285_hash NULL
86697 +_003286_hash traceprobe_probes_write 3 64969 _003286_hash NULL
86698 +_003287_hash trace_seq_to_user 3 65398 _003287_hash NULL
86699 +_003288_hash tracing_buffers_read 3 11124 _003288_hash NULL
86700 +_003289_hash tracing_clock_write 3 27961 _003289_hash NULL
86701 +_003290_hash tracing_cpumask_read 3 7010 _003290_hash NULL
86702 +_003291_hash tracing_ctrl_read 3 46922 _003291_hash NULL
86703 +_003292_hash tracing_entries_read 3 8345 _003292_hash NULL
86704 +_003293_hash tracing_max_lat_read 3 8890 _003293_hash NULL
86705 +_003294_hash tracing_read_dyn_info 3 45468 _003294_hash NULL
86706 +_003295_hash tracing_readme_read 3 16493 _003295_hash NULL
86707 +_003296_hash tracing_saved_cmdlines_read 3 21434 _003296_hash NULL
86708 +_003297_hash tracing_set_trace_read 3 44122 _003297_hash NULL
86709 +_003298_hash tracing_set_trace_write 3 57096 _003298_hash NULL
86710 +_003299_hash tracing_stats_read 3 34537 _003299_hash NULL
86711 +_003300_hash tracing_total_entries_read 3 62817 _003300_hash NULL
86712 +_003301_hash tracing_trace_options_write 3 153 _003301_hash NULL
86713 +_003302_hash tstats_write 3 60432 _003302_hash &_000009_hash
86714 +_003303_hash ttm_bo_fbdev_io 4 9805 _003303_hash NULL
86715 +_003304_hash ttm_bo_io 5 47000 _003304_hash NULL
86716 +_003305_hash ttm_dma_page_pool_free 2 34135 _003305_hash NULL
86717 +_003306_hash ttm_page_pool_free 2 61661 _003306_hash NULL
86718 +_003307_hash ttusb2_msg 4 3100 _003307_hash NULL
86719 +_003308_hash tx_internal_desc_overflow_read 3 47300 _003308_hash NULL
86720 +_003309_hash tx_queue_len_read 3 1463 _003309_hash NULL
86721 +_003310_hash tx_queue_status_read 3 44978 _003310_hash NULL
86722 +_003311_hash u_memcpya 2-3 30139 _003311_hash NULL
86723 +_003313_hash usb_allocate_stream_buffers 3 8964 _003313_hash NULL
86724 +_003314_hash vifs_state_read 3 33762 _003314_hash NULL
86725 +_003315_hash vmalloc_to_sg 2 58354 _003315_hash NULL
86726 +_003316_hash vm_map_ram 2 23078 _003316_hash &_001095_hash
86727 +_003317_hash vmw_execbuf_process 5 22885 _003317_hash NULL
86728 +_003318_hash vmw_fifo_reserve 2 12141 _003318_hash NULL
86729 +_003319_hash vmw_kms_present 9 38130 _003319_hash NULL
86730 +_003320_hash vmw_kms_readback 6 5727 _003320_hash NULL
86731 +_003321_hash wep_addr_key_count_read 3 20174 _003321_hash NULL
86732 +_003322_hash wep_decrypt_fail_read 3 58567 _003322_hash NULL
86733 +_003323_hash wep_default_key_count_read 3 43035 _003323_hash NULL
86734 +_003324_hash wep_interrupt_read 3 41492 _003324_hash NULL
86735 +_003325_hash wep_key_not_found_read 3 13377 _003325_hash &_000952_hash
86736 +_003326_hash wep_packets_read 3 18751 _003326_hash NULL
86737 +_003327_hash wl1251_cmd_template_set 4 6172 _003327_hash NULL
86738 +_003328_hash wl1271_format_buffer 2 20834 _003328_hash NULL
86739 +_003329_hash wl1271_rx_filter_alloc_field 5 46721 _003329_hash NULL
86740 +_003330_hash wl12xx_cmd_build_probe_req 6-8 54946 _003330_hash NULL
86741 +_003332_hash wlcore_alloc_hw 1 7785 _003332_hash NULL
86742 +_003333_hash aggr_size_rx_size_read 3 33526 _003333_hash NULL
86743 +_003334_hash aggr_size_tx_agg_vs_rate_read 3 21438 _003334_hash NULL
86744 +_003335_hash alloc_and_copy_ftrace_hash 1 29368 _003335_hash NULL
86745 +_003336_hash alloc_bulk_urbs_generic 5 12127 _003336_hash NULL
86746 +_003337_hash alloc_ieee80211 1 20063 _003337_hash NULL
86747 +_003338_hash alloc_ieee80211_rsl 1 34564 _003338_hash NULL
86748 +_003339_hash alloc_perm_bits 2 1532 _003339_hash NULL
86749 +_003340_hash alloc_private 2 22399 _003340_hash NULL
86750 +_003341_hash alloc_rtllib 1 51136 _003341_hash NULL
86751 +_003342_hash alloc_rx_desc_ring 2 18016 _003342_hash NULL
86752 +_003343_hash arcfb_write 3 8702 _003343_hash NULL
86753 +_003344_hash ath6kl_usb_bmi_read 3 48745 _003344_hash NULL
86754 +_003345_hash ath6kl_usb_bmi_write 3 2454 _003345_hash &_001020_hash
86755 +_003346_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003346_hash NULL
86756 +_003347_hash au0828_init_isoc 2-3 61917 _003347_hash NULL
86757 +_003349_hash auok190xfb_write 3 37001 _003349_hash NULL
86758 +_003350_hash beacon_interval_read 3 7091 _003350_hash NULL
86759 +_003351_hash brcmf_usb_attach 1-2 44656 _003351_hash NULL
86760 +_003353_hash broadsheetfb_write 3 39976 _003353_hash NULL
86761 +_003354_hash broadsheet_spiflash_rewrite_sector 2 54864 _003354_hash NULL
86762 +_003355_hash ci13xxx_add_device 3 14456 _003355_hash NULL
86763 +_003356_hash cmpk_message_handle_tx 4 54024 _003356_hash NULL
86764 +_003357_hash comedi_alloc_subdevices 2 29207 _003357_hash NULL
86765 +_003358_hash comedi_buf_alloc 3 24822 _003358_hash NULL
86766 +_003359_hash comedi_read 3 13199 _003359_hash NULL
86767 +_003360_hash comedi_write 3 47926 _003360_hash NULL
86768 +_003361_hash create_trace_probe 1 20175 _003361_hash NULL
86769 +_003362_hash create_trace_uprobe 1 13184 _003362_hash NULL
86770 +_003363_hash cx18_copy_buf_to_user 4 22735 _003363_hash NULL
86771 +_003364_hash cx231xx_init_bulk 2-3 47024 _003364_hash NULL
86772 +_003366_hash cx231xx_init_isoc 2-3 56453 _003366_hash NULL
86773 +_003368_hash cx231xx_init_vbi_isoc 2-3 28053 _003368_hash NULL
86774 +_003370_hash da9052_group_write 3 4534 _003370_hash NULL
86775 +_003371_hash debug_debug1_read 3 8856 _003371_hash NULL
86776 +_003372_hash debug_debug2_read 3 30526 _003372_hash NULL
86777 +_003373_hash debug_debug3_read 3 56894 _003373_hash NULL
86778 +_003374_hash debug_debug4_read 3 61367 _003374_hash NULL
86779 +_003375_hash debug_debug5_read 3 2291 _003375_hash NULL
86780 +_003376_hash debug_debug6_read 3 33168 _003376_hash NULL
86781 +_003377_hash dev_read 3 56369 _003377_hash NULL
86782 +_003378_hash do_dmabuf_dirty_ldu 6 52241 _003378_hash NULL
86783 +_003379_hash drm_compat_ioctl 2 51717 _003379_hash NULL
86784 +_003380_hash drm_mode_create_tv_properties 2 23122 _003380_hash NULL
86785 +_003381_hash drm_property_create_bitmask 5 30195 _003381_hash NULL
86786 +_003382_hash drm_property_create_enum 5 29201 _003382_hash NULL
86787 +_003383_hash dsp_buffer_alloc 2 11684 _003383_hash NULL
86788 +_003384_hash dt3155_alloc_coherent 2 58073 _003384_hash NULL
86789 +_003385_hash dtim_interval_read 3 654 _003385_hash NULL
86790 +_003386_hash dvb_audio_write 3 51275 _003386_hash NULL
86791 +_003387_hash dvb_ca_en50221_io_ioctl 2 26490 _003387_hash NULL
86792 +_003388_hash dvb_ca_write 3 41171 _003388_hash NULL
86793 +_003389_hash dvb_demux_ioctl 2 42733 _003389_hash NULL
86794 +_003390_hash dvb_dmxdev_buffer_read 4 20682 _003390_hash NULL
86795 +_003391_hash dvb_dvr_ioctl 2 49182 _003391_hash NULL
86796 +_003392_hash dvb_generic_ioctl 2 21810 _003392_hash NULL
86797 +_003393_hash dvb_net_ioctl 2 61559 _003393_hash NULL
86798 +_003394_hash dvb_net_sec_callback 2 28786 _003394_hash NULL
86799 +_003396_hash dvb_video_write 3 754 _003396_hash NULL
86800 +_003397_hash dynamic_ps_timeout_read 3 10110 _003397_hash NULL
86801 +_003398_hash easycap_alsa_vmalloc 2 14426 _003398_hash NULL
86802 +_003399_hash em28xx_alloc_isoc 4 46892 _003399_hash NULL
86803 +_003400_hash error_error_bar_retry_read 3 64305 _003400_hash NULL
86804 +_003401_hash error_error_frame_cts_nul_flid_read 3 17262 _003401_hash NULL
86805 +_003402_hash error_error_frame_read 3 39947 _003402_hash &_002436_hash
86806 +_003403_hash error_error_null_Frame_tx_start_read 3 55024 _003403_hash NULL
86807 +_003404_hash error_error_numll_frame_cts_start_read 3 47781 _003404_hash NULL
86808 +_003405_hash ext_sd_execute_read_data 9 48589 _003405_hash NULL
86809 +_003406_hash ext_sd_execute_write_data 9 8175 _003406_hash NULL
86810 +_003407_hash fast_user_write 5 20494 _003407_hash NULL
86811 +_003408_hash f_audio_buffer_alloc 1 41110 _003408_hash NULL
86812 +_003409_hash fb_alloc_cmap_gfp 2 20792 _003409_hash NULL
86813 +_003410_hash fbcon_do_set_font 2-3 4079 _003410_hash NULL
86814 +_003412_hash fb_read 3 33506 _003412_hash NULL
86815 +_003413_hash fb_sys_read 3 13778 _003413_hash NULL
86816 +_003414_hash fb_sys_write 3 33130 _003414_hash NULL
86817 +_003415_hash fb_write 3 46924 _003415_hash NULL
86818 +_003416_hash firmwareUpload 3 32794 _003416_hash NULL
86819 +_003417_hash fmc_send_cmd 5 20435 _003417_hash NULL
86820 +_003418_hash fops_read 3 40672 _003418_hash NULL
86821 +_003419_hash forced_ps_read 3 31685 _003419_hash NULL
86822 +_003420_hash frame_alloc 4 15981 _003420_hash NULL
86823 +_003421_hash framebuffer_alloc 1 59145 _003421_hash NULL
86824 +_003422_hash ftrace_write 3 29551 _003422_hash NULL
86825 +_003423_hash fw_download_code 3 13249 _003423_hash NULL
86826 +_003424_hash fwSendNullPacket 2 54618 _003424_hash NULL
86827 +_003425_hash gdm_wimax_netif_rx 3 43423 _003425_hash &_001810_hash
86828 +_003426_hash get_vm_area 1 18080 _003426_hash NULL
86829 +_003427_hash __get_vm_area 1 61599 _003427_hash NULL
86830 +_003428_hash get_vm_area_caller 1 10527 _003428_hash NULL
86831 +_003429_hash __get_vm_area_caller 1 56416 _003828_hash NULL nohasharray
86832 +_003430_hash gspca_dev_probe2 4 59833 _003430_hash NULL
86833 +_003431_hash hdpvr_read 3 9273 _003431_hash NULL
86834 +_003432_hash hecubafb_write 3 26942 _003432_hash NULL
86835 +_003433_hash i915_compat_ioctl 2 3656 _003433_hash NULL
86836 +_003434_hash i915_gem_execbuffer_relocate_slow 7 25355 _003434_hash NULL
86837 +_003435_hash ieee80211_alloc_txb 1-2 52477 _003435_hash NULL
86838 +_003437_hash ieee80211_authentication_req 3 63973 _003437_hash NULL
86839 +_003438_hash ieee80211_wx_set_gen_ie 3 51399 _003438_hash NULL
86840 +_003439_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _003458_hash NULL nohasharray
86841 +_003440_hash intel_sdvo_set_value 4 2311 _003440_hash NULL
86842 +_003441_hash ir_lirc_transmit_ir 3 64403 _003441_hash NULL
86843 +_003442_hash irq_blk_threshold_read 3 33666 _003442_hash NULL
86844 +_003443_hash irq_pkt_threshold_read 3 33356 _003443_hash &_000154_hash
86845 +_003444_hash irq_timeout_read 3 54653 _003444_hash NULL
86846 +_003445_hash ivtv_buf_copy_from_user 4 25502 _003445_hash NULL
86847 +_003446_hash ivtv_copy_buf_to_user 4 6159 _003446_hash NULL
86848 +_003447_hash ivtvfb_write 3 40023 _003447_hash NULL
86849 +_003448_hash kgdb_hex2mem 3 24755 _003448_hash NULL
86850 +_003449_hash lirc_buffer_init 2-3 53282 _003449_hash NULL
86851 +_003451_hash lirc_write 3 20604 _003451_hash NULL
86852 +_003452_hash mce_request_packet 3 1073 _003452_hash NULL
86853 +_003453_hash media_entity_init 2-4 15870 _003453_hash &_001742_hash
86854 +_003455_hash mem_fw_gen_free_mem_blks_read 3 11413 _003455_hash NULL
86855 +_003456_hash mem_fwlog_free_mem_blks_read 3 59616 _003456_hash NULL
86856 +_003457_hash mem_rx_free_mem_blks_read 3 675 _003457_hash NULL
86857 +_003458_hash mem_tx_free_mem_blks_read 3 3521 _003458_hash &_003439_hash
86858 +_003459_hash metronomefb_write 3 8823 _003459_hash NULL
86859 +_003460_hash mga_compat_ioctl 2 52170 _003460_hash NULL
86860 +_003461_hash mmio_read 4 40348 _003461_hash NULL
86861 +_003462_hash netlink_send 5 38434 _003462_hash NULL
86862 +_003463_hash nfc_hci_execute_cmd 5 43882 _003463_hash NULL
86863 +_003464_hash nfc_hci_send_event 5 21452 _003464_hash NULL
86864 +_003465_hash nfc_hci_send_response 5 56462 _003465_hash NULL
86865 +_003466_hash ni_gpct_device_construct 5 610 _003466_hash NULL
86866 +_003467_hash nouveau_compat_ioctl 2 28305 _003467_hash NULL
86867 +_003468_hash odev_update 2 50169 _003468_hash NULL
86868 +_003469_hash opera1_usb_i2c_msgxfer 4 64521 _003469_hash NULL
86869 +_003470_hash OSDSetBlock 2-4 38986 _003470_hash NULL
86870 +_003472_hash oz_add_farewell 5 20652 _003472_hash NULL
86871 +_003473_hash oz_cdev_read 3 20659 _003473_hash NULL
86872 +_003474_hash oz_cdev_write 3 33852 _003474_hash NULL
86873 +_003475_hash oz_ep_alloc 2 5587 _003475_hash NULL
86874 +_003476_hash oz_events_read 3 47535 _003476_hash NULL
86875 +_003477_hash persistent_ram_buffer_map 1-2 11332 _003477_hash NULL
86876 +_003479_hash pipeline_cs_rx_packet_in_read 3 37089 _003479_hash NULL
86877 +_003480_hash pipeline_cs_rx_packet_out_read 3 58926 _003480_hash NULL
86878 +_003481_hash pipeline_csum_to_rx_xfer_swi_read 3 15403 _003481_hash NULL
86879 +_003482_hash pipeline_dec_packet_in_fifo_full_read 3 33052 _003482_hash NULL
86880 +_003483_hash pipeline_dec_packet_in_read 3 47076 _003483_hash NULL
86881 +_003484_hash pipeline_dec_packet_out_read 3 54052 _003484_hash NULL
86882 +_003485_hash pipeline_defrag_to_csum_swi_read 3 63037 _003485_hash NULL
86883 +_003486_hash pipeline_enc_rx_stat_fifo_int_read 3 7107 _003486_hash NULL
86884 +_003487_hash pipeline_enc_tx_stat_fifo_int_read 3 14680 _003487_hash NULL
86885 +_003488_hash pipeline_hs_tx_stat_fifo_int_read 3 15642 _003488_hash &_001260_hash
86886 +_003489_hash pipeline_pipeline_fifo_full_read 3 34095 _003489_hash NULL
86887 +_003490_hash pipeline_post_proc_swi_read 3 24108 _003490_hash NULL
86888 +_003491_hash pipeline_pre_proc_swi_read 3 3898 _003491_hash NULL
86889 +_003492_hash pipeline_pre_to_defrag_swi_read 3 56321 _003492_hash NULL
86890 +_003493_hash pipeline_rx_complete_stat_fifo_int_read 3 40671 _003493_hash NULL
86891 +_003494_hash pipeline_sec_frag_swi_read 3 30294 _003494_hash NULL
86892 +_003495_hash pipeline_tcp_rx_stat_fifo_int_read 3 26745 _003495_hash NULL
86893 +_003496_hash pipeline_tcp_tx_stat_fifo_int_read 3 32589 _003496_hash NULL
86894 +_003497_hash play_iframe 3 8219 _003497_hash NULL
86895 +_003498_hash probes_write 3 29711 _003498_hash NULL
86896 +_003499_hash psb_unlocked_ioctl 2 16926 _003499_hash &_002668_hash
86897 +_003500_hash ps_poll_ps_poll_max_ap_turn_read 3 53140 _003500_hash NULL
86898 +_003501_hash ps_poll_ps_poll_timeouts_read 3 5934 _003501_hash NULL
86899 +_003502_hash ps_poll_ps_poll_utilization_read 3 39383 _003502_hash NULL
86900 +_003503_hash ps_poll_upsd_max_ap_turn_read 3 42050 _003503_hash NULL
86901 +_003504_hash ps_poll_upsd_timeouts_read 3 36755 _003504_hash NULL
86902 +_003505_hash ps_poll_upsd_utilization_read 3 28519 _003505_hash NULL
86903 +_003506_hash pvr2_ioread_read 3 10720 _003506_hash &_001669_hash
86904 +_003507_hash pvr2_ioread_set_sync_key 3 59882 _003507_hash NULL
86905 +_003508_hash pvr2_stream_buffer_count 2 33719 _003508_hash NULL
86906 +_003509_hash pwr_connection_out_of_sync_read 3 35061 _003509_hash NULL
86907 +_003510_hash pwr_cont_miss_bcns_spread_read 3 39250 _003515_hash NULL nohasharray
86908 +_003511_hash pwr_missing_bcns_cnt_read 3 45113 _003511_hash NULL
86909 +_003512_hash pwr_rcvd_awake_bcns_cnt_read 3 12632 _003512_hash NULL
86910 +_003513_hash pwr_rcvd_bcns_cnt_read 3 4774 _003513_hash NULL
86911 +_003514_hash qc_capture 3 19298 _003514_hash NULL
86912 +_003515_hash r128_compat_ioctl 2 39250 _003515_hash &_003510_hash
86913 +_003516_hash radeon_compat_ioctl 2 59150 _003516_hash NULL
86914 +_003517_hash radeon_kms_compat_ioctl 2 51371 _003517_hash NULL
86915 +_003518_hash Realloc 2 34961 _003518_hash NULL
86916 +_003519_hash redrat3_transmit_ir 3 64244 _003519_hash NULL
86917 +_003520_hash reg_w_buf 3 27724 _003520_hash NULL
86918 +_003521_hash reg_w_ixbuf 4 34736 _003521_hash NULL
86919 +_003522_hash rtllib_alloc_txb 1-2 21687 _003522_hash NULL
86920 +_003524_hash rtllib_authentication_req 3 26713 _003524_hash NULL
86921 +_003525_hash rtllib_wx_set_gen_ie 3 59808 _003525_hash NULL
86922 +_003526_hash rts51x_transfer_data_partial 6 5735 _003526_hash NULL
86923 +_003527_hash rvmalloc 1 46873 _003527_hash NULL
86924 +_003528_hash rx_decrypt_key_not_found_read 3 37820 _003528_hash NULL
86925 +_003529_hash rx_defrag_called_read 3 1897 _003529_hash NULL
86926 +_003530_hash rx_defrag_decrypt_failed_read 3 41411 _003530_hash NULL
86927 +_003531_hash rx_defrag_init_called_read 3 35935 _003531_hash NULL
86928 +_003532_hash rx_defrag_in_process_called_read 3 59338 _003532_hash NULL
86929 +_003533_hash rx_defrag_need_decrypt_read 3 42253 _003533_hash NULL
86930 +_003534_hash rx_defrag_need_defrag_read 3 28117 _003534_hash NULL
86931 +_003535_hash rx_defrag_tkip_called_read 3 21031 _003535_hash NULL
86932 +_003536_hash rx_filter_accum_arp_pend_requests_read 3 11003 _003536_hash NULL
86933 +_003537_hash rx_filter_arp_filter_read 3 61914 _003537_hash NULL
86934 +_003538_hash rx_filter_beacon_filter_read 3 49279 _003538_hash NULL
86935 +_003539_hash rx_filter_data_filter_read 3 30098 _003539_hash NULL
86936 +_003540_hash rx_filter_dup_filter_read 3 37238 _003540_hash NULL
86937 +_003541_hash rx_filter_ibss_filter_read 3 50167 _003541_hash NULL
86938 +_003542_hash rx_filter_max_arp_queue_dep_read 3 5851 _003542_hash NULL
86939 +_003543_hash rx_filter_mc_filter_read 3 25712 _003543_hash NULL
86940 +_003544_hash rx_filter_protection_filter_read 3 39282 _003544_hash NULL
86941 +_003545_hash rx_rate_rx_frames_per_rates_read 3 7282 _003545_hash NULL
86942 +_003546_hash rx_rx_beacon_early_term_read 3 21559 _003546_hash NULL
86943 +_003547_hash rx_rx_checksum_result_read 3 50617 _003547_hash NULL
86944 +_003548_hash rx_rx_cmplt_read 3 14753 _003548_hash NULL
86945 +_003549_hash rx_rx_cmplt_task_read 3 35226 _003549_hash NULL
86946 +_003550_hash rx_rx_defrag_end_read 3 505 _003550_hash NULL
86947 +_003551_hash rx_rx_defrag_read 3 2010 _003551_hash NULL
86948 +_003552_hash rx_rx_done_read 3 65217 _003552_hash NULL
86949 +_003553_hash rx_rx_dropped_frame_read 3 23748 _003553_hash NULL
86950 +_003554_hash rx_rx_frame_checksum_read 3 40140 _003554_hash NULL
86951 +_003555_hash rx_rx_hdr_overflow_read 3 35002 _003555_hash NULL
86952 +_003556_hash rx_rx_out_of_mpdu_nodes_read 3 64668 _003556_hash NULL
86953 +_003557_hash rx_rx_phy_hdr_read 3 20950 _003557_hash NULL
86954 +_003558_hash rx_rx_pre_complt_read 3 41653 _003558_hash NULL
86955 +_003559_hash rx_rx_timeout_read 3 62389 _003559_hash NULL
86956 +_003560_hash rx_rx_timeout_wa_read 3 50204 _003560_hash NULL
86957 +_003561_hash rx_rx_tkip_replays_read 3 60193 _003561_hash NULL
86958 +_003562_hash rx_rx_wa_ba_not_expected_read 3 61341 _003562_hash NULL
86959 +_003563_hash rx_rx_wa_density_dropped_frame_read 3 26095 _003563_hash NULL
86960 +_003564_hash rx_streaming_always_read 3 49401 _003564_hash NULL
86961 +_003565_hash rx_streaming_interval_read 3 55291 _003565_hash NULL
86962 +_003566_hash saa7164_buffer_alloc_user 2 9627 _003566_hash NULL
86963 +_003567_hash send_control_msg 6 48498 _003567_hash NULL
86964 +_003568_hash SendTxCommandPacket 3 42901 _003568_hash NULL
86965 +_003569_hash setup_window 2-7-5-4 59178 _003569_hash NULL
86966 +_003573_hash shmem_pwrite_fast 3 46842 _003573_hash NULL
86967 +_003574_hash sleep_auth_read 3 19159 _003574_hash NULL
86968 +_003575_hash sn9c102_read 3 29305 _003575_hash NULL
86969 +_003576_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _003576_hash NULL
86970 +_003577_hash split_scan_timeout_read 3 20029 _003577_hash NULL
86971 +_003578_hash stk_prepare_sio_buffers 2 57168 _003578_hash NULL
86972 +_003579_hash store_debug_level 3 35652 _003579_hash NULL
86973 +_003580_hash suspend_dtim_interval_read 3 64971 _003580_hash NULL
86974 +_003581_hash sys_prctl 4 8766 _003581_hash NULL
86975 +_003582_hash tm6000_read_write_usb 7 50774 _003582_hash &_002149_hash
86976 +_003583_hash tracing_read_pipe 3 35312 _003583_hash NULL
86977 +_003584_hash ts_read 3 44687 _003584_hash NULL
86978 +_003585_hash ts_write 3 64336 _003585_hash NULL
86979 +_003586_hash tt3650_ci_msg 4 57219 _003586_hash NULL
86980 +_003587_hash ttm_object_device_init 2 10321 _003587_hash NULL
86981 +_003588_hash ttm_object_file_init 2 27804 _003588_hash NULL
86982 +_003589_hash tx_frag_bad_mblk_num_read 3 28064 _003589_hash NULL
86983 +_003590_hash tx_frag_cache_hit_read 3 29639 _003590_hash NULL
86984 +_003591_hash tx_frag_cache_miss_read 3 28394 _003591_hash NULL
86985 +_003592_hash tx_frag_called_read 3 1748 _003592_hash NULL
86986 +_003593_hash tx_frag_failed_read 3 43540 _003593_hash NULL
86987 +_003594_hash tx_frag_init_called_read 3 48377 _003594_hash NULL
86988 +_003595_hash tx_frag_in_process_called_read 3 1290 _003595_hash NULL
86989 +_003596_hash tx_frag_key_not_found_read 3 22971 _003596_hash NULL
86990 +_003597_hash tx_frag_mpdu_alloc_failed_read 3 41167 _003597_hash NULL
86991 +_003598_hash tx_frag_need_fragmentation_read 3 50153 _003598_hash NULL
86992 +_003599_hash tx_frag_tkip_called_read 3 31575 _003599_hash NULL
86993 +_003600_hash tx_tx_burst_programmed_read 3 20320 _003600_hash NULL
86994 +_003601_hash tx_tx_checksum_result_read 3 36490 _003601_hash &_001996_hash
86995 +_003602_hash tx_tx_cmplt_read 3 35854 _003602_hash NULL
86996 +_003603_hash tx_tx_data_prepared_read 3 43497 _003603_hash NULL
86997 +_003604_hash tx_tx_data_programmed_read 3 36871 _003604_hash NULL
86998 +_003605_hash tx_tx_done_data_read 3 6799 _003605_hash NULL
86999 +_003606_hash tx_tx_done_int_template_read 3 55511 _003606_hash &_001887_hash
87000 +_003607_hash tx_tx_done_template_read 3 35104 _003607_hash &_000106_hash
87001 +_003608_hash tx_tx_exch_expiry_read 3 8749 _003608_hash NULL
87002 +_003609_hash tx_tx_exch_pending_read 3 53018 _003609_hash NULL
87003 +_003610_hash tx_tx_exch_read 3 52986 _003610_hash NULL
87004 +_003611_hash tx_tx_frame_checksum_read 3 41553 _003611_hash NULL
87005 +_003612_hash tx_tx_imm_resp_read 3 55964 _003612_hash NULL
87006 +_003613_hash tx_tx_prepared_descs_read 3 9221 _003613_hash NULL
87007 +_003614_hash tx_tx_retry_data_read 3 1926 _003614_hash NULL
87008 +_003615_hash tx_tx_retry_template_read 3 57623 _003615_hash NULL
87009 +_003616_hash tx_tx_start_data_read 3 53219 _003616_hash NULL
87010 +_003617_hash tx_tx_start_fw_gen_read 3 58648 _003617_hash NULL
87011 +_003618_hash tx_tx_start_int_templates_read 3 58324 _003618_hash NULL
87012 +_003619_hash tx_tx_start_null_frame_read 3 6281 _003619_hash NULL
87013 +_003620_hash tx_tx_starts_read 3 3617 _003620_hash NULL
87014 +_003621_hash tx_tx_start_templates_read 3 17164 _003621_hash NULL
87015 +_003622_hash tx_tx_template_prepared_read 3 30424 _003622_hash NULL
87016 +_003623_hash tx_tx_template_programmed_read 3 30461 _003623_hash NULL
87017 +_003624_hash udi_log_event 3 58105 _003624_hash NULL
87018 +_003625_hash udl_prime_create 2 57159 _003625_hash NULL
87019 +_003626_hash uf_create_device_nodes 2 24948 _003626_hash NULL
87020 +_003627_hash uf_sme_queue_message 3 15697 _003627_hash NULL
87021 +_003628_hash ufx_alloc_urb_list 3 10349 _003628_hash NULL
87022 +_003629_hash unifi_net_data_malloc 3 24716 _003629_hash NULL
87023 +_003630_hash unifi_read 3 14899 _003630_hash NULL
87024 +_003631_hash unifi_write 3 65012 _003631_hash NULL
87025 +_003632_hash usb_buffer_alloc 2 36276 _003632_hash NULL
87026 +_003633_hash usbvision_rvmalloc 1 19655 _003633_hash NULL
87027 +_003634_hash usbvision_v4l2_read 3 34386 _003634_hash NULL
87028 +_003635_hash uvc_alloc_buffers 2-3 9656 _003635_hash NULL
87029 +_003637_hash uvc_alloc_entity 3-4 20836 _003637_hash NULL
87030 +_003639_hash uvc_debugfs_stats_read 3 56651 _003639_hash NULL
87031 +_003640_hash uvc_simplify_fraction 3 31303 _003640_hash NULL
87032 +_003641_hash v4l2_ctrl_new 7 24927 _003641_hash NULL
87033 +_003642_hash v4l2_event_subscribe 3 53687 _003642_hash NULL
87034 +_003643_hash v4l_stk_read 3 39672 _003643_hash NULL
87035 +_003644_hash __vb2_perform_fileio 3 63033 _003644_hash NULL
87036 +_003645_hash vfd_write 3 14717 _003645_hash NULL
87037 +_003646_hash vfio_config_do_rw 3 46091 _003646_hash NULL
87038 +_003647_hash vfio_msi_enable 2 20906 _003647_hash NULL
87039 +_003648_hash viafb_dvp0_proc_write 3 23023 _003648_hash NULL
87040 +_003649_hash viafb_dvp1_proc_write 3 48864 _003649_hash NULL
87041 +_003650_hash viafb_vt1636_proc_write 3 16018 _003650_hash NULL
87042 +_003651_hash __videobuf_alloc_vb 1 27062 _003651_hash NULL
87043 +_003652_hash __videobuf_alloc_vb 1 5665 _003652_hash NULL
87044 +_003653_hash __videobuf_copy_to_user 4 15423 _003653_hash NULL
87045 +_003654_hash videobuf_dma_init_kernel 3 6963 _003654_hash NULL
87046 +_003655_hash videobuf_pages_to_sg 2 3708 _003655_hash NULL
87047 +_003656_hash videobuf_vmalloc_to_sg 2 4548 _003656_hash NULL
87048 +_003657_hash video_usercopy 2 62151 _003657_hash NULL
87049 +_003658_hash virtscsi_alloc_tgt 2 6643 _003658_hash NULL
87050 +_003659_hash vmw_cursor_update_image 3-4 16332 _003659_hash NULL
87051 +_003661_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003661_hash &_001116_hash
87052 +_003662_hash vmw_framebuffer_surface_dirty 6 48132 _003662_hash NULL
87053 +_003663_hash vmw_gmr2_bind 3 21305 _003663_hash NULL
87054 +_003664_hash vmw_unlocked_ioctl 2 19212 _003664_hash NULL
87055 +_003665_hash w9966_v4l_read 3 31148 _003665_hash NULL
87056 +_003666_hash wl1273_fm_fops_write 3 60621 _003666_hash NULL
87057 +_003667_hash zoran_write 3 22404 _003667_hash NULL
87058 +_003668_hash alloc_vm_area 1 15989 _003668_hash NULL
87059 +_003669_hash cx18_copy_mdl_to_user 4 45549 _003669_hash NULL
87060 +_003670_hash dlfb_ops_write 3 64150 _003670_hash NULL
87061 +_003671_hash dvb_demux_read 3 13981 _003671_hash NULL
87062 +_003672_hash dvb_dmxdev_read_sec 4 7892 _003672_hash NULL
87063 +_003673_hash dvb_dvr_read 3 17073 _003673_hash NULL
87064 +_003674_hash em28xx_init_isoc 4 62883 _003674_hash &_000729_hash
87065 +_003675_hash fb_alloc_cmap 2 6554 _003675_hash NULL
87066 +_003676_hash gspca_dev_probe 4 2570 _003676_hash NULL
87067 +_003677_hash ieee80211_auth_challenge 3 18810 _003677_hash NULL
87068 +_003678_hash ieee80211_rtl_auth_challenge 3 61897 _003678_hash NULL
87069 +_003679_hash init_pci_cap_msi_perm 2 59033 _003679_hash NULL
87070 +_003680_hash __ioremap_caller 1-2 21800 _003680_hash NULL
87071 +_003682_hash ivtv_read 3 57796 _003682_hash NULL
87072 +_003683_hash ivtv_v4l2_write 3 39226 _003683_hash NULL
87073 +_003684_hash mce_async_out 3 58056 _003684_hash NULL
87074 +_003685_hash mce_flush_rx_buffer 2 14976 _003685_hash NULL
87075 +_003686_hash ms_read_multiple_pages 4-5 8052 _003686_hash NULL
87076 +_003688_hash ms_write_multiple_pages 5-6 10362 _003688_hash NULL
87077 +_003690_hash nfc_hci_send_cmd 5 55714 _003690_hash NULL
87078 +_003691_hash persistent_ram_new 1-2 40501 _003691_hash NULL
87079 +_003693_hash picolcd_fb_write 3 2318 _003693_hash NULL
87080 +_003694_hash process_bulk_data_command 4 38906 _003694_hash NULL
87081 +_003695_hash pvr2_v4l2_read 3 18006 _003695_hash NULL
87082 +_003696_hash qcam_read 3 13977 _003696_hash NULL
87083 +_003697_hash register_unifi_sdio 2 55239 _003697_hash NULL
87084 +_003698_hash resize_async_buffer 4 64031 _003698_hash &_002431_hash
87085 +_003699_hash rtllib_auth_challenge 3 12493 _003699_hash NULL
87086 +_003702_hash stk_allocate_buffers 2 16291 _003702_hash NULL
87087 +_003703_hash subdev_ioctl 2 28417 _003703_hash NULL
87088 +_003704_hash _sys_packet_req 4 46793 _003704_hash NULL
87089 +_003705_hash tm6000_i2c_recv_regs16 5 2949 _003705_hash NULL
87090 +_003706_hash tm6000_i2c_recv_regs 5 46215 _003706_hash NULL
87091 +_003707_hash tm6000_i2c_send_regs 5 20250 _003707_hash NULL
87092 +_003708_hash tt3650_ci_msg_locked 4 8013 _003708_hash NULL
87093 +_003709_hash ufx_ops_write 3 54848 _003709_hash NULL
87094 +_003710_hash update_macheader 7 1775 _003710_hash NULL
87095 +_003711_hash usbdux_attach_common 4 51764 _003750_hash NULL nohasharray
87096 +_003712_hash usbduxfast_attach_common 4 52538 _003712_hash NULL
87097 +_003713_hash usbduxsigma_attach_common 4 40847 _003713_hash NULL
87098 +_003714_hash uvc_v4l2_ioctl 2 8411 _003714_hash NULL
87099 +_003715_hash v4l2_ctrl_new_int_menu 4 41151 _003715_hash NULL
87100 +_003716_hash v4l2_ctrl_new_std 5 45748 _003716_hash &_000497_hash
87101 +_003717_hash v4l2_ctrl_new_std_menu 4 6221 _003717_hash NULL
87102 +_003718_hash vb2_read 3 42703 _003718_hash NULL
87103 +_003719_hash vb2_write 3 31948 _003719_hash NULL
87104 +_003720_hash vfio_pci_set_msi_trigger 3-4 26507 _003720_hash NULL
87105 +_003722_hash viafb_iga1_odev_proc_write 3 36241 _003722_hash NULL
87106 +_003723_hash viafb_iga2_odev_proc_write 3 2363 _003723_hash NULL
87107 +_003724_hash __videobuf_alloc_cached 1 12740 _003724_hash NULL
87108 +_003725_hash __videobuf_alloc_uncached 1 55711 _003725_hash NULL
87109 +_003726_hash __videobuf_copy_stream 4 44769 _003726_hash NULL
87110 +_003727_hash videobuf_read_one 3 31637 _003727_hash NULL
87111 +_003728_hash video_ioctl2 2 21380 _003728_hash NULL
87112 +_003729_hash vmap 2 15025 _003729_hash NULL
87113 +_003730_hash vmw_cursor_update_dmabuf 3-4 32045 _003730_hash NULL
87114 +_003732_hash vmw_gmr_bind 3 44130 _003732_hash NULL
87115 +_003733_hash xd_read_multiple_pages 4-5 11422 _003733_hash NULL
87116 +_003735_hash xd_write_multiple_pages 5-6 53633 _003735_hash NULL
87117 +_003737_hash xenfb_write 3 43412 _003737_hash NULL
87118 +_003738_hash arch_gnttab_map_shared 3 41306 _003738_hash NULL
87119 +_003739_hash arch_gnttab_map_status 3 49812 _003739_hash NULL
87120 +_003740_hash bttv_read 3 11432 _003740_hash NULL
87121 +_003741_hash cx18_read 3 23699 _003741_hash NULL
87122 +_003742_hash cx2341x_ctrl_new_menu 3 49700 _003742_hash NULL
87123 +_003743_hash cx2341x_ctrl_new_std 4 57061 _003743_hash NULL
87124 +_003744_hash cx25821_video_ioctl 2 30188 _003744_hash NULL
87125 +_003745_hash dt3155_read 3 59226 _003745_hash NULL
87126 +_003746_hash ioremap_cache 1-2 47189 _003746_hash NULL
87127 +_003748_hash ioremap_nocache 1-2 2439 _003748_hash NULL
87128 +_003750_hash ioremap_prot 1-2 51764 _003750_hash &_003711_hash
87129 +_003752_hash ioremap_wc 1-2 62695 _003752_hash NULL
87130 +_003754_hash ivtv_read_pos 3 34400 _003754_hash &_000312_hash
87131 +_003755_hash mcam_v4l_read 3 36513 _003755_hash NULL
87132 +_003756_hash ms_rw_multi_sector 3-4 7459 _003756_hash NULL
87133 +_003758_hash pvr2_v4l2_ioctl 2 24398 _003758_hash &_000877_hash
87134 +_003759_hash ramoops_init_prz 5 12134 _003759_hash NULL
87135 +_003761_hash ttm_bo_kmap_ttm 3 5922 _003761_hash NULL
87136 +_003762_hash uf_ap_process_data_pdu 7 25860 _003762_hash NULL
87137 +_003763_hash vb2_fop_read 3 24080 _003763_hash NULL
87138 +_003764_hash vb2_fop_write 3 30420 _003764_hash NULL
87139 +_003765_hash videobuf_read_stream 3 14956 _003765_hash NULL
87140 +_003766_hash video_read 3 28148 _003766_hash NULL
87141 +_003767_hash vmw_du_crtc_cursor_set 4-5 28479 _003767_hash NULL
87142 +_003769_hash xd_rw 3-4 49020 _003769_hash NULL
87143 +_003771_hash zoran_ioctl 2 30465 _003771_hash NULL
87144 +_003772_hash zr364xx_read 3 2354 _003772_hash NULL
87145 +_003773_hash acpi_os_ioremap 1-2 49523 _003773_hash NULL
87146 +_003775_hash au0828_v4l2_read 3 40220 _003775_hash NULL
87147 +_003776_hash ca91cx42_alloc_resource 2 10502 _003776_hash NULL
87148 +_003778_hash cx18_read_pos 3 4683 _003778_hash NULL
87149 +_003779_hash cx18_v4l2_read 3 21196 _003779_hash NULL
87150 +_003780_hash cx231xx_v4l2_read 3 55014 _003780_hash NULL
87151 +_003781_hash devm_ioremap_nocache 2-3 2036 _003781_hash NULL
87152 +_003783_hash do_test 1 15766 _003783_hash NULL
87153 +_003784_hash __einj_error_trigger 1 17707 _003784_hash &_001764_hash
87154 +_003785_hash em28xx_v4l2_read 3 16701 _003785_hash NULL
87155 +_003786_hash init_chip_wc_pat 2 62768 _003786_hash NULL
87156 +_003787_hash intel_render_ring_init_dri 2-3 45446 _003787_hash NULL
87157 +_003789_hash io_mapping_create_wc 1-2 1354 _003789_hash NULL
87158 +_003791_hash iommu_map_mmio_space 1 30919 _003791_hash NULL
87159 +_003792_hash ioremap 1-2 23172 _003792_hash NULL
87160 +_003794_hash ivtv_v4l2_read 3 1964 _003794_hash NULL
87161 +_003795_hash mga_ioremap 1-2 8571 _003795_hash NULL
87162 +_003797_hash mpeg_read 3 6708 _003797_hash NULL
87163 +_003798_hash msix_map_region 3 3411 _003798_hash NULL
87164 +_003799_hash ms_rw 3-4 17220 _003799_hash NULL
87165 +_003801_hash pci_iomap 3 47575 _003801_hash NULL
87166 +_003802_hash pd_video_read 3 24510 _003802_hash NULL
87167 +_003803_hash sfi_map_memory 1-2 5183 _003803_hash NULL
87168 +_003805_hash solo_enc_read 3 33553 _003805_hash NULL
87169 +_003806_hash solo_v4l2_read 3 59247 _003806_hash NULL
87170 +_003807_hash timblogiw_read 3 48305 _003807_hash NULL
87171 +_003808_hash tm6000_read 3 4151 _003808_hash NULL
87172 +_003809_hash tsi148_alloc_resource 2 24563 _003809_hash NULL
87173 +_003810_hash ttm_bo_ioremap 2-3 31082 _003810_hash NULL
87174 +_003812_hash ttm_bo_kmap 3-2 60118 _003812_hash NULL
87175 +_003813_hash vb2_vmalloc_get_userptr 3 31374 _003813_hash NULL
87176 +_003814_hash vbi_read 3 63673 _003814_hash NULL
87177 +_003815_hash viacam_read 3 54526 _003815_hash NULL
87178 +_003816_hash xlate_dev_mem_ptr 1 15291 _003816_hash &_001231_hash
87179 +_003817_hash a4t_cs_init 3 27734 _003817_hash NULL
87180 +_003818_hash aac_nark_ioremap 2 50163 _003818_hash &_000323_hash
87181 +_003819_hash aac_rkt_ioremap 2 3333 _003819_hash NULL
87182 +_003820_hash aac_rx_ioremap 2 52410 _003820_hash NULL
87183 +_003821_hash aac_sa_ioremap 2 13596 _003821_hash &_000299_hash
87184 +_003822_hash aac_src_ioremap 2 41688 _003822_hash NULL
87185 +_003823_hash aac_srcv_ioremap 2 6659 _003823_hash NULL
87186 +_003824_hash acpi_map 1-2 58725 _003824_hash NULL
87187 +_003826_hash acpi_os_read_memory 1-3 54186 _003826_hash NULL
87188 +_003828_hash acpi_os_write_memory 1-3 56416 _003828_hash &_003429_hash
87189 +_003830_hash atyfb_setup_generic 3 49151 _003830_hash NULL
87190 +_003831_hash ca91cx42_master_set 4 23146 _003831_hash NULL
87191 +_003832_hash check_mirror 1-2 57342 _003832_hash &_001753_hash
87192 +_003834_hash cycx_setup 4 47562 _003834_hash NULL
87193 +_003835_hash devm_ioremap 2-3 29235 _003835_hash NULL
87194 +_003837_hash divasa_remap_pci_bar 3-4 23485 _003837_hash &_000979_hash
87195 +_003839_hash doc_probe 1 23285 _003839_hash NULL
87196 +_003840_hash DoC_Probe 1 57534 _003840_hash NULL
87197 +_003841_hash efi_ioremap 1-2 3492 _003841_hash &_001137_hash
87198 +_003843_hash ems_pcmcia_add_card 2 62627 _003843_hash NULL
87199 +_003844_hash isp1760_register 1-2 628 _003844_hash NULL
87200 +_003846_hash mid_get_vbt_data_r0 2 10876 _003846_hash NULL
87201 +_003847_hash mid_get_vbt_data_r10 2 6308 _003847_hash NULL
87202 +_003848_hash mid_get_vbt_data_r1 2 26170 _003848_hash NULL
87203 +_003849_hash mthca_map_reg 2-3 5664 _003849_hash NULL
87204 +_003851_hash mthca_setup_cmd_doorbells 2 53954 _003851_hash NULL
87205 +_003852_hash netxen_nic_map_indirect_address_128M 2 42257 _003852_hash NULL
87206 +_003853_hash pcim_iomap 3 58334 _003853_hash NULL
87207 +_003854_hash persistent_ram_iomap 1-2 47156 _003854_hash NULL
87208 +_003856_hash read_vbt_r0 1 503 _003856_hash NULL
87209 +_003857_hash read_vbt_r10 1 60679 _003857_hash NULL
87210 +_003858_hash register_device 2-3 60015 _003858_hash NULL
87211 +_003860_hash remap_pci_mem 1-2 15966 _003860_hash NULL
87212 +_003862_hash rtl_port_map 1-2 2385 _003862_hash NULL
87213 +_003864_hash sfi_map_table 1 5462 _003864_hash NULL
87214 +_003865_hash sriov_enable_migration 2 14889 _003865_hash NULL
87215 +_003866_hash ssb_bus_scan 2 36578 _003866_hash NULL
87216 +_003867_hash ssb_ioremap 2 5228 _003867_hash NULL
87217 +_003868_hash tpci200_slot_map_space 2 3848 _003868_hash NULL
87218 +_003869_hash tpm_tis_init 2-3 15304 _003869_hash NULL
87219 +_003871_hash tsi148_master_set 4 14685 _003871_hash NULL
87220 +_003872_hash acpi_os_map_memory 1-2 11161 _003872_hash NULL
87221 +_003874_hash com90xx_found 3 13974 _003874_hash NULL
87222 +_003875_hash netxen_nic_hw_read_wx_128M 2 26858 _003875_hash NULL
87223 +_003876_hash netxen_nic_hw_write_wx_128M 2 33488 _003876_hash NULL
87224 +_003877_hash sfi_check_table 1 6772 _003877_hash NULL
87225 +_003878_hash sfi_sysfs_install_table 1 51688 _003878_hash NULL
87226 +_003879_hash sriov_enable 2 59689 _003879_hash NULL
87227 +_003880_hash ssb_bus_register 3 65183 _003880_hash NULL
87228 +_003881_hash acpi_ex_system_memory_space_handler 2 31192 _003881_hash NULL
87229 +_003882_hash acpi_tb_check_xsdt 1 21862 _003882_hash NULL
87230 +_003883_hash acpi_tb_install_table 1 12988 _003883_hash NULL
87231 +_003884_hash acpi_tb_parse_root_table 1 53455 _003884_hash NULL
87232 +_003885_hash check_vendor_extension 1 3254 _003885_hash NULL
87233 +_003886_hash pci_enable_sriov 2 35745 _003886_hash NULL
87234 +_003887_hash ssb_bus_pcmciabus_register 3 56020 _003887_hash NULL
87235 +_003888_hash ssb_bus_ssbbus_register 2 2217 _003888_hash NULL
87236 +_003889_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003889_hash NULL
87237 +_003890_hash alloc_vm_area 1 36149 _003890_hash NULL
87238 +_003891_hash cma_create_area 2 38642 _003891_hash NULL
87239 +_003893_hash fbcon_prepare_logo 5 6246 _003893_hash NULL
87240 +_003894_hash io_mapping_map_wc 2 19284 _003894_hash NULL
87241 +_003895_hash nfs_dns_resolve_name 3 25036 _003895_hash NULL
87242 +_003896_hash nfs_parse_server_name 2 1899 _003896_hash NULL
87243 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87244 new file mode 100644
87245 index 0000000..244559e
87246 --- /dev/null
87247 +++ b/tools/gcc/size_overflow_plugin.c
87248 @@ -0,0 +1,1879 @@
87249 +/*
87250 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87251 + * Licensed under the GPL v2, or (at your option) v3
87252 + *
87253 + * Homepage:
87254 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87255 + *
87256 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87257 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87258 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87259 + *
87260 + * Usage:
87261 + * $ 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
87262 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87263 + */
87264 +
87265 +#include "gcc-plugin.h"
87266 +#include "config.h"
87267 +#include "system.h"
87268 +#include "coretypes.h"
87269 +#include "tree.h"
87270 +#include "tree-pass.h"
87271 +#include "intl.h"
87272 +#include "plugin-version.h"
87273 +#include "tm.h"
87274 +#include "toplev.h"
87275 +#include "function.h"
87276 +#include "tree-flow.h"
87277 +#include "plugin.h"
87278 +#include "gimple.h"
87279 +#include "c-common.h"
87280 +#include "diagnostic.h"
87281 +#include "cfgloop.h"
87282 +
87283 +#if BUILDING_GCC_VERSION >= 4007
87284 +#include "c-tree.h"
87285 +#else
87286 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87287 +#endif
87288 +
87289 +struct size_overflow_hash {
87290 + const struct size_overflow_hash * const next;
87291 + const char * const name;
87292 + const unsigned int param;
87293 +};
87294 +
87295 +#include "size_overflow_hash.h"
87296 +
87297 +enum marked {
87298 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87299 +};
87300 +
87301 +#define __unused __attribute__((__unused__))
87302 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87303 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87304 +#define BEFORE_STMT true
87305 +#define AFTER_STMT false
87306 +#define CREATE_NEW_VAR NULL_TREE
87307 +#define CODES_LIMIT 32
87308 +#define MAX_PARAM 32
87309 +#define MY_STMT GF_PLF_1
87310 +#define NO_CAST_CHECK GF_PLF_2
87311 +
87312 +#if BUILDING_GCC_VERSION == 4005
87313 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87314 +#endif
87315 +
87316 +int plugin_is_GPL_compatible;
87317 +void debug_gimple_stmt(gimple gs);
87318 +
87319 +static tree expand(struct pointer_set_t *visited, tree lhs);
87320 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87321 +static tree report_size_overflow_decl;
87322 +static const_tree const_char_ptr_type_node;
87323 +static unsigned int handle_function(void);
87324 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87325 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87326 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87327 +
87328 +static struct plugin_info size_overflow_plugin_info = {
87329 + .version = "20120930beta",
87330 + .help = "no-size-overflow\tturn off size overflow checking\n",
87331 +};
87332 +
87333 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87334 +{
87335 + unsigned int arg_count;
87336 + enum tree_code code = TREE_CODE(*node);
87337 +
87338 + switch (code) {
87339 + case FUNCTION_DECL:
87340 + arg_count = type_num_arguments(TREE_TYPE(*node));
87341 + break;
87342 + case FUNCTION_TYPE:
87343 + case METHOD_TYPE:
87344 + arg_count = type_num_arguments(*node);
87345 + break;
87346 + default:
87347 + *no_add_attrs = true;
87348 + error("%s: %qE attribute only applies to functions", __func__, name);
87349 + return NULL_TREE;
87350 + }
87351 +
87352 + for (; args; args = TREE_CHAIN(args)) {
87353 + tree position = TREE_VALUE(args);
87354 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87355 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87356 + *no_add_attrs = true;
87357 + }
87358 + }
87359 + return NULL_TREE;
87360 +}
87361 +
87362 +static const char* get_asm_name(tree node)
87363 +{
87364 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87365 +}
87366 +
87367 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87368 +{
87369 + unsigned int arg_count, arg_num;
87370 + enum tree_code code = TREE_CODE(*node);
87371 +
87372 + switch (code) {
87373 + case FUNCTION_DECL:
87374 + arg_count = type_num_arguments(TREE_TYPE(*node));
87375 + break;
87376 + case FUNCTION_TYPE:
87377 + case METHOD_TYPE:
87378 + arg_count = type_num_arguments(*node);
87379 + break;
87380 + case FIELD_DECL:
87381 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87382 + if (arg_num != 0) {
87383 + *no_add_attrs = true;
87384 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87385 + }
87386 + return NULL_TREE;
87387 + default:
87388 + *no_add_attrs = true;
87389 + error("%qE attribute only applies to functions", name);
87390 + return NULL_TREE;
87391 + }
87392 +
87393 + for (; args; args = TREE_CHAIN(args)) {
87394 + tree position = TREE_VALUE(args);
87395 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87396 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87397 + *no_add_attrs = true;
87398 + }
87399 + }
87400 + return NULL_TREE;
87401 +}
87402 +
87403 +static struct attribute_spec size_overflow_attr = {
87404 + .name = "size_overflow",
87405 + .min_length = 1,
87406 + .max_length = -1,
87407 + .decl_required = true,
87408 + .type_required = false,
87409 + .function_type_required = false,
87410 + .handler = handle_size_overflow_attribute,
87411 +#if BUILDING_GCC_VERSION >= 4007
87412 + .affects_type_identity = false
87413 +#endif
87414 +};
87415 +
87416 +static struct attribute_spec intentional_overflow_attr = {
87417 + .name = "intentional_overflow",
87418 + .min_length = 1,
87419 + .max_length = -1,
87420 + .decl_required = true,
87421 + .type_required = false,
87422 + .function_type_required = false,
87423 + .handler = handle_intentional_overflow_attribute,
87424 +#if BUILDING_GCC_VERSION >= 4007
87425 + .affects_type_identity = false
87426 +#endif
87427 +};
87428 +
87429 +static void register_attributes(void __unused *event_data, void __unused *data)
87430 +{
87431 + register_attribute(&size_overflow_attr);
87432 + register_attribute(&intentional_overflow_attr);
87433 +}
87434 +
87435 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87436 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87437 +{
87438 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87439 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87440 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87441 +
87442 + unsigned int m = 0x57559429;
87443 + unsigned int n = 0x5052acdb;
87444 + const unsigned int *key4 = (const unsigned int *)key;
87445 + unsigned int h = len;
87446 + unsigned int k = len + seed + n;
87447 + unsigned long long p;
87448 +
87449 + while (len >= 8) {
87450 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87451 + len -= 8;
87452 + }
87453 + if (len >= 4) {
87454 + cwmixb(key4[0]) key4 += 1;
87455 + len -= 4;
87456 + }
87457 + if (len)
87458 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87459 + cwmixb(h ^ (k + n));
87460 + return k ^ h;
87461 +
87462 +#undef cwfold
87463 +#undef cwmixa
87464 +#undef cwmixb
87465 +}
87466 +
87467 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87468 +{
87469 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87470 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87471 + return fn ^ codes;
87472 +}
87473 +
87474 +static inline tree get_original_function_decl(tree fndecl)
87475 +{
87476 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87477 + return DECL_ABSTRACT_ORIGIN(fndecl);
87478 + return fndecl;
87479 +}
87480 +
87481 +static inline gimple get_def_stmt(const_tree node)
87482 +{
87483 + gcc_assert(node != NULL_TREE);
87484 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87485 + return SSA_NAME_DEF_STMT(node);
87486 +}
87487 +
87488 +static unsigned char get_tree_code(const_tree type)
87489 +{
87490 + switch (TREE_CODE(type)) {
87491 + case ARRAY_TYPE:
87492 + return 0;
87493 + case BOOLEAN_TYPE:
87494 + return 1;
87495 + case ENUMERAL_TYPE:
87496 + return 2;
87497 + case FUNCTION_TYPE:
87498 + return 3;
87499 + case INTEGER_TYPE:
87500 + return 4;
87501 + case POINTER_TYPE:
87502 + return 5;
87503 + case RECORD_TYPE:
87504 + return 6;
87505 + case UNION_TYPE:
87506 + return 7;
87507 + case VOID_TYPE:
87508 + return 8;
87509 + case REAL_TYPE:
87510 + return 9;
87511 + case VECTOR_TYPE:
87512 + return 10;
87513 + case REFERENCE_TYPE:
87514 + return 11;
87515 + case OFFSET_TYPE:
87516 + return 12;
87517 + case COMPLEX_TYPE:
87518 + return 13;
87519 + default:
87520 + debug_tree((tree)type);
87521 + gcc_unreachable();
87522 + }
87523 +}
87524 +
87525 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87526 +{
87527 + gcc_assert(type != NULL_TREE);
87528 +
87529 + while (type && len < CODES_LIMIT) {
87530 + tree_codes[len] = get_tree_code(type);
87531 + len++;
87532 + type = TREE_TYPE(type);
87533 + }
87534 + return len;
87535 +}
87536 +
87537 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87538 +{
87539 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87540 + enum tree_code code = TREE_CODE(type);
87541 + size_t len = 0;
87542 +
87543 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87544 +
87545 + arg = TYPE_ARG_TYPES(type);
87546 + // skip builtins __builtin_constant_p
87547 + if (!arg && DECL_BUILT_IN(fndecl))
87548 + return 0;
87549 +
87550 + if (TREE_CODE_CLASS(code) == tcc_type)
87551 + result = type;
87552 + else
87553 + result = DECL_RESULT(fndecl);
87554 +
87555 + gcc_assert(result != NULL_TREE);
87556 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87557 +
87558 + if (arg == NULL_TREE) {
87559 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87560 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87561 + if (arg_field == NULL_TREE)
87562 + return 0;
87563 + arg = TREE_TYPE(arg_field);
87564 + len = add_type_codes(arg, tree_codes, len);
87565 + gcc_assert(len != 0);
87566 + return len;
87567 + }
87568 +
87569 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87570 + while (arg && len < CODES_LIMIT) {
87571 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
87572 + arg = TREE_CHAIN(arg);
87573 + }
87574 +
87575 + gcc_assert(len != 0);
87576 + return len;
87577 +}
87578 +
87579 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
87580 +{
87581 + unsigned int hash;
87582 + const struct size_overflow_hash *entry;
87583 + unsigned char tree_codes[CODES_LIMIT];
87584 + size_t len;
87585 + const char *func_name = get_asm_name(fndecl);
87586 +
87587 + len = get_function_decl(fndecl, tree_codes);
87588 + if (len == 0)
87589 + return NULL;
87590 +
87591 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
87592 +
87593 + entry = size_overflow_hash[hash];
87594 + while (entry) {
87595 + if (!strcmp(entry->name, func_name))
87596 + return entry;
87597 + entry = entry->next;
87598 + }
87599 +
87600 + return NULL;
87601 +}
87602 +
87603 +static void check_arg_type(const_tree arg)
87604 +{
87605 + const_tree type = TREE_TYPE(arg);
87606 + enum tree_code code = TREE_CODE(type);
87607 +
87608 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
87609 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
87610 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
87611 +}
87612 +
87613 +static int find_arg_number(const_tree arg, tree func)
87614 +{
87615 + tree var;
87616 + unsigned int argnum = 1;
87617 +
87618 + if (TREE_CODE(arg) == SSA_NAME)
87619 + arg = SSA_NAME_VAR(arg);
87620 +
87621 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
87622 + if (strcmp(NAME(arg), NAME(var))) {
87623 + argnum++;
87624 + continue;
87625 + }
87626 + check_arg_type(var);
87627 + return argnum;
87628 + }
87629 + gcc_unreachable();
87630 +}
87631 +
87632 +static tree create_new_var(tree type)
87633 +{
87634 + tree new_var = create_tmp_var(type, "cicus");
87635 +
87636 + add_referenced_var(new_var);
87637 + mark_sym_for_renaming(new_var);
87638 + return new_var;
87639 +}
87640 +
87641 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
87642 +{
87643 + gimple assign;
87644 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87645 + tree type = TREE_TYPE(rhs1);
87646 + tree lhs = create_new_var(type);
87647 +
87648 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
87649 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87650 +
87651 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87652 + update_stmt(assign);
87653 + gimple_set_plf(assign, MY_STMT, true);
87654 + return assign;
87655 +}
87656 +
87657 +static bool is_bool(const_tree node)
87658 +{
87659 + const_tree type;
87660 +
87661 + if (node == NULL_TREE)
87662 + return false;
87663 +
87664 + type = TREE_TYPE(node);
87665 + if (!INTEGRAL_TYPE_P(type))
87666 + return false;
87667 + if (TREE_CODE(type) == BOOLEAN_TYPE)
87668 + return true;
87669 + if (TYPE_PRECISION(type) == 1)
87670 + return true;
87671 + return false;
87672 +}
87673 +
87674 +static tree cast_a_tree(tree type, tree var)
87675 +{
87676 + gcc_assert(type != NULL_TREE);
87677 + gcc_assert(var != NULL_TREE);
87678 + gcc_assert(fold_convertible_p(type, var));
87679 +
87680 + return fold_convert(type, var);
87681 +}
87682 +
87683 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
87684 +{
87685 + gimple assign;
87686 +
87687 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
87688 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
87689 + gcc_unreachable();
87690 +
87691 + if (lhs == CREATE_NEW_VAR)
87692 + lhs = create_new_var(dst_type);
87693 +
87694 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
87695 +
87696 + if (!gsi_end_p(*gsi)) {
87697 + location_t loc = gimple_location(gsi_stmt(*gsi));
87698 + gimple_set_location(assign, loc);
87699 + }
87700 +
87701 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
87702 +
87703 + if (before)
87704 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
87705 + else
87706 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
87707 + update_stmt(assign);
87708 + gimple_set_plf(assign, MY_STMT, true);
87709 +
87710 + return assign;
87711 +}
87712 +
87713 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
87714 +{
87715 + const_gimple assign;
87716 + gimple_stmt_iterator gsi;
87717 +
87718 + if (new_rhs1 == NULL_TREE)
87719 + return NULL_TREE;
87720 +
87721 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
87722 + gsi = gsi_for_stmt(stmt);
87723 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
87724 + return gimple_get_lhs(assign);
87725 + }
87726 + return new_rhs1;
87727 +}
87728 +
87729 +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)
87730 +{
87731 + tree size_overflow_type = get_size_overflow_type(stmt, node);
87732 +
87733 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
87734 +
87735 + if (new_rhs2 != NULL_TREE)
87736 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
87737 +
87738 + if (new_rhs3 != NULL_TREE)
87739 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
87740 +
87741 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
87742 +}
87743 +
87744 +
87745 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
87746 +{
87747 + tree size_overflow_type, lhs;
87748 + gimple stmt;
87749 + gimple_stmt_iterator gsi;
87750 +
87751 + if (rhs1 == NULL_TREE) {
87752 + debug_gimple_stmt(oldstmt);
87753 + error("%s: rhs1 is NULL_TREE", __func__);
87754 + gcc_unreachable();
87755 + }
87756 +
87757 + if (gimple_code(oldstmt) == GIMPLE_ASM)
87758 + lhs = rhs1;
87759 + else
87760 + lhs = gimple_get_lhs(oldstmt);
87761 +
87762 + gsi = gsi_for_stmt(oldstmt);
87763 + pointer_set_insert(visited, oldstmt);
87764 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
87765 + basic_block next_bb, cur_bb;
87766 + const_edge e;
87767 +
87768 + gcc_assert(before == false);
87769 + gcc_assert(stmt_can_throw_internal(oldstmt));
87770 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
87771 + gcc_assert(!gsi_end_p(gsi));
87772 +
87773 + cur_bb = gimple_bb(oldstmt);
87774 + next_bb = cur_bb->next_bb;
87775 + e = find_edge(cur_bb, next_bb);
87776 + gcc_assert(e != NULL);
87777 + gcc_assert(e->flags & EDGE_FALLTHRU);
87778 +
87779 + gsi = gsi_after_labels(next_bb);
87780 + gcc_assert(!gsi_end_p(gsi));
87781 +
87782 + before = true;
87783 + oldstmt = gsi_stmt(gsi);
87784 + }
87785 +
87786 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
87787 +
87788 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
87789 + gimple_set_plf(stmt, MY_STMT, true);
87790 + return gimple_get_lhs(stmt);
87791 +}
87792 +
87793 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
87794 +{
87795 + gimple stmt;
87796 + gimple_stmt_iterator gsi;
87797 + tree new_var, lhs = gimple_get_lhs(oldstmt);
87798 +
87799 + if (gimple_plf(oldstmt, MY_STMT))
87800 + return lhs;
87801 +
87802 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
87803 + rhs1 = gimple_assign_rhs1(oldstmt);
87804 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
87805 + }
87806 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
87807 + rhs2 = gimple_assign_rhs2(oldstmt);
87808 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
87809 + }
87810 +
87811 + stmt = gimple_copy(oldstmt);
87812 + gimple_set_location(stmt, gimple_location(oldstmt));
87813 + gimple_set_plf(stmt, MY_STMT, true);
87814 +
87815 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
87816 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
87817 +
87818 + if (is_bool(lhs))
87819 + new_var = SSA_NAME_VAR(lhs);
87820 + else
87821 + new_var = create_new_var(size_overflow_type);
87822 + new_var = make_ssa_name(new_var, stmt);
87823 + gimple_set_lhs(stmt, new_var);
87824 +
87825 + if (rhs1 != NULL_TREE) {
87826 + if (!gimple_assign_cast_p(oldstmt))
87827 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
87828 + gimple_assign_set_rhs1(stmt, rhs1);
87829 + }
87830 +
87831 + if (rhs2 != NULL_TREE)
87832 + gimple_assign_set_rhs2(stmt, rhs2);
87833 +#if BUILDING_GCC_VERSION >= 4007
87834 + if (rhs3 != NULL_TREE)
87835 + gimple_assign_set_rhs3(stmt, rhs3);
87836 +#endif
87837 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
87838 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
87839 +
87840 + gsi = gsi_for_stmt(oldstmt);
87841 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
87842 + update_stmt(stmt);
87843 + pointer_set_insert(visited, oldstmt);
87844 + return gimple_get_lhs(stmt);
87845 +}
87846 +
87847 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
87848 +{
87849 + basic_block bb;
87850 + gimple phi;
87851 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
87852 +
87853 + bb = gsi_bb(gsi);
87854 +
87855 + phi = create_phi_node(result, bb);
87856 + gsi = gsi_last(phi_nodes(bb));
87857 + gsi_remove(&gsi, false);
87858 +
87859 + gsi = gsi_for_stmt(oldstmt);
87860 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
87861 + gimple_set_bb(phi, bb);
87862 + gimple_set_plf(phi, MY_STMT, true);
87863 + return phi;
87864 +}
87865 +
87866 +static basic_block create_a_first_bb(void)
87867 +{
87868 + basic_block first_bb;
87869 +
87870 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87871 + if (dom_info_available_p(CDI_DOMINATORS))
87872 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
87873 + return first_bb;
87874 +}
87875 +
87876 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
87877 +{
87878 + basic_block bb;
87879 + const_gimple newstmt;
87880 + gimple_stmt_iterator gsi;
87881 + bool before = BEFORE_STMT;
87882 +
87883 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
87884 + gsi = gsi_for_stmt(get_def_stmt(arg));
87885 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
87886 + return gimple_get_lhs(newstmt);
87887 + }
87888 +
87889 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
87890 + gsi = gsi_after_labels(bb);
87891 + if (bb->index == 0) {
87892 + bb = create_a_first_bb();
87893 + gsi = gsi_start_bb(bb);
87894 + }
87895 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
87896 + return gimple_get_lhs(newstmt);
87897 +}
87898 +
87899 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
87900 +{
87901 + gimple newstmt;
87902 + gimple_stmt_iterator gsi;
87903 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
87904 + gimple def_newstmt = get_def_stmt(new_rhs);
87905 +
87906 + gsi_insert = gsi_insert_after;
87907 + gsi = gsi_for_stmt(def_newstmt);
87908 +
87909 + switch (gimple_code(get_def_stmt(arg))) {
87910 + case GIMPLE_PHI:
87911 + newstmt = gimple_build_assign(new_var, new_rhs);
87912 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
87913 + gsi_insert = gsi_insert_before;
87914 + break;
87915 + case GIMPLE_ASM:
87916 + case GIMPLE_CALL:
87917 + newstmt = gimple_build_assign(new_var, new_rhs);
87918 + break;
87919 + case GIMPLE_ASSIGN:
87920 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
87921 + break;
87922 + default:
87923 + /* unknown gimple_code (handle_build_new_phi_arg) */
87924 + gcc_unreachable();
87925 + }
87926 +
87927 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
87928 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
87929 + gimple_set_plf(newstmt, MY_STMT, true);
87930 + update_stmt(newstmt);
87931 + return newstmt;
87932 +}
87933 +
87934 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
87935 +{
87936 + const_gimple newstmt;
87937 + gimple def_stmt;
87938 + tree new_rhs;
87939 +
87940 + new_rhs = expand(visited, arg);
87941 + if (new_rhs == NULL_TREE)
87942 + return NULL_TREE;
87943 +
87944 + def_stmt = get_def_stmt(new_rhs);
87945 + if (gimple_code(def_stmt) == GIMPLE_NOP)
87946 + return NULL_TREE;
87947 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
87948 +
87949 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
87950 + return gimple_get_lhs(newstmt);
87951 +}
87952 +
87953 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
87954 +{
87955 + gimple phi, oldstmt = get_def_stmt(orig_result);
87956 + tree new_result, size_overflow_type;
87957 + unsigned int i;
87958 + unsigned int n = gimple_phi_num_args(oldstmt);
87959 +
87960 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
87961 +
87962 + new_result = create_new_var(size_overflow_type);
87963 +
87964 + pointer_set_insert(visited, oldstmt);
87965 + phi = overflow_create_phi_node(oldstmt, new_result);
87966 + for (i = 0; i < n; i++) {
87967 + tree arg, lhs;
87968 +
87969 + arg = gimple_phi_arg_def(oldstmt, i);
87970 + if (is_gimple_constant(arg))
87971 + arg = cast_a_tree(size_overflow_type, arg);
87972 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
87973 + if (lhs == NULL_TREE)
87974 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
87975 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
87976 + }
87977 +
87978 + update_stmt(phi);
87979 + return gimple_phi_result(phi);
87980 +}
87981 +
87982 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
87983 +{
87984 + const_gimple assign;
87985 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
87986 + tree origtype = TREE_TYPE(orig_rhs);
87987 +
87988 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
87989 +
87990 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
87991 + return gimple_get_lhs(assign);
87992 +}
87993 +
87994 +static void change_rhs1(gimple stmt, tree new_rhs1)
87995 +{
87996 + tree assign_rhs;
87997 + const_tree rhs = gimple_assign_rhs1(stmt);
87998 +
87999 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88000 + gimple_assign_set_rhs1(stmt, assign_rhs);
88001 + update_stmt(stmt);
88002 +}
88003 +
88004 +static bool check_mode_type(const_gimple stmt)
88005 +{
88006 + const_tree lhs = gimple_get_lhs(stmt);
88007 + const_tree lhs_type = TREE_TYPE(lhs);
88008 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88009 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88010 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88011 +
88012 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88013 + return false;
88014 +
88015 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88016 + return false;
88017 +
88018 + return true;
88019 +}
88020 +
88021 +static bool check_undefined_integer_operation(const_gimple stmt)
88022 +{
88023 + const_gimple def_stmt;
88024 + const_tree lhs = gimple_get_lhs(stmt);
88025 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88026 + const_tree rhs1_type = TREE_TYPE(rhs1);
88027 + const_tree lhs_type = TREE_TYPE(lhs);
88028 +
88029 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88030 + return false;
88031 +
88032 + def_stmt = get_def_stmt(rhs1);
88033 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88034 + return false;
88035 +
88036 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88037 + return false;
88038 + return true;
88039 +}
88040 +
88041 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88042 +{
88043 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88044 + enum machine_mode lhs_mode, rhs_mode;
88045 + gimple def_stmt = get_def_stmt(no_const_rhs);
88046 +
88047 + if (!gimple_assign_cast_p(def_stmt))
88048 + return false;
88049 +
88050 + rhs1 = gimple_assign_rhs1(def_stmt);
88051 + lhs = gimple_get_lhs(def_stmt);
88052 + rhs1_type = TREE_TYPE(rhs1);
88053 + lhs_type = TREE_TYPE(lhs);
88054 + rhs_mode = TYPE_MODE(rhs1_type);
88055 + lhs_mode = TYPE_MODE(lhs_type);
88056 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88057 + return false;
88058 +
88059 + return true;
88060 +}
88061 +
88062 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88063 +{
88064 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88065 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88066 + const_tree rhs1_type = TREE_TYPE(rhs1);
88067 + const_tree lhs_type = TREE_TYPE(lhs);
88068 +
88069 + new_rhs1 = expand(visited, rhs1);
88070 +
88071 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88072 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88073 +
88074 + if (gimple_plf(stmt, MY_STMT))
88075 + return lhs;
88076 +
88077 + if (gimple_plf(stmt, NO_CAST_CHECK))
88078 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88079 +
88080 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88081 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88082 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88083 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88084 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88085 + }
88086 +
88087 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88088 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88089 +
88090 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88091 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88092 +
88093 + change_rhs1(stmt, new_rhs1);
88094 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88095 +
88096 + rhs1 = gimple_assign_rhs1(stmt);
88097 + rhs1_type = TREE_TYPE(rhs1);
88098 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88099 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88100 +
88101 + if (!check_mode_type(stmt))
88102 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88103 +
88104 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88105 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88106 +
88107 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88108 +
88109 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88110 +}
88111 +
88112 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88113 +{
88114 + gimple def_stmt = get_def_stmt(lhs);
88115 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88116 +
88117 + if (is_gimple_constant(rhs1))
88118 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88119 +
88120 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88121 + switch (TREE_CODE(rhs1)) {
88122 + case SSA_NAME:
88123 + return handle_unary_rhs(visited, def_stmt);
88124 + case ARRAY_REF:
88125 + case BIT_FIELD_REF:
88126 + case ADDR_EXPR:
88127 + case COMPONENT_REF:
88128 + case INDIRECT_REF:
88129 +#if BUILDING_GCC_VERSION >= 4006
88130 + case MEM_REF:
88131 +#endif
88132 + case PARM_DECL:
88133 + case TARGET_MEM_REF:
88134 + case VAR_DECL:
88135 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88136 +
88137 + default:
88138 + debug_gimple_stmt(def_stmt);
88139 + debug_tree(rhs1);
88140 + gcc_unreachable();
88141 + }
88142 +}
88143 +
88144 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88145 +{
88146 + gimple cond_stmt;
88147 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88148 +
88149 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88150 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88151 + update_stmt(cond_stmt);
88152 +}
88153 +
88154 +static tree create_string_param(tree string)
88155 +{
88156 + tree i_type, a_type;
88157 + const int length = TREE_STRING_LENGTH(string);
88158 +
88159 + gcc_assert(length > 0);
88160 +
88161 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88162 + a_type = build_array_type(char_type_node, i_type);
88163 +
88164 + TREE_TYPE(string) = a_type;
88165 + TREE_CONSTANT(string) = 1;
88166 + TREE_READONLY(string) = 1;
88167 +
88168 + return build1(ADDR_EXPR, ptr_type_node, string);
88169 +}
88170 +
88171 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88172 +{
88173 + gimple func_stmt;
88174 + const_gimple def_stmt;
88175 + const_tree loc_line;
88176 + tree loc_file, ssa_name, current_func;
88177 + expanded_location xloc;
88178 + char ssa_name_buf[256];
88179 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88180 +
88181 + def_stmt = get_def_stmt(arg);
88182 + xloc = expand_location(gimple_location(def_stmt));
88183 +
88184 + if (!gimple_has_location(def_stmt)) {
88185 + xloc = expand_location(gimple_location(stmt));
88186 + if (!gimple_has_location(stmt))
88187 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88188 + }
88189 +
88190 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88191 +
88192 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88193 + loc_file = create_string_param(loc_file);
88194 +
88195 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88196 + current_func = create_string_param(current_func);
88197 +
88198 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88199 + ssa_name = build_string(256, ssa_name_buf);
88200 + ssa_name = create_string_param(ssa_name);
88201 +
88202 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88203 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88204 +
88205 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88206 +}
88207 +
88208 +static void __unused print_the_code_insertions(const_gimple stmt)
88209 +{
88210 + location_t loc = gimple_location(stmt);
88211 +
88212 + inform(loc, "Integer size_overflow check applied here.");
88213 +}
88214 +
88215 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88216 +{
88217 + basic_block cond_bb, join_bb, bb_true;
88218 + edge e;
88219 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88220 +
88221 + cond_bb = gimple_bb(stmt);
88222 + if (before)
88223 + gsi_prev(&gsi);
88224 + if (gsi_end_p(gsi))
88225 + e = split_block_after_labels(cond_bb);
88226 + else
88227 + e = split_block(cond_bb, gsi_stmt(gsi));
88228 + cond_bb = e->src;
88229 + join_bb = e->dest;
88230 + e->flags = EDGE_FALSE_VALUE;
88231 + e->probability = REG_BR_PROB_BASE;
88232 +
88233 + bb_true = create_empty_bb(cond_bb);
88234 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88235 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88236 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88237 +
88238 + if (dom_info_available_p(CDI_DOMINATORS)) {
88239 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88240 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88241 + }
88242 +
88243 + if (current_loops != NULL) {
88244 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88245 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88246 + }
88247 +
88248 + insert_cond(cond_bb, arg, cond_code, type_value);
88249 + insert_cond_result(bb_true, stmt, arg, min);
88250 +
88251 +// print_the_code_insertions(stmt);
88252 +}
88253 +
88254 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88255 +{
88256 + const_tree rhs_type = TREE_TYPE(rhs);
88257 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88258 +
88259 + gcc_assert(rhs_type != NULL_TREE);
88260 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88261 + return;
88262 +
88263 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88264 +
88265 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88266 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88267 +
88268 + gcc_assert(!TREE_OVERFLOW(type_max));
88269 +
88270 + cast_rhs_type = TREE_TYPE(cast_rhs);
88271 + type_max_type = TREE_TYPE(type_max);
88272 + type_min_type = TREE_TYPE(type_min);
88273 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88274 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88275 +
88276 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88277 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88278 +}
88279 +
88280 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88281 +{
88282 + gimple change_rhs_def_stmt;
88283 + tree lhs = gimple_get_lhs(def_stmt);
88284 + tree lhs_type = TREE_TYPE(lhs);
88285 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88286 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88287 +
88288 + if (change_rhs == NULL_TREE)
88289 + return get_size_overflow_type(def_stmt, lhs);
88290 +
88291 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88292 +
88293 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88294 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88295 +
88296 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88297 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88298 +
88299 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88300 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88301 +
88302 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88303 + debug_gimple_stmt(def_stmt);
88304 + gcc_unreachable();
88305 + }
88306 +
88307 + return get_size_overflow_type(def_stmt, lhs);
88308 +}
88309 +
88310 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88311 +{
88312 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88313 + return false;
88314 + if (!is_gimple_constant(rhs))
88315 + return false;
88316 + return true;
88317 +}
88318 +
88319 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88320 +{
88321 + gimple def_stmt;
88322 +
88323 + def_stmt = get_def_stmt(new_rhs);
88324 + // get_size_overflow_type
88325 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88326 + gcc_assert(gimple_assign_cast_p(def_stmt));
88327 + return gimple_assign_rhs1(def_stmt);
88328 +}
88329 +
88330 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88331 +{
88332 + gimple_stmt_iterator gsi;
88333 + const_gimple cast_stmt;
88334 + gimple def_stmt;
88335 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88336 +
88337 + if (mode != TImode && mode != DImode) {
88338 + def_stmt = get_def_stmt(new_rhs);
88339 + gcc_assert(gimple_assign_cast_p(def_stmt));
88340 + new_rhs = gimple_assign_rhs1(def_stmt);
88341 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88342 + }
88343 +
88344 + gcc_assert(mode == TImode || mode == DImode);
88345 +
88346 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88347 + return new_rhs;
88348 +
88349 + gsi = gsi_for_stmt(stmt);
88350 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88351 + new_rhs = gimple_get_lhs(cast_stmt);
88352 +
88353 + if (mode == DImode)
88354 + return new_rhs;
88355 +
88356 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88357 +
88358 + return new_rhs;
88359 +}
88360 +
88361 +static bool is_an_integer_trunction(const_gimple stmt)
88362 +{
88363 + gimple rhs1_def_stmt, rhs2_def_stmt;
88364 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88365 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88366 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88367 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88368 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88369 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88370 +
88371 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88372 + return false;
88373 +
88374 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88375 +
88376 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88377 + return false;
88378 +
88379 + rhs1_def_stmt = get_def_stmt(rhs1);
88380 + rhs2_def_stmt = get_def_stmt(rhs2);
88381 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88382 + return false;
88383 +
88384 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88385 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88386 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88387 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88388 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88389 + return false;
88390 +
88391 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88392 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88393 + return true;
88394 +}
88395 +
88396 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88397 +{
88398 + tree new_rhs1, new_rhs2;
88399 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88400 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88401 + gimple assign, stmt = get_def_stmt(lhs);
88402 + tree rhs1 = gimple_assign_rhs1(stmt);
88403 + tree rhs2 = gimple_assign_rhs2(stmt);
88404 +
88405 + if (!is_an_integer_trunction(stmt))
88406 + return NULL_TREE;
88407 +
88408 + new_rhs1 = expand(visited, rhs1);
88409 + new_rhs2 = expand(visited, rhs2);
88410 +
88411 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88412 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88413 +
88414 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88415 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88416 +
88417 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88418 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88419 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88420 + }
88421 +
88422 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88423 + new_lhs = gimple_get_lhs(assign);
88424 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88425 +
88426 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88427 +}
88428 +
88429 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88430 +{
88431 + const_gimple def_stmt;
88432 +
88433 + if (TREE_CODE(rhs) != SSA_NAME)
88434 + return false;
88435 +
88436 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88437 + return false;
88438 +
88439 + def_stmt = get_def_stmt(rhs);
88440 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88441 + return false;
88442 +
88443 + return true;
88444 +}
88445 +
88446 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88447 +{
88448 + tree new_rhs, size_overflow_type, orig_rhs;
88449 + void (*gimple_assign_set_rhs)(gimple, tree);
88450 + tree rhs1 = gimple_assign_rhs1(stmt);
88451 + tree rhs2 = gimple_assign_rhs2(stmt);
88452 + tree lhs = gimple_get_lhs(stmt);
88453 +
88454 + if (change_rhs == NULL_TREE)
88455 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88456 +
88457 + if (new_rhs2 == NULL_TREE) {
88458 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88459 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88460 + orig_rhs = rhs1;
88461 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88462 + } else {
88463 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88464 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88465 + orig_rhs = rhs2;
88466 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88467 + }
88468 +
88469 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88470 +
88471 + if (check_overflow)
88472 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88473 +
88474 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88475 + gimple_assign_set_rhs(stmt, new_rhs);
88476 + update_stmt(stmt);
88477 +
88478 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88479 +}
88480 +
88481 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88482 +{
88483 + tree rhs1, rhs2, new_lhs;
88484 + gimple def_stmt = get_def_stmt(lhs);
88485 + tree new_rhs1 = NULL_TREE;
88486 + tree new_rhs2 = NULL_TREE;
88487 +
88488 + rhs1 = gimple_assign_rhs1(def_stmt);
88489 + rhs2 = gimple_assign_rhs2(def_stmt);
88490 +
88491 + /* no DImode/TImode division in the 32/64 bit kernel */
88492 + switch (gimple_assign_rhs_code(def_stmt)) {
88493 + case RDIV_EXPR:
88494 + case TRUNC_DIV_EXPR:
88495 + case CEIL_DIV_EXPR:
88496 + case FLOOR_DIV_EXPR:
88497 + case ROUND_DIV_EXPR:
88498 + case TRUNC_MOD_EXPR:
88499 + case CEIL_MOD_EXPR:
88500 + case FLOOR_MOD_EXPR:
88501 + case ROUND_MOD_EXPR:
88502 + case EXACT_DIV_EXPR:
88503 + case POINTER_PLUS_EXPR:
88504 + case BIT_AND_EXPR:
88505 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88506 + default:
88507 + break;
88508 + }
88509 +
88510 + new_lhs = handle_integer_truncation(visited, lhs);
88511 + if (new_lhs != NULL_TREE)
88512 + return new_lhs;
88513 +
88514 + if (TREE_CODE(rhs1) == SSA_NAME)
88515 + new_rhs1 = expand(visited, rhs1);
88516 + if (TREE_CODE(rhs2) == SSA_NAME)
88517 + new_rhs2 = expand(visited, rhs2);
88518 +
88519 + if (is_a_neg_overflow(def_stmt, rhs2))
88520 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88521 + if (is_a_neg_overflow(def_stmt, rhs1))
88522 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88523 +
88524 + if (is_a_constant_overflow(def_stmt, rhs2))
88525 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88526 + if (is_a_constant_overflow(def_stmt, rhs1))
88527 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88528 +
88529 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88530 +}
88531 +
88532 +#if BUILDING_GCC_VERSION >= 4007
88533 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88534 +{
88535 + if (is_gimple_constant(rhs))
88536 + return cast_a_tree(size_overflow_type, rhs);
88537 + if (TREE_CODE(rhs) != SSA_NAME)
88538 + return NULL_TREE;
88539 + return expand(visited, rhs);
88540 +}
88541 +
88542 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88543 +{
88544 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88545 + gimple def_stmt = get_def_stmt(lhs);
88546 +
88547 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88548 +
88549 + rhs1 = gimple_assign_rhs1(def_stmt);
88550 + rhs2 = gimple_assign_rhs2(def_stmt);
88551 + rhs3 = gimple_assign_rhs3(def_stmt);
88552 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88553 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88554 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88555 +
88556 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88557 +}
88558 +#endif
88559 +
88560 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88561 +{
88562 + const_tree type;
88563 +
88564 + gcc_assert(node != NULL_TREE);
88565 +
88566 + type = TREE_TYPE(node);
88567 +
88568 + if (gimple_plf(stmt, MY_STMT))
88569 + return TREE_TYPE(node);
88570 +
88571 + switch (TYPE_MODE(type)) {
88572 + case QImode:
88573 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
88574 + case HImode:
88575 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
88576 + case SImode:
88577 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88578 + case DImode:
88579 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
88580 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
88581 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
88582 + default:
88583 + debug_tree((tree)node);
88584 + error("%s: unsupported gcc configuration.", __func__);
88585 + gcc_unreachable();
88586 + }
88587 +}
88588 +
88589 +static tree expand_visited(gimple def_stmt)
88590 +{
88591 + const_gimple next_stmt;
88592 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
88593 +
88594 + gsi_next(&gsi);
88595 + next_stmt = gsi_stmt(gsi);
88596 +
88597 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
88598 +
88599 + switch (gimple_code(next_stmt)) {
88600 + case GIMPLE_ASSIGN:
88601 + return gimple_get_lhs(next_stmt);
88602 + case GIMPLE_PHI:
88603 + return gimple_phi_result(next_stmt);
88604 + case GIMPLE_CALL:
88605 + return gimple_call_lhs(next_stmt);
88606 + default:
88607 + return NULL_TREE;
88608 + }
88609 +}
88610 +
88611 +static tree expand(struct pointer_set_t *visited, tree lhs)
88612 +{
88613 + gimple def_stmt;
88614 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
88615 +
88616 + if (is_gimple_constant(lhs))
88617 + return NULL_TREE;
88618 +
88619 + if (TREE_CODE(lhs) == ADDR_EXPR)
88620 + return NULL_TREE;
88621 +
88622 + if (code == REAL_TYPE)
88623 + return NULL_TREE;
88624 +
88625 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
88626 +
88627 +
88628 + def_stmt = get_def_stmt(lhs);
88629 +
88630 + if (!def_stmt)
88631 + return NULL_TREE;
88632 +
88633 + if (gimple_plf(def_stmt, MY_STMT))
88634 + return lhs;
88635 +
88636 + if (pointer_set_contains(visited, def_stmt))
88637 + return expand_visited(def_stmt);
88638 +
88639 + switch (gimple_code(def_stmt)) {
88640 + case GIMPLE_NOP:
88641 + return NULL_TREE;
88642 + case GIMPLE_PHI:
88643 + return build_new_phi(visited, lhs);
88644 + case GIMPLE_CALL:
88645 + case GIMPLE_ASM:
88646 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88647 + case GIMPLE_ASSIGN:
88648 + switch (gimple_num_ops(def_stmt)) {
88649 + case 2:
88650 + return handle_unary_ops(visited, lhs);
88651 + case 3:
88652 + return handle_binary_ops(visited, lhs);
88653 +#if BUILDING_GCC_VERSION >= 4007
88654 + case 4:
88655 + return handle_ternary_ops(visited, lhs);
88656 +#endif
88657 + }
88658 + default:
88659 + debug_gimple_stmt(def_stmt);
88660 + error("%s: unknown gimple code", __func__);
88661 + gcc_unreachable();
88662 + }
88663 +}
88664 +
88665 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
88666 +{
88667 + const_gimple assign;
88668 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88669 + tree origtype = TREE_TYPE(origarg);
88670 +
88671 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
88672 +
88673 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88674 +
88675 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
88676 + update_stmt(stmt);
88677 +}
88678 +
88679 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
88680 +{
88681 + const char *origid;
88682 + tree arg;
88683 + const_tree origarg;
88684 +
88685 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
88686 + return true;
88687 +
88688 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
88689 + while (origarg && *argnum) {
88690 + (*argnum)--;
88691 + origarg = TREE_CHAIN(origarg);
88692 + }
88693 +
88694 + gcc_assert(*argnum == 0);
88695 +
88696 + gcc_assert(origarg != NULL_TREE);
88697 + origid = NAME(origarg);
88698 + *argnum = 0;
88699 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
88700 + if (!strcmp(origid, NAME(arg)))
88701 + return true;
88702 + (*argnum)++;
88703 + }
88704 + return false;
88705 +}
88706 +
88707 +static bool skip_types(const_tree var)
88708 +{
88709 + switch (TREE_CODE(var)) {
88710 + case ADDR_EXPR:
88711 +#if BUILDING_GCC_VERSION >= 4006
88712 + case MEM_REF:
88713 +#endif
88714 + case ARRAY_REF:
88715 + case BIT_FIELD_REF:
88716 + case INDIRECT_REF:
88717 + case TARGET_MEM_REF:
88718 + case VAR_DECL:
88719 + return true;
88720 + default:
88721 + break;
88722 + }
88723 + return false;
88724 +}
88725 +
88726 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
88727 +{
88728 + gimple phi = get_def_stmt(result);
88729 + unsigned int i, n = gimple_phi_num_args(phi);
88730 +
88731 + if (!phi)
88732 + return false;
88733 +
88734 + pointer_set_insert(visited, phi);
88735 + for (i = 0; i < n; i++) {
88736 + const_tree arg = gimple_phi_arg_def(phi, i);
88737 + if (pre_expand(visited, arg))
88738 + return true;
88739 + }
88740 + return false;
88741 +}
88742 +
88743 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
88744 +{
88745 + gimple def_stmt = get_def_stmt(lhs);
88746 + const_tree rhs;
88747 +
88748 + if (!def_stmt)
88749 + return false;
88750 +
88751 + rhs = gimple_assign_rhs1(def_stmt);
88752 + if (pre_expand(visited, rhs))
88753 + return true;
88754 + return false;
88755 +}
88756 +
88757 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
88758 +{
88759 + bool rhs1_found, rhs2_found;
88760 + gimple def_stmt = get_def_stmt(lhs);
88761 + const_tree rhs1, rhs2;
88762 +
88763 + if (!def_stmt)
88764 + return false;
88765 +
88766 + rhs1 = gimple_assign_rhs1(def_stmt);
88767 + rhs2 = gimple_assign_rhs2(def_stmt);
88768 + rhs1_found = pre_expand(visited, rhs1);
88769 + rhs2_found = pre_expand(visited, rhs2);
88770 +
88771 + return rhs1_found || rhs2_found;
88772 +}
88773 +
88774 +static const_tree search_field_decl(const_tree comp_ref)
88775 +{
88776 + const_tree field = NULL_TREE;
88777 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
88778 +
88779 + for (i = 0; i < len; i++) {
88780 + field = TREE_OPERAND(comp_ref, i);
88781 + if (TREE_CODE(field) == FIELD_DECL)
88782 + break;
88783 + }
88784 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
88785 + return field;
88786 +}
88787 +
88788 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
88789 +{
88790 + const_tree attr, p;
88791 +
88792 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
88793 + if (!attr || !TREE_VALUE(attr))
88794 + return MARKED_NO;
88795 +
88796 + p = TREE_VALUE(attr);
88797 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
88798 + return MARKED_NOT_INTENTIONAL;
88799 +
88800 + do {
88801 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
88802 + return MARKED_YES;
88803 + p = TREE_CHAIN(p);
88804 + } while (p);
88805 +
88806 + return MARKED_NO;
88807 +}
88808 +
88809 +static void print_missing_msg(tree func, unsigned int argnum)
88810 +{
88811 + unsigned int new_hash;
88812 + size_t len;
88813 + unsigned char tree_codes[CODES_LIMIT];
88814 + location_t loc = DECL_SOURCE_LOCATION(func);
88815 + const char *curfunc = get_asm_name(func);
88816 +
88817 + len = get_function_decl(func, tree_codes);
88818 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
88819 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
88820 +}
88821 +
88822 +static unsigned int search_missing_attribute(const_tree arg)
88823 +{
88824 + const_tree type = TREE_TYPE(arg);
88825 + tree func = get_original_function_decl(current_function_decl);
88826 + unsigned int argnum;
88827 + const struct size_overflow_hash *hash;
88828 +
88829 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
88830 +
88831 + if (TREE_CODE(type) == POINTER_TYPE)
88832 + return 0;
88833 +
88834 + argnum = find_arg_number(arg, func);
88835 + if (argnum == 0)
88836 + return 0;
88837 +
88838 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
88839 + return argnum;
88840 +
88841 + hash = get_function_hash(func);
88842 + if (!hash || !(hash->param & (1U << argnum))) {
88843 + print_missing_msg(func, argnum);
88844 + return 0;
88845 + }
88846 + return argnum;
88847 +}
88848 +
88849 +static bool is_already_marked(const_tree lhs)
88850 +{
88851 + unsigned int argnum;
88852 + const_tree fndecl;
88853 +
88854 + argnum = search_missing_attribute(lhs);
88855 + fndecl = get_original_function_decl(current_function_decl);
88856 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
88857 + return true;
88858 + return false;
88859 +}
88860 +
88861 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
88862 +{
88863 + const_gimple def_stmt;
88864 +
88865 + if (is_gimple_constant(lhs))
88866 + return false;
88867 +
88868 + if (skip_types(lhs))
88869 + return false;
88870 +
88871 + if (TREE_CODE(lhs) == PARM_DECL)
88872 + return is_already_marked(lhs);
88873 +
88874 + if (TREE_CODE(lhs) == COMPONENT_REF) {
88875 + const_tree field, attr;
88876 +
88877 + field = search_field_decl(lhs);
88878 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
88879 + if (!attr || !TREE_VALUE(attr))
88880 + return false;
88881 + return true;
88882 + }
88883 +
88884 + def_stmt = get_def_stmt(lhs);
88885 +
88886 + if (!def_stmt)
88887 + return false;
88888 +
88889 + if (pointer_set_contains(visited, def_stmt))
88890 + return false;
88891 +
88892 + switch (gimple_code(def_stmt)) {
88893 + case GIMPLE_NOP:
88894 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
88895 + return is_already_marked(lhs);
88896 + return false;
88897 + case GIMPLE_PHI:
88898 + return walk_phi(visited, lhs);
88899 + case GIMPLE_CALL:
88900 + case GIMPLE_ASM:
88901 + return false;
88902 + case GIMPLE_ASSIGN:
88903 + switch (gimple_num_ops(def_stmt)) {
88904 + case 2:
88905 + return walk_unary_ops(visited, lhs);
88906 + case 3:
88907 + return walk_binary_ops(visited, lhs);
88908 + }
88909 + default:
88910 + debug_gimple_stmt((gimple)def_stmt);
88911 + error("%s: unknown gimple code", __func__);
88912 + gcc_unreachable();
88913 + }
88914 +}
88915 +
88916 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
88917 +{
88918 + struct pointer_set_t *visited;
88919 + bool is_found;
88920 + enum marked is_marked;
88921 + location_t loc;
88922 +
88923 + visited = pointer_set_create();
88924 + is_found = pre_expand(visited, arg);
88925 + pointer_set_destroy(visited);
88926 +
88927 + is_marked = mark_status(fndecl, argnum + 1);
88928 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
88929 + return true;
88930 +
88931 + if (is_found) {
88932 + loc = DECL_SOURCE_LOCATION(fndecl);
88933 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
88934 + return true;
88935 + }
88936 + return false;
88937 +}
88938 +
88939 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
88940 +{
88941 + struct pointer_set_t *visited;
88942 + tree arg, newarg;
88943 + bool match;
88944 +
88945 + match = get_function_arg(&argnum, fndecl);
88946 + if (!match)
88947 + return;
88948 + gcc_assert(gimple_call_num_args(stmt) > argnum);
88949 + arg = gimple_call_arg(stmt, argnum);
88950 + if (arg == NULL_TREE)
88951 + return;
88952 +
88953 + if (is_gimple_constant(arg))
88954 + return;
88955 +
88956 + if (search_attributes(fndecl, arg, argnum))
88957 + return;
88958 +
88959 + if (TREE_CODE(arg) != SSA_NAME)
88960 + return;
88961 +
88962 + check_arg_type(arg);
88963 +
88964 + visited = pointer_set_create();
88965 + newarg = expand(visited, arg);
88966 + pointer_set_destroy(visited);
88967 +
88968 + if (newarg == NULL_TREE)
88969 + return;
88970 +
88971 + change_function_arg(stmt, arg, argnum, newarg);
88972 +
88973 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
88974 +}
88975 +
88976 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
88977 +{
88978 + tree p = TREE_VALUE(attr);
88979 + do {
88980 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
88981 + p = TREE_CHAIN(p);
88982 + } while (p);
88983 +}
88984 +
88985 +static void handle_function_by_hash(gimple stmt, tree fndecl)
88986 +{
88987 + tree orig_fndecl;
88988 + unsigned int num;
88989 + const struct size_overflow_hash *hash;
88990 +
88991 + orig_fndecl = get_original_function_decl(fndecl);
88992 + if (C_DECL_IMPLICIT(orig_fndecl))
88993 + return;
88994 + hash = get_function_hash(orig_fndecl);
88995 + if (!hash)
88996 + return;
88997 +
88998 + for (num = 1; num <= MAX_PARAM; num++)
88999 + if (hash->param & (1U << num))
89000 + handle_function_arg(stmt, fndecl, num - 1);
89001 +}
89002 +
89003 +static void set_plf_false(void)
89004 +{
89005 + basic_block bb;
89006 +
89007 + FOR_ALL_BB(bb) {
89008 + gimple_stmt_iterator si;
89009 +
89010 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89011 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89012 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89013 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89014 + }
89015 +}
89016 +
89017 +static unsigned int handle_function(void)
89018 +{
89019 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89020 +
89021 + set_plf_false();
89022 +
89023 + do {
89024 + gimple_stmt_iterator gsi;
89025 + next = bb->next_bb;
89026 +
89027 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89028 + tree fndecl, attr;
89029 + gimple stmt = gsi_stmt(gsi);
89030 +
89031 + if (!(is_gimple_call(stmt)))
89032 + continue;
89033 + fndecl = gimple_call_fndecl(stmt);
89034 + if (fndecl == NULL_TREE)
89035 + continue;
89036 + if (gimple_call_num_args(stmt) == 0)
89037 + continue;
89038 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89039 + if (!attr || !TREE_VALUE(attr))
89040 + handle_function_by_hash(stmt, fndecl);
89041 + else
89042 + handle_function_by_attribute(stmt, attr, fndecl);
89043 + gsi = gsi_for_stmt(stmt);
89044 + next = gimple_bb(stmt)->next_bb;
89045 + }
89046 + bb = next;
89047 + } while (bb);
89048 + return 0;
89049 +}
89050 +
89051 +static struct gimple_opt_pass size_overflow_pass = {
89052 + .pass = {
89053 + .type = GIMPLE_PASS,
89054 + .name = "size_overflow",
89055 + .gate = NULL,
89056 + .execute = handle_function,
89057 + .sub = NULL,
89058 + .next = NULL,
89059 + .static_pass_number = 0,
89060 + .tv_id = TV_NONE,
89061 + .properties_required = PROP_cfg | PROP_referenced_vars,
89062 + .properties_provided = 0,
89063 + .properties_destroyed = 0,
89064 + .todo_flags_start = 0,
89065 + .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
89066 + }
89067 +};
89068 +
89069 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89070 +{
89071 + tree fntype;
89072 +
89073 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89074 +
89075 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89076 + fntype = build_function_type_list(void_type_node,
89077 + const_char_ptr_type_node,
89078 + unsigned_type_node,
89079 + const_char_ptr_type_node,
89080 + const_char_ptr_type_node,
89081 + NULL_TREE);
89082 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89083 +
89084 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89085 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89086 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89087 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89088 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89089 +}
89090 +
89091 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89092 +{
89093 + int i;
89094 + const char * const plugin_name = plugin_info->base_name;
89095 + const int argc = plugin_info->argc;
89096 + const struct plugin_argument * const argv = plugin_info->argv;
89097 + bool enable = true;
89098 +
89099 + struct register_pass_info size_overflow_pass_info = {
89100 + .pass = &size_overflow_pass.pass,
89101 + .reference_pass_name = "ssa",
89102 + .ref_pass_instance_number = 1,
89103 + .pos_op = PASS_POS_INSERT_AFTER
89104 + };
89105 +
89106 + if (!plugin_default_version_check(version, &gcc_version)) {
89107 + error(G_("incompatible gcc/plugin versions"));
89108 + return 1;
89109 + }
89110 +
89111 + for (i = 0; i < argc; ++i) {
89112 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89113 + enable = false;
89114 + continue;
89115 + }
89116 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89117 + }
89118 +
89119 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89120 + if (enable) {
89121 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89122 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89123 + }
89124 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89125 +
89126 + return 0;
89127 +}
89128 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89129 new file mode 100644
89130 index 0000000..38d2014
89131 --- /dev/null
89132 +++ b/tools/gcc/stackleak_plugin.c
89133 @@ -0,0 +1,313 @@
89134 +/*
89135 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89136 + * Licensed under the GPL v2
89137 + *
89138 + * Note: the choice of the license means that the compilation process is
89139 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89140 + * but for the kernel it doesn't matter since it doesn't link against
89141 + * any of the gcc libraries
89142 + *
89143 + * gcc plugin to help implement various PaX features
89144 + *
89145 + * - track lowest stack pointer
89146 + *
89147 + * TODO:
89148 + * - initialize all local variables
89149 + *
89150 + * BUGS:
89151 + * - none known
89152 + */
89153 +#include "gcc-plugin.h"
89154 +#include "config.h"
89155 +#include "system.h"
89156 +#include "coretypes.h"
89157 +#include "tree.h"
89158 +#include "tree-pass.h"
89159 +#include "flags.h"
89160 +#include "intl.h"
89161 +#include "toplev.h"
89162 +#include "plugin.h"
89163 +//#include "expr.h" where are you...
89164 +#include "diagnostic.h"
89165 +#include "plugin-version.h"
89166 +#include "tm.h"
89167 +#include "function.h"
89168 +#include "basic-block.h"
89169 +#include "gimple.h"
89170 +#include "rtl.h"
89171 +#include "emit-rtl.h"
89172 +
89173 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89174 +
89175 +int plugin_is_GPL_compatible;
89176 +
89177 +static int track_frame_size = -1;
89178 +static const char track_function[] = "pax_track_stack";
89179 +static const char check_function[] = "pax_check_alloca";
89180 +static bool init_locals;
89181 +
89182 +static struct plugin_info stackleak_plugin_info = {
89183 + .version = "201203140940",
89184 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89185 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89186 +};
89187 +
89188 +static bool gate_stackleak_track_stack(void);
89189 +static unsigned int execute_stackleak_tree_instrument(void);
89190 +static unsigned int execute_stackleak_final(void);
89191 +
89192 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89193 + .pass = {
89194 + .type = GIMPLE_PASS,
89195 + .name = "stackleak_tree_instrument",
89196 + .gate = gate_stackleak_track_stack,
89197 + .execute = execute_stackleak_tree_instrument,
89198 + .sub = NULL,
89199 + .next = NULL,
89200 + .static_pass_number = 0,
89201 + .tv_id = TV_NONE,
89202 + .properties_required = PROP_gimple_leh | PROP_cfg,
89203 + .properties_provided = 0,
89204 + .properties_destroyed = 0,
89205 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89206 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89207 + }
89208 +};
89209 +
89210 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89211 + .pass = {
89212 + .type = RTL_PASS,
89213 + .name = "stackleak_final",
89214 + .gate = gate_stackleak_track_stack,
89215 + .execute = execute_stackleak_final,
89216 + .sub = NULL,
89217 + .next = NULL,
89218 + .static_pass_number = 0,
89219 + .tv_id = TV_NONE,
89220 + .properties_required = 0,
89221 + .properties_provided = 0,
89222 + .properties_destroyed = 0,
89223 + .todo_flags_start = 0,
89224 + .todo_flags_finish = TODO_dump_func
89225 + }
89226 +};
89227 +
89228 +static bool gate_stackleak_track_stack(void)
89229 +{
89230 + return track_frame_size >= 0;
89231 +}
89232 +
89233 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89234 +{
89235 + gimple check_alloca;
89236 + tree fntype, fndecl, alloca_size;
89237 +
89238 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89239 + fndecl = build_fn_decl(check_function, fntype);
89240 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89241 +
89242 + // insert call to void pax_check_alloca(unsigned long size)
89243 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89244 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89245 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89246 +}
89247 +
89248 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89249 +{
89250 + gimple track_stack;
89251 + tree fntype, fndecl;
89252 +
89253 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89254 + fndecl = build_fn_decl(track_function, fntype);
89255 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89256 +
89257 + // insert call to void pax_track_stack(void)
89258 + track_stack = gimple_build_call(fndecl, 0);
89259 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89260 +}
89261 +
89262 +#if BUILDING_GCC_VERSION == 4005
89263 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89264 +{
89265 + tree fndecl;
89266 +
89267 + if (!is_gimple_call(stmt))
89268 + return false;
89269 + fndecl = gimple_call_fndecl(stmt);
89270 + if (!fndecl)
89271 + return false;
89272 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89273 + return false;
89274 +// print_node(stderr, "pax", fndecl, 4);
89275 + return DECL_FUNCTION_CODE(fndecl) == code;
89276 +}
89277 +#endif
89278 +
89279 +static bool is_alloca(gimple stmt)
89280 +{
89281 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89282 + return true;
89283 +
89284 +#if BUILDING_GCC_VERSION >= 4007
89285 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89286 + return true;
89287 +#endif
89288 +
89289 + return false;
89290 +}
89291 +
89292 +static unsigned int execute_stackleak_tree_instrument(void)
89293 +{
89294 + basic_block bb, entry_bb;
89295 + bool prologue_instrumented = false, is_leaf = true;
89296 +
89297 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89298 +
89299 + // 1. loop through BBs and GIMPLE statements
89300 + FOR_EACH_BB(bb) {
89301 + gimple_stmt_iterator gsi;
89302 +
89303 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89304 + gimple stmt;
89305 +
89306 + stmt = gsi_stmt(gsi);
89307 +
89308 + if (is_gimple_call(stmt))
89309 + is_leaf = false;
89310 +
89311 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89312 + if (!is_alloca(stmt))
89313 + continue;
89314 +
89315 + // 2. insert stack overflow check before each __builtin_alloca call
89316 + stackleak_check_alloca(&gsi);
89317 +
89318 + // 3. insert track call after each __builtin_alloca call
89319 + stackleak_add_instrumentation(&gsi);
89320 + if (bb == entry_bb)
89321 + prologue_instrumented = true;
89322 + }
89323 + }
89324 +
89325 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89326 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89327 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89328 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89329 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89330 + return 0;
89331 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89332 + return 0;
89333 +
89334 + // 4. insert track call at the beginning
89335 + if (!prologue_instrumented) {
89336 + gimple_stmt_iterator gsi;
89337 +
89338 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89339 + if (dom_info_available_p(CDI_DOMINATORS))
89340 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89341 + gsi = gsi_start_bb(bb);
89342 + stackleak_add_instrumentation(&gsi);
89343 + }
89344 +
89345 + return 0;
89346 +}
89347 +
89348 +static unsigned int execute_stackleak_final(void)
89349 +{
89350 + rtx insn;
89351 +
89352 + if (cfun->calls_alloca)
89353 + return 0;
89354 +
89355 + // keep calls only if function frame is big enough
89356 + if (get_frame_size() >= track_frame_size)
89357 + return 0;
89358 +
89359 + // 1. find pax_track_stack calls
89360 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89361 + // 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))
89362 + rtx body;
89363 +
89364 + if (!CALL_P(insn))
89365 + continue;
89366 + body = PATTERN(insn);
89367 + if (GET_CODE(body) != CALL)
89368 + continue;
89369 + body = XEXP(body, 0);
89370 + if (GET_CODE(body) != MEM)
89371 + continue;
89372 + body = XEXP(body, 0);
89373 + if (GET_CODE(body) != SYMBOL_REF)
89374 + continue;
89375 + if (strcmp(XSTR(body, 0), track_function))
89376 + continue;
89377 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89378 + // 2. delete call
89379 + insn = delete_insn_and_edges(insn);
89380 +#if BUILDING_GCC_VERSION >= 4007
89381 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89382 + insn = delete_insn_and_edges(insn);
89383 +#endif
89384 + }
89385 +
89386 +// print_simple_rtl(stderr, get_insns());
89387 +// print_rtl(stderr, get_insns());
89388 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89389 +
89390 + return 0;
89391 +}
89392 +
89393 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89394 +{
89395 + const char * const plugin_name = plugin_info->base_name;
89396 + const int argc = plugin_info->argc;
89397 + const struct plugin_argument * const argv = plugin_info->argv;
89398 + int i;
89399 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89400 + .pass = &stackleak_tree_instrument_pass.pass,
89401 +// .reference_pass_name = "tree_profile",
89402 + .reference_pass_name = "optimized",
89403 + .ref_pass_instance_number = 1,
89404 + .pos_op = PASS_POS_INSERT_BEFORE
89405 + };
89406 + struct register_pass_info stackleak_final_pass_info = {
89407 + .pass = &stackleak_final_rtl_opt_pass.pass,
89408 + .reference_pass_name = "final",
89409 + .ref_pass_instance_number = 1,
89410 + .pos_op = PASS_POS_INSERT_BEFORE
89411 + };
89412 +
89413 + if (!plugin_default_version_check(version, &gcc_version)) {
89414 + error(G_("incompatible gcc/plugin versions"));
89415 + return 1;
89416 + }
89417 +
89418 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89419 +
89420 + for (i = 0; i < argc; ++i) {
89421 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89422 + if (!argv[i].value) {
89423 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89424 + continue;
89425 + }
89426 + track_frame_size = atoi(argv[i].value);
89427 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89428 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89429 + continue;
89430 + }
89431 + if (!strcmp(argv[i].key, "initialize-locals")) {
89432 + if (argv[i].value) {
89433 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89434 + continue;
89435 + }
89436 + init_locals = true;
89437 + continue;
89438 + }
89439 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89440 + }
89441 +
89442 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89443 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89444 +
89445 + return 0;
89446 +}
89447 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89448 index 6789d78..4afd019e 100644
89449 --- a/tools/perf/util/include/asm/alternative-asm.h
89450 +++ b/tools/perf/util/include/asm/alternative-asm.h
89451 @@ -5,4 +5,7 @@
89452
89453 #define altinstruction_entry #
89454
89455 + .macro pax_force_retaddr rip=0, reload=0
89456 + .endm
89457 +
89458 #endif
89459 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
89460 index af0f22f..9a7d479 100644
89461 --- a/usr/gen_init_cpio.c
89462 +++ b/usr/gen_init_cpio.c
89463 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
89464 int retval;
89465 int rc = -1;
89466 int namesize;
89467 - int i;
89468 + unsigned int i;
89469
89470 mode |= S_IFREG;
89471
89472 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
89473 *env_var = *expanded = '\0';
89474 strncat(env_var, start + 2, end - start - 2);
89475 strncat(expanded, new_location, start - new_location);
89476 - strncat(expanded, getenv(env_var), PATH_MAX);
89477 - strncat(expanded, end + 1, PATH_MAX);
89478 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
89479 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
89480 strncpy(new_location, expanded, PATH_MAX);
89481 + new_location[PATH_MAX] = 0;
89482 } else
89483 break;
89484 }
89485 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89486 index d617f69..6b445d2 100644
89487 --- a/virt/kvm/kvm_main.c
89488 +++ b/virt/kvm/kvm_main.c
89489 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89490
89491 static cpumask_var_t cpus_hardware_enabled;
89492 static int kvm_usage_count = 0;
89493 -static atomic_t hardware_enable_failed;
89494 +static atomic_unchecked_t hardware_enable_failed;
89495
89496 struct kmem_cache *kvm_vcpu_cache;
89497 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89498 @@ -715,7 +715,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89499 /* We can read the guest memory with __xxx_user() later on. */
89500 if (user_alloc &&
89501 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89502 - !access_ok(VERIFY_WRITE,
89503 + !__access_ok(VERIFY_WRITE,
89504 (void __user *)(unsigned long)mem->userspace_addr,
89505 mem->memory_size)))
89506 goto out;
89507 @@ -2304,7 +2304,7 @@ static void hardware_enable_nolock(void *junk)
89508
89509 if (r) {
89510 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89511 - atomic_inc(&hardware_enable_failed);
89512 + atomic_inc_unchecked(&hardware_enable_failed);
89513 printk(KERN_INFO "kvm: enabling virtualization on "
89514 "CPU%d failed\n", cpu);
89515 }
89516 @@ -2358,10 +2358,10 @@ static int hardware_enable_all(void)
89517
89518 kvm_usage_count++;
89519 if (kvm_usage_count == 1) {
89520 - atomic_set(&hardware_enable_failed, 0);
89521 + atomic_set_unchecked(&hardware_enable_failed, 0);
89522 on_each_cpu(hardware_enable_nolock, NULL, 1);
89523
89524 - if (atomic_read(&hardware_enable_failed)) {
89525 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89526 hardware_disable_all_nolock();
89527 r = -EBUSY;
89528 }
89529 @@ -2722,7 +2722,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89530 kvm_arch_vcpu_put(vcpu);
89531 }
89532
89533 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89534 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89535 struct module *module)
89536 {
89537 int r;
89538 @@ -2785,7 +2785,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89539 if (!vcpu_align)
89540 vcpu_align = __alignof__(struct kvm_vcpu);
89541 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89542 - 0, NULL);
89543 + SLAB_USERCOPY, NULL);
89544 if (!kvm_vcpu_cache) {
89545 r = -ENOMEM;
89546 goto out_free_3;
89547 @@ -2795,9 +2795,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89548 if (r)
89549 goto out_free;
89550
89551 - kvm_chardev_ops.owner = module;
89552 - kvm_vm_fops.owner = module;
89553 - kvm_vcpu_fops.owner = module;
89554 + pax_open_kernel();
89555 + *(void **)&kvm_chardev_ops.owner = module;
89556 + *(void **)&kvm_vm_fops.owner = module;
89557 + *(void **)&kvm_vcpu_fops.owner = module;
89558 + pax_close_kernel();
89559
89560 r = misc_register(&kvm_dev);
89561 if (r) {